import type { HotInstance } from '../../../core/types'; import type { RowUpdatePayload, RowsCreatePayload } from '../dataProvider'; /** * Row id option — a property name string, a resolver function, or absent. */ type RowIdOption = string | ((rowData: object | unknown[]) => unknown) | undefined | null; /** * A single afterChange tuple: `[visualRow, prop, oldValue, newValue]`. */ type ChangeTuple = [number, string | number, unknown, unknown]; /** * Internal per-row update payload used inside CRUD helpers (fields are optional during construction). */ type InternalRowUpdatePayload = Partial; /** * Runs `beforeRowsMutation`. Return `false` from a listener to cancel. * * @param {Core} hot Handsontable instance. * @param {string} operation Mutation kind (`create`, `update`, or `remove`). * @param {object} payload Hook payload (`RowMutationPayload` in `types/plugins/dataProvider/dataProvider.d.ts`). * @returns {boolean|undefined} `false` when cancelled. */ export declare function runBeforeRowsMutation(hot: HotInstance, operation: string, payload: object): false | undefined; /** * Runs `afterRowsMutation`. * * @param {Core} hot Handsontable instance. * @param {string} operation Mutation kind (`create`, `update`, or `remove`). * @param {object} payload Hook payload (`RowMutationPayload` in `types/plugins/dataProvider/dataProvider.d.ts`). * @returns {void} */ export declare function runAfterRowsMutation(hot: HotInstance, operation: string, payload: object): void; /** * Runs `afterRowsMutationError`. * * @param {Core} hot Handsontable instance. * @param {string} operation Mutation kind (`create`, `update`, or `remove`). * @param {Error} err Failure from the server callback. * @param {object} payload Hook payload (`RowMutationPayload` in `types/plugins/dataProvider/dataProvider.d.ts`). * @returns {void} */ export declare function runAfterRowsMutationError(hot: HotInstance, operation: string, err: unknown, payload: object): void; /** * Appends a mutation onto the queue so concurrent CRUD runs sequentially. * * @param {{ tail: Promise }} state Mutable queue tail (mutated). * @param {function(): Promise|void} fn Async work for one mutation. * @returns {Promise} */ export declare function enqueueMutation(state: { tail: Promise; }, fn: () => Promise | void): Promise; /** * Resolves stable row id from a row object using `rowId` option. * * @param {object|Array} rowData Source row. * @param {string|Function|undefined|null} rowIdOption `rowId` from config. * @returns {*|undefined} */ export declare function getRowIdFromRowData(rowData: object | unknown[], rowIdOption: RowIdOption): unknown; /** * Row id for a visual row index. * * @param {Core} hot Handsontable instance. * @param {string|Function|undefined|null} rowIdOption `rowId` from config. * @param {number} visualRow Visual row index. * @returns {*|undefined} */ export declare function getRowIdByVisualRow(hot: HotInstance, rowIdOption: RowIdOption, visualRow: number): unknown; /** * True when a value cannot be used as a server row id (`null` and `undefined` only). * * @param {*} id Resolved row id. * @returns {boolean} */ export declare function isMissingRowId(id: unknown): boolean; /** * Finds a visual row index for a row id. * * @param {Core} hot Handsontable instance. * @param {string|Function|undefined|null} rowIdOption `rowId` from config. * @param {*} rowId Row id. * @returns {number} Visual row index or -1 when not found. */ export declare function findVisualRowById(hot: HotInstance, rowIdOption: RowIdOption, rowId: unknown): number; /** * Collects row ids (or row snapshots) for `remove_row` alter ranges, including grouped indices. * * @param {Core} hot Handsontable instance. * @param {string|Function|undefined|null} rowIdOption `rowId` from config. * @param {number|Array|undefined|null} index Visual start index or `[[index, amount], ...]`. * @param {number} amount Row count when `index` is scalar. * @returns {Array<*>} * @throws {Error} When `rowId` resolves to null or undefined for a row in range. */ export declare function rowIdsFromAlterRemove(hot: HotInstance, rowIdOption: RowIdOption, index: number | [number, number][] | undefined | null, amount: number): unknown[]; /** * Builds `changes` map and merged `rowData` for one visual row from Handsontable change tuples. * * @param {Core} hot Handsontable instance. * @param {Array} rowChanges Tuples `[visualRow, prop, oldVal, newVal]` for one row. * @returns {{ changesObj: object, rowData: object|Array }} */ export declare function buildChangesAndRowData(hot: HotInstance, rowChanges: ChangeTuple[]): { changesObj: Record; rowData: Record | unknown[]; }; /** * Reverts optimistic cell edits after a failed server update. * * @param {Core} hot Handsontable instance. * @param {Array} changeTuples `[visualRow, prop, oldVal, newVal][]`. * @returns {void} */ export declare function revertChangeTuples(hot: HotInstance, changeTuples: ChangeTuple[]): void; /** * Whether every changed cell passes validator when `allowInvalid` is false. * * @param {Core} hot Handsontable instance. * @param {number} visualRow Visual row index. * @param {object} changes Prop-keyed new values. * @returns {Promise} */ export declare function validateRowChanges(hot: HotInstance, visualRow: number, changes: Record): Promise; /** * True when `afterChange` should not enqueue a batched `onRowsUpdate`. * * @param {boolean} hasOnRowsUpdate Whether `onRowsUpdate` is configured. * @param {Array} changes Change list from `afterChange`. * @param {string} [source] Change source. * @returns {boolean} */ export declare function shouldIgnoreAfterChangeForServerUpdate(hasOnRowsUpdate: boolean, changes: ChangeTuple[] | unknown[] | null, source?: string): boolean; /** * Filters change tuples to those with real edits and passing cell `valid` meta. * * @param {Core} hot Handsontable instance. * @param {Array} changes `[visualRow, prop, oldVal, newVal][]`. * @returns {Array} Subset safe to send to the server update path. */ export declare function filterChangesForBatchedServerUpdate(hot: HotInstance, changes: ChangeTuple[] | unknown[] | null): ChangeTuple[]; /** * Builds `{ id, changes, rowData }` payloads for programmatic `updateRows`. * * @param {Core} hot Handsontable instance. * @param {string|Function|undefined|null} rowIdOption `rowId` from config. * @param {object[]} rows Caller payloads `{ id, changes, rowData? }`. * @returns {object[]} */ export declare function buildManualUpdateRowPayloads(hot: HotInstance, rowIdOption: RowIdOption, rows: InternalRowUpdatePayload[]): InternalRowUpdatePayload[]; /** * Calls `onRowsUpdate`, success/error hooks, then re-fetches or re-renders. * * @param {Core} hot Handsontable instance. * @param {{ getOnRowsUpdate: function(): *, fetchData: function(): Promise<*>, logError: function(...*): void, onRequestFailed?: function(string, Error): void }} callbacks Callbacks for IO and logging (`getOnRowsUpdate` returns `onRowsUpdate` or a falsy value). `onRequestFailed` receives `'update'` only; when `fetchData` rejects after a successful update, the caller's `fetchData` implementation is responsible for error UI (for example [[DataProvider#fetchData]] shows a notification and rethrows). * @param {object[]} rowPayloads Per-row `RowUpdatePayload` objects (`types/plugins/dataProvider/dataProvider.d.ts`). * @param {object} [options] Optional flags. * @param {function(): void} [options.revertOptimistic] Restores previous cell values when the request fails. * @returns {Promise} */ type CommitRowsUpdateCallbacks = { getOnRowsUpdate: () => ((payload: object[]) => Promise) | undefined; fetchData: () => Promise; logError: (...args: unknown[]) => void; onRequestFailed?: (kind: string, err: unknown) => void; }; /** * */ export declare function commitRowsUpdate(hot: HotInstance, callbacks: CommitRowsUpdateCallbacks, rowPayloads: object[], options?: { revertOptimistic?: () => void; }): Promise; /** * Runs `beforeRowsMutation`, validates each payload row, then calls `commitRowsUpdate` for programmatic `updateRows`. * * @param {Core} hot Handsontable instance. * @param {object} ctx Row resolution and commit. * @param {function(): string|Function|undefined|null} ctx.getRowIdOption Current `rowId` config. * @param {function(object[]): Promise} ctx.commitRowsUpdate Commits payloads after validation. * @param {object[]} rowPayloads Per-row `{ id, changes, rowData }` payloads from `buildManualUpdateRowPayloads`. * @returns {Promise} */ type ManualUpdateCtx = { getRowIdOption: () => RowIdOption; commitRowsUpdate: (payloads: InternalRowUpdatePayload[]) => Promise; }; /** * */ export declare function runManualUpdateRowsMutation(hot: HotInstance, ctx: ManualUpdateCtx, rowPayloads: InternalRowUpdatePayload[]): Promise; /** * Groups cell changes by row, validates, then commits a single batched `onRowsUpdate`. * * @param {Core} hot Handsontable instance. * @param {object} ctx Row resolution and commit. * @param {function(): string|Function|undefined|null} ctx.getRowIdOption Current `rowId` config. * @param {function(object[], object): Promise} ctx.commitRowsUpdate Commits payloads (e.g. server + refetch). * @param {Array} changes Filtered change tuples `[visualRow, prop, oldVal, newVal][]`. * @returns {Promise} */ type UpdateFromChangesCtx = { getRowIdOption: () => RowIdOption; commitRowsUpdate: (payloads: InternalRowUpdatePayload[], opts?: { revertOptimistic?: () => void; }) => Promise; }; /** * */ export declare function runUpdateFromChanges(hot: HotInstance, ctx: UpdateFromChangesCtx, changes: ChangeTuple[]): Promise; /** * Queues create/remove server calls with before/after mutation hooks. * * @param {object} ctx Queue and hooks. * @param {function(function(): Promise|void): Promise} ctx.enqueueMutation - Serializes mutations. * @param {function(string, object): boolean|undefined} ctx.runBeforeRowsMutation - Returns false when the hook cancels. * @param {function(string, object): void} ctx.runAfterRowsMutation - Runs the success hook. * @param {function(string, Error, object): void} ctx.runAfterRowsMutationError - Runs the error hook. * @param {function(...*): void} ctx.logError - Logs mutation failures. * @param {function(string, Error): void} [ctx.onRequestFailed] - `'create'|'remove'` when the server callback rejects. When `onSuccess` (refetch) fails, error UI is owned by that `fetchData` implementation (not `onRequestFailed`). * @param {string} operation `'create'` or `'remove'`. * @param {object} payload Hook payload. * @param {function(): Promise<*>} userPromiseFn Server callback invocation. * @param {function(): Promise|void} onSuccess Runs after success (e.g. `fetchData`). * @returns {Promise} */ type QueueCrudCtx = { enqueueMutation: (fn: () => Promise) => Promise; runBeforeRowsMutation: (op: string, p: object) => false | undefined; runAfterRowsMutation: (op: string, p: object) => void; runAfterRowsMutationError: (op: string, err: unknown, p: object) => void; logError: (...args: unknown[]) => void; onRequestFailed?: (op: string, err: unknown) => void; }; /** * */ export declare function queueCrud(ctx: QueueCrudCtx, operation: string, payload: object, userPromiseFn: () => Promise, onSuccess: () => Promise | void): Promise; type BeforeAlterForCrudCtx = { hot: HotInstance; getOnRowsCreate: () => ((payload: RowsCreatePayload) => Promise | void) | undefined; getOnRowsRemove: () => ((rowIds: unknown[]) => Promise | void) | undefined; getRowIdOption: () => RowIdOption; getRowId: (visualRow: number) => unknown; createRows: (payload: Partial) => Promise | void; removeRows: (rowIds: unknown[]) => Promise | void; }; /** * Handles `beforeAlter` for server-backed row insert/remove when DataProvider CRUD is configured. * * @param {object} ctx Context. * @param {Core} ctx.hot - Handsontable instance. * @param {function(): *} ctx.getOnRowsCreate - Returns configured `onRowsCreate` when present. * @param {function(): *} ctx.getOnRowsRemove - Returns configured `onRowsRemove` when present. * @param {function(): string|Function|undefined|null} ctx.getRowIdOption - Returns current `rowId` setting. * @param {function(number): *} ctx.getRowId - Row id for a visual index (public API). * @param {function(object): Promise|void} ctx.createRows - Invokes server create path. * @param {function(*|*[]): Promise|void} ctx.removeRows - Invokes server remove path. * @param {string} action Alter action name. * @param {number|Array|undefined|null} index Row index, grouped `[[index, amount], ...]`, or undefined (alter default). * @param {number} amount Row count when `index` is a number. * @returns {boolean|undefined} False when alter is handled here. */ export declare function handleBeforeAlterForCrud(ctx: BeforeAlterForCrudCtx, action: string, index: number | [number, number][] | undefined | null, amount: number): false | undefined; export {};