@toolbox-web/grid 3.8.3 → 3.9.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 (84) hide show
  1. package/all.d.ts +1 -0
  2. package/all.js +1 -1
  3. package/all.js.map +1 -1
  4. package/index.js +1 -1
  5. package/index.js.map +1 -1
  6. package/lib/core/plugin/base-plugin.d.ts +14 -0
  7. package/lib/core/plugin/plugin-manager.d.ts +5 -1
  8. package/lib/core/plugin/types.d.ts +2 -0
  9. package/lib/features/registry.js +1 -1
  10. package/lib/plugins/clipboard/index.js +1 -1
  11. package/lib/plugins/clipboard/index.js.map +1 -1
  12. package/lib/plugins/column-virtualization/index.js +1 -1
  13. package/lib/plugins/column-virtualization/index.js.map +1 -1
  14. package/lib/plugins/context-menu/index.js +1 -1
  15. package/lib/plugins/context-menu/index.js.map +1 -1
  16. package/lib/plugins/editing/index.js +1 -1
  17. package/lib/plugins/editing/index.js.map +1 -1
  18. package/lib/plugins/export/index.js +1 -1
  19. package/lib/plugins/export/index.js.map +1 -1
  20. package/lib/plugins/filtering/index.js +1 -1
  21. package/lib/plugins/filtering/index.js.map +1 -1
  22. package/lib/plugins/grouping-columns/index.js +1 -1
  23. package/lib/plugins/grouping-columns/index.js.map +1 -1
  24. package/lib/plugins/grouping-rows/grouping-rows-plugin.d.ts +20 -24
  25. package/lib/plugins/grouping-rows/grouping-rows.d.ts +9 -4
  26. package/lib/plugins/grouping-rows/index.d.ts +1 -1
  27. package/lib/plugins/grouping-rows/index.js +1 -1
  28. package/lib/plugins/grouping-rows/index.js.map +1 -1
  29. package/lib/plugins/grouping-rows/types.d.ts +32 -4
  30. package/lib/plugins/hierarchy/hierarchy-plugin.d.ts +79 -0
  31. package/lib/plugins/hierarchy/hierarchy.d.ts +28 -0
  32. package/lib/plugins/hierarchy/index.d.ts +9 -0
  33. package/lib/plugins/hierarchy/index.js +2 -0
  34. package/lib/plugins/hierarchy/index.js.map +1 -0
  35. package/lib/plugins/hierarchy/types.d.ts +92 -0
  36. package/lib/plugins/master-detail/index.js +1 -1
  37. package/lib/plugins/master-detail/index.js.map +1 -1
  38. package/lib/plugins/multi-sort/index.js +1 -1
  39. package/lib/plugins/multi-sort/index.js.map +1 -1
  40. package/lib/plugins/pinned-columns/index.js +1 -1
  41. package/lib/plugins/pinned-columns/index.js.map +1 -1
  42. package/lib/plugins/pinned-rows/index.js +1 -1
  43. package/lib/plugins/pinned-rows/index.js.map +1 -1
  44. package/lib/plugins/pivot/index.js +1 -1
  45. package/lib/plugins/pivot/index.js.map +1 -1
  46. package/lib/plugins/print/index.js +1 -1
  47. package/lib/plugins/print/index.js.map +1 -1
  48. package/lib/plugins/reorder-columns/index.js +1 -1
  49. package/lib/plugins/reorder-columns/index.js.map +1 -1
  50. package/lib/plugins/responsive/index.js +1 -1
  51. package/lib/plugins/responsive/index.js.map +1 -1
  52. package/lib/plugins/row-drag-drop/index.js +1 -1
  53. package/lib/plugins/row-drag-drop/index.js.map +1 -1
  54. package/lib/plugins/selection/index.js +1 -1
  55. package/lib/plugins/selection/index.js.map +1 -1
  56. package/lib/plugins/server-side/index.js +1 -1
  57. package/lib/plugins/server-side/index.js.map +1 -1
  58. package/lib/plugins/shell/index.js +1 -1
  59. package/lib/plugins/shell/index.js.map +1 -1
  60. package/lib/plugins/sticky-rows/index.js +1 -1
  61. package/lib/plugins/sticky-rows/index.js.map +1 -1
  62. package/lib/plugins/tooltip/index.js +1 -1
  63. package/lib/plugins/tooltip/index.js.map +1 -1
  64. package/lib/plugins/tree/index.js +1 -1
  65. package/lib/plugins/tree/index.js.map +1 -1
  66. package/lib/plugins/tree/tree-datasource.d.ts +7 -10
  67. package/lib/plugins/tree/tree-plugin.d.ts +23 -3
  68. package/lib/plugins/undo-redo/index.js +1 -1
  69. package/lib/plugins/undo-redo/index.js.map +1 -1
  70. package/lib/plugins/visibility/index.js +1 -1
  71. package/lib/plugins/visibility/index.js.map +1 -1
  72. package/package.json +1 -1
  73. package/umd/grid.all.umd.js +1 -1
  74. package/umd/grid.all.umd.js.map +1 -1
  75. package/umd/grid.umd.js +1 -1
  76. package/umd/grid.umd.js.map +1 -1
  77. package/umd/plugins/grouping-rows.umd.js +1 -1
  78. package/umd/plugins/grouping-rows.umd.js.map +1 -1
  79. package/umd/plugins/hierarchy.umd.js +2 -0
  80. package/umd/plugins/hierarchy.umd.js.map +1 -0
  81. package/umd/plugins/selection.umd.js +1 -1
  82. package/umd/plugins/selection.umd.js.map +1 -1
  83. package/umd/plugins/tree.umd.js +1 -1
  84. package/umd/plugins/tree.umd.js.map +1 -1
@@ -1,13 +1,10 @@
1
- import { FlattenedTreeRow } from './types';
1
+ import { ViewportMappingResponse } from '../server-side/datasource-types';
2
2
  /**
3
- * Given a flat row index in the viewport, find the index of the
4
- * top-level node (depth 0) that "owns" that row.
3
+ * Translate a range of rendered row indices to the range of root nodes that own them.
5
4
  *
6
- * Walk backwards from the row index until a depth-0 row is found,
7
- * then return its position among all depth-0 rows.
5
+ * @param rootOwners - Index-aligned with the grid's final row list (including rows other
6
+ * contributors inserted, e.g. group headers): the 0-based ordinal of the root node each row
7
+ * belongs to, or `-1` for rows rendered before the first root.
8
+ * @param rootCount - Number of root nodes in the rendered rows.
8
9
  */
9
- export declare function getTopLevelNodeIndex(flattenedRows: FlattenedTreeRow[], flatRowIndex: number): number;
10
- /**
11
- * Count the number of top-level (depth 0) nodes in the flattened rows.
12
- */
13
- export declare function countTopLevelNodes(flattenedRows: FlattenedTreeRow[]): number;
10
+ export declare function mapViewportToRoots(rootOwners: readonly number[], rootCount: number, viewportStart: number, viewportEnd: number): ViewportMappingResponse;
@@ -1,5 +1,6 @@
1
1
  import { GridElement, BaseGridPlugin, CellClickEvent, HeaderClickEvent, PluginManifest, PluginQuery } from '../../core/plugin/base-plugin';
2
2
  import { ColumnConfig } from '../../core/types';
3
+ import { HierarchyContributor, HierarchyNode, HierarchyRowMeta, HierarchySiblingContext, HierarchyPlugin } from '../hierarchy';
3
4
  import { FlattenedTreeRow, TreeConfig, TreeRow } from './types';
4
5
  /**
5
6
  * Tree Data Plugin for tbw-grid
@@ -65,7 +66,7 @@ import { FlattenedTreeRow, TreeConfig, TreeRow } from './types';
65
66
  * @internal Extends BaseGridPlugin
66
67
  * @since 0.1.1
67
68
  */
68
- export declare class TreePlugin extends BaseGridPlugin<TreeConfig> {
69
+ export declare class TreePlugin extends BaseGridPlugin<TreeConfig> implements HierarchyContributor {
69
70
  #private;
70
71
  static readonly manifest: PluginManifest;
71
72
  /**
@@ -73,14 +74,22 @@ export declare class TreePlugin extends BaseGridPlugin<TreeConfig> {
73
74
  * When MultiSort is loaded, Tree defers header click sorting to it and queries the
74
75
  * sort model in processRows. When MultiSort is absent, Tree uses its own sort state.
75
76
  */
76
- static readonly dependencies: {
77
+ static readonly dependencies: ({
77
78
  name: string;
78
79
  required: boolean;
79
80
  reason: string;
80
- }[];
81
+ provide: () => HierarchyPlugin;
82
+ } | {
83
+ name: string;
84
+ required: boolean;
85
+ reason: string;
86
+ provide?: undefined;
87
+ })[];
81
88
  /** @internal */
82
89
  readonly name = "tree";
83
90
  /** @internal */
91
+ readonly hierarchyStage = "structure";
92
+ /** @internal */
84
93
  readonly styles: string;
85
94
  /** @internal */
86
95
  protected get defaultConfig(): Partial<TreeConfig>;
@@ -121,6 +130,17 @@ export declare class TreePlugin extends BaseGridPlugin<TreeConfig> {
121
130
  detect(rows: readonly unknown[]): boolean;
122
131
  /** @internal */
123
132
  processRows(rows: readonly unknown[]): TreeRow[];
133
+ /** @internal Hierarchy contributor hook */
134
+ beginHierarchy(rows: readonly unknown[]): boolean;
135
+ /**
136
+ * Sort one sibling list and attach each expanded node's children, never
137
+ * cloning row objects — `data` on each FlattenedTreeRow stays `===` the
138
+ * user's source row.
139
+ * @internal Hierarchy contributor hook
140
+ */
141
+ processSiblings(nodes: HierarchyNode[], context: HierarchySiblingContext): HierarchyNode[];
142
+ /** @internal Hierarchy contributor hook */
143
+ endHierarchy(rows: readonly unknown[], positionOf: (row: unknown) => HierarchyRowMeta | undefined): boolean;
124
144
  /**
125
145
  * Request lazy children for a node that is being expanded.
126
146
  *
@@ -1,2 +1,2 @@
1
- var 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){return"__proto__"===t||"constructor"===t||"prototype"===t}var r=/* @__PURE__ */new Map;function i(t,e,n){if(null==t||"object"!=typeof t)return!1;const i=function(t){if(-1===t.indexOf("."))return null;let e=r.get(t);return void 0===e&&(e=Object.freeze(t.split(".")),r.set(t,e)),e}(e),s=t;return null===i?!o(e)&&(s[e]=n,!0):Object.prototype.hasOwnProperty.call(s,e)?(s[e]=n,!0):function(t,e,n){if(null==t||"object"!=typeof t)return!1;let r=t;for(let s=0;s<e.length-1;s++){const t=e[s];if(o(t))return!1;const n=r[t];if(null==n||"object"!=typeof n)return!1;r=n}const i=e[e.length-1];return!o(i)&&(r[i]=n,!0)}(s,i,n)}var s="__otorp__|__retteGenifed__|__retteSenifed__|rotcurtsnoc|wodniw|sihTlabolg|labolg|ssecorp|noitcnuF|tropmi|lave|tcelfeR|yxorP|rorrE|stnemugra|tnemucod|noitacol|eikooc|egarotSlacol|egarotSnoisses|BDdexedni|hctef|tseuqeRpttHLMX|tekcoSbeW|rekroW|rekroWderahS|rekroWecivreS|renepo|tnerap|pot|semarf|fles".split("|").map(t=>t.split("").reverse().join("")),a=(new RegExp(`__(proto|defineGetter|defineSetter)|${s.slice(3).join("|")}|this\\b`),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|math".split("|"))),c=/^on\w+$/i,d=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),u=/^\s*(javascript|vbscript|data|blob):/i;function l(t){const e=document.createElement("template");return t&&"string"==typeof t&&(e.innerHTML=t,function(t){const e=[],n=t.querySelectorAll("*");for(const o of n){const t=o.tagName.toLowerCase();if(a.has(t)){e.push(o);continue}if(("svg"===t||"http://www.w3.org/2000/svg"===o.namespaceURI)&&Array.from(o.attributes).some(t=>c.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();c.test(t)?n.push(e.name):"is"!==t?(d.has(t)&&u.test(e.value)||"style"===t&&/expression\s*\(|javascript:|behavior\s*:/i.test(e.value))&&n.push(e.name):n.push(e.name)}n.forEach(t=>o.removeAttribute(t))}e.forEach(t=>t.remove())}(e.content)),e.content}var h={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};var f=class{static dependencies;static manifest;aliases;version="3.8.3";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#t;get defaultConfig(){return{}}constructor(t={}){this.userConfig=t}get resolvedConfig(){return this.#t?this.config:{...this.defaultConfig,...this.userConfig}}mergeConfigsFrom(t){if(0===t.length)return;const e={...this.userConfig},o={};for(const n of Object.keys(e))o[n]=this;for(const r of t){const t=r.userConfig;for(const[i,s]of Object.entries(t)){if(void 0===s)continue;if(!(i in e)){e[i]=s,o[i]=r;continue}if(e[i]===s)continue;const t=o[i]?.constructor.name??this.constructor.name,a=r.constructor.name,c=n("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${i}" supplied by both ${t} and ${a}. Pass the option on a single instance, or remove the duplicate.`,void 0,this.name);throw new Error(c)}}Object.assign(this.userConfig,e)}refreshUserConfigFrom(t){const e=this.userConfig,n={...t.userConfig};for(const o of Object.keys(e))delete e[o];Object.assign(e,n)}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)}broadcast(t,e){this.emitPluginEvent(t,e),this.emit(t,e)}queryBoolean(t,e=null){const n=this.grid?.query?.(t,e);return Array.isArray(n)?n.some(Boolean):!!n}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{...h,...t}}t(t,e){return this.grid?.effectiveConfig?.locale?.[t]??e}get translate(){return(t,e)=>this.t(t,e)}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;return!e||"0"!==getComputedStyle(e).getPropertyValue("--tbw-animation-enabled").trim()}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}setIcon(t,e,n){t.dataset.icon=e.replace(/([A-Z])/g,"-$1").toLowerCase(),"collapse"===e?t.dataset.expanded="":"expand"===e&&delete t.dataset.expanded;const o=this.#e(e,n);var r,i;void 0!==o?"string"==typeof o?(r=t,(i=o)&&"string"==typeof i?-1!==i.indexOf("<")||-1!==i.indexOf("&")?r.replaceChildren(l(i)):r.textContent=i:r.replaceChildren()):o instanceof HTMLElement&&t.replaceChildren(o.cloneNode(!0)):t.innerHTML=""}#e(t,e){return void 0!==e?e:this.grid?.gridConfig?.icons?.[t]}updateSortIndicator(t,e){t.querySelector('[part~="sort-indicator"], .sort-indicator')?.remove();const n=document.createElement("span");n.setAttribute("part","sort-indicator"),n.className="sort-indicator",e?(t.setAttribute("aria-sort","asc"===e?"ascending":"descending"),t.setAttribute("data-sort",e),this.setIcon(n,"asc"===e?"sortAsc":"sortDesc")):(t.setAttribute("aria-sort","none"),t.removeAttribute("data-sort"),this.setIcon(n,"sortNone"));const o=t.querySelector(".tbw-filter-btn")??t.querySelector(".resize-handle");return o?t.insertBefore(n,o):t.appendChild(n),n}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 g(t,e,n){const o=[...t.undoStack,e];for(;o.length>n;)o.shift();return{undoStack:o,redoStack:[]}}function p(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}}var m=class extends f{static dependencies=[{name:"editing",required:!0,reason:"UndoRedoPlugin tracks cell edit history"}];name="undoRedo";get defaultConfig(){return{maxHistorySize:100}}undoStack=[];redoStack=[];#n=!1;#o=null;#r=0;#i(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},"history")}catch{}i(n,t.field,e)}}#s(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}"]`);i?.classList.contains(t)&&i.querySelector('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])')?.focus({preventScroll:!0})}#a(t,e){if(this.#n=!0,"compound"===t.type){const n="undo"===e?[...t.actions].reverse():t.actions;for(const t of n)this.#i(t,"undo"===e?t.oldValue:t.newValue)}else this.#i(t,"undo"===e?t.oldValue:t.newValue);this.#n=!1}#c(t){const e="compound"===t.type?t.actions[t.actions.length-1]:t;e&&this.#s(e)}attach(t){super.attach(t),this.on("cell-edit-committed",t=>{this.#n||this.recordEdit(t.rowIndex,t.field,t.oldValue,t.newValue)})}detach(){this.undoStack=[],this.redoStack=[],this.#o=null,this.#r=0}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&&!n)return!1;const o=e?"undo":"redo";return this.#d(t.target)?(this.#u(t.target,o),!0):(t.preventDefault(),this.#l(o),!0)}#l(t){const e={undoStack:this.undoStack,redoStack:this.redoStack},n="undo"===t?p(e):S(e);n.action&&(this.#a(n.action,t),this.undoStack=n.newState.undoStack,this.redoStack=n.newState.redoStack,this.emit(t,{action:n.action,type:t}),this.#c(n.action),this.requestRenderWithFocus())}#d(t){return t instanceof Element&&!!t.closest('input, textarea, [contenteditable=""], [contenteditable="true"]')}#u(t,e){const n="undo"===e?"historyUndo":"historyRedo";let o=!1;const r=t=>{t.inputType===n&&(o=!0)};t.addEventListener("beforeinput",r,{capture:!0}),queueMicrotask(()=>{t.removeEventListener("beforeinput",r,{capture:!0}),o||this.#l(e)})}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.#o)return void this.#o.push(r);const i=g({undoStack:this.undoStack,redoStack:this.redoStack},r,this.config.maxHistorySize??100);this.undoStack=i.undoStack,this.redoStack=i.redoStack}beginTransaction(){0===this.#r&&(this.#o=[]),this.#r++}endTransaction(){if(0===this.#r&&function(t,e,o,r){throw new Error(n(t,e,o,r))}("TBW112","No transaction in progress. Call beginTransaction() first."),this.#r--,this.#r>0)return;const t=this.#o;if(this.#o=null,!t||0===t.length)return;const e=1===t.length?t[0]:{type:"compound",actions:t,timestamp:Date.now()};const o=g({undoStack:this.undoStack,redoStack:this.redoStack},e,this.config.maxHistorySize??100);this.undoStack=o.undoStack,this.redoStack=o.redoStack}undo(){const t=p({undoStack:this.undoStack,redoStack:this.redoStack});return t.action&&(this.#a(t.action,"undo"),this.undoStack=t.newState.undoStack,this.redoStack=t.newState.redoStack,this.#c(t.action),this.requestRenderWithFocus()),t.action}redo(){const t=S({undoStack:this.undoStack,redoStack:this.redoStack});return t.action&&(this.#a(t.action,"redo"),this.undoStack=t.newState.undoStack,this.redoStack=t.newState.redoStack,this.#c(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.#o=null,this.#r=0}getUndoStack(){return[...this.undoStack]}getRedoStack(){return[...this.redoStack]}};export{m as UndoRedoPlugin};
1
+ var 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){return"__proto__"===t||"constructor"===t||"prototype"===t}var r=/* @__PURE__ */new Map;function i(t,e,n){if(null==t||"object"!=typeof t)return!1;const i=function(t){if(-1===t.indexOf("."))return null;let e=r.get(t);return void 0===e&&(e=Object.freeze(t.split(".")),r.set(t,e)),e}(e),s=t;return null===i?!o(e)&&(s[e]=n,!0):Object.prototype.hasOwnProperty.call(s,e)?(s[e]=n,!0):function(t,e,n){if(null==t||"object"!=typeof t)return!1;let r=t;for(let s=0;s<e.length-1;s++){const t=e[s];if(o(t))return!1;const n=r[t];if(null==n||"object"!=typeof n)return!1;r=n}const i=e[e.length-1];return!o(i)&&(r[i]=n,!0)}(s,i,n)}var s="__otorp__|__retteGenifed__|__retteSenifed__|rotcurtsnoc|wodniw|sihTlabolg|labolg|ssecorp|noitcnuF|tropmi|lave|tcelfeR|yxorP|rorrE|stnemugra|tnemucod|noitacol|eikooc|egarotSlacol|egarotSnoisses|BDdexedni|hctef|tseuqeRpttHLMX|tekcoSbeW|rekroW|rekroWderahS|rekroWecivreS|renepo|tnerap|pot|semarf|fles".split("|").map(t=>t.split("").reverse().join("")),a=(new RegExp(`__(proto|defineGetter|defineSetter)|${s.slice(3).join("|")}|this\\b`),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|math".split("|"))),c=/^on\w+$/i,d=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),u=/^\s*(javascript|vbscript|data|blob):/i;function l(t){const e=document.createElement("template");return t&&"string"==typeof t&&(e.innerHTML=t,function(t){const e=[],n=t.querySelectorAll("*");for(const o of n){const t=o.tagName.toLowerCase();if(a.has(t)){e.push(o);continue}if(("svg"===t||"http://www.w3.org/2000/svg"===o.namespaceURI)&&Array.from(o.attributes).some(t=>c.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();c.test(t)?n.push(e.name):"is"!==t?(d.has(t)&&u.test(e.value)||"style"===t&&/expression\s*\(|javascript:|behavior\s*:/i.test(e.value))&&n.push(e.name):n.push(e.name)}n.forEach(t=>o.removeAttribute(t))}e.forEach(t=>t.remove())}(e.content)),e.content}var h={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};var f=class{static dependencies;static manifest;aliases;version="3.9.0";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#t;get defaultConfig(){return{}}constructor(t={}){this.userConfig=t}get resolvedConfig(){return this.#t?this.config:{...this.defaultConfig,...this.userConfig}}mergeConfigsFrom(t){if(0===t.length)return;const e={...this.userConfig},o={};for(const n of Object.keys(e))o[n]=this;for(const r of t){const t=r.userConfig;for(const[i,s]of Object.entries(t)){if(void 0===s)continue;if(!(i in e)){e[i]=s,o[i]=r;continue}if(e[i]===s)continue;const t=o[i]?.constructor.name??this.constructor.name,a=r.constructor.name,c=n("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${i}" supplied by both ${t} and ${a}. Pass the option on a single instance, or remove the duplicate.`,void 0,this.name);throw new Error(c)}}Object.assign(this.userConfig,e)}refreshUserConfigFrom(t){const e=this.userConfig,n={...t.userConfig};for(const o of Object.keys(e))delete e[o];Object.assign(e,n)}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)}broadcast(t,e){this.emitPluginEvent(t,e),this.emit(t,e)}queryBoolean(t,e=null){const n=this.grid?.query?.(t,e);return Array.isArray(n)?n.some(Boolean):!!n}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{...h,...t}}t(t,e){return this.grid?.effectiveConfig?.locale?.[t]??e}get translate(){return(t,e)=>this.t(t,e)}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;return!e||"0"!==getComputedStyle(e).getPropertyValue("--tbw-animation-enabled").trim()}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}setIcon(t,e,n){t.dataset.icon=e.replace(/([A-Z])/g,"-$1").toLowerCase(),"collapse"===e?t.dataset.expanded="":"expand"===e&&delete t.dataset.expanded;const o=this.#e(e,n);var r,i;void 0!==o?"string"==typeof o?(r=t,(i=o)&&"string"==typeof i?-1!==i.indexOf("<")||-1!==i.indexOf("&")?r.replaceChildren(l(i)):r.textContent=i:r.replaceChildren()):o instanceof HTMLElement&&t.replaceChildren(o.cloneNode(!0)):t.innerHTML=""}#e(t,e){return void 0!==e?e:this.grid?.gridConfig?.icons?.[t]}updateSortIndicator(t,e){t.querySelector('[part~="sort-indicator"], .sort-indicator')?.remove();const n=document.createElement("span");n.setAttribute("part","sort-indicator"),n.className="sort-indicator",e?(t.setAttribute("aria-sort","asc"===e?"ascending":"descending"),t.setAttribute("data-sort",e),this.setIcon(n,"asc"===e?"sortAsc":"sortDesc")):(t.setAttribute("aria-sort","none"),t.removeAttribute("data-sort"),this.setIcon(n,"sortNone"));const o=t.querySelector(".tbw-filter-btn")??t.querySelector(".resize-handle");return o?t.insertBefore(n,o):t.appendChild(n),n}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 g(t,e,n){const o=[...t.undoStack,e];for(;o.length>n;)o.shift();return{undoStack:o,redoStack:[]}}function p(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}}var m=class extends f{static dependencies=[{name:"editing",required:!0,reason:"UndoRedoPlugin tracks cell edit history"}];name="undoRedo";get defaultConfig(){return{maxHistorySize:100}}undoStack=[];redoStack=[];#n=!1;#o=null;#r=0;#i(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},"history")}catch{}i(n,t.field,e)}}#s(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}"]`);i?.classList.contains(t)&&i.querySelector('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])')?.focus({preventScroll:!0})}#a(t,e){if(this.#n=!0,"compound"===t.type){const n="undo"===e?[...t.actions].reverse():t.actions;for(const t of n)this.#i(t,"undo"===e?t.oldValue:t.newValue)}else this.#i(t,"undo"===e?t.oldValue:t.newValue);this.#n=!1}#c(t){const e="compound"===t.type?t.actions[t.actions.length-1]:t;e&&this.#s(e)}attach(t){super.attach(t),this.on("cell-edit-committed",t=>{this.#n||this.recordEdit(t.rowIndex,t.field,t.oldValue,t.newValue)})}detach(){this.undoStack=[],this.redoStack=[],this.#o=null,this.#r=0}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&&!n)return!1;const o=e?"undo":"redo";return this.#d(t.target)?(this.#u(t.target,o),!0):(t.preventDefault(),this.#l(o),!0)}#l(t){const e={undoStack:this.undoStack,redoStack:this.redoStack},n="undo"===t?p(e):S(e);n.action&&(this.#a(n.action,t),this.undoStack=n.newState.undoStack,this.redoStack=n.newState.redoStack,this.emit(t,{action:n.action,type:t}),this.#c(n.action),this.requestRenderWithFocus())}#d(t){return t instanceof Element&&!!t.closest('input, textarea, [contenteditable=""], [contenteditable="true"]')}#u(t,e){const n="undo"===e?"historyUndo":"historyRedo";let o=!1;const r=t=>{t.inputType===n&&(o=!0)};t.addEventListener("beforeinput",r,{capture:!0}),queueMicrotask(()=>{t.removeEventListener("beforeinput",r,{capture:!0}),o||this.#l(e)})}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.#o)return void this.#o.push(r);const i=g({undoStack:this.undoStack,redoStack:this.redoStack},r,this.config.maxHistorySize??100);this.undoStack=i.undoStack,this.redoStack=i.redoStack}beginTransaction(){0===this.#r&&(this.#o=[]),this.#r++}endTransaction(){if(0===this.#r&&function(t,e,o,r){throw new Error(n(t,e,o,r))}("TBW112","No transaction in progress. Call beginTransaction() first."),this.#r--,this.#r>0)return;const t=this.#o;if(this.#o=null,!t||0===t.length)return;const e=1===t.length?t[0]:{type:"compound",actions:t,timestamp:Date.now()};const o=g({undoStack:this.undoStack,redoStack:this.redoStack},e,this.config.maxHistorySize??100);this.undoStack=o.undoStack,this.redoStack=o.redoStack}undo(){const t=p({undoStack:this.undoStack,redoStack:this.redoStack});return t.action&&(this.#a(t.action,"undo"),this.undoStack=t.newState.undoStack,this.redoStack=t.newState.redoStack,this.#c(t.action),this.requestRenderWithFocus()),t.action}redo(){const t=S({undoStack:this.undoStack,redoStack:this.redoStack});return t.action&&(this.#a(t.action,"redo"),this.undoStack=t.newState.undoStack,this.redoStack=t.newState.redoStack,this.#c(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.#o=null,this.#r=0}getUndoStack(){return[...this.undoStack]}getRedoStack(){return[...this.redoStack]}};export{m as UndoRedoPlugin};
2
2
  //# sourceMappingURL=index.js.map