UNPKG

ag-grid-community

Version:

Advanced Data Grid / Data Table supporting Javascript / Typescript / React / Angular / Vue

216 lines (215 loc) 12.4 kB
import type { NamedBean } from '../context/bean'; import { BeanStub } from '../context/beanStub'; import type { AgColumn } from '../entities/agColumn'; import type { AgEventType } from '../eventTypes'; import type { CellFocusedEvent } from '../events'; import type { CellRange } from '../interfaces/IRangeService'; import type { EditingCellPosition, ICellEditorParams } from '../interfaces/iCellEditor'; import type { Column } from '../interfaces/iColumn'; import type { EditMap } from '../interfaces/iEditModelService'; import type { CellValueResolveFrom, EditNavOnValidationResult, EditPosition, EditSource, IsEditingParams, StartEditParams, StopEditParams, _SetEditingCellsParams } from '../interfaces/iEditService'; import type { IRowNode } from '../interfaces/iRowNode'; import type { UserCompDetails } from '../interfaces/iUserCompDetails'; import { CellCtrl } from '../rendering/cell/cellCtrl'; import type { RowCtrl } from '../rendering/row/rowCtrl'; import { PopupEditorWrapper } from './cellEditors/popupEditorWrapper'; type BatchPrepDetails = { compDetails?: UserCompDetails; valueToDisplay?: any; }; export declare class EditService extends BeanStub implements NamedBean { beanName: "editSvc"; committing: boolean; private csrm; private batch; private batchStartDispatched; private model; private valueSvc; private rangeSvc; private strategy?; private stopping; private rangeSelectionWhileEditing; /** * Whether the last stop was rejected by block mode holding an invalid value. `res === false` can't * stand in for this: a consumed mid-batch key also reports false but is a real stop that must still * navigate and must still be able to end the batch. */ private stopBlockRejected; /** Memo for hasConfiguredValidation, keyed on colModel.colDefsVersion. -1 never matches a real version. */ private validationConfigVersion; private validationConfigResult; /** Memo for editorsRequireValidation; undefined means "not scanned yet". */ private editorsValidation; /** Cell whose editor takes focus as it attaches, and whether the cell itself must be focused first. */ private pendingEditorFocus; private pendingEditorFocusCell; private bulkWriteDepth; private bulkWriteTouched; postConstruct(): void; isBatchEditing(): boolean; startBatchEditing(): void; stopBatchEditing(params?: StopEditParams): void; /** * Closes a batch's open editors, staging their values, without ending the batch. Block mode holds * instead: an invalid edit keeps its editor open so it can be corrected, as on every other stop path. */ stopBatchEditors(cancel: boolean): void; /** Lazily dispatch batchEditingStarted when the first write or editor open occurs during a batch session. */ private ensureBatchStarted; private createStrategy; private destroyStrategy; shouldStartEditing(position: Required<EditPosition>, event?: KeyboardEvent | MouseEvent | null, cellStartedEdit?: boolean | null, source?: EditSource): boolean; shouldStopEditing(position?: EditPosition, event?: KeyboardEvent | MouseEvent | null | undefined, source?: EditSource): boolean | null; shouldCancelEditing(position?: EditPosition, event?: KeyboardEvent | MouseEvent | null | undefined, source?: EditSource): boolean | null; isEditing(position?: EditPosition | null, params?: IsEditingParams): boolean; isRowEditing(rowNode?: IRowNode, params?: IsEditingParams): boolean; enableRangeSelectionWhileEditing(): void; disableRangeSelectionWhileEditing(): void; isRangeSelectionEnabledWhileEditing(): boolean; /** @returns whether to prevent default on event */ startEditing(position: Required<EditPosition>, params: StartEditParams): void; stopEditing(position?: EditPosition, params?: StopEditParams): boolean; private prepareStopContext; private processStopRequest; private handleStopOrCancel; private shouldHandleMidBatchKey; private handleMidBatchKey; private finishStopEditing; /** Dispatch batchEditingStopped if batchEditingStarted was (or should have been) dispatched. */ private dispatchBatchStopped; private clearValidationIfNoOpenEditors; private navigateAfterEdit; /** * Reverts each invalid cell to its previous pending value, so a revert-mode batch commit still * writes an earlier valid edit and drops cells that never held one. A row error invalidates the row. */ private revertInvalidEdits; /** Closes one cell's editor while its row keeps editing, so the edit and its pending value survive. */ closeCellEditor(position: Required<EditPosition>): void; /** * Drops a cell's in-flight editor attempt, keeping any earlier pending value (per-cell Escape * semantics), leaving any surrounding row or batch edit untouched. Callers that must revert one * cell without a key event go through here. */ revertCellEdit(position: Required<EditPosition>): void; private processEdits; /** * Commits a value to the row node's data via `rowNode.setDataValue`. * * This is a low-level helper that only writes to data; it does NOT update the * edit model. Callers are responsible for any model reconciliation — see * `syncEditAfterCommit` for the non-batch case and `processEdits` for the * batch-finalisation case (where edits are removed immediately after commit). */ private setNodeDataValue; /** * Syncs the edit model after a non-batch commit so sourceValue never becomes stale. * On success, re-reads the actual committed value from data (via getValue) because * a custom valueSetter may transform or store it differently than the passed value. * On failure, reverts the pending edit back to sourceValue. * * Skipped when an editor is open (state === 'editing'), because the upcoming * stopEditing flow will call _syncFromEditors which reads from the editor widget; * updating sourceValue here would cause that flow to re-commit stale editor content. * * NOTE: The re-read via `getValue` happens after `setNodeDataValue` has dispatched * `cellValueChanged`. If a `cellValueChanged` listener synchronously mutates the * same data field, the re-read will pick up that mutation. This is acceptable because * the listener intentionally transformed the value and the model should track the * actual committed state. */ private syncEditAfterCommit; setEditMap(edits: EditMap, params?: _SetEditingCellsParams): void; private dispatchEditValuesChanged; beginBulkWrite(): void; endBulkWrite(): void; private flushBulkWrite; private bulkRefreshCell; private bulkRefreshMap; private refCell; stopAllEditing(cancel?: boolean, source?: 'api' | 'ui'): void; isCellEditable(position: Required<EditPosition>, source?: 'api' | 'ui'): boolean; /** * Whether anything can report a validation error: a configured rule, or an open editor that validates * itself. Both halves are memoised — every probe would otherwise rescan the colDefs and the cell ctrls. */ hasValidationRules(): boolean; /** Configured validation: a row-level callback or a colDef rule, so it changes only with the colDefs. */ private hasConfiguredValidation; /** Editor-supplied validation: the scan materialises every rendered cell ctrl, hence the memo. */ private editorsRequireValidation; /** Called wherever an editor comes or goes: created, attached (React mounts late) or gone with its cell. */ invalidateEditorsValidation(): void; /** Rows whose edits were purged without a stop: the strategy still holds them, so let it release. */ releasePurgedRows(rowNodes: Set<IRowNode>): void; /** Ends a row's edits as it is torn down; its position can never be reached again. */ releaseRowEdits(rowNode: IRowNode): void; /** Ends edits on every column dropping out of colsList, destroyed or merely parked. */ releaseColumnsLeaving(newCols: AgColumn[]): void; cellEditingInvalidCommitBlocks(): boolean; checkNavWithValidation(position?: EditPosition, event?: Event | CellFocusedEvent, focus?: boolean): EditNavOnValidationResult; /** Calls through to standalone method for treeshaking via the editService */ populateModelValidationErrors(): void; /** * A cell component has attached: opens its editor if the cell is (or is starting) editing. * @returns whether the cell is editing, so the caller renders its value only when it is not. */ onCompAttached(cellCtrl: CellCtrl, startEdit?: boolean): boolean; /** Replays a start that was waiting for a component — React mounts one a turn late. Called after the * cell has rendered, so the editor takes over a cell that is already showing its value. */ replayPendingStart(cellCtrl: CellCtrl): void; /** A cell leaving takes its validation, and the focus it was owed, with it. */ onCellDestroyed(cellCtrl: CellCtrl): void; /** Focus can only be in one place, so a later request replaces an earlier one. */ focusEditorOnAttach(cellCtrl: CellCtrl, focusCell: boolean): void; /** An editor has attached to its cell — both view layers route here once the editor is live. */ onEditorAttached(cellCtrl: CellCtrl): void; /** Calls through to standalone method for treeshaking via the editService */ onPopupEditorClosed(cellCtrl: CellCtrl, event?: MouseEvent | TouchEvent | KeyboardEvent): void; revertSingleCellEdit(cellPosition: Required<EditPosition>, focus?: boolean): void; /** * Brings the validation state up to date, then reports it. Not a plain query: use the model's * {@link EditModelService.hasValidationErrors} when the state is known to be current. */ revalidateAndCheck(position?: EditPosition): boolean; /** The read half of {@link revalidateAndCheck}, for a caller that has just revalidated. */ checkValidated(position?: EditPosition): boolean; moveToNextCell(prev: CellCtrl | RowCtrl, backwards: boolean, event?: KeyboardEvent, source?: 'api' | 'ui'): boolean | null; /** * Gets the pending edit value for a cell (used by ValueService). * Returns undefined to fallback to committed data/valueGetter. */ getPendingEditValue(rowNode: IRowNode, column: Column, from: Exclude<CellValueResolveFrom, 'data'>): any; getCellDataValue(position: Required<EditPosition>): any; addStopEditingWhenGridLosesFocus(viewports: HTMLElement[]): void; createPopupEditorWrapper(params: ICellEditorParams): PopupEditorWrapper; batchResetToSourceValue(position: Required<EditPosition>): boolean; /** * Applies a data value change to a cell, handling batch editing, undo/redo, paste, and range operations. */ setDataValue(position: Required<EditPosition>, newValue: any, eventSource?: string): boolean | undefined; /** Handles setDataValue when an edit already exists for the cell. */ private applyExistingEdit; /** * Pushes a value into an open cell editor without closing it or committing. * Updates editorValue and pendingValue in the edit model, then refreshes the editor DOM. * Returns true if an editor was open and updated, false otherwise. */ private applyEditorValue; /** editApi or undoRedoApi apply change without involving the editor. */ private applyDirectValue; handleColDefChanged(cellCtrl: CellCtrl): void; destroy(): void; prepDetailsDuringBatch(position: Required<EditPosition>, params: BatchPrepDetails): BatchPrepDetails | undefined; cleanupEditors(): void; dispatchCellEvent<T extends AgEventType>(position: Required<EditPosition>, event?: Event | null, type?: T, payload?: any): void; dispatchBatchEvent(type: 'batchEditingStarted' | 'batchEditingStopped', edits: EditMap): void; private toEventChangeList; applyBulkEdit({ rowNode, column }: Required<EditPosition>, ranges: CellRange[]): void; applyCellEditStyles(cellCtrl: CellCtrl): void; applyRowEditStyles(rowCtrl: RowCtrl): void; setEditingCells(cells: EditingCellPosition[], params?: _SetEditingCellsParams): void; onCellFocused(event: CellFocusedEvent): void; allowedFocusTargetOnValidation(cellPosition: EditPosition): CellCtrl | undefined; } export {};