handsontable 11.1.0 → 12.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (461) hide show
  1. package/3rdparty/walkontable/src/border.js +120 -98
  2. package/3rdparty/walkontable/src/border.mjs +120 -94
  3. package/3rdparty/walkontable/src/cell/coords.js +59 -17
  4. package/3rdparty/walkontable/src/cell/coords.mjs +55 -17
  5. package/3rdparty/walkontable/src/cell/range.d.ts +10 -2
  6. package/3rdparty/walkontable/src/cell/range.js +278 -99
  7. package/3rdparty/walkontable/src/cell/range.mjs +273 -99
  8. package/3rdparty/walkontable/src/core/_base.js +452 -0
  9. package/3rdparty/walkontable/src/core/_base.mjs +440 -0
  10. package/3rdparty/walkontable/src/core/clone.js +97 -0
  11. package/3rdparty/walkontable/src/core/clone.mjs +80 -0
  12. package/3rdparty/walkontable/src/core/core.js +183 -0
  13. package/3rdparty/walkontable/src/core/core.mjs +160 -0
  14. package/3rdparty/walkontable/src/event.js +99 -66
  15. package/3rdparty/walkontable/src/event.mjs +99 -63
  16. package/3rdparty/walkontable/src/facade/core.js +251 -0
  17. package/3rdparty/walkontable/src/facade/core.mjs +243 -0
  18. package/3rdparty/walkontable/src/index.js +2 -46
  19. package/3rdparty/walkontable/src/index.mjs +3 -13
  20. package/3rdparty/walkontable/src/overlay/_base.js +124 -57
  21. package/3rdparty/walkontable/src/overlay/_base.mjs +124 -57
  22. package/3rdparty/walkontable/src/overlay/bottom.js +96 -80
  23. package/3rdparty/walkontable/src/overlay/bottom.mjs +96 -80
  24. package/3rdparty/walkontable/src/overlay/{bottomLeftCorner.js → bottomInlineStartCorner.js} +45 -62
  25. package/3rdparty/walkontable/src/overlay/{bottomLeftCorner.mjs → bottomInlineStartCorner.mjs} +44 -61
  26. package/3rdparty/walkontable/src/overlay/constants.js +25 -9
  27. package/3rdparty/walkontable/src/overlay/constants.mjs +14 -4
  28. package/3rdparty/walkontable/src/overlay/index.js +10 -19
  29. package/3rdparty/walkontable/src/overlay/index.mjs +4 -5
  30. package/3rdparty/walkontable/src/overlay/{left.js → inlineStart.js} +113 -82
  31. package/3rdparty/walkontable/src/overlay/{left.mjs → inlineStart.mjs} +112 -81
  32. package/3rdparty/walkontable/src/overlay/top.js +93 -68
  33. package/3rdparty/walkontable/src/overlay/top.mjs +93 -68
  34. package/3rdparty/walkontable/src/overlay/{topLeftCorner.js → topInlineStartCorner.js} +56 -57
  35. package/3rdparty/walkontable/src/overlay/{topLeftCorner.mjs → topInlineStartCorner.mjs} +51 -52
  36. package/3rdparty/walkontable/src/overlays.js +225 -156
  37. package/3rdparty/walkontable/src/overlays.mjs +224 -154
  38. package/3rdparty/walkontable/src/renderer/cells.js +4 -3
  39. package/3rdparty/walkontable/src/renderer/cells.mjs +4 -3
  40. package/3rdparty/walkontable/src/renderer/colGroup.js +2 -2
  41. package/3rdparty/walkontable/src/renderer/colGroup.mjs +2 -2
  42. package/3rdparty/walkontable/src/renderer/columnHeaders.js +2 -2
  43. package/3rdparty/walkontable/src/renderer/columnHeaders.mjs +2 -2
  44. package/3rdparty/walkontable/src/renderer/rowHeaders.js +2 -2
  45. package/3rdparty/walkontable/src/renderer/rowHeaders.mjs +2 -2
  46. package/3rdparty/walkontable/src/renderer/rows.js +2 -2
  47. package/3rdparty/walkontable/src/renderer/rows.mjs +2 -2
  48. package/3rdparty/walkontable/src/scroll.js +125 -104
  49. package/3rdparty/walkontable/src/scroll.mjs +124 -104
  50. package/3rdparty/walkontable/src/selection.js +10 -14
  51. package/3rdparty/walkontable/src/selection.mjs +10 -12
  52. package/3rdparty/walkontable/src/settings.js +235 -126
  53. package/3rdparty/walkontable/src/settings.mjs +235 -125
  54. package/3rdparty/walkontable/src/table/bottom.js +16 -5
  55. package/3rdparty/walkontable/src/table/bottom.mjs +15 -5
  56. package/3rdparty/walkontable/src/table/{bottomLeftCorner.js → bottomInlineStartCorner.js} +27 -15
  57. package/3rdparty/walkontable/src/table/{bottomLeftCorner.mjs → bottomInlineStartCorner.mjs} +26 -15
  58. package/3rdparty/walkontable/src/table/{left.js → inlineStart.js} +23 -15
  59. package/3rdparty/walkontable/src/table/{left.mjs → inlineStart.mjs} +22 -15
  60. package/3rdparty/walkontable/src/table/master.js +22 -12
  61. package/3rdparty/walkontable/src/table/master.mjs +22 -12
  62. package/3rdparty/walkontable/src/table/mixin/calculatedColumns.js +12 -6
  63. package/3rdparty/walkontable/src/table/mixin/calculatedColumns.mjs +12 -6
  64. package/3rdparty/walkontable/src/table/mixin/calculatedRows.js +12 -6
  65. package/3rdparty/walkontable/src/table/mixin/calculatedRows.mjs +12 -6
  66. package/3rdparty/walkontable/src/table/mixin/{stickyColumnsLeft.js → stickyColumnsStart.js} +13 -7
  67. package/3rdparty/walkontable/src/table/mixin/{stickyColumnsLeft.mjs → stickyColumnsStart.mjs} +13 -7
  68. package/3rdparty/walkontable/src/table/mixin/stickyRowsBottom.js +11 -5
  69. package/3rdparty/walkontable/src/table/mixin/stickyRowsBottom.mjs +11 -5
  70. package/3rdparty/walkontable/src/table/mixin/stickyRowsTop.js +9 -3
  71. package/3rdparty/walkontable/src/table/mixin/stickyRowsTop.mjs +9 -3
  72. package/3rdparty/walkontable/src/table/top.js +16 -5
  73. package/3rdparty/walkontable/src/table/top.mjs +15 -5
  74. package/3rdparty/walkontable/src/table/{topLeftCorner.js → topInlineStartCorner.js} +27 -15
  75. package/3rdparty/walkontable/src/table/{topLeftCorner.mjs → topInlineStartCorner.mjs} +26 -15
  76. package/3rdparty/walkontable/src/table.js +235 -140
  77. package/3rdparty/walkontable/src/table.mjs +231 -134
  78. package/3rdparty/walkontable/src/types.js +103 -0
  79. package/3rdparty/walkontable/src/types.mjs +102 -0
  80. package/3rdparty/walkontable/src/utils/column.js +22 -33
  81. package/3rdparty/walkontable/src/utils/column.mjs +22 -30
  82. package/3rdparty/walkontable/src/utils/orderView/sharedView.js +2 -2
  83. package/3rdparty/walkontable/src/utils/orderView/sharedView.mjs +2 -2
  84. package/3rdparty/walkontable/src/utils/row.js +9 -4
  85. package/3rdparty/walkontable/src/utils/row.mjs +9 -4
  86. package/3rdparty/walkontable/src/viewport.js +89 -100
  87. package/3rdparty/walkontable/src/viewport.mjs +89 -97
  88. package/CHANGELOG.md +92 -0
  89. package/LICENSE.txt +1 -1
  90. package/README.md +0 -1
  91. package/base.js +2 -2
  92. package/base.mjs +2 -2
  93. package/cellTypes/timeType/timeType.d.ts +6 -6
  94. package/cellTypes/timeType/timeType.js +4 -5
  95. package/cellTypes/timeType/timeType.mjs +4 -5
  96. package/core.d.ts +6 -1
  97. package/core.js +508 -80
  98. package/core.mjs +517 -92
  99. package/dataMap/index.js +4 -0
  100. package/dataMap/index.mjs +2 -1
  101. package/dataMap/metaManager/index.js +2 -2
  102. package/dataMap/metaManager/index.mjs +2 -2
  103. package/dataMap/metaManager/metaLayers/globalMeta.js +4 -0
  104. package/dataMap/metaManager/metaLayers/globalMeta.mjs +4 -0
  105. package/dataMap/metaManager/metaLayers/tableMeta.js +2 -2
  106. package/dataMap/metaManager/metaLayers/tableMeta.mjs +2 -2
  107. package/dataMap/metaManager/metaSchema.js +282 -187
  108. package/dataMap/metaManager/metaSchema.mjs +282 -187
  109. package/dataMap/metaManager/mods/extendMetaProperties.js +126 -0
  110. package/dataMap/metaManager/mods/extendMetaProperties.mjs +113 -0
  111. package/dataMap/replaceData.js +3 -17
  112. package/dataMap/replaceData.mjs +3 -17
  113. package/dist/handsontable.css +268 -92
  114. package/dist/handsontable.full.css +269 -103
  115. package/dist/handsontable.full.js +41990 -35658
  116. package/dist/handsontable.full.min.css +9 -9
  117. package/dist/handsontable.full.min.js +144 -144
  118. package/dist/handsontable.js +29561 -25597
  119. package/dist/handsontable.min.css +8 -8
  120. package/dist/handsontable.min.js +4 -4
  121. package/dist/languages/all.js +131 -34
  122. package/dist/languages/all.min.js +1 -1
  123. package/dist/languages/ar-AR.js +167 -0
  124. package/dist/languages/ar-AR.min.js +1 -0
  125. package/dist/languages/cs-CZ.js +167 -0
  126. package/dist/languages/cs-CZ.min.js +1 -0
  127. package/dist/languages/de-CH.js +31 -29
  128. package/dist/languages/de-CH.min.js +1 -1
  129. package/dist/languages/de-DE.js +4 -2
  130. package/dist/languages/de-DE.min.js +1 -1
  131. package/dist/languages/en-US.js +4 -2
  132. package/dist/languages/en-US.min.js +1 -1
  133. package/dist/languages/es-MX.js +4 -2
  134. package/dist/languages/es-MX.min.js +1 -1
  135. package/dist/languages/fr-FR.js +4 -2
  136. package/dist/languages/fr-FR.min.js +1 -1
  137. package/dist/languages/it-IT.js +4 -2
  138. package/dist/languages/it-IT.min.js +1 -1
  139. package/dist/languages/ja-JP.js +36 -38
  140. package/dist/languages/ja-JP.min.js +1 -1
  141. package/dist/languages/ko-KR.js +36 -39
  142. package/dist/languages/ko-KR.min.js +1 -1
  143. package/dist/languages/lv-LV.js +2 -2
  144. package/dist/languages/lv-LV.min.js +1 -1
  145. package/dist/languages/nb-NO.js +2 -2
  146. package/dist/languages/nb-NO.min.js +1 -1
  147. package/dist/languages/nl-NL.js +2 -2
  148. package/dist/languages/nl-NL.min.js +1 -1
  149. package/dist/languages/pl-PL.js +2 -2
  150. package/dist/languages/pl-PL.min.js +1 -1
  151. package/dist/languages/pt-BR.js +2 -2
  152. package/dist/languages/pt-BR.min.js +1 -1
  153. package/dist/languages/ru-RU.js +2 -2
  154. package/dist/languages/ru-RU.min.js +1 -1
  155. package/dist/languages/sr-SP.js +171 -0
  156. package/dist/languages/sr-SP.min.js +1 -0
  157. package/dist/languages/zh-CN.js +24 -24
  158. package/dist/languages/zh-CN.min.js +1 -1
  159. package/dist/languages/zh-TW.js +24 -24
  160. package/dist/languages/zh-TW.min.js +1 -1
  161. package/editorManager.js +120 -267
  162. package/editorManager.mjs +128 -278
  163. package/editors/autocompleteEditor/autocompleteEditor.js +22 -25
  164. package/editors/autocompleteEditor/autocompleteEditor.mjs +22 -25
  165. package/editors/baseEditor/baseEditor.js +205 -34
  166. package/editors/baseEditor/baseEditor.mjs +200 -32
  167. package/editors/checkboxEditor/checkboxEditor.js +2 -2
  168. package/editors/checkboxEditor/checkboxEditor.mjs +2 -2
  169. package/editors/dateEditor/dateEditor.js +21 -8
  170. package/editors/dateEditor/dateEditor.mjs +22 -9
  171. package/editors/dropdownEditor/dropdownEditor.js +3 -3
  172. package/editors/dropdownEditor/dropdownEditor.mjs +3 -3
  173. package/editors/handsontableEditor/handsontableEditor.js +106 -55
  174. package/editors/handsontableEditor/handsontableEditor.mjs +106 -55
  175. package/editors/index.d.ts +3 -0
  176. package/editors/index.js +6 -0
  177. package/editors/index.mjs +3 -1
  178. package/editors/numericEditor/numericEditor.js +2 -2
  179. package/editors/numericEditor/numericEditor.mjs +2 -2
  180. package/editors/passwordEditor/passwordEditor.js +3 -3
  181. package/editors/passwordEditor/passwordEditor.mjs +3 -3
  182. package/editors/selectEditor/selectEditor.js +65 -110
  183. package/editors/selectEditor/selectEditor.mjs +66 -109
  184. package/editors/textEditor/caretPositioner.js +49 -0
  185. package/editors/textEditor/caretPositioner.mjs +42 -0
  186. package/editors/textEditor/textEditor.js +205 -181
  187. package/editors/textEditor/textEditor.mjs +199 -179
  188. package/editors/timeEditor/index.d.ts +1 -0
  189. package/editors/timeEditor/index.js +9 -0
  190. package/editors/timeEditor/index.mjs +1 -0
  191. package/editors/timeEditor/timeEditor.d.ts +7 -0
  192. package/editors/timeEditor/timeEditor.js +105 -0
  193. package/editors/timeEditor/timeEditor.mjs +84 -0
  194. package/eventManager.js +4 -2
  195. package/eventManager.mjs +4 -2
  196. package/helpers/mixed.js +2 -2
  197. package/helpers/mixed.mjs +2 -2
  198. package/i18n/languages/ar-AR.js +41 -0
  199. package/i18n/languages/ar-AR.mjs +17 -0
  200. package/i18n/languages/cs-CZ.js +40 -0
  201. package/i18n/languages/cs-CZ.mjs +16 -0
  202. package/i18n/languages/index.js +12 -0
  203. package/i18n/languages/index.mjs +4 -1
  204. package/i18n/languages/sr-SP.js +40 -0
  205. package/i18n/languages/sr-SP.mjs +16 -0
  206. package/index.d.ts +4 -0
  207. package/languages/all.js +131 -34
  208. package/languages/ar-AR.js +167 -0
  209. package/languages/ar-AR.mjs +19 -0
  210. package/languages/cs-CZ.js +167 -0
  211. package/languages/cs-CZ.mjs +18 -0
  212. package/languages/de-CH.js +31 -29
  213. package/languages/de-DE.js +4 -2
  214. package/languages/en-US.js +4 -2
  215. package/languages/es-MX.js +4 -2
  216. package/languages/fr-FR.js +4 -2
  217. package/languages/index.js +131 -34
  218. package/languages/index.mjs +4 -1
  219. package/languages/it-IT.js +4 -2
  220. package/languages/ja-JP.js +36 -38
  221. package/languages/ko-KR.js +36 -39
  222. package/languages/lv-LV.js +2 -2
  223. package/languages/nb-NO.js +2 -2
  224. package/languages/nl-NL.js +2 -2
  225. package/languages/pl-PL.js +2 -2
  226. package/languages/pt-BR.js +2 -2
  227. package/languages/ru-RU.js +2 -2
  228. package/languages/sr-SP.js +171 -0
  229. package/languages/sr-SP.mjs +18 -0
  230. package/languages/zh-CN.js +24 -24
  231. package/languages/zh-TW.js +24 -24
  232. package/package.json +44 -4
  233. package/pluginHooks.js +49 -13
  234. package/pluginHooks.mjs +49 -13
  235. package/plugins/autoColumnSize/autoColumnSize.js +15 -10
  236. package/plugins/autoColumnSize/autoColumnSize.mjs +15 -10
  237. package/plugins/autoRowSize/autoRowSize.js +14 -9
  238. package/plugins/autoRowSize/autoRowSize.mjs +14 -9
  239. package/plugins/autofill/autofill.js +49 -33
  240. package/plugins/autofill/autofill.mjs +49 -32
  241. package/plugins/autofill/utils.js +10 -11
  242. package/plugins/autofill/utils.mjs +10 -10
  243. package/plugins/base/base.d.ts +8 -2
  244. package/plugins/base/base.js +67 -4
  245. package/plugins/base/base.mjs +66 -4
  246. package/plugins/bindRowsWithHeaders/bindRowsWithHeaders.js +3 -3
  247. package/plugins/bindRowsWithHeaders/bindRowsWithHeaders.mjs +3 -3
  248. package/plugins/bindRowsWithHeaders/maps/looseBindsMap.js +3 -3
  249. package/plugins/bindRowsWithHeaders/maps/looseBindsMap.mjs +3 -3
  250. package/plugins/bindRowsWithHeaders/maps/strictBindsMap.js +3 -3
  251. package/plugins/bindRowsWithHeaders/maps/strictBindsMap.mjs +3 -3
  252. package/plugins/collapsibleColumns/collapsibleColumns.js +27 -9
  253. package/plugins/collapsibleColumns/collapsibleColumns.mjs +27 -9
  254. package/plugins/columnSorting/columnSorting.js +5 -7
  255. package/plugins/columnSorting/columnSorting.mjs +5 -6
  256. package/plugins/columnSummary/columnSummary.js +3 -3
  257. package/plugins/columnSummary/columnSummary.mjs +3 -3
  258. package/plugins/comments/commentEditor.js +18 -2
  259. package/plugins/comments/commentEditor.mjs +19 -3
  260. package/plugins/comments/comments.js +57 -46
  261. package/plugins/comments/comments.mjs +58 -46
  262. package/plugins/contextMenu/contextMenu.js +10 -6
  263. package/plugins/contextMenu/contextMenu.mjs +10 -6
  264. package/plugins/contextMenu/menu.js +222 -110
  265. package/plugins/contextMenu/menu.mjs +219 -111
  266. package/plugins/contextMenu/predefinedItems/columnLeft.js +12 -4
  267. package/plugins/contextMenu/predefinedItems/columnLeft.mjs +11 -4
  268. package/plugins/contextMenu/predefinedItems/columnRight.js +9 -9
  269. package/plugins/contextMenu/predefinedItems/columnRight.mjs +9 -9
  270. package/plugins/contextMenu/utils.js +2 -2
  271. package/plugins/contextMenu/utils.mjs +2 -2
  272. package/plugins/copyPaste/copyPaste.js +31 -21
  273. package/plugins/copyPaste/copyPaste.mjs +30 -21
  274. package/plugins/customBorders/contextMenuItem/left.js +4 -3
  275. package/plugins/customBorders/contextMenuItem/left.mjs +4 -3
  276. package/plugins/customBorders/contextMenuItem/right.js +4 -3
  277. package/plugins/customBorders/contextMenuItem/right.mjs +4 -3
  278. package/plugins/customBorders/customBorders.js +144 -87
  279. package/plugins/customBorders/customBorders.mjs +143 -85
  280. package/plugins/customBorders/utils.js +131 -27
  281. package/plugins/customBorders/utils.mjs +115 -27
  282. package/plugins/dragToScroll/dragToScroll.js +10 -5
  283. package/plugins/dragToScroll/dragToScroll.mjs +10 -5
  284. package/plugins/dropdownMenu/dropdownMenu.js +9 -7
  285. package/plugins/dropdownMenu/dropdownMenu.mjs +9 -7
  286. package/plugins/exportFile/exportFile.js +2 -2
  287. package/plugins/exportFile/exportFile.mjs +2 -2
  288. package/plugins/exportFile/types/csv.js +2 -2
  289. package/plugins/exportFile/types/csv.mjs +2 -2
  290. package/plugins/filters/component/actionBar.js +2 -2
  291. package/plugins/filters/component/actionBar.mjs +2 -2
  292. package/plugins/filters/component/condition.js +3 -3
  293. package/plugins/filters/component/condition.mjs +3 -3
  294. package/plugins/filters/component/operators.js +2 -2
  295. package/plugins/filters/component/operators.mjs +2 -2
  296. package/plugins/filters/component/value.js +3 -3
  297. package/plugins/filters/component/value.mjs +3 -3
  298. package/plugins/filters/filters.js +11 -8
  299. package/plugins/filters/filters.mjs +11 -8
  300. package/plugins/filters/ui/input.js +3 -3
  301. package/plugins/filters/ui/input.mjs +3 -3
  302. package/plugins/filters/ui/link.js +3 -3
  303. package/plugins/filters/ui/link.mjs +3 -3
  304. package/plugins/filters/ui/multipleSelect.js +18 -31
  305. package/plugins/filters/ui/multipleSelect.mjs +18 -31
  306. package/plugins/filters/ui/radioInput.js +3 -3
  307. package/plugins/filters/ui/radioInput.mjs +3 -3
  308. package/plugins/filters/ui/select.js +4 -4
  309. package/plugins/filters/ui/select.mjs +4 -4
  310. package/plugins/formulas/formulas.js +14 -9
  311. package/plugins/formulas/formulas.mjs +14 -9
  312. package/plugins/hiddenColumns/contextMenuItem/hideColumn.js +2 -4
  313. package/plugins/hiddenColumns/contextMenuItem/hideColumn.mjs +2 -4
  314. package/plugins/hiddenColumns/contextMenuItem/showColumn.js +5 -5
  315. package/plugins/hiddenColumns/contextMenuItem/showColumn.mjs +5 -5
  316. package/plugins/hiddenColumns/hiddenColumns.js +9 -4
  317. package/plugins/hiddenColumns/hiddenColumns.mjs +9 -4
  318. package/plugins/hiddenRows/contextMenuItem/hideRow.js +2 -4
  319. package/plugins/hiddenRows/contextMenuItem/hideRow.mjs +2 -4
  320. package/plugins/hiddenRows/contextMenuItem/showRow.js +5 -5
  321. package/plugins/hiddenRows/contextMenuItem/showRow.mjs +5 -5
  322. package/plugins/hiddenRows/hiddenRows.js +9 -4
  323. package/plugins/hiddenRows/hiddenRows.mjs +9 -4
  324. package/plugins/manualColumnFreeze/contextMenuItem/freezeColumn.js +1 -1
  325. package/plugins/manualColumnFreeze/contextMenuItem/freezeColumn.mjs +1 -1
  326. package/plugins/manualColumnFreeze/contextMenuItem/unfreezeColumn.js +1 -1
  327. package/plugins/manualColumnFreeze/contextMenuItem/unfreezeColumn.mjs +1 -1
  328. package/plugins/manualColumnFreeze/manualColumnFreeze.js +54 -15
  329. package/plugins/manualColumnFreeze/manualColumnFreeze.mjs +49 -15
  330. package/plugins/manualColumnMove/manualColumnMove.js +70 -70
  331. package/plugins/manualColumnMove/manualColumnMove.mjs +71 -71
  332. package/plugins/manualColumnMove/ui/_base.js +25 -12
  333. package/plugins/manualColumnMove/ui/_base.mjs +24 -12
  334. package/plugins/manualColumnMove/ui/backlight.js +3 -3
  335. package/plugins/manualColumnMove/ui/backlight.mjs +3 -3
  336. package/plugins/manualColumnMove/ui/guideline.js +3 -3
  337. package/plugins/manualColumnMove/ui/guideline.mjs +3 -3
  338. package/plugins/manualColumnResize/manualColumnResize.js +37 -21
  339. package/plugins/manualColumnResize/manualColumnResize.mjs +37 -21
  340. package/plugins/manualRowMove/manualRowMove.js +26 -34
  341. package/plugins/manualRowMove/manualRowMove.mjs +26 -34
  342. package/plugins/manualRowMove/ui/backlight.js +3 -3
  343. package/plugins/manualRowMove/ui/backlight.mjs +3 -3
  344. package/plugins/manualRowMove/ui/guideline.js +3 -3
  345. package/plugins/manualRowMove/ui/guideline.mjs +3 -3
  346. package/plugins/manualRowResize/manualRowResize.js +34 -19
  347. package/plugins/manualRowResize/manualRowResize.mjs +34 -19
  348. package/plugins/mergeCells/calculations/autofill.js +6 -5
  349. package/plugins/mergeCells/calculations/autofill.mjs +6 -4
  350. package/plugins/mergeCells/calculations/selection.js +9 -4
  351. package/plugins/mergeCells/calculations/selection.mjs +9 -4
  352. package/plugins/mergeCells/cellCoords.js +16 -4
  353. package/plugins/mergeCells/cellCoords.mjs +16 -3
  354. package/plugins/mergeCells/cellsCollection.js +30 -23
  355. package/plugins/mergeCells/cellsCollection.mjs +30 -22
  356. package/plugins/mergeCells/mergeCells.js +94 -61
  357. package/plugins/mergeCells/mergeCells.mjs +94 -59
  358. package/plugins/multiColumnSorting/multiColumnSorting.js +4 -6
  359. package/plugins/multiColumnSorting/multiColumnSorting.mjs +4 -5
  360. package/plugins/multipleSelectionHandles/multipleSelectionHandles.js +51 -57
  361. package/plugins/multipleSelectionHandles/multipleSelectionHandles.mjs +52 -57
  362. package/plugins/nestedHeaders/nestedHeaders.js +31 -20
  363. package/plugins/nestedHeaders/nestedHeaders.mjs +31 -20
  364. package/plugins/nestedHeaders/stateManager/utils.js +3 -4
  365. package/plugins/nestedHeaders/stateManager/utils.mjs +3 -4
  366. package/plugins/nestedHeaders/utils/ghostTable.js +114 -75
  367. package/plugins/nestedHeaders/utils/ghostTable.mjs +114 -74
  368. package/plugins/nestedRows/nestedRows.js +9 -4
  369. package/plugins/nestedRows/nestedRows.mjs +9 -4
  370. package/plugins/nestedRows/ui/collapsing.js +2 -2
  371. package/plugins/nestedRows/ui/collapsing.mjs +2 -2
  372. package/plugins/nestedRows/ui/contextMenu.js +2 -2
  373. package/plugins/nestedRows/ui/contextMenu.mjs +2 -2
  374. package/plugins/nestedRows/ui/headers.js +2 -2
  375. package/plugins/nestedRows/ui/headers.mjs +2 -2
  376. package/plugins/nestedRows/utils/rowMoveController.js +2 -4
  377. package/plugins/nestedRows/utils/rowMoveController.mjs +2 -3
  378. package/plugins/persistentState/persistentState.js +9 -4
  379. package/plugins/persistentState/persistentState.mjs +9 -4
  380. package/plugins/search/search.js +9 -4
  381. package/plugins/search/search.mjs +9 -4
  382. package/plugins/touchScroll/touchScroll.js +27 -21
  383. package/plugins/touchScroll/touchScroll.mjs +27 -21
  384. package/plugins/trimRows/trimRows.js +9 -4
  385. package/plugins/trimRows/trimRows.mjs +9 -4
  386. package/plugins/undoRedo/undoRedo.js +53 -47
  387. package/plugins/undoRedo/undoRedo.mjs +53 -46
  388. package/renderers/autocompleteRenderer/autocompleteRenderer.js +1 -3
  389. package/renderers/autocompleteRenderer/autocompleteRenderer.mjs +1 -2
  390. package/renderers/checkboxRenderer/checkboxRenderer.js +48 -43
  391. package/renderers/checkboxRenderer/checkboxRenderer.mjs +48 -41
  392. package/renderers/index.d.ts +4 -1
  393. package/renderers/index.js +6 -0
  394. package/renderers/index.mjs +3 -1
  395. package/renderers/numericRenderer/numericRenderer.js +1 -0
  396. package/renderers/numericRenderer/numericRenderer.mjs +1 -0
  397. package/renderers/timeRenderer/index.d.ts +1 -0
  398. package/renderers/timeRenderer/index.js +9 -0
  399. package/renderers/timeRenderer/index.mjs +1 -0
  400. package/renderers/timeRenderer/timeRenderer.d.ts +5 -0
  401. package/renderers/timeRenderer/timeRenderer.js +31 -0
  402. package/renderers/timeRenderer/timeRenderer.mjs +20 -0
  403. package/selection/highlight/visualSelection.js +94 -220
  404. package/selection/highlight/visualSelection.mjs +91 -213
  405. package/selection/mouseEventHandler.js +15 -10
  406. package/selection/mouseEventHandler.mjs +15 -9
  407. package/selection/range.js +4 -5
  408. package/selection/range.mjs +4 -5
  409. package/selection/selection.js +35 -22
  410. package/selection/selection.mjs +35 -20
  411. package/selection/transformation.js +4 -6
  412. package/selection/transformation.mjs +4 -5
  413. package/settings.d.ts +3 -1
  414. package/shortcuts/context.d.ts +20 -0
  415. package/shortcuts/context.js +296 -0
  416. package/shortcuts/context.mjs +268 -0
  417. package/shortcuts/index.d.ts +1 -0
  418. package/shortcuts/index.js +8 -0
  419. package/shortcuts/index.mjs +1 -0
  420. package/shortcuts/keyObserver.js +67 -0
  421. package/shortcuts/keyObserver.mjs +58 -0
  422. package/shortcuts/manager.d.ts +10 -0
  423. package/shortcuts/manager.js +185 -0
  424. package/shortcuts/manager.mjs +176 -0
  425. package/shortcuts/recorder.js +192 -0
  426. package/shortcuts/recorder.mjs +180 -0
  427. package/shortcuts/utils.js +77 -0
  428. package/shortcuts/utils.mjs +54 -0
  429. package/tableView.js +164 -84
  430. package/tableView.mjs +164 -74
  431. package/translations/changesObservable/observer.js +0 -1
  432. package/translations/changesObservable/observer.mjs +0 -1
  433. package/translations/indexMapper.d.ts +3 -1
  434. package/translations/indexMapper.js +89 -11
  435. package/translations/indexMapper.mjs +91 -20
  436. package/translations/mapCollections/aggregatedCollection.js +2 -2
  437. package/translations/mapCollections/aggregatedCollection.mjs +2 -2
  438. package/translations/maps/hidingMap.js +4 -2
  439. package/translations/maps/hidingMap.mjs +4 -2
  440. package/translations/maps/indexMap.js +2 -0
  441. package/translations/maps/indexMap.mjs +2 -0
  442. package/translations/maps/indexesSequence.js +5 -3
  443. package/translations/maps/indexesSequence.mjs +5 -3
  444. package/translations/maps/linkedPhysicalIndexToValueMap.js +5 -3
  445. package/translations/maps/linkedPhysicalIndexToValueMap.mjs +5 -3
  446. package/translations/maps/physicalIndexToValueMap.js +5 -3
  447. package/translations/maps/physicalIndexToValueMap.mjs +5 -3
  448. package/translations/maps/trimmingMap.js +4 -2
  449. package/translations/maps/trimmingMap.mjs +4 -2
  450. package/utils/dataStructures/uniqueMap.js +14 -1
  451. package/utils/dataStructures/uniqueMap.mjs +14 -1
  452. package/utils/dataStructures/uniqueSet.js +9 -0
  453. package/utils/dataStructures/uniqueSet.mjs +9 -0
  454. package/utils/ghostTable.js +1 -1
  455. package/utils/ghostTable.mjs +1 -1
  456. package/3rdparty/walkontable/src/core.js +0 -309
  457. package/3rdparty/walkontable/src/core.mjs +0 -293
  458. package/3rdparty/walkontable/src/overlay/registerer.js +0 -70
  459. package/3rdparty/walkontable/src/overlay/registerer.mjs +0 -57
  460. package/utils/keyStateObserver.js +0 -121
  461. package/utils/keyStateObserver.mjs +0 -103
@@ -0,0 +1,58 @@
1
+ import "core-js/modules/es.array.iterator.js";
2
+ import "core-js/modules/es.object.to-string.js";
3
+ import "core-js/modules/es.set.js";
4
+ import "core-js/modules/es.string.iterator.js";
5
+ import "core-js/modules/web.dom-collections.iterator.js";
6
+
7
+ /* eslint-disable jsdoc/require-description-complete-sentence */
8
+
9
+ /**
10
+ * Create a key observer.
11
+ *
12
+ * @returns {object}
13
+ */
14
+ export function createKeysObserver() {
15
+ var PRESSED_KEYS = new Set();
16
+ return {
17
+ /**
18
+ * Press a key.
19
+ *
20
+ * @param {string} key Names of the shortcut's keys,
21
+ * (coming from [`KeyboardEvent.key`](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values)),
22
+ * in lowercase or uppercase, unified across browsers
23
+ */
24
+ press: function press(key) {
25
+ PRESSED_KEYS.add(key);
26
+ },
27
+
28
+ /**
29
+ * Release a pressed key.
30
+ *
31
+ * @param {string} key Names of the shortcut's keys,
32
+ * (coming from [`KeyboardEvent.key`](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values)),
33
+ * in lowercase or uppercase, unified across browsers
34
+ */
35
+ release: function release(key) {
36
+ PRESSED_KEYS.delete(key);
37
+ },
38
+
39
+ /**
40
+ * Release all pressed keys.
41
+ */
42
+ releaseAll: function releaseAll() {
43
+ PRESSED_KEYS.clear();
44
+ },
45
+
46
+ /**
47
+ * Check if a key is pressed.
48
+ *
49
+ * @param {string} key Names of the shortcut's keys,
50
+ * (coming from [`KeyboardEvent.key`](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values)),
51
+ * in lowercase or uppercase, unified across browsers
52
+ * @returns {boolean}
53
+ */
54
+ isPressed: function isPressed(key) {
55
+ return PRESSED_KEYS.has(key);
56
+ }
57
+ };
58
+ }
@@ -0,0 +1,10 @@
1
+ import { Context } from './context';
2
+
3
+ export interface ShortcutManager {
4
+ addContext(contextName: string): Context;
5
+ getActiveContextName(): string;
6
+ getContext(contextName: string): Context | undefined;
7
+ setActiveContextName(contextName: string): void;
8
+ isCtrlPressed(): boolean;
9
+ destroy(): void;
10
+ }
@@ -0,0 +1,185 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.createShortcutManager = void 0;
5
+
6
+ var _uniqueMap = require("../utils/dataStructures/uniqueMap");
7
+
8
+ var _context = require("./context");
9
+
10
+ var _recorder = require("./recorder");
11
+
12
+ /* eslint-disable jsdoc/require-description-complete-sentence */
13
+
14
+ /**
15
+ * The `ShortcutManager` API lets you store and manage [keyboard shortcut contexts](@/guides/accessories-and-menus/keyboard-shortcuts.md#keyboard-shortcut-contexts) ([`ShortcutContext`](@/api/shortcutContext.md)).
16
+ *
17
+ * Each `ShortcutManager` object:
18
+ * - Stores and manages its own set of keyboard shortcut contexts.
19
+ * - Listens to the [`KeyboardEvent`](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent) events and runs actions for them.
20
+ *
21
+ * @alias ShortcutManager
22
+ * @class ShortcutManager
23
+ * @param {object} options The manager's options
24
+ * @param {EventTarget} options.ownerWindow A starting `window` element
25
+ * @param {Function} options.handleEvent A condition on which `event` is handled.
26
+ * @param {Function} options.beforeKeyDown A hook fired before the `keydown` event is handled. You can use it to [block a keyboard shortcut's actions](@/guides/accessories-and-menus/keyboard-shortcuts.md#blocking-a-keyboard-shortcut-s-actions).
27
+ * @param {Function} options.afterKeyDown A hook fired after the `keydown` event is handled
28
+ */
29
+ var createShortcutManager = function createShortcutManager(_ref) {
30
+ var ownerWindow = _ref.ownerWindow,
31
+ handleEvent = _ref.handleEvent,
32
+ beforeKeyDown = _ref.beforeKeyDown,
33
+ afterKeyDown = _ref.afterKeyDown;
34
+
35
+ /**
36
+ * A unique map that stores keyboard shortcut contexts.
37
+ *
38
+ * @type {UniqueMap}
39
+ */
40
+ var CONTEXTS = (0, _uniqueMap.createUniqueMap)({
41
+ errorIdExists: function errorIdExists(keys) {
42
+ return "The \"".concat(keys, "\" context name is already registered.");
43
+ }
44
+ });
45
+ /**
46
+ * The name of the active [`ShortcutContext`](@/api/shortcutContext.md).
47
+ *
48
+ * @type {string}
49
+ */
50
+
51
+ var activeContextName = 'grid';
52
+ /**
53
+ * Create a new [`ShortcutContext`](@/api/shortcutContext.md) object.
54
+ *
55
+ * @memberof ShortcutManager#
56
+ * @param {string} contextName The name of the new shortcut context
57
+ * @returns {object}
58
+ */
59
+
60
+ var addContext = function addContext(contextName) {
61
+ var context = (0, _context.createContext)(contextName);
62
+ CONTEXTS.addItem(contextName, context);
63
+ return context;
64
+ };
65
+ /**
66
+ * Get the ID of the active [`ShortcutContext`](@/api/shortcutContext.md).
67
+ *
68
+ * @memberof ShortcutManager#
69
+ * @returns {string}
70
+ */
71
+
72
+
73
+ var getActiveContextName = function getActiveContextName() {
74
+ return activeContextName;
75
+ };
76
+ /**
77
+ * Get a keyboard shortcut context by its name.
78
+ *
79
+ * @memberof ShortcutManager#
80
+ * @param {string} contextName The name of the shortcut context
81
+ * @returns {object|undefined} A [`ShortcutContext`](@/api/shortcutContext.md) object that stores registered shortcuts
82
+ */
83
+
84
+
85
+ var getContext = function getContext(contextName) {
86
+ return CONTEXTS.getItem(contextName);
87
+ };
88
+ /**
89
+ * Start listening to keyboard shortcuts within a given [`ShortcutContext`](@/api/shortcutContext.md).
90
+ *
91
+ * @memberof ShortcutManager#
92
+ * @param {string} contextName The name of the shortcut context
93
+ */
94
+
95
+
96
+ var setActiveContextName = function setActiveContextName(contextName) {
97
+ activeContextName = contextName;
98
+ };
99
+ /**
100
+ * This variable relates to the `captureCtrl` shortcut option,
101
+ * which allows for capturing the state of the Control/Meta modifier key.
102
+ * Some of the default keyboard shortcuts related to cell selection need this feature for working properly.
103
+ *
104
+ * @type {boolean}
105
+ */
106
+
107
+
108
+ var isCtrlKeySilenced = false;
109
+ /**
110
+ * Internal key recorder.
111
+ *
112
+ * @private
113
+ */
114
+
115
+ var keyRecorder = (0, _recorder.useRecorder)(ownerWindow, handleEvent, beforeKeyDown, afterKeyDown, function (event, keys) {
116
+ var activeContext = getContext(getActiveContextName());
117
+ var isExecutionCancelled = false;
118
+
119
+ if (!activeContext.hasShortcut(keys)) {
120
+ return isExecutionCancelled;
121
+ } // Processing just actions being in stack at the moment of shortcut pressing (without respecting additions/removals performed dynamically).
122
+
123
+
124
+ var shortcuts = activeContext.getShortcuts(keys);
125
+
126
+ for (var index = 0; index < shortcuts.length; index++) {
127
+ var _shortcuts$index = shortcuts[index],
128
+ callback = _shortcuts$index.callback,
129
+ runOnlyIf = _shortcuts$index.runOnlyIf,
130
+ preventDefault = _shortcuts$index.preventDefault,
131
+ stopPropagation = _shortcuts$index.stopPropagation,
132
+ captureCtrl = _shortcuts$index.captureCtrl;
133
+
134
+ if (runOnlyIf(event) !== false) {
135
+ isCtrlKeySilenced = captureCtrl;
136
+ isExecutionCancelled = callback(event, keys) === false;
137
+ isCtrlKeySilenced = false;
138
+
139
+ if (preventDefault) {
140
+ event.preventDefault();
141
+ }
142
+
143
+ if (stopPropagation) {
144
+ event.stopPropagation();
145
+ }
146
+
147
+ if (isExecutionCancelled) {
148
+ break;
149
+ }
150
+ }
151
+ }
152
+
153
+ return isExecutionCancelled;
154
+ });
155
+ keyRecorder.mount();
156
+ return {
157
+ addContext: addContext,
158
+ getActiveContextName: getActiveContextName,
159
+ getContext: getContext,
160
+ setActiveContextName: setActiveContextName,
161
+
162
+ /**
163
+ * Returns whether `control` or `meta` keys are pressed.
164
+ *
165
+ * @memberof ShortcutManager#
166
+ * @type {Function}
167
+ * @returns {boolean}
168
+ */
169
+ isCtrlPressed: function isCtrlPressed() {
170
+ return !isCtrlKeySilenced && (keyRecorder.isPressed('control') || keyRecorder.isPressed('meta'));
171
+ },
172
+
173
+ /**
174
+ * Destroy a context manager instance.
175
+ *
176
+ * @type {Function}
177
+ * @memberof ShortcutManager#
178
+ */
179
+ destroy: function destroy() {
180
+ return keyRecorder.unmount();
181
+ }
182
+ };
183
+ };
184
+
185
+ exports.createShortcutManager = createShortcutManager;
@@ -0,0 +1,176 @@
1
+ import { createUniqueMap } from "../utils/dataStructures/uniqueMap.mjs";
2
+ import { createContext } from "./context.mjs";
3
+ import { useRecorder } from "./recorder.mjs";
4
+ /* eslint-disable jsdoc/require-description-complete-sentence */
5
+
6
+ /**
7
+ * The `ShortcutManager` API lets you store and manage [keyboard shortcut contexts](@/guides/accessories-and-menus/keyboard-shortcuts.md#keyboard-shortcut-contexts) ([`ShortcutContext`](@/api/shortcutContext.md)).
8
+ *
9
+ * Each `ShortcutManager` object:
10
+ * - Stores and manages its own set of keyboard shortcut contexts.
11
+ * - Listens to the [`KeyboardEvent`](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent) events and runs actions for them.
12
+ *
13
+ * @alias ShortcutManager
14
+ * @class ShortcutManager
15
+ * @param {object} options The manager's options
16
+ * @param {EventTarget} options.ownerWindow A starting `window` element
17
+ * @param {Function} options.handleEvent A condition on which `event` is handled.
18
+ * @param {Function} options.beforeKeyDown A hook fired before the `keydown` event is handled. You can use it to [block a keyboard shortcut's actions](@/guides/accessories-and-menus/keyboard-shortcuts.md#blocking-a-keyboard-shortcut-s-actions).
19
+ * @param {Function} options.afterKeyDown A hook fired after the `keydown` event is handled
20
+ */
21
+
22
+ export var createShortcutManager = function createShortcutManager(_ref) {
23
+ var ownerWindow = _ref.ownerWindow,
24
+ handleEvent = _ref.handleEvent,
25
+ beforeKeyDown = _ref.beforeKeyDown,
26
+ afterKeyDown = _ref.afterKeyDown;
27
+
28
+ /**
29
+ * A unique map that stores keyboard shortcut contexts.
30
+ *
31
+ * @type {UniqueMap}
32
+ */
33
+ var CONTEXTS = createUniqueMap({
34
+ errorIdExists: function errorIdExists(keys) {
35
+ return "The \"".concat(keys, "\" context name is already registered.");
36
+ }
37
+ });
38
+ /**
39
+ * The name of the active [`ShortcutContext`](@/api/shortcutContext.md).
40
+ *
41
+ * @type {string}
42
+ */
43
+
44
+ var activeContextName = 'grid';
45
+ /**
46
+ * Create a new [`ShortcutContext`](@/api/shortcutContext.md) object.
47
+ *
48
+ * @memberof ShortcutManager#
49
+ * @param {string} contextName The name of the new shortcut context
50
+ * @returns {object}
51
+ */
52
+
53
+ var addContext = function addContext(contextName) {
54
+ var context = createContext(contextName);
55
+ CONTEXTS.addItem(contextName, context);
56
+ return context;
57
+ };
58
+ /**
59
+ * Get the ID of the active [`ShortcutContext`](@/api/shortcutContext.md).
60
+ *
61
+ * @memberof ShortcutManager#
62
+ * @returns {string}
63
+ */
64
+
65
+
66
+ var getActiveContextName = function getActiveContextName() {
67
+ return activeContextName;
68
+ };
69
+ /**
70
+ * Get a keyboard shortcut context by its name.
71
+ *
72
+ * @memberof ShortcutManager#
73
+ * @param {string} contextName The name of the shortcut context
74
+ * @returns {object|undefined} A [`ShortcutContext`](@/api/shortcutContext.md) object that stores registered shortcuts
75
+ */
76
+
77
+
78
+ var getContext = function getContext(contextName) {
79
+ return CONTEXTS.getItem(contextName);
80
+ };
81
+ /**
82
+ * Start listening to keyboard shortcuts within a given [`ShortcutContext`](@/api/shortcutContext.md).
83
+ *
84
+ * @memberof ShortcutManager#
85
+ * @param {string} contextName The name of the shortcut context
86
+ */
87
+
88
+
89
+ var setActiveContextName = function setActiveContextName(contextName) {
90
+ activeContextName = contextName;
91
+ };
92
+ /**
93
+ * This variable relates to the `captureCtrl` shortcut option,
94
+ * which allows for capturing the state of the Control/Meta modifier key.
95
+ * Some of the default keyboard shortcuts related to cell selection need this feature for working properly.
96
+ *
97
+ * @type {boolean}
98
+ */
99
+
100
+
101
+ var isCtrlKeySilenced = false;
102
+ /**
103
+ * Internal key recorder.
104
+ *
105
+ * @private
106
+ */
107
+
108
+ var keyRecorder = useRecorder(ownerWindow, handleEvent, beforeKeyDown, afterKeyDown, function (event, keys) {
109
+ var activeContext = getContext(getActiveContextName());
110
+ var isExecutionCancelled = false;
111
+
112
+ if (!activeContext.hasShortcut(keys)) {
113
+ return isExecutionCancelled;
114
+ } // Processing just actions being in stack at the moment of shortcut pressing (without respecting additions/removals performed dynamically).
115
+
116
+
117
+ var shortcuts = activeContext.getShortcuts(keys);
118
+
119
+ for (var index = 0; index < shortcuts.length; index++) {
120
+ var _shortcuts$index = shortcuts[index],
121
+ callback = _shortcuts$index.callback,
122
+ runOnlyIf = _shortcuts$index.runOnlyIf,
123
+ preventDefault = _shortcuts$index.preventDefault,
124
+ stopPropagation = _shortcuts$index.stopPropagation,
125
+ captureCtrl = _shortcuts$index.captureCtrl;
126
+
127
+ if (runOnlyIf(event) !== false) {
128
+ isCtrlKeySilenced = captureCtrl;
129
+ isExecutionCancelled = callback(event, keys) === false;
130
+ isCtrlKeySilenced = false;
131
+
132
+ if (preventDefault) {
133
+ event.preventDefault();
134
+ }
135
+
136
+ if (stopPropagation) {
137
+ event.stopPropagation();
138
+ }
139
+
140
+ if (isExecutionCancelled) {
141
+ break;
142
+ }
143
+ }
144
+ }
145
+
146
+ return isExecutionCancelled;
147
+ });
148
+ keyRecorder.mount();
149
+ return {
150
+ addContext: addContext,
151
+ getActiveContextName: getActiveContextName,
152
+ getContext: getContext,
153
+ setActiveContextName: setActiveContextName,
154
+
155
+ /**
156
+ * Returns whether `control` or `meta` keys are pressed.
157
+ *
158
+ * @memberof ShortcutManager#
159
+ * @type {Function}
160
+ * @returns {boolean}
161
+ */
162
+ isCtrlPressed: function isCtrlPressed() {
163
+ return !isCtrlKeySilenced && (keyRecorder.isPressed('control') || keyRecorder.isPressed('meta'));
164
+ },
165
+
166
+ /**
167
+ * Destroy a context manager instance.
168
+ *
169
+ * @type {Function}
170
+ * @memberof ShortcutManager#
171
+ */
172
+ destroy: function destroy() {
173
+ return keyRecorder.unmount();
174
+ }
175
+ };
176
+ };
@@ -0,0 +1,192 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.useRecorder = useRecorder;
5
+
6
+ require("core-js/modules/es.array.includes.js");
7
+
8
+ require("core-js/modules/es.array.concat.js");
9
+
10
+ require("core-js/modules/es.string.includes.js");
11
+
12
+ var _keyObserver = require("./keyObserver");
13
+
14
+ var _utils = require("./utils");
15
+
16
+ var _event = require("../helpers/dom/event");
17
+
18
+ var _browser = require("../helpers/browser");
19
+
20
+ var MODIFIER_KEYS = ['meta', 'alt', 'shift', 'control'];
21
+ var modifierKeysObserver = (0, _keyObserver.createKeysObserver)();
22
+ /* eslint-disable jsdoc/require-description-complete-sentence */
23
+
24
+ /**
25
+ * A key recorder, used for tracking key events.
26
+ *
27
+ * @param {EventTarget} ownerWindow A starting `window` element
28
+ * @param {Function} handleEvent A condition on which event is handled.
29
+ * @param {Function} beforeKeyDown A hook fired before the `keydown` event is handled.
30
+ * @param {Function} afterKeyDown A hook fired after the `keydown` event is handled
31
+ * @param {Function} callback `KeyEvent`'s listener's callback function
32
+ * @returns {object}
33
+ */
34
+
35
+ function useRecorder(ownerWindow, handleEvent, beforeKeyDown, afterKeyDown, callback) {
36
+ /**
37
+ * Check if a pressed key is tracked or not.
38
+ *
39
+ * @param {string} pressedKey A pressed key
40
+ * @returns {boolean}
41
+ */
42
+ var isModifierKey = function isModifierKey(pressedKey) {
43
+ return MODIFIER_KEYS.includes(pressedKey);
44
+ };
45
+ /**
46
+ * Get every pressed modifier key from the performed `KeyboardEvent`.
47
+ *
48
+ * @private
49
+ * @param {KeyboardEvent} event The event object.
50
+ * @param {boolean} [mergeMetaKeys=false] If `true,` the function will return the "control" and "meta"
51
+ * modifiers keys as the "control/meta" name. This allows creating
52
+ * keyboard shortcuts with modifier key that trigger the shortcut
53
+ * actions depend on the OS keyboard layout (the Meta key for macOS
54
+ * and Control for non macOS system).
55
+ * @returns {string[]}
56
+ */
57
+
58
+
59
+ var getPressedModifierKeys = function getPressedModifierKeys(event) {
60
+ var mergeMetaKeys = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
61
+ var pressedModifierKeys = [];
62
+
63
+ if (event.altKey) {
64
+ pressedModifierKeys.push('alt');
65
+ }
66
+
67
+ if (mergeMetaKeys && (event.ctrlKey || event.metaKey)) {
68
+ pressedModifierKeys.push('control/meta');
69
+ } else {
70
+ if (event.ctrlKey) {
71
+ pressedModifierKeys.push('control');
72
+ }
73
+
74
+ if (event.metaKey) {
75
+ pressedModifierKeys.push('meta');
76
+ }
77
+ }
78
+
79
+ if (event.shiftKey) {
80
+ pressedModifierKeys.push('shift');
81
+ }
82
+
83
+ return pressedModifierKeys;
84
+ };
85
+ /**
86
+ * `KeyboardEvent`'s callback function
87
+ *
88
+ * @private
89
+ * @param {KeyboardEvent} event The event object
90
+ */
91
+
92
+
93
+ var onkeydown = function onkeydown(event) {
94
+ if (handleEvent(event) === false) {
95
+ return;
96
+ }
97
+
98
+ var result = beforeKeyDown(event);
99
+
100
+ if (result === false || (0, _event.isImmediatePropagationStopped)(event)) {
101
+ return;
102
+ }
103
+
104
+ var pressedKey = (0, _utils.normalizeEventKey)(event.key);
105
+ var extraModifierKeys = [];
106
+
107
+ if (isModifierKey(pressedKey)) {
108
+ modifierKeysObserver.press(pressedKey);
109
+ } else {
110
+ extraModifierKeys = getPressedModifierKeys(event);
111
+ }
112
+
113
+ var pressedKeys = [pressedKey].concat(extraModifierKeys);
114
+ var isExecutionCancelled = callback(event, pressedKeys);
115
+
116
+ if (!isExecutionCancelled && ((0, _browser.isMacOS)() && extraModifierKeys.includes('meta') || !(0, _browser.isMacOS)() && extraModifierKeys.includes('control'))) {
117
+ // Trigger the callback for the virtual OS-dependent "control/meta" key
118
+ callback(event, [pressedKey].concat(getPressedModifierKeys(event, true)));
119
+ }
120
+
121
+ afterKeyDown(event);
122
+ };
123
+ /**
124
+ * `KeyboardEvent`'s callback function
125
+ *
126
+ * @private
127
+ * @param {KeyboardEvent} event The event object
128
+ */
129
+
130
+
131
+ var onkeyup = function onkeyup(event) {
132
+ if (handleEvent(event) === false) {
133
+ return;
134
+ }
135
+
136
+ var pressedKey = (0, _utils.normalizeEventKey)(event.key);
137
+
138
+ if (isModifierKey(pressedKey) === false) {
139
+ return;
140
+ }
141
+
142
+ modifierKeysObserver.release(pressedKey);
143
+ };
144
+ /**
145
+ * `FocusEvent`'s callback function
146
+ *
147
+ * @private
148
+ */
149
+
150
+
151
+ var onblur = function onblur() {
152
+ modifierKeysObserver.releaseAll();
153
+ };
154
+ /**
155
+ * Add event listeners to the starting window and its parents' windows.
156
+ */
157
+
158
+
159
+ var mount = function mount() {
160
+ var eventTarget = ownerWindow;
161
+
162
+ while (eventTarget) {
163
+ eventTarget.addEventListener('keydown', onkeydown);
164
+ eventTarget.addEventListener('keyup', onkeyup);
165
+ eventTarget.addEventListener('blur', onblur);
166
+ eventTarget = eventTarget.frameElement;
167
+ }
168
+ };
169
+ /**
170
+ * Remove event listeners from the starting window and its parents' windows.
171
+ */
172
+
173
+
174
+ var unmount = function unmount() {
175
+ var eventTarget = ownerWindow;
176
+
177
+ while (eventTarget) {
178
+ eventTarget.removeEventListener('keydown', onkeydown);
179
+ eventTarget.removeEventListener('keyup', onkeyup);
180
+ eventTarget.removeEventListener('blur', onblur);
181
+ eventTarget = eventTarget.frameElement;
182
+ }
183
+ };
184
+
185
+ return {
186
+ mount: mount,
187
+ unmount: unmount,
188
+ isPressed: function isPressed(key) {
189
+ return modifierKeysObserver.isPressed(key);
190
+ }
191
+ };
192
+ }