@toolbox-web/grid 0.2.3 → 0.2.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/README.md +24 -0
- package/all.d.ts +59 -96
- package/index.d.ts +59 -96
- package/index.js +345 -291
- package/index.js.map +1 -1
- package/lib/plugins/clipboard/index.js.map +1 -1
- package/lib/plugins/column-virtualization/index.js.map +1 -1
- package/lib/plugins/context-menu/index.js.map +1 -1
- package/lib/plugins/export/index.js.map +1 -1
- package/lib/plugins/filtering/index.js.map +1 -1
- package/lib/plugins/grouping-columns/index.js.map +1 -1
- package/lib/plugins/grouping-rows/index.js.map +1 -1
- package/lib/plugins/master-detail/index.js.map +1 -1
- package/lib/plugins/multi-sort/index.js.map +1 -1
- package/lib/plugins/pinned-columns/index.js.map +1 -1
- package/lib/plugins/pinned-rows/index.js.map +1 -1
- package/lib/plugins/pivot/index.js.map +1 -1
- package/lib/plugins/reorder/index.js.map +1 -1
- package/lib/plugins/selection/index.js.map +1 -1
- package/lib/plugins/server-side/index.js.map +1 -1
- package/lib/plugins/tree/index.js.map +1 -1
- package/lib/plugins/undo-redo/index.js.map +1 -1
- package/lib/plugins/visibility/index.js.map +1 -1
- package/package.json +2 -2
- package/umd/grid.all.umd.js +4 -4
- package/umd/grid.all.umd.js.map +1 -1
- package/umd/grid.umd.js +6 -6
- package/umd/grid.umd.js.map +1 -1
package/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
const fe = ":root{color-scheme:light dark}:host{--tbw-color-bg: transparent;--tbw-color-panel-bg: light-dark(#eeeeee, #222222);--tbw-color-fg: light-dark(#222222, #eeeeee);--tbw-color-fg-muted: light-dark(#555555, #aaaaaa);--tbw-color-accent: light-dark(#3b82f6, #3b82f6);--tbw-color-accent-fg: light-dark(#ffffff, #000000);--tbw-color-success: light-dark(hsl(122, 39%, 40%), hsl(122, 39%, 49%));--tbw-color-selection: light-dark(#fff7d6, #333333);--tbw-color-row-alt: var(--tbw-color-bg);--tbw-color-row-hover: light-dark(#f0f6ff, #1c1c1c);--tbw-color-header-bg: color-mix(in hsl, var(--tbw-color-panel-bg) 85%, var(--tbw-color-fg));--tbw-color-header-fg: color-mix(in hsl, var(--tbw-color-fg) 75%, var(--tbw-color-panel-bg));--tbw-color-border: light-dark(#d0d0d4, #454545);--tbw-color-border-strong: light-dark(#777777, #adacac);--tbw-color-border-cell: var(--tbw-color-border);--tbw-color-border-header: var(--tbw-color-border);--tbw-color-shadow: light-dark(rgba(0, 0, 0, .1), rgba(0, 0, 0, .3));--tbw-font-family: inherit;--tbw-font-size: inherit;--tbw-font-size-header: var(--tbw-font-size);--tbw-font-weight-header: bold;--tbw-cell-padding-header: 2px 8px;--tbw-cell-padding: 2px 8px;--tbw-cell-padding-input: 2px 6px;--tbw-row-height: 28px;--tbw-header-height: 30px;--tbw-cell-white-space: nowrap;--tbw-border-radius: 4px;--tbw-border-input: 1px solid var(--tbw-color-border-strong);--tbw-border-header: 1px solid var(--tbw-color-border-header);--tbw-row-divider: 1px solid var(--tbw-color-border-cell);--tbw-row-hover-outline: 0;--tbw-color-active-row-bg: var(--tbw-color-selection);--tbw-active-row-outline: 0;--tbw-focus-outline: 2px solid var(--tbw-color-accent);--tbw-focus-outline-offset: -2px;--tbw-focus-background: rgba(from var(--tbw-color-accent) r g b / 12%);--tbw-range-border-color: var(--tbw-color-accent);--tbw-range-selection-bg: rgba(from var(--tbw-range-border-color) r g b / 12%);--tbw-resize-handle-width: 4px;--tbw-resize-handle-color: transparent;--tbw-resize-handle-color-hover: var(--tbw-color-accent);--tbw-resize-handle-border-radius: 0;--tbw-scrollbar-thumb: var(--tbw-color-border-strong);--tbw-scrollbar-track: var(--tbw-color-bg);--tbw-transition-duration: .12s;--tbw-transition-ease: ease;--tbw-editing-bg: var(--tbw-color-selection);--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-sort-indicator-color: var(--tbw-color-fg-muted);--tbw-sort-indicator-active-color: var(--tbw-color-accent);--tbw-header-text-transform: none;--tbw-header-letter-spacing: normal;--tbw-color-header-separator: var(--tbw-color-border-cell);--tbw-checkbox-size: 16px;--tbw-density-scale: 1}:host{position:relative;display:block;width:100%;height:100%;min-height:0;contain:content;font-family:var(--tbw-font-family);font-size:var(--tbw-font-size);background:var(--tbw-color-bg);color:var(--tbw-color-fg);border:1px solid var(--tbw-color-border);border-radius:var(--tbw-border-radius);overflow:clip;outline:none}:host,:host *{box-sizing:border-box}:host .header{display:block;flex-shrink:0;z-index:var(--tbw-z-layer-header, 30);background:var(--tbw-color-header-bg);overflow:visible}:host .header-group-row{display:grid;grid-template-columns:var(--tbw-column-template);background:var(--tbw-color-header-bg);z-index:var(--tbw-z-layer-header, 30)}:host .header-group-cell{display:flex;align-items:center;justify-content:flex-start;padding:var(--tbw-cell-padding-header, 2px 8px);color:var(--tbw-color-header-group-fg, var(--tbw-color-header-fg));font-weight:var(--tbw-font-weight-header-group, var(--tbw-font-weight-header));justify-content:var(--tbw-align-header-group, var(--tbw-align-header, flex-start))}:host .header-row{display:grid;grid-template-columns:var(--tbw-column-template);color:var(--tbw-color-header-fg);font-size:var(--tbw-font-size-header);min-height:var(--tbw-header-height);border-bottom:var(--tbw-border-header);z-index:var(--tbw-z-layer-header, 30)}:host .header-row>.cell{display:flex;align-items:center;gap:4px;padding:var(--tbw-cell-padding-header, 2px 8px);background-color:var(--tbw-color-header-bg);font-weight:var(--tbw-font-weight-header);border-right:1px solid var(--tbw-color-border-cell);overflow:hidden;min-width:0}:host .header-row>.cell>span:first-child{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}:host .header-row>.cell>span[part~=sort-indicator]{flex-shrink:0}:host .header-row>.cell:last-child{border-right:0}:host .header-group-cell,:host .header-row>.cell.grouped.group-end{border-right:2px solid var(--tbw-color-border)}:host .tbw-grid-root{display:flex;flex-direction:column;height:100%}:host .rows-body-wrapper{flex:1;min-height:0;display:flex;flex-direction:row;width:100%;min-width:fit-content}:host .rows-body{flex:1;min-width:0;min-height:0;display:flex;flex-direction:column;overflow:visible}:host .rows-container{display:flex;flex-direction:row;flex:1;min-height:0;overflow:visible}:host .rows-viewport{flex:1;min-width:0;position:relative;display:block;overflow:clip}:host .faux-vscroll{position:sticky;inset-inline-end:0;flex-shrink:0;width:auto;overflow-y:auto;overflow-x:hidden;z-index:var(--tbw-z-layer-header, 30)}:host .faux-vscroll-spacer{width:1px}:host .rows-viewport .rows{position:absolute;top:0;left:0;min-width:100%;will-change:transform;z-index:var(--tbw-z-layer-rows, 1)}:host .data-grid-row{display:grid;grid-template-columns:var(--tbw-column-template);contain:layout style}:host .data-grid-row:has(.editing){background:var(--tbw-editing-bg)}:host .selecting .data-grid-row>.cell{user-select:none}:host .data-grid-row>.cell.selected:focus-visible,:host .data-grid-row>.cell:focus-visible:not(.cell-focus){outline:none}:host .data-grid-row>.cell{display:block;padding:var(--tbw-cell-padding, 2px 8px);border-bottom:var(--tbw-row-divider);min-height:var(--tbw-row-height);line-height:calc(var(--tbw-row-height) - 5px);border-right:1px solid var(--tbw-color-border-cell);overflow:hidden;min-width:0;white-space:var(--tbw-cell-white-space, nowrap);text-overflow:ellipsis}:host .data-grid-row>.cell>*{overflow:hidden;text-overflow:ellipsis;white-space:inherit;min-width:0}:host .data-grid-row>.cell:last-child{border-right:0}:host .data-grid-row>.cell[data-type=boolean]{text-align:center}:host .data-grid-row>.cell[data-type=boolean] input[type=checkbox]{margin:0;width:var(--tbw-checkbox-size);height:var(--tbw-checkbox-size);vertical-align:middle}:host .data-grid-row>.cell.editing{overflow:hidden;padding:0;display:flex}:host .data-grid-row>.cell.editing input:not([type=checkbox]),:host .data-grid-row>.cell.editing select,:host .data-grid-row>.cell.editing textarea{width:100%;height:100%;max-width:100%;flex:1 1 auto;min-width:0;border:var(--tbw-editing-border);padding:var(--tbw-padding-editing-input);font-size:var(--tbw-font-size-editor)}:host .data-grid-row:nth-child(2n){background:var(--tbw-color-row-alt)}:host .data-grid-row:hover{background:var(--tbw-color-row-hover)}:host .sortable{cursor:pointer;user-select:none}:host .resize-handle{position:absolute;top:0;right:calc(var(--tbw-resize-handle-width) / -2);width:var(--tbw-resize-handle-width);height:100%;cursor:e-resize;user-select:none;touch-action:none;z-index:20;background:var(--tbw-resize-handle-color);transition:background .12s ease;border-radius:var(--tbw-resize-handle-border-radius)}:host .resize-handle:hover{background:var(--tbw-resize-handle-color-hover)}:host .cell-focus,:host .row-focus{outline:var(--tbw-focus-outline);outline-offset:var(--tbw-focus-outline-offset)}:host .group-row{display:grid;grid-template-columns:var(--tbw-column-template);background:var(--tbw-color-row-alt);font-weight:500;border-bottom:var(--tbw-row-divider);min-height:var(--tbw-row-height)}:host .group-row .cell{display:flex;align-items:center;padding:var(--tbw-cell-padding, 2px 8px)}:host .group-row .group-toggle{background:none;border:0;cursor:pointer;padding:0 4px 0 0;font:inherit}:host .group-row .group-count{margin-left:4px;opacity:.7}:host .sticky-left,:host .sticky-right{position:sticky;z-index:25}:host .header-row>.cell.sticky-left,:host .header-row>.cell.sticky-right{background:var(--tbw-color-header-bg);z-index:35}:host .data-grid-row>.cell.sticky-left,:host .data-grid-row>.cell.sticky-right{background:var(--tbw-color-panel-bg)}:host .sticky-left{box-shadow:1px 0 0 var(--tbw-color-border)}:host .sticky-right{box-shadow:-1px 0 0 var(--tbw-color-border)}.grid-container{position:relative;width:100%;height:100%}.grid-placeholder{padding:2rem;text-align:center;color:var(--tbw-color-fg);opacity:.6}:host{--tbw-shell-header-height: 44px;--tbw-shell-header-bg: var(--tbw-color-panel-bg);--tbw-shell-header-border: var(--tbw-color-border);--tbw-shell-title-font-size: 14px;--tbw-shell-title-font-weight: 600;--tbw-tool-panel-width: 280px;--tbw-tool-panel-bg: var(--tbw-color-panel-bg);--tbw-tool-panel-border: var(--tbw-color-border);--tbw-tool-panel-header-height: 40px;--tbw-tool-panel-transition: .2s ease-out;--tbw-toolbar-button-size: 32px;--tbw-toolbar-button-gap: 4px}:host .tbw-grid-root.has-shell{display:flex;flex-direction:column;height:100%}:host .tbw-shell-header{display:flex;align-items:center;gap:8px;min-height:var(--tbw-shell-header-height);padding:0 8px;background:var(--tbw-shell-header-bg);border-bottom:1px solid var(--tbw-shell-header-border);flex-shrink:0}:host .tbw-shell-title{font-size:var(--tbw-shell-title-font-size);font-weight:var(--tbw-shell-title-font-weight);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}:host .tbw-shell-content{flex:1;display:flex;align-items:center;gap:12px;min-width:0;overflow:hidden}:host .tbw-shell-toolbar{display:flex;align-items:center;gap:var(--tbw-toolbar-button-gap);flex-shrink:0}:host .tbw-toolbar-btn{display:inline-flex;align-items:center;justify-content:center;width:var(--tbw-toolbar-button-size);height:var(--tbw-toolbar-button-size);padding:0;border:1px solid transparent;border-radius:var(--tbw-border-radius);background:transparent;color:var(--tbw-color-fg);cursor:pointer;font-size:16px;transition:background var(--tbw-transition-duration) var(--tbw-transition-ease),border-color var(--tbw-transition-duration) var(--tbw-transition-ease)}:host .tbw-toolbar-btn:hover{background:var(--tbw-color-row-hover)}:host .tbw-toolbar-btn:focus-visible{outline:var(--tbw-focus-outline);outline-offset:var(--tbw-focus-outline-offset)}:host .tbw-toolbar-btn.active{background:var(--tbw-focus-background);border-color:var(--tbw-color-accent)}:host .tbw-toolbar-btn:disabled{opacity:.5;cursor:not-allowed}:host .tbw-toolbar-separator{width:1px;height:20px;background:var(--tbw-color-border);margin:0 4px}:host .tbw-shell-body{position:relative;display:flex;flex:1;min-height:0;overflow:visible}:host .tbw-grid-content{flex:1;min-width:0;min-height:0;display:flex;flex-direction:row;overflow:hidden}:host .tbw-scroll-area{flex:1;min-width:0;min-height:0;display:flex;flex-direction:column;overflow-x:auto;overflow-y:hidden}:host .tbw-tool-panel{position:absolute;top:0;bottom:0;right:0;width:0;overflow:hidden;background:var(--tbw-tool-panel-bg);border-left:1px solid var(--tbw-tool-panel-border);transition:width var(--tbw-tool-panel-transition);display:flex;flex-direction:column;z-index:30;box-shadow:-2px 0 8px var(--tbw-color-shadow)}:host .tbw-tool-panel[data-position=left]{right:auto;left:0;border-left:none;border-right:1px solid var(--tbw-tool-panel-border);box-shadow:2px 0 8px var(--tbw-color-shadow)}:host .tbw-tool-panel.open{width:var(--tbw-tool-panel-width)}:host .tbw-tool-panel-resize{position:absolute;top:0;bottom:0;width:6px;cursor:col-resize;background:transparent;z-index:10;transition:background .15s ease}:host .tbw-tool-panel-resize[data-handle-position=left]{left:0}:host .tbw-tool-panel-resize[data-handle-position=right]{right:0}:host .tbw-tool-panel-resize:hover,:host .tbw-tool-panel-resize.resizing{background:var(--tbw-color-accent)}:host .tbw-tool-panel-header{display:flex;align-items:center;justify-content:space-between;min-height:var(--tbw-tool-panel-header-height);padding:0 12px;border-bottom:1px solid var(--tbw-tool-panel-border);flex-shrink:0}:host .tbw-tool-panel-title{font-weight:600;font-size:13px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}:host .tbw-tool-panel-close{display:inline-flex;align-items:center;justify-content:center;width:24px;height:24px;padding:0;border:none;border-radius:var(--tbw-border-radius);background:transparent;color:var(--tbw-color-fg-muted);cursor:pointer;font-size:14px}:host .tbw-tool-panel-close:hover{background:var(--tbw-color-row-hover);color:var(--tbw-color-fg)}:host .tbw-tool-panel-content{flex:1;overflow:auto}:host .tbw-accordion{display:flex;flex-direction:column;gap:0}:host .tbw-accordion-section{border-bottom:1px solid var(--tbw-tool-panel-border)}:host .tbw-accordion-section:last-child{border-bottom:none}:host .tbw-accordion-header{display:flex;align-items:center;gap:8px;width:100%;padding:10px 12px;border:none;background:transparent;color:var(--tbw-color-fg);font-size:13px;font-weight:600;text-align:left;cursor:pointer;user-select:none}:host .tbw-accordion-header:hover{background:var(--tbw-color-row-hover)}:host .tbw-accordion-section.single .tbw-accordion-header{cursor:default}:host .tbw-accordion-section.single .tbw-accordion-header:hover{background:transparent}:host .tbw-accordion-chevron{display:inline-flex;align-items:center;justify-content:center;width:16px;height:16px;font-size:10px;color:var(--tbw-color-fg-muted);transition:transform .15s ease;flex-shrink:0}:host .tbw-accordion-section.expanded .tbw-accordion-chevron{transform:rotate(90deg)}:host .tbw-accordion-icon{display:inline-flex;align-items:center;justify-content:center;width:16px;height:16px;font-size:14px;flex-shrink:0}:host .tbw-accordion-title{flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}:host .tbw-accordion-content{display:none}:host .tbw-accordion-section.expanded .tbw-accordion-content{display:block}:host .tbw-quick-filter-input{flex:1;max-width:300px;height:28px;padding:0 8px;border:1px solid var(--tbw-color-border);border-radius:var(--tbw-border-radius);background:var(--tbw-color-bg);color:var(--tbw-color-fg);font-size:13px}:host .tbw-quick-filter-input:focus{outline:none;border-color:var(--tbw-color-accent)}:host .tbw-selection-summary{font-size:13px;color:var(--tbw-color-fg-muted);white-space:nowrap}";
|
|
2
2
|
function pe(t) {
|
|
3
3
|
const e = /* @__PURE__ */ new Map();
|
|
4
|
-
return t.
|
|
5
|
-
direction: t.
|
|
4
|
+
return t._sortState && e.set(t._sortState.field, {
|
|
5
|
+
direction: t._sortState.direction === 1 ? "asc" : "desc",
|
|
6
6
|
priority: 0
|
|
7
7
|
}), e;
|
|
8
8
|
}
|
|
@@ -43,12 +43,12 @@ function be(t, e, o, i) {
|
|
|
43
43
|
const r = e.columns.filter((l) => l.sort !== void 0).sort((l, a) => (l.sort?.priority ?? 0) - (a.sort?.priority ?? 0));
|
|
44
44
|
if (r.length > 0) {
|
|
45
45
|
const l = r[0];
|
|
46
|
-
l.sort && (t.
|
|
46
|
+
l.sort && (t._sortState = {
|
|
47
47
|
field: l.field,
|
|
48
48
|
direction: l.sort.direction === "asc" ? 1 : -1
|
|
49
49
|
});
|
|
50
50
|
} else
|
|
51
|
-
t.
|
|
51
|
+
t._sortState = null;
|
|
52
52
|
for (const l of i)
|
|
53
53
|
if (l.applyColumnState)
|
|
54
54
|
for (const a of e.columns)
|
|
@@ -95,7 +95,7 @@ function de(t, e) {
|
|
|
95
95
|
n[s.field] = s.type || "string";
|
|
96
96
|
}), { columns: i, typeMap: n };
|
|
97
97
|
}
|
|
98
|
-
const me = /{{\s*([^}]+)\s*}}/g, L = "__DG_EMPTY__", ve = /^[\w$. '?+\-*/%:()!<>=,&|]+$/,
|
|
98
|
+
const me = /{{\s*([^}]+)\s*}}/g, L = "__DG_EMPTY__", ve = /^[\w$. '?+\-*/%:()!<>=,&|]+$/, _e = /__(proto|defineGetter|defineSetter)|constructor|window|globalThis|global|process|Function|import|eval|Reflect|Proxy|Error|arguments|document|location|cookie|localStorage|sessionStorage|indexedDB|fetch|XMLHttpRequest|WebSocket|Worker|SharedWorker|ServiceWorker|opener|parent|top|frames|self|this\b/, Ee = /* @__PURE__ */ new Set([
|
|
99
99
|
"script",
|
|
100
100
|
"iframe",
|
|
101
101
|
"object",
|
|
@@ -120,23 +120,23 @@ const me = /{{\s*([^}]+)\s*}}/g, L = "__DG_EMPTY__", ve = /^[\w$. '?+\-*/%:()!<>
|
|
|
120
120
|
"plaintext",
|
|
121
121
|
"xmp",
|
|
122
122
|
"listing"
|
|
123
|
-
]),
|
|
123
|
+
]), Q = /^on\w+$/i, Ce = /* @__PURE__ */ new Set(["href", "src", "action", "formaction", "data", "srcdoc", "xlink:href", "poster", "srcset"]), ye = /^\s*(javascript|vbscript|data|blob):/i;
|
|
124
124
|
function F(t) {
|
|
125
125
|
if (!t || typeof t != "string") return "";
|
|
126
126
|
if (t.indexOf("<") === -1) return t;
|
|
127
127
|
const e = document.createElement("template");
|
|
128
|
-
return e.innerHTML = t,
|
|
128
|
+
return e.innerHTML = t, Re(e.content), e.innerHTML;
|
|
129
129
|
}
|
|
130
|
-
function
|
|
130
|
+
function Re(t) {
|
|
131
131
|
const e = [], o = t.querySelectorAll("*");
|
|
132
132
|
for (const i of o) {
|
|
133
133
|
const n = i.tagName.toLowerCase();
|
|
134
|
-
if (
|
|
134
|
+
if (Ee.has(n)) {
|
|
135
135
|
e.push(i);
|
|
136
136
|
continue;
|
|
137
137
|
}
|
|
138
138
|
if ((n === "svg" || i.namespaceURI === "http://www.w3.org/2000/svg") && Array.from(i.attributes).some(
|
|
139
|
-
(l) =>
|
|
139
|
+
(l) => Q.test(l.name) || l.name === "href" || l.name === "xlink:href"
|
|
140
140
|
)) {
|
|
141
141
|
e.push(i);
|
|
142
142
|
continue;
|
|
@@ -144,11 +144,11 @@ function _e(t) {
|
|
|
144
144
|
const s = [];
|
|
145
145
|
for (const r of i.attributes) {
|
|
146
146
|
const l = r.name.toLowerCase();
|
|
147
|
-
if (
|
|
147
|
+
if (Q.test(l)) {
|
|
148
148
|
s.push(r.name);
|
|
149
149
|
continue;
|
|
150
150
|
}
|
|
151
|
-
if (
|
|
151
|
+
if (Ce.has(l) && ye.test(r.value)) {
|
|
152
152
|
s.push(r.name);
|
|
153
153
|
continue;
|
|
154
154
|
}
|
|
@@ -176,7 +176,7 @@ function Se(t, e) {
|
|
|
176
176
|
const i = t.slice(4), n = e.row ? e.row[i] : void 0;
|
|
177
177
|
return n == null ? L : String(n);
|
|
178
178
|
}
|
|
179
|
-
if (t.length > 80 || !ve.test(t) ||
|
|
179
|
+
if (t.length > 80 || !ve.test(t) || _e.test(t)) return L;
|
|
180
180
|
const o = t.match(/\./g);
|
|
181
181
|
if (o && o.length > 1) return L;
|
|
182
182
|
try {
|
|
@@ -256,14 +256,14 @@ function Pe(t) {
|
|
|
256
256
|
function te(t) {
|
|
257
257
|
const e = t.effectiveConfig?.fitMode || t.fitMode || $.STRETCH;
|
|
258
258
|
if (e !== $.STRETCH && e !== $.FIXED || t.__didInitialAutoSize || !t.isConnected) return;
|
|
259
|
-
const o = t.
|
|
259
|
+
const o = t._headerRowEl?.children || [];
|
|
260
260
|
if (!o.length) return;
|
|
261
261
|
let i = !1;
|
|
262
|
-
t.
|
|
262
|
+
t._visibleColumns.forEach((n, s) => {
|
|
263
263
|
if (n.width) return;
|
|
264
264
|
const r = o[s];
|
|
265
265
|
let l = r ? r.scrollWidth : 0;
|
|
266
|
-
for (const a of t.
|
|
266
|
+
for (const a of t._rowPool) {
|
|
267
267
|
const d = a.children[s];
|
|
268
268
|
if (d) {
|
|
269
269
|
const f = d.scrollWidth;
|
|
@@ -271,14 +271,14 @@ function te(t) {
|
|
|
271
271
|
}
|
|
272
272
|
}
|
|
273
273
|
l > 0 && (n.width = l + 2, n.__autoSized = !0, i = !0);
|
|
274
|
-
}), i &&
|
|
274
|
+
}), i && N(t), t.__didInitialAutoSize = !0;
|
|
275
275
|
}
|
|
276
|
-
function
|
|
277
|
-
(t.effectiveConfig?.fitMode || t.fitMode || $.STRETCH) === $.STRETCH ? t.
|
|
276
|
+
function N(t) {
|
|
277
|
+
(t.effectiveConfig?.fitMode || t.fitMode || $.STRETCH) === $.STRETCH ? t._gridTemplate = t._visibleColumns.map((o) => {
|
|
278
278
|
if (o.width) return `${o.width}px`;
|
|
279
279
|
const i = o.minWidth;
|
|
280
280
|
return i != null ? `minmax(${i}px, 1fr)` : "1fr";
|
|
281
|
-
}).join(" ").trim() : t.
|
|
281
|
+
}).join(" ").trim() : t._gridTemplate = t._visibleColumns.map((o) => o.width ? `${o.width}px` : "max-content").join(" "), t.style.setProperty("--tbw-column-template", t._gridTemplate);
|
|
282
282
|
}
|
|
283
283
|
function He(t) {
|
|
284
284
|
switch (t.type) {
|
|
@@ -331,10 +331,10 @@ function He(t) {
|
|
|
331
331
|
};
|
|
332
332
|
}
|
|
333
333
|
}
|
|
334
|
-
function
|
|
335
|
-
if (t.
|
|
334
|
+
function Oe(t, e) {
|
|
335
|
+
if (t._dispatchKeyDown?.(e))
|
|
336
336
|
return;
|
|
337
|
-
const o = t._rows.length - 1, i = t.
|
|
337
|
+
const o = t._rows.length - 1, i = t._visibleColumns.length - 1, n = t._activeEditRows !== void 0 && t._activeEditRows !== -1, r = t._visibleColumns[t._focusCol]?.type, l = e.composedPath ? e.composedPath() : [], a = l && l.length ? l[0] : e.target, d = (f) => {
|
|
338
338
|
if (!f) return !1;
|
|
339
339
|
const h = f.tagName;
|
|
340
340
|
return !!(h === "INPUT" || h === "SELECT" || h === "TEXTAREA" || f.isContentEditable);
|
|
@@ -342,36 +342,36 @@ function ke(t, e) {
|
|
|
342
342
|
if (!(d(a) && (e.key === "Home" || e.key === "End")) && !(d(a) && (e.key === "ArrowUp" || e.key === "ArrowDown") && a.tagName === "INPUT" && a.type === "number") && !(d(a) && (e.key === "ArrowLeft" || e.key === "ArrowRight")) && !(d(a) && (e.key === "Enter" || e.key === "Escape")) && !(n && (r === "select" || r === "typeahead") && (e.key === "ArrowDown" || e.key === "ArrowUp"))) {
|
|
343
343
|
switch (e.key) {
|
|
344
344
|
case "Tab": {
|
|
345
|
-
e.preventDefault(), !e.shiftKey ? t.
|
|
345
|
+
e.preventDefault(), !e.shiftKey ? t._focusCol < i ? t._focusCol += 1 : (typeof t.commitActiveRowEdit == "function" && t.commitActiveRowEdit(), t._focusRow < o && (t._focusRow += 1, t._focusCol = 0)) : t._focusCol > 0 ? t._focusCol -= 1 : t._focusRow > 0 && (typeof t.commitActiveRowEdit == "function" && t._activeEditRows === t._focusRow && t.commitActiveRowEdit(), t._focusRow -= 1, t._focusCol = i), z(t);
|
|
346
346
|
return;
|
|
347
347
|
}
|
|
348
348
|
case "ArrowDown":
|
|
349
|
-
n && typeof t.commitActiveRowEdit == "function" && t.commitActiveRowEdit(), t.
|
|
349
|
+
n && typeof t.commitActiveRowEdit == "function" && t.commitActiveRowEdit(), t._focusRow = Math.min(o, t._focusRow + 1), e.preventDefault();
|
|
350
350
|
break;
|
|
351
351
|
case "ArrowUp":
|
|
352
|
-
n && typeof t.commitActiveRowEdit == "function" && t.commitActiveRowEdit(), t.
|
|
352
|
+
n && typeof t.commitActiveRowEdit == "function" && t.commitActiveRowEdit(), t._focusRow = Math.max(0, t._focusRow - 1), e.preventDefault();
|
|
353
353
|
break;
|
|
354
354
|
case "ArrowRight":
|
|
355
|
-
t.
|
|
355
|
+
t._focusCol = Math.min(i, t._focusCol + 1), e.preventDefault();
|
|
356
356
|
break;
|
|
357
357
|
case "ArrowLeft":
|
|
358
|
-
t.
|
|
358
|
+
t._focusCol = Math.max(0, t._focusCol - 1), e.preventDefault();
|
|
359
359
|
break;
|
|
360
360
|
case "Home":
|
|
361
|
-
(e.ctrlKey || e.metaKey) && (n && typeof t.commitActiveRowEdit == "function" && t.commitActiveRowEdit(), t.
|
|
361
|
+
(e.ctrlKey || e.metaKey) && (n && typeof t.commitActiveRowEdit == "function" && t.commitActiveRowEdit(), t._focusRow = 0), t._focusCol = 0, e.preventDefault(), z(t, { forceScrollLeft: !0 });
|
|
362
362
|
return;
|
|
363
363
|
case "End":
|
|
364
|
-
(e.ctrlKey || e.metaKey) && (n && typeof t.commitActiveRowEdit == "function" && t.commitActiveRowEdit(), t.
|
|
364
|
+
(e.ctrlKey || e.metaKey) && (n && typeof t.commitActiveRowEdit == "function" && t.commitActiveRowEdit(), t._focusRow = o), t._focusCol = i, e.preventDefault(), z(t, { forceScrollRight: !0 });
|
|
365
365
|
return;
|
|
366
366
|
case "PageDown":
|
|
367
|
-
t.
|
|
367
|
+
t._focusRow = Math.min(o, t._focusRow + 20), e.preventDefault();
|
|
368
368
|
break;
|
|
369
369
|
case "PageUp":
|
|
370
|
-
t.
|
|
370
|
+
t._focusRow = Math.max(0, t._focusRow - 20), e.preventDefault();
|
|
371
371
|
break;
|
|
372
372
|
case "Enter":
|
|
373
|
-
return typeof t.beginBulkEdit == "function" ? t.beginBulkEdit(t.
|
|
374
|
-
new CustomEvent("activate-cell", { detail: { row: t.
|
|
373
|
+
return typeof t.beginBulkEdit == "function" ? t.beginBulkEdit(t._focusRow) : t.dispatchEvent(
|
|
374
|
+
new CustomEvent("activate-cell", { detail: { row: t._focusRow, col: t._focusCol } })
|
|
375
375
|
), z(t);
|
|
376
376
|
default:
|
|
377
377
|
return;
|
|
@@ -380,19 +380,19 @@ function ke(t, e) {
|
|
|
380
380
|
}
|
|
381
381
|
}
|
|
382
382
|
function z(t, e) {
|
|
383
|
-
if (t.
|
|
384
|
-
const { rowHeight: r, container: l, viewportEl: a } = t.
|
|
383
|
+
if (t._virtualization?.enabled) {
|
|
384
|
+
const { rowHeight: r, container: l, viewportEl: a } = t._virtualization, d = l, f = a?.clientHeight ?? d?.clientHeight ?? 0;
|
|
385
385
|
if (d && f > 0) {
|
|
386
|
-
const h = t.
|
|
386
|
+
const h = t._focusRow * r;
|
|
387
387
|
h < d.scrollTop ? d.scrollTop = h : h + r > d.scrollTop + f && (d.scrollTop = h - f + r);
|
|
388
388
|
}
|
|
389
389
|
}
|
|
390
|
-
t.
|
|
390
|
+
t._activeEditRows !== void 0 && t._activeEditRows !== -1 || t.refreshVirtualWindow(!1), Array.from(t._bodyEl.querySelectorAll(".cell-focus")).forEach((r) => r.classList.remove("cell-focus")), Array.from(t._bodyEl.querySelectorAll('[aria-selected="true"]')).forEach((r) => {
|
|
391
391
|
r.setAttribute("aria-selected", "false");
|
|
392
392
|
});
|
|
393
|
-
const i = t.
|
|
393
|
+
const i = t._focusRow, n = t._virtualization.start ?? 0, s = t._virtualization.end ?? t._rows.length;
|
|
394
394
|
if (i >= n && i < s) {
|
|
395
|
-
const r = t.
|
|
395
|
+
const r = t._bodyEl.querySelectorAll(".data-grid-row")[i - n], l = r?.children[t._focusCol];
|
|
396
396
|
if (l) {
|
|
397
397
|
l.classList.add("cell-focus"), l.setAttribute("aria-selected", "true");
|
|
398
398
|
const a = t.shadowRoot?.querySelector(".tbw-scroll-area");
|
|
@@ -402,13 +402,13 @@ function z(t, e) {
|
|
|
402
402
|
else if (e?.forceScrollRight)
|
|
403
403
|
a.scrollLeft = a.scrollWidth - a.clientWidth;
|
|
404
404
|
else {
|
|
405
|
-
const d = t.
|
|
405
|
+
const d = t._getHorizontalScrollOffsets?.(r ?? void 0, l) ?? { left: 0, right: 0 };
|
|
406
406
|
if (!d.skipScroll) {
|
|
407
407
|
const f = l.getBoundingClientRect(), h = a.getBoundingClientRect(), p = f.left - h.left + a.scrollLeft, c = p + f.width, u = a.scrollLeft + d.left, b = a.scrollLeft + a.clientWidth - d.right;
|
|
408
408
|
p < u ? a.scrollLeft = p - d.left : c > b && (a.scrollLeft = c - a.clientWidth + d.right);
|
|
409
409
|
}
|
|
410
410
|
}
|
|
411
|
-
if (t.
|
|
411
|
+
if (t._activeEditRows !== void 0 && t._activeEditRows !== -1 && l.classList.contains("editing")) {
|
|
412
412
|
const d = l.querySelector(
|
|
413
413
|
'input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])'
|
|
414
414
|
);
|
|
@@ -427,82 +427,82 @@ function z(t, e) {
|
|
|
427
427
|
}
|
|
428
428
|
}
|
|
429
429
|
}
|
|
430
|
-
const
|
|
430
|
+
const ke = "__cellDisplayCache", ze = "__cellCacheEpoch";
|
|
431
431
|
function Y(t) {
|
|
432
|
-
t[
|
|
432
|
+
t[ke] = void 0, t[ze] = void 0, t.__hasSpecialColumns = void 0;
|
|
433
433
|
}
|
|
434
434
|
function Me(t, e, o, i, n) {
|
|
435
|
-
const s = Math.max(0, o - e), r = t.
|
|
435
|
+
const s = Math.max(0, o - e), r = t._bodyEl, l = t._visibleColumns, a = l.length;
|
|
436
436
|
let d = t.__cachedHeaderRowCount;
|
|
437
|
-
for (d === void 0 && (d = t.shadowRoot?.querySelector(".header-group-row") ? 2 : 1, t.__cachedHeaderRowCount = d); t.
|
|
437
|
+
for (d === void 0 && (d = t.shadowRoot?.querySelector(".header-group-row") ? 2 : 1, t.__cachedHeaderRowCount = d); t._rowPool.length < s; ) {
|
|
438
438
|
const h = document.createElement("div");
|
|
439
|
-
h.className = "data-grid-row", h.setAttribute("role", "row"), h.addEventListener("click", (p) => oe(t, p, h, !1)), h.addEventListener("dblclick", (p) => oe(t, p, h, !0)), t.
|
|
439
|
+
h.className = "data-grid-row", h.setAttribute("role", "row"), h.addEventListener("click", (p) => oe(t, p, h, !1)), h.addEventListener("dblclick", (p) => oe(t, p, h, !0)), t._rowPool.push(h);
|
|
440
440
|
}
|
|
441
|
-
if (t.
|
|
442
|
-
for (let h = s; h < t.
|
|
443
|
-
const p = t.
|
|
441
|
+
if (t._rowPool.length > s) {
|
|
442
|
+
for (let h = s; h < t._rowPool.length; h++) {
|
|
443
|
+
const p = t._rowPool[h];
|
|
444
444
|
p.parentNode === r && p.remove();
|
|
445
445
|
}
|
|
446
|
-
t.
|
|
446
|
+
t._rowPool.length = s;
|
|
447
447
|
}
|
|
448
448
|
const f = n && t.__hasRenderRowPlugins !== !1;
|
|
449
449
|
for (let h = 0; h < s; h++) {
|
|
450
|
-
const p = e + h, c = t._rows[p], u = t.
|
|
450
|
+
const p = e + h, c = t._rows[p], u = t._rowPool[h];
|
|
451
451
|
if (u.setAttribute("aria-rowindex", String(p + d + 1)), f && n(c, u, p)) {
|
|
452
452
|
u.__epoch = i, u.__rowDataRef = c, u.parentNode !== r && r.appendChild(u);
|
|
453
453
|
continue;
|
|
454
454
|
}
|
|
455
|
-
const b = u.__epoch, w = u.__rowDataRef, v = u.children.length, x = b === i && v === a,
|
|
455
|
+
const b = u.__epoch, w = u.__rowDataRef, v = u.children.length, x = b === i && v === a, R = w !== c;
|
|
456
456
|
let g = !1;
|
|
457
|
-
if (x &&
|
|
458
|
-
for (let
|
|
459
|
-
if (l[
|
|
457
|
+
if (x && R) {
|
|
458
|
+
for (let _ = 0; _ < a; _++)
|
|
459
|
+
if (l[_].externalView && !u.querySelector(`.cell[data-col="${_}"] [data-external-view]`)) {
|
|
460
460
|
g = !0;
|
|
461
461
|
break;
|
|
462
462
|
}
|
|
463
463
|
}
|
|
464
464
|
if (!x || g) {
|
|
465
|
-
const
|
|
466
|
-
if (
|
|
467
|
-
u.__isCustomRow && (u.className = "data-grid-row", u.setAttribute("role", "row"), u.__isCustomRow = !1),
|
|
468
|
-
else if (
|
|
465
|
+
const _ = u.querySelector(".cell.editing"), E = t._activeEditRows === p;
|
|
466
|
+
if (_ && !E)
|
|
467
|
+
u.__isCustomRow && (u.className = "data-grid-row", u.setAttribute("role", "row"), u.__isCustomRow = !1), D(t, u, c, p), u.__epoch = i, u.__rowDataRef = c;
|
|
468
|
+
else if (_ && E)
|
|
469
469
|
U(t, u, c, p), u.__rowDataRef = c;
|
|
470
|
-
else if (u.__isCustomRow && (u.className = "data-grid-row", u.setAttribute("role", "row"), u.__isCustomRow = !1),
|
|
470
|
+
else if (u.__isCustomRow && (u.className = "data-grid-row", u.setAttribute("role", "row"), u.__isCustomRow = !1), D(t, u, c, p), u.__epoch = i, u.__rowDataRef = c, E) {
|
|
471
471
|
const S = u.children;
|
|
472
472
|
for (let A = 0; A < S.length; A++) {
|
|
473
|
-
const P = t.
|
|
474
|
-
P && P.editable &&
|
|
473
|
+
const P = t._visibleColumns[A];
|
|
474
|
+
P && P.editable && O(t, c, p, P, S[A]);
|
|
475
475
|
}
|
|
476
476
|
}
|
|
477
|
-
} else if (
|
|
478
|
-
const
|
|
479
|
-
if (
|
|
480
|
-
|
|
481
|
-
else if (U(t, u, c, p), u.__rowDataRef = c,
|
|
477
|
+
} else if (R) {
|
|
478
|
+
const _ = u.querySelector(".cell.editing"), E = t._activeEditRows === p;
|
|
479
|
+
if (_ && !E)
|
|
480
|
+
D(t, u, c, p), u.__epoch = i, u.__rowDataRef = c;
|
|
481
|
+
else if (U(t, u, c, p), u.__rowDataRef = c, E && !_) {
|
|
482
482
|
const S = u.children;
|
|
483
483
|
for (let A = 0; A < S.length; A++) {
|
|
484
|
-
const P = t.
|
|
485
|
-
P && P.editable &&
|
|
484
|
+
const P = t._visibleColumns[A];
|
|
485
|
+
P && P.editable && O(t, c, p, P, S[A]);
|
|
486
486
|
}
|
|
487
487
|
}
|
|
488
488
|
} else {
|
|
489
|
-
const
|
|
490
|
-
if (
|
|
491
|
-
|
|
492
|
-
else if (U(t, u, c, p),
|
|
489
|
+
const _ = u.querySelector(".cell.editing"), E = t._activeEditRows === p;
|
|
490
|
+
if (_ && !E)
|
|
491
|
+
D(t, u, c, p), u.__epoch = i, u.__rowDataRef = c;
|
|
492
|
+
else if (U(t, u, c, p), E && !_) {
|
|
493
493
|
const S = u.children;
|
|
494
494
|
for (let A = 0; A < S.length; A++) {
|
|
495
|
-
const P = t.
|
|
496
|
-
P && P.editable &&
|
|
495
|
+
const P = t._visibleColumns[A];
|
|
496
|
+
P && P.editable && O(t, c, p, P, S[A]);
|
|
497
497
|
}
|
|
498
498
|
}
|
|
499
499
|
}
|
|
500
|
-
const m = t._changedRowIndices.has(p),
|
|
501
|
-
m !==
|
|
500
|
+
const m = t._changedRowIndices.has(p), C = u.classList.contains("changed");
|
|
501
|
+
m !== C && u.classList.toggle("changed", m), u.parentNode !== r && r.appendChild(u);
|
|
502
502
|
}
|
|
503
503
|
}
|
|
504
504
|
function U(t, e, o, i) {
|
|
505
|
-
const n = e.children, s = t.
|
|
505
|
+
const n = e.children, s = t._visibleColumns, r = s.length, l = n.length, a = r < l ? r : l, d = t._focusRow, f = t._focusCol;
|
|
506
506
|
let h = t.__hasSpecialColumns;
|
|
507
507
|
if (h === void 0) {
|
|
508
508
|
h = !1;
|
|
@@ -527,7 +527,7 @@ function U(t, e, o, i) {
|
|
|
527
527
|
}
|
|
528
528
|
for (let c = 0; c < a; c++)
|
|
529
529
|
if (s[c].externalView && !n[c].querySelector("[data-external-view]")) {
|
|
530
|
-
|
|
530
|
+
D(t, e, o, i);
|
|
531
531
|
return;
|
|
532
532
|
}
|
|
533
533
|
for (let c = 0; c < a; c++) {
|
|
@@ -536,41 +536,41 @@ function U(t, e, o, i) {
|
|
|
536
536
|
const w = d === i && f === c, v = b.classList.contains("cell-focus");
|
|
537
537
|
if (w !== v && (b.classList.toggle("cell-focus", w), b.setAttribute("aria-selected", String(w))), b.classList.contains("editing")) continue;
|
|
538
538
|
if (u.viewRenderer) {
|
|
539
|
-
const
|
|
540
|
-
typeof g == "string" ? b.innerHTML = F(g) : g ? (b.innerHTML = "", b.appendChild(g)) : b.textContent =
|
|
539
|
+
const R = o[u.field], g = u.viewRenderer({ row: o, value: R, field: u.field, column: u });
|
|
540
|
+
typeof g == "string" ? b.innerHTML = F(g) : g ? (b.innerHTML = "", b.appendChild(g)) : b.textContent = R == null ? "" : String(R);
|
|
541
541
|
continue;
|
|
542
542
|
}
|
|
543
543
|
if (u.__viewTemplate || u.__compiledView || u.externalView)
|
|
544
544
|
continue;
|
|
545
|
-
const
|
|
545
|
+
const y = o[u.field];
|
|
546
546
|
let x;
|
|
547
547
|
if (u.format)
|
|
548
548
|
try {
|
|
549
|
-
const
|
|
550
|
-
x = _ == null ? "" : String(_);
|
|
551
|
-
} catch {
|
|
549
|
+
const R = u.format(y, o);
|
|
552
550
|
x = R == null ? "" : String(R);
|
|
551
|
+
} catch {
|
|
552
|
+
x = y == null ? "" : String(y);
|
|
553
553
|
}
|
|
554
554
|
else if (u.type === "date") {
|
|
555
|
-
if (
|
|
555
|
+
if (y == null || y === "")
|
|
556
556
|
x = "";
|
|
557
|
-
else if (
|
|
558
|
-
x = isNaN(
|
|
557
|
+
else if (y instanceof Date)
|
|
558
|
+
x = isNaN(y.getTime()) ? "" : y.toLocaleDateString();
|
|
559
559
|
else {
|
|
560
|
-
const
|
|
561
|
-
x = isNaN(
|
|
560
|
+
const R = new Date(y);
|
|
561
|
+
x = isNaN(R.getTime()) ? "" : R.toLocaleDateString();
|
|
562
562
|
}
|
|
563
563
|
b.textContent = x;
|
|
564
564
|
} else if (u.type === "boolean") {
|
|
565
|
-
const
|
|
566
|
-
b.innerHTML = `<span role="checkbox" aria-checked="${
|
|
565
|
+
const R = !!y;
|
|
566
|
+
b.innerHTML = `<span role="checkbox" aria-checked="${R}" aria-label="${R}">${R ? "🗹" : "☐"}</span>`;
|
|
567
567
|
} else
|
|
568
|
-
x =
|
|
568
|
+
x = y == null ? "" : String(y), b.textContent = x;
|
|
569
569
|
}
|
|
570
570
|
}
|
|
571
|
-
function
|
|
571
|
+
function D(t, e, o, i) {
|
|
572
572
|
e.innerHTML = "";
|
|
573
|
-
const n = t.
|
|
573
|
+
const n = t._visibleColumns, s = n.length, r = t._focusRow, l = t._focusCol, a = t.effectiveConfig?.editOn || t.editOn, d = t, f = document.createDocumentFragment();
|
|
574
574
|
for (let h = 0; h < s; h++) {
|
|
575
575
|
const p = n[h], c = document.createElement("div");
|
|
576
576
|
c.className = "cell", j(c, "cell"), c.setAttribute("role", "gridcell"), c.setAttribute("aria-colindex", String(h + 1)), c.setAttribute("data-col", String(h)), c.setAttribute("data-row", String(i)), p.type, p.type && c.setAttribute("data-type", p.type);
|
|
@@ -581,18 +581,18 @@ function N(t, e, o, i) {
|
|
|
581
581
|
u = b(u, o);
|
|
582
582
|
} catch {
|
|
583
583
|
}
|
|
584
|
-
const w = p.__compiledView, v = p.__viewTemplate,
|
|
585
|
-
let
|
|
586
|
-
if (
|
|
587
|
-
const g =
|
|
588
|
-
typeof g == "string" ? (c.innerHTML = F(g),
|
|
584
|
+
const w = p.__compiledView, v = p.__viewTemplate, y = p.viewRenderer, x = p.externalView;
|
|
585
|
+
let R = !1;
|
|
586
|
+
if (y) {
|
|
587
|
+
const g = y({ row: o, value: u, field: p.field, column: p });
|
|
588
|
+
typeof g == "string" ? (c.innerHTML = F(g), R = !0) : g ? c.appendChild(g) : c.textContent = u == null ? "" : String(u);
|
|
589
589
|
} else if (x) {
|
|
590
590
|
const g = x, m = document.createElement("div");
|
|
591
591
|
m.setAttribute("data-external-view", ""), m.setAttribute("data-field", p.field), c.appendChild(m);
|
|
592
|
-
const
|
|
592
|
+
const C = { row: o, value: u, field: p.field, column: p };
|
|
593
593
|
if (g.mount)
|
|
594
594
|
try {
|
|
595
|
-
g.mount({ placeholder: m, context:
|
|
595
|
+
g.mount({ placeholder: m, context: C, spec: g });
|
|
596
596
|
} catch {
|
|
597
597
|
}
|
|
598
598
|
else
|
|
@@ -602,7 +602,7 @@ function N(t, e, o, i) {
|
|
|
602
602
|
new CustomEvent("mount-external-view", {
|
|
603
603
|
bubbles: !0,
|
|
604
604
|
composed: !0,
|
|
605
|
-
detail: { placeholder: m, spec: g, context:
|
|
605
|
+
detail: { placeholder: m, spec: g, context: C }
|
|
606
606
|
})
|
|
607
607
|
);
|
|
608
608
|
} catch {
|
|
@@ -611,10 +611,10 @@ function N(t, e, o, i) {
|
|
|
611
611
|
m.setAttribute("data-mounted", "");
|
|
612
612
|
} else if (w) {
|
|
613
613
|
const g = w({ row: o, value: u, field: p.field, column: p }), m = w.__blocked;
|
|
614
|
-
c.innerHTML = m ? "" : F(g),
|
|
614
|
+
c.innerHTML = m ? "" : F(g), R = !0, m && (c.textContent = "", c.setAttribute("data-blocked-template", ""));
|
|
615
615
|
} else if (v) {
|
|
616
616
|
const g = v.innerHTML;
|
|
617
|
-
/Reflect\.|\bProxy\b|ownKeys\(/.test(g) ? (c.textContent = "", c.setAttribute("data-blocked-template", "")) : (c.innerHTML = F(ue(g, { row: o, value: u })),
|
|
617
|
+
/Reflect\.|\bProxy\b|ownKeys\(/.test(g) ? (c.textContent = "", c.setAttribute("data-blocked-template", "")) : (c.innerHTML = F(ue(g, { row: o, value: u })), R = !0);
|
|
618
618
|
} else if (p.type === "date")
|
|
619
619
|
if (u == null || u === "")
|
|
620
620
|
c.textContent = "";
|
|
@@ -632,7 +632,7 @@ function N(t, e, o, i) {
|
|
|
632
632
|
c.innerHTML = `<span role="checkbox" aria-checked="${g}" aria-label="${g}">${g ? "🗹" : "☐"}</span>`;
|
|
633
633
|
} else
|
|
634
634
|
c.textContent = u == null ? "" : String(u);
|
|
635
|
-
if (
|
|
635
|
+
if (R) {
|
|
636
636
|
Ae(c);
|
|
637
637
|
const g = c.textContent || "";
|
|
638
638
|
/Proxy|Reflect\.ownKeys/.test(g) && (c.textContent = g.replace(/Proxy|Reflect\.ownKeys/g, "").trim(), /Proxy|Reflect\.ownKeys/.test(c.textContent || "") && (c.textContent = ""));
|
|
@@ -640,36 +640,36 @@ function N(t, e, o, i) {
|
|
|
640
640
|
c.hasAttribute("data-blocked-template") && (c.textContent || "").trim().length && (c.textContent = ""), p.editable ? (c.tabIndex = 0, c.addEventListener("mousedown", () => {
|
|
641
641
|
if (c.classList.contains("editing")) return;
|
|
642
642
|
const g = Number(c.getAttribute("data-row")), m = Number(c.getAttribute("data-col"));
|
|
643
|
-
isNaN(g) || isNaN(m) || (t.
|
|
643
|
+
isNaN(g) || isNaN(m) || (t._focusRow = g, t._focusCol = m, z(t));
|
|
644
644
|
}), a === "click" ? c.addEventListener("click", (g) => {
|
|
645
645
|
if (c.classList.contains("editing")) return;
|
|
646
646
|
g.stopPropagation();
|
|
647
|
-
const m = Number(c.getAttribute("data-row")),
|
|
648
|
-
if (isNaN(m) || isNaN(
|
|
649
|
-
const
|
|
650
|
-
!
|
|
647
|
+
const m = Number(c.getAttribute("data-row")), C = Number(c.getAttribute("data-col"));
|
|
648
|
+
if (isNaN(m) || isNaN(C)) return;
|
|
649
|
+
const _ = t._rows[m], E = t._visibleColumns[C];
|
|
650
|
+
!_ || !E || (t._focusRow = m, t._focusCol = C, O(t, _, m, E, c));
|
|
651
651
|
}) : c.addEventListener("dblclick", (g) => {
|
|
652
652
|
g.stopPropagation();
|
|
653
653
|
const m = Number(c.getAttribute("data-row"));
|
|
654
654
|
if (isNaN(m)) return;
|
|
655
|
-
const
|
|
656
|
-
if (!
|
|
657
|
-
B(t, m,
|
|
658
|
-
const
|
|
659
|
-
if (
|
|
660
|
-
const
|
|
661
|
-
for (let S = 0; S <
|
|
662
|
-
const A = t.
|
|
663
|
-
A && A.editable &&
|
|
655
|
+
const C = t._rows[m];
|
|
656
|
+
if (!C) return;
|
|
657
|
+
B(t, m, C);
|
|
658
|
+
const _ = t.findRenderedRowElement?.(m);
|
|
659
|
+
if (_) {
|
|
660
|
+
const E = _.children;
|
|
661
|
+
for (let S = 0; S < E.length; S++) {
|
|
662
|
+
const A = t._visibleColumns[S];
|
|
663
|
+
A && A.editable && O(t, C, m, A, E[S]);
|
|
664
664
|
}
|
|
665
665
|
}
|
|
666
666
|
}), c.addEventListener("keydown", (g) => {
|
|
667
|
-
const m = Number(c.getAttribute("data-row")),
|
|
668
|
-
if (isNaN(m) || isNaN(
|
|
669
|
-
const
|
|
670
|
-
if (!(!
|
|
671
|
-
if ((
|
|
672
|
-
g.preventDefault(), t.
|
|
667
|
+
const m = Number(c.getAttribute("data-row")), C = Number(c.getAttribute("data-col"));
|
|
668
|
+
if (isNaN(m) || isNaN(C)) return;
|
|
669
|
+
const _ = t._rows[m], E = t._visibleColumns[C];
|
|
670
|
+
if (!(!_ || !E)) {
|
|
671
|
+
if ((E.type === "select" || E.type === "typeahead") && !c.classList.contains("editing") && g.key === "Enter") {
|
|
672
|
+
g.preventDefault(), t._activeEditRows !== m && B(t, m, _), O(t, _, m, E, c), setTimeout(() => {
|
|
673
673
|
const S = c.querySelector("select");
|
|
674
674
|
try {
|
|
675
675
|
S?.showPicker?.();
|
|
@@ -679,18 +679,18 @@ function N(t, e, o, i) {
|
|
|
679
679
|
}, 0);
|
|
680
680
|
return;
|
|
681
681
|
}
|
|
682
|
-
if (
|
|
683
|
-
g.preventDefault(), t.
|
|
684
|
-
const S = !E
|
|
685
|
-
|
|
682
|
+
if (E.type === "boolean" && g.key === " " && !c.classList.contains("editing")) {
|
|
683
|
+
g.preventDefault(), t._activeEditRows !== m && B(t, m, _);
|
|
684
|
+
const S = !_[E.field];
|
|
685
|
+
J(t, m, E, S, _), c.innerHTML = `<span role="checkbox" aria-checked="${S}" aria-label="${S}">${S ? "🗹" : "☐"}</span>`;
|
|
686
686
|
return;
|
|
687
687
|
}
|
|
688
688
|
if (g.key === "Enter" && !c.classList.contains("editing")) {
|
|
689
|
-
g.preventDefault(), g.stopPropagation(), t.
|
|
689
|
+
g.preventDefault(), g.stopPropagation(), t._focusRow = m, t._focusCol = C, typeof t.beginBulkEdit == "function" ? t.beginBulkEdit(m) : O(t, _, m, E, c);
|
|
690
690
|
return;
|
|
691
691
|
}
|
|
692
692
|
if (g.key === "F2" && !c.classList.contains("editing")) {
|
|
693
|
-
g.preventDefault(),
|
|
693
|
+
g.preventDefault(), O(t, _, m, E, c);
|
|
694
694
|
return;
|
|
695
695
|
}
|
|
696
696
|
}
|
|
@@ -711,9 +711,9 @@ function oe(t, e, o, i) {
|
|
|
711
711
|
if (l.classList.contains("editing")) return;
|
|
712
712
|
const d = Number(l.getAttribute("data-col"));
|
|
713
713
|
if (!isNaN(d)) {
|
|
714
|
-
if (t.
|
|
714
|
+
if (t._dispatchCellClick?.(e, s, d, l))
|
|
715
715
|
return;
|
|
716
|
-
t.
|
|
716
|
+
t._focusRow = s, t._focusCol = d, z(t);
|
|
717
717
|
}
|
|
718
718
|
}
|
|
719
719
|
if (o.querySelector(".cell.editing")) {
|
|
@@ -725,10 +725,10 @@ function oe(t, e, o, i) {
|
|
|
725
725
|
if (a === "click" || a === "doubleClick" && i) B(t, s, r);
|
|
726
726
|
else return;
|
|
727
727
|
Array.from(o.children).forEach((d, f) => {
|
|
728
|
-
const h = t.
|
|
729
|
-
h && h.editable &&
|
|
728
|
+
const h = t._visibleColumns[f];
|
|
729
|
+
h && h.editable && O(t, r, s, h, d);
|
|
730
730
|
}), l && queueMicrotask(() => {
|
|
731
|
-
const d = o.querySelector(`.cell[data-col="${t.
|
|
731
|
+
const d = o.querySelector(`.cell[data-col="${t._focusCol}"]`);
|
|
732
732
|
if (d?.classList.contains("editing")) {
|
|
733
733
|
const f = d.querySelector(
|
|
734
734
|
'input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])'
|
|
@@ -744,20 +744,20 @@ function Z(t) {
|
|
|
744
744
|
return !(t === "__proto__" || t === "constructor" || t === "prototype");
|
|
745
745
|
}
|
|
746
746
|
function B(t, e, o) {
|
|
747
|
-
t.
|
|
747
|
+
t._activeEditRows !== e && (t._rowEditSnapshots.set(e, { ...o }), t._activeEditRows = e);
|
|
748
748
|
}
|
|
749
749
|
function M(t, e, o) {
|
|
750
|
-
if (t.
|
|
751
|
-
const i = t.
|
|
750
|
+
if (t._activeEditRows !== e) return;
|
|
751
|
+
const i = t._rowEditSnapshots.get(e), n = t._rows[e], s = t.findRenderedRowElement?.(e);
|
|
752
752
|
if (!o && s && n && s.querySelectorAll(".cell.editing").forEach((l) => {
|
|
753
753
|
const a = Number(l.getAttribute("data-col"));
|
|
754
754
|
if (isNaN(a)) return;
|
|
755
|
-
const d = t.
|
|
755
|
+
const d = t._visibleColumns[a];
|
|
756
756
|
if (!d) return;
|
|
757
757
|
const f = l.querySelector("input,textarea,select");
|
|
758
758
|
if (f) {
|
|
759
759
|
let h;
|
|
760
|
-
f instanceof HTMLInputElement && f.type === "checkbox" ? h = f.checked : (h = f.value, d.type === "number" && h !== "" && (h = Number(h))), n[d.field] !== h &&
|
|
760
|
+
f instanceof HTMLInputElement && f.type === "checkbox" ? h = f.checked : (h = f.value, d.type === "number" && h !== "" && (h = Number(h))), n[d.field] !== h && J(t, e, d, h, n);
|
|
761
761
|
}
|
|
762
762
|
}), o && i && n)
|
|
763
763
|
Object.keys(i).forEach((r) => n[r] = i[r]), t._changedRowIndices.delete(e), Y(t);
|
|
@@ -775,11 +775,13 @@ function M(t, e, o) {
|
|
|
775
775
|
})
|
|
776
776
|
);
|
|
777
777
|
}
|
|
778
|
-
t.
|
|
778
|
+
t._rowEditSnapshots.delete(e), t._activeEditRows = -1, s && (D(t, s, t._rows[e], e), t._changedRowIndices.has(e) ? s.classList.add("changed") : s.classList.remove("changed")), queueMicrotask(() => {
|
|
779
779
|
try {
|
|
780
|
-
const r = t.
|
|
780
|
+
const r = t._focusRow, l = t._focusCol, a = t.findRenderedRowElement?.(r);
|
|
781
781
|
if (a) {
|
|
782
|
-
Array.from(t.
|
|
782
|
+
Array.from(t._bodyEl.querySelectorAll(".cell-focus")).forEach(
|
|
783
|
+
(f) => f.classList.remove("cell-focus")
|
|
784
|
+
);
|
|
783
785
|
const d = a.querySelector(`.cell[data-row="${r}"][data-col="${l}"]`);
|
|
784
786
|
d && (d.classList.add("cell-focus"), d.setAttribute("aria-selected", "true"), d.hasAttribute("tabindex") || d.setAttribute("tabindex", "-1"), d.focus({ preventScroll: !0 }));
|
|
785
787
|
}
|
|
@@ -787,7 +789,7 @@ function M(t, e, o) {
|
|
|
787
789
|
}
|
|
788
790
|
});
|
|
789
791
|
}
|
|
790
|
-
function
|
|
792
|
+
function J(t, e, o, i, n) {
|
|
791
793
|
const s = o.field;
|
|
792
794
|
if (!Z(s) || n[s] === i) return;
|
|
793
795
|
n[s] = i;
|
|
@@ -808,13 +810,13 @@ function Q(t, e, o, i, n) {
|
|
|
808
810
|
})
|
|
809
811
|
);
|
|
810
812
|
}
|
|
811
|
-
function
|
|
812
|
-
if (!i.editable || (t.
|
|
813
|
+
function O(t, e, o, i, n) {
|
|
814
|
+
if (!i.editable || (t._activeEditRows !== o && B(t, o, e), n.classList.contains("editing"))) return;
|
|
813
815
|
const s = Z(i.field) ? e[i.field] : void 0;
|
|
814
816
|
n.classList.add("editing");
|
|
815
817
|
let r = !1;
|
|
816
818
|
const l = (c) => {
|
|
817
|
-
r || t.
|
|
819
|
+
r || t._activeEditRows === -1 || J(t, o, i, c, e);
|
|
818
820
|
}, a = () => {
|
|
819
821
|
r = !0, e[i.field] = Z(i.field) ? s : void 0;
|
|
820
822
|
const c = n.querySelector("input,textarea,select");
|
|
@@ -827,8 +829,8 @@ function k(t, e, o, i, n) {
|
|
|
827
829
|
if (h === "template" && f) {
|
|
828
830
|
const c = f.cloneNode(!0), u = i.__compiledEditor;
|
|
829
831
|
u ? c.innerHTML = u({ row: e, value: s, field: i.field, column: i }) : c.querySelectorAll("*").forEach((w) => {
|
|
830
|
-
w.childNodes.length === 1 && w.firstChild?.nodeType === Node.TEXT_NODE && (w.textContent = w.textContent?.replace(/{{\s*value\s*}}/g, s == null ? "" : String(s)).replace(/{{\s*row\.([a-zA-Z0-9_]+)\s*}}/g, (v,
|
|
831
|
-
const x = e[
|
|
832
|
+
w.childNodes.length === 1 && w.firstChild?.nodeType === Node.TEXT_NODE && (w.textContent = w.textContent?.replace(/{{\s*value\s*}}/g, s == null ? "" : String(s)).replace(/{{\s*row\.([a-zA-Z0-9_]+)\s*}}/g, (v, y) => {
|
|
833
|
+
const x = e[y];
|
|
832
834
|
return x == null ? "" : String(x);
|
|
833
835
|
}) || "");
|
|
834
836
|
});
|
|
@@ -841,8 +843,8 @@ function k(t, e, o, i, n) {
|
|
|
841
843
|
}), b.addEventListener("keydown", (v) => {
|
|
842
844
|
if (v.key === "Enter") {
|
|
843
845
|
v.stopPropagation(), v.preventDefault(), r = !0;
|
|
844
|
-
const
|
|
845
|
-
l(
|
|
846
|
+
const y = w && b instanceof HTMLInputElement && b.type === "checkbox" ? b.checked : b.value;
|
|
847
|
+
l(y), M(t, o, !1);
|
|
846
848
|
}
|
|
847
849
|
v.key === "Escape" && (v.stopPropagation(), v.preventDefault(), a(), M(t, o, !0));
|
|
848
850
|
}), w && b instanceof HTMLInputElement && b.type === "checkbox" && b.addEventListener("change", () => {
|
|
@@ -873,26 +875,26 @@ function k(t, e, o, i, n) {
|
|
|
873
875
|
}
|
|
874
876
|
}
|
|
875
877
|
function ne(t, e) {
|
|
876
|
-
!t.
|
|
877
|
-
i.getAttribute("aria-sort") ? (i.getAttribute("aria-sort") === "ascending" || i.getAttribute("aria-sort") === "descending") && (t.
|
|
878
|
+
!t._sortState || t._sortState.field !== e.field ? (t._sortState || (t.__originalOrder = t._rows.slice()), ie(t, e, 1)) : t._sortState.direction === 1 ? ie(t, e, -1) : (t._sortState = null, t.__rowRenderEpoch++, t._rowPool.forEach((i) => i.__epoch = -1), t._rows = t.__originalOrder.slice(), q(t), t._headerRowEl?.querySelectorAll('[role="columnheader"].sortable')?.forEach((i) => {
|
|
879
|
+
i.getAttribute("aria-sort") ? (i.getAttribute("aria-sort") === "ascending" || i.getAttribute("aria-sort") === "descending") && (t._sortState || i.setAttribute("aria-sort", "none")) : i.setAttribute("aria-sort", "none");
|
|
878
880
|
}), t.refreshVirtualWindow(!0), t.dispatchEvent(
|
|
879
881
|
new CustomEvent("sort-change", { detail: { field: e.field, direction: 0 } })
|
|
880
882
|
), t.requestStateChange?.());
|
|
881
883
|
}
|
|
882
884
|
function ie(t, e, o) {
|
|
883
|
-
t.
|
|
885
|
+
t._sortState = { field: e.field, direction: o };
|
|
884
886
|
const i = e.sortComparator || ((n, s) => n == null && s == null ? 0 : n == null ? -1 : s == null || n > s ? 1 : n < s ? -1 : 0);
|
|
885
|
-
t._rows.sort((n, s) => i(n[e.field], s[e.field], n, s) * o), t.__rowRenderEpoch++, t.
|
|
887
|
+
t._rows.sort((n, s) => i(n[e.field], s[e.field], n, s) * o), t.__rowRenderEpoch++, t._rowPool.forEach((n) => n.__epoch = -1), q(t), t.refreshVirtualWindow(!0), t.dispatchEvent(
|
|
886
888
|
new CustomEvent("sort-change", { detail: { field: e.field, direction: o } })
|
|
887
889
|
), t.requestStateChange?.();
|
|
888
890
|
}
|
|
889
|
-
function
|
|
891
|
+
function Ne(t, e) {
|
|
890
892
|
typeof e == "string" ? t.textContent = e : e instanceof HTMLElement && (t.innerHTML = "", t.appendChild(e.cloneNode(!0)));
|
|
891
893
|
}
|
|
892
894
|
function q(t) {
|
|
893
|
-
t.
|
|
894
|
-
const e = t.
|
|
895
|
-
e.innerHTML = "", t.
|
|
895
|
+
t._headerRowEl = t.findHeaderRow();
|
|
896
|
+
const e = t._headerRowEl;
|
|
897
|
+
e.innerHTML = "", t._visibleColumns.forEach((o, i) => {
|
|
896
898
|
const n = document.createElement("div");
|
|
897
899
|
n.className = "cell", j(n, "header-cell"), n.setAttribute("role", "columnheader"), n.setAttribute("aria-colindex", String(i + 1)), n.setAttribute("data-field", o.field), n.setAttribute("data-col", String(i));
|
|
898
900
|
const s = o.__headerTemplate;
|
|
@@ -905,12 +907,12 @@ function q(t) {
|
|
|
905
907
|
n.classList.add("sortable"), n.tabIndex = 0;
|
|
906
908
|
const r = document.createElement("span");
|
|
907
909
|
j(r, "sort-indicator"), r.style.opacity = "0.6";
|
|
908
|
-
const l = t.
|
|
909
|
-
|
|
910
|
-
t.
|
|
910
|
+
const l = t._sortState?.field === o.field ? t._sortState.direction : 0, a = { ...H, ...t.icons }, d = l === 1 ? a.sortAsc : l === -1 ? a.sortDesc : a.sortNone;
|
|
911
|
+
Ne(r, d), n.appendChild(r), n.setAttribute("aria-sort", l === 0 ? "none" : l === 1 ? "ascending" : "descending"), n.addEventListener("click", (f) => {
|
|
912
|
+
t._resizeController?.isResizing || t._dispatchHeaderClick?.(f, i, n) || ne(t, o);
|
|
911
913
|
}), n.addEventListener("keydown", (f) => {
|
|
912
914
|
if (f.key === "Enter" || f.key === " ") {
|
|
913
|
-
if (f.preventDefault(), t.
|
|
915
|
+
if (f.preventDefault(), t._dispatchHeaderClick?.(f, i, n)) return;
|
|
914
916
|
ne(t, o);
|
|
915
917
|
}
|
|
916
918
|
});
|
|
@@ -919,7 +921,7 @@ function q(t) {
|
|
|
919
921
|
n.style.position = "relative";
|
|
920
922
|
const r = document.createElement("div");
|
|
921
923
|
r.className = "resize-handle", r.setAttribute("aria-hidden", "true"), r.addEventListener("mousedown", (l) => {
|
|
922
|
-
l.stopPropagation(), l.preventDefault(), t.
|
|
924
|
+
l.stopPropagation(), l.preventDefault(), t._resizeController.start(l, i, n);
|
|
923
925
|
}), n.appendChild(r);
|
|
924
926
|
}
|
|
925
927
|
e.appendChild(n);
|
|
@@ -927,11 +929,11 @@ function q(t) {
|
|
|
927
929
|
o.getAttribute("aria-sort") || o.setAttribute("aria-sort", "none");
|
|
928
930
|
}), e.children.length > 0 ? (e.setAttribute("role", "row"), e.setAttribute("aria-rowindex", "1")) : (e.removeAttribute("role"), e.removeAttribute("aria-rowindex"));
|
|
929
931
|
}
|
|
930
|
-
function
|
|
932
|
+
function De(t) {
|
|
931
933
|
let e = null, o = null, i = null, n = null;
|
|
932
934
|
const s = (a) => {
|
|
933
935
|
if (!e) return;
|
|
934
|
-
const d = a.clientX - e.startX, f = Math.max(40, e.startWidth + d), h = t.
|
|
936
|
+
const d = a.clientX - e.startX, f = Math.max(40, e.startWidth + d), h = t._visibleColumns[e.colIndex];
|
|
935
937
|
h.width = f, h.__userResized = !0, h.__renderedWidth = f, o == null && (o = requestAnimationFrame(() => {
|
|
936
938
|
o = null, t.updateTemplate?.();
|
|
937
939
|
})), t.dispatchEvent(
|
|
@@ -1668,7 +1670,11 @@ class Ye {
|
|
|
1668
1670
|
class W extends HTMLElement {
|
|
1669
1671
|
// TODO: Rename to 'data-grid' when migration is complete
|
|
1670
1672
|
static tagName = "tbw-grid";
|
|
1671
|
-
static version = "0.2.
|
|
1673
|
+
static version = "0.2.4";
|
|
1674
|
+
// ---------------- Observed Attributes ----------------
|
|
1675
|
+
static get observedAttributes() {
|
|
1676
|
+
return ["rows", "columns", "grid-config", "fit-mode", "edit-on"];
|
|
1677
|
+
}
|
|
1672
1678
|
#o;
|
|
1673
1679
|
#A = !1;
|
|
1674
1680
|
// ---------------- Ready Promise ----------------
|
|
@@ -1695,11 +1701,11 @@ class W extends HTMLElement {
|
|
|
1695
1701
|
// Cached flag for plugin scroll handlers
|
|
1696
1702
|
#T;
|
|
1697
1703
|
// Cached hook to avoid closures
|
|
1698
|
-
#
|
|
1704
|
+
#_ = !1;
|
|
1705
|
+
#E = null;
|
|
1699
1706
|
#C = null;
|
|
1700
1707
|
#y = null;
|
|
1701
1708
|
#R = null;
|
|
1702
|
-
#_ = null;
|
|
1703
1709
|
#a;
|
|
1704
1710
|
#b;
|
|
1705
1711
|
// ---------------- Plugin System ----------------
|
|
@@ -1729,44 +1735,45 @@ class W extends HTMLElement {
|
|
|
1729
1735
|
}
|
|
1730
1736
|
// visibleColumns returns only visible columns for rendering
|
|
1731
1737
|
// This is what header/row rendering should use
|
|
1732
|
-
get
|
|
1738
|
+
get _visibleColumns() {
|
|
1733
1739
|
return this._columns.filter((e) => !e.hidden);
|
|
1734
1740
|
}
|
|
1735
1741
|
// #endregion
|
|
1736
|
-
// #region Runtime State
|
|
1737
|
-
//
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
__lightDomColumnsCache;
|
|
1745
|
-
__originalColumnNodes;
|
|
1746
|
-
headerRowEl;
|
|
1747
|
-
bodyEl;
|
|
1748
|
-
virtualization = {
|
|
1742
|
+
// #region Runtime State (Plugin-accessible)
|
|
1743
|
+
// DOM references
|
|
1744
|
+
_headerRowEl;
|
|
1745
|
+
_bodyEl;
|
|
1746
|
+
_rowPool = [];
|
|
1747
|
+
_resizeController;
|
|
1748
|
+
// Virtualization & scroll state
|
|
1749
|
+
_virtualization = {
|
|
1749
1750
|
enabled: !0,
|
|
1750
1751
|
rowHeight: 28,
|
|
1751
|
-
// Initial state - will recalculate after first render
|
|
1752
1752
|
bypassThreshold: 24,
|
|
1753
|
-
// Skip virtualization if <= this many rows (saves overhead)
|
|
1754
1753
|
start: 0,
|
|
1755
1754
|
end: 0,
|
|
1756
1755
|
container: null,
|
|
1757
|
-
// Faux scrollbar element
|
|
1758
1756
|
viewportEl: null,
|
|
1759
|
-
// Rows viewport for measuring visible height
|
|
1760
1757
|
totalHeightEl: null
|
|
1761
|
-
// Spacer for virtual height
|
|
1762
1758
|
};
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1759
|
+
// Focus & navigation
|
|
1760
|
+
_focusRow = 0;
|
|
1761
|
+
_focusCol = 0;
|
|
1762
|
+
// Sort state
|
|
1763
|
+
_sortState = null;
|
|
1764
|
+
// Edit state
|
|
1765
|
+
_activeEditRows = -1;
|
|
1766
|
+
_rowEditSnapshots = /* @__PURE__ */ new Map();
|
|
1769
1767
|
_changedRowIndices = /* @__PURE__ */ new Set();
|
|
1768
|
+
// Layout
|
|
1769
|
+
_gridTemplate = "";
|
|
1770
|
+
// #endregion
|
|
1771
|
+
// #region Implementation Details (Internal only)
|
|
1772
|
+
__rowRenderEpoch = 0;
|
|
1773
|
+
__didInitialAutoSize = !1;
|
|
1774
|
+
__lightDomColumnsCache;
|
|
1775
|
+
__originalColumnNodes;
|
|
1776
|
+
__originalOrder = [];
|
|
1770
1777
|
// #endregion
|
|
1771
1778
|
// ---------------- Public API Props (getters/setters) ----------------
|
|
1772
1779
|
// Getters return the EFFECTIVE value (after merging), not the raw input.
|
|
@@ -1814,9 +1821,12 @@ class W extends HTMLElement {
|
|
|
1814
1821
|
const o = this.#g;
|
|
1815
1822
|
this.#g = e, o !== e && this.#X();
|
|
1816
1823
|
}
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1824
|
+
/**
|
|
1825
|
+
* Effective config accessor for internal modules and plugins.
|
|
1826
|
+
* Returns the merged config (single source of truth) before plugin processing.
|
|
1827
|
+
* Use this when you need the raw merged config (e.g., for column definitions including hidden).
|
|
1828
|
+
* @internal Plugin API
|
|
1829
|
+
*/
|
|
1820
1830
|
get effectiveConfig() {
|
|
1821
1831
|
return this.#t;
|
|
1822
1832
|
}
|
|
@@ -1824,6 +1834,7 @@ class W extends HTMLElement {
|
|
|
1824
1834
|
* Get the disconnect signal for event listener cleanup.
|
|
1825
1835
|
* This signal is aborted when the grid disconnects from the DOM.
|
|
1826
1836
|
* Plugins and internal code can use this for automatic listener cleanup.
|
|
1837
|
+
* @internal Plugin API
|
|
1827
1838
|
* @example
|
|
1828
1839
|
* element.addEventListener('click', handler, { signal: this.grid.disconnectSignal });
|
|
1829
1840
|
*/
|
|
@@ -1850,6 +1861,7 @@ class W extends HTMLElement {
|
|
|
1850
1861
|
/**
|
|
1851
1862
|
* Get a plugin instance by its class.
|
|
1852
1863
|
* Used by plugins for inter-plugin communication.
|
|
1864
|
+
* @internal Plugin API
|
|
1853
1865
|
*/
|
|
1854
1866
|
getPlugin(e) {
|
|
1855
1867
|
return this.#e?.getPlugin(e);
|
|
@@ -1857,6 +1869,7 @@ class W extends HTMLElement {
|
|
|
1857
1869
|
/**
|
|
1858
1870
|
* Get a plugin instance by its name.
|
|
1859
1871
|
* Used for loose coupling between plugins (avoids static imports).
|
|
1872
|
+
* @internal Plugin API
|
|
1860
1873
|
*/
|
|
1861
1874
|
getPluginByName(e) {
|
|
1862
1875
|
return this.#e?.getPluginByName(e);
|
|
@@ -1865,14 +1878,16 @@ class W extends HTMLElement {
|
|
|
1865
1878
|
* Request a full re-render of the grid.
|
|
1866
1879
|
* Called by plugins when they need the grid to update.
|
|
1867
1880
|
* Note: This does NOT reset plugin state - just re-processes rows/columns and renders.
|
|
1881
|
+
* @internal Plugin API
|
|
1868
1882
|
*/
|
|
1869
1883
|
requestRender() {
|
|
1870
|
-
this.#x(), this.#H(), q(this),
|
|
1884
|
+
this.#x(), this.#H(), q(this), N(this), this.refreshVirtualWindow(!0);
|
|
1871
1885
|
}
|
|
1872
1886
|
/**
|
|
1873
1887
|
* Request a lightweight style update without rebuilding DOM.
|
|
1874
1888
|
* Called by plugins when they only need to update CSS classes/styles.
|
|
1875
1889
|
* This runs all plugin afterRender hooks without rebuilding row/column DOM.
|
|
1890
|
+
* @internal Plugin API
|
|
1876
1891
|
*/
|
|
1877
1892
|
requestAfterRender() {
|
|
1878
1893
|
this.#e?.afterRender();
|
|
@@ -1881,7 +1896,7 @@ class W extends HTMLElement {
|
|
|
1881
1896
|
* Initialize plugin system with instances from config.
|
|
1882
1897
|
* Plugins are class instances passed in gridConfig.plugins[].
|
|
1883
1898
|
*/
|
|
1884
|
-
#
|
|
1899
|
+
#N() {
|
|
1885
1900
|
this.#e = new Ye(this);
|
|
1886
1901
|
const e = this.#t?.plugins, o = Array.isArray(e) ? e : [];
|
|
1887
1902
|
this.#e.attachAll(o);
|
|
@@ -1890,7 +1905,7 @@ class W extends HTMLElement {
|
|
|
1890
1905
|
* Inject all plugin styles into the shadow DOM.
|
|
1891
1906
|
* Must be called after #render() since innerHTML wipes existing content.
|
|
1892
1907
|
*/
|
|
1893
|
-
#
|
|
1908
|
+
#D() {
|
|
1894
1909
|
const e = this.#e?.getAllStyles() ?? "";
|
|
1895
1910
|
if (e) {
|
|
1896
1911
|
const o = document.createElement("style");
|
|
@@ -1902,7 +1917,7 @@ class W extends HTMLElement {
|
|
|
1902
1917
|
* With class-based plugins, we need to detach old and attach new.
|
|
1903
1918
|
*/
|
|
1904
1919
|
#q() {
|
|
1905
|
-
this.#e && this.#e.detachAll(), this.#
|
|
1920
|
+
this.#e && this.#e.detachAll(), this.#N(), this.#D(), this.#v = this.#e?.getAll().some((e) => e.onScroll) ?? !1;
|
|
1906
1921
|
}
|
|
1907
1922
|
/**
|
|
1908
1923
|
* Clean up plugin states when grid disconnects.
|
|
@@ -1925,42 +1940,66 @@ class W extends HTMLElement {
|
|
|
1925
1940
|
}
|
|
1926
1941
|
// ---------------- Lifecycle ----------------
|
|
1927
1942
|
connectedCallback() {
|
|
1928
|
-
this.hasAttribute("tabindex") || (this.tabIndex = 0), this.hasAttribute("version") || this.setAttribute("version", W.version), this._rows = Array.isArray(this.#r) ? [...this.#r] : [], this.#a?.abort(), this.#a = new AbortController(), this.#u(), this.#
|
|
1943
|
+
this.hasAttribute("tabindex") || (this.tabIndex = 0), this.hasAttribute("version") || this.setAttribute("version", W.version), this._rows = Array.isArray(this.#r) ? [...this.#r] : [], this.#a?.abort(), this.#a = new AbortController(), this.#u(), this.#N(), this.#G(), this.#A || (this.#$(), this.#D(), this.#A = !0), this.#B();
|
|
1929
1944
|
}
|
|
1930
1945
|
disconnectedCallback() {
|
|
1931
|
-
this.#V(), Xe(this.#i), this.#n.setInitialized(!1), this.#S?.(), this.#S = void 0, this.#a && (this.#a.abort(), this.#a = void 0), this.
|
|
1946
|
+
this.#V(), Xe(this.#i), this.#n.setInitialized(!1), this.#S?.(), this.#S = void 0, this.#a && (this.#a.abort(), this.#a = void 0), this._resizeController && this._resizeController.dispose(), this.#b && (this.#b.disconnect(), this.#b = void 0), this.#h = !1;
|
|
1947
|
+
}
|
|
1948
|
+
/**
|
|
1949
|
+
* Handle HTML attribute changes.
|
|
1950
|
+
* Only processes attribute values when SET (non-null).
|
|
1951
|
+
* Removing an attribute does NOT clear JS-set properties.
|
|
1952
|
+
*/
|
|
1953
|
+
attributeChangedCallback(e, o, i) {
|
|
1954
|
+
if (o === i || !i || i === "null" || i === "undefined") return;
|
|
1955
|
+
const s = {
|
|
1956
|
+
rows: "rows",
|
|
1957
|
+
columns: "columns",
|
|
1958
|
+
"grid-config": "gridConfig",
|
|
1959
|
+
"fit-mode": "fitMode",
|
|
1960
|
+
"edit-on": "editOn"
|
|
1961
|
+
}[e];
|
|
1962
|
+
if (s)
|
|
1963
|
+
if (e === "rows" || e === "columns" || e === "grid-config")
|
|
1964
|
+
try {
|
|
1965
|
+
this[s] = JSON.parse(i);
|
|
1966
|
+
} catch {
|
|
1967
|
+
console.warn(`[tbw-grid] Invalid JSON for '${e}' attribute:`, i);
|
|
1968
|
+
}
|
|
1969
|
+
else
|
|
1970
|
+
this[s] = i;
|
|
1932
1971
|
}
|
|
1933
1972
|
#B() {
|
|
1934
1973
|
const o = this.#o.querySelector(".tbw-grid-content") ?? this.#o.querySelector(".tbw-grid-root");
|
|
1935
|
-
if (this.
|
|
1974
|
+
if (this._headerRowEl = o?.querySelector(".header-row"), this._virtualization.totalHeightEl = o?.querySelector(".faux-vscroll-spacer"), this._virtualization.viewportEl = o?.querySelector(".rows-viewport"), this._bodyEl = o?.querySelector(".rows"), this.#n.isInitialized) {
|
|
1936
1975
|
he(this.#o, this.#i), Ge(this.#o, this.#t?.shell, this.#i);
|
|
1937
1976
|
const l = this.#t?.shell?.toolPanel?.defaultOpen;
|
|
1938
1977
|
l && this.#i.toolPanels.has(l) && (this.openToolPanel(), this.#i.expandedSections.add(l));
|
|
1939
1978
|
}
|
|
1940
1979
|
this.setAttribute("data-upgraded", ""), this.#h = !0;
|
|
1941
1980
|
const i = this.disconnectSignal;
|
|
1942
|
-
this.#c(), this.addEventListener("keydown", (l) =>
|
|
1981
|
+
this.#c(), this.addEventListener("keydown", (l) => Oe(this, l), { signal: i }), document.addEventListener(
|
|
1943
1982
|
"keydown",
|
|
1944
1983
|
(l) => {
|
|
1945
|
-
l.key === "Escape" && this.
|
|
1984
|
+
l.key === "Escape" && this._activeEditRows !== -1 && M(this, this._activeEditRows, !0);
|
|
1946
1985
|
},
|
|
1947
1986
|
{ capture: !0, signal: i }
|
|
1948
1987
|
), document.addEventListener(
|
|
1949
1988
|
"mousedown",
|
|
1950
1989
|
(l) => {
|
|
1951
|
-
if (this.
|
|
1952
|
-
const a = this.findRenderedRowElement(this.
|
|
1953
|
-
!a || (l.composedPath && l.composedPath() || []).includes(a) || M(this, this.
|
|
1990
|
+
if (this._activeEditRows === -1) return;
|
|
1991
|
+
const a = this.findRenderedRowElement(this._activeEditRows);
|
|
1992
|
+
!a || (l.composedPath && l.composedPath() || []).includes(a) || M(this, this._activeEditRows, !1);
|
|
1954
1993
|
},
|
|
1955
1994
|
{ signal: i }
|
|
1956
1995
|
);
|
|
1957
1996
|
const n = o?.querySelector(".faux-vscroll"), s = o?.querySelector(".rows");
|
|
1958
|
-
if (this.
|
|
1997
|
+
if (this._virtualization.container = n ?? this, this.#v = this.#e?.getAll().some((l) => l.onScroll) ?? !1, n && s) {
|
|
1959
1998
|
n.addEventListener(
|
|
1960
1999
|
"scroll",
|
|
1961
2000
|
() => {
|
|
1962
|
-
if (!this.
|
|
1963
|
-
const d = n.scrollTop, f = this.
|
|
2001
|
+
if (!this._virtualization.enabled && !this.#v) return;
|
|
2002
|
+
const d = n.scrollTop, f = this._virtualization.rowHeight, h = Math.floor(d / f), p = h - h % 2, c = -(d - p * f);
|
|
1964
2003
|
s.style.transform = `translateY(${c}px)`, this.#m = d, this.#f || (this.#f = requestAnimationFrame(() => {
|
|
1965
2004
|
this.#f = 0, this.#m !== null && (this.#Z(this.#m), this.#m = null);
|
|
1966
2005
|
}));
|
|
@@ -1977,65 +2016,65 @@ class W extends HTMLElement {
|
|
|
1977
2016
|
), l.addEventListener(
|
|
1978
2017
|
"touchstart",
|
|
1979
2018
|
(d) => {
|
|
1980
|
-
d.touches.length === 1 && (this.#
|
|
2019
|
+
d.touches.length === 1 && (this.#E = d.touches[0].clientY, this.#C = d.touches[0].clientX, this.#y = n.scrollTop, this.#R = a?.scrollLeft ?? 0);
|
|
1981
2020
|
},
|
|
1982
2021
|
{ passive: !0, signal: i }
|
|
1983
2022
|
), l.addEventListener(
|
|
1984
2023
|
"touchmove",
|
|
1985
2024
|
(d) => {
|
|
1986
|
-
if (d.touches.length === 1 && this.#
|
|
1987
|
-
const f = this.#
|
|
1988
|
-
n.scrollTop = this.#
|
|
2025
|
+
if (d.touches.length === 1 && this.#E !== null && this.#C !== null && this.#y !== null && this.#R !== null) {
|
|
2026
|
+
const f = this.#E - d.touches[0].clientY, h = this.#C - d.touches[0].clientX;
|
|
2027
|
+
n.scrollTop = this.#y + f, a && (a.scrollLeft = this.#R + h), d.preventDefault();
|
|
1989
2028
|
}
|
|
1990
2029
|
},
|
|
1991
2030
|
{ passive: !1, signal: i }
|
|
1992
2031
|
), l.addEventListener(
|
|
1993
2032
|
"touchend",
|
|
1994
2033
|
() => {
|
|
1995
|
-
this.#
|
|
2034
|
+
this.#E = null, this.#C = null, this.#y = null, this.#R = null;
|
|
1996
2035
|
},
|
|
1997
2036
|
{ passive: !0, signal: i }
|
|
1998
2037
|
));
|
|
1999
2038
|
}
|
|
2000
|
-
this.
|
|
2039
|
+
this._resizeController = De(this), this.#o.addEventListener("mousedown", (l) => this.#J(l), { signal: i }), document.addEventListener("mousemove", (l) => this.#Q(l), { signal: i }), document.addEventListener("mouseup", (l) => this.#ee(l), { signal: i }), this._virtualization.enabled && requestAnimationFrame(() => this.refreshVirtualWindow(!0));
|
|
2001
2040
|
const r = this.#t.rowHeight;
|
|
2002
|
-
r && r > 0 ? this.
|
|
2003
|
-
const l = this.
|
|
2041
|
+
r && r > 0 ? this._virtualization.rowHeight = r : requestAnimationFrame(() => {
|
|
2042
|
+
const l = this._bodyEl?.querySelector(".data-grid-row");
|
|
2004
2043
|
if (l) {
|
|
2005
2044
|
const a = l.getBoundingClientRect().height;
|
|
2006
|
-
a > 0 && (this.
|
|
2045
|
+
a > 0 && (this._virtualization.rowHeight = a, this.refreshVirtualWindow(!0));
|
|
2007
2046
|
}
|
|
2008
|
-
}), this.
|
|
2047
|
+
}), this._virtualization.viewportEl && (this.#b = new ResizeObserver(() => {
|
|
2009
2048
|
this.#f || (this.#f = requestAnimationFrame(() => {
|
|
2010
2049
|
this.#f = 0, this.refreshVirtualWindow(!0), z(this);
|
|
2011
2050
|
}));
|
|
2012
|
-
}), this.#b.observe(this.
|
|
2051
|
+
}), this.#b.observe(this._virtualization.viewportEl)), queueMicrotask(() => this.#F()), requestAnimationFrame(() => requestAnimationFrame(() => this.#M?.()));
|
|
2013
2052
|
}
|
|
2014
2053
|
// ---------------- Event Emitters ----------------
|
|
2015
2054
|
#s(e, o) {
|
|
2016
2055
|
this.dispatchEvent(new CustomEvent(e, { detail: o, bubbles: !0, composed: !0 }));
|
|
2017
2056
|
}
|
|
2018
|
-
|
|
2057
|
+
_emitCellCommit(e) {
|
|
2019
2058
|
this.#s("cell-commit", e);
|
|
2020
2059
|
}
|
|
2021
|
-
|
|
2060
|
+
_emitRowCommit(e) {
|
|
2022
2061
|
this.#s("row-commit", e);
|
|
2023
2062
|
}
|
|
2024
|
-
|
|
2063
|
+
_emitSortChange(e) {
|
|
2025
2064
|
this.#s("sort-change", e);
|
|
2026
2065
|
}
|
|
2027
|
-
|
|
2066
|
+
_emitColumnResize(e) {
|
|
2028
2067
|
this.#s("column-resize", e);
|
|
2029
2068
|
}
|
|
2030
|
-
|
|
2069
|
+
_emitActivateCell(e) {
|
|
2031
2070
|
this.#s("activate-cell", e);
|
|
2032
2071
|
}
|
|
2033
2072
|
/** Update ARIA selection attributes on rendered rows/cells */
|
|
2034
2073
|
#F() {
|
|
2035
|
-
this.
|
|
2036
|
-
const n = i === this.
|
|
2074
|
+
this._bodyEl?.querySelectorAll(".data-grid-row")?.forEach((o, i) => {
|
|
2075
|
+
const n = i === this._focusRow;
|
|
2037
2076
|
o.setAttribute("aria-selected", String(n)), o.querySelectorAll(".cell").forEach((s, r) => {
|
|
2038
|
-
s.setAttribute("aria-selected", String(n && r === this.
|
|
2077
|
+
s.setAttribute("aria-selected", String(n && r === this._focusCol));
|
|
2039
2078
|
});
|
|
2040
2079
|
});
|
|
2041
2080
|
}
|
|
@@ -2044,10 +2083,10 @@ class W extends HTMLElement {
|
|
|
2044
2083
|
if (!this.#h) return;
|
|
2045
2084
|
this.#u(), this.#t.fitMode === "fixed" ? (this.__didInitialAutoSize = !1, te(this)) : (this._columns.forEach((o) => {
|
|
2046
2085
|
!o.__userResized && o.__autoSized && delete o.width;
|
|
2047
|
-
}),
|
|
2086
|
+
}), N(this));
|
|
2048
2087
|
}
|
|
2049
2088
|
#X() {
|
|
2050
|
-
this.#h && (this.#u(), this.
|
|
2089
|
+
this.#h && (this.#u(), this._rowPool.length = 0, this._bodyEl && (this._bodyEl.innerHTML = ""), this.__rowRenderEpoch++, this.refreshVirtualWindow(!0));
|
|
2051
2090
|
}
|
|
2052
2091
|
#K() {
|
|
2053
2092
|
this._rows = Array.isArray(this.#r) ? [...this.#r] : [], this.#x(), !this.#l || Array.isArray(this.#l) && this.#l.length === 0 ? this.#c() : this.refreshVirtualWindow(!0);
|
|
@@ -2056,7 +2095,7 @@ class W extends HTMLElement {
|
|
|
2056
2095
|
Y(this), this.#h && (this.#u(), this.#c());
|
|
2057
2096
|
}
|
|
2058
2097
|
#Y() {
|
|
2059
|
-
this.#h && (this.#u(), this.#q(), this.#x(), this.#H(), q(this),
|
|
2098
|
+
this.#h && (this.#u(), this.#q(), this.#x(), this.#H(), q(this), N(this), this.refreshVirtualWindow(!0));
|
|
2060
2099
|
}
|
|
2061
2100
|
#H() {
|
|
2062
2101
|
if (this.#e) {
|
|
@@ -2124,17 +2163,17 @@ class W extends HTMLElement {
|
|
|
2124
2163
|
const n = this.#t.columns;
|
|
2125
2164
|
n?.some((s) => s.__compiledView || s.__compiledEditor) && (e.columns = n);
|
|
2126
2165
|
}
|
|
2127
|
-
this.#w && (e.fitMode = this.#w), e.fitMode || (e.fitMode = "stretch"), this.#g && (e.editOn = this.#g), e.rowHeight && e.rowHeight > 0 && (this.
|
|
2166
|
+
this.#w && (e.fitMode = this.#w), e.fitMode || (e.fitMode = "stretch"), this.#g && (e.editOn = this.#g), e.rowHeight && e.rowHeight > 0 && (this._virtualization.rowHeight = e.rowHeight), e.columnState && !this.#d && (this.#d = e.columnState), this.#t = e, e.fitMode === "fixed" && this._columns.forEach((n) => {
|
|
2128
2167
|
n.width == null && (n.width = 80);
|
|
2129
2168
|
});
|
|
2130
2169
|
}
|
|
2131
2170
|
// ---------------- Delegate Wrappers ----------------
|
|
2132
|
-
#
|
|
2171
|
+
#O(e, o, i = this.__rowRenderEpoch) {
|
|
2133
2172
|
this.#T || (this.#T = (n, s, r) => this.#e?.renderRow(n, s, r) ?? !1), Me(this, e, o, i, this.#T);
|
|
2134
2173
|
}
|
|
2135
2174
|
// ---------------- Core Helpers ----------------
|
|
2136
2175
|
#c() {
|
|
2137
|
-
if (!this.isConnected || !this.
|
|
2176
|
+
if (!this.isConnected || !this._headerRowEl || !this._bodyEl)
|
|
2138
2177
|
return;
|
|
2139
2178
|
const e = this.#p?.columns || this.#l || [];
|
|
2140
2179
|
if (e.length) {
|
|
@@ -2148,7 +2187,7 @@ class W extends HTMLElement {
|
|
|
2148
2187
|
const i = this.#d;
|
|
2149
2188
|
this.#d = void 0, this.#I(i);
|
|
2150
2189
|
}
|
|
2151
|
-
q(this),
|
|
2190
|
+
q(this), N(this), this.refreshVirtualWindow(!0), this.#t.fitMode === "fixed" && !this.__didInitialAutoSize && requestAnimationFrame(() => te(this)), this._bodyEl && (this._bodyEl.style.display = "", this._bodyEl.style.gridTemplateColumns = ""), queueMicrotask(() => this.#e?.afterRender());
|
|
2152
2191
|
}
|
|
2153
2192
|
/** Internal method to apply column state without triggering setup loop */
|
|
2154
2193
|
#I(e) {
|
|
@@ -2161,7 +2200,7 @@ class W extends HTMLElement {
|
|
|
2161
2200
|
}
|
|
2162
2201
|
#Z(e) {
|
|
2163
2202
|
if (this.refreshVirtualWindow(!1), this.#e?.onScrollRender(), this.#v) {
|
|
2164
|
-
const o = this.
|
|
2203
|
+
const o = this._virtualization.container, i = {
|
|
2165
2204
|
scrollTop: e,
|
|
2166
2205
|
scrollLeft: o?.scrollLeft ?? 0,
|
|
2167
2206
|
scrollHeight: o?.scrollHeight ?? 0,
|
|
@@ -2173,11 +2212,23 @@ class W extends HTMLElement {
|
|
|
2173
2212
|
this.#e?.onScroll(i);
|
|
2174
2213
|
}
|
|
2175
2214
|
}
|
|
2215
|
+
/**
|
|
2216
|
+
* Find the header row element in the shadow DOM.
|
|
2217
|
+
* Used by plugins that need to access header cells for styling or measurement.
|
|
2218
|
+
* @internal Plugin API
|
|
2219
|
+
*/
|
|
2176
2220
|
findHeaderRow() {
|
|
2177
2221
|
return this.#o.querySelector(".header-row");
|
|
2178
2222
|
}
|
|
2223
|
+
/**
|
|
2224
|
+
* Find a rendered row element by its data row index.
|
|
2225
|
+
* Returns null if the row is not currently rendered (virtualized out of view).
|
|
2226
|
+
* Used by plugins that need to access specific row elements for styling or measurement.
|
|
2227
|
+
* @internal Plugin API
|
|
2228
|
+
* @param rowIndex - The data row index (not the DOM position)
|
|
2229
|
+
*/
|
|
2179
2230
|
findRenderedRowElement(e) {
|
|
2180
|
-
return Array.from(this.
|
|
2231
|
+
return Array.from(this._bodyEl.querySelectorAll(".data-grid-row")).find((o) => {
|
|
2181
2232
|
const i = o.querySelector(".cell[data-row]");
|
|
2182
2233
|
return i && Number(i.getAttribute("data-row")) === e;
|
|
2183
2234
|
}) || null;
|
|
@@ -2186,7 +2237,7 @@ class W extends HTMLElement {
|
|
|
2186
2237
|
* Dispatch a cell click event to the plugin system.
|
|
2187
2238
|
* Returns true if any plugin handled the event.
|
|
2188
2239
|
*/
|
|
2189
|
-
|
|
2240
|
+
_dispatchCellClick(e, o, i, n) {
|
|
2190
2241
|
const s = this._rows[o], r = this._columns[i];
|
|
2191
2242
|
if (!s || !r) return !1;
|
|
2192
2243
|
const l = {
|
|
@@ -2204,7 +2255,7 @@ class W extends HTMLElement {
|
|
|
2204
2255
|
* Dispatch a header click event to the plugin system.
|
|
2205
2256
|
* Returns true if any plugin handled the event.
|
|
2206
2257
|
*/
|
|
2207
|
-
|
|
2258
|
+
_dispatchHeaderClick(e, o, i) {
|
|
2208
2259
|
const n = this._columns[o];
|
|
2209
2260
|
if (!n) return !1;
|
|
2210
2261
|
const s = {
|
|
@@ -2220,7 +2271,7 @@ class W extends HTMLElement {
|
|
|
2220
2271
|
* Dispatch a keyboard event to the plugin system.
|
|
2221
2272
|
* Returns true if any plugin handled the event.
|
|
2222
2273
|
*/
|
|
2223
|
-
|
|
2274
|
+
_dispatchKeyDown(e) {
|
|
2224
2275
|
return this.#e?.onKeyDown(e) ?? !1;
|
|
2225
2276
|
}
|
|
2226
2277
|
/**
|
|
@@ -2228,12 +2279,13 @@ class W extends HTMLElement {
|
|
|
2228
2279
|
* Used by keyboard navigation to ensure focused cells are fully visible
|
|
2229
2280
|
* when plugins like pinned columns obscure part of the scroll area.
|
|
2230
2281
|
*/
|
|
2231
|
-
|
|
2282
|
+
_getHorizontalScrollOffsets(e, o) {
|
|
2232
2283
|
return this.#e?.getHorizontalScrollOffsets(e, o) ?? { left: 0, right: 0 };
|
|
2233
2284
|
}
|
|
2234
2285
|
/**
|
|
2235
2286
|
* Query all plugins with a generic query and collect responses.
|
|
2236
2287
|
* This enables inter-plugin communication without the core knowing plugin-specific concepts.
|
|
2288
|
+
* @internal Plugin API
|
|
2237
2289
|
*
|
|
2238
2290
|
* @example
|
|
2239
2291
|
* // Check if any plugin vetoes moving a column
|
|
@@ -2247,7 +2299,7 @@ class W extends HTMLElement {
|
|
|
2247
2299
|
* Build a CellMouseEvent from a native MouseEvent.
|
|
2248
2300
|
* Extracts cell/row information from the event target.
|
|
2249
2301
|
*/
|
|
2250
|
-
#
|
|
2302
|
+
#k(e, o) {
|
|
2251
2303
|
let i = null;
|
|
2252
2304
|
const n = e.composedPath?.();
|
|
2253
2305
|
if (n && n.length > 0 ? i = n[0] : i = e.target, i && !this.#o.contains(i)) {
|
|
@@ -2274,25 +2326,25 @@ class W extends HTMLElement {
|
|
|
2274
2326
|
/**
|
|
2275
2327
|
* Handle mousedown events and dispatch to plugin system.
|
|
2276
2328
|
*/
|
|
2277
|
-
#
|
|
2278
|
-
const o = this.#
|
|
2279
|
-
(this.#e?.onCellMouseDown(o) ?? !1) && (this.#
|
|
2329
|
+
#J(e) {
|
|
2330
|
+
const o = this.#k(e, "mousedown");
|
|
2331
|
+
(this.#e?.onCellMouseDown(o) ?? !1) && (this.#_ = !0);
|
|
2280
2332
|
}
|
|
2281
2333
|
/**
|
|
2282
2334
|
* Handle mousemove events (only when dragging).
|
|
2283
2335
|
*/
|
|
2284
|
-
#
|
|
2285
|
-
if (!this.#
|
|
2286
|
-
const o = this.#
|
|
2336
|
+
#Q(e) {
|
|
2337
|
+
if (!this.#_) return;
|
|
2338
|
+
const o = this.#k(e, "mousemove");
|
|
2287
2339
|
this.#e?.onCellMouseMove(o);
|
|
2288
2340
|
}
|
|
2289
2341
|
/**
|
|
2290
2342
|
* Handle mouseup events.
|
|
2291
2343
|
*/
|
|
2292
2344
|
#ee(e) {
|
|
2293
|
-
if (!this.#
|
|
2294
|
-
const o = this.#
|
|
2295
|
-
this.#e?.onCellMouseUp(o), this.#
|
|
2345
|
+
if (!this.#_) return;
|
|
2346
|
+
const o = this.#k(e, "mouseup");
|
|
2347
|
+
this.#e?.onCellMouseUp(o), this.#_ = !1;
|
|
2296
2348
|
}
|
|
2297
2349
|
// API consumed by internal utils (rows.ts)
|
|
2298
2350
|
get changedRows() {
|
|
@@ -2302,7 +2354,7 @@ class W extends HTMLElement {
|
|
|
2302
2354
|
return Array.from(this._changedRowIndices);
|
|
2303
2355
|
}
|
|
2304
2356
|
async resetChangedRows(e) {
|
|
2305
|
-
this._changedRowIndices.clear(), e || this.#s("changed-rows-reset", { rows: this.changedRows, indices: this.changedRowIndices }), this.
|
|
2357
|
+
this._changedRowIndices.clear(), e || this.#s("changed-rows-reset", { rows: this.changedRows, indices: this.changedRowIndices }), this._rowPool.forEach((o) => o.classList.remove("changed"));
|
|
2306
2358
|
}
|
|
2307
2359
|
async beginBulkEdit(e) {
|
|
2308
2360
|
if (!this._columns.some((s) => s.editable)) return;
|
|
@@ -2310,13 +2362,13 @@ class W extends HTMLElement {
|
|
|
2310
2362
|
B(this, e, i);
|
|
2311
2363
|
const n = this.findRenderedRowElement?.(e);
|
|
2312
2364
|
n && (Array.from(n.children).forEach((s, r) => {
|
|
2313
|
-
const l = this.
|
|
2365
|
+
const l = this._visibleColumns[r];
|
|
2314
2366
|
if (l?.editable) {
|
|
2315
2367
|
const a = s;
|
|
2316
|
-
a.classList.contains("editing") ||
|
|
2368
|
+
a.classList.contains("editing") || O(this, i, e, l, a);
|
|
2317
2369
|
}
|
|
2318
2370
|
}), queueMicrotask(() => {
|
|
2319
|
-
const s = n.querySelector(`.cell[data-col="${this.
|
|
2371
|
+
const s = n.querySelector(`.cell[data-col="${this._focusCol}"]`);
|
|
2320
2372
|
if (s?.classList.contains("editing")) {
|
|
2321
2373
|
const r = s.querySelector(
|
|
2322
2374
|
'input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])'
|
|
@@ -2329,7 +2381,7 @@ class W extends HTMLElement {
|
|
|
2329
2381
|
}));
|
|
2330
2382
|
}
|
|
2331
2383
|
async commitActiveRowEdit() {
|
|
2332
|
-
this.
|
|
2384
|
+
this._activeEditRows !== -1 && M(this, this._activeEditRows, !1);
|
|
2333
2385
|
}
|
|
2334
2386
|
async ready() {
|
|
2335
2387
|
return this.#z;
|
|
@@ -2357,7 +2409,7 @@ class W extends HTMLElement {
|
|
|
2357
2409
|
field: e,
|
|
2358
2410
|
visible: o,
|
|
2359
2411
|
visibleColumns: (i ?? []).filter((l) => !l.hidden).map((l) => l.field)
|
|
2360
|
-
}), this.
|
|
2412
|
+
}), this._rowPool.length = 0, this._bodyEl && (this._bodyEl.innerHTML = ""), this.__rowRenderEpoch++, this.#c(), this.requestStateChange(), !0) : !1;
|
|
2361
2413
|
}
|
|
2362
2414
|
/**
|
|
2363
2415
|
* Toggle the visibility of a column.
|
|
@@ -2386,7 +2438,7 @@ class W extends HTMLElement {
|
|
|
2386
2438
|
i.hidden = !1;
|
|
2387
2439
|
}), this.#s("column-visibility", {
|
|
2388
2440
|
visibleColumns: (e ?? []).map((i) => i.field)
|
|
2389
|
-
}), this.
|
|
2441
|
+
}), this._rowPool.length = 0, this._bodyEl && (this._bodyEl.innerHTML = ""), this.__rowRenderEpoch++, this.#c(), this.requestStateChange());
|
|
2390
2442
|
}
|
|
2391
2443
|
/**
|
|
2392
2444
|
* Get list of all column fields (including hidden).
|
|
@@ -2416,7 +2468,7 @@ class W extends HTMLElement {
|
|
|
2416
2468
|
}
|
|
2417
2469
|
for (const n of o.values())
|
|
2418
2470
|
i.push(n);
|
|
2419
|
-
this._columns = i, q(this),
|
|
2471
|
+
this._columns = i, q(this), N(this), this.refreshVirtualWindow(!0);
|
|
2420
2472
|
}
|
|
2421
2473
|
/**
|
|
2422
2474
|
* Get the current column order as an array of field names.
|
|
@@ -2460,6 +2512,7 @@ class W extends HTMLElement {
|
|
|
2460
2512
|
* Called internally after resize, reorder, visibility, or sort changes.
|
|
2461
2513
|
* Plugins should call this after changing their state.
|
|
2462
2514
|
* The event is debounced to avoid excessive events during drag operations.
|
|
2515
|
+
* @internal Plugin API
|
|
2463
2516
|
*/
|
|
2464
2517
|
requestStateChange() {
|
|
2465
2518
|
this.#L || (this.#L = we(
|
|
@@ -2475,7 +2528,7 @@ class W extends HTMLElement {
|
|
|
2475
2528
|
resetColumnState() {
|
|
2476
2529
|
this.#d = void 0, (this.#t.columns ?? []).forEach((i) => {
|
|
2477
2530
|
i.hidden = !1;
|
|
2478
|
-
}), this.
|
|
2531
|
+
}), this._sortState = null, this.__originalOrder = [], this.#u(), this.#c();
|
|
2479
2532
|
const o = this.#e?.getAll() ?? [];
|
|
2480
2533
|
for (const i of o)
|
|
2481
2534
|
if (i.applyColumnState)
|
|
@@ -2573,43 +2626,44 @@ class W extends HTMLElement {
|
|
|
2573
2626
|
/**
|
|
2574
2627
|
* Core virtualization routine. Chooses between bypass (small datasets), grouped window rendering,
|
|
2575
2628
|
* or standard row window rendering.
|
|
2629
|
+
* @internal Plugin API
|
|
2576
2630
|
*/
|
|
2577
2631
|
refreshVirtualWindow(e = !1) {
|
|
2578
|
-
if (!this.
|
|
2632
|
+
if (!this._bodyEl) return;
|
|
2579
2633
|
const o = this._rows.length;
|
|
2580
|
-
if (!this.
|
|
2581
|
-
this.#
|
|
2634
|
+
if (!this._virtualization.enabled) {
|
|
2635
|
+
this.#O(0, o), this.#e?.afterRender();
|
|
2582
2636
|
return;
|
|
2583
2637
|
}
|
|
2584
|
-
if (this._rows.length <= this.
|
|
2585
|
-
if (this.
|
|
2586
|
-
const
|
|
2587
|
-
this.
|
|
2638
|
+
if (this._rows.length <= this._virtualization.bypassThreshold) {
|
|
2639
|
+
if (this._virtualization.start = 0, this._virtualization.end = o, this._bodyEl.style.transform = "translateY(0px)", this.#O(0, o, this.__rowRenderEpoch), this._virtualization.totalHeightEl) {
|
|
2640
|
+
const C = this.#o.querySelector(".tbw-scroll-area"), _ = C ? C.offsetHeight - C.clientHeight : 0;
|
|
2641
|
+
this._virtualization.totalHeightEl.style.height = `${o * this._virtualization.rowHeight + _}px`;
|
|
2588
2642
|
}
|
|
2589
2643
|
const m = this.#o.querySelector(".rows-body");
|
|
2590
|
-
m?.setAttribute("aria-rowcount", String(o)), m?.setAttribute("aria-colcount", String(this.
|
|
2644
|
+
m?.setAttribute("aria-rowcount", String(o)), m?.setAttribute("aria-colcount", String(this._visibleColumns.length)), this.#e?.afterRender();
|
|
2591
2645
|
return;
|
|
2592
2646
|
}
|
|
2593
|
-
const i = this.
|
|
2647
|
+
const i = this._virtualization.container ?? this, s = (this._virtualization.viewportEl ?? i).clientHeight, r = this._virtualization.rowHeight, l = i.scrollTop;
|
|
2594
2648
|
let a = Math.floor(l / r), d = 0;
|
|
2595
2649
|
const f = 10;
|
|
2596
2650
|
for (; d < f; ) {
|
|
2597
|
-
const m = this.#e?.getExtraHeightBefore?.(a) ?? 0,
|
|
2598
|
-
if (
|
|
2599
|
-
a =
|
|
2651
|
+
const m = this.#e?.getExtraHeightBefore?.(a) ?? 0, C = Math.floor((l - m) / r);
|
|
2652
|
+
if (C >= a || C < 0) break;
|
|
2653
|
+
a = C, d++;
|
|
2600
2654
|
}
|
|
2601
2655
|
a = a - a % 2, a < 0 && (a = 0);
|
|
2602
2656
|
const h = this.#e?.adjustVirtualStart(a, l, r);
|
|
2603
2657
|
h !== void 0 && h < a && (a = h, a = a - a % 2, a < 0 && (a = 0));
|
|
2604
2658
|
const p = Math.ceil(s / r) + 3;
|
|
2605
2659
|
let c = a + p;
|
|
2606
|
-
c > o && (c = o), this.
|
|
2607
|
-
const b = this.#o.querySelector(".tbw-footer")?.offsetHeight ?? 0, w = this.#e?.getExtraHeight() ?? 0, v = this.#o.querySelector(".tbw-scroll-area"),
|
|
2608
|
-
this.
|
|
2609
|
-
const x = this.#e?.getExtraHeightBefore?.(a) ?? 0,
|
|
2610
|
-
this.
|
|
2660
|
+
c > o && (c = o), this._virtualization.start = a, this._virtualization.end = c;
|
|
2661
|
+
const b = this.#o.querySelector(".tbw-footer")?.offsetHeight ?? 0, w = this.#e?.getExtraHeight() ?? 0, v = this.#o.querySelector(".tbw-scroll-area"), y = v ? v.offsetHeight - v.clientHeight : 0;
|
|
2662
|
+
this._virtualization.totalHeightEl && (this._virtualization.totalHeightEl.style.height = `${o * r + r + b + w + y}px`);
|
|
2663
|
+
const x = this.#e?.getExtraHeightBefore?.(a) ?? 0, R = -(l - a * r - x);
|
|
2664
|
+
this._bodyEl.style.transform = `translateY(${R}px)`, this.#O(a, c, e ? ++this.__rowRenderEpoch : this.__rowRenderEpoch);
|
|
2611
2665
|
const g = this.#o.querySelector(".rows-body");
|
|
2612
|
-
g?.setAttribute("aria-rowcount", String(o)), g?.setAttribute("aria-colcount", String(this.
|
|
2666
|
+
g?.setAttribute("aria-rowcount", String(o)), g?.setAttribute("aria-colcount", String(this._visibleColumns.length)), e && this.#e?.afterRender();
|
|
2613
2667
|
}
|
|
2614
2668
|
// ---------------- Render ----------------
|
|
2615
2669
|
#$() {
|
|
@@ -2679,13 +2733,13 @@ class W extends HTMLElement {
|
|
|
2679
2733
|
}
|
|
2680
2734
|
}
|
|
2681
2735
|
customElements.get(W.tagName) || customElements.define(W.tagName, W);
|
|
2682
|
-
const
|
|
2736
|
+
const Je = {
|
|
2683
2737
|
/** Ask if a column can be moved. Context: ColumnConfig. Response: boolean | undefined */
|
|
2684
2738
|
CAN_MOVE_COLUMN: "canMoveColumn",
|
|
2685
2739
|
/** Get context menu items. Context: ContextMenuParams. Response: ContextMenuItem[] */
|
|
2686
2740
|
GET_CONTEXT_MENU_ITEMS: "getContextMenuItems"
|
|
2687
2741
|
};
|
|
2688
|
-
class
|
|
2742
|
+
class Qe {
|
|
2689
2743
|
/** Plugin version - override in subclass if needed */
|
|
2690
2744
|
version = "1.0.0";
|
|
2691
2745
|
/** CSS styles to inject into the grid's shadow DOM */
|
|
@@ -2993,7 +3047,7 @@ const T = {
|
|
|
2993
3047
|
max: (t, e) => Math.max(...t.map((o) => Number(o[e]) || -1 / 0)),
|
|
2994
3048
|
first: (t, e) => t[0]?.[e],
|
|
2995
3049
|
last: (t, e) => t[t.length - 1]?.[e]
|
|
2996
|
-
}, I = /* @__PURE__ */ new Map(),
|
|
3050
|
+
}, I = /* @__PURE__ */ new Map(), k = {
|
|
2997
3051
|
/**
|
|
2998
3052
|
* Register a custom aggregator function.
|
|
2999
3053
|
*/
|
|
@@ -3047,9 +3101,9 @@ function Ze(t) {
|
|
|
3047
3101
|
function it(t, e) {
|
|
3048
3102
|
return Ze(t)(e);
|
|
3049
3103
|
}
|
|
3050
|
-
const st =
|
|
3104
|
+
const st = k.register.bind(k), rt = k.unregister.bind(k), lt = k.get.bind(k), at = k.run.bind(k), ct = k.list.bind(k);
|
|
3051
3105
|
export {
|
|
3052
|
-
|
|
3106
|
+
Qe as BaseGridPlugin,
|
|
3053
3107
|
H as DEFAULT_GRID_ICONS,
|
|
3054
3108
|
ot as DGEvents,
|
|
3055
3109
|
W as DataGridElement,
|
|
@@ -3059,10 +3113,10 @@ export {
|
|
|
3059
3113
|
G as GridDataAttrs,
|
|
3060
3114
|
W as GridElement,
|
|
3061
3115
|
et as GridSelectors,
|
|
3062
|
-
|
|
3116
|
+
Je as PLUGIN_QUERIES,
|
|
3063
3117
|
nt as PluginEvents,
|
|
3064
3118
|
Ye as PluginManager,
|
|
3065
|
-
|
|
3119
|
+
k as aggregatorRegistry,
|
|
3066
3120
|
lt as getAggregator,
|
|
3067
3121
|
Ze as getValueAggregator,
|
|
3068
3122
|
ct as listAggregators,
|