/** * Copyright (c) 2025 Elara AI Pty Ltd * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details. */ import { type option } from "@elaraai/east"; import { type CellCoord, type DragEventValue, type DragPayload, type DropCellOptions, type DropVeto } from "@elaraai/east-ui-components"; import { type AllocationCommands } from "./actions.js"; import type { AllocationFit } from "./fit.js"; import { type Context, type Day, type FitAsk, type FitResult, type Slot } from "./model.js"; import { type Nouns } from "./nouns.js"; /** What a drag of something on the board carries: a bin's body (A24), its connector, or one of its links. */ export type BoardGrip = { kind: "body"; bin: string; } | { kind: "port"; bin: string; } | { kind: "link"; bin: string; resource: string; }; /** What a Library card carries (#1330): an arrival to book, a committed bin the drafts removed, or a resource. */ export type LibraryGrip = { kind: "arrival"; arrival: string; } | { kind: "removed"; bin: string; } | { kind: "resource"; resource: string; }; /** What a drag carries. */ export type Grip = BoardGrip | LibraryGrip; /** * Where a drag rests (A26): a lane hour (a card in it names the card; a Table * row's arrival cell is its slot's, `table`), a resource — its row, the fits * marker over the rows (its #1's), or a fit in the inspector's drop list, each * dropping as the resource's row does, at `rowCoord` — or a Table row's * resource cell. */ export type Target = { kind: "lane"; lane: string; at: Date; card: string | undefined; table?: boolean; } | { kind: "resource"; resource: string; } | { kind: "cell"; row: string; }; /** A target's identity, as a cache and the drag's rest key it. */ export declare function targetKey(target: Target): string; /** Where a drag rests, as the board's drop targets report it: the target, and whether it takes the drop there. */ export interface DragRest { target: Target; allowed: boolean; } /** * Where a drag rests, held outside React's state (A35): the drop targets set * it as the drag rests on them and clear it as it leaves them, and the parts * that mark or draw it — a row's bins and its run's label (A29), the links * (A65) — subscribe; nothing else renders as the pointer moves. */ export declare class DragRestStore { private value; private readonly listeners; readonly subscribe: (listener: () => void) => (() => void); readonly get: () => DragRest | undefined; /** The drag rests on a target, which takes the drop there or refuses it. */ rest(target: Target, allowed: boolean): void; /** The drag left a target: it rests on nothing, unless another has taken it already. */ leave(target: Target): void; /** The drag ended. */ clear(): void; private set; } /** A grip on the board as the drag grammar's coordinate. */ export declare function gripCoord(surface: string, grip: BoardGrip): Required; /** A lane hour's coordinate, or a card's in it; a Table row's arrival cell names its slot's (`table`). */ export declare function laneCoord(surface: string, lane: string, at: Date, card?: string, table?: boolean): CellCoord; /** A Table row's resource cell's coordinate. */ export declare function resourceCellCoord(surface: string, row: string): CellCoord; /** A resource row's coordinate. */ export declare function rowCoord(surface: string, resource: string): CellCoord; /** The Library's two lists, by the board's surface: the drag grammar's sources (#1330). */ export interface AllocationLibraries { arrivals: string; resources: string; } /** * The Library's ids for a board. * * @param surface - The board's drag surface * @returns Its Arrivals and its Resources lists' ids */ export declare function libraryIds(surface: string): AllocationLibraries; /** An Arrivals card's key: an arrival's, or a removed bin's. */ export declare function arrivalCardKey(grip: Extract): string; /** * The grip a Library card's reference names. * * @param libraries - The board's Library ids * @param ref - The card's library and key * @returns Its grip, or `undefined` for a card of no list of the board's */ export declare function libraryGripOf(libraries: AllocationLibraries, ref: { library: string; key: string; }): LibraryGrip | undefined; /** The grip a drag grammar's reference on the board names. */ export declare function gripOf(ref: { row: string; slot: string; event: option; }): BoardGrip | undefined; /** The target a drag grammar's reference names. */ export declare function targetOf(ref: { row: string; slot: string; event: option; }): Target | undefined; /** A grip's identity, as a cache keys it. */ export declare function gripKey(grip: Grip): string; /** A refusal, as the inspector's note says it (A40, A88): `Not allocated · LD-2232 can't go into K-103: gap too short · next job Tue 18.` */ export interface Refusal { word: string; text: string; } /** A drop's verdict, where the drag rests. */ export interface Verdict { /** Whether the drop is taken: a pending answer is (the drop waits for it). */ allowed: boolean; /** The ghost's caption (A33), and whether it warns. */ caption: string; warn: boolean; /** Why it is refused. */ refusal: Refusal | undefined; /** The fit's words for it, when the fit gave a verdict: its reason for a fit (`0 d spare to Wed 19 · …`), or for a refusal. */ reason?: string | undefined; /** The fit's answer is still on its way. */ pending: boolean; /** The drop's command. */ run: (() => boolean) | undefined; } /** A question the board asks the fit, of the drafts or of a day derived from them, and the quantity it places. */ export interface Asked { ask: FitAsk; of: Day | undefined; quantity: number; } /** The question a grip on the board asks of the fit (A23, A73): a link's part, a connector's remainder, a body's whole bin. */ export declare function placeAsk(plan: Day, grip: BoardGrip): { ask: FitAsk; quantity: number; } | undefined; /** The resource a grip's link leaves: a link's own, or a connector's largest part (A28: its current resource is never ranked). */ export declare function currentOf(plan: Day, grip: Grip): string | undefined; /** * The link a grip's drag moves (A69): a link's own; a connector's when it * carries its bin's largest part, its bin having nothing left to link (A21); a * body's or a Library card's, none. * * @param plan - The day as drafted * @param grip - What is dragged * @returns The bin's part it moves, or `undefined` for a drag that moves no link */ export declare function movedLinkOf(plan: Day, grip: Grip): { bin: string; resource: string; } | undefined; /** The three best fits of an answer, best first, the current resource excepted (A28). */ export declare function rankOf(answer: FitResult | undefined, current: string | undefined): string[]; /** What the board knows where a drag rests. */ export interface DropScene { /** The plan day. */ day: Date; plan: Day; /** The day as the record holds it: the bins a Removed from plan card books again. */ held: Day | undefined; context: Context; slots: readonly Slot[]; fit: AllocationFit; commands: AllocationCommands; /** The day without a reservation: what a fill asks the fit of, as the mock asks it. */ without: (reservation: string) => Day; /** The day with a committed bin the drafts removed back on it, unlinked — and without a reservation it fills: what booking it again asks the fit of. */ restoring: (bin: string, reservation?: string) => Day | undefined; /** The day's first free slot, by time then lane, of the lanes that show (A36). */ firstFree: () => { lane: string; at: Date; } | undefined; /** A booking with no free slot left (A36): the banner's words. */ notice: (refusal: Refusal) => void; /** A lane's label. */ laneLabel: (lane: string) => string; /** The board's nouns, as its captions and refusals write them. */ nouns: Nouns; } /** A grip's question of the fit, of the drafts or of a day the board derives from them (`of`, a fill's or a restore's). */ export declare function askOf(scene: Pick, grip: Grip, of?: Day): Asked | undefined; /** Where a bin lands in a lane slot (A37): the slot's time, or a minute after the last bin already in it. */ export declare function landing(slots: readonly Slot[], plan: Day, lane: string, at: Date, bin: string | undefined): Date; /** * Books a Library arrival, or a committed bin the drafts removed, onto a * resource at the day's first free slot of the lanes that show (A36): what a * drop on the resource runs, and a narrow card's `Book an arrival…` (A78). * With no slot left, nothing is booked and the banner says so. * * @param scene - What the board knows * @param grip - The arrival, or the removed bin * @param resource - The resource * @returns Whether it was booked */ export declare function bookOnto(scene: Pick, grip: Extract, resource: string): boolean; /** * A drop's verdict (see the module docs, §10). * * @param scene - What the board knows * @param grip - What is dragged * @param target - Where it rests * @param ranks - The three best fits, best first * @param asking - Whether an unanswered question is asked: never while the board renders * @returns The verdict */ export declare function verdictOf(scene: DropScene, grip: Grip, target: Target, ranks: readonly string[], asking?: boolean): Verdict; /** The target a cell's coordinate names. */ export declare function targetOfCoord(coord: CellCoord): Target | undefined; /** The board's drags, as its parts read them. */ export interface AllocationDrag { /** The board's one drag surface. */ surface: string; /** The Library's lists: the sources of its drags. */ libraries: AllocationLibraries; /** Whether the day takes drags: an editable day, and not the narrow layout. */ enabled: boolean; /** What is being dragged, while a drag is under way. */ grip: Grip | undefined; /** What the board shows the fit's verdicts for: the drag's grip, or, with none under way, the pick (A11). */ subject: Grip | undefined; /** The subject's question of the fit: what the previews place, of which day (A28). */ asked: Asked | undefined; /** The grip under a pointer-down: the fit is asked about it before the drag needs it (A23). */ arm: (grip: Grip) => void; /** The fit's answer about the subject (A27–A29, A32). */ answer: FitResult | undefined; /** Its three best fits, best first (A28). */ ranks: readonly string[]; /** A drop's verdict where a drag rests, kept for this drag, these drafts and this answer (A35); it asks the fit what it has not answered. */ verdict: (grip: Grip, target: Target) => Verdict; /** The same verdict, asking nothing: what the board draws while it renders. */ peek: (grip: Grip, target: Target) => Verdict; /** The grip a dragged payload carries, if it is the board's or a card of its Library's. */ gripOfPayload: (payload: DragPayload) => Grip | undefined; /** The grip and the target a completed drag names. */ gripOfEvent: (event: DragEventValue) => Grip | undefined; /** Where the drag rests, as its targets report it (`dropTarget`): what the board's marks and its links read. */ rest: DragRestStore; /** A target's name, for what the drag layer says to a screen reader: as the board shows it, never its keys. */ name: (target: Target) => string; } /** * A drop target of the board's (A26) — a lane hour, a card, a resource row, * the fits marker, a Table cell, a fit in the inspector's drop list — as the * shared drag layer takes it: its veto and the ghost's caption, both the * board's one verdict for the target (§10), and where the drag rests told to * the board as it rests and as it leaves (`rest`). A fit in the drop list is * `{ kind: "resource", resource }` at `rowCoord(drag.surface, resource)`, as * its row is. * * @param drag - The board's drags * @param target - What the target is * @returns The veto and the options a `useDropCell` takes */ export declare function dropTarget(drag: AllocationDrag, target: Target): { veto: DropVeto; options: DropCellOptions; }; /** * The board's drags (see the module docs): its one drag target, what is * dragged, and each drop's verdict. * * @param surface - The board's drag surface * @param enabled - Whether the day takes drags * @param scene - What the board knows * @param onRefuse - A refused drop's reason (A40), or `undefined` once a drop is taken * @param pick - The picked Library card, if any (A11): its fits show as a drag's do * @returns The drags */ export declare function useAllocationDrag(surface: string, enabled: boolean, scene: DropScene, onRefuse: (refusal: Refusal | undefined) => void, pick?: Grip): AllocationDrag; //# sourceMappingURL=drag.d.ts.map