/** * Copyright (c) 2025 Elara AI Pty Ltd * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details. */ /** * The Schematic's drops (#1390, `Schematic Builder Spec.md` §7, §8, * SC11–SC13) — pure and React-free: what a library card does where it lands, * decided as data before anything is drawn or written. The frame records a * plan as one step of the editing's history (`use-drop.ts`), and the canvas * works out where a drag rests from its own drawing. * * - **What is dragged** ({@link SchematicDropCard}, {@link dropHostOf}): a * card of a tab that drops — an item kind's template, which adds an item; a * row of the Backlog, which places it; a link or a net kind's template, * which writes its values over a link or a net of its kind; an author's * card, whose patch sets its fields on an entity of the kind it names. * - **Where a drag rests** ({@link SchematicDropAtType}, {@link restsAt}): the * point of the drawing under the pointer, for a card that adds or places an * item — at the screen's resolution ({@link dropPoint}), so what the ghost * says is what is written — or the entity of the card's kind under it, for * one that lands on an entity; or nothing of its kind. The shared drag * grammar's `CellRef` carries it in its `row`, printed. * - **What a drop does** ({@link planDrop}, {@link dropEdits}): an item added * at the point, under the key its kind makes (SC12, #1549); a backlog row * placed there (SC4); a template's values written over the link or the net, * never its ends, its sides or its key (SC11); an author's card's fields set * — or refused, with the reason the ghost says in red: outside the drawing, * no entity of the card's kind under it, its kind read only, its kind's * session taking no edit now, or its kind adding no item, its keys of a type * the form can't type (#1549). * - **⏎ on a card** ({@link planEnter}, SC13): a card that adds or places an * item lands at the view's centre — and Details' Place there too (#1394) — * refused where that is off the drawing in words that say what brings the * drawing to it; one that lands on an entity, on the selection — every * selected entity of its kind, as one step. * - **Its words** ({@link dropCaption}, {@link dropName}, {@link dropRefusal}, * {@link dropLabel}) and **its marks** ({@link markOf}): the point a card * lands at and the zone holding it, or the entity it lands on. * * @packageDocumentation */ import { FloatType, IntegerType, NullType, StringType, StructType, VariantType, type ValueTypeOf } from "@elaraai/east"; import { Schematic } from "@elaraai/e3-ui/internal"; import type { DragPayload, DropCellOptions, DropVeto } from "@elaraai/east-ui-components"; import type { BacklogEntry } from "./backlog.js"; import { type SchematicRef } from "./canvas/drawn.js"; import type { SchematicValue } from "./data.js"; import type { SchematicNewKey } from "./editing.js"; import { type SchematicEdit, type SchematicFieldWrite, type SchematicKeyRefusal } from "./edits.js"; import type { SchematicDropRefusalWord, SchematicWords } from "./messages.js"; /** A point of the drawing, in world units. */ type Point = ValueTypeOf; /** A card the canvas takes, as the Schematic reads it: what its drop does, the kind it writes, and its name. */ export type SchematicDropCard = /** An item kind's template: a new item of its kind at the drop point, every other field the template's (SC12). */ { readonly does: "add"; readonly kind: string; readonly label: string; readonly values: Uint8Array; } /** A row of an item kind's backlog: placed at the drop point (SC4). */ | { readonly does: "place"; readonly ref: SchematicRef; readonly label: string; } /** A link or a net kind's template: its values written over a link or a net of its kind, never its ends, its sides or its key (SC11). */ | { readonly does: "retype"; readonly kind: string; readonly label: string; readonly values: Uint8Array; } /** An author's card: the fields its patch sets, on an entity of the kind its patch names. */ | { readonly does: "set"; readonly kind: string; readonly label: string; readonly sets: readonly SchematicFieldWrite[]; }; /** * The slot of the kind a card writes. * * @param card - The card * @returns The kind's slot */ export declare function cardKind(card: SchematicDropCard): string; /** * Whether a card lands at a point of the drawing — a template's new item, a * backlog row placed — rather than on an entity. * * @param card - The card * @returns Whether it lands at a point */ export declare function landsAtPoint(card: SchematicDropCard): card is Extract; /** A kind whose templates the Templates tab lists: its slot, and its templates. */ export interface SchematicTemplatesKind { /** The kind's slot. */ readonly key: string; /** Its templates, as the wire carries them: each its key, its name, and its values as bytes. */ readonly templates: readonly ValueTypeOf[]; } /** What the canvas takes dropped: its drop target, and each library whose cards drop — its cards by key. */ export interface SchematicDropHost { /** The Schematic's drop target: the surface its canvas registers on. */ readonly surface: string; /** Each library whose cards drop, by its id: its cards, by key. */ readonly libraries: ReadonlyMap>; /** Each library whose cards a paged list draws, by its id: a card it has drawn, by key — the paged Backlog's (#1393). */ readonly paged: ReadonlyMap SchematicDropCard | undefined>; } /** * What the canvas takes dropped, from the tabs the payload lists: the * Templates tab's cards — an item kind's adding an item, a link or a net * kind's writing its values over one — keyed as the tab keys them, by their * kind's slot and their key; the Backlog's rows, each placed where it is * dropped, keyed by its id; and each author's tab whose patch names a kind, * its cards by their keys. The Index, the Layers and an author's tab with no * `drop` drop nothing. * * @param surface - The Schematic's drop target * @param libraryOf - The library a tab's cards drag from, by the tab's key * @param tabs - The tabs the payload lists * @param kinds - The payload's item, link and net kinds: their templates * @param backlog - The Backlog's rows in hand * @param pagedBacklog - What a card of the paged Backlog drops, by its id (#1393): a row it has drawn, placed where it lands; * `undefined` while the Backlog lists only rows in hand * @returns What the canvas takes */ export declare function dropHostOf(surface: string, libraryOf: (tabKey: string) => string, tabs: SchematicValue["library"], kinds: { readonly items: readonly SchematicTemplatesKind[]; readonly links: readonly SchematicTemplatesKind[]; readonly nets: readonly SchematicTemplatesKind[]; }, backlog: readonly BacklogEntry[], pagedBacklog?: (key: string) => SchematicDropCard | undefined): SchematicDropHost; /** * A card the canvas takes, by its library and its key: one the library lists in hand, or one its paged list has drawn. * * @param host - What the canvas takes * @param library - The card's library * @param key - The card's key * @returns The card, or `undefined` for one no tab that drops lists */ export declare function cardOf(host: SchematicDropHost, library: string, key: string): SchematicDropCard | undefined; /** * A point a card lands at: its coordinates in world units, and how many * decimal digits the screen resolved them to — what the words print them at. */ export declare const SchematicDropPointType: StructType<{ readonly x: FloatType; readonly y: FloatType; readonly digits: IntegerType; }>; /** A point a card lands at, decoded. */ export type SchematicDropPoint = ValueTypeOf; /** Where a drag rests over the canvas, for what it carries — what the Schematic's drop `CellRef` names in its `row`, printed. */ export declare const SchematicDropAtType: VariantType<{ /** A point of the drawing: where a template's item or a backlog row lands. */ readonly point: StructType<{ readonly x: FloatType; readonly y: FloatType; readonly digits: IntegerType; }>; /** The entity of the card's kind under the pointer: what a template writes its values over, or an author's card sets its fields on. */ readonly entity: StructType<{ readonly kind: StringType; readonly key: StringType; }>; /** Nothing of the card's kind under the pointer. */ readonly nothing: NullType; }>; /** Where a drag rests, decoded. */ export type SchematicDropAt = ValueTypeOf; /** Where a drag rests, as its `CellRef` carries it. */ export declare const printDropAt: (at: SchematicDropAt) => string; /** * Where a drop's `CellRef` says the drag rests. * * @param text - The `CellRef`'s `row` * @returns Where it rests, or `undefined` when the text names nowhere — a coordinate another surface made */ export declare function readDropAt(text: string): SchematicDropAt | undefined; /** Nothing of a card's kind: where the canvas's drop cell rests before a drag says otherwise. */ export declare const NOWHERE: SchematicDropAt; /** * The point a drop lands at, from the pointer's place in the world: each * coordinate rounded to the screen's resolution — the fewest decimal digits * whose last is no wider than a pixel at the current zoom — so the drop lands * within a pixel of the pointer, and the ghost says what is written. * * @param world - The pointer's place, in world units * @param ppu - The canvas's pixels per world unit * @returns The point, and its digits */ export declare function dropPoint(world: { readonly x: number; readonly y: number; }, ppu: number): SchematicDropPoint; /** * Where a drag rests at a point of the canvas, for a card: the point, for one * that lands at a point; else the entity of its kind under the pointer, or * nothing. * * @param card - The card dragged * @param point - The point under the pointer, at the screen's resolution ({@link dropPoint}) * @param entityOf - The entity of a kind under the pointer, by the kind's slot; `undefined` for none * @returns Where the drag rests */ export declare function restsAt(card: SchematicDropCard, point: SchematicDropPoint, entityOf: (kind: string) => SchematicRef | undefined): SchematicDropAt; /** A kind, as a drop reads it: its name, and whether it writes — bound with its patch door, the Schematic not read only. */ export interface SchematicDropKind { /** Its name (`Rack`). */ readonly name: string; /** Whether a drop writes it. */ readonly writes: boolean; } /** What a drop reads of the Schematic as it stands. */ export interface SchematicDropContext { /** The drawing's world bounds: a card lands at a point inside them. */ readonly extent: { readonly width: number; readonly height: number; }; /** Each kind, by its slot. */ readonly kinds: ReadonlyMap; /** Whether a kind's session takes a gesture now: its record read, no Save on its way. */ readonly available: (slot: string) => boolean; /** * Why a kind adds no item (#1549): its keys' type's name, a type the form can't type, where it builds none of its own; * `undefined` for a kind that keys the items it adds. */ readonly untyped: (slot: string) => string | undefined; /** An entity's name, as the words say it; `undefined` for one the drawing no longer draws. */ readonly nameOf: (ref: SchematicRef) => string | undefined; /** The label of the innermost zone holding a point; `undefined` for none. */ readonly zoneAt: (point: Point) => string | undefined; } /** * Why a drop is refused where it rests: in its words — the kind named as the * kind gives its name — or, what it lands on having left the drawing, in none. */ export type SchematicDropRefusal = { readonly why: "gone"; } | SchematicDropRefusalWord; /** What a drop does where it rests. */ export type SchematicDropPlan = /** A new item of a kind at a point, its other fields a template's values (SC12): the zone holding the point, for its words. */ { readonly kind: "add"; readonly slot: string; readonly at: SchematicDropPoint; readonly zone: string | undefined; readonly values: Uint8Array; } /** A backlog row placed at a point (SC4). */ | { readonly kind: "place"; readonly ref: SchematicRef; readonly at: SchematicDropPoint; readonly zone: string | undefined; } /** A template's values written over a link or a net of its kind (SC11), and its name. */ | { readonly kind: "retype"; readonly ref: SchematicRef; readonly name: string; readonly values: Uint8Array; } /** An author's card's fields set on entities of a kind: one's name, or — several, a card's ⏎ — the kind's. */ | { readonly kind: "set"; readonly refs: readonly SchematicRef[]; readonly name: string | undefined; readonly kindName: string; readonly sets: readonly SchematicFieldWrite[]; } | { readonly kind: "refused"; readonly why: SchematicDropRefusal; }; /** * What a drop does where it rests — see the module docs. A card of a kind * read only, or whose session takes no gesture now, is refused wherever it * rests, and so is a template of a kind that adds no item (#1549); a card that lands at a point is refused outside the drawing, and one * that lands on an entity anywhere but on an entity of its kind; one whose * entity has left the drawing is refused in no words. * * @param card - The card dragged * @param at - Where the drag rests * @param ctx - The Schematic as it stands * @returns What the drop does, or why it is refused */ export declare function planDrop(card: SchematicDropCard, at: SchematicDropAt, ctx: SchematicDropContext): SchematicDropPlan; /** * What ⏎ on a card does (SC13) — and Details' Place, below 480px of main * (#1394): a card that adds or places an item lands at the view's centre, and * where that is off the drawing it is refused in words that say what brings the * drawing there — pan it into view, or Fit — as no pointer can be moved there; * a template of a link or a net kind, on the selected link or net of its kind; * an author's card, on every selected entity of its kind, as one step. A card * the selection holds nothing of its kind for is refused, naming where it * lands, as a drag over nothing of its kind is. * * @param card - The card * @param selection - What the canvas has selected, each entity by its reference * @param centre - The view's centre, at the screen's resolution; `undefined` while the canvas has no size * @param ctx - The Schematic as it stands * @returns What the ⏎ does, or why it is refused */ export declare function planEnter(card: SchematicDropCard, selection: readonly SchematicRef[], centre: SchematicDropPoint | undefined, ctx: SchematicDropContext): SchematicDropPlan; /** * The edits a plan writes, one step of the history: a new item under the key * its kind makes (#1549); a backlog row's centre; a link's or a net's template * values; each entity's fields an author's card sets — none for a refusal. * * @param plan - The plan * @param newKey - A new row's key, as its kind makes one from the edit making it (`editing.ts`' `newKey`) * @returns The edits, or why the drop records nothing — the key its item builds taken; `undefined` while the key is * still to be read */ export declare function dropEdits(plan: SchematicDropPlan, newKey: (made: SchematicEdit) => SchematicNewKey | undefined): { readonly edits: SchematicEdit[]; } | { readonly refused: SchematicKeyRefusal; } | undefined; /** * The item a drop brings onto the canvas, which it selects: the one a * template added — its key the one its edits made — or the backlog row it * placed; none for a drop on an entity. * * @param plan - The plan * @param edits - The edits it wrote * @returns The item's reference, or `undefined` */ export declare function droppedItem(plan: SchematicDropPlan, edits: readonly SchematicEdit[]): SchematicRef | undefined; /** What the canvas marks while a drag rests where it lands: the point a card lands at, in world units, or the entity it lands on, by its id. */ export type SchematicDropMark = { readonly kind: "point"; readonly x: number; readonly y: number; } | { readonly kind: "entity"; readonly id: string; }; /** * What the canvas marks for a plan: the point a template's item or a backlog * row lands at, or the entity a card lands on — nothing for a refusal. * * @param plan - The plan * @returns The mark, or `undefined` */ export declare function markOf(plan: SchematicDropPlan): SchematicDropMark | undefined; /** * Whether two marks are one: what the canvas draws need not move. * * @param a - A mark, or none * @param b - Another, or none * @returns Whether they mark the same */ export declare function markEqual(a: SchematicDropMark | undefined, b: SchematicDropMark | undefined): boolean; /** * What the ghost says of a plan: where a card lands — `Cage A · 6.04, 2.91 m` * — or what it lands on — `onto A01 → ODF-1` — or, red, why it can't: * `Drop onto a fibre run`. * * @param plan - The plan * @param words - The Schematic's words * @param unit - The drawing's scale unit, if it has one * @returns The caption; `undefined` for a refusal that says nothing */ export declare function dropCaption(plan: SchematicDropPlan, words: SchematicWords, unit: string | undefined): string | undefined; /** * Why a plan is refused, as the footer says it for a card's ⏎ (SC13). * * @param plan - The plan * @param words - The Schematic's words * @returns The words; `undefined` for a plan that lands, or a refusal that says nothing */ export declare function dropRefusal(plan: SchematicDropPlan, words: SchematicWords): string | undefined; /** * Where a plan lands, as a screen reader hears the drag layer say it — the * point and its zone, or the entity — or, refused, the canvas. * * @param plan - The plan * @param words - The Schematic's words * @param unit - The drawing's scale unit, if it has one * @returns The name */ export declare function dropName(plan: SchematicDropPlan, words: SchematicWords, unit: string | undefined): string; /** * A drop's step in the history, and its Save's — `Drop 42U rack · 8 kW at * Cage A · 6.04, 2.91 m`. * * @param plan - The plan: one that lands * @param card - The card dropped * @param words - The Schematic's words * @param unit - The drawing's scale unit, if it has one * @returns The name */ export declare function dropLabel(plan: SchematicDropPlan, card: SchematicDropCard, words: SchematicWords, unit: string | undefined): string; /** * What the canvas hands the drag layer as its one drop cell: built by the * frame and held still while the Schematic takes drops, its functions reading * the Schematic as it stands. The canvas works out where a drag rests from its * own drawing, and marks it. */ export interface SchematicCanvasDrop { /** The surface the cell registers on: the Schematic's drop target. */ readonly surface: string; /** What a drag carries, as the Schematic reads it — a card a tab of its library drops — or `undefined`. */ readonly cardOf: (payload: DragPayload) => SchematicDropCard | undefined; /** What a drop of a card where a drag rests does, over the Schematic as it stands. */ readonly plan: (card: SchematicDropCard, at: SchematicDropAt) => SchematicDropPlan; /** The veto: whether the drop a candidate event makes lands. */ readonly canDrop: DropVeto; /** What the ghost says where the drag rests, and that place's name for the announcements. */ readonly options: Required>; } export {}; //# sourceMappingURL=drop.d.ts.map