@toolbox-web/grid 3.0.0-beta.3 → 3.0.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/all.js +2 -2
- package/all.js.map +1 -1
- package/custom-elements.json +7 -6
- package/index.js +1 -1
- package/index.js.map +1 -1
- package/lib/core/constants.d.ts +7 -0
- package/lib/core/grid.d.ts +5 -1
- package/lib/core/internal/rows.d.ts +2 -5
- package/lib/core/internal/tag-registry.d.ts +23 -0
- package/lib/features/registry.js +1 -1
- package/lib/plugins/clipboard/index.js +1 -1
- package/lib/plugins/clipboard/index.js.map +1 -1
- package/lib/plugins/column-virtualization/index.js +1 -1
- package/lib/plugins/context-menu/index.js +1 -1
- package/lib/plugins/editing/index.js +1 -1
- package/lib/plugins/editing/index.js.map +1 -1
- package/lib/plugins/export/index.js +1 -1
- package/lib/plugins/filtering/index.js +1 -1
- package/lib/plugins/grouping-columns/index.js +1 -1
- package/lib/plugins/grouping-rows/index.js +1 -1
- package/lib/plugins/grouping-rows/index.js.map +1 -1
- package/lib/plugins/master-detail/index.js +1 -1
- package/lib/plugins/multi-sort/index.js +1 -1
- package/lib/plugins/pinned-columns/index.js +1 -1
- package/lib/plugins/pinned-columns/index.js.map +1 -1
- package/lib/plugins/pinned-rows/index.js +1 -1
- package/lib/plugins/pivot/index.js +1 -1
- package/lib/plugins/pivot/index.js.map +1 -1
- package/lib/plugins/print/index.js +1 -1
- package/lib/plugins/reorder-columns/index.js +1 -1
- package/lib/plugins/reorder-columns/index.js.map +1 -1
- package/lib/plugins/responsive/index.js +1 -1
- package/lib/plugins/responsive/index.js.map +1 -1
- package/lib/plugins/row-drag-drop/index.js +1 -1
- package/lib/plugins/row-drag-drop/index.js.map +1 -1
- package/lib/plugins/selection/index.js +1 -1
- package/lib/plugins/selection/index.js.map +1 -1
- package/lib/plugins/server-side/index.js +1 -1
- package/lib/plugins/server-side/index.js.map +1 -1
- package/lib/plugins/shell/index.js +1 -1
- package/lib/plugins/shell/index.js.map +1 -1
- package/lib/plugins/shell/shell.d.ts +0 -33
- package/lib/plugins/sticky-rows/index.js +1 -1
- package/lib/plugins/tooltip/index.js +1 -1
- package/lib/plugins/tree/index.js +1 -1
- package/lib/plugins/tree/index.js.map +1 -1
- package/lib/plugins/undo-redo/index.js +1 -1
- package/lib/plugins/undo-redo/index.js.map +1 -1
- package/lib/plugins/visibility/index.js +1 -1
- package/lib/plugins/visibility/index.js.map +1 -1
- package/package.json +1 -1
- package/umd/grid.all.umd.js +1 -1
- package/umd/grid.all.umd.js.map +1 -1
- package/umd/grid.umd.js +1 -1
- package/umd/grid.umd.js.map +1 -1
- package/umd/plugins/clipboard.umd.js +1 -1
- package/umd/plugins/clipboard.umd.js.map +1 -1
- package/umd/plugins/editing.umd.js +1 -1
- package/umd/plugins/editing.umd.js.map +1 -1
- package/umd/plugins/shell.umd.js.map +1 -1
- package/lib/plugins/selection/row-selection.d.ts +0 -47
- package/lib/plugins/visibility/visibility.d.ts +0 -31
package/lib/core/constants.d.ts
CHANGED
|
@@ -11,6 +11,13 @@
|
|
|
11
11
|
* Plugins can define their own additional constants and export them.
|
|
12
12
|
* See each plugin's index.ts for plugin-specific exports.
|
|
13
13
|
*/
|
|
14
|
+
/**
|
|
15
|
+
* CSS selector for focusable editor elements within a cell.
|
|
16
|
+
* Used by EditingPlugin, UndoRedoPlugin, and keyboard navigation. Defined here
|
|
17
|
+
* (a leaf module) rather than in `rows.ts` so `keyboard.ts` can consume it
|
|
18
|
+
* without creating a rows ↔ keyboard import cycle.
|
|
19
|
+
*/
|
|
20
|
+
export declare const FOCUSABLE_EDITOR_SELECTOR = "input,select,textarea,[contenteditable=\"true\"],[contenteditable=\"\"],[tabindex]:not([tabindex=\"-1\"])";
|
|
14
21
|
/**
|
|
15
22
|
* CSS class names used in the grid's DOM.
|
|
16
23
|
* Use these when adding/removing classes or querying elements.
|
package/lib/core/grid.d.ts
CHANGED
|
@@ -32,8 +32,12 @@ export declare class DataGridElement<T = any> extends HTMLElement implements Int
|
|
|
32
32
|
*
|
|
33
33
|
* Adapters and consumers that need to construct or query for the grid
|
|
34
34
|
* element MUST use this property, not the hard-coded `tagName` literal.
|
|
35
|
+
*
|
|
36
|
+
* Backed by `internal/tag-registry` (a leaf module) so `style-injector` and
|
|
37
|
+
* other internals can read the active tag without importing this class.
|
|
35
38
|
*/
|
|
36
|
-
static activeTag: string;
|
|
39
|
+
static get activeTag(): string;
|
|
40
|
+
static set activeTag(tag: string);
|
|
37
41
|
/**
|
|
38
42
|
* Registry of framework adapters that handle converting light DOM elements
|
|
39
43
|
* to functional renderers/editors. Framework libraries (Angular, React, Vue)
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { FOCUSABLE_EDITOR_SELECTOR } from '../constants';
|
|
1
2
|
import { ColumnInternal, ColumnViewRenderer, GridHost, InternalGrid } from '../types';
|
|
2
3
|
/** Callback type for plugin row rendering hook */
|
|
3
4
|
export type RenderRowHook = (row: any, rowEl: HTMLElement, rowIndex: number) => boolean;
|
|
@@ -19,11 +20,7 @@ export declare function resolveRenderer<TRow>(grid: InternalGrid<TRow>, col: Col
|
|
|
19
20
|
* 3. Returns undefined (caller uses built-in or fallback)
|
|
20
21
|
*/
|
|
21
22
|
export declare function resolveFormat<TRow>(grid: InternalGrid<TRow>, col: ColumnInternal<TRow>): ((value: unknown, row: TRow) => string) | undefined;
|
|
22
|
-
|
|
23
|
-
* CSS selector for focusable editor elements within a cell.
|
|
24
|
-
* Used by EditingPlugin and keyboard navigation.
|
|
25
|
-
*/
|
|
26
|
-
export declare const FOCUSABLE_EDITOR_SELECTOR = "input,select,textarea,[contenteditable=\"true\"],[contenteditable=\"\"],[tabindex]:not([tabindex=\"-1\"])";
|
|
23
|
+
export { FOCUSABLE_EDITOR_SELECTOR };
|
|
27
24
|
/**
|
|
28
25
|
* Create a row element from template. Significantly faster than createElement + setAttribute.
|
|
29
26
|
*/
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tag Registry (leaf module)
|
|
3
|
+
*
|
|
4
|
+
* Holds the grid's registered custom-element tag name as standalone module
|
|
5
|
+
* state so that modules needing the active tag (e.g. `style-injector`) do not
|
|
6
|
+
* import the `DataGridElement` class, which would create an import cycle with
|
|
7
|
+
* `grid.ts`.
|
|
8
|
+
*
|
|
9
|
+
* `DataGridElement.tagName` / `DataGridElement.activeTag` delegate here, so the
|
|
10
|
+
* public static API is unchanged. See issue #339 for multi-version coexistence.
|
|
11
|
+
*
|
|
12
|
+
* @module internal/tag-registry
|
|
13
|
+
*/
|
|
14
|
+
/** The canonical, unsuffixed grid custom-element tag name. */
|
|
15
|
+
export declare const GRID_TAG_NAME = "tbw-grid";
|
|
16
|
+
/**
|
|
17
|
+
* Tag name this bundle should render and query for. Equals {@link GRID_TAG_NAME}
|
|
18
|
+
* in the common single-version case, or a version-suffixed tag when a second
|
|
19
|
+
* bundle coexists on the page.
|
|
20
|
+
*/
|
|
21
|
+
export declare function getActiveGridTag(): string;
|
|
22
|
+
/** Update the active tag. Called during custom-element registration. */
|
|
23
|
+
export declare function setActiveGridTag(tag: string): void;
|
package/lib/features/registry.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{setFeatureResolver as o}from"@toolbox-web/grid";function t(o,t,e,n){console.warn(function(o,t){return`[tbw-grid] ${o}: ${t}\n\n → More info: ${function(o){return`https://toolboxjs.com/grid/errors#${o.toLowerCase()}`}(o)}`}(o,t))}const e="3.0.0-beta.
|
|
1
|
+
import{setFeatureResolver as o}from"@toolbox-web/grid";function t(o,t,e,n){console.warn(function(o,t){return`[tbw-grid] ${o}: ${t}\n\n → More info: ${function(o){return`https://toolboxjs.com/grid/errors#${o.toLowerCase()}`}(o)}`}(o,t))}const e="3.0.0-beta.4",n=/* @__PURE__ */Symbol.for(`@toolbox-web/grid:feature-registry@${e}/v1`),r=/* @__PURE__ */Symbol.for(`@toolbox-web/grid:feature-registry-warned@${e}/v1`);function s(o,t){let e=Reflect.get(globalThis,o);return void 0===e&&(e=t(),Reflect.set(globalThis,o,e)),e}const i=s(n,()=>/* @__PURE__ */new Map),c=s(r,()=>/* @__PURE__ */new Set),f=()=>"undefined"!=typeof window&&("localhost"===window.location?.hostname||"127.0.0.1"===window.location?.hostname);function a(o,e,n){f()&&i.has(o)&&!n?.override&&t("TBW030",`Feature "${o}" was re-registered. Previous registration overwritten.`),i.set(o,{factory:e,name:o})}function u(o){return i.has(o)}function d(o){return i.get(o)?.factory}function l(){return Array.from(i.keys())}const w={undoRedo:["editing"],clipboard:["selection"]};function g(o,e){const n=i.get(o);if(n)return n.factory(e);if(f()&&!c.has(o)){c.add(o);const e=o.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase();t("TBW031",`Feature "${o}" is configured but not registered.\nAdd this import to enable it:\n\n import '@toolbox-web/grid/features/${e}';\n`)}}function b(o){const e=[];for(const[t,r]of Object.entries(o))void 0!==r&&!1!==r&&e.push(t);!function(o){const e=new Set(o);for(const n of o){const o=w[n];if(o)for(const r of o)e.has(r)||f()&&t("TBW032",`Feature "${n}" requires "${r}" to be enabled. Add "${r}" to your features configuration.`)}}(e);const n=[];for(const t of e){const e=g(t,o[t]);e&&n.push(e)}return function(o){if(o.length<2)return o;const t=/* @__PURE__ */new Map;for(const i of o)t.set(i.name,i);const e=[],n=/* @__PURE__ */new Set,r=/* @__PURE__ */new Set,s=o=>{if(n.has(o)||r.has(o))return;r.add(o);const i=o.constructor.dependencies??[];for(const e of i){const o=t.get(e.name);o&&s(o)}r.delete(o),n.add(o),e.push(o)};for(const i of o)s(i);return e}(n)}function h(){i.clear(),c.clear()}o(b);export{h 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
|
-
const e=/* @__PURE__ */new WeakMap;function t(t,n,r=-1){if(!n.valueAccessor)return t?.[n.field];if("object"!=typeof t||null===t)return n.valueAccessor({row:t,column:n,rowIndex:r});const o=t,i=n.field;let s=e.get(o);if(s){const e=s.get(i);if(void 0!==e)return e.v}else s=/* @__PURE__ */new Map,e.set(o,s);const l=n.valueAccessor({row:t,column:n,rowIndex:r});return s.set(i,{v:l}),l}function n(t,n){t&&(n?e.get(t)?.delete(n):e.delete(t))}function r(e,t){return`[tbw-grid${e?`#${e}`:""}${t?`:${t}`:""}]`}function o(e,t,n,o){return`${r(n,o)} ${e}: ${t}\n\n → More info: ${function(e){return`https://toolboxjs.com/grid/errors#${e.toLowerCase()}`}(e)}`}const i="__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)|${i.slice(3).join("|")}|this\\b`);const s=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".split("|")),l=/^on\w+$/i,a=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),c=/^\s*(javascript|vbscript|data|blob):/i;function u(e){if(!e||"string"!=typeof e)return"";if(-1===e.indexOf("<"))return e;const t=document.createElement("template");return t.innerHTML=e,function(e){const t=[],n=e.querySelectorAll("*");for(const r of n){const e=r.tagName.toLowerCase();if(s.has(e)){t.push(r);continue}if("svg"===e||"http://www.w3.org/2000/svg"===r.namespaceURI){if(Array.from(r.attributes).some(e=>l.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();l.test(e)?n.push(t.name):(a.has(e)&&c.test(t.value)||"style"===e&&/expression\s*\(|javascript:|behavior\s*:/i.test(t.value))&&n.push(t.name)}n.forEach(e=>r.removeAttribute(e))}t.forEach(e=>e.remove())}(t.content),t.innerHTML}const d={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};class h{static dependencies;static manifest;aliases;version="3.0.0-beta.3";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[i,s]of Object.entries(e)){if(void 0===s)continue;if(!(i in t)){t[i]=s,n[i]=r;continue}if(t[i]===s)continue;const e=n[i]?.constructor.name??this.constructor.name,l=r.constructor.name,a=o("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${i}" supplied by both ${e} 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,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)}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{...d,...e}}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;if(t){return"0"!==getComputedStyle(t).getPropertyValue("--tbw-animation-enabled").trim()}return!0}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);void 0!==r?"string"==typeof r?e.innerHTML=u(r):r instanceof HTMLElement&&(e.innerHTML="",e.appendChild(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(o(e,t,this.gridElement.id,this.name)):console.warn(`${r(this.gridElement.id,this.name)} ${e}`)}throwDiagnostic(e,t){throw new Error(o(e,t,this.gridElement.id,this.name))}}function f(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}const g="data-tbw-clip";const p=e=>e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""");function m(e,t,n){const r=e?`<thead><tr>${e.map(e=>`<th>${p(e)}</th>`).join("")}</tr></thead>`:"",o=`<tbody>${t.map(e=>`<tr>${e.map(e=>`<td>${p(e)}</td>`).join("")}</tr>`).join("")}</tbody>`;return`<table ${g}="${function(e){return btoa(encodeURIComponent(JSON.stringify(e)))}(n)}">${r}${o}</table>`}async function w(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(l){n="TBW100",r=`Clipboard API failed: ${l}`,console.warn(o(n,r,i,s));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 a=document.execCommand("copy");return document.body.removeChild(t),a}var n,r,i,s}function b(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},h=()=>{(l.length>1||l.some(e=>""!==e.trim()))&&s.push(l),l=[]};for(let f=0;f<i;f++){const e=o[f];'"'===e?(u=!0,c?'"'===o[f+1]?f++:c=!1:c=!0):e!==n||c?e!==r||c||(l.push(d(f)),a=f+1,u=!1,h()):(l.push(d(f)),a=f+1,u=!1)}return l.push(d(i)),h(),s}function C(e,t){const{rows:r,rawRows:o,target:i,fields:s,fillSelection:l}=e;if(!i||0===r.length)return;const a=o??r,c=t.rows,u=(t.effectiveConfig.columns??[]).map(e=>e.field),[d=()=>!1]=t.query("getCellEditableResolver"),h=/* @__PURE__ */new Map;let f=c.length;const g=(e,t,n,r)=>{if(!t||!d(t,r))return;let o=h.get(e);o||(o={},h.set(e,o)),o[t]=y(n)};if(l&&i.bounds){const e=a.length;for(let t=i.row;t<=i.bounds.endRow&&!(t>=c.length);t++){const n=a[(t-i.row)%e],r=n.length;if(0===r)continue;const o=c[t];s.forEach((e,i)=>g(t,e,n[i%r],o))}}else{const e=i.bounds?i.bounds.endRow:1/0;a.forEach((t,n)=>{const r=i.row+n;if(r>e)return;if(i.bounds&&r>=c.length)return;!i.bounds&&r>=f&&(f=r+1);const o=c[r]??{};t.forEach((e,t)=>g(r,s[t],e,o))})}if(0===h.size&&f===c.length)return;if(f>c.length){const e=[...c];for(;e.length<f;){const t={};u.forEach(e=>t[e]=""),e.push(t)}t.rows=e}const p=t.rows,m=[];let w=!1;for(const[b,C]of h){const e=p[b];if(!e)continue;let r;try{r=t.getRowId(e)}catch{r=void 0}if(null==r){for(const[t,r]of Object.entries(C))e[t]=r,n(e,t);w=!0}else m.push({id:r,changes:C})}m.length>0?t.updateRows(m,"api"):w&&f===c.length&&(t.rows=[...p])}function y(e){if(null===e||"object"!=typeof e)return e;try{return structuredClone(e)}catch{return e}}class v extends h{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=b(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 g of o)s=Math.min(s,g.from.row,g.to.row),a=Math.max(a,g.from.row,g.to.row),l=Math.min(l,g.from.col,g.to.col),c=Math.max(c,g.from.col,g.to.col);const u=r?.anchor??null,d=i?s:u?.row??0,h=i?l:u?.col??0,f=!(!i||"range"!==r?.mode&&"row"!==r?.mode||s===a&&l===c)?{endRow:a,endCol:c}:null,p=f?.endCol??this.visibleColumns.length-1;let m;if(this.#a(n),this.#n&&this.#n.text===t&&this.#n.rawRows.length===n.length)m=this.#n.rawRows;else{const t=function(e){if(!e||-1===e.indexOf(g))return null;try{const t=(new DOMParser).parseFromString(e,"text/html"),n=t.querySelector(`[${g}]`)?.getAttribute(g);if(!n)return null;const r=JSON.parse(decodeURIComponent(atob(n)));return r&&Array.isArray(r.rows)&&Array.isArray(r.fields)?r:null}catch{return null}}(e.clipboardData?.getData("text/html"));t&&t.rows.length===n.length&&(m=t.rows)}const w=this.visibleColumns[h],C=w?{row:d,col:h,field:w.field,bounds:f}:null,y=!0===this.config.fillSelection&&null!==f,v=[],x=n[0]?.length??0,S=y?p-h+1:x;for(let g=0;g<S&&h+g<=p;g++){const e=this.visibleColumns[h+g];e&&v.push(e.field)}const E={rows:n,text:t,target:C,fields:v,fillSelection:y,rawRows:m};this.emit("paste",E),this.#c(E)}#c(e){if(!this.grid)return;const{pasteHandler:t}=this.config;if(null===t)return;(t??C)(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(){const e=this.grid?.query("getSelection");return e?.[0]}#d(e){const t=this.#i();let n,r;if(e?.columns)n=f(this.columns,e.columns);else if(t?.ranges.length&&"row"!==t.mode){const e=t.ranges[t.ranges.length-1],r=Math.min(e.from.col,e.to.col),o=Math.max(e.from.col,e.to.col);n=f(this.visibleColumns.slice(r,o+1))}else n=f(this.columns);if(e?.rowIndices)r=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(t?.ranges.length){const e=t.ranges[t.ranges.length-1],n=Math.min(e.from.row,e.to.row),o=Math.max(e.from.row,e.to.row);r=[];for(let t=n;t<=o;t++){const e=this.rows[t];e&&r.push(e)}}else r=this.rows;return{columns:n,rows:r}}#h(e,t,n){return this.#f(this.#g(e,t,n),n)}#g(e,n,r){const o=r?.includeHeaders??this.config.includeHeaders??!1,i=r?.processCell??this.config.processCell;return{header:o?e.map(e=>e.header||e.field):null,rows:n.map(n=>e.map(e=>{const r=t(n,e);return i?i(r,e.field,n):this.#p(e,r,n)}))}}#f(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)}#p(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}=this.#d(e);return 0===t.length||0===n.length?"":this.#h(t,n,e)}async copy(e){const{columns:n,rows:r}=this.#d(e);if(0===n.length||0===r.length)return"";const o=this.#g(n,r,e),i=this.#f(o,e),s=r.map(e=>n.map(n=>y(t(e,n)))),l=n.map(e=>e.field);return await w(i,m(o.header,o.rows,{v:1,fields:l,rows:s})),this.lastCopied={text:i,timestamp:Date.now()},this.#n={text:i,rawRows:s},this.emit("copy",{text:i,rowCount:r.length,columnCount:n.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?b(e,this.config):null}getLastCopied(){return this.lastCopied}}export{v as ClipboardPlugin,C as defaultPasteHandler};
|
|
1
|
+
const e=/* @__PURE__ */new WeakMap;function t(t,n,r=-1){if(!n.valueAccessor)return t?.[n.field];if("object"!=typeof t||null===t)return n.valueAccessor({row:t,column:n,rowIndex:r});const o=t,i=n.field;let s=e.get(o);if(s){const e=s.get(i);if(void 0!==e)return e.v}else s=/* @__PURE__ */new Map,e.set(o,s);const l=n.valueAccessor({row:t,column:n,rowIndex:r});return s.set(i,{v:l}),l}function n(t,n){t&&(n?e.get(t)?.delete(n):e.delete(t))}function r(e,t){return`[tbw-grid${e?`#${e}`:""}${t?`:${t}`:""}]`}function o(e,t,n,o){return`${r(n,o)} ${e}: ${t}\n\n → More info: ${function(e){return`https://toolboxjs.com/grid/errors#${e.toLowerCase()}`}(e)}`}const i="__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)|${i.slice(3).join("|")}|this\\b`);const s=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".split("|")),l=/^on\w+$/i,a=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),c=/^\s*(javascript|vbscript|data|blob):/i;function u(e){if(!e||"string"!=typeof e)return"";if(-1===e.indexOf("<"))return e;const t=document.createElement("template");return t.innerHTML=e,function(e){const t=[],n=e.querySelectorAll("*");for(const r of n){const e=r.tagName.toLowerCase();if(s.has(e)){t.push(r);continue}if("svg"===e||"http://www.w3.org/2000/svg"===r.namespaceURI){if(Array.from(r.attributes).some(e=>l.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();l.test(e)?n.push(t.name):(a.has(e)&&c.test(t.value)||"style"===e&&/expression\s*\(|javascript:|behavior\s*:/i.test(t.value))&&n.push(t.name)}n.forEach(e=>r.removeAttribute(e))}t.forEach(e=>e.remove())}(t.content),t.innerHTML}const d={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};class h{static dependencies;static manifest;aliases;version="3.0.0-beta.4";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[i,s]of Object.entries(e)){if(void 0===s)continue;if(!(i in t)){t[i]=s,n[i]=r;continue}if(t[i]===s)continue;const e=n[i]?.constructor.name??this.constructor.name,l=r.constructor.name,a=o("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${i}" supplied by both ${e} 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,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)}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{...d,...e}}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;if(t){return"0"!==getComputedStyle(t).getPropertyValue("--tbw-animation-enabled").trim()}return!0}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);void 0!==r?"string"==typeof r?e.innerHTML=u(r):r instanceof HTMLElement&&(e.innerHTML="",e.appendChild(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(o(e,t,this.gridElement.id,this.name)):console.warn(`${r(this.gridElement.id,this.name)} ${e}`)}throwDiagnostic(e,t){throw new Error(o(e,t,this.gridElement.id,this.name))}}function f(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}const g="data-tbw-clip";const p=e=>e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""");function m(e,t,n){const r=e?`<thead><tr>${e.map(e=>`<th>${p(e)}</th>`).join("")}</tr></thead>`:"",o=`<tbody>${t.map(e=>`<tr>${e.map(e=>`<td>${p(e)}</td>`).join("")}</tr>`).join("")}</tbody>`;return`<table ${g}="${function(e){return btoa(encodeURIComponent(JSON.stringify(e)))}(n)}">${r}${o}</table>`}async function w(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(l){n="TBW100",r=`Clipboard API failed: ${l}`,console.warn(o(n,r,i,s));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 a=document.execCommand("copy");return document.body.removeChild(t),a}var n,r,i,s}function b(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},h=()=>{(l.length>1||l.some(e=>""!==e.trim()))&&s.push(l),l=[]};for(let f=0;f<i;f++){const e=o[f];'"'===e?(u=!0,c?'"'===o[f+1]?f++:c=!1:c=!0):e!==n||c?e!==r||c||(l.push(d(f)),a=f+1,u=!1,h()):(l.push(d(f)),a=f+1,u=!1)}return l.push(d(i)),h(),s}function C(e,t){const{rows:r,rawRows:o,target:i,fields:s,fillSelection:l}=e;if(!i||0===r.length)return;const a=o??r,c=t.rows,u=(t.effectiveConfig.columns??[]).map(e=>e.field),[d=()=>!1]=t.query("getCellEditableResolver"),h=/* @__PURE__ */new Map;let f=c.length;const g=(e,t,n,r)=>{if(!t||!d(t,r))return;let o=h.get(e);o||(o={},h.set(e,o)),o[t]=y(n)};if(l&&i.bounds){const e=a.length;for(let t=i.row;t<=i.bounds.endRow&&!(t>=c.length);t++){const n=a[(t-i.row)%e],r=n.length;if(0===r)continue;const o=c[t];s.forEach((e,i)=>g(t,e,n[i%r],o))}}else{const e=i.bounds?i.bounds.endRow:1/0;a.forEach((t,n)=>{const r=i.row+n;if(r>e)return;if(i.bounds&&r>=c.length)return;!i.bounds&&r>=f&&(f=r+1);const o=c[r]??{};t.forEach((e,t)=>g(r,s[t],e,o))})}if(0===h.size&&f===c.length)return;if(f>c.length){const e=[...c];for(;e.length<f;){const t={};u.forEach(e=>t[e]=""),e.push(t)}t.rows=e}const p=t.rows,m=[];let w=!1;for(const[b,C]of h){const e=p[b];if(!e)continue;let r;try{r=t.getRowId(e)}catch{r=void 0}if(null==r){for(const[t,r]of Object.entries(C))e[t]=r,n(e,t);w=!0}else m.push({id:r,changes:C})}m.length>0?t.updateRows(m,"api"):w&&f===c.length&&(t.rows=[...p])}function y(e){if(null===e||"object"!=typeof e)return e;try{return structuredClone(e)}catch{return e}}class v extends h{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=b(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 g of o)s=Math.min(s,g.from.row,g.to.row),a=Math.max(a,g.from.row,g.to.row),l=Math.min(l,g.from.col,g.to.col),c=Math.max(c,g.from.col,g.to.col);const u=r?.anchor??null,d=i?s:u?.row??0,h=i?l:u?.col??0,f=!(!i||"range"!==r?.mode&&"row"!==r?.mode||s===a&&l===c)?{endRow:a,endCol:c}:null,p=f?.endCol??this.visibleColumns.length-1;let m;if(this.#a(n),this.#n&&this.#n.text===t&&this.#n.rawRows.length===n.length)m=this.#n.rawRows;else{const t=function(e){if(!e||-1===e.indexOf(g))return null;try{const t=e.match(new RegExp(`${g}="([A-Za-z0-9+/=]*)"`)),n=t?.[1];if(!n)return null;const r=JSON.parse(decodeURIComponent(atob(n)));return r&&Array.isArray(r.rows)&&Array.isArray(r.fields)?r:null}catch{return null}}(e.clipboardData?.getData("text/html"));t&&t.rows.length===n.length&&(m=t.rows)}const w=this.visibleColumns[h],C=w?{row:d,col:h,field:w.field,bounds:f}:null,y=!0===this.config.fillSelection&&null!==f,v=[],x=n[0]?.length??0,E=y?p-h+1:x;for(let g=0;g<E&&h+g<=p;g++){const e=this.visibleColumns[h+g];e&&v.push(e.field)}const S={rows:n,text:t,target:C,fields:v,fillSelection:y,rawRows:m};this.emit("paste",S),this.#c(S)}#c(e){if(!this.grid)return;const{pasteHandler:t}=this.config;if(null===t)return;(t??C)(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(){const e=this.grid?.query("getSelection");return e?.[0]}#d(e){const t=this.#i();let n,r;if(e?.columns)n=f(this.columns,e.columns);else if(t?.ranges.length&&"row"!==t.mode){const e=t.ranges[t.ranges.length-1],r=Math.min(e.from.col,e.to.col),o=Math.max(e.from.col,e.to.col);n=f(this.visibleColumns.slice(r,o+1))}else n=f(this.columns);if(e?.rowIndices)r=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(t?.ranges.length){const e=t.ranges[t.ranges.length-1],n=Math.min(e.from.row,e.to.row),o=Math.max(e.from.row,e.to.row);r=[];for(let t=n;t<=o;t++){const e=this.rows[t];e&&r.push(e)}}else r=this.rows;return{columns:n,rows:r}}#h(e,t,n){return this.#f(this.#g(e,t,n),n)}#g(e,n,r){const o=r?.includeHeaders??this.config.includeHeaders??!1,i=r?.processCell??this.config.processCell;return{header:o?e.map(e=>e.header||e.field):null,rows:n.map(n=>e.map(e=>{const r=t(n,e);return i?i(r,e.field,n):this.#p(e,r,n)}))}}#f(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)}#p(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}=this.#d(e);return 0===t.length||0===n.length?"":this.#h(t,n,e)}async copy(e){const{columns:n,rows:r}=this.#d(e);if(0===n.length||0===r.length)return"";const o=this.#g(n,r,e),i=this.#f(o,e),s=r.map(e=>n.map(n=>y(t(e,n)))),l=n.map(e=>e.field);return await w(i,m(o.header,o.rows,{v:1,fields:l,rows:s})),this.lastCopied={text:i,timestamp:Date.now()},this.#n={text:i,rawRows:s},this.emit("copy",{text:i,rowCount:r.length,columnCount:n.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?b(e,this.config):null}getLastCopied(){return this.lastCopied}}export{v as ClipboardPlugin,C as defaultPasteHandler};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|