@toolbox-web/grid 3.8.1 → 3.8.3
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.
- package/all.js +1 -1
- package/all.js.map +1 -1
- package/index.js +1 -1
- package/index.js.map +1 -1
- package/lib/core/defaults.d.ts +1 -1
- package/lib/core/internal/aria.d.ts +1 -1
- package/lib/core/internal/config-manager.d.ts +0 -4
- package/lib/core/types.d.ts +6 -0
- package/lib/features/registry.js +1 -1
- package/lib/plugins/clipboard/clipboard-plugin.d.ts +2 -3
- package/lib/plugins/clipboard/index.js +1 -1
- package/lib/plugins/clipboard/index.js.map +1 -1
- package/lib/plugins/column-virtualization/index.js +1 -1
- package/lib/plugins/column-virtualization/index.js.map +1 -1
- package/lib/plugins/context-menu/index.js +1 -1
- package/lib/plugins/context-menu/index.js.map +1 -1
- package/lib/plugins/editing/index.js +1 -1
- package/lib/plugins/editing/index.js.map +1 -1
- package/lib/plugins/export/index.js +1 -1
- package/lib/plugins/export/index.js.map +1 -1
- package/lib/plugins/filtering/index.js +1 -1
- package/lib/plugins/filtering/index.js.map +1 -1
- package/lib/plugins/grouping-columns/index.js +1 -1
- package/lib/plugins/grouping-columns/index.js.map +1 -1
- package/lib/plugins/grouping-rows/index.js +1 -1
- package/lib/plugins/grouping-rows/index.js.map +1 -1
- package/lib/plugins/master-detail/index.js +1 -1
- package/lib/plugins/master-detail/index.js.map +1 -1
- package/lib/plugins/multi-sort/index.js +1 -1
- package/lib/plugins/multi-sort/index.js.map +1 -1
- package/lib/plugins/pinned-columns/index.js +1 -1
- package/lib/plugins/pinned-columns/index.js.map +1 -1
- package/lib/plugins/pinned-rows/index.js +1 -1
- package/lib/plugins/pinned-rows/index.js.map +1 -1
- package/lib/plugins/pivot/index.js +1 -1
- package/lib/plugins/pivot/index.js.map +1 -1
- package/lib/plugins/print/index.js +1 -1
- package/lib/plugins/print/index.js.map +1 -1
- package/lib/plugins/reorder-columns/index.js +1 -1
- package/lib/plugins/reorder-columns/index.js.map +1 -1
- package/lib/plugins/responsive/index.js +1 -1
- package/lib/plugins/responsive/index.js.map +1 -1
- package/lib/plugins/row-drag-drop/index.js +1 -1
- package/lib/plugins/row-drag-drop/index.js.map +1 -1
- package/lib/plugins/row-drag-drop/row-drag-drop-plugin.d.ts +1 -0
- package/lib/plugins/row-drag-drop/types.d.ts +3 -2
- package/lib/plugins/selection/index.js +1 -1
- package/lib/plugins/selection/index.js.map +1 -1
- package/lib/plugins/selection/selection-plugin.d.ts +2 -2
- package/lib/plugins/server-side/index.js +1 -1
- package/lib/plugins/server-side/index.js.map +1 -1
- package/lib/plugins/shell/index.js +1 -1
- package/lib/plugins/shell/index.js.map +1 -1
- package/lib/plugins/sticky-rows/index.js +1 -1
- package/lib/plugins/sticky-rows/index.js.map +1 -1
- package/lib/plugins/tooltip/index.js +1 -1
- package/lib/plugins/tooltip/index.js.map +1 -1
- package/lib/plugins/tree/index.js +1 -1
- package/lib/plugins/tree/index.js.map +1 -1
- package/lib/plugins/undo-redo/index.js +1 -1
- package/lib/plugins/undo-redo/index.js.map +1 -1
- package/lib/plugins/visibility/index.js +1 -1
- package/lib/plugins/visibility/index.js.map +1 -1
- package/package.json +1 -1
- package/umd/grid.all.umd.js +1 -1
- package/umd/grid.all.umd.js.map +1 -1
- package/umd/grid.umd.js +1 -1
- package/umd/grid.umd.js.map +1 -1
- package/umd/plugins/clipboard.umd.js +1 -1
- package/umd/plugins/clipboard.umd.js.map +1 -1
- package/umd/plugins/editing.umd.js +1 -1
- package/umd/plugins/editing.umd.js.map +1 -1
- package/umd/plugins/grouping-rows.umd.js +1 -1
- package/umd/plugins/grouping-rows.umd.js.map +1 -1
- package/umd/plugins/row-drag-drop.umd.js +1 -1
- package/umd/plugins/row-drag-drop.umd.js.map +1 -1
- package/umd/plugins/selection.umd.js +1 -1
- package/umd/plugins/selection.umd.js.map +1 -1
- package/umd/plugins/tooltip.umd.js +1 -1
- package/umd/plugins/tooltip.umd.js.map +1 -1
- package/umd/plugins/tree.umd.js +1 -1
- package/umd/plugins/tree.umd.js.map +1 -1
|
@@ -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.1";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.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};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|