/** * Copyright (c) 2025 Elara AI Pty Ltd * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details. */ /** * The Roster's commands (#1369, `Builder Interfaces Spec.md` §5.5, §7): one * command path for the grid, the library, the inspector and the narrow cards. * Each reads the week as drafted, works out the rows it changes — a duty * through the duty kind's `write`, and `create` for a new one, its times by * §5.5; a period's own row — the week's, or by the day the day's (#1550) — * through the periods' `dismiss` and `publish`; a target through `write`, and * `create` for a new one — and records them across the records' sessions as * one step. A gesture on a day whose period takes no edits — a published week, * or by the day a published day — is refused, the week's other days taking * theirs. A new duty's or target's key is its record's session's to make * (#1583, east-ui-components' `keys.ts`, through `ScheduleEditing.mint`): made * up at random, past every key its drafts and its record are known to hold — * a key a record read a window at a time holds unread is its Save's own * conflict, never an overwrite. A duty's own form or a library card that * changes its shift or its team carries what it leaves as it was, as a move * does: its times move with the shift, so it stays on its day, and its * activity clears across teams. A find edits nothing: it asks the app's fit * (#1334). Publish runs Save, then writes the status of each period it * publishes once every record reads back as saved (`publishPeriod`). A pattern * dropped on a person's week (#1406, D4) replaces its seven days as one step, * `Apply pattern`: a day the pattern leaves as it is keeps its duty, a day it * changes runs the pattern's shift in the person's home group at the shift's * own times, an off day removes the person's duties that day, and a day whose * period takes no edits keeps its duties as they are. * * @packageDocumentation */ import { type option } from "@elaraai/east"; import type { Origin } from "@elaraai/east-ui-components"; import type { ScheduleChange } from "../shared/schedule/editing.js"; import { type RosterEditing } from "./editing.js"; import type { RosterFind } from "./fit.js"; import { type Assignment, type Context, type Issue, type Pattern, type Person, type Place, type PlacedDuties, type PlacedTargets, type Requirement, type Roles, type RosterPayload, type RosterValue, type Selection, type Slot, type Week, type WeekPeriod, type WeekState } from "./model.js"; /** Where a place command gets its person or request. */ export type RosterSource = { type: "person" | "agency" | "assignment" | "proposal"; key: string; }; /** What a form changes of a duty's roles: its times, its position, its activity. */ export type RolesChange = Partial>; /** One field a library card's drop sets, as the kind writes it. */ export interface FieldWrite { readonly path: readonly string[]; readonly value: Uint8Array; } /** What the commands read: the week as drafted and as stored, its rows, and the editing they record through. */ export interface RosterState { readonly value: RosterValue; /** The week's first day. */ readonly start: Date; /** The configuration: every person and activity. */ readonly context: Context; /** The week as drafted, and as the records hold it. */ readonly week: Week; readonly held: Week; /** Its duties as drafted, and as stored: each placed duty's row. */ readonly duties: PlacedDuties; readonly heldDuties: PlacedDuties; /** The week before's duties, while the week holds none: what Copy previous week copies. */ readonly previous: PlacedDuties | undefined; /** Its targets as drafted: each slot's row. */ readonly targets: PlacedTargets; /** Its periods (#1550): its own, or its seven days', each its row as drafted and as stored. */ readonly periods: readonly WeekPeriod[]; /** * What Publish publishes now (#1550): the week's own period, or by the day the day in view's in the Shifts layout's * Day, else every day of the week — each one that takes edits. */ readonly publishes: readonly WeekPeriod[]; /** Every week of the span in view, drafts in place (#1406): what a pattern dropped on one of them applies to; the week above among them. */ readonly weeks?: readonly WeekState[] | undefined; /** The editing; `undefined` for a read-only Roster. */ readonly editing: RosterEditing | undefined; /** Whether the week's reads have landed and the rail is not mid-read: a gesture waits for them. */ readonly ready: boolean; /** * Whether what main shows is retained while a narrowing of it is read (#1398, CL8): readable, focusable and * selectable, its controls in place, and every gesture refused until it lands. */ readonly retained?: boolean | undefined; } /** All mutation paths use these guarded commands, each one step of the history. */ export interface RosterCommands { /** Whether the week takes a gesture now: a period of it editable, its reads landed, its records' sessions writable. */ readonly available: boolean; /** * Whether a day of the week takes a gesture now (#1550): the week does, and the day's period — the week's, or the * day's own where the Roster publishes by the day — is editable. Each day's controls ask it. */ readonly availableOn: (day: bigint) => boolean; /** Whether Publish can publish now: the week takes a gesture, and a period it publishes takes edits (#1550). */ readonly publishable: boolean; /** Whether a week of the span takes a gesture (#1406): the month's cells each ask of their own week. */ readonly availableIn: (held: WeekState) => boolean; /** Whether any week in view takes a gesture: the week, or one of the month's — what registers drag sources and targets (P32). */ readonly editable: boolean; /** * Why every gesture is refused while a run of the optimiser holds the week (#1409, R2) — `Elara is optimising W11` * — and `undefined` while none does: the week's controls stay in place, inert, never swapped for a read-only * week's `Off`. */ readonly locked: string | undefined; /** * Places a person, a request, a duty or a proposal at a place: a group's shift on a day, or the shift in no group, * where the duty kind's group takes none (#1548). */ place(source: RosterSource, place: Place, checkOnly?: boolean): string | undefined; update(id: string, change: RolesChange, origin?: Origin, checkOnly?: boolean): string | undefined; activity(id: string, activity: option, checkOnly?: boolean): string | undefined; sets(id: string, writes: readonly FieldWrite[], checkOnly?: boolean): string | undefined; field(id: string, path: readonly string[], next: unknown): string | undefined; row(id: string, bytes: Uint8Array): string | undefined; remove(id: string): void; restore(id: string): void; requirement(slot: Slot, target: Requirement): string | undefined; targetRow(slot: Slot, bytes: Uint8Array): string | undefined; accept(key: string): string | undefined; reject(key: string): void; fix(issue: Issue): string | undefined; copy(): void; publish(): void; /** * A pattern over a person's week (#1406, D4): what applying it changes — each day kept, set to a shift or taken off, * and the person's week as it leaves it — or why it cannot be applied, in the caption's words (P19). */ pattern(person: string, start: Date, key: string): PatternPlan | string; /** Applies a pattern to a person's week as one step of the history, `Apply pattern` (P17); one that changes nothing applies nothing (P18). */ applyPattern(person: string, start: Date, key: string, checkOnly?: boolean): string | undefined; } /** One day of a pattern applied to a person's week: left as it is, set to a shift, or taken off. */ export interface PatternDay { /** The day of the week, from zero. */ readonly day: number; /** The shift the day runs after the pattern; `undefined` for a day off. */ readonly shift: string | undefined; /** Whether the pattern leaves the day as it is, sets its shift, or takes it off. */ readonly kind: "keep" | "set" | "off"; } /** A pattern applied to a person's week, planned (#1406): what the drop records, and what the preview draws and checks. */ export interface PatternPlan { readonly pattern: Pattern; readonly person: Person; /** The week's first day. */ readonly start: Date; /** Each of the seven days. */ readonly days: readonly PatternDay[]; /** The changes, as one step; none where the week already matches. */ readonly changes: readonly ScheduleChange[]; /** The person's week as the pattern leaves it, each duty by key — kept, moved, or new under a minted key: what a preview's check runs over. */ readonly candidates: ReadonlyMap; /** The duties the pattern removes, by key. */ readonly removed: readonly string[]; } /** * The Roster's commands over the week (see the module docs). * * @param state - The week, its rows and the editing * @param select - Selects what a command made, keeping the panes as they are * @param find - Asks the app's fit who fits a find's need * @param publish - Publishes what the state says Publish publishes: Save, then each period's status * @returns The commands */ export declare function rosterCommands(state: RosterState, select: (selection: Selection | undefined) => void, find: (asked: RosterFind) => void, publish: () => void): RosterCommands; /** * The rows Publish writes (#1550): each period given that takes edits — the * week's, or by the day each day's — its status the published case, at the * time given, over its row as the Save left it (`periodPublishChange`). A * period with no row is given one made from the periods' `values` only then, * and one they fail to make records none of the changes, so Publish never * publishes a part of what it was pressed for. * * @param value - The payload: its periods * @param periods - The periods Publish publishes * @param at - When they are published * @returns The changes, one a period; none without periods */ export declare function publishChanges(value: RosterPayload, periods: readonly WeekPeriod[], at: Date): readonly ScheduleChange[]; //# sourceMappingURL=actions.d.ts.map