pluginHooks.js 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906
  1. 'use strict';
  2. exports.__esModule = true;
  3. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  4. var _array = require('./helpers/array');
  5. var _object = require('./helpers/object');
  6. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  7. /**
  8. * @description
  9. * Handsontable events are the common interface that function in 2 ways: as __callbacks__ and as __hooks__.
  10. *
  11. * @example
  12. *
  13. * ```js
  14. * // Using events as callbacks:
  15. * ...
  16. * var hot1 = new Handsontable(document.getElementById('example1'), {
  17. * afterChange: function(changes, source) {
  18. * $.ajax({
  19. * url: "save.php',
  20. * data: change
  21. * });
  22. * }
  23. * });
  24. * ...
  25. * ```
  26. *
  27. * ```js
  28. * // Using events as plugin hooks:
  29. * ...
  30. * var hot1 = new Handsontable(document.getElementById('example1'), {
  31. * myPlugin: true
  32. * });
  33. *
  34. * var hot2 = new Handsontable(document.getElementById('example2'), {
  35. * myPlugin: false
  36. * });
  37. *
  38. * // global hook
  39. * Handsontable.hooks.add('afterChange', function() {
  40. * // Fired twice - for hot1 and hot2
  41. * if (this.getSettings().myPlugin) {
  42. * // function body - will only run for hot1
  43. * }
  44. * });
  45. *
  46. * // local hook (has same effect as a callback)
  47. * hot2.addHook('afterChange', function() {
  48. * // function body - will only run in #example2
  49. * });
  50. * ```
  51. * ...
  52. */
  53. // @TODO: Move plugin description hooks to plugin?
  54. var REGISTERED_HOOKS = [
  55. /**
  56. * Callback fired after resetting a cell's meta.
  57. *
  58. * @event Hooks#afterCellMetaReset
  59. * @since 0.11
  60. */
  61. 'afterCellMetaReset',
  62. /**
  63. * @description
  64. * Callback fired after one or more cells has been changed. Its main use case is to save the input.
  65. *
  66. * __Note:__ For performance reasons, the `changes` array is null for `"loadData"` source.
  67. *
  68. * @event Hooks#afterChange
  69. * @param {Array} changes 2D array containing information about each of the edited cells `[[row, prop, oldVal, newVal], ...]`.
  70. * @param {String} [source] String that identifies source of hook call
  71. * ([list of all available sources]{@link http://docs.handsontable.com/tutorial-using-callbacks.html#page-source-definition}).
  72. */
  73. 'afterChange',
  74. /**
  75. * @description
  76. * Fired after observing changes.
  77. *
  78. * @event Hooks#afterChangesObserved
  79. */
  80. 'afterChangesObserved',
  81. /**
  82. * @description
  83. * Fired after setting up the Context Menu's default options. These options are a collection which user can select by setting
  84. * an array of keys or an array of objects in `contextMenu` option.
  85. *
  86. * @event Hooks#afterContextMenuDefaultOptions
  87. * @param {Array} predefinedItems Array of objects containing information about the pre-defined Context Menu items.
  88. */
  89. 'afterContextMenuDefaultOptions',
  90. /**
  91. * @description
  92. * Fired before setting up the Context Menu's items but after filtering these options by user (`contextMenu` option). This hook
  93. * can by helpful to determine if user use specified menu item or to set up one of the menu item to by always visible.
  94. *
  95. * @event Hooks#beforeContextMenuSetItems
  96. * @param {Array} menuItems Array of objects containing information about to generated Context Menu items.
  97. */
  98. 'beforeContextMenuSetItems',
  99. /**
  100. * @description
  101. * Fired after setting up the Context Menu's default options. These options are a collection which user can select by setting
  102. * an array of keys or an array of objects in `contextMenu` option.
  103. *
  104. * @pro
  105. * @event Hooks#afterDropdownMenuDefaultOptions
  106. * @param {Array} predefinedItems Array of objects containing information about the pre-defined Context Menu items.
  107. */
  108. 'afterDropdownMenuDefaultOptions',
  109. /**
  110. * @description
  111. * Fired before setting up the Dropdown Menu's items but after filtering these options by user (`dropdownMenu` option). This hook
  112. * can by helpful to determine if user use specified menu item or to set up one of the menu item to by always visible.
  113. *
  114. * @pro
  115. * @event Hooks#beforeDropdownMenuSetItems
  116. * @param {Array} menuItems Array of objects containing information about to generated Dropdown Menu items.
  117. */
  118. 'beforeDropdownMenuSetItems',
  119. /**
  120. * @description
  121. * Fired after hiding the Context Menu.
  122. *
  123. * @event Hooks#afterContextMenuHide
  124. * @param {Object} context The Context menu instance.
  125. */
  126. 'afterContextMenuHide',
  127. /**
  128. * @description
  129. * Fired after opening the Context Menu.
  130. *
  131. * @event Hooks#afterContextMenuShow
  132. * @param {Object} context The Context Menu instance.
  133. */
  134. 'afterContextMenuShow',
  135. /**
  136. * @description
  137. * Fired after reaching the copy limit while copying data.
  138. *
  139. * @event Hooks#afterCopyLimit
  140. * @param {Number} selectedRows Count of selected copyable rows.
  141. * @param {Number} selectedColumns Count of selected copyable columns.
  142. * @param {Number} copyRowsLimit Current copy rows limit.
  143. * @param {Number} copyColumnsLimit Current copy columns limit.
  144. */
  145. 'afterCopyLimit',
  146. /**
  147. * Callback is fired before a new column was created.
  148. *
  149. * @since 0.28.0
  150. * @event Hooks#beforeCreateCol
  151. * @param {Number} index Represents the index of first newly created column in the data source array.
  152. * @param {Number} amount Number of newly created columns in the data source array.
  153. * @param {String} [source] String that identifies source of hook call
  154. * ([list of all available sources]{@link http://docs.handsontable.com/tutorial-using-callbacks.html#page-source-definition}).
  155. */
  156. 'beforeCreateCol',
  157. /**
  158. * Callback is fired after a new column was created.
  159. *
  160. * @event Hooks#afterCreateCol
  161. * @param {Number} index Represents the index of first newly created column in the data source array.
  162. * @param {Number} amount Number of newly created columns in the data source array.
  163. * @param {String} [source] String that identifies source of hook call
  164. * ([list of all available sources]{@link http://docs.handsontable.com/tutorial-using-callbacks.html#page-source-definition}).
  165. */
  166. 'afterCreateCol',
  167. /**
  168. * Callback is fired before a new row was created.
  169. *
  170. * @since 0.28.0
  171. * @event Hooks#beforeCreateRow
  172. * @param {Number} index Represents the index of first newly created row in the data source array.
  173. * @param {Number} amount Number of newly created rows in the data source array.
  174. * @param {String} [source] String that identifies source of hook call
  175. * ([list of all available sources]{@link http://docs.handsontable.com/tutorial-using-callbacks.html#page-source-definition}).
  176. */
  177. 'beforeCreateRow',
  178. /**
  179. * Callback is fired after a new row was created.
  180. *
  181. * @event Hooks#afterCreateRow
  182. * @param {Number} index Represents the index of first newly created row in the data source array.
  183. * @param {Number} amount Number of newly created rows in the data source array.
  184. * @param {String} [source] String that identifies source of hook call
  185. * ([list of all available sources]{@link http://docs.handsontable.com/tutorial-using-callbacks.html#page-source-definition}).
  186. */
  187. 'afterCreateRow',
  188. /**
  189. * Fired after the current cell is deselected.
  190. *
  191. * @event Hooks#afterDeselect
  192. */
  193. 'afterDeselect',
  194. /**
  195. * Fired after destroying the Handsontable instance.
  196. *
  197. * @event Hooks#afterDestroy
  198. */
  199. 'afterDestroy',
  200. /**
  201. * Fired on a `keydown` event on the document body.
  202. *
  203. * @event Hooks#afterDocumentKeyDown
  204. * @param {Event} event A `keydown` event.
  205. */
  206. 'afterDocumentKeyDown',
  207. /**
  208. * Callback fired after getting the cell settings.
  209. *
  210. * @event Hooks#afterGetCellMeta
  211. * @param {Number} row Row index.
  212. * @param {Number} col Column index.
  213. * @param {Object} cellProperties Object containing the cell properties.
  214. */
  215. 'afterGetCellMeta',
  216. /**
  217. * Callback fired after retrieving information about a column header and appending it to the table header.
  218. *
  219. * @event Hooks#afterGetColHeader
  220. * @param {Number} col Column index.
  221. * @param {Element} TH Header's TH element.
  222. */
  223. 'afterGetColHeader',
  224. /**
  225. * Callback fired after retrieving information about a column header and appending it to the table header.
  226. *
  227. * @event Hooks#afterGetRowHeader
  228. * @param {Number} row Row index.
  229. * @param {Element} TH Header's TH element.
  230. */
  231. 'afterGetRowHeader',
  232. /**
  233. * Callback fired after Handsontable instance is initiated.
  234. *
  235. * @event Hooks#afterInit
  236. */
  237. 'afterInit',
  238. /**
  239. * Callback fired after new data is loaded (by `loadData` method) into the data source array.
  240. *
  241. * @event Hooks#afterLoadData
  242. * @param {Boolean} firstTime flag that determines whether the data has been loaded during the initialization.
  243. */
  244. 'afterLoadData',
  245. /**
  246. * Fired after a scroll event, which is identified as a momentum scroll (e.g. on an iPad).
  247. *
  248. * @event Hooks#afterMomentumScroll
  249. */
  250. 'afterMomentumScroll',
  251. /**
  252. * Fired after a `mousedown` event is triggered on the cell corner (the drag handle).
  253. *
  254. * @event Hooks#afterOnCellCornerMouseDown
  255. * @since 0.11
  256. * @param {Object} event `mousedown` event object.
  257. */
  258. 'afterOnCellCornerMouseDown',
  259. /**
  260. * Fired after a `dblclick` event is triggered on the cell corner (the drag handle).
  261. *
  262. * @event Hooks#afterOnCellCornerDblClick
  263. * @since 0.30.0
  264. * @param {Object} event `dblclick` event object.
  265. */
  266. 'afterOnCellCornerDblClick',
  267. /**
  268. * Callback fired after clicking on a cell or row/column header.
  269. * In case the row/column header was clicked, the index is negative.
  270. * For example clicking on the row header of cell (0, 0) results with `afterOnCellMouseDown` called
  271. * with coords `{row: 0, col: -1}`.
  272. *
  273. * @event Hooks#afterOnCellMouseDown
  274. * @since 0.11
  275. * @param {Object} event `mousedown` event object.
  276. * @param {Object} coords Coordinates object containing the row and column indexes of the clicked cell.
  277. * @param {Element} TD Cell's TD (or TH) element.
  278. */
  279. 'afterOnCellMouseDown',
  280. /**
  281. * Callback fired after hovering a cell or row/column header with the mouse cursor.
  282. * In case the row/column header was hovered, the index is negative.
  283. * For example, hovering over the row header of cell (0, 0) results with `afterOnCellMouseOver` called
  284. * with coords `{row: 0, col: -1}`.
  285. *
  286. * @event Hooks#afterOnCellMouseOver
  287. * @since 0.11
  288. * @param {Object} event `mouseover` event object.
  289. * @param {Object} coords Hovered cell's coordinate object.
  290. * @param {Element} TD Cell's TD (or TH) element.
  291. */
  292. 'afterOnCellMouseOver',
  293. /**
  294. * Callback fired after leaving a cell or row/column header with the mouse cursor.
  295. *
  296. * @event Hooks#afterOnCellMouseOver
  297. * @since 0.31.1
  298. * @param {Object} event `mouseout` event object.
  299. * @param {Object} coords Leaved cell's coordinate object.
  300. * @param {Element} TD Cell's TD (or TH) element.
  301. */
  302. 'afterOnCellMouseOut',
  303. /**
  304. * Callback is fired when one or more columns are removed.
  305. *
  306. * @event Hooks#afterRemoveCol
  307. * @param {Number} index Is an index of starter column.
  308. * @param {Number} amount Is an amount of removed columns.
  309. */
  310. 'afterRemoveCol',
  311. /**
  312. * Callback is fired when one or more rows are removed.
  313. *
  314. * @event Hooks#afterRemoveRow
  315. * @param {Number} index Is an index of starter row.
  316. * @param {Number} amount Is an amount of removed rows.
  317. */
  318. 'afterRemoveRow',
  319. /**
  320. * Callback fired after the Handsontable table is rendered.
  321. *
  322. * @event Hooks#afterRender
  323. * @param {Boolean} isForced Is `true` if rendering was triggered by a change of settings or data; or `false` if
  324. * rendering was triggered by scrolling or moving selection.
  325. */
  326. 'afterRender',
  327. /**
  328. * Fired before starting rendering the cell.
  329. *
  330. * @event Hooks#beforeRenderer
  331. * @since 0.24.2
  332. * @param {Element} TD Currently rendered cell's TD element.
  333. * @param {Number} row Row index.
  334. * @param {Number} col Column index.
  335. * @param {String|Number} prop Column property name or a column index, if datasource is an array of arrays.
  336. * @param {String} value Value of the rendered cell.
  337. * @param {Object} cellProperties Object containing the cell's properties.
  338. */
  339. 'beforeRenderer',
  340. /**
  341. * Fired after finishing rendering the cell (after the renderer finishes).
  342. *
  343. * @event Hooks#afterRenderer
  344. * @since 0.11.0
  345. * @param {Element} TD Currently rendered cell's TD element.
  346. * @param {Number} row Row index.
  347. * @param {Number} col Column index.
  348. * @param {String|Number} prop Column property name or a column index, if datasource is an array of arrays.
  349. * @param {String} value Value of the rendered cell.
  350. * @param {Object} cellProperties Object containing the cell's properties.
  351. */
  352. 'afterRenderer',
  353. /**
  354. * Fired after the horizontal scroll event.
  355. *
  356. * @event Hooks#afterScrollHorizontally
  357. * @since 0.11
  358. */
  359. 'afterScrollHorizontally',
  360. /**
  361. * Fired after the vertical scroll event.
  362. *
  363. * @event Hooks#afterScrollVertically
  364. * @since 0.11
  365. */
  366. 'afterScrollVertically',
  367. /**
  368. * Callback fired after one or more cells are selected (e.g. during mouse move).
  369. *
  370. * @event Hooks#afterSelection
  371. * @param {Number} r Selection start row index.
  372. * @param {Number} c Selection start column index.
  373. * @param {Number} r2 Selection end row index.
  374. * @param {Number} c2 Selection end column index.
  375. * @param {Object} preventScrolling Object with `value` property where its value change will be observed.
  376. * * @example
  377. * ```js
  378. * handsontable({
  379. * afterSelection: function (r, c, r2, c2, preventScrolling) {
  380. * // setting if prevent scrolling after selection
  381. *
  382. * preventScrolling.value = true;
  383. * }
  384. * })
  385. * ```
  386. */
  387. 'afterSelection',
  388. /**
  389. * Callback fired after one or more cells are selected. The `p` argument represents the source object property name instead of the column number.
  390. *
  391. * @event Hooks#afterSelectionByProp
  392. * @param {Number} r Selection start row index.
  393. * @param {String} p Selection start data source object property name.
  394. * @param {Number} r2 Selection end row index.
  395. * @param {String} p2 Selection end data source object property name.
  396. * @param {Object} preventScrolling Object with `value` property where its value change will be observed.
  397. * * @example
  398. * ```js
  399. * handsontable({
  400. * afterSelectionByProp: function (r, c, r2, c2, preventScrolling) {
  401. * // setting if prevent scrolling after selection
  402. *
  403. * preventScrolling.value = true;
  404. * }
  405. * })
  406. * ```
  407. */
  408. 'afterSelectionByProp',
  409. /**
  410. * Callback fired after one or more cells are selected (e.g. on mouse up).
  411. *
  412. * @event Hooks#afterSelectionEnd
  413. * @param {Number} r Selection start row index.
  414. * @param {Number} c Selection start column index.
  415. * @param {Number} r2 Selection end row index.
  416. * @param {Number} c2 Selection end column index.
  417. */
  418. 'afterSelectionEnd',
  419. /**
  420. * Callback fired after one or more cells are selected (e.g. on mouse up). The `p` argument represents the data source object
  421. * property name instead of the column number.
  422. *
  423. * @event Hooks#afterSelectionEndByProp
  424. * @param {Number} r Selection start row index.
  425. * @param {String} p Selection start data source object property index.
  426. * @param {Number} r2 Selection end row index.
  427. * @param {String} p2 Selection end data source object property index.
  428. */
  429. 'afterSelectionEndByProp',
  430. /**
  431. * Called after cell meta is changed.
  432. *
  433. * @event Hooks#afterSetCellMeta
  434. * @since 0.11.0
  435. * @param {Number} row Row index.
  436. * @param {Number} col Column index.
  437. * @param {String} key The updated meta key.
  438. * @param {*} value The updated meta value.
  439. */
  440. 'afterSetCellMeta',
  441. /**
  442. * Called after cell data was changed.
  443. *
  444. * @event Hooks#afterSetDataAtCell
  445. * @since 0.28.0
  446. * @param {Array} changes An array of changes in format `[[row, col, oldValue, value], ...]`.
  447. * @param {String} [source] String that identifies source of hook call
  448. * ([list of all available sources]{@link http://docs.handsontable.com/tutorial-using-callbacks.html#page-source-definition}).
  449. */
  450. 'afterSetDataAtCell',
  451. /**
  452. * Called after cell data was changed.
  453. *
  454. * @event Hooks#afterSetDataAtRowProp
  455. * @since 0.28.0
  456. * @param {Array} changes An array of changes in format `[[row, prop, oldValue, value], ...]`.
  457. * @param {String} [source] String that identifies source of hook call
  458. * ([list of all available sources]{@link http://docs.handsontable.com/tutorial-using-callbacks.html#page-source-definition}).
  459. */
  460. 'afterSetDataAtRowProp',
  461. /**
  462. * Fired after calling the `updateSettings` method.
  463. *
  464. * @event Hooks#afterUpdateSettings
  465. */
  466. 'afterUpdateSettings',
  467. /**
  468. * @description
  469. * A plugin hook executed after validator function, only if validator function is defined.
  470. * Validation result is the first parameter. This can be used to determinate if validation passed successfully or not.
  471. *
  472. * __Returning false from the callback will mark the cell as invalid.__
  473. *
  474. * @event Hooks#afterValidate
  475. * @since 0.9.5
  476. * @param {Boolean} isValid `true` if valid, `false` if not.
  477. * @param {*} value The value in question.
  478. * @param {Number} row Row index.
  479. * @param {String|Number} prop Property name / column index.
  480. * @param {String} [source] String that identifies source of hook call
  481. * ([list of all available sources]{@link http://docs.handsontable.com/tutorial-using-callbacks.html#page-source-definition}).
  482. */
  483. 'afterValidate',
  484. /**
  485. * Fired before populating the data in the autofill feature.
  486. *
  487. * @event Hooks#beforeAutofill
  488. * @param {Object} start Object containing information about first filled cell: `{row: 2, col: 0}`.
  489. * @param {Object} end Object containing information about last filled cell: `{row: 4, col: 1}`.
  490. * @param {Array} data 2D array containing information about fill pattern: `[["1', "Ted"], ["1', "John"]]`.
  491. */
  492. 'beforeAutofill',
  493. /**
  494. * Fired before aligning the cell contents.
  495. *
  496. * @event Hooks#beforeCellAlignment
  497. * @param stateBefore
  498. * @param range
  499. * @param {String} type Type of the alignment - either `horizontal` or `vertical`
  500. * @param {String} alignmentClass String defining the alignment class added to the cell.
  501. * Possible values:
  502. * * `htLeft`,
  503. * * `htCenter`,
  504. * * `htRight`,
  505. * * `htJustify`
  506. * for horizontal alignment,
  507. *
  508. *
  509. * * `htTop`,
  510. * * `htMiddle`,
  511. * * `htBottom`
  512. * for vertical alignment.
  513. */
  514. 'beforeCellAlignment',
  515. /**
  516. * Callback fired before one or more cells is changed. Its main purpose is to alter changes silently before input.
  517. *
  518. * @event Hooks#beforeChange
  519. * @param {Array} changes 2D array containing information about each of the edited cells.
  520. * @param {String} [source] String that identifies source of hook call
  521. * ([list of all available sources]{@link http://docs.handsontable.com/tutorial-using-callbacks.html#page-source-definition}).
  522. * @example
  523. * ```js
  524. * // To disregard a single change, set changes[i] to null or remove it from array using changes.splice(i, 1).
  525. * ...
  526. * new Handsontable(document.getElementById('example'), {
  527. * beforeChange: function(changes, source) {
  528. * // [[row, prop, oldVal, newVal], ...]
  529. * changes[0] = null;
  530. * }
  531. * });
  532. * ...
  533. *
  534. * // To alter a single change, overwrite the desired value to changes[i][3].
  535. * ...
  536. * new Handsontable(document.getElementById('example'), {
  537. * beforeChange: function(changes, source) {
  538. * // [[row, prop, oldVal, newVal], ...]
  539. * changes[0][3] = 10;
  540. * }
  541. * });
  542. * ...
  543. *
  544. * // To cancel all edit, return false from the callback or set array length to 0 (changes.length = 0).
  545. * ...
  546. * new Handsontable(document.getElementById('example'), {
  547. * beforeChange: function(changes, source) {
  548. * // [[row, prop, oldVal, newVal], ...]
  549. * return false;
  550. * }
  551. * });
  552. * ...
  553. * ```
  554. */
  555. 'beforeChange',
  556. /**
  557. * Fired right before rendering the changes.
  558. *
  559. * @event Hooks#beforeChangeRender
  560. * @since 0.11
  561. * @param {Array} changes Array in form of [row, prop, oldValue, newValue].
  562. * @param {String} [source] String that identifies source of hook call
  563. * ([list of all available sources]{@link http://docs.handsontable.com/tutorial-using-callbacks.html#page-source-definition}).
  564. */
  565. 'beforeChangeRender',
  566. /**
  567. * Fired before drawing the borders.
  568. *
  569. * @event Hooks#beforeDrawBorders
  570. * @param {Array} corners Array specifying the current selection borders.
  571. * @param {String} borderClassName Specifies the border class name.
  572. */
  573. 'beforeDrawBorders',
  574. /**
  575. * Callback fired before getting cell settings.
  576. *
  577. * @event Hooks#beforeGetCellMeta
  578. * @param {Number} row Row index.
  579. * @param {Number} col Column index.
  580. * @param {Object} cellProperties Object containing the cell's properties.
  581. */
  582. 'beforeGetCellMeta',
  583. /**
  584. * @description
  585. * Callback fired before Handsontable instance is initiated.
  586. *
  587. * @event Hooks#beforeInit
  588. */
  589. 'beforeInit',
  590. /**
  591. * Callback fired before Walkontable instance is initiated.
  592. *
  593. * @since 0.11
  594. * @event Hooks#beforeInitWalkontable
  595. * @param {Object} walkontableConfig Walkontable configuration object.
  596. */
  597. 'beforeInitWalkontable',
  598. /**
  599. * Callback fired before keydown event is handled. It can be used to overwrite default key bindings.
  600. * Caution - in your `beforeKeyDown` handler you need to call `event.stopImmediatePropagation()` to prevent default key behavior.
  601. *
  602. * @event Hooks#beforeKeyDown
  603. * @since 0.9.0
  604. * @param {Event} event Original DOM event.
  605. */
  606. 'beforeKeyDown',
  607. /**
  608. * Fired after the user clicked a cell, but before all the calculations related with it.
  609. *
  610. * @event Hooks#beforeOnCellMouseDown
  611. * @param {Event} event The `mousedown` event object.
  612. * @param {CellCoords} coords CellCoords object containing the coordinates of the clicked cell.
  613. * @param {Element} TD TD element.
  614. */
  615. 'beforeOnCellMouseDown',
  616. /**
  617. * Fired after the user moved cursor over a cell, but before all the calculations related with it.
  618. *
  619. * @event Hooks#beforeOnCellMouseOver
  620. * @param {Event} event The `mouseover` event object.
  621. * @param {CellCoords} coords CellCoords object containing the coordinates of the clicked cell.
  622. * @param {Element} TD TD element.
  623. * @param {Object} blockCalculations Contain keys 'row' and 'column' with boolean value.
  624. */
  625. 'beforeOnCellMouseOver',
  626. /**
  627. * Fired after the user moved cursor out from a cell, but before all the calculations related with it.
  628. *
  629. * @event Hooks#beforeOnCellMouseOut
  630. * @since 0.31.1
  631. * @param {Event} event The `mouseout` event object.
  632. * @param {WalkontableCellCoords} coords WalkontableCellCoords object containing the coordinates of the leaved cell.
  633. * @param {Element} TD TD element.
  634. */
  635. 'beforeOnCellMouseOut',
  636. /**
  637. * Callback is fired when one or more columns are about to be removed.
  638. *
  639. * @event Hooks#beforeRemoveCol
  640. * @param {Number} index Index of starter column.
  641. * @param {Number} amount Amount of columns to be removed.
  642. * @param {Array} [logicalCols] Consists of logical indexes of processed columns.
  643. */
  644. 'beforeRemoveCol',
  645. /**
  646. * Callback is fired when one or more rows are about to be removed.
  647. *
  648. * @event Hooks#beforeRemoveRow
  649. * @param {Number} index Index of starter column.
  650. * @param {Number} amount Amount of columns to be removed.
  651. * @param {Array} [logicalRows] Consists of logical indexes of processed rows.
  652. */
  653. 'beforeRemoveRow',
  654. /**
  655. * Callback fired before Handsontable table is rendered.
  656. *
  657. * @event Hooks#beforeRender
  658. * @param {Boolean} isForced If `true` rendering was triggered by a change of settings or data; or `false` if
  659. * rendering was triggered by scrolling or moving selection.
  660. */
  661. 'beforeRender',
  662. /**
  663. * Callback fired before setting range is started.
  664. *
  665. * @event Hooks#beforeSetRangeStart
  666. * @param {Array} coords CellCoords array.
  667. */
  668. 'beforeSetRangeStart',
  669. /**
  670. * Callback fired before setting range is ended.
  671. *
  672. * @event Hooks#beforeSetRangeEnd
  673. * @param {Array} coords CellCoords array.
  674. */
  675. 'beforeSetRangeEnd',
  676. /**
  677. * Fired before the logic of handling a touch scroll, when user started scrolling on a touch-enabled device.
  678. *
  679. * @event Hooks#beforeTouchScroll
  680. */
  681. 'beforeTouchScroll',
  682. /**
  683. * @description
  684. * A plugin hook executed before validator function, only if validator function is defined.
  685. * This can be used to manipulate the value of changed cell before it is applied to the validator function.
  686. *
  687. * __Notice:__ this will not affect values of changes. This will change value ONLY for validation!
  688. *
  689. * @event Hooks#beforeValidate
  690. * @since 0.9.5
  691. * @param {*} value Value of the cell.
  692. * @param {Number} row Row index.
  693. * @param {String|Number} prop Property name / column index.
  694. * @param {String} [source] String that identifies source of hook call
  695. * ([list of all available sources]{@link http://docs.handsontable.com/tutorial-using-callbacks.html#page-source-definition}).
  696. */
  697. 'beforeValidate',
  698. /**
  699. * Callback fired before cell value is rendered into the DOM (through renderer function).
  700. *
  701. * @event Hooks#beforeValueRender
  702. * @since 0.29.0
  703. * @param {*} value Cell value to render.
  704. */
  705. 'beforeValueRender',
  706. /**
  707. * Callback fired after Handsontable instance is constructed (via `new` operator).
  708. *
  709. * @event Hooks#construct
  710. * @since 0.16.1
  711. */
  712. 'construct',
  713. /**
  714. * Callback fired after Handsontable instance is initiated but before table is rendered.
  715. *
  716. * @event Hooks#init
  717. * @since 0.16.1
  718. */
  719. 'init',
  720. /**
  721. * Fired when a column index is about to be modified by a callback function.
  722. *
  723. * @event Hooks#modifyCol
  724. * @since 0.11
  725. * @param {Number} col Column index.
  726. */
  727. 'modifyCol',
  728. /**
  729. * Fired when a column index is about to be de-modified by a callback function.
  730. *
  731. * @event Hooks#unmodifyCol
  732. * @since 0.23.0
  733. * @param {Number} col Column index.
  734. */
  735. 'unmodifyCol',
  736. /**
  737. * Fired when a row index is about to be de-modified by a callback function.
  738. *
  739. * @event Hooks#unmodifyRow
  740. * @since 0.26.2
  741. * @param {Number} row Logical row index.
  742. */
  743. 'unmodifyRow',
  744. /**
  745. * Fired when a column header index is about to be modified by a callback function.
  746. *
  747. * @event Hooks#modifyColHeader
  748. * @since 0.20.0
  749. * @param {Number} column Column header index.
  750. */
  751. 'modifyColHeader',
  752. /**
  753. * Fired when a column width is about to be modified by a callback function.
  754. *
  755. * @event Hooks#modifyColWidth
  756. * @since 0.11
  757. * @param {Number} width Current column width.
  758. * @param {Number} col Column index.
  759. */
  760. 'modifyColWidth',
  761. /**
  762. * Fired when a row index is about to be modified by a callback function.
  763. *
  764. * @event Hooks#modifyRow
  765. * @since 0.11
  766. * @param {Number} row Row index.
  767. */
  768. 'modifyRow',
  769. /**
  770. * Fired when a row header index is about to be modified by a callback function.
  771. *
  772. * @event Hooks#modifyRowHeader
  773. * @since 0.20.0
  774. * @param {Number} row Row header index.
  775. */
  776. 'modifyRowHeader',
  777. /**
  778. * Fired when a row height is about to be modified by a callback function.
  779. *
  780. * @event Hooks#modifyRowHeight
  781. * @since 0.11.0
  782. * @param {Number} height Row height.
  783. * @param {Number} row Row index.
  784. */
  785. 'modifyRowHeight',
  786. /**
  787. * Fired when a data was retrieved or modified.
  788. *
  789. * @event Hooks#modifyData
  790. * @since 0.28.0
  791. * @param {Number} row Row height.
  792. * @param {Number} column Column index.
  793. * @param {Object} valueHolder Object which contains original value which can be modified by overwriting `.value` property.
  794. * @param {String} ioMode String which indicates for what operation hook is fired (`get` or `set`).
  795. */
  796. 'modifyData',
  797. /**
  798. * Fired when a data was retrieved or modified.
  799. *
  800. * @event Hooks#modifyRowSourceData
  801. * @since 0.28.0
  802. * @param {Number} row Row logical index.
  803. */
  804. 'modifyRowData',
  805. /**
  806. * Fired after loading data using the Persistent State plugin.
  807. *
  808. * @event Hooks#persistentStateLoad
  809. * @param {String} key Key string.
  810. * @param {Object} valuePlaceholder Object containing the loaded data.
  811. */
  812. 'persistentStateLoad',
  813. /**
  814. * Fired after resetting data using the Persistent State plugin.
  815. *
  816. * @event Hooks#persistentStateReset
  817. * @param {String} key Key string.
  818. */
  819. 'persistentStateReset',
  820. /**
  821. * Fired after resetting data using the Persistent State plugin.
  822. *
  823. * @event Hooks#persistentStateSave
  824. * @param {String} key Key string.
  825. * @param {Mixed} value Value to save.
  826. */
  827. 'persistentStateSave',
  828. /**
  829. * Fired before sorting the column. If you return `false` value then sorting will be not applied by
  830. * Handsontable (useful for server-side sorting).
  831. *
  832. * @event Hooks#beforeColumnSort
  833. * @param {Number} column Sorted column index.
  834. * @param {Boolean} order Soring order where:
  835. * * `true` means ascending order,
  836. * * `false` means descending order,
  837. * * `undefined` means original order.
  838. */
  839. 'beforeColumnSort',
  840. /**
  841. * Fired after sorting the column.
  842. *
  843. * @event Hooks#afterColumnSort
  844. * @param {Number} column Sorted column index.
  845. * @param {Boolean} order Soring order where:
  846. * * `true` means ascending order
  847. * * `false` means descending order
  848. * * `undefined` means original order
  849. */
  850. 'afterColumnSort',
  851. /**
  852. * @description
  853. * Fired after setting range of autofill.
  854. * Both arguments are provided in the following format:
  855. * ```js
  856. * [startRow, startColumn, endRow, endColumn]
  857. * ```
  858. *
  859. * @event Hooks#modifyAutofillRange
  860. * @param {Array} startArea Array of coordinates of the starting point for the drag-down operation.
  861. * @param {Array} entireArea Array of coordinates of the entire area of the drag-down operation.
  862. */
  863. 'modifyAutofillRange',
  864. /**
  865. * Fired to allow modifying the copyable range with a callback function.
  866. *
  867. * @since 0.19.0
  868. * @event Hooks#modifyCopyableRange
  869. * @param {Array} copyableRanges Array of objects defining copyable cells.
  870. */
  871. 'modifyCopyableRange',
  872. /**
  873. * Called before copying the values into clipboard and before clearing values of the selected cells.
  874. *
  875. * @event Hooks#beforeCut
  876. * @since 0.31.1
  877. * @param {Array} data An array of arrays which contains data to cut.
  878. * @param {Array} coords An array of objects with ranges of the visual indexes (`startRow`, `startCol`, `endRow`, `endCol`)
  879. * which will be cut out.
  880. * @returns {*} If returns `false` then operation of the cutting out is cancelled.
  881. *
  882. * @example
  883. * ```js
  884. * // To disregard a single row, remove it from array using data.splice(i, 1).
  885. * ...
  886. * new Handsontable(document.getElementById('example'), {
  887. * beforeCut: function(data, coords) {
  888. * // data -> [[1, 2, 3], [4, 5, 6]]
  889. * data.splice(0, 1);
  890. * // data -> [[4, 5, 6]]
  891. * // coords -> [{startRow: 0, startCol: 0, endRow: 1, endCol: 2}]
  892. * }
  893. * });
  894. * ...
  895. *
  896. * // To cancel cutting out, return false from the callback.
  897. * ...
  898. * new Handsontable(document.getElementById('example'), {
  899. * beforeCut: function(data, coords) {
  900. * return false;
  901. * }
  902. * });
  903. * ...
  904. * ```
  905. */
  906. 'beforeCut',
  907. /**
  908. * Fired after data are cutted out from the table.
  909. *
  910. * @event Hooks#afterCut
  911. * @since 0.31.1
  912. * @param {Array} data An array of arrays which contains the cutted out data.
  913. * @param {Array} coords An array of objects with ranges of the visual indexes (`startRow`, `startCol`, `endRow`, `endCol`)
  914. * which was cut out.
  915. */
  916. 'afterCut',
  917. /**
  918. * Fired before values are copied into clipboard.
  919. *
  920. * @event Hooks#beforeCopy
  921. * @since 0.31.1
  922. * @param {Array} data An array of arrays which contains data to copied.
  923. * @param {Array} coords An array of objects with ranges of the visual indexes (`startRow`, `startCol`, `endRow`, `endCol`)
  924. * which will copied.
  925. * @returns {*} If returns `false` then copying is cancelled.
  926. *
  927. * @example
  928. * ```js
  929. * // To disregard a single row, remove it from array using data.splice(i, 1).
  930. * ...
  931. * new Handsontable(document.getElementById('example'), {
  932. * beforeCopy: function(data, coords) {
  933. * // data -> [[1, 2, 3], [4, 5, 6]]
  934. * data.splice(0, 1);
  935. * // data -> [[4, 5, 6]]
  936. * // coords -> [{startRow: 0, startCol: 0, endRow: 1, endCol: 2}]
  937. * }
  938. * });
  939. * ...
  940. *
  941. * // To cancel copying, return false from the callback.
  942. * ...
  943. * new Handsontable(document.getElementById('example'), {
  944. * beforeCopy: function(data, coords) {
  945. * return false;
  946. * }
  947. * });
  948. * ...
  949. * ```
  950. */
  951. 'beforeCopy',
  952. /**
  953. * Fired after data are pasted into table.
  954. *
  955. * @event Hooks#afterCopy
  956. * @since 0.31.1
  957. * @param {Array} data An array of arrays which contains the copied data.
  958. * @param {Array} coords An array of objects with ranges of the visual indexes (`startRow`, `startCol`, `endRow`, `endCol`)
  959. * which was copied.
  960. */
  961. 'afterCopy',
  962. /**
  963. * Fired before values are pasted into table.
  964. *
  965. * @event Hooks#beforePaste
  966. * @since 0.31.1
  967. * @param {Array} data An array of arrays which contains data to paste.
  968. * @param {Array} coords An array of objects with ranges of the visual indexes (`startRow`, `startCol`, `endRow`, `endCol`)
  969. * where changes will be inserted.
  970. * @returns {*} If returns `false` then pasting is cancelled.
  971. *
  972. * @example
  973. * ```js
  974. * // To disregard a single row, remove it from array using data.splice(i, 1).
  975. * ...
  976. * new Handsontable(document.getElementById('example'), {
  977. * beforePaste: function(data, coords) {
  978. * // data -> [[1, 2, 3], [4, 5, 6]]
  979. * data.splice(0, 1);
  980. * // data -> [[4, 5, 6]]
  981. * // coords -> [{startRow: 0, startCol: 0, endRow: 1, endCol: 2}]
  982. * }
  983. * });
  984. * ...
  985. *
  986. * // To cancel pasting, return false from the callback.
  987. * ...
  988. * new Handsontable(document.getElementById('example'), {
  989. * beforePaste: function(data, coords) {
  990. * return false;
  991. * }
  992. * });
  993. * ...
  994. * ```
  995. */
  996. 'beforePaste',
  997. /**
  998. * Fired after values are pasted into table.
  999. *
  1000. * @event Hooks#afterePaste
  1001. * @since 0.31.1
  1002. * @param {Array} data An array of arrays which contains the pasted data.
  1003. * @param {Array} coords An array of objects with ranges of the visual indexes (`startRow`, `startCol`, `endRow`, `endCol`)
  1004. * where changes was inserted.
  1005. */
  1006. 'afterPaste',
  1007. /**
  1008. * Fired before change order of the logical indexes.
  1009. *
  1010. * @event Hooks#beforeColumnMove
  1011. * @param {Array} columns Array of visual column indexes to be moved.
  1012. * @param {Number} target Visual column index being a target for moved columns.
  1013. */
  1014. 'beforeColumnMove',
  1015. /**
  1016. * Fired after change order of the logical indexes.
  1017. *
  1018. * @event Hooks#afterColumnMove
  1019. * @param {Array} columns Array of visual column indexes that were moved.
  1020. * @param {Number} target Visual column index being a target for moved columns.
  1021. */
  1022. 'afterColumnMove',
  1023. /**
  1024. * Fired before change order of the logical indexes.
  1025. *
  1026. * @event Hooks#beforeRowMove
  1027. * @param {Array} rows Array of visual row indexes to be moved.
  1028. * @param {Number} target Visual row index being a target for moved rows.
  1029. */
  1030. 'beforeRowMove',
  1031. /**
  1032. * Fired after change order of the logical indexes.
  1033. *
  1034. * @event Hooks#afterRowMove
  1035. * @param {Array} rows Array of visual row indexes that were moved.
  1036. * @param {Number} target Visual row index being a target for moved rows.
  1037. */
  1038. 'afterRowMove',
  1039. /**
  1040. * Fired before rendering the table with modified column sizes.
  1041. *
  1042. * @event Hooks#beforeColumnResize
  1043. * @param {Number} currentColumn Index of the resized column.
  1044. * @param {Number} newSize Calculated new column width.
  1045. * @param {Boolean} isDoubleClick Flag that determines whether there was a double-click.
  1046. * @returns {Number} Returns a new column size or `undefined`, if column size should be calculated automatically.
  1047. */
  1048. 'beforeColumnResize',
  1049. /**
  1050. * Fired after rendering the table with modified column sizes.
  1051. *
  1052. * @event Hooks#afterColumnResize
  1053. * @param {Number} currentColumn Index of the resized column.
  1054. * @param {Number} newSize Calculated new column width.
  1055. * @param {Boolean} isDoubleClick Flag that determines whether there was a double-click.
  1056. */
  1057. 'afterColumnResize',
  1058. /**
  1059. * Fired before rendering the table with modified row sizes.
  1060. *
  1061. * @event Hooks#beforeRowResize
  1062. * @param {Number} currentRow Index of the resized row.
  1063. * @param {Number} newSize Calculated new row height.
  1064. * @param {Boolean} isDoubleClick Flag that determines whether there was a double-click.
  1065. * @returns {Number} Returns the new row size or `undefined` if row size should be calculated automatically.
  1066. */
  1067. 'beforeRowResize',
  1068. /**
  1069. * Fired after rendering the table with modified row sizes.
  1070. *
  1071. * @event Hooks#afterRowResize
  1072. * @param {Number} currentRow Index of the resized row.
  1073. * @param {Number} newSize Calculated new row height.
  1074. * @param {Boolean} isDoubleClick Flag that determines whether there was a double-click.
  1075. */
  1076. 'afterRowResize',
  1077. /**
  1078. * Fired after getting the column header renderers.
  1079. *
  1080. * @event Hooks#afterGetColumnHeaderRenderers
  1081. * @param {Array} array Array of the column header renderers.
  1082. */
  1083. 'afterGetColumnHeaderRenderers',
  1084. /**
  1085. * Fired after getting the row header renderers.
  1086. *
  1087. * @event Hooks#afterGetRowHeaderRenderers
  1088. * @param {Array} array Array of the row header renderers.
  1089. */
  1090. 'afterGetRowHeaderRenderers',
  1091. /**
  1092. * Fired before applying stretched column width to column.
  1093. *
  1094. * @event Hooks#beforeStretchingColumnWidth
  1095. * @param {Number} stretchedWidth Calculated width.
  1096. * @param {Number} column Column index.
  1097. * @returns {Number} Returns new width which will be applied to the column element.
  1098. */
  1099. 'beforeStretchingColumnWidth',
  1100. /**
  1101. * Fired before applying [filtering]{@link http://docs.handsontable.com/pro/demo-filtering.html}.
  1102. *
  1103. * @pro
  1104. * @event Hooks#beforeFilter
  1105. * @param {Array} formulasStack An array of objects with added formulas.
  1106. * @returns {Boolean} If hook returns `false` value then filtering won't be applied on the UI side (server-side filtering).
  1107. */
  1108. 'beforeFilter',
  1109. /**
  1110. * Fired after applying [filtering]{@link http://docs.handsontable.com/pro/demo-filtering.html}.
  1111. *
  1112. * @pro
  1113. * @event Hooks#afterFilter
  1114. * @param {Array} formulasStack An array of objects with added formulas.
  1115. */
  1116. 'afterFilter',
  1117. /**
  1118. * Used to modify the column header height.
  1119. *
  1120. * @event Hooks#modifyColumnHeaderHeight
  1121. * @since 0.25.0
  1122. * @param {Number} col Column index.
  1123. */
  1124. 'modifyColumnHeaderHeight',
  1125. /**
  1126. * Fired before the undo action. Contains information about the action that is being undone.
  1127. *
  1128. * @event Hooks#beforeUndo
  1129. * @since 0.26.2
  1130. * @param {Object} action The action object. Contains information about the action being undone. The `actionType`
  1131. * property of the object specifies the type of the action in a String format. (e.g. `'remove_row'`).
  1132. */
  1133. 'beforeUndo',
  1134. /**
  1135. * Fired after the undo action. Contains information about the action that is being undone.
  1136. *
  1137. * @event Hooks#afterUndo
  1138. * @since 0.26.2
  1139. * @param {Object} action The action object. Contains information about the action being undone. The `actionType`
  1140. * property of the object specifies the type of the action in a String format. (e.g. `'remove_row'`).
  1141. */
  1142. 'afterUndo',
  1143. /**
  1144. * Fired before the redo action. Contains information about the action that is being redone.
  1145. *
  1146. * @event Hooks#beforeRedo
  1147. * @since 0.26.2
  1148. * @param {Object} action The action object. Contains information about the action being redone. The `actionType`
  1149. * property of the object specifies the type of the action in a String format. (e.g. `'remove_row'`).
  1150. */
  1151. 'beforeRedo',
  1152. /**
  1153. * Fired after the redo action. Contains information about the action that is being redone.
  1154. *
  1155. * @event Hooks#afterRedo
  1156. * @since 0.26.2
  1157. * @param {Object} action The action object. Contains information about the action being redone. The `actionType`
  1158. * property of the object specifies the type of the action in a String format. (e.g. `'remove_row'`).
  1159. */
  1160. 'afterRedo',
  1161. /**
  1162. * Used to modify the row header width.
  1163. *
  1164. * @event Hooks#modifyRowHeaderWidth
  1165. * @param {Number} rowHeaderWidth Row header width.
  1166. */
  1167. 'modifyRowHeaderWidth',
  1168. /**
  1169. * Fired from the `populateFromArray` method during the `autofill` process. Fired for each "autofilled" cell individually.
  1170. *
  1171. * @event Hooks#beforeAutofillInsidePopulate
  1172. * @param {Object} index Object containing `row` and `col` properties, defining the number of rows/columns from the initial cell of the autofill.
  1173. * @param {String} direction Declares the direction of the autofill. Possible values: `up`, `down`, `left`, `right`.
  1174. * @param {Array} input Array of arrays. Contains an array of rows with data being used in the autofill.
  1175. * @param {Array} deltas The deltas array passed to the `populateFromArray` method.
  1176. */
  1177. 'beforeAutofillInsidePopulate',
  1178. /**
  1179. * Fired when the start of the selection is being modified. (e.g. moving the selection with the arrow keys).
  1180. *
  1181. * @event Hooks#modifyTransformStart
  1182. * @param {CellCoords} delta Cell coords object declaring the delta of the new selection relative to the previous one.
  1183. */
  1184. 'modifyTransformStart',
  1185. /**
  1186. * Fired when the end of the selection is being modified. (e.g. moving the selection with the arrow keys).
  1187. *
  1188. * @event Hooks#modifyTransformEnd
  1189. * @param {CellCoords} delta Cell coords object declaring the delta of the new selection relative to the previous one.
  1190. */
  1191. 'modifyTransformEnd',
  1192. /**
  1193. * Fired after the start of the selection is being modified. (e.g. moving the selection with the arrow keys).
  1194. *
  1195. * @event Hooks#afterModifyTransformStart
  1196. * @param {CellCoords} coords Coords of the freshly selected cell.
  1197. * @param {Number} rowTransformDir `-1` if trying to select a cell with a negative row index. `0` otherwise.
  1198. * @param {Number} colTransformDir `-1` if trying to select a cell with a negative column index. `0` otherwise.
  1199. */
  1200. 'afterModifyTransformStart',
  1201. /**
  1202. * Fired after the end of the selection is being modified. (e.g. moving the selection with the arrow keys).
  1203. *
  1204. * @event Hooks#afterModifyTransformEnd
  1205. * @param {CellCoords} coords Coords of the freshly selected cell.
  1206. * @param {Number} rowTransformDir `-1` if trying to select a cell with a negative row index. `0` otherwise.
  1207. * @param {Number} colTransformDir `-1` if trying to select a cell with a negative column index. `0` otherwise.
  1208. */
  1209. 'afterModifyTransformEnd',
  1210. /**
  1211. * Fired before rendering a cell value.
  1212. *
  1213. * @event Hooks#beforeValueRender
  1214. * @param {Mixed} value The rendered value.
  1215. */
  1216. 'beforeValueRender',
  1217. /**
  1218. * Fired inside the `viewportRowCalculatorOverride` method. Allows modifying the row calculator parameters.
  1219. *
  1220. * @event Hooks#afterViewportRowCalculatorOverride
  1221. * @param {Object} calc The row calculator.
  1222. */
  1223. 'afterViewportRowCalculatorOverride',
  1224. /**
  1225. * Fired inside the `viewportColumnCalculatorOverride` method. Allows modifying the row calculator parameters.
  1226. *
  1227. * @event Hooks#afterViewportColumnCalculatorOverride
  1228. * @param {Object} calc The row calculator.
  1229. */
  1230. 'afterViewportColumnCalculatorOverride',
  1231. /**
  1232. * Fired after initializing all the plugins.
  1233. *
  1234. * @event Hooks#afterPluginsInitialized
  1235. */
  1236. 'afterPluginsInitialized',
  1237. /**
  1238. * Used when saving/loading the manual row heights state.
  1239. *
  1240. * @event Hooks#manualRowHeights
  1241. * @param {Array} state The current manual row heights state.
  1242. */
  1243. 'manualRowHeights',
  1244. /**
  1245. * Used to skip the length cache calculation for a defined period of time.
  1246. *
  1247. * @event Hooks#skipLengthCache
  1248. * @param {Number} delay The delay in milliseconds.
  1249. */
  1250. 'skipLengthCache',
  1251. /**
  1252. * Fired after trimming rows in the TrimRows plugin.
  1253. *
  1254. * @pro
  1255. * @event Hooks#afterTrimRow
  1256. * @param {Array} rows Indexes of trimmed rows.
  1257. */
  1258. 'afterTrimRow',
  1259. /**
  1260. * Fired after untrimming rows in the TrimRows plugin.
  1261. *
  1262. * @pro
  1263. * @event Hooks#afterUntrimRow
  1264. * @param {Array} rows Indexes of untrimmed rows.
  1265. */
  1266. 'afterUntrimRow',
  1267. /**
  1268. * Fired after opening the dropdown menu.
  1269. *
  1270. * @pro
  1271. * @event Hooks#afterDropdownMenuShow
  1272. * @param {DropdownMenu} instance The DropdownMenu instance.
  1273. */
  1274. 'afterDropdownMenuShow',
  1275. /**
  1276. * Fired after hiding the dropdown menu.
  1277. *
  1278. * @pro
  1279. * @event Hooks#afterDropdownMenuHide
  1280. * @param {DropdownMenu} instance The DropdownMenu instance.
  1281. */
  1282. 'afterDropdownMenuHide',
  1283. /**
  1284. * Used to check whether the provided row index is hidden.
  1285. *
  1286. * @pro
  1287. * @event Hooks#hiddenRow
  1288. * @param {Number} row The row index in question.
  1289. */
  1290. 'hiddenRow',
  1291. /**
  1292. * Used to check whether the provided column index is hidden.
  1293. *
  1294. * @pro
  1295. * @event Hooks#hiddenColumn
  1296. * @param {Number} column The column index in question.
  1297. */
  1298. 'hiddenColumn',
  1299. /**
  1300. * Fired before adding a children to the NestedRows structure.
  1301. *
  1302. * @pro
  1303. * @event Hooks#beforeAddChild
  1304. * @param {Object} parent The parent object.
  1305. * @param {Object|undefined} element The element added as a child. If `undefined`, a blank child was added.
  1306. * @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.
  1307. */
  1308. 'beforeAddChild',
  1309. /**
  1310. * Fired after adding a children to the NestedRows structure.
  1311. *
  1312. * @pro
  1313. * @event Hooks#afterAddChild
  1314. * @param {Object} parent The parent object.
  1315. * @param {Object|undefined} element The element added as a child. If `undefined`, a blank child was added.
  1316. * @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.
  1317. */
  1318. 'afterAddChild',
  1319. /**
  1320. * Fired before detaching a child from its parent in the NestedRows plugin.
  1321. *
  1322. * @pro
  1323. * @event Hooks#beforeDetachChild
  1324. * @param {Object} parent An object representing the parent from which the element is to be detached.
  1325. * @param {Object} element The detached element.
  1326. */
  1327. 'beforeDetachChild',
  1328. /**
  1329. * Fired after detaching a child from its parent in the NestedRows plugin.
  1330. *
  1331. * @pro
  1332. * @event Hooks#afterDetachChild
  1333. * @param {Object} parent An object representing the parent from which the element was detached.
  1334. * @param {Object} element The detached element.
  1335. */
  1336. 'afterDetachChild',
  1337. /**
  1338. * Fired after the editor is opened and rendered.
  1339. *
  1340. * @event Hooks#afterBeginEditing
  1341. * @param {Number} row Row index of the edited cell.
  1342. * @param {Number} column Column index of the edited cell.
  1343. */
  1344. 'afterBeginEditing'];
  1345. var Hooks = function () {
  1346. _createClass(Hooks, null, [{
  1347. key: 'getSingleton',
  1348. value: function getSingleton() {
  1349. return globalSingleton;
  1350. }
  1351. /**
  1352. *
  1353. */
  1354. }]);
  1355. function Hooks() {
  1356. _classCallCheck(this, Hooks);
  1357. this.globalBucket = this.createEmptyBucket();
  1358. }
  1359. /**
  1360. * Returns a new object with empty handlers related to every registered hook name.
  1361. *
  1362. * @returns {Object} The empty bucket object.
  1363. *
  1364. * @example
  1365. * ```js
  1366. * Handsontable.hooks.createEmptyBucket();
  1367. * // Results:
  1368. * {
  1369. * ...
  1370. * afterCreateCol: [],
  1371. * afterCreateRow: [],
  1372. * beforeInit: [],
  1373. * ...
  1374. * }
  1375. * ```
  1376. */
  1377. _createClass(Hooks, [{
  1378. key: 'createEmptyBucket',
  1379. value: function createEmptyBucket() {
  1380. var bucket = Object.create(null);
  1381. (0, _array.arrayEach)(REGISTERED_HOOKS, function (hook) {
  1382. return bucket[hook] = [];
  1383. });
  1384. return bucket;
  1385. }
  1386. /**
  1387. * Get hook bucket based on the context of the object or if argument is `undefined`, get the global hook bucket.
  1388. *
  1389. * @param {Object} [context=null] A Handsontable instance.
  1390. * @returns {Object} Returns a global or Handsontable instance bucket.
  1391. */
  1392. }, {
  1393. key: 'getBucket',
  1394. value: function getBucket() {
  1395. var context = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
  1396. if (context) {
  1397. if (!context.pluginHookBucket) {
  1398. context.pluginHookBucket = this.createEmptyBucket();
  1399. }
  1400. return context.pluginHookBucket;
  1401. }
  1402. return this.globalBucket;
  1403. }
  1404. /**
  1405. * Adds a listener (globally or locally) to a specified hook name.
  1406. * If the `context` parameter is provided, the hook will be added only to the instance it references.
  1407. * Otherwise, the callback will be used everytime the hook fires on any Handsontable instance.
  1408. * You can provide an array of callback functions as the `callback` argument, this way they will all be fired
  1409. * once the hook is triggered.
  1410. *
  1411. * @see Core#addHook
  1412. * @param {String} key Hook name.
  1413. * @param {Function|Array} callback Callback function or an array of functions.
  1414. * @param {Object} [context=null] The context for the hook callback to be added - a Handsontable instance or leave empty.
  1415. * @returns {Hooks} Instance of Hooks.
  1416. *
  1417. * @example
  1418. * ```js
  1419. * // single callback, added locally
  1420. * Handsontable.hooks.add('beforeInit', myCallback, hotInstance);
  1421. *
  1422. * // single callback, added globally
  1423. * Handsontable.hooks.add('beforeInit', myCallback);
  1424. *
  1425. * // multiple callbacks, added locally
  1426. * Handsontable.hooks.add('beforeInit', [myCallback, anotherCallback], hotInstance);
  1427. *
  1428. * // multiple callbacks, added globally
  1429. * Handsontable.hooks.add('beforeInit', [myCallback, anotherCallback]);
  1430. * ```
  1431. */
  1432. }, {
  1433. key: 'add',
  1434. value: function add(key, callback) {
  1435. var _this = this;
  1436. var context = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  1437. if (Array.isArray(callback)) {
  1438. (0, _array.arrayEach)(callback, function (c) {
  1439. return _this.add(key, c, context);
  1440. });
  1441. } else {
  1442. var bucket = this.getBucket(context);
  1443. if (typeof bucket[key] === 'undefined') {
  1444. this.register(key);
  1445. bucket[key] = [];
  1446. }
  1447. callback.skip = false;
  1448. if (bucket[key].indexOf(callback) === -1) {
  1449. // only add a hook if it has not already been added (adding the same hook twice is now silently ignored)
  1450. var foundInitialHook = false;
  1451. if (callback.initialHook) {
  1452. (0, _array.arrayEach)(bucket[key], function (cb, i) {
  1453. if (cb.initialHook) {
  1454. bucket[key][i] = callback;
  1455. foundInitialHook = true;
  1456. return false;
  1457. }
  1458. });
  1459. }
  1460. if (!foundInitialHook) {
  1461. bucket[key].push(callback);
  1462. }
  1463. }
  1464. }
  1465. return this;
  1466. }
  1467. /**
  1468. * Adds a listener to a specified hook. After the hook runs this listener will be automatically removed from the bucket.
  1469. *
  1470. * @see Core#addHookOnce
  1471. * @param {String} key Hook/Event name.
  1472. * @param {Function|Array} callback Callback function.
  1473. * @param {Object} [context=null] A Handsontable instance.
  1474. *
  1475. * @example
  1476. * ```js
  1477. * Handsontable.hooks.once('beforeInit', myCallback, hotInstance);
  1478. * ```
  1479. */
  1480. }, {
  1481. key: 'once',
  1482. value: function once(key, callback) {
  1483. var _this2 = this;
  1484. var context = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  1485. if (Array.isArray(callback)) {
  1486. (0, _array.arrayEach)(callback, function (c) {
  1487. return _this2.once(key, c, context);
  1488. });
  1489. } else {
  1490. callback.runOnce = true;
  1491. this.add(key, callback, context);
  1492. }
  1493. }
  1494. /**
  1495. * 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.
  1496. *
  1497. * @see Core#removeHook
  1498. * @param {String} key Hook/Event name.
  1499. * @param {Function} callback Callback function (needs the be the function that was previously added to the hook).
  1500. * @param {Object} [context=null] Handsontable instance.
  1501. * @return {Boolean} Returns `true` if hook was removed, `false` otherwise.
  1502. *
  1503. * @example
  1504. * ```js
  1505. * Handsontable.hooks.remove('beforeInit', myCallback);
  1506. * ```
  1507. */
  1508. }, {
  1509. key: 'remove',
  1510. value: function remove(key, callback) {
  1511. var context = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  1512. var bucket = this.getBucket(context);
  1513. if (typeof bucket[key] !== 'undefined') {
  1514. if (bucket[key].indexOf(callback) >= 0) {
  1515. callback.skip = true;
  1516. return true;
  1517. }
  1518. }
  1519. return false;
  1520. }
  1521. /**
  1522. * Checks whether there are any registered listeners for the provided hook name.
  1523. * If the `context` parameter is provided, it only checks for listeners assigned to the given Handsontable instance.
  1524. *
  1525. * @param {String} key Hook name.
  1526. * @param {Object} [context=null] A Handsontable instance.
  1527. * @returns {Boolean} `true` for success, `false` otherwise.
  1528. */
  1529. }, {
  1530. key: 'has',
  1531. value: function has(key) {
  1532. var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
  1533. var bucket = this.getBucket(context);
  1534. return !!(bucket[key] !== void 0 && bucket[key].length);
  1535. }
  1536. /**
  1537. * Runs all local and global callbacks assigned to the hook identified by the `key` parameter.
  1538. * It returns either a return value from the last called callback or the first parameter (`p1`) passed to the `run` function.
  1539. *
  1540. * @see Core#runHooks
  1541. * @param {Object} context Handsontable instance.
  1542. * @param {String} key Hook/Event name.
  1543. * @param {*} [p1] Parameter to be passed as an argument to the callback function.
  1544. * @param {*} [p2] Parameter to be passed as an argument to the callback function.
  1545. * @param {*} [p3] Parameter to be passed as an argument to the callback function.
  1546. * @param {*} [p4] Parameter to be passed as an argument to the callback function.
  1547. * @param {*} [p5] Parameter to be passed as an argument to the callback function.
  1548. * @param {*} [p6] Parameter to be passed as an argument to the callback function.
  1549. * @returns {*} Either a return value from the last called callback or `p1`.
  1550. *
  1551. * @example
  1552. * ```js
  1553. * Handsontable.hooks.run(hot, 'beforeInit');
  1554. * ```
  1555. */
  1556. }, {
  1557. key: 'run',
  1558. value: function run(context, key, p1, p2, p3, p4, p5, p6) {
  1559. {
  1560. var globalHandlers = this.globalBucket[key];
  1561. var index = -1;
  1562. var length = globalHandlers ? globalHandlers.length : 0;
  1563. if (length) {
  1564. // Do not optimise this loop with arrayEach or arrow function! If you do You'll decrease perf because of GC.
  1565. while (++index < length) {
  1566. if (!globalHandlers[index] || globalHandlers[index].skip) {
  1567. /* eslint-disable no-continue */
  1568. continue;
  1569. }
  1570. // performance considerations - http://jsperf.com/call-vs-apply-for-a-plugin-architecture
  1571. var res = globalHandlers[index].call(context, p1, p2, p3, p4, p5, p6);
  1572. if (res !== void 0) {
  1573. p1 = res;
  1574. }
  1575. if (globalHandlers[index] && globalHandlers[index].runOnce) {
  1576. this.remove(key, globalHandlers[index]);
  1577. }
  1578. }
  1579. }
  1580. }
  1581. {
  1582. var localHandlers = this.getBucket(context)[key];
  1583. var _index = -1;
  1584. var _length = localHandlers ? localHandlers.length : 0;
  1585. if (_length) {
  1586. // Do not optimise this loop with arrayEach or arrow function! If you do You'll decrease perf because of GC.
  1587. while (++_index < _length) {
  1588. if (!localHandlers[_index] || localHandlers[_index].skip) {
  1589. /* eslint-disable no-continue */
  1590. continue;
  1591. }
  1592. // performance considerations - http://jsperf.com/call-vs-apply-for-a-plugin-architecture
  1593. var _res = localHandlers[_index].call(context, p1, p2, p3, p4, p5, p6);
  1594. if (_res !== void 0) {
  1595. p1 = _res;
  1596. }
  1597. if (localHandlers[_index] && localHandlers[_index].runOnce) {
  1598. this.remove(key, localHandlers[_index], context);
  1599. }
  1600. }
  1601. }
  1602. }
  1603. return p1;
  1604. }
  1605. /**
  1606. * Destroy all listeners connected to the context. If no context is provided, the global listeners will be destroyed.
  1607. *
  1608. * @param {Object} [context=null] A Handsontable instance.
  1609. * @example
  1610. * ```js
  1611. * // destroy the global listeners
  1612. * Handsontable.hooks.destroy();
  1613. *
  1614. * // destroy the local listeners
  1615. * Handsontable.hooks.destroy(hotInstance);
  1616. * ```
  1617. */
  1618. }, {
  1619. key: 'destroy',
  1620. value: function destroy() {
  1621. var context = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
  1622. (0, _object.objectEach)(this.getBucket(context), function (value, key, bucket) {
  1623. return bucket[key].length = 0;
  1624. });
  1625. }
  1626. /**
  1627. * Registers a hook name (adds it to the list of the known hook names). Used by plugins.
  1628. * It is not necessary to call register, but if you use it, your plugin hook will be used returned by
  1629. * the `getRegistered` method. (which itself is used in the demo http://docs.handsontable.com/tutorial-callbacks.html).
  1630. *
  1631. * @param key {String} The hook name.
  1632. *
  1633. * @example
  1634. * ```js
  1635. * Handsontable.hooks.register('myHook');
  1636. * ```
  1637. */
  1638. }, {
  1639. key: 'register',
  1640. value: function register(key) {
  1641. if (!this.isRegistered(key)) {
  1642. REGISTERED_HOOKS.push(key);
  1643. }
  1644. }
  1645. /**
  1646. * Deregisters a hook name (removes it from the list of known hook names).
  1647. *
  1648. * @param key {String} Hook name.
  1649. *
  1650. * @example
  1651. * ```js
  1652. * Handsontable.hooks.deregister('myHook');
  1653. * ```
  1654. */
  1655. }, {
  1656. key: 'deregister',
  1657. value: function deregister(key) {
  1658. if (this.isRegistered(key)) {
  1659. REGISTERED_HOOKS.splice(REGISTERED_HOOKS.indexOf(key), 1);
  1660. }
  1661. }
  1662. /**
  1663. * Returns a boolean depending on if a hook by such name has been registered.
  1664. *
  1665. * @param key {String} Hook name.
  1666. * @returns {Boolean} `true` for success, `false` otherwise.
  1667. *
  1668. * @example
  1669. * ```js
  1670. * Handsontable.hooks.isRegistered('beforeInit');
  1671. *
  1672. * // Results:
  1673. * true
  1674. * ```
  1675. */
  1676. }, {
  1677. key: 'isRegistered',
  1678. value: function isRegistered(key) {
  1679. return REGISTERED_HOOKS.indexOf(key) >= 0;
  1680. }
  1681. /**
  1682. * Returns an array of registered hooks.
  1683. *
  1684. * @returns {Array} An array of registered hooks.
  1685. *
  1686. * @example
  1687. * ```js
  1688. * Handsontable.hooks.getRegistered();
  1689. *
  1690. * // Results:
  1691. * [
  1692. * ...
  1693. * 'beforeInit',
  1694. * 'beforeRender',
  1695. * 'beforeSetRangeEnd',
  1696. * 'beforeDrawBorders',
  1697. * 'beforeChange',
  1698. * ...
  1699. * ]
  1700. * ```
  1701. */
  1702. }, {
  1703. key: 'getRegistered',
  1704. value: function getRegistered() {
  1705. return REGISTERED_HOOKS;
  1706. }
  1707. }]);
  1708. return Hooks;
  1709. }();
  1710. var globalSingleton = new Hooks();
  1711. exports.default = Hooks;