pluginHooks.js 57 KB

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