import type { PartialEditorLanguage } from './alt-editor-lite-language.js'; import type { EditingOptions } from './editing-options.js'; import type { EditorCloseReason } from './editor-event.js'; import type { EditorOperationTarget } from './editor-operation.js'; import type { BatchChanges, DeepPartial, EditorValues } from './editor-values.js'; import type { FieldConfig } from '../fields/field-config.js'; import type { MaybePromise } from '../fields/field-value.js'; import type { FormDependencies } from '../form/form-dependency.js'; import type { FormValidator } from '../form/form-validation.js'; interface OperationContextBase { /** Signal aborted when the operation is closed, replaced, or destroyed. */ readonly signal: AbortSignal; } /** Context supplied to a Create persistence operation. */ export interface CreateOperationContext extends OperationContextBase { readonly operation: 'create'; readonly mode: 'dialog'; } /** Context supplied to a single-record Edit persistence operation. */ export interface EditOperationContext extends OperationContextBase { readonly operation: 'edit'; readonly mode: 'dialog' | 'inline'; readonly target: Readonly; } /** Context supplied to a multi-record Edit persistence operation. */ export interface BatchEditOperationContext extends OperationContextBase { readonly operation: 'batchEdit'; readonly mode: 'dialog'; readonly targets: readonly Readonly[]; } /** Context supplied to a Remove persistence operation. */ export interface RemoveOperationContext extends OperationContextBase { readonly operation: 'remove'; readonly mode: 'dialog'; } /** Context supplied to a Refresh persistence operation. */ export type RefreshOperationContext = (OperationContextBase & { readonly operation: 'refresh'; readonly mode: 'api'; }) | (OperationContextBase & { readonly operation: 'refresh'; readonly mode: 'inline'; readonly target: Readonly; }); /** Context supplied to a persistence operation. */ export type OperationContext = CreateOperationContext | EditOperationContext | BatchEditOperationContext | RemoveOperationContext | RefreshOperationContext; type BeforeOpenContextBase = OperationContextBase & { readonly mode: 'dialog' | 'inline'; }; /** Context supplied before a dialog or inline presentation opens. */ export type BeforeOpenContext = (BeforeOpenContextBase & { readonly operation: 'create'; readonly mode: 'dialog'; }) | (BeforeOpenContextBase & { readonly operation: 'edit'; readonly row: Readonly; readonly target: Readonly; }) | (BeforeOpenContextBase & { readonly operation: 'batchEdit'; readonly mode: 'dialog'; readonly originals: readonly Readonly[]; readonly targets: readonly Readonly[]; }) | (BeforeOpenContextBase & { readonly operation: 'remove'; readonly mode: 'dialog'; readonly rows: readonly Readonly[]; readonly targets: readonly Readonly[]; }); /** Context supplied after validation and before submission is observed. */ export type BeforeSubmitContext = CreateOperationContext | (EditOperationContext & { readonly original: Readonly; }) | (BatchEditOperationContext & { readonly originals: readonly Readonly[]; }); /** Consumer-controlled reasons that can be intercepted before a dialog closes. */ export type BeforeCloseReason = Extract; /** Context supplied before a consumer-controlled dialog close. */ export interface BeforeCloseContext { readonly operation: 'create' | 'edit' | 'batchEdit' | 'remove'; readonly mode: 'dialog'; readonly reason: BeforeCloseReason; readonly dirty: boolean; readonly signal: AbortSignal; } /** Context supplied after a successful canonical row commit. */ export type AfterSuccessContext = { readonly operation: 'create'; readonly mode: 'dialog'; readonly row: Readonly; readonly values: Readonly>; } | { readonly operation: 'edit'; readonly mode: 'dialog' | 'inline'; readonly target: Readonly; readonly original: Readonly; readonly row: Readonly; readonly values: Readonly>; } | { readonly operation: 'batchEdit'; readonly mode: 'dialog'; readonly targets: readonly Readonly[]; readonly changes: Readonly>; readonly originals: readonly Readonly[]; readonly rows: readonly Readonly[]; } | { readonly operation: 'remove'; readonly mode: 'dialog'; readonly rows: readonly Readonly[]; } | { readonly operation: 'refresh'; readonly mode: 'api' | 'inline'; readonly target?: Readonly; }; /** Context supplied to the non-recursive error callback. */ interface EditorErrorHookContextBase { readonly phase: 'open' | 'validation' | 'submit' | 'persistence' | 'commit' | 'afterSuccess' | 'close'; /** Whether configured persistence completed or Host application began. */ readonly committed: boolean; } /** Context supplied to the non-recursive error callback. */ export type EditorErrorHookContext = EditorErrorHookContextBase & ({ readonly operation: 'create'; readonly mode: 'dialog'; } | { readonly operation: 'edit'; readonly mode: 'dialog' | 'inline'; readonly target: Readonly; } | { readonly operation: 'batchEdit'; readonly mode: 'dialog'; readonly targets: readonly Readonly[]; } | { readonly operation: 'remove'; readonly mode: 'dialog'; } | { readonly operation: 'refresh'; readonly mode: 'api'; } | { readonly operation: 'refresh'; readonly mode: 'inline'; readonly target: Readonly; }); /** Optional lifecycle callbacks that cannot replace submitted values. */ export interface EditorHooks { readonly beforeOpen?: (context: BeforeOpenContext) => MaybePromise; readonly beforeSubmit?: (values: Readonly | BatchChanges>, context: BeforeSubmitContext) => MaybePromise; readonly beforeClose?: (context: Readonly) => MaybePromise; readonly afterSuccess?: (context: AfterSuccessContext) => MaybePromise; readonly onError?: (error: import('./alt-editor-lite-error.js').AltEditorLiteError, context: EditorErrorHookContext) => void; } /** * Optional synchronous or asynchronous editor operations. */ export interface EditorOperations { /** * Persists collected Create values and returns one complete row. * * The Host is updated only after this callback resolves successfully. */ create?(values: Readonly>, context: CreateOperationContext): TRow | Promise; /** * Persists collected Edit values and returns one complete replacement row. * * @param values - Enabled values collected from the Edit form. * @param original - Detached snapshot whose plain records and arrays are recursively frozen. * @param context - Owned operation context. */ update?(values: Readonly>, original: Readonly, context: EditOperationContext): TRow | Promise; /** * Persists one common change set and returns position-matched canonical rows. */ updateMany?(changes: Readonly>, originals: readonly Readonly[], context: BatchEditOperationContext): readonly TRow[] | Promise; /** * Persists removal of every row captured by the confirmation snapshot. * * Host records are removed only after this callback resolves successfully. */ remove?(rows: readonly Readonly[], context: RemoveOperationContext): void | Promise; /** * Refreshes data through a consumer-owned, optionally cancellable operation. * * When configured, this callback replaces the default `ajax.reload` or local * presentation behavior and owns any resulting Host update. */ refresh?(context: RefreshOperationContext): void | Promise; } /** * Synchronous client-side row construction and update mappings. */ export interface ClientSideOperations { /** * Builds one complete record from collected form values. * * Returning a promise is intentionally unsupported. */ createRow?(values: Readonly>): TRow; /** * Builds one complete replacement row without mutating the original snapshot. * * Returning a promise is intentionally unsupported. */ updateRow?(original: Readonly, values: Readonly>): TRow; } /** * Configuration for an AltEditorLite instance. */ export interface AltEditorLiteOptions> { /** Ordered field definitions used by Create and Edit forms. */ readonly fields: readonly FieldConfig[]; /** Declarative field state derived from dialog form values. */ readonly dependencies?: FormDependencies; /** Optional cross-field validator shared by dialog and inline editing. */ readonly validateForm?: FormValidator; /** Composable Dialog Edit and Inline Edit behavior. */ readonly editing?: EditingOptions; /** * Asynchronous editor operations. * * A capability cannot also define the matching `clientSide` mapper. */ readonly operations?: EditorOperations; /** * Synchronous client-side row mappings. * * Create requires `createRow`; Edit otherwise falls back to a safe merge of * declared field paths. */ readonly clientSide?: ClientSideOperations; /** Language data or nested overrides merged with the English fallback. */ readonly language?: PartialEditorLanguage; /** Optional lifecycle callbacks. */ readonly hooks?: EditorHooks; } export {};