UNPKG

20.9 kBTypeScriptView Raw
1import { ExportedChange } from 'hyperformula';
2import CellCoords from './3rdparty/walkontable/src/cell/coords';
3import CellRange from './3rdparty/walkontable/src/cell/range';
4import { ViewportColumnsCalculator } from './3rdparty/walkontable/src/calculator/viewportColumns';
5import Core from './core';
6import { SelectionController } from './selection';
7import {
8 ContextMenu,
9 PredefinedMenuItemKey as ContextMenuPredefinedMenuItemKey,
10 MenuItemConfig as ContextMenuMenuItemConfig,
11} from './plugins/contextMenu';
12import {
13 DropdownMenu,
14} from './plugins/dropdownMenu';
15import {
16 Config as ColumnSortingConfig,
17} from './plugins/columnSorting';
18import {
19 ColumnConditions as FiltersColumnConditions,
20} from './plugins/filters';
21import {
22 Action as UndoRedoAction,
23} from './plugins/undoRedo';
24import {
25 Settings as MergeCellsSettings,
26} from './plugins/mergeCells';
27import {
28 GridSettings,
29 CellProperties,
30} from './settings';
31
32import {
33 CellValue,
34 RowObject,
35 CellChange,
36 ChangeSource,
37 RangeType,
38 OverlayType,
39} from './common';
40
41type Bucket = {
42 [P in keyof Events]: Array<Events[P]>;
43};
44
45interface HookHighlightRowHeaderMeta {
46 selectionType: string;
47 rowCursor: number;
48 selectionHeight: number;
49}
50interface HookHighlightColumnHeaderMeta {
51 selectionType: string;
52 columnCursor: number;
53 selectionWidth: number;
54}
55
56export interface Events {
57 afterAddChild?: (parent: RowObject, element: RowObject | undefined, index: number | undefined) => void;
58 afterAutofill?: (fillData: CellValue[][], sourceRange: CellRange, targetRange: CellRange, direction: 'up' | 'down' | 'left' | 'right') => void;
59 afterBeginEditing?: (row: number, column: number) => void;
60 afterCellMetaReset?: () => void;
61 afterChange?: (changes: CellChange[] | null, source: ChangeSource) => void;
62 afterChangesObserved?: () => void;
63 afterColumnCollapse?: (currentCollapsedColumns: number[], destinationCollapsedColumns: number[], collapsePossible: boolean, successfullyCollapsed: boolean) => void;
64 afterColumnExpand?: (currentCollapsedColumns: number[], destinationCollapsedColumns: number[], expandPossible: boolean, successfullyExpanded: boolean) => void;
65 afterColumnFreeze?: (columnIndex: number, isFreezingPerformed: boolean) => void;
66 afterColumnMove?: (movedColumns: number[], finalIndex: number, dropIndex: number | undefined, movePossible: boolean, orderChanged: boolean) => void;
67 afterColumnResize?: (newSize: number, column: number, isDoubleClick: boolean) => void;
68 afterColumnSequenceChange?: (source: 'init' | 'move' | 'insert' | 'remove' | 'update') => void;
69 afterColumnSort?: (currentSortConfig: ColumnSortingConfig[], destinationSortConfigs: ColumnSortingConfig[]) => void;
70 afterColumnUnfreeze?: (columnIndex: number, isUnfreezingPerformed: boolean) => void;
71 afterContextMenuDefaultOptions?: (predefinedItems: Array<ContextMenuPredefinedMenuItemKey | ContextMenuMenuItemConfig>) => void;
72 afterContextMenuHide?: (context: ContextMenu) => void;
73 afterContextMenuShow?: (context: ContextMenu) => void;
74 afterCopy?: (data: CellValue[][], coords: RangeType[], copiedHeadersCount: { columnHeadersCount: number }) => void;
75 afterCopyLimit?: (selectedRows: number, selectedColumns: number, copyRowsLimit: number, copyColumnsLimit: number) => void;
76 afterCreateCol?: (index: number, amount: number, source?: ChangeSource) => void;
77 afterCreateRow?: (index: number, amount: number, source?: ChangeSource) => void;
78 afterCut?: (data: CellValue[][], coords: RangeType[]) => void;
79 afterDeselect?: () => void;
80 afterDestroy?: () => void;
81 afterDetachChild?: (parent: RowObject, element: RowObject) => void;
82 afterDocumentKeyDown?: (event: KeyboardEvent) => void;
83 afterDrawSelection?: (currentRow: number, currentColumn: number, cornersOfSelection: number[], layerLevel?: number) => string | void;
84 afterDropdownMenuDefaultOptions?: (predefinedItems: Array<ContextMenuPredefinedMenuItemKey | ContextMenuMenuItemConfig>) => void;
85 afterDropdownMenuHide?: (instance: DropdownMenu) => void;
86 afterDropdownMenuShow?: (instance: DropdownMenu) => void;
87 afterFilter?: (conditionsStack: FiltersColumnConditions[]) => void;
88 afterFormulasValuesUpdate?: (changes: ExportedChange[]) => void;
89 afterGetCellMeta?: (row: number, column: number, cellProperties: CellProperties) => void;
90 afterGetColHeader?: (column: number, TH: HTMLTableHeaderCellElement, headerLevel: number) => void;
91 afterGetColumnHeaderRenderers?: (renderers: Array<(column: number, TH: HTMLTableHeaderCellElement) => void>) => void;
92 afterGetRowHeader?: (row: number, TH: HTMLTableHeaderCellElement) => void;
93 afterGetRowHeaderRenderers?: (renderers: Array<(row: number, TH: HTMLTableHeaderCellElement) => void>) => void;
94 afterHideColumns?: (currentHideConfig: number[], destinationHideConfig: number[], actionPossible: boolean, stateChanged: boolean) => void;
95 afterHideRows?: (currentHideConfig: number[], destinationHideConfig: number[], actionPossible: boolean, stateChanged: boolean) => void;
96 afterInit?: () => void;
97 afterLanguageChange?: (languageCode: string) => void;
98 afterListen?: () => void;
99 afterLoadData?: (sourceData: CellValue[], initialLoad: boolean, source: string | undefined) => void;
100 afterMergeCells?: (cellRange: CellRange, mergeParent: MergeCellsSettings, auto: boolean) => void;
101 afterModifyTransformEnd?: (coords: CellCoords, rowTransformDir: -1 | 0, colTransformDir: -1 | 0) => void;
102 afterModifyTransformFocus?: (coords: CellCoords, rowTransformDir: -1 | 0, colTransformDir: -1 | 0) => void;
103 afterModifyTransformStart?: (coords: CellCoords, rowTransformDir: -1 | 0, colTransformDir: -1 | 0) => void;
104 afterMomentumScroll?: () => void;
105 afterNamedExpressionAdded?: (namedExpressionName: string, changes: ExportedChange[]) => void;
106 afterNamedExpressionRemoved?: (namedExpressionName: string, changes: ExportedChange[]) => void;
107 afterOnCellContextMenu?: (event: MouseEvent, coords: CellCoords, TD: HTMLTableCellElement) => void;
108 afterOnCellCornerDblClick?: (event: MouseEvent) => void;
109 afterOnCellCornerMouseDown?: (event: MouseEvent) => void;
110 afterOnCellMouseDown?: (event: MouseEvent, coords: CellCoords, TD: HTMLTableCellElement) => void;
111 afterOnCellMouseOut?: (event: MouseEvent, coords: CellCoords, TD: HTMLTableCellElement) => void;
112 afterOnCellMouseOver?: (event: MouseEvent, coords: CellCoords, TD: HTMLTableCellElement) => void;
113 afterOnCellMouseUp?: (event: MouseEvent, coords: CellCoords, TD: HTMLTableCellElement) => void;
114 afterPaste?: (data: CellValue[][], coords: RangeType[]) => void;
115 afterPluginsInitialized?: () => void;
116 afterRedo?: (action: UndoRedoAction) => void;
117 afterRedoStackChange?: (undoneActionsBefore: UndoRedoAction[], undoneActionsAfter: UndoRedoAction[]) => void;
118 afterRefreshDimensions?: (previousDimensions: { width: number, height: number }, currentDimensions: { width: number, height: number }, stateChanged: boolean) => void;
119 afterRemoveCellMeta?: (row: number, column: number, key: string, value: any) => void;
120 afterRemoveCol?: (index: number, amount: number, physicalColumns: number[], source?: ChangeSource) => void;
121 afterRemoveRow?: (index: number, amount: number, physicalRows: number[], source?: ChangeSource) => void;
122 afterRender?: (isForced: boolean) => void;
123 afterRenderer?: (TD: HTMLTableCellElement, row: number, column: number, prop: string | number, value: string, cellProperties: CellProperties) => void;
124 afterRowMove?: (movedRows: number[], finalIndex: number, dropIndex: number | undefined, movePossible: boolean, orderChanged: boolean) => void;
125 afterRowResize?: (newSize: number, row: number, isDoubleClick: boolean) => void;
126 afterRowSequenceChange?: (source: 'init' | 'move' | 'insert' | 'remove' | 'update') => void;
127 afterScrollHorizontally?: () => void;
128 afterScrollVertically?: () => void;
129 afterScroll?: () => void;
130 afterSelectColumns?: (from: CellCoords, to: CellCoords, highlight: CellCoords) => void;
131 afterSelection?: (row: number, column: number, row2: number, column2: number, preventScrolling: { value: boolean }, selectionLayerLevel: number) => void;
132 afterSelectionByProp?: (row: number, prop: string, row2: number, prop2: string, preventScrolling: { value: boolean }, selectionLayerLevel: number) => void;
133 afterSelectionEnd?: (row: number, column: number, row2: number, column2: number, selectionLayerLevel: number) => void;
134 afterSelectionEndByProp?: (row: number, prop: string, row2: number, prop2: string, selectionLayerLevel: number) => void;
135 afterSelectionFocusSet?: (row: number, column: number, preventScrolling: { value: boolean }) => void;
136 afterSelectRows?: (from: CellCoords, to: CellCoords, highlight: CellCoords) => void;
137 afterSetCellMeta?: (row: number, column: number, key: string, value: any) => void;
138 afterSetDataAtCell?: (changes: CellChange[], source?: ChangeSource) => void;
139 afterSetDataAtRowProp?: (changes: CellChange[], source?: ChangeSource) => void;
140 afterSetSourceDataAtCell?: (changes: CellChange[], source?: ChangeSource) => void;
141 afterSheetAdded?: (addedSheetDisplayName: string) => void;
142 afterSheetRemoved?: (removedSheetDisplayName: string, changes: ExportedChange[]) => void;
143 afterSheetRenamed?: (oldDisplayName: string, newDisplayName: string) => void;
144 afterTrimRow?: (currentTrimConfig: number[], destinationTrimConfig: number[], actionPossible: boolean, stateChanged: boolean) => void;
145 afterUndo?: (action: UndoRedoAction) => void;
146 afterUndoStackChange?: (doneActionsBefore: UndoRedoAction[], doneActionsAfter: UndoRedoAction[]) => void;
147 afterUnhideColumns?: (currentHideConfig: number[], destinationHideConfig: number[], actionPossible: boolean, stateChanged: boolean) => void;
148 afterUnhideRows?: (currentHideConfig: number[], destinationHideConfig: number[], actionPossible: boolean, stateChanged: boolean) => void;
149 afterUnlisten?: () => void;
150 afterUnmergeCells?: (cellRange: CellRange, auto: boolean) => void;
151 afterUntrimRow?: (currentTrimConfig: number[], destinationTrimConfig: number[], actionPossible: boolean, stateChanged: boolean) => void;
152 afterUpdateData?: (sourceData: CellValue[], initialLoad: boolean, source: string | undefined) => void;
153 afterUpdateSettings?: (newSettings: GridSettings) => void;
154 afterValidate?: (isValid: boolean, value: CellValue, row: number, prop: string | number, source: ChangeSource) => void | boolean;
155 afterViewportColumnCalculatorOverride?: (calc: ViewportColumnsCalculator) => void;
156 afterViewportRowCalculatorOverride?: (calc: ViewportColumnsCalculator) => void;
157 afterViewRender?: (isForced: boolean) => void;
158 beforeAddChild?: (parent: RowObject, element?: RowObject, index?: number) => void;
159 beforeAutofill?: (selectionData: CellValue[][], sourceRange: CellRange, targetRange: CellRange, direction: 'up' | 'down' | 'left' | 'right') => CellValue[][] | boolean | void;
160 beforeBeginEditing?: (row: number, column: number, initialValue: any, event: MouseEvent | KeyboardEvent, fullEditMode: boolean) => boolean | void;
161 beforeCellAlignment?: (stateBefore: { [row: number]: string[] }, range: CellRange[], type: 'horizontal' | 'vertical',
162 alignmentClass: 'htLeft' | 'htCenter' | 'htRight' | 'htJustify' | 'htTop' | 'htMiddle' | 'htBottom') => void;
163 beforeChange?: (changes: Array<CellChange | null>, source: ChangeSource) => void | boolean;
164 beforeChangeRender?: (changes: CellChange[], source: ChangeSource) => void;
165 beforeColumnCollapse?: (currentCollapsedColumn: number[], destinationCollapsedColumns: number[], collapsePossible: boolean) => void | boolean;
166 beforeColumnExpand?: (currentCollapsedColumn: number[], destinationCollapsedColumns: number[], expandPossible: boolean) => void | boolean;
167 beforeColumnFreeze?: (columnIndex: number, isFreezingPerformed: boolean) => void | boolean;
168 beforeColumnMove?: (movedColumns: number[], finalIndex: number, dropIndex: number | undefined, movePossible: boolean) => void | boolean;
169 beforeColumnResize?: (newSize: number, column: number, isDoubleClick: boolean) => void | number;
170 beforeColumnSort?: (currentSortConfig: ColumnSortingConfig[], destinationSortConfigs: ColumnSortingConfig[]) => void | boolean;
171 beforeColumnWrap?: (isActionInterrupted: { value: boolean }, newCoords: CellCoords, isColumnFlipped: boolean) => void;
172 beforeColumnUnfreeze?: (columnIndex: number, isUnfreezingPerformed: boolean) => void | boolean;
173 beforeContextMenuSetItems?: (menuItems: ContextMenuMenuItemConfig[]) => void;
174 beforeContextMenuShow?: (context: ContextMenu) => void;
175 beforeCopy?: (data: CellValue[][], coords: RangeType[], copiedHeadersCount: { columnHeadersCount: number }) => void | boolean;
176 beforeCreateCol?: (index: number, amount: number, source?: ChangeSource) => void | boolean;
177 beforeCreateRow?: (index: number, amount: number, source?: ChangeSource) => void | boolean;
178 beforeCut?: (data: CellValue[][], coords: RangeType[]) => void | boolean;
179 beforeDetachChild?: (parent: RowObject, element: RowObject) => void;
180 beforeDrawBorders?: (corners: number[], borderClassName: 'current' | 'area' | 'highlight' | undefined) => void;
181 beforeDropdownMenuSetItems?: (menuItems: ContextMenuMenuItemConfig[]) => void;
182 beforeDropdownMenuShow?: (instance: DropdownMenu) => void;
183 beforeFilter?: (conditionsStack: FiltersColumnConditions[], previousConditionsStack: FiltersColumnConditions[]) => void | boolean;
184 beforeGetCellMeta?: (row: number, column: number, cellProperties: CellProperties) => void;
185 beforeHideColumns?: (currentHideConfig: number[], destinationHideConfig: number[], actionPossible: boolean) => void | boolean;
186 beforeHideRows?: (currentHideConfig: number[], destinationHideConfig: number[], actionPossible: boolean) => void | boolean;
187 beforeHighlightingColumnHeader?: (column: number, headerLevel: number, highlightMeta: HookHighlightColumnHeaderMeta) => number | void;
188 beforeHighlightingRowHeader?: (row: number, headerLevel: number, highlightMeta: HookHighlightRowHeaderMeta) => number | void;
189 beforeInit?: () => void;
190 beforeInitWalkontable?: (walkontableConfig: object) => void;
191 beforeKeyDown?: (event: KeyboardEvent) => void;
192 beforeLanguageChange?: (languageCode: string) => void;
193 beforeLoadData?: (sourceData: CellValue[], initialLoad: boolean, source: string | undefined) => void;
194 beforeMergeCells?: (cellRange: CellRange, auto: boolean) => void;
195 beforeOnCellContextMenu?: (event: MouseEvent, coords: CellCoords, TD: HTMLTableCellElement) => void;
196 beforeOnCellMouseDown?: (event: MouseEvent, coords: CellCoords, TD: HTMLTableCellElement, controller: SelectionController) => void;
197 beforeOnCellMouseOut?: (event: MouseEvent, coords: CellCoords, TD: HTMLTableCellElement) => void;
198 beforeOnCellMouseOver?: (event: MouseEvent, coords: CellCoords, TD: HTMLTableCellElement, controller: SelectionController) => void;
199 beforeOnCellMouseUp?: (event: MouseEvent, coords: CellCoords, TD: HTMLTableCellElement) => void;
200 beforePaste?: (data: CellValue[][], coords: RangeType[]) => void | boolean;
201 beforeRedo?: (action: UndoRedoAction) => void;
202 beforeRedoStackChange?: (undoneActions: UndoRedoAction[]) => void;
203 beforeRefreshDimensions?: (previousDimensions: { width: number, height: number }, currentDimensions: { width: number, height: number }, actionPossible: boolean) => boolean | void;
204 beforeRemoveCellClassNames?: () => string[] | void;
205 beforeRemoveCellMeta?: (row: number, column: number, key: string, value: any) => void;
206 beforeRemoveCol?: (index: number, amount: number, physicalColumns: number[], source?: ChangeSource) => void;
207 beforeRemoveRow?: (index: number, amount: number, physicalColumns: number[], source?: ChangeSource) => void;
208 beforeRender?: (isForced: boolean) => void;
209 beforeRenderer?: (TD: HTMLTableCellElement, row: number, column: number, prop: string | number, value: CellValue, cellProperties: CellProperties) => void;
210 beforeRowMove?: (movedRows: number[], finalIndex: number, dropIndex: number | undefined, movePossible: boolean) => void;
211 beforeRowResize?: (newSize: number, row: number, isDoubleClick: boolean) => number | void;
212 beforeRowWrap?: (isActionInterrupted: { value: boolean }, newCoords: CellCoords, isRowFlipped: boolean) => void;
213 beforeSelectColumns?: (from: CellCoords, to: CellCoords, highlight: CellCoords) => void;
214 beforeSelectionFocusSet?: (coords: CellCoords) => void;
215 beforeSelectionHighlightSet?: () => void;
216 beforeSelectRows?: (from: CellCoords, to: CellCoords, highlight: CellCoords) => void;
217 beforeSetCellMeta?: (row: number, column: number, key: string, value: any) => boolean | void;
218 beforeSetRangeEnd?: (coords: CellCoords) => void;
219 beforeSetRangeStart?: (coords: CellCoords) => void;
220 beforeSetRangeStartOnly?: (coords: CellCoords) => void;
221 beforeStretchingColumnWidth?: (stretchedWidth: number, column: number) => void | number;
222 beforeTouchScroll?: () => void;
223 beforeTrimRow?: (currentTrimConfig: number[], destinationTrimConfig: number[], actionPossible: boolean) => void | boolean;
224 beforeUndo?: (action: UndoRedoAction) => void;
225 beforeUndoStackChange?: (doneActions: UndoRedoAction[], source?: string) => void;
226 beforeUnhideColumns?: (currentHideConfig: number[], destinationHideConfig: number[], actionPossible: boolean) => void | boolean;
227 beforeUnhideRows?: (currentHideConfig: number[], destinationHideConfig: number[], actionPossible: boolean) => void | boolean;
228 beforeUnmergeCells?: (cellRange: CellRange, auto: boolean) => void;
229 beforeUntrimRow?: (currentTrimConfig: number[], destinationTrimConfig: number[], actionPossible: boolean) => void | boolean;
230 beforeUpdateData?: (sourceData: CellValue[], initialLoad: boolean, source: string | undefined) => void;
231 beforeValidate?: (value: CellValue, row: number, prop: string | number, source?: ChangeSource) => void;
232 beforeValueRender?: (value: CellValue, cellProperties: CellProperties) => void;
233 beforeViewportScrollVertically?: (visualRow: number) => number | boolean;
234 beforeViewportScrollHorizontally?: (visualColumn: number) => number | boolean;
235 beforeViewportScroll?: () => void;
236 beforeViewRender?: (isForced: boolean, skipRender: { skipRender?: boolean }) => void;
237 construct?: () => void;
238 init?: () => void;
239 modifyAutoColumnSizeSeed?: (seed: string, cellProperties: CellProperties, cellValue: CellValue) => string | void;
240 modifyAutofillRange?: (startArea: Array<[number, number, number, number]>, entireArea: Array<[number, number, number, number]>) => void;
241 modifyColHeader?: (column: number) => void;
242 modifyColumnHeaderHeight?: () => void;
243 modifyColumnHeaderValue?: (headerValue: string, visualColumnIndex: number, headerLevel: number) => void | string;
244 modifyColWidth?: (width: number, column: number) => void;
245 modifyCopyableRange?: (copyableRanges: RangeType[]) => void;
246 modifyFiltersMultiSelectValue?: (value: string, meta: CellProperties) => void | CellValue;
247 modifyFocusedElement?: (row: number, column: number, focusedElement: HTMLElement) => void | HTMLElement;
248 modifyData?: (row: number, column: number, valueHolder: { value: CellValue }, ioMode: 'get' | 'set') => void;
249 modifyFocusOnTabNavigation?: (tabActivationDir: 'from_above' | 'from_below', visualCoords: CellCoords) => void;
250 modifyGetCellCoords?: (row: number, column: number, topmost: boolean) => void | [number, number] | [number, number, number, number];
251 modifyRowData?: (row: number) => void;
252 modifyRowHeader?: (row: number) => void;
253 modifyRowHeaderWidth?: (rowHeaderWidth: number) => void;
254 modifyRowHeight?: (height: number, row: number) => void | number;
255 modifyRowHeightByOverlayName?: (height: number, row: number, overlayType: OverlayType) => void | number;
256 modifySourceData?: (row: number, column: number, valueHolder: { value: CellValue }, ioMode: 'get' | 'set') => void;
257 modifyTransformEnd?: (delta: CellCoords) => void;
258 modifyTransformFocus?: (delta: CellCoords) => void;
259 modifyTransformStart?: (delta: CellCoords) => void;
260 persistentStateLoad?: (key: string, valuePlaceholder: { value: any }) => void;
261 persistentStateReset?: (key: string) => void;
262 persistentStateSave?: (key: string, value: any) => void;
263}
264
265export class Hooks {
266 add<K extends keyof Events>(key: K, callback: Events[K] | Array<Events[K]>, context?: Core, orderIndex?: number): Hooks;
267 createEmptyBucket(): Bucket;
268 deregister(key: string): void;
269 destroy(context?: Core): void;
270 getBucket(context?: Core): Bucket;
271 getRegistered(): Array<keyof Events>;
272 has(key: keyof Events, context?: Core): boolean;
273 isDeprecated(key: keyof Events): boolean;
274 isRegistered(key: keyof Events): boolean;
275 once<K extends keyof Events>(key: K, callback: Events[K] | Array<Events[K]>, context?: Core): void;
276 register(key: string): void;
277 remove(key: keyof Events, callback: () => void, context?: Core): boolean;
278 run(context: Core, key: keyof Events, p1?: any, p2?: any, p3?: any, p4?: any, p5?: any, p6?: any): any;
279}