1 | import "core-js/modules/es.error.cause.js";
|
2 | import "core-js/modules/es.array.push.js";
|
3 | import "core-js/modules/es.array.unscopables.flat-map.js";
|
4 | function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
5 | function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
6 | function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
7 | import { arrayEach } from "./helpers/array.mjs";
|
8 | import { objectEach } from "./helpers/object.mjs";
|
9 | import { substitute } from "./helpers/string.mjs";
|
10 | import { warn } from "./helpers/console.mjs";
|
11 | import { toSingleLine } from "./helpers/templateLiteralTag.mjs";
|
12 | import { fastCall } from "./helpers/function.mjs";
|
13 | /* eslint-disable jsdoc/require-description-complete-sentence */
|
14 | /**
|
15 | * @description
|
16 | *
|
17 | * ::: only-for javascript
|
18 | * Handsontable events are the common interface that function in 2 ways: as __callbacks__ and as __hooks__.
|
19 | * :::
|
20 | *
|
21 | * ::: only-for react
|
22 | * This page lists all the **Handsontable hooks** – callbacks that let you react before or after an action occurs.
|
23 | *
|
24 | * Read more on the [Events and hooks](@/guides/getting-started/events-and-hooks/events-and-hooks.md) page.
|
25 | * :::
|
26 | *
|
27 | * @example
|
28 | *
|
29 | * ::: only-for javascript
|
30 | * ```js
|
31 | * // using events as callbacks
|
32 | * ...
|
33 | * const hot1 = new Handsontable(document.getElementById('example1'), {
|
34 | * afterChange: function(changes, source) {
|
35 | * $.ajax({
|
36 | * url: "save.php',
|
37 | * data: change
|
38 | * });
|
39 | * }
|
40 | * });
|
41 | * ...
|
42 | * ```
|
43 | * :::
|
44 | *
|
45 | * ::: only-for react
|
46 | * ```jsx
|
47 | * <HotTable
|
48 | * afterChange={(changes, source) => {
|
49 | * fetch('save.php', {
|
50 | * method: 'POST',
|
51 | * headers: {
|
52 | * 'Accept': 'application/json',
|
53 | * 'Content-Type': 'application/json'
|
54 | * },
|
55 | * body: JSON.stringify(changes)
|
56 | * });
|
57 | * }}
|
58 | * />
|
59 | * :::
|
60 | *
|
61 | * ::: only-for javascript
|
62 | * ```js
|
63 | * // using events as plugin hooks
|
64 | * ...
|
65 | * const hot1 = new Handsontable(document.getElementById('example1'), {
|
66 | * myPlugin: true
|
67 | * });
|
68 | *
|
69 | * const hot2 = new Handsontable(document.getElementById('example2'), {
|
70 | * myPlugin: false
|
71 | * });
|
72 | *
|
73 | * // global hook
|
74 | * Handsontable.hooks.add('afterChange', function() {
|
75 | * // Fired twice - for hot1 and hot2
|
76 | * if (this.getSettings().myPlugin) {
|
77 | * // function body - will only run for hot1
|
78 | * }
|
79 | * });
|
80 | *
|
81 | * // local hook (has same effect as a callback)
|
82 | * hot2.addHook('afterChange', function() {
|
83 | * // function body - will only run in #example2
|
84 | * });
|
85 | * ```
|
86 | * :::
|
87 | *
|
88 | * ::: only-for react
|
89 | * ```jsx
|
90 | * const hotRef1 = useRef(null);
|
91 | * const hotRef2 = useRef(null);
|
92 | *
|
93 | * // Using events as plugin hooks:
|
94 | * ...
|
95 | *
|
96 | * <HotTable
|
97 | * ref={hotRef1}
|
98 | * myPlugin={true}
|
99 | * });
|
100 | *
|
101 | * <HotTable
|
102 | * ref={hotRef2}
|
103 | * myPlugin={false}
|
104 | * });
|
105 | *
|
106 | * ...
|
107 | *
|
108 | * const hot2 = hotRef2.current.hotInstance;
|
109 | * // local hook (has same effect as a callback)
|
110 | * hot2.addHook('afterChange', function() {
|
111 | * // function body - will only run in #example2
|
112 | * });
|
113 | *
|
114 | * // global hook
|
115 | * Handsontable.hooks.add('afterChange', function() {
|
116 | * // Fired twice - for hot1 and hot2
|
117 | * if (this.getSettings().myPlugin) {
|
118 | * // function body - will only run for first instance
|
119 | * }
|
120 | * });
|
121 | * :::
|
122 | * ...
|
123 | */
|
124 | // @TODO: Move plugin description hooks to plugin?
|
125 | const REGISTERED_HOOKS = [/* eslint-disable jsdoc/require-description-complete-sentence */
|
126 | /**
|
127 | * Fired after resetting a cell's meta. This happens when the {@link Core#updateSettings} method is called.
|
128 | *
|
129 | * @event Hooks#afterCellMetaReset
|
130 | */
|
131 | 'afterCellMetaReset',
|
132 | /**
|
133 | * Fired after one or more cells has been changed. The changes are triggered in any situation when the
|
134 | * value is entered using an editor or changed using API (e.q [`setDataAtCell`](@/api/core.md#setdataatcell) method).
|
135 | *
|
136 | * __Note:__ For performance reasons, the `changes` array is null for `"loadData"` source.
|
137 | *
|
138 | * @event Hooks#afterChange
|
139 | * @param {Array[]} changes 2D array containing information about each of the edited cells `[[row, prop, oldVal, newVal], ...]`. `row` is a visual row index.
|
140 | * @param {string} [source] String that identifies source of hook call ([list of all available sources](@/guides/getting-started/events-and-hooks/events-and-hooks.md#definition-for-source-argument)).
|
141 | * @example
|
142 | * ::: only-for javascript
|
143 | * ```js
|
144 | * new Handsontable(element, {
|
145 | * afterChange: (changes) => {
|
146 | * changes?.forEach(([row, prop, oldValue, newValue]) => {
|
147 | * // Some logic...
|
148 | * });
|
149 | * }
|
150 | * })
|
151 | * ```
|
152 | * :::
|
153 | *
|
154 | * ::: only-for react
|
155 | * ```jsx
|
156 | * <HotTable
|
157 | * afterChange={(changes, source) => {
|
158 | * changes?.forEach(([row, prop, oldValue, newValue]) => {
|
159 | * // Some logic...
|
160 | * });
|
161 | * }}
|
162 | * />
|
163 | * ```
|
164 | * :::
|
165 | */
|
166 | 'afterChange',
|
167 | /**
|
168 | * Fired each time user opens {@link ContextMenu} and after setting up the Context Menu's default options. These options are a collection
|
169 | * which user can select by setting an array of keys or an array of objects in {@link Options#contextMenu} option.
|
170 | *
|
171 | * @event Hooks#afterContextMenuDefaultOptions
|
172 | * @param {Array} predefinedItems An array of objects containing information about the pre-defined Context Menu items.
|
173 | */
|
174 | 'afterContextMenuDefaultOptions',
|
175 | /**
|
176 | * Fired each time user opens {@link ContextMenu} plugin before setting up the Context Menu's items but after filtering these options by
|
177 | * user ([`contextMenu`](@/api/options.md#contextmenu) option). This hook can by helpful to determine if user use specified menu item or to set up
|
178 | * one of the menu item to by always visible.
|
179 | *
|
180 | * @event Hooks#beforeContextMenuSetItems
|
181 | * @param {object[]} menuItems An array of objects containing information about to generated Context Menu items.
|
182 | */
|
183 | 'beforeContextMenuSetItems',
|
184 | /**
|
185 | * Fired by {@link DropdownMenu} plugin after setting up the Dropdown Menu's default options. These options are a
|
186 | * collection which user can select by setting an array of keys or an array of objects in {@link Options#dropdownMenu}
|
187 | * option.
|
188 | *
|
189 | * @event Hooks#afterDropdownMenuDefaultOptions
|
190 | * @param {object[]} predefinedItems An array of objects containing information about the pre-defined Context Menu items.
|
191 | */
|
192 | 'afterDropdownMenuDefaultOptions',
|
193 | /**
|
194 | * Fired by {@link DropdownMenu} plugin before setting up the Dropdown Menu's items but after filtering these options
|
195 | * by user ([`dropdownMenu`](@/api/options.md#dropdownmenu) option). This hook can by helpful to determine if user use specified menu item or to set
|
196 | * up one of the menu item to by always visible.
|
197 | *
|
198 | * @event Hooks#beforeDropdownMenuSetItems
|
199 | * @param {object[]} menuItems An array of objects containing information about to generated Dropdown Menu items.
|
200 | */
|
201 | 'beforeDropdownMenuSetItems',
|
202 | /**
|
203 | * Fired by {@link ContextMenu} plugin after hiding the Context Menu. This hook is fired when {@link Options#contextMenu}
|
204 | * option is enabled.
|
205 | *
|
206 | * @event Hooks#afterContextMenuHide
|
207 | * @param {object} context The Context Menu plugin instance.
|
208 | */
|
209 | 'afterContextMenuHide',
|
210 | /**
|
211 | * Fired by {@link ContextMenu} plugin before opening the Context Menu. This hook is fired when {@link Options#contextMenu}
|
212 | * option is enabled.
|
213 | *
|
214 | * @event Hooks#beforeContextMenuShow
|
215 | * @param {object} context The Context Menu instance.
|
216 | */
|
217 | 'beforeContextMenuShow',
|
218 | /**
|
219 | * Fired by {@link ContextMenu} plugin after opening the Context Menu. This hook is fired when {@link Options#contextMenu}
|
220 | * option is enabled.
|
221 | *
|
222 | * @event Hooks#afterContextMenuShow
|
223 | * @param {object} context The Context Menu plugin instance.
|
224 | */
|
225 | 'afterContextMenuShow',
|
226 | /**
|
227 | * Fired by {@link CopyPaste} plugin after reaching the copy limit while copying data. This hook is fired when
|
228 | * {@link Options#copyPaste} option is enabled.
|
229 | *
|
230 | * @event Hooks#afterCopyLimit
|
231 | * @param {number} selectedRows Count of selected copyable rows.
|
232 | * @param {number} selectedColumns Count of selected copyable columns.
|
233 | * @param {number} copyRowsLimit Current copy rows limit.
|
234 | * @param {number} copyColumnsLimit Current copy columns limit.
|
235 | */
|
236 | 'afterCopyLimit',
|
237 | /**
|
238 | * Fired before created a new column.
|
239 | *
|
240 | * @event Hooks#beforeCreateCol
|
241 | * @param {number} index Represents the visual index of first newly created column in the data source array.
|
242 | * @param {number} amount Number of newly created columns in the data source array.
|
243 | * @param {string} [source] String that identifies source of hook call
|
244 | * ([list of all available sources](@/guides/getting-started/events-and-hooks/events-and-hooks.md#definition-for-source-argument)).
|
245 | * @returns {*} If `false` then creating columns is cancelled.
|
246 | * @example
|
247 | * ::: only-for javascript
|
248 | * ```js
|
249 | * // Return `false` to cancel column inserting.
|
250 | * new Handsontable(element, {
|
251 | * beforeCreateCol: function(data, coords) {
|
252 | * return false;
|
253 | * }
|
254 | * });
|
255 | * ```
|
256 | * :::
|
257 | *
|
258 | * ::: only-for react
|
259 | * ```jsx
|
260 | * // Return `false` to cancel column inserting.
|
261 | * <HotTable
|
262 | * beforeCreateCol={(data, coords) => {
|
263 | * return false;
|
264 | * }}
|
265 | * />
|
266 | * ```
|
267 | * :::
|
268 | */
|
269 | 'beforeCreateCol',
|
270 | /**
|
271 | * Fired after the order of columns has changed.
|
272 | * This hook is fired by changing column indexes of any type supported by the {@link IndexMapper}.
|
273 | *
|
274 | * @event Hooks#afterColumnSequenceChange
|
275 | * @param {'init'|'remove'|'insert'|'move'|'update'} [source] A string that indicates what caused the change to the order of columns.
|
276 | */
|
277 | 'afterColumnSequenceChange',
|
278 | /**
|
279 | * Fired after created a new column.
|
280 | *
|
281 | * @event Hooks#afterCreateCol
|
282 | * @param {number} index Represents the visual index of first newly created column in the data source.
|
283 | * @param {number} amount Number of newly created columns in the data source.
|
284 | * @param {string} [source] String that identifies source of hook call
|
285 | * ([list of all available sources](@/guides/getting-started/events-and-hooks/events-and-hooks.md#definition-for-source-argument)).
|
286 | */
|
287 | 'afterCreateCol',
|
288 | /**
|
289 | * Fired before created a new row.
|
290 | *
|
291 | * @event Hooks#beforeCreateRow
|
292 | * @param {number} index Represents the visual index of first newly created row in the data source array.
|
293 | * @param {number} amount Number of newly created rows in the data source array.
|
294 | * @param {string} [source] String that identifies source of hook call
|
295 | * ([list of all available sources](@/guides/getting-started/events-and-hooks/events-and-hooks.md#definition-for-source-argument)).
|
296 | * @returns {*|boolean} If false is returned the action is canceled.
|
297 | */
|
298 | 'beforeCreateRow',
|
299 | /**
|
300 | * Fired after created a new row.
|
301 | *
|
302 | * @event Hooks#afterCreateRow
|
303 | * @param {number} index Represents the visual index of first newly created row in the data source array.
|
304 | * @param {number} amount Number of newly created rows in the data source array.
|
305 | * @param {string} [source] String that identifies source of hook call
|
306 | * ([list of all available sources](@/guides/getting-started/events-and-hooks/events-and-hooks.md#definition-for-source-argument)).
|
307 | */
|
308 | 'afterCreateRow',
|
309 | /**
|
310 | * Fired after all selected cells are deselected.
|
311 | *
|
312 | * @event Hooks#afterDeselect
|
313 | */
|
314 | 'afterDeselect',
|
315 | /**
|
316 | * Fired after destroying the Handsontable instance.
|
317 | *
|
318 | * @event Hooks#afterDestroy
|
319 | */
|
320 | 'afterDestroy',
|
321 | /**
|
322 | * Hook fired after `keydown` event is handled.
|
323 | *
|
324 | * @event Hooks#afterDocumentKeyDown
|
325 | * @param {Event} event A native `keydown` event object.
|
326 | */
|
327 | 'afterDocumentKeyDown',
|
328 | /**
|
329 | * Fired inside the Walkontable's selection `draw` method. Can be used to add additional class names to cells, depending on the current selection.
|
330 | *
|
331 | * @event Hooks#afterDrawSelection
|
332 | * @param {number} currentRow Row index of the currently processed cell.
|
333 | * @param {number} currentColumn Column index of the currently cell.
|
334 | * @param {number[]} cornersOfSelection Array of the current selection in a form of `[startRow, startColumn, endRow, endColumn]`.
|
335 | * @param {number|undefined} layerLevel Number indicating which layer of selection is currently processed.
|
336 | * @since 0.38.1
|
337 | * @returns {string|undefined} Can return a `String`, which will act as an additional `className` to be added to the currently processed cell.
|
338 | */
|
339 | 'afterDrawSelection',
|
340 | /**
|
341 | * Fired inside the Walkontable's `refreshSelections` method. Can be used to remove additional class names from all cells in the table.
|
342 | *
|
343 | * @event Hooks#beforeRemoveCellClassNames
|
344 | * @since 0.38.1
|
345 | * @returns {string[]|undefined} Can return an `Array` of `String`s. Each of these strings will act like class names to be removed from all the cells in the table.
|
346 | */
|
347 | 'beforeRemoveCellClassNames',
|
348 | /**
|
349 | * Fired after getting the cell settings.
|
350 | *
|
351 | * @event Hooks#afterGetCellMeta
|
352 | * @param {number} row Visual row index.
|
353 | * @param {number} column Visual column index.
|
354 | * @param {object} cellProperties Object containing the cell properties.
|
355 | */
|
356 | 'afterGetCellMeta',
|
357 | /**
|
358 | * Fired after retrieving information about a column header and appending it to the table header.
|
359 | *
|
360 | * @event Hooks#afterGetColHeader
|
361 | * @param {number} column Visual column index.
|
362 | * @param {HTMLTableCellElement} TH Header's TH element.
|
363 | * @param {number} [headerLevel=0] (Since 12.2.0) Header level index. Accepts positive (0 to n)
|
364 | * and negative (-1 to -n) values. For positive values, 0 points to the
|
365 | * topmost header. For negative values, -1 points to the bottom-most
|
366 | * header (the header closest to the cells).
|
367 | */
|
368 | 'afterGetColHeader',
|
369 | /**
|
370 | * Fired after retrieving information about a row header and appending it to the table header.
|
371 | *
|
372 | * @event Hooks#afterGetRowHeader
|
373 | * @param {number} row Visual row index.
|
374 | * @param {HTMLTableCellElement} TH Header's TH element.
|
375 | */
|
376 | 'afterGetRowHeader',
|
377 | /**
|
378 | * Fired after the Handsontable instance is initiated.
|
379 | *
|
380 | * @event Hooks#afterInit
|
381 | */
|
382 | 'afterInit',
|
383 | /**
|
384 | * Fired after Handsontable's [`data`](@/api/options.md#data)
|
385 | * gets modified by the [`loadData()`](@/api/core.md#loaddata) method
|
386 | * or the [`updateSettings()`](@/api/core.md#updatesettings) method.
|
387 | *
|
388 | * Read more:
|
389 | * - [Binding to data](@/guides/getting-started/binding-to-data/binding-to-data.md)
|
390 | * - [Saving data](@/guides/getting-started/saving-data/saving-data.md)
|
391 | *
|
392 | * @event Hooks#afterLoadData
|
393 | * @param {Array} sourceData An [array of arrays](@/guides/getting-started/binding-to-data/binding-to-data.md#array-of-arrays), or an [array of objects](@/guides/getting-started/binding-to-data/binding-to-data.md#array-of-objects), that contains Handsontable's data
|
394 | * @param {boolean} initialLoad A flag that indicates whether the data was loaded at Handsontable's initialization (`true`) or later (`false`)
|
395 | * @param {string} source The source of the call
|
396 | */
|
397 | 'afterLoadData',
|
398 | /**
|
399 | * Fired after the [`updateData()`](@/api/core.md#updatedata) method
|
400 | * modifies Handsontable's [`data`](@/api/options.md#data).
|
401 | *
|
402 | * Read more:
|
403 | * - [Binding to data](@/guides/getting-started/binding-to-data/binding-to-data.md)
|
404 | * - [Saving data](@/guides/getting-started/saving-data/saving-data.md)
|
405 | *
|
406 | * @event Hooks#afterUpdateData
|
407 | * @since 11.1.0
|
408 | * @param {Array} sourceData An [array of arrays](@/guides/getting-started/binding-to-data/binding-to-data.md#array-of-arrays), or an [array of objects](@/guides/getting-started/binding-to-data/binding-to-data.md#array-of-objects), that contains Handsontable's data
|
409 | * @param {boolean} initialLoad A flag that indicates whether the data was loaded at Handsontable's initialization (`true`) or later (`false`)
|
410 | * @param {string} source The source of the call
|
411 | */
|
412 | 'afterUpdateData',
|
413 | /**
|
414 | * Fired after a scroll event, which is identified as a momentum scroll (e.g. on an iPad).
|
415 | *
|
416 | * @event Hooks#afterMomentumScroll
|
417 | */
|
418 | 'afterMomentumScroll',
|
419 | /**
|
420 | * Fired after a `mousedown` event is triggered on the cell corner (the drag handle).
|
421 | *
|
422 | * @event Hooks#afterOnCellCornerMouseDown
|
423 | * @param {Event} event `mousedown` event object.
|
424 | */
|
425 | 'afterOnCellCornerMouseDown',
|
426 | /**
|
427 | * Fired after a `dblclick` event is triggered on the cell corner (the drag handle).
|
428 | *
|
429 | * @event Hooks#afterOnCellCornerDblClick
|
430 | * @param {Event} event `dblclick` event object.
|
431 | */
|
432 | 'afterOnCellCornerDblClick',
|
433 | /**
|
434 | * Fired after clicking on a cell or row/column header. In case the row/column header was clicked, the coordinate
|
435 | * indexes are negative.
|
436 | *
|
437 | * For example clicking on the row header of cell (0, 0) results with `afterOnCellMouseDown` called
|
438 | * with coordinates `{row: 0, col: -1}`.
|
439 | *
|
440 | * @event Hooks#afterOnCellMouseDown
|
441 | * @param {Event} event `mousedown` event object.
|
442 | * @param {CellCoords} coords Coordinates object containing the visual row and visual column indexes of the clicked cell.
|
443 | * @param {HTMLTableCellElement} TD Cell's TD (or TH) element.
|
444 | */
|
445 | 'afterOnCellMouseDown',
|
446 | /**
|
447 | * Fired after clicking on a cell or row/column header. In case the row/column header was clicked, the coordinate
|
448 | * indexes are negative.
|
449 | *
|
450 | * For example clicking on the row header of cell (0, 0) results with `afterOnCellMouseUp` called
|
451 | * with coordinates `{row: 0, col: -1}`.
|
452 | *
|
453 | * @event Hooks#afterOnCellMouseUp
|
454 | * @param {Event} event `mouseup` event object.
|
455 | * @param {CellCoords} coords Coordinates object containing the visual row and visual column indexes of the clicked cell.
|
456 | * @param {HTMLTableCellElement} TD Cell's TD (or TH) element.
|
457 | */
|
458 | 'afterOnCellMouseUp',
|
459 | /**
|
460 | * Fired after clicking right mouse button on a cell or row/column header.
|
461 | *
|
462 | * For example clicking on the row header of cell (0, 0) results with `afterOnCellContextMenu` called
|
463 | * with coordinates `{row: 0, col: -1}`.
|
464 | *
|
465 | * @event Hooks#afterOnCellContextMenu
|
466 | * @since 4.1.0
|
467 | * @param {Event} event `contextmenu` event object.
|
468 | * @param {CellCoords} coords Coordinates object containing the visual row and visual column indexes of the clicked cell.
|
469 | * @param {HTMLTableCellElement} TD Cell's TD (or TH) element.
|
470 | */
|
471 | 'afterOnCellContextMenu',
|
472 | /**
|
473 | * Fired after hovering a cell or row/column header with the mouse cursor. In case the row/column header was
|
474 | * hovered, the index is negative.
|
475 | *
|
476 | * For example, hovering over the row header of cell (0, 0) results with `afterOnCellMouseOver` called
|
477 | * with coords `{row: 0, col: -1}`.
|
478 | *
|
479 | * @event Hooks#afterOnCellMouseOver
|
480 | * @param {Event} event `mouseover` event object.
|
481 | * @param {CellCoords} coords Hovered cell's visual coordinate object.
|
482 | * @param {HTMLTableCellElement} TD Cell's TD (or TH) element.
|
483 | */
|
484 | 'afterOnCellMouseOver',
|
485 | /**
|
486 | * Fired after leaving a cell or row/column header with the mouse cursor.
|
487 | *
|
488 | * @event Hooks#afterOnCellMouseOut
|
489 | * @param {Event} event `mouseout` event object.
|
490 | * @param {CellCoords} coords Leaved cell's visual coordinate object.
|
491 | * @param {HTMLTableCellElement} TD Cell's TD (or TH) element.
|
492 | */
|
493 | 'afterOnCellMouseOut',
|
494 | /**
|
495 | * Fired after one or more columns are removed.
|
496 | *
|
497 | * @event Hooks#afterRemoveCol
|
498 | * @param {number} index Visual index of starter column.
|
499 | * @param {number} amount An amount of removed columns.
|
500 | * @param {number[]} physicalColumns An array of physical columns removed from the data source.
|
501 | * @param {string} [source] String that identifies source of hook call
|
502 | * ([list of all available sources](@/guides/getting-started/events-and-hooks/events-and-hooks.md#definition-for-source-argument)).
|
503 | */
|
504 | 'afterRemoveCol',
|
505 | /**
|
506 | * Fired after one or more rows are removed.
|
507 | *
|
508 | * @event Hooks#afterRemoveRow
|
509 | * @param {number} index Visual index of starter row.
|
510 | * @param {number} amount An amount of removed rows.
|
511 | * @param {number[]} physicalRows An array of physical rows removed from the data source.
|
512 | * @param {string} [source] String that identifies source of hook call
|
513 | * ([list of all available sources](@/guides/getting-started/events-and-hooks/events-and-hooks.md#definition-for-source-argument)).
|
514 | */
|
515 | 'afterRemoveRow',
|
516 | /**
|
517 | * Fired before starting rendering the cell.
|
518 | *
|
519 | * @event Hooks#beforeRenderer
|
520 | * @param {HTMLTableCellElement} TD Currently rendered cell's TD element.
|
521 | * @param {number} row Visual row index.
|
522 | * @param {number} column Visual column index.
|
523 | * @param {string|number} prop Column property name or a column index, if datasource is an array of arrays.
|
524 | * @param {*} value Value of the rendered cell.
|
525 | * @param {object} cellProperties Object containing the cell's properties.
|
526 | */
|
527 | 'beforeRenderer',
|
528 | /**
|
529 | * Fired after finishing rendering the cell (after the renderer finishes).
|
530 | *
|
531 | * @event Hooks#afterRenderer
|
532 | * @param {HTMLTableCellElement} TD Currently rendered cell's TD element.
|
533 | * @param {number} row Visual row index.
|
534 | * @param {number} column Visual column index.
|
535 | * @param {string|number} prop Column property name or a column index, if datasource is an array of arrays.
|
536 | * @param {*} value Value of the rendered cell.
|
537 | * @param {object} cellProperties Object containing the cell's properties.
|
538 | */
|
539 | 'afterRenderer',
|
540 | /**
|
541 | * Fired after the order of rows has changed.
|
542 | * This hook is fired by changing row indexes of any type supported by the {@link IndexMapper}.
|
543 | *
|
544 | * @event Hooks#afterRowSequenceChange
|
545 | * @param {'init'|'remove'|'insert'|'move'|'update'} [source] A string that indicates what caused the change to the order of rows.
|
546 | */
|
547 | 'afterRowSequenceChange',
|
548 | /**
|
549 | * Fired before the vertical viewport scroll. Triggered by the [`scrollViewportTo()`](@/api/core.md#scrollviewportto)
|
550 | * method or table internals.
|
551 | *
|
552 | * @since 14.0.0
|
553 | * @event Hooks#beforeViewportScrollVertically
|
554 | * @param {number} visualRow Visual row index.
|
555 | * @returns {number | boolean} Returns modified row index (or the same as passed in the method argument) to which
|
556 | * the viewport will be scrolled. If the returned value is `false`, the scrolling will be canceled.
|
557 | */
|
558 | 'beforeViewportScrollVertically',
|
559 | /**
|
560 | * Fired before the horizontal viewport scroll. Triggered by the [`scrollViewportTo()`](@/api/core.md#scrollviewportto)
|
561 | * method or table internals.
|
562 | *
|
563 | * @since 14.0.0
|
564 | * @event Hooks#beforeViewportScrollHorizontally
|
565 | * @param {number} visualColumn Visual column index.
|
566 | * @returns {number | boolean} Returns modified column index (or the same as passed in the method argument) to which
|
567 | * the viewport will be scrolled. If the returned value is `false`, the scrolling will be canceled.
|
568 | */
|
569 | 'beforeViewportScrollHorizontally',
|
570 | /**
|
571 | * Fired before the vertical or horizontal viewport scroll. Triggered by the [`scrollViewportTo()`](@/api/core.md#scrollviewportto)
|
572 | * method or table internals.
|
573 | *
|
574 | * @since 14.0.0
|
575 | * @event Hooks#beforeViewportScroll
|
576 | */
|
577 | 'beforeViewportScroll',
|
578 | /**
|
579 | * Fired after the horizontal scroll event.
|
580 | *
|
581 | * @event Hooks#afterScrollHorizontally
|
582 | */
|
583 | 'afterScrollHorizontally',
|
584 | /**
|
585 | * Fired after the vertical scroll event.
|
586 | *
|
587 | * @event Hooks#afterScrollVertically
|
588 | */
|
589 | 'afterScrollVertically',
|
590 | /**
|
591 | * Fired after the vertical or horizontal scroll event.
|
592 | *
|
593 | * @since 14.0.0
|
594 | * @event Hooks#afterScroll
|
595 | */
|
596 | 'afterScroll',
|
597 | /**
|
598 | * Fired after one or more cells are selected (e.g. during mouse move).
|
599 | *
|
600 | * @event Hooks#afterSelection
|
601 | * @param {number} row Selection start visual row index.
|
602 | * @param {number} column Selection start visual column index.
|
603 | * @param {number} row2 Selection end visual row index.
|
604 | * @param {number} column2 Selection end visual column index.
|
605 | * @param {object} preventScrolling A reference to the observable object with the `value` property.
|
606 | * Property `preventScrolling.value` expects a boolean value that
|
607 | * Handsontable uses to control scroll behavior after selection.
|
608 | * @param {number} selectionLayerLevel The number which indicates what selection layer is currently modified.
|
609 | * @example
|
610 | * ::: only-for javascript
|
611 | * ```js
|
612 | * new Handsontable(element, {
|
613 | * afterSelection: (row, column, row2, column2, preventScrolling, selectionLayerLevel) => {
|
614 | * // If set to `false` (default): when cell selection is outside the viewport,
|
615 | * // Handsontable scrolls the viewport to cell selection's end corner.
|
616 | * // If set to `true`: when cell selection is outside the viewport,
|
617 | * // Handsontable doesn't scroll to cell selection's end corner.
|
618 | * preventScrolling.value = true;
|
619 | * }
|
620 | * })
|
621 | * ```
|
622 | * :::
|
623 | *
|
624 | * ::: only-for react
|
625 | * ```jsx
|
626 | * <HotTable
|
627 | * afterSelection={(row, column, row2, column2, preventScrolling, selectionLayerLevel) => {
|
628 | * // If set to `false` (default): when cell selection is outside the viewport,
|
629 | * // Handsontable scrolls the viewport to cell selection's end corner.
|
630 | * // If set to `true`: when cell selection is outside the viewport,
|
631 | * // Handsontable doesn't scroll to cell selection's end corner.
|
632 | * preventScrolling.value = true;
|
633 | * }}
|
634 | * />
|
635 | * ```
|
636 | * :::
|
637 | */
|
638 | 'afterSelection',
|
639 | /**
|
640 | * Fired after one or more cells are selected.
|
641 | *
|
642 | * The `prop` and `prop2` arguments represent the source object property name instead of the column number.
|
643 | *
|
644 | * @event Hooks#afterSelectionByProp
|
645 | * @param {number} row Selection start visual row index.
|
646 | * @param {string} prop Selection start data source object property name.
|
647 | * @param {number} row2 Selection end visual row index.
|
648 | * @param {string} prop2 Selection end data source object property name.
|
649 | * @param {object} preventScrolling A reference to the observable object with the `value` property.
|
650 | * Property `preventScrolling.value` expects a boolean value that
|
651 | * Handsontable uses to control scroll behavior after selection.
|
652 | * @param {number} selectionLayerLevel The number which indicates what selection layer is currently modified.
|
653 | * @example
|
654 | * ```js
|
655 | * ::: only-for javascript
|
656 | * new Handsontable(element, {
|
657 | * afterSelectionByProp: (row, column, row2, column2, preventScrolling, selectionLayerLevel) => {
|
658 | * // setting if prevent scrolling after selection
|
659 | * preventScrolling.value = true;
|
660 | * }
|
661 | * })
|
662 | * ```
|
663 | * :::
|
664 | *
|
665 | * ::: only-for react
|
666 | * ```jsx
|
667 | * <HotTable
|
668 | * afterSelectionByProp={(row, column, row2, column2, preventScrolling, selectionLayerLevel) => {
|
669 | * // setting if prevent scrolling after selection
|
670 | * preventScrolling.value = true;
|
671 | * }}
|
672 | * />
|
673 | * ```
|
674 | * :::
|
675 | */
|
676 | 'afterSelectionByProp',
|
677 | /**
|
678 | * Fired after one or more cells are selected (e.g. on mouse up).
|
679 | *
|
680 | * @event Hooks#afterSelectionEnd
|
681 | * @param {number} row Selection start visual row index.
|
682 | * @param {number} column Selection start visual column index.
|
683 | * @param {number} row2 Selection end visual row index.
|
684 | * @param {number} column2 Selection end visual column index.
|
685 | * @param {number} selectionLayerLevel The number which indicates what selection layer is currently modified.
|
686 | */
|
687 | 'afterSelectionEnd',
|
688 | /**
|
689 | * Fired after one or more cells are selected (e.g. on mouse up).
|
690 | *
|
691 | * The `prop` and `prop2` arguments represent the source object property name instead of the column number.
|
692 | *
|
693 | * @event Hooks#afterSelectionEndByProp
|
694 | * @param {number} row Selection start visual row index.
|
695 | * @param {string} prop Selection start data source object property index.
|
696 | * @param {number} row2 Selection end visual row index.
|
697 | * @param {string} prop2 Selection end data source object property index.
|
698 | * @param {number} selectionLayerLevel The number which indicates what selection layer is currently modified.
|
699 | */
|
700 | 'afterSelectionEndByProp',
|
701 | /**
|
702 | * Fired after the focus position within a selected range is changed.
|
703 | *
|
704 | * @since 14.3.0
|
705 | * @event Hooks#afterSelectionFocusSet
|
706 | * @param {number} row The focus visual row index position.
|
707 | * @param {number} column The focus visual column index position.
|
708 | * @param {object} preventScrolling A reference to the observable object with the `value` property.
|
709 | * Property `preventScrolling.value` expects a boolean value that
|
710 | * Handsontable uses to control scroll behavior after selection.
|
711 | * @example
|
712 | * ```js
|
713 | * ::: only-for javascript
|
714 | * new Handsontable(element, {
|
715 | * afterSelectionFocusSet: (row, column, preventScrolling) => {
|
716 | * // If set to `false` (default): when focused cell selection is outside the viewport,
|
717 | * // Handsontable scrolls the viewport to that cell.
|
718 | * // If set to `true`: when focused cell selection is outside the viewport,
|
719 | * // Handsontable doesn't scroll the viewport.
|
720 | * preventScrolling.value = true;
|
721 | * }
|
722 | * })
|
723 | * ```
|
724 | * :::
|
725 | *
|
726 | * ::: only-for react
|
727 | * ```jsx
|
728 | * <HotTable
|
729 | * afterSelectionFocusSet={(row, column, preventScrolling) => {
|
730 | * // If set to `false` (default): when focused cell selection is outside the viewport,
|
731 | * // Handsontable scrolls the viewport to that cell.
|
732 | * // If set to `true`: when focused cell selection is outside the viewport,
|
733 | * // Handsontable doesn't scroll the viewport.
|
734 | * preventScrolling.value = true;
|
735 | * }}
|
736 | * />
|
737 | * ```
|
738 | * :::
|
739 | */
|
740 | 'afterSelectionFocusSet',
|
741 | /**
|
742 | * Fired before one or more columns are selected (e.g. During mouse header click or {@link Core#selectColumns} API call).
|
743 | *
|
744 | * @since 14.0.0
|
745 | * @event Hooks#beforeSelectColumns
|
746 | * @param {CellCoords} from Selection start coords object.
|
747 | * @param {CellCoords} to Selection end coords object.
|
748 | * @param {CellCoords} highlight Selection cell focus coords object.
|
749 | * @example
|
750 | * ::: only-for javascript
|
751 | * ```js
|
752 | * new Handsontable(element, {
|
753 | * beforeSelectColumns: (from, to, highlight) => {
|
754 | * // Extend the column selection by one column left and one column right.
|
755 | * from.col = Math.max(from.col - 1, 0);
|
756 | * to.col = Math.min(to.col + 1, this.countCols() - 1);
|
757 | * }
|
758 | * })
|
759 | * ```
|
760 | * :::
|
761 | *
|
762 | * ::: only-for react
|
763 | * ```jsx
|
764 | * <HotTable
|
765 | * beforeSelectColumns={(from, to, highlight) => {
|
766 | * // Extend the column selection by one column left and one column right.
|
767 | * from.col = Math.max(from.col - 1, 0);
|
768 | * to.col = Math.min(to.col + 1, this.countCols() - 1);
|
769 | * }}
|
770 | * />
|
771 | * ```
|
772 | * :::
|
773 | */
|
774 | 'beforeSelectColumns',
|
775 | /**
|
776 | * Fired after one or more columns are selected (e.g. during mouse header click or {@link Core#selectColumns} API call).
|
777 | *
|
778 | * @since 14.0.0
|
779 | * @event Hooks#afterSelectColumns
|
780 | * @param {CellCoords} from Selection start coords object.
|
781 | * @param {CellCoords} to Selection end coords object.
|
782 | * @param {CellCoords} highlight Selection cell focus coords object.
|
783 | */
|
784 | 'afterSelectColumns',
|
785 | /**
|
786 | * Fired before one or more rows are selected (e.g. during mouse header click or {@link Core#selectRows} API call).
|
787 | *
|
788 | * @since 14.0.0
|
789 | * @event Hooks#beforeSelectRows
|
790 | * @param {CellCoords} from Selection start coords object.
|
791 | * @param {CellCoords} to Selection end coords object.
|
792 | * @param {CellCoords} highlight Selection cell focus coords object.
|
793 | * @example
|
794 | * ::: only-for javascript
|
795 | * ```js
|
796 | * new Handsontable(element, {
|
797 | * beforeSelectRows: (from, to, highlight) => {
|
798 | * // Extend the row selection by one row up and one row bottom more.
|
799 | * from.row = Math.max(from.row - 1, 0);
|
800 | * to.row = Math.min(to.row + 1, this.countRows() - 1);
|
801 | * }
|
802 | * })
|
803 | * ```
|
804 | * :::
|
805 | *
|
806 | * ::: only-for react
|
807 | * ```jsx
|
808 | * <HotTable
|
809 | * beforeSelectRows={(from, to, highlight) => {
|
810 | * // Extend the row selection by one row up and one row bottom more.
|
811 | * from.row = Math.max(from.row - 1, 0);
|
812 | * to.row = Math.min(to.row + 1, this.countRows() - 1);
|
813 | * }}
|
814 | * />
|
815 | * ```
|
816 | * :::
|
817 | */
|
818 | 'beforeSelectRows',
|
819 | /**
|
820 | * Fired after one or more rows are selected (e.g. during mouse header click or {@link Core#selectRows} API call).
|
821 | *
|
822 | * @since 14.0.0
|
823 | * @event Hooks#afterSelectRows
|
824 | * @param {CellCoords} from Selection start coords object.
|
825 | * @param {CellCoords} to Selection end coords object.
|
826 | * @param {CellCoords} highlight Selection cell focus coords object.
|
827 | */
|
828 | 'afterSelectRows',
|
829 | /**
|
830 | * Fired after cell meta is changed.
|
831 | *
|
832 | * @event Hooks#afterSetCellMeta
|
833 | * @param {number} row Visual row index.
|
834 | * @param {number} column Visual column index.
|
835 | * @param {string} key The updated meta key.
|
836 | * @param {*} value The updated meta value.
|
837 | */
|
838 | 'afterSetCellMeta',
|
839 | /**
|
840 | * Fired after cell meta is removed.
|
841 | *
|
842 | * @event Hooks#afterRemoveCellMeta
|
843 | * @param {number} row Visual row index.
|
844 | * @param {number} column Visual column index.
|
845 | * @param {string} key The removed meta key.
|
846 | * @param {*} value Value which was under removed key of cell meta.
|
847 | */
|
848 | 'afterRemoveCellMeta',
|
849 | /**
|
850 | * Fired after cell data was changed.
|
851 | *
|
852 | * @event Hooks#afterSetDataAtCell
|
853 | * @param {Array} changes An array of changes in format `[[row, column, oldValue, value], ...]`.
|
854 | * @param {string} [source] String that identifies source of hook call
|
855 | * ([list of all available sources](@/guides/getting-started/events-and-hooks/events-and-hooks.md#definition-for-source-argument)).
|
856 | */
|
857 | 'afterSetDataAtCell',
|
858 | /**
|
859 | * Fired after cell data was changed.
|
860 | * Called only when [`setDataAtRowProp`](@/api/core.md#setdataatrowprop) was executed.
|
861 | *
|
862 | * @event Hooks#afterSetDataAtRowProp
|
863 | * @param {Array} changes An array of changes in format `[[row, prop, oldValue, value], ...]`.
|
864 | * @param {string} [source] String that identifies source of hook call
|
865 | * ([list of all available sources](@/guides/getting-started/events-and-hooks/events-and-hooks.md#definition-for-source-argument)).
|
866 | */
|
867 | 'afterSetDataAtRowProp',
|
868 | /**
|
869 | * Fired after cell source data was changed.
|
870 | *
|
871 | * @event Hooks#afterSetSourceDataAtCell
|
872 | * @since 8.0.0
|
873 | * @param {Array} changes An array of changes in format `[[row, column, oldValue, value], ...]`.
|
874 | * @param {string} [source] String that identifies source of hook call.
|
875 | */
|
876 | 'afterSetSourceDataAtCell',
|
877 | /**
|
878 | * Fired after calling the [`updateSettings`](@/api/core.md#updatesettings) method.
|
879 | *
|
880 | * @event Hooks#afterUpdateSettings
|
881 | * @param {object} newSettings New settings object.
|
882 | */
|
883 | 'afterUpdateSettings',
|
884 | /**
|
885 | * @description
|
886 | * A plugin hook executed after validator function, only if validator function is defined.
|
887 | * Validation result is the first parameter. This can be used to determinate if validation passed successfully or not.
|
888 | *
|
889 | * __Returning false from the callback will mark the cell as invalid__.
|
890 | *
|
891 | * @event Hooks#afterValidate
|
892 | * @param {boolean} isValid `true` if valid, `false` if not.
|
893 | * @param {*} value The value in question.
|
894 | * @param {number} row Visual row index.
|
895 | * @param {string|number} prop Property name / visual column index.
|
896 | * @param {string} [source] String that identifies source of hook call
|
897 | * ([list of all available sources](@/guides/getting-started/events-and-hooks/events-and-hooks.md#definition-for-source-argument)).
|
898 | * @returns {undefined | boolean} If `false` the cell will be marked as invalid, `true` otherwise.
|
899 | */
|
900 | 'afterValidate',
|
901 | /**
|
902 | * Fired before successful change of language (when proper language code was set).
|
903 | *
|
904 | * @event Hooks#beforeLanguageChange
|
905 | * @since 0.35.0
|
906 | * @param {string} languageCode New language code.
|
907 | */
|
908 | 'beforeLanguageChange',
|
909 | /**
|
910 | * Fired after successful change of language (when proper language code was set).
|
911 | *
|
912 | * @event Hooks#afterLanguageChange
|
913 | * @since 0.35.0
|
914 | * @param {string} languageCode New language code.
|
915 | */
|
916 | 'afterLanguageChange',
|
917 | /**
|
918 | * Fired by {@link Autofill} plugin before populating the data in the autofill feature. This hook is fired when
|
919 | * {@link Options#fillHandle} option is enabled.
|
920 | *
|
921 | * @event Hooks#beforeAutofill
|
922 | * @param {Array[]} selectionData Data the autofill operation will start from.
|
923 | * @param {CellRange} sourceRange The range values will be filled from.
|
924 | * @param {CellRange} targetRange The range new values will be filled into.
|
925 | * @param {string} direction Declares the direction of the autofill. Possible values: `up`, `down`, `left`, `right`.
|
926 | *
|
927 | * @returns {boolean|Array[]} If false, the operation is cancelled. If array of arrays, the returned data
|
928 | * will be passed into [`populateFromArray`](@/api/core.md#populatefromarray) instead of the default autofill
|
929 | * algorithm's result.
|
930 | */
|
931 | 'beforeAutofill',
|
932 | /**
|
933 | * Fired by {@link Autofill} plugin after populating the data in the autofill feature. This hook is fired when
|
934 | * {@link Options#fillHandle} option is enabled.
|
935 | *
|
936 | * @event Hooks#afterAutofill
|
937 | * @since 8.0.0
|
938 | * @param {Array[]} fillData The data that was used to fill the `targetRange`. If `beforeAutofill` was used
|
939 | * and returned `[[]]`, this will be the same object that was returned from `beforeAutofill`.
|
940 | * @param {CellRange} sourceRange The range values will be filled from.
|
941 | * @param {CellRange} targetRange The range new values will be filled into.
|
942 | * @param {string} direction Declares the direction of the autofill. Possible values: `up`, `down`, `left`, `right`.
|
943 | */
|
944 | 'afterAutofill',
|
945 | /**
|
946 | * Fired before aligning the cell contents.
|
947 | *
|
948 | * @event Hooks#beforeCellAlignment
|
949 | * @param {object} stateBefore An object with class names defining the cell alignment.
|
950 | * @param {CellRange[]} range An array of `CellRange` coordinates where the alignment will be applied.
|
951 | * @param {string} type Type of the alignment - either `horizontal` or `vertical`.
|
952 | * @param {string} alignmentClass String defining the alignment class added to the cell.
|
953 | * Possible values: `htLeft` , `htCenter`, `htRight`, `htJustify`, `htTop`, `htMiddle`, `htBottom`.
|
954 | */
|
955 | 'beforeCellAlignment',
|
956 | /**
|
957 | * Fired before one or more cells are changed.
|
958 | *
|
959 | * Use this hook to silently alter the user's changes before Handsontable re-renders.
|
960 | *
|
961 | * To ignore the user's changes, use a nullified array or return `false`.
|
962 | *
|
963 | * @event Hooks#beforeChange
|
964 | * @param {Array[]} changes 2D array containing information about each of the edited cells `[[row, prop, oldVal, newVal], ...]`. `row` is a visual row index.
|
965 | * @param {string} [source] String that identifies source of hook call
|
966 | * ([list of all available sources](@/guides/getting-started/events-and-hooks/events-and-hooks.md#definition-for-source-argument)).
|
967 | * @returns {undefined | boolean} If `false` all changes were cancelled, `true` otherwise.
|
968 | * @example
|
969 | * ::: only-for javascript
|
970 | * ```js
|
971 | * // to alter a single change, overwrite the value with `changes[i][3]`
|
972 | * new Handsontable(element, {
|
973 | * beforeChange: (changes, source) => {
|
974 | * // [[row, prop, oldVal, newVal], ...]
|
975 | * changes[0][3] = 10;
|
976 | * }
|
977 | * });
|
978 | *
|
979 | * // to ignore a single change, set `changes[i]` to `null`
|
980 | * // or remove `changes[i]` from the array, by using `changes.splice(i, 1)`
|
981 | * new Handsontable(element, {
|
982 | * beforeChange: (changes, source) => {
|
983 | * // [[row, prop, oldVal, newVal], ...]
|
984 | * changes[0] = null;
|
985 | * }
|
986 | * });
|
987 | *
|
988 | * // to ignore all changes, return `false`
|
989 | * // or set the array's length to 0, by using `changes.length = 0`
|
990 | * new Handsontable(element, {
|
991 | * beforeChange: (changes, source) => {
|
992 | * // [[row, prop, oldVal, newVal], ...]
|
993 | * return false;
|
994 | * }
|
995 | * });
|
996 | * ```
|
997 | * :::
|
998 | *
|
999 | * ::: only-for react
|
1000 | * ```jsx
|
1001 | * // to alter a single change, overwrite the desired value with `changes[i][3]`
|
1002 | * <HotTable
|
1003 | * beforeChange={(changes, source) => {
|
1004 | * // [[row, prop, oldVal, newVal], ...]
|
1005 | * changes[0][3] = 10;
|
1006 | * }}
|
1007 | * />
|
1008 | *
|
1009 | * // to ignore a single change, set `changes[i]` to `null`
|
1010 | * // or remove `changes[i]` from the array, by using changes.splice(i, 1).
|
1011 | * <HotTable
|
1012 | * beforeChange={(changes, source) => {
|
1013 | * // [[row, prop, oldVal, newVal], ...]
|
1014 | * changes[0] = null;
|
1015 | * }}
|
1016 | * />
|
1017 | *
|
1018 | * // to ignore all changes, return `false`
|
1019 | * // or set the array's length to 0 (`changes.length = 0`)
|
1020 | * <HotTable
|
1021 | * beforeChange={(changes, source) => {
|
1022 | * // [[row, prop, oldVal, newVal], ...]
|
1023 | * return false;
|
1024 | * }}
|
1025 | * />
|
1026 | * ```
|
1027 | * :::
|
1028 | */
|
1029 | 'beforeChange',
|
1030 | /**
|
1031 | * Fired right before rendering the changes.
|
1032 | *
|
1033 | * @event Hooks#beforeChangeRender
|
1034 | * @param {Array[]} changes Array in form of `[row, prop, oldValue, newValue]`.
|
1035 | * @param {string} [source] String that identifies source of hook call
|
1036 | * ([list of all available sources](@/guides/getting-started/events-and-hooks/events-and-hooks.md#definition-for-source-argument)).
|
1037 | */
|
1038 | 'beforeChangeRender',
|
1039 | /**
|
1040 | * Fired before drawing the borders.
|
1041 | *
|
1042 | * @event Hooks#beforeDrawBorders
|
1043 | * @param {Array} corners Array specifying the current selection borders.
|
1044 | * @param {string} borderClassName Specifies the border class name.
|
1045 | */
|
1046 | 'beforeDrawBorders',
|
1047 | /**
|
1048 | * Fired before getting cell settings.
|
1049 | *
|
1050 | * @event Hooks#beforeGetCellMeta
|
1051 | * @param {number} row Visual row index.
|
1052 | * @param {number} column Visual column index.
|
1053 | * @param {object} cellProperties Object containing the cell's properties.
|
1054 | */
|
1055 | 'beforeGetCellMeta',
|
1056 | /**
|
1057 | * Fired before cell meta is removed.
|
1058 | *
|
1059 | * @event Hooks#beforeRemoveCellMeta
|
1060 | * @param {number} row Visual row index.
|
1061 | * @param {number} column Visual column index.
|
1062 | * @param {string} key The removed meta key.
|
1063 | * @param {*} value Value which is under removed key of cell meta.
|
1064 | * @returns {*|boolean} If false is returned the action is canceled.
|
1065 | */
|
1066 | 'beforeRemoveCellMeta',
|
1067 | /**
|
1068 | * Fired before the Handsontable instance is initiated.
|
1069 | *
|
1070 | * @event Hooks#beforeInit
|
1071 | */
|
1072 | 'beforeInit',
|
1073 | /**
|
1074 | * Fired before the Walkontable instance is initiated.
|
1075 | *
|
1076 | * @event Hooks#beforeInitWalkontable
|
1077 | * @param {object} walkontableConfig Walkontable configuration object.
|
1078 | */
|
1079 | 'beforeInitWalkontable',
|
1080 | /**
|
1081 | * Fired before Handsontable's [`data`](@/api/options.md#data)
|
1082 | * gets modified by the [`loadData()`](@/api/core.md#loaddata) method
|
1083 | * or the [`updateSettings()`](@/api/core.md#updatesettings) method.
|
1084 | *
|
1085 | * Read more:
|
1086 | * - [Binding to data](@/guides/getting-started/binding-to-data/binding-to-data.md)
|
1087 | * - [Saving data](@/guides/getting-started/saving-data/saving-data.md)
|
1088 | *
|
1089 | * @event Hooks#beforeLoadData
|
1090 | * @since 8.0.0
|
1091 | * @param {Array} sourceData An [array of arrays](@/guides/getting-started/binding-to-data/binding-to-data.md#array-of-arrays), or an [array of objects](@/guides/getting-started/binding-to-data/binding-to-data.md#array-of-objects), that contains Handsontable's data
|
1092 | * @param {boolean} initialLoad A flag that indicates whether the data was loaded at Handsontable's initialization (`true`) or later (`false`)
|
1093 | * @param {string} source The source of the call
|
1094 | * @returns {Array} The returned array will be used as Handsontable's new dataset.
|
1095 | */
|
1096 | 'beforeLoadData',
|
1097 | /**
|
1098 | * Fired before the [`updateData()`](@/api/core.md#updatedata) method
|
1099 | * modifies Handsontable's [`data`](@/api/options.md#data).
|
1100 | *
|
1101 | * Read more:
|
1102 | * - [Binding to data](@/guides/getting-started/binding-to-data/binding-to-data.md)
|
1103 | * - [Saving data](@/guides/getting-started/saving-data/saving-data.md)
|
1104 | *
|
1105 | * @event Hooks#beforeUpdateData
|
1106 | * @since 11.1.0
|
1107 | * @param {Array} sourceData An [array of arrays](@/guides/getting-started/binding-to-data/binding-to-data.md#array-of-arrays), or an [array of objects](@/guides/getting-started/binding-to-data/binding-to-data.md#array-of-objects), that contains Handsontable's data
|
1108 | * @param {boolean} initialLoad A flag that indicates whether the data was loaded at Handsontable's initialization (`true`) or later (`false`)
|
1109 | * @param {string} source The source of the call
|
1110 | * @returns {Array} The returned array will be used as Handsontable's new dataset.
|
1111 | */
|
1112 | 'beforeUpdateData',
|
1113 | /**
|
1114 | * Hook fired before `keydown` event is handled. It can be used to stop default key bindings.
|
1115 | *
|
1116 | * __Note__: To prevent default behavior you need to call `false` in your `beforeKeyDown` handler.
|
1117 | *
|
1118 | * @event Hooks#beforeKeyDown
|
1119 | * @param {Event} event Original DOM event.
|
1120 | */
|
1121 | 'beforeKeyDown',
|
1122 | /**
|
1123 | * Fired after the user clicked a cell, but before all the calculations related with it.
|
1124 | *
|
1125 | * @event Hooks#beforeOnCellMouseDown
|
1126 | * @param {Event} event The `mousedown` event object.
|
1127 | * @param {CellCoords} coords Cell coords object containing the visual coordinates of the clicked cell.
|
1128 | * @param {HTMLTableCellElement} TD TD element.
|
1129 | * @param {object} controller An object with properties `row`, `column` and `cell`. Each property contains
|
1130 | * a boolean value that allows or disallows changing the selection for that particular area.
|
1131 | */
|
1132 | 'beforeOnCellMouseDown',
|
1133 | /**
|
1134 | * Fired after the user clicked a cell.
|
1135 | *
|
1136 | * @event Hooks#beforeOnCellMouseUp
|
1137 | * @param {Event} event The `mouseup` event object.
|
1138 | * @param {CellCoords} coords Cell coords object containing the visual coordinates of the clicked cell.
|
1139 | * @param {HTMLTableCellElement} TD TD element.
|
1140 | */
|
1141 | 'beforeOnCellMouseUp',
|
1142 | /**
|
1143 | * Fired after the user clicked a cell, but before all the calculations related with it.
|
1144 | *
|
1145 | * @event Hooks#beforeOnCellContextMenu
|
1146 | * @since 4.1.0
|
1147 | * @param {Event} event The `contextmenu` event object.
|
1148 | * @param {CellCoords} coords Cell coords object containing the visual coordinates of the clicked cell.
|
1149 | * @param {HTMLTableCellElement} TD TD element.
|
1150 | */
|
1151 | 'beforeOnCellContextMenu',
|
1152 | /**
|
1153 | * Fired after the user moved cursor over a cell, but before all the calculations related with it.
|
1154 | *
|
1155 | * @event Hooks#beforeOnCellMouseOver
|
1156 | * @param {Event} event The `mouseover` event object.
|
1157 | * @param {CellCoords} coords CellCoords object containing the visual coordinates of the clicked cell.
|
1158 | * @param {HTMLTableCellElement} TD TD element.
|
1159 | * @param {object} controller An object with properties `row`, `column` and `cell`. Each property contains
|
1160 | * a boolean value that allows or disallows changing the selection for that particular area.
|
1161 | */
|
1162 | 'beforeOnCellMouseOver',
|
1163 | /**
|
1164 | * Fired after the user moved cursor out from a cell, but before all the calculations related with it.
|
1165 | *
|
1166 | * @event Hooks#beforeOnCellMouseOut
|
1167 | * @param {Event} event The `mouseout` event object.
|
1168 | * @param {CellCoords} coords CellCoords object containing the visual coordinates of the leaved cell.
|
1169 | * @param {HTMLTableCellElement} TD TD element.
|
1170 | */
|
1171 | 'beforeOnCellMouseOut',
|
1172 | /**
|
1173 | * Fired before one or more columns are about to be removed.
|
1174 | *
|
1175 | * @event Hooks#beforeRemoveCol
|
1176 | * @param {number} index Visual index of starter column.
|
1177 | * @param {number} amount Amount of columns to be removed.
|
1178 | * @param {number[]} physicalColumns An array of physical columns removed from the data source.
|
1179 | * @param {string} [source] String that identifies source of hook call
|
1180 | * ([list of all available sources](@/guides/getting-started/events-and-hooks/events-and-hooks.md#definition-for-source-argument)).
|
1181 | * @returns {*|boolean} If false is returned the action is canceled.
|
1182 | */
|
1183 | 'beforeRemoveCol',
|
1184 | /**
|
1185 | * Fired when one or more rows are about to be removed.
|
1186 | *
|
1187 | * @event Hooks#beforeRemoveRow
|
1188 | * @param {number} index Visual index of starter row.
|
1189 | * @param {number} amount Amount of rows to be removed.
|
1190 | * @param {number[]} physicalRows An array of physical rows removed from the data source.
|
1191 | * @param {string} [source] String that identifies source of hook call
|
1192 | * ([list of all available sources](@/guides/getting-started/events-and-hooks/events-and-hooks.md#definition-for-source-argument)).
|
1193 | * @returns {*|boolean} If false is returned the action is canceled.
|
1194 | */
|
1195 | 'beforeRemoveRow',
|
1196 | /**
|
1197 | * Fired before Handsontable's view-rendering engine is rendered.
|
1198 | *
|
1199 | * __Note:__ In Handsontable 9.x and earlier, the `beforeViewRender` hook was named `beforeRender`.
|
1200 | *
|
1201 | * @event Hooks#beforeViewRender
|
1202 | * @since 10.0.0
|
1203 | * @param {boolean} isForced If set to `true`, the rendering gets triggered by a change of settings, a change of
|
1204 | * data, or a logic that needs a full Handsontable render cycle.
|
1205 | * If set to `false`, the rendering gets triggered by scrolling or moving the selection.
|
1206 | * @param {object} skipRender Object with `skipRender` property, if it is set to `true ` the next rendering cycle will be skipped.
|
1207 | */
|
1208 | 'beforeViewRender',
|
1209 | /**
|
1210 | * Fired after Handsontable's view-rendering engine is rendered,
|
1211 | * but before redrawing the selection borders and before scroll syncing.
|
1212 | *
|
1213 | * __Note:__ In Handsontable 9.x and earlier, the `afterViewRender` hook was named `afterRender`.
|
1214 | *
|
1215 | * @event Hooks#afterViewRender
|
1216 | * @since 10.0.0
|
1217 | * @param {boolean} isForced If set to `true`, the rendering gets triggered by a change of settings, a change of
|
1218 | * data, or a logic that needs a full Handsontable render cycle.
|
1219 | * If set to `false`, the rendering gets triggered by scrolling or moving the selection.
|
1220 | */
|
1221 | 'afterViewRender',
|
1222 | /**
|
1223 | * Fired before Handsontable's view-rendering engine updates the view.
|
1224 | *
|
1225 | * The `beforeRender` event is fired right after the Handsontable
|
1226 | * business logic is executed and right before the rendering engine starts calling
|
1227 | * the Core logic, renderers, cell meta objects etc. to update the view.
|
1228 | *
|
1229 | * @event Hooks#beforeRender
|
1230 | * @param {boolean} isForced If set to `true`, the rendering gets triggered by a change of settings, a change of
|
1231 | * data, or a logic that needs a full Handsontable render cycle.
|
1232 | * If set to `false`, the rendering gets triggered by scrolling or moving the selection.
|
1233 | */
|
1234 | 'beforeRender',
|
1235 | /**
|
1236 | * Fired after Handsontable's view-rendering engine updates the view.
|
1237 | *
|
1238 | * @event Hooks#afterRender
|
1239 | * @param {boolean} isForced If set to `true`, the rendering gets triggered by a change of settings, a change of
|
1240 | * data, or a logic that needs a full Handsontable render cycle.
|
1241 | * If set to `false`, the rendering gets triggered by scrolling or moving the selection.
|
1242 | */
|
1243 | 'afterRender',
|
1244 | /**
|
1245 | * When the focus position is moved to the next or previous row caused by the {@link Options#autoWrapRow} option
|
1246 | * the hook is triggered.
|
1247 | *
|
1248 | * @since 14.0.0
|
1249 | * @event Hooks#beforeRowWrap
|
1250 | * @param {boolean} isWrapEnabled Tells whether the row wrapping is going to happen.
|
1251 | * There may be situations where the option does not work even though it is enabled.
|
1252 | * This is due to the priority of other options that may block the feature.
|
1253 | * For example, when the {@link Options#minSpareCols} is defined, the {@link Options#autoWrapRow} option is not checked.
|
1254 | * Thus, row wrapping is off.
|
1255 | * @param {CellCoords} newCoords The new focus position. It is an object with keys `row` and `col`, where a value of `-1` indicates a header.
|
1256 | * @param {boolean} isFlipped `true` if the row index was flipped, `false` otherwise.
|
1257 | * Flipped index means that the user reached the last row and the focus is moved to the first row or vice versa.
|
1258 | */
|
1259 | 'beforeRowWrap',
|
1260 | /**
|
1261 | * When the focus position is moved to the next or previous column caused by the {@link Options#autoWrapCol} option
|
1262 | * the hook is triggered.
|
1263 | *
|
1264 | * @since 14.0.0
|
1265 | * @event Hooks#beforeColumnWrap
|
1266 | * @param {boolean} isWrapEnabled Tells whether the column wrapping is going to happen.
|
1267 | * There may be situations where the option does not work even though it is enabled.
|
1268 | * This is due to the priority of other options that may block the feature.
|
1269 | * For example, when the {@link Options#minSpareRows} is defined, the {@link Options#autoWrapCol} option is not checked.
|
1270 | * Thus, column wrapping is off.
|
1271 | * @param {CellCoords} newCoords The new focus position. It is an object with keys `row` and `col`, where a value of `-1` indicates a header.
|
1272 | * @param {boolean} isFlipped `true` if the column index was flipped, `false` otherwise.
|
1273 | * Flipped index means that the user reached the last column and the focus is moved to the first column or vice versa.
|
1274 | */
|
1275 | 'beforeColumnWrap',
|
1276 | /**
|
1277 | * Fired before cell meta is changed.
|
1278 | *
|
1279 | * @event Hooks#beforeSetCellMeta
|
1280 | * @since 8.0.0
|
1281 | * @param {number} row Visual row index.
|
1282 | * @param {number} column Visual column index.
|
1283 | * @param {string} key The updated meta key.
|
1284 | * @param {*} value The updated meta value.
|
1285 | * @returns {boolean|undefined} If false is returned the action is canceled.
|
1286 | */
|
1287 | 'beforeSetCellMeta',
|
1288 | /**
|
1289 | * Fired before setting focus selection.
|
1290 | *
|
1291 | * @since 14.3.0
|
1292 | * @event Hooks#beforeSelectionFocusSet
|
1293 | * @param {CellCoords} coords CellCoords instance.
|
1294 | */
|
1295 | 'beforeSelectionFocusSet',
|
1296 | /**
|
1297 | * Fired before setting range is started but not finished yet.
|
1298 | *
|
1299 | * @event Hooks#beforeSetRangeStartOnly
|
1300 | * @param {CellCoords} coords `CellCoords` instance.
|
1301 | */
|
1302 | 'beforeSetRangeStartOnly',
|
1303 | /**
|
1304 | * Fired before setting range is started.
|
1305 | *
|
1306 | * @event Hooks#beforeSetRangeStart
|
1307 | * @param {CellCoords} coords `CellCoords` instance.
|
1308 | */
|
1309 | 'beforeSetRangeStart',
|
1310 | /**
|
1311 | * Fired before setting range is ended.
|
1312 | *
|
1313 | * @event Hooks#beforeSetRangeEnd
|
1314 | * @param {CellCoords} coords `CellCoords` instance.
|
1315 | */
|
1316 | 'beforeSetRangeEnd',
|
1317 | /**
|
1318 | * Fired before applying selection coordinates to the renderable coordinates for Walkontable (rendering engine).
|
1319 | * It occurs even when cell coordinates remain unchanged and activates during cell selection and drag selection.
|
1320 | * The behavior of Shift+Tab differs from Arrow Left when there's no further movement possible.
|
1321 | *
|
1322 | * @since 14.0.0
|
1323 | * @event Hooks#beforeSelectionHighlightSet
|
1324 | */
|
1325 | 'beforeSelectionHighlightSet',
|
1326 | /**
|
1327 | * Fired before the logic of handling a touch scroll, when user started scrolling on a touch-enabled device.
|
1328 | *
|
1329 | * @event Hooks#beforeTouchScroll
|
1330 | */
|
1331 | 'beforeTouchScroll',
|
1332 | /**
|
1333 | * Fired before cell validation, only if validator function is defined. This can be used to manipulate the value
|
1334 | * of changed cell before it is applied to the validator function.
|
1335 | *
|
1336 | * __Note:__ this will not affect values of changes. This will change value *ONLY* for validation.
|
1337 | *
|
1338 | * @event Hooks#beforeValidate
|
1339 | * @param {*} value Value of the cell.
|
1340 | * @param {number} row Visual row index.
|
1341 | * @param {string|number} prop Property name / column index.
|
1342 | * @param {string} [source] String that identifies source of hook call
|
1343 | * ([list of all available sources](@/guides/getting-started/events-and-hooks/events-and-hooks.md#definition-for-source-argument)).
|
1344 | */
|
1345 | 'beforeValidate',
|
1346 | /**
|
1347 | * Fired before cell value is rendered into the DOM (through renderer function). This can be used to manipulate the
|
1348 | * value which is passed to the renderer without modifying the renderer itself.
|
1349 | *
|
1350 | * @event Hooks#beforeValueRender
|
1351 | * @param {*} value Cell value to render.
|
1352 | * @param {object} cellProperties An object containing the cell properties.
|
1353 | */
|
1354 | 'beforeValueRender',
|
1355 | /**
|
1356 | * Fired after Handsontable instance is constructed (using `new` operator).
|
1357 | *
|
1358 | * @event Hooks#construct
|
1359 | */
|
1360 | 'construct',
|
1361 | /**
|
1362 | * Fired after Handsontable instance is initiated but before table is rendered.
|
1363 | *
|
1364 | * @event Hooks#init
|
1365 | */
|
1366 | 'init',
|
1367 | /**
|
1368 | * Fired when a column header index is about to be modified by a callback function.
|
1369 | *
|
1370 | * @event Hooks#modifyColHeader
|
1371 | * @param {number} column Visual column header index.
|
1372 | */
|
1373 | 'modifyColHeader',
|
1374 | /**
|
1375 | * Fired when a column width is about to be modified by a callback function.
|
1376 | *
|
1377 | * @event Hooks#modifyColWidth
|
1378 | * @param {number} width Current column width.
|
1379 | * @param {number} column Visual column index.
|
1380 | */
|
1381 | 'modifyColWidth',
|
1382 | /**
|
1383 | * Fired when rendering the list of values in the multiple-selection component of the Filters dropdown.
|
1384 | * The hook allows modifying the displayed values in that component.
|
1385 | *
|
1386 | * @since 14.2.0
|
1387 | * @event Hooks#modifyFiltersMultiSelectValue
|
1388 | * @param {object} item The item in the list of values.
|
1389 | * @param {object} meta The cell properties object.
|
1390 | */
|
1391 | 'modifyFiltersMultiSelectValue',
|
1392 | /**
|
1393 | * Fired when focusing a cell or a header element. Allows replacing the element to be focused by returning a
|
1394 | * different HTML element.
|
1395 | *
|
1396 | * @since 14.0.0
|
1397 | * @event Hooks#modifyFocusedElement
|
1398 | * @param {number} row Row index.
|
1399 | * @param {number} column Column index.
|
1400 | * @param {HTMLElement|undefined} focusedElement The element to be focused. `null` for focusedElement is intended when focused cell is hidden.
|
1401 | */
|
1402 | 'modifyFocusedElement',
|
1403 | /**
|
1404 | * Fired when a row header index is about to be modified by a callback function.
|
1405 | *
|
1406 | * @event Hooks#modifyRowHeader
|
1407 | * @param {number} row Visual row header index.
|
1408 | */
|
1409 | 'modifyRowHeader',
|
1410 | /**
|
1411 | * Fired when a row height is about to be modified by a callback function.
|
1412 | *
|
1413 | * @event Hooks#modifyRowHeight
|
1414 | * @param {number} height Row height.
|
1415 | * @param {number} row Visual row index.
|
1416 | */
|
1417 | 'modifyRowHeight',
|
1418 | /**
|
1419 | * Fired when a row height is about to be modified by a callback function. The hook allows to change the row height
|
1420 | * for the specified overlay type.
|
1421 | *
|
1422 | * @since 14.5.0
|
1423 | * @event Hooks#modifyRowHeightByOverlayName
|
1424 | * @param {number} height Row height.
|
1425 | * @param {number} row Visual row index.
|
1426 | * @param {'inline_start'|'top'|'top_inline_start_corner'|'bottom'|'bottom_inline_start_corner'|'master'} overlayName Overlay name.
|
1427 | */
|
1428 | 'modifyRowHeightByOverlayName',
|
1429 | /**
|
1430 | * Fired when a data was retrieved or modified.
|
1431 | *
|
1432 | * @event Hooks#modifyData
|
1433 | * @param {number} row Physical row index.
|
1434 | * @param {number} column Visual column index.
|
1435 | * @param {object} valueHolder Object which contains original value which can be modified by overwriting `.value` property.
|
1436 | * @param {string} ioMode String which indicates for what operation hook is fired (`get` or `set`).
|
1437 | */
|
1438 | 'modifyData',
|
1439 | /**
|
1440 | * Fired when a data was retrieved or modified from the source data set.
|
1441 | *
|
1442 | * @event Hooks#modifySourceData
|
1443 | * @since 8.0.0
|
1444 | * @param {number} row Physical row index.
|
1445 | * @param {number} column Physical column index or property name.
|
1446 | * @param {object} valueHolder Object which contains original value which can be modified by overwriting `.value` property.
|
1447 | * @param {string} ioMode String which indicates for what operation hook is fired (`get` or `set`).
|
1448 | */
|
1449 | 'modifySourceData',
|
1450 | /**
|
1451 | * Fired when a data was retrieved or modified.
|
1452 | *
|
1453 | * @event Hooks#modifyRowData
|
1454 | * @param {number} row Physical row index.
|
1455 | */
|
1456 | 'modifyRowData',
|
1457 | /**
|
1458 | * Used to modify the cell coordinates when using the [`getCell`](@/api/core.md#getcell) method, opening editor, getting value from the editor
|
1459 | * and saving values from the closed editor.
|
1460 | *
|
1461 | * @event Hooks#modifyGetCellCoords
|
1462 | * @since 0.36.0
|
1463 | * @param {number} row Visual row index.
|
1464 | * @param {number} column Visual column index.
|
1465 | * @param {boolean} topmost If set to `true`, it returns the TD element from the topmost overlay. For example,
|
1466 | * if the wanted cell is in the range of fixed rows, it will return a TD element
|
1467 | * from the `top` overlay.
|
1468 | * @returns {undefined|number[]}
|
1469 | */
|
1470 | 'modifyGetCellCoords',
|
1471 | /**
|
1472 | * Used to modify the cell coordinates when the table is activated (going into the listen mode).
|
1473 | *
|
1474 | * @event Hooks#modifyFocusOnTabNavigation
|
1475 | * @since 14.0.0
|
1476 | * @param {'from_above' | 'from_below'} tabActivationDir The browsers Tab navigation direction. Depending on
|
1477 | * whether the user activated the table from the element above or below, another cell can be selected.
|
1478 | * @param {CellCoords} visualCoords The coords that will be used to select a cell.
|
1479 | */
|
1480 | 'modifyFocusOnTabNavigation',
|
1481 | /**
|
1482 | * Allows modify the visual row index that is used to retrieve the row header element (TH) before it's
|
1483 | * highlighted (proper CSS class names are added). Modifying the visual row index allows building a custom
|
1484 | * implementation of the nested headers feature or other features that require highlighting other DOM
|
1485 | * elements than that the rendering engine, by default, would have highlighted.
|
1486 | *
|
1487 | * @event Hooks#beforeHighlightingRowHeader
|
1488 | * @since 8.4.0
|
1489 | * @param {number} row Visual row index.
|
1490 | * @param {number} headerLevel Column header level (0 = most distant to the table).
|
1491 | * @param {object} highlightMeta An object that contains additional information about processed selection.
|
1492 | * @returns {number|undefined}
|
1493 | */
|
1494 | 'beforeHighlightingRowHeader',
|
1495 | /**
|
1496 | * Allows modify the visual column index that is used to retrieve the column header element (TH) before it's
|
1497 | * highlighted (proper CSS class names are added). Modifying the visual column index allows building a custom
|
1498 | * implementation of the nested headers feature or other features that require highlighting other DOM
|
1499 | * elements than that the rendering engine, by default, would have highlighted.
|
1500 | *
|
1501 | * @event Hooks#beforeHighlightingColumnHeader
|
1502 | * @since 8.4.0
|
1503 | * @param {number} column Visual column index.
|
1504 | * @param {number} headerLevel Row header level (0 = most distant to the table).
|
1505 | * @param {object} highlightMeta An object that contains additional information about processed selection.
|
1506 | * @returns {number|undefined}
|
1507 | */
|
1508 | 'beforeHighlightingColumnHeader',
|
1509 | /**
|
1510 | * Fired by {@link PersistentState} plugin, after loading value, saved under given key, from browser local storage.
|
1511 | *
|
1512 | * The `persistentStateLoad` hook is fired even when the {@link Options#persistentState} option is disabled.
|
1513 | *
|
1514 | * @event Hooks#persistentStateLoad
|
1515 | * @param {string} key Key.
|
1516 | * @param {object} valuePlaceholder Object containing the loaded value under `valuePlaceholder.value` (if no value have been saved, `value` key will be undefined).
|
1517 | */
|
1518 | 'persistentStateLoad',
|
1519 | /**
|
1520 | * Fired by {@link PersistentState} plugin after resetting data from local storage. If no key is given, all values associated with table will be cleared.
|
1521 | * This hook is fired when {@link Options#persistentState} option is enabled.
|
1522 | *
|
1523 | * @event Hooks#persistentStateReset
|
1524 | * @param {string} [key] Key.
|
1525 | */
|
1526 | 'persistentStateReset',
|
1527 | /**
|
1528 | * Fired by {@link PersistentState} plugin, after saving value under given key in browser local storage.
|
1529 | *
|
1530 | * The `persistentStateSave` hook is fired even when the {@link Options#persistentState} option is disabled.
|
1531 | *
|
1532 | * @event Hooks#persistentStateSave
|
1533 | * @param {string} key Key.
|
1534 | * @param {Mixed} value Value to save.
|
1535 | */
|
1536 | 'persistentStateSave',
|
1537 | /**
|
1538 | * Fired by {@link ColumnSorting} and {@link MultiColumnSorting} plugins before sorting the column. If you return `false` value inside callback for hook, then sorting
|
1539 | * will be not applied by the Handsontable (useful for server-side sorting).
|
1540 | *
|
1541 | * This hook is fired when {@link Options#columnSorting} or {@link Options#multiColumnSorting} option is enabled.
|
1542 | *
|
1543 | * @event Hooks#beforeColumnSort
|
1544 | * @param {Array} currentSortConfig Current sort configuration (for all sorted columns).
|
1545 | * @param {Array} destinationSortConfigs Destination sort configuration (for all sorted columns).
|
1546 | * @returns {boolean | undefined} If `false` the column will not be sorted, `true` otherwise.
|
1547 | */
|
1548 | 'beforeColumnSort',
|
1549 | /**
|
1550 | * Fired by {@link ColumnSorting} and {@link MultiColumnSorting} plugins after sorting the column. This hook is fired when {@link Options#columnSorting}
|
1551 | * or {@link Options#multiColumnSorting} option is enabled.
|
1552 | *
|
1553 | * @event Hooks#afterColumnSort
|
1554 | * @param {Array} currentSortConfig Current sort configuration (for all sorted columns).
|
1555 | * @param {Array} destinationSortConfigs Destination sort configuration (for all sorted columns).
|
1556 | */
|
1557 | 'afterColumnSort',
|
1558 | /**
|
1559 | * Fired by {@link Autofill} plugin after setting range of autofill. This hook is fired when {@link Options#fillHandle}
|
1560 | * option is enabled.
|
1561 | *
|
1562 | * @event Hooks#modifyAutofillRange
|
1563 | * @param {Array} startArea Array of visual coordinates of the starting point for the drag-down operation (`[startRow, startColumn, endRow, endColumn]`).
|
1564 | * @param {Array} entireArea Array of visual coordinates of the entire area of the drag-down operation (`[startRow, startColumn, endRow, endColumn]`).
|
1565 | */
|
1566 | 'modifyAutofillRange',
|
1567 | /**
|
1568 | * Fired to allow modifying the copyable range with a callback function.
|
1569 | *
|
1570 | * @event Hooks#modifyCopyableRange
|
1571 | * @param {Array[]} copyableRanges Array of objects defining copyable cells.
|
1572 | */
|
1573 | 'modifyCopyableRange',
|
1574 | /**
|
1575 | * Fired by {@link CopyPaste} plugin before copying the values to the clipboard and before clearing values of
|
1576 | * the selected cells. This hook is fired when {@link Options#copyPaste} option is enabled.
|
1577 | *
|
1578 | * @event Hooks#beforeCut
|
1579 | * @param {Array[]} data An array of arrays which contains data to cut.
|
1580 | * @param {object[]} coords An array of objects with ranges of the visual indexes (`startRow`, `startCol`, `endRow`, `endCol`)
|
1581 | * which will be cut out.
|
1582 | * @returns {*} If returns `false` then operation of the cutting out is canceled.
|
1583 | * @example
|
1584 | * ::: only-for javascript
|
1585 | * ```js
|
1586 | * // To disregard a single row, remove it from the array using data.splice(i, 1).
|
1587 | * new Handsontable(element, {
|
1588 | * beforeCut: function(data, coords) {
|
1589 | * // data -> [[1, 2, 3], [4, 5, 6]]
|
1590 | * data.splice(0, 1);
|
1591 | * // data -> [[4, 5, 6]]
|
1592 | * // coords -> [{startRow: 0, startCol: 0, endRow: 1, endCol: 2}]
|
1593 | * }
|
1594 | * });
|
1595 | * // To cancel a cutting action, just return `false`.
|
1596 | * new Handsontable(element, {
|
1597 | * beforeCut: function(data, coords) {
|
1598 | * return false;
|
1599 | * }
|
1600 | * });
|
1601 | * ```
|
1602 | * :::
|
1603 | *
|
1604 | * ::: only-for react
|
1605 | * ```jsx
|
1606 | * // To disregard a single row, remove it from the array using data.splice(i, 1).
|
1607 | * <HotTable
|
1608 | * beforeCut={(data, coords) => {
|
1609 | * // data -> [[1, 2, 3], [4, 5, 6]]
|
1610 | * data.splice(0, 1);
|
1611 | * // data -> [[4, 5, 6]]
|
1612 | * // coords -> [{startRow: 0, startCol: 0, endRow: 1, endCol: 2}]
|
1613 | * }}
|
1614 | * />
|
1615 | * // To cancel a cutting action, just return `false`.
|
1616 | * <HotTable
|
1617 | * beforeCut={(data, coords) => {
|
1618 | * return false;
|
1619 | * }}
|
1620 | * />
|
1621 | * ```
|
1622 | * :::
|
1623 | */
|
1624 | 'beforeCut',
|
1625 | /**
|
1626 | * Fired by {@link CopyPaste} plugin after data was cut out from the table. This hook is fired when
|
1627 | * {@link Options#copyPaste} option is enabled.
|
1628 | *
|
1629 | * @event Hooks#afterCut
|
1630 | * @param {Array[]} data An array of arrays with the cut data.
|
1631 | * @param {object[]} coords An array of objects with ranges of the visual indexes (`startRow`, `startCol`, `endRow`, `endCol`)
|
1632 | * which was cut out.
|
1633 | */
|
1634 | 'afterCut',
|
1635 | /**
|
1636 | * Fired before values are copied to the clipboard.
|
1637 | *
|
1638 | * @event Hooks#beforeCopy
|
1639 | * @param {Array[]} data An array of arrays which contains data to copied.
|
1640 | * @param {object[]} coords An array of objects with ranges of the visual indexes (`startRow`, `startCol`, `endRow`, `endCol`)
|
1641 | * which will copied.
|
1642 | * @param {{ columnHeadersCount: number }} copiedHeadersCount (Since 12.3.0) The number of copied column headers.
|
1643 | * @returns {*} If returns `false` then copying is canceled.
|
1644 | *
|
1645 | * @example
|
1646 | * ::: only-for javascript
|
1647 | * ```js
|
1648 | * // To disregard a single row, remove it from array using data.splice(i, 1).
|
1649 | * ...
|
1650 | * new Handsontable(document.getElementById('example'), {
|
1651 | * beforeCopy: (data, coords) => {
|
1652 | * // data -> [[1, 2, 3], [4, 5, 6]]
|
1653 | * data.splice(0, 1);
|
1654 | * // data -> [[4, 5, 6]]
|
1655 | * // coords -> [{startRow: 0, startCol: 0, endRow: 1, endCol: 2}]
|
1656 | * }
|
1657 | * });
|
1658 | * ...
|
1659 | *
|
1660 | * // To cancel copying, return false from the callback.
|
1661 | * ...
|
1662 | * new Handsontable(document.getElementById('example'), {
|
1663 | * beforeCopy: (data, coords) => {
|
1664 | * return false;
|
1665 | * }
|
1666 | * });
|
1667 | * ...
|
1668 | * ```
|
1669 | * :::
|
1670 | *
|
1671 | * ::: only-for react
|
1672 | * ```jsx
|
1673 | * // To disregard a single row, remove it from array using data.splice(i, 1).
|
1674 | * ...
|
1675 | * <HotTable
|
1676 | * beforeCopy={(data, coords) => {
|
1677 | * // data -> [[1, 2, 3], [4, 5, 6]]
|
1678 | * data.splice(0, 1);
|
1679 | * // data -> [[4, 5, 6]]
|
1680 | * // coords -> [{startRow: 0, startCol: 0, endRow: 1, endCol: 2}]
|
1681 | * }}
|
1682 | * />
|
1683 | * ...
|
1684 | *
|
1685 | * // To cancel copying, return false from the callback.
|
1686 | * ...
|
1687 | * <HotTable
|
1688 | * beforeCopy={(data, coords) => {
|
1689 | * return false;
|
1690 | * }}
|
1691 | * />
|
1692 | * ...
|
1693 | * ```
|
1694 | * :::
|
1695 | */
|
1696 | 'beforeCopy',
|
1697 | /**
|
1698 | * Fired by {@link CopyPaste} plugin after data are pasted into table. This hook is fired when {@link Options#copyPaste}
|
1699 | * option is enabled.
|
1700 | *
|
1701 | * @event Hooks#afterCopy
|
1702 | * @param {Array[]} data An array of arrays which contains the copied data.
|
1703 | * @param {object[]} coords An array of objects with ranges of the visual indexes (`startRow`, `startCol`, `endRow`, `endCol`)
|
1704 | * which was copied.
|
1705 | * @param {{ columnHeadersCount: number }} copiedHeadersCount (Since 12.3.0) The number of copied column headers.
|
1706 | */
|
1707 | 'afterCopy',
|
1708 | /**
|
1709 | * Fired by {@link CopyPaste} plugin before values are pasted into table. This hook is fired when
|
1710 | * {@link Options#copyPaste} option is enabled.
|
1711 | *
|
1712 | * @event Hooks#beforePaste
|
1713 | * @param {Array[]} data An array of arrays which contains data to paste.
|
1714 | * @param {object[]} coords An array of objects with ranges of the visual indexes (`startRow`, `startCol`, `endRow`, `endCol`)
|
1715 | * that correspond to the previously selected area.
|
1716 | * @returns {*} If returns `false` then pasting is canceled.
|
1717 | * @example
|
1718 | * ```js
|
1719 | * ::: only-for javascript
|
1720 | * // To disregard a single row, remove it from array using data.splice(i, 1).
|
1721 | * new Handsontable(example, {
|
1722 | * beforePaste: (data, coords) => {
|
1723 | * // data -> [[1, 2, 3], [4, 5, 6]]
|
1724 | * data.splice(0, 1);
|
1725 | * // data -> [[4, 5, 6]]
|
1726 | * // coords -> [{startRow: 0, startCol: 0, endRow: 1, endCol: 2}]
|
1727 | * }
|
1728 | * });
|
1729 | * // To cancel pasting, return false from the callback.
|
1730 | * new Handsontable(example, {
|
1731 | * beforePaste: (data, coords) => {
|
1732 | * return false;
|
1733 | * }
|
1734 | * });
|
1735 | * ```
|
1736 | * :::
|
1737 | *
|
1738 | * ::: only-for react
|
1739 | * ```jsx
|
1740 | * // To disregard a single row, remove it from array using data.splice(i, 1).
|
1741 | * <HotTable
|
1742 | * beforePaste={(data, coords) => {
|
1743 | * // data -> [[1, 2, 3], [4, 5, 6]]
|
1744 | * data.splice(0, 1);
|
1745 | * // data -> [[4, 5, 6]]
|
1746 | * // coords -> [{startRow: 0, startCol: 0, endRow: 1, endCol: 2}]
|
1747 | * }}
|
1748 | * />
|
1749 | * // To cancel pasting, return false from the callback.
|
1750 | * <HotTable
|
1751 | * beforePaste={(data, coords) => {
|
1752 | * return false;
|
1753 | * }}
|
1754 | * />
|
1755 | * ```
|
1756 | * :::
|
1757 | */
|
1758 | 'beforePaste',
|
1759 | /**
|
1760 | * Fired by {@link CopyPaste} plugin after values are pasted into table. This hook is fired when
|
1761 | * {@link Options#copyPaste} option is enabled.
|
1762 | *
|
1763 | * @event Hooks#afterPaste
|
1764 | * @param {Array[]} data An array of arrays with the pasted data.
|
1765 | * @param {object[]} coords An array of objects with ranges of the visual indexes (`startRow`, `startCol`, `endRow`, `endCol`)
|
1766 | * that correspond to the previously selected area.
|
1767 | */
|
1768 | 'afterPaste',
|
1769 | /**
|
1770 | * Fired by the {@link ManualColumnFreeze} plugin, before freezing a column.
|
1771 | *
|
1772 | * @event Hooks#beforeColumnFreeze
|
1773 | * @since 12.1.0
|
1774 | * @param {number} column The visual index of the column that is going to freeze.
|
1775 | * @param {boolean} freezePerformed If `true`: the column is going to freeze. If `false`: the column is not going to freeze (which might happen if the column is already frozen).
|
1776 | * @returns {boolean|undefined} If `false`: the column is not going to freeze, and the `afterColumnFreeze` hook won't fire.
|
1777 | */
|
1778 | 'beforeColumnFreeze',
|
1779 | /**
|
1780 | * Fired by the {@link ManualColumnFreeze} plugin, right after freezing a column.
|
1781 | *
|
1782 | * @event Hooks#afterColumnFreeze
|
1783 | * @since 12.1.0
|
1784 | * @param {number} column The visual index of the frozen column.
|
1785 | * @param {boolean} freezePerformed If `true`: the column got successfully frozen. If `false`: the column didn't get frozen.
|
1786 | */
|
1787 | 'afterColumnFreeze',
|
1788 | /**
|
1789 | * Fired by {@link ManualColumnMove} plugin before change order of the visual indexes. This hook is fired when
|
1790 | * {@link Options#manualColumnMove} option is enabled.
|
1791 | *
|
1792 | * @event Hooks#beforeColumnMove
|
1793 | * @param {Array} movedColumns Array of visual column indexes to be moved.
|
1794 | * @param {number} finalIndex Visual column index, being a start index for the moved columns.
|
1795 | * Points to where the elements will be placed after the moving action.
|
1796 | * To check visualization of final index please take a look at
|
1797 | * [documentation](@/guides/columns/column-moving/column-moving.md).
|
1798 | * @param {number|undefined} dropIndex Visual column index, being a drop index for the moved columns.
|
1799 | * Points to where we are going to drop the moved elements. To check
|
1800 | * visualization of drop index please take a look at
|
1801 | * [documentation](@/guides/columns/column-moving/column-moving.md).
|
1802 | * It's `undefined` when `dragColumns` function wasn't called.
|
1803 | * @param {boolean} movePossible Indicates if it's possible to move rows to the desired position.
|
1804 | * @returns {undefined | boolean} If `false` the column will not be moved, `true` otherwise.
|
1805 | */
|
1806 | 'beforeColumnMove',
|
1807 | /**
|
1808 | * Fired by {@link ManualColumnMove} plugin after changing order of the visual indexes.
|
1809 | * This hook is fired when {@link Options#manualColumnMove} option is enabled.
|
1810 | *
|
1811 | * @event Hooks#afterColumnMove
|
1812 | * @param {Array} movedColumns Array of visual column indexes to be moved.
|
1813 | * @param {number} finalIndex Visual column index, being a start index for the moved columns.
|
1814 | * Points to where the elements will be placed after the moving action.
|
1815 | * To check visualization of final index please take a look at
|
1816 | * [documentation](@/guides/columns/column-moving/column-moving.md).
|
1817 | * @param {number|undefined} dropIndex Visual column index, being a drop index for the moved columns.
|
1818 | * Points to where we are going to drop the moved elements.
|
1819 | * To check visualization of drop index please take a look at
|
1820 | * [documentation](@/guides/columns/column-moving/column-moving.md).
|
1821 | * It's `undefined` when `dragColumns` function wasn't called.
|
1822 | * @param {boolean} movePossible Indicates if it was possible to move columns to the desired position.
|
1823 | * @param {boolean} orderChanged Indicates if order of columns was changed by move.
|
1824 | */
|
1825 | 'afterColumnMove',
|
1826 | /**
|
1827 | * Fired by the {@link ManualColumnFreeze} plugin, before unfreezing a column.
|
1828 | *
|
1829 | * @event Hooks#beforeColumnUnfreeze
|
1830 | * @since 12.1.0
|
1831 | * @param {number} column The visual index of the column that is going to unfreeze.
|
1832 | * @param {boolean} unfreezePerformed If `true`: the column is going to unfreeze. If `false`: the column is not going to unfreeze (which might happen if the column is already unfrozen).
|
1833 | * @returns {boolean|undefined} If `false`: the column is not going to unfreeze, and the `afterColumnUnfreeze` hook won't fire.
|
1834 | */
|
1835 | 'beforeColumnUnfreeze',
|
1836 | /**
|
1837 | * Fired by the {@link ManualColumnFreeze} plugin, right after unfreezing a column.
|
1838 | *
|
1839 | * @event Hooks#afterColumnUnfreeze
|
1840 | * @since 12.1.0
|
1841 | * @param {number} column The visual index of the unfrozen column.
|
1842 | * @param {boolean} unfreezePerformed If `true`: the column got successfully unfrozen. If `false`: the column didn't get unfrozen.
|
1843 | */
|
1844 | 'afterColumnUnfreeze',
|
1845 | /**
|
1846 | * Fired by {@link ManualRowMove} plugin before changing the order of the visual indexes. This hook is fired when
|
1847 | * {@link Options#manualRowMove} option is enabled.
|
1848 | *
|
1849 | * @event Hooks#beforeRowMove
|
1850 | * @param {Array} movedRows Array of visual row indexes to be moved.
|
1851 | * @param {number} finalIndex Visual row index, being a start index for the moved rows.
|
1852 | * Points to where the elements will be placed after the moving action.
|
1853 | * To check visualization of final index please take a look at
|
1854 | * [documentation](@/guides/rows/row-moving/row-moving.md).
|
1855 | * @param {number|undefined} dropIndex Visual row index, being a drop index for the moved rows.
|
1856 | * Points to where we are going to drop the moved elements.
|
1857 | * To check visualization of drop index please take a look at
|
1858 | * [documentation](@/guides/rows/row-moving/row-moving.md).
|
1859 | * It's `undefined` when `dragRows` function wasn't called.
|
1860 | * @param {boolean} movePossible Indicates if it's possible to move rows to the desired position.
|
1861 | * @returns {*|boolean} If false is returned the action is canceled.
|
1862 | */
|
1863 | 'beforeRowMove',
|
1864 | /**
|
1865 | * Fired by {@link ManualRowMove} plugin after changing the order of the visual indexes.
|
1866 | * This hook is fired when {@link Options#manualRowMove} option is enabled.
|
1867 | *
|
1868 | * @event Hooks#afterRowMove
|
1869 | * @param {Array} movedRows Array of visual row indexes to be moved.
|
1870 | * @param {number} finalIndex Visual row index, being a start index for the moved rows.
|
1871 | * Points to where the elements will be placed after the moving action.
|
1872 | * To check visualization of final index please take a look at
|
1873 | * [documentation](@/guides/rows/row-moving/row-moving.md).
|
1874 | * @param {number|undefined} dropIndex Visual row index, being a drop index for the moved rows.
|
1875 | * Points to where we are going to drop the moved elements.
|
1876 | * To check visualization of drop index please take a look at
|
1877 | * [documentation](@/guides/rows/row-moving/row-moving.md).
|
1878 | * It's `undefined` when `dragRows` function wasn't called.
|
1879 | * @param {boolean} movePossible Indicates if it was possible to move rows to the desired position.
|
1880 | * @param {boolean} orderChanged Indicates if order of rows was changed by move.
|
1881 | */
|
1882 | 'afterRowMove',
|
1883 | /**
|
1884 | * Fired by {@link ManualColumnResize} plugin before rendering the table with modified column sizes. This hook is
|
1885 | * fired when {@link Options#manualColumnResize} option is enabled.
|
1886 | *
|
1887 | * @event Hooks#beforeColumnResize
|
1888 | * @param {number} newSize Calculated new column width.
|
1889 | * @param {number} column Visual index of the resized column.
|
1890 | * @param {boolean} isDoubleClick Flag that determines whether there was a double-click.
|
1891 | * @returns {number} Returns a new column size or `undefined`, if column size should be calculated automatically.
|
1892 | */
|
1893 | 'beforeColumnResize',
|
1894 | /**
|
1895 | * Fired by {@link ManualColumnResize} plugin after rendering the table with modified column sizes. This hook is
|
1896 | * fired when {@link Options#manualColumnResize} option is enabled.
|
1897 | *
|
1898 | * @event Hooks#afterColumnResize
|
1899 | * @param {number} newSize Calculated new column width.
|
1900 | * @param {number} column Visual index of the resized column.
|
1901 | * @param {boolean} isDoubleClick Flag that determines whether there was a double-click.
|
1902 | */
|
1903 | 'afterColumnResize',
|
1904 | /**
|
1905 | * Fired by {@link ManualRowResize} plugin before rendering the table with modified row sizes. This hook is
|
1906 | * fired when {@link Options#manualRowResize} option is enabled.
|
1907 | *
|
1908 | * @event Hooks#beforeRowResize
|
1909 | * @param {number} newSize Calculated new row height.
|
1910 | * @param {number} row Visual index of the resized row.
|
1911 | * @param {boolean} isDoubleClick Flag that determines whether there was a double-click.
|
1912 | * @returns {number|undefined} Returns the new row size or `undefined` if row size should be calculated automatically.
|
1913 | */
|
1914 | 'beforeRowResize',
|
1915 | /**
|
1916 | * Fired by {@link ManualRowResize} plugin after rendering the table with modified row sizes. This hook is
|
1917 | * fired when {@link Options#manualRowResize} option is enabled.
|
1918 | *
|
1919 | * @event Hooks#afterRowResize
|
1920 | * @param {number} newSize Calculated new row height.
|
1921 | * @param {number} row Visual index of the resized row.
|
1922 | * @param {boolean} isDoubleClick Flag that determines whether there was a double-click.
|
1923 | */
|
1924 | 'afterRowResize',
|
1925 | /**
|
1926 | * Fired after getting the column header renderers.
|
1927 | *
|
1928 | * @event Hooks#afterGetColumnHeaderRenderers
|
1929 | * @param {Function[]} renderers An array of the column header renderers.
|
1930 | */
|
1931 | 'afterGetColumnHeaderRenderers',
|
1932 | /**
|
1933 | * Fired after getting the row header renderers.
|
1934 | *
|
1935 | * @event Hooks#afterGetRowHeaderRenderers
|
1936 | * @param {Function[]} renderers An array of the row header renderers.
|
1937 | */
|
1938 | 'afterGetRowHeaderRenderers',
|
1939 | /**
|
1940 | * Fired before applying stretched column width to column.
|
1941 | *
|
1942 | * @event Hooks#beforeStretchingColumnWidth
|
1943 | * @param {number} stretchedWidth Calculated width.
|
1944 | * @param {number} column Visual column index.
|
1945 | * @returns {number|undefined} Returns new width which will be applied to the column element.
|
1946 | */
|
1947 | 'beforeStretchingColumnWidth',
|
1948 | /**
|
1949 | * Fired by the [`Filters`](@/api/filters.md) plugin,
|
1950 | * before a [column filter](@/guides/columns/column-filter/column-filter.md) gets applied.
|
1951 | *
|
1952 | * [`beforeFilter`](#beforefilter) takes two arguments: `conditionsStack` and `previousConditionsStack`, both are
|
1953 | * arrays of objects.
|
1954 | *
|
1955 | * Each object represents one of your [column filters](@/api/filters.md#addcondition),
|
1956 | * and consists of the following properties:
|
1957 | *
|
1958 | * | Property | Possible values | Description |
|
1959 | * | ------------ | ----------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ |
|
1960 | * | `column` | Number | A visual index of the column to which the filter will be applied. |
|
1961 | * | `conditions` | Array of objects | Each object represents one condition. For details, see [`addCondition()`](@/api/filters.md#addcondition). |
|
1962 | * | `operation` | `'conjunction'` \| `'disjunction'` \| `'disjunctionWithExtraCondition'` | An operation to perform on your set of `conditions`. For details, see [`addCondition()`](@/api/filters.md#addcondition). |
|
1963 | *
|
1964 | * An example of the format of the `conditionsStack` argument:
|
1965 | *
|
1966 | * ```js
|
1967 | * [
|
1968 | * {
|
1969 | * column: 2,
|
1970 | * conditions: [
|
1971 | * {name: 'begins_with', args: [['S']]}
|
1972 | * ],
|
1973 | * operation: 'conjunction'
|
1974 | * },
|
1975 | * {
|
1976 | * column: 4,
|
1977 | * conditions: [
|
1978 | * {name: 'not_empty', args: []}
|
1979 | * ],
|
1980 | * operation: 'conjunction'
|
1981 | * },
|
1982 | * ]
|
1983 | * ```
|
1984 | *
|
1985 | * To perform server-side filtering (i.e., to not apply filtering to Handsontable's UI),
|
1986 | * set [`beforeFilter`](#beforefilter) to return `false`:
|
1987 | *
|
1988 | * ```js
|
1989 | * new Handsontable(document.getElementById('example'), {
|
1990 | * beforeFilter: (conditionsStack) => {
|
1991 | * return false;
|
1992 | * }
|
1993 | * });
|
1994 | *```
|
1995 | *
|
1996 | * Read more:
|
1997 | * - [Guides: Column filter](@/guides/columns/column-filter/column-filter.md)
|
1998 | * - [Hooks: `afterFilter`](#afterfilter)
|
1999 | * - [Options: `filters`](@/api/options.md#filters)
|
2000 | * - [Plugins: `Filters`](@/api/filters.md)
|
2001 | * – [Plugin methods: `addCondition()`](@/api/filters.md#addcondition)
|
2002 | *
|
2003 | * @event Hooks#beforeFilter
|
2004 | * @param {object[]} conditionsStack An array of objects with your [column filters](@/api/filters.md#addcondition).
|
2005 | * @param {object[]|null} previousConditionsStack An array of objects with your previous [column filters](@/api/filters.md#addcondition). It can also be `null` if there was no previous filters applied or the conditions did not change between performing the `filter` action.
|
2006 | * @returns {boolean} To perform server-side filtering (i.e., to not apply filtering to Handsontable's UI), return `false`.
|
2007 | */
|
2008 | 'beforeFilter',
|
2009 | /**
|
2010 | * Fired by the [`Filters`](@/api/filters.md) plugin,
|
2011 | * after a [column filter](@/guides/columns/column-filter/column-filter.md) gets applied.
|
2012 | *
|
2013 | * [`afterFilter`](#afterfilter) takes one argument (`conditionsStack`), which is an array of objects.
|
2014 | * Each object represents one of your [column filters](@/api/filters.md#addcondition),
|
2015 | * and consists of the following properties:
|
2016 | *
|
2017 | * | Property | Possible values | Description |
|
2018 | * | ------------ | ----------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ |
|
2019 | * | `column` | Number | A visual index of the column to which the filter was applied. |
|
2020 | * | `conditions` | Array of objects | Each object represents one condition. For details, see [`addCondition()`](@/api/filters.md#addcondition). |
|
2021 | * | `operation` | `'conjunction'` \| `'disjunction'` \| `'disjunctionWithExtraCondition'` | An operation to perform on your set of `conditions`. For details, see [`addCondition()`](@/api/filters.md#addcondition). |
|
2022 | *
|
2023 | * An example of the format of the `conditionsStack` argument:
|
2024 | *
|
2025 | * ```js
|
2026 | * [
|
2027 | * {
|
2028 | * column: 2,
|
2029 | * conditions: [
|
2030 | * {name: 'begins_with', args: [['S']]}
|
2031 | * ],
|
2032 | * operation: 'conjunction'
|
2033 | * },
|
2034 | * {
|
2035 | * column: 4,
|
2036 | * conditions: [
|
2037 | * {name: 'not_empty', args: []}
|
2038 | * ],
|
2039 | * operation: 'conjunction'
|
2040 | * },
|
2041 | * ]
|
2042 | * ```
|
2043 | *
|
2044 | * Read more:
|
2045 | * - [Guides: Column filter](@/guides/columns/column-filter/column-filter.md)
|
2046 | * - [Hooks: `beforeFilter`](#beforefilter)
|
2047 | * - [Options: `filters`](@/api/options.md#filters)
|
2048 | * - [Plugins: `Filters`](@/api/filters.md)
|
2049 | * – [Plugin methods: `addCondition()`](@/api/filters.md#addcondition)
|
2050 | *
|
2051 | * @event Hooks#afterFilter
|
2052 | * @param {object[]} conditionsStack An array of objects with your [column filters](@/api/filters.md#addcondition).
|
2053 | */
|
2054 | 'afterFilter',
|
2055 | /**
|
2056 | * Fired by the {@link Formulas} plugin, when any cell value changes.
|
2057 | *
|
2058 | * Returns an array of objects that contains:
|
2059 | * - The addresses (`sheet`, `row`, `col`) and new values (`newValue`) of the changed cells.
|
2060 | * - The addresses and new values of any cells that had to be recalculated (because their formulas depend on the cells that changed).
|
2061 | *
|
2062 | * This hook gets also fired on Handsontable's initialization, returning the addresses and values of all cells.
|
2063 | *
|
2064 | * Read more:
|
2065 | * - [Guides: Formula calculation](@/guides/formulas/formula-calculation/formula-calculation.md)
|
2066 | * - [HyperFormula documentation: `valuesUpdated`](https://hyperformula.handsontable.com/api/interfaces/listeners.html#valuesupdated)
|
2067 | *
|
2068 | * @since 9.0.0
|
2069 | * @event Hooks#afterFormulasValuesUpdate
|
2070 | * @param {Array} changes The addresses and new values of all the changed and recalculated cells.
|
2071 | */
|
2072 | 'afterFormulasValuesUpdate',
|
2073 | /**
|
2074 | * Fired when a named expression is added to the Formulas' engine instance.
|
2075 | *
|
2076 | * @since 9.0.0
|
2077 | * @event Hooks#afterNamedExpressionAdded
|
2078 | * @param {string} namedExpressionName The name of the added expression.
|
2079 | * @param {Array} changes The values and location of applied changes.
|
2080 | */
|
2081 | 'afterNamedExpressionAdded',
|
2082 | /**
|
2083 | * Fired when a named expression is removed from the Formulas' engine instance.
|
2084 | *
|
2085 | * @since 9.0.0
|
2086 | * @event Hooks#afterNamedExpressionRemoved
|
2087 | * @param {string} namedExpressionName The name of the removed expression.
|
2088 | * @param {Array} changes The values and location of applied changes.
|
2089 | */
|
2090 | 'afterNamedExpressionRemoved',
|
2091 | /**
|
2092 | * Fired when a new sheet is added to the Formulas' engine instance.
|
2093 | *
|
2094 | * @since 9.0.0
|
2095 | * @event Hooks#afterSheetAdded
|
2096 | * @param {string} addedSheetDisplayName The name of the added sheet.
|
2097 | */
|
2098 | 'afterSheetAdded',
|
2099 | /**
|
2100 | * Fired when a sheet in the Formulas' engine instance is renamed.
|
2101 | *
|
2102 | * @since 9.0.0
|
2103 | * @event Hooks#afterSheetRenamed
|
2104 | * @param {string} oldDisplayName The old name of the sheet.
|
2105 | * @param {string} newDisplayName The new name of the sheet.
|
2106 | */
|
2107 | 'afterSheetRenamed',
|
2108 | /**
|
2109 | * Fired when a sheet is removed from the Formulas' engine instance.
|
2110 | *
|
2111 | * @since 9.0.0
|
2112 | * @event Hooks#afterSheetRemoved
|
2113 | * @param {string} removedSheetDisplayName The removed sheet name.
|
2114 | * @param {Array} changes The values and location of applied changes.
|
2115 | */
|
2116 | 'afterSheetRemoved',
|
2117 | /**
|
2118 | * Fired while retrieving the column header height.
|
2119 | *
|
2120 | * @event Hooks#modifyColumnHeaderHeight
|
2121 | */
|
2122 | 'modifyColumnHeaderHeight',
|
2123 | /**
|
2124 | * Fired while retrieving a column header's value.
|
2125 | *
|
2126 | * @since 12.3.0
|
2127 | * @event Hooks#modifyColumnHeaderValue
|
2128 | * @param {string} value A column header value.
|
2129 | * @param {number} visualColumnIndex A visual column index.
|
2130 | * @param {number} [headerLevel=0] Header level index. Accepts positive (`0` to `n`)
|
2131 | * and negative (`-1` to `-n`) values. For positive values, `0` points to the
|
2132 | * topmost header. For negative values, `-1` points to the bottom-most
|
2133 | * header (the header closest to the cells).
|
2134 | * @returns {string} The column header value to be updated.
|
2135 | */
|
2136 | 'modifyColumnHeaderValue',
|
2137 | /**
|
2138 | * Fired by {@link UndoRedo} plugin before the undo action. Contains information about the action that is being undone.
|
2139 | * This hook is fired when {@link Options#undo} option is enabled.
|
2140 | *
|
2141 | * @event Hooks#beforeUndo
|
2142 | * @param {object} action The action object. Contains information about the action being undone. The `actionType`
|
2143 | * property of the object specifies the type of the action in a String format. (e.g. `'remove_row'`).
|
2144 | * @returns {*|boolean} If false is returned the action is canceled.
|
2145 | */
|
2146 | 'beforeUndo',
|
2147 | /**
|
2148 | * Fired by {@link UndoRedo} plugin before changing undo stack.
|
2149 | *
|
2150 | * @event Hooks#beforeUndoStackChange
|
2151 | * @since 8.4.0
|
2152 | * @param {Array} doneActions Stack of actions which may be undone.
|
2153 | * @param {string} [source] String that identifies source of action
|
2154 | * ([list of all available sources](@/guides/getting-started/events-and-hooks/events-and-hooks.md#definition-for-source-argument)).
|
2155 | * @returns {*|boolean} If false is returned the action of changing undo stack is canceled.
|
2156 | */
|
2157 | 'beforeUndoStackChange',
|
2158 | /**
|
2159 | * Fired by {@link UndoRedo} plugin after the undo action. Contains information about the action that is being undone.
|
2160 | * This hook is fired when {@link Options#undo} option is enabled.
|
2161 | *
|
2162 | * @event Hooks#afterUndo
|
2163 | * @param {object} action The action object. Contains information about the action being undone. The `actionType`
|
2164 | * property of the object specifies the type of the action in a String format. (e.g. `'remove_row'`).
|
2165 | */
|
2166 | 'afterUndo',
|
2167 | /**
|
2168 | * Fired by {@link UndoRedo} plugin after changing undo stack.
|
2169 | *
|
2170 | * @event Hooks#afterUndoStackChange
|
2171 | * @since 8.4.0
|
2172 | * @param {Array} doneActionsBefore Stack of actions which could be undone before performing new action.
|
2173 | * @param {Array} doneActionsAfter Stack of actions which can be undone after performing new action.
|
2174 | */
|
2175 | 'afterUndoStackChange',
|
2176 | /**
|
2177 | * Fired by {@link UndoRedo} plugin before the redo action. Contains information about the action that is being redone.
|
2178 | * This hook is fired when {@link Options#undo} option is enabled.
|
2179 | *
|
2180 | * @event Hooks#beforeRedo
|
2181 | * @param {object} action The action object. Contains information about the action being redone. The `actionType`
|
2182 | * property of the object specifies the type of the action in a String format (e.g. `'remove_row'`).
|
2183 | * @returns {*|boolean} If false is returned the action is canceled.
|
2184 | */
|
2185 | 'beforeRedo',
|
2186 | /**
|
2187 | * Fired by {@link UndoRedo} plugin before changing redo stack.
|
2188 | *
|
2189 | * @event Hooks#beforeRedoStackChange
|
2190 | * @since 8.4.0
|
2191 | * @param {Array} undoneActions Stack of actions which may be redone.
|
2192 | */
|
2193 | 'beforeRedoStackChange',
|
2194 | /**
|
2195 | * Fired by {@link UndoRedo} plugin after the redo action. Contains information about the action that is being redone.
|
2196 | * This hook is fired when {@link Options#undo} option is enabled.
|
2197 | *
|
2198 | * @event Hooks#afterRedo
|
2199 | * @param {object} action The action object. Contains information about the action being redone. The `actionType`
|
2200 | * property of the object specifies the type of the action in a String format (e.g. `'remove_row'`).
|
2201 | */
|
2202 | 'afterRedo',
|
2203 | /**
|
2204 | * Fired by {@link UndoRedo} plugin after changing redo stack.
|
2205 | *
|
2206 | * @event Hooks#afterRedoStackChange
|
2207 | * @since 8.4.0
|
2208 | * @param {Array} undoneActionsBefore Stack of actions which could be redone before performing new action.
|
2209 | * @param {Array} undoneActionsAfter Stack of actions which can be redone after performing new action.
|
2210 | */
|
2211 | 'afterRedoStackChange',
|
2212 | /**
|
2213 | * Fired while retrieving the row header width.
|
2214 | *
|
2215 | * @event Hooks#modifyRowHeaderWidth
|
2216 | * @param {number} rowHeaderWidth Row header width.
|
2217 | */
|
2218 | 'modifyRowHeaderWidth',
|
2219 | /**
|
2220 | * Fired when the focus of the selection is being modified (e.g. Moving the focus with the enter/tab keys).
|
2221 | *
|
2222 | * @since 14.3.0
|
2223 | * @event Hooks#modifyTransformFocus
|
2224 | * @param {CellCoords} delta Cell coords object declaring the delta of the new selection relative to the previous one.
|
2225 | */
|
2226 | 'modifyTransformFocus',
|
2227 | /**
|
2228 | * Fired when the start of the selection is being modified (e.g. Moving the selection with the arrow keys).
|
2229 | *
|
2230 | * @event Hooks#modifyTransformStart
|
2231 | * @param {CellCoords} delta Cell coords object declaring the delta of the new selection relative to the previous one.
|
2232 | */
|
2233 | 'modifyTransformStart',
|
2234 | /**
|
2235 | * Fired when the end of the selection is being modified (e.g. Moving the selection with the arrow keys).
|
2236 | *
|
2237 | * @event Hooks#modifyTransformEnd
|
2238 | * @param {CellCoords} delta Cell coords object declaring the delta of the new selection relative to the previous one.
|
2239 | */
|
2240 | 'modifyTransformEnd',
|
2241 | /**
|
2242 | * Fired after the focus of the selection is being modified (e.g. Moving the focus with the enter/tab keys).
|
2243 | *
|
2244 | * @since 14.3.0
|
2245 | * @event Hooks#afterModifyTransformFocus
|
2246 | * @param {CellCoords} coords Coords of the freshly focused cell.
|
2247 | * @param {number} rowTransformDir `-1` if trying to focus a cell with a negative row index. `0` otherwise.
|
2248 | * @param {number} colTransformDir `-1` if trying to focus a cell with a negative column index. `0` otherwise.
|
2249 | */
|
2250 | 'afterModifyTransformFocus',
|
2251 | /**
|
2252 | * Fired after the start of the selection is being modified (e.g. Moving the selection with the arrow keys).
|
2253 | *
|
2254 | * @event Hooks#afterModifyTransformStart
|
2255 | * @param {CellCoords} coords Coords of the freshly selected cell.
|
2256 | * @param {number} rowTransformDir `-1` if trying to select a cell with a negative row index. `0` otherwise.
|
2257 | * @param {number} colTransformDir `-1` if trying to select a cell with a negative column index. `0` otherwise.
|
2258 | */
|
2259 | 'afterModifyTransformStart',
|
2260 | /**
|
2261 | * Fired after the end of the selection is being modified (e.g. Moving the selection with the arrow keys).
|
2262 | *
|
2263 | * @event Hooks#afterModifyTransformEnd
|
2264 | * @param {CellCoords} coords Visual coords of the freshly selected cell.
|
2265 | * @param {number} rowTransformDir `-1` if trying to select a cell with a negative row index. `0` otherwise.
|
2266 | * @param {number} colTransformDir `-1` if trying to select a cell with a negative column index. `0` otherwise.
|
2267 | */
|
2268 | 'afterModifyTransformEnd',
|
2269 | /**
|
2270 | * Fired inside the `viewportRowCalculatorOverride` method. Allows modifying the row calculator parameters.
|
2271 | *
|
2272 | * @event Hooks#afterViewportRowCalculatorOverride
|
2273 | * @param {object} calc The row calculator.
|
2274 | */
|
2275 | 'afterViewportRowCalculatorOverride',
|
2276 | /**
|
2277 | * Fired inside the `viewportColumnCalculatorOverride` method. Allows modifying the row calculator parameters.
|
2278 | *
|
2279 | * @event Hooks#afterViewportColumnCalculatorOverride
|
2280 | * @param {object} calc The row calculator.
|
2281 | */
|
2282 | 'afterViewportColumnCalculatorOverride',
|
2283 | /**
|
2284 | * Fired after initializing all the plugins.
|
2285 | * This hook should be added before Handsontable is initialized.
|
2286 | *
|
2287 | * @event Hooks#afterPluginsInitialized
|
2288 | *
|
2289 | * @example
|
2290 | * ```js
|
2291 | * Handsontable.hooks.add('afterPluginsInitialized', myCallback);
|
2292 | * ```
|
2293 | */
|
2294 | 'afterPluginsInitialized',
|
2295 | /**
|
2296 | * Fired by {@link HiddenRows} plugin before marking the rows as hidden. Fired only if the {@link Options#hiddenRows} option is enabled.
|
2297 | * Returning `false` in the callback will prevent the hiding action from completing.
|
2298 | *
|
2299 | * @event Hooks#beforeHideRows
|
2300 | * @param {Array} currentHideConfig Current hide configuration - a list of hidden physical row indexes.
|
2301 | * @param {Array} destinationHideConfig Destination hide configuration - a list of hidden physical row indexes.
|
2302 | * @param {boolean} actionPossible `true`, if provided row indexes are valid, `false` otherwise.
|
2303 | * @returns {undefined|boolean} If the callback returns `false`, the hiding action will not be completed.
|
2304 | */
|
2305 | 'beforeHideRows',
|
2306 | /**
|
2307 | * Fired by {@link HiddenRows} plugin after marking the rows as hidden. Fired only if the {@link Options#hiddenRows} option is enabled.
|
2308 | *
|
2309 | * @event Hooks#afterHideRows
|
2310 | * @param {Array} currentHideConfig Current hide configuration - a list of hidden physical row indexes.
|
2311 | * @param {Array} destinationHideConfig Destination hide configuration - a list of hidden physical row indexes.
|
2312 | * @param {boolean} actionPossible `true`, if provided row indexes are valid, `false` otherwise.
|
2313 | * @param {boolean} stateChanged `true`, if the action affected any non-hidden rows, `false` otherwise.
|
2314 | */
|
2315 | 'afterHideRows',
|
2316 | /**
|
2317 | * Fired by {@link HiddenRows} plugin before marking the rows as not hidden. Fired only if the {@link Options#hiddenRows} option is enabled.
|
2318 | * Returning `false` in the callback will prevent the row revealing action from completing.
|
2319 | *
|
2320 | * @event Hooks#beforeUnhideRows
|
2321 | * @param {Array} currentHideConfig Current hide configuration - a list of hidden physical row indexes.
|
2322 | * @param {Array} destinationHideConfig Destination hide configuration - a list of hidden physical row indexes.
|
2323 | * @param {boolean} actionPossible `true`, if provided row indexes are valid, `false` otherwise.
|
2324 | * @returns {undefined|boolean} If the callback returns `false`, the revealing action will not be completed.
|
2325 | */
|
2326 | 'beforeUnhideRows',
|
2327 | /**
|
2328 | * Fired by {@link HiddenRows} plugin after marking the rows as not hidden. Fired only if the {@link Options#hiddenRows} option is enabled.
|
2329 | *
|
2330 | * @event Hooks#afterUnhideRows
|
2331 | * @param {Array} currentHideConfig Current hide configuration - a list of hidden physical row indexes.
|
2332 | * @param {Array} destinationHideConfig Destination hide configuration - a list of hidden physical row indexes.
|
2333 | * @param {boolean} actionPossible `true`, if provided row indexes are valid, `false` otherwise.
|
2334 | * @param {boolean} stateChanged `true`, if the action affected any hidden rows, `false` otherwise.
|
2335 | */
|
2336 | 'afterUnhideRows',
|
2337 | /**
|
2338 | * Fired by {@link HiddenColumns} plugin before marking the columns as hidden. Fired only if the {@link Options#hiddenColumns} option is enabled.
|
2339 | * Returning `false` in the callback will prevent the hiding action from completing.
|
2340 | *
|
2341 | * @event Hooks#beforeHideColumns
|
2342 | * @param {Array} currentHideConfig Current hide configuration - a list of hidden physical column indexes.
|
2343 | * @param {Array} destinationHideConfig Destination hide configuration - a list of hidden physical column indexes.
|
2344 | * @param {boolean} actionPossible `true`, if the provided column indexes are valid, `false` otherwise.
|
2345 | * @returns {undefined|boolean} If the callback returns `false`, the hiding action will not be completed.
|
2346 | */
|
2347 | 'beforeHideColumns',
|
2348 | /**
|
2349 | * Fired by {@link HiddenColumns} plugin after marking the columns as hidden. Fired only if the {@link Options#hiddenColumns} option is enabled.
|
2350 | *
|
2351 | * @event Hooks#afterHideColumns
|
2352 | * @param {Array} currentHideConfig Current hide configuration - a list of hidden physical column indexes.
|
2353 | * @param {Array} destinationHideConfig Destination hide configuration - a list of hidden physical column indexes.
|
2354 | * @param {boolean} actionPossible `true`, if the provided column indexes are valid, `false` otherwise.
|
2355 | * @param {boolean} stateChanged `true`, if the action affected any non-hidden columns, `false` otherwise.
|
2356 | */
|
2357 | 'afterHideColumns',
|
2358 | /**
|
2359 | * Fired by {@link HiddenColumns} plugin before marking the columns as not hidden. Fired only if the {@link Options#hiddenColumns} option is enabled.
|
2360 | * Returning `false` in the callback will prevent the column revealing action from completing.
|
2361 | *
|
2362 | * @event Hooks#beforeUnhideColumns
|
2363 | * @param {Array} currentHideConfig Current hide configuration - a list of hidden physical column indexes.
|
2364 | * @param {Array} destinationHideConfig Destination hide configuration - a list of hidden physical column indexes.
|
2365 | * @param {boolean} actionPossible `true`, if the provided column indexes are valid, `false` otherwise.
|
2366 | * @returns {undefined|boolean} If the callback returns `false`, the hiding action will not be completed.
|
2367 | */
|
2368 | 'beforeUnhideColumns',
|
2369 | /**
|
2370 | * Fired by {@link HiddenColumns} plugin after marking the columns as not hidden. Fired only if the {@link Options#hiddenColumns} option is enabled.
|
2371 | *
|
2372 | * @event Hooks#afterUnhideColumns
|
2373 | * @param {Array} currentHideConfig Current hide configuration - a list of hidden physical column indexes.
|
2374 | * @param {Array} destinationHideConfig Destination hide configuration - a list of hidden physical column indexes.
|
2375 | * @param {boolean} actionPossible `true`, if the provided column indexes are valid, `false` otherwise.
|
2376 | * @param {boolean} stateChanged `true`, if the action affected any hidden columns, `false` otherwise.
|
2377 | */
|
2378 | 'afterUnhideColumns',
|
2379 | /**
|
2380 | * Fired by {@link TrimRows} plugin before trimming rows. This hook is fired when {@link Options#trimRows} option is enabled.
|
2381 | *
|
2382 | * @event Hooks#beforeTrimRow
|
2383 | * @param {Array} currentTrimConfig Current trim configuration - a list of trimmed physical row indexes.
|
2384 | * @param {Array} destinationTrimConfig Destination trim configuration - a list of trimmed physical row indexes.
|
2385 | * @param {boolean} actionPossible `true`, if all of the row indexes are withing the bounds of the table, `false` otherwise.
|
2386 | * @returns {undefined|boolean} If the callback returns `false`, the trimming action will not be completed.
|
2387 | */
|
2388 | 'beforeTrimRow',
|
2389 | /**
|
2390 | * Fired by {@link TrimRows} plugin after trimming rows. This hook is fired when {@link Options#trimRows} option is enabled.
|
2391 | *
|
2392 | * @event Hooks#afterTrimRow
|
2393 | * @param {Array} currentTrimConfig Current trim configuration - a list of trimmed physical row indexes.
|
2394 | * @param {Array} destinationTrimConfig Destination trim configuration - a list of trimmed physical row indexes.
|
2395 | * @param {boolean} actionPossible `true`, if all of the row indexes are withing the bounds of the table, `false` otherwise.
|
2396 | * @param {boolean} stateChanged `true`, if the action affected any non-trimmed rows, `false` otherwise.
|
2397 | * @returns {undefined|boolean} If the callback returns `false`, the trimming action will not be completed.
|
2398 | */
|
2399 | 'afterTrimRow',
|
2400 | /**
|
2401 | * Fired by {@link TrimRows} plugin before untrimming rows. This hook is fired when {@link Options#trimRows} option is enabled.
|
2402 | *
|
2403 | * @event Hooks#beforeUntrimRow
|
2404 | * @param {Array} currentTrimConfig Current trim configuration - a list of trimmed physical row indexes.
|
2405 | * @param {Array} destinationTrimConfig Destination trim configuration - a list of trimmed physical row indexes.
|
2406 | * @param {boolean} actionPossible `true`, if all of the row indexes are withing the bounds of the table, `false` otherwise.
|
2407 | * @returns {undefined|boolean} If the callback returns `false`, the untrimming action will not be completed.
|
2408 | */
|
2409 | 'beforeUntrimRow',
|
2410 | /**
|
2411 | * Fired by {@link TrimRows} plugin after untrimming rows. This hook is fired when {@link Options#trimRows} option is enabled.
|
2412 | *
|
2413 | * @event Hooks#afterUntrimRow
|
2414 | * @param {Array} currentTrimConfig Current trim configuration - a list of trimmed physical row indexes.
|
2415 | * @param {Array} destinationTrimConfig Destination trim configuration - a list of trimmed physical row indexes.
|
2416 | * @param {boolean} actionPossible `true`, if all of the row indexes are withing the bounds of the table, `false` otherwise.
|
2417 | * @param {boolean} stateChanged `true`, if the action affected any trimmed rows, `false` otherwise.
|
2418 | * @returns {undefined|boolean} If the callback returns `false`, the untrimming action will not be completed.
|
2419 | */
|
2420 | 'afterUntrimRow',
|
2421 | /**
|
2422 | * Fired by {@link DropdownMenu} plugin before opening the dropdown menu. This hook is fired when {@link Options#dropdownMenu}
|
2423 | * option is enabled.
|
2424 | *
|
2425 | * @event Hooks#beforeDropdownMenuShow
|
2426 | * @param {DropdownMenu} dropdownMenu The `DropdownMenu` instance.
|
2427 | */
|
2428 | 'beforeDropdownMenuShow',
|
2429 | /**
|
2430 | * Fired by {@link DropdownMenu} plugin after opening the Dropdown Menu. This hook is fired when {@link Options#dropdownMenu}
|
2431 | * option is enabled.
|
2432 | *
|
2433 | * @event Hooks#afterDropdownMenuShow
|
2434 | * @param {DropdownMenu} dropdownMenu The `DropdownMenu` instance.
|
2435 | */
|
2436 | 'afterDropdownMenuShow',
|
2437 | /**
|
2438 | * Fired by {@link DropdownMenu} plugin after hiding the Dropdown Menu. This hook is fired when {@link Options#dropdownMenu}
|
2439 | * option is enabled.
|
2440 | *
|
2441 | * @event Hooks#afterDropdownMenuHide
|
2442 | * @param {DropdownMenu} instance The `DropdownMenu` instance.
|
2443 | */
|
2444 | 'afterDropdownMenuHide',
|
2445 | /**
|
2446 | * Fired by {@link NestedRows} plugin before adding a children to the `NestedRows` structure. This hook is fired when
|
2447 | * {@link Options#nestedRows} option is enabled.
|
2448 | *
|
2449 | * @event Hooks#beforeAddChild
|
2450 | * @param {object} parent The parent object.
|
2451 | * @param {object|undefined} element The element added as a child. If `undefined`, a blank child was added.
|
2452 | * @param {number|undefined} index The index within the parent where the new child was added. If `undefined`, the element was added as the last child.
|
2453 | */
|
2454 | 'beforeAddChild',
|
2455 | /**
|
2456 | * Fired by {@link NestedRows} plugin after adding a children to the `NestedRows` structure. This hook is fired when
|
2457 | * {@link Options#nestedRows} option is enabled.
|
2458 | *
|
2459 | * @event Hooks#afterAddChild
|
2460 | * @param {object} parent The parent object.
|
2461 | * @param {object|undefined} element The element added as a child. If `undefined`, a blank child was added.
|
2462 | * @param {number|undefined} index The index within the parent where the new child was added. If `undefined`, the element was added as the last child.
|
2463 | */
|
2464 | 'afterAddChild',
|
2465 | /**
|
2466 | * Fired by {@link NestedRows} plugin before detaching a child from its parent. This hook is fired when
|
2467 | * {@link Options#nestedRows} option is enabled.
|
2468 | *
|
2469 | * @event Hooks#beforeDetachChild
|
2470 | * @param {object} parent An object representing the parent from which the element is to be detached.
|
2471 | * @param {object} element The detached element.
|
2472 | */
|
2473 | 'beforeDetachChild',
|
2474 | /**
|
2475 | * Fired by {@link NestedRows} plugin after detaching a child from its parent. This hook is fired when
|
2476 | * {@link Options#nestedRows} option is enabled.
|
2477 | *
|
2478 | * @event Hooks#afterDetachChild
|
2479 | * @param {object} parent An object representing the parent from which the element was detached.
|
2480 | * @param {object} element The detached element.
|
2481 | * @param {number} finalElementPosition The final row index of the detached element.
|
2482 | */
|
2483 | 'afterDetachChild',
|
2484 | /**
|
2485 | * Fired before the editor is opened and rendered.
|
2486 | *
|
2487 | * @since 14.2.0
|
2488 | * @event Hooks#beforeBeginEditing
|
2489 | * @param {number} row Visual row index of the edited cell.
|
2490 | * @param {number} column Visual column index of the edited cell.
|
2491 | * @param {*} initialValue The initial editor value.
|
2492 | * @param {MouseEvent | KeyboardEvent} event The event which was responsible for opening the editor.
|
2493 | * @param {boolean} fullEditMode `true` if the editor is opened in full edit mode, `false` otherwise.
|
2494 | * Editor opened in full edit mode does not close after pressing Arrow keys.
|
2495 | * @returns {boolean | undefined} If the callback returns `false,` the editor won't be opened after
|
2496 | * the mouse double click or after pressing the Enter key. Returning `undefined` (or other value
|
2497 | * than boolean) will result in default behavior, which disallows opening an editor for non-contiguous
|
2498 | * selection (while pressing Ctrl/Cmd) and for multiple selected cells (while pressing SHIFT).
|
2499 | * Returning `true` removes those restrictions.
|
2500 | */
|
2501 | 'beforeBeginEditing',
|
2502 | /**
|
2503 | * Fired after the editor is opened and rendered.
|
2504 | *
|
2505 | * @event Hooks#afterBeginEditing
|
2506 | * @param {number} row Visual row index of the edited cell.
|
2507 | * @param {number} column Visual column index of the edited cell.
|
2508 | */
|
2509 | 'afterBeginEditing',
|
2510 | /**
|
2511 | * Fired by {@link MergeCells} plugin before cell merging. This hook is fired when {@link Options#mergeCells}
|
2512 | * option is enabled.
|
2513 | *
|
2514 | * @event Hooks#beforeMergeCells
|
2515 | * @param {CellRange} cellRange Selection cell range.
|
2516 | * @param {boolean} [auto=false] `true` if called automatically by the plugin.
|
2517 | */
|
2518 | 'beforeMergeCells',
|
2519 | /**
|
2520 | * Fired by {@link MergeCells} plugin after cell merging. This hook is fired when {@link Options#mergeCells}
|
2521 | * option is enabled.
|
2522 | *
|
2523 | * @event Hooks#afterMergeCells
|
2524 | * @param {CellRange} cellRange Selection cell range.
|
2525 | * @param {object} mergeParent The parent collection of the provided cell range.
|
2526 | * @param {boolean} [auto=false] `true` if called automatically by the plugin.
|
2527 | */
|
2528 | 'afterMergeCells',
|
2529 | /**
|
2530 | * Fired by {@link MergeCells} plugin before unmerging the cells. This hook is fired when {@link Options#mergeCells}
|
2531 | * option is enabled.
|
2532 | *
|
2533 | * @event Hooks#beforeUnmergeCells
|
2534 | * @param {CellRange} cellRange Selection cell range.
|
2535 | * @param {boolean} [auto=false] `true` if called automatically by the plugin.
|
2536 | */
|
2537 | 'beforeUnmergeCells',
|
2538 | /**
|
2539 | * Fired by {@link MergeCells} plugin after unmerging the cells. This hook is fired when {@link Options#mergeCells}
|
2540 | * option is enabled.
|
2541 | *
|
2542 | * @event Hooks#afterUnmergeCells
|
2543 | * @param {CellRange} cellRange Selection cell range.
|
2544 | * @param {boolean} [auto=false] `true` if called automatically by the plugin.
|
2545 | */
|
2546 | 'afterUnmergeCells',
|
2547 | /**
|
2548 | * Fired after the table was switched into listening mode. This allows Handsontable to capture keyboard events and
|
2549 | * respond in the right way.
|
2550 | *
|
2551 | * @event Hooks#afterListen
|
2552 | */
|
2553 | 'afterListen',
|
2554 | /**
|
2555 | * Fired after the table was switched off from the listening mode. This makes the Handsontable inert for any
|
2556 | * keyboard events.
|
2557 | *
|
2558 | * @event Hooks#afterUnlisten
|
2559 | */
|
2560 | 'afterUnlisten',
|
2561 | /**
|
2562 | * Fired after the window was resized or the size of the Handsontable root element was changed.
|
2563 | *
|
2564 | * @event Hooks#afterRefreshDimensions
|
2565 | * @param {{ width: number, height: number }} previousDimensions Previous dimensions of the container.
|
2566 | * @param {{ width: number, height: number }} currentDimensions Current dimensions of the container.
|
2567 | * @param {boolean} stateChanged `true`, if the container was re-render, `false` otherwise.
|
2568 | */
|
2569 | 'afterRefreshDimensions',
|
2570 | /**
|
2571 | * Cancellable hook, called after resizing a window or after detecting size change of the
|
2572 | * Handsontable root element, but before redrawing a table.
|
2573 | *
|
2574 | * @event Hooks#beforeRefreshDimensions
|
2575 | * @param {{ width: number, height: number }} previousDimensions Previous dimensions of the container.
|
2576 | * @param {{ width: number, height: number }} currentDimensions Current dimensions of the container.
|
2577 | * @param {boolean} actionPossible `true`, if current and previous dimensions are different, `false` otherwise.
|
2578 | * @returns {undefined|boolean} If the callback returns `false`, the refresh action will not be completed.
|
2579 | */
|
2580 | 'beforeRefreshDimensions',
|
2581 | /**
|
2582 | * Fired by {@link CollapsibleColumns} plugin before columns collapse. This hook is fired when {@link Options#collapsibleColumns} option is enabled.
|
2583 | *
|
2584 | * @event Hooks#beforeColumnCollapse
|
2585 | * @since 8.0.0
|
2586 | * @param {Array} currentCollapsedColumns Current collapsible configuration - a list of collapsible physical column indexes.
|
2587 | * @param {Array} destinationCollapsedColumns Destination collapsible configuration - a list of collapsible physical column indexes.
|
2588 | * @param {boolean} collapsePossible `true`, if all of the column indexes are withing the bounds of the collapsed sections, `false` otherwise.
|
2589 | * @returns {undefined|boolean} If the callback returns `false`, the collapsing action will not be completed.
|
2590 | */
|
2591 | 'beforeColumnCollapse',
|
2592 | /**
|
2593 | * Fired by {@link CollapsibleColumns} plugin before columns collapse. This hook is fired when {@link Options#collapsibleColumns} option is enabled.
|
2594 | *
|
2595 | * @event Hooks#afterColumnCollapse
|
2596 | * @since 8.0.0
|
2597 | * @param {Array} currentCollapsedColumns Current collapsible configuration - a list of collapsible physical column indexes.
|
2598 | * @param {Array} destinationCollapsedColumns Destination collapsible configuration - a list of collapsible physical column indexes.
|
2599 | * @param {boolean} collapsePossible `true`, if all of the column indexes are withing the bounds of the collapsed sections, `false` otherwise.
|
2600 | * @param {boolean} successfullyCollapsed `true`, if the action affected any non-collapsible column, `false` otherwise.
|
2601 | */
|
2602 | 'afterColumnCollapse',
|
2603 | /**
|
2604 | * Fired by {@link CollapsibleColumns} plugin before columns expand. This hook is fired when {@link Options#collapsibleColumns} option is enabled.
|
2605 | *
|
2606 | * @event Hooks#beforeColumnExpand
|
2607 | * @since 8.0.0
|
2608 | * @param {Array} currentCollapsedColumns Current collapsible configuration - a list of collapsible physical column indexes.
|
2609 | * @param {Array} destinationCollapsedColumns Destination collapsible configuration - a list of collapsible physical column indexes.
|
2610 | * @param {boolean} expandPossible `true`, if all of the column indexes are withing the bounds of the collapsed sections, `false` otherwise.
|
2611 | * @returns {undefined|boolean} If the callback returns `false`, the expanding action will not be completed.
|
2612 | */
|
2613 | 'beforeColumnExpand',
|
2614 | /**
|
2615 | * Fired by {@link CollapsibleColumns} plugin before columns expand. This hook is fired when {@link Options#collapsibleColumns} option is enabled.
|
2616 | *
|
2617 | * @event Hooks#afterColumnExpand
|
2618 | * @since 8.0.0
|
2619 | * @param {Array} currentCollapsedColumns Current collapsible configuration - a list of collapsible physical column indexes.
|
2620 | * @param {Array} destinationCollapsedColumns Destination collapsible configuration - a list of collapsible physical column indexes.
|
2621 | * @param {boolean} expandPossible `true`, if all of the column indexes are withing the bounds of the collapsed sections, `false` otherwise.
|
2622 | * @param {boolean} successfullyExpanded `true`, if the action affected any non-collapsible column, `false` otherwise.
|
2623 | */
|
2624 | 'afterColumnExpand',
|
2625 | /**
|
2626 | * Fired by {@link AutoColumnSize} plugin within SampleGenerator utility.
|
2627 | *
|
2628 | * @event Hooks#modifyAutoColumnSizeSeed
|
2629 | * @since 8.4.0
|
2630 | * @param {string|undefined} seed Seed ID, unique name to categorize samples.
|
2631 | * @param {object} cellProperties Object containing the cell properties.
|
2632 | * @param {*} cellValue Value of the cell.
|
2633 | */
|
2634 | 'modifyAutoColumnSizeSeed'];
|
2635 |
|
2636 | /**
|
2637 | * Template warning message for removed hooks.
|
2638 | *
|
2639 | * @type {string}
|
2640 | */
|
2641 | const REMOVED_MESSAGE = toSingleLine`The plugin hook "[hookName]" was removed in Handsontable [removedInVersion].\x20
|
2642 | Please consult release notes https://github.com/handsontable/handsontable/releases/tag/[removedInVersion] to\x20
|
2643 | learn about the migration path.`;
|
2644 |
|
2645 | /**
|
2646 | * The list of the hooks which are removed from the API. The warning message is printed out in
|
2647 | * the developer console when the hook is used.
|
2648 | *
|
2649 | * The Map key is represented by hook name and its value points to the Handsontable version
|
2650 | * in which it was removed.
|
2651 | *
|
2652 | * @type {Map<string, string>}
|
2653 | */
|
2654 | const REMOVED_HOOKS = new Map([['modifyRow', '8.0.0'], ['modifyCol', '8.0.0'], ['unmodifyRow', '8.0.0'], ['unmodifyCol', '8.0.0'], ['skipLengthCache', '8.0.0'], ['hiddenColumn', '8.0.0'], ['hiddenRow', '8.0.0']]);
|
2655 |
|
2656 | /* eslint-disable jsdoc/require-description-complete-sentence */
|
2657 | /**
|
2658 | * The list of the hooks which are deprecated. The warning message is printed out in
|
2659 | * the developer console when the hook is used.
|
2660 | *
|
2661 | * The Map key is represented by hook name and its value keeps message which whould be
|
2662 | * printed out when the hook is used.
|
2663 | *
|
2664 | * Usage:
|
2665 | * ```js
|
2666 | * ...
|
2667 | * New Map([
|
2668 | * ['beforeColumnExpand', 'The plugin hook "beforeColumnExpand" is deprecated. Use "beforeColumnExpand2" instead.'],
|
2669 | * ])
|
2670 | * ...
|
2671 | * ```
|
2672 | *
|
2673 | *
|
2674 | * @type {Map<string, string>}
|
2675 | */
|
2676 | /* eslint-enable jsdoc/require-description-complete-sentence */
|
2677 | const DEPRECATED_HOOKS = new Map([[]]);
|
2678 | const callbackOrder = new WeakMap();
|
2679 | class Hooks {
|
2680 | static getSingleton() {
|
2681 | return getGlobalSingleton();
|
2682 | }
|
2683 |
|
2684 | /**
|
2685 | * @type {object}
|
2686 | */
|
2687 |
|
2688 | /**
|
2689 | *
|
2690 | */
|
2691 | constructor() {
|
2692 | _defineProperty(this, "globalBucket", void 0);
|
2693 | this.globalBucket = this.createEmptyBucket();
|
2694 | }
|
2695 |
|
2696 | /**
|
2697 | * Returns a new object with empty handlers related to every registered hook name.
|
2698 | *
|
2699 | * @returns {object} The empty bucket object.
|
2700 | *
|
2701 | * @example
|
2702 | * ```js
|
2703 | * Handsontable.hooks.createEmptyBucket();
|
2704 | * // Results:
|
2705 | * {
|
2706 | * ...
|
2707 | * afterCreateCol: [],
|
2708 | * afterCreateRow: [],
|
2709 | * beforeInit: [],
|
2710 | * ...
|
2711 | * }
|
2712 | * ```
|
2713 | */
|
2714 | createEmptyBucket() {
|
2715 | const bucket = Object.create(null);
|
2716 |
|
2717 | // eslint-disable-next-line no-return-assign
|
2718 | arrayEach(REGISTERED_HOOKS, hook => {
|
2719 | bucket[hook] = [];
|
2720 | this.initOrderMap(bucket, hook);
|
2721 | });
|
2722 | return bucket;
|
2723 | }
|
2724 |
|
2725 | /**
|
2726 | * Get hook bucket based on the context of the object or if argument is `undefined`, get the global hook bucket.
|
2727 | *
|
2728 | * @param {object} [context=null] A Handsontable instance.
|
2729 | * @returns {object} Returns a global or Handsontable instance bucket.
|
2730 | */
|
2731 | getBucket() {
|
2732 | let context = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
2733 | if (context) {
|
2734 | if (!context.pluginHookBucket) {
|
2735 | context.pluginHookBucket = this.createEmptyBucket();
|
2736 | }
|
2737 | return context.pluginHookBucket;
|
2738 | }
|
2739 | return this.globalBucket;
|
2740 | }
|
2741 |
|
2742 | /**
|
2743 | * Adds a listener (globally or locally) to a specified hook name.
|
2744 | * If the `context` parameter is provided, the hook will be added only to the instance it references.
|
2745 | * Otherwise, the callback will be used everytime the hook fires on any Handsontable instance.
|
2746 | * You can provide an array of callback functions as the `callback` argument, this way they will all be fired
|
2747 | * once the hook is triggered.
|
2748 | *
|
2749 | * @see Core#addHook
|
2750 | * @param {string} key Hook name.
|
2751 | * @param {Function|Array} callback Callback function or an array of functions.
|
2752 | * @param {object} [context=null] The context for the hook callback to be added - a Handsontable instance or leave empty.
|
2753 | * @param {number} [orderIndex] Order index of the callback.
|
2754 | * If > 0, the callback will be added after the others, for example, with an index of 1, the callback will be added before the ones with an index of 2, 3, etc., but after the ones with an index of 0 and lower.
|
2755 | * If < 0, the callback will be added before the others, for example, with an index of -1, the callback will be added after the ones with an index of -2, -3, etc., but before the ones with an index of 0 and higher.
|
2756 | * If 0 or no order index is provided, the callback will be added between the "negative" and "positive" indexes.
|
2757 | * @returns {Hooks} Instance of Hooks.
|
2758 | *
|
2759 | * @example
|
2760 | * ```js
|
2761 | * // single callback, added locally
|
2762 | * Handsontable.hooks.add('beforeInit', myCallback, hotInstance);
|
2763 | *
|
2764 | * // single callback, added globally
|
2765 | * Handsontable.hooks.add('beforeInit', myCallback);
|
2766 | *
|
2767 | * // multiple callbacks, added locally
|
2768 | * Handsontable.hooks.add('beforeInit', [myCallback, anotherCallback], hotInstance);
|
2769 | *
|
2770 | * // multiple callbacks, added globally
|
2771 | * Handsontable.hooks.add('beforeInit', [myCallback, anotherCallback]);
|
2772 | * ```
|
2773 | */
|
2774 | add(key, callback) {
|
2775 | let context = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
2776 | let orderIndex = arguments.length > 3 ? arguments[3] : undefined;
|
2777 | if (Array.isArray(callback)) {
|
2778 | arrayEach(callback, c => this.add(key, c, context));
|
2779 | } else {
|
2780 | if (REMOVED_HOOKS.has(key)) {
|
2781 | warn(substitute(REMOVED_MESSAGE, {
|
2782 | hookName: key,
|
2783 | removedInVersion: REMOVED_HOOKS.get(key)
|
2784 | }));
|
2785 | }
|
2786 | if (DEPRECATED_HOOKS.has(key)) {
|
2787 | warn(DEPRECATED_HOOKS.get(key));
|
2788 | }
|
2789 | const bucket = this.getBucket(context);
|
2790 | if (typeof bucket[key] === 'undefined') {
|
2791 | this.register(key);
|
2792 | bucket[key] = [];
|
2793 | this.initOrderMap(bucket, key);
|
2794 | }
|
2795 | callback.skip = false;
|
2796 | if (bucket[key].indexOf(callback) === -1) {
|
2797 | // only add a hook if it has not already been added (adding the same hook twice is now silently ignored)
|
2798 | let foundInitialHook = false;
|
2799 | if (callback.initialHook) {
|
2800 | arrayEach(bucket[key], (cb, i) => {
|
2801 | if (cb.initialHook) {
|
2802 | bucket[key][i] = callback;
|
2803 | foundInitialHook = true;
|
2804 | return false;
|
2805 | }
|
2806 | });
|
2807 | }
|
2808 | if (!foundInitialHook) {
|
2809 | bucket[key].push(callback);
|
2810 | }
|
2811 | }
|
2812 | this.setCallbackOrderIndex(bucket, key, callback, orderIndex);
|
2813 | this.orderBucketByOrderIndex(bucket, key);
|
2814 | }
|
2815 | return this;
|
2816 | }
|
2817 |
|
2818 | /**
|
2819 | * Adds a listener to a specified hook. After the hook runs this listener will be automatically removed from the bucket.
|
2820 | *
|
2821 | * @see Core#addHookOnce
|
2822 | * @param {string} key Hook/Event name.
|
2823 | * @param {Function|Array} callback Callback function.
|
2824 | * @param {object} [context=null] A Handsontable instance.
|
2825 | * @param {number} [orderIndex] Order index of the callback.
|
2826 | * If > 0, the callback will be added after the others, for example, with an index of 1, the callback will be added before the ones with an index of 2, 3, etc., but after the ones with an index of 0 and lower.
|
2827 | * If < 0, the callback will be added before the others, for example, with an index of -1, the callback will be added after the ones with an index of -2, -3, etc., but before the ones with an index of 0 and higher.
|
2828 | * If 0 or no order index is provided, the callback will be added between the "negative" and "positive" indexes.
|
2829 | *
|
2830 | * @example
|
2831 | * ```js
|
2832 | * Handsontable.hooks.once('beforeInit', myCallback, hotInstance);
|
2833 | * ```
|
2834 | */
|
2835 | once(key, callback) {
|
2836 | let context = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
2837 | let orderIndex = arguments.length > 3 ? arguments[3] : undefined;
|
2838 | if (Array.isArray(callback)) {
|
2839 | arrayEach(callback, c => this.once(key, c, context));
|
2840 | } else {
|
2841 | callback.runOnce = true;
|
2842 | this.add(key, callback, context, orderIndex);
|
2843 | }
|
2844 | }
|
2845 |
|
2846 | /**
|
2847 | * Removes a listener from a hook with a given name. If the `context` argument is provided, it removes a listener from a local hook assigned to the given Handsontable instance.
|
2848 | *
|
2849 | * @see Core#removeHook
|
2850 | * @param {string} key Hook/Event name.
|
2851 | * @param {Function} callback Callback function (needs the be the function that was previously added to the hook).
|
2852 | * @param {object} [context=null] Handsontable instance.
|
2853 | * @returns {boolean} Returns `true` if hook was removed, `false` otherwise.
|
2854 | *
|
2855 | * @example
|
2856 | * ```js
|
2857 | * Handsontable.hooks.remove('beforeInit', myCallback);
|
2858 | * ```
|
2859 | */
|
2860 | remove(key, callback) {
|
2861 | let context = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
2862 | const bucket = this.getBucket(context);
|
2863 | if (typeof bucket[key] !== 'undefined') {
|
2864 | if (bucket[key].indexOf(callback) >= 0) {
|
2865 | callback.skip = true;
|
2866 | return true;
|
2867 | }
|
2868 | }
|
2869 | return false;
|
2870 | }
|
2871 |
|
2872 | /**
|
2873 | * Checks whether there are any registered listeners for the provided hook name.
|
2874 | * If the `context` parameter is provided, it only checks for listeners assigned to the given Handsontable instance.
|
2875 | *
|
2876 | * @param {string} key Hook name.
|
2877 | * @param {object} [context=null] A Handsontable instance.
|
2878 | * @returns {boolean} `true` for success, `false` otherwise.
|
2879 | */
|
2880 | has(key) {
|
2881 | let context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
2882 | const bucket = this.getBucket(context);
|
2883 | return !!(bucket[key] !== undefined && bucket[key].length);
|
2884 | }
|
2885 |
|
2886 | /**
|
2887 | * Runs all local and global callbacks assigned to the hook identified by the `key` parameter.
|
2888 | * It returns either a return value from the last called callback or the first parameter (`p1`) passed to the `run` function.
|
2889 | *
|
2890 | * @see Core#runHooks
|
2891 | * @param {object} context Handsontable instance.
|
2892 | * @param {string} key Hook/Event name.
|
2893 | * @param {*} [p1] Parameter to be passed as an argument to the callback function.
|
2894 | * @param {*} [p2] Parameter to be passed as an argument to the callback function.
|
2895 | * @param {*} [p3] Parameter to be passed as an argument to the callback function.
|
2896 | * @param {*} [p4] Parameter to be passed as an argument to the callback function.
|
2897 | * @param {*} [p5] Parameter to be passed as an argument to the callback function.
|
2898 | * @param {*} [p6] Parameter to be passed as an argument to the callback function.
|
2899 | * @returns {*} Either a return value from the last called callback or `p1`.
|
2900 | *
|
2901 | * @example
|
2902 | * ```js
|
2903 | * Handsontable.hooks.run(hot, 'beforeInit');
|
2904 | * ```
|
2905 | */
|
2906 | run(context, key, p1, p2, p3, p4, p5, p6) {
|
2907 | {
|
2908 | const globalHandlers = this.globalBucket[key];
|
2909 | const length = globalHandlers ? globalHandlers.length : 0;
|
2910 | let index = 0;
|
2911 | if (length) {
|
2912 | // Do not optimise this loop with arrayEach or arrow function! If you do You'll decrease perf because of GC.
|
2913 | while (index < length) {
|
2914 | if (!globalHandlers[index] || globalHandlers[index].skip) {
|
2915 | index += 1;
|
2916 | /* eslint-disable no-continue */
|
2917 | continue;
|
2918 | }
|
2919 | const res = fastCall(globalHandlers[index], context, p1, p2, p3, p4, p5, p6);
|
2920 | if (res !== undefined) {
|
2921 | // eslint-disable-next-line no-param-reassign
|
2922 | p1 = res;
|
2923 | }
|
2924 | if (globalHandlers[index] && globalHandlers[index].runOnce) {
|
2925 | this.remove(key, globalHandlers[index]);
|
2926 | }
|
2927 | index += 1;
|
2928 | }
|
2929 | }
|
2930 | }
|
2931 | {
|
2932 | const localHandlers = this.getBucket(context)[key];
|
2933 | const length = localHandlers ? localHandlers.length : 0;
|
2934 | let index = 0;
|
2935 | if (length) {
|
2936 | // Do not optimise this loop with arrayEach or arrow function! If you do You'll decrease perf because of GC.
|
2937 | while (index < length) {
|
2938 | if (!localHandlers[index] || localHandlers[index].skip) {
|
2939 | index += 1;
|
2940 | /* eslint-disable no-continue */
|
2941 | continue;
|
2942 | }
|
2943 | const res = fastCall(localHandlers[index], context, p1, p2, p3, p4, p5, p6);
|
2944 | if (res !== undefined) {
|
2945 | // eslint-disable-next-line no-param-reassign
|
2946 | p1 = res;
|
2947 | }
|
2948 | if (localHandlers[index] && localHandlers[index].runOnce) {
|
2949 | this.remove(key, localHandlers[index], context);
|
2950 | }
|
2951 | index += 1;
|
2952 | }
|
2953 | }
|
2954 | }
|
2955 | return p1;
|
2956 | }
|
2957 |
|
2958 | /**
|
2959 | * Destroy all listeners connected to the context. If no context is provided, the global listeners will be destroyed.
|
2960 | *
|
2961 | * @param {object} [context=null] A Handsontable instance.
|
2962 | * @example
|
2963 | * ```js
|
2964 | * // destroy the global listeners
|
2965 | * Handsontable.hooks.destroy();
|
2966 | *
|
2967 | * // destroy the local listeners
|
2968 | * Handsontable.hooks.destroy(hotInstance);
|
2969 | * ```
|
2970 | */
|
2971 | destroy() {
|
2972 | let context = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
2973 | // eslint-disable-next-line no-return-assign
|
2974 | objectEach(this.getBucket(context), (value, key, bucket) => bucket[key].length = 0);
|
2975 | }
|
2976 |
|
2977 | /**
|
2978 | * Registers a hook name (adds it to the list of the known hook names). Used by plugins.
|
2979 | * It is not necessary to call register, but if you use it, your plugin hook will be used returned by
|
2980 | * the `getRegistered` method. (which itself is used in the [demo](@/guides/getting-started/events-and-hooks/events-and-hooks.md)).
|
2981 | *
|
2982 | * @param {string} key The hook name.
|
2983 | *
|
2984 | * @example
|
2985 | * ```js
|
2986 | * Handsontable.hooks.register('myHook');
|
2987 | * ```
|
2988 | */
|
2989 | register(key) {
|
2990 | if (!this.isRegistered(key)) {
|
2991 | REGISTERED_HOOKS.push(key);
|
2992 | }
|
2993 | }
|
2994 |
|
2995 | /**
|
2996 | * Deregisters a hook name (removes it from the list of known hook names).
|
2997 | *
|
2998 | * @param {string} key The hook name.
|
2999 | *
|
3000 | * @example
|
3001 | * ```js
|
3002 | * Handsontable.hooks.deregister('myHook');
|
3003 | * ```
|
3004 | */
|
3005 | deregister(key) {
|
3006 | if (this.isRegistered(key)) {
|
3007 | REGISTERED_HOOKS.splice(REGISTERED_HOOKS.indexOf(key), 1);
|
3008 | }
|
3009 | }
|
3010 |
|
3011 | /**
|
3012 | * Returns a boolean value depending on if a hook by such name has been removed or deprecated.
|
3013 | *
|
3014 | * @param {string} hookName The hook name to check.
|
3015 | * @returns {boolean} Returns `true` if the provided hook name was marked as deprecated or
|
3016 | * removed from API, `false` otherwise.
|
3017 | * @example
|
3018 | * ```js
|
3019 | * Handsontable.hooks.isDeprecated('skipLengthCache');
|
3020 | *
|
3021 | * // Results:
|
3022 | * true
|
3023 | * ```
|
3024 | */
|
3025 | isDeprecated(hookName) {
|
3026 | return DEPRECATED_HOOKS.has(hookName) || REMOVED_HOOKS.has(hookName);
|
3027 | }
|
3028 |
|
3029 | /**
|
3030 | * Returns a boolean depending on if a hook by such name has been registered.
|
3031 | *
|
3032 | * @param {string} hookName The hook name to check.
|
3033 | * @returns {boolean} `true` for success, `false` otherwise.
|
3034 | * @example
|
3035 | * ```js
|
3036 | * Handsontable.hooks.isRegistered('beforeInit');
|
3037 | *
|
3038 | * // Results:
|
3039 | * true
|
3040 | * ```
|
3041 | */
|
3042 | isRegistered(hookName) {
|
3043 | return REGISTERED_HOOKS.indexOf(hookName) >= 0;
|
3044 | }
|
3045 |
|
3046 | /**
|
3047 | * Returns an array of registered hooks.
|
3048 | *
|
3049 | * @returns {Array} An array of registered hooks.
|
3050 | *
|
3051 | * @example
|
3052 | * ```js
|
3053 | * Handsontable.hooks.getRegistered();
|
3054 | *
|
3055 | * // Results:
|
3056 | * [
|
3057 | * ...
|
3058 | * 'beforeInit',
|
3059 | * 'beforeRender',
|
3060 | * 'beforeSetRangeEnd',
|
3061 | * 'beforeDrawBorders',
|
3062 | * 'beforeChange',
|
3063 | * ...
|
3064 | * ]
|
3065 | * ```
|
3066 | */
|
3067 | getRegistered() {
|
3068 | return REGISTERED_HOOKS;
|
3069 | }
|
3070 |
|
3071 | /**
|
3072 | * Sets the order index of the callback in the bucket object.
|
3073 | *
|
3074 | * @private
|
3075 | * @param {object} bucket The bucket object.
|
3076 | * @param {string} key Hook name.
|
3077 | * @param {Function} callback Callback function.
|
3078 | * @param {number|undefined} orderIndex Order index of the callback.
|
3079 | */
|
3080 | setCallbackOrderIndex(bucket, key, callback, orderIndex) {
|
3081 | const normalizedOrderIndex = Number.isInteger(orderIndex) ? orderIndex : 0;
|
3082 | const orderMap = this.getCallbackOrderMap(bucket, key);
|
3083 | orderMap.set(normalizedOrderIndex, [...(orderMap.get(normalizedOrderIndex) || []), callback]);
|
3084 | }
|
3085 |
|
3086 | /**
|
3087 | * Reorders the callbacks in the bucket object by their order index.
|
3088 | *
|
3089 | * @private
|
3090 | * @param {objcet} bucket The bucket object.
|
3091 | * @param {string} key Hook name.
|
3092 | */
|
3093 | orderBucketByOrderIndex(bucket, key) {
|
3094 | const orderMap = this.getCallbackOrderMap(bucket, key);
|
3095 | if (orderMap === undefined || orderMap.size === 0 || orderMap.size === 1 && orderMap.has(0)) {
|
3096 | return;
|
3097 | }
|
3098 | bucket[key] = [...orderMap].sort((a, b) => a[0] - b[0]).flatMap(_ref => {
|
3099 | let [, callbacks] = _ref;
|
3100 | return callbacks;
|
3101 | });
|
3102 | }
|
3103 |
|
3104 | /**
|
3105 | * Extends the bucket object with the order property.
|
3106 | *
|
3107 | * @private
|
3108 | * @param {object} bucket The bucket object.
|
3109 | * @param {string} hook The hook name.
|
3110 | */
|
3111 | initOrderMap(bucket, hook) {
|
3112 | if (!callbackOrder.has(bucket)) {
|
3113 | callbackOrder.set(bucket, []);
|
3114 | }
|
3115 | callbackOrder.get(bucket)[hook] = new Map();
|
3116 | }
|
3117 |
|
3118 | /**
|
3119 | * Returns the order map for the provided hook.
|
3120 | *
|
3121 | * @private
|
3122 | * @param {object} bucket The bucket object.
|
3123 | * @param {string} hook The hook name.
|
3124 | * @returns {Map<number, Array<Function>>} Returns the order map for the provided hook.
|
3125 | */
|
3126 | getCallbackOrderMap(bucket, hook) {
|
3127 | return callbackOrder.get(bucket)[hook];
|
3128 | }
|
3129 | }
|
3130 | const globalSingleton = new Hooks();
|
3131 |
|
3132 | /**
|
3133 | * @returns {Hooks}
|
3134 | */
|
3135 | function getGlobalSingleton() {
|
3136 | return globalSingleton;
|
3137 | }
|
3138 | export default Hooks; |
\ | No newline at end of file |