@ninebone/datagrid 0.0.5 → 0.0.7

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.
@@ -1,4204 +0,0 @@
1
- import { trace as e } from "@ninebone/util";
2
- // src/core/protype.js
3
- Array.prototype.nineBinarySearch = function(e) {
4
- let t = 0, n = this.length - 1, r;
5
- for (; t <= n;) {
6
- if (r = parseInt((t + n) / 2), e === this[r]) return r;
7
- e < this[r] ? n = r - 1 : t = r + 1;
8
- }
9
- return -1;
10
- };
11
- var t = /* @__PURE__ */ new WeakMap();
12
- HTMLElement.prototype.addDebounseEventListener = function(e, n, r, i, a = 500) {
13
- let o = this;
14
- t.has(o) || t.set(o, {
15
- timer: null,
16
- cancelFn: null
17
- });
18
- let s = t.get(o);
19
- o.addEventListener(r, (e) => {
20
- e.actualTarget = e.target, s.timer &&= (clearTimeout(s.timer), null), s.timer = setTimeout(() => {
21
- s.timer = null, s.cancelFn = i.call(o, e);
22
- }, a);
23
- }), o.addEventListener(e, (e) => {
24
- s.timer &&= (clearTimeout(s.timer), null), s.cancelFn &&= (s.cancelFn(), null), n.call(o, e);
25
- });
26
- }, nine.measureTextSize = (e, t = "12px sans-serif") => {
27
- if (typeof e == "number" && (e += ""), !e) return {
28
- width: null,
29
- height: null
30
- };
31
- let n = (e) => {
32
- let t = document.createElement("DIV");
33
- return t.innerHTML = e, t.textContent || t.innerText || "";
34
- };
35
- e = e.replaceAll("\n", "<br>");
36
- let r = document.body.querySelector("canvas#_nine_measure_canvas_");
37
- r || (r = document.createElement("canvas"), r.id = "_nine_measure_canvas_", r.style.cssText = "position: absolute; visibility: hidden; pointer-events: none; left: -9999px;", document.body.appendChild(r));
38
- let i = r.getContext("2d");
39
- i.font = t;
40
- let a = 0, o = 0;
41
- for (let t of e.split("<br>")) {
42
- let e = n(t), r = i.measureText(e);
43
- a = Math.max(a, r.width);
44
- let s = r.fontBoundingBoxAscent || 10, c = r.fontBoundingBoxDescent || 3;
45
- o += s + c;
46
- }
47
- return {
48
- width: a,
49
- height: o
50
- };
51
- };
52
- var n = new class extends e.constructor {
53
- constructor() {
54
- super(), this.init("nine-table", "green");
55
- }
56
- }(), r = {
57
- META: { INDEX: {
58
- ROWID: 0,
59
- FILTER: 1,
60
- GROUP: 2
61
- } },
62
- ROW_STATE: {
63
- EMPTY: "EMPTY",
64
- NORMAL: "NORMAL",
65
- INSERT: "INSERT",
66
- UPDATE: "UPDATE",
67
- DELETE: "DELETE"
68
- },
69
- EVENT: {
70
- LOAD: "load",
71
- CELL_BUTTON_CLICK: "cell-button-click"
72
- }
73
- }, i = class {
74
- #e;
75
- #t = -1;
76
- constructor(e) {
77
- this.#e = e;
78
- }
79
- get at() {
80
- return this.#t;
81
- }
82
- set at(e) {
83
- this.#t = parseInt(e, 10);
84
- }
85
- count = () => this.#e.rawRecords.length;
86
- }, a = class e {
87
- #e;
88
- #t;
89
- #n = 0;
90
- #r = [];
91
- static META_INDEX = { FILTER: 0 };
92
- static ROW_STATE = {
93
- EMPTY: "EMPTY",
94
- NORMAL: "NORMAL",
95
- INSERT: "INSERT",
96
- UPDATE: "UPDATE",
97
- DELETE: "DELETE"
98
- };
99
- constructor(e, t) {
100
- this.#e = e, this.#t = t, this.#a();
101
- }
102
- #i = () => (this.#t.rawRecords || []).filter((e) => !e.__ng?.deleted);
103
- get count() {
104
- return this.length;
105
- }
106
- count = () => this.length;
107
- getArray = (e, t) => {
108
- let n = this.#i();
109
- if (e == null) return n;
110
- if (e < 0 || e >= n.length) return null;
111
- let r = n[e];
112
- if (t != null) {
113
- let e = this.getHostFields().indexOf(t);
114
- return e >= 0 ? r.v[e] : null;
115
- }
116
- return r;
117
- };
118
- setArray = (t, n, r) => {
119
- let i = this.#i()[t];
120
- i.v[n] !== r && i.__ng.rowState !== e.ROW_STATE.INSERT && (i.__ng.rowState = e.ROW_STATE.UPDATE), i.v[n] = r;
121
- };
122
- get = (e, t) => {
123
- let n = this.#i();
124
- if (e == null) return this.#u(n);
125
- if (e < 0 || e >= n.length) return null;
126
- let r = n[e], i = this.getHostFields();
127
- if (t != null) {
128
- let e = i.indexOf(t);
129
- return e >= 0 ? r.v[e] : null;
130
- }
131
- return this.#u(r);
132
- };
133
- getAll = () => this.#t.rawRecords || [];
134
- getHostFields = () => typeof this.#e.fields?.get == "function" ? this.#e.fields.get() : [];
135
- #a = () => {
136
- this.#r = [];
137
- let e = this.#e.template || [];
138
- Array.from(e).forEach((e) => {
139
- this.#r.push(e.getBoundingClientRect?.().height || 24);
140
- }), (this.#t.rawRecords || []).forEach((e) => {
141
- e.__ng ||= this.#s(), e.__ng.height = this.#r.slice();
142
- });
143
- };
144
- get source() {
145
- return this.#u(this.#t.rawRecords);
146
- }
147
- set source(e) {
148
- this.set(e);
149
- }
150
- #o = () => {
151
- this.#e.shadowRoot.querySelectorAll("nine-table-sheet").forEach((e) => {
152
- e.invalidate();
153
- }), this.#e.shadowRoot.querySelector("nine-table-sheets-footer")?.refresh();
154
- };
155
- set = (e) => {
156
- let t = () => {
157
- this.#e.loading = !0, setTimeout(() => {
158
- try {
159
- this.clear(), this.add(e, !1), this.#o();
160
- } finally {
161
- this.#e.loading = !1;
162
- }
163
- });
164
- };
165
- this.#e.loaded ? t() : this.#e.addEventListener(r.EVENT.LOAD, (e) => {
166
- t();
167
- }, { once: !0 });
168
- };
169
- get nextId() {
170
- return this.#n++;
171
- }
172
- get length() {
173
- return this.#i().length;
174
- }
175
- get count() {
176
- return this.length;
177
- }
178
- getRowCount() {
179
- return this.length;
180
- }
181
- #s = (t = 0) => ({
182
- rowState: e.ROW_STATE.EMPTY,
183
- deleted: !1,
184
- filtered: !1,
185
- height: this.#r.slice(),
186
- o: {},
187
- c: {},
188
- __: [
189
- 0,
190
- 0,
191
- 0,
192
- 0,
193
- e.ROW_STATE.EMPTY,
194
- !1,
195
- !1,
196
- !0,
197
- !1,
198
- !0,
199
- !0,
200
- !1,
201
- this.#r.slice(),
202
- -1,
203
- {},
204
- {}
205
- ],
206
- _: [t, []]
207
- });
208
- reset = () => {
209
- this.#t.rawRecords = [], this.#o();
210
- };
211
- clear = () => {
212
- this.#t.rawRecords = [], this.#t.viewRecords?.reset && this.#t.viewRecords.reset(), this.#n = 0, this.#o();
213
- };
214
- #c = (e) => {
215
- Array.isArray(e) || (e = [e]);
216
- let t = this.getHostFields().length > 0 ? this.getHostFields() : Object.keys(e[0] || {}), n = [];
217
- return e.forEach((e) => {
218
- let r = { v: [] };
219
- t.forEach((t) => {
220
- r.v.push(e[t] !== void 0 && e[t] !== null ? e[t] : "");
221
- }), n.push(r);
222
- }), n;
223
- };
224
- #l = (t) => (Array.isArray(t) || (t = [t]), t.forEach((t) => {
225
- let n = this.nextId;
226
- t.m = this.#s(n), t.__ng = t.m, t.__ng.rowid = n, t.__ng.rowState = e.ROW_STATE.INSERT, t.__ng._[0] = n;
227
- }), t);
228
- add = (t, n = !0) => {
229
- t === void 0 && (t = {});
230
- let r = this.#c(t);
231
- this.#t.rawRecords = this.#t.rawRecords.concat(this.#l(r));
232
- let i = this.count() - 1;
233
- return n || r.forEach((t, n) => {
234
- let r = this.#t.rawRecords[this.#t.rawRecords.length - 1 - n];
235
- r && (r.__ng.rowState = e.ROW_STATE.EMPTY);
236
- }), this.#o(), i;
237
- };
238
- delete = (t) => {
239
- let n = [];
240
- n = Array.isArray(t) ? t : t === void 0 ? [this.#t.host.row.at] : [parseInt(t, 10)];
241
- let r = this.#i();
242
- n.sort((e, t) => t - e).forEach((t) => {
243
- if (r[t]) {
244
- let n = r[t].__ng.rowid;
245
- r[t].__ng.rowState === e.ROW_STATE.INSERT ? this.#t.rawRecords = this.#t.rawRecords.filter((e) => e.__ng.rowid !== n) : this.#t.rawRecords.forEach((t) => {
246
- t.__ng.rowid === n && (t.__ng.deleted = !0, t.__ng.rowState = e.ROW_STATE.DELETE);
247
- });
248
- }
249
- }), this.#o();
250
- };
251
- setValue = (t, n, r) => {
252
- t = parseInt(t, 10);
253
- let i = this.getHostFields().indexOf(n);
254
- if (i < 0) return;
255
- let a = this.#i()[t];
256
- if (!a) return;
257
- let o = a.v[i];
258
- o !== r && a.__ng.rowState !== e.ROW_STATE.INSERT && (a.__ng.o.hasOwnProperty(n) || (a.__ng.o[n] = o), a.__ng.rowState = e.ROW_STATE.UPDATE), a.v[i] = r;
259
- };
260
- #u = (e) => {
261
- if (!e) return e;
262
- let t = !Array.isArray(e), n = t ? [e] : e, r = this.getHostFields(), i = n.filter((e) => !e.__ng?.deleted).map((e) => {
263
- let t = {};
264
- return r.forEach((n, r) => {
265
- t[n] = e.v ? e.v[r] : e[n];
266
- }), t.__ng = e.__ng, t;
267
- });
268
- return t ? i[0] : i;
269
- };
270
- }, o = class {
271
- #e;
272
- constructor(e) {
273
- this.#e = e, this.row = new i(this), this.data = new a(this.#e, this), this.rawRecords = [], this.viewRecords = [], this.delRecords = [], this.pageCnt = 25, this.viewRecords.reset = () => {
274
- this.#e.view?.redraw && this.#e.view.redraw();
275
- }, this.setDataSource = (e) => {
276
- this.data && this.data.reset(), this.rawRecords = [], this.viewRecords = [], this.delRecords = [], this.data.set(e || []);
277
- }, this.getRowState = (e) => {
278
- let t = parseInt(e, 10);
279
- if (!(t >= this.data.count())) return this.data.getValidData()[t]?.__ng?.rowState;
280
- }, this.getRowPosition = () => this.row.at, this.setRowPosition = (e) => {
281
- this.row.at = e;
282
- }, this.scrollTo_V1 = (e) => (e < 0 && (e = 0), e >= this.rawRecords.length && (e = this.rawRecords.length - 1), this.viewRecords.rawIndex = e, this.viewRecords.reset && this.viewRecords.reset(), !(e <= 0 || e >= this.rawRecords.length - 1)), this.getColumn = (e, t) => this.data.get(e, t), this.setColumn = (e, t, n) => {
283
- e = parseInt(e, 10), this.data.setValue(e, t, n);
284
- }, this.setDataSource([]);
285
- }
286
- }, s = class {
287
- #e;
288
- #t = [];
289
- constructor(e) {
290
- this.#e = e, this.#r();
291
- }
292
- get() {
293
- return this.#t.map((e) => e.name);
294
- }
295
- getFields() {
296
- return this.#t;
297
- }
298
- getType(e) {
299
- let t = this.#t.find((t) => t.name === e);
300
- return t ? t.type : "string";
301
- }
302
- add = (e, t = "string") => {
303
- e.forEach((e) => {
304
- this.#t.some((t) => t.name === e) || this.#t.push({
305
- name: e,
306
- type: t
307
- });
308
- }), this.#n();
309
- };
310
- indexOf(e) {
311
- return this.#t.findIndex((t) => t.name === e);
312
- }
313
- includes(e) {
314
- return this.#t.some((t) => t.name === e);
315
- }
316
- #n = () => {
317
- let e = /* @__PURE__ */ new Map();
318
- this.#t.forEach((t) => {
319
- e.set(t.name, t.type);
320
- }), this.#t = Array.from(e, ([e, t]) => ({
321
- name: e,
322
- type: t
323
- })), this.#t = this.#t.filter((e) => e.name !== "" && e.name !== "__ng"), this.#t.sort((e, t) => e.name.length < t.name.length ? 1 : -1);
324
- };
325
- #r = () => {
326
- this.#t = [];
327
- let e = Array.from(this.#e.querySelectorAll("table"));
328
- if (e && e.length !== 0) {
329
- for (let t of e) t.querySelectorAll("[data-bind]").forEach((e) => {
330
- let t = e.dataset.bind, n = e.getAttribute("data-type") || "string";
331
- t && this.#t.push({
332
- name: t,
333
- type: n
334
- });
335
- }), [
336
- "data-expr",
337
- "background-color",
338
- "color",
339
- "tooltip",
340
- "visible",
341
- "readonly",
342
- "enable-button",
343
- "enable-check",
344
- "class-expr",
345
- "icon-color",
346
- "icon-src"
347
- ].forEach((e) => {
348
- t.querySelectorAll(`[${e}]`).forEach((t) => {
349
- let n = t.getAttribute(e);
350
- if (n) {
351
- if (n.indexOf("data.") < 0) {
352
- let e = n.search(/[(]/g);
353
- if (e > 0) try {
354
- n = String(window[n.substring(0, e).trim()]);
355
- } catch {
356
- n = "";
357
- }
358
- }
359
- n.split("data.").forEach((e) => {
360
- if (e.trim() != "") {
361
- let t = e.search(/[^_A-Za-z0-9]/g), r = "";
362
- t >= 0 ? r = e.substring(0, t) : n.startsWith("data.") && (r = e.replace("data.", "")), r && this.#t.push({
363
- name: r,
364
- type: "string"
365
- });
366
- }
367
- });
368
- }
369
- });
370
- });
371
- this.#n();
372
- }
373
- };
374
- }, c = class extends HTMLElement {
375
- constructor() {
376
- super();
377
- }
378
- connectedCallback() {
379
- this.#e();
380
- }
381
- #e = () => {};
382
- };
383
- customElements.get("nine-table-sheets") || customElements.define("nine-table-sheets", c);
384
- // src/layout/nine-table-sheets-footer.js
385
- var l = class extends HTMLElement {
386
- #e;
387
- constructor() {
388
- super();
389
- }
390
- connectedCallback() {
391
- this.#t();
392
- }
393
- refresh = () => {
394
- this.querySelector("#row-count").innerHTML = this.#e.data.count().toLocaleString();
395
- };
396
- #t = () => {
397
- this.#e = this.getRootNode().host, this.#r(), this.querySelector(".nine-tab-bar")?.addEventListener("click", (e) => {
398
- let t = e.ctrlKey || e.metaKey || e.shiftKey, n = e.target.closest("nt-sheets-tab-item");
399
- if (!n) return;
400
- let r = parseInt(n.dataset.index, 10);
401
- this.#n(r, t);
402
- }), setTimeout(() => {
403
- this.#n(0, !1);
404
- });
405
- };
406
- #n = (e, t = !1) => {
407
- let n = () => {
408
- let e = Array.from(this.#e.shadowRoot.querySelectorAll("nine-table-sheet"));
409
- Array.from(this.#e.shadowRoot.querySelectorAll("nine-splitter")).forEach((e) => e.style.setProperty("display", "none"));
410
- let t = e.map((e, t) => ({
411
- sheet: e,
412
- idx: t
413
- })).filter(({ sheet: e }) => e.classList.contains("active"));
414
- if (!(t.length < 2)) for (let e = 0; e < t.length - 1; e++) {
415
- let n = t[e].idx, r = this.#e.shadowRoot.querySelector(`nine-splitter[data-split-index="${n}"]`);
416
- r && r.style.setProperty("display", "");
417
- }
418
- }, r = this.querySelector(".nine-tab-bar"), i = this.#e.shadowRoot.querySelector("nine-table-sheets-body"), a = r.querySelectorAll("nt-sheets-tab-item"), o = i.querySelectorAll("nine-table-sheet");
419
- if (!a[e]) return;
420
- if (!t) a.forEach((t, n) => {
421
- t.setActive(n === e);
422
- }), o.forEach((t, n) => {
423
- let r = n === e;
424
- t.classList.toggle("active", r), t.style.flex = r ? "1 1 100%" : "";
425
- });
426
- else {
427
- let t = a[e], n = r.querySelectorAll("nt-sheets-tab-item.active");
428
- if (t.classList.contains("active") && n.length <= 1) return;
429
- t.classList.toggle("active");
430
- let o = i.querySelector(`nine-table-sheet[data-index="${e}"]`);
431
- o && (o.classList.toggle("active"), o.classList.contains("active") || (o.style.flex = ""));
432
- }
433
- let s = i.querySelectorAll("nine-table-sheet.active");
434
- s?.forEach((e) => {
435
- e.style.flex = s.length > 1 ? "1 1 0%" : "1 1 100%", typeof e.refreshLayout == "function" ? e.refreshLayout() : e.invalidate?.();
436
- }), n();
437
- };
438
- #r() {
439
- let e = Array.from(this.#e.children).filter((e) => e.tagName.toUpperCase() === "TABLE").map((e, t) => `<nt-sheets-tab-item class="${t === 0 ? "active" : ""}" data-index="${t}">${e.getAttribute("caption") || `Sheet ${t + 1}`}</nt-sheets-tab-item>`).join("");
440
- this.innerHTML = `
441
- <div class="nine-tab-bar">${e}</div>
442
- <div class="sheets-counter">Total : <span id="row-count">0</span></div>
443
- `;
444
- }
445
- }, u = class extends HTMLElement {
446
- constructor() {
447
- super();
448
- }
449
- connectedCallback() {}
450
- setActive(e) {
451
- this.classList.toggle("active", e);
452
- }
453
- };
454
- customElements.get("nt-sheets-tab-item") || customElements.define("nt-sheets-tab-item", u), customElements.get("nine-table-sheets-footer") || customElements.define("nine-table-sheets-footer", l);
455
- // src/layout/nine-table-toolbar.js
456
- var d = class extends HTMLElement {
457
- #e;
458
- #t;
459
- connectedCallback() {
460
- this.#e = this.getRootNode().host, this.#n(), this.#i();
461
- }
462
- #n() {
463
- this.innerHTML = "\n <div class=\"ng-toolbar-left\">\n <button type=\"button\" class=\"ng-toolbar-menu-btn\" title=\"Menu\">\n <svg width=\"16\" height=\"16\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"#374151\" stroke-width=\"2\">\n <line x1=\"3\" y1=\"12\" x2=\"21\" y2=\"12\"></line>\n <line x1=\"3\" y1=\"6\" x2=\"21\" y2=\"6\"></line>\n <line x1=\"3\" y1=\"18\" x2=\"21\" y2=\"18\"></line>\n </svg>\n </button>\n <span class=\"ng-toolbar-title\"></span>\n </div>\n\n <div class=\"ng-toolbar-custom\" id=\"custom-container\"></div>\n ", this.#t = this.querySelector("#custom-container"), this.#r();
464
- }
465
- #r() {
466
- let e = this.#e.getAttribute("theme") === "simple" || this.#e.classList.contains("simple"), t = this.#e.getAttribute("show-toolbar") !== "false", n = this.#e.getAttribute("show-menu") !== "false", r = this.#e.getAttribute("caption") || "";
467
- e || !t ? this.setAttribute("hidden", "") : this.removeAttribute("hidden"), this.setAttribute("show-menu", n ? "true" : "false"), this.updateCaption(r);
468
- }
469
- #i() {
470
- let e = this.querySelector(".ng-toolbar-title");
471
- e && e.addEventListener("dblclick", () => {
472
- let t = "<font color=\"green\">https://www.ninegrid.net</font>", n = this.#e.getAttribute("caption") || "";
473
- e.innerHTML = e.innerHTML === t ? n : t;
474
- });
475
- let t = this.querySelector(".ng-toolbar-menu-btn");
476
- t && t.addEventListener("click", () => {
477
- this.#e.dispatchEvent(new CustomEvent("toolbar-menu-click", {
478
- bubbles: !0,
479
- composed: !0,
480
- detail: { targetTable: this.#e }
481
- }));
482
- });
483
- }
484
- addCustomElement(e) {
485
- this.#t && this.#t.append(e);
486
- }
487
- updateCaption(e) {
488
- let t = this.querySelector(".ng-toolbar-title");
489
- t && (t.textContent = e);
490
- }
491
- };
492
- customElements.get("nine-table-toolbar") || customElements.define("nine-table-toolbar", d);
493
- // src/layout/nine-table-hscrollbar.js
494
- var f = class extends HTMLElement {
495
- #e;
496
- #t = !1;
497
- #n;
498
- #r;
499
- #i;
500
- #a;
501
- constructor() {
502
- super();
503
- }
504
- connectedCallback() {
505
- if (this.#e = this.closest("nine-table-sheet") || this.getRootNode().host, !this.#e) return;
506
- this.innerHTML = "\n <button class='scroll-left' disabled><div class='scroll-icon'></div></button>\n <div class='scroll-track'><div class='scroll-thumb'></div></div>\n <button class='scroll-right' disabled><div class='scroll-icon'></div></button>\n ";
507
- let e = () => {
508
- let t = this.#e.querySelector(".ng-sheet-body .ng-container-body");
509
- t ? (this.#n = {
510
- container: t,
511
- track: this.querySelector(".scroll-track"),
512
- thumb: this.querySelector(".scroll-thumb"),
513
- left: this.querySelector(".scroll-left"),
514
- right: this.querySelector(".scroll-right")
515
- }, this.#c(), this.#o(), this.refresh()) : setTimeout(e, 10);
516
- };
517
- e();
518
- }
519
- disconnectedCallback() {
520
- this.#a && this.#a.disconnect();
521
- }
522
- #o = () => {
523
- if (!this.#e) return;
524
- let e = this.#e.querySelector(".ng-sheet-body .ng-container-body");
525
- e && (this.#a = new ResizeObserver(() => {
526
- this.refresh();
527
- }), this.#a.observe(e));
528
- };
529
- refresh = () => {
530
- if (!this.#e || !this.#n || this.#t) return;
531
- let e = this.#n.container, t = e.querySelector("table");
532
- if (!t) return;
533
- let n = this.#n.track, r = this.#n.thumb, i = e.clientWidth, a = t.scrollWidth, o = i !== 0 && a > i;
534
- if (this.#e.classList.toggle("hscroll-visible", o), !o) return;
535
- let s = n.clientWidth;
536
- if (s <= 0) return;
537
- let c = Math.max(Math.min(i / a * s, s), 20);
538
- r.style.width = `${c}px`;
539
- let l = e.scrollLeft, u = a - i, d = 0;
540
- u > 0 && (d = parseInt(l / u * (s - c), 10)), d < 0 && (d = 0);
541
- let f = s - c;
542
- d > f && (d = f), r.style.left = `${d}px`, this.#n.left.disabled = d === 0, this.#n.right.disabled = d >= f - 1;
543
- };
544
- #s = (e) => {
545
- if (!this.#n) return !1;
546
- let t = this.#n.container, n = t.querySelector("table");
547
- if (!n) return !1;
548
- let r = this.#n.track.getBoundingClientRect(), i = this.#n.thumb.clientWidth, a = e;
549
- a < 0 && (a = 0);
550
- let o = r.width - i;
551
- a > o && (a = o), a = parseInt(a, 10), this.#n.thumb.style.left = `${a}px`, this.#n.left.disabled = a === 0, this.#n.right.disabled = a >= o - 1;
552
- let s = t.clientWidth, c = n.scrollWidth - s;
553
- return o > 0 && c > 0 && (t.scrollLeft = a / o * c), a > 0 && a < o - 1;
554
- };
555
- #c = () => {
556
- let e = (e) => {
557
- clearInterval(this.#r), clearInterval(this.#i);
558
- let t = parseInt(this.#n.thumb.style.left || 0, 10);
559
- this.#s(t + e), this.#r = setInterval(() => {
560
- clearInterval(this.#r), this.#i = setInterval(() => {
561
- let t = parseInt(this.#n.thumb.style.left || 0, 10);
562
- this.#s(t + e) || clearInterval(this.#i);
563
- }, 50);
564
- }, 500);
565
- }, t = () => {
566
- clearInterval(this.#r), clearInterval(this.#i);
567
- };
568
- [
569
- "mouseup",
570
- "mouseleave",
571
- "touchend"
572
- ].forEach((e) => {
573
- this.#n.left.addEventListener(e, t), this.#n.right.addEventListener(e, t), this.#n.track.addEventListener(e, t);
574
- }), this.#n.left.addEventListener("mousedown", (t) => {
575
- t.button === 0 && e(-20);
576
- }), this.#n.right.addEventListener("mousedown", (t) => {
577
- t.button === 0 && e(20);
578
- }), this.#n.left.addEventListener("touchstart", () => e(-20)), this.#n.right.addEventListener("touchstart", () => e(20)), this.#n.track.addEventListener("mousedown", (e) => {
579
- if (e.button !== 0) return;
580
- e.preventDefault();
581
- let t = this.#n.track.getBoundingClientRect(), n = this.#n.thumb.clientWidth;
582
- this.#s(e.clientX - t.left - n / 2);
583
- }), this.#n.thumb.addEventListener("mousedown", (e) => {
584
- if (e.button !== 0) return;
585
- e.stopPropagation(), e.preventDefault(), this.#t = !0, this.shiftX = e.clientX - this.#n.thumb.getBoundingClientRect().left;
586
- let n = (e) => {
587
- if (!this.#t) return;
588
- let t = this.#n.track.getBoundingClientRect();
589
- this.#s(e.clientX - t.left - this.shiftX);
590
- }, r = () => {
591
- this.#t = !1, t(), document.removeEventListener("mousemove", n), document.removeEventListener("mouseup", r), this.refresh();
592
- };
593
- document.addEventListener("mousemove", n), document.addEventListener("mouseup", r);
594
- });
595
- };
596
- };
597
- customElements.get("nine-table-hscrollbar") || customElements.define("nine-table-hscrollbar", f);
598
- // src/layout/nine-table-vscrollbar.js
599
- var p = class extends HTMLElement {
600
- #e;
601
- #t;
602
- #n = !1;
603
- #r;
604
- #i = 0;
605
- #a = 0;
606
- constructor() {
607
- super();
608
- }
609
- connectedCallback() {
610
- this.#e = this.getRootNode().host, this.#t = this.closest("nine-table-sheet"), this.innerHTML = "\n <button class='scroll-top' disabled><div class='scroll-icon'></div></button>\n <div class='scroll-track'><div class='scroll-thumb'></div></div>\n <button class='scroll-bottom' disabled><div class='scroll-icon'></div></button>\n ";
611
- let e = () => {
612
- let t = this.#t.querySelector(".ng-sheet-body");
613
- t ? (this.#r = {
614
- container: t,
615
- track: this.querySelector(".scroll-track"),
616
- thumb: this.querySelector(".scroll-thumb"),
617
- top: this.querySelector(".scroll-top"),
618
- bottom: this.querySelector(".scroll-bottom")
619
- }, this.#s(), this.refresh()) : setTimeout(e, 10);
620
- };
621
- e();
622
- }
623
- #o = () => {
624
- let e = this.#t.view.getArray(), t = e ? e.length : 0, n = this.#t.elements?.scrollHolder, r = n && parseFloat(n.style.height) || 0;
625
- (!r || r <= 0) && (r = this.#t.sourceTable?.querySelector("tbody tr[grouping='true']") && this.#t.rowManager ? body.scrollHeight > body.clientHeight ? body.scrollHeight : t * 30 : t * (this.#t.getRowHeight() || 1));
626
- let i = 15e6, a = r > i, o = 1, s = r;
627
- return a && (o = i / r, s = i), {
628
- rawContentHeight: r,
629
- contentHeight: s,
630
- scaleFactor: o,
631
- useScaling: a,
632
- totalCount: t
633
- };
634
- };
635
- refresh = () => {
636
- if (this.#n || !this.#t || !this.#t.elements || !this.#r) return;
637
- let e = this.#r.container, t = this.#r.track, n = this.#r.thumb, { contentHeight: r } = this.#o(), i = (this.#t.querySelector("thead")?.offsetHeight || 0) + (this.#t.querySelector("tfoot")?.offsetHeight || 0) + (this.#t.querySelector("tbody.head")?.offsetHeight || 0), a = this.#t.querySelector(".ng-sheet-body").offsetHeight || 0, o = a - i, s = this.#t.view.getArray().length, c = this.#t.getRowHeight() * s, l = c > o;
638
- if (this.#t.classList.toggle("vscroll-visible", l), !l) return;
639
- let u = t.clientHeight;
640
- if (u <= 0) return;
641
- let d = Math.max(Math.min(a / c * u, u), 20);
642
- n.style.height = `${d}px`;
643
- let f = e.scrollTop, p = Math.max(r - this.#t.rowManager.getRowHeight(), 1), m = 0;
644
- p > 0 && (m = f / p * (u - d));
645
- let h = u - d;
646
- m < 0 && (m = 0), m > h && (m = h), n.style.top = `${m}px`, this.#r.top.disabled = f <= 0, this.#r.bottom.disabled = f >= p - 1;
647
- };
648
- #s = () => {
649
- this.#r.thumb.addEventListener("mousedown", (e) => {
650
- if (e.button !== 0) return;
651
- e.stopPropagation(), e.preventDefault(), this.#n = !0, this.#i = e.clientY, this.#a = parseFloat(this.#r.thumb.style.top) || 0;
652
- let t = this.#r.track.getBoundingClientRect().height - this.#r.thumb.clientHeight, n = (e) => {
653
- if (!this.#n || t <= 0) return;
654
- let n = e.clientY - this.#i, r = this.#a + n;
655
- r < 0 && (r = 0), r > t && (r = t), this.#r.thumb.style.top = `${r}px`;
656
- let i = r / t, a = this.#t.getRowHeight(), o = (this.#t.querySelector(".ng-sheet-body").offsetHeight || 0) - (this.#t.elements.body.thead?.offsetHeight || 0) - (this.#t.elements.body.tfoot?.offsetHeight || 0) - (this.#t.elements.body.tbody.head.offsetHeight || 0), s = Math.floor(o / a), { totalCount: c } = this.#o(), l = Math.floor(i * (c - s + 1));
657
- this.#t.rowManager.scrollToDataRow(l);
658
- let { rawContentHeight: u, contentHeight: d } = this.#o(), f = this.#r.container.scrollTop, p = Math.max(d - this.#t.rowManager.getRowHeight(), 0);
659
- this.#r.top.disabled = f <= 0, this.#r.bottom.disabled = f >= p - 1;
660
- }, r = () => {
661
- this.#n = !1, document.removeEventListener("mousemove", n), document.removeEventListener("mouseup", r);
662
- };
663
- document.addEventListener("mousemove", n), document.addEventListener("mouseup", r);
664
- }), this.#r.track.addEventListener("mousedown", (e) => {
665
- if (e.button !== 0 || e.target === this.#r.thumb) return;
666
- let t = this.#r.track.getBoundingClientRect(), n = this.#r.thumb.clientHeight, r = this.#r.track.clientHeight - n;
667
- if (r > 0) {
668
- let i = e.clientY - t.top - n / 2, a = Math.max(0, Math.min(1, i / r)), { totalCount: o } = this.#o(), s = Math.max(0, Math.min(Math.floor(a * (o - 1)), o - 1));
669
- s >= 0 && this.#t.rowManager && typeof this.#t.rowManager.scrollToDataRow == "function" && this.#t.rowManager.scrollToDataRow(s, "top");
670
- }
671
- this.refresh();
672
- });
673
- let e = null, t = (t) => {
674
- if (e) return;
675
- let n = () => {
676
- let e = this.#t.querySelector("tbody.body tr");
677
- if (!e || e.dataset.row === void 0 || t === "down" && this.#t.isLastRow()) return;
678
- let n = parseInt(e.dataset.row, 10), r = t === "down" ? n + 1 : Math.max(0, n - 1);
679
- this.#t.rowManager.scrollToDataRow(r, null, () => {
680
- this.refresh();
681
- });
682
- };
683
- n(), e = setInterval(n, 200);
684
- }, n = () => {
685
- e &&= (clearInterval(e), null);
686
- };
687
- this.#r.top.addEventListener("mousedown", (e) => {
688
- e.button === 0 && t("up");
689
- }), this.#r.bottom.addEventListener("mousedown", (e) => {
690
- e.button === 0 && t("down");
691
- }), document.addEventListener("mouseup", n), this.#r.top.addEventListener("mouseleave", n), this.#r.bottom.addEventListener("mouseleave", n);
692
- };
693
- };
694
- customElements.get("nine-table-vscrollbar") || customElements.define("nine-table-vscrollbar", p);
695
- // src/data/Grouping.js
696
- var m = {
697
- ID: 0,
698
- DEPTH: 1,
699
- NAME: 2,
700
- CHILDREN: 3
701
- }, h = class {
702
- #e;
703
- #t;
704
- #n = [];
705
- #r = /* @__PURE__ */ new Map();
706
- #i = !1;
707
- constructor(e) {
708
- this.#e = e, this.#t = this.#e.getRootNode().host;
709
- }
710
- get columns() {
711
- return this.#n;
712
- }
713
- get groupMap() {
714
- return this.#r;
715
- }
716
- initialize = () => {
717
- let e = [], t = this.#e.sourceTable;
718
- t && t.querySelectorAll("tbody tr[grouping=\"true\"]").forEach((t) => {
719
- let n = t.querySelector("[cell-type=\"tree\"]");
720
- n && n.dataset.bind && e.push(n.dataset.bind);
721
- }), this.#n = e;
722
- };
723
- apply() {
724
- if (this.#i) return;
725
- this.#i = !0;
726
- let e = [], t = this.#e.sourceTable;
727
- t && t.querySelectorAll("tbody tr[grouping=\"true\"]").forEach((t) => {
728
- let n = t.querySelector("[cell-type=\"tree\"]");
729
- n && n.dataset.bind && e.push(n.dataset.bind);
730
- }), this.#n = e, this.#i = !1, this.#e.scrollToY(0), this.#e.view.refresh();
731
- }
732
- clear() {
733
- this.#n = [], this.#r.clear(), this.#i = !1, this.#e.scrollToY(0), this.#e.view.refresh();
734
- }
735
- setGroupMap(e) {
736
- this.#r = e;
737
- }
738
- getChildrenRowIds(e) {
739
- return this.#r.get(e) || [];
740
- }
741
- getChildrenRecords(e) {
742
- let t = this.getChildrenRowIds(e), n = this.#t.data;
743
- return t.map((e) => n.getArray(e)).filter(Boolean);
744
- }
745
- }, g = class e {
746
- static apply(t, n = [], r = []) {
747
- if (!n || n.length === 0) return {
748
- headers: [],
749
- renderItems: [],
750
- groupMap: /* @__PURE__ */ new Map()
751
- };
752
- let i = t.filter((e) => !e.__ng?.deleted), a = /* @__PURE__ */ new Map(), o = e.#t(i, n, r), s = [], c = [];
753
- return e.#e(o, 0, n, s, c, a, ""), {
754
- headers: s,
755
- renderItems: c,
756
- groupMap: a
757
- };
758
- }
759
- static #e(t, n, r, i, a, o, s) {
760
- let c = 0, l = n === r.length - 1;
761
- for (let [u, d] of t.entries()) {
762
- let t = s ? `${s}_${c++}` : `g_${c++}`, f = e.#n(d);
763
- o.set(t, f);
764
- let p = [];
765
- p[m.ID] = t, p[m.DEPTH] = n, p[m.NAME] = u, p[m.CHILDREN] = f, p.__isGroupHeader = !0, p.__groupId = t, i.push(p), a.push({
766
- type: "group",
767
- record: p,
768
- groupId: t
769
- }), !l && d instanceof Map ? e.#e(d, n + 1, r, i, a, o, t) : e.#r(d).forEach((e) => {
770
- e.__isGroupHeader = !1, e.__groupId = t, i.push(e), a.push({
771
- type: "data",
772
- record: e,
773
- groupId: t
774
- });
775
- });
776
- }
777
- }
778
- static #t(t, n, r) {
779
- let i = r.indexOf(n[0]), a = n.slice(1), o = /* @__PURE__ */ new Map();
780
- if (t.forEach((e) => {
781
- let t = i >= 0 ? e.v[i] : "(Unknown)";
782
- o.has(t) || o.set(t, []), o.get(t).push(e);
783
- }), a.length > 0) {
784
- let t = /* @__PURE__ */ new Map();
785
- for (let [n, i] of o.entries()) t.set(n, e.#t(i, a, r));
786
- return t;
787
- }
788
- return o;
789
- }
790
- static #n(t) {
791
- let n = [];
792
- if (t instanceof Map) for (let r of t.values()) n = n.concat(e.#n(r));
793
- else Array.isArray(t) && (n = n.concat(t.map((e) => e.__ng?.rowid ?? e.m?._?.[0])));
794
- return n;
795
- }
796
- static #r(t) {
797
- let n = [];
798
- if (t instanceof Map) for (let r of t.values()) n = n.concat(e.#r(r));
799
- else Array.isArray(t) && (n = n.concat(t));
800
- return n;
801
- }
802
- }, _ = class {
803
- #e = 3;
804
- #t;
805
- #n;
806
- #r;
807
- #i = /* @__PURE__ */ new Map();
808
- #a = [];
809
- #o = null;
810
- #s = null;
811
- #c = 0;
812
- #l;
813
- #u = !1;
814
- #d = !1;
815
- constructor(e) {
816
- this.#t = e.getRootNode().host, this.#n = e, this.#x();
817
- }
818
- getRowHeight() {
819
- return this.#a.reduce((e, t) => e + t, 0);
820
- }
821
- refresh = (e = !1) => {
822
- if (!this.#n.classList.contains("active")) return;
823
- let t = this.#n.querySelector(".ng-sheet-body");
824
- t && ((!this.#o || this.#o <= 0) && (this.#g(), this.#o && this.#o > 0 && this.#v()), this.#f(t.scrollTop, e), this.#n.querySelector("nine-table-vscrollbar")?.refresh());
825
- };
826
- #f = (e, t = !1) => {
827
- if (this.#d) {
828
- this.#p(e, t);
829
- return;
830
- }
831
- let n = this.#o;
832
- if (!n || n <= 0) return;
833
- let i = this.#n.view.getArray(), a = i.length;
834
- if (a === 0) {
835
- this.#n.elements.scrollHolder.style.height = "0px";
836
- return;
837
- }
838
- let o = this.#n.templateLength, s = (this.#n.elements.body.thead?.offsetHeight || 0) + (this.#n.elements.body.tfoot?.offsetHeight || 0) + this.#n.elements.body.tbody.head.offsetHeight, c = this.#n.querySelector(".ng-sheet-body").offsetHeight || 0, l = Math.max(a * n - (c - s - n), 0), u = 15e6, d = l > u, f = 1, p = l;
839
- d && (f = u / l, p = u), this.#n.elements.scrollHolder.style.height = `${p}px`;
840
- let m = d ? e / f : e, h = Math.max(0, a - 1), g = Math.min(m, l), _ = Math.max(0, Math.min(Math.floor(g / n), h)), v = g % n;
841
- this.#n.elements.left.tbody.body.style.top = this.#n.elements.body.tbody.body.style.top = this.#n.elements.right.tbody.body.style.top = `-${v}px`;
842
- let y = this.#r.firstTr, b = y && y.dataset.row !== void 0 ? parseInt(y.dataset.row, 10) : -1;
843
- (t || b !== _) && ([
844
- this.#n.elements.left.tbody.body,
845
- this.#n.elements.body.tbody.body,
846
- this.#n.elements.right.tbody.body
847
- ].forEach((e, t) => {
848
- e && e.querySelectorAll("tbody.body tr").forEach((e, t) => {
849
- let n = _ + Math.floor(t / o);
850
- if (n >= a) {
851
- e.style.display = "none", e.dataset.matrixRow = null, e.dataset.row = null, e.dataset.index = null;
852
- return;
853
- }
854
- let s = i[n];
855
- if (!s) {
856
- e.style.display = "none";
857
- return;
858
- }
859
- let c = s.m._[r.META.INDEX.ROWID];
860
- e.style.display = "", this.#h(e, s, c, n);
861
- });
862
- }), this.#n.selection.refresh());
863
- };
864
- #p = (e, t = !1) => {
865
- let n = this.#n.view.getArray() || [], r = n.length;
866
- if (r === 0) {
867
- this.#n.elements.scrollHolder.style.height = "0px";
868
- return;
869
- }
870
- let i = this.#n.querySelector(".ng-sheet-body .ng-sheet-body-content"), a = this.#n.templateLength || 1, o = (e) => {
871
- if (e.type === "group") {
872
- let t = e.record[m.DEPTH] || 0;
873
- return this.#a[t] || this.#o / a;
874
- }
875
- {
876
- let e = 0, t = this.#n.templateLength || 1, n = 0;
877
- for (let e = 0; e < t - 1; e++) n += this.#a[e] || 0;
878
- return e = this.#o - n, e > 0 ? e : this.#o;
879
- }
880
- }, s = 0, c = Array(r);
881
- for (let e = 0; e < r; e++) {
882
- let t = o(n[e]);
883
- c[e] = t, s += t;
884
- }
885
- this.#n.elements.scrollHolder.style.height = `${s}px`;
886
- let l = this.#n.clientHeight, u = 0, d = 0;
887
- for (let t = 0; t < r; t++) {
888
- let n = c[t];
889
- if (u + n > e) {
890
- d = t;
891
- break;
892
- }
893
- u += n, d = t;
894
- }
895
- let f = e - u;
896
- i && i.querySelectorAll("tbody").forEach((e) => {
897
- e.style.top = `-${Math.max(0, f)}px`;
898
- });
899
- let p = this.#r.firstTr, h = p && p.dataset.virtualIndex !== void 0 ? parseInt(p.dataset.virtualIndex, 10) : -1;
900
- if (!t && h === d) return;
901
- let g = Math.ceil(l / (this.#o / a)), _ = (this.#n.grouping.columns?.length || 1) * 15, v = d, y = Math.min(r, d + g + _), b = n.slice(v, y);
902
- [
903
- ".ng-container-body",
904
- ".ng-container-left",
905
- ".ng-container-right"
906
- ].forEach((e) => {
907
- let t = this.#n.querySelector(`.ng-sheet-body ${e}`);
908
- if (!t) return;
909
- let r = Array.from(t.querySelectorAll("tbody.body tr"));
910
- for (let e = 0; e < r.length; e += a) {
911
- let t = Math.floor(e / a), i = b[t], o = r.slice(e, e + a);
912
- if (!i || t >= b.length) {
913
- o.forEach((e) => {
914
- e.style.display = "none", e.dataset.matrixRow = null, e.dataset.row = null, e.dataset.index = null;
915
- });
916
- continue;
917
- }
918
- let s = d + t;
919
- o.forEach((e, r) => {
920
- let a = d + t;
921
- e.dataset.virtualIndex = a, e.dataset.row = i.type === "data" ? s : "";
922
- let o = e.getAttribute("grouping") === "true";
923
- if (i.type === "group") o && r === i.record[m.DEPTH] ? (e.style.display = "", this.#m(e, n, i.record, a)) : (e.style.display = "none", e.dataset.matrixRow = null, e.dataset.row = null, e.dataset.index = null);
924
- else if (o) e.style.display = "none", e.dataset.matrixRow = null, e.dataset.row = null, e.dataset.index = null;
925
- else {
926
- e.style.display = "";
927
- let t = i.record.m?.rowid ?? 0;
928
- this.#h(e, i.record, t, a);
929
- }
930
- });
931
- }
932
- }), this.#n.selection.refresh();
933
- };
934
- #m = (e, t, n, r) => {
935
- let i = this.#n.templateLength || 1, a = parseInt(e.dataset.subrow, 10) || 0, o = r * i + a, s = n[m.CHILDREN], c = this.#t.data.getArray(), l = s ? s.map((e) => c[e]).filter(Boolean) : [];
936
- e.dataset.virtualIndex = r, e.dataset.row = "", e.dataset.matrixRow = o, e.data = l, e.dataset.groupId = n[m.ID], Array.from(e.cells).forEach((e) => {
937
- e.dataset.row = r;
938
- let t = Array.from(e.children).find((e) => e.tagName.toLowerCase().startsWith("cell-") || typeof e.refresh == "function");
939
- t !== void 0 && typeof t.refresh == "function" && t?.refresh();
940
- });
941
- };
942
- #h = (e, t, n, r) => {
943
- let i = this.#n.templateLength || 1, a = parseInt(e.dataset.subrow, 10) || 0, o = r * i + a;
944
- e.dataset.index = r, e.dataset.row = n, e.dataset.matrixRow = o, e.data = t, Array.from(e.cells).forEach((e) => {
945
- e.dataset.index = r, e.dataset.row = n, Array.from(e.children).find((e) => e.tagName.toLowerCase().startsWith("cell-") && typeof e.refresh == "function")?.refresh();
946
- });
947
- };
948
- initialize = () => {
949
- this.#d = !!this.#n.sourceTable.querySelector("tbody tr[grouping='true']"), this.#o = null, this.#i.clear(), this.#r = {
950
- scrollTables: this.#n.querySelectorAll(".ng-sheet-body table"),
951
- firstTr: this.#n.querySelector(".ng-sheet-body .ng-container-body tbody.body tr")
952
- }, [
953
- ".ng-container-body",
954
- ".ng-container-left",
955
- ".ng-container-right"
956
- ].forEach((e) => {
957
- let t = this.#n.querySelector(`.ng-sheet-body ${e}`);
958
- if (!t) return;
959
- let n = t.querySelector("table");
960
- if (!n) return;
961
- let r = n.querySelector("tbody.body");
962
- if (!r) return;
963
- let i = Array.from(r.querySelectorAll("tr")).map((e) => e.cloneNode(!0));
964
- this.#i.set(e, i);
965
- });
966
- let e = this.#n.querySelector(".ng-sheet-body");
967
- e && (this.#c = e.clientHeight, this.#g(), this.#v(), this.#f(e.scrollTop, !0), e.addEventListener("scroll", (t) => {
968
- if (this.#u) return;
969
- let n = this.#o || 0;
970
- (this.#n.view.getArray()?.length || 0) * n <= e.clientHeight || (this.#f(e.scrollTop), this.#n.querySelector("nine-table-vscrollbar").refresh());
971
- }, { passive: !0 }));
972
- };
973
- scrollToDataRow(e, t = "top", n) {
974
- let r = this.#n.querySelector(".ng-sheet-body"), i = this.#n.view.getArray()?.length || 0, a = Math.max(0, Math.min(e, i - 1)), o = 0;
975
- if (this.#d) {
976
- let e = Math.max(r.scrollHeight - r.clientHeight, 1);
977
- o = a / Math.max(i - 1, 1) * e;
978
- } else {
979
- let e = this.#o, t = a * e, n = (this.#n.elements.body.thead?.offsetHeight || 0) + (this.#n.elements.body.tfoot?.offsetHeight || 0) + this.#n.elements.body.tbody.head.offsetHeight, s = r.offsetHeight || 0, c = Math.max(i * e + n - s, 0), l = 15e6, u = c > l, d = 1;
980
- u && (d = l / c), o = t * d;
981
- }
982
- this.#u = !0, r.scrollTop = o, this.#f(o), requestAnimationFrame(() => {
983
- requestAnimationFrame(() => {
984
- this.#u = !1, typeof n == "function" && n();
985
- });
986
- });
987
- }
988
- destroy = () => {
989
- this.#s &&= (this.#s.disconnect(), null);
990
- };
991
- #g = () => {
992
- if (!this.#n.classList.contains("active") || !this.#n.sourceTable) return;
993
- let e = this.#n.sourceTable?.querySelectorAll("tbody.body tr"), t = this.#n.querySelector(".ng-sheet-body .ng-container-body tbody.body");
994
- t.querySelectorAll("tr").forEach((e) => e.remove());
995
- let n = document.createDocumentFragment();
996
- e.forEach((e) => n.appendChild(e.cloneNode(!0))), t.appendChild(n);
997
- let r = t.querySelectorAll("tr");
998
- this.#a = [], r.forEach((e) => {
999
- this.#a.push(Math.max(e.offsetHeight, 24));
1000
- }), r.forEach((e) => e.remove()), this.#o = this.#a.reduce((e, t) => e + t, 0), this.#_();
1001
- };
1002
- #_ = () => {
1003
- if (this.#c > 0 && this.#o > 0) {
1004
- let e = Math.ceil(this.#c / this.#o), t = this.#e;
1005
- if (this.#d && this.#n.grouping) {
1006
- let e = this.#n.grouping.columns?.length || 1;
1007
- t += e * 15;
1008
- }
1009
- this.#l = e + t;
1010
- }
1011
- };
1012
- #v = () => {
1013
- [
1014
- ".ng-container-body",
1015
- ".ng-container-left",
1016
- ".ng-container-right"
1017
- ].forEach((e) => {
1018
- let t = this.#n.querySelector(`.ng-sheet-body ${e}`);
1019
- t && t.querySelector("tbody") && this.#y(t);
1020
- }), this.#b();
1021
- };
1022
- #y = (e) => {
1023
- let t = null;
1024
- e.classList.contains("ng-container-left") ? t = "left" : e.classList.contains("ng-container-right") && (t = "right");
1025
- let n = Array.from(this.#n.sourceTable.querySelectorAll("tbody.body tr")).map((e) => {
1026
- let n = e.cloneNode(!0);
1027
- return t === "left" ? n.querySelectorAll("th,td").forEach((e) => {
1028
- e.getAttribute("fixed") !== "left" && e.remove();
1029
- }) : t === "right" ? n.querySelectorAll("th,td").forEach((e) => {
1030
- e.getAttribute("fixed") !== "right" && e.remove();
1031
- }) : n.querySelectorAll("[fixed=left], [fixed=right]").forEach((e) => {
1032
- e.remove();
1033
- }), n;
1034
- });
1035
- if (n.length === 0) return;
1036
- let r = e.querySelector("tbody.body");
1037
- if (!r) return;
1038
- r.querySelectorAll("tr").forEach((e) => e.remove());
1039
- let i = document.createDocumentFragment();
1040
- for (let e = 0; e < this.#l; e++) n.forEach((e) => i.appendChild(e.cloneNode(!0)));
1041
- r.appendChild(i), e.classList.contains("ng-container-body") && (this.#r.firstTr = r.querySelector("tr"));
1042
- };
1043
- #b = () => {
1044
- let e = this.#n.querySelector(".ng-sheet-body .ng-container-left table"), t = this.#n.querySelector(".ng-sheet-body .ng-container-body table"), n = this.#n.querySelector(".ng-sheet-body .ng-container-right table");
1045
- if (t) {
1046
- let r = e ? Array.from(e.querySelectorAll("tbody tr")) : [], i = Array.from(t.querySelectorAll("tbody tr")), a = n ? Array.from(n.querySelectorAll("tbody tr")) : [], o = Math.max(r.length, i.length, a.length);
1047
- for (let e = 0; e < o; e++) {
1048
- let t = [
1049
- r[e]?.getBoundingClientRect().height || 0,
1050
- i[e]?.getBoundingClientRect().height || 0,
1051
- a[e]?.getBoundingClientRect().height || 0
1052
- ], n = Math.max(...t);
1053
- n > 0 && (r[e] && (r[e].style.height = `${n}px`), i[e] && (i[e].style.height = `${n}px`), a[e] && (a[e].style.height = `${n}px`));
1054
- }
1055
- }
1056
- };
1057
- #x = () => {
1058
- this.#n && this.#n instanceof HTMLElement && (this.#s = new ResizeObserver((e) => {
1059
- for (let t of e) {
1060
- if (!t.target.classList.contains("active")) continue;
1061
- let e = t.contentRect.height;
1062
- t.contentRect.width > 0 && this.#n.isAutoFitCol && this.#n.autoFit(!0), e > 0 && this.#c !== e && (this.#c = e, this.#_(), this.#o !== null && (this.#v(), this.refresh()));
1063
- }
1064
- }), this.#s.observe(this.#n));
1065
- };
1066
- }, v = class e {
1067
- static compile(t) {
1068
- let n = t.cloneNode(!0);
1069
- return e.resetColIndex(n, n.querySelectorAll("thead tr")), e.resetColIndex(n, n.querySelectorAll("tbody.body tr[grouping=\"true\"]")), e.resetColIndex(n, n.querySelectorAll("tbody.body tr:not([grouping=\"true\"])")), e.resetColIndex(n, n.querySelectorAll("tfoot tr")), e.#e(n), n;
1070
- }
1071
- static recompile(t) {
1072
- return e.resetColIndex(t, t.querySelectorAll("thead tr")), e.resetColIndex(t, t.querySelectorAll("tbody.body tr[grouping=\"true\"]")), e.resetColIndex(t, t.querySelectorAll("tbody.body tr:not([grouping=\"true\"])")), e.resetColIndex(t, t.querySelectorAll("tfoot tr")), e.#e(t), t;
1073
- }
1074
- static #e(e) {
1075
- e.querySelectorAll("colgroup col").forEach((t, n) => {
1076
- t.setAttribute("data-col", n);
1077
- let r = t.getAttribute("fixed");
1078
- e.querySelectorAll(`[data-col="${n}"]`).forEach((e) => {
1079
- r ? e.setAttribute("fixed", r) : e.removeAttribute("fixed");
1080
- });
1081
- });
1082
- }
1083
- static resetColIndex(e, t) {
1084
- let n = e.querySelectorAll("colgroup col"), r = Array.from({ length: t.length }, () => Array(n.length).fill(null));
1085
- t.forEach((e, i) => {
1086
- e.dataset.subrow = i;
1087
- let a = 0;
1088
- e.querySelectorAll("th, td").forEach((e) => {
1089
- for (; a < n.length && r[i][a] !== null;) a++;
1090
- e.dataset.col = a;
1091
- let o = e.rowSpan || 1, s = e.colSpan || 1;
1092
- for (let c = 0; c < o; c++) for (let o = 0; o < s; o++) i + c < t.length && a + o < n.length && (r[i + c][a + o] = e);
1093
- a += s;
1094
- });
1095
- });
1096
- }
1097
- }, y = class {
1098
- #e;
1099
- #t = {
1100
- startRow: -1,
1101
- startCol: -1,
1102
- endRow: -1,
1103
- endCol: -1
1104
- };
1105
- constructor(e) {
1106
- this.#e = e, this.#r();
1107
- }
1108
- #n(e) {
1109
- if (!e) return {
1110
- dataRow: -1,
1111
- subRowIndex: -1,
1112
- matrixRow: -1
1113
- };
1114
- let t = parseInt(e.dataset.index, 10);
1115
- if (isNaN(t)) return {
1116
- dataRow: -1,
1117
- subRowIndex: -1,
1118
- matrixRow: -1
1119
- };
1120
- let n = e.closest("tbody"), r = Array.from(n.querySelectorAll("tr")).filter((e) => parseInt(e.dataset.index, 10) === t), i = r.indexOf(e), a = r.length > 0 ? r.length : 1;
1121
- return {
1122
- dataRow: t,
1123
- subRowIndex: i,
1124
- matrixRow: t * a + (i >= 0 ? i : e.sectionRowIndex % a)
1125
- };
1126
- }
1127
- setFocus(e, t) {
1128
- this.#e.querySelectorAll("tr.selected-start").forEach((e) => {
1129
- e.classList.remove("selected-start"), e.querySelectorAll("td.selected-start").forEach((e) => {
1130
- e.classList.remove("selected-start");
1131
- });
1132
- });
1133
- let n = this.#e.querySelector(`.ng-sheet-body-content tr[data-matrix-row="${e}"] td[data-col="${t}"]`);
1134
- n && (n.classList.add("selected-start"), n.closest("tr")?.classList.add("selected-start"));
1135
- }
1136
- setRange(e, t, n, r) {
1137
- let i = Math.min(e, n), a = Math.max(e, n), o = Math.min(t, r), s = Math.max(t, r), c = this.#e.querySelectorAll(".ng-container-left, .ng-container-body, .ng-container-right"), l = !0, u = 0;
1138
- for (; l && u < 5;) l = !1, u++, c.forEach((e) => {
1139
- Array.from(e.querySelectorAll("tbody tr")).filter((e) => e.style.display !== "none").forEach((e) => {
1140
- let { matrixRow: t } = this.#n(e);
1141
- t < 0 || e.querySelectorAll("td, th").forEach((e) => {
1142
- let n = parseInt(e.dataset.col, 10);
1143
- if (isNaN(n)) return;
1144
- let r = parseInt(e.rowSpan || 1, 10), c = parseInt(e.colSpan || 1, 10), u = t + r - 1, d = n + c - 1;
1145
- if (u >= i && t <= a && d >= o && n <= s) {
1146
- let e = Math.min(i, t), r = Math.max(a, u), c = Math.min(o, n), f = Math.max(s, d);
1147
- (e !== i || r !== a || c !== o || f !== s) && (i = e, a = r, o = c, s = f, l = !0);
1148
- }
1149
- });
1150
- });
1151
- });
1152
- this.#t = {
1153
- startRow: i,
1154
- startCol: o,
1155
- endRow: a,
1156
- endCol: s
1157
- }, this.render();
1158
- }
1159
- refresh = () => {
1160
- this.render();
1161
- };
1162
- render = () => {
1163
- let { startRow: e, startCol: t, endRow: n, endCol: r } = this.#t, i = this.#e.querySelectorAll(".ng-container-left, .ng-container-body, .ng-container-right");
1164
- i.forEach((e) => {
1165
- e.querySelectorAll(".selected, .selected-top, .selected-bottom, .selected-left, .selected-right, .selected-start").forEach((e) => {
1166
- e.classList.remove("selected", "selected-top", "selected-bottom", "selected-left", "selected-right", "selected-start");
1167
- }), e.querySelectorAll("tr.selected-start").forEach((e) => {
1168
- e.classList.remove("selected-start");
1169
- });
1170
- }), e < 0 || t < 0 || i.forEach((i) => {
1171
- Array.from(i.querySelectorAll("tbody tr")).filter((e) => e.style.display !== "none").forEach((i) => {
1172
- let { matrixRow: a } = this.#n(i);
1173
- a < 0 || i.querySelectorAll("td, th").forEach((i) => {
1174
- let o = parseInt(i.dataset.col, 10);
1175
- if (isNaN(o)) return;
1176
- let s = parseInt(i.rowSpan || 1, 10), c = parseInt(i.colSpan || 1, 10), l = a + s - 1, u = o + c - 1;
1177
- l >= e && a <= n && u >= t && o <= r && (i.classList.add("selected"), a <= e && i.classList.add("selected-top"), l >= n && i.classList.add("selected-bottom"), o <= t && i.classList.add("selected-left"), u >= r && i.classList.add("selected-right"));
1178
- });
1179
- });
1180
- });
1181
- };
1182
- #r() {
1183
- let e = this.#e.querySelector(".ng-sheet-body");
1184
- e && e.addEventListener("mousedown", (e) => {
1185
- if (e.button !== 0) return;
1186
- let t = e.target.closest("td, th");
1187
- if (!t || t.dataset.row === void 0 || t.dataset.col === void 0) return;
1188
- this.#e.style.userSelect = "none", this.#e.style.webkitUserSelect = "none";
1189
- let n = t.closest("tr"), { matrixRow: r } = this.#n(n), i = parseInt(t.dataset.col, 10);
1190
- if (r < 0) {
1191
- this.#e.style.userSelect = "", this.#e.style.webkitUserSelect = "";
1192
- return;
1193
- }
1194
- this.setFocus(r, i), this.setRange(r, i, r, i);
1195
- let a = r, o = i, s = (e) => {
1196
- let t = document.elementFromPoint(e.clientX, e.clientY)?.closest("td, th");
1197
- if (!t || !this.#e.contains(t)) {
1198
- let n = this.#e.querySelectorAll(".ng-sheet-body-content tbody tr td, .ng-sheet-body-content tbody tr:not(.nodata) th");
1199
- for (let r of n) {
1200
- let n = r.getBoundingClientRect();
1201
- if (e.clientX >= n.left && e.clientX <= n.right && e.clientY >= n.top && e.clientY <= n.bottom) {
1202
- t = r;
1203
- break;
1204
- }
1205
- }
1206
- }
1207
- if (!t || t.dataset.row === void 0 || t.dataset.col === void 0) return;
1208
- let n = t.closest("tr"), { matrixRow: s } = this.#n(n), c = parseInt(t.dataset.col, 10);
1209
- s < 0 || (a !== s || o !== c) && (a = s, o = c, this.setRange(r, i, s, c));
1210
- }, c = () => {
1211
- this.#e.style.userSelect = "", this.#e.style.webkitUserSelect = "", document.removeEventListener("mousemove", s), document.removeEventListener("mouseup", c);
1212
- };
1213
- document.addEventListener("mousemove", s), document.addEventListener("mouseup", c);
1214
- });
1215
- }
1216
- }, b = class {
1217
- #e;
1218
- #t;
1219
- #n = null;
1220
- #r = null;
1221
- constructor(e) {
1222
- this.#e = e, this.#t = e.getRootNode().host, this.#g();
1223
- }
1224
- get currentCell() {
1225
- return this.#n;
1226
- }
1227
- set currentCell(e) {
1228
- if (!e) return;
1229
- this.#n = e, e.focus({ preventScroll: !0 }), this.#r = e.closest("tr");
1230
- let t = parseInt(this.#r.dataset.matrixRow, 10);
1231
- this.#e.selection.setFocus(t, this.#n.dataset.col);
1232
- }
1233
- #i = (e, t) => {
1234
- if (t) {
1235
- switch (e.code) {
1236
- case "Tab":
1237
- e.shiftKey ? this.#p(t) || t.scrollIntoView({
1238
- inline: "nearest",
1239
- block: "nearest"
1240
- }) : this.#m(t) || t.scrollIntoView({
1241
- inline: "nearest",
1242
- block: "nearest"
1243
- });
1244
- break;
1245
- case "ArrowRight":
1246
- this.#m(t) || t.scrollIntoView({
1247
- inline: "nearest",
1248
- block: "nearest"
1249
- });
1250
- break;
1251
- case "ArrowLeft": this.#p(t) || t.scrollIntoView({
1252
- inline: "nearest",
1253
- block: "nearest"
1254
- });
1255
- }
1256
- this.currentCell = t, this.#e.selection.setRange(this.#r.dataset.matrixRow, t.dataset.col, this.#r.dataset.matrixRow, t.dataset.col);
1257
- }
1258
- };
1259
- #a = (e, t) => {
1260
- if (t) {
1261
- let n = !1;
1262
- switch (e.code) {
1263
- case "Enter":
1264
- e.shiftKey, this.#f(t) && (n = !0);
1265
- break;
1266
- case "ArrowDown":
1267
- this.#f(t) && (n = !0);
1268
- break;
1269
- case "ArrowUp": this.#d(t) && (n = !0);
1270
- }
1271
- if (n) {
1272
- this.currentCell = t, this.#e.selection.setRange(this.#r.dataset.matrixRow, t.dataset.col, this.#r.dataset.matrixRow, t.dataset.col);
1273
- return;
1274
- }
1275
- }
1276
- let n = parseInt(this.#r.dataset.index, 10), r = -1;
1277
- switch (e.code) {
1278
- case "Enter":
1279
- if (e.shiftKey) {
1280
- let e = this.#h();
1281
- r = Math.max(n - e + 0, 0);
1282
- } else r = Math.min(n, this.#e.view.count());
1283
- break;
1284
- case "ArrowDown":
1285
- r = Math.min(n, this.#e.view.count());
1286
- break;
1287
- case "ArrowUp":
1288
- let t = this.#h();
1289
- r = Math.max(n - t + 0, 0);
1290
- }
1291
- if (r < 0) return;
1292
- let i = parseInt(this.#r.dataset.matrixRow, 10), a = parseInt(this.#n.dataset.col, 10), o = parseInt(this.#n.rowSpan, 10) || 1;
1293
- switch (e.code) {
1294
- case "ArrowDown":
1295
- i += o;
1296
- break;
1297
- case "ArrowUp": i--;
1298
- }
1299
- this.#e.rowManager.scrollToDataRow(r, null, () => {
1300
- let e = this.#c(i, a);
1301
- e && (this.currentCell = e, this.#e.selection.setRange(this.#r.dataset.matrixRow, e.dataset.col, this.#r.dataset.matrixRow, e.dataset.col));
1302
- });
1303
- };
1304
- moveCell = (e) => {
1305
- if (e.target.tagName === "INPUT" && (["text"].includes(e.target.type) && [
1306
- "ArrowLeft",
1307
- "ArrowRight",
1308
- "Home",
1309
- "End"
1310
- ].includes(e.code) || [
1311
- "date",
1312
- "datetime-local",
1313
- "time",
1314
- "week",
1315
- "month"
1316
- ].includes(e.target.type)) || !this.#n || !this.#r) return;
1317
- let t;
1318
- switch (e.code) {
1319
- case "Tab":
1320
- t = e.shiftKey ? this.#s() : this.#o();
1321
- break;
1322
- case "ArrowRight":
1323
- t = this.#o();
1324
- break;
1325
- case "ArrowLeft":
1326
- t = this.#s();
1327
- break;
1328
- case "Enter":
1329
- t = e.shiftKey ? this.#l() : this.#u();
1330
- break;
1331
- case "ArrowDown":
1332
- t = this.#u();
1333
- break;
1334
- case "ArrowUp": t = this.#l();
1335
- }
1336
- e.preventDefault(), [
1337
- "ArrowLeft",
1338
- "ArrowRight",
1339
- "Tab"
1340
- ].includes(e.code) ? this.#i(e, t) : [
1341
- "Enter",
1342
- "ArrowUp",
1343
- "ArrowDown"
1344
- ].includes(e.code) && this.#a(e, t);
1345
- };
1346
- #o = () => {
1347
- let e = parseInt(this.#n.dataset.col, 10), t = parseInt(this.#n.colSpan, 10) || 1, n = parseInt(this.#r.dataset.index, 10), r = parseInt(this.#r.dataset.matrixRow, 10), i = e + t, a = this.#e.querySelector(`tbody tr[data-matrix-row="${r}"] td[data-col="${i}"]`);
1348
- return a ||= this.#e.querySelector(`tbody tr[data-index="${n}"] td[data-col="${i}"]`), a;
1349
- };
1350
- #s = () => {
1351
- let e = parseInt(this.#n.dataset.col, 10), t = parseInt(this.#r.dataset.index, 10), n = parseInt(this.#r.dataset.matrixRow, 10), r;
1352
- for (let i = e - 1; i >= 0 && (r = this.#e.querySelector(`tbody tr[data-matrix-row="${n}"] td[data-col="${i}"]`), r ||= this.#e.querySelector(`tbody tr[data-index="${t}"] td[data-col="${i}"]`), !r); i--);
1353
- return r;
1354
- };
1355
- #c = (e, t) => {
1356
- let n = this.#e.querySelector(`tbody tr[data-matrix-row="${e}"]`);
1357
- if (!n) return;
1358
- let r = parseInt(n.dataset.index, 10), i = this.#e.querySelector(`tbody tr[data-matrix-row="${e}"] td[data-col="${t}"]`);
1359
- return i || (this.#e.querySelectorAll(`tbody tr[data-matrix-row="${e}"] td`).forEach((e) => {
1360
- let n = parseInt(e.dataset.col, 10), r = parseInt(e.colSpan, 10) || 1;
1361
- t >= n && t < n + r && (i = e);
1362
- }), i || (i = this.#e.querySelector(`tbody tr[data-index="${r}"] td[data-col="${t}"]`), i || this.#e.querySelectorAll(`tbody tr[data-index="${r}"] td`).forEach((e) => {
1363
- let n = parseInt(e.dataset.col, 10), r = parseInt(e.colSpan, 10) || 1;
1364
- t >= n && t < n + r && (i = e);
1365
- }))), i;
1366
- };
1367
- #l = () => {
1368
- let e = parseInt(this.#n.dataset.col, 10), t = parseInt(this.#r.dataset.matrixRow, 10);
1369
- return this.#c(t - 1, e);
1370
- };
1371
- #u = () => {
1372
- let e = parseInt(this.#n.dataset.col, 10), t = parseInt(this.#r.dataset.matrixRow, 10), n = parseInt(this.#n.rowSpan, 10) || 1;
1373
- return this.#c(t + n, e);
1374
- };
1375
- #d = (e) => {
1376
- let t = this.#e.querySelector(".ng-sheet-body");
1377
- if (!t || !e) return !0;
1378
- let n = e.getBoundingClientRect(), r = t.getBoundingClientRect(), i = t.querySelector("thead")?.offsetHeight || 0;
1379
- return n.top >= r.top + i;
1380
- };
1381
- #f = (e) => {
1382
- let t = this.#e.querySelector(".ng-sheet-body");
1383
- if (!t || !e) return !0;
1384
- let n = e.getBoundingClientRect(), r = t.getBoundingClientRect();
1385
- return n.bottom <= r.bottom;
1386
- };
1387
- #p = (e) => {
1388
- let t = this.#e.querySelector(".ng-container-body");
1389
- if (!t || !e) return !0;
1390
- let n = e.getBoundingClientRect(), r = t.getBoundingClientRect();
1391
- return n.left >= r.left;
1392
- };
1393
- #m = (e) => {
1394
- let t = this.#e.querySelector(".ng-container-body");
1395
- if (!t || !e) return !0;
1396
- let n = e.getBoundingClientRect(), r = t.getBoundingClientRect();
1397
- return n.right <= r.right;
1398
- };
1399
- #h = () => {
1400
- let e = this.#e.querySelector(".ng-sheet-body"), t = e.clientHeight - (e.querySelector("thead")?.offsetHeight || 0), n = this.#e.rowManager.getRowHeight();
1401
- return Math.max(1, Math.floor(t / n));
1402
- };
1403
- #g() {
1404
- this.#e.addEventListener("mousedown", (e) => {
1405
- if (e.button !== 0) return;
1406
- let t = e.target.closest("td, th");
1407
- t && t.dataset.index !== void 0 && t.dataset.col !== void 0 && (this.currentCell = t);
1408
- }), this.#e.addEventListener("keydown", (e) => {
1409
- [
1410
- "Enter",
1411
- "Tab",
1412
- "ArrowUp",
1413
- "ArrowDown",
1414
- "ArrowLeft",
1415
- "ArrowRight"
1416
- ].includes(e.code) && this.moveCell(e);
1417
- });
1418
- }
1419
- }, x = 2, S = class {
1420
- #e;
1421
- #t;
1422
- #n;
1423
- #r;
1424
- #i = null;
1425
- #a = null;
1426
- #o = null;
1427
- #s = null;
1428
- #c = 0;
1429
- #l = 0;
1430
- #u = 0;
1431
- #d = 0;
1432
- #f = 0;
1433
- constructor(e) {
1434
- this.#e = e, this.#t = e.getRootNode().host, this.#n = this.#e.querySelector("nine-table-col-resizer-panel"), this.#r = this.#n.querySelector(".resizer-overlay"), this.bindEvents();
1435
- }
1436
- destroy() {
1437
- this.#e.removeEventListener("pointermove", this.#h), this.#e.removeEventListener("pointerdown", this.#g), this.#e.removeEventListener("dblclick", this.#b);
1438
- }
1439
- refreshLayout(e = "body") {
1440
- let t = Array.from(this.#e.querySelectorAll(`.ng-container-${e}`));
1441
- if (t.length !== 0) {
1442
- if (e === "left" || e === "right" || !this.#e.isAutoFitCol && t[0].querySelector("table")?.getAttribute("auto-fit-col") !== "true") {
1443
- let n = t[0].querySelector("table colgroup");
1444
- if (!n) return;
1445
- let r = 0, i = {};
1446
- Array.from(n.querySelectorAll("col")).forEach((e) => {
1447
- let t = e.getAttribute("data-col"), n = parseInt(e.getAttribute("width"), 10);
1448
- isNaN(n) || (i[t] = n, r += n);
1449
- }), t.forEach((t) => {
1450
- let n = t.querySelectorAll("table");
1451
- e === "body" ? n.forEach((e) => {
1452
- e.style.width = `${r}px`;
1453
- }) : (t.style.flex = `0 0 ${r}px`, t.style.width = `${r}px`, t.style.minWidth = `${r}px`, t.style.maxWidth = `${r}px`, n.forEach((e) => {
1454
- e.style.width = `${r}px`, e.style.minWidth = `${r}px`, e.style.maxWidth = `${r}px`, Object.entries(i).forEach(([t, n]) => {
1455
- e.querySelectorAll(`th[data-col="${t}"], td[data-col="${t}"]`).forEach((e) => {
1456
- e.style.width = `${n}px`, e.style.minWidth = `${n}px`, e.style.maxWidth = `${n}px`;
1457
- });
1458
- });
1459
- }));
1460
- });
1461
- } else t.forEach((e) => {
1462
- e.querySelectorAll("table").forEach((e) => {});
1463
- });
1464
- this.#e.querySelector("nine-table-hscrollbar")?.refresh();
1465
- }
1466
- }
1467
- setColumnWidth(e, t, n = null) {
1468
- let r = [];
1469
- if (r = Array.from(this.#e.querySelectorAll(`table colgroup col[data-col="${e}"]`)), r.length === 0) return;
1470
- let i = r[0].closest(".ng-container-left, .ng-container-body, .ng-container-right"), a = n || (i?.classList.contains("ng-container-left") ? "left" : i?.classList.contains("ng-container-right") ? "right" : "body");
1471
- r.forEach((e) => {
1472
- e.setAttribute("width", t), e.style.width = `${t}px`;
1473
- });
1474
- let o = this.#e.sourceTable?.querySelector(`colgroup col[data-col="${e}"]`);
1475
- o && (o.setAttribute("width", t), o.style.width = `${t}px`), this.refreshLayout(a), (a === "left" || a === "right") && this.refreshLayout("body"), this.#e.rowManager?.refresh();
1476
- }
1477
- #p(e) {
1478
- if (this.#e.isAutoFitCol) return !0;
1479
- let t = e?.closest("table");
1480
- return !!(t && t.getAttribute("auto-fit-col") === "true");
1481
- }
1482
- bindEvents() {
1483
- this.#e.addEventListener("pointermove", this.#h), this.#e.addDebounseEventListener("dblclick", this.#b, "pointerdown", this.#g);
1484
- }
1485
- #m(e) {
1486
- let t = e.closest(".ng-container-left, .ng-container-body, .ng-container-right");
1487
- return t ? t.classList.contains("ng-container-left") ? "left" : t.classList.contains("ng-container-right") ? "right" : "body" : null;
1488
- }
1489
- #h = (e) => {
1490
- let t = e.target.closest("thead");
1491
- if (!t) return;
1492
- let n = e.target.closest("th, td");
1493
- if (t.querySelectorAll(".resizable-edge").forEach((e) => {
1494
- e !== n && e.classList.remove("resizable-edge");
1495
- }), !n || n.dataset.col === void 0 || n.getAttribute("collapsed") === "true") return;
1496
- let r = n.getBoundingClientRect(), i = e.clientX - r.left, a = i <= x, o = r.width - i <= x;
1497
- if (a) {
1498
- let e = n.previousElementSibling;
1499
- if (!e || e.getAttribute("collapsed") === "true") {
1500
- n.classList.remove("resizable-edge");
1501
- return;
1502
- }
1503
- }
1504
- a || o ? n.classList.add("resizable-edge") : n.classList.remove("resizable-edge");
1505
- };
1506
- #g = (e) => {
1507
- if (!e.actualTarget.closest("thead")) return;
1508
- let t = e.actualTarget.closest("th, td");
1509
- if (!t || !t.classList.contains("resizable-edge")) return;
1510
- e.preventDefault();
1511
- let n = t.getBoundingClientRect(), r = e.clientX - n.left, i = t;
1512
- if (r <= x) {
1513
- let e = t.previousElementSibling;
1514
- if (e && e.dataset.col !== void 0 && e.getAttribute("collapsed") !== "true") i = e;
1515
- else if (!t.previousElementSibling) return;
1516
- }
1517
- this.#s = i, this.#o = this.#m(i);
1518
- let a = this.#e.querySelector(`.ng-container-${this.#o}`);
1519
- if (!a) return;
1520
- let o = parseInt(i.dataset.col, 10), s = i.colSpan || 1;
1521
- if (this.#i = o + s - 1, this.#p(i)) {
1522
- this.#a = this.#i + 1;
1523
- let e = a.querySelector(`col[data-col="${this.#a}"]`);
1524
- e ? this.#u = parseInt(e.getAttribute("width"), 10) || 100 : this.#a = null;
1525
- } else this.#a = null;
1526
- let c = i.getBoundingClientRect(), l = this.#e.getBoundingClientRect();
1527
- this.#d = c.width, this.#f = c.left - l.left;
1528
- let u = a.querySelector(`col[data-col="${this.#i}"]`)?.getAttribute("width");
1529
- this.#l = u && !isNaN(parseInt(u, 10)) ? parseInt(u, 10) : c.width / s, this.#c = e.clientX, this.#n && (this.#n.classList.add("active"), this.#_(e.clientX)), window.addEventListener("pointermove", this.#v), window.addEventListener("pointerup", this.#y, { once: !0 });
1530
- };
1531
- #_(e) {
1532
- let t = e - this.#c, n = this.#p(this.#s);
1533
- if (n && this.#a !== null) {
1534
- let e = this.#u - 16, n = -(this.#l - 16);
1535
- t = Math.max(n, Math.min(t, e));
1536
- }
1537
- let r = Math.max(16, this.#l + t), i = e - this.#s.getBoundingClientRect().left;
1538
- if (n && this.#a !== null) {
1539
- let e = this.#d + (this.#u - 16);
1540
- i = Math.min(i, e);
1541
- }
1542
- let a = Math.max(16, i);
1543
- this.#n && (this.#n.style.setProperty("--col-resizer-tooltip-left", `${this.#f}px`), this.#n.style.setProperty("--col-resizer-tooltip-width", `${a}px`));
1544
- let o = this.#r?.querySelector(".size-badge");
1545
- o && (o.textContent = `${Math.round(r)}px`);
1546
- }
1547
- #v = (e) => {
1548
- this.#_(e.clientX);
1549
- };
1550
- #y = (e) => {
1551
- window.removeEventListener("pointermove", this.#v);
1552
- let t = e.clientX - this.#c, n = this.#p(this.#s), r = 0;
1553
- if (n && this.#a !== null) {
1554
- let e = Math.max(16, this.#l + t), n = this.#l + this.#u - e;
1555
- n < 16 && (n = 16, e = this.#l + this.#u - 16), this.setColumnWidth(this.#i, e, this.#o), this.setColumnWidth(this.#a, n, this.#o), r = e;
1556
- } else {
1557
- let e = Math.max(16, this.#l + t);
1558
- this.#i !== null && this.#o && (this.setColumnWidth(this.#i, e, this.#o), r = e);
1559
- }
1560
- if (this.#s) {
1561
- let e = this.#s;
1562
- e.getAttribute("collapsed") !== "true" && r > 20 && (e.dataset.expandWidth = String(r));
1563
- }
1564
- this.#n && (this.#r?.classList.add("fade-out"), setTimeout(() => {
1565
- this.#n.classList.remove("active"), this.#r?.classList.remove("fade-out");
1566
- }, 150)), this.#i = null, this.#a = null, this.#o = null, this.#s = null;
1567
- };
1568
- #b = (e) => {
1569
- let t = e.target.closest("th, td");
1570
- if (!t || !t.classList.contains("resizable-edge")) return;
1571
- let n = t.getBoundingClientRect();
1572
- e.clientX - n.left <= x && (t = t.previousElementSibling);
1573
- let r = parseInt(t.dataset.col, 10), i = this.#e.querySelector(`tbody.body [data-col="${r}"]`);
1574
- if (!i || !i.dataset.bind || i.classList.contains("CELL-RADIO")) return;
1575
- let a = 0;
1576
- Array.from(i.firstElementChild.children).forEach((e) => {
1577
- switch (e.tagName) {
1578
- case "SPAN":
1579
- a += 8;
1580
- break;
1581
- case "DIV":
1582
- a += 8;
1583
- break;
1584
- case "BUTTON":
1585
- a += 32;
1586
- break;
1587
- case "SELECT":
1588
- a += 32;
1589
- break;
1590
- case "INPUT": switch ((e.type || "text").toLowerCase()) {
1591
- case "checkbox":
1592
- case "radio":
1593
- a += 12;
1594
- break;
1595
- case "button":
1596
- case "submit":
1597
- case "reset":
1598
- case "image":
1599
- a += 16;
1600
- break;
1601
- case "color":
1602
- case "file":
1603
- case "range":
1604
- a += 24;
1605
- break;
1606
- case "hidden":
1607
- a += 0;
1608
- break;
1609
- default: a += 16;
1610
- }
1611
- }
1612
- });
1613
- let o = this.#t.fields.get().indexOf(i.dataset.bind), s = window.getComputedStyle(i).font || "12px sans-serif", c = t.innerText || "", l = (nine.measureTextSize(c, s).width || 0) + 16;
1614
- this.#t.execute(() => {
1615
- this.#e.view.getArray().forEach((e, t) => {
1616
- let n = String(i.dataset.expr ? this.#t.exprEngine.evaluate(i.dataset.expr, e, t) : e.v[o] ?? "").trim(), r = nine.measureTextSize(n, s);
1617
- r.width && r.width > l && (l = r.width);
1618
- });
1619
- let e = Math.max(32, Math.min(400, Math.ceil(l) + a));
1620
- this.setColumnWidth(i.dataset.col, e, this.#m(t));
1621
- });
1622
- };
1623
- }, C = class extends HTMLElement {
1624
- constructor() {
1625
- super();
1626
- }
1627
- connectedCallback() {
1628
- this.#e();
1629
- }
1630
- #e = () => {
1631
- this.innerHTML = "\n <div class=\"resizer-overlay\">\n <span class=\"size-badge\">0px</span>\n </div>\n ";
1632
- };
1633
- };
1634
- customElements.get("nine-table-col-resizer-panel") || customElements.define("nine-table-col-resizer-panel", C);
1635
- // src/col/ColMover.js
1636
- var w = class {
1637
- #e;
1638
- #t;
1639
- #n;
1640
- #r = !1;
1641
- #i = null;
1642
- #a = null;
1643
- #o = null;
1644
- #s = 0;
1645
- #c = null;
1646
- constructor(e) {
1647
- this.#e = e, this.#t = this.#e.querySelector(".ng-col-mover-grip"), this.#n = this.#e.querySelector(".ng-col-mover-indi"), this.bindEvents();
1648
- }
1649
- bindEvents() {
1650
- this.#e.addEventListener("pointerdown", this.#p);
1651
- }
1652
- #l() {
1653
- let e = this.#e.getRootNode()?.host;
1654
- return this.#e.getAttribute("col-movable") === "true" || e?.getAttribute("col-movable") === "true";
1655
- }
1656
- #u(e, t) {
1657
- let n = this.#e.getRootNode(), r = n.elementFromPoint ? n.elementFromPoint(e, t) : document.elementFromPoint(e, t);
1658
- for (; r && r.shadowRoot && r.shadowRoot.elementFromPoint;) {
1659
- let n = r.shadowRoot.elementFromPoint(e, t);
1660
- if (!n || n === r) break;
1661
- r = n;
1662
- }
1663
- return r;
1664
- }
1665
- #d(e) {
1666
- if (!e || e.dataset.col === void 0) return null;
1667
- let t = parseInt(e.dataset.col, 10), n = e.colSpan || 1, r = t + n - 1, i = e.closest("tr")?.sectionRowIndex ?? 0, a = e.closest("table");
1668
- if (!a) return {
1669
- startCol: t,
1670
- colSpan: n,
1671
- endCol: r,
1672
- rowIndex: i,
1673
- isGroup: !1,
1674
- parentGroupRange: null,
1675
- isValidGroup: !0
1676
- };
1677
- let o = a.querySelectorAll("thead th, thead td"), s = !1, c = !0, l = null;
1678
- for (let a of o) {
1679
- if (a === e || a.dataset.col === void 0) continue;
1680
- let o = parseInt(a.dataset.col, 10), u = a.colSpan || 1, d = o + u - 1;
1681
- (a.closest("tr")?.sectionRowIndex ?? 0) < i && o <= t && d >= r && u > n && (l ? (l.startCol = Math.max(l.startCol, o), l.endCol = Math.min(l.endCol, d)) : l = {
1682
- startCol: o,
1683
- endCol: d
1684
- }), d < t || o > r || (o >= t && d <= r ? u < n && (s = !0) : (o < t || d > r) && (o <= t && d >= r || (c = !1)));
1685
- }
1686
- let u = s && c;
1687
- return {
1688
- startCol: t,
1689
- colSpan: u ? n : 1,
1690
- endCol: u ? r : t,
1691
- rowIndex: i,
1692
- isGroup: u,
1693
- parentGroupRange: l,
1694
- isValidGroup: c
1695
- };
1696
- }
1697
- #f(e) {
1698
- let t = this.#d(e);
1699
- if (!t) return null;
1700
- let { startCol: n, endCol: r, isGroup: i } = t, a = e.closest("table");
1701
- if (!a) return null;
1702
- let o = Infinity, s = -Infinity, c = Infinity, l = -Infinity, u = [];
1703
- if (a.querySelectorAll("thead th, thead td").forEach((t) => {
1704
- if (t.dataset.col === void 0) return;
1705
- let a = parseInt(t.dataset.col, 10), d = a + (t.colSpan || 1) - 1;
1706
- if (i ? a >= n && d <= r : t === e) {
1707
- let e = t.getBoundingClientRect();
1708
- o = Math.min(o, e.left), s = Math.max(s, e.right), c = Math.min(c, e.top), l = Math.max(l, e.bottom);
1709
- let n = window.getComputedStyle(t);
1710
- u.push({
1711
- el: t,
1712
- rect: e,
1713
- style: n
1714
- });
1715
- }
1716
- }), u.length === 0) return null;
1717
- let d = s - o, f = l - c, p = document.createElement("div");
1718
- return p.className = "grip-header-content", p.style.position = "relative", p.style.width = `${d}px`, p.style.height = `${f}px`, u.forEach(({ el: e, rect: t, style: n }) => {
1719
- let r = e.cloneNode(!0);
1720
- r.style.position = "absolute", r.style.left = `${t.left - o}px`, r.style.top = `${t.top - c}px`, r.style.width = `${t.width}px`, r.style.minWidth = `${t.width}px`, r.style.maxWidth = "none", r.style.height = `${t.height}px`, r.style.boxSizing = "border-box", r.style.margin = "0", r.style.backgroundColor = n.backgroundColor !== "transparent" && n.backgroundColor !== "rgba(0, 0, 0, 0)" ? n.backgroundColor : "#f9fafb", r.style.color = n.color, r.style.font = n.font, r.style.fontWeight = n.fontWeight, r.style.fontSize = n.fontSize, r.style.textAlign = n.textAlign, r.style.padding = n.padding, r.style.border = n.border, r.style.borderRight = n.borderRight, r.style.borderBottom = n.borderBottom, r.style.display = "flex", r.style.alignItems = "center", r.style.justifyContent = n.textAlign === "center" ? "center" : n.textAlign === "right" ? "flex-end" : "flex-start", p.appendChild(r);
1721
- }), {
1722
- element: p,
1723
- bounds: {
1724
- left: o,
1725
- right: s,
1726
- top: c,
1727
- bottom: l,
1728
- width: d,
1729
- height: f
1730
- }
1731
- };
1732
- }
1733
- #p = (e) => {
1734
- if (!this.#l() || !e.target.closest(".ng-sheet-header")) return;
1735
- let t = e.target.closest("th, td");
1736
- if (!t || t.classList.contains("resizable-edge") || ["INPUT", "BUTTON"].includes(e.target.tagName) || t.dataset.col === void 0) return;
1737
- e.preventDefault();
1738
- let n = e.clientX, r = e.clientY, i = () => {
1739
- this.#c &&= (clearTimeout(this.#c), null), window.removeEventListener("pointermove", a), window.removeEventListener("pointerup", i), window.removeEventListener("pointercancel", i);
1740
- }, a = (e) => {
1741
- Math.hypot(e.clientX - n, e.clientY - r) > 5 && i();
1742
- };
1743
- this.#c = setTimeout(() => {
1744
- i(), this.#m(e, t);
1745
- }, 500), window.addEventListener("pointermove", a), window.addEventListener("pointerup", i, { once: !0 }), window.addEventListener("pointercancel", i, { once: !0 });
1746
- };
1747
- #m(e, t) {
1748
- if (this.#r) return;
1749
- let n = this.#f(t);
1750
- if (!n) return;
1751
- this.#r = !0, this.#i = t, this.#a = parseInt(t.dataset.col, 10);
1752
- let r = this.#e.getBoundingClientRect(), { bounds: i, element: a } = n;
1753
- if (this.#s = e.clientX - i.left, this.#t) {
1754
- this.#t.replaceChildren(a);
1755
- let t = i.top - r.top, n = r.height - t;
1756
- this.#t.style.width = `${i.width}px`, this.#t.style.height = `${n}px`, this.#t.style.top = `${t}px`, this.#t.style.display = "block", this.#g(e.clientX);
1757
- }
1758
- document.body.style.cursor = "move", window.addEventListener("pointermove", this.#h), window.addEventListener("pointerup", this.#_, { once: !0 });
1759
- }
1760
- #h = (e) => {
1761
- if (!this.#r) return;
1762
- this.#g(e.clientX), this.#t && (this.#t.style.pointerEvents = "none"), this.#n && (this.#n.style.pointerEvents = "none");
1763
- let t = this.#u(e.clientX, e.clientY)?.closest(".ng-sheet-header th, .ng-sheet-header td");
1764
- if (t && t.dataset.col !== void 0) {
1765
- let n = parseInt(t.dataset.col, 10), r = this.#e.getBoundingClientRect(), i = t.closest("table"), a = Infinity, o = -Infinity;
1766
- if (i && i.querySelectorAll("thead th, thead td").forEach((e) => {
1767
- if (e.dataset.col === void 0) return;
1768
- let t = parseInt(e.dataset.col, 10), r = t + (e.colSpan || 1) - 1;
1769
- if (t <= n && r >= n) {
1770
- let t = e.getBoundingClientRect();
1771
- a = Math.min(a, t.left), o = Math.max(o, t.right);
1772
- }
1773
- }), a === Infinity) {
1774
- let e = t.getBoundingClientRect();
1775
- a = e.left, o = e.right;
1776
- }
1777
- let s = a + (o - a) / 2, c = 0, l = 0;
1778
- e.clientX < s ? (c = n, l = a - r.left) : (c = n + (t.colSpan || 1), l = o - r.left);
1779
- let u = this.#d(this.#i), d = u.colSpan, f = u.rowIndex, p = f + (this.#i.rowSpan || 1) - 1, m = t.closest("tr")?.sectionRowIndex ?? 0, h = m + (t.rowSpan || 1) - 1, g = !(p < m || f > h), _ = !1;
1780
- if (u.parentGroupRange) {
1781
- let { startCol: e, endCol: t } = u.parentGroupRange;
1782
- (c < e || c + d - 1 > t) && (_ = !0);
1783
- }
1784
- let v = !1;
1785
- if (i) {
1786
- let e = i.querySelectorAll("thead th[colspan], thead td[colspan]");
1787
- for (let t of e) {
1788
- if (t === this.#i) continue;
1789
- let e = t.closest("tr")?.sectionRowIndex ?? 0, n = e + (t.rowSpan || 1) - 1;
1790
- if (p < e || f > n) continue;
1791
- let r = parseInt(t.dataset.col, 10), i = r + (t.colSpan || 1) - 1;
1792
- if (c > r && c < i + 1) {
1793
- v = !0;
1794
- break;
1795
- }
1796
- let a = c + d - 1;
1797
- if (c > r && c <= i && a > i || c < r && a >= r && a < i) {
1798
- v = !0;
1799
- break;
1800
- }
1801
- }
1802
- }
1803
- let y = c >= u.startCol && c <= u.endCol + 1;
1804
- if (!g || y || _ || v || !u.isValidGroup) this.#o = null, this.#n && (this.#n.style.display = "none"), this.#t && this.#t.classList.add("invalid");
1805
- else if (this.#o = c, this.#t && this.#t.classList.remove("invalid"), this.#n) {
1806
- let e = t.closest(".ng-sheet-header").getBoundingClientRect().top - r.top, n = r.height - e;
1807
- this.#n.style.top = `${e}px`, this.#n.style.height = `${n}px`, this.#n.style.left = `${l - 1}px`, this.#n.style.display = "block";
1808
- }
1809
- } else this.#n && (this.#n.style.display = "none"), this.#t && this.#t.classList.add("invalid"), this.#o = null;
1810
- };
1811
- #g(e) {
1812
- if (!this.#t) return;
1813
- let t = e - this.#e.getBoundingClientRect().left - this.#s;
1814
- this.#t.style.left = `${t}px`;
1815
- }
1816
- #_ = (e) => {
1817
- this.#r && (window.removeEventListener("pointermove", this.#h), document.body.style.cursor = "", this.#t && (this.#t.style.display = "none", this.#t.replaceChildren()), this.#n && (this.#n.style.display = "none"), this.#o !== null && this.#a !== null && this.#o !== this.#a && this.#o !== this.#a + 1 && this.moveColumn(this.#a, this.#o), this.#r = !1, this.#i = null, this.#a = null, this.#o = null);
1818
- };
1819
- moveColumn(e, t) {
1820
- let n = this.#e.sourceTable.querySelector("colgroup"), r = n.querySelector(`col[data-col="${t}"]`), i = this.#d(this.#i);
1821
- if (!i || !i.isValidGroup) return;
1822
- let a = i.colSpan, o = (t) => t >= e && t < e + a, s = this.#e.querySelector(`.ng-sheet-body-content col[data-col="${t}"]`), c = s?.closest(".ng-container-left") ? "left" : s?.closest(".ng-container-right") ? "right" : null;
1823
- n.querySelectorAll("col").forEach((e) => {
1824
- o(parseInt(e.getAttribute("data-col"), 10)) && (c ? e.setAttribute("fixed", c) : e.removeAttribute("fixed"), n.insertBefore(e, r));
1825
- }), [
1826
- "thead",
1827
- "tbody",
1828
- "tfoot"
1829
- ].forEach((e) => {
1830
- this.#e.sourceTable.querySelectorAll(`${e} tr`).forEach((e) => {
1831
- let n = Array.from(e.children), r = n.find((e) => parseInt(e.dataset.col, 10) >= t);
1832
- n.forEach((t) => {
1833
- o(parseInt(t.dataset.col, 10)) && e.insertBefore(t, r || null);
1834
- });
1835
- });
1836
- }), this.#e.recompileAndRefresh();
1837
- }
1838
- destroy() {
1839
- this.#e.removeEventListener("pointerdown", this.#p);
1840
- }
1841
- }, T = class {
1842
- #e;
1843
- constructor(e) {
1844
- this.#e = e;
1845
- }
1846
- getFixState(e, t) {
1847
- if (!e || !t) return "none";
1848
- let n = e.closest(".ng-container-left, .ng-container-right, .ng-container-body");
1849
- if (n?.classList.contains("ng-container-left")) return "left";
1850
- if (n?.classList.contains("ng-container-right")) return "right";
1851
- let r = parseInt(e.dataset.col, 10);
1852
- if (!isNaN(r)) {
1853
- let e = t.querySelector(`colgroup col[data-col="${r}"]`)?.getAttribute("fixed");
1854
- if (e) return e;
1855
- }
1856
- return "none";
1857
- }
1858
- canFixColumn(e, t) {
1859
- if (!e || e.tagName !== "TH" || !t) return !1;
1860
- let n = parseInt(e.dataset.col, 10), r = e.colSpan || 1;
1861
- if (isNaN(n)) return !1;
1862
- let i = n + r - 1, a = Array.from(t.querySelectorAll("thead tr"));
1863
- if (a.length <= 1) return !0;
1864
- for (let e of a) {
1865
- let t = Array.from(e.querySelectorAll("th, td")), n = !1;
1866
- for (let e of t) {
1867
- let t = parseInt(e.dataset.col, 10), r = t + (e.colSpan || 1) - 1;
1868
- if (t <= i && i < r) return !1;
1869
- if (r === i) {
1870
- n = !0;
1871
- break;
1872
- }
1873
- }
1874
- if (!n) return !1;
1875
- }
1876
- return !0;
1877
- }
1878
- executeFixToggle(e, t, n = "left") {
1879
- if (!this.#e || !t) return;
1880
- let r = this.#e.sourceTable;
1881
- if (!r) return;
1882
- let i = parseInt(t.dataset.col, 10), a = t.colSpan || 1, o = i + a - 1;
1883
- if (isNaN(o)) return;
1884
- let s = r.querySelector("colgroup");
1885
- if (!s) return;
1886
- let c = Array.from(s.querySelectorAll("col"));
1887
- if (e === "fix-column") c.forEach((e) => {
1888
- parseInt(e.getAttribute("data-col"), 10) <= o && e.setAttribute("fixed", n);
1889
- }), [
1890
- "thead",
1891
- "tbody",
1892
- "tfoot"
1893
- ].forEach((e) => {
1894
- r.querySelectorAll(`${e} tr`).forEach((e) => {
1895
- Array.from(e.children).forEach((e) => {
1896
- let t = parseInt(e.dataset.col, 10);
1897
- !isNaN(t) && t <= o && e.setAttribute("fixed", n);
1898
- });
1899
- });
1900
- });
1901
- else if (e === "unfix-column") {
1902
- let e = i, t = i + a - 1;
1903
- [
1904
- "thead",
1905
- "tbody",
1906
- "tfoot"
1907
- ].forEach((n) => {
1908
- r.querySelectorAll(`${n} tr`).forEach((n, r) => {
1909
- Array.from(n.children).forEach((a) => {
1910
- let s = parseInt(a.dataset.col, 10), c = s + (a.colSpan || 1) - 1, l = a.rowSpan || 1;
1911
- (n.sectionRowIndex ?? r) + l - 1 < a.closest("tr").sectionRowIndex || a.closest("tr").sectionRowIndex + l - 1, c < i || s > o || (e = Math.min(e, s), t = Math.max(t, c));
1912
- });
1913
- });
1914
- }), c.forEach((t) => {
1915
- parseInt(t.getAttribute("data-col"), 10) >= e && t.removeAttribute("fixed");
1916
- });
1917
- let n = !1;
1918
- c.forEach((e) => {
1919
- n ? e.removeAttribute("fixed") : e.getAttribute("fixed") || (n = !0);
1920
- }), [
1921
- "thead",
1922
- "tbody",
1923
- "tfoot"
1924
- ].forEach((e) => {
1925
- r.querySelectorAll(`${e} tr`).forEach((e) => {
1926
- Array.from(e.children).forEach((e) => {
1927
- let t = parseInt(e.dataset.col, 10);
1928
- if (isNaN(t)) return;
1929
- let n = c.find((e) => parseInt(e.getAttribute("data-col"), 10) === t)?.getAttribute("fixed");
1930
- n ? e.setAttribute("fixed", n) : e.removeAttribute("fixed");
1931
- });
1932
- });
1933
- });
1934
- }
1935
- this.#e.recompileAndRefresh?.();
1936
- }
1937
- }, E = class extends HTMLElement {
1938
- #e;
1939
- #t;
1940
- #n;
1941
- #r;
1942
- #i;
1943
- currentCol = null;
1944
- connectedCallback() {
1945
- this.#a(), document.addEventListener("mousedown", this.#s);
1946
- }
1947
- #a = () => {
1948
- this.#o(), this.#e = this.closest("nine-table-sheet"), this.#t = this.getRootNode().host, this.#n = this.querySelector("nine-table-simple"), setTimeout(() => {
1949
- this.#r = this.#n.shadowRoot.querySelector("nine-table-sheet");
1950
- }), this.querySelector(".search-box").addEventListener("focusin", (e) => {
1951
- e.stopPropagation();
1952
- }), this.querySelector(".search-box").addEventListener("input", this.#u), this.querySelector("#chkSelectAll").addEventListener("change", this.#d), this.querySelector("#btnOk").addEventListener("click", this.#l);
1953
- };
1954
- #o = () => {
1955
- this.innerHTML = "\n <input type=\"text\" class=\"search-box\" placeholder=\"Search...\">\n \n <nine-table-simple class=\"filter-list\" theme=\"simple\">\n <table auto-fit-col=\"true\">\n <colgroup>\n <col width=\"32\" fixed=\"left\" />\n <col width=\"180\" />\n <col width=\"0\" fixed=\"right\"/>\n </colgroup>\n <tbody>\n <tr>\n <td cell-type=\"checkbox\" data-bind=\"CHK\"></td>\n <td data-bind=\"DATA2\" html=\"true\"></td>\n <td data-bind=\"DATA\"></td>\n </tr>\n </tbody>\n </table>\n </nine-table-simple>\n\n <div class=\"footer-section\">\n <div class=\"footer-btns\">\n <label><input type=\"checkbox\" id=\"chkSelectAll\" checked> Select All</label>\n <div class=\"btn-group\">\n <button id=\"btnOk\">Apply</button>\n </div>\n </div>\n </div>\n ";
1956
- };
1957
- open(e) {
1958
- this.#i = e;
1959
- let t = e.closest("th, td");
1960
- this.currentCol = t?.dataset.col;
1961
- let n = t.getBoundingClientRect(), r = this.#e.getBoundingClientRect(), i = this.offsetWidth || 240, a = n.right - r.left - i, o = n.bottom - r.top;
1962
- a < 0 && (a = Math.max(0, n.left - r.left)), this.style.left = `${a}px`, this.style.top = `${o}px`;
1963
- let s = this.querySelector(".search-box");
1964
- s.value = "", this.classList.add("active"), this.classList.add("loading"), setTimeout(() => {
1965
- try {
1966
- this.#c(), this.#r.rowManager.scrollToDataRow(0), s.focus();
1967
- } finally {
1968
- this.classList.remove("loading");
1969
- }
1970
- });
1971
- }
1972
- #s = (e) => {
1973
- let t = e.composedPath ? e.composedPath() : [];
1974
- t.includes(this) || this.#i && t.includes(this.#i) || this.close();
1975
- };
1976
- close() {
1977
- this.currentCol = null, this.classList.remove("active"), this.#i = null;
1978
- }
1979
- #c() {
1980
- let e = this.#t.data.getArray(), t = this.#i?.columns || [], n = this.#t.fields.get() || [], r = this.#e.filtering?.filters || {}, i = this.#t.exprEngine, a = t.flatMap((t) => {
1981
- let a = t.bind, o = t.expr, s = a || o, c = a ? n.indexOf(a) : -1, l = r[s] || [], u = /* @__PURE__ */ new Map();
1982
- for (let t = 0; t < e.length; t++) {
1983
- let n = e[t];
1984
- if (!n) continue;
1985
- let r;
1986
- c >= 0 && n.v ? r = n.v[c] : a && a.includes("data.") ? r = i ? i.evaluate(a, n, t) : void 0 : o && i && (r = i.evaluate(o, n, t));
1987
- let s = r;
1988
- o && i && (s = i.evaluate(o, n, t)), s != null && !u.has(s) && u.set(s, {
1989
- v: r,
1990
- v2: s
1991
- });
1992
- }
1993
- let d = [...u.values()];
1994
- return d.sort((e, t) => {
1995
- let n = e.v2, r = t.v2;
1996
- if (n === r) return 0;
1997
- if (n == null || n === "") return 1;
1998
- if (r == null || r === "") return -1;
1999
- let i = Number(n), a = Number(r);
2000
- return !isNaN(i) && !isNaN(a) ? i - a : String(n).localeCompare(String(r));
2001
- }), l.sort((e, t) => e > t ? 1 : -1), d.map((e) => ({
2002
- LVL: 2,
2003
- DATA: e.v,
2004
- DATA2: e.v2 === "" || e.v2 === null || e.v2 === void 0 ? "<span class=\"empty-value\">(empty)</span>" : e.v2,
2005
- COLNM: s,
2006
- CHK: l.length === 0 || l.nineBinarySearch(e.v) >= 0 ? "Y" : "N"
2007
- }));
2008
- });
2009
- this.#n.data.set(a);
2010
- let o = this.querySelector("#chkSelectAll");
2011
- o && (o.checked = a.length > 0 && a.every((e) => e.CHK === "Y"));
2012
- }
2013
- #l = () => {
2014
- this.#t.loading = !0;
2015
- let e = this.#r.view.getArray(), t = this.#n.data.getHostFields(), n = e.filter((e) => {
2016
- let n = e.v[t.indexOf("CHK")];
2017
- return n === "Y" || n === !0;
2018
- }), r = { ...this.#e.filtering?.filters || {} };
2019
- this.#i.columns.forEach((e) => {
2020
- let i = e.expr || e.bind, a = e.expr ? t.indexOf("DATA2") : t.indexOf("DATA"), o = n.map((e) => e.v[a]);
2021
- o.length > 0 ? r[i] = o : delete r[i];
2022
- });
2023
- let i = this.#n.data.count();
2024
- setTimeout(() => {
2025
- try {
2026
- i === n.length ? this.#i.columns.forEach((e) => {
2027
- let t = e.expr || e.bind;
2028
- t && this.#e.filtering.clear(t);
2029
- }) : this.#e.filtering.set(r), this.#e.querySelectorAll("nine-table-filter-button").forEach((e) => {
2030
- e.updateFilteredState();
2031
- }), this.#e.invalidate(), this.close();
2032
- } finally {
2033
- this.#t.loading = !1;
2034
- }
2035
- });
2036
- };
2037
- #u = (e) => {
2038
- let t = e.target.value.toLowerCase().trim();
2039
- if (!t) this.#r.filtering.clear();
2040
- else {
2041
- let e = this.#n.data.getArray(), n = this.#n.data.getHostFields().indexOf("DATA2"), r = [];
2042
- e.forEach((e) => {
2043
- let i = n >= 0 && e.v ? e.v[n] : "";
2044
- String(i).replace(/<[^>]*>?/gm, "").toLowerCase().includes(t) && r.push(i);
2045
- }), this.#r.filtering.set({ DATA2: [...new Set(r)] });
2046
- }
2047
- };
2048
- #d = (e) => {
2049
- let t = e.target.checked, n = this.#n?.data?.getArray() || [], r = this.#n.data.getHostFields().indexOf("CHK");
2050
- r >= 0 && n.forEach((e) => {
2051
- e.v[r] = t ? "Y" : "N";
2052
- }), this.#n.refresh();
2053
- };
2054
- }, D = class extends HTMLElement {
2055
- #e;
2056
- #t = null;
2057
- connectedCallback() {
2058
- this.#e = this.closest("nine-table-sheet") || this.getRootNode().host, this.removeEventListener("click", this.#n), this.addEventListener("click", this.#n);
2059
- }
2060
- get columns() {
2061
- if (this.#t) return this.#t;
2062
- let e = this.closest("th, td")?.dataset.col, t = this.#e.sourceTable, n = [], r = /* @__PURE__ */ new Set();
2063
- return t && e !== void 0 && t.querySelectorAll(`tbody [data-col="${e}"]`).forEach((e) => {
2064
- let t = e.dataset.bind, i = e.dataset.expr;
2065
- if (t || i) {
2066
- let e = `${t || ""}_${i || ""}`;
2067
- r.has(e) || (r.add(e), n.push({
2068
- bind: t,
2069
- expr: i
2070
- }));
2071
- }
2072
- }), this.#t = n, this.#t;
2073
- }
2074
- updateFilteredState = () => {
2075
- let e = this.#e.filtering?.filters || {}, t = this.columns.some((t) => {
2076
- let n = t.expr || t.bind;
2077
- return n && e[n] && e[n].length > 0;
2078
- });
2079
- this.classList.toggle("filtered", t);
2080
- };
2081
- #n = (e) => {
2082
- e.preventDefault(), e.stopPropagation();
2083
- let t = this.#e.querySelector("nine-table-filter-panel"), n = this.closest("th, td").dataset.col;
2084
- t && t.currentCol === n && t.classList.contains("active") ? t.close() : t && t.open(this);
2085
- };
2086
- }, O = class {
2087
- #e;
2088
- #t;
2089
- #n = !1;
2090
- #r = null;
2091
- #i = {};
2092
- constructor(e) {
2093
- this.#e = e, this.#t = this.#e.getRootNode().host, this.#a();
2094
- }
2095
- get filters() {
2096
- return this.#i;
2097
- }
2098
- #a = () => {
2099
- this.#o();
2100
- };
2101
- #o = () => {
2102
- if (this.#t.tagName.toLowerCase() === "nine-table-simple") return;
2103
- let e = this.#e.querySelector("nine-table-filter-panel");
2104
- e || (e = document.createElement("nine-table-filter-panel"), this.#e.appendChild(e)), this.#r = e;
2105
- };
2106
- isFiltering() {
2107
- return this.#n;
2108
- }
2109
- clear = (e) => {
2110
- e ? delete this.#i[e] : this.#i = {}, this.#n = Object.keys(this.#i).length > 0, this.#s(), this.#e.querySelectorAll("nine-table-filter-button").forEach((e) => {
2111
- e.updateFilteredState();
2112
- });
2113
- };
2114
- set = (e) => {
2115
- let t = Array.isArray(e) ? Object.fromEntries(Object.keys(e[0]).map((t) => [t, [...new Set(e.map((e) => e[t]))]])) : e;
2116
- this.#i = t, this.#n = Object.keys(t).length > 0, this.#e.toggleAttribute("filtering", this.#n), this.#s();
2117
- };
2118
- #s() {
2119
- let e = this.#t.data.getArray(), t = this.#t.data.getHostFields(), n = this.#e.index, i = this.#t.exprEngine;
2120
- if (!(Object.keys(this.#i).length > 0)) {
2121
- e.forEach((e) => {
2122
- e?.m?._?.[r.META.INDEX.FILTER] && (e.m._[r.META.INDEX.FILTER][n] = !0);
2123
- }), this.#e.invalidate();
2124
- return;
2125
- }
2126
- let a = Object.entries(this.#i).map(([e, n]) => {
2127
- let r = e.includes("data.") || e.includes("host.") || e.includes("rowItem.v");
2128
- return {
2129
- targetKey: e,
2130
- isExpr: r,
2131
- fieldIdx: r ? -1 : t.indexOf(e),
2132
- allowedSet: new Set(n)
2133
- };
2134
- });
2135
- e.forEach((e, t) => {
2136
- if (!e) return;
2137
- e.m._[r.META.INDEX.FILTER] || (e.m._[r.META.INDEX.FILTER] = []);
2138
- let o = !0;
2139
- for (let n = 0; n < a.length; n++) {
2140
- let { targetKey: r, isExpr: s, fieldIdx: c, allowedSet: l } = a[n], u;
2141
- if (s && i ? u = i.evaluate(r, e, t) : c >= 0 && e.v && (u = e.v[c]), !l.has(u)) {
2142
- o = !1;
2143
- break;
2144
- }
2145
- }
2146
- e.m._[r.META.INDEX.FILTER][n] = o;
2147
- }), this.#e.invalidate();
2148
- }
2149
- };
2150
- customElements.get("nine-table-filter-panel") || customElements.define("nine-table-filter-panel", E), customElements.get("nine-table-filter-button") || customElements.define("nine-table-filter-button", D);
2151
- // src/data/Sorting.js
2152
- var k = class {
2153
- #e;
2154
- #t;
2155
- #n = [];
2156
- constructor(e) {
2157
- this.#e = e, this.#t = e.getRootNode().host, setTimeout(() => {
2158
- this.#r();
2159
- }, 300);
2160
- }
2161
- #r() {
2162
- this.#e.querySelectorAll("thead").forEach((e) => {
2163
- e.addEventListener("dblclick", (e) => {
2164
- let t = e.target.closest("th, td");
2165
- if (!t || t.classList.contains("resizable-edge") || ["INPUT", "CELL-CHECKBOX"].includes(e.target.tagName) || e.offsetX <= 2 || e.offsetX >= t.offsetWidth - 2) return;
2166
- let n = this.#e.getRootNode().host;
2167
- n.loading = !0, setTimeout(() => {
2168
- try {
2169
- this.#i(e, t);
2170
- } finally {
2171
- n.loading = !1;
2172
- }
2173
- });
2174
- });
2175
- });
2176
- }
2177
- #i(e, t) {
2178
- let n = t.dataset.col, r = t.closest("tr"), i = r ? r.dataset.subrow || String(r.sectionRowIndex) : "0";
2179
- if (n === void 0) return;
2180
- let a = this.#e.sourceTable;
2181
- if (!a) return;
2182
- let o = null, s = null;
2183
- if (a.querySelectorAll(`tbody [data-col="${n}"]`).forEach((e) => {
2184
- e.dataset.bind && (o = e.dataset.bind), e.dataset.expr && (s = e.dataset.expr);
2185
- }), !o && !s) return;
2186
- let c = t.classList.contains("asc"), l = t.classList.contains("desc");
2187
- !e.ctrlKey && !e.shiftKey && (this.#n = []);
2188
- let u = this.#n.findIndex((e) => e.colIndex === n && e.subRowIndex === i || e.colName === o), d = {
2189
- colIndex: n,
2190
- subRowIndex: i,
2191
- colname: o || s,
2192
- colName: o || s,
2193
- expr: s,
2194
- asc: !0,
2195
- "expr-func": s ? (e, t) => this.#t.exprEngine(s, e, t) : null
2196
- };
2197
- !c && !l ? u >= 0 ? this.#n[u].asc = !0 : this.#n.push({
2198
- ...d,
2199
- asc: !0
2200
- }) : c ? u >= 0 ? this.#n[u].asc = !1 : this.#n.push({
2201
- ...d,
2202
- asc: !1
2203
- }) : this.#n = this.#n.filter((e) => !(e.colIndex === n && e.subRowIndex === i || e.colName === o)), this.#a();
2204
- }
2205
- #a() {
2206
- this.#e.view && (this.#e.view.setSorting(this.#n), this.#o(), this.#e.invalidate());
2207
- }
2208
- #o() {
2209
- this.#e.querySelectorAll("thead th, thead td").forEach((e) => {
2210
- e.classList.remove("asc", "desc");
2211
- }), this.#n.length !== 0 && this.#n.forEach((e) => {
2212
- let { colIndex: t, subRowIndex: n, asc: r } = e;
2213
- if (t !== void 0) {
2214
- let e = `thead [data-col="${t}"]`;
2215
- n !== void 0 && (e = `thead tr[data-subrow="${n}"] [data-col="${t}"]`), this.#e.querySelectorAll(e).forEach((e) => {
2216
- e.classList.add(r ? "asc" : "desc");
2217
- });
2218
- }
2219
- });
2220
- }
2221
- restore() {
2222
- this.#n = [], this.#e.view && this.#e.view.resetSorting(), this.#o(), this.#e.rowManager?.refresh(!0);
2223
- }
2224
- }, A = class {
2225
- #e;
2226
- #t;
2227
- #n = [];
2228
- #r = [];
2229
- #i = null;
2230
- constructor(e) {
2231
- this.#e = e, this.#t = e.getRootNode().host, this.refresh();
2232
- }
2233
- getArray = (e, t) => {
2234
- if (!this.#i) {
2235
- let e = this.#t.data.getArray();
2236
- this.#i = this.#r.map((t) => e[t]);
2237
- }
2238
- let n = this.#i;
2239
- if (e == null) return n;
2240
- if (e < 0 || e >= n.length) return null;
2241
- let r = n[e];
2242
- if (t != null) {
2243
- let e = this.#t.data.getHostFields().indexOf(t);
2244
- return e >= 0 && r.v ? r.v[e] : null;
2245
- }
2246
- return r;
2247
- };
2248
- count = () => {
2249
- if (!this.#i) {
2250
- let e = this.#t.data.getArray();
2251
- this.#i = this.#r.map((t) => e[t]);
2252
- }
2253
- return this.#i.length;
2254
- };
2255
- get = (e, t) => {
2256
- let n = this.getArray(), r = this.#t.data.getHostFields?.() || [];
2257
- if (e == null) return n.map((e) => this.#a(e, r));
2258
- if (e < 0 || e >= n.length) return null;
2259
- let i = n[e];
2260
- if (!i) return null;
2261
- if (t != null) {
2262
- let e = r.indexOf(t);
2263
- return e >= 0 && i.v ? i.v[e] : null;
2264
- }
2265
- return this.#a(i, r);
2266
- };
2267
- #a = (e, t) => {
2268
- if (!e) return null;
2269
- let n = {};
2270
- return t.forEach((t, r) => {
2271
- n[t] = e.v ? e.v[r] : e[t];
2272
- }), e.m && (n.m = e.m), e._ && (n._ = e._), n;
2273
- };
2274
- refresh = () => {
2275
- this.#i = null;
2276
- let e = this.#t.data.getArray(), t = [];
2277
- e.forEach((e, n) => {
2278
- if (!e) return;
2279
- let i = e.m?._?.[r.META.INDEX.FILTER];
2280
- i && i[this.#e.index] === !1 || t.push(n);
2281
- }), this.#n.length > 0 && (t = this.#o(t, e)), this.#r = t;
2282
- let n = t.map((t) => e[t]), i = this.#e.grouping?.columns || [];
2283
- if (i.length > 0) {
2284
- let e = g.apply(n, i, this.#t.data.getHostFields());
2285
- this.#i = e.renderItems, this.#e.grouping.setGroupMap(e.groupMap);
2286
- } else this.#i = n;
2287
- };
2288
- setSorting = (e) => {
2289
- this.#n = e || [], this.refresh();
2290
- };
2291
- getSorting = () => this.#n;
2292
- resetSorting = () => {
2293
- this.#n = [], this.refresh();
2294
- };
2295
- #o = (e, t) => {
2296
- let n = typeof this.#t.data.getHostFields == "function" ? this.#t.data.getHostFields() : [], r = this.#n.map((e) => ({
2297
- ...e,
2298
- colIndex: n.indexOf(e.colname || e.colName)
2299
- }));
2300
- return e.sort((e, n) => {
2301
- let i = t[e], a = t[n];
2302
- for (let t of r) {
2303
- let r = t.asc, o = t.expr, s, c;
2304
- o ? (s = this.#t.exprEngine.evaluate(o, i, e), c = this.#t.exprEngine.evaluate(o, a, n)) : t.colIndex >= 0 && i.v && a.v && (s = i.v[t.colIndex], c = a.v[t.colIndex]);
2305
- let l = s == null || s === "", u = c == null || c === "";
2306
- if (!(l && u)) {
2307
- if (l) return 1;
2308
- if (u) return -1;
2309
- if (s !== c) {
2310
- let e = 0;
2311
- if (typeof s == "number" && typeof c == "number") e = s - c;
2312
- else {
2313
- let t = String(s), n = String(c);
2314
- e = t > n ? 1 : t < n ? -1 : 0;
2315
- }
2316
- if (e !== 0) return r ? e : -e;
2317
- }
2318
- }
2319
- }
2320
- return e - n;
2321
- });
2322
- };
2323
- }, j = class e {
2324
- static initializeTable(t, n) {
2325
- return e.#r(n), e.#a(n), e.#n(n), e.#u(n), e.#i(n), v.resetColIndex(n, n.querySelectorAll("thead tr")), v.resetColIndex(n, n.querySelectorAll("tbody.body tr[grouping=\"true\"]")), v.resetColIndex(n, n.querySelectorAll("tbody.body tr:not([grouping=\"true\"])")), v.resetColIndex(n, n.querySelectorAll("tfoot tr")), e.#e(n), e.#o(n), e.#s(t, n), e.#l(n), e.#c(t, n), e.#d(n), n;
2326
- }
2327
- static #e(t) {
2328
- let n = t.querySelector("thead");
2329
- if (!n || n.querySelector(".col-indicator-rowgroup")) return;
2330
- let r = n.insertRow(0);
2331
- r.setAttribute("role", "row"), r.classList.add("col-indicator-rowgroup"), r.classList.add("collapse");
2332
- let i = t.querySelector("tbody tr");
2333
- if (!i) return;
2334
- let a = 0;
2335
- i.querySelectorAll("th, td").forEach((t) => {
2336
- if (!t.classList.contains("dummy")) {
2337
- let n = t.colSpan || 1;
2338
- for (let t = 0; t < n; t++) {
2339
- let t = "<th data-col=\"@col\" class=\"col-indicator\" scope=\"col\"></th>".replace("@col", a).replace("@text", e.#t(a++));
2340
- r.insertAdjacentHTML("beforeend", t);
2341
- }
2342
- }
2343
- });
2344
- let o = Array.from(t.querySelectorAll("colgroup col"));
2345
- r.querySelectorAll(".col-indicator").forEach((e, t) => {
2346
- let n = o[t].getAttribute("background");
2347
- n && (e.style.background = n);
2348
- });
2349
- }
2350
- static #t(e) {
2351
- let t = "";
2352
- for (let n = e; n >= 0; n = Math.floor(n / 26) - 1) t = String.fromCharCode(65 + n % 26) + t;
2353
- return t;
2354
- }
2355
- static #n(e) {
2356
- let t = e.querySelector("tbody:not(.head):not(.foot)");
2357
- if (t) {
2358
- if (t.classList.add("body"), !e.querySelector("tbody.head")) {
2359
- let e = document.createElement("tbody");
2360
- e.classList.add("head"), t.before(e);
2361
- }
2362
- if (!e.querySelector("tbody.foot")) {
2363
- let e = document.createElement("tbody");
2364
- e.classList.add("foot"), t.after(e);
2365
- }
2366
- }
2367
- }
2368
- static #r(e) {
2369
- let t = e.querySelector("colgroup");
2370
- if (t || (t = document.createElement("colgroup"), e.prepend(t)), t.querySelectorAll("col").length === 0) {
2371
- let n = e.querySelector("tbody tr"), r = 1;
2372
- n && (r = Array.from(n.querySelectorAll("th, td")).reduce((e, t) => e + (parseInt(t.getAttribute("colspan") || t.colSpan, 10) || 1), 0)), r = Math.max(r, 1);
2373
- for (let e = 0; e < r; e++) {
2374
- let e = document.createElement("col");
2375
- t.appendChild(e);
2376
- }
2377
- }
2378
- }
2379
- static #i(e) {
2380
- let t = Array.from(e.querySelectorAll("colgroup col"));
2381
- if (t.length === 0) return;
2382
- let n = e.clientWidth || 0, r = Math.max(Math.floor(n / t.length), 100);
2383
- t.forEach((e, t) => {
2384
- e.hasAttribute("data-col") || e.setAttribute("data-col", t);
2385
- let n = e.getAttribute("width") || parseInt(e.style.width, 10) || r;
2386
- e.setAttribute("width", n);
2387
- let i = String(n).includes("px") ? n : `${n}px`;
2388
- e.style.width = i;
2389
- });
2390
- }
2391
- static #a(e) {
2392
- if (e.querySelector("thead")) return;
2393
- let t = document.createElement("thead"), n = e.querySelector("colgroup");
2394
- n ? n.after(t) : e.prepend(t);
2395
- }
2396
- static #o(e) {
2397
- e.querySelectorAll("thead th, thead td").forEach((e) => {
2398
- e.getAttribute("collapsed") === "true" && e.getAttribute("collapsible") !== "true" && e.setAttribute("collapsible", "true");
2399
- });
2400
- }
2401
- static #s(e, t) {
2402
- let n = [
2403
- "data-bind",
2404
- "data-expr",
2405
- "type"
2406
- ], r = 0;
2407
- t.querySelectorAll("tbody th, tbody td").forEach((t) => {
2408
- let i = `cell-${t.getAttribute("cell-type") || "renderer"}`, a = t.querySelector("datalist");
2409
- if (a) {
2410
- let n = [];
2411
- a.querySelectorAll("option").forEach((e) => {
2412
- n.push({
2413
- k: e.getAttribute("k"),
2414
- v: e.getAttribute("v"),
2415
- value: e.getAttribute("value")
2416
- });
2417
- });
2418
- let i = `__ds_${Date.now()}_${++r}`;
2419
- e && (e[i] = () => n), t.setAttribute("data-source", `host.${i}()`), a.remove();
2420
- }
2421
- let o = t.dataset.expr;
2422
- o && t.setAttribute("data-expr", e.exprEngine.precompile(o)), Array.from(t.attributes).forEach((n) => {
2423
- [
2424
- "data-bind",
2425
- "data-expr",
2426
- "cell-type",
2427
- "validator"
2428
- ].includes(n.name) || (n.value.includes("data.") || n.value.includes("host.")) && t.setAttribute(n.name, e.exprEngine.precompile(n.value));
2429
- }), t.innerHTML = `<${i} ${n.filter((e) => t.hasAttribute(e)).map((e) => `${e}="${t.getAttribute(e)}"`).join(" ")}></${i}>`, t.setAttribute("tabindex", "0");
2430
- }), t.querySelectorAll("thead th, thead td, tfoot th, tfoot td").forEach((e) => {
2431
- let t = e.getAttribute("cell-type");
2432
- if (t) {
2433
- let r = e.innerHTML, i = `cell-${t}`;
2434
- e.innerHTML = `<${i} ${n.filter((t) => e.hasAttribute(t)).map((t) => `${t}="${e.getAttribute(t)}"`).join(" ")} content="${r}"></${i}>`;
2435
- }
2436
- });
2437
- }
2438
- static #c(e, t) {
2439
- let n = e.getAttribute("filtering") === "true", r = t.getAttribute("filtering") === "true";
2440
- t.querySelectorAll("thead tr:not(.col-indicator-rowgroup) th, thead tr:not(.col-indicator-rowgroup) td").forEach((e) => {
2441
- let t = e.getAttribute("filtering") === "true" || r || n;
2442
- e.setAttribute("filtering", t ? "true" : "false"), t && e.appendChild(document.createElement("nine-table-filter-button"));
2443
- });
2444
- }
2445
- static #l(e) {
2446
- e.querySelectorAll("thead th, thead td").forEach((t) => {
2447
- if (t.getAttribute("collapsible") !== "true" && t.getAttribute("expandable") !== "true") return;
2448
- let n = parseInt(t.dataset.col, 10), r = t.colSpan || 1, i = e.querySelector(`colgroup col[data-col="${n}"]`), a = i && parseInt(i.getAttribute("width"), 10) || 100;
2449
- (!t.dataset.expandWidth || parseInt(t.dataset.expandWidth, 10) <= 16) && (t.dataset.expandWidth = String(a > 16 ? a : 100));
2450
- let o = t.querySelector("nine-table-col-expand");
2451
- if (o || (o = document.createElement("nine-table-col-expand"), t.insertBefore(o, t.firstChild)), t.getAttribute("collapsed") === "true") {
2452
- o.classList.add("collapsed"), o.classList.remove("expand"), o.setAttribute("collapsed", "true"), t.style.color = "transparent";
2453
- let i = Math.max(10, Math.floor(16 / r));
2454
- if (!isNaN(n)) for (let t = 0; t < r; t++) {
2455
- let r = e.querySelector(`colgroup col[data-col="${n + t}"]`);
2456
- r && (r.setAttribute("width", i), r.style.width = `${i}px`);
2457
- }
2458
- } else o.classList.remove("collapsed"), o.classList.add("expand"), o.setAttribute("collapsed", "false"), t.style.color = "";
2459
- });
2460
- }
2461
- static #u(e, t) {
2462
- let n = e.getAttribute("row-indicator") === "true" ? 48 : 0, r = e.querySelector("colgroup"), i = document.createElement("col");
2463
- i.setAttribute("fixed", "left"), i.setAttribute("width", n), i.style.width = `${n}px`, r.prepend(i), e.querySelectorAll("thead, tbody, tfoot").forEach((e) => {
2464
- let t = Array.from(e.querySelectorAll("tr"));
2465
- if (t.length === 0) return;
2466
- let n = t[0], r = document.createElement("th");
2467
- r.className = "row-indicator", r.setAttribute("cell-type", "row-indicator"), t.length > 1 && (r.rowSpan = t.length), n.insertBefore(r, n.firstElementChild);
2468
- });
2469
- }
2470
- static #d(e) {
2471
- e.querySelectorAll("th[data-col], td[data-col]").forEach((t) => {
2472
- let n = parseInt(t.getAttribute("data-col"), 10);
2473
- if (isNaN(n)) return;
2474
- let r = parseInt(t.getAttribute("colspan") || t.colSpan, 10) || 1, i = 0;
2475
- for (let t = 0; t < r; t++) {
2476
- let r = n + t, a = e.querySelector(`colgroup col[data-col="${r}"]`);
2477
- a && (i += parseInt(a.getAttribute("width"), 10) || 100);
2478
- }
2479
- if (i > 0) {
2480
- let e = `${i}px`;
2481
- t.style.width = e, t.style.minWidth = e, t.style.maxWidth = e;
2482
- }
2483
- });
2484
- }
2485
- }, M = class extends HTMLElement {
2486
- #e;
2487
- #t;
2488
- #n;
2489
- #r;
2490
- #i;
2491
- #a;
2492
- #o;
2493
- #s;
2494
- #c;
2495
- #l;
2496
- #u;
2497
- #d;
2498
- #f = { table: null };
2499
- #p;
2500
- static SCROLLBAR_SIZE = 16;
2501
- constructor() {
2502
- super(), this.#t = this.getRootNode().host, this.#n = new _(this);
2503
- }
2504
- connectedCallback() {
2505
- this.#b();
2506
- }
2507
- get index() {
2508
- return this.#e;
2509
- }
2510
- get colResizer() {
2511
- return this.#a;
2512
- }
2513
- get filtering() {
2514
- return this.#l;
2515
- }
2516
- get grouping() {
2517
- return this.#u;
2518
- }
2519
- get colMover() {
2520
- return this.#o;
2521
- }
2522
- get colFix() {
2523
- return this.#s;
2524
- }
2525
- get rowManager() {
2526
- return this.#n;
2527
- }
2528
- get selection() {
2529
- return this.#r;
2530
- }
2531
- get navigation() {
2532
- return this.#i;
2533
- }
2534
- get templateLength() {
2535
- return this.#f.tbody.tr.length || 0;
2536
- }
2537
- get elements() {
2538
- return this.#p;
2539
- }
2540
- get isAutoFitCol() {
2541
- let e = this.getAttribute("auto-fit-col") === "true" || this.#t?.getAttribute("auto-fit-col") === "true", t = this.#f.table?.getAttribute("auto-fit-col") === "true";
2542
- return e || t;
2543
- }
2544
- get sourceTable() {
2545
- return this.#f.table;
2546
- }
2547
- get source() {
2548
- return this.#f;
2549
- }
2550
- get #m() {
2551
- return this.#t.hasAttribute("simple") || this.#t.getAttribute("theme") === "simple";
2552
- }
2553
- recompileAndRefresh() {
2554
- this.#f.table && (v.recompile(this.#f.table), [
2555
- "left",
2556
- "right",
2557
- "body"
2558
- ].forEach((e) => {
2559
- [
2560
- "header",
2561
- "body",
2562
- "footer"
2563
- ].forEach((t) => {
2564
- let n = this.querySelector(`.ng-sheet-${t} .ng-container-${e}`);
2565
- n && n.querySelectorAll("table").forEach((e) => e.remove());
2566
- });
2567
- }), this.#v(), this.#_(), this.#n.initialize(), this.isAutoFitCol ? this.autoFit(!0) : this.querySelector("nine-table-hscrollbar")?.refresh(), requestAnimationFrame(() => {
2568
- this.#_(), this.#n?.refresh();
2569
- }));
2570
- }
2571
- refreshLayout() {
2572
- requestAnimationFrame(() => {
2573
- this.classList.contains("active") && this.#f.table && (this.#_(), this.isAutoFitCol ? this.autoFit(!0) : this.querySelector("nine-table-hscrollbar")?.refresh(), this.#h(), this.#a?.refreshLayout(), this.#n?.refresh());
2574
- });
2575
- }
2576
- #h = () => {
2577
- let e = this.querySelector(".ng-container-body thead"), t = this.querySelector(".nodata-overlay");
2578
- t.style.top = `${e.offsetHeight}px`;
2579
- };
2580
- get view() {
2581
- return !this.#d && this.#t?.data && (this.#d = new A(this)), this.#d;
2582
- }
2583
- invalidate = () => {
2584
- this.view.refresh(), this.#n.refresh(!0), this.isAutoFitCol && this.autoFit(!0);
2585
- };
2586
- autoFit = (e = !0) => {
2587
- requestAnimationFrame(() => {
2588
- this.#g?.(e);
2589
- });
2590
- };
2591
- #g = (e = !0) => {
2592
- let t = this.querySelector(".ng-sheet-body .ng-container-body");
2593
- if (!t) return;
2594
- let n = this.querySelector(".ng-container-body table colgroup");
2595
- if (n) {
2596
- if (e) {
2597
- this.setAttribute("auto-fit-col", "true");
2598
- let e = t.clientWidth;
2599
- if (e <= 0) return;
2600
- let r = 0, i = [];
2601
- n.querySelectorAll("col").forEach((e) => {
2602
- let t = e.getAttribute("data-col");
2603
- if (this.querySelector(`thead th[data-col="${t}"]`)?.getAttribute("collapsed") === "true") i.unshift({
2604
- globalColIndex: t,
2605
- width: 16,
2606
- isCollapsed: !0
2607
- });
2608
- else {
2609
- let n = parseInt(e.getAttribute("width"), 10) || 100;
2610
- i.push({
2611
- globalColIndex: t,
2612
- width: n,
2613
- isCollapsed: !1
2614
- }), r += n;
2615
- }
2616
- });
2617
- let a = i.filter((e) => e.isCollapsed).reduce((e, t) => e + t.width, 0), o = Math.max(0, e - a);
2618
- if (r > 0 && i.length > 0) {
2619
- let e = 0, t = i.map((t) => {
2620
- if (t.isCollapsed) return {
2621
- globalColIndex: t.globalColIndex,
2622
- remainder: 0,
2623
- width: 16
2624
- };
2625
- let n = t.width * o / r, i = Math.max(30, Math.floor(n));
2626
- return e += i, {
2627
- globalColIndex: t.globalColIndex,
2628
- remainder: n - Math.floor(n),
2629
- width: i
2630
- };
2631
- }), n = o - e, a = t.filter((e) => !i.find((t) => t.globalColIndex === e.globalColIndex)?.isCollapsed);
2632
- if (n > 0 && a.length > 0) {
2633
- a.sort((e, t) => t.remainder - e.remainder);
2634
- for (let e = 0; e < n; e++) a[e % a.length].width += 1;
2635
- } else if (n < 0 && a.length > 0) {
2636
- a.sort((e, t) => e.remainder - t.remainder);
2637
- for (let e = 0; e < Math.abs(n); e++) {
2638
- let t = a[e % a.length];
2639
- t.width > 30 && --t.width;
2640
- }
2641
- }
2642
- t.forEach(({ globalColIndex: e, width: t }) => {
2643
- this.#a?.setColumnWidth(e, t, "body");
2644
- });
2645
- }
2646
- } else this.removeAttribute("auto-fit-col");
2647
- this.querySelector("nine-table-hscrollbar")?.refresh();
2648
- }
2649
- };
2650
- generate = (e, t) => {
2651
- e.style.display = "none", this.#e = t, j.initializeTable(this.#t, e), e.style.display = "", this.#f = {
2652
- table: v.compile(e),
2653
- tbody: { tr: e.querySelectorAll("tbody tr") }
2654
- }, this.#v(), this.#_(), this.#S(), this.#w(), [
2655
- "left",
2656
- "body",
2657
- "right"
2658
- ].forEach((e) => {
2659
- let t = `.ng-container-${e}`;
2660
- this.#p[e] = {
2661
- thead: this.querySelector(`${t} thead`),
2662
- tbody: {
2663
- head: this.querySelector(`${t} tbody.head`),
2664
- body: this.querySelector(`${t} tbody.body`),
2665
- foot: this.querySelector(`${t} tbody.foot`)
2666
- },
2667
- tfoot: this.querySelector(`${t} tfoot`)
2668
- };
2669
- }), this.#n.initialize(), this.isAutoFitCol ? this.autoFit(!0) : this.querySelector("nine-table-hscrollbar").refresh(), this.#u.initialize(), this.loaded = !0;
2670
- };
2671
- #_ = () => {
2672
- [
2673
- "left",
2674
- "right",
2675
- "body"
2676
- ].forEach((e) => {
2677
- let t = this.querySelectorAll(`.ng-container-${e}`);
2678
- if (t.length === 0) return;
2679
- let n = t[0].querySelector("table");
2680
- if (!n) return;
2681
- let r = 0;
2682
- n.querySelectorAll("col").forEach((e) => {
2683
- let t = parseInt(e.getAttribute("width"), 10);
2684
- isNaN(t) || (r += t);
2685
- }), t.forEach((t) => {
2686
- t.querySelectorAll("table"), e === "body" ? t.style.flex = "1" : (t.style.flex = `0 0 ${r}px`, t.style.width = `${r}px`, t.style.minWidth = `${r}px`, t.style.maxWidth = `${r}px`);
2687
- });
2688
- });
2689
- };
2690
- #v = () => {
2691
- [
2692
- {
2693
- selector: ".ng-container-left",
2694
- type: "left"
2695
- },
2696
- {
2697
- selector: ".ng-container-body",
2698
- type: null
2699
- },
2700
- {
2701
- selector: ".ng-container-right",
2702
- type: "right"
2703
- }
2704
- ].forEach(({ selector: e, type: t }) => {
2705
- this.querySelector(`.ng-sheet-body ${e}`).appendChild(this.#y(t));
2706
- });
2707
- };
2708
- #y = (e) => {
2709
- let t = this.#f.table.cloneNode(!0);
2710
- return e === "left" ? t.querySelectorAll("col, th, td").forEach((e) => {
2711
- e.getAttribute("fixed") !== "left" && e.remove();
2712
- }) : e === "right" ? t.querySelectorAll("col, th, td").forEach((e) => {
2713
- e.getAttribute("fixed") !== "right" && e.remove();
2714
- }) : t.querySelectorAll("[fixed=left], [fixed=right]").forEach((e) => {
2715
- e.remove();
2716
- }), t;
2717
- };
2718
- getRowHeight = () => this.#n.getRowHeight();
2719
- getViewHeight = () => (this.#p.content.offsetHeight || 0) - ((this.#p.body.thead?.offsetHeight || 0) + (this.#p.body.tfoot?.offsetHeight || 0) + (this.#p.body.tbody.head.offsetHeight || 0));
2720
- isLastRow = () => {
2721
- let e = this.querySelector(".ng-sheet-body"), t = this.querySelector(".ng-container-body tbody.body"), n = this.#p.body.tfoot?.offsetHeight || 0, r = e.getBoundingClientRect().bottom, i = t.getBoundingClientRect().bottom;
2722
- return r - n >= i;
2723
- };
2724
- scrollToX = (e) => {
2725
- let t = this.querySelector(".ng-sheet-body .ng-container-body");
2726
- t && (t.scrollLeft = e);
2727
- };
2728
- scrollToY = (e) => {
2729
- let t = this.querySelector(".ng-sheet-body");
2730
- t && (t.scrollTop = e);
2731
- };
2732
- #b = () => {
2733
- this.#x(), this.#r = new y(this), this.#i = new b(this), this.#a = new S(this), this.#o = new w(this), this.#s = new T(this), this.#d = new A(this), this.#l = new O(this), this.#u = new h(this), this.#m || (this.#c = new k(this)), this.#p.mainBody.addEventListener("scroll", () => {
2734
- this.querySelector("nine-table-hscrollbar").refresh();
2735
- });
2736
- };
2737
- #x = () => {
2738
- this.innerHTML = "\n <div class=\"ng-sheet-body\">\n <div class=\"ng-sheet-body-content\">\n <div class=\"ng-container-left\"></div>\n <div class=\"ng-container-body\"></div>\n <div class=\"ng-container-right\"></div>\n </div>\n <div class=\"ng-virtual-height-holder\"></div>\n </div>\n\n <div class=\"nodata-overlay\">Data Not Found</div>\n\n <nine-table-vscrollbar></nine-table-vscrollbar>\n <nine-table-hscrollbar></nine-table-hscrollbar>\n <div class=\"scroll-edge\"></div>\n \n <nine-table-col-resizer-panel></nine-table-col-resizer-panel>\n \n <div class=\"ng-col-mover-grip\"></div>\n <div class=\"ng-col-mover-indi\"></div>\n ", this.#p = {
2739
- mainBody: this.querySelector(".ng-sheet-body .ng-container-body"),
2740
- hscrollbar: this.querySelector("nine-table-hscrollbar"),
2741
- vscrollbar: this.querySelector("nine-table-vscrollbar"),
2742
- content: this.querySelector(".ng-sheet-body .ng-sheet-body-content"),
2743
- scrollHolder: this.querySelector(".ng-sheet-body .ng-virtual-height-holder")
2744
- };
2745
- };
2746
- #S = () => {
2747
- let e = this.querySelector(".ng-container-left table"), t = this.querySelector(".ng-container-body table"), n = this.querySelector(".ng-container-right table"), r = Array.from(e.querySelectorAll("thead tr:not(.col-indicator-rowgroup)")), i = Array.from(t.querySelectorAll("thead tr:not(.col-indicator-rowgroup)")), a = Array.from(n.querySelectorAll("thead tr:not(.col-indicator-rowgroup)"));
2748
- this.#C(r, i, a);
2749
- let o = Array.from(e.querySelectorAll("tfoot tr")), s = Array.from(t.querySelectorAll("tfoot tr")), c = Array.from(n.querySelectorAll("tfoot tr"));
2750
- this.#C(o, s, c);
2751
- };
2752
- #C = (e, t, n) => {
2753
- setTimeout(() => {
2754
- let r = Math.max(e.length, t.length, n.length);
2755
- for (let i = 0; i < r; i++) {
2756
- let r = [
2757
- e[i]?.getBoundingClientRect().height || 0,
2758
- t[i]?.getBoundingClientRect().height || 0,
2759
- n[i]?.getBoundingClientRect().height || 0
2760
- ], a = Math.max(...r);
2761
- a > 0 && (e[i] && (e[i].style.height = `${a}px`), t[i] && (t[i].style.height = `${a}px`), n[i] && (n[i].style.height = `${a}px`));
2762
- }
2763
- });
2764
- };
2765
- #w = () => {
2766
- let e = this.querySelector(".ng-sheet-body");
2767
- if (!e) return;
2768
- let t = null;
2769
- e.addEventListener("mouseover", (n) => {
2770
- let r = n.target.closest("tr");
2771
- if (!r || !r.dataset.row && r.dataset.row !== "0") return;
2772
- let i = r.dataset.row;
2773
- t !== i && (t = i, e.querySelectorAll(`tr[data-row="${i}"]`).forEach((e) => {
2774
- e.classList.add("hover");
2775
- }));
2776
- }), e.addEventListener("mouseout", (n) => {
2777
- let r = n.target.closest("tr");
2778
- if (!r) return;
2779
- let i = n.relatedTarget;
2780
- r.contains(i) || (e.querySelectorAll("tr.hover").forEach((e) => {
2781
- e.classList.remove("hover");
2782
- }), t = null);
2783
- });
2784
- };
2785
- disconnectedCallback() {
2786
- this.#a?.destroy(), this.#o?.destroy(), this.innerHTML = "";
2787
- }
2788
- };
2789
- customElements.get("nine-table-sheet") || customElements.define("nine-table-sheet", M);
2790
- // src/layout/core/LayoutManager.js
2791
- var N = class {
2792
- #e;
2793
- constructor(e) {
2794
- this.#e = e, this.#t();
2795
- }
2796
- #t = () => {
2797
- this.#r(), new ResizeObserver((e) => {
2798
- for (let t of e) this.#e.getAttribute("auto-height") === "true" && this.#n();
2799
- }).observe(this.#e);
2800
- };
2801
- set loading(e) {
2802
- e ? this.#e.classList.add("loading") : this.#e.classList.remove("loading");
2803
- }
2804
- #n = () => {
2805
- let e = Array.from(this.#e.shadowRoot.querySelectorAll("nine-table-sheet.active"));
2806
- if (e.length === 0) return;
2807
- let t = parseInt(this.#e.getAttribute("max-display-row"), 10) || 10, n = Math.max(...e.map((e) => e.getRowHeight())), r = this.#e.shadowRoot.querySelector("nine-table-toolbar"), i = this.#e.shadowRoot.querySelector("nine-table-sheets-footer"), a = r ? r.getBoundingClientRect().height : 0, o = i ? i.getBoundingClientRect().height : 0, s = M.SCROLLBAR_SIZE, c = t * n + a + o + s;
2808
- this.#e.style.height = `${c}px`;
2809
- };
2810
- #r = () => {
2811
- let e = Array.from(this.#e.children).filter((e) => e.tagName.toUpperCase() === "TABLE"), t = this.#e.getAttribute("auto-height") === "true", n = e.length, r = e.map((e, t) => {
2812
- let r = t === 0 ? "active" : "", i = e.id || `sheet${t + 1}`;
2813
- return `<nine-table-sheet class="${r}" data-index="${t}" data-sheet-id="${i}" id="${i}"></nine-table-sheet>` + (t < n - 1 ? `<nine-splitter class="h" data-split-index="${t}"></nine-splitter>` : "");
2814
- }).join(""), i = ["@import \"https://cdn.jsdelivr.net/npm/@ninebone/datagrid@0.0.4/dist/css/nine-table.css\";"];
2815
- nine["nine-table"] && nine["nine-table"].cssFile && i.push(`@import "${nine["nine-table"].cssFile}";`), this.#e.shadowRoot.innerHTML = `
2816
- <style>
2817
- ${i.join("\n")}
2818
- </style>
2819
-
2820
- <nine-table-toolbar></nine-table-toolbar>
2821
-
2822
- <nine-table-body>
2823
- <nine-table-summary></nine-table-summary>
2824
- <div class="ng-loading-bar"></div>
2825
- <nine-table-sheets>
2826
- <nine-table-sheets-body>
2827
- ${r}
2828
- </nine-table-sheets-body>
2829
- <nine-table-sheets-footer></nine-table-sheets-footer>
2830
- </nine-table-sheets>
2831
- <nine-table-analysis></nine-table-analysis>
2832
- </nine-table-body>
2833
- <nine-table-footer></nine-table-footer>
2834
- `, this.#e.shadowRoot.querySelectorAll("nine-table-sheet").forEach((n, r) => {
2835
- e[r] && setTimeout(() => {
2836
- n.generate(e[r], r), t && this.#n();
2837
- });
2838
- });
2839
- };
2840
- }, P = class {
2841
- #e;
2842
- #t;
2843
- #n = /* @__PURE__ */ new Map();
2844
- constructor(e) {
2845
- this.#e = e, this.#t = e.fields.get();
2846
- }
2847
- rewriteExpr(e) {
2848
- return !e || !this.#t.length ? e : e.replace(/data\.([a-zA-Z_$][\w$]*)/g, (e, t) => {
2849
- let n = this.#t.indexOf(t);
2850
- return n >= 0 ? `rowItem.v[${n}]` : e;
2851
- });
2852
- }
2853
- precompile(e) {
2854
- return e && this.rewriteExpr(e);
2855
- }
2856
- evaluate(e, t, n = 0) {
2857
- if (e == null) return "";
2858
- try {
2859
- let r = String(e).trim(), i = this.rewriteExpr(r);
2860
- if (i.includes("provider.") || i.includes("host.") || i.includes("data.") || i.includes("rowItem.v") || i.includes("(")) {
2861
- let e = this.#n.get(i);
2862
- return e || (e = Function("rowItem", "row", "host", `
2863
- const data = rowItem;
2864
- const provider = host;
2865
-
2866
- if (!data && !host) return "";
2867
- return ${i};
2868
- `), this.#n.set(i, e)), e(t, n, this.#e);
2869
- }
2870
- return i;
2871
- } catch {
2872
- return e;
2873
- }
2874
- }
2875
- }, F = class extends HTMLElement {
2876
- #e;
2877
- #t;
2878
- #n;
2879
- #r = 0;
2880
- constructor() {
2881
- super(), ["NINE-TABLE"].includes(this.tagName) && n.log("Welcome nine-table", "0.0.4"), this.#e = this.attachShadow({ mode: "open" }), this.#t = new o(this);
2882
- }
2883
- connectedCallback() {
2884
- setTimeout(() => {
2885
- this.#r = this.querySelectorAll("table")?.length, this.fields = new s(this), this.exprEngine = new P(this), this.#a(), this.#n = new N(this), this.#i();
2886
- });
2887
- }
2888
- disconnectedCallback() {}
2889
- #i = () => {
2890
- let e = 0, t = setInterval(() => {
2891
- e++;
2892
- let n = this.shadow.querySelectorAll("nine-table-sheet");
2893
- if (e >= 50 && clearInterval(t), n.length >= this.#r) {
2894
- let e = 0;
2895
- n.forEach((t) => {
2896
- t.loaded && e++;
2897
- }), e >= this.#r && (clearInterval(t), this.loaded = !0, this.dispatchEvent(new CustomEvent(r.EVENT.LOAD, {
2898
- bubbles: !0,
2899
- detail: { target: this }
2900
- })));
2901
- }
2902
- }, 100);
2903
- };
2904
- get shadow() {
2905
- return this.#e;
2906
- }
2907
- get dataManager() {
2908
- return this.#t;
2909
- }
2910
- get data() {
2911
- return this.#t.data;
2912
- }
2913
- get row() {
2914
- return this.#t.row;
2915
- }
2916
- addProvider(e) {
2917
- e && typeof e == "object" && setTimeout(() => {
2918
- Object.entries(e).forEach(([e, t]) => {
2919
- typeof t == "function" && (this[e] = t);
2920
- }), this.rerenderer();
2921
- });
2922
- }
2923
- setData(e) {
2924
- this.#t.data.set(e), this.refresh();
2925
- }
2926
- refresh() {
2927
- this.activeSheet?.invalidate();
2928
- }
2929
- set loading(e) {
2930
- this.#n && (this.#n.loading = e);
2931
- }
2932
- rerenderer() {
2933
- this.activeSheet?.querySelectorAll("tbody.body th,tbody.body td").forEach((e) => {
2934
- Array.from(e.children).find((e) => e.tagName.toLowerCase().startsWith("cell-") && typeof e.rerenderer == "function")?.rerenderer();
2935
- });
2936
- }
2937
- sheet = (e) => {
2938
- if (e === null || e < 0) return this.activeSheet;
2939
- let t = Array.from(this.shadow.querySelectorAll("nine-table-sheet"));
2940
- return typeof e == "number" ? t[e] || null : typeof e == "string" ? this.shadow.querySelector(`nine-table-sheet#${e}, nine-table-sheet[data-sheet-id="${e}"]`) || null : t[0] || null;
2941
- };
2942
- get sheets() {
2943
- return Array.from(this.shadow.querySelectorAll("nine-table-sheet"));
2944
- }
2945
- get activeSheet() {
2946
- return this.shadow.querySelector("nine-table-sheet.active") || null;
2947
- }
2948
- #a() {
2949
- let e = /* @__PURE__ */ new Set();
2950
- this.querySelectorAll("[data-source]").forEach((t) => {
2951
- let n = t.getAttribute("data-source");
2952
- if (!n) return;
2953
- let r = n.matchAll(/(?:host\.)?([a-zA-Z0-9_$]+)\s*\(/g);
2954
- for (let t of r) {
2955
- let n = t[1];
2956
- n && n !== "host" && e.add(n);
2957
- }
2958
- }), e.forEach((e) => {
2959
- let t = null;
2960
- Object.defineProperty(this, e, {
2961
- set: (e) => {
2962
- t = e, this.rerenderer();
2963
- },
2964
- get: () => t,
2965
- configurable: !0,
2966
- enumerable: !0
2967
- });
2968
- });
2969
- }
2970
- execute = (e) => {
2971
- setTimeout(() => {
2972
- this.loading = !0, setTimeout(() => {
2973
- try {
2974
- e.call(this);
2975
- } finally {
2976
- this.loading = !1;
2977
- }
2978
- });
2979
- });
2980
- };
2981
- };
2982
- customElements.get("nine-table") || customElements.define("nine-table", F), customElements.get("nine-table-simple") || customElements.define("nine-table-simple", class extends F {
2983
- connectedCallback() {
2984
- this.setAttribute("theme", "simple"), super.connectedCallback();
2985
- }
2986
- });
2987
- // src/cell/core/BasicCellElement.js
2988
- var I = class extends HTMLElement {
2989
- constructor() {
2990
- super();
2991
- }
2992
- applyBaseStyle() {}
2993
- connectedCallback() {}
2994
- }, L = /* @__PURE__ */ new Map(), R = class extends I {
2995
- #e;
2996
- #t;
2997
- #n;
2998
- #r;
2999
- #i;
3000
- constructor() {
3001
- super();
3002
- }
3003
- get host() {
3004
- return this.#e;
3005
- }
3006
- get sheet() {
3007
- return this.#t;
3008
- }
3009
- get cell() {
3010
- return this.#r;
3011
- }
3012
- get tr() {
3013
- return this.#n;
3014
- }
3015
- get attr() {
3016
- return this.#i;
3017
- }
3018
- connectedCallback() {
3019
- super.connectedCallback(), this.#e = this.getRootNode().host, this.#r = this.closest("th,td"), this.#n = this.#r.closest("tr"), this.#t = this.#n.closest("nine-table-sheet"), this.#r.classList.add(this.tagName), this.#i = {};
3020
- for (let e = 0; e < this.#r.attributes.length; e++) {
3021
- let t = this.#r.attributes[e].name;
3022
- [
3023
- "text-align",
3024
- "class",
3025
- "cell-type",
3026
- "data-bind",
3027
- "data-expr",
3028
- "data-col",
3029
- "tabindex"
3030
- ].includes(t) || (this.#i[t] = this.#r.attributes[e].value);
3031
- }
3032
- if (!this.#r) return;
3033
- let e = this.shadowRoot || this;
3034
- e.querySelectorAll("button, ng-expand-button").forEach((e) => {
3035
- e.addEventListener("click", () => {
3036
- let e = this.getAttribute("onbuttonclick") || this.getAttribute("onButtonClick") || this.#r?.getAttribute("onbuttonclick") || this.#r?.getAttribute("onButtonClick"), t = this.data, n = parseInt(this.#r.dataset.row, 10);
3037
- if (e && this.#e) {
3038
- e = e.replace("()", "");
3039
- let r = e.match(/^(\w+)\s*\(/)?.[1] || e;
3040
- typeof this.#e[r] == "function" ? this.#e[r].call(this.#e, t, n, this.#r) : typeof this.#e.exprFunction == "function" && this.#e.exprFunction(e).call(this, t, n);
3041
- }
3042
- });
3043
- });
3044
- let t = e.querySelector(".renderer");
3045
- t && this.getAttribute("link") === "true" && (t.classList.add("link"), t.addEventListener("click", () => {
3046
- let e = this.getAttribute("onlinkclick") || this.getAttribute("onLinkClick"), t = this.data, n = parseInt(this.#r.dataset.row, 10);
3047
- if (e && this.#e) {
3048
- e = e.replace("()", "");
3049
- let r = e.match(/^(\w+)\s*\(/)?.[1] || e;
3050
- typeof this.#e[r] == "function" ? this.#e[r].call(this.#e, t, n, this.#r) : typeof this.#e.exprFunction == "function" && this.#e.exprFunction(e).call(this, t, n);
3051
- }
3052
- this.#e?.dispatchEvent(new CustomEvent(ninegrid.EVENT.LINK_CLICK, {
3053
- detail: {
3054
- target: this.#r,
3055
- data: t,
3056
- currow: n
3057
- },
3058
- bubbles: !0,
3059
- composed: !0
3060
- }));
3061
- }));
3062
- }
3063
- get data() {
3064
- let e = this.#n?.data;
3065
- if (!e) return null;
3066
- if (!e.v) return e;
3067
- let t = this.#e;
3068
- return new Proxy(e, { get(e, n) {
3069
- if (n === "__ng") return e.__ng;
3070
- if (n === "v") return e.v;
3071
- let r = t?.fields?.indexOf?.(n) ?? -1;
3072
- return r >= 0 ? e.v[r] : e[n];
3073
- } });
3074
- }
3075
- get value() {
3076
- if (!this.#r || !this.#n?.data) return "";
3077
- let e = this.#r.dataset?.bind;
3078
- if (!e) return "";
3079
- let t = this.#n.data;
3080
- if (t.v && Array.isArray(t.v)) {
3081
- let n = this.#e.fields.get().indexOf(e) ?? -1;
3082
- return n >= 0 ? t.v[n] ?? "" : "";
3083
- }
3084
- return t[e] ?? "";
3085
- }
3086
- set value(e) {
3087
- if (!this.#r || !this.#e?.data) return;
3088
- let t = parseInt(this.#r.dataset.row, 10), n = this.#r.dataset.bind;
3089
- if (isNaN(t) || !n) return;
3090
- let r = this.getAttribute("update-row-state") !== "false";
3091
- this.#e.data.setValue(t, n, e, r);
3092
- }
3093
- get row() {
3094
- return parseInt(this.#r?.dataset?.row, 10);
3095
- }
3096
- get index() {
3097
- return parseInt(this.#r?.dataset?.index, 10);
3098
- }
3099
- isValid() {
3100
- return !this.#r.classList.contains("invalid");
3101
- }
3102
- isInvalid() {
3103
- return !this.isValid();
3104
- }
3105
- getDisplayText = (e = "") => {
3106
- if (!this.#r || !this.#r.closest("tbody") || !this.#n.data) return e;
3107
- let t = this.#r.dataset.expr, n = this.#r.dataset.bind, r = parseInt(this.#r.dataset.row, 10);
3108
- if (t) try {
3109
- return this.#n.getAttribute("grouping") === "true" ? this.getGroupExprValue(t, this.#n.data, r, this.#r) : this.#e.exprEngine.evaluate(t, this.#n.data, r);
3110
- } catch {
3111
- return e;
3112
- }
3113
- return n ? this.value ?? e : e;
3114
- };
3115
- refresh() {
3116
- if (!this.#r || !this.#n) return;
3117
- let e = this.value;
3118
- return this.#r.classList.remove("invalid"), [
3119
- "color",
3120
- "background",
3121
- "background-color",
3122
- "visible",
3123
- "enable",
3124
- "validator"
3125
- ].forEach((e) => {
3126
- let t = this.#i[e];
3127
- if (t) {
3128
- let n = this.#e.exprEngine.evaluate(t, this.#n.data, parseInt(this.#r.dataset.row, 10));
3129
- e === "validator" ? n || this.#r.classList.add("invalid") : e === "visible" ? this.style.display = n ? "" : "none" : e === "enable" ? (this.querySelectorAll("input, button, textarea, select").forEach((e) => {
3130
- e.disabled = !n;
3131
- }), n ? this.#r.removeAttribute("disabled") : this.#r.setAttribute("disabled", "true")) : this.#r.style[e] = n;
3132
- }
3133
- }), e;
3134
- }
3135
- getExprValue(e, t, n) {
3136
- return !this.#e || !this.#e.exprEngine || e == null || e === "" ? e : this.#e.exprEngine.evaluate(e, t, n);
3137
- }
3138
- getGroupExprValue = (e, t, n, r) => {
3139
- if (!e) return "";
3140
- try {
3141
- n = parseInt(n, 10);
3142
- let i = e.replace("()", "").trim();
3143
- if (this.#e && typeof this.#e[i] == "function") return this.#e[i].call(this, t, n, r);
3144
- let a = i.match(/^(\w+)\s*\(\s*([\w\-]*)\s*\)/);
3145
- if (a) {
3146
- let e = t[GROUP_IDX.CHILDREN], n = this.#e?.data?.getArray ? this.#e.data.getArray() : [], r = e ? e.map((e) => n[e]).filter(Boolean) : [], [, i, o] = a, s = this.#e;
3147
- switch (i.toLowerCase()) {
3148
- case "count": return r.length;
3149
- case "sum": {
3150
- let e = s?.fields?.indexOf?.(o) ?? -1;
3151
- return r.reduce((t, n) => {
3152
- let r = e >= 0 ? n.v?.[e] : n[o];
3153
- return t + (Number(r) || 0);
3154
- }, 0);
3155
- }
3156
- case "avg": {
3157
- if (r.length === 0) return 0;
3158
- let e = s?.fields?.indexOf?.(o) ?? -1;
3159
- return r.reduce((t, n) => {
3160
- let r = e >= 0 ? n.v?.[e] : n[o];
3161
- return t + (Number(r) || 0);
3162
- }, 0) / r.length;
3163
- }
3164
- }
3165
- }
3166
- if (this.#e && typeof this.#e.exprFunction == "function") return this.#e.exprFunction(e).call(this, t, n, this.#e.data);
3167
- if (e.includes("data.") || e.includes("childRecords") || e.includes("groupRecord")) {
3168
- let i = L.get("grp_" + e);
3169
- return i || (i = Function("groupRecord", "row", "cell", "host", `
3170
- const indices = groupRecord[3]; // GROUP_IDX.CHILDREN = 3
3171
- const allRecords = host?.data?.getArray ? host.data.getArray() : [];
3172
-
3173
- let childRecords = [];
3174
- if (Array.isArray(indices)) {
3175
- // indices가 숫자 인덱스 배열인지, rowid 문자열 배열인지 판별하여 안전하게 추출
3176
- childRecords = indices.map(idx => {
3177
- if (typeof idx === 'number') {
3178
- return allRecords[idx];
3179
- } else {
3180
- // rowid 등 문자열 식별자인 경우 전체 배열에서 찾거나 dataManager 활용
3181
- return allRecords.find(r => r?.__ng?.rowid === idx || r?.m?._?.[0] === idx);
3182
- }
3183
- }).filter(Boolean);
3184
- }
3185
-
3186
- // 만약 위에서 못 찾았는데 host.grouping을 쓸 수 있다면 매니저 위임 시도
3187
- if (childRecords.length === 0 && host?.grouping?.getChildrenRecords && groupRecord[0]) {
3188
- childRecords = host.grouping.getChildrenRecords(groupRecord[0]);
3189
- }
3190
-
3191
- const data = childRecords; // data.length 등을 쓸 수 있도록 호환
3192
- return ${e};
3193
- `), L.set("grp_" + e, i)), i(t, n, r, this.#e);
3194
- }
3195
- return e;
3196
- } catch (t) {
3197
- return console.error("Group expr evaluation error:", e, t), e;
3198
- }
3199
- };
3200
- }, z = class extends R {
3201
- get host() {
3202
- return super.host;
3203
- }
3204
- get sheet() {
3205
- return super.sheet;
3206
- }
3207
- get cell() {
3208
- return super.cell;
3209
- }
3210
- get tr() {
3211
- return super.tr;
3212
- }
3213
- get attr() {
3214
- return super.attr;
3215
- }
3216
- getExprValue(e, t, n, r) {
3217
- return super.getExprValue(e, t, n, r);
3218
- }
3219
- constructor() {
3220
- super();
3221
- }
3222
- connectedCallback() {
3223
- super.connectedCallback();
3224
- }
3225
- refresh() {
3226
- return super.refresh();
3227
- }
3228
- getExprValue = (e, t, n, r) => super.getExprValue(e, t, n, r);
3229
- isValid = () => super.isValid();
3230
- isInvalid = () => super.isInvalid();
3231
- }, B = class extends z {
3232
- #e;
3233
- constructor() {
3234
- super();
3235
- }
3236
- connectedCallback() {
3237
- super.connectedCallback(), this.#n(), this.#e = this.querySelector("input"), this.#t();
3238
- }
3239
- refresh = () => {
3240
- let e = super.refresh();
3241
- this.#e.value = e;
3242
- };
3243
- #t = () => {
3244
- this.#e.addEventListener("input", (e) => {
3245
- if (this.#r) {
3246
- let t = Number(this.#r);
3247
- nine.getByteLength(e.target.value) > t && (e.target.value = nine.cut(e.target.value, t), this.value = e.target.value);
3248
- }
3249
- }), this.#e.addEventListener("change", (e) => {
3250
- this.value = e.target.value, this.sheet.rowManager.refresh(!0);
3251
- });
3252
- };
3253
- #n = () => {
3254
- this.innerHTML = "\n <input type=\"text\" ondragstart=\"return false;\">\n ";
3255
- };
3256
- get #r() {
3257
- return this.cell.getAttribute("maxbyte") || this.cell.getAttribute("max-byte");
3258
- }
3259
- };
3260
- customElements.get("cell-input") || customElements.define("cell-input", B);
3261
- // src/cell/cell-input-number.js
3262
- var V = class extends z {
3263
- #e;
3264
- constructor() {
3265
- super();
3266
- }
3267
- connectedCallback() {
3268
- super.connectedCallback(), this.#t(), this.#e = this.querySelector("input"), this.#n();
3269
- }
3270
- #t = () => {
3271
- this.innerHTML = "\n <input type=\"text\" ondragstart=\"return false;\">\n ";
3272
- };
3273
- #n = () => {
3274
- this.#e.addEventListener("keydown", this.#i), this.#e.addEventListener("input", (e) => {
3275
- this.value = e.target.value, this.sheet.rowManager.refresh(!0);
3276
- }), this.#e.addEventListener("change", (e) => {
3277
- this.value = e.target.value, this.sheet.rowManager.refresh(!0);
3278
- });
3279
- };
3280
- refresh = () => {
3281
- let e = super.refresh();
3282
- this.#e.value = e, this.isValid() && this.#r();
3283
- };
3284
- #r = () => {
3285
- let e = this.#e.value;
3286
- if (e !== "" && e != null) {
3287
- let t = Number(e);
3288
- if (isNaN(t) || this.#o && t > Number(this.#o) || this.#a && t < Number(this.#a)) this.cell.classList.add("invalid");
3289
- else if (this.#s) {
3290
- let t = String(e), n = t.indexOf(".");
3291
- n >= 0 && t.substring(n + 1).length > Number(this.#s) && this.cell.classList.add("invalid");
3292
- }
3293
- }
3294
- };
3295
- #i = (e) => {
3296
- if ([
3297
- "Escape",
3298
- "Enter",
3299
- "Tab",
3300
- "Home",
3301
- "End",
3302
- "ArrowLeft",
3303
- "ArrowRight",
3304
- "PageUp",
3305
- "PageDown",
3306
- "Backspace",
3307
- "Delete"
3308
- ].includes(e.code)) return;
3309
- let t = e.target, n = t.value, r = t.selectionStart, i = e.key;
3310
- if (i === "-" && (n.includes("-") || r !== 0)) {
3311
- e.preventDefault();
3312
- return;
3313
- }
3314
- if (i === ".") {
3315
- let t = Number(this.#s);
3316
- if (isNaN(t) || t <= 0 || n.includes(".")) {
3317
- e.preventDefault();
3318
- return;
3319
- }
3320
- }
3321
- let a = [];
3322
- this.#s && Number(this.#s) > 0 && a.push("."), (this.#a || Number(this.#a) > 0) && a.push("-");
3323
- let o = e.keyCode >= 48 && e.keyCode <= 57 || e.keyCode >= 96 && e.keyCode <= 105;
3324
- if (!o && !a.includes(e.key)) e.preventDefault();
3325
- else {
3326
- if (this.#s && o && e.target.selectionStart == e.target.selectionEnd) {
3327
- let t = e.target.value, n = t.indexOf(".");
3328
- n >= 0 && e.target.selectionStart > n && t.substr(n + 1).length >= Number(this.#s) && e.preventDefault();
3329
- }
3330
- this.#c && nine.getByteLength(e.target.value) >= Number(this.#c) && e.target.selectionStart == e.target.selectionEnd && e.preventDefault();
3331
- }
3332
- };
3333
- get #a() {
3334
- return this.cell.getAttribute("min") || "";
3335
- }
3336
- get #o() {
3337
- return this.cell.getAttribute("max") || "";
3338
- }
3339
- get #s() {
3340
- return this.cell.getAttribute("scale") || "";
3341
- }
3342
- get #c() {
3343
- return this.cell.getAttribute("maxbyte") || this.cell.getAttribute("max-byte");
3344
- }
3345
- };
3346
- customElements.get("cell-input-number") || customElements.define("cell-input-number", V);
3347
- // src/cell/cell-input-color.js
3348
- var H = class extends z {
3349
- #e;
3350
- #t;
3351
- #n;
3352
- constructor() {
3353
- super();
3354
- }
3355
- connectedCallback() {
3356
- super.connectedCallback(), this.#i(), this.#e = this.querySelector("input[type=color]"), this.#t = this.querySelector("button"), this.#r();
3357
- }
3358
- #r = () => {
3359
- this.#t.addEventListener("click", () => {
3360
- this.#e.click();
3361
- }), this.#e.addEventListener("input", (e) => {
3362
- let t = e.target.value;
3363
- this.value = t, this.#o(t), this.sheet.rowManager.refresh(!0);
3364
- }), this.#e.addEventListener("change", (e) => {
3365
- let t = e.target.value;
3366
- this.value = t, this.#o(t), this.sheet.rowManager.refresh(!0);
3367
- });
3368
- };
3369
- #i = () => {
3370
- this.innerHTML = "\n <input type=\"color\" ondragstart=\"return false;\">\n <button tabindex=\"-1\" type=\"button\"></button>\n ";
3371
- };
3372
- rerenderer = () => {
3373
- this.refresh();
3374
- };
3375
- #a = () => {
3376
- let e = this.cell.getAttribute("data-source");
3377
- if (e && (this.#n = super.getExprValue(e, this.tr.data, this.tr.dataset.row), this.querySelector("datalist")?.remove(), this.#n && Array.isArray(this.#n))) {
3378
- let e = `color-list-${Math.random().toString(36).substr(2, 9)}`, t = document.createElement("datalist");
3379
- t.id = e;
3380
- let n = document.createDocumentFragment();
3381
- this.#n.forEach((e) => {
3382
- if (e.value) {
3383
- let t = document.createElement("option");
3384
- t.value = e.value, n.appendChild(t);
3385
- }
3386
- }), t.appendChild(n), this.appendChild(t), this.#e.setAttribute("list", e);
3387
- }
3388
- };
3389
- refresh = () => {
3390
- if (!this.tr.data) return;
3391
- let e = super.refresh();
3392
- this.#a(), this.#e.value = e != null && e !== "" ? e : "#ffffff", this.isValid() && this.#o();
3393
- };
3394
- #o = () => {
3395
- let e = this.#e.value;
3396
- e !== "" && e != null && (this.#s(e) ? this.#n && Array.isArray(this.#n) && this.#n.length > 0 && (this.#n.some((t) => (t.value === void 0 ? t.code === void 0 ? "" : t.code : t.value).toLowerCase() === e.toLowerCase()) || this.cell.classList.add("invalid")) : this.cell.classList.add("invalid"));
3397
- };
3398
- #s = (e) => {
3399
- if (typeof e != "string" || e.length != 7 || !e.startsWith("#")) return !1;
3400
- var t = parseInt(e.substr(1, 2), 16), n = parseInt(e.substr(3, 2), 16), r = parseInt(e.substr(5, 2), 16);
3401
- return !(isNaN(t) || isNaN(n) || isNaN(r) || t < 0 || t > 255 || n < 0 || n > 255 || r < 0 || r > 255);
3402
- };
3403
- };
3404
- customElements.get("cell-input-color") || customElements.define("cell-input-color", H);
3405
- // src/cell/cell-input-date.js
3406
- var U = class extends z {
3407
- #e;
3408
- #t;
3409
- constructor() {
3410
- super();
3411
- }
3412
- connectedCallback() {
3413
- super.connectedCallback(), this.#n(), this.#e = this.querySelector("input"), this.#e.addEventListener("input", (e) => {
3414
- let t = e.target.value;
3415
- this.value = t, this.#e.classList.toggle("has-value", !!t), this.#r(t), super.sheet.rowManager.refresh(!0);
3416
- }), this.#e.addEventListener("change", (e) => {
3417
- let t = e.target.value;
3418
- this.value = t, this.#r(t), super.sheet.rowManager.refresh(!0);
3419
- });
3420
- }
3421
- #n = () => {
3422
- if (this.#t = this.cell.getAttribute("date-type") || "date", ![
3423
- "date",
3424
- "datetime-local",
3425
- "time",
3426
- "week",
3427
- "month"
3428
- ].includes(this.#t)) throw `invalid type : ${this.#t}`;
3429
- let e = [];
3430
- for (let t = 0; t < this.cell.attributes.length; t++) [
3431
- "value",
3432
- "max",
3433
- "min",
3434
- "step"
3435
- ].includes(this.cell.attributes[t].name) && e.push(`${this.cell.attributes[t].name}="${this.cell.attributes[t].value}"`);
3436
- this.innerHTML = `
3437
- <input
3438
- type="${this.#t}"
3439
- data-placeholder="${this.cell.getAttribute("placeholder") || "Select"}"
3440
- ${e.join(" ")}
3441
- required
3442
- />
3443
- `;
3444
- };
3445
- refresh = () => {
3446
- let e = super.refresh(), t = e;
3447
- if (t) switch (this.#t) {
3448
- case "date":
3449
- t = t.substr(0, 10);
3450
- break;
3451
- case "datetime-local":
3452
- t = t.substr(0, 16);
3453
- break;
3454
- case "time":
3455
- var n = new Date(e);
3456
- n != "Invalid Date" && !isNaN(n) && (t = ("00" + n.getHours()).slice(-2) + ":" + ("00" + n.getMinutes()).slice(-2));
3457
- break;
3458
- case "month":
3459
- var n = new Date(e);
3460
- n != "Invalid Date" && !isNaN(n) && (t = ("0000" + n.getFullYear()).slice(-4) + "-" + ("00" + (n.getMonth() + 1)).slice(-2));
3461
- }
3462
- this.#e.value = t || "", this.#e.classList.toggle("has-value", !!t), this.isValid() && this.#r(t);
3463
- };
3464
- #r = (e) => {
3465
- if (e !== "" && e != null) {
3466
- let t = this.#i(e);
3467
- t && (this.#a && e < this.#a && (t = !1), this.#o && e > this.#o && (t = !1)), t || super.cell.classList.add("invalid");
3468
- }
3469
- };
3470
- #i = (e) => {
3471
- if (typeof e != "string") return !1;
3472
- let t = !0;
3473
- switch (this.#t) {
3474
- case "date":
3475
- case "datetime-local":
3476
- let n = Number(e.substr(0, 4)), r = Number(e.substr(5, 2)), i = Number(e.substr(8, 2));
3477
- if (isNaN(n) || isNaN(r) || isNaN(i)) t = !1;
3478
- else if (r < 1 || r > 12 || i < 1 || i > 31) t = !1;
3479
- else if ([
3480
- 4,
3481
- 6,
3482
- 9,
3483
- 11
3484
- ].includes(r) && i == 31) t = !1;
3485
- else if (r == 2) {
3486
- let e = n % 4 == 0 && (n % 100 != 0 || n % 400 == 0);
3487
- (i > 29 || i == 29 && !e) && (t = !1);
3488
- }
3489
- }
3490
- if (t) switch (this.#t) {
3491
- case "datetime-local":
3492
- var n = e.substr(10, 1), r = Number(e.substr(11, 2)), i = Number(e.substr(14, 2));
3493
- n == "T" ? (isNaN(r) || isNaN(i) || r < 0 || r > 23 || i < 0 || i > 59) && (t = !1) : t = !1;
3494
- break;
3495
- case "month":
3496
- var a = Number(e.substr(0, 4)), o = Number(e.substr(5, 2));
3497
- (isNaN(a) || isNaN(o) || o < 1 || o > 12) && (t = !1);
3498
- break;
3499
- case "week":
3500
- var a = Number(e.substr(0, 4)), s = e.substr(5, 1), c = Number(e.substr(6, 2));
3501
- s == "W" ? (isNaN(a) || isNaN(c) || c <= 0 || c > 53) && (t = !1) : t = !1;
3502
- }
3503
- return t;
3504
- };
3505
- get #a() {
3506
- return this.cell.getAttribute("min");
3507
- }
3508
- get #o() {
3509
- return this.cell.getAttribute("max");
3510
- }
3511
- };
3512
- customElements.get("cell-input-date") || customElements.define("cell-input-date", U);
3513
- // src/cell/cell-checkbox.js
3514
- var W = class extends z {
3515
- #e;
3516
- #t;
3517
- constructor() {
3518
- super();
3519
- }
3520
- connectedCallback() {
3521
- super.connectedCallback(), this.#r(), this.#e = this.querySelector("input"), this.#t = this.querySelector("span"), this.#n();
3522
- }
3523
- get dataSource() {
3524
- return [{
3525
- value: this.trueValue,
3526
- text: this.#a
3527
- }, {
3528
- value: this.falseValue,
3529
- text: this.#o
3530
- }];
3531
- }
3532
- #n = () => {
3533
- this.closest("thead") && this.#e.addEventListener("change", (e) => {
3534
- super.sheet.querySelector(`tbody.body [data-col="${super.cell.dataset.col}"] cell-checkbox`)?.selectAll(e.target.checked);
3535
- }), this.#e.addEventListener("change", (e) => {
3536
- this.closest("tbody") && (this.#s ? (this.selectAll(!1), this.value = this.trueValue) : this.value = e.target.checked ? this.trueValue : this.falseValue, this.sheet.rowManager.refresh(!0));
3537
- });
3538
- };
3539
- #r = () => {
3540
- let e = this.trueValue, t = this.cell.getAttribute("content") || "", n = this.#s ? `<input type="radio" value="${e}" />` : `<label><input type="checkbox" /><span>${t}</span></label>`;
3541
- this.innerHTML = `
3542
- ${n}
3543
- `;
3544
- };
3545
- refresh = () => {
3546
- let e = super.refresh();
3547
- this.#e.checked = e === this.trueValue, this.isValid() && this.#i(e);
3548
- let t = e === this.trueValue ? this.#a : e === this.falseValue ? this.#o : e;
3549
- this.#t && (this.#t.textContent = t);
3550
- };
3551
- #i = (e) => {
3552
- this.cell.classList.remove("invalid"), e !== "" && e != null && e !== this.trueValue && e !== this.falseValue && this.cell.classList.add("invalid");
3553
- };
3554
- selectAll = (e) => {
3555
- if (this.closest("thead")) return;
3556
- let t = this.host.data.getArray(), n = this.host.fields.indexOf(this.cell.dataset.bind);
3557
- if (!(n < 0)) {
3558
- for (let r = 0; r < t.length; r++) this.#c && super.getExprValue(this.#c, t[r], r, this.cell) === !1 || this.#l && super.getExprValue(this.#l, t[r], r, this.cell) === !0 || this.#u && super.getExprValue(this.#u, t[r], r, this.cell) === !1 || (t[r].v[n] = e ? this.trueValue : this.falseValue);
3559
- super.sheet.invalidate();
3560
- }
3561
- };
3562
- get trueValue() {
3563
- return this.cell.getAttribute("true-value") || "Y";
3564
- }
3565
- get falseValue() {
3566
- return this.cell.getAttribute("false-value") || "N";
3567
- }
3568
- get #a() {
3569
- return this.cell.getAttribute("true-text") || "";
3570
- }
3571
- get #o() {
3572
- return this.cell.getAttribute("false-text") || "";
3573
- }
3574
- get #s() {
3575
- return this.cell.getAttribute("is-radio") || !1;
3576
- }
3577
- get #c() {
3578
- return this.cell.getAttribute("enable") || !1;
3579
- }
3580
- get #l() {
3581
- return this.cell.getAttribute("readonly") || !1;
3582
- }
3583
- get #u() {
3584
- return this.cell.getAttribute("visible") || !1;
3585
- }
3586
- };
3587
- customElements.get("cell-checkbox") || customElements.define("cell-checkbox", W);
3588
- // src/cell/cell-radio.js
3589
- var G = class extends z {
3590
- #e;
3591
- #t = [];
3592
- #n = [];
3593
- constructor() {
3594
- super();
3595
- }
3596
- connectedCallback() {
3597
- super.connectedCallback(), this.#a(), this.#i(), this.#r();
3598
- }
3599
- #r = () => {
3600
- this.cell.addEventListener("keydown", (e) => {
3601
- if (!(this.cell.hasAttribute("readonly") || this.cell.classList.contains("readonly")) && this.cell.getAttribute("disabled") !== "true" && e.code === "Space") {
3602
- e.preventDefault();
3603
- let t = -1;
3604
- this.#t.forEach((e, n) => {
3605
- if (this.value === e.getAttribute("value")) return t = n, !1;
3606
- }), t = t === this.#t.length - 1 ? 0 : t >= 0 ? t + 1 : 0, this.value = this.#t[t].getAttribute("value"), this.sheet.rowManager.refresh(!0);
3607
- }
3608
- });
3609
- };
3610
- #i = () => {
3611
- if (!this.host) return;
3612
- let e = this.cell.getAttribute("data-source");
3613
- if (e && (this.#n = super.getExprValue(e, this.tr.data, this.tr.dataset.row), this.#e.replaceChildren(), this.#n && Array.isArray(this.#n))) {
3614
- let e = document.createDocumentFragment();
3615
- this.#n.forEach((t) => {
3616
- let n = t[this.#s] === void 0 ? "" : t[this.#s], r = t[this.#c] === void 0 ? "" : t[this.#c], i = document.createElement("label"), a = document.createElement("input");
3617
- a.type = "radio", a.value = n;
3618
- let o = document.createElement("span");
3619
- o.textContent = r, i.appendChild(a), i.appendChild(o), e.appendChild(i);
3620
- }), this.#e.appendChild(e), this.#t = Array.from(this.querySelectorAll("input")), this.#t.forEach((e) => {
3621
- e.addEventListener("change", (e) => {
3622
- this.value = e.target.value, this.sheet.rowManager.refresh(!0);
3623
- });
3624
- });
3625
- }
3626
- };
3627
- #a = () => {
3628
- this.innerHTML = "\n <div></div>\n ", this.#e = this.querySelector("div");
3629
- };
3630
- rerenderer = () => {
3631
- this.#i(), this.refresh();
3632
- };
3633
- refresh = () => {
3634
- let e = super.refresh();
3635
- this.#t.forEach((t) => {
3636
- t.checked = e === t.value;
3637
- }), this.isValid() && this.#o();
3638
- };
3639
- #o = () => {
3640
- this.value !== null && this.value !== void 0 && this.value !== "" && Array.isArray(this.#n) && this.#n.findIndex((e) => this.value === e[this.#s]) < 0 && this.cell.classList.add("invalid");
3641
- };
3642
- get dataSource() {
3643
- return this.#n;
3644
- }
3645
- get #s() {
3646
- return this.cell.getAttribute("key-name") || "k";
3647
- }
3648
- get #c() {
3649
- return this.cell.getAttribute("value-name") || "v";
3650
- }
3651
- };
3652
- customElements.get("cell-radio") || customElements.define("cell-radio", G);
3653
- // src/cell/cell-combo-panel.js
3654
- var K = class extends HTMLElement {
3655
- #e;
3656
- #t;
3657
- #n;
3658
- #r = !1;
3659
- constructor() {
3660
- super();
3661
- }
3662
- connectedCallback() {
3663
- this.#u(), this.#l();
3664
- }
3665
- #i = (e, t, n, r, i) => {
3666
- let a = this.querySelector("nine-table-simple");
3667
- if (!a || !e || e.length === 0) return;
3668
- let o = this.#e.getAttribute("items"), s = [];
3669
- s = o ? o.split(",").map((e) => e.trim()) : [n].filter(Boolean);
3670
- let c = s.length;
3671
- a.shadowRoot.querySelector(".ng-container-left").style.display = r ? "" : "none", a.shadowRoot.querySelectorAll("table colgroup col, tbody td").forEach((e, t) => {
3672
- let n = parseInt(e.dataset.col, 10);
3673
- n >= 2 && (e.style.display = n - 2 >= c ? "none" : "");
3674
- });
3675
- let l = e.map((e) => {
3676
- let n = {
3677
- CHK: "N",
3678
- k: t && e[t] !== void 0 ? e[t] : e[0] === void 0 ? "" : e[0]
3679
- };
3680
- return s.forEach((t, r) => {
3681
- n[`tmp${r + 1}`] = e[t] === void 0 ? e[r] === void 0 ? "" : e[r] : e[t];
3682
- }), n;
3683
- });
3684
- if (a.data.set(l), r && this.#e.value) {
3685
- let e = String(this.#e.value).split(i || ",");
3686
- a.data.getValidData().forEach((t) => {
3687
- e.includes(String(t.v[1])) && (t.v[0] = "Y");
3688
- }), a.refreshData();
3689
- }
3690
- };
3691
- open = (e, t, n, r, i, a) => {
3692
- this.#e = e, this.#t = n, this.#n = r, this.#r = !0, this.classList.add("active");
3693
- let o = this.querySelector("nine-table-simple");
3694
- if (!o || !t) return;
3695
- this.querySelector(".search-input").value = "", this.querySelector("#chkAll").checked = !0, t.length > 10 ? this.classList.add("expand") : this.classList.remove("expand"), i ? this.classList.add("multi") : this.classList.remove("multi");
3696
- let s = e.closest("nine-table-sheet"), c = e.querySelector(".btn1");
3697
- if (!c || !s) return;
3698
- let l = c.getBoundingClientRect(), u = s.getBoundingClientRect(), d = l.left - u.left, f = l.bottom - u.top + 2, p = this.offsetWidth || 250, m = this.offsetHeight || 250;
3699
- if (d + p > u.width && (d = Math.max(0, u.width - p - 5)), d < 0 && (d = 5), f + m > u.height) {
3700
- let e = l.top - u.top - m - 2;
3701
- f = e >= 0 ? e : Math.max(0, u.height - m - 5);
3702
- }
3703
- this.style.left = `${d}px`, this.style.top = `${f}px`, setTimeout(() => {
3704
- this.#i(t, n, r, i, a);
3705
- let e = o.shadowRoot.querySelector(".ng-container-body table tbody.body");
3706
- e.__hasClickEvent ||= (e.addEventListener("mousedown", (e) => {
3707
- e.target.closest("tr") && (i || this.#a(e));
3708
- }), !0);
3709
- }, 100);
3710
- };
3711
- close = () => {
3712
- this.classList.remove("active"), this.#r = !1, this.#e && this.#e.cell && this.#e.cell.focus();
3713
- };
3714
- #a = (e) => {
3715
- let t = e.target.closest("nine-table-sheet"), n = e.target.closest("tr"), r = parseInt(n.dataset.row, 10), i = t.view.get(r);
3716
- this.#e.value = i.k, this.#e.sheet.rowManager.refresh(!0), this.close();
3717
- };
3718
- #o = () => {
3719
- let e = this.querySelector("nine-table-simple").data.getValidData(), t = [];
3720
- e.forEach((e) => {
3721
- e.v[0] === "Y" && t.push(e.v[1]);
3722
- }), this.#e.value = t.join(this.#e.getAttribute("multi-separator") || ","), this.#e.sheet.rowManager.refresh(!0), this.close();
3723
- };
3724
- #s = (e) => {
3725
- let t = this.querySelector("nine-table-simple"), n = e.target.checked ? "Y" : "N";
3726
- t.data.getValidData().forEach((e) => {
3727
- e.v[0] = n;
3728
- }), t.refreshData();
3729
- };
3730
- #c = (e) => {
3731
- let t = e.target.value.toLowerCase(), n = this.querySelector("nine-table-simple");
3732
- n.data.getValidDataNF().forEach((e) => {
3733
- let n = Object.values(e.v).some((e) => e != null && String(e).toLowerCase().includes(t));
3734
- e.__ng.filtered = !n;
3735
- }), n.data.resetRecords(), n.dataManager.viewRecords.reset();
3736
- };
3737
- get isOpen() {
3738
- return this.#r;
3739
- }
3740
- get targetCell() {
3741
- return this.#e;
3742
- }
3743
- #l = () => {
3744
- this.querySelector(".search-input").addEventListener("input", this.#c), this.querySelector("#btnOk").addEventListener("click", this.#o), this.querySelector("#chkAll").addEventListener("change", this.#s), document.addEventListener("mousedown", (e) => {
3745
- (e.composedPath ? e.composedPath() : []).includes(this) || this.close();
3746
- });
3747
- };
3748
- #u = () => {
3749
- this.innerHTML = "\n <div class=\"head\">\n <input type=\"text\" class=\"search-input\" placeholder=\"Search...\" />\n </div>\n \n <nine-table-simple class=\"combo-list\" theme=\"simple\">\n <table auto-fit-col=\"true\">\n <colgroup>\n <col width=\"30\" fixed=\"left\" />\n <col width=\"100\" />\n <col width=\"100\" />\n <col width=\"100\" />\n <col width=\"100\" />\n <col width=\"100\" />\n <col width=\"100\" />\n <col width=\"100\" />\n <col width=\"100\" />\n <col width=\"100\" />\n <col width=\"100\" />\n <col width=\"0\" />\n </colgroup>\n <tbody>\n <tr>\n <td cell-type=\"checkbox\" data-bind=\"CHK\"></td>\n <td data-bind=\"tmp1\" />\n <td data-bind=\"tmp2\" />\n <td data-bind=\"tmp3\" />\n <td data-bind=\"tmp4\" />\n <td data-bind=\"tmp5\" />\n <td data-bind=\"tmp6\" />\n <td data-bind=\"tmp7\" />\n <td data-bind=\"tmp8\" />\n <td data-bind=\"tmp9\" />\n <td data-bind=\"tmp10\" />\n <td data-bind=\"k\" />\n </tr>\n </tbody>\n </table>\n </nine-table-simple>\n \n <div class=\"footer\">\n <div>\n <input id=\"chkAll\" type=\"checkbox\" checked>\n <label for=\"chkAll\">Select All</label>\n </div>\n <button id=\"btnOk\">OK</button>\n </div>\n ";
3750
- };
3751
- };
3752
- customElements.get("cell-combo-panel") || customElements.define("cell-combo-panel", K);
3753
- // src/cell/cell-combo.js
3754
- var q = class extends z {
3755
- #e;
3756
- #t = [];
3757
- #n;
3758
- #r;
3759
- #i;
3760
- #a;
3761
- #o;
3762
- constructor() {
3763
- super();
3764
- }
3765
- connectedCallback() {
3766
- this.#u(), super.connectedCallback(), this.#n = super.cell.getAttribute("key-name") || "k", this.#r = super.cell.getAttribute("value-name") || "v", this.#i = super.cell.getAttribute("multi") === "true", this.#a = super.cell.getAttribute("multi-separator") || ",", this.#s(), this.#c();
3767
- }
3768
- rerenderer = () => {
3769
- this.#s(), this.refresh();
3770
- };
3771
- #s = () => {
3772
- if (!super.sheet || !super.cell) return;
3773
- let e = super.cell?.getAttribute("data-source");
3774
- e && (this.#t = super.getExprValue(e, super.tr.data, super.tr.dataset.row));
3775
- };
3776
- #c = () => {
3777
- this.querySelectorAll("button").forEach((e) => {
3778
- e.addEventListener("click", (e) => {
3779
- e.stopPropagation(), this.#l();
3780
- });
3781
- });
3782
- };
3783
- #l = () => {
3784
- this.#o || (this.#o = super.sheet.querySelector("cell-combo-panel"), this.#o || (this.#o = document.createElement("cell-combo-panel"), super.sheet.appendChild(this.#o))), this.#o.isOpen && this.#o.targetCell === this ? this.#o.close() : this.#o.open(this, this.#t, this.#n, this.#r, this.#i, this.#a);
3785
- };
3786
- #u = () => {
3787
- this.innerHTML = "\n <button class=\"btn1\" type=\"button\" tabindex=\"-1\">Select</button>\n <button class=\"btn2\" type=\"button\" tabindex=\"-1\"></button>\n ", this.#e = this.querySelector(".btn1");
3788
- };
3789
- refresh = () => {
3790
- let e = super.refresh();
3791
- return this.#e && (this.#e.textContent = this.#d() || "Select", this.#f()), e;
3792
- };
3793
- #d = () => {
3794
- if (!this.value || !Array.isArray(this.#t)) return "";
3795
- if (this.#i) {
3796
- let e = String(this.value).split(this.#a);
3797
- return this.#t.filter((t) => e.includes(String(t[this.#n]))).map((e) => e[this.#r]).join(this.#a);
3798
- }
3799
- {
3800
- let e = this.#t.find((e) => String(e[this.#n]) === String(this.value));
3801
- return e ? e[this.#r] : this.value;
3802
- }
3803
- };
3804
- #f = () => {
3805
- if (!super.cell || (super.cell.classList.remove("invalid"), this.value === null || this.value === void 0 || this.value === "" || !Array.isArray(this.#t))) return;
3806
- let e = this.#i ? String(this.value).split(this.#a) : [this.value];
3807
- for (let t of e) if (this.#t.findIndex((e) => String(t) === String(e[this.#n])) < 0) {
3808
- super.cell.classList.add("invalid");
3809
- break;
3810
- }
3811
- };
3812
- get dataSource() {
3813
- return this.#t;
3814
- }
3815
- };
3816
- customElements.get("cell-combo") || customElements.define("cell-combo", q);
3817
- // src/cell/cell-renderer.js
3818
- var J = class extends R {
3819
- #e;
3820
- constructor() {
3821
- super();
3822
- }
3823
- connectedCallback() {
3824
- super.connectedCallback(), this.#t(), this.#e = this.querySelector("span");
3825
- }
3826
- refresh = () => {
3827
- super.refresh(), this.cell.getAttribute("html") === "true" ? this.#e.innerHTML = this.getDisplayText() : this.#e.textContent = this.getDisplayText();
3828
- };
3829
- #t = () => {
3830
- this.innerHTML = "\n <span class=\"wrapper\"></span>\n ";
3831
- };
3832
- };
3833
- customElements.get("cell-renderer") || customElements.define("cell-renderer", J);
3834
- // src/cell/cell-button.js
3835
- var Y = class extends R {
3836
- #e;
3837
- constructor() {
3838
- super();
3839
- }
3840
- connectedCallback() {
3841
- this.#n(), super.connectedCallback(), this.#e = this.querySelector("button"), this.#e.removeEventListener("click", this.#t), this.#e.addEventListener("click", this.#t);
3842
- }
3843
- #t = (e) => {
3844
- e.stopPropagation();
3845
- let t = parseInt(this.cell.dataset.row, 10), n = new CustomEvent(r.EVENT.CELL_BUTTON_CLICK, {
3846
- bubbles: !0,
3847
- composed: !0,
3848
- detail: {
3849
- originalEvent: e,
3850
- cell: this.cell,
3851
- row: t,
3852
- col: parseInt(this.cell.dataset.col, 10),
3853
- bind: this.dataset.bind,
3854
- data: this.host.data.get(t),
3855
- value: this.value
3856
- }
3857
- });
3858
- this.dispatchEvent(n);
3859
- };
3860
- refresh = () => {
3861
- let e = super.refresh ? super.refresh() : this.value;
3862
- this.#e.innerHTML = this.getDisplayText(e);
3863
- };
3864
- #n = () => {
3865
- this.innerHTML = "\n <button class=\"button\">...</button>\n ";
3866
- };
3867
- };
3868
- customElements.get("cell-button") || customElements.define("cell-button", Y);
3869
- // src/cell/cell-row-indicator.js
3870
- var X = class extends R {
3871
- #e;
3872
- #t;
3873
- #n;
3874
- constructor() {
3875
- super();
3876
- }
3877
- connectedCallback() {
3878
- this.#r(), super.connectedCallback(), this.cell && (this.cell.removeAttribute("tabindex"), this.cell.dataset.bind = "rowState"), this.#e = this.querySelector(".ng-row-main"), this.#t = this.querySelector(".ng-row-sub"), this.#n = this.querySelector(".ng-row-status");
3879
- }
3880
- #r = () => {
3881
- this.innerHTML = "\n <span class=\"ng-row-main\"></span>\n <span class=\"ng-row-sub\"></span>\n <span class=\"ng-row-status\"></span>\n ";
3882
- };
3883
- refresh = () => {
3884
- if (!this.cell || !this.tr) return;
3885
- let e = this.row;
3886
- if (isNaN(e)) return;
3887
- let t = this.tr.data;
3888
- t && t.__ng;
3889
- let n = this.index + 1, r = n.toLocaleString();
3890
- if (n >= 1e4) {
3891
- let e = r.length - 4, t = r.substring(0, e + 1), n = r.substring(e + 1);
3892
- this.#e.innerHTML = `
3893
- <span class="ng-row-prefix">${t}</span>
3894
- <span class="ng-row-suffix">${n}</span>
3895
- `;
3896
- } else this.#e.innerHTML = `${r}`;
3897
- let i = !!this.sheet.querySelector("thead .asc,thead .desc"), a = !!this.sheet.querySelector("thead nine-table-filter-button.filtered");
3898
- this.#t.innerHTML = e, this.#t.style.display = i || a ? "" : "none";
3899
- };
3900
- };
3901
- customElements.get("cell-row-indicator") || customElements.define("cell-row-indicator", X);
3902
- // src/col/col-expand.js
3903
- var Z = class extends HTMLElement {
3904
- #e;
3905
- #t;
3906
- constructor() {
3907
- super();
3908
- }
3909
- connectedCallback() {
3910
- this.#t = this.closest("th, td"), this.#e = this.closest("nine-table-sheet"), this.#t && (this.#t.style.position = "relative"), this.getAttribute("collapsed") === "true" || this.#t?.getAttribute("collapsed") === "true" ? requestAnimationFrame(() => {
3911
- this.collapse(!0);
3912
- }) : (this.classList.remove("collapsed"), this.classList.add("expand")), this.removeEventListener("click", this.#n), this.addEventListener("click", this.#n);
3913
- }
3914
- #n = (e) => {
3915
- e.preventDefault(), e.stopPropagation(), this.classList.contains("expand") ? this.collapse() : this.expand();
3916
- };
3917
- expand = () => {
3918
- if (!this.#e?.colResizer || !this.#t) return;
3919
- let e = parseInt(this.#t.dataset.col, 10), t = this.#t.colSpan || 1;
3920
- this.classList.remove("collapsed"), this.classList.add("expand"), this.#t.setAttribute("collapsed", "false"), this.#t.style.color = "";
3921
- let n = parseInt(this.#t.dataset.expandWidth, 10) || 100;
3922
- if (t === 1) this.#e.colResizer.setColumnWidth(e, n);
3923
- else {
3924
- let r = Math.max(30, Math.floor(n / t));
3925
- for (let n = 0; n < t; n++) this.#e.colResizer.setColumnWidth(e + n, r);
3926
- }
3927
- requestAnimationFrame(() => {
3928
- typeof this.#e.refreshLayout == "function" && this.#e.refreshLayout();
3929
- });
3930
- };
3931
- collapse = (e = !1) => {
3932
- if (!this.#e?.colResizer || !this.#t) return;
3933
- let t = parseInt(this.#t.dataset.col, 10), n = this.#t.colSpan || 1;
3934
- if (this.classList.contains("expand")) {
3935
- let e = this.#e.querySelector(`colgroup col[data-col="${t}"]`), r = e ? parseInt(e.getAttribute("width"), 10) : 0;
3936
- r > 16 && (this.#t.dataset.expandWidth = String(r * n));
3937
- }
3938
- if (this.classList.remove("expand"), this.classList.add("collapsed"), this.#t.setAttribute("collapsed", "true"), this.#t.style.color = "transparent", n === 1) this.#e.colResizer.setColumnWidth(t, 16);
3939
- else {
3940
- let e = Math.max(10, Math.floor(16 / n));
3941
- for (let r = 0; r < n; r++) this.#e.colResizer.setColumnWidth(t + r, e);
3942
- }
3943
- requestAnimationFrame(() => {
3944
- typeof this.#e.refreshLayout == "function" && this.#e.refreshLayout();
3945
- });
3946
- };
3947
- disconnectedCallback() {
3948
- this.removeEventListener("click", this.#n);
3949
- }
3950
- };
3951
- customElements.get("nine-table-col-expand") || customElements.define("nine-table-col-expand", Z);
3952
- // src/menu/nine-table-menu.js
3953
- var Q = class extends HTMLElement {
3954
- #e;
3955
- #t;
3956
- connectedCallback() {
3957
- let e = this.getRootNode();
3958
- this.#e = e instanceof ShadowRoot ? e.host : this.closest("nine-table") || e.host, this.#e ||= this.parentElement?.closest("nine-table") || this.assignedSlot?.closest("nine-table"), this.#e;
3959
- }
3960
- #n = (e) => {
3961
- let t = e.composedPath ? e.composedPath() : [], n = t.find((e) => e.tagName === "TH" || e.tagName === "TD");
3962
- if (!n) return;
3963
- let r = t.find((e) => e.tagName === "TABLE") || n.closest("table");
3964
- e.preventDefault(), e.stopPropagation(), this.openMenu(e.clientX, e.clientY, n, r);
3965
- };
3966
- #r(e) {
3967
- return e?.closest("nine-table-sheet") || this.#e.activeSheet || this.#e;
3968
- }
3969
- #i(e) {
3970
- let t = this.#r(e);
3971
- return t ? (t.colFix ||= new T(t), t.colFix) : null;
3972
- }
3973
- #a(e, t) {
3974
- let n = [], r = t?.id;
3975
- return Array.from(e.querySelectorAll(":scope > ul")).forEach((e) => {
3976
- let t = e.getAttribute("target-table");
3977
- if (!t || r && t === r) {
3978
- let t = this.#o(e);
3979
- n.push(...t);
3980
- }
3981
- }), n;
3982
- }
3983
- #o(e) {
3984
- let t = [];
3985
- return Array.from(e.children).forEach((e) => {
3986
- let n = e.tagName.toLowerCase();
3987
- if (n === "hr" || e.classList.contains("separator")) t.push({ type: "separator" });
3988
- else if (n === "li") {
3989
- let n = "", r = e.querySelector(":scope > span");
3990
- n = r ? r.textContent.trim() : Array.from(e.childNodes).filter((e) => e.nodeType === Node.TEXT_NODE).map((e) => e.textContent.trim()).join("");
3991
- let i = e.querySelector(":scope > ul"), a = {
3992
- menuId: e.id || n,
3993
- name: n,
3994
- className: e.className || "",
3995
- disabled: e.hasAttribute("disabled") || e.getAttribute("disabled") === "true",
3996
- isCustom: !0
3997
- };
3998
- i && (a.items = this.#o(i)), t.push(a);
3999
- }
4000
- }), t;
4001
- }
4002
- #s(e, t, n) {
4003
- let r = this.getAttribute("use-default-menu") !== "false", i = [], a = this.#a(this, e);
4004
- a.length > 0 && i.push(...a);
4005
- let o = this.#i(n), s = o?.getFixState(n, e) ?? "none", c = t && (o?.canFixColumn(n, e) ?? !1), l = null;
4006
- l = s === "left" || s === "right" ? {
4007
- menuId: "unfix-column",
4008
- name: "Unfix Column",
4009
- className: "ng-menu-unfix-col",
4010
- disabled: !t
4011
- } : {
4012
- menuId: "fix-column",
4013
- name: "Fix Column",
4014
- className: "ng-menu-fix-col",
4015
- disabled: !c
4016
- }, r && i.push({ type: "separator" }, {
4017
- menuId: "sort",
4018
- name: "Sort",
4019
- className: "ng-menu-sort",
4020
- disabled: !t
4021
- }, l, { type: "separator" }, {
4022
- menuId: "filtering",
4023
- name: "Filtering",
4024
- className: "ng-menu-filtering"
4025
- }, {
4026
- menuId: "maximize",
4027
- name: "Maximize",
4028
- className: "maximize"
4029
- }, {
4030
- menuId: "export",
4031
- name: "Export",
4032
- className: "export",
4033
- items: [{
4034
- menuId: "export-excel",
4035
- name: "Excel",
4036
- className: "export-excel"
4037
- }, {
4038
- menuId: "export-pdf",
4039
- name: "PDF",
4040
- className: "export-pdf",
4041
- disabled: !0
4042
- }]
4043
- }, {
4044
- menuId: "properties",
4045
- name: "Options",
4046
- className: "options",
4047
- items: [
4048
- {
4049
- menuId: "show-title-bar",
4050
- name: "Title Bar Show/Hide",
4051
- className: "show-title-bar"
4052
- },
4053
- {
4054
- menuId: "show-status-bar",
4055
- name: "Status Bar Show/Hide",
4056
- className: "show-status-bar"
4057
- },
4058
- {
4059
- menuId: "auto-fit-col",
4060
- name: "Auto Fit Columns",
4061
- className: "auto-fit-col"
4062
- }
4063
- ]
4064
- });
4065
- let u = [];
4066
- return i.forEach((e) => {
4067
- (e.type !== "separator" || u.length !== 0 && u[u.length - 1].type !== "separator") && u.push(e);
4068
- }), u.length > 0 && u[u.length - 1].type === "separator" && u.pop(), u;
4069
- }
4070
- openMenu(e, t, n, r) {
4071
- let i = this.#e.shadowRoot || this.#e;
4072
- this.#t || (this.#t = document.createElement("nine-table-menu-panel"), i.appendChild(this.#t));
4073
- let a = !!n.closest("thead"), o = this.#s(r, a, n);
4074
- this.#t.render(o, (e) => this.#l(e, n, r));
4075
- let s = this.#r(n);
4076
- this.#c(s), this.#t.openAt(e, t);
4077
- }
4078
- #c(e) {
4079
- if (!this.#t || !e) return;
4080
- let t = e.filtering?.isFiltering?.() || !1;
4081
- this.#t.toggleItemState("filtering", "on", t);
4082
- let n = this.#e.getAttribute("auto-fit-col") === "true";
4083
- this.#t.toggleItemState("auto-fit-col", "on", n);
4084
- let r = this.#e.getAttribute("show-title-bar") === "true";
4085
- this.#t.toggleItemState("show-title-bar", "on", r);
4086
- }
4087
- #l(e, t, n) {
4088
- let r = e.menuId, i = new CustomEvent("menu-click", {
4089
- detail: {
4090
- menuId: r,
4091
- targetCell: t,
4092
- targetTable: n,
4093
- originalEvent: e
4094
- },
4095
- bubbles: !0,
4096
- composed: !0
4097
- });
4098
- this.dispatchEvent(i);
4099
- let a = parseInt(t.dataset.col, 10), o = this.#r(t);
4100
- switch (r) {
4101
- case "fix-column":
4102
- case "unfix-column":
4103
- this.#i(t)?.executeFixToggle(r, t);
4104
- break;
4105
- case "sort":
4106
- isNaN(a) || o.sorting?.handleSortFromMenu?.(a, t);
4107
- break;
4108
- case "filtering":
4109
- o?.filtering?.toggle();
4110
- break;
4111
- case "auto-fit-col":
4112
- this.#e.setAttribute("auto-fit-col", this.#e.getAttribute("auto-fit-col") === "true" ? "false" : "true");
4113
- break;
4114
- case "show-title-bar": this.#e.setAttribute("show-title-bar", this.#e.getAttribute("show-title-bar") === "true" ? "false" : "true");
4115
- }
4116
- this.#t.close();
4117
- }
4118
- disconnectedCallback() {
4119
- this.#e?.removeEventListener("contextmenu", this.#n);
4120
- }
4121
- };
4122
- customElements.get("nine-table-menu") || customElements.define("nine-table-menu", Q);
4123
- // src/menu/nine-table-menu-panel.js
4124
- var $ = class extends HTMLElement {
4125
- #e;
4126
- #t = null;
4127
- constructor() {
4128
- super();
4129
- }
4130
- connectedCallback() {
4131
- this.style.position = "fixed", this.style.display = "none", this.style.zIndex = "99999", this.innerHTML = "\n <div class=\"menu-wrapper\">\n <ul class=\"menu-container\"></ul>\n </div>\n ";
4132
- }
4133
- render(e, t) {
4134
- this.#e = t;
4135
- let n = this.querySelector(".menu-container");
4136
- n && (n.innerHTML = "", this.#n(n, e), this.#r());
4137
- }
4138
- openAt(e, t, n = null) {
4139
- if (this.style.display = "block", n) {
4140
- let e = n.getBoundingClientRect(), r = e.right;
4141
- requestAnimationFrame(() => {
4142
- let n = this.querySelector(".menu-wrapper");
4143
- if (!n) return;
4144
- let i = n.getBoundingClientRect().width, a = r - i;
4145
- a < 0 && (a = e.left);
4146
- let o = n.getBoundingClientRect().height, s = t;
4147
- t + o > window.innerHeight && (s = t - o), this.style.left = `${a}px`, this.style.top = `${s}px`;
4148
- });
4149
- } else this.style.left = `${e}px`, this.style.top = `${t}px`, requestAnimationFrame(() => {
4150
- let n = this.querySelector(".menu-wrapper");
4151
- if (!n) return;
4152
- let r = n.getBoundingClientRect();
4153
- e + r.width > window.innerWidth && (this.style.left = `${e - r.width}px`), t + r.height > window.innerHeight && (this.style.top = `${t - r.height}px`);
4154
- });
4155
- this.#t && window.removeEventListener("pointerdown", this.#t), this.#t = (e) => {
4156
- !(e.composedPath ? e.composedPath() : []).includes(this) && !this.contains(e.target) && this.close();
4157
- }, setTimeout(() => {
4158
- window.addEventListener("pointerdown", this.#t);
4159
- }, 0);
4160
- }
4161
- close() {
4162
- this.style.display = "none", this.#t &&= (window.removeEventListener("pointerdown", this.#t), null);
4163
- }
4164
- toggleItemState(e, t, n) {
4165
- let r = this.querySelector(`li[menu-id="${e}"]`);
4166
- r && (n ? r.classList.add(t) : r.classList.remove(t));
4167
- }
4168
- #n(e, t) {
4169
- t.forEach((t) => {
4170
- if (t.type === "separator") {
4171
- let t = document.createElement("li");
4172
- t.className = "ng-menu-separator", e.appendChild(t);
4173
- return;
4174
- }
4175
- let n = document.createElement("li");
4176
- n.setAttribute("menu-id", t.menuId), n.className = `${t.className || ""} ${t.items ? "submenu" : ""} ${t.disabled ? "disabled" : ""}`.trim();
4177
- let r = document.createElement("span");
4178
- if (r.textContent = t.name, n.appendChild(r), t.items && t.items.length > 0) {
4179
- let e = document.createElement("ul");
4180
- e.className = "ng-menu-sublist", this.#n(e, t.items), n.appendChild(e);
4181
- }
4182
- e.appendChild(n);
4183
- });
4184
- }
4185
- #r() {
4186
- this.querySelectorAll("li[menu-id]").forEach((e) => {
4187
- e.addEventListener("click", (t) => {
4188
- if (t.stopPropagation(), e.classList.contains("disabled")) return;
4189
- let n = e.getAttribute("menu-id");
4190
- this.#e?.({
4191
- menuId: n,
4192
- target: e
4193
- }), this.close();
4194
- });
4195
- });
4196
- }
4197
- disconnectedCallback() {
4198
- this.close();
4199
- }
4200
- };
4201
- customElements.get("nine-table-menu-panel") || customElements.define("nine-table-menu-panel", $);
4202
- export { r as NINE_TABLE };
4203
-
4204
- //# sourceMappingURL=nine-table.js.map