@toolbox-web/grid 3.6.0 → 3.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1 -1
  3. package/all.js +1 -1
  4. package/all.js.map +1 -1
  5. package/index.js +1 -1
  6. package/index.js.map +1 -1
  7. package/lib/core/internal/empty.d.ts +14 -6
  8. package/lib/core/types.d.ts +4 -0
  9. package/lib/features/registry.js +1 -1
  10. package/lib/plugins/clipboard/index.js +1 -1
  11. package/lib/plugins/clipboard/index.js.map +1 -1
  12. package/lib/plugins/column-virtualization/index.js +1 -1
  13. package/lib/plugins/column-virtualization/index.js.map +1 -1
  14. package/lib/plugins/context-menu/index.js +1 -1
  15. package/lib/plugins/context-menu/index.js.map +1 -1
  16. package/lib/plugins/editing/index.js +1 -1
  17. package/lib/plugins/editing/index.js.map +1 -1
  18. package/lib/plugins/export/index.js +1 -1
  19. package/lib/plugins/export/index.js.map +1 -1
  20. package/lib/plugins/filtering/index.js +1 -1
  21. package/lib/plugins/filtering/index.js.map +1 -1
  22. package/lib/plugins/grouping-columns/index.js +1 -1
  23. package/lib/plugins/grouping-columns/index.js.map +1 -1
  24. package/lib/plugins/grouping-rows/index.js +1 -1
  25. package/lib/plugins/grouping-rows/index.js.map +1 -1
  26. package/lib/plugins/master-detail/index.js +1 -1
  27. package/lib/plugins/master-detail/index.js.map +1 -1
  28. package/lib/plugins/multi-sort/index.js +1 -1
  29. package/lib/plugins/multi-sort/index.js.map +1 -1
  30. package/lib/plugins/pinned-columns/index.js +1 -1
  31. package/lib/plugins/pinned-columns/index.js.map +1 -1
  32. package/lib/plugins/pinned-rows/index.js +1 -1
  33. package/lib/plugins/pinned-rows/index.js.map +1 -1
  34. package/lib/plugins/pivot/index.js +1 -1
  35. package/lib/plugins/pivot/index.js.map +1 -1
  36. package/lib/plugins/print/index.js +1 -1
  37. package/lib/plugins/print/index.js.map +1 -1
  38. package/lib/plugins/reorder-columns/index.js +1 -1
  39. package/lib/plugins/reorder-columns/index.js.map +1 -1
  40. package/lib/plugins/responsive/index.d.ts +1 -1
  41. package/lib/plugins/responsive/index.js +1 -1
  42. package/lib/plugins/responsive/index.js.map +1 -1
  43. package/lib/plugins/responsive/types.d.ts +36 -1
  44. package/lib/plugins/row-drag-drop/index.js +1 -1
  45. package/lib/plugins/row-drag-drop/index.js.map +1 -1
  46. package/lib/plugins/selection/index.js +1 -1
  47. package/lib/plugins/selection/index.js.map +1 -1
  48. package/lib/plugins/server-side/index.js +1 -1
  49. package/lib/plugins/server-side/index.js.map +1 -1
  50. package/lib/plugins/shell/index.js +1 -1
  51. package/lib/plugins/shell/index.js.map +1 -1
  52. package/lib/plugins/sticky-rows/index.js +1 -1
  53. package/lib/plugins/sticky-rows/index.js.map +1 -1
  54. package/lib/plugins/tooltip/index.js +1 -1
  55. package/lib/plugins/tooltip/index.js.map +1 -1
  56. package/lib/plugins/tree/index.js +1 -1
  57. package/lib/plugins/tree/index.js.map +1 -1
  58. package/lib/plugins/undo-redo/index.js +1 -1
  59. package/lib/plugins/undo-redo/index.js.map +1 -1
  60. package/lib/plugins/visibility/index.js +1 -1
  61. package/lib/plugins/visibility/index.js.map +1 -1
  62. package/package.json +3 -2
  63. package/themes/dg-theme-bootstrap.css +13 -4
  64. package/themes/dg-theme-contrast.css +3 -0
  65. package/themes/dg-theme-large.css +4 -0
  66. package/themes/dg-theme-material.css +3 -0
  67. package/themes/dg-theme-standard.css +12 -3
  68. package/themes/dg-theme-vibrant.css +10 -3
  69. package/umd/grid.all.umd.js +1 -1
  70. package/umd/grid.all.umd.js.map +1 -1
  71. package/umd/grid.umd.js +1 -1
  72. package/umd/grid.umd.js.map +1 -1
  73. package/umd/plugins/grouping-columns.umd.js +1 -1
  74. package/umd/plugins/grouping-columns.umd.js.map +1 -1
  75. package/umd/plugins/responsive.umd.js +1 -1
  76. package/umd/plugins/responsive.umd.js.map +1 -1
  77. package/umd/plugins/selection.umd.js +1 -1
  78. package/umd/plugins/selection.umd.js.map +1 -1
@@ -18,11 +18,19 @@ export declare function defaultEmptyRenderer(ctx: EmptyContext): HTMLElement;
18
18
  export declare function createEmptyContent(ctx: EmptyContext, renderer?: EmptyRenderer): HTMLElement;
19
19
  /**
20
20
  * Create the empty-state overlay element.
21
- * Always carries `role="status"` + `aria-live="polite"` so screen readers
22
- * announce the state on transition; the `data-overlay-target` attribute is
23
- * informational only. CSS positions absolutely against the closest positioned
24
- * ancestor — `.tbw-grid-root` is positioned by `base.css`, and `.rows-container`
25
- * is given `position: relative` for `target='rows'` for the same reason.
21
+ *
22
+ * The overlay is **presentational**: for `target='rows'` it mounts inside
23
+ * `.rows-container`, which is `role="presentation"` and therefore transparent
24
+ * to ARIA — a `role="status"` there would be promoted to a direct child of
25
+ * `role="grid"`, which only owns `row`/`rowgroup` (axe `aria-required-children`).
26
+ * The message is instead announced through the grid's `.tbw-sr-only`
27
+ * `aria-live` region by `updateEmptyOverlay()`, which sits outside the grid
28
+ * role and is honoured consistently by screen readers.
29
+ *
30
+ * The `data-overlay-target` attribute is informational only. CSS positions
31
+ * absolutely against the closest positioned ancestor — `.tbw-grid-root` is
32
+ * positioned by `base.css`, and `.rows-container` is given `position: relative`
33
+ * for `target='rows'` for the same reason.
26
34
  */
27
35
  export declare function createEmptyOverlay(ctx: EmptyContext, renderer?: EmptyRenderer, target?: EmptyOverlay): HTMLElement;
28
36
  /**
@@ -70,4 +78,4 @@ export interface EmptyOverlayState {
70
78
  * The `state` object is mutated in place — callers store a single reference
71
79
  * and pass it back on every tick.
72
80
  */
73
- export declare function updateEmptyOverlay(gridRoot: Element | null, loading: boolean, renderedRowCount: number, sourceRows: readonly unknown[], renderer: GridConfig['emptyRenderer'] | undefined, target: EmptyOverlay, state: EmptyOverlayState): void;
81
+ export declare function updateEmptyOverlay(gridRoot: Element | null, loading: boolean, renderedRowCount: number, sourceRows: readonly unknown[], renderer: GridConfig['emptyRenderer'] | undefined, target: EmptyOverlay, state: EmptyOverlayState, host?: HTMLElement): void;
@@ -2378,6 +2378,10 @@ export interface A11yMessages {
2378
2378
  groupCollapsed: (name: string) => string;
2379
2379
  /** Announced when row selection changes. */
2380
2380
  selectionChanged: (count: number) => string;
2381
+ /** Accessible name for the header "select all rows" checkbox. @since 3.7.0 */
2382
+ selectAllRows: () => string;
2383
+ /** Accessible name for a row's selection checkbox. `rowIndex` is zero-based. @since 3.7.0 */
2384
+ selectRow: (rowIndex: number) => string;
2381
2385
  /** Announced when a single column is selected. @since 2.8.0 */
2382
2386
  columnSelected: (label: string) => string;
2383
2387
  /** Announced when multiple columns are selected. @since 2.8.0 */
@@ -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.6.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);f()&&!c.has(o)&&(c.add(o),e("TBW031",`Feature "${o}" is configured but not registered.\nAdd this import to enable it:\n\n import '@toolbox-web/grid/features/${o.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()}';\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.7.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);f()&&!c.has(o)&&(c.add(o),e("TBW031",`Feature "${o}" is configured but not registered.\nAdd this import to enable it:\n\n import '@toolbox-web/grid/features/${o.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()}';\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.6.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.7.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};
2
2
  //# sourceMappingURL=index.js.map