@toolbox-web/grid 1.28.1 → 1.29.0

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 (151) hide show
  1. package/all.js +2 -2
  2. package/all.js.map +1 -1
  3. package/custom-elements.json +43 -1
  4. package/index.js +1 -1
  5. package/index.js.map +1 -1
  6. package/lib/core/constants.d.ts +1 -7
  7. package/lib/core/grid.d.ts +40 -3
  8. package/lib/core/internal/render-scheduler.d.ts +3 -1
  9. package/lib/core/plugin/base-plugin.d.ts +1 -1
  10. package/lib/core/plugin/plugin-manager.d.ts +2 -0
  11. package/lib/core/types.d.ts +59 -0
  12. package/lib/features/clipboard.d.ts +2 -0
  13. package/lib/features/clipboard.js.map +1 -1
  14. package/lib/features/column-virtualization.d.ts +2 -0
  15. package/lib/features/column-virtualization.js.map +1 -1
  16. package/lib/features/context-menu.d.ts +2 -0
  17. package/lib/features/context-menu.js.map +1 -1
  18. package/lib/features/editing.d.ts +2 -0
  19. package/lib/features/editing.js.map +1 -1
  20. package/lib/features/export.d.ts +2 -0
  21. package/lib/features/export.js.map +1 -1
  22. package/lib/features/filtering.d.ts +2 -0
  23. package/lib/features/filtering.js.map +1 -1
  24. package/lib/features/grouping-columns.d.ts +2 -0
  25. package/lib/features/grouping-columns.js.map +1 -1
  26. package/lib/features/grouping-rows.d.ts +2 -0
  27. package/lib/features/grouping-rows.js.map +1 -1
  28. package/lib/features/master-detail.d.ts +2 -0
  29. package/lib/features/master-detail.js.map +1 -1
  30. package/lib/features/multi-sort.d.ts +2 -0
  31. package/lib/features/multi-sort.js.map +1 -1
  32. package/lib/features/pinned-columns.d.ts +2 -1
  33. package/lib/features/pinned-columns.js.map +1 -1
  34. package/lib/features/pinned-rows.d.ts +2 -0
  35. package/lib/features/pinned-rows.js.map +1 -1
  36. package/lib/features/pivot.d.ts +2 -0
  37. package/lib/features/pivot.js.map +1 -1
  38. package/lib/features/print.d.ts +2 -0
  39. package/lib/features/print.js.map +1 -1
  40. package/lib/features/reorder-columns.d.ts +2 -0
  41. package/lib/features/reorder-columns.js.map +1 -1
  42. package/lib/features/reorder-rows.d.ts +2 -0
  43. package/lib/features/reorder-rows.js.map +1 -1
  44. package/lib/features/responsive.d.ts +2 -0
  45. package/lib/features/responsive.js.map +1 -1
  46. package/lib/features/selection.d.ts +2 -0
  47. package/lib/features/selection.js.map +1 -1
  48. package/lib/features/server-side.d.ts +2 -0
  49. package/lib/features/server-side.js.map +1 -1
  50. package/lib/features/tooltip.d.ts +2 -0
  51. package/lib/features/tooltip.js.map +1 -1
  52. package/lib/features/tree.d.ts +2 -0
  53. package/lib/features/tree.js.map +1 -1
  54. package/lib/features/undo-redo.d.ts +2 -0
  55. package/lib/features/undo-redo.js.map +1 -1
  56. package/lib/features/visibility.d.ts +2 -0
  57. package/lib/features/visibility.js.map +1 -1
  58. package/lib/plugins/clipboard/ClipboardPlugin.d.ts +0 -21
  59. package/lib/plugins/clipboard/index.js.map +1 -1
  60. package/lib/plugins/column-virtualization/ColumnVirtualizationPlugin.d.ts +0 -16
  61. package/lib/plugins/column-virtualization/index.js.map +1 -1
  62. package/lib/plugins/context-menu/index.js.map +1 -1
  63. package/lib/plugins/editing/index.js +1 -1
  64. package/lib/plugins/editing/index.js.map +1 -1
  65. package/lib/plugins/export/ExportPlugin.d.ts +0 -18
  66. package/lib/plugins/export/index.js.map +1 -1
  67. package/lib/plugins/filtering/FilteringPlugin.d.ts +0 -21
  68. package/lib/plugins/filtering/filter-model.d.ts +8 -1
  69. package/lib/plugins/filtering/index.js +1 -1
  70. package/lib/plugins/filtering/index.js.map +1 -1
  71. package/lib/plugins/grouping-columns/GroupingColumnsPlugin.d.ts +0 -16
  72. package/lib/plugins/grouping-columns/grouping-columns.d.ts +23 -3
  73. package/lib/plugins/grouping-columns/index.js +1 -1
  74. package/lib/plugins/grouping-columns/index.js.map +1 -1
  75. package/lib/plugins/grouping-rows/GroupingRowsPlugin.d.ts +0 -23
  76. package/lib/plugins/grouping-rows/index.js +2 -2
  77. package/lib/plugins/grouping-rows/index.js.map +1 -1
  78. package/lib/plugins/master-detail/MasterDetailPlugin.d.ts +0 -22
  79. package/lib/plugins/master-detail/index.js.map +1 -1
  80. package/lib/plugins/multi-sort/MultiSortPlugin.d.ts +0 -18
  81. package/lib/plugins/multi-sort/index.js +1 -1
  82. package/lib/plugins/multi-sort/index.js.map +1 -1
  83. package/lib/plugins/multi-sort/multi-sort.d.ts +7 -0
  84. package/lib/plugins/pinned-columns/index.js +1 -1
  85. package/lib/plugins/pinned-columns/index.js.map +1 -1
  86. package/lib/plugins/pinned-rows/PinnedRowsPlugin.d.ts +0 -11
  87. package/lib/plugins/pinned-rows/index.js.map +1 -1
  88. package/lib/plugins/pivot/PivotPlugin.d.ts +0 -24
  89. package/lib/plugins/pivot/index.js +1 -1
  90. package/lib/plugins/pivot/index.js.map +1 -1
  91. package/lib/plugins/print/PrintPlugin.d.ts +2 -21
  92. package/lib/plugins/print/index.js.map +1 -1
  93. package/lib/plugins/reorder-columns/ReorderPlugin.d.ts +0 -7
  94. package/lib/plugins/reorder-columns/index.js +1 -1
  95. package/lib/plugins/reorder-columns/index.js.map +1 -1
  96. package/lib/plugins/reorder-rows/RowReorderPlugin.d.ts +1 -13
  97. package/lib/plugins/reorder-rows/index.js +1 -1
  98. package/lib/plugins/reorder-rows/index.js.map +1 -1
  99. package/lib/plugins/responsive/index.js +1 -1
  100. package/lib/plugins/responsive/index.js.map +1 -1
  101. package/lib/plugins/selection/index.js +1 -1
  102. package/lib/plugins/selection/index.js.map +1 -1
  103. package/lib/plugins/server-side/ServerSidePlugin.d.ts +0 -16
  104. package/lib/plugins/server-side/index.js.map +1 -1
  105. package/lib/plugins/tooltip/index.js.map +1 -1
  106. package/lib/plugins/tree/TreePlugin.d.ts +0 -22
  107. package/lib/plugins/tree/index.js +1 -1
  108. package/lib/plugins/tree/index.js.map +1 -1
  109. package/lib/plugins/undo-redo/UndoRedoPlugin.d.ts +0 -19
  110. package/lib/plugins/undo-redo/index.js +1 -1
  111. package/lib/plugins/undo-redo/index.js.map +1 -1
  112. package/lib/plugins/visibility/VisibilityPlugin.d.ts +0 -16
  113. package/lib/plugins/visibility/index.js +1 -1
  114. package/lib/plugins/visibility/index.js.map +1 -1
  115. package/package.json +1 -1
  116. package/themes/dg-theme-material.css +5 -0
  117. package/umd/grid.all.umd.js +1 -1
  118. package/umd/grid.all.umd.js.map +1 -1
  119. package/umd/grid.umd.js +1 -1
  120. package/umd/grid.umd.js.map +1 -1
  121. package/umd/plugins/clipboard.umd.js.map +1 -1
  122. package/umd/plugins/column-virtualization.umd.js.map +1 -1
  123. package/umd/plugins/export.umd.js.map +1 -1
  124. package/umd/plugins/filtering.umd.js +1 -1
  125. package/umd/plugins/filtering.umd.js.map +1 -1
  126. package/umd/plugins/grouping-columns.umd.js +1 -1
  127. package/umd/plugins/grouping-columns.umd.js.map +1 -1
  128. package/umd/plugins/grouping-rows.umd.js +1 -1
  129. package/umd/plugins/grouping-rows.umd.js.map +1 -1
  130. package/umd/plugins/master-detail.umd.js.map +1 -1
  131. package/umd/plugins/multi-sort.umd.js +1 -1
  132. package/umd/plugins/multi-sort.umd.js.map +1 -1
  133. package/umd/plugins/pinned-columns.umd.js +1 -1
  134. package/umd/plugins/pinned-columns.umd.js.map +1 -1
  135. package/umd/plugins/pinned-rows.umd.js.map +1 -1
  136. package/umd/plugins/pivot.umd.js +1 -1
  137. package/umd/plugins/pivot.umd.js.map +1 -1
  138. package/umd/plugins/print.umd.js.map +1 -1
  139. package/umd/plugins/reorder-columns.umd.js +1 -1
  140. package/umd/plugins/reorder-columns.umd.js.map +1 -1
  141. package/umd/plugins/reorder-rows.umd.js +1 -1
  142. package/umd/plugins/reorder-rows.umd.js.map +1 -1
  143. package/umd/plugins/selection.umd.js +1 -1
  144. package/umd/plugins/selection.umd.js.map +1 -1
  145. package/umd/plugins/server-side.umd.js.map +1 -1
  146. package/umd/plugins/tree.umd.js +1 -1
  147. package/umd/plugins/tree.umd.js.map +1 -1
  148. package/umd/plugins/undo-redo.umd.js +1 -1
  149. package/umd/plugins/undo-redo.umd.js.map +1 -1
  150. package/umd/plugins/visibility.umd.js +1 -1
  151. package/umd/plugins/visibility.umd.js.map +1 -1
@@ -17,12 +17,6 @@ import { UndoRedoAction, UndoRedoConfig } from './types';
17
17
  * import { UndoRedoPlugin } from '@toolbox-web/grid/plugins/undo-redo';
18
18
  * ```
19
19
  *
20
- * ## Configuration Options
21
- *
22
- * | Option | Type | Default | Description |
23
- * |--------|------|---------|-------------|
24
- * | `maxHistorySize` | `number` | `100` | Maximum actions in history stack |
25
- *
26
20
  * ## Keyboard Shortcuts
27
21
  *
28
22
  * | Shortcut | Action |
@@ -30,19 +24,6 @@ import { UndoRedoAction, UndoRedoConfig } from './types';
30
24
  * | `Ctrl+Z` / `Cmd+Z` | Undo last edit |
31
25
  * | `Ctrl+Y` / `Cmd+Shift+Z` | Redo last undone edit |
32
26
  *
33
- * ## Programmatic API
34
- *
35
- * | Method | Signature | Description |
36
- * |--------|-----------|-------------|
37
- * | `undo` | `() => UndoRedoAction \| null` | Undo the last edit (or compound) |
38
- * | `redo` | `() => UndoRedoAction \| null` | Redo the last undone edit (or compound) |
39
- * | `canUndo` | `() => boolean` | Check if undo is available |
40
- * | `canRedo` | `() => boolean` | Check if redo is available |
41
- * | `clearHistory` | `() => void` | Clear the entire history stack |
42
- * | `recordEdit` | `(rowIndex, field, old, new) => void` | Manually record a cell edit |
43
- * | `beginTransaction` | `() => void` | Start grouping edits into a compound |
44
- * | `endTransaction` | `() => void` | Finalize and push the compound action |
45
- *
46
27
  * @example Basic Usage with EditingPlugin
47
28
  * ```ts
48
29
  * import { queryGrid } from '@toolbox-web/grid';
@@ -1,2 +1,2 @@
1
- function t(t,e){return`[tbw-grid${t?`#${t}`:""}${e?`:${e}`:""}]`}function e(e,n,o,r){return`${t(o,r)} ${e}: ${n}\n\n → More info: ${function(t){return`https://toolboxjs.com/grid/errors#${t.toLowerCase()}`}(e)}`}function n(t,n,o,r){throw new Error(e(t,n,o,r))}const o=/* @__PURE__ */new Set(["script","iframe","object","embed","form","input","button","textarea","select","link","meta","base","style","template","slot","portal","frame","frameset","applet","noscript","noembed","plaintext","xmp","listing"]),r=/^on\w+$/i,i=/* @__PURE__ */new Set(["href","src","action","formaction","data","srcdoc","xlink:href","poster","srcset"]),s=/^\s*(javascript|vbscript|data|blob):/i;function a(t){if(!t||"string"!=typeof t)return"";if(-1===t.indexOf("<"))return t;const e=document.createElement("template");return e.innerHTML=t,function(t){const e=[],n=t.querySelectorAll("*");for(const a of n){const t=a.tagName.toLowerCase();if(o.has(t)){e.push(a);continue}if("svg"===t||"http://www.w3.org/2000/svg"===a.namespaceURI){if(Array.from(a.attributes).some(t=>r.test(t.name)||"href"===t.name||"xlink:href"===t.name)){e.push(a);continue}}const n=[];for(const e of a.attributes){const t=e.name.toLowerCase();r.test(t)?n.push(e.name):(i.has(t)&&s.test(e.value)||"style"===t&&/expression\s*\(|javascript:|behavior\s*:/i.test(e.value))&&n.push(e.name)}n.forEach(t=>a.removeAttribute(t))}e.forEach(t=>t.remove())}(e.content),e.innerHTML}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 c='<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>',d={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:c,filterActive:c,print:"🖨️"};class u{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?._hostElement}get disconnectSignal(){return this.#t?.signal??this.grid?.disconnectSignal}get gridIcons(){const t=this.grid?.gridConfig?.icons??{};return{...d,...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=a(e):e instanceof HTMLElement&&(t.innerHTML="",t.appendChild(e.cloneNode(!0)))}warn(n,o){void 0!==o?console.warn(e(n,o,this.gridElement.id,this.name)):console.warn(`${t(this.gridElement.id,this.name)} ${n}`)}throwDiagnostic(t,n){throw new Error(e(t,n,this.gridElement.id,this.name))}}function l(t,e,n){const o=[...t.undoStack,e];for(;o.length>n;)o.shift();return{undoStack:o,redoStack:[]}}function h(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 f(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 S extends u{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}}#r(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 r=o.querySelector(`.cell[data-col="${n}"]`);if(r?.classList.contains("editing")){const t=r.querySelector('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])');t?.focus({preventScroll:!0})}}#i(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}#s(t){const e="compound"===t.type?t.actions[t.actions.length-1]:t;e&&this.#r(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=h({undoStack:this.undoStack,redoStack:this.redoStack});return e.action&&(this.#i(e.action,"undo"),this.undoStack=e.newState.undoStack,this.redoStack=e.newState.redoStack,this.emit("undo",{action:e.action,type:"undo"}),this.#s(e.action),this.requestRenderWithFocus()),!0}if(n){t.preventDefault();const e=f({undoStack:this.undoStack,redoStack:this.redoStack});return e.action&&(this.#i(e.action,"redo"),this.undoStack=e.newState.undoStack,this.redoStack=e.newState.redoStack,this.emit("redo",{action:e.action,type:"redo"}),this.#s(e.action),this.requestRenderWithFocus()),!0}return!1}recordEdit(t,e,n,o){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,o);if(this.#n)return void this.#n.push(r);const i=l({undoStack:this.undoStack,redoStack:this.redoStack},r,this.config.maxHistorySize??100);this.undoStack=i.undoStack,this.redoStack=i.redoStack}beginTransaction(){this.#n&&n("TBW111","Transaction already in progress. Call endTransaction() first."),this.#n=[]}endTransaction(){const t=this.#n;if(t||n("TBW112","No transaction in progress. Call beginTransaction() first."),this.#n=null,0===t.length)return;const e=1===t.length?t[0]:{type:"compound",actions:t,timestamp:Date.now()};const o=l({undoStack:this.undoStack,redoStack:this.redoStack},e,this.config.maxHistorySize??100);this.undoStack=o.undoStack,this.redoStack=o.redoStack}undo(){const t=h({undoStack:this.undoStack,redoStack:this.redoStack});return t.action&&(this.#i(t.action,"undo"),this.undoStack=t.newState.undoStack,this.redoStack=t.newState.redoStack,this.#s(t.action),this.requestRenderWithFocus()),t.action}redo(){const t=f({undoStack:this.undoStack,redoStack:this.redoStack});return t.action&&(this.#i(t.action,"redo"),this.undoStack=t.newState.undoStack,this.redoStack=t.newState.redoStack,this.#s(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{S as UndoRedoPlugin};
1
+ const t="editing";function e(t,e){return`[tbw-grid${t?`#${t}`:""}${e?`:${e}`:""}]`}function n(t,n,o,r){return`${e(o,r)} ${t}: ${n}\n\n → More info: ${function(t){return`https://toolboxjs.com/grid/errors#${t.toLowerCase()}`}(t)}`}function o(t,e,o,r){throw new Error(n(t,e,o,r))}const r=/* @__PURE__ */new Set(["script","iframe","object","embed","form","input","button","textarea","select","link","meta","base","style","template","slot","portal","frame","frameset","applet","noscript","noembed","plaintext","xmp","listing"]),i=/^on\w+$/i,s=/* @__PURE__ */new Set(["href","src","action","formaction","data","srcdoc","xlink:href","poster","srcset"]),a=/^\s*(javascript|vbscript|data|blob):/i;function c(t){if(!t||"string"!=typeof t)return"";if(-1===t.indexOf("<"))return t;const e=document.createElement("template");return e.innerHTML=t,function(t){const e=[],n=t.querySelectorAll("*");for(const o of n){const t=o.tagName.toLowerCase();if(r.has(t)){e.push(o);continue}if("svg"===t||"http://www.w3.org/2000/svg"===o.namespaceURI){if(Array.from(o.attributes).some(t=>i.test(t.name)||"href"===t.name||"xlink:href"===t.name)){e.push(o);continue}}const n=[];for(const e of o.attributes){const t=e.name.toLowerCase();i.test(t)?n.push(e.name):(s.has(t)&&a.test(e.value)||"style"===t&&/expression\s*\(|javascript:|behavior\s*:/i.test(e.value))&&n.push(e.name)}n.forEach(t=>o.removeAttribute(t))}e.forEach(t=>t.remove())}(e.content),e.innerHTML}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 d='<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>',u={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:d,filterActive:d,print:"🖨️"};class l{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?._hostElement}get disconnectSignal(){return this.#t?.signal??this.grid?.disconnectSignal}get gridIcons(){const t=this.grid?.gridConfig?.icons??{};return{...u,...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=c(e):e instanceof HTMLElement&&(t.innerHTML="",t.appendChild(e.cloneNode(!0)))}warn(t,o){void 0!==o?console.warn(n(t,o,this.gridElement.id,this.name)):console.warn(`${e(this.gridElement.id,this.name)} ${t}`)}throwDiagnostic(t,e){throw new Error(n(t,e,this.gridElement.id,this.name))}}function h(t,e,n){const o=[...t.undoStack,e];for(;o.length>n;)o.shift();return{undoStack:o,redoStack:[]}}function f(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 S(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 g extends l{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}}#r(e){const n=this.grid,o=n._visibleColumns?.findIndex(t=>t.field===e.field)??-1;if(o<0)return;n._focusRow=e.rowIndex,n._focusCol=o;const r=n.findRenderedRowElement?.(e.rowIndex);if(!r)return;const i=r.querySelector(`.cell[data-col="${o}"]`);if(i?.classList.contains(t)){const t=i.querySelector('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])');t?.focus({preventScroll:!0})}}#i(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}#s(t){const e="compound"===t.type?t.actions[t.actions.length-1]:t;e&&this.#r(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=f({undoStack:this.undoStack,redoStack:this.redoStack});return e.action&&(this.#i(e.action,"undo"),this.undoStack=e.newState.undoStack,this.redoStack=e.newState.redoStack,this.emit("undo",{action:e.action,type:"undo"}),this.#s(e.action),this.requestRenderWithFocus()),!0}if(n){t.preventDefault();const e=S({undoStack:this.undoStack,redoStack:this.redoStack});return e.action&&(this.#i(e.action,"redo"),this.undoStack=e.newState.undoStack,this.redoStack=e.newState.redoStack,this.emit("redo",{action:e.action,type:"redo"}),this.#s(e.action),this.requestRenderWithFocus()),!0}return!1}recordEdit(t,e,n,o){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,o);if(this.#n)return void this.#n.push(r);const i=h({undoStack:this.undoStack,redoStack:this.redoStack},r,this.config.maxHistorySize??100);this.undoStack=i.undoStack,this.redoStack=i.redoStack}beginTransaction(){this.#n&&o("TBW111","Transaction already in progress. Call endTransaction() first."),this.#n=[]}endTransaction(){const t=this.#n;if(t||o("TBW112","No transaction in progress. Call beginTransaction() first."),this.#n=null,0===t.length)return;const e=1===t.length?t[0]:{type:"compound",actions:t,timestamp:Date.now()};const n=h({undoStack:this.undoStack,redoStack:this.redoStack},e,this.config.maxHistorySize??100);this.undoStack=n.undoStack,this.redoStack=n.redoStack}undo(){const t=f({undoStack:this.undoStack,redoStack:this.redoStack});return t.action&&(this.#i(t.action,"undo"),this.undoStack=t.newState.undoStack,this.redoStack=t.newState.redoStack,this.#s(t.action),this.requestRenderWithFocus()),t.action}redo(){const t=S({undoStack:this.undoStack,redoStack:this.redoStack});return t.action&&(this.#i(t.action,"redo"),this.undoStack=t.newState.undoStack,this.redoStack=t.newState.redoStack,this.#s(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{g as UndoRedoPlugin};
2
2
  //# sourceMappingURL=index.js.map