@toolbox-web/grid 1.23.4 → 1.24.1

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 (215) hide show
  1. package/README.md +35 -6
  2. package/all.d.ts +2 -2
  3. package/all.d.ts.map +1 -1
  4. package/all.js +2 -2
  5. package/all.js.map +1 -1
  6. package/index.js +1 -1
  7. package/index.js.map +1 -1
  8. package/lib/core/grid.d.ts +30 -0
  9. package/lib/core/grid.d.ts.map +1 -1
  10. package/lib/core/internal/event-delegation.d.ts.map +1 -1
  11. package/lib/core/internal/feature-hook.d.ts +8 -0
  12. package/lib/core/internal/feature-hook.d.ts.map +1 -0
  13. package/lib/core/plugin/base-plugin.d.ts +14 -2
  14. package/lib/core/plugin/base-plugin.d.ts.map +1 -1
  15. package/lib/core/plugin/types.d.ts +3 -1
  16. package/lib/core/plugin/types.d.ts.map +1 -1
  17. package/lib/core/types.d.ts +59 -0
  18. package/lib/core/types.d.ts.map +1 -1
  19. package/lib/features/clipboard.d.ts +8 -0
  20. package/lib/features/clipboard.d.ts.map +1 -0
  21. package/lib/features/clipboard.js +2 -0
  22. package/lib/features/clipboard.js.map +1 -0
  23. package/lib/features/column-virtualization.d.ts +8 -0
  24. package/lib/features/column-virtualization.d.ts.map +1 -0
  25. package/lib/features/column-virtualization.js +2 -0
  26. package/lib/features/column-virtualization.js.map +1 -0
  27. package/lib/features/context-menu.d.ts +8 -0
  28. package/lib/features/context-menu.d.ts.map +1 -0
  29. package/lib/features/context-menu.js +2 -0
  30. package/lib/features/context-menu.js.map +1 -0
  31. package/lib/features/editing.d.ts +8 -0
  32. package/lib/features/editing.d.ts.map +1 -0
  33. package/lib/features/editing.js +2 -0
  34. package/lib/features/editing.js.map +1 -0
  35. package/lib/features/export.d.ts +8 -0
  36. package/lib/features/export.d.ts.map +1 -0
  37. package/lib/features/export.js +2 -0
  38. package/lib/features/export.js.map +1 -0
  39. package/lib/features/filtering.d.ts +8 -0
  40. package/lib/features/filtering.d.ts.map +1 -0
  41. package/lib/features/filtering.js +2 -0
  42. package/lib/features/filtering.js.map +1 -0
  43. package/lib/features/grouping-columns.d.ts +8 -0
  44. package/lib/features/grouping-columns.d.ts.map +1 -0
  45. package/lib/features/grouping-columns.js +2 -0
  46. package/lib/features/grouping-columns.js.map +1 -0
  47. package/lib/features/grouping-rows.d.ts +8 -0
  48. package/lib/features/grouping-rows.d.ts.map +1 -0
  49. package/lib/features/grouping-rows.js +2 -0
  50. package/lib/features/grouping-rows.js.map +1 -0
  51. package/lib/features/magic-string.es-CkyDP9Ir.mjs.map +1 -0
  52. package/lib/features/master-detail.d.ts +8 -0
  53. package/lib/features/master-detail.d.ts.map +1 -0
  54. package/lib/features/master-detail.js +2 -0
  55. package/lib/features/master-detail.js.map +1 -0
  56. package/lib/features/multi-sort.d.ts +10 -0
  57. package/lib/features/multi-sort.d.ts.map +1 -0
  58. package/lib/features/multi-sort.js +2 -0
  59. package/lib/features/multi-sort.js.map +1 -0
  60. package/lib/features/pinned-columns.d.ts +18 -0
  61. package/lib/features/pinned-columns.d.ts.map +1 -0
  62. package/lib/features/pinned-columns.js +2 -0
  63. package/lib/features/pinned-columns.js.map +1 -0
  64. package/lib/features/pinned-rows.d.ts +8 -0
  65. package/lib/features/pinned-rows.d.ts.map +1 -0
  66. package/lib/features/pinned-rows.js +2 -0
  67. package/lib/features/pinned-rows.js.map +1 -0
  68. package/lib/features/pivot.d.ts +8 -0
  69. package/lib/features/pivot.d.ts.map +1 -0
  70. package/lib/features/pivot.js +2 -0
  71. package/lib/features/pivot.js.map +1 -0
  72. package/lib/features/print.d.ts +8 -0
  73. package/lib/features/print.d.ts.map +1 -0
  74. package/lib/features/print.js +2 -0
  75. package/lib/features/print.js.map +1 -0
  76. package/lib/features/registry.d.ts +50 -0
  77. package/lib/features/registry.d.ts.map +1 -0
  78. package/lib/features/registry.js +2 -0
  79. package/lib/features/registry.js.map +1 -0
  80. package/lib/features/registry.spec.js +5 -0
  81. package/lib/features/registry.spec.js.map +1 -0
  82. package/lib/features/reorder-columns.d.ts +10 -0
  83. package/lib/features/reorder-columns.d.ts.map +1 -0
  84. package/lib/features/reorder-columns.js +2 -0
  85. package/lib/features/reorder-columns.js.map +1 -0
  86. package/lib/features/reorder-rows.d.ts +10 -0
  87. package/lib/features/reorder-rows.d.ts.map +1 -0
  88. package/lib/features/reorder-rows.js +2 -0
  89. package/lib/features/reorder-rows.js.map +1 -0
  90. package/lib/features/responsive.d.ts +8 -0
  91. package/lib/features/responsive.d.ts.map +1 -0
  92. package/lib/features/responsive.js +2 -0
  93. package/lib/features/responsive.js.map +1 -0
  94. package/lib/features/selection.d.ts +8 -0
  95. package/lib/features/selection.d.ts.map +1 -0
  96. package/lib/features/selection.js +2 -0
  97. package/lib/features/selection.js.map +1 -0
  98. package/lib/features/server-side.d.ts +8 -0
  99. package/lib/features/server-side.d.ts.map +1 -0
  100. package/lib/features/server-side.js +2 -0
  101. package/lib/features/server-side.js.map +1 -0
  102. package/lib/features/tree.d.ts +8 -0
  103. package/lib/features/tree.d.ts.map +1 -0
  104. package/lib/features/tree.js +2 -0
  105. package/lib/features/tree.js.map +1 -0
  106. package/lib/features/undo-redo.d.ts +8 -0
  107. package/lib/features/undo-redo.d.ts.map +1 -0
  108. package/lib/features/undo-redo.js +2 -0
  109. package/lib/features/undo-redo.js.map +1 -0
  110. package/lib/features/visibility.d.ts +8 -0
  111. package/lib/features/visibility.d.ts.map +1 -0
  112. package/lib/features/visibility.js +2 -0
  113. package/lib/features/visibility.js.map +1 -0
  114. package/lib/plugins/clipboard/index.js +1 -1
  115. package/lib/plugins/clipboard/index.js.map +1 -1
  116. package/lib/plugins/column-virtualization/index.js +1 -1
  117. package/lib/plugins/column-virtualization/index.js.map +1 -1
  118. package/lib/plugins/context-menu/index.js +1 -1
  119. package/lib/plugins/context-menu/index.js.map +1 -1
  120. package/lib/plugins/editing/index.js +1 -1
  121. package/lib/plugins/editing/index.js.map +1 -1
  122. package/lib/plugins/export/index.js +1 -1
  123. package/lib/plugins/export/index.js.map +1 -1
  124. package/lib/plugins/filtering/index.js +1 -1
  125. package/lib/plugins/filtering/index.js.map +1 -1
  126. package/lib/plugins/filtering/types.d.ts +428 -27
  127. package/lib/plugins/filtering/types.d.ts.map +1 -1
  128. package/lib/plugins/grouping-columns/index.d.ts +1 -1
  129. package/lib/plugins/grouping-columns/index.js +1 -1
  130. package/lib/plugins/grouping-columns/index.js.map +1 -1
  131. package/lib/plugins/grouping-rows/index.d.ts +2 -2
  132. package/lib/plugins/grouping-rows/index.d.ts.map +1 -1
  133. package/lib/plugins/grouping-rows/index.js +2 -2
  134. package/lib/plugins/grouping-rows/index.js.map +1 -1
  135. package/lib/plugins/master-detail/MasterDetailPlugin.d.ts +2 -2
  136. package/lib/plugins/master-detail/index.js +1 -1
  137. package/lib/plugins/master-detail/index.js.map +1 -1
  138. package/lib/plugins/multi-sort/index.js +1 -1
  139. package/lib/plugins/multi-sort/index.js.map +1 -1
  140. package/lib/plugins/pinned-columns/index.js +1 -1
  141. package/lib/plugins/pinned-columns/index.js.map +1 -1
  142. package/lib/plugins/pinned-columns/types.d.ts +3 -3
  143. package/lib/plugins/pinned-rows/index.js +1 -1
  144. package/lib/plugins/pinned-rows/index.js.map +1 -1
  145. package/lib/plugins/pivot/index.js +1 -1
  146. package/lib/plugins/pivot/index.js.map +1 -1
  147. package/lib/plugins/print/index.js +1 -1
  148. package/lib/plugins/print/index.js.map +1 -1
  149. package/lib/plugins/{reorder → reorder-columns}/ReorderPlugin.d.ts +5 -3
  150. package/lib/plugins/reorder-columns/ReorderPlugin.d.ts.map +1 -0
  151. package/lib/plugins/reorder-columns/column-drag.d.ts.map +1 -0
  152. package/lib/plugins/{reorder → reorder-columns}/index.d.ts +2 -2
  153. package/lib/plugins/reorder-columns/index.d.ts.map +1 -0
  154. package/lib/plugins/reorder-columns/index.js +2 -0
  155. package/lib/plugins/reorder-columns/index.js.map +1 -0
  156. package/lib/plugins/{reorder → reorder-columns}/types.d.ts +5 -0
  157. package/lib/plugins/reorder-columns/types.d.ts.map +1 -0
  158. package/lib/plugins/{row-reorder → reorder-rows}/RowReorderPlugin.d.ts +10 -10
  159. package/lib/plugins/reorder-rows/RowReorderPlugin.d.ts.map +1 -0
  160. package/lib/plugins/{row-reorder → reorder-rows}/index.d.ts +2 -2
  161. package/lib/plugins/reorder-rows/index.d.ts.map +1 -0
  162. package/lib/plugins/reorder-rows/index.js +2 -0
  163. package/lib/plugins/reorder-rows/index.js.map +1 -0
  164. package/lib/plugins/{row-reorder → reorder-rows}/types.d.ts +5 -0
  165. package/lib/plugins/reorder-rows/types.d.ts.map +1 -0
  166. package/lib/plugins/responsive/ResponsivePlugin.d.ts +2 -2
  167. package/lib/plugins/responsive/ResponsivePlugin.d.ts.map +1 -1
  168. package/lib/plugins/responsive/index.js +1 -1
  169. package/lib/plugins/responsive/index.js.map +1 -1
  170. package/lib/plugins/selection/index.js +1 -1
  171. package/lib/plugins/selection/index.js.map +1 -1
  172. package/lib/plugins/server-side/ServerSidePlugin.d.ts +2 -0
  173. package/lib/plugins/server-side/ServerSidePlugin.d.ts.map +1 -1
  174. package/lib/plugins/server-side/index.js +1 -1
  175. package/lib/plugins/server-side/index.js.map +1 -1
  176. package/lib/plugins/tree/index.js +1 -1
  177. package/lib/plugins/tree/index.js.map +1 -1
  178. package/lib/plugins/undo-redo/index.js +1 -1
  179. package/lib/plugins/undo-redo/index.js.map +1 -1
  180. package/lib/plugins/visibility/VisibilityPlugin.d.ts +1 -1
  181. package/lib/plugins/visibility/index.js +1 -1
  182. package/lib/plugins/visibility/index.js.map +1 -1
  183. package/package.json +17 -2
  184. package/public.d.ts +9 -2
  185. package/public.d.ts.map +1 -1
  186. package/umd/grid.all.umd.js +1 -1
  187. package/umd/grid.all.umd.js.map +1 -1
  188. package/umd/grid.umd.js +1 -1
  189. package/umd/grid.umd.js.map +1 -1
  190. package/umd/plugins/master-detail.umd.js.map +1 -1
  191. package/umd/plugins/reorder-columns.umd.js +2 -0
  192. package/umd/plugins/reorder-columns.umd.js.map +1 -0
  193. package/umd/plugins/reorder-rows.umd.js +2 -0
  194. package/umd/plugins/reorder-rows.umd.js.map +1 -0
  195. package/umd/plugins/responsive.umd.js +1 -1
  196. package/umd/plugins/responsive.umd.js.map +1 -1
  197. package/umd/plugins/server-side.umd.js +1 -1
  198. package/umd/plugins/server-side.umd.js.map +1 -1
  199. package/umd/plugins/visibility.umd.js.map +1 -1
  200. package/lib/plugins/reorder/ReorderPlugin.d.ts.map +0 -1
  201. package/lib/plugins/reorder/column-drag.d.ts.map +0 -1
  202. package/lib/plugins/reorder/index.d.ts.map +0 -1
  203. package/lib/plugins/reorder/index.js +0 -2
  204. package/lib/plugins/reorder/index.js.map +0 -1
  205. package/lib/plugins/reorder/types.d.ts.map +0 -1
  206. package/lib/plugins/row-reorder/RowReorderPlugin.d.ts.map +0 -1
  207. package/lib/plugins/row-reorder/index.d.ts.map +0 -1
  208. package/lib/plugins/row-reorder/index.js +0 -2
  209. package/lib/plugins/row-reorder/index.js.map +0 -1
  210. package/lib/plugins/row-reorder/types.d.ts.map +0 -1
  211. package/umd/plugins/reorder.umd.js +0 -2
  212. package/umd/plugins/reorder.umd.js.map +0 -1
  213. package/umd/plugins/row-reorder.umd.js +0 -2
  214. package/umd/plugins/row-reorder.umd.js.map +0 -1
  215. /package/lib/plugins/{reorder → reorder-columns}/column-drag.d.ts +0 -0
@@ -1,2 +1,2 @@
1
- document.createElement("template").innerHTML='<div class="cell" role="gridcell" part="cell"></div>';document.createElement("template").innerHTML='<div class="data-grid-row" role="row" part="row"></div>';const t='<svg viewBox="0 0 16 16" width="12" height="12"><path fill="currentColor" d="M6 10.5a.5.5 0 0 1 .5-.5h3a.5.5 0 0 1 0 1h-3a.5.5 0 0 1-.5-.5zm-2-3a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5zm-2-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5z"/></svg>',e={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:t,filterActive:t,print:"🖨️"};class n{static dependencies;static manifest;version="undefined"!=typeof __GRID_VERSION__?__GRID_VERSION__:"dev";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#t;get defaultConfig(){return{}}constructor(t={}){this.userConfig=t}attach(t){this.#t?.abort(),this.#t=new AbortController,this.grid=t,this.config={...this.defaultConfig,...this.userConfig}}detach(){this.#t?.abort(),this.#t=void 0}getPlugin(t){return this.grid?.getPlugin(t)}emit(t,e){this.grid?.dispatchEvent?.(new CustomEvent(t,{detail:e,bubbles:!0}))}emitCancelable(t,e){const n=new CustomEvent(t,{detail:e,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(n),n.defaultPrevented}on(t,e){this.grid?._pluginManager?.subscribe(this,t,e)}off(t){this.grid?._pluginManager?.unsubscribe(this,t)}emitPluginEvent(t,e){this.grid?._pluginManager?.emitPluginEvent(t,e)}requestRender(){this.grid?.requestRender?.()}requestColumnsRender(){this.grid?.requestColumnsRender?.()}requestRenderWithFocus(){this.grid?.requestRenderWithFocus?.()}requestAfterRender(){this.grid?.requestAfterRender?.()}get rows(){return this.grid?.rows??[]}get sourceRows(){return this.grid?.sourceRows??[]}get columns(){return this.grid?.columns??[]}get visibleColumns(){return this.grid?._visibleColumns??[]}get gridElement(){return this.grid}get disconnectSignal(){return this.#t?.signal??this.grid?.disconnectSignal}get gridIcons(){const t=this.grid?.gridConfig?.icons??{};return{...e,...t}}get isAnimationEnabled(){const t=this.grid?.effectiveConfig?.animation?.mode??"reduced-motion";if(!1===t||"off"===t)return!1;if(!0===t||"on"===t)return!0;const e=this.gridElement;if(e){return"0"!==getComputedStyle(e).getPropertyValue("--tbw-animation-enabled").trim()}return!0}get animationDuration(){const t=this.gridElement;if(t){const e=getComputedStyle(t).getPropertyValue("--tbw-animation-duration").trim(),n=parseInt(e,10);if(!isNaN(n))return n}return 200}resolveIcon(t,e){return void 0!==e?e:this.gridIcons[t]}setIcon(t,e){"string"==typeof e?t.innerHTML=e:e instanceof HTMLElement&&(t.innerHTML="",t.appendChild(e.cloneNode(!0)))}warn(t){console.warn(`[tbw-grid:${this.name}] ${t}`)}}function o(t,e,n){const o=[...t.undoStack,e];for(;o.length>n;)o.shift();return{undoStack:o,redoStack:[]}}function i(t){if(0===t.undoStack.length)return{newState:t,action:null};const e=[...t.undoStack],n=e.pop();return n?{newState:{undoStack:e,redoStack:[...t.redoStack,n]},action:n}:{newState:t,action:null}}function r(t){if(0===t.redoStack.length)return{newState:t,action:null};const e=[...t.redoStack],n=e.pop();return n?{newState:{undoStack:[...t.undoStack,n],redoStack:e},action:n}:{newState:t,action:null}}class a extends n{static dependencies=[{name:"editing",required:!0,reason:"UndoRedoPlugin tracks cell edit history"}];name="undoRedo";get defaultConfig(){return{maxHistorySize:100}}undoStack=[];redoStack=[];#e=!1;#n=null;#o(t,e){const n=this.rows[t.rowIndex];if(n){try{const o=this.grid.getRowId(n);if(o)return void this.grid.updateRow(o,{[t.field]:e})}catch{}n[t.field]=e}}#i(t){const e=this.grid,n=e._visibleColumns?.findIndex(e=>e.field===t.field)??-1;if(n<0)return;e._focusRow=t.rowIndex,e._focusCol=n;const o=e.findRenderedRowElement?.(t.rowIndex);if(!o)return;const i=o.querySelector(`.cell[data-col="${n}"]`);if(i?.classList.contains("editing")){const t=i.querySelector('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])');t?.focus({preventScroll:!0})}}#r(t,e){if(this.#e=!0,"compound"===t.type){const n="undo"===e?[...t.actions].reverse():t.actions;for(const t of n)this.#o(t,"undo"===e?t.oldValue:t.newValue)}else this.#o(t,"undo"===e?t.oldValue:t.newValue);this.#e=!1}#a(t){const e="compound"===t.type?t.actions[t.actions.length-1]:t;e&&this.#i(e)}attach(t){super.attach(t),this.on("cell-edit-committed",t=>{this.#e||this.recordEdit(t.rowIndex,t.field,t.oldValue,t.newValue)})}detach(){this.undoStack=[],this.redoStack=[],this.#n=null}onKeyDown(t){const e=(t.ctrlKey||t.metaKey)&&"z"===t.key&&!t.shiftKey,n=(t.ctrlKey||t.metaKey)&&("y"===t.key||"z"===t.key&&t.shiftKey);if(e){t.preventDefault();const e=i({undoStack:this.undoStack,redoStack:this.redoStack});return e.action&&(this.#r(e.action,"undo"),this.undoStack=e.newState.undoStack,this.redoStack=e.newState.redoStack,this.emit("undo",{action:e.action,type:"undo"}),this.#a(e.action),this.requestRenderWithFocus()),!0}if(n){t.preventDefault();const e=r({undoStack:this.undoStack,redoStack:this.redoStack});return e.action&&(this.#r(e.action,"redo"),this.undoStack=e.newState.undoStack,this.redoStack=e.newState.redoStack,this.emit("redo",{action:e.action,type:"redo"}),this.#a(e.action),this.requestRenderWithFocus()),!0}return!1}recordEdit(t,e,n,i){const r=function(t,e,n,o){return{type:"cell-edit",rowIndex:t,field:e,oldValue:n,newValue:o,timestamp:Date.now()}}(t,e,n,i);if(this.#n)return void this.#n.push(r);const a=o({undoStack:this.undoStack,redoStack:this.redoStack},r,this.config.maxHistorySize??100);this.undoStack=a.undoStack,this.redoStack=a.redoStack}beginTransaction(){if(this.#n)throw new Error("UndoRedoPlugin: Transaction already in progress. Call endTransaction() first.");this.#n=[]}endTransaction(){const t=this.#n;if(!t)throw new Error("UndoRedoPlugin: No transaction in progress. Call beginTransaction() first.");if(this.#n=null,0===t.length)return;const e=1===t.length?t[0]:{type:"compound",actions:t,timestamp:Date.now()};const n=o({undoStack:this.undoStack,redoStack:this.redoStack},e,this.config.maxHistorySize??100);this.undoStack=n.undoStack,this.redoStack=n.redoStack}undo(){const t=i({undoStack:this.undoStack,redoStack:this.redoStack});return t.action&&(this.#r(t.action,"undo"),this.undoStack=t.newState.undoStack,this.redoStack=t.newState.redoStack,this.#a(t.action),this.requestRenderWithFocus()),t.action}redo(){const t=r({undoStack:this.undoStack,redoStack:this.redoStack});return t.action&&(this.#r(t.action,"redo"),this.undoStack=t.newState.undoStack,this.redoStack=t.newState.redoStack,this.#a(t.action),this.requestRenderWithFocus()),t.action}canUndo(){return{undoStack:this.undoStack,redoStack:this.redoStack}.undoStack.length>0}canRedo(){return{undoStack:this.undoStack,redoStack:this.redoStack}.redoStack.length>0}clearHistory(){const t={undoStack:[],redoStack:[]};this.undoStack=t.undoStack,this.redoStack=t.redoStack,this.#n=null}getUndoStack(){return[...this.undoStack]}getRedoStack(){return[...this.redoStack]}}export{a as UndoRedoPlugin};
1
+ document.createElement("template").innerHTML='<div class="cell" role="gridcell" part="cell"></div>';document.createElement("template").innerHTML='<div class="data-grid-row" role="row" part="row"></div>';const t='<svg viewBox="0 0 16 16" width="12" height="12"><path fill="currentColor" d="M6 10.5a.5.5 0 0 1 .5-.5h3a.5.5 0 0 1 0 1h-3a.5.5 0 0 1-.5-.5zm-2-3a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5zm-2-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5z"/></svg>',e={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:t,filterActive:t,print:"🖨️"};class n{static dependencies;static manifest;aliases;version="undefined"!=typeof __GRID_VERSION__?__GRID_VERSION__:"dev";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#t;get defaultConfig(){return{}}constructor(t={}){this.userConfig=t}attach(t){this.#t?.abort(),this.#t=new AbortController,this.grid=t,this.config={...this.defaultConfig,...this.userConfig}}detach(){this.#t?.abort(),this.#t=void 0}getPlugin(t){return this.grid?.getPlugin(t)}emit(t,e){this.grid?.dispatchEvent?.(new CustomEvent(t,{detail:e,bubbles:!0}))}emitCancelable(t,e){const n=new CustomEvent(t,{detail:e,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(n),n.defaultPrevented}on(t,e){this.grid?._pluginManager?.subscribe(this,t,e)}off(t){this.grid?._pluginManager?.unsubscribe(this,t)}emitPluginEvent(t,e){this.grid?._pluginManager?.emitPluginEvent(t,e)}requestRender(){this.grid?.requestRender?.()}requestColumnsRender(){this.grid?.requestColumnsRender?.()}requestRenderWithFocus(){this.grid?.requestRenderWithFocus?.()}requestAfterRender(){this.grid?.requestAfterRender?.()}requestVirtualRefresh(){this.grid?.requestVirtualRefresh?.()}get rows(){return this.grid?.rows??[]}get sourceRows(){return this.grid?.sourceRows??[]}get columns(){return this.grid?.columns??[]}get visibleColumns(){return this.grid?._visibleColumns??[]}get gridElement(){return this.grid}get disconnectSignal(){return this.#t?.signal??this.grid?.disconnectSignal}get gridIcons(){const t=this.grid?.gridConfig?.icons??{};return{...e,...t}}get isAnimationEnabled(){const t=this.grid?.effectiveConfig?.animation?.mode??"reduced-motion";if(!1===t||"off"===t)return!1;if(!0===t||"on"===t)return!0;const e=this.gridElement;if(e){return"0"!==getComputedStyle(e).getPropertyValue("--tbw-animation-enabled").trim()}return!0}get animationDuration(){const t=this.gridElement;if(t){const e=getComputedStyle(t).getPropertyValue("--tbw-animation-duration").trim(),n=parseInt(e,10);if(!isNaN(n))return n}return 200}resolveIcon(t,e){return void 0!==e?e:this.gridIcons[t]}setIcon(t,e){"string"==typeof e?t.innerHTML=e:e instanceof HTMLElement&&(t.innerHTML="",t.appendChild(e.cloneNode(!0)))}warn(t){console.warn(`[tbw-grid:${this.name}] ${t}`)}}function o(t,e,n){const o=[...t.undoStack,e];for(;o.length>n;)o.shift();return{undoStack:o,redoStack:[]}}function i(t){if(0===t.undoStack.length)return{newState:t,action:null};const e=[...t.undoStack],n=e.pop();return n?{newState:{undoStack:e,redoStack:[...t.redoStack,n]},action:n}:{newState:t,action:null}}function r(t){if(0===t.redoStack.length)return{newState:t,action:null};const e=[...t.redoStack],n=e.pop();return n?{newState:{undoStack:[...t.undoStack,n],redoStack:e},action:n}:{newState:t,action:null}}class a extends n{static dependencies=[{name:"editing",required:!0,reason:"UndoRedoPlugin tracks cell edit history"}];name="undoRedo";get defaultConfig(){return{maxHistorySize:100}}undoStack=[];redoStack=[];#e=!1;#n=null;#o(t,e){const n=this.rows[t.rowIndex];if(n){try{const o=this.grid.getRowId(n);if(o)return void this.grid.updateRow(o,{[t.field]:e})}catch{}n[t.field]=e}}#i(t){const e=this.grid,n=e._visibleColumns?.findIndex(e=>e.field===t.field)??-1;if(n<0)return;e._focusRow=t.rowIndex,e._focusCol=n;const o=e.findRenderedRowElement?.(t.rowIndex);if(!o)return;const i=o.querySelector(`.cell[data-col="${n}"]`);if(i?.classList.contains("editing")){const t=i.querySelector('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])');t?.focus({preventScroll:!0})}}#r(t,e){if(this.#e=!0,"compound"===t.type){const n="undo"===e?[...t.actions].reverse():t.actions;for(const t of n)this.#o(t,"undo"===e?t.oldValue:t.newValue)}else this.#o(t,"undo"===e?t.oldValue:t.newValue);this.#e=!1}#a(t){const e="compound"===t.type?t.actions[t.actions.length-1]:t;e&&this.#i(e)}attach(t){super.attach(t),this.on("cell-edit-committed",t=>{this.#e||this.recordEdit(t.rowIndex,t.field,t.oldValue,t.newValue)})}detach(){this.undoStack=[],this.redoStack=[],this.#n=null}onKeyDown(t){const e=(t.ctrlKey||t.metaKey)&&"z"===t.key&&!t.shiftKey,n=(t.ctrlKey||t.metaKey)&&("y"===t.key||"z"===t.key&&t.shiftKey);if(e){t.preventDefault();const e=i({undoStack:this.undoStack,redoStack:this.redoStack});return e.action&&(this.#r(e.action,"undo"),this.undoStack=e.newState.undoStack,this.redoStack=e.newState.redoStack,this.emit("undo",{action:e.action,type:"undo"}),this.#a(e.action),this.requestRenderWithFocus()),!0}if(n){t.preventDefault();const e=r({undoStack:this.undoStack,redoStack:this.redoStack});return e.action&&(this.#r(e.action,"redo"),this.undoStack=e.newState.undoStack,this.redoStack=e.newState.redoStack,this.emit("redo",{action:e.action,type:"redo"}),this.#a(e.action),this.requestRenderWithFocus()),!0}return!1}recordEdit(t,e,n,i){const r=function(t,e,n,o){return{type:"cell-edit",rowIndex:t,field:e,oldValue:n,newValue:o,timestamp:Date.now()}}(t,e,n,i);if(this.#n)return void this.#n.push(r);const a=o({undoStack:this.undoStack,redoStack:this.redoStack},r,this.config.maxHistorySize??100);this.undoStack=a.undoStack,this.redoStack=a.redoStack}beginTransaction(){if(this.#n)throw new Error("UndoRedoPlugin: Transaction already in progress. Call endTransaction() first.");this.#n=[]}endTransaction(){const t=this.#n;if(!t)throw new Error("UndoRedoPlugin: No transaction in progress. Call beginTransaction() first.");if(this.#n=null,0===t.length)return;const e=1===t.length?t[0]:{type:"compound",actions:t,timestamp:Date.now()};const n=o({undoStack:this.undoStack,redoStack:this.redoStack},e,this.config.maxHistorySize??100);this.undoStack=n.undoStack,this.redoStack=n.redoStack}undo(){const t=i({undoStack:this.undoStack,redoStack:this.redoStack});return t.action&&(this.#r(t.action,"undo"),this.undoStack=t.newState.undoStack,this.redoStack=t.newState.redoStack,this.#a(t.action),this.requestRenderWithFocus()),t.action}redo(){const t=r({undoStack:this.undoStack,redoStack:this.redoStack});return t.action&&(this.#r(t.action,"redo"),this.undoStack=t.newState.undoStack,this.redoStack=t.newState.redoStack,this.#a(t.action),this.requestRenderWithFocus()),t.action}canUndo(){return{undoStack:this.undoStack,redoStack:this.redoStack}.undoStack.length>0}canRedo(){return{undoStack:this.undoStack,redoStack:this.redoStack}.redoStack.length>0}clearHistory(){const t={undoStack:[],redoStack:[]};this.undoStack=t.undoStack,this.redoStack=t.redoStack,this.#n=null}getUndoStack(){return[...this.undoStack]}getRedoStack(){return[...this.redoStack]}}export{a as UndoRedoPlugin};
2
2
  //# sourceMappingURL=index.js.map