/** * Copyright (c) 2025 Elara AI Pty Ltd * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details. */ /** * The sheet's drops (#1187, `Sheet Builder Spec.md` §9.8, §10; SB38–SB40, * SB44, SB45, SB61): what a builder's library cards and the rows' own grips * do where they land, decided as data before anything is drawn or written. * * - **Where a drag rests** is a row of the row space — a flat row, a loose * row, a group's line, its band, its blank line, or the blank tail — which * the shared drag grammar's `CellRef` names by {@link SheetDropRowType}, * printed, its `slot` the seam the pointer's half picks (`before` / * `after`), or `""` for the row itself, where an author's card lands. * - **What a drop does** ({@link planDrop}): a template inserted at the seam, * as the seam's own chips insert, seeded by the template (SB39, SB40); a * card's cells set on the row, or on the band (SB61); a row, a line or a * group moved to the seam (SB44); nothing, where the row already stands; or * refused, with the reason the ghost says in red. * - **Its words** ({@link dropCaption}, {@link dropName}): the place it lands * — `after row 3`, `→ row 3` — or why it can't, in the sheet's words. * * Pure: no React, no DOM. The sheet's core hands it the rows as they stand * ({@link SheetDropContext}), and runs a plan as one transaction. * * @packageDocumentation */ import { NullType, StringType, StructType, VariantType, type ValueTypeOf } from "@elaraai/east"; import type { CellCoord, DragPayload, DropCellOptions, DropVeto } from "@elaraai/east-ui-components"; import { type SheetBodyItem, type SheetColumnMeta } from "./model.js"; import { type InsertRequest, type InsertionAnchor } from "./insertion-gesture.js"; import type { SheetDropRefusalWord } from "./messages.js"; import type { SheetSeeds } from "./use-editing.js"; import type { SheetCellValue, SheetNounValue, SheetRowValue } from "./values.js"; import type { SheetWords } from "./words.js"; /** A row of the row space a drag rests on — what a sheet's drop `CellRef` names in its `row`, printed. */ export declare const SheetDropRowType: VariantType<{ /** A flat row — or a loose row between the groups (#846) — by its id. */ readonly row: StringType; /** A group's line: its group's id, and its key among the group's lines. */ readonly line: StructType<{ readonly group: StringType; readonly key: StringType; }>; /** A group's band, by its group's id. */ readonly band: StringType; /** A group's blank line, by its group's id: a new line at the group's end. */ readonly groupEnd: StringType; /** The blank tail under a flat sheet's rows. */ readonly end: NullType; }>; /** A row a drag rests on, decoded. */ export type SheetDropRow = ValueTypeOf; /** A drop's row as its `CellRef` carries it. */ export declare const printDropRow: (row: SheetDropRow) => string; /** * The row a drop's `CellRef` names. * * @param text - The `CellRef`'s `row` * @returns The row, or `undefined` when the text names none — a coordinate another surface made */ export declare function readDropRow(text: string): SheetDropRow | undefined; /** A seam's side of a row. */ export type SheetDropSide = "before" | "after"; /** A template the builder offers to drop (SB39, SB40): its name, whether it makes a row or a group, and the seeds its new entry takes. */ export interface SheetDropTemplate { /** The template's name — the card's. */ name: string; /** A row (a grouped sheet's line), or a group with its lines. */ kind: "row" | "group"; /** `newRow`'s or `newGroup`'s seed, the template's fields over its defaults: what the new entry starts as. */ seeds: SheetSeeds; } /** An author's card that drops (SB61): its label, and the cells its `drop` patch sets. */ export interface SheetDropCard { /** The card's label. */ label: string; /** The cells the patch sets, by the column key (a band's: the band cell's). */ sets: ReadonlyMap; } /** What the host lets the sheet take, and from where (#1187): a builder's library and the rows' grips. */ export interface SheetDropHost { /** The sheet's drop target: the surface its rows register on. */ surface: string; /** The templates' library, and the templates by key — `undefined` when the builder lists no Rows tab. */ templates: { library: string; byKey: ReadonlyMap; } | undefined; /** Each author's tab that drops, by its library: where its cards land, and its cards by key. */ tabs: ReadonlyMap; }>; } /** What is dragged, as the sheet reads it: a template, a card, or one of its own rows. */ export type SheetDropSource = { kind: "template"; template: SheetDropTemplate; } | { kind: "card"; card: SheetDropCard; lands: "row" | "group"; } | { kind: "move"; row: SheetDropRow; }; /** * A library card, as the sheet reads it. * * @param host - What the host offers * @param library - The card's library * @param key - The card's key * @returns The template or the card, or `undefined` when the host offers none by that key */ export declare function cardSource(host: SheetDropHost, library: string, key: string): SheetDropSource | undefined; /** * What a drag carries, as the sheet reads it. * * @param host - What the host offers * @param payload - What the drag carries * @returns A library card, or one of the sheet's rows; `undefined` for anything else */ export declare function payloadSource(host: SheetDropHost, payload: DragPayload): SheetDropSource | undefined; /** * The slot a drag picks over a row: the row itself for an author's card, else * the seam the pointer's half is nearer. * * @param host - What the host offers * @param payload - What the drag carries * @param rect - The row's box * @param clientY - The pointer's height * @returns `""`, `before` or `after` */ export declare function slotAt(host: SheetDropHost, payload: DragPayload, rect: { top: number; height: number; }, clientY: number): string; /** What a drop reads of the sheet as it stands. */ export interface SheetDropContext { /** The rows on screen, in order: a flat sheet's rows, a grouped sheet's groups and loose rows. */ rows: readonly SheetRowValue[]; /** The body item at a row-space index. */ rowAt: (r: number) => SheetBodyItem | undefined; /** The row-space index of a row, a band or a line, by its id — a line's by its synthetic id. */ rowOf: (id: string) => number | undefined; /** The row-space index of a group's blank line. */ blankLineRowOf: (group: string) => number | undefined; /** The row-space index of a flat sheet's first blank padding row: its tail. */ tailRow: number | undefined; /** The rows of the row space. */ rowCount: number; /** Whether the rows are groups (#740). */ grouped: boolean; /** Whether rows stand between the groups (#846). */ loose: boolean; /** Whether the source sorts its entries by key. */ keyed: boolean; /** Whether a gesture may be made now: the sheet is not read only, and its session takes one. */ writable: boolean; /** What the sheet's `edits` let it do. */ can: { insertRows: boolean; insertGroups: boolean; moveRows: "none" | "within" | "between"; moveGroups: boolean; }; /** The column a card's cell lands under — on a band, its band cell — by key: whether the sheet writes it, and its header. */ columnAt: (band: boolean, key: string) => Pick | undefined; /** Whether a card's cell takes an edit on a row — its column writes, and no mark locks it (#1560); the column's `editable` alone when absent. */ writableAt?: ((r: number, band: boolean, key: string) => boolean) | undefined; /** Where an insertion at a row's seam goes: the seam chips' own anchor. */ anchorFor: (r: number, side: SheetDropSide) => InsertionAnchor; } /** A drop's place: a seam beside a row of the row space, a group's start or end, the sheet's end, or a keyed source's key order. */ export type SheetDropPlace = { at: "seam"; r: number; side: SheetDropSide; } | { at: "groupStart" | "groupEnd"; r: number; } | { at: "sheetEnd"; } | { at: "keyOrder"; group: boolean; }; /** The seam a drop marks: a row of the row space, and the edge of it the insertion line runs along. */ export interface SheetDropMark { r: number; edge: "top" | "bottom"; } /** Why a drop is refused where it rests. */ export type SheetDropRefusal = /** The row it rests on, or the one it carries, has left the sheet. It says nothing. */ { why: "gone"; } | { why: "readOnly" | "insertGroup" | "ontoBand" | "noGroupMove" | "lineOut"; } | { why: "insert" | "ontoRow" | "noMove"; line: boolean; } | { why: "keyOrder"; group: boolean; } | { why: "column"; header: string; } /** A line moves only within its group: the group's band. */ | { why: "within"; r: number; }; /** What a drop does where it rests. */ export type SheetDropPlan = /** A template inserted where the seam's own chips would insert it, seeded by the template (SB39, SB40). */ { kind: "insert"; template: SheetDropTemplate; request: InsertRequest; place: SheetDropPlace; mark: SheetDropMark | undefined; } /** A card's cells set on a row or a band (SB61). */ | { kind: "set"; card: SheetDropCard; r: number; } /** An entry — a flat or loose row, or a group with its lines — placed beside another, or at the end (SB44). */ | { kind: "moveEntry"; id: string; to: { side: SheetDropSide; anchor: string; } | "end"; place: SheetDropPlace; mark: SheetDropMark; } /** A line moved within its group or into another (SB44): from its group and key, into a group at a slot of its lines as they stand. */ | { kind: "moveLine"; from: { group: string; key: string; }; to: { group: string; index: number; }; place: SheetDropPlace; mark: SheetDropMark; } /** The row is where the drop would put it: nothing moves. */ | { kind: "stay"; place: SheetDropPlace; mark: SheetDropMark; } | { kind: "refused"; why: SheetDropRefusal; }; /** A row of the row space, and what stands there. */ interface At { r: number; item: SheetBodyItem; } /** * Where a drop's row stands now. * * @param row - The row * @param ctx - The sheet as it stands * @returns Its row-space index and its item, or `undefined` once it has left the sheet */ export declare function locateDrop(row: SheetDropRow, ctx: SheetDropContext): At | undefined; /** * The row a row-space item is, as a drop names it. * * @param item - The item * @returns Its drop row; `undefined` for what no drop rests on (a band of * unloaded rows, a sub row, a proposal) */ export declare function dropRowOf(item: SheetBodyItem): SheetDropRow | undefined; /** * What a drop does where it rests — see the module docs. * * @param source - What is dragged * @param row - The row it rests on * @param slot - The seam the pointer's half picks (`before` / `after`), or `""`, the row itself * @param ctx - The sheet as it stands * @returns What the drop does, or why it is refused */ export declare function planDrop(source: SheetDropSource, row: SheetDropRow, slot: string, ctx: SheetDropContext): SheetDropPlan; /** * What a card's ⏎ does (SB45): what a drop below the ring's row would — a * row template after it, a group template after its group, and a card on * the row itself. * * @param source - The card: a template, or an author's card * @param row - The ring's row * @param ctx - The sheet as it stands * @returns What the ⏎ does, or why it is refused there */ export declare function planBelow(source: SheetDropSource, row: SheetDropRow, ctx: SheetDropContext): SheetDropPlan; /** * A row of the row space, in words — `row 3`, `line 2 of WO-2201 · Kitchen, * oak`, `order 1` — as the inspector names it. * * @param r - The row's index * @param ctx - The sheet as it stands * @param words - The sheet's words * @param noun - The word for a group * @returns The words; `""` for no row */ export declare function dropWhat(r: number, ctx: SheetDropContext, words: SheetWords, noun: SheetNounValue): string; /** * Why a plan is refused, as the words take it — what a card's ⏎ leaves in the * footer where it can't land (SB45). * * @param plan - The plan * @param ctx - The sheet as it stands * @param words - The sheet's words * @param noun - The word for a group * @returns The refusal's words; `undefined` for a plan that lands, or one refused without words */ export declare function dropRefusal(plan: SheetDropPlan, ctx: SheetDropContext, words: SheetWords, noun: SheetNounValue): SheetDropRefusalWord | undefined; /** * What the ghost says of a plan (SB38, SB61): the place a drop lands — * `after row 3`, `at the start of order 2`, `→ row 3` for a card — or, red, * why it can't. * * @param plan - The plan * @param ctx - The sheet as it stands * @param words - The sheet's words * @param noun - The word for a group * @returns The caption; `undefined` when it says nothing */ export declare function dropCaption(plan: SheetDropPlan, ctx: SheetDropContext, words: SheetWords, noun: SheetNounValue): string | undefined; /** * Where a plan lands, as a screen reader hears the drag layer say it — `the * gap after row 3`, `row 3` for a card — or, refused, the row it rests on. * * @param plan - The plan * @param at - The row it rests on * @param ctx - The sheet as it stands * @param words - The sheet's words * @param noun - The word for a group * @returns The name */ export declare function dropName(plan: SheetDropPlan, at: number | undefined, ctx: SheetDropContext, words: SheetWords, noun: SheetNounValue): string; /** * What every row hands the drag layer, as a drop target and as a grip * (#1187): one object every row shares, held still while the sheet takes * drops, its functions reading the sheet as it stands. */ export interface SheetRowDrop { /** The surface the rows register on. */ surface: string; /** The veto: whether the drop a candidate event makes lands. */ canDrop: DropVeto; /** The slot a drag picks over a row, from its box and the pointer's height. */ slotAt: (payload: DragPayload, rect: { top: number; height: number; }, clientY: number) => string; /** What the ghost says over a row, and its name for the announcements. */ options: Required>; /** Told each time a drag rests over a row that takes it: the row's element, where it rests, and what is dragged — the seam line, or the row itself, lights. */ hover: (el: HTMLElement, coord: CellCoord, payload: DragPayload) => void; } export {}; //# sourceMappingURL=drop.d.ts.map