@toolbox-web/grid 3.8.0 → 3.8.2

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 (36) hide show
  1. package/all.js +1 -1
  2. package/all.js.map +1 -1
  3. package/index.js +1 -1
  4. package/index.js.map +1 -1
  5. package/lib/core/types.d.ts +4 -0
  6. package/lib/features/registry.js +1 -1
  7. package/lib/plugins/clipboard/index.js +1 -1
  8. package/lib/plugins/column-virtualization/index.js +1 -1
  9. package/lib/plugins/context-menu/index.js +1 -1
  10. package/lib/plugins/editing/index.js +1 -1
  11. package/lib/plugins/export/index.js +1 -1
  12. package/lib/plugins/filtering/index.js +1 -1
  13. package/lib/plugins/grouping-columns/index.js +1 -1
  14. package/lib/plugins/grouping-rows/index.js +1 -1
  15. package/lib/plugins/master-detail/index.js +1 -1
  16. package/lib/plugins/multi-sort/index.js +1 -1
  17. package/lib/plugins/pinned-columns/index.js +1 -1
  18. package/lib/plugins/pinned-rows/index.js +1 -1
  19. package/lib/plugins/pivot/index.js +1 -1
  20. package/lib/plugins/print/index.js +1 -1
  21. package/lib/plugins/reorder-columns/index.js +1 -1
  22. package/lib/plugins/responsive/index.js +1 -1
  23. package/lib/plugins/row-drag-drop/index.js +1 -1
  24. package/lib/plugins/selection/index.js +1 -1
  25. package/lib/plugins/server-side/index.js +1 -1
  26. package/lib/plugins/shell/index.js +1 -1
  27. package/lib/plugins/sticky-rows/index.js +1 -1
  28. package/lib/plugins/tooltip/index.js +1 -1
  29. package/lib/plugins/tree/index.js +1 -1
  30. package/lib/plugins/undo-redo/index.js +1 -1
  31. package/lib/plugins/visibility/index.js +1 -1
  32. package/package.json +1 -1
  33. package/umd/grid.all.umd.js +1 -1
  34. package/umd/grid.all.umd.js.map +1 -1
  35. package/umd/grid.umd.js +1 -1
  36. package/umd/grid.umd.js.map +1 -1
@@ -2657,6 +2657,10 @@ export interface GridConfig<TRow = any, TField extends string = ColumnFieldKey<T
2657
2657
  * **Variable Row Heights**: When a function is provided, the grid enables variable height
2658
2658
  * virtualization. Heights are measured on first render and cached by row identity.
2659
2659
  *
2660
+ * **Numeric form**: the value is written to the `--tbw-row-height` custom property on the host
2661
+ * element (overriding the theme) and is never replaced by a measured height, even when a plugin
2662
+ * enables variable-height virtualization.
2663
+ *
2660
2664
  * @default Auto-measured from first row (respects --tbw-row-height CSS variable)
2661
2665
  *
2662
2666
  * @example
@@ -1,2 +1,2 @@
1
- import{setFeatureResolver as o}from"@toolbox-web/grid";function e(o,e,t,n){console.warn(function(o,e,t,n){return`${function(o,e){return`[tbw-grid${o?`#${o}`:""}${e?`:${e}`:""}]`}(t,n)} ${o}: ${e}\n\n → More info: ${function(o){return`https://toolboxjs.com/grid/errors#${o.toLowerCase()}`}(o)}`}(o,e,t,n))}var t="3.8.0",n=Symbol.for(`@toolbox-web/grid:feature-registry@${t}/v1`),r=Symbol.for(`@toolbox-web/grid:feature-registry-warned@${t}/v1`);function i(o,e){let t=Reflect.get(globalThis,o);return void 0===t&&(t=e(),Reflect.set(globalThis,o,t)),t}var s=i(n,()=>/* @__PURE__ */new Map),c=i(r,()=>/* @__PURE__ */new Set),f=()=>"undefined"!=typeof window&&("localhost"===window.location?.hostname||"127.0.0.1"===window.location?.hostname);function a(o,t,n){f()&&s.has(o)&&!n?.override&&e("TBW030",`Feature "${o}" was re-registered. Previous registration overwritten.`),s.set(o,{factory:t,name:o})}function u(o){return s.has(o)}function d(o){return s.get(o)?.factory}function l(){return Array.from(s.keys())}var w={undoRedo:["editing"],clipboard:["selection"]};function g(o,t){const n=s.get(o);if(n)return n.factory(t);if(f()&&!c.has(o)){c.add(o);const t=o.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase();e("TBW031",`Feature "${o}" is configured but not registered.\nAdd this import to enable it:\n\n import '@toolbox-web/grid/features/${t}';\n`)}}function b(o){const t=[];for(const[e,r]of Object.entries(o))void 0!==r&&!1!==r&&t.push(e);!function(o){const t=new Set(o);for(const n of o){const o=w[n];if(o)for(const r of o)t.has(r)||f()&&e("TBW032",`Feature "${n}" requires "${r}" to be enabled. Add "${r}" to your features configuration.`)}}(t);const n=[];for(const e of t){const t=g(e,o[e]);t&&n.push(t)}return function(o){if(o.length<2)return o;const e=/* @__PURE__ */new Map;for(const s of o)e.set(s.name,s);const t=[],n=/* @__PURE__ */new Set,r=/* @__PURE__ */new Set,i=o=>{if(n.has(o)||r.has(o))return;r.add(o);const s=o.constructor.dependencies??[];for(const t of s){const o=e.get(t.name);o&&i(o)}r.delete(o),n.add(o),t.push(o)};for(const s of o)i(s);return t}(n)}function $(){s.clear(),c.clear()}o(b);export{$ as clearFeatureRegistry,g as createPluginFromFeature,b as createPluginsFromFeatures,d as getFeatureFactory,l as getRegisteredFeatures,u as isFeatureRegistered,a as registerFeature};
1
+ import{setFeatureResolver as o}from"@toolbox-web/grid";function e(o,e,t,n){console.warn(function(o,e,t,n){return`${function(o,e){return`[tbw-grid${o?`#${o}`:""}${e?`:${e}`:""}]`}(t,n)} ${o}: ${e}\n\n → More info: ${function(o){return`https://toolboxjs.com/grid/errors#${o.toLowerCase()}`}(o)}`}(o,e,t,n))}var t="3.8.2",n=Symbol.for(`@toolbox-web/grid:feature-registry@${t}/v1`),r=Symbol.for(`@toolbox-web/grid:feature-registry-warned@${t}/v1`);function i(o,e){let t=Reflect.get(globalThis,o);return void 0===t&&(t=e(),Reflect.set(globalThis,o,t)),t}var s=i(n,()=>/* @__PURE__ */new Map),c=i(r,()=>/* @__PURE__ */new Set),f=()=>"undefined"!=typeof window&&("localhost"===window.location?.hostname||"127.0.0.1"===window.location?.hostname);function a(o,t,n){f()&&s.has(o)&&!n?.override&&e("TBW030",`Feature "${o}" was re-registered. Previous registration overwritten.`),s.set(o,{factory:t,name:o})}function u(o){return s.has(o)}function d(o){return s.get(o)?.factory}function l(){return Array.from(s.keys())}var w={undoRedo:["editing"],clipboard:["selection"]};function g(o,t){const n=s.get(o);if(n)return n.factory(t);if(f()&&!c.has(o)){c.add(o);const t=o.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase();e("TBW031",`Feature "${o}" is configured but not registered.\nAdd this import to enable it:\n\n import '@toolbox-web/grid/features/${t}';\n`)}}function b(o){const t=[];for(const[e,r]of Object.entries(o))void 0!==r&&!1!==r&&t.push(e);!function(o){const t=new Set(o);for(const n of o){const o=w[n];if(o)for(const r of o)t.has(r)||f()&&e("TBW032",`Feature "${n}" requires "${r}" to be enabled. Add "${r}" to your features configuration.`)}}(t);const n=[];for(const e of t){const t=g(e,o[e]);t&&n.push(t)}return function(o){if(o.length<2)return o;const e=/* @__PURE__ */new Map;for(const s of o)e.set(s.name,s);const t=[],n=/* @__PURE__ */new Set,r=/* @__PURE__ */new Set,i=o=>{if(n.has(o)||r.has(o))return;r.add(o);const s=o.constructor.dependencies??[];for(const t of s){const o=e.get(t.name);o&&i(o)}r.delete(o),n.add(o),t.push(o)};for(const s of o)i(s);return t}(n)}function $(){s.clear(),c.clear()}o(b);export{$ as clearFeatureRegistry,g as createPluginFromFeature,b as createPluginsFromFeatures,d as getFeatureFactory,l as getRegisteredFeatures,u as isFeatureRegistered,a as registerFeature};
2
2
  //# sourceMappingURL=registry.js.map
@@ -1,2 +1,2 @@
1
- var e=/* @__PURE__ */new WeakMap;function t(e){return"__proto__"===e||"constructor"===e||"prototype"===e}var n=/* @__PURE__ */new Map;function r(e){if(-1===e.indexOf("."))return null;let t=n.get(e);return void 0===t&&(t=Object.freeze(e.split(".")),n.set(e,t)),t}function o(e,n){if(null==e)return;const o=r(n),i=e;return null===o?t(n)?void 0:i[n]:Object.prototype.hasOwnProperty.call(i,n)?i[n]:function(e,n){let r=e;for(let o=0;o<n.length;o++){if(null==r||"object"!=typeof r)return;const e=n[o];if(t(e))return;r=r[e]}return r}(i,o)}function i(e,n,o){if(null==e||"object"!=typeof e)return!1;const i=r(n),s=e;return null===i?!t(n)&&(s[n]=o,!0):Object.prototype.hasOwnProperty.call(s,n)?(s[n]=o,!0):function(e,n,r){if(null==e||"object"!=typeof e)return!1;let o=e;for(let s=0;s<n.length-1;s++){const e=n[s];if(t(e))return!1;const r=o[e];if(null==r||"object"!=typeof r)return!1;o=r}const i=n[n.length-1];return!t(i)&&(o[i]=r,!0)}(s,i,o)}function s(t,n,r=-1){if(!n.valueAccessor)return o(t,n.field);if("object"!=typeof t||null===t)return n.valueAccessor({row:t,column:n,rowIndex:r});const i=t,s=n.field;let l=e.get(i);if(l){const e=l.get(s);if(void 0!==e)return e.v}else l=/* @__PURE__ */new Map,e.set(i,l);const a=n.valueAccessor({row:t,column:n,rowIndex:r});return l.set(s,{v:a}),a}function l(t,n){t&&(n?e.get(t)?.delete(n):e.delete(t))}var a={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};function c(e,t){return`[tbw-grid${e?`#${e}`:""}${t?`:${t}`:""}]`}function u(e,t,n,r){return`${c(n,r)} ${e}: ${t}\n\n → More info: ${function(e){return`https://toolboxjs.com/grid/errors#${e.toLowerCase()}`}(e)}`}var d="__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(e=>e.split("").reverse().join(""));new RegExp(`__(proto|defineGetter|defineSetter)|${d.slice(3).join("|")}|this\\b`);function f(e){return e&&"string"==typeof e?e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;"):""}var h=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("|")),p=/^on\w+$/i,g=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),m=/^\s*(javascript|vbscript|data|blob):/i;function w(e){const t=document.createElement("template");return e&&"string"==typeof e&&(t.innerHTML=e,function(e){const t=[],n=e.querySelectorAll("*");for(const r of n){const e=r.tagName.toLowerCase();if(h.has(e)){t.push(r);continue}if(("svg"===e||"http://www.w3.org/2000/svg"===r.namespaceURI)&&Array.from(r.attributes).some(e=>p.test(e.name)||"href"===e.name||"xlink:href"===e.name)){t.push(r);continue}const n=[];for(const t of r.attributes){const e=t.name.toLowerCase();p.test(e)?n.push(t.name):"is"!==e?(g.has(e)&&m.test(t.value)||"style"===e&&/expression\s*\(|javascript:|behavior\s*:/i.test(t.value))&&n.push(t.name):n.push(t.name)}n.forEach(e=>r.removeAttribute(e))}t.forEach(e=>e.remove())}(t.content)),t.content}var b=class{static dependencies;static manifest;aliases;version="3.8.0";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#e;get defaultConfig(){return{}}constructor(e={}){this.userConfig=e}get resolvedConfig(){return this.#e?this.config:{...this.defaultConfig,...this.userConfig}}mergeConfigsFrom(e){if(0===e.length)return;const t={...this.userConfig},n={};for(const r of Object.keys(t))n[r]=this;for(const r of e){const e=r.userConfig;for(const[o,i]of Object.entries(e)){if(void 0===i)continue;if(!(o in t)){t[o]=i,n[o]=r;continue}if(t[o]===i)continue;const e=n[o]?.constructor.name??this.constructor.name,s=r.constructor.name,l=u("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${o}" supplied by both ${e} and ${s}. Pass the option on a single instance, or remove the duplicate.`,void 0,this.name);throw new Error(l)}}Object.assign(this.userConfig,t)}refreshUserConfigFrom(e){const t=this.userConfig,n={...e.userConfig};for(const r of Object.keys(t))delete t[r];Object.assign(t,n)}attach(e){this.#e?.abort(),this.#e=new AbortController,this.grid=e,this.config={...this.defaultConfig,...this.userConfig}}detach(){this.#e?.abort(),this.#e=void 0}getPlugin(e){return this.grid?.getPlugin(e)}emit(e,t){this.grid?.dispatchEvent?.(new CustomEvent(e,{detail:t,bubbles:!0}))}emitCancelable(e,t){const n=new CustomEvent(e,{detail:t,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(n),n.defaultPrevented}on(e,t){this.grid?._pluginManager?.subscribe(this,e,t)}off(e){this.grid?._pluginManager?.unsubscribe(this,e)}emitPluginEvent(e,t){this.grid?._pluginManager?.emitPluginEvent(e,t)}broadcast(e,t){this.emitPluginEvent(e,t),this.emit(e,t)}queryBoolean(e,t=null){const n=this.grid?.query?.(e,t);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.#e?.signal??this.grid?.disconnectSignal}get gridIcons(){const e=this.grid?.gridConfig?.icons??{};return{...a,...e}}t(e,t){return this.grid?.effectiveConfig?.locale?.[e]??t}get translate(){return(e,t)=>this.t(e,t)}get isAnimationEnabled(){const e=this.grid?.effectiveConfig?.animation?.mode??"reduced-motion";if(!1===e||"off"===e)return!1;if(!0===e||"on"===e)return!0;const t=this.gridElement;return!t||"0"!==getComputedStyle(t).getPropertyValue("--tbw-animation-enabled").trim()}get animationDuration(){const e=this.gridElement;if(e){const t=getComputedStyle(e).getPropertyValue("--tbw-animation-duration").trim(),n=parseInt(t,10);if(!isNaN(n))return n}return 200}setIcon(e,t,n){e.dataset.icon=t.replace(/([A-Z])/g,"-$1").toLowerCase(),"collapse"===t?e.dataset.expanded="":"expand"===t&&delete e.dataset.expanded;const r=this.#t(t,n);var o,i;void 0!==r?"string"==typeof r?(o=e,(i=r)&&"string"==typeof i?-1!==i.indexOf("<")||-1!==i.indexOf("&")?o.replaceChildren(w(i)):o.textContent=i:o.replaceChildren()):r instanceof HTMLElement&&e.replaceChildren(r.cloneNode(!0)):e.innerHTML=""}#t(e,t){return void 0!==t?t:this.grid?.gridConfig?.icons?.[e]}updateSortIndicator(e,t){e.querySelector('[part~="sort-indicator"], .sort-indicator')?.remove();const n=document.createElement("span");n.setAttribute("part","sort-indicator"),n.className="sort-indicator",t?(e.setAttribute("aria-sort","asc"===t?"ascending":"descending"),e.setAttribute("data-sort",t),this.setIcon(n,"asc"===t?"sortAsc":"sortDesc")):(e.setAttribute("aria-sort","none"),e.removeAttribute("data-sort"),this.setIcon(n,"sortNone"));const r=e.querySelector(".tbw-filter-btn")??e.querySelector(".resize-handle");return r?e.insertBefore(n,r):e.appendChild(n),n}warn(e,t){void 0!==t?console.warn(u(e,t,this.gridElement.id,this.name)):console.warn(`${c(this.gridElement.id,this.name)} ${e}`)}throwDiagnostic(e,t){throw new Error(u(e,t,this.gridElement.id,this.name))}};function y(e,t,n=!0){let r=e;if(n&&(r=r.filter(e=>!e.hidden&&!e.field.startsWith("__")&&!0!==e.utility)),t?.length){const e=new Set(t);r=r.filter(t=>e.has(t.field))}return r}var v="data-tbw-clip";function C(e,t,n){const r=e?`<thead><tr>${e.map(e=>`<th>${f(e)}</th>`).join("")}</tr></thead>`:"",o=`<tbody>${t.map(e=>`<tr>${e.map(e=>`<td>${f(e)}</td>`).join("")}</tr>`).join("")}</tbody>`;return`<table ${v}="${function(e){return btoa(encodeURIComponent(JSON.stringify(e)))}(n)}">${r}${o}</table>`}async function x(e,t){if(t&&"undefined"!=typeof ClipboardItem&&navigator.clipboard?.write)try{return await navigator.clipboard.write([new ClipboardItem({"text/plain":new Blob([e],{type:"text/plain"}),"text/html":new Blob([t],{type:"text/html"})})]),!0}catch{}try{return await navigator.clipboard.writeText(e),!0}catch(s){n="TBW100",r=`Clipboard API failed: ${s}`,console.warn(u(n,r,o,i));const t=document.createElement("textarea");t.value=e,t.style.position="fixed",t.style.opacity="0",t.style.pointerEvents="none",document.body.appendChild(t),t.select();const l=document.execCommand("copy");return document.body.removeChild(t),l}var n,r,o,i}function E(e,t){const n=t.delimiter??"\t",r=t.newline??"\n",o=e.replace(/\r\n/g,"\n").replace(/\r/g,"\n"),i=o.length,s=[];let l=[],a=0,c=!1,u=!1;const d=e=>{const t=o.slice(a,e);return u?function(e){let t="",n=!1;for(let r=0;r<e.length;r++){const o=e[r];'"'===o?n?'"'===e[r+1]?(t+='"',r++):n=!1:n=!0:t+=o}return t}(t):t},f=()=>{(l.length>1||l.some(e=>""!==e.trim()))&&s.push(l),l=[]};for(let h=0;h<i;h++){const e=o[h];'"'===e?(u=!0,c?'"'===o[h+1]?h++:c=!1:c=!0):e!==n||c?e!==r||c||(l.push(d(h)),a=h+1,u=!1,f()):(l.push(d(h)),a=h+1,u=!1)}return l.push(d(i)),f(),s}function S(e,t){if(!1===e)return{accepted:!1,reason:"column"};if("function"==typeof e){const n=e(t);if(!1===n)return{accepted:!1,reason:"cell"};if(n&&"object"==typeof n&&"value"in n)return{accepted:!0,value:n.value}}return{accepted:!0,value:t.value}}function R(e,t){0!==t.length&&e.dispatchEvent?.(new CustomEvent("paste-rejected",{detail:{rejected:t},bubbles:!0}))}function j(e,t){const{rows:n,rawRows:r,target:s,fields:a,fillSelection:c,sourceFields:u}=e;if(!s||0===n.length)return;const d=r??n,f=t.rows,h=t.effectiveConfig.columns??[],p=h.map(e=>e.field),g=new Map(h.map(e=>[e.field,e])),[m=()=>!1]=t.query("getCellEditableResolver"),w=/* @__PURE__ */new Map;let b=f.length;const y=[],v=(e,t,n,r,i)=>{if(!t||!m(t,r))return;const s=S(g.get(t)?.onPaste,{value:n,field:t,row:r,rowIndex:e,oldValue:o(r,t),sourceField:i});if(!s.accepted)return void y.push({field:t,rowIndex:e,row:r,value:n,reason:s.reason});let l=w.get(e);l||(l={},w.set(e,l)),l[t]=A(s.value)};if(c&&s.bounds){const e=d.length;for(let t=s.row;t<=s.bounds.endRow&&!(t>=f.length);t++){const n=d[(t-s.row)%e],r=n.length;if(0===r)continue;const o=f[t];a.forEach((e,i)=>v(t,e,n[i%r],o,u?.[i%r]))}}else{const e=s.bounds?s.bounds.endRow:1/0;d.forEach((t,n)=>{const r=s.row+n;if(r>e)return;if(s.bounds&&r>=f.length)return;!s.bounds&&r>=b&&(b=r+1);const o=f[r]??{};t.forEach((e,t)=>v(r,a[t],e,o,u?.[t]))})}if(0===w.size&&b===f.length)return void R(t,y);if(b>f.length){const e=[...f];for(;e.length<b;){const t={};p.forEach(e=>t[e]=""),e.push(t)}t.rows=e}const C=t.rows,x=[];let E=!1;for(const[o,S]of w){const e=C[o];if(!e)continue;let n;try{n=t.getRowId(e)}catch{n=void 0}if(null==n){for(const[t,n]of Object.entries(S))i(e,t,n),l(e,t);E=!0}else x.push({id:n,changes:S})}x.length>0?t.updateRows(x,"paste"):E&&b===f.length&&(t.rows=[...C]),R(t,y)}function A(e){if(null===e||"object"!=typeof e)return e;try{return structuredClone(e)}catch{return e}}var M=class extends b{static manifest={queries:[{type:"clipboard:copy",description:"Triggers a copy operation and returns the copied text"}]};static dependencies=[{name:"selection",required:!1,reason:"Enables copy/paste of selected cells instead of entire grid"}];name="clipboard";get defaultConfig(){return{includeHeaders:!1,delimiter:"\t",newline:"\n",quoteStrings:!1}}lastCopied=null;#n=null;attach(e){super.attach(e),e.addEventListener("paste",e=>this.#r(e),{signal:this.disconnectSignal})}detach(){this.lastCopied=null,this.#n=null}handleQuery(e){if("clipboard:copy"===e.type)return this.copy(),!0}onKeyDown(e){return!(!e.ctrlKey&&!e.metaKey||"c"!==e.key)&&(e.preventDefault(),this.#o(e.target),!0)}#o(e){const t=this.#i();if(t&&0===t.ranges.length){let n,r;if(t.anchor)n=t.anchor.row,r=this.visibleColumns[t.anchor.col]?.field;else{const t=this.#s(e);t&&(n=t.row,r=this.columns[t.col]?.field)}if(null==n||null==r)return;return void this.copy({rowIndices:[n],columns:[r]})}this.copy()}#r(e){if(this.#l(e.target))return;const t=e.clipboardData?.getData("text/plain");if(!t)return;e.preventDefault();const n=E(t,this.config),r=this.#i(),o=r?.ranges??[],i=o[0];let s=1/0,l=1/0,a=-1/0,c=-1/0;for(const v of o)s=Math.min(s,v.from.row,v.to.row),a=Math.max(a,v.from.row,v.to.row),l=Math.min(l,v.from.col,v.to.col),c=Math.max(c,v.from.col,v.to.col);const u=r?.anchor??null,d=i?s:u?.row??0,f=i?l:u?.col??0,h=!i||"range"!==r?.mode&&"row"!==r?.mode||s===a&&l===c?null:{endRow:a,endCol:c},p=h?.endCol??this.visibleColumns.length-1;let g,m;if(this.#a(n),this.#n&&this.#n.text===t&&this.#n.rawRows.length===n.length)g=this.#n.rawRows,m=this.#n.fields;else{const t=function(e){if(!e||-1===e.indexOf("data-tbw-clip"))return null;try{const t=e.match(new RegExp(`${v}="([A-Za-z0-9+/=]*)"`))?.[1];if(!t)return null;const n=JSON.parse(decodeURIComponent(atob(t)));return n&&Array.isArray(n.rows)&&Array.isArray(n.fields)?n:null}catch{return null}}(e.clipboardData?.getData("text/html"));t&&t.rows.length===n.length&&(g=t.rows,m=t.fields)}const w=this.visibleColumns[f],b=w?{row:d,col:f,field:w.field,bounds:h}:null,y=!0===this.config.fillSelection&&null!==h,C=[],x=n[0]?.length??0,S=y?p-f+1:x;for(let v=0;v<S&&f+v<=p;v++){const e=this.visibleColumns[f+v];e&&C.push(e.field)}const R={rows:n,text:t,target:b,fields:C,fillSelection:y,rawRows:g,sourceFields:m};this.emit("paste",R),this.#c(R)}#c(e){if(!this.grid)return;const{pasteHandler:t}=this.config;null!==t&&(t??j)(e,this.grid)}#a(e){if(!this.config.includeHeaders)return;if(e.length<=1)return;const t=e[0];if(0===t.length)return;const n=this.#u();for(const r of t)if(!n.has(r))return;e.shift()}#u(){const e=/* @__PURE__ */new Set;for(const t of this.columns){const n=t.header||t.field;n&&e.add(n)}return e}#l(e){return e instanceof Element&&!!e.closest('input, textarea, select, [contenteditable=""], [contenteditable="true"]')}#i(){return(this.grid?.query("getSelection"))?.[0]}#d(e){const t=this.#i(),n=t?.ranges??[];let r,o=1/0,i=-1/0,s=1/0,l=-1/0;for(const h of n)o=Math.min(o,h.from.row,h.to.row),i=Math.max(i,h.from.row,h.to.row),s=Math.min(s,h.from.col,h.to.col),l=Math.max(l,h.from.col,h.to.col);let a,c=null;e?.columns?r=y(this.columns,e.columns):n.length&&"row"!==t?.mode?(r=y(this.visibleColumns.slice(s,l+1)),c=r.map(e=>this.visibleColumns.indexOf(e))):r=y(this.columns);let u=null;if(e?.rowIndices)a=function(e,t){return t?.length?[...t].sort((e,t)=>e-t).map(t=>e[t]).filter(e=>null!=e):e}(this.rows,e.rowIndices);else if(n.length){const e="row"===t?.mode,r=e=>n.some(t=>e>=Math.min(t.from.row,t.to.row)&&e<=Math.max(t.from.row,t.to.row));a=[],u=[];for(let t=o;t<=i;t++){const n=this.rows[t];n&&(e&&!r(t)||(a.push(n),u.push(t)))}}else a=this.rows;const d=u,f=c;return{columns:r,rows:a,contains:d&&f?(e,t)=>{const r=d[e],o=f[t];return n.some(e=>r>=Math.min(e.from.row,e.to.row)&&r<=Math.max(e.from.row,e.to.row)&&o>=Math.min(e.from.col,e.to.col)&&o<=Math.max(e.from.col,e.to.col))}:null}}#f(e,t,n,r){return this.#h(this.#p(e,t,n,r),n)}#p(e,t,n,r){const o=n?.includeHeaders??this.config.includeHeaders??!1,i=n?.processCell??this.config.processCell;return{header:o?e.map(e=>e.header||e.field):null,rows:t.map((t,n)=>e.map((e,o)=>{if(r&&!r(n,o))return"";const l=s(t,e);return i?i(l,e.field,t):this.#g(e,l,t)}))}}#h(e,t){const n=t?.delimiter??this.config.delimiter??"\t",r=t?.newline??this.config.newline??"\n",o=[];e.header&&o.push(e.header.join(n));for(const i of e.rows)o.push(i.join(n));return o.join(r)}#g(e,t,n){if(e.format)try{const r=e.format(t,n);return null==r?"":String(r)}catch{}if(e.renderer||e.viewRenderer){const t=this.#m(e.field,n);if(null!=t)return t}return function(e){return null==e?"":e instanceof Date?e.toISOString():"object"==typeof e?JSON.stringify(e):String(e)}(t)}#m(e,t){const n=this.gridElement;if(!n)return null;const r=this.rows.indexOf(t);if(-1===r)return null;const o=n.querySelector(`.cell[data-row="${r}"][data-field="${e}"]`);return o?o.textContent?.trim()??null:null}#s(e){const t=e.closest(".cell[data-field]");if(!t)return null;const n=t.dataset.field,r=t.dataset.row;if(!n||!r)return null;const o=parseInt(r,10);if(isNaN(o))return null;const i=this.columns.findIndex(e=>e.field===n);return-1===i?null:{row:o,col:i}}getSelectionAsText(e){const{columns:t,rows:n,contains:r}=this.#d(e);return 0===t.length||0===n.length?"":this.#f(t,n,e,r)}async copy(e){const{columns:t,rows:n,contains:r}=this.#d(e);if(0===t.length||0===n.length)return"";const o=this.#p(t,n,e,r),i=this.#h(o,e),l=n.map((e,n)=>t.map((t,o)=>r&&!r(n,o)?"":A(s(e,t)))),a=t.map(e=>e.field);return await x(i,C(o.header,o.rows,{v:1,fields:a,rows:l})),this.lastCopied={text:i,timestamp:Date.now()},this.#n={text:i,rawRows:l,fields:a},this.emit("copy",{text:i,rowCount:n.length,columnCount:t.length}),i}async copyRows(e,t){return 0===e.length?"":this.copy({...t,rowIndices:e})}async paste(){const e=await async function(){try{return await navigator.clipboard.readText()}catch{return""}}();return e?E(e,this.config):null}getLastCopied(){return this.lastCopied}};export{M as ClipboardPlugin,j as defaultPasteHandler,R as emitPasteRejected,S as resolveColumnPaste};
1
+ var e=/* @__PURE__ */new WeakMap;function t(e){return"__proto__"===e||"constructor"===e||"prototype"===e}var n=/* @__PURE__ */new Map;function r(e){if(-1===e.indexOf("."))return null;let t=n.get(e);return void 0===t&&(t=Object.freeze(e.split(".")),n.set(e,t)),t}function o(e,n){if(null==e)return;const o=r(n),i=e;return null===o?t(n)?void 0:i[n]:Object.prototype.hasOwnProperty.call(i,n)?i[n]:function(e,n){let r=e;for(let o=0;o<n.length;o++){if(null==r||"object"!=typeof r)return;const e=n[o];if(t(e))return;r=r[e]}return r}(i,o)}function i(e,n,o){if(null==e||"object"!=typeof e)return!1;const i=r(n),s=e;return null===i?!t(n)&&(s[n]=o,!0):Object.prototype.hasOwnProperty.call(s,n)?(s[n]=o,!0):function(e,n,r){if(null==e||"object"!=typeof e)return!1;let o=e;for(let s=0;s<n.length-1;s++){const e=n[s];if(t(e))return!1;const r=o[e];if(null==r||"object"!=typeof r)return!1;o=r}const i=n[n.length-1];return!t(i)&&(o[i]=r,!0)}(s,i,o)}function s(t,n,r=-1){if(!n.valueAccessor)return o(t,n.field);if("object"!=typeof t||null===t)return n.valueAccessor({row:t,column:n,rowIndex:r});const i=t,s=n.field;let l=e.get(i);if(l){const e=l.get(s);if(void 0!==e)return e.v}else l=/* @__PURE__ */new Map,e.set(i,l);const a=n.valueAccessor({row:t,column:n,rowIndex:r});return l.set(s,{v:a}),a}function l(t,n){t&&(n?e.get(t)?.delete(n):e.delete(t))}var a={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};function c(e,t){return`[tbw-grid${e?`#${e}`:""}${t?`:${t}`:""}]`}function u(e,t,n,r){return`${c(n,r)} ${e}: ${t}\n\n → More info: ${function(e){return`https://toolboxjs.com/grid/errors#${e.toLowerCase()}`}(e)}`}var d="__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(e=>e.split("").reverse().join(""));new RegExp(`__(proto|defineGetter|defineSetter)|${d.slice(3).join("|")}|this\\b`);function f(e){return e&&"string"==typeof e?e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;"):""}var h=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("|")),p=/^on\w+$/i,g=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),m=/^\s*(javascript|vbscript|data|blob):/i;function w(e){const t=document.createElement("template");return e&&"string"==typeof e&&(t.innerHTML=e,function(e){const t=[],n=e.querySelectorAll("*");for(const r of n){const e=r.tagName.toLowerCase();if(h.has(e)){t.push(r);continue}if(("svg"===e||"http://www.w3.org/2000/svg"===r.namespaceURI)&&Array.from(r.attributes).some(e=>p.test(e.name)||"href"===e.name||"xlink:href"===e.name)){t.push(r);continue}const n=[];for(const t of r.attributes){const e=t.name.toLowerCase();p.test(e)?n.push(t.name):"is"!==e?(g.has(e)&&m.test(t.value)||"style"===e&&/expression\s*\(|javascript:|behavior\s*:/i.test(t.value))&&n.push(t.name):n.push(t.name)}n.forEach(e=>r.removeAttribute(e))}t.forEach(e=>e.remove())}(t.content)),t.content}var b=class{static dependencies;static manifest;aliases;version="3.8.2";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#e;get defaultConfig(){return{}}constructor(e={}){this.userConfig=e}get resolvedConfig(){return this.#e?this.config:{...this.defaultConfig,...this.userConfig}}mergeConfigsFrom(e){if(0===e.length)return;const t={...this.userConfig},n={};for(const r of Object.keys(t))n[r]=this;for(const r of e){const e=r.userConfig;for(const[o,i]of Object.entries(e)){if(void 0===i)continue;if(!(o in t)){t[o]=i,n[o]=r;continue}if(t[o]===i)continue;const e=n[o]?.constructor.name??this.constructor.name,s=r.constructor.name,l=u("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${o}" supplied by both ${e} and ${s}. Pass the option on a single instance, or remove the duplicate.`,void 0,this.name);throw new Error(l)}}Object.assign(this.userConfig,t)}refreshUserConfigFrom(e){const t=this.userConfig,n={...e.userConfig};for(const r of Object.keys(t))delete t[r];Object.assign(t,n)}attach(e){this.#e?.abort(),this.#e=new AbortController,this.grid=e,this.config={...this.defaultConfig,...this.userConfig}}detach(){this.#e?.abort(),this.#e=void 0}getPlugin(e){return this.grid?.getPlugin(e)}emit(e,t){this.grid?.dispatchEvent?.(new CustomEvent(e,{detail:t,bubbles:!0}))}emitCancelable(e,t){const n=new CustomEvent(e,{detail:t,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(n),n.defaultPrevented}on(e,t){this.grid?._pluginManager?.subscribe(this,e,t)}off(e){this.grid?._pluginManager?.unsubscribe(this,e)}emitPluginEvent(e,t){this.grid?._pluginManager?.emitPluginEvent(e,t)}broadcast(e,t){this.emitPluginEvent(e,t),this.emit(e,t)}queryBoolean(e,t=null){const n=this.grid?.query?.(e,t);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.#e?.signal??this.grid?.disconnectSignal}get gridIcons(){const e=this.grid?.gridConfig?.icons??{};return{...a,...e}}t(e,t){return this.grid?.effectiveConfig?.locale?.[e]??t}get translate(){return(e,t)=>this.t(e,t)}get isAnimationEnabled(){const e=this.grid?.effectiveConfig?.animation?.mode??"reduced-motion";if(!1===e||"off"===e)return!1;if(!0===e||"on"===e)return!0;const t=this.gridElement;return!t||"0"!==getComputedStyle(t).getPropertyValue("--tbw-animation-enabled").trim()}get animationDuration(){const e=this.gridElement;if(e){const t=getComputedStyle(e).getPropertyValue("--tbw-animation-duration").trim(),n=parseInt(t,10);if(!isNaN(n))return n}return 200}setIcon(e,t,n){e.dataset.icon=t.replace(/([A-Z])/g,"-$1").toLowerCase(),"collapse"===t?e.dataset.expanded="":"expand"===t&&delete e.dataset.expanded;const r=this.#t(t,n);var o,i;void 0!==r?"string"==typeof r?(o=e,(i=r)&&"string"==typeof i?-1!==i.indexOf("<")||-1!==i.indexOf("&")?o.replaceChildren(w(i)):o.textContent=i:o.replaceChildren()):r instanceof HTMLElement&&e.replaceChildren(r.cloneNode(!0)):e.innerHTML=""}#t(e,t){return void 0!==t?t:this.grid?.gridConfig?.icons?.[e]}updateSortIndicator(e,t){e.querySelector('[part~="sort-indicator"], .sort-indicator')?.remove();const n=document.createElement("span");n.setAttribute("part","sort-indicator"),n.className="sort-indicator",t?(e.setAttribute("aria-sort","asc"===t?"ascending":"descending"),e.setAttribute("data-sort",t),this.setIcon(n,"asc"===t?"sortAsc":"sortDesc")):(e.setAttribute("aria-sort","none"),e.removeAttribute("data-sort"),this.setIcon(n,"sortNone"));const r=e.querySelector(".tbw-filter-btn")??e.querySelector(".resize-handle");return r?e.insertBefore(n,r):e.appendChild(n),n}warn(e,t){void 0!==t?console.warn(u(e,t,this.gridElement.id,this.name)):console.warn(`${c(this.gridElement.id,this.name)} ${e}`)}throwDiagnostic(e,t){throw new Error(u(e,t,this.gridElement.id,this.name))}};function y(e,t,n=!0){let r=e;if(n&&(r=r.filter(e=>!e.hidden&&!e.field.startsWith("__")&&!0!==e.utility)),t?.length){const e=new Set(t);r=r.filter(t=>e.has(t.field))}return r}var v="data-tbw-clip";function C(e,t,n){const r=e?`<thead><tr>${e.map(e=>`<th>${f(e)}</th>`).join("")}</tr></thead>`:"",o=`<tbody>${t.map(e=>`<tr>${e.map(e=>`<td>${f(e)}</td>`).join("")}</tr>`).join("")}</tbody>`;return`<table ${v}="${function(e){return btoa(encodeURIComponent(JSON.stringify(e)))}(n)}">${r}${o}</table>`}async function x(e,t){if(t&&"undefined"!=typeof ClipboardItem&&navigator.clipboard?.write)try{return await navigator.clipboard.write([new ClipboardItem({"text/plain":new Blob([e],{type:"text/plain"}),"text/html":new Blob([t],{type:"text/html"})})]),!0}catch{}try{return await navigator.clipboard.writeText(e),!0}catch(s){n="TBW100",r=`Clipboard API failed: ${s}`,console.warn(u(n,r,o,i));const t=document.createElement("textarea");t.value=e,t.style.position="fixed",t.style.opacity="0",t.style.pointerEvents="none",document.body.appendChild(t),t.select();const l=document.execCommand("copy");return document.body.removeChild(t),l}var n,r,o,i}function E(e,t){const n=t.delimiter??"\t",r=t.newline??"\n",o=e.replace(/\r\n/g,"\n").replace(/\r/g,"\n"),i=o.length,s=[];let l=[],a=0,c=!1,u=!1;const d=e=>{const t=o.slice(a,e);return u?function(e){let t="",n=!1;for(let r=0;r<e.length;r++){const o=e[r];'"'===o?n?'"'===e[r+1]?(t+='"',r++):n=!1:n=!0:t+=o}return t}(t):t},f=()=>{(l.length>1||l.some(e=>""!==e.trim()))&&s.push(l),l=[]};for(let h=0;h<i;h++){const e=o[h];'"'===e?(u=!0,c?'"'===o[h+1]?h++:c=!1:c=!0):e!==n||c?e!==r||c||(l.push(d(h)),a=h+1,u=!1,f()):(l.push(d(h)),a=h+1,u=!1)}return l.push(d(i)),f(),s}function S(e,t){if(!1===e)return{accepted:!1,reason:"column"};if("function"==typeof e){const n=e(t);if(!1===n)return{accepted:!1,reason:"cell"};if(n&&"object"==typeof n&&"value"in n)return{accepted:!0,value:n.value}}return{accepted:!0,value:t.value}}function R(e,t){0!==t.length&&e.dispatchEvent?.(new CustomEvent("paste-rejected",{detail:{rejected:t},bubbles:!0}))}function j(e,t){const{rows:n,rawRows:r,target:s,fields:a,fillSelection:c,sourceFields:u}=e;if(!s||0===n.length)return;const d=r??n,f=t.rows,h=t.effectiveConfig.columns??[],p=h.map(e=>e.field),g=new Map(h.map(e=>[e.field,e])),[m=()=>!1]=t.query("getCellEditableResolver"),w=/* @__PURE__ */new Map;let b=f.length;const y=[],v=(e,t,n,r,i)=>{if(!t||!m(t,r))return;const s=S(g.get(t)?.onPaste,{value:n,field:t,row:r,rowIndex:e,oldValue:o(r,t),sourceField:i});if(!s.accepted)return void y.push({field:t,rowIndex:e,row:r,value:n,reason:s.reason});let l=w.get(e);l||(l={},w.set(e,l)),l[t]=A(s.value)};if(c&&s.bounds){const e=d.length;for(let t=s.row;t<=s.bounds.endRow&&!(t>=f.length);t++){const n=d[(t-s.row)%e],r=n.length;if(0===r)continue;const o=f[t];a.forEach((e,i)=>v(t,e,n[i%r],o,u?.[i%r]))}}else{const e=s.bounds?s.bounds.endRow:1/0;d.forEach((t,n)=>{const r=s.row+n;if(r>e)return;if(s.bounds&&r>=f.length)return;!s.bounds&&r>=b&&(b=r+1);const o=f[r]??{};t.forEach((e,t)=>v(r,a[t],e,o,u?.[t]))})}if(0===w.size&&b===f.length)return void R(t,y);if(b>f.length){const e=[...f];for(;e.length<b;){const t={};p.forEach(e=>t[e]=""),e.push(t)}t.rows=e}const C=t.rows,x=[];let E=!1;for(const[o,S]of w){const e=C[o];if(!e)continue;let n;try{n=t.getRowId(e)}catch{n=void 0}if(null==n){for(const[t,n]of Object.entries(S))i(e,t,n),l(e,t);E=!0}else x.push({id:n,changes:S})}x.length>0?t.updateRows(x,"paste"):E&&b===f.length&&(t.rows=[...C]),R(t,y)}function A(e){if(null===e||"object"!=typeof e)return e;try{return structuredClone(e)}catch{return e}}var M=class extends b{static manifest={queries:[{type:"clipboard:copy",description:"Triggers a copy operation and returns the copied text"}]};static dependencies=[{name:"selection",required:!1,reason:"Enables copy/paste of selected cells instead of entire grid"}];name="clipboard";get defaultConfig(){return{includeHeaders:!1,delimiter:"\t",newline:"\n",quoteStrings:!1}}lastCopied=null;#n=null;attach(e){super.attach(e),e.addEventListener("paste",e=>this.#r(e),{signal:this.disconnectSignal})}detach(){this.lastCopied=null,this.#n=null}handleQuery(e){if("clipboard:copy"===e.type)return this.copy(),!0}onKeyDown(e){return!(!e.ctrlKey&&!e.metaKey||"c"!==e.key)&&(e.preventDefault(),this.#o(e.target),!0)}#o(e){const t=this.#i();if(t&&0===t.ranges.length){let n,r;if(t.anchor)n=t.anchor.row,r=this.visibleColumns[t.anchor.col]?.field;else{const t=this.#s(e);t&&(n=t.row,r=this.columns[t.col]?.field)}if(null==n||null==r)return;return void this.copy({rowIndices:[n],columns:[r]})}this.copy()}#r(e){if(this.#l(e.target))return;const t=e.clipboardData?.getData("text/plain");if(!t)return;e.preventDefault();const n=E(t,this.config),r=this.#i(),o=r?.ranges??[],i=o[0];let s=1/0,l=1/0,a=-1/0,c=-1/0;for(const v of o)s=Math.min(s,v.from.row,v.to.row),a=Math.max(a,v.from.row,v.to.row),l=Math.min(l,v.from.col,v.to.col),c=Math.max(c,v.from.col,v.to.col);const u=r?.anchor??null,d=i?s:u?.row??0,f=i?l:u?.col??0,h=!i||"range"!==r?.mode&&"row"!==r?.mode||s===a&&l===c?null:{endRow:a,endCol:c},p=h?.endCol??this.visibleColumns.length-1;let g,m;if(this.#a(n),this.#n&&this.#n.text===t&&this.#n.rawRows.length===n.length)g=this.#n.rawRows,m=this.#n.fields;else{const t=function(e){if(!e||-1===e.indexOf("data-tbw-clip"))return null;try{const t=e.match(new RegExp(`${v}="([A-Za-z0-9+/=]*)"`))?.[1];if(!t)return null;const n=JSON.parse(decodeURIComponent(atob(t)));return n&&Array.isArray(n.rows)&&Array.isArray(n.fields)?n:null}catch{return null}}(e.clipboardData?.getData("text/html"));t&&t.rows.length===n.length&&(g=t.rows,m=t.fields)}const w=this.visibleColumns[f],b=w?{row:d,col:f,field:w.field,bounds:h}:null,y=!0===this.config.fillSelection&&null!==h,C=[],x=n[0]?.length??0,S=y?p-f+1:x;for(let v=0;v<S&&f+v<=p;v++){const e=this.visibleColumns[f+v];e&&C.push(e.field)}const R={rows:n,text:t,target:b,fields:C,fillSelection:y,rawRows:g,sourceFields:m};this.emit("paste",R),this.#c(R)}#c(e){if(!this.grid)return;const{pasteHandler:t}=this.config;null!==t&&(t??j)(e,this.grid)}#a(e){if(!this.config.includeHeaders)return;if(e.length<=1)return;const t=e[0];if(0===t.length)return;const n=this.#u();for(const r of t)if(!n.has(r))return;e.shift()}#u(){const e=/* @__PURE__ */new Set;for(const t of this.columns){const n=t.header||t.field;n&&e.add(n)}return e}#l(e){return e instanceof Element&&!!e.closest('input, textarea, select, [contenteditable=""], [contenteditable="true"]')}#i(){return(this.grid?.query("getSelection"))?.[0]}#d(e){const t=this.#i(),n=t?.ranges??[];let r,o=1/0,i=-1/0,s=1/0,l=-1/0;for(const h of n)o=Math.min(o,h.from.row,h.to.row),i=Math.max(i,h.from.row,h.to.row),s=Math.min(s,h.from.col,h.to.col),l=Math.max(l,h.from.col,h.to.col);let a,c=null;e?.columns?r=y(this.columns,e.columns):n.length&&"row"!==t?.mode?(r=y(this.visibleColumns.slice(s,l+1)),c=r.map(e=>this.visibleColumns.indexOf(e))):r=y(this.columns);let u=null;if(e?.rowIndices)a=function(e,t){return t?.length?[...t].sort((e,t)=>e-t).map(t=>e[t]).filter(e=>null!=e):e}(this.rows,e.rowIndices);else if(n.length){const e="row"===t?.mode,r=e=>n.some(t=>e>=Math.min(t.from.row,t.to.row)&&e<=Math.max(t.from.row,t.to.row));a=[],u=[];for(let t=o;t<=i;t++){const n=this.rows[t];n&&(e&&!r(t)||(a.push(n),u.push(t)))}}else a=this.rows;const d=u,f=c;return{columns:r,rows:a,contains:d&&f?(e,t)=>{const r=d[e],o=f[t];return n.some(e=>r>=Math.min(e.from.row,e.to.row)&&r<=Math.max(e.from.row,e.to.row)&&o>=Math.min(e.from.col,e.to.col)&&o<=Math.max(e.from.col,e.to.col))}:null}}#f(e,t,n,r){return this.#h(this.#p(e,t,n,r),n)}#p(e,t,n,r){const o=n?.includeHeaders??this.config.includeHeaders??!1,i=n?.processCell??this.config.processCell;return{header:o?e.map(e=>e.header||e.field):null,rows:t.map((t,n)=>e.map((e,o)=>{if(r&&!r(n,o))return"";const l=s(t,e);return i?i(l,e.field,t):this.#g(e,l,t)}))}}#h(e,t){const n=t?.delimiter??this.config.delimiter??"\t",r=t?.newline??this.config.newline??"\n",o=[];e.header&&o.push(e.header.join(n));for(const i of e.rows)o.push(i.join(n));return o.join(r)}#g(e,t,n){if(e.format)try{const r=e.format(t,n);return null==r?"":String(r)}catch{}if(e.renderer||e.viewRenderer){const t=this.#m(e.field,n);if(null!=t)return t}return function(e){return null==e?"":e instanceof Date?e.toISOString():"object"==typeof e?JSON.stringify(e):String(e)}(t)}#m(e,t){const n=this.gridElement;if(!n)return null;const r=this.rows.indexOf(t);if(-1===r)return null;const o=n.querySelector(`.cell[data-row="${r}"][data-field="${e}"]`);return o?o.textContent?.trim()??null:null}#s(e){const t=e.closest(".cell[data-field]");if(!t)return null;const n=t.dataset.field,r=t.dataset.row;if(!n||!r)return null;const o=parseInt(r,10);if(isNaN(o))return null;const i=this.columns.findIndex(e=>e.field===n);return-1===i?null:{row:o,col:i}}getSelectionAsText(e){const{columns:t,rows:n,contains:r}=this.#d(e);return 0===t.length||0===n.length?"":this.#f(t,n,e,r)}async copy(e){const{columns:t,rows:n,contains:r}=this.#d(e);if(0===t.length||0===n.length)return"";const o=this.#p(t,n,e,r),i=this.#h(o,e),l=n.map((e,n)=>t.map((t,o)=>r&&!r(n,o)?"":A(s(e,t)))),a=t.map(e=>e.field);return await x(i,C(o.header,o.rows,{v:1,fields:a,rows:l})),this.lastCopied={text:i,timestamp:Date.now()},this.#n={text:i,rawRows:l,fields:a},this.emit("copy",{text:i,rowCount:n.length,columnCount:t.length}),i}async copyRows(e,t){return 0===e.length?"":this.copy({...t,rowIndices:e})}async paste(){const e=await async function(){try{return await navigator.clipboard.readText()}catch{return""}}();return e?E(e,this.config):null}getLastCopied(){return this.lastCopied}};export{M as ClipboardPlugin,j as defaultPasteHandler,R as emitPasteRejected,S as resolveColumnPaste};
2
2
  //# sourceMappingURL=index.js.map
@@ -1,2 +1,2 @@
1
- var t={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};function e(t,e){return`[tbw-grid${t?`#${t}`:""}${e?`:${e}`:""}]`}function r(t,r,s,i){return`${e(s,i)} ${t}: ${r}\n\n → More info: ${function(t){return`https://toolboxjs.com/grid/errors#${t.toLowerCase()}`}(t)}`}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("")),i=(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("|"))),n=/^on\w+$/i,o=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),l=/^\s*(javascript|vbscript|data|blob):/i;function a(t){const e=document.createElement("template");return t&&"string"==typeof t&&(e.innerHTML=t,function(t){const e=[],r=t.querySelectorAll("*");for(const s of r){const t=s.tagName.toLowerCase();if(i.has(t)){e.push(s);continue}if(("svg"===t||"http://www.w3.org/2000/svg"===s.namespaceURI)&&Array.from(s.attributes).some(t=>n.test(t.name)||"href"===t.name||"xlink:href"===t.name)){e.push(s);continue}const r=[];for(const e of s.attributes){const t=e.name.toLowerCase();n.test(t)?r.push(e.name):"is"!==t?(o.has(t)&&l.test(e.value)||"style"===t&&/expression\s*\(|javascript:|behavior\s*:/i.test(e.value))&&r.push(e.name):r.push(e.name)}r.forEach(t=>s.removeAttribute(t))}e.forEach(t=>t.remove())}(e.content)),e.content}var c=class{static dependencies;static manifest;aliases;version="3.8.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},s={};for(const r of Object.keys(e))s[r]=this;for(const i of t){const t=i.userConfig;for(const[n,o]of Object.entries(t)){if(void 0===o)continue;if(!(n in e)){e[n]=o,s[n]=i;continue}if(e[n]===o)continue;const t=s[n]?.constructor.name??this.constructor.name,l=i.constructor.name,a=r("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${n}" supplied by both ${t} and ${l}. Pass the option on a single instance, or remove the duplicate.`,void 0,this.name);throw new Error(a)}}Object.assign(this.userConfig,e)}refreshUserConfigFrom(t){const e=this.userConfig,r={...t.userConfig};for(const s of Object.keys(e))delete e[s];Object.assign(e,r)}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 r=new CustomEvent(t,{detail:e,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(r),r.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 r=this.grid?.query?.(t,e);return Array.isArray(r)?r.some(Boolean):!!r}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 e=this.grid?.gridConfig?.icons??{};return{...t,...e}}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(),r=parseInt(e,10);if(!isNaN(r))return r}return 200}setIcon(t,e,r){t.dataset.icon=e.replace(/([A-Z])/g,"-$1").toLowerCase(),"collapse"===e?t.dataset.expanded="":"expand"===e&&delete t.dataset.expanded;const s=this.#e(e,r);var i,n;void 0!==s?"string"==typeof s?(i=t,(n=s)&&"string"==typeof n?-1!==n.indexOf("<")||-1!==n.indexOf("&")?i.replaceChildren(a(n)):i.textContent=n:i.replaceChildren()):s instanceof HTMLElement&&t.replaceChildren(s.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 r=document.createElement("span");r.setAttribute("part","sort-indicator"),r.className="sort-indicator",e?(t.setAttribute("aria-sort","asc"===e?"ascending":"descending"),t.setAttribute("data-sort",e),this.setIcon(r,"asc"===e?"sortAsc":"sortDesc")):(t.setAttribute("aria-sort","none"),t.removeAttribute("data-sort"),this.setIcon(r,"sortNone"));const s=t.querySelector(".tbw-filter-btn")??t.querySelector(".resize-handle");return s?t.insertBefore(r,s):t.appendChild(r),r}warn(t,s){void 0!==s?console.warn(r(t,s,this.gridElement.id,this.name)):console.warn(`${e(this.gridElement.id,this.name)} ${t}`)}throwDiagnostic(t,e){throw new Error(r(t,e,this.gridElement.id,this.name))}};function u(t){if(null==t)return 100;if("number"==typeof t)return t;const e=parseFloat(t);return isNaN(e)?100:e}function h(t){return t.map(t=>u(t.width))}function d(t){const e=[];let r=0;for(const s of t)e.push(r),r+=u(s.width);return e}function f(t){return t.reduce((t,e)=>t+u(e.width),0)}function g(t,e,r,s,i){const n=r.length;if(0===n)return{startCol:0,endCol:0,visibleColumns:[]};let o=function(t,e,r){let s=0,i=e.length-1;for(;s<i;){const n=Math.floor((s+i)/2);e[n]+r[n]<=t?s=n+1:i=n}return s}(t,r,s);o=Math.max(0,o-i);const l=t+e;let a=o;for(let u=o;u<n;u++){if(r[u]>=l){a=u-1;break}a=u}a=Math.min(n-1,a+i);const c=[];for(let u=o;u<=a;u++)c.push(u);return{startCol:o,endCol:a,visibleColumns:c}}var m=class extends c{name="columnVirtualization";get defaultConfig(){return{autoEnable:!0,threshold:30,overscan:3}}isVirtualized=!1;startCol=0;endCol=0;scrollLeft=0;totalWidth=0;columnWidths=[];columnOffsets=[];originalColumns=[];attach(t){super.attach(t);const e=this.columns;this.columnWidths=h(e),this.columnOffsets=d(e),this.totalWidth=f(e),this.endCol=e.length-1}detach(){this.#r(),this.columnWidths=[],this.columnOffsets=[],this.originalColumns=[],this.isVirtualized=!1,this.startCol=0,this.endCol=0,this.scrollLeft=0,this.totalWidth=0}#r(){const t=this.gridElement;if(!t)return;const e=t.querySelector(".header-row");e&&(e.style.paddingLeft="",e.style.minWidth=""),t.querySelectorAll(".data-grid-row").forEach(t=>{t.style.paddingLeft=""});const r=t.querySelector(".rows-viewport .rows");r&&(r.style.width="");const s=t.querySelector(".rows-body");s&&(s.style.minWidth="")}processColumns(t){(0===this.originalColumns.length||t.length>=this.originalColumns.length)&&(this.originalColumns=t,this.columnWidths=h(t),this.columnOffsets=d(t),this.totalWidth=f(t));const e=this.originalColumns,r=(s=e.length,i=this.config.threshold??30,!!(this.config.autoEnable??!0)&&s>i);var s,i;if(this.isVirtualized=r??!1,!r)return this.startCol=0,this.endCol=e.length-1,[...e];const n=this.grid?.clientWidth||800,o=g(this.scrollLeft,n,this.columnOffsets,this.columnWidths,this.config.overscan??3);return this.startCol=o.startCol,this.endCol=o.endCol,o.visibleColumns.map(t=>e[t])}afterRender(){if(!this.isVirtualized)return;const t=this.gridElement;if(!t)return;const e=this.columnOffsets[this.startCol]??0,r=t.querySelector(".header-row"),s=t.querySelectorAll(".data-grid-row");r&&(r.style.paddingLeft=`${e}px`,r.style.minWidth=`${this.totalWidth}px`),s.forEach(t=>{t.style.paddingLeft=`${e}px`});const i=t.querySelector(".rows-viewport .rows");i&&(i.style.width=`${this.totalWidth}px`);const n=t.querySelector(".rows-body");n&&(n.style.minWidth=`${this.totalWidth}px`)}onScroll(t){this.isVirtualized&&(Math.abs(t.scrollLeft-this.scrollLeft)<1||(this.scrollLeft=t.scrollLeft,this.requestColumnsRender()))}getIsVirtualized(){return this.isVirtualized}getVisibleColumnRange(){return{start:this.startCol,end:this.endCol}}scrollToColumn(t){const e=this.columnOffsets[t]??0,r=this.gridElement;r&&(r.scrollLeft=e)}getColumnOffset(t){return this.columnOffsets[t]??0}getTotalWidth(){return this.totalWidth}};export{m as ColumnVirtualizationPlugin};
1
+ var t={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};function e(t,e){return`[tbw-grid${t?`#${t}`:""}${e?`:${e}`:""}]`}function r(t,r,s,i){return`${e(s,i)} ${t}: ${r}\n\n → More info: ${function(t){return`https://toolboxjs.com/grid/errors#${t.toLowerCase()}`}(t)}`}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("")),i=(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("|"))),n=/^on\w+$/i,o=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),l=/^\s*(javascript|vbscript|data|blob):/i;function a(t){const e=document.createElement("template");return t&&"string"==typeof t&&(e.innerHTML=t,function(t){const e=[],r=t.querySelectorAll("*");for(const s of r){const t=s.tagName.toLowerCase();if(i.has(t)){e.push(s);continue}if(("svg"===t||"http://www.w3.org/2000/svg"===s.namespaceURI)&&Array.from(s.attributes).some(t=>n.test(t.name)||"href"===t.name||"xlink:href"===t.name)){e.push(s);continue}const r=[];for(const e of s.attributes){const t=e.name.toLowerCase();n.test(t)?r.push(e.name):"is"!==t?(o.has(t)&&l.test(e.value)||"style"===t&&/expression\s*\(|javascript:|behavior\s*:/i.test(e.value))&&r.push(e.name):r.push(e.name)}r.forEach(t=>s.removeAttribute(t))}e.forEach(t=>t.remove())}(e.content)),e.content}var c=class{static dependencies;static manifest;aliases;version="3.8.2";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},s={};for(const r of Object.keys(e))s[r]=this;for(const i of t){const t=i.userConfig;for(const[n,o]of Object.entries(t)){if(void 0===o)continue;if(!(n in e)){e[n]=o,s[n]=i;continue}if(e[n]===o)continue;const t=s[n]?.constructor.name??this.constructor.name,l=i.constructor.name,a=r("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${n}" supplied by both ${t} and ${l}. Pass the option on a single instance, or remove the duplicate.`,void 0,this.name);throw new Error(a)}}Object.assign(this.userConfig,e)}refreshUserConfigFrom(t){const e=this.userConfig,r={...t.userConfig};for(const s of Object.keys(e))delete e[s];Object.assign(e,r)}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 r=new CustomEvent(t,{detail:e,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(r),r.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 r=this.grid?.query?.(t,e);return Array.isArray(r)?r.some(Boolean):!!r}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 e=this.grid?.gridConfig?.icons??{};return{...t,...e}}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(),r=parseInt(e,10);if(!isNaN(r))return r}return 200}setIcon(t,e,r){t.dataset.icon=e.replace(/([A-Z])/g,"-$1").toLowerCase(),"collapse"===e?t.dataset.expanded="":"expand"===e&&delete t.dataset.expanded;const s=this.#e(e,r);var i,n;void 0!==s?"string"==typeof s?(i=t,(n=s)&&"string"==typeof n?-1!==n.indexOf("<")||-1!==n.indexOf("&")?i.replaceChildren(a(n)):i.textContent=n:i.replaceChildren()):s instanceof HTMLElement&&t.replaceChildren(s.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 r=document.createElement("span");r.setAttribute("part","sort-indicator"),r.className="sort-indicator",e?(t.setAttribute("aria-sort","asc"===e?"ascending":"descending"),t.setAttribute("data-sort",e),this.setIcon(r,"asc"===e?"sortAsc":"sortDesc")):(t.setAttribute("aria-sort","none"),t.removeAttribute("data-sort"),this.setIcon(r,"sortNone"));const s=t.querySelector(".tbw-filter-btn")??t.querySelector(".resize-handle");return s?t.insertBefore(r,s):t.appendChild(r),r}warn(t,s){void 0!==s?console.warn(r(t,s,this.gridElement.id,this.name)):console.warn(`${e(this.gridElement.id,this.name)} ${t}`)}throwDiagnostic(t,e){throw new Error(r(t,e,this.gridElement.id,this.name))}};function u(t){if(null==t)return 100;if("number"==typeof t)return t;const e=parseFloat(t);return isNaN(e)?100:e}function h(t){return t.map(t=>u(t.width))}function d(t){const e=[];let r=0;for(const s of t)e.push(r),r+=u(s.width);return e}function f(t){return t.reduce((t,e)=>t+u(e.width),0)}function g(t,e,r,s,i){const n=r.length;if(0===n)return{startCol:0,endCol:0,visibleColumns:[]};let o=function(t,e,r){let s=0,i=e.length-1;for(;s<i;){const n=Math.floor((s+i)/2);e[n]+r[n]<=t?s=n+1:i=n}return s}(t,r,s);o=Math.max(0,o-i);const l=t+e;let a=o;for(let u=o;u<n;u++){if(r[u]>=l){a=u-1;break}a=u}a=Math.min(n-1,a+i);const c=[];for(let u=o;u<=a;u++)c.push(u);return{startCol:o,endCol:a,visibleColumns:c}}var m=class extends c{name="columnVirtualization";get defaultConfig(){return{autoEnable:!0,threshold:30,overscan:3}}isVirtualized=!1;startCol=0;endCol=0;scrollLeft=0;totalWidth=0;columnWidths=[];columnOffsets=[];originalColumns=[];attach(t){super.attach(t);const e=this.columns;this.columnWidths=h(e),this.columnOffsets=d(e),this.totalWidth=f(e),this.endCol=e.length-1}detach(){this.#r(),this.columnWidths=[],this.columnOffsets=[],this.originalColumns=[],this.isVirtualized=!1,this.startCol=0,this.endCol=0,this.scrollLeft=0,this.totalWidth=0}#r(){const t=this.gridElement;if(!t)return;const e=t.querySelector(".header-row");e&&(e.style.paddingLeft="",e.style.minWidth=""),t.querySelectorAll(".data-grid-row").forEach(t=>{t.style.paddingLeft=""});const r=t.querySelector(".rows-viewport .rows");r&&(r.style.width="");const s=t.querySelector(".rows-body");s&&(s.style.minWidth="")}processColumns(t){(0===this.originalColumns.length||t.length>=this.originalColumns.length)&&(this.originalColumns=t,this.columnWidths=h(t),this.columnOffsets=d(t),this.totalWidth=f(t));const e=this.originalColumns,r=(s=e.length,i=this.config.threshold??30,!!(this.config.autoEnable??!0)&&s>i);var s,i;if(this.isVirtualized=r??!1,!r)return this.startCol=0,this.endCol=e.length-1,[...e];const n=this.grid?.clientWidth||800,o=g(this.scrollLeft,n,this.columnOffsets,this.columnWidths,this.config.overscan??3);return this.startCol=o.startCol,this.endCol=o.endCol,o.visibleColumns.map(t=>e[t])}afterRender(){if(!this.isVirtualized)return;const t=this.gridElement;if(!t)return;const e=this.columnOffsets[this.startCol]??0,r=t.querySelector(".header-row"),s=t.querySelectorAll(".data-grid-row");r&&(r.style.paddingLeft=`${e}px`,r.style.minWidth=`${this.totalWidth}px`),s.forEach(t=>{t.style.paddingLeft=`${e}px`});const i=t.querySelector(".rows-viewport .rows");i&&(i.style.width=`${this.totalWidth}px`);const n=t.querySelector(".rows-body");n&&(n.style.minWidth=`${this.totalWidth}px`)}onScroll(t){this.isVirtualized&&(Math.abs(t.scrollLeft-this.scrollLeft)<1||(this.scrollLeft=t.scrollLeft,this.requestColumnsRender()))}getIsVirtualized(){return this.isVirtualized}getVisibleColumnRange(){return{start:this.startCol,end:this.endCol}}scrollToColumn(t){const e=this.columnOffsets[t]??0,r=this.gridElement;r&&(r.scrollLeft=e)}getColumnOffset(t){return this.columnOffsets[t]??0}getTotalWidth(){return this.totalWidth}};export{m as ColumnVirtualizationPlugin};
2
2
  //# sourceMappingURL=index.js.map
@@ -1,2 +1,2 @@
1
- var e={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};function t(e,t){return`[tbw-grid${e?`#${e}`:""}${t?`:${t}`:""}]`}function n(e,n,o,r){return`${t(o,r)} ${e}: ${n}\n\n → More info: ${function(e){return`https://toolboxjs.com/grid/errors#${e.toLowerCase()}`}(e)}`}var o="__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(e=>e.split("").reverse().join("")),r=(new RegExp(`__(proto|defineGetter|defineSetter)|${o.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("|"))),s=/^on\w+$/i,i=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),a=/^\s*(javascript|vbscript|data|blob):/i;function c(e){const t=document.createElement("template");return e&&"string"==typeof e&&(t.innerHTML=e,function(e){const t=[],n=e.querySelectorAll("*");for(const o of n){const e=o.tagName.toLowerCase();if(r.has(e)){t.push(o);continue}if(("svg"===e||"http://www.w3.org/2000/svg"===o.namespaceURI)&&Array.from(o.attributes).some(e=>s.test(e.name)||"href"===e.name||"xlink:href"===e.name)){t.push(o);continue}const n=[];for(const t of o.attributes){const e=t.name.toLowerCase();s.test(e)?n.push(t.name):"is"!==e?(i.has(e)&&a.test(t.value)||"style"===e&&/expression\s*\(|javascript:|behavior\s*:/i.test(t.value))&&n.push(t.name):n.push(t.name)}n.forEach(e=>o.removeAttribute(e))}t.forEach(e=>e.remove())}(t.content)),t.content}function l(e,t){t&&"string"==typeof t?-1!==t.indexOf("<")||-1!==t.indexOf("&")?e.replaceChildren(c(t)):e.textContent=t:e.replaceChildren()}function u(e){return e.replace(/([A-Z])/g,"-$1").toLowerCase()}var d=class{static dependencies;static manifest;aliases;version="3.8.0";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#e;get defaultConfig(){return{}}constructor(e={}){this.userConfig=e}get resolvedConfig(){return this.#e?this.config:{...this.defaultConfig,...this.userConfig}}mergeConfigsFrom(e){if(0===e.length)return;const t={...this.userConfig},o={};for(const n of Object.keys(t))o[n]=this;for(const r of e){const e=r.userConfig;for(const[s,i]of Object.entries(e)){if(void 0===i)continue;if(!(s in t)){t[s]=i,o[s]=r;continue}if(t[s]===i)continue;const e=o[s]?.constructor.name??this.constructor.name,a=r.constructor.name,c=n("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${s}" supplied by both ${e} 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,t)}refreshUserConfigFrom(e){const t=this.userConfig,n={...e.userConfig};for(const o of Object.keys(t))delete t[o];Object.assign(t,n)}attach(e){this.#e?.abort(),this.#e=new AbortController,this.grid=e,this.config={...this.defaultConfig,...this.userConfig}}detach(){this.#e?.abort(),this.#e=void 0}getPlugin(e){return this.grid?.getPlugin(e)}emit(e,t){this.grid?.dispatchEvent?.(new CustomEvent(e,{detail:t,bubbles:!0}))}emitCancelable(e,t){const n=new CustomEvent(e,{detail:t,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(n),n.defaultPrevented}on(e,t){this.grid?._pluginManager?.subscribe(this,e,t)}off(e){this.grid?._pluginManager?.unsubscribe(this,e)}emitPluginEvent(e,t){this.grid?._pluginManager?.emitPluginEvent(e,t)}broadcast(e,t){this.emitPluginEvent(e,t),this.emit(e,t)}queryBoolean(e,t=null){const n=this.grid?.query?.(e,t);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.#e?.signal??this.grid?.disconnectSignal}get gridIcons(){const t=this.grid?.gridConfig?.icons??{};return{...e,...t}}t(e,t){return this.grid?.effectiveConfig?.locale?.[e]??t}get translate(){return(e,t)=>this.t(e,t)}get isAnimationEnabled(){const e=this.grid?.effectiveConfig?.animation?.mode??"reduced-motion";if(!1===e||"off"===e)return!1;if(!0===e||"on"===e)return!0;const t=this.gridElement;return!t||"0"!==getComputedStyle(t).getPropertyValue("--tbw-animation-enabled").trim()}get animationDuration(){const e=this.gridElement;if(e){const t=getComputedStyle(e).getPropertyValue("--tbw-animation-duration").trim(),n=parseInt(t,10);if(!isNaN(n))return n}return 200}setIcon(e,t,n){e.dataset.icon=u(t),"collapse"===t?e.dataset.expanded="":"expand"===t&&delete e.dataset.expanded;const o=this.#t(t,n);void 0!==o?"string"==typeof o?l(e,o):o instanceof HTMLElement&&e.replaceChildren(o.cloneNode(!0)):e.innerHTML=""}#t(e,t){return void 0!==t?t:this.grid?.gridConfig?.icons?.[e]}updateSortIndicator(e,t){e.querySelector('[part~="sort-indicator"], .sort-indicator')?.remove();const n=document.createElement("span");n.setAttribute("part","sort-indicator"),n.className="sort-indicator",t?(e.setAttribute("aria-sort","asc"===t?"ascending":"descending"),e.setAttribute("data-sort",t),this.setIcon(n,"asc"===t?"sortAsc":"sortDesc")):(e.setAttribute("aria-sort","none"),e.removeAttribute("data-sort"),this.setIcon(n,"sortNone"));const o=e.querySelector(".tbw-filter-btn")??e.querySelector(".resize-handle");return o?e.insertBefore(n,o):e.appendChild(n),n}warn(e,o){void 0!==o?console.warn(n(e,o,this.gridElement.id,this.name)):console.warn(`${t(this.gridElement.id,this.name)} ${e}`)}throwDiagnostic(e,t){throw new Error(n(e,t,this.gridElement.id,this.name))}};function m(e,t){return("function"==typeof e?e(t):e).filter(e=>!0!==e.hidden&&("function"!=typeof e.hidden||!e.hidden(t)))}function h(e,t){return!0===e.disabled||"function"==typeof e.disabled&&e.disabled(t)}function b(e,t,n,o){const r=document.createElement("div");r.className="tbw-context-menu",r.setAttribute("role","menu");const s=e.some(e=>!e.separator&&e.icon);for(const i of e){if(i.separator){const e=document.createElement("div");e.className="tbw-context-menu-separator",e.setAttribute("role","separator"),r.appendChild(e);continue}const e=document.createElement("div");e.className="tbw-context-menu-item",i.cssClass&&e.classList.add(i.cssClass),e.setAttribute("role","menuitem"),e.setAttribute("data-id",i.id),e.setAttribute("tabindex","-1");const a=h(i,t);if(a&&(e.classList.add("disabled"),e.setAttribute("aria-disabled","true")),i.icon){const t=document.createElement("span");t.className="tbw-context-menu-icon",l(t,i.icon),e.appendChild(t)}else if(s){const t=document.createElement("span");t.className="tbw-context-menu-icon",t.innerHTML="&nbsp;",e.appendChild(t)}const c=document.createElement("span");if(c.className="tbw-context-menu-label",c.textContent=i.name,e.appendChild(c),i.shortcut){const t=document.createElement("span");if(t.className="tbw-context-menu-shortcut",Array.isArray(i.shortcut))i.shortcut.forEach((e,n)=>{n>0&&t.appendChild(document.createTextNode("+"));const o=document.createElement("kbd");o.textContent=e,t.appendChild(o)});else{const e=document.createElement("kbd");e.textContent=i.shortcut,t.appendChild(e)}e.appendChild(t)}if(i.subMenu?.length){const r=document.createElement("span");r.className="tbw-context-menu-arrow",r.dataset.icon=u("submenuArrow"),void 0!==o&&("string"==typeof o?l(r,o):o instanceof HTMLElement&&r.appendChild(o.cloneNode(!0))),e.appendChild(r),e.addEventListener("mouseenter",()=>{if(e.querySelector(".tbw-context-menu"))return;if(!i.subMenu)return;const r=b(m(i.subMenu,t),t,n,o);r.classList.add("tbw-context-submenu"),r.style.position="absolute",r.style.left="100%",r.style.top="0",e.style.position="relative",e.appendChild(r)}),e.addEventListener("mouseleave",()=>{const t=e.querySelector(".tbw-context-menu");t&&t.remove()})}a||!i.action||i.subMenu||e.addEventListener("click",e=>{e.stopPropagation(),n(i)}),r.appendChild(e)}return r}var p="getContextMenuItems",f=null,g=null,w=0,v=/* @__PURE__ */new Set,x=[{id:"copy",name:"Copy",shortcut:"Ctrl+C",action:e=>{e.grid?.query?.("clipboard:copy")}},{separator:!0,id:"sep1",name:""},{id:"export-csv",name:"Export CSV",action:e=>{e.grid?.query?.("export:csv")}}],C=class e extends d{static manifest={queries:[{type:p,description:"Collects context menu items from other plugins for header right-click menus"}]};name="contextMenu";get defaultConfig(){return{items:x}}isOpen=!1;position={x:0,y:0};params=null;menuElement=null;boundHost=null;attach(e){super.attach(e),this.installGlobalHandlers(),w++,v.add(this)}detach(){this.menuElement&&(this.menuElement.remove(),this.menuElement=null),this.isOpen=!1,this.params=null,this.boundHost=null,v.delete(this),this.uninstallGlobalHandlers()}syncSelectionOnContextMenu(e){if(e<0)return[];const t=(this.grid?.query("getSelectedRowIndices"))?.[0];return t?t.includes(e)?t:(this.grid?.query("selectRows",[e]),[e]):[e]}static CSS_VARS_TO_COPY=["--tbw-color-panel-bg","--tbw-color-fg","--tbw-color-fg-muted","--tbw-color-border","--tbw-color-row-hover","--tbw-color-shadow","--tbw-color-danger","--tbw-border-radius","--tbw-font-family","--tbw-font-size-sm","--tbw-font-size-xs","--tbw-font-size-2xs","--tbw-spacing-xs","--tbw-icon-size","--tbw-menu-min-width","--tbw-menu-item-padding","--tbw-menu-item-gap","--tbw-context-menu-bg","--tbw-context-menu-fg","--tbw-context-menu-border","--tbw-context-menu-radius","--tbw-context-menu-shadow","--tbw-context-menu-hover","--tbw-context-menu-danger","--tbw-context-menu-muted","--tbw-context-menu-min-width","--tbw-context-menu-font-size","--tbw-context-menu-font-family","--tbw-context-menu-item-padding","--tbw-context-menu-item-gap","--tbw-context-menu-icon-size","--tbw-context-menu-shortcut-size","--tbw-context-menu-arrow-size","--tbw-icon-submenu-arrow"];copyGridStyles(t){const n=this.gridElement;if(!n)return;const o=getComputedStyle(n),r=[],s=o.getPropertyValue("color-scheme").trim();s&&r.push(`color-scheme: ${s}`);for(const i of e.CSS_VARS_TO_COPY){const e=o.getPropertyValue(i).trim();e&&r.push(`${i}: ${e}`)}if(r.length>0){const e=t.getAttribute("style")||"";t.setAttribute("style",e+r.join("; ")+";")}}installGlobalHandlers(){if(g||"undefined"==typeof document||((g=document.createElement("style")).id="tbw-context-menu-styles",g.textContent="@layer tbw-plugins{.tbw-context-menu{background:var(--tbw-context-menu-bg,var(--tbw-color-panel-bg));color:var(--tbw-context-menu-fg,var(--tbw-color-fg));border:1px solid var(--tbw-context-menu-border,var(--tbw-color-border));border-radius:var(--tbw-context-menu-radius,var(--tbw-border-radius));box-shadow:var(--tbw-context-menu-shadow,0 2px 10px var(--tbw-color-shadow));min-width:var(--tbw-context-menu-min-width,var(--tbw-menu-min-width));padding:var(--tbw-spacing-xs) 0;z-index:10000;font-size:var(--tbw-context-menu-font-size,var(--tbw-font-size-sm));font-family:var(--tbw-context-menu-font-family,var(--tbw-font-family));position:fixed}.tbw-context-menu-item{padding:var(--tbw-context-menu-item-padding,var(--tbw-menu-item-padding));cursor:pointer;align-items:center;gap:var(--tbw-context-menu-item-gap,var(--tbw-menu-item-gap));display:flex}.tbw-context-menu-item:hover:not(.disabled){background:var(--tbw-context-menu-hover,var(--tbw-color-row-hover))}.tbw-context-menu-item.disabled{opacity:.5;cursor:default}.tbw-context-menu-item.danger{color:var(--tbw-context-menu-danger,var(--tbw-color-danger))}.tbw-context-menu-icon{width:var(--tbw-context-menu-icon-size,var(--tbw-icon-size));text-align:center}.tbw-context-menu-label{flex:1}.tbw-context-menu-shortcut kbd{color:var(--tbw-context-menu-muted,var(--tbw-color-fg-muted));font-size:var(--tbw-context-menu-shortcut-size,var(--tbw-font-size-xs))}.tbw-context-menu-arrow{font-size:var(--tbw-context-menu-arrow-size,var(--tbw-font-size-2xs));color:var(--tbw-context-menu-muted,var(--tbw-color-fg-muted))}.tbw-context-menu-separator{background:var(--tbw-context-menu-border,var(--tbw-color-border));height:1px;margin:var(--tbw-spacing-xs) 0}}",document.head.appendChild(g)),!f){const e=(f=new AbortController).signal,t=()=>{for(const e of v)e.isMenuOpen()&&e.hideMenu();document.querySelectorAll(".tbw-context-menu").forEach(e=>e.remove())};document.addEventListener("click",t,{signal:e}),document.addEventListener("keydown",e=>{"Escape"===e.key&&t()},{signal:e}),document.addEventListener("scroll",t,{capture:!0,signal:e})}}uninstallGlobalHandlers(){--w>0||(f&&(f.abort(),f=null),g&&(g.remove(),g=null))}collectPluginItems(e){if(!this.grid)return[];const t=this.grid.query(p,e),n=[];for(const o of t)Array.isArray(o)&&n.push(...o);return n.sort((e,t)=>(e.order??100)-(t.order??100)),this.insertGroupSeparators(n)}insertGroupSeparators(e){if(e.length<=1)return e;const t=[];let n=-1;for(const o of e){if(o.separator){t.push(o);continue}const e=Math.floor((o.order??100)/10);n>=0&&e!==n&&t.push({id:`__sep-${n}-${e}`,label:"",separator:!0,action:()=>{}}),n=e,t.push(o)}return t}convertPluginItems(e){return e.map(e=>({id:e.id,name:e.label,icon:e.icon,shortcut:e.shortcut,disabled:e.disabled??!1,action:()=>e.action(),separator:e.separator,cssClass:e.cssClass}))}openMenuAt(e,t,n,o=!1){this.params=e,this.position={x:t,y:n};const r=this.collectPluginItems(e);let s=m(this.config.items??x,e);if(r.length>0){const e=this.convertPluginItems(r);s=s.length>0&&e.length>0?[...s,{id:"__plugin-sep",name:"",separator:!0},...e]:[...s,...e]}var i,a;(s=function(e){const t=[];for(const n of e)n.separator&&(0===t.length||t[t.length-1].separator)||t.push(n);return t.length>0&&t[t.length-1].separator&&t.pop(),t}(s),s.length)&&(document.querySelectorAll(".tbw-context-menu").forEach(e=>e.remove()),this.menuElement=null,this.menuElement=b(s,e,t=>{t.action&&t.action(e),this.hideMenu()},this.grid?.gridConfig?.icons?.submenuArrow),i=this.menuElement,a=()=>this.hideMenu(),i.addEventListener("keydown",e=>{const t=Array.from(i.querySelectorAll('[role="menuitem"]:not(.disabled)'));if(!t.length)return;const n=document.activeElement,o=t.indexOf(n);switch(e.key){case"ArrowDown":e.preventDefault(),t[o<t.length-1?o+1:0].focus();break;case"ArrowUp":e.preventDefault(),t[o>0?o-1:t.length-1].focus();break;case"Enter":case" ":e.preventDefault(),n&&t.includes(n)&&n.click();break;case"Escape":e.preventDefault(),a()}}),document.body.appendChild(this.menuElement),this.copyGridStyles(this.menuElement),function(e,t,n){e.style.position="fixed",e.style.left=`${t}px`,e.style.top=`${n}px`,e.style.visibility="hidden",e.style.zIndex="10000";const o=e.getBoundingClientRect(),r=window.innerWidth,s=window.innerHeight;let i=t,a=n;t+o.width>r&&(i=t-o.width),n+o.height>s&&(a=n-o.height),i=Math.max(0,i),a=Math.max(0,a),e.style.left=`${i}px`,e.style.top=`${a}px`,e.style.visibility="visible"}(this.menuElement,t,n),this.isOpen=!0,o&&function(e){e.querySelector('[role="menuitem"]:not(.disabled)')?.focus()}(this.menuElement),this.emit("context-menu-open",{params:e,items:s}))}openMenuAtFocusedCell(e){const t=this.grid;if(!t)return!1;const n=t._focusRow,o=t._focusCol;if(n<0||o<0)return!1;const r=this.visibleColumns[o],s=this.rows[n],i=this.gridElement?.querySelector(`[data-row="${n}"][data-col="${o}"]`);let a=0,c=0;if(i){const e=i.getBoundingClientRect();a=e.left+e.width/2,c=e.bottom}const l=this.syncSelectionOnContextMenu(n);return this.openMenuAt({row:s,rowIndex:n,column:r,columnIndex:o,field:r?.field??"",value:s?.[r?.field]??null,isHeader:!1,event:e,selectedRows:l},a,c,!0),!0}handleContextMenu=e=>{const t=e;t.preventDefault();const n=t.target,o=n?.closest("[data-row][data-col]"),r=n?.closest('[part~="header-cell"]');let s;if(o){const e=parseInt(o.getAttribute("data-row")??"-1",10),n=parseInt(o.getAttribute("data-col")??"-1",10),r=this.visibleColumns[n],i=this.rows[e],a=this.syncSelectionOnContextMenu(e);s={row:i,rowIndex:e,column:r,columnIndex:n,field:r?.field??"",value:i?.[r?.field]??null,isHeader:!1,event:t,selectedRows:a}}else{if(!r)return void(-1===t.button&&t.target===this.boundHost&&this.openMenuAtFocusedCell(t));{const e=parseInt(r.getAttribute("data-col")??"-1",10),n=this.visibleColumns[e];s={row:null,rowIndex:-1,column:n,columnIndex:e,field:n?.field??"",value:null,isHeader:!0,event:t,selectedRows:[]}}}this.openMenuAt(s,t.clientX,t.clientY)};afterRender(){const e=this.gridElement;e&&this.boundHost!==e&&(this.boundHost=e,e.addEventListener("contextmenu",this.handleContextMenu,{signal:this.disconnectSignal}))}onKeyDown(e){const t="F10"===e.key&&e.shiftKey,n="ContextMenu"===e.key;if((t||n)&&(e.preventDefault(),this.openMenuAtFocusedCell(e)))return!0}showMenu(e,t,n){const o={row:n.row??null,rowIndex:n.rowIndex??-1,column:n.column??null,columnIndex:n.columnIndex??-1,field:n.field??"",value:n.value??null,isHeader:n.isHeader??!1,event:n.event??new MouseEvent("contextmenu"),selectedRows:n.selectedRows??[]};this.openMenuAt(o,e,t)}hideMenu(){this.menuElement&&(this.menuElement.remove(),this.menuElement=null),this.isOpen&&(this.isOpen=!1)}isMenuOpen(){return this.isOpen}};export{C as ContextMenuPlugin};
1
+ var e={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};function t(e,t){return`[tbw-grid${e?`#${e}`:""}${t?`:${t}`:""}]`}function n(e,n,o,r){return`${t(o,r)} ${e}: ${n}\n\n → More info: ${function(e){return`https://toolboxjs.com/grid/errors#${e.toLowerCase()}`}(e)}`}var o="__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(e=>e.split("").reverse().join("")),r=(new RegExp(`__(proto|defineGetter|defineSetter)|${o.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("|"))),s=/^on\w+$/i,i=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),a=/^\s*(javascript|vbscript|data|blob):/i;function c(e){const t=document.createElement("template");return e&&"string"==typeof e&&(t.innerHTML=e,function(e){const t=[],n=e.querySelectorAll("*");for(const o of n){const e=o.tagName.toLowerCase();if(r.has(e)){t.push(o);continue}if(("svg"===e||"http://www.w3.org/2000/svg"===o.namespaceURI)&&Array.from(o.attributes).some(e=>s.test(e.name)||"href"===e.name||"xlink:href"===e.name)){t.push(o);continue}const n=[];for(const t of o.attributes){const e=t.name.toLowerCase();s.test(e)?n.push(t.name):"is"!==e?(i.has(e)&&a.test(t.value)||"style"===e&&/expression\s*\(|javascript:|behavior\s*:/i.test(t.value))&&n.push(t.name):n.push(t.name)}n.forEach(e=>o.removeAttribute(e))}t.forEach(e=>e.remove())}(t.content)),t.content}function l(e,t){t&&"string"==typeof t?-1!==t.indexOf("<")||-1!==t.indexOf("&")?e.replaceChildren(c(t)):e.textContent=t:e.replaceChildren()}function u(e){return e.replace(/([A-Z])/g,"-$1").toLowerCase()}var d=class{static dependencies;static manifest;aliases;version="3.8.2";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#e;get defaultConfig(){return{}}constructor(e={}){this.userConfig=e}get resolvedConfig(){return this.#e?this.config:{...this.defaultConfig,...this.userConfig}}mergeConfigsFrom(e){if(0===e.length)return;const t={...this.userConfig},o={};for(const n of Object.keys(t))o[n]=this;for(const r of e){const e=r.userConfig;for(const[s,i]of Object.entries(e)){if(void 0===i)continue;if(!(s in t)){t[s]=i,o[s]=r;continue}if(t[s]===i)continue;const e=o[s]?.constructor.name??this.constructor.name,a=r.constructor.name,c=n("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${s}" supplied by both ${e} 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,t)}refreshUserConfigFrom(e){const t=this.userConfig,n={...e.userConfig};for(const o of Object.keys(t))delete t[o];Object.assign(t,n)}attach(e){this.#e?.abort(),this.#e=new AbortController,this.grid=e,this.config={...this.defaultConfig,...this.userConfig}}detach(){this.#e?.abort(),this.#e=void 0}getPlugin(e){return this.grid?.getPlugin(e)}emit(e,t){this.grid?.dispatchEvent?.(new CustomEvent(e,{detail:t,bubbles:!0}))}emitCancelable(e,t){const n=new CustomEvent(e,{detail:t,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(n),n.defaultPrevented}on(e,t){this.grid?._pluginManager?.subscribe(this,e,t)}off(e){this.grid?._pluginManager?.unsubscribe(this,e)}emitPluginEvent(e,t){this.grid?._pluginManager?.emitPluginEvent(e,t)}broadcast(e,t){this.emitPluginEvent(e,t),this.emit(e,t)}queryBoolean(e,t=null){const n=this.grid?.query?.(e,t);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.#e?.signal??this.grid?.disconnectSignal}get gridIcons(){const t=this.grid?.gridConfig?.icons??{};return{...e,...t}}t(e,t){return this.grid?.effectiveConfig?.locale?.[e]??t}get translate(){return(e,t)=>this.t(e,t)}get isAnimationEnabled(){const e=this.grid?.effectiveConfig?.animation?.mode??"reduced-motion";if(!1===e||"off"===e)return!1;if(!0===e||"on"===e)return!0;const t=this.gridElement;return!t||"0"!==getComputedStyle(t).getPropertyValue("--tbw-animation-enabled").trim()}get animationDuration(){const e=this.gridElement;if(e){const t=getComputedStyle(e).getPropertyValue("--tbw-animation-duration").trim(),n=parseInt(t,10);if(!isNaN(n))return n}return 200}setIcon(e,t,n){e.dataset.icon=u(t),"collapse"===t?e.dataset.expanded="":"expand"===t&&delete e.dataset.expanded;const o=this.#t(t,n);void 0!==o?"string"==typeof o?l(e,o):o instanceof HTMLElement&&e.replaceChildren(o.cloneNode(!0)):e.innerHTML=""}#t(e,t){return void 0!==t?t:this.grid?.gridConfig?.icons?.[e]}updateSortIndicator(e,t){e.querySelector('[part~="sort-indicator"], .sort-indicator')?.remove();const n=document.createElement("span");n.setAttribute("part","sort-indicator"),n.className="sort-indicator",t?(e.setAttribute("aria-sort","asc"===t?"ascending":"descending"),e.setAttribute("data-sort",t),this.setIcon(n,"asc"===t?"sortAsc":"sortDesc")):(e.setAttribute("aria-sort","none"),e.removeAttribute("data-sort"),this.setIcon(n,"sortNone"));const o=e.querySelector(".tbw-filter-btn")??e.querySelector(".resize-handle");return o?e.insertBefore(n,o):e.appendChild(n),n}warn(e,o){void 0!==o?console.warn(n(e,o,this.gridElement.id,this.name)):console.warn(`${t(this.gridElement.id,this.name)} ${e}`)}throwDiagnostic(e,t){throw new Error(n(e,t,this.gridElement.id,this.name))}};function m(e,t){return("function"==typeof e?e(t):e).filter(e=>!0!==e.hidden&&("function"!=typeof e.hidden||!e.hidden(t)))}function h(e,t){return!0===e.disabled||"function"==typeof e.disabled&&e.disabled(t)}function b(e,t,n,o){const r=document.createElement("div");r.className="tbw-context-menu",r.setAttribute("role","menu");const s=e.some(e=>!e.separator&&e.icon);for(const i of e){if(i.separator){const e=document.createElement("div");e.className="tbw-context-menu-separator",e.setAttribute("role","separator"),r.appendChild(e);continue}const e=document.createElement("div");e.className="tbw-context-menu-item",i.cssClass&&e.classList.add(i.cssClass),e.setAttribute("role","menuitem"),e.setAttribute("data-id",i.id),e.setAttribute("tabindex","-1");const a=h(i,t);if(a&&(e.classList.add("disabled"),e.setAttribute("aria-disabled","true")),i.icon){const t=document.createElement("span");t.className="tbw-context-menu-icon",l(t,i.icon),e.appendChild(t)}else if(s){const t=document.createElement("span");t.className="tbw-context-menu-icon",t.innerHTML="&nbsp;",e.appendChild(t)}const c=document.createElement("span");if(c.className="tbw-context-menu-label",c.textContent=i.name,e.appendChild(c),i.shortcut){const t=document.createElement("span");if(t.className="tbw-context-menu-shortcut",Array.isArray(i.shortcut))i.shortcut.forEach((e,n)=>{n>0&&t.appendChild(document.createTextNode("+"));const o=document.createElement("kbd");o.textContent=e,t.appendChild(o)});else{const e=document.createElement("kbd");e.textContent=i.shortcut,t.appendChild(e)}e.appendChild(t)}if(i.subMenu?.length){const r=document.createElement("span");r.className="tbw-context-menu-arrow",r.dataset.icon=u("submenuArrow"),void 0!==o&&("string"==typeof o?l(r,o):o instanceof HTMLElement&&r.appendChild(o.cloneNode(!0))),e.appendChild(r),e.addEventListener("mouseenter",()=>{if(e.querySelector(".tbw-context-menu"))return;if(!i.subMenu)return;const r=b(m(i.subMenu,t),t,n,o);r.classList.add("tbw-context-submenu"),r.style.position="absolute",r.style.left="100%",r.style.top="0",e.style.position="relative",e.appendChild(r)}),e.addEventListener("mouseleave",()=>{const t=e.querySelector(".tbw-context-menu");t&&t.remove()})}a||!i.action||i.subMenu||e.addEventListener("click",e=>{e.stopPropagation(),n(i)}),r.appendChild(e)}return r}var p="getContextMenuItems",f=null,g=null,w=0,v=/* @__PURE__ */new Set,x=[{id:"copy",name:"Copy",shortcut:"Ctrl+C",action:e=>{e.grid?.query?.("clipboard:copy")}},{separator:!0,id:"sep1",name:""},{id:"export-csv",name:"Export CSV",action:e=>{e.grid?.query?.("export:csv")}}],C=class e extends d{static manifest={queries:[{type:p,description:"Collects context menu items from other plugins for header right-click menus"}]};name="contextMenu";get defaultConfig(){return{items:x}}isOpen=!1;position={x:0,y:0};params=null;menuElement=null;boundHost=null;attach(e){super.attach(e),this.installGlobalHandlers(),w++,v.add(this)}detach(){this.menuElement&&(this.menuElement.remove(),this.menuElement=null),this.isOpen=!1,this.params=null,this.boundHost=null,v.delete(this),this.uninstallGlobalHandlers()}syncSelectionOnContextMenu(e){if(e<0)return[];const t=(this.grid?.query("getSelectedRowIndices"))?.[0];return t?t.includes(e)?t:(this.grid?.query("selectRows",[e]),[e]):[e]}static CSS_VARS_TO_COPY=["--tbw-color-panel-bg","--tbw-color-fg","--tbw-color-fg-muted","--tbw-color-border","--tbw-color-row-hover","--tbw-color-shadow","--tbw-color-danger","--tbw-border-radius","--tbw-font-family","--tbw-font-size-sm","--tbw-font-size-xs","--tbw-font-size-2xs","--tbw-spacing-xs","--tbw-icon-size","--tbw-menu-min-width","--tbw-menu-item-padding","--tbw-menu-item-gap","--tbw-context-menu-bg","--tbw-context-menu-fg","--tbw-context-menu-border","--tbw-context-menu-radius","--tbw-context-menu-shadow","--tbw-context-menu-hover","--tbw-context-menu-danger","--tbw-context-menu-muted","--tbw-context-menu-min-width","--tbw-context-menu-font-size","--tbw-context-menu-font-family","--tbw-context-menu-item-padding","--tbw-context-menu-item-gap","--tbw-context-menu-icon-size","--tbw-context-menu-shortcut-size","--tbw-context-menu-arrow-size","--tbw-icon-submenu-arrow"];copyGridStyles(t){const n=this.gridElement;if(!n)return;const o=getComputedStyle(n),r=[],s=o.getPropertyValue("color-scheme").trim();s&&r.push(`color-scheme: ${s}`);for(const i of e.CSS_VARS_TO_COPY){const e=o.getPropertyValue(i).trim();e&&r.push(`${i}: ${e}`)}if(r.length>0){const e=t.getAttribute("style")||"";t.setAttribute("style",e+r.join("; ")+";")}}installGlobalHandlers(){if(g||"undefined"==typeof document||((g=document.createElement("style")).id="tbw-context-menu-styles",g.textContent="@layer tbw-plugins{.tbw-context-menu{background:var(--tbw-context-menu-bg,var(--tbw-color-panel-bg));color:var(--tbw-context-menu-fg,var(--tbw-color-fg));border:1px solid var(--tbw-context-menu-border,var(--tbw-color-border));border-radius:var(--tbw-context-menu-radius,var(--tbw-border-radius));box-shadow:var(--tbw-context-menu-shadow,0 2px 10px var(--tbw-color-shadow));min-width:var(--tbw-context-menu-min-width,var(--tbw-menu-min-width));padding:var(--tbw-spacing-xs) 0;z-index:10000;font-size:var(--tbw-context-menu-font-size,var(--tbw-font-size-sm));font-family:var(--tbw-context-menu-font-family,var(--tbw-font-family));position:fixed}.tbw-context-menu-item{padding:var(--tbw-context-menu-item-padding,var(--tbw-menu-item-padding));cursor:pointer;align-items:center;gap:var(--tbw-context-menu-item-gap,var(--tbw-menu-item-gap));display:flex}.tbw-context-menu-item:hover:not(.disabled){background:var(--tbw-context-menu-hover,var(--tbw-color-row-hover))}.tbw-context-menu-item.disabled{opacity:.5;cursor:default}.tbw-context-menu-item.danger{color:var(--tbw-context-menu-danger,var(--tbw-color-danger))}.tbw-context-menu-icon{width:var(--tbw-context-menu-icon-size,var(--tbw-icon-size));text-align:center}.tbw-context-menu-label{flex:1}.tbw-context-menu-shortcut kbd{color:var(--tbw-context-menu-muted,var(--tbw-color-fg-muted));font-size:var(--tbw-context-menu-shortcut-size,var(--tbw-font-size-xs))}.tbw-context-menu-arrow{font-size:var(--tbw-context-menu-arrow-size,var(--tbw-font-size-2xs));color:var(--tbw-context-menu-muted,var(--tbw-color-fg-muted))}.tbw-context-menu-separator{background:var(--tbw-context-menu-border,var(--tbw-color-border));height:1px;margin:var(--tbw-spacing-xs) 0}}",document.head.appendChild(g)),!f){const e=(f=new AbortController).signal,t=()=>{for(const e of v)e.isMenuOpen()&&e.hideMenu();document.querySelectorAll(".tbw-context-menu").forEach(e=>e.remove())};document.addEventListener("click",t,{signal:e}),document.addEventListener("keydown",e=>{"Escape"===e.key&&t()},{signal:e}),document.addEventListener("scroll",t,{capture:!0,signal:e})}}uninstallGlobalHandlers(){--w>0||(f&&(f.abort(),f=null),g&&(g.remove(),g=null))}collectPluginItems(e){if(!this.grid)return[];const t=this.grid.query(p,e),n=[];for(const o of t)Array.isArray(o)&&n.push(...o);return n.sort((e,t)=>(e.order??100)-(t.order??100)),this.insertGroupSeparators(n)}insertGroupSeparators(e){if(e.length<=1)return e;const t=[];let n=-1;for(const o of e){if(o.separator){t.push(o);continue}const e=Math.floor((o.order??100)/10);n>=0&&e!==n&&t.push({id:`__sep-${n}-${e}`,label:"",separator:!0,action:()=>{}}),n=e,t.push(o)}return t}convertPluginItems(e){return e.map(e=>({id:e.id,name:e.label,icon:e.icon,shortcut:e.shortcut,disabled:e.disabled??!1,action:()=>e.action(),separator:e.separator,cssClass:e.cssClass}))}openMenuAt(e,t,n,o=!1){this.params=e,this.position={x:t,y:n};const r=this.collectPluginItems(e);let s=m(this.config.items??x,e);if(r.length>0){const e=this.convertPluginItems(r);s=s.length>0&&e.length>0?[...s,{id:"__plugin-sep",name:"",separator:!0},...e]:[...s,...e]}var i,a;(s=function(e){const t=[];for(const n of e)n.separator&&(0===t.length||t[t.length-1].separator)||t.push(n);return t.length>0&&t[t.length-1].separator&&t.pop(),t}(s),s.length)&&(document.querySelectorAll(".tbw-context-menu").forEach(e=>e.remove()),this.menuElement=null,this.menuElement=b(s,e,t=>{t.action&&t.action(e),this.hideMenu()},this.grid?.gridConfig?.icons?.submenuArrow),i=this.menuElement,a=()=>this.hideMenu(),i.addEventListener("keydown",e=>{const t=Array.from(i.querySelectorAll('[role="menuitem"]:not(.disabled)'));if(!t.length)return;const n=document.activeElement,o=t.indexOf(n);switch(e.key){case"ArrowDown":e.preventDefault(),t[o<t.length-1?o+1:0].focus();break;case"ArrowUp":e.preventDefault(),t[o>0?o-1:t.length-1].focus();break;case"Enter":case" ":e.preventDefault(),n&&t.includes(n)&&n.click();break;case"Escape":e.preventDefault(),a()}}),document.body.appendChild(this.menuElement),this.copyGridStyles(this.menuElement),function(e,t,n){e.style.position="fixed",e.style.left=`${t}px`,e.style.top=`${n}px`,e.style.visibility="hidden",e.style.zIndex="10000";const o=e.getBoundingClientRect(),r=window.innerWidth,s=window.innerHeight;let i=t,a=n;t+o.width>r&&(i=t-o.width),n+o.height>s&&(a=n-o.height),i=Math.max(0,i),a=Math.max(0,a),e.style.left=`${i}px`,e.style.top=`${a}px`,e.style.visibility="visible"}(this.menuElement,t,n),this.isOpen=!0,o&&function(e){e.querySelector('[role="menuitem"]:not(.disabled)')?.focus()}(this.menuElement),this.emit("context-menu-open",{params:e,items:s}))}openMenuAtFocusedCell(e){const t=this.grid;if(!t)return!1;const n=t._focusRow,o=t._focusCol;if(n<0||o<0)return!1;const r=this.visibleColumns[o],s=this.rows[n],i=this.gridElement?.querySelector(`[data-row="${n}"][data-col="${o}"]`);let a=0,c=0;if(i){const e=i.getBoundingClientRect();a=e.left+e.width/2,c=e.bottom}const l=this.syncSelectionOnContextMenu(n);return this.openMenuAt({row:s,rowIndex:n,column:r,columnIndex:o,field:r?.field??"",value:s?.[r?.field]??null,isHeader:!1,event:e,selectedRows:l},a,c,!0),!0}handleContextMenu=e=>{const t=e;t.preventDefault();const n=t.target,o=n?.closest("[data-row][data-col]"),r=n?.closest('[part~="header-cell"]');let s;if(o){const e=parseInt(o.getAttribute("data-row")??"-1",10),n=parseInt(o.getAttribute("data-col")??"-1",10),r=this.visibleColumns[n],i=this.rows[e],a=this.syncSelectionOnContextMenu(e);s={row:i,rowIndex:e,column:r,columnIndex:n,field:r?.field??"",value:i?.[r?.field]??null,isHeader:!1,event:t,selectedRows:a}}else{if(!r)return void(-1===t.button&&t.target===this.boundHost&&this.openMenuAtFocusedCell(t));{const e=parseInt(r.getAttribute("data-col")??"-1",10),n=this.visibleColumns[e];s={row:null,rowIndex:-1,column:n,columnIndex:e,field:n?.field??"",value:null,isHeader:!0,event:t,selectedRows:[]}}}this.openMenuAt(s,t.clientX,t.clientY)};afterRender(){const e=this.gridElement;e&&this.boundHost!==e&&(this.boundHost=e,e.addEventListener("contextmenu",this.handleContextMenu,{signal:this.disconnectSignal}))}onKeyDown(e){const t="F10"===e.key&&e.shiftKey,n="ContextMenu"===e.key;if((t||n)&&(e.preventDefault(),this.openMenuAtFocusedCell(e)))return!0}showMenu(e,t,n){const o={row:n.row??null,rowIndex:n.rowIndex??-1,column:n.column??null,columnIndex:n.columnIndex??-1,field:n.field??"",value:n.value??null,isHeader:n.isHeader??!1,event:n.event??new MouseEvent("contextmenu"),selectedRows:n.selectedRows??[]};this.openMenuAt(o,e,t)}hideMenu(){this.menuElement&&(this.menuElement.remove(),this.menuElement=null),this.isOpen&&(this.isOpen=!1)}isMenuOpen(){return this.isOpen}};export{C as ContextMenuPlugin};
2
2
  //# sourceMappingURL=index.js.map
@@ -1,2 +1,2 @@
1
- import{readCellField as t,writeCellField as e}from"@toolbox-web/grid";var i="editing",n="data-tbw-truncated",r={sortApplied:(t,e)=>`Sorted by ${t}, ${e}`,sortCleared:()=>"Sort cleared",filterApplied:t=>`Filter applied on ${t}`,filterCleared:t=>`Filter cleared from ${t}`,allFiltersCleared:()=>"All filters cleared",groupExpanded:(t,e)=>`Group ${t} expanded, ${e} rows`,groupCollapsed:t=>`Group ${t} collapsed`,selectionChanged:t=>`${t} rows selected`,selectAllRows:()=>"Select all rows",selectRow:t=>`Select row ${t+1}`,columnSelected:t=>`Column ${t} selected`,columnSelectionChanged:t=>`${t} columns selected`,columnSelectionCleared:()=>"Column selection cleared",selectionAxisChanged:t=>"column"===t?"Row selection cleared, column selection active":"Column selection cleared, row selection active",editingStarted:t=>`Editing row ${t+1}`,editingCommitted:t=>`Row ${t+1} saved`,dataLoaded:t=>`${t} rows loaded`},o={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};function s(t,e){if(!t)return;if(!1===("effectiveConfig"in t?t.effectiveConfig:void 0)?.a11y?.announcements)return;const i=t.querySelector?.(".tbw-sr-only");i&&(i.textContent="","function"==typeof requestAnimationFrame?requestAnimationFrame(()=>{i.textContent=e}):i.textContent=e)}function l(t,e,...i){const n=(t&&"effectiveConfig"in t?t.effectiveConfig:void 0)?.a11y?.messages?.[e];return n?n(...i):r[e](...i)}var a=/* @__PURE__ */new WeakMap;function d(t){return"__proto__"===t||"constructor"===t||"prototype"===t}var c=/* @__PURE__ */new Map;function u(t){if(-1===t.indexOf("."))return null;let e=c.get(t);return void 0===e&&(e=Object.freeze(t.split(".")),c.set(t,e)),e}function h(t,e){if(null==t)return;const i=u(e),n=t;return null===i?d(e)?void 0:n[e]:Object.prototype.hasOwnProperty.call(n,e)?n[e]:function(t,e){let i=t;for(let n=0;n<e.length;n++){if(null==i||"object"!=typeof i)return;const t=e[n];if(d(t))return;i=i[t]}return i}(n,i)}function f(t,e,i){if(null==t||"object"!=typeof t)return!1;const n=u(e),r=t;return null===n?!d(e)&&(r[e]=i,!0):Object.prototype.hasOwnProperty.call(r,e)?(r[e]=i,!0):function(t,e,i){if(null==t||"object"!=typeof t)return!1;let n=t;for(let o=0;o<e.length-1;o++){const t=e[o];if(d(t))return!1;const i=n[t];if(null==i||"object"!=typeof i)return!1;n=i}const r=e[e.length-1];return!d(r)&&(n[r]=i,!0)}(r,n,i)}function g(t,e){t&&(e?a.get(t)?.delete(e):a.delete(t))}function w(t,e){if(!e.capped)return t;const i=e.spacerHeight-e.viewportHeight,n=e.rawContentHeight-e.viewportHeight;return i<=0||n<=0?t:t*i/n}function m(t,e){!function(t){if(!t._virtualization?.enabled)return;const{rowHeight:e,container:i,viewportEl:n,scrollMapping:r}=t._virtualization,o=i,s=n?.clientHeight??o?.clientHeight??0;if(!o||s<=0)return;const l=t._getVerticalScrollOffsets?.(t._focusRow)??{top:0,bottom:0};if(l.skipScroll)return;const a=Math.max(0,l.top),d=s-a-Math.max(0,l.bottom);if(d<=0)return;const c=t._focusRow*e,u=r?function(t,e){if(!e.capped)return t;const i=e.spacerHeight-e.viewportHeight,n=e.rawContentHeight-e.viewportHeight;if(i<=0||n<=0)return t;const r=t*n/i;return r<0?0:r>n?n:r}(o.scrollTop,r):o.scrollTop;if(c<u+a){const t=Math.max(0,c-a);o.scrollTop=r?w(t,r):t}else if(c+e>u+a+d){const t=Math.max(0,c-d+e-a);o.scrollTop=r?w(t,r):t}}(t);const n=function(t){return void 0!==t._activeEditRows&&-1!==t._activeEditRows}(t)||!!t._isGridEditMode;var r;n||t.refreshVirtualWindow(!1),(r=t._bodyEl)&&r.querySelectorAll(".cell-focus").forEach(t=>t.classList.remove("cell-focus")),Array.from(t._bodyEl.querySelectorAll('[aria-selected="true"]')).forEach(t=>{t.setAttribute("aria-selected","false")});const o=function(t){const e=t._focusRow,i=t._virtualization.start??0,n=t._virtualization.end??t._rows.length;if(e<i||e>=n)return;const r=t._bodyEl.querySelectorAll(".data-grid-row")[e-i];let o=r?.children[t._focusCol];return o&&o.classList?.contains("cell")||(o=r?.querySelector(`.cell[data-col="${t._focusCol}"]`)??r?.querySelector(".cell[data-col]")),o?{rowEl:r??null,cell:o}:void 0}(t);if(!o)return;const{rowEl:s,cell:l}=o;l.classList.add("cell-focus"),l.setAttribute("aria-selected","true"),n&&!e?.forceHorizontalScroll||function(t,e,i,n){const r=t.querySelector(".tbw-scroll-area");if(!r)return;if(n?.forceScrollLeft)return void(r.scrollLeft=0);if(n?.forceScrollRight)return void(r.scrollLeft=r.scrollWidth-r.clientWidth);const o=t._getHorizontalScrollOffsets?.(e??void 0,i)??{left:0,right:0};if(o.skipScroll)return;const s=i.getBoundingClientRect(),l=r.getBoundingClientRect(),a=s.left-l.left+r.scrollLeft,d=a+s.width,c=r.scrollLeft+o.left,u=r.scrollLeft+r.clientWidth-o.right;a<c?r.scrollLeft=a-o.left:d>u&&(r.scrollLeft=d-r.clientWidth+o.right)}(t,s,l,e),function(t,e,n){if(n&&e.classList.contains(i)){const t=e.querySelector('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])');if(t&&document.activeElement!==t)try{t.focus({preventScroll:!0})}catch{}return}if(n){if(e.contains(document.activeElement))return;e.hasAttribute("tabindex")||e.setAttribute("tabindex","-1");try{e.focus({preventScroll:!0})}catch{}return}const r=document.activeElement;r instanceof HTMLElement&&r!==t&&"function"==typeof t.contains&&t.contains(r)&&!r.classList.contains("cell")&&!r.closest(".cell")||r===t||t.focus({preventScroll:!0})}(t,l,n)}var p=/{{\s*([^}]+)\s*}}/g,v="__DG_EMPTY__",y=/^[\w$. '?+\-*/%:()!<>=,&|]+$/,b="__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("")),E=new RegExp(`__(proto|defineGetter|defineSetter)|${b.slice(3).join("|")}|this\\b`);var R=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,I=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),_=/^\s*(javascript|vbscript|data|blob):/i;function S(t){const e=document.createElement("template");return t&&"string"==typeof t&&(e.innerHTML=t,function(t){const e=[],i=t.querySelectorAll("*");for(const n of i){const t=n.tagName.toLowerCase();if(R.has(t)){e.push(n);continue}if(("svg"===t||"http://www.w3.org/2000/svg"===n.namespaceURI)&&Array.from(n.attributes).some(t=>C.test(t.name)||"href"===t.name||"xlink:href"===t.name)){e.push(n);continue}const i=[];for(const e of n.attributes){const t=e.name.toLowerCase();C.test(t)?i.push(e.name):"is"!==t?(I.has(t)&&_.test(e.value)||"style"===t&&/expression\s*\(|javascript:|behavior\s*:/i.test(e.value))&&i.push(e.name):i.push(e.name)}i.forEach(t=>n.removeAttribute(t))}e.forEach(t=>t.remove())}(e.content)),e.content}function k(t,e){const i=function(t){const e=[];let i=0;for(;i<t.length;){const n=t[i];if(" "!==n){if(n>="0"&&n<="9"||"."===n&&i+1<t.length&&t[i+1]>="0"&&t[i+1]<="9"){const n=i;for(;i<t.length&&(t[i]>="0"&&t[i]<="9"||"."===t[i]);)i++;e.push({type:"num",v:Number(t.slice(n,i))});continue}if("'"===n){let n="";for(i++;i<t.length&&"'"!==t[i];)n+=t[i++];if(i>=t.length)return null;i++,e.push({type:"str",v:n});continue}if(n>="a"&&n<="z"||n>="A"&&n<="Z"||"_"===n||"$"===n){const n=i;for(;i<t.length&&/[\w$.]/.test(t[i]);)i++;e.push({type:"id",v:t.slice(n,i)});continue}if(i+2<t.length){const n=t.slice(i,i+3);if("==="===n||"!=="===n){e.push({type:"op",v:n}),i+=3;continue}}if(i+1<t.length){const n=t.slice(i,i+2);if("=="===n||"!="===n||"<="===n||">="===n||"&&"===n||"||"===n){e.push({type:"op",v:n}),i+=2;continue}}if(!"+-*/%<>!?:(),".includes(n))return null;e.push({type:"op",v:n}),i++}else i++}return e}(t);if(!i)return;const n=i;let r=0;function o(){return n[r]}function s(){return n[r++]}function l(t,e){const i=o();return!!i&&(i.type===t&&(void 0===e||i.v===e))}function a(){const t=function(){let t=d();for(;l("op","||");)s(),t=t||d();return t}();if(l("op","?")){s();const e=a();if(!l("op",":"))return;s();const i=a();return t?e:i}return t}function d(){let t=c();for(;l("op","&&");)s(),t=t&&c();return t}function c(){let t=u();for(;;){const e=o();if(!e||"op"!==e.type)break;if("==="===e.v)s(),t=t===u();else if("!=="===e.v)s(),t=t!==u();else if("=="===e.v)s(),t=t==u();else{if("!="!==e.v)break;s(),t=t!=u()}}return t}function u(){let t=h();for(;;){const e=o();if(!e||"op"!==e.type)break;if("<"===e.v)s(),t=t<h();else if(">"===e.v)s(),t=t>h();else if("<="===e.v)s(),t=t<=h();else{if(">="!==e.v)break;s(),t=t>=h()}}return t}function h(){let t=f();for(;;){const e=o();if(!e||"op"!==e.type)break;if("+"===e.v)s(),t+=f();else{if("-"!==e.v)break;s(),t-=f()}}return t}function f(){let t=g();for(;;){const e=o();if(!e||"op"!==e.type)break;if("*"===e.v)s(),t*=g();else if("/"===e.v)s(),t/=g();else{if("%"!==e.v)break;s(),t%=g()}}return t}function g(){return l("op","!")?(s(),!g()):w()}function w(){const t=o();if(t){if("num"===t.type)return s(),t.v;if("str"===t.type)return s(),t.v;if("id"===t.type)return s(),function(t){if("value"===t)return e.value;if(t.startsWith("row.")){const i=t.slice(4);return e.row?e.row[i]:void 0}if(t.startsWith("typeDefault.")){const i=t.slice(12);return e.typeDefault?e.typeDefault[i]:void 0}return"row"===t?e.row:"typeDefault"===t?e.typeDefault:void 0}(t.v);if("op"===t.type&&"("===t.v){s();const t=a();return l("op",")")&&s(),t}return"op"===t.type&&"-"===t.v?(s(),-w()):void 0}}const m=a();return r<n.length?void 0:m}function x(t,e){if(!t||-1===t.indexOf("{{"))return t;const i=[],n=(r=t.replace(p,(t,n)=>{const r=function(t,e){if(!(t=(t||"").trim()))return v;if(A.test(t))return v;if("value"===t)return null==e.value?v:String(e.value);if(t.startsWith("row.")&&!/[()?]/.test(t)&&!t.includes(":")){const i=t.slice(4),n=e.row?e.row[i]:void 0;return null==n?v:String(n)}if(t.startsWith("typeDefault.")&&!/[()?]/.test(t)&&!t.includes(":")){const i=t.slice(12),n=e.typeDefault?e.typeDefault[i]:void 0;return null==n?v:String(n)}if(t.length>80)return v;if(!y.test(t)||E.test(t))return v;const i=t.match(/\./g);if(i&&i.length>1)return v;try{const i=k(t,e),n=null==i?"":String(i);return A.test(n)?v:n||v}catch{return v}}(n,e);return i.push({expr:n.trim(),result:r}),r===v?r:(o=r)&&"string"==typeof o?o.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;"):"";var o}),r?r.replace(new RegExp(v,"g"),"").replace(/Reflect\.[^<>{}\s]+|\bProxy\b|ownKeys\([^)]*\)/g,""):r);var r;const o=i.length&&i.every(t=>""===t.result||t.result===v);return A.test(t)||o?"":n}var A=/Reflect|Proxy|ownKeys/;function M(t){if(A.test(t)){const t=()=>"";return t.__blocked=!0,t}const e=e=>x(t,e);return e.__blocked=!1,e}function L(t,e){return`[tbw-grid${t?`#${t}`:""}${e?`:${e}`:""}]`}function D(t,e,i,n){return`${L(i,n)} ${t}: ${e}\n\n → More info: ${function(t){return`https://toolboxjs.com/grid/errors#${t.toLowerCase()}`}(t)}`}var G=class{static dependencies;static manifest;aliases;version="3.8.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},i={};for(const n of Object.keys(e))i[n]=this;for(const n of t){const t=n.userConfig;for(const[r,o]of Object.entries(t)){if(void 0===o)continue;if(!(r in e)){e[r]=o,i[r]=n;continue}if(e[r]===o)continue;const t=i[r]?.constructor.name??this.constructor.name,s=n.constructor.name,l=D("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${r}" supplied by both ${t} and ${s}. Pass the option on a single instance, or remove the duplicate.`,void 0,this.name);throw new Error(l)}}Object.assign(this.userConfig,e)}refreshUserConfigFrom(t){const e=this.userConfig,i={...t.userConfig};for(const n of Object.keys(e))delete e[n];Object.assign(e,i)}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 i=new CustomEvent(t,{detail:e,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(i),i.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 i=this.grid?.query?.(t,e);return Array.isArray(i)?i.some(Boolean):!!i}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{...o,...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(),i=parseInt(e,10);if(!isNaN(i))return i}return 200}setIcon(t,e,i){t.dataset.icon=e.replace(/([A-Z])/g,"-$1").toLowerCase(),"collapse"===e?t.dataset.expanded="":"expand"===e&&delete t.dataset.expanded;const n=this.#e(e,i);var r,o;void 0!==n?"string"==typeof n?(r=t,(o=n)&&"string"==typeof o?-1!==o.indexOf("<")||-1!==o.indexOf("&")?r.replaceChildren(S(o)):r.textContent=o:r.replaceChildren()):n instanceof HTMLElement&&t.replaceChildren(n.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 i=document.createElement("span");i.setAttribute("part","sort-indicator"),i.className="sort-indicator",e?(t.setAttribute("aria-sort","asc"===e?"ascending":"descending"),t.setAttribute("data-sort",e),this.setIcon(i,"asc"===e?"sortAsc":"sortDesc")):(t.setAttribute("aria-sort","none"),t.removeAttribute("data-sort"),this.setIcon(i,"sortNone"));const n=t.querySelector(".tbw-filter-btn")??t.querySelector(".resize-handle");return n?t.insertBefore(i,n):t.appendChild(i),i}warn(t,e){void 0!==e?console.warn(D(t,e,this.gridElement.id,this.name)):console.warn(`${L(this.gridElement.id,this.name)} ${t}`)}throwDiagnostic(t,e){throw new Error(D(t,e,this.gridElement.id,this.name))}};function T(t){return e=>{const i=t.editorParams,n=document.createElement("input");n.type="date",e.value instanceof Date?n.valueAsDate=e.value:"string"==typeof e.value&&e.value&&(n.value=e.value.split("T")[0]),i?.min&&(n.min=i.min),i?.max&&(n.max=i.max),i?.placeholder&&(n.placeholder=i.placeholder);return n.addEventListener("change",()=>{var r;if(n.value)"string"==typeof e.value?e.commit(n.value):e.commit(n.valueAsDate);else if(t.nullable)e.commit(null);else{const t=i?.default;"string"==typeof e.value||"string"==typeof t?e.commit("string"==typeof t?t:`${(r=t??/* @__PURE__ */new Date).getFullYear()}-${String(r.getMonth()+1).padStart(2,"0")}-${String(r.getDate()).padStart(2,"0")}`):e.commit(t instanceof Date?t:/* @__PURE__ */new Date)}}),n.addEventListener("keydown",t=>{"Escape"===t.key&&e.cancel()}),n}}var q="__tbw_null__";function $(t){switch(t.type){case"number":return function(t){return e=>{const i=t.editorParams,n=document.createElement("input");n.type="number",n.value=null!=e.value?String(e.value):"",void 0!==i?.min&&(n.min=String(i.min)),void 0!==i?.max&&(n.max=String(i.max)),void 0!==i?.step&&(n.step=String(i.step)),i?.placeholder&&(n.placeholder=i.placeholder);const r=()=>{""===n.value?t.nullable?e.commit(null):e.commit(i?.min??0):e.commit(Number(n.value))};return n.addEventListener("blur",r),n.addEventListener("keydown",t=>{"Enter"===t.key&&r(),"Escape"===t.key&&e.cancel()}),n}}(t);case"boolean":return t=>{const e=document.createElement("input");return e.type="checkbox",e.checked=!!t.value,e.addEventListener("change",()=>t.commit(e.checked)),e};case"date":return T(t);case"select":return function(t){return e=>{const i=t.editorParams,n=document.createElement("select");if(t.multi&&(n.multiple=!0),t.nullable||i?.includeEmpty){const r=document.createElement("option");r.value=t.nullable?q:"",r.textContent=t.nullable?i?.emptyLabel??"(Blank)":i?.emptyLabel??"",null==e.value&&(r.selected=!0),n.appendChild(r)}(function(t){const e=t.options;return e?"function"==typeof e?e():e:[]})(t).forEach(i=>{const r=document.createElement("option");r.value=String(i.value),r.textContent=i.label,t.multi&&Array.isArray(e.value)&&e.value.includes(i.value)?r.selected=!0:t.multi||e.value!==i.value||(r.selected=!0),n.appendChild(r)});const r=()=>{if(t.multi){const t=Array.from(n.selectedOptions).map(t=>t.value);e.commit(t)}else t.nullable&&n.value===q?e.commit(null):e.commit(n.value)};return n.addEventListener("change",r),n.addEventListener("blur",r),n.addEventListener("keydown",t=>{"Escape"===t.key&&e.cancel()}),n}}(t);default:return function(t){return e=>{const i=t.editorParams,n=document.createElement("input");n.type="text",n.value=null!=e.value?String(e.value):"",void 0!==i?.maxLength&&(n.maxLength=i.maxLength),i?.pattern&&(n.pattern=i.pattern),i?.placeholder&&(n.placeholder=i.placeholder);const r=()=>{const i=n.value;""!==i?"string"==typeof e.value&&i===e.value.replace(/[\n\r]/g,"")||("number"==typeof e.value?e.commit(Number(i)):e.commit(i)):t.nullable?e.commit(null):e.commit("")};return n.addEventListener("blur",r),n.addEventListener("keydown",t=>{"Enter"===t.key&&r(),"Escape"===t.key&&e.cancel()}),n}}(t)}}function F(t,e){return""===t?e?.nullable?null:(e?.editorParams)?.min??0:Number(t)}function P(t,e,i){if(!(t instanceof HTMLInputElement))return function(t,e,i){return""===t.value||"number"!==e?.type&&"number"!=typeof i?null==i&&""===t.value?e?.nullable?null:"":t.value:Number(t.value)}(t,e,i);switch(t.type){case"checkbox":return t.checked;case"number":return F(t.value,e);case"date":return function(t,e,i){return t.value?"string"==typeof i?t.value:t.valueAsDate:e?.nullable?null:"string"==typeof i?i||/* @__PURE__ */(new Date).toISOString().slice(0,10):i??/* @__PURE__ */new Date}(t,e,i);default:return function(t,e,i){return"number"==typeof i?F(t.value,e):""===t.value&&null==i?e?.nullable?null:"":"string"==typeof i&&t.value===i.replace(/[\n\r]/g,"")?i:t.value}(t,e,i)}}var V=class{#i=/* @__PURE__ */new Map;#n;constructor(t){this.#n=t}setInvalid(t,e,i=""){let n=this.#i.get(t);n||(n=/* @__PURE__ */new Map,this.#i.set(t,n)),n.set(e,i),this.#n(t,e,!0)}clearInvalid(t,e){const i=this.#i.get(t);i&&(i.delete(e),0===i.size&&this.#i.delete(t)),this.#n(t,e,!1)}clearRowInvalid(t){const e=this.#i.get(t);if(e){const i=Array.from(e.keys());this.#i.delete(t),i.forEach(e=>this.#n(t,e,!1))}}clearAllInvalid(){const t=Array.from(this.#i.entries());this.#i.clear(),t.forEach(([t,e])=>{e.forEach((e,i)=>this.#n(t,i,!1))})}isCellInvalid(t,e){return this.#i.get(t)?.has(e)??!1}getInvalidMessage(t,e){return this.#i.get(t)?.get(e)}hasInvalidCells(t){const e=this.#i.get(t);return!!e&&e.size>0}getInvalidFields(t){return new Map(this.#i.get(t)??[])}};function O(t,e,i){const n=t.get(e);return!!n&&!H(n,i)}function H(t,e){if(t===e)return!0;if(null==t||null==e)return!1;if(typeof t!=typeof e)return!1;if(t instanceof Date&&e instanceof Date)return t.getTime()===e.getTime();if(Array.isArray(t)){if(!Array.isArray(e)||t.length!==e.length)return!1;for(let i=0;i<t.length;i++)if(!H(t[i],e[i]))return!1;return!0}if("object"==typeof t){const i=t,n=e,r=Object.keys(i),o=Object.keys(n);if(r.length!==o.length)return!1;for(const t of r)if(!H(i[t],n[t]))return!1;return!0}return!1}function j(t,e,i){t.set(e,structuredClone(i))}function N(t,e,i){const n=t.get(e);if(!n)return!1;const r=n,o=i;for(const s of Object.keys(r))o[s]=r[s];return!0}var W=class{baselines=/* @__PURE__ */new Map;baselinesWereCaptured=!1;newRowIds=/* @__PURE__ */new Set;changedRowIds=/* @__PURE__ */new Set;committedDirtyRowIds=/* @__PURE__ */new Set;clear(){this.changedRowIds.clear(),this.committedDirtyRowIds.clear(),this.baselines.clear(),this.newRowIds.clear(),this.baselinesWereCaptured=!1}capture(t,e){const i=this.baselines.size;!function(t,e,i){for(const n of e)try{const e=i(n);null==e||t.has(e)||t.set(e,structuredClone(n))}catch{}}(this.baselines,t,e),this.baselines.size>i&&(this.baselinesWereCaptured=!0)}drainCapturedFlag(){return this.baselinesWereCaptured?(this.baselinesWereCaptured=!1,this.baselines.size):null}isRowDirty(t,e){return O(this.baselines,t,e)}hasAnyDirty(t){if(this.newRowIds.size>0)return!0;for(const[e]of this.baselines){const i=t(e);if(i&&O(this.baselines,e,i))return!0}return!1}isCellDirty(e,i,n){return function(e,i,n,r){const o=e.get(i);return!!o&&!H(t(o,r),t(n,r))}(this.baselines,e,i,n)}getRowDirtyState(t,e){const i=this.newRowIds.has(t);return{isNew:i,isCommittedDirty:!i&&this.committedDirtyRowIds.has(t)&&O(this.baselines,t,e),hasBaseline:this.baselines.has(t)}}markPristine(t,e){j(this.baselines,t,e),this.newRowIds.delete(t),this.changedRowIds.delete(t),this.committedDirtyRowIds.delete(t)}rebaselineCell(t,i,n){const r=this.baselines.get(t);r&&e(r,i,n)}markNew(t){this.newRowIds.add(t),this.committedDirtyRowIds.add(t)}markDirty(t){this.changedRowIds.add(t),this.committedDirtyRowIds.add(t)}markAllPristine(t){for(const[e]of this.baselines){const i=t(e);i&&j(this.baselines,e,i)}this.newRowIds.clear(),this.changedRowIds.clear(),this.committedDirtyRowIds.clear()}getOriginalRow(t){return function(t,e){const i=t.get(e);return i?structuredClone(i):void 0}(this.baselines,t)}hasBaseline(t){return this.baselines.has(t)}getDirtyRows(t){const e=[];for(const[i,n]of this.baselines){const r=t(i);r&&O(this.baselines,i,r)&&e.push({id:i,original:structuredClone(n),current:r})}for(const i of this.newRowIds){const n=t(i);n&&e.push({id:i,original:void 0,current:n})}return e}getDirtyRowIds(t){const e=[];for(const[i]of this.baselines){const n=t(i);n&&O(this.baselines,i,n)&&e.push(i)}for(const i of this.newRowIds)e.push(i);return e}revertRow(t,e){const i=N(this.baselines,t,e);return i&&(this.changedRowIds.delete(t),this.committedDirtyRowIds.delete(t)),i}revertAll(t){for(const[e]of this.baselines){const i=t(e);i&&N(this.baselines,e,i)}this.changedRowIds.clear(),this.committedDirtyRowIds.clear()}getChangedRows(t){const e=[];for(const i of this.changedRowIds){const n=t(i);n&&e.push(n)}return e}getChangedRowIds(){return Array.from(this.changedRowIds)}isRowChanged(t){return this.changedRowIds.has(t)}},z='input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])';function B(t){return t?.closest?.('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])')??null}function K(t){return"string"==typeof t&&("__proto__"!==t&&"constructor"!==t&&"prototype"!==t)}function U(t){}function Z(t,e){return!1===t.onBeforeEditClose?.(e)}function J(i,n,r,o,s,l,a,d){if(!o.editable)return;if(l.classList.contains("editing"))return;const{grid:c,isGridMode:u,config:h,editingCells:f,editorValueCallbacks:g}=i;let w;try{w=c.getRowId?.(n)}catch{}const m=w?t=>c.updateRow(w,t,"cascade"):U,p=K(o.field)?t(n,o.field):void 0;l.classList.add("editing"),f.add(`${r}:${s}`);const v=d??l.parentElement;v&&function(t){t.__editingCellCount=(t.__editingCellCount??0)+1,t.setAttribute("data-has-editing","")}(v);let y=!1;const b=t=>{if(y||!u&&!i.isEditSessionActive())return;const e=w?c._getRowEntry(w):void 0,s=e?.row??n,l=e?.index??r;i.commitCellValue(l,o,t,s)},E=()=>{if(y=!0,K(o.field)){const t=(w?c._getRowEntry(w):void 0)?.row??n;e(t,o.field,p)}},R=document.createElement("div");R.className="tbw-editor-host",l.firstElementChild&&c.__frameworkAdapter?.releaseCell?.(l),l.innerHTML="",l.appendChild(R),R.addEventListener("keydown",t=>{if(!t.defaultPrevented){if("Enter"===t.key){const e=t.target;if(e&&"true"===e.getAttribute?.("aria-expanded")&&e.hasAttribute?.("aria-controls"))return}if("Enter"===t.key){const e=t.target,n=B(e);if(n&&n!==e)return;if(u){t.preventDefault();const e=R.querySelector("input,textarea,select");return void(e&&b(P(e,o,p)))}if(Z(h,t))return;t.stopPropagation(),t.preventDefault(),y=!0,i.exitRowEdit(r,!1)}if("Escape"===t.key){if(u)return t.stopPropagation(),void t.preventDefault();if(Z(h,t))return;t.stopPropagation(),t.preventDefault(),E(),i.exitRowEdit(r,!0)}}});const C=o,I=C.__editorTemplate,_=function(t,e){if(e.editor)return e.editor;if(e.__editorTemplate)return"template";if(!e.type)return;const i=t.effectiveConfig?.typeDefaults;if(i?.[e.type]?.editor)return i[e.type].editor;const n=t.__frameworkAdapter;if(n?.getTypeDefault){const i=n.getTypeDefault(e.type,t._hostElement);if(i?.editor)return i.editor}}(c,C)??$(o),S=p,k=`${r}:${o.field}`,x=[];g.set(k,t=>{for(const e of x)e(t)});const A=t=>{x.push(t)};if("template"===_&&I)!function(t,e,i,n,r,o,s,l,a){const d=i.__editorTemplate;if(!d)return;const c=d.cloneNode(!0),u=i.__compiledEditor;u?c.innerHTML=u({row:n,value:r,field:i.field,column:i,commit:o,cancel:s}):c.querySelectorAll("*").forEach(t=>{1===t.childNodes.length&&t.firstChild?.nodeType===Node.TEXT_NODE&&(t.textContent=t.textContent?.replace(/{{\s*value\s*}}/g,null==r?"":String(r)).replace(/{{\s*row\.([a-zA-Z0-9_]+)\s*}}/g,(t,e)=>{if(!K(e))return"";const i=n[e];return null==i?"":String(i)})||"")});const h=c.querySelector("input,textarea,select");if(h){h instanceof HTMLInputElement&&"checkbox"===h.type?h.checked=!!r:h.value=String(r??"");let e=!1;h.addEventListener("blur",()=>{e||o(P(h,i,r))}),h.addEventListener("keydown",n=>{const l=n;if("Enter"===l.key){if(Z(t.config,l))return;l.stopPropagation(),l.preventDefault(),e=!0,o(P(h,i,r)),t.exitRowEdit(a,!1)}if("Escape"===l.key){if(Z(t.config,l))return;l.stopPropagation(),l.preventDefault(),s(),t.exitRowEdit(a,!0)}}),h instanceof HTMLInputElement&&"checkbox"===h.type&&h.addEventListener("change",()=>o(h.checked)),l||setTimeout(()=>h.focus({preventScroll:!0}),0)}e.appendChild(c)}(i,R,C,n,p,b,E,a,r),A(t=>{if(null!=t&&"object"==typeof t)return;const e=R.querySelector("input,textarea,select");e&&(e instanceof HTMLInputElement&&"checkbox"===e.type?e.checked=!!t:e.value=String(t??""))});else if("string"==typeof _){const t=document.createElement(_);t.value=S,t.addEventListener("change",()=>b(t.value)),A(e=>{t.value=e}),R.appendChild(t),a||queueMicrotask(()=>{R.querySelector(z)?.focus({preventScroll:!0})})}else if("function"==typeof _){const t=_({row:n,rowId:w??"",value:S,field:o.field,column:o,commit:b,cancel:E,updateRow:m,onValueChange:A,grid:i.grid});"string"==typeof t?(R.innerHTML=t,function(t,e,i,n){const r=t.querySelector("input,textarea,select");r&&(r.addEventListener("blur",()=>{i(P(r,e,n))}),r instanceof HTMLInputElement&&"checkbox"===r.type?r.addEventListener("change",()=>i(r.checked)):r instanceof HTMLSelectElement&&r.addEventListener("change",()=>i(P(r,e,n))))}(R,o,b,p),A(t=>{const e=R.querySelector("input,textarea,select");e&&(e instanceof HTMLInputElement&&"checkbox"===e.type?e.checked=!!t:e.value=String(t??""))})):t instanceof Node?(R.appendChild(t),t instanceof HTMLInputElement||t instanceof HTMLSelectElement||t instanceof HTMLTextAreaElement?A(e=>{t instanceof HTMLInputElement&&"checkbox"===t.type?t.checked=!!e:t.value=String(e??"")}):l.setAttribute("data-editor-managed","")):!t&&R.hasChildNodes()&&l.setAttribute("data-editor-managed",""),a||queueMicrotask(()=>{R.querySelector(z)?.focus({preventScroll:!0})})}else if(_&&"object"==typeof _){const t=document.createElement("div");t.setAttribute("data-external-editor",""),t.setAttribute("data-field",o.field),R.appendChild(t),l.setAttribute("data-editor-managed","");const e={row:n,rowId:w??"",value:S,field:o.field,column:o,commit:b,cancel:E,updateRow:m,onValueChange:A,grid:i.grid};if(_.mount)try{_.mount({placeholder:t,context:e,spec:_})}catch(q){M="TBW080",L=`External editor mount error for column '${o.field}': ${q}`,G=i.grid.id,console.warn(D(M,L,G,T))}else c.dispatchEvent(new CustomEvent("mount-external-editor",{detail:{placeholder:t,spec:_,context:e}}))}var M,L,G,T;!function(t,e){const i="string"==typeof e.header?e.header:e.field;if(!i)return;queueMicrotask(()=>{const e=t.querySelector(z);e&&(e.hasAttribute("aria-label")||e.hasAttribute("aria-labelledby")||e.hasAttribute("title")||e.id&&t.querySelector(`label[for="${CSS.escape(e.id)}"]`)||e.closest("label")||e.setAttribute("aria-label",i))})}(R,o)}var X=class extends G{static manifest={ownedProperties:[{property:"editable",level:"column",description:'the "editable" column property',isUsed:t=>!0===t||"function"==typeof t},{property:"editor",level:"column",description:'the "editor" column property'},{property:"editorParams",level:"column",description:'the "editorParams" column property'},{property:"nullable",level:"column",description:'the "nullable" column property (allows null values)'}],events:[{type:"cell-edit-committed",description:"Emitted when a cell edit is committed (for plugin-to-plugin coordination)"}],queries:[{type:"isEditing",description:"Returns whether any cell is currently being edited"},{type:"getCellEditableResolver",description:"Returns a predicate (field, row) => boolean resolving per-cell editability (rowEditable gate + column.editable true/false/function), for consumers like clipboard paste"},{type:"commitCellValue",description:"Commits a single cell value coming from a core row mutation (updateRow/updateRows), running the full edit pipeline: cancelable cell-commit (validation/abortion), dirty tracking, history, and cascade. Returns true (applied), false (vetoed), or undefined (not handled)."}]};name="editing";styles="@layer tbw-plugins{tbw-grid{--tbw-editing-bg:var(--tbw-color-selection);--tbw-editing-row-bg:var(--tbw-editing-bg);--tbw-editing-border:var(--tbw-border-input,1px solid var(--tbw-color-border-strong));--tbw-padding-editing-input:var(--tbw-cell-padding-input,2px 6px);--tbw-font-size-editor:inherit;--tbw-editing-row-outline-color:var(--tbw-color-accent);--tbw-editing-row-outline-width:1px}tbw-grid:not(.tbw-grid-mode) .data-grid-row:has(.editing){background:var(--tbw-editing-row-bg);outline:var(--tbw-editing-row-outline-width) solid var(--tbw-editing-row-outline-color);outline-offset:calc(-1 * var(--tbw-editing-row-outline-width))}tbw-grid .data-grid-row>.cell.editing{min-height:max(var(--tbw-row-height), calc(1lh + 2 * var(--tbw-cell-padding-v,.25em) + var(--tbw-border-width,1px)));justify-content:center;align-items:center;padding:0;display:flex;overflow:hidden}tbw-grid .data-grid-row>.cell.editing input:not([type=checkbox]),tbw-grid .data-grid-row>.cell.editing select,tbw-grid .data-grid-row>.cell.editing textarea{border:var(--tbw-editing-border);width:100%;min-width:0;height:100%;padding:var(--tbw-padding-editing-input);font-size:var(--tbw-font-size-editor);flex:auto;align-self:stretch}tbw-grid .tbw-editor-host{display:contents}tbw-grid{--tbw-invalid-bg:light-dark(#fef2f2,#450a0a);--tbw-invalid-border-color:light-dark(#ef4444,#f87171)}tbw-grid .data-grid-row>.cell[data-invalid=true]{background:var(--tbw-invalid-bg);outline:1px solid var(--tbw-invalid-border-color);outline-offset:-1px}}";get defaultConfig(){return{mode:"row",editOn:"click"}}get#r(){return"grid"===this.config.mode}#o(t,e){const i=this.#s.effectiveConfig?.rowEditable;if(i&&!i(e))return!1;const{editable:n}=t;return"function"==typeof n?n(e):!0===n}#l(t){return!0===t.editable||"function"==typeof t.editable}#a=-1;#d;#c;#u=-1;#h=/* @__PURE__ */new Map;#f=/* @__PURE__ */new Set;#g=/* @__PURE__ */new WeakSet;#w=/* @__PURE__ */new Map;#m=!1;#p=-1;#v;#y=!1;#b=!1;#E=!1;#R=null;#C=new W;#I=/* @__PURE__ */new Set;#_;get#s(){return this.grid}attach(t){super.attach(t);const e=this.disconnectSignal,i=this.#s;this.#v=new V((t,e,i)=>{this.#S(t,e,i)}),this.#_={grid:i,isGridMode:this.#r,config:this.config,editingCells:this.#f,editorValueCallbacks:this.#w,isEditSessionActive:()=>-1!==this.#a,commitCellValue:(t,e,i,n)=>this.#k(t,e,i,n),exitRowEdit:(t,e)=>this.#x(t,e)},this.#A(),Object.defineProperty(t,"changedRows",{get:()=>this.changedRows,configurable:!0}),Object.defineProperty(t,"changedRowIds",{get:()=>this.changedRowIds,configurable:!0}),Object.defineProperty(t,"_changedRowIdSet",{get:()=>this.#C.changedRowIds,configurable:!0}),t.resetChangedRows=t=>this.resetChangedRows(t),this.#M(e,i),this.#r&&(i._isGridEditMode=!0,this.gridElement.classList.add("tbw-grid-mode"),this.requestRender(),this.#L(e,i))}#M(t,e){if(document.addEventListener("keydown",t=>{if(!this.#r&&"Escape"===t.key&&-1!==this.#a){if(Z(this.config,t))return;this.#x(this.#a,!0)}},{capture:!0,signal:t}),document.addEventListener("mousedown",t=>{if(this.#r)return;if(-1===this.#a)return;const i=e.findRenderedRowElement?.(this.#a);if(!i)return;if((t.composedPath&&t.composedPath()||[]).includes(i))return;const n=t.target;if(!n||this.gridElement.contains(n)||!this.grid.containsFocus?.(n)){if(n&&!this.gridElement.contains(n)){const t=e.findRenderedRowElement?.(this.#a);if(t&&function(t,e){if(!t)return!1;const i=e.querySelectorAll('[aria-expanded="true"][aria-controls]');for(let n=0;n<i.length;n++){const r=i[n].getAttribute("aria-controls");if(!r)continue;const o=e.ownerDocument?.getElementById(r);if(o&&o.contains(t))return!0}return!1}(n,t))return}Z(this.config,t)||queueMicrotask(()=>{-1!==this.#a&&this.#x(this.#a,!1)})}},{signal:t}),this.config.focusTrap&&this.gridElement.addEventListener("focusout",t=>{if(this.#r)return;if(-1===this.#a)return;const e=t.relatedTarget;e&&this.grid.containsFocus?.(e)||e&&this.gridElement.contains(e)||queueMicrotask(()=>{-1!==this.#a&&this.#D()})},{signal:t}),this.gridElement.addEventListener("cell-change",t=>{const e=t.detail;if("user"===e.source)return;const i=`${e.rowIndex}:${e.field}`,n=this.#w.get(i);n&&n(e.newValue)},{signal:t}),this.config.dirtyTracking){const e=t=>{const e=t.detail?.action;if(!e)return;const i=this.rows[e.rowIndex];if(!i)return;const n=this.#G(i);if(!n)return;const r=this.#C.isRowDirty(n,i);this.#T(n,i,r?"modified":"pristine")};this.gridElement.addEventListener("undo",e,{signal:t}),this.gridElement.addEventListener("redo",e,{signal:t}),this.on("row-inserted",t=>{const e=this.#G(t.row);null!=e&&this.markAsNew(String(e))})}}#L(t,e){this.gridElement.addEventListener("focusin",t=>{const i=t.target;if(i!==this.gridElement&&i.matches('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])')){if(this.#b)return i.blur(),void this.gridElement.focus();const t=e._focusRow,n=e._focusCol,r=this.#R;if(!r||r.rowIndex!==t||r.colIndex!==n){const i=e._visibleColumns?.[n],r=e._rows?.[t];if(i?.field&&r){const e=i.field;this.#R={rowIndex:t,colIndex:n,field:e,value:h(r,e)}}}this.#y=!0}},{signal:t}),this.gridElement.addEventListener("focusout",t=>{const e=t.target,i=t.relatedTarget;if(e&&i){if(e.contains(i))return;const t=B(i);if(t&&t!==this.gridElement&&this.gridElement.contains(t))return}i&&(this.gridElement.contains(i)||this.grid.containsFocus?.(i))&&i.matches('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])')||(this.#y=!1,this.#R=null)},{signal:t}),this.gridElement.addEventListener("keydown",t=>{if("Escape"===t.key&&this.#y){if(Z(this.config,t))return void queueMicrotask(()=>{this.#y&&this.#q()});this.#q(),t.preventDefault(),t.stopPropagation()}},{capture:!0,signal:t}),this.gridElement.addEventListener("mousedown",t=>{t.target.matches('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])')&&(this.#b=!1)},{signal:t})}detach(){this.#s._isGridEditMode=!1,this.gridElement.classList.remove("tbw-grid-mode"),this.#a=-1,this.#d=void 0,this.#c=void 0,this.#u=-1,this.#h.clear(),this.#C.clear(),this.#f.clear(),this.#w.clear(),this.#y=!1,this.#b=!1,this.#R=null,this.#E=!1,this.#g=/* @__PURE__ */new WeakSet,super.detach()}handleQuery(t){if("isEditing"===t.type)return this.#r||-1!==this.#a;if("getCellEditableResolver"===t.type){const t=this.#s.effectiveConfig?.columns??[],e=/* @__PURE__ */new Map;for(const i of t)e.set(i.field,i);return(t,i)=>{const n=e.get(t);return!!n&&this.#o(n,i)}}return"commitCellValue"===t.type?this.#$(t.context):void 0}#$(t){const e=this.#s,i=(e._visibleColumns??[]).find(e=>e.field===t.field)??e._columns?.find(e=>e.field===t.field),n=t.row??(null!=t.rowId?e._getRowEntry(t.rowId)?.row:void 0)??e._rows?.[t.rowIndex];if("sync"===t.source){if(!n||!K(t.field))return;f(n,t.field,t.newValue),g(n);const e=this.#G(n);if(e&&this.config.dirtyTracking){this.#C.rebaselineCell(e,t.field,t.newValue);const i=this.#C.isRowDirty(e,n);i||this.#C.changedRowIds.delete(e),this.#T(e,n,i?"modified":"pristine")}return!0}if(i&&n&&K(t.field)){if("history"===t.source){f(n,t.field,t.newValue),g(n);const e=this.#G(n);if(e&&this.config.dirtyTracking){const t=this.#C.isRowDirty(e,n);t||this.#C.changedRowIds.delete(e),this.#T(e,n,t?"modified":"pristine")}return!0}return this.#k(t.rowIndex,i,t.newValue,n,t.source),h(n,t.field)===t.newValue}}onCellClick(t){if(this.#r)return!1;const e=this.#s,i=this.config.editOn??e.effectiveConfig?.editOn;if(!1===i||"manual"===i)return!1;if("click"!==i&&"dblclick"!==i)return!1;const n="dblclick"===t.originalEvent.type;if("click"===i&&n)return!1;if("dblclick"===i&&!n)return!1;const{rowIndex:r}=t;return!!e._columns?.some(t=>this.#l(t))&&(!!this.#F(e._rows[r])&&(t.originalEvent.stopPropagation(),this.beginBulkEdit(r),!0))}onKeyDown(t){switch(t.key){case"Escape":return this.#P(t);case"ArrowUp":case"ArrowDown":case"ArrowLeft":case"ArrowRight":return this.#V(t);case"Tab":return this.#O(t);case" ":case"Spacebar":return this.#H(t);case"Enter":return!(t.shiftKey||t.ctrlKey||t.altKey||t.metaKey)&&this.#j(t);case"F2":return this.#N(t);default:return!1}}#P(t){return this.#r&&this.#y?(this.#q(),this.requestAfterRender(),!0):-1!==this.#a&&!this.#r&&(Z(this.config,t)||this.#x(this.#a,!0),!0)}#V(t){const e=B(t.target),i=!!e&&e!==this.gridElement,n="ArrowUp"===t.key||"ArrowDown"===t.key;return!(this.#r&&!this.#y&&!i)&&(!(!this.#r||!this.#y&&!i||!n)||!(!n||-1===this.#a||this.#r))}#O(t){return!(-1===this.#a&&!this.#r)&&(t.preventDefault(),this.#E?(this.#x(this.#a,!1),!0):(this.#W(!t.shiftKey),!0))}#H(t){if(-1!==this.#a)return!1;const e=this.#s,i=e._focusRow,n=e._focusCol;if(i<0||n<0)return!1;const r=e._visibleColumns[n],o=e._rows[i];if(!r||!o||"boolean"!==r.type)return!1;if(!this.#o(r,o))return!1;const s=r.field;return!!K(s)&&(this.#k(i,r,!h(o,s),o),t.preventDefault(),this.requestRender(),!0)}#j(t){if(this.#r&&!this.#y)return this.#D(),!0;if(this.#r&&this.#y)return this.#z(t);if(-1!==this.#a){const e=t.target;return(!e||"true"!==e.getAttribute?.("aria-expanded")||!e.hasAttribute?.("aria-controls"))&&!!Z(this.config,t)}return this.#B(t)}#z(t){const e=B(t.target);if(e&&e!==t.target)return!0;this.#R=null;const i=document.activeElement;return i&&this.gridElement.contains(i)&&(i.blur(),this.gridElement.focus()),this.#y=!1,this.#b=!0,this.requestAfterRender(),!0}#B(t){const e=this.#s,i=this.config.editOn??e.effectiveConfig?.editOn;if(!1===i||"manual"===i)return!1;const n=e._focusRow,r=e._focusCol;if(n<0)return!1;const o=e._columns?.some(t=>this.#l(t)),s=e._rows[n];if(!o||!this.#F(s))return!1;const l=e._visibleColumns[r]?.field??"",a=l&&s?h(s,l):void 0,d=this.gridElement.querySelector(`[data-row="${n}"][data-col="${r}"]`),c=new CustomEvent("cell-activate",{cancelable:!0,bubbles:!0,detail:{rowIndex:n,colIndex:r,field:l,value:a,row:s,cellEl:d,trigger:"keyboard",originalEvent:t}});return this.gridElement.dispatchEvent(c),c.defaultPrevented?(t.preventDefault(),!0):(this.beginBulkEdit(n),!0)}#N(t){if(-1!==this.#a||this.#r)return!1;const e=this.#s;if(!1===(this.config.editOn??e.effectiveConfig?.editOn))return!1;const i=e._focusRow,n=e._focusCol;if(i<0||n<0)return!1;const r=e._visibleColumns[n],o=e._rows[i];return!!(r&&o&&r.field)&&(!!this.#o(r,o)&&(t.preventDefault(),this.beginCellEdit(i,r.field),!0))}#K(t){const e={};for(const i of Array.from(t.attributes)){if(!i.name.startsWith("data-"))continue;const t=i.name.slice(5).replace(/-([a-z])/g,(t,e)=>e.toUpperCase()).trim();t&&(e[t]=i.value)}return e}#U(){const t=this.#s,e=t._hostElement;if(!e)return;const i=t.effectiveConfig;if(!i)return;const n=Array.from(e.children).filter(t=>"tbw-grid-type"===t.tagName.toLowerCase());if(!n.length)return;const r=t.__frameworkAdapter,o=i.typeDefaults??={};for(let s=0;s<n.length;s++){const t=n[s],e=t.getAttribute("name")?.trim();if(!e)continue;const i=o[e];if(i?.editor)continue;const l=t.querySelector("tbw-grid-column-editor"),a=l??t;let d=r?.canHandle?.(a)?r.createEditor?.(a):void 0;if(!d&&l){const e=this.#K(t),i=M(l.innerHTML);d=t=>i({row:t.row,value:t.value,field:t.field,column:t.column,typeDefault:e})}d&&(o[e]={...i??{},editor:d})}}processColumns(t){const e=this.#s;this.#U();const i=e.effectiveConfig?.typeDefaults,n=e.__frameworkAdapter,r=!!i||!!n?.getTypeDefault;return t.map(t=>{const o=t.__element;if(o&&!this.#g.has(o)){this.#g.add(o),null==t.editable&&o.hasAttribute("editable")&&(t.editable="false"!==o.getAttribute("editable"));const e=t;if(!e.__editorTemplate){const t=o.querySelector("tbw-grid-column-editor");t&&(e.__editorTemplate=t)}}if(!t.type||!r)return t;let s;if(i?.[t.type]?.editorParams&&(s=i[t.type].editorParams),!s&&n?.getTypeDefault){const i=n.getTypeDefault(t.type,e._hostElement);i?.editorParams&&(s=i.editorParams)}return s?{...t,editorParams:{...s,...t.editorParams}}:t})}processRows(t){const e=this.#s;if(this.config.dirtyTracking&&e.getRowId&&this.#C.capture(t,t=>{try{return e.getRowId?.(t)}catch{return}}),-1===this.#a||this.#r)return t;const i=this.#d,n=this.#c;if(!i||!n)return t;const r=[...t];let o=-1;for(let s=0;s<r.length;s++)if(this.#G(r[s])===i){o=s;break}return-1===o?(setTimeout(()=>this.cancelActiveRowEdit(),0),r):(r[o]=n,this.#a!==o&&this.#Z(this.#a,o),r)}afterRender(){const t=this.#s;if(-1!==this.#a&&this.#c&&!this.#r&&t._rows[this.#a]!==this.#c){const e=t._rows.indexOf(this.#c);if(-1===e)return void setTimeout(()=>this.cancelActiveRowEdit(),0);this.#Z(this.#a,e)}if(this.#m&&(this.#m=!1,this.#J(t)),-1!==this.#p){const e=this.#p;this.#p=-1,t.animateRow?.(e,"change")}const e=this.#C.drainCapturedFlag();if(null!=e&&this.emit("baselines-captured",{count:e}),!this.#r&&0!==this.#f.size)for(const i of this.#f){const[e,n]=i.split(":"),r=parseInt(e,10),o=parseInt(n,10),s=this.#X(r,o);if(!s||s.classList.contains("editing"))continue;const l=t._rows[r],a=t._visibleColumns[o];l&&a&&this.#Y(l,r,a,o,s,!0)}}afterCellRender(t){const{row:e,rowIndex:i,column:n,colIndex:r,cellElement:o}=t,s=this.#o(n,e);if(s)o.removeAttribute("aria-readonly");else if(o.setAttribute("aria-readonly","true"),this.#r&&o.classList.contains("editing")){o.classList.remove("editing");const t=h(e,n.field);o.textContent=null==t?"":String(t)}this.#r&&s&&(o.classList.contains("editing")||this.#Y(e,i,n,r,o,!0,t.rowElement))}afterRowRender(t){if(!this.config.dirtyTracking)return;const e=this.#s.getRowId?.(t.row);if(!e)return;const{isNew:i,isCommittedDirty:n,hasBaseline:r}=this.#C.getRowDirtyState(e,t.row),o=t.rowElement;if(o.classList.toggle("tbw-row-dirty",n),o.classList.toggle("tbw-row-new",i),r){const i=o.querySelectorAll(".cell[data-field]");for(let n=0;n<i.length;n++){const r=i[n],o=r.getAttribute("data-field");o&&r.classList.toggle("tbw-cell-dirty",this.#C.isCellDirty(e,t.row,o))}}else{const t=o.querySelectorAll(".tbw-cell-dirty");for(let e=0;e<t.length;e++)t[e].classList.remove("tbw-cell-dirty")}}onScrollRender(){this.afterRender()}get changedRows(){return this.#C.getChangedRows(t=>this.grid.getRow(t))}get changedRowIds(){return this.#C.getChangedRowIds()}get activeEditRow(){return this.#a}get activeEditCol(){return this.#u}isRowEditing(t){return this.#a===t}isCellEditing(t,e){return this.#f.has(`${t}:${e}`)}isRowChanged(t){const e=this.#s,i=e._rows[t];if(!i)return!1;try{const t=e.getRowId?.(i);return!!t&&this.#C.isRowChanged(t)}catch{return!1}}isRowChangedById(t){return this.#C.isRowChanged(t)}isDirty(t){if(!this.config.dirtyTracking)return!1;if(this.#C.newRowIds.has(t))return!0;const e=this.grid.getRow(t);return!!e&&this.#C.isRowDirty(t,e)}isPristine(t){return!this.isDirty(t)}get dirty(){if(!this.config.dirtyTracking)return!1;const t=this.#s;return this.#C.hasAnyDirty(e=>t._getRowEntry(e)?.row)}get pristine(){return!this.dirty}markAsPristine(t){if(!this.config.dirtyTracking)return;const e=this.grid.getRow(t);e&&(this.#C.markPristine(t,e),this.emit("dirty-change",{rowId:t,row:e,original:e,type:"pristine"}))}markAsNew(t){if(!this.config.dirtyTracking)return;this.#C.markNew(t);const e=this.grid.getRow(t);this.emit("dirty-change",{rowId:t,row:e,original:void 0,type:"new"})}markAsDirty(t){if(!this.config.dirtyTracking)return;const e=this.grid.getRow(t);e&&(this.#C.markDirty(t),this.#T(t,e,"modified"))}markAllPristine(){if(!this.config.dirtyTracking)return;const t=this.#s;this.#C.markAllPristine(e=>t._getRowEntry(e)?.row)}getOriginalRow(t){if(this.config.dirtyTracking)return this.#C.getOriginalRow(t)}hasBaseline(t){return!!this.config.dirtyTracking&&this.#C.hasBaseline(t)}getDirtyRows(){if(!this.config.dirtyTracking)return[];const t=this.#s;return this.#C.getDirtyRows(e=>t._getRowEntry(e)?.row)}get dirtyRowIds(){if(!this.config.dirtyTracking)return[];const t=this.#s;return this.#C.getDirtyRowIds(e=>t._getRowEntry(e)?.row)}revertRow(t){if(!this.config.dirtyTracking)return;const e=this.grid.getRow(t);e&&this.#C.revertRow(t,e)&&(this.#T(t,e,"reverted"),this.requestRender())}revertAll(){if(!this.config.dirtyTracking)return;const t=this.#s;this.#C.revertAll(e=>t._getRowEntry(e)?.row),this.requestRender()}setInvalid(t,e,i=""){this.#v.setInvalid(t,e,i)}clearInvalid(t,e){this.#v.clearInvalid(t,e)}clearRowInvalid(t){this.#v.clearRowInvalid(t)}clearAllInvalid(){this.#v.clearAllInvalid()}isCellInvalid(t,e){return this.#v.isCellInvalid(t,e)}getInvalidMessage(t,e){return this.#v.getInvalidMessage(t,e)}hasInvalidCells(t){return this.#v.hasInvalidCells(t)}getInvalidFields(t){return this.#v.getInvalidFields(t)}resetChangedRows(t){const e=this.changedRows,i=this.changedRowIds;this.#C.changedRowIds.clear(),this.#C.committedDirtyRowIds.clear(),this.#A(),t||this.emit("changed-rows-reset",{rows:e,ids:i}),this.#s._rowPool?.forEach(t=>t.classList.remove("changed"))}beginCellEdit(t,e){const i=this.#s,n=i._visibleColumns.findIndex(t=>t.field===e);if(-1===n)return;const r=i._visibleColumns[n],o=i._rows[t];if(!r||!o||!this.#o(r,o))return;const s=this.#X(t,n);s&&(this.#E=!0,this.#Q(t,n,s))}beginBulkEdit(t){const e=this.#s;if(!1===(this.config.editOn??e.effectiveConfig?.editOn))return;if(!e._columns?.some(t=>this.#l(t)))return;const i=e.findRenderedRowElement?.(t);if(!i)return;const n=e._rows[t];this.#F(n)&&(this.#E=!1,this.#tt(t,n),Array.from(i.children).forEach((i,r)=>{const o=e._visibleColumns[r];if(o&&this.#o(o,n)){const e=i;e.classList.contains("editing")||this.#Y(n,t,o,r,e,!0)}}),setTimeout(()=>{let t=i.querySelector(`.cell[data-col="${e._focusCol}"]`);if(t?.classList.contains("editing")||(t=i.querySelector(".cell.editing")),t?.classList.contains("editing")){const e=t.querySelector(z);try{e?.focus({preventScroll:!0})}catch{}}},0))}commitActiveRowEdit(){-1!==this.#a&&this.#x(this.#a,!1)}cancelActiveRowEdit(){-1!==this.#a&&this.#x(this.#a,!0)}#G(t){if(t)try{return this.#s.getRowId?.(t)}catch{return}}#X(t,e){return(this.#s.findRenderedRowElement?.(t))?.querySelector(`.cell[data-col="${e}"]`)??null}#F(t){if(!t)return!0;const e=this.#s.effectiveConfig?.rowEditable;return!e||!1!==e(t)}#T(t,e,i){this.emit("dirty-change",{rowId:t,row:e,original:this.#C.getOriginalRow(t),type:i})}#q(){this.#et();const t=document.activeElement;t&&this.gridElement.contains(t)&&(t.blur(),this.gridElement.focus()),this.#y=!1,this.#b=!0}#it(t,e,i){i&&(Object.keys(i).forEach(t=>{e[t]=i[t]}),t&&(this.#C.changedRowIds.delete(t),this.#C.committedDirtyRowIds.delete(t),this.clearRowInvalid(t)))}#S(t,e,i){const r=this.#s,o=r._visibleColumns?.findIndex(t=>t.field===e);if(-1===o||void 0===o)return;const s=r._rows?.findIndex(e=>this.#G(e)===t);if(-1===s||void 0===s)return;const l=this.#X(s,o);if(l)if(i){l.setAttribute("data-invalid","true"),l.setAttribute("aria-invalid","true");const i=this.#v.getInvalidMessage(t,e);i&&(l.setAttribute("title",i),l.removeAttribute(n))}else l.removeAttribute("data-invalid"),l.removeAttribute("aria-invalid"),l.removeAttribute("title")}#Z(t,e){this.#a=e;const i=/* @__PURE__ */new Set,n=`${t}:`;for(const s of this.#f)s.startsWith(n)?i.add(`${e}:${s.substring(n.length)}`):i.add(s);this.#f.clear();for(const s of i)this.#f.add(s);const r=this.#h.get(t);void 0!==r&&(this.#h.delete(t),this.#h.set(e,r));const o=[];for(const[s,l]of this.#w)s.startsWith(n)&&(o.push([`${e}:${s.substring(n.length)}`,l]),this.#w.delete(s));for(const[s,l]of o)this.#w.set(s,l);this.#A()}#Q(t,e,i){const n=this.#s,r=n._rows[t],o=n._visibleColumns[e];r&&o&&this.#o(o,r)&&(i.classList.contains("editing")||(this.#a!==t&&this.#tt(t,r),this.#u=e,this.#Y(r,t,o,e,i,!1)))}#et(){const t=this.#R;if(!t)return;const e=this.#s._rows?.[t.rowIndex];e&&f(e,t.field,t.value);const i=`${t.rowIndex}:${t.field}`,n=this.#w.get(i);if(n&&n(t.value),this.emit("cell-cancel",{rowIndex:t.rowIndex,colIndex:t.colIndex,field:t.field,previousValue:t.value}),e){const t=this.#G(e);t&&(this.config.dirtyTracking?this.#C.isRowDirty(t,e)||(this.#C.changedRowIds.delete(t),this.#T(t,e,"reverted")):this.#C.changedRowIds.delete(t))}this.requestRender(),this.#R=null}#D(){const t=this.#s,e=t._focusRow,i=t._focusCol;if(e<0||i<0)return;const n=this.#X(e,i);if(n?.classList.contains("editing")){const t=n.querySelector(z);t&&(this.#b=!1,t.focus(),this.#y=!0,t instanceof HTMLInputElement&&("text"===t.type||"number"===t.type)&&t.select())}}#W(t){const e=this.#s,i=e._rows,n=this.#r?e._focusRow:this.#a,r=i[n],o=e._visibleColumns.map((t,e)=>r&&this.#o(t,r)?e:-1).filter(t=>t>=0);if(0===o.length)return;const s=o.indexOf(e._focusCol)+(t?1:-1);if(s>=0&&s<o.length){e._focusCol=o[s];const t=this.#X(n,o[s]);return t?.classList.contains("editing")&&t.querySelector(z)?.focus({preventScroll:!0}),void m(e,{forceHorizontalScroll:!0})}const l=n+(t?1:-1);if(l>=0&&l<i.length){const r=i[l],o=e._visibleColumns.map((t,e)=>r&&this.#o(t,r)?e:-1).filter(t=>t>=0);if(0===o.length)return;this.#r?(e._focusRow=l,e._focusCol=t?o[0]:o[o.length-1],m(e,{forceHorizontalScroll:!0}),this.requestAfterRender(),setTimeout(()=>{const t=this.#X(l,e._focusCol);t?.classList.contains("editing")&&t.querySelector(z)?.focus({preventScroll:!0})},0)):(this.#x(n,!1),e._focusRow=l,e._focusCol=t?o[0]:o[o.length-1],this.beginBulkEdit(l),m(e,{forceHorizontalScroll:!0}))}}#A(){const t=this.#s;t._activeEditRows=this.#a,t._rowEditSnapshots=this.#h}#tt(t,e){this.#a!==t&&(-1!==this.#a&&this.#x(this.#a,!1),this.#h.set(t,{...e}),this.#a=t,this.#c=e,this.#d=this.#G(e),this.#A(),this.#r||(this.broadcast("edit-open",{rowIndex:t,rowId:this.#d??"",row:e}),s(this.gridElement,l(this.gridElement,"editingStarted",t))))}#x(t,e){if(this.#a!==t)return;const i=this.#s,n=this.#h.get(t),r=i.findRenderedRowElement?.(t),{rowId:o,current:a}=this.#nt(t);!e&&r&&a&&this.#rt(r,t,a),e||this.#r||!a||this.emit("before-edit-close",{rowIndex:t,rowId:o??"",row:a}),e&&a?this.#it(o,a,n):!e&&a&&this.#ot(t,o,a,n),this.#st(t),this.#m=!0,r?this.#lt(r,i):(this.#J(i),this.#m=!1),!this.#r&&a&&(this.broadcast("edit-close",{rowIndex:t,rowId:o??"",row:a,reverted:e}),e||s(this.gridElement,l(this.gridElement,"editingCommitted",t)))}#nt(t){const e=this.#s;let i=this.#d;const n=(i?e._getRowEntry(i):void 0)?.row??this.#c??e._rows[t];return!i&&n&&(i=this.#G(n)),{rowId:i,current:n}}#rt(t,e,i){const n=this.#s;t.querySelectorAll(".cell.editing").forEach(t=>{const r=Number(t.getAttribute("data-col"));if(isNaN(r))return;const o=n._visibleColumns[r];if(!o)return;if(t.hasAttribute("data-editor-managed"))return;const s=t.querySelector("input,textarea,select");if(!s)return;const l=o.field,a=h(i,l),d=P(s,o,a);a!==d&&this.#k(e,o,d,i)})}#ot(t,e,i,n){const r=function(t,e){if(!t)return!1;const i=t,n=e,r=/* @__PURE__ */new Set([...Object.keys(i),...Object.keys(n)]);for(const o of r)if(i[o]!==n[o])return!0;return!1}(n,i),o=e?this.#C.changedRowIds.has(e):r;this.emitCancelable("row-commit",{rowIndex:t,rowId:e??"",row:i,oldValue:n,newValue:i,changed:o,changedRows:this.changedRows,changedRowIds:this.changedRowIds})?n&&this.#it(e,i,n):(e&&this.config.dirtyTracking&&(this.#C.isRowDirty(e,i)?this.#C.committedDirtyRowIds.add(e):this.#C.committedDirtyRowIds.delete(e)),r&&this.isAnimationEnabled&&(this.#p=t))}#st(t){this.#h.delete(t),this.#a=-1,this.#d=void 0,this.#c=void 0,this.#u=-1,this.#E=!1,this.#A();for(const e of this.#f)e.startsWith(`${t}:`)&&this.#f.delete(e);for(const e of this.#w.keys())e.startsWith(`${t}:`)&&this.#w.delete(e)}#lt(t,e){const i=e.__frameworkAdapter,n=t.querySelectorAll(".cell.editing");i?.releaseCell&&n.forEach(t=>{i.releaseCell(t)}),n.forEach(t=>{t.classList.remove("editing"),function(t){t.__editingCellCount=0,t.removeAttribute("data-has-editing")}(t.parentElement)}),e.refreshVirtualWindow(!0)}#k(t,e,i,n,r="user"){const o=e.field;if(!K(o))return;const s=h(n,o);if(s===i)return;const l=this.#s,a=this.#G(n),d=!a||!this.#C.changedRowIds.has(a),c=a?t=>this.grid.updateRow(a,t,"cascade"):U;let u=!1;const w=a?t=>{u=!0,this.setInvalid(a,o,t??"")}:()=>{},m=`${a??t}\0${o}`;if(this.#I.has(m))return;let p=!1;this.#I.add(m);try{p=this.emitCancelable("cell-commit",{row:n,rowId:a??"",field:o,oldValue:s,value:i,source:r,rowIndex:t,changedRows:this.changedRows,changedRowIds:this.changedRowIds,firstTimeForRow:d,updateRow:c,setInvalid:w})}finally{this.#I.delete(m)}if(p)return;if(a&&!u&&this.isCellInvalid(a,o)&&this.clearInvalid(a,o),f(n,o,i),g(n),a&&this.#C.changedRowIds.add(a),this.#A(),this.config.dirtyTracking&&a){const t=this.#C.isRowDirty(a,n);this.#T(a,n,t?"modified":"pristine")}this.emitPluginEvent("cell-edit-committed",{rowIndex:t,field:o,oldValue:s,newValue:i});const v=l.findRenderedRowElement?.(t);v&&v.classList.add("changed")}#Y(t,e,i,n,r,o,s){J(this.#_,t,e,i,n,r,o,s)}#J(t){queueMicrotask(()=>{try{const e=t._focusRow,i=t._focusCol,n=t.findRenderedRowElement?.(e);if(n){Array.from(t._bodyEl.querySelectorAll(".cell-focus")).forEach(t=>t.classList.remove("cell-focus"));const r=n.querySelector(`.cell[data-row="${e}"][data-col="${i}"]`);r&&(r.classList.add("cell-focus"),r.setAttribute("aria-selected","true"),r.hasAttribute("tabindex")||r.setAttribute("tabindex","-1"),r.focus({preventScroll:!0}))}}catch{}})}};export{X as EditingPlugin,$ as defaultEditorFor};
1
+ import{readCellField as t,writeCellField as e}from"@toolbox-web/grid";var i="editing",n="data-tbw-truncated",r={sortApplied:(t,e)=>`Sorted by ${t}, ${e}`,sortCleared:()=>"Sort cleared",filterApplied:t=>`Filter applied on ${t}`,filterCleared:t=>`Filter cleared from ${t}`,allFiltersCleared:()=>"All filters cleared",groupExpanded:(t,e)=>`Group ${t} expanded, ${e} rows`,groupCollapsed:t=>`Group ${t} collapsed`,selectionChanged:t=>`${t} rows selected`,selectAllRows:()=>"Select all rows",selectRow:t=>`Select row ${t+1}`,columnSelected:t=>`Column ${t} selected`,columnSelectionChanged:t=>`${t} columns selected`,columnSelectionCleared:()=>"Column selection cleared",selectionAxisChanged:t=>"column"===t?"Row selection cleared, column selection active":"Column selection cleared, row selection active",editingStarted:t=>`Editing row ${t+1}`,editingCommitted:t=>`Row ${t+1} saved`,dataLoaded:t=>`${t} rows loaded`},o={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};function s(t,e){if(!t)return;if(!1===("effectiveConfig"in t?t.effectiveConfig:void 0)?.a11y?.announcements)return;const i=t.querySelector?.(".tbw-sr-only");i&&(i.textContent="","function"==typeof requestAnimationFrame?requestAnimationFrame(()=>{i.textContent=e}):i.textContent=e)}function l(t,e,...i){const n=(t&&"effectiveConfig"in t?t.effectiveConfig:void 0)?.a11y?.messages?.[e];return n?n(...i):r[e](...i)}var a=/* @__PURE__ */new WeakMap;function d(t){return"__proto__"===t||"constructor"===t||"prototype"===t}var c=/* @__PURE__ */new Map;function u(t){if(-1===t.indexOf("."))return null;let e=c.get(t);return void 0===e&&(e=Object.freeze(t.split(".")),c.set(t,e)),e}function h(t,e){if(null==t)return;const i=u(e),n=t;return null===i?d(e)?void 0:n[e]:Object.prototype.hasOwnProperty.call(n,e)?n[e]:function(t,e){let i=t;for(let n=0;n<e.length;n++){if(null==i||"object"!=typeof i)return;const t=e[n];if(d(t))return;i=i[t]}return i}(n,i)}function f(t,e,i){if(null==t||"object"!=typeof t)return!1;const n=u(e),r=t;return null===n?!d(e)&&(r[e]=i,!0):Object.prototype.hasOwnProperty.call(r,e)?(r[e]=i,!0):function(t,e,i){if(null==t||"object"!=typeof t)return!1;let n=t;for(let o=0;o<e.length-1;o++){const t=e[o];if(d(t))return!1;const i=n[t];if(null==i||"object"!=typeof i)return!1;n=i}const r=e[e.length-1];return!d(r)&&(n[r]=i,!0)}(r,n,i)}function g(t,e){t&&(e?a.get(t)?.delete(e):a.delete(t))}function w(t,e){if(!e.capped)return t;const i=e.spacerHeight-e.viewportHeight,n=e.rawContentHeight-e.viewportHeight;return i<=0||n<=0?t:t*i/n}function m(t,e){!function(t){if(!t._virtualization?.enabled)return;const{rowHeight:e,container:i,viewportEl:n,scrollMapping:r}=t._virtualization,o=i,s=n?.clientHeight??o?.clientHeight??0;if(!o||s<=0)return;const l=t._getVerticalScrollOffsets?.(t._focusRow)??{top:0,bottom:0};if(l.skipScroll)return;const a=Math.max(0,l.top),d=s-a-Math.max(0,l.bottom);if(d<=0)return;const c=t._focusRow*e,u=r?function(t,e){if(!e.capped)return t;const i=e.spacerHeight-e.viewportHeight,n=e.rawContentHeight-e.viewportHeight;if(i<=0||n<=0)return t;const r=t*n/i;return r<0?0:r>n?n:r}(o.scrollTop,r):o.scrollTop;if(c<u+a){const t=Math.max(0,c-a);o.scrollTop=r?w(t,r):t}else if(c+e>u+a+d){const t=Math.max(0,c-d+e-a);o.scrollTop=r?w(t,r):t}}(t);const n=function(t){return void 0!==t._activeEditRows&&-1!==t._activeEditRows}(t)||!!t._isGridEditMode;var r;n||t.refreshVirtualWindow(!1),(r=t._bodyEl)&&r.querySelectorAll(".cell-focus").forEach(t=>t.classList.remove("cell-focus")),Array.from(t._bodyEl.querySelectorAll('[aria-selected="true"]')).forEach(t=>{t.setAttribute("aria-selected","false")});const o=function(t){const e=t._focusRow,i=t._virtualization.start??0,n=t._virtualization.end??t._rows.length;if(e<i||e>=n)return;const r=t._bodyEl.querySelectorAll(".data-grid-row")[e-i];let o=r?.children[t._focusCol];return o&&o.classList?.contains("cell")||(o=r?.querySelector(`.cell[data-col="${t._focusCol}"]`)??r?.querySelector(".cell[data-col]")),o?{rowEl:r??null,cell:o}:void 0}(t);if(!o)return;const{rowEl:s,cell:l}=o;l.classList.add("cell-focus"),l.setAttribute("aria-selected","true"),n&&!e?.forceHorizontalScroll||function(t,e,i,n){const r=t.querySelector(".tbw-scroll-area");if(!r)return;if(n?.forceScrollLeft)return void(r.scrollLeft=0);if(n?.forceScrollRight)return void(r.scrollLeft=r.scrollWidth-r.clientWidth);const o=t._getHorizontalScrollOffsets?.(e??void 0,i)??{left:0,right:0};if(o.skipScroll)return;const s=i.getBoundingClientRect(),l=r.getBoundingClientRect(),a=s.left-l.left+r.scrollLeft,d=a+s.width,c=r.scrollLeft+o.left,u=r.scrollLeft+r.clientWidth-o.right;a<c?r.scrollLeft=a-o.left:d>u&&(r.scrollLeft=d-r.clientWidth+o.right)}(t,s,l,e),function(t,e,n){if(n&&e.classList.contains(i)){const t=e.querySelector('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])');if(t&&document.activeElement!==t)try{t.focus({preventScroll:!0})}catch{}return}if(n){if(e.contains(document.activeElement))return;e.hasAttribute("tabindex")||e.setAttribute("tabindex","-1");try{e.focus({preventScroll:!0})}catch{}return}const r=document.activeElement;r instanceof HTMLElement&&r!==t&&"function"==typeof t.contains&&t.contains(r)&&!r.classList.contains("cell")&&!r.closest(".cell")||r===t||t.focus({preventScroll:!0})}(t,l,n)}var p=/{{\s*([^}]+)\s*}}/g,v="__DG_EMPTY__",y=/^[\w$. '?+\-*/%:()!<>=,&|]+$/,b="__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("")),E=new RegExp(`__(proto|defineGetter|defineSetter)|${b.slice(3).join("|")}|this\\b`);var R=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,I=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),_=/^\s*(javascript|vbscript|data|blob):/i;function S(t){const e=document.createElement("template");return t&&"string"==typeof t&&(e.innerHTML=t,function(t){const e=[],i=t.querySelectorAll("*");for(const n of i){const t=n.tagName.toLowerCase();if(R.has(t)){e.push(n);continue}if(("svg"===t||"http://www.w3.org/2000/svg"===n.namespaceURI)&&Array.from(n.attributes).some(t=>C.test(t.name)||"href"===t.name||"xlink:href"===t.name)){e.push(n);continue}const i=[];for(const e of n.attributes){const t=e.name.toLowerCase();C.test(t)?i.push(e.name):"is"!==t?(I.has(t)&&_.test(e.value)||"style"===t&&/expression\s*\(|javascript:|behavior\s*:/i.test(e.value))&&i.push(e.name):i.push(e.name)}i.forEach(t=>n.removeAttribute(t))}e.forEach(t=>t.remove())}(e.content)),e.content}function k(t,e){const i=function(t){const e=[];let i=0;for(;i<t.length;){const n=t[i];if(" "!==n){if(n>="0"&&n<="9"||"."===n&&i+1<t.length&&t[i+1]>="0"&&t[i+1]<="9"){const n=i;for(;i<t.length&&(t[i]>="0"&&t[i]<="9"||"."===t[i]);)i++;e.push({type:"num",v:Number(t.slice(n,i))});continue}if("'"===n){let n="";for(i++;i<t.length&&"'"!==t[i];)n+=t[i++];if(i>=t.length)return null;i++,e.push({type:"str",v:n});continue}if(n>="a"&&n<="z"||n>="A"&&n<="Z"||"_"===n||"$"===n){const n=i;for(;i<t.length&&/[\w$.]/.test(t[i]);)i++;e.push({type:"id",v:t.slice(n,i)});continue}if(i+2<t.length){const n=t.slice(i,i+3);if("==="===n||"!=="===n){e.push({type:"op",v:n}),i+=3;continue}}if(i+1<t.length){const n=t.slice(i,i+2);if("=="===n||"!="===n||"<="===n||">="===n||"&&"===n||"||"===n){e.push({type:"op",v:n}),i+=2;continue}}if(!"+-*/%<>!?:(),".includes(n))return null;e.push({type:"op",v:n}),i++}else i++}return e}(t);if(!i)return;const n=i;let r=0;function o(){return n[r]}function s(){return n[r++]}function l(t,e){const i=o();return!!i&&(i.type===t&&(void 0===e||i.v===e))}function a(){const t=function(){let t=d();for(;l("op","||");)s(),t=t||d();return t}();if(l("op","?")){s();const e=a();if(!l("op",":"))return;s();const i=a();return t?e:i}return t}function d(){let t=c();for(;l("op","&&");)s(),t=t&&c();return t}function c(){let t=u();for(;;){const e=o();if(!e||"op"!==e.type)break;if("==="===e.v)s(),t=t===u();else if("!=="===e.v)s(),t=t!==u();else if("=="===e.v)s(),t=t==u();else{if("!="!==e.v)break;s(),t=t!=u()}}return t}function u(){let t=h();for(;;){const e=o();if(!e||"op"!==e.type)break;if("<"===e.v)s(),t=t<h();else if(">"===e.v)s(),t=t>h();else if("<="===e.v)s(),t=t<=h();else{if(">="!==e.v)break;s(),t=t>=h()}}return t}function h(){let t=f();for(;;){const e=o();if(!e||"op"!==e.type)break;if("+"===e.v)s(),t+=f();else{if("-"!==e.v)break;s(),t-=f()}}return t}function f(){let t=g();for(;;){const e=o();if(!e||"op"!==e.type)break;if("*"===e.v)s(),t*=g();else if("/"===e.v)s(),t/=g();else{if("%"!==e.v)break;s(),t%=g()}}return t}function g(){return l("op","!")?(s(),!g()):w()}function w(){const t=o();if(t){if("num"===t.type)return s(),t.v;if("str"===t.type)return s(),t.v;if("id"===t.type)return s(),function(t){if("value"===t)return e.value;if(t.startsWith("row.")){const i=t.slice(4);return e.row?e.row[i]:void 0}if(t.startsWith("typeDefault.")){const i=t.slice(12);return e.typeDefault?e.typeDefault[i]:void 0}return"row"===t?e.row:"typeDefault"===t?e.typeDefault:void 0}(t.v);if("op"===t.type&&"("===t.v){s();const t=a();return l("op",")")&&s(),t}return"op"===t.type&&"-"===t.v?(s(),-w()):void 0}}const m=a();return r<n.length?void 0:m}function x(t,e){if(!t||-1===t.indexOf("{{"))return t;const i=[],n=(r=t.replace(p,(t,n)=>{const r=function(t,e){if(!(t=(t||"").trim()))return v;if(A.test(t))return v;if("value"===t)return null==e.value?v:String(e.value);if(t.startsWith("row.")&&!/[()?]/.test(t)&&!t.includes(":")){const i=t.slice(4),n=e.row?e.row[i]:void 0;return null==n?v:String(n)}if(t.startsWith("typeDefault.")&&!/[()?]/.test(t)&&!t.includes(":")){const i=t.slice(12),n=e.typeDefault?e.typeDefault[i]:void 0;return null==n?v:String(n)}if(t.length>80)return v;if(!y.test(t)||E.test(t))return v;const i=t.match(/\./g);if(i&&i.length>1)return v;try{const i=k(t,e),n=null==i?"":String(i);return A.test(n)?v:n||v}catch{return v}}(n,e);return i.push({expr:n.trim(),result:r}),r===v?r:(o=r)&&"string"==typeof o?o.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;"):"";var o}),r?r.replace(new RegExp(v,"g"),"").replace(/Reflect\.[^<>{}\s]+|\bProxy\b|ownKeys\([^)]*\)/g,""):r);var r;const o=i.length&&i.every(t=>""===t.result||t.result===v);return A.test(t)||o?"":n}var A=/Reflect|Proxy|ownKeys/;function M(t){if(A.test(t)){const t=()=>"";return t.__blocked=!0,t}const e=e=>x(t,e);return e.__blocked=!1,e}function L(t,e){return`[tbw-grid${t?`#${t}`:""}${e?`:${e}`:""}]`}function D(t,e,i,n){return`${L(i,n)} ${t}: ${e}\n\n → More info: ${function(t){return`https://toolboxjs.com/grid/errors#${t.toLowerCase()}`}(t)}`}var G=class{static dependencies;static manifest;aliases;version="3.8.2";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},i={};for(const n of Object.keys(e))i[n]=this;for(const n of t){const t=n.userConfig;for(const[r,o]of Object.entries(t)){if(void 0===o)continue;if(!(r in e)){e[r]=o,i[r]=n;continue}if(e[r]===o)continue;const t=i[r]?.constructor.name??this.constructor.name,s=n.constructor.name,l=D("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${r}" supplied by both ${t} and ${s}. Pass the option on a single instance, or remove the duplicate.`,void 0,this.name);throw new Error(l)}}Object.assign(this.userConfig,e)}refreshUserConfigFrom(t){const e=this.userConfig,i={...t.userConfig};for(const n of Object.keys(e))delete e[n];Object.assign(e,i)}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 i=new CustomEvent(t,{detail:e,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(i),i.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 i=this.grid?.query?.(t,e);return Array.isArray(i)?i.some(Boolean):!!i}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{...o,...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(),i=parseInt(e,10);if(!isNaN(i))return i}return 200}setIcon(t,e,i){t.dataset.icon=e.replace(/([A-Z])/g,"-$1").toLowerCase(),"collapse"===e?t.dataset.expanded="":"expand"===e&&delete t.dataset.expanded;const n=this.#e(e,i);var r,o;void 0!==n?"string"==typeof n?(r=t,(o=n)&&"string"==typeof o?-1!==o.indexOf("<")||-1!==o.indexOf("&")?r.replaceChildren(S(o)):r.textContent=o:r.replaceChildren()):n instanceof HTMLElement&&t.replaceChildren(n.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 i=document.createElement("span");i.setAttribute("part","sort-indicator"),i.className="sort-indicator",e?(t.setAttribute("aria-sort","asc"===e?"ascending":"descending"),t.setAttribute("data-sort",e),this.setIcon(i,"asc"===e?"sortAsc":"sortDesc")):(t.setAttribute("aria-sort","none"),t.removeAttribute("data-sort"),this.setIcon(i,"sortNone"));const n=t.querySelector(".tbw-filter-btn")??t.querySelector(".resize-handle");return n?t.insertBefore(i,n):t.appendChild(i),i}warn(t,e){void 0!==e?console.warn(D(t,e,this.gridElement.id,this.name)):console.warn(`${L(this.gridElement.id,this.name)} ${t}`)}throwDiagnostic(t,e){throw new Error(D(t,e,this.gridElement.id,this.name))}};function T(t){return e=>{const i=t.editorParams,n=document.createElement("input");n.type="date",e.value instanceof Date?n.valueAsDate=e.value:"string"==typeof e.value&&e.value&&(n.value=e.value.split("T")[0]),i?.min&&(n.min=i.min),i?.max&&(n.max=i.max),i?.placeholder&&(n.placeholder=i.placeholder);return n.addEventListener("change",()=>{var r;if(n.value)"string"==typeof e.value?e.commit(n.value):e.commit(n.valueAsDate);else if(t.nullable)e.commit(null);else{const t=i?.default;"string"==typeof e.value||"string"==typeof t?e.commit("string"==typeof t?t:`${(r=t??/* @__PURE__ */new Date).getFullYear()}-${String(r.getMonth()+1).padStart(2,"0")}-${String(r.getDate()).padStart(2,"0")}`):e.commit(t instanceof Date?t:/* @__PURE__ */new Date)}}),n.addEventListener("keydown",t=>{"Escape"===t.key&&e.cancel()}),n}}var q="__tbw_null__";function $(t){switch(t.type){case"number":return function(t){return e=>{const i=t.editorParams,n=document.createElement("input");n.type="number",n.value=null!=e.value?String(e.value):"",void 0!==i?.min&&(n.min=String(i.min)),void 0!==i?.max&&(n.max=String(i.max)),void 0!==i?.step&&(n.step=String(i.step)),i?.placeholder&&(n.placeholder=i.placeholder);const r=()=>{""===n.value?t.nullable?e.commit(null):e.commit(i?.min??0):e.commit(Number(n.value))};return n.addEventListener("blur",r),n.addEventListener("keydown",t=>{"Enter"===t.key&&r(),"Escape"===t.key&&e.cancel()}),n}}(t);case"boolean":return t=>{const e=document.createElement("input");return e.type="checkbox",e.checked=!!t.value,e.addEventListener("change",()=>t.commit(e.checked)),e};case"date":return T(t);case"select":return function(t){return e=>{const i=t.editorParams,n=document.createElement("select");if(t.multi&&(n.multiple=!0),t.nullable||i?.includeEmpty){const r=document.createElement("option");r.value=t.nullable?q:"",r.textContent=t.nullable?i?.emptyLabel??"(Blank)":i?.emptyLabel??"",null==e.value&&(r.selected=!0),n.appendChild(r)}(function(t){const e=t.options;return e?"function"==typeof e?e():e:[]})(t).forEach(i=>{const r=document.createElement("option");r.value=String(i.value),r.textContent=i.label,t.multi&&Array.isArray(e.value)&&e.value.includes(i.value)?r.selected=!0:t.multi||e.value!==i.value||(r.selected=!0),n.appendChild(r)});const r=()=>{if(t.multi){const t=Array.from(n.selectedOptions).map(t=>t.value);e.commit(t)}else t.nullable&&n.value===q?e.commit(null):e.commit(n.value)};return n.addEventListener("change",r),n.addEventListener("blur",r),n.addEventListener("keydown",t=>{"Escape"===t.key&&e.cancel()}),n}}(t);default:return function(t){return e=>{const i=t.editorParams,n=document.createElement("input");n.type="text",n.value=null!=e.value?String(e.value):"",void 0!==i?.maxLength&&(n.maxLength=i.maxLength),i?.pattern&&(n.pattern=i.pattern),i?.placeholder&&(n.placeholder=i.placeholder);const r=()=>{const i=n.value;""!==i?"string"==typeof e.value&&i===e.value.replace(/[\n\r]/g,"")||("number"==typeof e.value?e.commit(Number(i)):e.commit(i)):t.nullable?e.commit(null):e.commit("")};return n.addEventListener("blur",r),n.addEventListener("keydown",t=>{"Enter"===t.key&&r(),"Escape"===t.key&&e.cancel()}),n}}(t)}}function F(t,e){return""===t?e?.nullable?null:(e?.editorParams)?.min??0:Number(t)}function P(t,e,i){if(!(t instanceof HTMLInputElement))return function(t,e,i){return""===t.value||"number"!==e?.type&&"number"!=typeof i?null==i&&""===t.value?e?.nullable?null:"":t.value:Number(t.value)}(t,e,i);switch(t.type){case"checkbox":return t.checked;case"number":return F(t.value,e);case"date":return function(t,e,i){return t.value?"string"==typeof i?t.value:t.valueAsDate:e?.nullable?null:"string"==typeof i?i||/* @__PURE__ */(new Date).toISOString().slice(0,10):i??/* @__PURE__ */new Date}(t,e,i);default:return function(t,e,i){return"number"==typeof i?F(t.value,e):""===t.value&&null==i?e?.nullable?null:"":"string"==typeof i&&t.value===i.replace(/[\n\r]/g,"")?i:t.value}(t,e,i)}}var V=class{#i=/* @__PURE__ */new Map;#n;constructor(t){this.#n=t}setInvalid(t,e,i=""){let n=this.#i.get(t);n||(n=/* @__PURE__ */new Map,this.#i.set(t,n)),n.set(e,i),this.#n(t,e,!0)}clearInvalid(t,e){const i=this.#i.get(t);i&&(i.delete(e),0===i.size&&this.#i.delete(t)),this.#n(t,e,!1)}clearRowInvalid(t){const e=this.#i.get(t);if(e){const i=Array.from(e.keys());this.#i.delete(t),i.forEach(e=>this.#n(t,e,!1))}}clearAllInvalid(){const t=Array.from(this.#i.entries());this.#i.clear(),t.forEach(([t,e])=>{e.forEach((e,i)=>this.#n(t,i,!1))})}isCellInvalid(t,e){return this.#i.get(t)?.has(e)??!1}getInvalidMessage(t,e){return this.#i.get(t)?.get(e)}hasInvalidCells(t){const e=this.#i.get(t);return!!e&&e.size>0}getInvalidFields(t){return new Map(this.#i.get(t)??[])}};function O(t,e,i){const n=t.get(e);return!!n&&!H(n,i)}function H(t,e){if(t===e)return!0;if(null==t||null==e)return!1;if(typeof t!=typeof e)return!1;if(t instanceof Date&&e instanceof Date)return t.getTime()===e.getTime();if(Array.isArray(t)){if(!Array.isArray(e)||t.length!==e.length)return!1;for(let i=0;i<t.length;i++)if(!H(t[i],e[i]))return!1;return!0}if("object"==typeof t){const i=t,n=e,r=Object.keys(i),o=Object.keys(n);if(r.length!==o.length)return!1;for(const t of r)if(!H(i[t],n[t]))return!1;return!0}return!1}function j(t,e,i){t.set(e,structuredClone(i))}function N(t,e,i){const n=t.get(e);if(!n)return!1;const r=n,o=i;for(const s of Object.keys(r))o[s]=r[s];return!0}var W=class{baselines=/* @__PURE__ */new Map;baselinesWereCaptured=!1;newRowIds=/* @__PURE__ */new Set;changedRowIds=/* @__PURE__ */new Set;committedDirtyRowIds=/* @__PURE__ */new Set;clear(){this.changedRowIds.clear(),this.committedDirtyRowIds.clear(),this.baselines.clear(),this.newRowIds.clear(),this.baselinesWereCaptured=!1}capture(t,e){const i=this.baselines.size;!function(t,e,i){for(const n of e)try{const e=i(n);null==e||t.has(e)||t.set(e,structuredClone(n))}catch{}}(this.baselines,t,e),this.baselines.size>i&&(this.baselinesWereCaptured=!0)}drainCapturedFlag(){return this.baselinesWereCaptured?(this.baselinesWereCaptured=!1,this.baselines.size):null}isRowDirty(t,e){return O(this.baselines,t,e)}hasAnyDirty(t){if(this.newRowIds.size>0)return!0;for(const[e]of this.baselines){const i=t(e);if(i&&O(this.baselines,e,i))return!0}return!1}isCellDirty(e,i,n){return function(e,i,n,r){const o=e.get(i);return!!o&&!H(t(o,r),t(n,r))}(this.baselines,e,i,n)}getRowDirtyState(t,e){const i=this.newRowIds.has(t);return{isNew:i,isCommittedDirty:!i&&this.committedDirtyRowIds.has(t)&&O(this.baselines,t,e),hasBaseline:this.baselines.has(t)}}markPristine(t,e){j(this.baselines,t,e),this.newRowIds.delete(t),this.changedRowIds.delete(t),this.committedDirtyRowIds.delete(t)}rebaselineCell(t,i,n){const r=this.baselines.get(t);r&&e(r,i,n)}markNew(t){this.newRowIds.add(t),this.committedDirtyRowIds.add(t)}markDirty(t){this.changedRowIds.add(t),this.committedDirtyRowIds.add(t)}markAllPristine(t){for(const[e]of this.baselines){const i=t(e);i&&j(this.baselines,e,i)}this.newRowIds.clear(),this.changedRowIds.clear(),this.committedDirtyRowIds.clear()}getOriginalRow(t){return function(t,e){const i=t.get(e);return i?structuredClone(i):void 0}(this.baselines,t)}hasBaseline(t){return this.baselines.has(t)}getDirtyRows(t){const e=[];for(const[i,n]of this.baselines){const r=t(i);r&&O(this.baselines,i,r)&&e.push({id:i,original:structuredClone(n),current:r})}for(const i of this.newRowIds){const n=t(i);n&&e.push({id:i,original:void 0,current:n})}return e}getDirtyRowIds(t){const e=[];for(const[i]of this.baselines){const n=t(i);n&&O(this.baselines,i,n)&&e.push(i)}for(const i of this.newRowIds)e.push(i);return e}revertRow(t,e){const i=N(this.baselines,t,e);return i&&(this.changedRowIds.delete(t),this.committedDirtyRowIds.delete(t)),i}revertAll(t){for(const[e]of this.baselines){const i=t(e);i&&N(this.baselines,e,i)}this.changedRowIds.clear(),this.committedDirtyRowIds.clear()}getChangedRows(t){const e=[];for(const i of this.changedRowIds){const n=t(i);n&&e.push(n)}return e}getChangedRowIds(){return Array.from(this.changedRowIds)}isRowChanged(t){return this.changedRowIds.has(t)}},z='input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])';function B(t){return t?.closest?.('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])')??null}function K(t){return"string"==typeof t&&("__proto__"!==t&&"constructor"!==t&&"prototype"!==t)}function U(t){}function Z(t,e){return!1===t.onBeforeEditClose?.(e)}function J(i,n,r,o,s,l,a,d){if(!o.editable)return;if(l.classList.contains("editing"))return;const{grid:c,isGridMode:u,config:h,editingCells:f,editorValueCallbacks:g}=i;let w;try{w=c.getRowId?.(n)}catch{}const m=w?t=>c.updateRow(w,t,"cascade"):U,p=K(o.field)?t(n,o.field):void 0;l.classList.add("editing"),f.add(`${r}:${s}`);const v=d??l.parentElement;v&&function(t){t.__editingCellCount=(t.__editingCellCount??0)+1,t.setAttribute("data-has-editing","")}(v);let y=!1;const b=t=>{if(y||!u&&!i.isEditSessionActive())return;const e=w?c._getRowEntry(w):void 0,s=e?.row??n,l=e?.index??r;i.commitCellValue(l,o,t,s)},E=()=>{if(y=!0,K(o.field)){const t=(w?c._getRowEntry(w):void 0)?.row??n;e(t,o.field,p)}},R=document.createElement("div");R.className="tbw-editor-host",l.firstElementChild&&c.__frameworkAdapter?.releaseCell?.(l),l.innerHTML="",l.appendChild(R),R.addEventListener("keydown",t=>{if(!t.defaultPrevented){if("Enter"===t.key){const e=t.target;if(e&&"true"===e.getAttribute?.("aria-expanded")&&e.hasAttribute?.("aria-controls"))return}if("Enter"===t.key){const e=t.target,n=B(e);if(n&&n!==e)return;if(u){t.preventDefault();const e=R.querySelector("input,textarea,select");return void(e&&b(P(e,o,p)))}if(Z(h,t))return;t.stopPropagation(),t.preventDefault(),y=!0,i.exitRowEdit(r,!1)}if("Escape"===t.key){if(u)return t.stopPropagation(),void t.preventDefault();if(Z(h,t))return;t.stopPropagation(),t.preventDefault(),E(),i.exitRowEdit(r,!0)}}});const C=o,I=C.__editorTemplate,_=function(t,e){if(e.editor)return e.editor;if(e.__editorTemplate)return"template";if(!e.type)return;const i=t.effectiveConfig?.typeDefaults;if(i?.[e.type]?.editor)return i[e.type].editor;const n=t.__frameworkAdapter;if(n?.getTypeDefault){const i=n.getTypeDefault(e.type,t._hostElement);if(i?.editor)return i.editor}}(c,C)??$(o),S=p,k=`${r}:${o.field}`,x=[];g.set(k,t=>{for(const e of x)e(t)});const A=t=>{x.push(t)};if("template"===_&&I)!function(t,e,i,n,r,o,s,l,a){const d=i.__editorTemplate;if(!d)return;const c=d.cloneNode(!0),u=i.__compiledEditor;u?c.innerHTML=u({row:n,value:r,field:i.field,column:i,commit:o,cancel:s}):c.querySelectorAll("*").forEach(t=>{1===t.childNodes.length&&t.firstChild?.nodeType===Node.TEXT_NODE&&(t.textContent=t.textContent?.replace(/{{\s*value\s*}}/g,null==r?"":String(r)).replace(/{{\s*row\.([a-zA-Z0-9_]+)\s*}}/g,(t,e)=>{if(!K(e))return"";const i=n[e];return null==i?"":String(i)})||"")});const h=c.querySelector("input,textarea,select");if(h){h instanceof HTMLInputElement&&"checkbox"===h.type?h.checked=!!r:h.value=String(r??"");let e=!1;h.addEventListener("blur",()=>{e||o(P(h,i,r))}),h.addEventListener("keydown",n=>{const l=n;if("Enter"===l.key){if(Z(t.config,l))return;l.stopPropagation(),l.preventDefault(),e=!0,o(P(h,i,r)),t.exitRowEdit(a,!1)}if("Escape"===l.key){if(Z(t.config,l))return;l.stopPropagation(),l.preventDefault(),s(),t.exitRowEdit(a,!0)}}),h instanceof HTMLInputElement&&"checkbox"===h.type&&h.addEventListener("change",()=>o(h.checked)),l||setTimeout(()=>h.focus({preventScroll:!0}),0)}e.appendChild(c)}(i,R,C,n,p,b,E,a,r),A(t=>{if(null!=t&&"object"==typeof t)return;const e=R.querySelector("input,textarea,select");e&&(e instanceof HTMLInputElement&&"checkbox"===e.type?e.checked=!!t:e.value=String(t??""))});else if("string"==typeof _){const t=document.createElement(_);t.value=S,t.addEventListener("change",()=>b(t.value)),A(e=>{t.value=e}),R.appendChild(t),a||queueMicrotask(()=>{R.querySelector(z)?.focus({preventScroll:!0})})}else if("function"==typeof _){const t=_({row:n,rowId:w??"",value:S,field:o.field,column:o,commit:b,cancel:E,updateRow:m,onValueChange:A,grid:i.grid});"string"==typeof t?(R.innerHTML=t,function(t,e,i,n){const r=t.querySelector("input,textarea,select");r&&(r.addEventListener("blur",()=>{i(P(r,e,n))}),r instanceof HTMLInputElement&&"checkbox"===r.type?r.addEventListener("change",()=>i(r.checked)):r instanceof HTMLSelectElement&&r.addEventListener("change",()=>i(P(r,e,n))))}(R,o,b,p),A(t=>{const e=R.querySelector("input,textarea,select");e&&(e instanceof HTMLInputElement&&"checkbox"===e.type?e.checked=!!t:e.value=String(t??""))})):t instanceof Node?(R.appendChild(t),t instanceof HTMLInputElement||t instanceof HTMLSelectElement||t instanceof HTMLTextAreaElement?A(e=>{t instanceof HTMLInputElement&&"checkbox"===t.type?t.checked=!!e:t.value=String(e??"")}):l.setAttribute("data-editor-managed","")):!t&&R.hasChildNodes()&&l.setAttribute("data-editor-managed",""),a||queueMicrotask(()=>{R.querySelector(z)?.focus({preventScroll:!0})})}else if(_&&"object"==typeof _){const t=document.createElement("div");t.setAttribute("data-external-editor",""),t.setAttribute("data-field",o.field),R.appendChild(t),l.setAttribute("data-editor-managed","");const e={row:n,rowId:w??"",value:S,field:o.field,column:o,commit:b,cancel:E,updateRow:m,onValueChange:A,grid:i.grid};if(_.mount)try{_.mount({placeholder:t,context:e,spec:_})}catch(q){M="TBW080",L=`External editor mount error for column '${o.field}': ${q}`,G=i.grid.id,console.warn(D(M,L,G,T))}else c.dispatchEvent(new CustomEvent("mount-external-editor",{detail:{placeholder:t,spec:_,context:e}}))}var M,L,G,T;!function(t,e){const i="string"==typeof e.header?e.header:e.field;if(!i)return;queueMicrotask(()=>{const e=t.querySelector(z);e&&(e.hasAttribute("aria-label")||e.hasAttribute("aria-labelledby")||e.hasAttribute("title")||e.id&&t.querySelector(`label[for="${CSS.escape(e.id)}"]`)||e.closest("label")||e.setAttribute("aria-label",i))})}(R,o)}var X=class extends G{static manifest={ownedProperties:[{property:"editable",level:"column",description:'the "editable" column property',isUsed:t=>!0===t||"function"==typeof t},{property:"editor",level:"column",description:'the "editor" column property'},{property:"editorParams",level:"column",description:'the "editorParams" column property'},{property:"nullable",level:"column",description:'the "nullable" column property (allows null values)'}],events:[{type:"cell-edit-committed",description:"Emitted when a cell edit is committed (for plugin-to-plugin coordination)"}],queries:[{type:"isEditing",description:"Returns whether any cell is currently being edited"},{type:"getCellEditableResolver",description:"Returns a predicate (field, row) => boolean resolving per-cell editability (rowEditable gate + column.editable true/false/function), for consumers like clipboard paste"},{type:"commitCellValue",description:"Commits a single cell value coming from a core row mutation (updateRow/updateRows), running the full edit pipeline: cancelable cell-commit (validation/abortion), dirty tracking, history, and cascade. Returns true (applied), false (vetoed), or undefined (not handled)."}]};name="editing";styles="@layer tbw-plugins{tbw-grid{--tbw-editing-bg:var(--tbw-color-selection);--tbw-editing-row-bg:var(--tbw-editing-bg);--tbw-editing-border:var(--tbw-border-input,1px solid var(--tbw-color-border-strong));--tbw-padding-editing-input:var(--tbw-cell-padding-input,2px 6px);--tbw-font-size-editor:inherit;--tbw-editing-row-outline-color:var(--tbw-color-accent);--tbw-editing-row-outline-width:1px}tbw-grid:not(.tbw-grid-mode) .data-grid-row:has(.editing){background:var(--tbw-editing-row-bg);outline:var(--tbw-editing-row-outline-width) solid var(--tbw-editing-row-outline-color);outline-offset:calc(-1 * var(--tbw-editing-row-outline-width))}tbw-grid .data-grid-row>.cell.editing{min-height:max(var(--tbw-row-height), calc(1lh + 2 * var(--tbw-cell-padding-v,.25em) + var(--tbw-border-width,1px)));justify-content:center;align-items:center;padding:0;display:flex;overflow:hidden}tbw-grid .data-grid-row>.cell.editing input:not([type=checkbox]),tbw-grid .data-grid-row>.cell.editing select,tbw-grid .data-grid-row>.cell.editing textarea{border:var(--tbw-editing-border);width:100%;min-width:0;height:100%;padding:var(--tbw-padding-editing-input);font-size:var(--tbw-font-size-editor);flex:auto;align-self:stretch}tbw-grid .tbw-editor-host{display:contents}tbw-grid{--tbw-invalid-bg:light-dark(#fef2f2,#450a0a);--tbw-invalid-border-color:light-dark(#ef4444,#f87171)}tbw-grid .data-grid-row>.cell[data-invalid=true]{background:var(--tbw-invalid-bg);outline:1px solid var(--tbw-invalid-border-color);outline-offset:-1px}}";get defaultConfig(){return{mode:"row",editOn:"click"}}get#r(){return"grid"===this.config.mode}#o(t,e){const i=this.#s.effectiveConfig?.rowEditable;if(i&&!i(e))return!1;const{editable:n}=t;return"function"==typeof n?n(e):!0===n}#l(t){return!0===t.editable||"function"==typeof t.editable}#a=-1;#d;#c;#u=-1;#h=/* @__PURE__ */new Map;#f=/* @__PURE__ */new Set;#g=/* @__PURE__ */new WeakSet;#w=/* @__PURE__ */new Map;#m=!1;#p=-1;#v;#y=!1;#b=!1;#E=!1;#R=null;#C=new W;#I=/* @__PURE__ */new Set;#_;get#s(){return this.grid}attach(t){super.attach(t);const e=this.disconnectSignal,i=this.#s;this.#v=new V((t,e,i)=>{this.#S(t,e,i)}),this.#_={grid:i,isGridMode:this.#r,config:this.config,editingCells:this.#f,editorValueCallbacks:this.#w,isEditSessionActive:()=>-1!==this.#a,commitCellValue:(t,e,i,n)=>this.#k(t,e,i,n),exitRowEdit:(t,e)=>this.#x(t,e)},this.#A(),Object.defineProperty(t,"changedRows",{get:()=>this.changedRows,configurable:!0}),Object.defineProperty(t,"changedRowIds",{get:()=>this.changedRowIds,configurable:!0}),Object.defineProperty(t,"_changedRowIdSet",{get:()=>this.#C.changedRowIds,configurable:!0}),t.resetChangedRows=t=>this.resetChangedRows(t),this.#M(e,i),this.#r&&(i._isGridEditMode=!0,this.gridElement.classList.add("tbw-grid-mode"),this.requestRender(),this.#L(e,i))}#M(t,e){if(document.addEventListener("keydown",t=>{if(!this.#r&&"Escape"===t.key&&-1!==this.#a){if(Z(this.config,t))return;this.#x(this.#a,!0)}},{capture:!0,signal:t}),document.addEventListener("mousedown",t=>{if(this.#r)return;if(-1===this.#a)return;const i=e.findRenderedRowElement?.(this.#a);if(!i)return;if((t.composedPath&&t.composedPath()||[]).includes(i))return;const n=t.target;if(!n||this.gridElement.contains(n)||!this.grid.containsFocus?.(n)){if(n&&!this.gridElement.contains(n)){const t=e.findRenderedRowElement?.(this.#a);if(t&&function(t,e){if(!t)return!1;const i=e.querySelectorAll('[aria-expanded="true"][aria-controls]');for(let n=0;n<i.length;n++){const r=i[n].getAttribute("aria-controls");if(!r)continue;const o=e.ownerDocument?.getElementById(r);if(o&&o.contains(t))return!0}return!1}(n,t))return}Z(this.config,t)||queueMicrotask(()=>{-1!==this.#a&&this.#x(this.#a,!1)})}},{signal:t}),this.config.focusTrap&&this.gridElement.addEventListener("focusout",t=>{if(this.#r)return;if(-1===this.#a)return;const e=t.relatedTarget;e&&this.grid.containsFocus?.(e)||e&&this.gridElement.contains(e)||queueMicrotask(()=>{-1!==this.#a&&this.#D()})},{signal:t}),this.gridElement.addEventListener("cell-change",t=>{const e=t.detail;if("user"===e.source)return;const i=`${e.rowIndex}:${e.field}`,n=this.#w.get(i);n&&n(e.newValue)},{signal:t}),this.config.dirtyTracking){const e=t=>{const e=t.detail?.action;if(!e)return;const i=this.rows[e.rowIndex];if(!i)return;const n=this.#G(i);if(!n)return;const r=this.#C.isRowDirty(n,i);this.#T(n,i,r?"modified":"pristine")};this.gridElement.addEventListener("undo",e,{signal:t}),this.gridElement.addEventListener("redo",e,{signal:t}),this.on("row-inserted",t=>{const e=this.#G(t.row);null!=e&&this.markAsNew(String(e))})}}#L(t,e){this.gridElement.addEventListener("focusin",t=>{const i=t.target;if(i!==this.gridElement&&i.matches('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])')){if(this.#b)return i.blur(),void this.gridElement.focus();const t=e._focusRow,n=e._focusCol,r=this.#R;if(!r||r.rowIndex!==t||r.colIndex!==n){const i=e._visibleColumns?.[n],r=e._rows?.[t];if(i?.field&&r){const e=i.field;this.#R={rowIndex:t,colIndex:n,field:e,value:h(r,e)}}}this.#y=!0}},{signal:t}),this.gridElement.addEventListener("focusout",t=>{const e=t.target,i=t.relatedTarget;if(e&&i){if(e.contains(i))return;const t=B(i);if(t&&t!==this.gridElement&&this.gridElement.contains(t))return}i&&(this.gridElement.contains(i)||this.grid.containsFocus?.(i))&&i.matches('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])')||(this.#y=!1,this.#R=null)},{signal:t}),this.gridElement.addEventListener("keydown",t=>{if("Escape"===t.key&&this.#y){if(Z(this.config,t))return void queueMicrotask(()=>{this.#y&&this.#q()});this.#q(),t.preventDefault(),t.stopPropagation()}},{capture:!0,signal:t}),this.gridElement.addEventListener("mousedown",t=>{t.target.matches('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])')&&(this.#b=!1)},{signal:t})}detach(){this.#s._isGridEditMode=!1,this.gridElement.classList.remove("tbw-grid-mode"),this.#a=-1,this.#d=void 0,this.#c=void 0,this.#u=-1,this.#h.clear(),this.#C.clear(),this.#f.clear(),this.#w.clear(),this.#y=!1,this.#b=!1,this.#R=null,this.#E=!1,this.#g=/* @__PURE__ */new WeakSet,super.detach()}handleQuery(t){if("isEditing"===t.type)return this.#r||-1!==this.#a;if("getCellEditableResolver"===t.type){const t=this.#s.effectiveConfig?.columns??[],e=/* @__PURE__ */new Map;for(const i of t)e.set(i.field,i);return(t,i)=>{const n=e.get(t);return!!n&&this.#o(n,i)}}return"commitCellValue"===t.type?this.#$(t.context):void 0}#$(t){const e=this.#s,i=(e._visibleColumns??[]).find(e=>e.field===t.field)??e._columns?.find(e=>e.field===t.field),n=t.row??(null!=t.rowId?e._getRowEntry(t.rowId)?.row:void 0)??e._rows?.[t.rowIndex];if("sync"===t.source){if(!n||!K(t.field))return;f(n,t.field,t.newValue),g(n);const e=this.#G(n);if(e&&this.config.dirtyTracking){this.#C.rebaselineCell(e,t.field,t.newValue);const i=this.#C.isRowDirty(e,n);i||this.#C.changedRowIds.delete(e),this.#T(e,n,i?"modified":"pristine")}return!0}if(i&&n&&K(t.field)){if("history"===t.source){f(n,t.field,t.newValue),g(n);const e=this.#G(n);if(e&&this.config.dirtyTracking){const t=this.#C.isRowDirty(e,n);t||this.#C.changedRowIds.delete(e),this.#T(e,n,t?"modified":"pristine")}return!0}return this.#k(t.rowIndex,i,t.newValue,n,t.source),h(n,t.field)===t.newValue}}onCellClick(t){if(this.#r)return!1;const e=this.#s,i=this.config.editOn??e.effectiveConfig?.editOn;if(!1===i||"manual"===i)return!1;if("click"!==i&&"dblclick"!==i)return!1;const n="dblclick"===t.originalEvent.type;if("click"===i&&n)return!1;if("dblclick"===i&&!n)return!1;const{rowIndex:r}=t;return!!e._columns?.some(t=>this.#l(t))&&(!!this.#F(e._rows[r])&&(t.originalEvent.stopPropagation(),this.beginBulkEdit(r),!0))}onKeyDown(t){switch(t.key){case"Escape":return this.#P(t);case"ArrowUp":case"ArrowDown":case"ArrowLeft":case"ArrowRight":return this.#V(t);case"Tab":return this.#O(t);case" ":case"Spacebar":return this.#H(t);case"Enter":return!(t.shiftKey||t.ctrlKey||t.altKey||t.metaKey)&&this.#j(t);case"F2":return this.#N(t);default:return!1}}#P(t){return this.#r&&this.#y?(this.#q(),this.requestAfterRender(),!0):-1!==this.#a&&!this.#r&&(Z(this.config,t)||this.#x(this.#a,!0),!0)}#V(t){const e=B(t.target),i=!!e&&e!==this.gridElement,n="ArrowUp"===t.key||"ArrowDown"===t.key;return!(this.#r&&!this.#y&&!i)&&(!(!this.#r||!this.#y&&!i||!n)||!(!n||-1===this.#a||this.#r))}#O(t){return!(-1===this.#a&&!this.#r)&&(t.preventDefault(),this.#E?(this.#x(this.#a,!1),!0):(this.#W(!t.shiftKey),!0))}#H(t){if(-1!==this.#a)return!1;const e=this.#s,i=e._focusRow,n=e._focusCol;if(i<0||n<0)return!1;const r=e._visibleColumns[n],o=e._rows[i];if(!r||!o||"boolean"!==r.type)return!1;if(!this.#o(r,o))return!1;const s=r.field;return!!K(s)&&(this.#k(i,r,!h(o,s),o),t.preventDefault(),this.requestRender(),!0)}#j(t){if(this.#r&&!this.#y)return this.#D(),!0;if(this.#r&&this.#y)return this.#z(t);if(-1!==this.#a){const e=t.target;return(!e||"true"!==e.getAttribute?.("aria-expanded")||!e.hasAttribute?.("aria-controls"))&&!!Z(this.config,t)}return this.#B(t)}#z(t){const e=B(t.target);if(e&&e!==t.target)return!0;this.#R=null;const i=document.activeElement;return i&&this.gridElement.contains(i)&&(i.blur(),this.gridElement.focus()),this.#y=!1,this.#b=!0,this.requestAfterRender(),!0}#B(t){const e=this.#s,i=this.config.editOn??e.effectiveConfig?.editOn;if(!1===i||"manual"===i)return!1;const n=e._focusRow,r=e._focusCol;if(n<0)return!1;const o=e._columns?.some(t=>this.#l(t)),s=e._rows[n];if(!o||!this.#F(s))return!1;const l=e._visibleColumns[r]?.field??"",a=l&&s?h(s,l):void 0,d=this.gridElement.querySelector(`[data-row="${n}"][data-col="${r}"]`),c=new CustomEvent("cell-activate",{cancelable:!0,bubbles:!0,detail:{rowIndex:n,colIndex:r,field:l,value:a,row:s,cellEl:d,trigger:"keyboard",originalEvent:t}});return this.gridElement.dispatchEvent(c),c.defaultPrevented?(t.preventDefault(),!0):(this.beginBulkEdit(n),!0)}#N(t){if(-1!==this.#a||this.#r)return!1;const e=this.#s;if(!1===(this.config.editOn??e.effectiveConfig?.editOn))return!1;const i=e._focusRow,n=e._focusCol;if(i<0||n<0)return!1;const r=e._visibleColumns[n],o=e._rows[i];return!!(r&&o&&r.field)&&(!!this.#o(r,o)&&(t.preventDefault(),this.beginCellEdit(i,r.field),!0))}#K(t){const e={};for(const i of Array.from(t.attributes)){if(!i.name.startsWith("data-"))continue;const t=i.name.slice(5).replace(/-([a-z])/g,(t,e)=>e.toUpperCase()).trim();t&&(e[t]=i.value)}return e}#U(){const t=this.#s,e=t._hostElement;if(!e)return;const i=t.effectiveConfig;if(!i)return;const n=Array.from(e.children).filter(t=>"tbw-grid-type"===t.tagName.toLowerCase());if(!n.length)return;const r=t.__frameworkAdapter,o=i.typeDefaults??={};for(let s=0;s<n.length;s++){const t=n[s],e=t.getAttribute("name")?.trim();if(!e)continue;const i=o[e];if(i?.editor)continue;const l=t.querySelector("tbw-grid-column-editor"),a=l??t;let d=r?.canHandle?.(a)?r.createEditor?.(a):void 0;if(!d&&l){const e=this.#K(t),i=M(l.innerHTML);d=t=>i({row:t.row,value:t.value,field:t.field,column:t.column,typeDefault:e})}d&&(o[e]={...i??{},editor:d})}}processColumns(t){const e=this.#s;this.#U();const i=e.effectiveConfig?.typeDefaults,n=e.__frameworkAdapter,r=!!i||!!n?.getTypeDefault;return t.map(t=>{const o=t.__element;if(o&&!this.#g.has(o)){this.#g.add(o),null==t.editable&&o.hasAttribute("editable")&&(t.editable="false"!==o.getAttribute("editable"));const e=t;if(!e.__editorTemplate){const t=o.querySelector("tbw-grid-column-editor");t&&(e.__editorTemplate=t)}}if(!t.type||!r)return t;let s;if(i?.[t.type]?.editorParams&&(s=i[t.type].editorParams),!s&&n?.getTypeDefault){const i=n.getTypeDefault(t.type,e._hostElement);i?.editorParams&&(s=i.editorParams)}return s?{...t,editorParams:{...s,...t.editorParams}}:t})}processRows(t){const e=this.#s;if(this.config.dirtyTracking&&e.getRowId&&this.#C.capture(t,t=>{try{return e.getRowId?.(t)}catch{return}}),-1===this.#a||this.#r)return t;const i=this.#d,n=this.#c;if(!i||!n)return t;const r=[...t];let o=-1;for(let s=0;s<r.length;s++)if(this.#G(r[s])===i){o=s;break}return-1===o?(setTimeout(()=>this.cancelActiveRowEdit(),0),r):(r[o]=n,this.#a!==o&&this.#Z(this.#a,o),r)}afterRender(){const t=this.#s;if(-1!==this.#a&&this.#c&&!this.#r&&t._rows[this.#a]!==this.#c){const e=t._rows.indexOf(this.#c);if(-1===e)return void setTimeout(()=>this.cancelActiveRowEdit(),0);this.#Z(this.#a,e)}if(this.#m&&(this.#m=!1,this.#J(t)),-1!==this.#p){const e=this.#p;this.#p=-1,t.animateRow?.(e,"change")}const e=this.#C.drainCapturedFlag();if(null!=e&&this.emit("baselines-captured",{count:e}),!this.#r&&0!==this.#f.size)for(const i of this.#f){const[e,n]=i.split(":"),r=parseInt(e,10),o=parseInt(n,10),s=this.#X(r,o);if(!s||s.classList.contains("editing"))continue;const l=t._rows[r],a=t._visibleColumns[o];l&&a&&this.#Y(l,r,a,o,s,!0)}}afterCellRender(t){const{row:e,rowIndex:i,column:n,colIndex:r,cellElement:o}=t,s=this.#o(n,e);if(s)o.removeAttribute("aria-readonly");else if(o.setAttribute("aria-readonly","true"),this.#r&&o.classList.contains("editing")){o.classList.remove("editing");const t=h(e,n.field);o.textContent=null==t?"":String(t)}this.#r&&s&&(o.classList.contains("editing")||this.#Y(e,i,n,r,o,!0,t.rowElement))}afterRowRender(t){if(!this.config.dirtyTracking)return;const e=this.#s.getRowId?.(t.row);if(!e)return;const{isNew:i,isCommittedDirty:n,hasBaseline:r}=this.#C.getRowDirtyState(e,t.row),o=t.rowElement;if(o.classList.toggle("tbw-row-dirty",n),o.classList.toggle("tbw-row-new",i),r){const i=o.querySelectorAll(".cell[data-field]");for(let n=0;n<i.length;n++){const r=i[n],o=r.getAttribute("data-field");o&&r.classList.toggle("tbw-cell-dirty",this.#C.isCellDirty(e,t.row,o))}}else{const t=o.querySelectorAll(".tbw-cell-dirty");for(let e=0;e<t.length;e++)t[e].classList.remove("tbw-cell-dirty")}}onScrollRender(){this.afterRender()}get changedRows(){return this.#C.getChangedRows(t=>this.grid.getRow(t))}get changedRowIds(){return this.#C.getChangedRowIds()}get activeEditRow(){return this.#a}get activeEditCol(){return this.#u}isRowEditing(t){return this.#a===t}isCellEditing(t,e){return this.#f.has(`${t}:${e}`)}isRowChanged(t){const e=this.#s,i=e._rows[t];if(!i)return!1;try{const t=e.getRowId?.(i);return!!t&&this.#C.isRowChanged(t)}catch{return!1}}isRowChangedById(t){return this.#C.isRowChanged(t)}isDirty(t){if(!this.config.dirtyTracking)return!1;if(this.#C.newRowIds.has(t))return!0;const e=this.grid.getRow(t);return!!e&&this.#C.isRowDirty(t,e)}isPristine(t){return!this.isDirty(t)}get dirty(){if(!this.config.dirtyTracking)return!1;const t=this.#s;return this.#C.hasAnyDirty(e=>t._getRowEntry(e)?.row)}get pristine(){return!this.dirty}markAsPristine(t){if(!this.config.dirtyTracking)return;const e=this.grid.getRow(t);e&&(this.#C.markPristine(t,e),this.emit("dirty-change",{rowId:t,row:e,original:e,type:"pristine"}))}markAsNew(t){if(!this.config.dirtyTracking)return;this.#C.markNew(t);const e=this.grid.getRow(t);this.emit("dirty-change",{rowId:t,row:e,original:void 0,type:"new"})}markAsDirty(t){if(!this.config.dirtyTracking)return;const e=this.grid.getRow(t);e&&(this.#C.markDirty(t),this.#T(t,e,"modified"))}markAllPristine(){if(!this.config.dirtyTracking)return;const t=this.#s;this.#C.markAllPristine(e=>t._getRowEntry(e)?.row)}getOriginalRow(t){if(this.config.dirtyTracking)return this.#C.getOriginalRow(t)}hasBaseline(t){return!!this.config.dirtyTracking&&this.#C.hasBaseline(t)}getDirtyRows(){if(!this.config.dirtyTracking)return[];const t=this.#s;return this.#C.getDirtyRows(e=>t._getRowEntry(e)?.row)}get dirtyRowIds(){if(!this.config.dirtyTracking)return[];const t=this.#s;return this.#C.getDirtyRowIds(e=>t._getRowEntry(e)?.row)}revertRow(t){if(!this.config.dirtyTracking)return;const e=this.grid.getRow(t);e&&this.#C.revertRow(t,e)&&(this.#T(t,e,"reverted"),this.requestRender())}revertAll(){if(!this.config.dirtyTracking)return;const t=this.#s;this.#C.revertAll(e=>t._getRowEntry(e)?.row),this.requestRender()}setInvalid(t,e,i=""){this.#v.setInvalid(t,e,i)}clearInvalid(t,e){this.#v.clearInvalid(t,e)}clearRowInvalid(t){this.#v.clearRowInvalid(t)}clearAllInvalid(){this.#v.clearAllInvalid()}isCellInvalid(t,e){return this.#v.isCellInvalid(t,e)}getInvalidMessage(t,e){return this.#v.getInvalidMessage(t,e)}hasInvalidCells(t){return this.#v.hasInvalidCells(t)}getInvalidFields(t){return this.#v.getInvalidFields(t)}resetChangedRows(t){const e=this.changedRows,i=this.changedRowIds;this.#C.changedRowIds.clear(),this.#C.committedDirtyRowIds.clear(),this.#A(),t||this.emit("changed-rows-reset",{rows:e,ids:i}),this.#s._rowPool?.forEach(t=>t.classList.remove("changed"))}beginCellEdit(t,e){const i=this.#s,n=i._visibleColumns.findIndex(t=>t.field===e);if(-1===n)return;const r=i._visibleColumns[n],o=i._rows[t];if(!r||!o||!this.#o(r,o))return;const s=this.#X(t,n);s&&(this.#E=!0,this.#Q(t,n,s))}beginBulkEdit(t){const e=this.#s;if(!1===(this.config.editOn??e.effectiveConfig?.editOn))return;if(!e._columns?.some(t=>this.#l(t)))return;const i=e.findRenderedRowElement?.(t);if(!i)return;const n=e._rows[t];this.#F(n)&&(this.#E=!1,this.#tt(t,n),Array.from(i.children).forEach((i,r)=>{const o=e._visibleColumns[r];if(o&&this.#o(o,n)){const e=i;e.classList.contains("editing")||this.#Y(n,t,o,r,e,!0)}}),setTimeout(()=>{let t=i.querySelector(`.cell[data-col="${e._focusCol}"]`);if(t?.classList.contains("editing")||(t=i.querySelector(".cell.editing")),t?.classList.contains("editing")){const e=t.querySelector(z);try{e?.focus({preventScroll:!0})}catch{}}},0))}commitActiveRowEdit(){-1!==this.#a&&this.#x(this.#a,!1)}cancelActiveRowEdit(){-1!==this.#a&&this.#x(this.#a,!0)}#G(t){if(t)try{return this.#s.getRowId?.(t)}catch{return}}#X(t,e){return(this.#s.findRenderedRowElement?.(t))?.querySelector(`.cell[data-col="${e}"]`)??null}#F(t){if(!t)return!0;const e=this.#s.effectiveConfig?.rowEditable;return!e||!1!==e(t)}#T(t,e,i){this.emit("dirty-change",{rowId:t,row:e,original:this.#C.getOriginalRow(t),type:i})}#q(){this.#et();const t=document.activeElement;t&&this.gridElement.contains(t)&&(t.blur(),this.gridElement.focus()),this.#y=!1,this.#b=!0}#it(t,e,i){i&&(Object.keys(i).forEach(t=>{e[t]=i[t]}),t&&(this.#C.changedRowIds.delete(t),this.#C.committedDirtyRowIds.delete(t),this.clearRowInvalid(t)))}#S(t,e,i){const r=this.#s,o=r._visibleColumns?.findIndex(t=>t.field===e);if(-1===o||void 0===o)return;const s=r._rows?.findIndex(e=>this.#G(e)===t);if(-1===s||void 0===s)return;const l=this.#X(s,o);if(l)if(i){l.setAttribute("data-invalid","true"),l.setAttribute("aria-invalid","true");const i=this.#v.getInvalidMessage(t,e);i&&(l.setAttribute("title",i),l.removeAttribute(n))}else l.removeAttribute("data-invalid"),l.removeAttribute("aria-invalid"),l.removeAttribute("title")}#Z(t,e){this.#a=e;const i=/* @__PURE__ */new Set,n=`${t}:`;for(const s of this.#f)s.startsWith(n)?i.add(`${e}:${s.substring(n.length)}`):i.add(s);this.#f.clear();for(const s of i)this.#f.add(s);const r=this.#h.get(t);void 0!==r&&(this.#h.delete(t),this.#h.set(e,r));const o=[];for(const[s,l]of this.#w)s.startsWith(n)&&(o.push([`${e}:${s.substring(n.length)}`,l]),this.#w.delete(s));for(const[s,l]of o)this.#w.set(s,l);this.#A()}#Q(t,e,i){const n=this.#s,r=n._rows[t],o=n._visibleColumns[e];r&&o&&this.#o(o,r)&&(i.classList.contains("editing")||(this.#a!==t&&this.#tt(t,r),this.#u=e,this.#Y(r,t,o,e,i,!1)))}#et(){const t=this.#R;if(!t)return;const e=this.#s._rows?.[t.rowIndex];e&&f(e,t.field,t.value);const i=`${t.rowIndex}:${t.field}`,n=this.#w.get(i);if(n&&n(t.value),this.emit("cell-cancel",{rowIndex:t.rowIndex,colIndex:t.colIndex,field:t.field,previousValue:t.value}),e){const t=this.#G(e);t&&(this.config.dirtyTracking?this.#C.isRowDirty(t,e)||(this.#C.changedRowIds.delete(t),this.#T(t,e,"reverted")):this.#C.changedRowIds.delete(t))}this.requestRender(),this.#R=null}#D(){const t=this.#s,e=t._focusRow,i=t._focusCol;if(e<0||i<0)return;const n=this.#X(e,i);if(n?.classList.contains("editing")){const t=n.querySelector(z);t&&(this.#b=!1,t.focus(),this.#y=!0,t instanceof HTMLInputElement&&("text"===t.type||"number"===t.type)&&t.select())}}#W(t){const e=this.#s,i=e._rows,n=this.#r?e._focusRow:this.#a,r=i[n],o=e._visibleColumns.map((t,e)=>r&&this.#o(t,r)?e:-1).filter(t=>t>=0);if(0===o.length)return;const s=o.indexOf(e._focusCol)+(t?1:-1);if(s>=0&&s<o.length){e._focusCol=o[s];const t=this.#X(n,o[s]);return t?.classList.contains("editing")&&t.querySelector(z)?.focus({preventScroll:!0}),void m(e,{forceHorizontalScroll:!0})}const l=n+(t?1:-1);if(l>=0&&l<i.length){const r=i[l],o=e._visibleColumns.map((t,e)=>r&&this.#o(t,r)?e:-1).filter(t=>t>=0);if(0===o.length)return;this.#r?(e._focusRow=l,e._focusCol=t?o[0]:o[o.length-1],m(e,{forceHorizontalScroll:!0}),this.requestAfterRender(),setTimeout(()=>{const t=this.#X(l,e._focusCol);t?.classList.contains("editing")&&t.querySelector(z)?.focus({preventScroll:!0})},0)):(this.#x(n,!1),e._focusRow=l,e._focusCol=t?o[0]:o[o.length-1],this.beginBulkEdit(l),m(e,{forceHorizontalScroll:!0}))}}#A(){const t=this.#s;t._activeEditRows=this.#a,t._rowEditSnapshots=this.#h}#tt(t,e){this.#a!==t&&(-1!==this.#a&&this.#x(this.#a,!1),this.#h.set(t,{...e}),this.#a=t,this.#c=e,this.#d=this.#G(e),this.#A(),this.#r||(this.broadcast("edit-open",{rowIndex:t,rowId:this.#d??"",row:e}),s(this.gridElement,l(this.gridElement,"editingStarted",t))))}#x(t,e){if(this.#a!==t)return;const i=this.#s,n=this.#h.get(t),r=i.findRenderedRowElement?.(t),{rowId:o,current:a}=this.#nt(t);!e&&r&&a&&this.#rt(r,t,a),e||this.#r||!a||this.emit("before-edit-close",{rowIndex:t,rowId:o??"",row:a}),e&&a?this.#it(o,a,n):!e&&a&&this.#ot(t,o,a,n),this.#st(t),this.#m=!0,r?this.#lt(r,i):(this.#J(i),this.#m=!1),!this.#r&&a&&(this.broadcast("edit-close",{rowIndex:t,rowId:o??"",row:a,reverted:e}),e||s(this.gridElement,l(this.gridElement,"editingCommitted",t)))}#nt(t){const e=this.#s;let i=this.#d;const n=(i?e._getRowEntry(i):void 0)?.row??this.#c??e._rows[t];return!i&&n&&(i=this.#G(n)),{rowId:i,current:n}}#rt(t,e,i){const n=this.#s;t.querySelectorAll(".cell.editing").forEach(t=>{const r=Number(t.getAttribute("data-col"));if(isNaN(r))return;const o=n._visibleColumns[r];if(!o)return;if(t.hasAttribute("data-editor-managed"))return;const s=t.querySelector("input,textarea,select");if(!s)return;const l=o.field,a=h(i,l),d=P(s,o,a);a!==d&&this.#k(e,o,d,i)})}#ot(t,e,i,n){const r=function(t,e){if(!t)return!1;const i=t,n=e,r=/* @__PURE__ */new Set([...Object.keys(i),...Object.keys(n)]);for(const o of r)if(i[o]!==n[o])return!0;return!1}(n,i),o=e?this.#C.changedRowIds.has(e):r;this.emitCancelable("row-commit",{rowIndex:t,rowId:e??"",row:i,oldValue:n,newValue:i,changed:o,changedRows:this.changedRows,changedRowIds:this.changedRowIds})?n&&this.#it(e,i,n):(e&&this.config.dirtyTracking&&(this.#C.isRowDirty(e,i)?this.#C.committedDirtyRowIds.add(e):this.#C.committedDirtyRowIds.delete(e)),r&&this.isAnimationEnabled&&(this.#p=t))}#st(t){this.#h.delete(t),this.#a=-1,this.#d=void 0,this.#c=void 0,this.#u=-1,this.#E=!1,this.#A();for(const e of this.#f)e.startsWith(`${t}:`)&&this.#f.delete(e);for(const e of this.#w.keys())e.startsWith(`${t}:`)&&this.#w.delete(e)}#lt(t,e){const i=e.__frameworkAdapter,n=t.querySelectorAll(".cell.editing");i?.releaseCell&&n.forEach(t=>{i.releaseCell(t)}),n.forEach(t=>{t.classList.remove("editing"),function(t){t.__editingCellCount=0,t.removeAttribute("data-has-editing")}(t.parentElement)}),e.refreshVirtualWindow(!0)}#k(t,e,i,n,r="user"){const o=e.field;if(!K(o))return;const s=h(n,o);if(s===i)return;const l=this.#s,a=this.#G(n),d=!a||!this.#C.changedRowIds.has(a),c=a?t=>this.grid.updateRow(a,t,"cascade"):U;let u=!1;const w=a?t=>{u=!0,this.setInvalid(a,o,t??"")}:()=>{},m=`${a??t}\0${o}`;if(this.#I.has(m))return;let p=!1;this.#I.add(m);try{p=this.emitCancelable("cell-commit",{row:n,rowId:a??"",field:o,oldValue:s,value:i,source:r,rowIndex:t,changedRows:this.changedRows,changedRowIds:this.changedRowIds,firstTimeForRow:d,updateRow:c,setInvalid:w})}finally{this.#I.delete(m)}if(p)return;if(a&&!u&&this.isCellInvalid(a,o)&&this.clearInvalid(a,o),f(n,o,i),g(n),a&&this.#C.changedRowIds.add(a),this.#A(),this.config.dirtyTracking&&a){const t=this.#C.isRowDirty(a,n);this.#T(a,n,t?"modified":"pristine")}this.emitPluginEvent("cell-edit-committed",{rowIndex:t,field:o,oldValue:s,newValue:i});const v=l.findRenderedRowElement?.(t);v&&v.classList.add("changed")}#Y(t,e,i,n,r,o,s){J(this.#_,t,e,i,n,r,o,s)}#J(t){queueMicrotask(()=>{try{const e=t._focusRow,i=t._focusCol,n=t.findRenderedRowElement?.(e);if(n){Array.from(t._bodyEl.querySelectorAll(".cell-focus")).forEach(t=>t.classList.remove("cell-focus"));const r=n.querySelector(`.cell[data-row="${e}"][data-col="${i}"]`);r&&(r.classList.add("cell-focus"),r.setAttribute("aria-selected","true"),r.hasAttribute("tabindex")||r.setAttribute("tabindex","-1"),r.focus({preventScroll:!0}))}}catch{}})}};export{X as EditingPlugin,$ as defaultEditorFor};
2
2
  //# sourceMappingURL=index.js.map