@revolist/revogrid 4.9.41 → 4.9.42

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (403) hide show
  1. package/dist/cjs/app-globals-c0b20747.js.map +1 -1
  2. package/dist/cjs/{column.drag.plugin-fcd892ec.js → column.drag.plugin-a6ef25bf.js} +1034 -149
  3. package/dist/cjs/column.drag.plugin-a6ef25bf.js.map +1 -0
  4. package/dist/cjs/column.service-831e1c92.js +1321 -0
  5. package/dist/cjs/column.service-831e1c92.js.map +1 -0
  6. package/dist/cjs/{column.service-26c61ed6.js → dimension.helpers-1927ad24.js} +490 -1273
  7. package/dist/cjs/dimension.helpers-1927ad24.js.map +1 -0
  8. package/dist/cjs/{edit.utils-179c0800.js → edit.utils-e51411f6.js} +3 -3
  9. package/dist/cjs/{edit.utils-179c0800.js.map → edit.utils-e51411f6.js.map} +1 -1
  10. package/dist/cjs/{header-cell-renderer-d879d95e.js → header-cell-renderer-53ecdcdb.js} +2 -2
  11. package/dist/cjs/{header-cell-renderer-d879d95e.js.map → header-cell-renderer-53ecdcdb.js.map} +1 -1
  12. package/dist/cjs/index.cjs.js +127 -69
  13. package/dist/cjs/index.cjs.js.map +1 -1
  14. package/dist/cjs/key.utils-96d0bc42.js +101 -0
  15. package/dist/cjs/key.utils-96d0bc42.js.map +1 -0
  16. package/dist/cjs/loader.cjs.js +1 -1
  17. package/dist/cjs/revo-grid.cjs.entry.js +310 -941
  18. package/dist/cjs/revo-grid.cjs.entry.js.map +1 -1
  19. package/dist/cjs/revo-grid.cjs.js +1 -1
  20. package/dist/cjs/revogr-attribution_7.cjs.entry.js +100 -70
  21. package/dist/cjs/revogr-attribution_7.cjs.entry.js.map +1 -1
  22. package/dist/cjs/revogr-clipboard_3.cjs.entry.js +11 -10
  23. package/dist/cjs/revogr-clipboard_3.cjs.entry.js.map +1 -1
  24. package/dist/cjs/revogr-data_4.cjs.entry.js +88 -78
  25. package/dist/cjs/revogr-data_4.cjs.entry.js.map +1 -1
  26. package/dist/cjs/revogr-filter-panel.cjs.entry.js +33 -13
  27. package/dist/cjs/revogr-filter-panel.cjs.entry.js.map +1 -1
  28. package/dist/cjs/{text-editor-b756d6b3.js → text-editor-1afffaf1.js} +6 -6
  29. package/dist/cjs/text-editor-1afffaf1.js.map +1 -0
  30. package/dist/cjs/{throttle-a57f51f9.js → throttle-bb713c73.js} +4 -4
  31. package/dist/cjs/{throttle-a57f51f9.js.map → throttle-bb713c73.js.map} +1 -1
  32. package/dist/cjs/{row-header-utils-c37f76e4.js → viewport.store-69b45f22.js} +15 -14
  33. package/dist/cjs/viewport.store-69b45f22.js.map +1 -0
  34. package/dist/collection/components/attribution/revogr-attribution.js +1 -1
  35. package/dist/collection/components/attribution/revogr-attribution.js.map +1 -1
  36. package/dist/collection/components/data/cell-renderer.js +11 -9
  37. package/dist/collection/components/data/cell-renderer.js.map +1 -1
  38. package/dist/collection/components/data/column.service.js +7 -19
  39. package/dist/collection/components/data/column.service.js.map +1 -1
  40. package/dist/collection/components/data/revogr-data-style.css +10 -5
  41. package/dist/collection/components/data/revogr-data.js +50 -28
  42. package/dist/collection/components/data/revogr-data.js.map +1 -1
  43. package/dist/collection/components/data/row-highlight.plugin.js.map +1 -1
  44. package/dist/collection/components/data/row-renderer.js.map +1 -1
  45. package/dist/collection/components/editors/revogr-edit-style.css +8 -5
  46. package/dist/collection/components/editors/revogr-edit.js +2 -2
  47. package/dist/collection/components/editors/revogr-edit.js.map +1 -1
  48. package/dist/collection/components/editors/text-editor.js +2 -2
  49. package/dist/collection/components/editors/text-editor.js.map +1 -1
  50. package/dist/collection/components/extra/revogr-extra.js +44 -6
  51. package/dist/collection/components/extra/revogr-extra.js.map +1 -1
  52. package/dist/collection/components/header/header-cell-renderer.js.map +1 -1
  53. package/dist/collection/components/header/header-renderer.js.map +1 -1
  54. package/dist/collection/components/header/resizable.element.js.map +1 -1
  55. package/dist/collection/components/header/revogr-header-style.css +8 -5
  56. package/dist/collection/components/header/revogr-header.js +9 -9
  57. package/dist/collection/components/header/revogr-header.js.map +1 -1
  58. package/dist/collection/components/order/order-renderer.js.map +1 -1
  59. package/dist/collection/components/order/revogr-order-editor.js +12 -24
  60. package/dist/collection/components/order/revogr-order-editor.js.map +1 -1
  61. package/dist/collection/components/overlay/autofill.service.js +7 -5
  62. package/dist/collection/components/overlay/autofill.service.js.map +1 -1
  63. package/dist/collection/components/overlay/keyboard.service.js +1 -4
  64. package/dist/collection/components/overlay/keyboard.service.js.map +1 -1
  65. package/dist/collection/components/overlay/revogr-overlay-selection.js +88 -72
  66. package/dist/collection/components/overlay/revogr-overlay-selection.js.map +1 -1
  67. package/dist/collection/components/overlay/revogr-overlay-style.css +8 -5
  68. package/dist/collection/components/overlay/selection.utils.js.map +1 -1
  69. package/dist/collection/components/revoGrid/plugin.service.js +81 -0
  70. package/dist/collection/components/revoGrid/plugin.service.js.map +1 -0
  71. package/dist/collection/components/revoGrid/revo-grid-style.css +18 -11
  72. package/dist/collection/components/revoGrid/revo-grid.js +289 -140
  73. package/dist/collection/components/revoGrid/revo-grid.js.map +1 -1
  74. package/dist/collection/components/revoGrid/viewport.service.js +9 -9
  75. package/dist/collection/components/revoGrid/viewport.service.js.map +1 -1
  76. package/dist/collection/components/rowHeaders/revogr-row-headers.js +1 -1
  77. package/dist/collection/components/rowHeaders/revogr-row-headers.js.map +1 -1
  78. package/dist/collection/components/rowHeaders/row-header-render.js.map +1 -1
  79. package/dist/collection/components/scroll/revogr-viewport-scroll-style.css +8 -5
  80. package/dist/collection/components/scroll/revogr-viewport-scroll.js +26 -20
  81. package/dist/collection/components/scroll/revogr-viewport-scroll.js.map +1 -1
  82. package/dist/collection/components/scrollable/revogr-scroll-style.css +10 -7
  83. package/dist/collection/components/scrollable/revogr-scroll-virtual.js +10 -8
  84. package/dist/collection/components/scrollable/revogr-scroll-virtual.js.map +1 -1
  85. package/dist/collection/components/selectionFocus/revogr-focus-style.css +8 -5
  86. package/dist/collection/components/selectionFocus/revogr-focus.js +10 -10
  87. package/dist/collection/components/selectionFocus/revogr-focus.js.map +1 -1
  88. package/dist/collection/components/selectionTempRange/revogr-temp-range-style.css +8 -5
  89. package/dist/collection/components/selectionTempRange/revogr-temp-range.js +6 -6
  90. package/dist/collection/components/selectionTempRange/revogr-temp-range.js.map +1 -1
  91. package/dist/collection/components/vnode/vnode-converter.js +1 -1
  92. package/dist/collection/components/vnode/vnode-converter.js.map +1 -1
  93. package/dist/collection/components/vnode/vnode.utils.js.map +1 -1
  94. package/dist/collection/index.js.map +1 -1
  95. package/dist/collection/plugins/add-rows-on-paste.plugin.js +40 -0
  96. package/dist/collection/plugins/add-rows-on-paste.plugin.js.map +1 -0
  97. package/dist/collection/plugins/base.plugin.js.map +1 -1
  98. package/dist/collection/plugins/column.auto-size.plugin.js +1 -1
  99. package/dist/collection/plugins/column.auto-size.plugin.js.map +1 -1
  100. package/dist/collection/plugins/column.stretch.plugin.js +1 -1
  101. package/dist/collection/plugins/column.stretch.plugin.js.map +1 -1
  102. package/dist/collection/plugins/export/csv.js +1 -1
  103. package/dist/collection/plugins/export/csv.js.map +1 -1
  104. package/dist/collection/plugins/export/export.plugin.js +4 -2
  105. package/dist/collection/plugins/export/export.plugin.js.map +1 -1
  106. package/dist/collection/plugins/filter/filter.indexed.js +1 -0
  107. package/dist/collection/plugins/filter/filter.indexed.js.map +1 -1
  108. package/dist/collection/plugins/filter/filter.panel.js +35 -35
  109. package/dist/collection/plugins/filter/filter.panel.js.map +1 -1
  110. package/dist/collection/plugins/filter/filter.plugin.js +117 -77
  111. package/dist/collection/plugins/filter/filter.plugin.js.map +1 -1
  112. package/dist/collection/plugins/filter/filter.style.css +19 -5
  113. package/dist/collection/plugins/filter/filter.types.js.map +1 -1
  114. package/dist/collection/plugins/groupingColumn/columnGroupsRenderer.js.map +1 -1
  115. package/dist/collection/plugins/groupingColumn/headerGroupRenderer.js.map +1 -1
  116. package/dist/collection/plugins/groupingRow/grouping.const.js +1 -0
  117. package/dist/collection/plugins/groupingRow/grouping.const.js.map +1 -1
  118. package/dist/collection/plugins/groupingRow/grouping.row.plugin.js +64 -79
  119. package/dist/collection/plugins/groupingRow/grouping.row.plugin.js.map +1 -1
  120. package/dist/collection/plugins/groupingRow/grouping.row.renderer.js +3 -3
  121. package/dist/collection/plugins/groupingRow/grouping.row.renderer.js.map +1 -1
  122. package/dist/collection/plugins/groupingRow/grouping.row.types.js.map +1 -1
  123. package/dist/collection/plugins/groupingRow/grouping.service.js +40 -6
  124. package/dist/collection/plugins/groupingRow/grouping.service.js.map +1 -1
  125. package/dist/collection/plugins/index.js +2 -0
  126. package/dist/collection/plugins/index.js.map +1 -1
  127. package/dist/collection/plugins/moveColumn/column.drag.plugin.js +12 -6
  128. package/dist/collection/plugins/moveColumn/column.drag.plugin.js.map +1 -1
  129. package/dist/collection/plugins/sorting/sorting.func.js +42 -0
  130. package/dist/collection/plugins/sorting/sorting.func.js.map +1 -0
  131. package/dist/collection/plugins/sorting/sorting.plugin.js +71 -69
  132. package/dist/collection/plugins/sorting/sorting.plugin.js.map +1 -1
  133. package/dist/collection/plugins/sorting/sorting.types.js +2 -0
  134. package/dist/collection/plugins/sorting/sorting.types.js.map +1 -0
  135. package/dist/collection/serve/controller.js +32 -15
  136. package/dist/collection/serve/data.js +18 -11
  137. package/dist/collection/services/column.data.provider.js +5 -2
  138. package/dist/collection/services/column.data.provider.js.map +1 -1
  139. package/dist/collection/services/data.provider.js +18 -7
  140. package/dist/collection/services/data.provider.js.map +1 -1
  141. package/dist/collection/services/dimension.provider.js +32 -33
  142. package/dist/collection/services/dimension.provider.js.map +1 -1
  143. package/dist/collection/services/selection.store.connector.js +1 -1
  144. package/dist/collection/services/selection.store.connector.js.map +1 -1
  145. package/dist/collection/store/dataSource/data.proxy.js +9 -15
  146. package/dist/collection/store/dataSource/data.proxy.js.map +1 -1
  147. package/dist/collection/store/dataSource/data.store.js +1 -1
  148. package/dist/collection/store/dataSource/data.store.js.map +1 -1
  149. package/dist/collection/store/dataSource/trimmed.plugin.js +5 -8
  150. package/dist/collection/store/dataSource/trimmed.plugin.js.map +1 -1
  151. package/dist/collection/store/dimension/dimension.helpers.js +7 -9
  152. package/dist/collection/store/dimension/dimension.helpers.js.map +1 -1
  153. package/dist/collection/store/dimension/dimension.recalculate.plugin.js +35 -0
  154. package/dist/collection/store/dimension/dimension.recalculate.plugin.js.map +1 -0
  155. package/dist/collection/store/dimension/dimension.store.js +47 -67
  156. package/dist/collection/store/dimension/dimension.store.js.map +1 -1
  157. package/dist/collection/store/dimension/dimension.trim.plugin.js +61 -0
  158. package/dist/collection/store/dimension/dimension.trim.plugin.js.map +1 -0
  159. package/dist/collection/store/selection/selection.store.js +1 -1
  160. package/dist/collection/store/selection/selection.store.js.map +1 -1
  161. package/dist/collection/store/vp/viewport.store.js +4 -2
  162. package/dist/collection/store/vp/viewport.store.js.map +1 -1
  163. package/dist/collection/types/events.js +6 -2
  164. package/dist/collection/types/events.js.map +1 -1
  165. package/dist/collection/types/interfaces.js +4 -0
  166. package/dist/collection/types/interfaces.js.map +1 -1
  167. package/dist/collection/types/plugin.types.js.map +1 -1
  168. package/dist/collection/types/selection.js.map +1 -1
  169. package/dist/collection/types/viewport.interfaces.js.map +1 -1
  170. package/dist/collection/utils/column.utils.js +13 -3
  171. package/dist/collection/utils/column.utils.js.map +1 -1
  172. package/dist/esm/app-globals-3a760941.js.map +1 -1
  173. package/dist/esm/{column.drag.plugin-3cc77986.js → column.drag.plugin-50f49fa9.js} +1012 -130
  174. package/dist/esm/column.drag.plugin-50f49fa9.js.map +1 -0
  175. package/dist/esm/column.service-a6a7c415.js +1281 -0
  176. package/dist/esm/column.service-a6a7c415.js.map +1 -0
  177. package/dist/esm/{debounce-72878ced.js → debounce-b3166f78.js} +2 -2
  178. package/dist/esm/{debounce-72878ced.js.map → debounce-b3166f78.js.map} +1 -1
  179. package/dist/esm/{column.service-751345b2.js → dimension.helpers-d0d709c4.js} +450 -1234
  180. package/dist/esm/dimension.helpers-d0d709c4.js.map +1 -0
  181. package/dist/esm/{edit.utils-6fc686b9.js → edit.utils-0ae0db50.js} +2 -2
  182. package/dist/esm/{edit.utils-6fc686b9.js.map → edit.utils-0ae0db50.js.map} +1 -1
  183. package/dist/esm/{header-cell-renderer-32d2ed96.js → header-cell-renderer-36ecbdef.js} +2 -2
  184. package/dist/esm/{header-cell-renderer-32d2ed96.js.map → header-cell-renderer-36ecbdef.js.map} +1 -1
  185. package/dist/esm/index.js +52 -11
  186. package/dist/esm/index.js.map +1 -1
  187. package/dist/esm/{key.utils-17273f42.js → key.utils-7c3218d4.js} +2 -2
  188. package/dist/esm/{key.utils-17273f42.js.map → key.utils-7c3218d4.js.map} +1 -1
  189. package/dist/esm/loader.js +1 -1
  190. package/dist/esm/revo-grid.entry.js +246 -877
  191. package/dist/esm/revo-grid.entry.js.map +1 -1
  192. package/dist/esm/revo-grid.js +1 -1
  193. package/dist/esm/revogr-attribution_7.entry.js +63 -33
  194. package/dist/esm/revogr-attribution_7.entry.js.map +1 -1
  195. package/dist/esm/revogr-clipboard_3.entry.js +7 -6
  196. package/dist/esm/revogr-clipboard_3.entry.js.map +1 -1
  197. package/dist/esm/revogr-data_4.entry.js +60 -50
  198. package/dist/esm/revogr-data_4.entry.js.map +1 -1
  199. package/dist/esm/revogr-filter-panel.entry.js +34 -14
  200. package/dist/esm/revogr-filter-panel.entry.js.map +1 -1
  201. package/dist/esm/{text-editor-901c3eb8.js → text-editor-148a17c1.js} +5 -5
  202. package/dist/esm/text-editor-148a17c1.js.map +1 -0
  203. package/dist/esm/{throttle-138d69c3.js → throttle-394e489c.js} +3 -3
  204. package/dist/esm/{throttle-138d69c3.js.map → throttle-394e489c.js.map} +1 -1
  205. package/dist/esm/{row-header-utils-3dfbb81f.js → viewport.store-afa8c4fe.js} +11 -10
  206. package/dist/esm/viewport.store-afa8c4fe.js.map +1 -0
  207. package/dist/revo-grid/app-globals-3a760941.js +8 -1
  208. package/dist/revo-grid/app-globals-3a760941.js.map +1 -1
  209. package/dist/revo-grid/column.drag.plugin-50f49fa9.js +2541 -0
  210. package/dist/revo-grid/column.drag.plugin-50f49fa9.js.map +1 -0
  211. package/dist/revo-grid/column.service-a6a7c415.js +1281 -0
  212. package/dist/revo-grid/column.service-a6a7c415.js.map +1 -0
  213. package/dist/revo-grid/debounce-b3166f78.js +495 -0
  214. package/dist/revo-grid/debounce-b3166f78.js.map +1 -0
  215. package/dist/revo-grid/dimension.helpers-d0d709c4.js +3611 -0
  216. package/dist/revo-grid/dimension.helpers-d0d709c4.js.map +1 -0
  217. package/dist/revo-grid/edit.utils-0ae0db50.js +17 -0
  218. package/dist/revo-grid/edit.utils-0ae0db50.js.map +1 -0
  219. package/dist/revo-grid/events-cf0893a3.js +38 -1
  220. package/dist/revo-grid/events-cf0893a3.js.map +1 -1
  221. package/dist/revo-grid/filter.button-d40ab17b.js +34 -1
  222. package/dist/revo-grid/filter.button-d40ab17b.js.map +1 -1
  223. package/dist/revo-grid/header-cell-renderer-36ecbdef.js +339 -0
  224. package/dist/revo-grid/header-cell-renderer-36ecbdef.js.map +1 -0
  225. package/dist/revo-grid/index-a61f225b.js +1845 -2
  226. package/dist/revo-grid/index-a61f225b.js.map +1 -1
  227. package/dist/revo-grid/index.esm.js +160 -1
  228. package/dist/revo-grid/index.esm.js.map +1 -1
  229. package/dist/revo-grid/key.utils-7c3218d4.js +89 -0
  230. package/dist/revo-grid/key.utils-7c3218d4.js.map +1 -0
  231. package/dist/revo-grid/resize-observer-83c9e167.js +501 -1
  232. package/dist/revo-grid/resize-observer-83c9e167.js.map +1 -1
  233. package/dist/revo-grid/revo-grid.entry.js +1934 -1
  234. package/dist/revo-grid/revo-grid.entry.js.map +1 -1
  235. package/dist/revo-grid/revo-grid.esm.js +21 -1
  236. package/dist/revo-grid/revo-grid.esm.js.map +1 -1
  237. package/dist/revo-grid/revogr-attribution_7.entry.js +1431 -1
  238. package/dist/revo-grid/revogr-attribution_7.entry.js.map +1 -1
  239. package/dist/revo-grid/revogr-clipboard_3.entry.js +455 -1
  240. package/dist/revo-grid/revogr-clipboard_3.entry.js.map +1 -1
  241. package/dist/revo-grid/revogr-data_4.entry.js +974 -1
  242. package/dist/revo-grid/revogr-data_4.entry.js.map +1 -1
  243. package/dist/revo-grid/revogr-filter-panel.entry.js +340 -1
  244. package/dist/revo-grid/revogr-filter-panel.entry.js.map +1 -1
  245. package/dist/revo-grid/sorting.sign-1a675bf7.js +9 -1
  246. package/dist/revo-grid/sorting.sign-1a675bf7.js.map +1 -1
  247. package/dist/revo-grid/text-editor-148a17c1.js +80 -0
  248. package/dist/revo-grid/text-editor-148a17c1.js.map +1 -0
  249. package/dist/revo-grid/throttle-394e489c.js +230 -0
  250. package/dist/revo-grid/throttle-394e489c.js.map +1 -0
  251. package/dist/revo-grid/viewport.helpers-7e7f9dad.js +48 -1
  252. package/dist/revo-grid/viewport.helpers-7e7f9dad.js.map +1 -1
  253. package/dist/revo-grid/viewport.store-afa8c4fe.js +406 -0
  254. package/dist/revo-grid/viewport.store-afa8c4fe.js.map +1 -0
  255. package/dist/types/components/data/cell-renderer.d.ts +3 -5
  256. package/dist/types/components/data/column.service.d.ts +2 -3
  257. package/dist/types/components/data/revogr-data.d.ts +10 -6
  258. package/dist/types/components/data/row-highlight.plugin.d.ts +1 -1
  259. package/dist/types/components/data/row-renderer.d.ts +1 -1
  260. package/dist/types/components/editors/revogr-edit.d.ts +2 -2
  261. package/dist/types/components/editors/text-editor.d.ts +5 -6
  262. package/dist/types/components/extra/revogr-extra.d.ts +17 -3
  263. package/dist/types/components/header/header-cell-renderer.d.ts +1 -1
  264. package/dist/types/components/header/header-renderer.d.ts +2 -2
  265. package/dist/types/components/header/resizable.element.d.ts +1 -1
  266. package/dist/types/components/header/revogr-header.d.ts +2 -3
  267. package/dist/types/components/order/order-renderer.d.ts +1 -1
  268. package/dist/types/components/order/revogr-order-editor.d.ts +4 -10
  269. package/dist/types/components/overlay/autofill.service.d.ts +2 -2
  270. package/dist/types/components/overlay/keyboard.service.d.ts +1 -1
  271. package/dist/types/components/overlay/revogr-overlay-selection.d.ts +16 -13
  272. package/dist/types/components/overlay/selection.utils.d.ts +1 -1
  273. package/dist/types/components/revoGrid/plugin.service.d.ts +37 -0
  274. package/dist/types/components/revoGrid/revo-grid.d.ts +105 -61
  275. package/dist/types/components/revoGrid/viewport.service.d.ts +2 -2
  276. package/dist/types/components/rowHeaders/row-header-render.d.ts +2 -2
  277. package/dist/types/components/scroll/revogr-viewport-scroll.d.ts +2 -5
  278. package/dist/types/components/scrollable/revogr-scroll-virtual.d.ts +2 -3
  279. package/dist/types/components/selectionFocus/revogr-focus.d.ts +2 -2
  280. package/dist/types/components/selectionTempRange/revogr-temp-range.d.ts +2 -3
  281. package/dist/types/components/vnode/vnode-converter.d.ts +1 -1
  282. package/dist/types/components/vnode/vnode.utils.d.ts +2 -2
  283. package/dist/types/components.d.ts +191 -108
  284. package/dist/types/index.d.ts +1 -1
  285. package/dist/types/plugins/add-rows-on-paste.plugin.d.ts +14 -0
  286. package/dist/types/plugins/base.plugin.d.ts +3 -4
  287. package/dist/types/plugins/column.auto-size.plugin.d.ts +1 -1
  288. package/dist/types/plugins/column.stretch.plugin.d.ts +1 -1
  289. package/dist/types/plugins/export/csv.d.ts +1 -1
  290. package/dist/types/plugins/export/export.plugin.d.ts +4 -3
  291. package/dist/types/plugins/filter/filter.panel.d.ts +2 -2
  292. package/dist/types/plugins/filter/filter.plugin.d.ts +25 -7
  293. package/dist/types/plugins/filter/filter.types.d.ts +32 -10
  294. package/dist/types/plugins/groupingColumn/columnGroupsRenderer.d.ts +2 -2
  295. package/dist/types/plugins/groupingColumn/headerGroupRenderer.d.ts +3 -4
  296. package/dist/types/plugins/groupingRow/grouping.const.d.ts +3 -1
  297. package/dist/types/plugins/groupingRow/grouping.row.plugin.d.ts +15 -10
  298. package/dist/types/plugins/groupingRow/grouping.row.types.d.ts +38 -4
  299. package/dist/types/plugins/groupingRow/grouping.service.d.ts +9 -12
  300. package/dist/types/plugins/index.d.ts +2 -0
  301. package/dist/types/plugins/moveColumn/column.drag.plugin.d.ts +2 -2
  302. package/dist/types/plugins/sorting/sorting.func.d.ts +3 -0
  303. package/dist/types/plugins/sorting/sorting.plugin.d.ts +14 -13
  304. package/dist/types/plugins/sorting/sorting.types.d.ts +13 -0
  305. package/dist/types/services/column.data.provider.d.ts +5 -2
  306. package/dist/types/services/data.provider.d.ts +3 -1
  307. package/dist/types/services/dimension.provider.d.ts +9 -4
  308. package/dist/types/services/selection.store.connector.d.ts +4 -4
  309. package/dist/types/store/dataSource/data.proxy.d.ts +7 -9
  310. package/dist/types/store/dataSource/data.store.d.ts +2 -3
  311. package/dist/types/store/dataSource/trimmed.plugin.d.ts +1 -1
  312. package/dist/types/store/dimension/dimension.helpers.d.ts +1 -4
  313. package/dist/types/store/dimension/dimension.recalculate.plugin.d.ts +9 -0
  314. package/dist/types/store/dimension/dimension.store.d.ts +3 -2
  315. package/dist/types/store/dimension/dimension.trim.plugin.d.ts +13 -0
  316. package/dist/types/store/selection/selection.store.d.ts +1 -1
  317. package/dist/types/store/vp/viewport.store.d.ts +1 -1
  318. package/dist/types/types/events.d.ts +1 -1
  319. package/dist/types/types/interfaces.d.ts +36 -12
  320. package/dist/types/types/plugin.types.d.ts +17 -1
  321. package/dist/types/types/selection.d.ts +23 -17
  322. package/dist/types/types/viewport.interfaces.d.ts +1 -3
  323. package/dist/types/utils/column.utils.d.ts +1 -0
  324. package/hydrate/index.js +2490 -2135
  325. package/hydrate/index.mjs +2490 -2135
  326. package/package.json +20 -19
  327. package/readme.md +15 -17
  328. package/standalone/column.service.js +192 -160
  329. package/standalone/column.service.js.map +1 -1
  330. package/standalone/data.store.js +36 -25
  331. package/standalone/data.store.js.map +1 -1
  332. package/standalone/dimension.helpers.js +8 -10
  333. package/standalone/dimension.helpers.js.map +1 -1
  334. package/standalone/index.js +46 -6
  335. package/standalone/index.js.map +1 -1
  336. package/standalone/revo-grid.js +1275 -1022
  337. package/standalone/revo-grid.js.map +1 -1
  338. package/standalone/revogr-attribution2.js +1 -1
  339. package/standalone/revogr-attribution2.js.map +1 -1
  340. package/standalone/revogr-data2.js +26 -22
  341. package/standalone/revogr-data2.js.map +1 -1
  342. package/standalone/revogr-edit2.js +3 -3
  343. package/standalone/revogr-edit2.js.map +1 -1
  344. package/standalone/revogr-extra2.js +25 -4
  345. package/standalone/revogr-extra2.js.map +1 -1
  346. package/standalone/revogr-filter-panel.js +34 -14
  347. package/standalone/revogr-filter-panel.js.map +1 -1
  348. package/standalone/revogr-focus2.js +2 -1
  349. package/standalone/revogr-focus2.js.map +1 -1
  350. package/standalone/revogr-header2.js +6 -5
  351. package/standalone/revogr-header2.js.map +1 -1
  352. package/standalone/revogr-order-editor2.js +3 -0
  353. package/standalone/revogr-order-editor2.js.map +1 -1
  354. package/standalone/revogr-overlay-selection2.js +29 -17
  355. package/standalone/revogr-overlay-selection2.js.map +1 -1
  356. package/standalone/revogr-row-headers2.js +12 -9
  357. package/standalone/revogr-row-headers2.js.map +1 -1
  358. package/standalone/revogr-scroll-virtual2.js +6 -4
  359. package/standalone/revogr-scroll-virtual2.js.map +1 -1
  360. package/standalone/revogr-temp-range2.js +1 -1
  361. package/standalone/revogr-temp-range2.js.map +1 -1
  362. package/standalone/revogr-viewport-scroll2.js +27 -21
  363. package/standalone/revogr-viewport-scroll2.js.map +1 -1
  364. package/standalone/selection.utils.js +1 -0
  365. package/standalone/selection.utils.js.map +1 -1
  366. package/standalone/vnode-converter.js +1 -1
  367. package/standalone/vnode-converter.js.map +1 -1
  368. package/dist/cjs/column.drag.plugin-fcd892ec.js.map +0 -1
  369. package/dist/cjs/column.service-26c61ed6.js.map +0 -1
  370. package/dist/cjs/index-3ab26ab9.js +0 -513
  371. package/dist/cjs/index-3ab26ab9.js.map +0 -1
  372. package/dist/cjs/key.utils-f49d7bee.js +0 -101
  373. package/dist/cjs/key.utils-f49d7bee.js.map +0 -1
  374. package/dist/cjs/row-header-utils-c37f76e4.js.map +0 -1
  375. package/dist/cjs/text-editor-b756d6b3.js.map +0 -1
  376. package/dist/esm/column.drag.plugin-3cc77986.js.map +0 -1
  377. package/dist/esm/column.service-751345b2.js.map +0 -1
  378. package/dist/esm/index-1dcad6ef.js +0 -476
  379. package/dist/esm/index-1dcad6ef.js.map +0 -1
  380. package/dist/esm/row-header-utils-3dfbb81f.js.map +0 -1
  381. package/dist/esm/text-editor-901c3eb8.js.map +0 -1
  382. package/dist/revo-grid/column.drag.plugin-3cc77986.js +0 -5
  383. package/dist/revo-grid/column.drag.plugin-3cc77986.js.map +0 -1
  384. package/dist/revo-grid/column.service-751345b2.js +0 -5
  385. package/dist/revo-grid/column.service-751345b2.js.map +0 -1
  386. package/dist/revo-grid/debounce-72878ced.js +0 -5
  387. package/dist/revo-grid/debounce-72878ced.js.map +0 -1
  388. package/dist/revo-grid/edit.utils-6fc686b9.js +0 -5
  389. package/dist/revo-grid/edit.utils-6fc686b9.js.map +0 -1
  390. package/dist/revo-grid/header-cell-renderer-32d2ed96.js +0 -5
  391. package/dist/revo-grid/header-cell-renderer-32d2ed96.js.map +0 -1
  392. package/dist/revo-grid/index-1dcad6ef.js +0 -5
  393. package/dist/revo-grid/index-1dcad6ef.js.map +0 -1
  394. package/dist/revo-grid/key.utils-17273f42.js +0 -5
  395. package/dist/revo-grid/key.utils-17273f42.js.map +0 -1
  396. package/dist/revo-grid/row-header-utils-3dfbb81f.js +0 -5
  397. package/dist/revo-grid/row-header-utils-3dfbb81f.js.map +0 -1
  398. package/dist/revo-grid/text-editor-901c3eb8.js +0 -5
  399. package/dist/revo-grid/text-editor-901c3eb8.js.map +0 -1
  400. package/dist/revo-grid/throttle-138d69c3.js +0 -5
  401. package/dist/revo-grid/throttle-138d69c3.js.map +0 -1
  402. package/standalone/identity.js +0 -26
  403. package/standalone/identity.js.map +0 -1
@@ -0,0 +1,2541 @@
1
+ /*!
2
+ * Built by Revolist OU ❤️
3
+ */
4
+ import { x as reduce, y as baseEach, r as getColumnType, h as isGrouping, f as getGroupingName, q as getCellDataParsed, G as GROUP_EXPANDED, k as getParsedGroup, P as PSEUDO_GROUP_ITEM_ID, l as isSameGroup, z as GROUP_DEPTH, A as PSEUDO_GROUP_ITEM_VALUE, w as getColumnByProp, p as getCellRaw, B as GROUPING_ROW_TYPE, b as getSource, C as PSEUDO_GROUP_COLUMN, e as gatherGrouping, j as isGroupingColumn, d as getExpanded, t as isColGrouping } from './column.service-a6a7c415.js';
5
+ import { W as createStore, w as setStore, i as calculateDimensionData, X as identity, Y as isArray, b as getSourceItem, o as getScrollbarSize, Z as toInteger, _ as isIterateeCall, u as timeout, $ as baseProperty, a0 as isArrayLike, a1 as getTag, a2 as baseKeys, g as getPhysical, e as setItems, j as getItemByPosition } from './dimension.helpers-d0d709c4.js';
6
+ import { f as calculateRowHeaderSize } from './viewport.store-afa8c4fe.js';
7
+ import { h } from './index-a61f225b.js';
8
+ import { b as FILTER_PROP, i as isFilterBtn } from './filter.button-d40ab17b.js';
9
+ import { i as isObjectLike, b as baseGetTag, d as debounce } from './debounce-b3166f78.js';
10
+ import { d as dispatch, O as ON_COLUMN_CLICK } from './header-cell-renderer-36ecbdef.js';
11
+
12
+ /**
13
+ * Plugin which recalculates realSize on changes of sizes, originItemSize and count
14
+ */
15
+ const recalculateRealSizePlugin = (storeService) => {
16
+ /**
17
+ * Recalculates realSize if size, origin size or count changes
18
+ */
19
+ return {
20
+ /**
21
+ * Reacts on changes of count, sizes and originItemSize
22
+ */
23
+ set(k) {
24
+ switch (k) {
25
+ case 'count':
26
+ case 'sizes':
27
+ case 'originItemSize': {
28
+ // recalculate realSize
29
+ let realSize = 0;
30
+ const count = storeService.store.get('count');
31
+ for (let i = 0; i < count; i++) {
32
+ realSize +=
33
+ storeService.store.get('sizes')[i] ||
34
+ storeService.store.get('originItemSize');
35
+ }
36
+ storeService.setStore({ realSize });
37
+ break;
38
+ }
39
+ }
40
+ },
41
+ };
42
+ };
43
+
44
+ /**
45
+ * Plugin for trimming
46
+ *
47
+ * 1.a. Retrieves the previous sizes value. Saves the resulting trimmed data as a new sizes value.
48
+ * 1.b. Stores a reference to the trimmed data to prevent further changes.
49
+ * 2. Removes multiple and shifts the data based on the trimmed value.
50
+ */
51
+ const trimmedPlugin = (storeService) => {
52
+ let trimmingObject = null;
53
+ let trimmedPreviousSizes = null;
54
+ return {
55
+ set(key, val) {
56
+ switch (key) {
57
+ case 'sizes': {
58
+ // prevent changes after trimming
59
+ if (trimmingObject && trimmingObject === val) {
60
+ trimmingObject = null;
61
+ return;
62
+ }
63
+ trimmedPreviousSizes = null;
64
+ break;
65
+ }
66
+ case 'trimmed': {
67
+ const trim = val;
68
+ if (!trimmedPreviousSizes) {
69
+ trimmedPreviousSizes = storeService.store.get('sizes');
70
+ }
71
+ trimmingObject = removeMultipleAndShift(trimmedPreviousSizes, trim || {});
72
+ // save a reference to the trimmed object to prevent changes after trimming
73
+ storeService.setSizes(trimmingObject);
74
+ break;
75
+ }
76
+ }
77
+ },
78
+ };
79
+ };
80
+ function removeMultipleAndShift(items, toRemove) {
81
+ const newItems = {};
82
+ const sortedIndexes = Object.keys(items || {})
83
+ .map(Number)
84
+ .sort((a, b) => a - b);
85
+ const lastIndex = sortedIndexes[sortedIndexes.length - 1];
86
+ let shift = 0;
87
+ for (let i = 0; i <= lastIndex; i++) {
88
+ if (toRemove[i] !== undefined) {
89
+ shift++;
90
+ // skip already removed
91
+ if (items[i] !== undefined) {
92
+ continue;
93
+ }
94
+ }
95
+ if (items[i] !== undefined) {
96
+ newItems[i - shift] = items[i];
97
+ }
98
+ }
99
+ return newItems;
100
+ }
101
+
102
+ /**
103
+ * Storing pre-calculated
104
+ * Dimension information and sizes
105
+ */
106
+ function initialBase() {
107
+ return {
108
+ indexes: [],
109
+ count: 0,
110
+ // hidden items
111
+ trimmed: null,
112
+ // virtual item index to size
113
+ sizes: {},
114
+ // order in indexes[] to coordinate
115
+ positionIndexToItem: {},
116
+ // initial element to coordinate ^
117
+ indexToItem: {},
118
+ positionIndexes: [],
119
+ };
120
+ }
121
+ function initialState() {
122
+ return Object.assign(Object.assign({}, initialBase()), {
123
+ // size which all items can take
124
+ realSize: 0,
125
+ // initial item size if it wasn't changed
126
+ originItemSize: 0 });
127
+ }
128
+ class DimensionStore {
129
+ constructor(type) {
130
+ this.type = type;
131
+ this.store = createStore(initialState());
132
+ this.store.use(trimmedPlugin({
133
+ store: this.store,
134
+ setSizes: this.setDimensionSize.bind(this),
135
+ }));
136
+ this.store.use(recalculateRealSizePlugin({
137
+ store: this.store,
138
+ setStore: this.setStore.bind(this),
139
+ }));
140
+ }
141
+ getCurrentState() {
142
+ const state = initialState();
143
+ const keys = Object.keys(state);
144
+ return reduce(keys, (r, k) => {
145
+ const data = this.store.get(k);
146
+ r[k] = data;
147
+ return r;
148
+ }, state);
149
+ }
150
+ dispose() {
151
+ setStore(this.store, initialState());
152
+ }
153
+ setStore(data) {
154
+ setStore(this.store, data);
155
+ }
156
+ drop() {
157
+ setStore(this.store, initialBase());
158
+ }
159
+ /**
160
+ * Set custom dimension sizes and overwrite old
161
+ * Generates new indexes based on sizes
162
+ * @param sizes - sizes to set
163
+ */
164
+ setDimensionSize(sizes = {}) {
165
+ const dimensionData = calculateDimensionData(this.store.get('originItemSize'), sizes);
166
+ setStore(this.store, Object.assign(Object.assign({}, dimensionData), { sizes }));
167
+ }
168
+ updateSizesPositionByIndexes(newItemsOrder, prevItemsOrder = []) {
169
+ // Move custom sizes to new order
170
+ const customSizes = Object.assign({}, this.store.get('sizes'));
171
+ if (!Object.keys(customSizes).length) {
172
+ return;
173
+ }
174
+ // Step 1: Create a map of original indices, but allow duplicates by storing arrays of indices
175
+ const originalIndices = {};
176
+ prevItemsOrder.forEach((physIndex, virtIndex) => {
177
+ if (!originalIndices[physIndex]) {
178
+ originalIndices[physIndex] = [];
179
+ }
180
+ originalIndices[physIndex].push(virtIndex); // Store all indices for each value
181
+ });
182
+ // Step 2: Create new sizes based on new item order
183
+ const newSizes = {};
184
+ newItemsOrder.forEach((physIndex, virtIndex) => {
185
+ const indices = originalIndices[physIndex]; // Get all original indices for this value
186
+ if (indices && indices.length > 0) {
187
+ const originalIndex = indices.shift(); // Get the first available original index
188
+ if (originalIndex !== undefined && originalIndex !== virtIndex && customSizes[originalIndex]) {
189
+ newSizes[virtIndex] = customSizes[originalIndex];
190
+ delete customSizes[originalIndex];
191
+ }
192
+ }
193
+ });
194
+ // Step 3: Set new sizes if there are changes
195
+ if (Object.keys(newSizes).length) {
196
+ this.setDimensionSize(Object.assign(Object.assign({}, customSizes), newSizes));
197
+ }
198
+ }
199
+ }
200
+
201
+ const rowTypes = ['rowPinStart', 'rgRow', 'rowPinEnd'];
202
+ const columnTypes = [
203
+ 'colPinStart',
204
+ 'rgCol',
205
+ 'colPinEnd',
206
+ ];
207
+ function isRowType(type) {
208
+ return rowTypes.indexOf(type) > -1;
209
+ }
210
+
211
+ /**
212
+ * Base layer for plugins
213
+ * Provide minimal starting core for plugins to work
214
+ * Extend this class to create plugin
215
+ */
216
+ class BasePlugin {
217
+ constructor(revogrid, providers) {
218
+ this.revogrid = revogrid;
219
+ this.providers = providers;
220
+ this.h = h;
221
+ this.subscriptions = {};
222
+ }
223
+ /**
224
+ *
225
+ * @param eventName - event name to subscribe to in revo-grid component (e.g. 'beforeheaderclick')
226
+ * @param callback - callback function for event
227
+ */
228
+ addEventListener(eventName, callback) {
229
+ this.revogrid.addEventListener(eventName, callback);
230
+ this.subscriptions[eventName] = callback;
231
+ }
232
+ /**
233
+ * Subscribe to property change in revo-grid component
234
+ * You can return false in callback to prevent default value set
235
+ *
236
+ * @param prop - property name
237
+ * @param callback - callback function
238
+ * @param immediate - trigger callback immediately with current value
239
+ */
240
+ watch(prop, callback, { immediate } = { immediate: false }) {
241
+ const nativeValueDesc = Object.getOwnPropertyDescriptor(this.revogrid, prop) ||
242
+ Object.getOwnPropertyDescriptor(this.revogrid.constructor.prototype, prop);
243
+ // Overwrite property descriptor for this instance
244
+ Object.defineProperty(this.revogrid, prop, {
245
+ set(val) {
246
+ var _a;
247
+ const keepDefault = callback(val);
248
+ if (keepDefault === false) {
249
+ return;
250
+ }
251
+ // Continue with native behavior
252
+ return (_a = nativeValueDesc === null || nativeValueDesc === void 0 ? void 0 : nativeValueDesc.set) === null || _a === void 0 ? void 0 : _a.call(this, val);
253
+ },
254
+ get() {
255
+ var _a;
256
+ // Continue with native behavior
257
+ return (_a = nativeValueDesc === null || nativeValueDesc === void 0 ? void 0 : nativeValueDesc.get) === null || _a === void 0 ? void 0 : _a.call(this);
258
+ },
259
+ });
260
+ if (immediate) {
261
+ callback(nativeValueDesc === null || nativeValueDesc === void 0 ? void 0 : nativeValueDesc.value);
262
+ }
263
+ }
264
+ /**
265
+ * Remove event listener
266
+ * @param eventName
267
+ */
268
+ removeEventListener(eventName) {
269
+ this.revogrid.removeEventListener(eventName, this.subscriptions[eventName]);
270
+ delete this.subscriptions[eventName];
271
+ }
272
+ /**
273
+ * Emit event from revo-grid component
274
+ * Event can be cancelled by calling event.preventDefault() in callback
275
+ */
276
+ emit(eventName, detail) {
277
+ const event = new CustomEvent(eventName, { detail, cancelable: true });
278
+ this.revogrid.dispatchEvent(event);
279
+ return event;
280
+ }
281
+ /**
282
+ * Clear all subscriptions
283
+ */
284
+ clearSubscriptions() {
285
+ for (let type in this.subscriptions) {
286
+ this.removeEventListener(type);
287
+ }
288
+ }
289
+ /**
290
+ * Destroy plugin and clear all subscriptions
291
+ */
292
+ destroy() {
293
+ this.clearSubscriptions();
294
+ }
295
+ }
296
+
297
+ /**
298
+ * A specialized version of `_.forEach` for arrays without support for
299
+ * iteratee shorthands.
300
+ *
301
+ * @private
302
+ * @param {Array} [array] The array to iterate over.
303
+ * @param {Function} iteratee The function invoked per iteration.
304
+ * @returns {Array} Returns `array`.
305
+ */
306
+ function arrayEach(array, iteratee) {
307
+ var index = -1,
308
+ length = array == null ? 0 : array.length;
309
+
310
+ while (++index < length) {
311
+ if (iteratee(array[index], index, array) === false) {
312
+ break;
313
+ }
314
+ }
315
+ return array;
316
+ }
317
+
318
+ /**
319
+ * Casts `value` to `identity` if it's not a function.
320
+ *
321
+ * @private
322
+ * @param {*} value The value to inspect.
323
+ * @returns {Function} Returns cast function.
324
+ */
325
+ function castFunction(value) {
326
+ return typeof value == 'function' ? value : identity;
327
+ }
328
+
329
+ /**
330
+ * Iterates over elements of `collection` and invokes `iteratee` for each element.
331
+ * The iteratee is invoked with three arguments: (value, index|key, collection).
332
+ * Iteratee functions may exit iteration early by explicitly returning `false`.
333
+ *
334
+ * **Note:** As with other "Collections" methods, objects with a "length"
335
+ * property are iterated like arrays. To avoid this behavior use `_.forIn`
336
+ * or `_.forOwn` for object iteration.
337
+ *
338
+ * @static
339
+ * @memberOf _
340
+ * @since 0.1.0
341
+ * @alias each
342
+ * @category Collection
343
+ * @param {Array|Object} collection The collection to iterate over.
344
+ * @param {Function} [iteratee=_.identity] The function invoked per iteration.
345
+ * @returns {Array|Object} Returns `collection`.
346
+ * @see _.forEachRight
347
+ * @example
348
+ *
349
+ * _.forEach([1, 2], function(value) {
350
+ * console.log(value);
351
+ * });
352
+ * // => Logs `1` then `2`.
353
+ *
354
+ * _.forEach({ 'a': 1, 'b': 2 }, function(value, key) {
355
+ * console.log(key);
356
+ * });
357
+ * // => Logs 'a' then 'b' (iteration order is not guaranteed).
358
+ */
359
+ function forEach(collection, iteratee) {
360
+ var func = isArray(collection) ? arrayEach : baseEach;
361
+ return func(collection, castFunction(iteratee));
362
+ }
363
+
364
+ /**
365
+ * Plugin module for revo-grid grid system
366
+ * Add support for automatic column resize
367
+ */
368
+ const LETTER_BLOCK_SIZE = 7;
369
+ var ColumnAutoSizeMode;
370
+ (function (ColumnAutoSizeMode) {
371
+ // increases column width on header click according the largest text value
372
+ ColumnAutoSizeMode["headerClickAutosize"] = "headerClickAutoSize";
373
+ // increases column width on data set and text edit, decreases performance
374
+ ColumnAutoSizeMode["autoSizeOnTextOverlap"] = "autoSizeOnTextOverlap";
375
+ // increases and decreases column width based on all items sizes, worst for performance
376
+ ColumnAutoSizeMode["autoSizeAll"] = "autoSizeAll";
377
+ })(ColumnAutoSizeMode || (ColumnAutoSizeMode = {}));
378
+ class AutoSizeColumnPlugin extends BasePlugin {
379
+ constructor(revogrid, providers, config) {
380
+ super(revogrid, providers);
381
+ this.providers = providers;
382
+ this.config = config;
383
+ this.autoSizeColumns = null;
384
+ /** for edge case when no columns defined before data */
385
+ this.dataResolve = null;
386
+ this.dataReject = null;
387
+ this.letterBlockSize = (config === null || config === void 0 ? void 0 : config.letterBlockSize) || LETTER_BLOCK_SIZE;
388
+ // create test container to check text width
389
+ if (config === null || config === void 0 ? void 0 : config.preciseSize) {
390
+ this.precsizeCalculationArea = this.initiatePresizeElement();
391
+ revogrid.appendChild(this.precsizeCalculationArea);
392
+ }
393
+ const aftersourceset = ({ detail: { source }, }) => {
394
+ this.setSource(source);
395
+ };
396
+ const afteredit = ({ detail }) => {
397
+ this.afteredit(detail);
398
+ };
399
+ const afterEditAll = ({ detail }) => {
400
+ this.afterEditAll(detail);
401
+ };
402
+ const beforecolumnsset = ({ detail: { columns }, }) => {
403
+ this.columnSet(columns);
404
+ };
405
+ const headerDblClick = ({ detail }) => {
406
+ const type = getColumnType(detail.column);
407
+ const size = this.getColumnSize(detail.index, type);
408
+ if (size) {
409
+ this.providers.dimension.setCustomSizes(type, {
410
+ [detail.index]: size,
411
+ }, true);
412
+ }
413
+ };
414
+ this.addEventListener('beforecolumnsset', beforecolumnsset);
415
+ switch (config === null || config === void 0 ? void 0 : config.mode) {
416
+ case ColumnAutoSizeMode.autoSizeOnTextOverlap:
417
+ this.addEventListener('aftersourceset', aftersourceset);
418
+ this.addEventListener('afteredit', afteredit);
419
+ break;
420
+ case ColumnAutoSizeMode.autoSizeAll:
421
+ this.addEventListener('aftersourceset', aftersourceset);
422
+ this.addEventListener('afteredit', afterEditAll);
423
+ break;
424
+ default:
425
+ this.addEventListener('headerdblclick', headerDblClick);
426
+ break;
427
+ }
428
+ }
429
+ async setSource(source) {
430
+ let autoSize = this.autoSizeColumns;
431
+ if (this.dataReject) {
432
+ this.dataReject();
433
+ this.clearPromise();
434
+ }
435
+ /** If data set first and no column provided await until get one */
436
+ if (!autoSize) {
437
+ const request = new Promise((resolve, reject) => {
438
+ this.dataResolve = resolve;
439
+ this.dataReject = reject;
440
+ });
441
+ try {
442
+ autoSize = await request;
443
+ }
444
+ catch (e) {
445
+ return;
446
+ }
447
+ }
448
+ // calculate sizes
449
+ forEach(autoSize, (_v, type) => {
450
+ const sizes = {};
451
+ forEach(autoSize[type], rgCol => {
452
+ // calculate size
453
+ rgCol.size = sizes[rgCol.index] = source.reduce((prev, rgRow) => Math.max(prev, this.getLength(rgRow[rgCol.prop])), this.getLength(rgCol.name || ''));
454
+ });
455
+ this.providers.dimension.setCustomSizes(type, sizes, true);
456
+ });
457
+ }
458
+ getLength(len) {
459
+ var _a;
460
+ const padding = 15;
461
+ if (!len) {
462
+ return 0;
463
+ }
464
+ try {
465
+ const str = len.toString();
466
+ /**if exact calculation required proxy with html element, slow operation */
467
+ if ((_a = this.config) === null || _a === void 0 ? void 0 : _a.preciseSize) {
468
+ this.precsizeCalculationArea.innerText = str;
469
+ return this.precsizeCalculationArea.scrollWidth + padding * 2;
470
+ }
471
+ return str.length * this.letterBlockSize + padding * 2;
472
+ }
473
+ catch (e) {
474
+ return 0;
475
+ }
476
+ }
477
+ afteredit(e) {
478
+ let data;
479
+ if (this.isRangeEdit(e)) {
480
+ data = e.data;
481
+ }
482
+ else {
483
+ data = { 0: { [e.prop]: e.val } };
484
+ }
485
+ forEach(this.autoSizeColumns, (columns, type) => {
486
+ const sizes = {};
487
+ forEach(columns, rgCol => {
488
+ var _a;
489
+ // calculate size
490
+ const size = reduce(data, (prev, rgRow) => {
491
+ if (typeof rgRow[rgCol.prop] === 'undefined') {
492
+ return prev;
493
+ }
494
+ return Math.max(prev || 0, this.getLength(rgRow[rgCol.prop]));
495
+ }, undefined);
496
+ if (size && ((_a = rgCol.size) !== null && _a !== void 0 ? _a : 0) < size) {
497
+ rgCol.size = sizes[rgCol.index] = size;
498
+ }
499
+ });
500
+ this.providers.dimension.setCustomSizes(type, sizes, true);
501
+ });
502
+ }
503
+ afterEditAll(e) {
504
+ const props = {};
505
+ if (this.isRangeEdit(e)) {
506
+ forEach(e.data, r => forEach(r, (_v, p) => (props[p] = true)));
507
+ }
508
+ else {
509
+ props[e.prop] = true;
510
+ }
511
+ forEach(this.autoSizeColumns, (columns, type) => {
512
+ const sizes = {};
513
+ forEach(columns, rgCol => {
514
+ if (props[rgCol.prop]) {
515
+ const size = this.getColumnSize(rgCol.index, type);
516
+ if (size) {
517
+ sizes[rgCol.index] = size;
518
+ }
519
+ }
520
+ });
521
+ this.providers.dimension.setCustomSizes(type, sizes, true);
522
+ });
523
+ }
524
+ getColumnSize(index, type) {
525
+ var _a, _b;
526
+ const rgCol = (_b = (_a = this.autoSizeColumns) === null || _a === void 0 ? void 0 : _a[type]) === null || _b === void 0 ? void 0 : _b[index];
527
+ if (!rgCol) {
528
+ return 0;
529
+ }
530
+ return reduce(this.providers.data.stores, (r, s) => {
531
+ const perStore = reduce(s.store.get('items'), (prev, _row, i) => {
532
+ const item = getSourceItem(s.store, i);
533
+ return Math.max(prev || 0, this.getLength(item === null || item === void 0 ? void 0 : item[rgCol.prop]));
534
+ }, 0);
535
+ return Math.max(r, perStore);
536
+ }, rgCol.size || 0);
537
+ }
538
+ columnSet(columns) {
539
+ var _a;
540
+ for (let t of columnTypes) {
541
+ const type = t;
542
+ const cols = columns[type];
543
+ for (let i in cols) {
544
+ if (cols[i].autoSize || ((_a = this.config) === null || _a === void 0 ? void 0 : _a.allColumns)) {
545
+ if (!this.autoSizeColumns) {
546
+ this.autoSizeColumns = {};
547
+ }
548
+ if (!this.autoSizeColumns[type]) {
549
+ this.autoSizeColumns[type] = {};
550
+ }
551
+ this.autoSizeColumns[type][i] = Object.assign(Object.assign({}, cols[i]), { index: parseInt(i, 10) });
552
+ }
553
+ }
554
+ }
555
+ if (this.dataResolve) {
556
+ this.dataResolve(this.autoSizeColumns || {});
557
+ this.clearPromise();
558
+ }
559
+ }
560
+ clearPromise() {
561
+ this.dataResolve = null;
562
+ this.dataReject = null;
563
+ }
564
+ isRangeEdit(e) {
565
+ return !!e.data;
566
+ }
567
+ initiatePresizeElement() {
568
+ var _a;
569
+ const styleForFontTest = {
570
+ position: 'absolute',
571
+ fontSize: '14px',
572
+ height: '0',
573
+ width: '0',
574
+ whiteSpace: 'nowrap',
575
+ top: '0',
576
+ overflowX: 'scroll',
577
+ };
578
+ const el = document.createElement('div');
579
+ for (let s in styleForFontTest) {
580
+ el.style[s] = (_a = styleForFontTest[s]) !== null && _a !== void 0 ? _a : '';
581
+ }
582
+ el.classList.add('revo-test-container');
583
+ return el;
584
+ }
585
+ destroy() {
586
+ var _a;
587
+ super.destroy();
588
+ (_a = this.precsizeCalculationArea) === null || _a === void 0 ? void 0 : _a.remove();
589
+ }
590
+ }
591
+
592
+ class StretchColumn extends BasePlugin {
593
+ constructor(revogrid, providers) {
594
+ super(revogrid, providers);
595
+ this.providers = providers;
596
+ this.stretchedColumn = null;
597
+ // calculate scroll bar size for current user session
598
+ this.scrollSize = getScrollbarSize(document);
599
+ // subscribe to column changes
600
+ const beforecolumnapplied = ({ detail: { columns }, }) => this.applyStretch(columns);
601
+ this.addEventListener('beforecolumnapplied', beforecolumnapplied);
602
+ }
603
+ setScroll({ type, hasScroll }) {
604
+ var _a;
605
+ if (type === 'rgRow' &&
606
+ this.stretchedColumn &&
607
+ ((_a = this.stretchedColumn) === null || _a === void 0 ? void 0 : _a.initialSize) === this.stretchedColumn.size) {
608
+ if (hasScroll) {
609
+ this.stretchedColumn.size -= this.scrollSize;
610
+ this.apply();
611
+ this.dropChanges();
612
+ }
613
+ }
614
+ }
615
+ activateChanges() {
616
+ const setScroll = ({ detail }) => this.setScroll(detail);
617
+ this.addEventListener('scrollchange', setScroll);
618
+ }
619
+ dropChanges() {
620
+ this.stretchedColumn = null;
621
+ this.removeEventListener('scrollchange');
622
+ }
623
+ apply() {
624
+ if (!this.stretchedColumn) {
625
+ return;
626
+ }
627
+ const type = 'rgCol';
628
+ const sizes = this.providers.dimension.stores[type].store.get('sizes');
629
+ this.providers.dimension.setCustomSizes(type, Object.assign(Object.assign({}, sizes), { [this.stretchedColumn.index]: this.stretchedColumn.size }), true);
630
+ }
631
+ /**
632
+ * Apply stretch changes
633
+ */
634
+ applyStretch(columns) {
635
+ // unsubscribe from all events
636
+ this.dropChanges();
637
+ // calculate grid size
638
+ let sizeDifference = this.revogrid.clientWidth - 1;
639
+ forEach(columns, (_, type) => {
640
+ const realSize = this.providers.dimension.stores[type].store.get('realSize');
641
+ sizeDifference -= realSize;
642
+ });
643
+ if (this.revogrid.rowHeaders) {
644
+ const itemsLength = this.providers.data.stores.rgRow.store.get('source').length;
645
+ const header = this.revogrid.rowHeaders;
646
+ const rowHeaderSize = calculateRowHeaderSize(itemsLength, typeof header === 'object' ? header : undefined);
647
+ if (rowHeaderSize) {
648
+ sizeDifference -= rowHeaderSize;
649
+ }
650
+ }
651
+ if (sizeDifference > 0) {
652
+ // currently plugin accepts last column only
653
+ const index = columns.rgCol.length - 1;
654
+ const last = columns.rgCol[index];
655
+ /**
656
+ * has column
657
+ * no auto size applied
658
+ * size for column shouldn't be defined
659
+ */
660
+ const colSize = (last === null || last === void 0 ? void 0 : last.size) || this.revogrid.colSize || 0;
661
+ const size = sizeDifference + colSize - 1;
662
+ if (last && !last.autoSize && colSize < size) {
663
+ this.stretchedColumn = {
664
+ initialSize: size,
665
+ index,
666
+ size,
667
+ };
668
+ this.apply();
669
+ this.activateChanges();
670
+ }
671
+ }
672
+ }
673
+ }
674
+ /**
675
+ * Check plugin type is Stretch
676
+ */
677
+ function isStretchPlugin(plugin) {
678
+ return !!plugin.applyStretch;
679
+ }
680
+
681
+ /**
682
+ * The base implementation of `_.clamp` which doesn't coerce arguments.
683
+ *
684
+ * @private
685
+ * @param {number} number The number to clamp.
686
+ * @param {number} [lower] The lower bound.
687
+ * @param {number} upper The upper bound.
688
+ * @returns {number} Returns the clamped number.
689
+ */
690
+ function baseClamp(number, lower, upper) {
691
+ if (number === number) {
692
+ if (upper !== undefined) {
693
+ number = number <= upper ? number : upper;
694
+ }
695
+ if (lower !== undefined) {
696
+ number = number >= lower ? number : lower;
697
+ }
698
+ }
699
+ return number;
700
+ }
701
+
702
+ /** Used as references for the maximum length and index of an array. */
703
+ var MAX_ARRAY_LENGTH = 4294967295;
704
+
705
+ /**
706
+ * Converts `value` to an integer suitable for use as the length of an
707
+ * array-like object.
708
+ *
709
+ * **Note:** This method is based on
710
+ * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
711
+ *
712
+ * @static
713
+ * @memberOf _
714
+ * @since 4.0.0
715
+ * @category Lang
716
+ * @param {*} value The value to convert.
717
+ * @returns {number} Returns the converted integer.
718
+ * @example
719
+ *
720
+ * _.toLength(3.2);
721
+ * // => 3
722
+ *
723
+ * _.toLength(Number.MIN_VALUE);
724
+ * // => 0
725
+ *
726
+ * _.toLength(Infinity);
727
+ * // => 4294967295
728
+ *
729
+ * _.toLength('3.2');
730
+ * // => 3
731
+ */
732
+ function toLength(value) {
733
+ return value ? baseClamp(toInteger(value), 0, MAX_ARRAY_LENGTH) : 0;
734
+ }
735
+
736
+ /**
737
+ * The base implementation of `_.fill` without an iteratee call guard.
738
+ *
739
+ * @private
740
+ * @param {Array} array The array to fill.
741
+ * @param {*} value The value to fill `array` with.
742
+ * @param {number} [start=0] The start position.
743
+ * @param {number} [end=array.length] The end position.
744
+ * @returns {Array} Returns `array`.
745
+ */
746
+ function baseFill(array, value, start, end) {
747
+ var length = array.length;
748
+
749
+ start = toInteger(start);
750
+ if (start < 0) {
751
+ start = -start > length ? 0 : (length + start);
752
+ }
753
+ end = (end === undefined || end > length) ? length : toInteger(end);
754
+ if (end < 0) {
755
+ end += length;
756
+ }
757
+ end = start > end ? 0 : toLength(end);
758
+ while (start < end) {
759
+ array[start++] = value;
760
+ }
761
+ return array;
762
+ }
763
+
764
+ /**
765
+ * Fills elements of `array` with `value` from `start` up to, but not
766
+ * including, `end`.
767
+ *
768
+ * **Note:** This method mutates `array`.
769
+ *
770
+ * @static
771
+ * @memberOf _
772
+ * @since 3.2.0
773
+ * @category Array
774
+ * @param {Array} array The array to fill.
775
+ * @param {*} value The value to fill `array` with.
776
+ * @param {number} [start=0] The start position.
777
+ * @param {number} [end=array.length] The end position.
778
+ * @returns {Array} Returns `array`.
779
+ * @example
780
+ *
781
+ * var array = [1, 2, 3];
782
+ *
783
+ * _.fill(array, 'a');
784
+ * console.log(array);
785
+ * // => ['a', 'a', 'a']
786
+ *
787
+ * _.fill(Array(3), 2);
788
+ * // => [2, 2, 2]
789
+ *
790
+ * _.fill([4, 6, 8, 10], '*', 1, 3);
791
+ * // => [4, '*', '*', 10]
792
+ */
793
+ function fill(array, value, start, end) {
794
+ var length = array == null ? 0 : array.length;
795
+ if (!length) {
796
+ return [];
797
+ }
798
+ if (start && typeof start != 'number' && isIterateeCall(array, value, start)) {
799
+ start = 0;
800
+ end = length;
801
+ }
802
+ return baseFill(array, value, start, end);
803
+ }
804
+
805
+ const INITIAL = {
806
+ mime: 'text/csv',
807
+ fileKind: 'csv',
808
+ // BOM signature
809
+ bom: true,
810
+ columnDelimiter: ',',
811
+ rowDelimiter: '\r\n',
812
+ encoding: '',
813
+ };
814
+ // The ASCII character code 13 is called a Carriage Return or CR.
815
+ const CARRIAGE_RETURN = String.fromCharCode(13);
816
+ // Chr(13) followed by a Chr(10) that compose a proper CRLF.
817
+ const LINE_FEED = String.fromCharCode(10);
818
+ const DOUBLE_QT = String.fromCharCode(34);
819
+ const NO_BREAK_SPACE = String.fromCharCode(0xfeff);
820
+ const escapeRegex = new RegExp('"', 'g');
821
+ class ExportCsv {
822
+ constructor(options = {}) {
823
+ this.options = Object.assign(Object.assign({}, INITIAL), options);
824
+ }
825
+ doExport({ data, headers, props }) {
826
+ let result = this.options.bom ? NO_BREAK_SPACE : '';
827
+ // any header
828
+ if ((headers === null || headers === void 0 ? void 0 : headers.length) > 0) {
829
+ headers.forEach(header => {
830
+ // ignore empty
831
+ if (!header.length) {
832
+ return;
833
+ }
834
+ result += this.prepareHeader(header, this.options.columnDelimiter);
835
+ result += this.options.rowDelimiter;
836
+ });
837
+ }
838
+ data.forEach((rgRow, index) => {
839
+ if (index > 0) {
840
+ result += this.options.rowDelimiter;
841
+ }
842
+ // support grouping
843
+ if (isGrouping(rgRow)) {
844
+ result += this.parseCell(getGroupingName(rgRow), this.options.columnDelimiter);
845
+ return;
846
+ }
847
+ result += props.map(p => this.parseCell(rgRow[p], this.options.columnDelimiter)).join(this.options.columnDelimiter);
848
+ });
849
+ return result;
850
+ }
851
+ prepareHeader(columnHeaders, columnDelimiter) {
852
+ let result = '';
853
+ const newColumnHeaders = columnHeaders.map(v => this.parseCell(v, columnDelimiter, true));
854
+ result += newColumnHeaders.join(columnDelimiter);
855
+ return result;
856
+ }
857
+ parseCell(value, columnDelimiter, force = false) {
858
+ let escape = value;
859
+ if (typeof value !== 'string') {
860
+ escape = JSON.stringify(value);
861
+ }
862
+ const toEscape = [CARRIAGE_RETURN, DOUBLE_QT, LINE_FEED, columnDelimiter];
863
+ if (typeof escape === 'undefined') {
864
+ return '';
865
+ }
866
+ if (escape !== '' && (force || toEscape.some(i => escape.indexOf(i) >= 0))) {
867
+ return `"${escape.replace(escapeRegex, '""')}"`;
868
+ }
869
+ return escape;
870
+ }
871
+ }
872
+
873
+ var ExportTypes;
874
+ (function (ExportTypes) {
875
+ ExportTypes["csv"] = "csv";
876
+ })(ExportTypes || (ExportTypes = {}));
877
+ class ExportFilePlugin extends BasePlugin {
878
+ /** Exports string */
879
+ async exportString(options = {}, t = ExportTypes.csv) {
880
+ const data = await this.beforeexport();
881
+ if (!data) {
882
+ return null;
883
+ }
884
+ return this.formatter(t, options).doExport(data);
885
+ }
886
+ /** Exports Blob */
887
+ async exportBlob(options = {}, t = ExportTypes.csv) {
888
+ return await this.getBlob(this.formatter(t, options));
889
+ }
890
+ /** Export file */
891
+ async exportFile(options = {}, t = ExportTypes.csv) {
892
+ const formatter = this.formatter(t, options);
893
+ // url
894
+ const URL = window.URL || window.webkitURL;
895
+ const a = document.createElement('a');
896
+ const { filename, fileKind } = formatter.options;
897
+ const name = `${filename}.${fileKind}`;
898
+ const blob = await this.getBlob(formatter);
899
+ const url = blob ? URL.createObjectURL(blob) : '';
900
+ a.style.display = 'none';
901
+ a.setAttribute('href', url);
902
+ a.setAttribute('download', name);
903
+ this.revogrid.appendChild(a);
904
+ a.dispatchEvent(new MouseEvent('click'));
905
+ this.revogrid.removeChild(a);
906
+ // delay for revoke, correct for some browsers
907
+ await timeout(120);
908
+ URL.revokeObjectURL(url);
909
+ }
910
+ /** Blob object */
911
+ async getBlob(formatter) {
912
+ const type = `${formatter.options.mime};charset=${formatter.options.encoding}`;
913
+ if (typeof Blob !== 'undefined') {
914
+ const data = await this.beforeexport();
915
+ if (!data) {
916
+ return null;
917
+ }
918
+ return new Blob([formatter.doExport(data)], { type });
919
+ }
920
+ return null;
921
+ }
922
+ // before event
923
+ async beforeexport() {
924
+ let data = await this.getData();
925
+ const event = this.emit('beforeexport', { data });
926
+ if (event.defaultPrevented) {
927
+ return null;
928
+ }
929
+ return event.detail.data;
930
+ }
931
+ async getData() {
932
+ const data = await this.getSource();
933
+ const colSource = [];
934
+ const colPromises = [];
935
+ columnTypes.forEach((t, i) => {
936
+ colPromises.push(this.getColPerSource(t).then(s => (colSource[i] = s)));
937
+ });
938
+ await Promise.all(colPromises);
939
+ const columns = {
940
+ headers: [],
941
+ props: [],
942
+ };
943
+ for (let source of colSource) {
944
+ source.headers.forEach((h, i) => {
945
+ if (!columns.headers[i]) {
946
+ columns.headers[i] = [];
947
+ }
948
+ columns.headers[i].push(...h);
949
+ });
950
+ columns.props.push(...source.props);
951
+ }
952
+ return Object.assign({ data }, columns);
953
+ }
954
+ async getColPerSource(t) {
955
+ const store = await this.revogrid.getColumnStore(t);
956
+ const source = store.get('source');
957
+ const virtualIndexes = store.get('items');
958
+ const depth = store.get('groupingDepth');
959
+ const groups = store.get('groups');
960
+ const colNames = [];
961
+ const colProps = [];
962
+ const visibleItems = virtualIndexes.reduce((r, v, virtualIndex) => {
963
+ const prop = source[v].prop;
964
+ colNames.push(source[v].name || '');
965
+ colProps.push(prop);
966
+ r[prop] = virtualIndex;
967
+ return r;
968
+ }, {});
969
+ const rows = this.getGroupHeaders(depth, groups, virtualIndexes, visibleItems);
970
+ rows.push(colNames);
971
+ return {
972
+ headers: rows,
973
+ props: colProps,
974
+ };
975
+ }
976
+ getGroupHeaders(depth, groups, items, visibleItems) {
977
+ const rows = [];
978
+ const template = fill(new Array(items.length), '');
979
+ for (let d = 0; d < depth; d++) {
980
+ const rgRow = [...template];
981
+ rows.push(rgRow);
982
+ if (!groups[d]) {
983
+ continue;
984
+ }
985
+ const levelGroups = groups[d];
986
+ // add names of groups
987
+ levelGroups.forEach((group) => {
988
+ const minIndex = this.findGroupStartIndex(group.ids, visibleItems);
989
+ if (typeof minIndex === 'number') {
990
+ rgRow[minIndex] = group.name;
991
+ }
992
+ });
993
+ }
994
+ return rows;
995
+ }
996
+ findGroupStartIndex(ids, visibleItems) {
997
+ let min;
998
+ ids.forEach(id => {
999
+ const current = visibleItems[id];
1000
+ if (typeof current === 'number') {
1001
+ if (typeof min !== 'number' || min > current) {
1002
+ min = current;
1003
+ }
1004
+ }
1005
+ });
1006
+ return min;
1007
+ }
1008
+ async getSource() {
1009
+ const data = [];
1010
+ const promisesData = [];
1011
+ rowTypes.forEach(t => {
1012
+ const dataPart = [];
1013
+ data.push(dataPart);
1014
+ const promise = this.revogrid.getVisibleSource(t).then((d) => dataPart.push(...d));
1015
+ promisesData.push(promise);
1016
+ });
1017
+ await Promise.all(promisesData);
1018
+ return data.reduce((r, v) => {
1019
+ r.push(...v);
1020
+ return r;
1021
+ }, []);
1022
+ }
1023
+ // get correct class for future multiple types support
1024
+ formatter(type, options = {}) {
1025
+ switch (type) {
1026
+ case ExportTypes.csv:
1027
+ return new ExportCsv(options);
1028
+ default:
1029
+ throw new Error('Unknown format');
1030
+ }
1031
+ }
1032
+ }
1033
+
1034
+ const eq = (value, extra) => {
1035
+ if (typeof value === 'undefined' || (value === null && !extra)) {
1036
+ return true;
1037
+ }
1038
+ if (typeof value !== 'string') {
1039
+ value = JSON.stringify(value);
1040
+ }
1041
+ const filterVal = extra === null || extra === void 0 ? void 0 : extra.toString().toLocaleLowerCase();
1042
+ if ((filterVal === null || filterVal === void 0 ? void 0 : filterVal.length) === 0) {
1043
+ return true;
1044
+ }
1045
+ return value.toLocaleLowerCase() === filterVal;
1046
+ };
1047
+ const notEq = (value, extra) => !eq(value, extra);
1048
+ notEq.extra = 'input';
1049
+ eq.extra = 'input';
1050
+
1051
+ const gtThan = function (value, extra) {
1052
+ let conditionValue;
1053
+ if (typeof value === 'number' && typeof extra !== 'undefined' && extra !== null) {
1054
+ conditionValue = parseFloat(extra === null || extra === void 0 ? void 0 : extra.toString());
1055
+ return value > conditionValue;
1056
+ }
1057
+ return false;
1058
+ };
1059
+ gtThan.extra = 'input';
1060
+
1061
+ const gtThanEq = function (value, extra) {
1062
+ return eq(value, extra) || gtThan(value, extra);
1063
+ };
1064
+ gtThanEq.extra = 'input';
1065
+
1066
+ const lt = function (value, extra) {
1067
+ let conditionValue;
1068
+ if (typeof value === 'number' && typeof extra !== 'undefined' && extra !== null) {
1069
+ conditionValue = parseFloat(extra.toString());
1070
+ return value < conditionValue;
1071
+ }
1072
+ else {
1073
+ return false;
1074
+ }
1075
+ };
1076
+ lt.extra = 'input';
1077
+
1078
+ const lsEq = function (value, extra) {
1079
+ return eq(value, extra) || lt(value, extra);
1080
+ };
1081
+ lsEq.extra = 'input';
1082
+
1083
+ const set = (value) => !(value === '' || value === null || value === void 0);
1084
+ const notSet = (value) => !set(value);
1085
+
1086
+ const beginsWith = (value, extra) => {
1087
+ if (!value) {
1088
+ return false;
1089
+ }
1090
+ if (!extra) {
1091
+ return true;
1092
+ }
1093
+ if (typeof value !== 'string') {
1094
+ value = JSON.stringify(value);
1095
+ }
1096
+ if (typeof extra !== 'string') {
1097
+ extra = JSON.stringify(extra);
1098
+ }
1099
+ return value.toLocaleLowerCase().indexOf(extra.toLocaleLowerCase()) === 0;
1100
+ };
1101
+ beginsWith.extra = 'input';
1102
+
1103
+ const contains = (value, extra) => {
1104
+ if (!extra) {
1105
+ return true;
1106
+ }
1107
+ if (!value) {
1108
+ return false;
1109
+ }
1110
+ if (extra) {
1111
+ if (typeof value !== 'string') {
1112
+ value = JSON.stringify(value);
1113
+ }
1114
+ return value.toLocaleLowerCase().indexOf(extra.toString().toLowerCase()) > -1;
1115
+ }
1116
+ return true;
1117
+ };
1118
+ const notContains = (value, extra) => {
1119
+ return !contains(value, extra);
1120
+ };
1121
+ notContains.extra = 'input';
1122
+ contains.extra = 'input';
1123
+
1124
+ // filter.indexed.ts
1125
+ const filterCoreFunctionsIndexedByType = {
1126
+ none: () => true,
1127
+ empty: notSet,
1128
+ notEmpty: set,
1129
+ eq: eq,
1130
+ notEq: notEq,
1131
+ begins: beginsWith,
1132
+ contains: contains,
1133
+ notContains: notContains,
1134
+ eqN: eq,
1135
+ neqN: notEq,
1136
+ gt: gtThan,
1137
+ gte: gtThanEq,
1138
+ lt: lt,
1139
+ lte: lsEq,
1140
+ };
1141
+ const filterTypes = {
1142
+ string: ['notEmpty', 'empty', 'eq', 'notEq', 'begins', 'contains', 'notContains'],
1143
+ number: ['notEmpty', 'empty', 'eqN', 'neqN', 'gt', 'gte', 'lt', 'lte'],
1144
+ };
1145
+ const filterNames = {
1146
+ none: 'None',
1147
+ empty: 'Not set',
1148
+ notEmpty: 'Set',
1149
+ eq: 'Equal',
1150
+ notEq: 'Not equal',
1151
+ begins: 'Begins with',
1152
+ contains: 'Contains',
1153
+ notContains: 'Does not contain',
1154
+ eqN: '=',
1155
+ neqN: '!=',
1156
+ gt: '>',
1157
+ gte: '>=',
1158
+ lt: '<',
1159
+ lte: '<=',
1160
+ };
1161
+
1162
+ // filter.plugin.tsx
1163
+ const FILTER_TRIMMED_TYPE = 'filter';
1164
+ const FILTER_CONFIG_CHANGED_EVENT = 'filterconfigchanged';
1165
+ const FILTE_PANEL = 'revogr-filter-panel';
1166
+ /**
1167
+ * @typedef ColumnFilterConfig
1168
+ * @type {object}
1169
+ *
1170
+ * @property {MultiFilterItem|undefined} multiFilterItems - data for multi filtering with relation
1171
+ *
1172
+ * @property {Record<ColumnProp, FilterCollectionItem>|undefined} collection - preserved filter data, relation for filters will be applied as 'and'
1173
+ *
1174
+ * @property {string[]|undefined} include - filters to be included, if defined everything else out of scope will be ignored
1175
+ *
1176
+ * @property {Record<string, CustomFilter>|undefined} customFilters - hash map of {FilterType:CustomFilter}.
1177
+ *
1178
+ * @property {FilterLocalization|undefined} localization - translation for filter popup captions.
1179
+ *
1180
+ * @property {boolean|undefined} disableDynamicFiltering - disables dynamic filtering. A way to apply filters on Save only.
1181
+ */
1182
+ /**
1183
+ * @internal
1184
+ */
1185
+ class FilterPlugin extends BasePlugin {
1186
+ constructor(revogrid, providers, config) {
1187
+ var _a;
1188
+ super(revogrid, providers);
1189
+ this.revogrid = revogrid;
1190
+ this.config = config;
1191
+ this.filterCollection = {};
1192
+ this.multiFilterItems = {};
1193
+ /**
1194
+ * Filter types
1195
+ * @example
1196
+ * {
1197
+ * string: ['contains', 'beginswith'],
1198
+ * number: ['eqN', 'neqN', 'gt']
1199
+ * }
1200
+ */
1201
+ this.filterByType = Object.assign({}, filterTypes);
1202
+ this.filterNameIndexByType = Object.assign({}, filterNames);
1203
+ this.filterFunctionsIndexedByType = Object.assign({}, filterCoreFunctionsIndexedByType);
1204
+ this.filterProp = FILTER_PROP;
1205
+ if (config) {
1206
+ this.initConfig(config);
1207
+ }
1208
+ const existingNodes = this.revogrid.registerVNode.filter(n => typeof n === 'object' && n.$tag$ !== FILTE_PANEL);
1209
+ this.revogrid.registerVNode = [
1210
+ ...existingNodes,
1211
+ h("revogr-filter-panel", { filterNames: this.filterNameIndexByType, filterEntities: this.filterFunctionsIndexedByType, filterCaptions: (_a = config === null || config === void 0 ? void 0 : config.localization) === null || _a === void 0 ? void 0 : _a.captions, onFilterChange: e => this.onFilterChange(e.detail), onResetChange: e => this.onFilterReset(e.detail), disableDynamicFiltering: config === null || config === void 0 ? void 0 : config.disableDynamicFiltering, ref: e => (this.pop = e) },
1212
+ ' ',
1213
+ this.extraContent()),
1214
+ ];
1215
+ const aftersourceset = async () => {
1216
+ const filterCollectionProps = Object.keys(this.filterCollection);
1217
+ if (filterCollectionProps.length > 0) {
1218
+ // handle old way of filtering by reworking FilterCollection to new MultiFilterItem
1219
+ filterCollectionProps.forEach((prop, index) => {
1220
+ if (!this.multiFilterItems[prop]) {
1221
+ this.multiFilterItems[prop] = [
1222
+ {
1223
+ id: index,
1224
+ type: this.filterCollection[prop].type,
1225
+ value: this.filterCollection[prop].value,
1226
+ relation: 'and',
1227
+ },
1228
+ ];
1229
+ }
1230
+ });
1231
+ }
1232
+ if (Object.keys(this.multiFilterItems).length === 0) {
1233
+ return;
1234
+ }
1235
+ await this.runFiltering(this.multiFilterItems);
1236
+ };
1237
+ this.addEventListener('headerclick', e => this.headerclick(e));
1238
+ this.addEventListener(FILTER_CONFIG_CHANGED_EVENT, ({ detail }) => {
1239
+ if (!detail ||
1240
+ (typeof detail === 'object' &&
1241
+ (!detail.multiFilterItems ||
1242
+ !Object.keys(detail.multiFilterItems).length))) {
1243
+ this.clearFiltering();
1244
+ return;
1245
+ }
1246
+ if (typeof detail === 'object') {
1247
+ this.initConfig(detail);
1248
+ }
1249
+ aftersourceset();
1250
+ });
1251
+ this.addEventListener('aftersourceset', aftersourceset);
1252
+ this.addEventListener('filter', ({ detail }) => this.onFilterChange(detail));
1253
+ }
1254
+ beforeshow(_) {
1255
+ // used as hook for filter panel
1256
+ }
1257
+ extraContent() {
1258
+ return null;
1259
+ }
1260
+ initConfig(config) {
1261
+ if (config.multiFilterItems) {
1262
+ this.multiFilterItems = Object.assign({}, config.multiFilterItems);
1263
+ }
1264
+ else {
1265
+ this.multiFilterItems = {};
1266
+ }
1267
+ // Add custom filters
1268
+ if (config.customFilters) {
1269
+ for (let customFilterType in config.customFilters) {
1270
+ const cFilter = config.customFilters[customFilterType];
1271
+ if (!this.filterByType[cFilter.columnFilterType]) {
1272
+ this.filterByType[cFilter.columnFilterType] = [];
1273
+ }
1274
+ // add custom filter type
1275
+ this.filterByType[cFilter.columnFilterType].push(customFilterType);
1276
+ // add custom filter function
1277
+ this.filterFunctionsIndexedByType[customFilterType] = cFilter.func;
1278
+ // add custom filter name
1279
+ this.filterNameIndexByType[customFilterType] = cFilter.name;
1280
+ }
1281
+ }
1282
+ // Add filterProp if provided in config
1283
+ if (config.filterProp) {
1284
+ this.filterProp = config.filterProp;
1285
+ }
1286
+ /**
1287
+ * which filters has to be included/excluded
1288
+ * convenient way to exclude system filters
1289
+ */
1290
+ const cfgInlcude = config.include;
1291
+ if (cfgInlcude) {
1292
+ const filters = {};
1293
+ for (let t in this.filterByType) {
1294
+ // validate filters, if appropriate function present
1295
+ const newTypes = this.filterByType[t].filter(f => cfgInlcude.indexOf(f) > -1);
1296
+ if (newTypes.length) {
1297
+ filters[t] = newTypes;
1298
+ }
1299
+ }
1300
+ // if any valid filters provided show them
1301
+ if (Object.keys(filters).length > 0) {
1302
+ this.filterByType = filters;
1303
+ }
1304
+ }
1305
+ if (config.collection) {
1306
+ const filtersWithFilterFunctionPresent = Object.entries(config.collection).filter(([, item]) => this.filterFunctionsIndexedByType[item.type]);
1307
+ this.filterCollection = Object.fromEntries(filtersWithFilterFunctionPresent);
1308
+ }
1309
+ else {
1310
+ this.filterCollection = {};
1311
+ }
1312
+ if (config.localization) {
1313
+ if (config.localization.filterNames) {
1314
+ Object.entries(config.localization.filterNames).forEach(([k, v]) => {
1315
+ if (this.filterNameIndexByType[k] != void 0) {
1316
+ this.filterNameIndexByType[k] = v;
1317
+ }
1318
+ });
1319
+ }
1320
+ }
1321
+ }
1322
+ async headerclick(e) {
1323
+ var _a, _b;
1324
+ const el = (_a = e.detail.originalEvent) === null || _a === void 0 ? void 0 : _a.target;
1325
+ if (!isFilterBtn(el)) {
1326
+ return;
1327
+ }
1328
+ e.preventDefault();
1329
+ if (!this.pop) {
1330
+ return;
1331
+ }
1332
+ // filter button clicked, open filter dialog
1333
+ const gridPos = this.revogrid.getBoundingClientRect();
1334
+ const buttonPos = el.getBoundingClientRect();
1335
+ const prop = e.detail.prop;
1336
+ const data = Object.assign(Object.assign(Object.assign({}, e.detail), this.filterCollection[prop]), { x: buttonPos.x - gridPos.x, y: buttonPos.y - gridPos.y + buttonPos.height, autoCorrect: true, filterTypes: this.getColumnFilter(e.detail.filter), filterItems: this.multiFilterItems, extraContent: this.extraHyperContent });
1337
+ (_b = this.beforeshow) === null || _b === void 0 ? void 0 : _b.call(this, data);
1338
+ this.pop.show(data);
1339
+ }
1340
+ getColumnFilter(type) {
1341
+ let filterType = 'string';
1342
+ if (!type) {
1343
+ return { [filterType]: this.filterByType[filterType] };
1344
+ }
1345
+ // if custom column filter
1346
+ if (this.isValidType(type)) {
1347
+ filterType = type;
1348
+ // if multiple filters applied
1349
+ }
1350
+ else if (typeof type === 'object' && type.length) {
1351
+ return type.reduce((r, multiType) => {
1352
+ if (this.isValidType(multiType)) {
1353
+ r[multiType] = this.filterByType[multiType];
1354
+ }
1355
+ return r;
1356
+ }, {});
1357
+ }
1358
+ return { [filterType]: this.filterByType[filterType] };
1359
+ }
1360
+ isValidType(type) {
1361
+ return !!(typeof type === 'string' && this.filterByType[type]);
1362
+ }
1363
+ /**
1364
+ * Called on internal component change
1365
+ */
1366
+ async onFilterChange(filterItems) {
1367
+ // store the filter items
1368
+ this.multiFilterItems = filterItems;
1369
+ // run the filtering when the items change
1370
+ this.runFiltering(this.multiFilterItems);
1371
+ }
1372
+ onFilterReset(prop) {
1373
+ delete this.multiFilterItems[prop !== null && prop !== void 0 ? prop : ''];
1374
+ this.onFilterChange(this.multiFilterItems);
1375
+ }
1376
+ /**
1377
+ * Triggers grid filtering
1378
+ */
1379
+ async doFiltering(collection, source, columns, filterItems) {
1380
+ const columnsToUpdate = [];
1381
+ /**
1382
+ * Loop through the columns and update the columns that need to be updated with the `hasFilter` property.
1383
+ */
1384
+ const columnByProp = {};
1385
+ columns.forEach(rgCol => {
1386
+ const column = Object.assign({}, rgCol);
1387
+ const hasFilter = filterItems[column.prop];
1388
+ columnByProp[column.prop] = column;
1389
+ /**
1390
+ * If the column has a filter and it's not already marked as filtered, update the column.
1391
+ */
1392
+ if (column[this.filterProp] && !hasFilter) {
1393
+ delete column[this.filterProp];
1394
+ columnsToUpdate.push(column);
1395
+ }
1396
+ /**
1397
+ * If the column does not have a filter and it's marked as filtered, update the column.
1398
+ */
1399
+ if (!column[this.filterProp] && hasFilter) {
1400
+ columnsToUpdate.push(column);
1401
+ column[this.filterProp] = true;
1402
+ }
1403
+ });
1404
+ const itemsToTrim = this.getRowFilter(source, filterItems, columnByProp);
1405
+ // check is filter event prevented
1406
+ const { defaultPrevented, detail } = this.emit('beforefiltertrimmed', {
1407
+ collection,
1408
+ itemsToFilter: itemsToTrim,
1409
+ source,
1410
+ filterItems,
1411
+ });
1412
+ if (defaultPrevented) {
1413
+ return;
1414
+ }
1415
+ // check is trimmed event prevented
1416
+ const isAddedEvent = await this.revogrid.addTrimmed(detail.itemsToFilter, FILTER_TRIMMED_TYPE);
1417
+ if (isAddedEvent.defaultPrevented) {
1418
+ return;
1419
+ }
1420
+ // applies the hasFilter to the columns to show filter icon
1421
+ this.providers.column.updateColumns(columnsToUpdate);
1422
+ this.emit('afterfilterapply', {
1423
+ multiFilterItems: filterItems,
1424
+ source,
1425
+ collection,
1426
+ });
1427
+ }
1428
+ async clearFiltering() {
1429
+ this.multiFilterItems = {};
1430
+ await this.runFiltering(this.multiFilterItems);
1431
+ }
1432
+ async runFiltering(multiFilterItems) {
1433
+ const collection = {};
1434
+ // handle old filterCollection to return the first filter only (if any) from multiFilterItems
1435
+ const filterProps = Object.keys(multiFilterItems);
1436
+ for (const prop of filterProps) {
1437
+ // check if we have any filter for a column
1438
+ if (multiFilterItems[prop].length > 0) {
1439
+ const firstFilterItem = multiFilterItems[prop][0];
1440
+ collection[prop] = {
1441
+ type: firstFilterItem.type,
1442
+ value: firstFilterItem.value,
1443
+ };
1444
+ }
1445
+ }
1446
+ this.filterCollection = collection;
1447
+ const columns = this.providers.column.getColumns();
1448
+ // run the filtering on the main source only
1449
+ const source = this.providers.data.stores['rgRow'].store.get('source');
1450
+ const { defaultPrevented, detail } = this.emit('beforefilterapply', {
1451
+ collection: this.filterCollection,
1452
+ source,
1453
+ columns,
1454
+ filterItems: this.multiFilterItems,
1455
+ });
1456
+ if (defaultPrevented) {
1457
+ return;
1458
+ }
1459
+ this.doFiltering(detail.collection, detail.source, detail.columns, detail.filterItems);
1460
+ }
1461
+ /**
1462
+ * Get trimmed rows based on filter
1463
+ */
1464
+ getRowFilter(rows, filterItems, columnByProp) {
1465
+ const propKeys = Object.keys(filterItems);
1466
+ const trimmed = {};
1467
+ // each rows
1468
+ for (let rowIndex = 0; rowIndex < rows.length; rowIndex++) {
1469
+ // check filter by column properties
1470
+ for (const prop of propKeys) {
1471
+ // add to the list of removed/trimmed rows of filter condition is satisfied
1472
+ if (this.shouldTrimRow(filterItems[prop], prop, columnByProp[prop], rows[rowIndex])) {
1473
+ trimmed[rowIndex] = true;
1474
+ }
1475
+ } // end of for-of propKeys
1476
+ }
1477
+ return trimmed;
1478
+ }
1479
+ shouldTrimRow(propFilters, prop, column, model = {}) {
1480
+ // reset the count of satisfied filters
1481
+ let propFilterSatisfiedCount = 0;
1482
+ // reset the array of last filter results
1483
+ let lastFilterResults = [];
1484
+ // testing each filter for a prop
1485
+ for (const [filterIndex, filterData] of propFilters.entries()) {
1486
+ // the filter LogicFunction based on the type
1487
+ const filterFunc = this.filterFunctionsIndexedByType[filterData.type];
1488
+ // THE MAGIC OF FILTERING IS HERE
1489
+ // If there is no column but user wants to filter by a property
1490
+ const value = column ? getCellDataParsed(model, column) : model[prop];
1491
+ // OR relation
1492
+ if (filterData.relation === 'or') {
1493
+ // reset the array of last filter results
1494
+ lastFilterResults = [];
1495
+ // if the filter is satisfied, continue to the next filter
1496
+ if (filterFunc(value, filterData.value)) {
1497
+ continue;
1498
+ }
1499
+ // if the filter is not satisfied, count it
1500
+ propFilterSatisfiedCount++;
1501
+ // AND relation
1502
+ }
1503
+ else {
1504
+ // 'and' relation will need to know the next filter
1505
+ // so we save this current filter to include it in the next filter
1506
+ lastFilterResults.push(!filterFunc(value, filterData.value));
1507
+ if (isFinalAndFilter(filterIndex, propFilters)) {
1508
+ // let's just continue since for sure propFilterSatisfiedCount cannot be satisfied
1509
+ if (allAndConditionsSatisfied(lastFilterResults)) {
1510
+ // reset the array of last filter results
1511
+ lastFilterResults = [];
1512
+ continue;
1513
+ }
1514
+ // we need to add all of the lastFilterResults since we need to satisfy all
1515
+ propFilterSatisfiedCount += lastFilterResults.length;
1516
+ // reset the array of last filter results
1517
+ lastFilterResults = [];
1518
+ }
1519
+ }
1520
+ } // end of propFilters forEach
1521
+ return propFilterSatisfiedCount === propFilters.length;
1522
+ }
1523
+ }
1524
+ /**
1525
+ * Checks if the current filter is the final one in an AND sequence.
1526
+ * @param index - Current filter index in the list.
1527
+ * @param filters - Array of filters for the property.
1528
+ * @returns True if this is the last AND condition; false otherwise.
1529
+ */
1530
+ function isFinalAndFilter(index, filters) {
1531
+ const nextFilter = filters[index + 1]; // Get the next filter in the list.
1532
+ // Return true if there's no next filter or if the next filter defined and is not part of the AND sequence.
1533
+ return !nextFilter || (!!nextFilter.relation && nextFilter.relation !== 'and');
1534
+ }
1535
+ /**
1536
+ * Determines if all conditions in an AND sequence are satisfied.
1537
+ * @param pendingResults - An array of results from the AND conditions.
1538
+ * @returns True if all conditions are satisfied; false otherwise.
1539
+ */
1540
+ function allAndConditionsSatisfied(pendingResults) {
1541
+ // Check if there are any failed conditions in the pending results.
1542
+ return !pendingResults.includes(true);
1543
+ }
1544
+
1545
+ // provide collapse data
1546
+ function doCollapse(pIndex, source) {
1547
+ const model = source[pIndex];
1548
+ const collapseValue = model[PSEUDO_GROUP_ITEM_VALUE];
1549
+ const trimmed = {};
1550
+ let i = pIndex + 1;
1551
+ const total = source.length;
1552
+ while (i < total) {
1553
+ const currentModel = source[i];
1554
+ if (isGrouping(currentModel)) {
1555
+ const currentValue = currentModel[PSEUDO_GROUP_ITEM_VALUE];
1556
+ if (!currentValue.length || !currentValue.startsWith(collapseValue + ',')) {
1557
+ break;
1558
+ }
1559
+ currentModel[GROUP_EXPANDED] = false;
1560
+ }
1561
+ trimmed[i++] = true;
1562
+ }
1563
+ model[GROUP_EXPANDED] = false;
1564
+ return { trimmed };
1565
+ }
1566
+ /**
1567
+ *
1568
+ * @param pIndex - physical index
1569
+ * @param vIndex - virtual index, need to update item collection
1570
+ * @param source - data source
1571
+ * @param rowItemsIndexes - rgRow indexes
1572
+ */
1573
+ function doExpand(vIndex, source, rowItemsIndexes) {
1574
+ const physicalIndex = rowItemsIndexes[vIndex];
1575
+ const model = source[physicalIndex];
1576
+ const currentGroup = getParsedGroup(model[PSEUDO_GROUP_ITEM_ID]);
1577
+ const trimmed = {};
1578
+ // no group found
1579
+ if (!currentGroup) {
1580
+ return { trimmed };
1581
+ }
1582
+ const groupItems = [];
1583
+ model[GROUP_EXPANDED] = true;
1584
+ let i = physicalIndex + 1;
1585
+ const total = source.length;
1586
+ let groupLevelOnly = 0;
1587
+ // go through all rows
1588
+ while (i < total) {
1589
+ const currentModel = source[i];
1590
+ const isGroup = isGrouping(currentModel);
1591
+ // group found
1592
+ if (isGroup) {
1593
+ if (!isSameGroup(currentGroup, model, currentModel)) {
1594
+ break;
1595
+ }
1596
+ else if (!groupLevelOnly) {
1597
+ // if get group first it's group only level
1598
+ groupLevelOnly = currentModel[GROUP_DEPTH];
1599
+ }
1600
+ }
1601
+ // level 0 or same depth
1602
+ if (!groupLevelOnly || (isGroup && groupLevelOnly === currentModel[GROUP_DEPTH])) {
1603
+ trimmed[i] = false;
1604
+ groupItems.push(i);
1605
+ }
1606
+ i++;
1607
+ }
1608
+ const result = {
1609
+ trimmed,
1610
+ };
1611
+ if (groupItems.length) {
1612
+ const items = [...rowItemsIndexes];
1613
+ items.splice(vIndex + 1, 0, ...groupItems);
1614
+ result.items = items;
1615
+ }
1616
+ return result;
1617
+ }
1618
+
1619
+ const TRIMMED_GROUPING = 'grouping';
1620
+ /**
1621
+ * Prepare trimming updated indexes for grouping
1622
+ * @param initiallyTrimed
1623
+ * @param firstLevelMap
1624
+ * @param secondLevelMap
1625
+ */
1626
+ function processDoubleConversionTrimmed(initiallyTrimed, firstLevelMap, secondLevelMap) {
1627
+ const trimemedOptionsToUpgrade = {};
1628
+ /**
1629
+ * go through all groups except grouping
1630
+ */
1631
+ for (let type in initiallyTrimed) {
1632
+ if (type === TRIMMED_GROUPING) {
1633
+ continue;
1634
+ }
1635
+ const items = initiallyTrimed[type];
1636
+ const newItems = {};
1637
+ for (let initialIndex in items) {
1638
+ /**
1639
+ * if item exists we find it in collection
1640
+ * we support 2 level of conversions
1641
+ */
1642
+ let newConversionIndex = firstLevelMap[initialIndex];
1643
+ if (secondLevelMap) {
1644
+ newConversionIndex = secondLevelMap[newConversionIndex];
1645
+ }
1646
+ /**
1647
+ * if item was trimmed previously
1648
+ * trimming makes sense to apply
1649
+ */
1650
+ if (items[initialIndex]) {
1651
+ newItems[newConversionIndex] = true;
1652
+ /**
1653
+ * If changes present apply changes to new source
1654
+ */
1655
+ if (newConversionIndex !== parseInt(initialIndex, 10)) {
1656
+ trimemedOptionsToUpgrade[type] = newItems;
1657
+ }
1658
+ }
1659
+ }
1660
+ }
1661
+ return trimemedOptionsToUpgrade;
1662
+ }
1663
+
1664
+ /** `Object#toString` result references. */
1665
+ var stringTag = '[object String]';
1666
+
1667
+ /**
1668
+ * Checks if `value` is classified as a `String` primitive or object.
1669
+ *
1670
+ * @static
1671
+ * @since 0.1.0
1672
+ * @memberOf _
1673
+ * @category Lang
1674
+ * @param {*} value The value to check.
1675
+ * @returns {boolean} Returns `true` if `value` is a string, else `false`.
1676
+ * @example
1677
+ *
1678
+ * _.isString('abc');
1679
+ * // => true
1680
+ *
1681
+ * _.isString(1);
1682
+ * // => false
1683
+ */
1684
+ function isString(value) {
1685
+ return typeof value == 'string' ||
1686
+ (!isArray(value) && isObjectLike(value) && baseGetTag(value) == stringTag);
1687
+ }
1688
+
1689
+ /**
1690
+ * Gets the size of an ASCII `string`.
1691
+ *
1692
+ * @private
1693
+ * @param {string} string The string inspect.
1694
+ * @returns {number} Returns the string size.
1695
+ */
1696
+ var asciiSize = baseProperty('length');
1697
+
1698
+ const asciiSize$1 = asciiSize;
1699
+
1700
+ /** Used to compose unicode character classes. */
1701
+ var rsAstralRange$1 = '\\ud800-\\udfff',
1702
+ rsComboMarksRange$1 = '\\u0300-\\u036f',
1703
+ reComboHalfMarksRange$1 = '\\ufe20-\\ufe2f',
1704
+ rsComboSymbolsRange$1 = '\\u20d0-\\u20ff',
1705
+ rsComboRange$1 = rsComboMarksRange$1 + reComboHalfMarksRange$1 + rsComboSymbolsRange$1,
1706
+ rsVarRange$1 = '\\ufe0e\\ufe0f';
1707
+
1708
+ /** Used to compose unicode capture groups. */
1709
+ var rsZWJ$1 = '\\u200d';
1710
+
1711
+ /** Used to detect strings with [zero-width joiners or code points from the astral planes](http://eev.ee/blog/2015/09/12/dark-corners-of-unicode/). */
1712
+ var reHasUnicode = RegExp('[' + rsZWJ$1 + rsAstralRange$1 + rsComboRange$1 + rsVarRange$1 + ']');
1713
+
1714
+ /**
1715
+ * Checks if `string` contains Unicode symbols.
1716
+ *
1717
+ * @private
1718
+ * @param {string} string The string to inspect.
1719
+ * @returns {boolean} Returns `true` if a symbol is found, else `false`.
1720
+ */
1721
+ function hasUnicode(string) {
1722
+ return reHasUnicode.test(string);
1723
+ }
1724
+
1725
+ /** Used to compose unicode character classes. */
1726
+ var rsAstralRange = '\\ud800-\\udfff',
1727
+ rsComboMarksRange = '\\u0300-\\u036f',
1728
+ reComboHalfMarksRange = '\\ufe20-\\ufe2f',
1729
+ rsComboSymbolsRange = '\\u20d0-\\u20ff',
1730
+ rsComboRange = rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsRange,
1731
+ rsVarRange = '\\ufe0e\\ufe0f';
1732
+
1733
+ /** Used to compose unicode capture groups. */
1734
+ var rsAstral = '[' + rsAstralRange + ']',
1735
+ rsCombo = '[' + rsComboRange + ']',
1736
+ rsFitz = '\\ud83c[\\udffb-\\udfff]',
1737
+ rsModifier = '(?:' + rsCombo + '|' + rsFitz + ')',
1738
+ rsNonAstral = '[^' + rsAstralRange + ']',
1739
+ rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}',
1740
+ rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]',
1741
+ rsZWJ = '\\u200d';
1742
+
1743
+ /** Used to compose unicode regexes. */
1744
+ var reOptMod = rsModifier + '?',
1745
+ rsOptVar = '[' + rsVarRange + ']?',
1746
+ rsOptJoin = '(?:' + rsZWJ + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*',
1747
+ rsSeq = rsOptVar + reOptMod + rsOptJoin,
1748
+ rsSymbol = '(?:' + [rsNonAstral + rsCombo + '?', rsCombo, rsRegional, rsSurrPair, rsAstral].join('|') + ')';
1749
+
1750
+ /** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */
1751
+ var reUnicode = RegExp(rsFitz + '(?=' + rsFitz + ')|' + rsSymbol + rsSeq, 'g');
1752
+
1753
+ /**
1754
+ * Gets the size of a Unicode `string`.
1755
+ *
1756
+ * @private
1757
+ * @param {string} string The string inspect.
1758
+ * @returns {number} Returns the string size.
1759
+ */
1760
+ function unicodeSize(string) {
1761
+ var result = reUnicode.lastIndex = 0;
1762
+ while (reUnicode.test(string)) {
1763
+ ++result;
1764
+ }
1765
+ return result;
1766
+ }
1767
+
1768
+ /**
1769
+ * Gets the number of symbols in `string`.
1770
+ *
1771
+ * @private
1772
+ * @param {string} string The string to inspect.
1773
+ * @returns {number} Returns the string size.
1774
+ */
1775
+ function stringSize(string) {
1776
+ return hasUnicode(string)
1777
+ ? unicodeSize(string)
1778
+ : asciiSize$1(string);
1779
+ }
1780
+
1781
+ /** `Object#toString` result references. */
1782
+ var mapTag = '[object Map]',
1783
+ setTag = '[object Set]';
1784
+
1785
+ /**
1786
+ * Gets the size of `collection` by returning its length for array-like
1787
+ * values or the number of own enumerable string keyed properties for objects.
1788
+ *
1789
+ * @static
1790
+ * @memberOf _
1791
+ * @since 0.1.0
1792
+ * @category Collection
1793
+ * @param {Array|Object|string} collection The collection to inspect.
1794
+ * @returns {number} Returns the collection size.
1795
+ * @example
1796
+ *
1797
+ * _.size([1, 2, 3]);
1798
+ * // => 3
1799
+ *
1800
+ * _.size({ 'a': 1, 'b': 2 });
1801
+ * // => 2
1802
+ *
1803
+ * _.size('pebbles');
1804
+ * // => 7
1805
+ */
1806
+ function size(collection) {
1807
+ if (collection == null) {
1808
+ return 0;
1809
+ }
1810
+ if (isArrayLike(collection)) {
1811
+ return isString(collection) ? stringSize(collection) : collection.length;
1812
+ }
1813
+ var tag = getTag(collection);
1814
+ if (tag == mapTag || tag == setTag) {
1815
+ return collection.size;
1816
+ }
1817
+ return baseKeys(collection).length;
1818
+ }
1819
+
1820
+ function sortIndexByItems(indexes, source, sortingFunc = {}) {
1821
+ // if no sorting - return unsorted indexes
1822
+ if (Object.entries(sortingFunc).length === 0) {
1823
+ // Unsorted indexes
1824
+ return [...Array(indexes.length).keys()];
1825
+ }
1826
+ //
1827
+ /**
1828
+ * go through all indexes and align in new order
1829
+ * performs a multi-level sorting by applying multiple comparison functions to determine the order of the items based on different properties.
1830
+ */
1831
+ return indexes.sort((a, b) => {
1832
+ const itemA = source[a];
1833
+ const itemB = source[b];
1834
+ for (const [prop, cmp] of Object.entries(sortingFunc)) {
1835
+ if (isGrouping(itemA)) {
1836
+ if (itemA['__rvgr-prop'] !== prop) {
1837
+ return 0;
1838
+ }
1839
+ }
1840
+ if (isGrouping(itemB)) {
1841
+ if (itemB['__rvgr-prop'] !== prop) {
1842
+ return 0;
1843
+ }
1844
+ }
1845
+ /**
1846
+ * If the comparison function returns a non-zero value (sorted), it means that the items should be sorted based on the given property. In such a case, the function immediately returns the sorted value, indicating the order in which the items should be arranged.
1847
+ * If none of the comparison functions result in a non-zero value, indicating that the items are equal or should remain in the same order, the function eventually returns 0.
1848
+ */
1849
+ const sorted = cmp === null || cmp === void 0 ? void 0 : cmp(prop, itemA, itemB);
1850
+ if (sorted) {
1851
+ return sorted;
1852
+ }
1853
+ }
1854
+ return 0;
1855
+ });
1856
+ }
1857
+
1858
+ /**
1859
+ * Lifecycle
1860
+ * 1. @event `beforesorting` - Triggered when sorting just starts. Nothing has happened yet. This can be triggered from a column or from the source. If the type is from rows, the column will be undefined.
1861
+ * 1.1. @event `beforesourcesortingapply` - Triggered before the sorting data is applied to the data source. You can prevent this event, and the data will not be sorted.
1862
+ * 2. @method `updateColumnSorting` - Updates the column sorting icon on the grid and the column itself, but the data remains untouched.
1863
+ * 3. @event `beforesortingapply` - Triggered before the sorting data is applied to the data source. You can prevent this event, and the data will not be sorted. This event is only called from a column sorting click.
1864
+ * 4. @event `aftersortingapply` - Triggered after sorting has been applied and completed. This event occurs for both row and column sorting.
1865
+ *
1866
+ * Note: If you prevent an event, it will not proceed to the subsequent steps.
1867
+ */
1868
+ class SortingPlugin extends BasePlugin {
1869
+ runSorting(order, comparison, ignoreViewportUpdate) {
1870
+ var _a;
1871
+ this.sort(order, comparison, undefined, ignoreViewportUpdate);
1872
+ (_a = this.sortingPromise) === null || _a === void 0 ? void 0 : _a.call(this);
1873
+ this.sortingPromise = null;
1874
+ }
1875
+ constructor(revogrid, providers, config) {
1876
+ super(revogrid, providers);
1877
+ this.revogrid = revogrid;
1878
+ this.sortingPromise = null;
1879
+ this.postponeSort = debounce((order, comparison, ignoreViewportUpdate) => this.runSorting(order, comparison, ignoreViewportUpdate), 50);
1880
+ const setConfig = (cfg) => {
1881
+ var _a;
1882
+ if (cfg) {
1883
+ const sortingFunc = {};
1884
+ const order = {};
1885
+ (_a = cfg.columns) === null || _a === void 0 ? void 0 : _a.forEach(col => {
1886
+ sortingFunc[col.prop] = this.getComparer(col, col.order);
1887
+ order[col.prop] = col.order;
1888
+ });
1889
+ // // set sorting
1890
+ this.sorting = order;
1891
+ this.sortingFunc = sortingFunc;
1892
+ }
1893
+ };
1894
+ setConfig(config);
1895
+ this.addEventListener('sortingconfigchanged', ({ detail }) => {
1896
+ config = detail;
1897
+ setConfig(detail);
1898
+ this.startSorting(this.sorting, this.sortingFunc);
1899
+ });
1900
+ this.addEventListener('beforeanysource', ({ detail: { type }, }) => {
1901
+ // if sorting was provided - sort data
1902
+ if (!!this.sorting && this.sortingFunc) {
1903
+ const event = this.emit('beforesourcesortingapply', { type, sorting: this.sorting });
1904
+ if (event.defaultPrevented) {
1905
+ return;
1906
+ }
1907
+ this.startSorting(this.sorting, this.sortingFunc);
1908
+ }
1909
+ });
1910
+ this.addEventListener('aftercolumnsset', ({ detail: { order }, }) => {
1911
+ // if config provided - do nothing, read from config
1912
+ if (config) {
1913
+ return;
1914
+ }
1915
+ const columns = this.providers.column.getColumns();
1916
+ const sortingFunc = {};
1917
+ for (let prop in order) {
1918
+ const cmp = this.getComparer(getColumnByProp(columns, prop), order[prop]);
1919
+ sortingFunc[prop] = cmp;
1920
+ }
1921
+ // set sorting
1922
+ this.sorting = order;
1923
+ this.sortingFunc = order && sortingFunc;
1924
+ });
1925
+ this.addEventListener('beforeheaderclick', (e) => {
1926
+ var _a, _b, _c, _d;
1927
+ if (e.defaultPrevented) {
1928
+ return;
1929
+ }
1930
+ if (!((_b = (_a = e.detail) === null || _a === void 0 ? void 0 : _a.column) === null || _b === void 0 ? void 0 : _b.sortable)) {
1931
+ return;
1932
+ }
1933
+ this.headerclick(e.detail.column, e.detail.index, (_d = (_c = e.detail) === null || _c === void 0 ? void 0 : _c.originalEvent) === null || _d === void 0 ? void 0 : _d.shiftKey);
1934
+ });
1935
+ }
1936
+ startSorting(order, sortingFunc, ignoreViewportUpdate) {
1937
+ if (!this.sortingPromise) {
1938
+ // add job before render
1939
+ this.revogrid.jobsBeforeRender.push(new Promise(resolve => {
1940
+ this.sortingPromise = resolve;
1941
+ }));
1942
+ }
1943
+ this.postponeSort(order, sortingFunc, ignoreViewportUpdate);
1944
+ }
1945
+ getComparer(column, order) {
1946
+ var _a, _b;
1947
+ const cellCmp = ((_a = column === null || column === void 0 ? void 0 : column.cellCompare) === null || _a === void 0 ? void 0 : _a.bind({ order })) || ((_b = this.defaultCellCompare) === null || _b === void 0 ? void 0 : _b.bind({ column, order }));
1948
+ if (order == 'asc') {
1949
+ return cellCmp;
1950
+ }
1951
+ if (order == 'desc') {
1952
+ return this.descCellCompare(cellCmp);
1953
+ }
1954
+ return undefined;
1955
+ }
1956
+ /**
1957
+ * Apply sorting to data on header click
1958
+ * If additive - add to existing sorting, multiple columns can be sorted
1959
+ */
1960
+ headerclick(column, index, additive) {
1961
+ var _a, _b;
1962
+ let order = this.getNextOrder(column.order);
1963
+ const beforeEvent = this.emit('beforesorting', { column, order, additive });
1964
+ if (beforeEvent.defaultPrevented) {
1965
+ return;
1966
+ }
1967
+ order = beforeEvent.detail.order;
1968
+ const newCol = this.providers.column.updateColumnSorting(beforeEvent.detail.column, index, order, additive);
1969
+ // apply sort data
1970
+ const beforeApplyEvent = this.emit('beforesortingapply', {
1971
+ column: newCol,
1972
+ order,
1973
+ additive,
1974
+ });
1975
+ if (beforeApplyEvent.defaultPrevented) {
1976
+ return;
1977
+ }
1978
+ const cmp = this.getComparer(beforeApplyEvent.detail.column, beforeApplyEvent.detail.order);
1979
+ if (beforeApplyEvent.detail.additive && this.sorting) {
1980
+ const sorting = {};
1981
+ const sortingFunc = {};
1982
+ this.sorting = Object.assign(Object.assign({}, this.sorting), sorting);
1983
+ // extend sorting function with new sorting for multiple columns sorting
1984
+ this.sortingFunc = Object.assign(Object.assign({}, this.sortingFunc), sortingFunc);
1985
+ if (column.prop in sorting && size(sorting) > 1 && order === undefined) {
1986
+ delete sorting[column.prop];
1987
+ delete sortingFunc[column.prop];
1988
+ }
1989
+ else {
1990
+ sorting[column.prop] = order;
1991
+ sortingFunc[column.prop] = cmp;
1992
+ }
1993
+ }
1994
+ else {
1995
+ if (order) {
1996
+ // reset sorting
1997
+ this.sorting = { [column.prop]: order };
1998
+ this.sortingFunc = { [column.prop]: cmp };
1999
+ }
2000
+ else {
2001
+ (_a = this.sorting) === null || _a === void 0 ? true : delete _a[column.prop];
2002
+ (_b = this.sortingFunc) === null || _b === void 0 ? true : delete _b[column.prop];
2003
+ }
2004
+ }
2005
+ this.startSorting(this.sorting, this.sortingFunc);
2006
+ }
2007
+ /**
2008
+ * Sort items by sorting function
2009
+ * @requires proxyItems applied to row store
2010
+ * @requires source applied to row store
2011
+ *
2012
+ * @param sorting - per column sorting
2013
+ * @param data - this.stores['rgRow'].store.get('source')
2014
+ */
2015
+ sort(sorting, sortingFunc, types = rowTypes, ignoreViewportUpdate = false) {
2016
+ // if no sorting - reset
2017
+ if (!Object.keys(sorting || {}).length) {
2018
+ for (let type of types) {
2019
+ const storeService = this.providers.data.stores[type];
2020
+ // row data
2021
+ const source = storeService.store.get('source');
2022
+ // row indexes
2023
+ const proxyItems = storeService.store.get('proxyItems');
2024
+ // row indexes
2025
+ const newItemsOrder = Array.from({ length: source.length }, (_, i) => i); // recover indexes range(0, source.length)
2026
+ this.providers.dimension.updateSizesPositionByNewDataIndexes(type, newItemsOrder, proxyItems);
2027
+ storeService.setData({ proxyItems: newItemsOrder, source: [...source], });
2028
+ }
2029
+ }
2030
+ else {
2031
+ for (let type of types) {
2032
+ const storeService = this.providers.data.stores[type];
2033
+ // row data
2034
+ const source = storeService.store.get('source');
2035
+ // row indexes
2036
+ const proxyItems = storeService.store.get('proxyItems');
2037
+ const newItemsOrder = sortIndexByItems([...proxyItems], source, sortingFunc);
2038
+ // take row indexes before trim applied and proxy items
2039
+ const prevItems = storeService.store.get('items');
2040
+ storeService.setData({
2041
+ proxyItems: newItemsOrder,
2042
+ source: [...source],
2043
+ });
2044
+ // take currently visible row indexes
2045
+ const newItems = storeService.store.get('items');
2046
+ if (!ignoreViewportUpdate) {
2047
+ this.providers.dimension
2048
+ .updateSizesPositionByNewDataIndexes(type, newItems, prevItems);
2049
+ }
2050
+ }
2051
+ }
2052
+ this.emit('aftersortingapply');
2053
+ }
2054
+ defaultCellCompare(prop, a, b) {
2055
+ const aRaw = this.column ? getCellRaw(a, this.column) : a === null || a === void 0 ? void 0 : a[prop];
2056
+ const bRaw = this.column ? getCellRaw(b, this.column) : b === null || b === void 0 ? void 0 : b[prop];
2057
+ const av = aRaw === null || aRaw === void 0 ? void 0 : aRaw.toString().toLowerCase();
2058
+ const bv = bRaw === null || bRaw === void 0 ? void 0 : bRaw.toString().toLowerCase();
2059
+ return av == bv ? 0 : av > bv ? 1 : -1;
2060
+ }
2061
+ descCellCompare(cmp) {
2062
+ return (prop, a, b) => {
2063
+ return -1 * cmp(prop, a, b);
2064
+ };
2065
+ }
2066
+ getNextOrder(currentOrder) {
2067
+ switch (currentOrder) {
2068
+ case undefined:
2069
+ return 'asc';
2070
+ case 'asc':
2071
+ return 'desc';
2072
+ case 'desc':
2073
+ return undefined;
2074
+ }
2075
+ }
2076
+ }
2077
+
2078
+ class GroupingRowPlugin extends BasePlugin {
2079
+ getStore(type = GROUPING_ROW_TYPE) {
2080
+ return this.providers.data.stores[type].store;
2081
+ }
2082
+ constructor(revogrid, providers) {
2083
+ super(revogrid, providers);
2084
+ this.revogrid = revogrid;
2085
+ this.providers = providers;
2086
+ }
2087
+ // befoce cell focus
2088
+ onFocus(e) {
2089
+ if (isGrouping(e.detail.model)) {
2090
+ e.preventDefault();
2091
+ }
2092
+ }
2093
+ // expand event triggered
2094
+ onExpand({ virtualIndex }) {
2095
+ const { source } = getSource(this.getStore().get('source'), this.getStore().get('proxyItems'));
2096
+ let newTrimmed = this.getStore().get('trimmed')[TRIMMED_GROUPING];
2097
+ let i = getPhysical(this.getStore(), virtualIndex);
2098
+ const isExpanded = getExpanded(source[i]);
2099
+ if (!isExpanded) {
2100
+ const { trimmed, items } = doExpand(virtualIndex, source, this.getStore().get('items'));
2101
+ newTrimmed = Object.assign(Object.assign({}, newTrimmed), trimmed);
2102
+ if (items) {
2103
+ setItems(this.getStore(), items);
2104
+ }
2105
+ }
2106
+ else {
2107
+ const { trimmed } = doCollapse(i, source);
2108
+ newTrimmed = Object.assign(Object.assign({}, newTrimmed), trimmed);
2109
+ this.revogrid.clearFocus();
2110
+ }
2111
+ this.getStore().set('source', source);
2112
+ this.revogrid.addTrimmed(newTrimmed, TRIMMED_GROUPING);
2113
+ }
2114
+ setColumnGrouping(cols) {
2115
+ // if 0 column as holder
2116
+ if (cols === null || cols === void 0 ? void 0 : cols.length) {
2117
+ cols[0][PSEUDO_GROUP_COLUMN] = true;
2118
+ return true;
2119
+ }
2120
+ return false;
2121
+ }
2122
+ setColumns({ columns }) {
2123
+ for (let type of columnTypes) {
2124
+ if (this.setColumnGrouping(columns[type])) {
2125
+ break;
2126
+ }
2127
+ }
2128
+ }
2129
+ // evaluate drag between groups
2130
+ onDrag(e) {
2131
+ const { from, to } = e.detail;
2132
+ const isDown = to - from >= 0;
2133
+ const { source } = getSource(this.getStore().get('source'), this.getStore().get('proxyItems'));
2134
+ const items = this.getStore().get('items');
2135
+ let i = isDown ? from : to;
2136
+ const end = isDown ? to : from;
2137
+ for (; i < end; i++) {
2138
+ const model = source[items[i]];
2139
+ const isGroup = isGrouping(model);
2140
+ if (isGroup) {
2141
+ e.preventDefault();
2142
+ return;
2143
+ }
2144
+ }
2145
+ }
2146
+ beforeTrimmedApply(trimmed, type) {
2147
+ /** Before filter apply remove grouping filtering */
2148
+ if (type === FILTER_TRIMMED_TYPE) {
2149
+ const source = this.getStore().get('source');
2150
+ for (let index in trimmed) {
2151
+ if (trimmed[index] && isGrouping(source[index])) {
2152
+ trimmed[index] = false;
2153
+ }
2154
+ }
2155
+ }
2156
+ }
2157
+ isSortingRunning() {
2158
+ const sortingPlugin = this.providers.plugins.getByClass(SortingPlugin);
2159
+ return !!(sortingPlugin === null || sortingPlugin === void 0 ? void 0 : sortingPlugin.sortingPromise);
2160
+ }
2161
+ // subscribe to grid events to process them accordingly
2162
+ subscribe() {
2163
+ /** if grouping present and new data source arrived */
2164
+ this.addEventListener('beforesourceset', ({ detail }) => {
2165
+ var _a, _b, _c;
2166
+ if (!(((_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.props) === null || _b === void 0 ? void 0 : _b.length) && ((_c = detail === null || detail === void 0 ? void 0 : detail.source) === null || _c === void 0 ? void 0 : _c.length))) {
2167
+ return;
2168
+ }
2169
+ // if sorting is running don't apply grouping, wait for sorting, then it'll apply in @aftersortingapply
2170
+ if (this.isSortingRunning()) {
2171
+ return;
2172
+ }
2173
+ this.onDataSet(detail);
2174
+ });
2175
+ this.addEventListener('beforecolumnsset', ({ detail }) => {
2176
+ this.setColumns(detail);
2177
+ });
2178
+ /**
2179
+ * filter applied need to clear grouping and apply again
2180
+ * based on new results can be new grouping
2181
+ */
2182
+ this.addEventListener('beforetrimmed', ({ detail: { trimmed, trimmedType } }) => this.beforeTrimmedApply(trimmed, trimmedType));
2183
+ /**
2184
+ * sorting applied need to clear grouping and apply again
2185
+ * based on new results whole grouping order will changed
2186
+ */
2187
+ this.addEventListener('aftersortingapply', () => {
2188
+ var _a, _b;
2189
+ if (!((_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.props) === null || _b === void 0 ? void 0 : _b.length)) {
2190
+ return;
2191
+ }
2192
+ this.doSourceUpdate(Object.assign({}, this.options));
2193
+ });
2194
+ /**
2195
+ * Apply logic for focus inside of grouping
2196
+ * We can't focus on grouping rows, navigation only inside of groups for now
2197
+ */
2198
+ this.addEventListener('beforecellfocus', e => this.onFocus(e));
2199
+ /**
2200
+ * Prevent rgRow drag outside the group
2201
+ */
2202
+ this.addEventListener('roworderchanged', e => this.onDrag(e));
2203
+ /**
2204
+ * When grouping expand icon was clicked
2205
+ */
2206
+ this.addEventListener('groupexpandclick', e => this.onExpand(e.detail));
2207
+ }
2208
+ /**
2209
+ * Starts global source update with group clearing and applying new one
2210
+ * Initiated when need to reapply grouping
2211
+ */
2212
+ doSourceUpdate(options) {
2213
+ var _a;
2214
+ /**
2215
+ * Get source without grouping
2216
+ * @param newOldIndexMap - provides us mapping with new indexes vs old indexes, we would use it for trimmed mapping
2217
+ */
2218
+ const { source, prevExpanded, oldNewIndexes } = getSource(this.getStore().get('source'), this.getStore().get('proxyItems'), true);
2219
+ const expanded = Object.assign({ prevExpanded }, options);
2220
+ /**
2221
+ * Group again
2222
+ * @param oldNewIndexMap - provides us mapping with new indexes vs old indexes
2223
+ */
2224
+ const { sourceWithGroups, depth, trimmed, oldNewIndexMap, childrenByGroup, } = gatherGrouping(source, ((_a = this.options) === null || _a === void 0 ? void 0 : _a.props) || [], expanded);
2225
+ const customRenderer = options === null || options === void 0 ? void 0 : options.groupLabelTemplate;
2226
+ // setup source
2227
+ this.providers.data.setData(sourceWithGroups, GROUPING_ROW_TYPE, this.revogrid.disableVirtualY, { depth, customRenderer }, true);
2228
+ this.updateTrimmed(trimmed, childrenByGroup, oldNewIndexes !== null && oldNewIndexes !== void 0 ? oldNewIndexes : {}, oldNewIndexMap);
2229
+ }
2230
+ /**
2231
+ * Apply grouping on data set
2232
+ * Clear grouping from source
2233
+ * If source came from other plugin
2234
+ */
2235
+ onDataSet(data) {
2236
+ var _a, _b;
2237
+ let preservedExpanded = {};
2238
+ if (((_a = this.options) === null || _a === void 0 ? void 0 : _a.preserveGroupingOnUpdate) !== false) {
2239
+ let { prevExpanded } = getSource(this.getStore().get('source'), this.getStore().get('proxyItems'), true);
2240
+ preservedExpanded = prevExpanded;
2241
+ }
2242
+ const source = data.source.filter(s => !isGrouping(s));
2243
+ const options = Object.assign(Object.assign({}, (this.revogrid.grouping || {})), { prevExpanded: preservedExpanded });
2244
+ const { sourceWithGroups, depth, trimmed, oldNewIndexMap, childrenByGroup, } = gatherGrouping(source, ((_b = this.options) === null || _b === void 0 ? void 0 : _b.props) || [], options);
2245
+ data.source = sourceWithGroups;
2246
+ this.providers.data.setGrouping({ depth });
2247
+ this.updateTrimmed(trimmed, childrenByGroup, oldNewIndexMap);
2248
+ }
2249
+ /**
2250
+ * Externam call to apply grouping. Called by revogrid when prop changed.
2251
+ */
2252
+ setGrouping(options) {
2253
+ var _a, _b;
2254
+ // unsubscribe from all events when group applied
2255
+ this.clearSubscriptions();
2256
+ this.options = options;
2257
+ // clear props, no grouping exists
2258
+ if (!((_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.props) === null || _b === void 0 ? void 0 : _b.length)) {
2259
+ this.clearGrouping();
2260
+ return;
2261
+ }
2262
+ // props exist and source inited
2263
+ const { source } = getSource(this.getStore().get('source'), this.getStore().get('proxyItems'));
2264
+ if (source.length) {
2265
+ this.doSourceUpdate(Object.assign({}, options));
2266
+ }
2267
+ // props exist and columns inited
2268
+ for (let t of columnTypes) {
2269
+ if (this.setColumnGrouping(this.providers.column.getColumns(t))) {
2270
+ this.providers.column.refreshByType(t);
2271
+ break;
2272
+ }
2273
+ }
2274
+ // if has any grouping subscribe to events again
2275
+ this.subscribe();
2276
+ }
2277
+ // clear grouping
2278
+ clearGrouping() {
2279
+ // clear columns
2280
+ columnTypes.forEach(t => {
2281
+ const cols = this.providers.column.getColumns(t);
2282
+ let deleted = false;
2283
+ cols.forEach(c => {
2284
+ if (isGroupingColumn(c)) {
2285
+ delete c[PSEUDO_GROUP_COLUMN];
2286
+ deleted = true;
2287
+ }
2288
+ });
2289
+ // if column store had grouping clear and refresh
2290
+ if (deleted) {
2291
+ this.providers.column.refreshByType(t);
2292
+ }
2293
+ });
2294
+ // clear rows
2295
+ const { source, oldNewIndexes } = getSource(this.getStore().get('source'), this.getStore().get('proxyItems'), true);
2296
+ this.providers.data.setData(source, GROUPING_ROW_TYPE, this.revogrid.disableVirtualY, undefined, true);
2297
+ this.updateTrimmed(undefined, undefined, oldNewIndexes);
2298
+ }
2299
+ updateTrimmed(trimmedGroup = {}, _childrenByGroup = {}, firstLevelMap = {}, secondLevelMap) {
2300
+ // map previously trimmed data
2301
+ const trimemedOptionsToUpgrade = processDoubleConversionTrimmed(this.getStore().get('trimmed'), firstLevelMap, secondLevelMap);
2302
+ for (let type in trimemedOptionsToUpgrade) {
2303
+ this.revogrid.addTrimmed(trimemedOptionsToUpgrade[type], type);
2304
+ }
2305
+ // const emptyGroups = this.filterOutEmptyGroups(trimemedOptionsToUpgrade, childrenByGroup);
2306
+ // setup trimmed data for grouping
2307
+ this.revogrid.addTrimmed(Object.assign({}, trimmedGroup), TRIMMED_GROUPING);
2308
+ }
2309
+ }
2310
+
2311
+ const COLUMN_DRAG_CLASS = 'column-drag-start';
2312
+ class ColumnOrderHandler {
2313
+ constructor() {
2314
+ this.offset = 0;
2315
+ }
2316
+ renderAutoscroll(_, parent) {
2317
+ if (!parent) {
2318
+ return;
2319
+ }
2320
+ this.autoscrollEl = document.createElement('div');
2321
+ this.autoscrollEl.classList.add('drag-auto-scroll-y');
2322
+ parent.appendChild(this.autoscrollEl);
2323
+ }
2324
+ autoscroll(pos, dataContainerSize, direction = 'translateX') {
2325
+ if (!this.autoscrollEl) {
2326
+ return;
2327
+ }
2328
+ const helperOffset = 10;
2329
+ // calculate current y position inside of the grid active holder
2330
+ // 3 - size of element + border
2331
+ const maxScroll = Math.min(pos + helperOffset, dataContainerSize - 3);
2332
+ this.autoscrollEl.style.transform = `${direction}(${maxScroll}px)`;
2333
+ this.autoscrollEl.scrollIntoView({
2334
+ block: 'nearest',
2335
+ inline: 'nearest',
2336
+ });
2337
+ }
2338
+ start(e, { dataEl, gridRect, scrollEl, gridEl }, dir = 'left') {
2339
+ gridEl.classList.add(COLUMN_DRAG_CLASS);
2340
+ const scrollContainerRect = scrollEl.getBoundingClientRect();
2341
+ if (scrollContainerRect) {
2342
+ this.offset = scrollContainerRect[dir] - gridRect[dir];
2343
+ }
2344
+ this.renderAutoscroll(e, dataEl);
2345
+ }
2346
+ stop(gridEl) {
2347
+ var _a;
2348
+ gridEl.classList.remove(COLUMN_DRAG_CLASS);
2349
+ if (this.element) {
2350
+ this.element.hidden = true;
2351
+ }
2352
+ this.offset = 0;
2353
+ (_a = this.autoscrollEl) === null || _a === void 0 ? void 0 : _a.remove();
2354
+ this.autoscrollEl = undefined;
2355
+ }
2356
+ showHandler(pos, size, direction = 'translateX') {
2357
+ if (!this.element) {
2358
+ return;
2359
+ }
2360
+ // do not allow overcross top of the scrollable area, header excluded
2361
+ if (this.offset) {
2362
+ pos = Math.max(pos, this.offset);
2363
+ }
2364
+ // can not be bigger then grid end
2365
+ pos = Math.min(pos, size);
2366
+ this.element.style.transform = `${direction}(${pos}px)`;
2367
+ this.element.hidden = false;
2368
+ }
2369
+ render() {
2370
+ const el = this.element = document.createElement('div');
2371
+ el.classList.add('drag-position-y');
2372
+ el.hidden = true;
2373
+ return el;
2374
+ }
2375
+ }
2376
+
2377
+ /**
2378
+ * Plugin for column manual move
2379
+ */
2380
+ const COLUMN_CLICK = ON_COLUMN_CLICK;
2381
+ const MOVE = 'columndragmousemove';
2382
+ const DRAG_END = 'columndragend';
2383
+ const BEFORE_DRAG_END = 'beforecolumndragend';
2384
+ // use this event subscription to drop D&D for particular columns
2385
+ const DRAG_START = 'columndragstart';
2386
+ class ColumnMovePlugin extends BasePlugin {
2387
+ constructor(revogrid, providers) {
2388
+ super(revogrid, providers);
2389
+ this.revogrid = revogrid;
2390
+ this.providers = providers;
2391
+ this.moveFunc = debounce((e) => this.doMove(e), 5);
2392
+ this.staticDragData = null;
2393
+ this.dragData = null;
2394
+ this.localSubscriptions = {};
2395
+ this.orderUi = new ColumnOrderHandler();
2396
+ revogrid.appendChild(this.orderUi.render());
2397
+ revogrid.classList.add('column-draggable');
2398
+ // Register events
2399
+ this.localSubscriptions['mouseleave'] = {
2400
+ target: document,
2401
+ callback: (e) => this.onMouseOut(e),
2402
+ };
2403
+ this.localSubscriptions['mouseup'] = {
2404
+ target: document,
2405
+ callback: (e) => this.onMouseUp(e),
2406
+ };
2407
+ this.localSubscriptions['mousemove'] = {
2408
+ target: document,
2409
+ callback: (e) => this.move(e),
2410
+ };
2411
+ this.addEventListener(COLUMN_CLICK, ({ detail }) => this.dragStart(detail));
2412
+ }
2413
+ dragStart({ event, data }) {
2414
+ if (event.defaultPrevented) {
2415
+ return;
2416
+ }
2417
+ const { defaultPrevented } = dispatch(this.revogrid, DRAG_START, data);
2418
+ // check if allowed to drag particulat column
2419
+ if (defaultPrevented) {
2420
+ return;
2421
+ }
2422
+ this.clearOrder();
2423
+ const { mouseleave, mouseup, mousemove } = this.localSubscriptions;
2424
+ mouseleave.target.addEventListener('mouseleave', mouseleave.callback);
2425
+ mouseup.target.addEventListener('mouseup', mouseup.callback);
2426
+ const dataEl = event.target.closest('revogr-header');
2427
+ const scrollEl = event.target.closest('revogr-viewport-scroll');
2428
+ if (!dataEl || !scrollEl) {
2429
+ return;
2430
+ }
2431
+ // no grouping drag and no row header column drag
2432
+ if (isColGrouping(data) || data.providers.type === 'rowHeaders') {
2433
+ return;
2434
+ }
2435
+ const cols = this.getDimension(data.pin || 'rgCol');
2436
+ const gridRect = this.revogrid.getBoundingClientRect();
2437
+ const elRect = dataEl.getBoundingClientRect();
2438
+ const startItem = getItemByPosition(cols, getLeftRelative(event.x, gridRect.left, elRect.left - gridRect.left));
2439
+ this.staticDragData = {
2440
+ startPos: event.x,
2441
+ startItem,
2442
+ data,
2443
+ dataEl,
2444
+ scrollEl,
2445
+ gridEl: this.revogrid,
2446
+ cols,
2447
+ };
2448
+ this.dragData = this.getData(this.staticDragData);
2449
+ mousemove.target.addEventListener('mousemove', mousemove.callback);
2450
+ this.orderUi.start(event, Object.assign(Object.assign({}, this.dragData), this.staticDragData));
2451
+ }
2452
+ doMove(e) {
2453
+ if (!this.staticDragData) {
2454
+ return;
2455
+ }
2456
+ const dragData = (this.dragData = this.getData(this.staticDragData));
2457
+ if (!dragData) {
2458
+ return;
2459
+ }
2460
+ const start = this.staticDragData.startPos;
2461
+ if (Math.abs(start - e.x) > 10) {
2462
+ const x = getLeftRelative(e.x, this.dragData.gridRect.left, this.dragData.scrollOffset);
2463
+ const rgCol = getItemByPosition(this.staticDragData.cols, x);
2464
+ this.orderUi.autoscroll(x, dragData.elRect.width);
2465
+ // prevent position change if out of bounds
2466
+ if (rgCol.itemIndex >= this.staticDragData.cols.count) {
2467
+ return;
2468
+ }
2469
+ this.orderUi.showHandler(rgCol.end + dragData.scrollOffset, dragData.gridRect.width);
2470
+ }
2471
+ }
2472
+ move(e) {
2473
+ dispatch(this.revogrid, MOVE, e);
2474
+ // then do move
2475
+ this.moveFunc(e);
2476
+ }
2477
+ onMouseOut(_) {
2478
+ this.clearOrder();
2479
+ }
2480
+ onMouseUp(e) {
2481
+ // apply new positions
2482
+ if (this.dragData && this.staticDragData) {
2483
+ let relativePos = getLeftRelative(e.x, this.dragData.gridRect.left, this.dragData.scrollOffset);
2484
+ if (relativePos < 0) {
2485
+ relativePos = 0;
2486
+ }
2487
+ const newPosition = getItemByPosition(this.staticDragData.cols, relativePos);
2488
+ const store = this.providers.column.stores[this.dragData.type].store;
2489
+ const newItems = [...store.get('items')];
2490
+ // prevent position change if needed
2491
+ const { defaultPrevented: stopDrag } = dispatch(this.revogrid, BEFORE_DRAG_END, Object.assign(Object.assign({}, this.staticDragData), { startPosition: this.staticDragData.startItem, newPosition, newItem: store.get('source')[newItems[this.staticDragData.startItem.itemIndex]] }));
2492
+ if (!stopDrag) {
2493
+ const prevItems = [...newItems];
2494
+ // todo: if move item out of group remove item from group
2495
+ const toMove = newItems.splice(this.staticDragData.startItem.itemIndex, 1);
2496
+ newItems.splice(newPosition.itemIndex, 0, ...toMove);
2497
+ store.set('items', newItems);
2498
+ this.providers.dimension.updateSizesPositionByNewDataIndexes(this.dragData.type, newItems, prevItems);
2499
+ }
2500
+ dispatch(this.revogrid, DRAG_END, this.dragData);
2501
+ }
2502
+ this.clearOrder();
2503
+ }
2504
+ clearLocalSubscriptions() {
2505
+ forEach(this.localSubscriptions, ({ target, callback }, key) => target.removeEventListener(key, callback));
2506
+ }
2507
+ clearOrder() {
2508
+ this.staticDragData = null;
2509
+ this.dragData = null;
2510
+ this.clearLocalSubscriptions();
2511
+ this.orderUi.stop(this.revogrid);
2512
+ }
2513
+ /**
2514
+ * Clearing subscription
2515
+ */
2516
+ clearSubscriptions() {
2517
+ super.clearSubscriptions();
2518
+ this.clearLocalSubscriptions();
2519
+ }
2520
+ getData({ gridEl, dataEl, data, }) {
2521
+ const gridRect = gridEl.getBoundingClientRect();
2522
+ const elRect = dataEl.getBoundingClientRect();
2523
+ const scrollOffset = elRect.left - gridRect.left;
2524
+ return {
2525
+ elRect,
2526
+ gridRect,
2527
+ type: data.pin || 'rgCol',
2528
+ scrollOffset,
2529
+ };
2530
+ }
2531
+ getDimension(type) {
2532
+ return this.providers.dimension.stores[type].getCurrentState();
2533
+ }
2534
+ }
2535
+ function getLeftRelative(absoluteX, gridPos, offset) {
2536
+ return absoluteX - gridPos - offset;
2537
+ }
2538
+
2539
+ export { AutoSizeColumnPlugin as A, BasePlugin as B, ColumnMovePlugin as C, DimensionStore as D, ExportFilePlugin as E, FILTER_TRIMMED_TYPE as F, GroupingRowPlugin as G, StretchColumn as S, isStretchPlugin as a, ExportCsv as b, columnTypes as c, FILTER_CONFIG_CHANGED_EVENT as d, FILTE_PANEL as e, FilterPlugin as f, filterCoreFunctionsIndexedByType as g, filterTypes as h, isRowType as i, filterNames as j, getLeftRelative as k, SortingPlugin as l, forEach as m, rowTypes as r };
2540
+
2541
+ //# sourceMappingURL=column.drag.plugin-50f49fa9.js.map