spaday-regular-table 0.1.0__py3-none-any.whl
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.
- spaday_regular_table/__init__.py +48 -0
- spaday_regular_table/components.cem.json +39 -0
- spaday_regular_table/components.py +42 -0
- spaday_regular_table/example.py +267 -0
- spaday_regular_table/extension/cdn/index.js +1202 -0
- spaday_regular_table/extension/cdn/index.js.map +7 -0
- spaday_regular_table/extension/css/material.css +1 -0
- spaday_regular_table/extension/index.html +13 -0
- spaday_regular_table/tests/test_all.py +66 -0
- spaday_regular_table/tests/test_example.py +34 -0
- spaday_regular_table-0.1.0.dist-info/METADATA +111 -0
- spaday_regular_table-0.1.0.dist-info/RECORD +15 -0
- spaday_regular_table-0.1.0.dist-info/WHEEL +4 -0
- spaday_regular_table-0.1.0.dist-info/entry_points.txt +2 -0
- spaday_regular_table-0.1.0.dist-info/licenses/LICENSE +201 -0
|
@@ -0,0 +1,1202 @@
|
|
|
1
|
+
// node_modules/.pnpm/regular-table@0.9.0/node_modules/regular-table/dist/esm/regular-table.js
|
|
2
|
+
var G = 0;
|
|
3
|
+
var k = 0;
|
|
4
|
+
var te = performance.now();
|
|
5
|
+
function ie() {
|
|
6
|
+
let w = performance.now(), e = w - te, t = G, i = k * 1e3 / e, s = 1e3 / t, n = k;
|
|
7
|
+
return G = 0, k = 0, te = w, { avg: t, real_fps: i, virtual_fps: s, num_frames: n, elapsed: e };
|
|
8
|
+
}
|
|
9
|
+
function se(w) {
|
|
10
|
+
G = (G * k + w) / (k + 1), k += 1;
|
|
11
|
+
}
|
|
12
|
+
var z = /* @__PURE__ */ new Map();
|
|
13
|
+
async function ne(w) {
|
|
14
|
+
return await new Promise(requestAnimationFrame), await z.get(w)?.promise;
|
|
15
|
+
}
|
|
16
|
+
async function $(w, e) {
|
|
17
|
+
if (z.has(w) && (await z.get(w)?.promise, z.has(w))) {
|
|
18
|
+
await z.get(w)?.promise;
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
z.set(w, Promise.withResolvers());
|
|
22
|
+
try {
|
|
23
|
+
return await e();
|
|
24
|
+
} finally {
|
|
25
|
+
let t = z.get(w);
|
|
26
|
+
z.delete(w), t?.resolve(void 0);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
var me = navigator.userAgent.toLowerCase().indexOf("firefox") > -1;
|
|
30
|
+
var re = me ? 5e6 : 1e7;
|
|
31
|
+
var oe = ":host{position:absolute;top:0px;left:0px;right:0px;bottom:0px;overflow:scroll;overflow-anchor:none;overscroll-behavior:none;-webkit-overflow-scrolling:touch;}div.rt-virtual-panel{position:absolute;top:0;left:0;right:0;pointer-events:none;}div.rt-scroll-table-clip{position:sticky;contain:strict;overflow-anchor:none;width:100%;height:100%;}slot{position:absolute;overflow:hidden;overflow-anchor:none;}";
|
|
32
|
+
var le = ":host ::slotted(table){--regular-table--transform-x:0px;--regular-table--transform-y:0px;--regular-table--clip-x:0px;--regular-table--clip-y:0px;}";
|
|
33
|
+
var be = "--regular-table--clip-x";
|
|
34
|
+
var pe = "--regular-table--clip-y";
|
|
35
|
+
var we = "--regular-table--transform-x";
|
|
36
|
+
var ge = "--regular-table--transform-y";
|
|
37
|
+
var Me = '<div class="rt-virtual-panel"></div><div class="rt-scroll-table-clip"><slot></slot></div>';
|
|
38
|
+
var ve = 1;
|
|
39
|
+
var q = class extends HTMLElement {
|
|
40
|
+
f;
|
|
41
|
+
a;
|
|
42
|
+
i;
|
|
43
|
+
r;
|
|
44
|
+
G;
|
|
45
|
+
q;
|
|
46
|
+
_;
|
|
47
|
+
b;
|
|
48
|
+
p;
|
|
49
|
+
U;
|
|
50
|
+
s;
|
|
51
|
+
e;
|
|
52
|
+
t;
|
|
53
|
+
it;
|
|
54
|
+
st;
|
|
55
|
+
table_model;
|
|
56
|
+
n;
|
|
57
|
+
T;
|
|
58
|
+
Y;
|
|
59
|
+
h;
|
|
60
|
+
o;
|
|
61
|
+
async draw(e = {}) {
|
|
62
|
+
return typeof e.throttle < "u" && !e.throttle ? await he.call(this, e) : await $(this, () => he.call(this, e));
|
|
63
|
+
}
|
|
64
|
+
async flush() {
|
|
65
|
+
do
|
|
66
|
+
await ne(this);
|
|
67
|
+
while (this.T);
|
|
68
|
+
}
|
|
69
|
+
async predraw(e, t, i = {}) {
|
|
70
|
+
let { invalid_viewport: s = true, preserve_width: n = false, cache: r = false, scroll_left: o = this.scrollLeft, scroll_top: l = this.scrollTop, container_height: u = t, throttle: d } = i, h = () => Object.assign(() => true, { inline: true }), a = async () => (await this.draw({ invalid_viewport: s, preserve_width: n, cache: r, throttle: d }), h());
|
|
71
|
+
if (!this.t) return console.warn("data listener not configured"), h();
|
|
72
|
+
let { num_columns: _, num_rows: p } = await this.j(r);
|
|
73
|
+
if (!this.e.row_height) return await a();
|
|
74
|
+
let c = p || 0, M = _ || 0, f = this.K(() => e, () => t, () => u);
|
|
75
|
+
this.r = f;
|
|
76
|
+
let m = Math.round(this.P(c)), T = Number.isFinite(f.containerHeight) ? Math.min(l, Math.max(0, m - f.containerHeight)) : l, b, v, L = false, y = false;
|
|
77
|
+
for (let V = 0; V < 2; V++) {
|
|
78
|
+
let D = this.t.row_headers_length, S = this.Z(c, M, T, o), A = this.Ce(S, M);
|
|
79
|
+
if (A === void 0) return await a();
|
|
80
|
+
if (S.end_col = Math.min(M, A + ve), V === 0) {
|
|
81
|
+
let { invalid_row: C, invalid_column: H } = this.J(S);
|
|
82
|
+
y = !!(this.p || H), L = y || C || s;
|
|
83
|
+
} else if (Math.floor(S.start_col) === Math.floor(b.start_col) && Math.ceil(S.end_col) <= Math.ceil(b.end_col)) {
|
|
84
|
+
S.end_col = b.end_col, b = S;
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
if (b = S, !L) break;
|
|
88
|
+
v = await this.t.view(Math.floor(b.start_col), Math.floor(b.start_row), Math.ceil(b.end_col), Math.ceil(b.end_row));
|
|
89
|
+
let g = v.num_row_headers ?? v.row_headers?.[0]?.length ?? 0;
|
|
90
|
+
if (g === D) break;
|
|
91
|
+
this.t.row_headers_length = g;
|
|
92
|
+
}
|
|
93
|
+
let E = this.t;
|
|
94
|
+
return Object.assign(() => {
|
|
95
|
+
if (this.r = f, this.Q(b), this.ee(s, c, M, n), !L || v === void 0) return this.w(b), true;
|
|
96
|
+
let V = true, D = () => {
|
|
97
|
+
V && (this.w(b), V = false);
|
|
98
|
+
for (let A of this.n) A({ detail: this });
|
|
99
|
+
}, S = this.table_model.draw_sync(f, E, this.U, n, b, M, v, D);
|
|
100
|
+
return this.te(b, c, M, n, y), E === this.t && (this.p = false), S || this.draw({ invalid_viewport: true }), S;
|
|
101
|
+
}, { inline: false });
|
|
102
|
+
}
|
|
103
|
+
async j(e) {
|
|
104
|
+
e || this.table_model.Te();
|
|
105
|
+
let t = await this.table_model.Se(this.t);
|
|
106
|
+
return this.Y = t.num_columns || 0, this.e.row_height = t.row_height || this.e.row_height, t.num_row_headers !== void 0 && (this.t.row_headers_length = t.num_row_headers), t.num_column_headers !== void 0 && (this.t.column_headers_length = t.num_column_headers), t;
|
|
107
|
+
}
|
|
108
|
+
K(e, t, i) {
|
|
109
|
+
let s = this.i === "none" || this.i === "horizontal";
|
|
110
|
+
return { width: this.i === "none" || this.i === "vertical" ? 1 / 0 : e(), height: s ? 1 / 0 : t(), containerHeight: s ? 1 / 0 : i() };
|
|
111
|
+
}
|
|
112
|
+
ee(e, t, i, s) {
|
|
113
|
+
this.ie(t), s || this.se(e, i);
|
|
114
|
+
}
|
|
115
|
+
te(e, t, i, s, n) {
|
|
116
|
+
this.w(e);
|
|
117
|
+
let r = this.e.row_height;
|
|
118
|
+
this.table_model.header.reset_header_cache(), r !== this.e.row_height && this.ie(t), s || this.se(n, i);
|
|
119
|
+
}
|
|
120
|
+
Ce(e, t) {
|
|
121
|
+
if (this.i === "none" || this.i === "vertical") return e.end_col;
|
|
122
|
+
let { indices: i, override: s } = this.e, n = (h) => s[h] ?? i[h], r = this.t.row_headers_length, o = 0;
|
|
123
|
+
for (let h = 0; h < r; h++) {
|
|
124
|
+
let a = n(h);
|
|
125
|
+
if (a === void 0) return;
|
|
126
|
+
o += a;
|
|
127
|
+
}
|
|
128
|
+
let l = Math.floor(e.start_col), u = i[r + l] ?? 0, d = l;
|
|
129
|
+
for (; d < t && o - u <= this.r.width; ) {
|
|
130
|
+
let h = n(r + d);
|
|
131
|
+
if (h === void 0) return;
|
|
132
|
+
o += h, d++;
|
|
133
|
+
}
|
|
134
|
+
return d;
|
|
135
|
+
}
|
|
136
|
+
Ee() {
|
|
137
|
+
if (this._ === void 0 || this.b === void 0 || !this.t || this.i === "none" || this.i === "vertical" || this.b >= (this.Y ?? 0)) return;
|
|
138
|
+
let { indices: e, override: t } = this.e, i = this.t.row_headers_length, s = 0;
|
|
139
|
+
for (let r = 0; r < i; r++) s += e[r] || 0;
|
|
140
|
+
for (let r = this._; r < this.b; r++) {
|
|
141
|
+
let o = i + r, l = t[o] ?? e[o];
|
|
142
|
+
if (l === void 0) return;
|
|
143
|
+
s += l;
|
|
144
|
+
}
|
|
145
|
+
let n = e[i + this._];
|
|
146
|
+
s - (n ?? 0) <= this.r.width && this.draw({ invalid_viewport: true });
|
|
147
|
+
}
|
|
148
|
+
xe() {
|
|
149
|
+
if (!this.o) {
|
|
150
|
+
this.o = [document.createElement("table"), document.createElement("td")], this.o[0].style.visibility = "hidden", this.o[0].style.position = "absolute";
|
|
151
|
+
let e = document.createElement("tbody"), t = document.createElement("tr");
|
|
152
|
+
this.o[1].textContent = "X", t.appendChild(this.o[1]), e.appendChild(t), this.o[0].appendChild(e);
|
|
153
|
+
}
|
|
154
|
+
this.appendChild(this.o[0]), this.e.row_height = this.o[1].offsetHeight, this.o[0].remove();
|
|
155
|
+
}
|
|
156
|
+
Le() {
|
|
157
|
+
if (this.attachShadow({ mode: "open" }), !this.shadowRoot) return;
|
|
158
|
+
let e = new CSSStyleSheet();
|
|
159
|
+
e.replaceSync(oe);
|
|
160
|
+
let t = new CSSStyleSheet();
|
|
161
|
+
t.replaceSync(le), this.f = t.cssRules[0], this.shadowRoot.adoptedStyleSheets = [e, t], this.shadowRoot.innerHTML = Me;
|
|
162
|
+
let [i, s] = this.shadowRoot.children;
|
|
163
|
+
this.s = s, this.a = i, this.ne();
|
|
164
|
+
}
|
|
165
|
+
ne() {
|
|
166
|
+
this.s && (this.i === "both" || this.i === "vertical" ? this.s.style.top = "0px" : this.s.style.removeProperty("top"), this.i === "both" || this.i === "horizontal" ? this.s.style.left = "0px" : this.s.style.removeProperty("left"), this.i !== "both" ? this.s.style.contain = "none" : this.s.style.removeProperty("contain"));
|
|
167
|
+
}
|
|
168
|
+
Z(e, t, i, s) {
|
|
169
|
+
let { start_row: n, end_row: r } = this.He(e, i), { start_col: o, end_col: l } = this.V(t, s);
|
|
170
|
+
return { start_col: o, end_col: l, start_row: n, end_row: r };
|
|
171
|
+
}
|
|
172
|
+
J({ start_col: e, end_col: t, start_row: i, end_row: s }) {
|
|
173
|
+
i = Math.floor(i), s = Math.ceil(s), e = Math.floor(e), t = Math.ceil(t);
|
|
174
|
+
let n = this._ !== e, r = this.G !== i || this.q !== s || this.b !== t;
|
|
175
|
+
return { invalid_column: n, invalid_row: r };
|
|
176
|
+
}
|
|
177
|
+
Q({ start_col: e, end_col: t, start_row: i, end_row: s }) {
|
|
178
|
+
this._ = Math.floor(e), this.b = Math.ceil(t), this.G = Math.floor(i), this.q = Math.ceil(s);
|
|
179
|
+
}
|
|
180
|
+
se(e, t) {
|
|
181
|
+
if (e) if (this.i === "vertical" || this.i === "none") {
|
|
182
|
+
let i = 0;
|
|
183
|
+
for (let s of this.e.indices) i += s || 0;
|
|
184
|
+
this.a.style.width = i.toPrecision(10) + "px";
|
|
185
|
+
} else {
|
|
186
|
+
let i = this.Re(t);
|
|
187
|
+
if (i !== 0) {
|
|
188
|
+
let s = this.r.width + i + 2;
|
|
189
|
+
this.a.style.width = s.toPrecision(10) + "px";
|
|
190
|
+
} else this.a.style.width = "1px";
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
ie(e) {
|
|
194
|
+
let t = this.P(e);
|
|
195
|
+
this.a.style.height = `${t.toPrecision(10)}px`;
|
|
196
|
+
}
|
|
197
|
+
P(e) {
|
|
198
|
+
let { row_height: t = 0 } = this.e, i = this.t.column_headers_length * t;
|
|
199
|
+
return Math.min(re, e * t + i);
|
|
200
|
+
}
|
|
201
|
+
w(e) {
|
|
202
|
+
let t = (this.e.row_height || 0) * (e.start_row % 1) || 0, i = (this.table_model.c || 0) + Math.floor(e.start_col), s = (this.e.indices[i] ?? this.table_model.Ae()) * (e.start_col % 1) || 0;
|
|
203
|
+
this.f.style.setProperty(be, `${s}px`), this.f.style.setProperty(pe, `${t}px`), this.f.style.setProperty(we, `${-s}px`), this.f.style.setProperty(ge, `${-t}px`);
|
|
204
|
+
}
|
|
205
|
+
V(e, t) {
|
|
206
|
+
if (this.i === "none" || this.i === "vertical") return { start_col: 0, end_col: 1 / 0 };
|
|
207
|
+
{
|
|
208
|
+
let i = this.Pe(t), s = this.table_model.num_columns() || Math.min(e, Math.ceil(this.r.width / 60)), n = i + s + 1;
|
|
209
|
+
return { start_col: i, end_col: n };
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
He(e, t) {
|
|
213
|
+
let { height: i, containerHeight: s } = this.r, n = this.e.row_height || 0, r = this.t.column_headers_length, o = Math.round(this.P(e)), l = Math.max(1, o - s), u = Math.max(Math.ceil(t), 0) / l, d = i / n - r, _ = Math.max(0, (e || 0) - d) * u, p = Math.max(0, Math.min(_ + d, e));
|
|
214
|
+
return { start_row: _, end_row: p };
|
|
215
|
+
}
|
|
216
|
+
Pe(e) {
|
|
217
|
+
let t = this.t.row_headers_length, i = 0, s = 0, n = 0;
|
|
218
|
+
for (; s < e; ) {
|
|
219
|
+
let r = this.e.indices[i + t];
|
|
220
|
+
n = e - s, i += 1, s += r !== void 0 ? r : 60;
|
|
221
|
+
}
|
|
222
|
+
return i += n / (this.e.indices[i + t - 1] || 60), Math.max(0, i - 1);
|
|
223
|
+
}
|
|
224
|
+
Ve(e) {
|
|
225
|
+
let t = 0;
|
|
226
|
+
if (this.t.row_headers_length > 0) for (let n of this.e.indices.slice(0, this.t.row_headers_length)) t += n || 0;
|
|
227
|
+
let i = this.t.row_headers_length, s = e;
|
|
228
|
+
for (; t < this.r.width && s >= 0; ) s--, t += this.e.indices[s + i] || 60;
|
|
229
|
+
return Math.min(e - 1, s + 1);
|
|
230
|
+
}
|
|
231
|
+
Re(e) {
|
|
232
|
+
let t = this.t.row_headers_length, i = this.Ve(e), s = t, n = 0;
|
|
233
|
+
for (; s < i + t; ) n += this.e.indices[s] || 60, s++;
|
|
234
|
+
if (s < this.e.indices.length) {
|
|
235
|
+
let r = 0, o = this.t.row_headers_length;
|
|
236
|
+
for (let l = 0; l < o && l < this.e.indices.length; l++) r += this.e.indices[l] || 0;
|
|
237
|
+
n += Math.max(0, (this.e.indices[s] || 0) - (this.r.width - (r || 0)) || 0);
|
|
238
|
+
}
|
|
239
|
+
return n;
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
async function he(w) {
|
|
243
|
+
let e = performance.now(), { invalid_viewport: t = true, preserve_width: i = false } = w, { num_columns: s, num_rows: n } = await this.j(w.cache);
|
|
244
|
+
this.e.row_height || this.xe();
|
|
245
|
+
let r = n || 0, o = s || 0;
|
|
246
|
+
this.r = this.K(() => this.s.clientWidth, () => this.s.clientHeight, () => this.clientHeight), this.ee(t, r, o, i);
|
|
247
|
+
let l = this.Z(r, o, this.scrollTop, this.scrollLeft), { invalid_row: u, invalid_column: d } = this.J(l);
|
|
248
|
+
this.Q(l);
|
|
249
|
+
let h = this.p || d;
|
|
250
|
+
if (h || u || t) {
|
|
251
|
+
let a = true;
|
|
252
|
+
await this.table_model.draw(this.r, this.t, this.U, i, l, o, async () => {
|
|
253
|
+
a && (this.w(l), a = false);
|
|
254
|
+
for (let _ of this.n) await _({ detail: this });
|
|
255
|
+
}), this.te(l, r, o, i, h), this.p = false;
|
|
256
|
+
} else this.w(l);
|
|
257
|
+
se(performance.now() - e);
|
|
258
|
+
}
|
|
259
|
+
var P = /* @__PURE__ */ new WeakMap();
|
|
260
|
+
var B = /* @__PURE__ */ new WeakMap();
|
|
261
|
+
var F = class {
|
|
262
|
+
e;
|
|
263
|
+
De;
|
|
264
|
+
table;
|
|
265
|
+
cells;
|
|
266
|
+
rows;
|
|
267
|
+
constructor(e, t, i) {
|
|
268
|
+
this.e = e, this.De = t, this.table = i, this.cells = [], this.rows = [];
|
|
269
|
+
}
|
|
270
|
+
num_columns() {
|
|
271
|
+
return this.S(Math.max(0, this.rows.length - 1)).row_container.length;
|
|
272
|
+
}
|
|
273
|
+
num_rows() {
|
|
274
|
+
return this.cells.length;
|
|
275
|
+
}
|
|
276
|
+
nt(e, t) {
|
|
277
|
+
P.set(e, t);
|
|
278
|
+
}
|
|
279
|
+
D(e, t) {
|
|
280
|
+
let i = B.get(e);
|
|
281
|
+
i !== t && (i !== void 0 && e.classList.remove(`rt-col-${i}`), e.classList.add(`rt-col-${t}`), B.set(e, t));
|
|
282
|
+
}
|
|
283
|
+
g(e) {
|
|
284
|
+
let t = B.get(e);
|
|
285
|
+
t !== void 0 && (e.classList.remove(`rt-col-${t}`), B.delete(e));
|
|
286
|
+
}
|
|
287
|
+
M(e) {
|
|
288
|
+
if (!e) return { value: void 0 };
|
|
289
|
+
let t = P.get(e);
|
|
290
|
+
return t || (t = { value: void 0 }, P.set(e, t)), t;
|
|
291
|
+
}
|
|
292
|
+
re(e, t) {
|
|
293
|
+
let { tr: i, row_container: s } = this.S(e), n = s[t];
|
|
294
|
+
return n && (i.removeChild(n), s.splice(t, 1, void 0)), n;
|
|
295
|
+
}
|
|
296
|
+
v(e, t) {
|
|
297
|
+
if (!(e < 0 || t < 0)) return this.cells[e]?.[t];
|
|
298
|
+
}
|
|
299
|
+
S(e) {
|
|
300
|
+
let t = this.rows[e];
|
|
301
|
+
t || (t = this.rows[e] = document.createElement("tr"), this.table.appendChild(t));
|
|
302
|
+
let i = this.cells[e];
|
|
303
|
+
return i || (i = this.cells[e] = []), { tr: t, row_container: i };
|
|
304
|
+
}
|
|
305
|
+
z(e = "TD", t, i) {
|
|
306
|
+
let { tr: s, row_container: n } = this.S(t), r = n[i];
|
|
307
|
+
if (!r) if (i < n.length) {
|
|
308
|
+
r = n[i] = document.createElement(e);
|
|
309
|
+
let o = n.slice(i + 1).find((l) => l);
|
|
310
|
+
s.insertBefore(r, o || null);
|
|
311
|
+
} else r = n[i] = document.createElement(e), s.appendChild(r);
|
|
312
|
+
if (r.tagName !== e) {
|
|
313
|
+
let o = document.createElement(e);
|
|
314
|
+
s.replaceChild(o, r), this.cells[t].splice(i, 1, o), r = o;
|
|
315
|
+
}
|
|
316
|
+
return r;
|
|
317
|
+
}
|
|
318
|
+
oe(e) {
|
|
319
|
+
for (let t = 0; t < this.rows.length; t++) {
|
|
320
|
+
let i = this.rows[t], s = this.cells[t];
|
|
321
|
+
s.length = (Array.isArray(e) ? e[t] : e) || 0;
|
|
322
|
+
let n = this.cells[t].filter((o) => o !== void 0).length, r = [];
|
|
323
|
+
for (let o = n; o < i.children.length; o++) r.push(i.children[o]);
|
|
324
|
+
for (let o of r) o.remove();
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
E(e) {
|
|
328
|
+
e = Math.min(e, this.rows.length);
|
|
329
|
+
let t = [];
|
|
330
|
+
for (let i = e; i < this.table.children.length; i++) t.push(this.table.children[i]);
|
|
331
|
+
for (let i of t) i.remove();
|
|
332
|
+
this.rows.length = e, this.cells.length = e;
|
|
333
|
+
}
|
|
334
|
+
};
|
|
335
|
+
var ye = false;
|
|
336
|
+
var U = class extends q {
|
|
337
|
+
le;
|
|
338
|
+
ae;
|
|
339
|
+
he;
|
|
340
|
+
de;
|
|
341
|
+
L;
|
|
342
|
+
O;
|
|
343
|
+
ce;
|
|
344
|
+
ue;
|
|
345
|
+
register_listeners() {
|
|
346
|
+
this.addEventListener("mousedown", this.ze.bind(this)), this.addEventListener("scroll", this.W.bind(this), { passive: true }), this.Oe();
|
|
347
|
+
}
|
|
348
|
+
async W(e) {
|
|
349
|
+
if (e.stopPropagation(), this.ce = this.scrollLeft, this.ue = this.scrollTop, this.T) {
|
|
350
|
+
this.O = true;
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
this.T = true;
|
|
354
|
+
let t = this.s.clientWidth, i = this.s.clientHeight, s = this.clientHeight;
|
|
355
|
+
try {
|
|
356
|
+
await $(this, async () => {
|
|
357
|
+
do {
|
|
358
|
+
this.O = false;
|
|
359
|
+
let n = await this.predraw(t, i, { invalid_viewport: false, cache: true, throttle: false, container_height: s, scroll_left: this.ce, scroll_top: this.ue });
|
|
360
|
+
n.inline || (await new Promise(requestAnimationFrame), n());
|
|
361
|
+
} while (this.O);
|
|
362
|
+
});
|
|
363
|
+
} finally {
|
|
364
|
+
this.T = false;
|
|
365
|
+
}
|
|
366
|
+
this.dispatchEvent(new CustomEvent("regular-table-scroll"));
|
|
367
|
+
}
|
|
368
|
+
Oe() {
|
|
369
|
+
this.addEventListener("mousewheel", this.We.bind(this), { passive: true }), ye && (this.addEventListener("touchmove", this.ke.bind(this)), this.addEventListener("touchstart", this.Be.bind(this), { passive: true }));
|
|
370
|
+
}
|
|
371
|
+
We(e) {
|
|
372
|
+
if (!window.hasOwnProperty("safari")) return;
|
|
373
|
+
let t = e, { clientWidth: i, clientHeight: s, scrollTop: n, scrollLeft: r } = this;
|
|
374
|
+
t.preventDefault(), t.returnValue = false;
|
|
375
|
+
let o = Math.max(1, this.a.offsetHeight - s), l = Math.max(1, this.a.offsetWidth - i);
|
|
376
|
+
this.scrollTop = Math.max(0, Math.min(o, n + t.deltaY)), this.scrollLeft = Math.max(0, Math.min(l, r + t.deltaX)), this.W(t);
|
|
377
|
+
}
|
|
378
|
+
ke(e) {
|
|
379
|
+
e.stopPropagation(), e.preventDefault(), e.returnValue = false;
|
|
380
|
+
let { clientWidth: t, clientHeight: i } = this, s = Math.max(1, this.a.offsetHeight - i), n = Math.max(1, this.a.offsetWidth - t);
|
|
381
|
+
this.scrollTop = Math.min(s, (this.le || 0) + ((this.he || 0) - e.touches[0].pageY)), this.scrollLeft = Math.min(n, (this.ae || 0) + ((this.de || 0) - e.touches[0].pageX)), this.W(e);
|
|
382
|
+
}
|
|
383
|
+
Be(e) {
|
|
384
|
+
this.he = e.touches[0].pageY, this.de = e.touches[0].pageX, this.le = this.scrollTop, this.ae = this.scrollLeft;
|
|
385
|
+
}
|
|
386
|
+
async Fe(e) {
|
|
387
|
+
let t = e.target, i = t.classList.contains("rt-column-resize");
|
|
388
|
+
for (; t.tagName !== "TD" && t.tagName !== "TH"; ) if (t = t.parentElement, !this.contains(t)) return;
|
|
389
|
+
let s = P.get(t);
|
|
390
|
+
if (i && s) {
|
|
391
|
+
e.stopImmediatePropagation(), e.shiftKey ? (this.e.override = {}, this.e.auto = [], this.e.indices = []) : (delete this.e.override[s.size_key], this.e.auto[s.size_key] = void 0, this.e.indices[s.size_key] = void 0), this.table_model.updateColumnWidthStyles({ start_row: 0, end_row: 0, ...this.V(0, this.scrollLeft) }, this.t.row_headers_length);
|
|
392
|
+
for (let n of e.shiftKey ? [this.table_model.header.cells[this.table_model.header.cells.length - 1], ...this.table_model.body.cells] : this.table_model.body.cells) for (let r of e.shiftKey ? n : [n[s.virtual_x]]) r && (r.classList.remove("rt-cell-clip"), this.h || this.table_model.body.g(r));
|
|
393
|
+
await this.draw({ cache: true });
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
async $e(e) {
|
|
397
|
+
if (e.button !== 0) return;
|
|
398
|
+
let t = e.target, i = t.classList.contains("rt-column-resize");
|
|
399
|
+
for (; t.tagName !== "TD" && t.tagName !== "TH"; ) if (t = t.parentElement, !this.contains(t)) return;
|
|
400
|
+
let s = P.get(t);
|
|
401
|
+
i && s && (this.Ne(e, t, s), e.stopImmediatePropagation());
|
|
402
|
+
}
|
|
403
|
+
async ze(e) {
|
|
404
|
+
let t = performance.now();
|
|
405
|
+
this.L && t - this.L < 500 ? (this.L = t, await this.Fe(e)) : (this.L = t, await this.$e(e));
|
|
406
|
+
}
|
|
407
|
+
Ne(e, t, i) {
|
|
408
|
+
let { virtual_x: s, size_key: n } = i, r = e.pageX, o = (s || 0) + t.colSpan - 1, l = this.table_model.header.get_column_header(o), u = this.e.indices[n || 0] || 0, d = (a) => $(this, async () => await this.Ie(a, l, r, u, n || 0, o)), h = () => {
|
|
409
|
+
document.removeEventListener("mousemove", d), document.removeEventListener("mouseup", h);
|
|
410
|
+
let a = this.e.override[n || 0], _ = this.e.indices[n || 0] !== a;
|
|
411
|
+
this.e.indices[n || 0] = a, _ && this.draw({ cache: true });
|
|
412
|
+
};
|
|
413
|
+
document.addEventListener("mousemove", d), document.addEventListener("mouseup", h);
|
|
414
|
+
}
|
|
415
|
+
async Ie(e, t, i, s, n, r) {
|
|
416
|
+
await new Promise(requestAnimationFrame);
|
|
417
|
+
let o = e.pageX - i, l = Math.max(1, s + o);
|
|
418
|
+
if (this.e.override[n] = l, o < 0) await this.draw({ preserve_width: true, throttle: false, cache: true });
|
|
419
|
+
else {
|
|
420
|
+
this.table_model.updateColumnWidthStyles({ start_row: 0, end_row: 0, ...this.V(0, this.scrollLeft) }, this.t.row_headers_length);
|
|
421
|
+
let d = (this.e.auto[n] || 0) > l;
|
|
422
|
+
t.classList.toggle("rt-cell-clip", d);
|
|
423
|
+
for (let h of this.table_model.body.cells) {
|
|
424
|
+
let a = h[r];
|
|
425
|
+
a && (a.classList.toggle("rt-cell-clip", d), this.h || (d ? this.table_model.body.D(a, n) : this.table_model.body.g(a)));
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
};
|
|
430
|
+
var de = /* @__PURE__ */ new WeakMap();
|
|
431
|
+
var Y = class extends F {
|
|
432
|
+
l;
|
|
433
|
+
d;
|
|
434
|
+
H;
|
|
435
|
+
constructor(e, t, i, s) {
|
|
436
|
+
super(e, t, i), this.l = [], this.d = [], this.H = s;
|
|
437
|
+
}
|
|
438
|
+
me(e, t, i) {
|
|
439
|
+
let s = this.z("TH", t, e[t] || 0);
|
|
440
|
+
e[t] += 1;
|
|
441
|
+
let n = de.get(s);
|
|
442
|
+
if (n !== void 0 && n.value === i && s.lastChild === n.resize && s.firstChild === (i instanceof HTMLElement ? i : n.span)) return s;
|
|
443
|
+
if (s.removeAttribute("colspan"), s.textContent = "", n === void 0) {
|
|
444
|
+
let r = document.createElement("span");
|
|
445
|
+
r.className = "rt-column-resize", n = { value: void 0, span: document.createElement("span"), resize: r }, de.set(s, n);
|
|
446
|
+
}
|
|
447
|
+
return i instanceof HTMLElement ? s.appendChild(i) : (n.span.textContent = String(i ?? ""), s.appendChild(n.span)), s.appendChild(n.resize), n.value = i, s;
|
|
448
|
+
}
|
|
449
|
+
Xe(e, t, i) {
|
|
450
|
+
let s = this.M(i);
|
|
451
|
+
return this.g(i), s.column_header = e, s.value = t, s;
|
|
452
|
+
}
|
|
453
|
+
Ge(e, t, i, s) {
|
|
454
|
+
let n = this.M(i);
|
|
455
|
+
if (n.column_header = e, n.value = t, n.size_key = Array.isArray(s) ? s[0] : s, !Array.isArray(s) || s.length <= 1) {
|
|
456
|
+
this.D(i, n.size_key || 0), this.H?.(i);
|
|
457
|
+
let r = this.e.override[n.size_key || 0], o = this.e.auto[n.size_key || 0] || 0;
|
|
458
|
+
i.classList.toggle("rt-cell-clip", !!r && o > r);
|
|
459
|
+
} else this.g(i);
|
|
460
|
+
return n;
|
|
461
|
+
}
|
|
462
|
+
get_column_header(e) {
|
|
463
|
+
return this.z("TH", this.num_rows() - 1, e);
|
|
464
|
+
}
|
|
465
|
+
draw(e, t, i, s, n, r, o, l, u) {
|
|
466
|
+
let d = t?.length;
|
|
467
|
+
if (d === 0) return;
|
|
468
|
+
let h, a, _, p;
|
|
469
|
+
l = typeof l > "u" ? d - 1 : l;
|
|
470
|
+
for (let c = 0; c < d; c++) {
|
|
471
|
+
if (_ = t[c] ? t[c] : "", this.d[c] = this.d[c] || 0, c < l) u && this.l?.[c]?.[0]?.value === _ ? (h = this.l[c][1], this.l[c][2] += 1, i === 1 && (this.l[c][0].row_header_x = Array.isArray(n) ? n[0] : n)) : (this.fe(c), h = this.me(this.d, c, _), a = this.Xe(t, _, h), this.l[c] = [a, h, 1]);
|
|
472
|
+
else {
|
|
473
|
+
h = this.me(this.d, c, _), a = this.Ge(e.length > 0 ? e : t, _, h, n), typeof p > "u" && (p = { th: h, metadata: a });
|
|
474
|
+
for (let [M] of this.l) M.size_key = a.size_key;
|
|
475
|
+
h.removeAttribute("colspan");
|
|
476
|
+
}
|
|
477
|
+
this.S(c).tr.classList.toggle("rt-autosize", c === l), h.classList.toggle("rt-group-corner", s === void 0), a && (a.x = typeof s > "u" ? s : Math.floor(s), a.column_header_y = c, a.x0 = Math.floor(r), a.virtual_x = o, i === 1 ? (a.type = "corner", a.row_header_x = Array.isArray(n) ? n[0] : n) : (a.type = "column_header", delete a.row_header_x));
|
|
478
|
+
}
|
|
479
|
+
return this.E(this.d.length), p = p || { th: h, metadata: a }, p;
|
|
480
|
+
}
|
|
481
|
+
fe(e) {
|
|
482
|
+
let t = this.l[e];
|
|
483
|
+
if (!t) return;
|
|
484
|
+
let [, i, s] = t;
|
|
485
|
+
if (s > 1) {
|
|
486
|
+
let n = String(s);
|
|
487
|
+
i.getAttribute("colspan") !== n && i.setAttribute("colspan", n);
|
|
488
|
+
} else i.hasAttribute("colspan") && i.removeAttribute("colspan");
|
|
489
|
+
}
|
|
490
|
+
flush_colspans() {
|
|
491
|
+
for (let e = 0; e < this.l.length; e++) this.fe(e);
|
|
492
|
+
}
|
|
493
|
+
clean() {
|
|
494
|
+
this.flush_colspans(), this.oe(this.d);
|
|
495
|
+
}
|
|
496
|
+
reset_header_cache() {
|
|
497
|
+
this.d = [], this.l = [];
|
|
498
|
+
}
|
|
499
|
+
};
|
|
500
|
+
var j = class extends F {
|
|
501
|
+
h;
|
|
502
|
+
_e(e, t, i, s, { column_name: n }, { ridx_offset: r }, o) {
|
|
503
|
+
let l = this.z(e, t, s), u = this.M(l);
|
|
504
|
+
u.y = t + Math.floor(r);
|
|
505
|
+
let d = u.size_key = o || 0;
|
|
506
|
+
e === "TD" && (u.column_header = n);
|
|
507
|
+
let h = this.e.override[d], a = !!h && (this.e.auto[d] || 0) > h;
|
|
508
|
+
return l.classList.toggle("rt-cell-clip", a), this.h || a ? this.D(l, d) : this.g(l), u.value !== i && (i instanceof HTMLElement ? (l.textContent = "", l.appendChild(i)) : l.textContent = String(i ?? "")), u.value = i, { td: l, metadata: u };
|
|
509
|
+
}
|
|
510
|
+
draw(e, t, i, s = false, n, r, o, l) {
|
|
511
|
+
let { cidx: u, column_data: d, row_headers: h, column_data_listener_metadata: a } = t, { row_height: _ } = i, p, c = [], M = [], f = 0, m = [], T = s ? i.row_headers_length ?? 1 : 1, b = (i.ridx_offset ?? 0) % 1 !== 0 ? 1 : 0, v = false, L = Math.floor(i.ridx_offset), y = Math.ceil(i.y1), E = Math.ceil(i.x1), V = n === void 0 ? n : Math.floor(n), D = r === void 0 ? void 0 : Math.floor(r), S = Math.floor((n ?? 0) - (r ?? 0));
|
|
512
|
+
for (let g = 0; g < T; g++) {
|
|
513
|
+
f = 0, v = false;
|
|
514
|
+
let C = u + g;
|
|
515
|
+
for (let H of d) {
|
|
516
|
+
let R;
|
|
517
|
+
if (s) {
|
|
518
|
+
let x = H, N = x[g], Q = c[g] || 1, I = this.v(f - Q, C), ce = this.M(I), ee = m[f] || 1, X = this.v(f, C - ee), ue = this.M(X);
|
|
519
|
+
if (l && X && (ue.value === N || N === void 0) && !X.hasAttribute("rowspan")) {
|
|
520
|
+
let O = m[f] = ee + 1;
|
|
521
|
+
X.setAttribute("colspan", String(O)), this.re(f, C);
|
|
522
|
+
} else if (l && I && ce.value === N && !I.hasAttribute("colspan")) {
|
|
523
|
+
let O = c[g] = Q + 1;
|
|
524
|
+
I.setAttribute("rowspan", String(O)), this.re(f, C);
|
|
525
|
+
} else {
|
|
526
|
+
R = this._e("TH", f, N, C, t, i, g);
|
|
527
|
+
let O = R.td, W = R.metadata;
|
|
528
|
+
O.style.display = "", O.removeAttribute("rowspan"), O.removeAttribute("colspan"), W.type = "row_header", W.row_header = x, W.row_header_x = g, W.y0 = L, W.y1 = y, W.virtual_x = g, D !== void 0 && (W.x0 = D), c[g] = 1, m[f] = 1, M[g] = R;
|
|
529
|
+
}
|
|
530
|
+
} else {
|
|
531
|
+
R = this._e("TD", f, H, u, t, i, o ?? 0);
|
|
532
|
+
let x = R.metadata;
|
|
533
|
+
a && (x.user = a[f]), x.type = "body", x.x = V || 0, x.x1 = E, x.row_header = h?.[f] || [], x.y0 = L, x.y1 = y, x.dx = S, x.dy = (x.y ?? 0) - L, x.virtual_x = u, D !== void 0 && (x.x0 = D), M[0] = R;
|
|
534
|
+
}
|
|
535
|
+
if (f++, p = R ? R.metadata : p, _ = _ || R?.td.offsetHeight, (f - b) * (_ ?? 0) > e) {
|
|
536
|
+
v = true;
|
|
537
|
+
break;
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
let A = v ? f : f + b;
|
|
542
|
+
if (A > f) {
|
|
543
|
+
let g = this.rows[f], C = this.rows[f - 1];
|
|
544
|
+
(!!l && (i.row_headers_length ?? 0) > 0 || !g || !C || g.children.length !== C.children.length || g.querySelector("[colspan],[rowspan]") !== null || C.querySelector("[colspan],[rowspan]") !== null) && (A = f);
|
|
545
|
+
}
|
|
546
|
+
return this.E(A), { tds: M, ridx: A, drawn_ridx: f, row_height: _ };
|
|
547
|
+
}
|
|
548
|
+
clean({ ridx: e, cidx: t, drawn_ridx: i = e }) {
|
|
549
|
+
if (this.E(e), this.oe(t), i < this.rows.length) {
|
|
550
|
+
let s = this.rows[i], n = this.rows[i - 1], r = (h) => h?.children[h.children.length - 1], o = r(s), l = r(n), u = o && P.get(o), d = l && P.get(l);
|
|
551
|
+
(!u || !d || u.x !== d.x || s.children.length !== n.children.length) && this.E(i);
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
};
|
|
555
|
+
var Z = class {
|
|
556
|
+
e;
|
|
557
|
+
c = 0;
|
|
558
|
+
header;
|
|
559
|
+
body;
|
|
560
|
+
qe(e, t) {
|
|
561
|
+
let { start_row: i = 0, start_col: s = 0, end_col: n = 0, end_row: r = 0 } = e, o = this.e.indices[(this.c || 0) + Math.floor(e.start_col)] ?? 0;
|
|
562
|
+
return { viewport_width: 0, selected_id: t, ridx_offset: i, sub_cell_offset: o, x0: s, x1: n, y1: r, row_height: this.e.row_height, row_headers_length: this.c };
|
|
563
|
+
}
|
|
564
|
+
Ae() {
|
|
565
|
+
let e = 0, t = 0;
|
|
566
|
+
for (let i of this.e.indices) i && (e += i, t++);
|
|
567
|
+
return t ? e / t : 60;
|
|
568
|
+
}
|
|
569
|
+
Ue(e, t, i, s, n, r, o, l, u, d) {
|
|
570
|
+
let h = [`${t}`], a = [], _ = { column_name: h, cidx: 0, column_data: e, row_headers: e, first_col: true }, p = Math.floor(o), c = this.body.draw(s, _, { ...n, x0: 0 }, true, void 0, void 0, p, d), M = [];
|
|
571
|
+
for (let m = 0; m < t; m++) {
|
|
572
|
+
let T = this.header.draw(h, Array(i).fill(""), 1, void 0, m, o, m, l, u);
|
|
573
|
+
T && M.push(T);
|
|
574
|
+
}
|
|
575
|
+
for (let m = 0; m < M.length; m++) {
|
|
576
|
+
let { th: T } = M[m];
|
|
577
|
+
n.viewport_width += this.e.indices[m] || T.offsetWidth;
|
|
578
|
+
}
|
|
579
|
+
n.row_height = n.row_height || c.row_height;
|
|
580
|
+
let f = e[0].length;
|
|
581
|
+
if (!r) for (let m = 0; m < t; m++) {
|
|
582
|
+
let { td: T, metadata: b } = c.tds[m] || {}, { th: v, metadata: L } = M[m] || {};
|
|
583
|
+
(T || v) && a.push([v || T, L || b]);
|
|
584
|
+
}
|
|
585
|
+
return { cont_body: c, first_col: false, Ye: f, last_cells: a };
|
|
586
|
+
}
|
|
587
|
+
je(e, t, i, s, n, r) {
|
|
588
|
+
let o = 0, l = 0;
|
|
589
|
+
for (; this.e.indices.length > n + r + o + 1 && l + t.viewport_width < i; ) o++, l += this.e.indices[n + r + o] || 0;
|
|
590
|
+
if (l + t.viewport_width < i) {
|
|
591
|
+
let u = Math.min(s, e.start_col + 5);
|
|
592
|
+
e.end_col = Math.max(1, Math.min(s, u));
|
|
593
|
+
} else e.end_col = Math.max(1, Math.min(s, e.start_col + o));
|
|
594
|
+
}
|
|
595
|
+
Ke(e, t, i, s, n, r, o, l, u, d) {
|
|
596
|
+
let h = t.column_headers?.[e] || [], a = t.data[e], _ = t.metadata?.[e], p = { column_name: h, cidx: i, column_data: a, column_data_listener_metadata: _, row_headers: t.row_headers, first_col: o }, c = e + s, M = i + Math.floor(s), f = this.header.draw(h, h, void 0, c, M, s, i, l, u), m = this.body.draw(n, p, r, false, c, s, M, d);
|
|
597
|
+
return { cont_head: f, cont_body: m };
|
|
598
|
+
}
|
|
599
|
+
async Ze(e, t, i, s, n, r, o, l, u) {
|
|
600
|
+
let d = Math.max(s + Math.floor(u), 0), h = structuredClone(e);
|
|
601
|
+
h.start_col = d, this.je(h, n, r, o, l, u);
|
|
602
|
+
let a = await t(Math.floor(h.start_col), Math.floor(h.start_row), Math.ceil(h.end_col), Math.ceil(h.end_row)), _, p;
|
|
603
|
+
if (typeof a.column_header_merge_depth < "u" && (_ = a.column_header_merge_depth), typeof a.merge_headers < "u" && (p = a.merge_headers), a.data.length === 0) return { column_header_merge_depth: _, merge_headers: p };
|
|
604
|
+
e.end_col = h.start_col + a.data.length;
|
|
605
|
+
for (let c = 0; c < a.data.length; c++) i.data[s + c] = a.data[c], a.metadata && i.metadata && (i.metadata[s + c] = a.metadata[c]), i.column_headers && a.column_headers?.[c] && (i.column_headers[s + c] = a.column_headers[c]);
|
|
606
|
+
return { column_header_merge_depth: _, merge_headers: p };
|
|
607
|
+
}
|
|
608
|
+
R(e, t) {
|
|
609
|
+
this.body.clean({ ridx: e?.ridx || 0, cidx: t, drawn_ridx: e?.drawn_ridx ?? e?.ridx ?? 0 }), this.header.clean();
|
|
610
|
+
}
|
|
611
|
+
};
|
|
612
|
+
var Ce = 0;
|
|
613
|
+
var K = class extends Z {
|
|
614
|
+
table;
|
|
615
|
+
u;
|
|
616
|
+
k = /* @__PURE__ */ new Map();
|
|
617
|
+
A = /* @__PURE__ */ new Map();
|
|
618
|
+
B;
|
|
619
|
+
C;
|
|
620
|
+
Je;
|
|
621
|
+
m;
|
|
622
|
+
be = /* @__PURE__ */ new WeakSet();
|
|
623
|
+
pe = {};
|
|
624
|
+
F = false;
|
|
625
|
+
we;
|
|
626
|
+
constructor(e, t, i) {
|
|
627
|
+
super(), this.e = t, this.clear(i);
|
|
628
|
+
let [s] = i.children, [n, r] = s.children;
|
|
629
|
+
this.table = s, this.B = `rt-scope-${Ce++}`, this.table.classList.add(this.B), this.m = new ResizeObserver(this.Qe.bind(this)), this.header = new Y(t, e, n, (o) => this.H(o)), this.body = new j(t, e, r);
|
|
630
|
+
}
|
|
631
|
+
dispose() {
|
|
632
|
+
this.m?.disconnect();
|
|
633
|
+
}
|
|
634
|
+
H(e) {
|
|
635
|
+
!this.m || this.be.has(e) || (this.be.add(e), this.m.observe(e));
|
|
636
|
+
}
|
|
637
|
+
Qe(e) {
|
|
638
|
+
if (this.F) {
|
|
639
|
+
for (let s of e) this.m.unobserve(s.target), this.m.observe(s.target);
|
|
640
|
+
return;
|
|
641
|
+
}
|
|
642
|
+
let t = this.table.currentCSSZoom ?? 1, i = [];
|
|
643
|
+
for (let s of e) {
|
|
644
|
+
let n = B.get(s.target);
|
|
645
|
+
if (n === void 0 || this.e.override[n] !== void 0) continue;
|
|
646
|
+
let r = s.target.getBoundingClientRect().width / t;
|
|
647
|
+
r && this.e.indices[n] !== r && i.push([n, r]);
|
|
648
|
+
}
|
|
649
|
+
if (i.length > 0) {
|
|
650
|
+
this.ge();
|
|
651
|
+
for (let [s, n] of i) this.e.indices[s] = n, this.e.auto[s] = n, this.$(s);
|
|
652
|
+
this.we?.();
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
num_columns() {
|
|
656
|
+
return this.header.num_columns();
|
|
657
|
+
}
|
|
658
|
+
clear(e) {
|
|
659
|
+
e.innerHTML = '<table cellspacing="0"><thead></thead><tbody></tbody></table>';
|
|
660
|
+
}
|
|
661
|
+
N(e) {
|
|
662
|
+
for (let [, t] of e) {
|
|
663
|
+
let i = t?.size_key;
|
|
664
|
+
if (i === void 0) return true;
|
|
665
|
+
let s = this.e.override[i];
|
|
666
|
+
if (s !== void 0) {
|
|
667
|
+
if (this.pe[i] !== s) return true;
|
|
668
|
+
} else if (!this.e.indices[i]) return true;
|
|
669
|
+
}
|
|
670
|
+
return false;
|
|
671
|
+
}
|
|
672
|
+
autosize_cells(e, t) {
|
|
673
|
+
let i = this.table.currentCSSZoom ?? 1, s = [];
|
|
674
|
+
for (let [n, r] of e) {
|
|
675
|
+
let o = n.getBoundingClientRect();
|
|
676
|
+
s.push({ cell: n, metadata: r, box: o });
|
|
677
|
+
}
|
|
678
|
+
for (let { metadata: n, box: r } of s) if (this.e.row_height = t ?? Math.max(10, Math.min(this.e.row_height ?? r.height / i, r.height / i)), n?.size_key !== void 0) {
|
|
679
|
+
this.e.indices[n.size_key] = r.width / i;
|
|
680
|
+
let o = this.e.override[n.size_key];
|
|
681
|
+
r.width / i && o === void 0 && (this.e.auto[n.size_key] = r.width / i), o !== void 0 && (this.pe[n.size_key] = o);
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
updateColumnWidthStyles(e, t) {
|
|
685
|
+
if (!this.ge()) return;
|
|
686
|
+
let i;
|
|
687
|
+
for (i = 0; i < t; i++) this.$(i);
|
|
688
|
+
let s = Math.floor(e.start_col);
|
|
689
|
+
for (let n = i; n < i + (Math.floor(e.end_col) - s); n++) this.$(n + s);
|
|
690
|
+
}
|
|
691
|
+
$(e) {
|
|
692
|
+
let t = this.e.override[e], i = this.e.auto[e];
|
|
693
|
+
t !== void 0 ? this.Me(e, t, t) : i !== void 0 ? this.Me(e, i, void 0) : this.et(e);
|
|
694
|
+
}
|
|
695
|
+
ge() {
|
|
696
|
+
let e = this.table.getRootNode();
|
|
697
|
+
if (!(!e || !e.adoptedStyleSheets)) return this.u || (this.u = new CSSStyleSheet()), e.adoptedStyleSheets.includes(this.u) || (e.adoptedStyleSheets = [...e.adoptedStyleSheets, this.u]), this.u;
|
|
698
|
+
}
|
|
699
|
+
tt(e) {
|
|
700
|
+
let t = this.k.get(e);
|
|
701
|
+
if (t) return t;
|
|
702
|
+
let i = this.u;
|
|
703
|
+
if (!i) return;
|
|
704
|
+
let s = i.cssRules.length;
|
|
705
|
+
return i.insertRule(`.${this.B} .rt-col-${e}{}`, s), t = i.cssRules[s], this.k.set(e, t), t;
|
|
706
|
+
}
|
|
707
|
+
Me(e, t, i) {
|
|
708
|
+
let s = i === void 0 ? `${t}` : `${t}|${i}`;
|
|
709
|
+
if (this.A.get(e) === s) return;
|
|
710
|
+
let n = this.tt(e);
|
|
711
|
+
n && (n.style.minWidth = `${t}px`, i === void 0 ? n.style.removeProperty("max-width") : n.style.maxWidth = `${i}px`, this.A.set(e, s));
|
|
712
|
+
}
|
|
713
|
+
et(e) {
|
|
714
|
+
if (this.A.get(e) === "") return;
|
|
715
|
+
let t = this.k.get(e);
|
|
716
|
+
t && (t.style.removeProperty("min-width"), t.style.removeProperty("max-width")), this.A.set(e, "");
|
|
717
|
+
}
|
|
718
|
+
async Se(e) {
|
|
719
|
+
return this.C ? this.C : await e.view(0, 0, 0, 0);
|
|
720
|
+
}
|
|
721
|
+
Te() {
|
|
722
|
+
this.C = void 0, this.Je = void 0;
|
|
723
|
+
}
|
|
724
|
+
async draw(e, t, i, s, n, r, o) {
|
|
725
|
+
let l = this.C = await t.view(Math.floor(n.start_col), Math.floor(n.start_row), Math.ceil(n.end_col), Math.ceil(n.end_row)), u = this.ve(e, t, i, s, n, r, l);
|
|
726
|
+
this.F = true;
|
|
727
|
+
try {
|
|
728
|
+
let d = u.next();
|
|
729
|
+
for (; !d.done; ) await o(), d = u.next(d.value === "style" ? void 0 : await d.value.fetch());
|
|
730
|
+
} finally {
|
|
731
|
+
this.F = false, u.return(false);
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
draw_sync(e, t, i, s, n, r, o, l) {
|
|
735
|
+
this.C = o;
|
|
736
|
+
let u = this.ve(e, t, i, s, n, r, o), d = u.next();
|
|
737
|
+
for (; !d.done; ) d.value === "style" && l(), d = u.next();
|
|
738
|
+
return d.value;
|
|
739
|
+
}
|
|
740
|
+
*ve(e, t, i, s, n, r, o) {
|
|
741
|
+
let { width: l, height: u } = e, { column_header_merge_depth: d, merge_headers: h = "both" } = o, a = h === "both" || h === "row", _ = h === "both" || h === "column", p = n.start_col ?? 0;
|
|
742
|
+
if (o.row_headers) {
|
|
743
|
+
let y = 0;
|
|
744
|
+
for (let E of o.row_headers) E.length > y && (y = E.length);
|
|
745
|
+
this.c = y;
|
|
746
|
+
for (let E = 0; E < o.row_headers.length; E++) o.row_headers[E].length = this.c || 0;
|
|
747
|
+
}
|
|
748
|
+
t.row_headers_length = o.num_row_headers ?? o.row_headers?.[0]?.length ?? 0, t.column_headers_length = o.num_column_headers ?? o.column_headers?.[0]?.length ?? 0;
|
|
749
|
+
let { view: c, row_headers_length: M, column_headers_length: f } = t, m = this.qe(n, i), T, b = 0, v = [], L = true;
|
|
750
|
+
if (o.row_headers?.length) {
|
|
751
|
+
let y = this.Ue(o.row_headers, M, f, u, m, s, p, d, _, a);
|
|
752
|
+
T = y.cont_body, L = y.first_col, b = y.Ye, v = y.last_cells;
|
|
753
|
+
}
|
|
754
|
+
try {
|
|
755
|
+
let y = 0, E = 0, V = r - n.start_col, D = this.e.indices.some(Boolean);
|
|
756
|
+
for (; y < V; ) {
|
|
757
|
+
if (!o.data[y]) {
|
|
758
|
+
this.header.flush_colspans(), this.updateColumnWidthStyles(n, t.row_headers_length);
|
|
759
|
+
let C = yield { fetch: () => this.Ze(n, c, o, y, m, l, r, b, p) };
|
|
760
|
+
if (C?.column_header_merge_depth !== void 0 && (d = C.column_header_merge_depth), C?.merge_headers !== void 0 && (h = C.merge_headers), !o.data[y]) return this.R(T, b), this.updateColumnWidthStyles(n, t.row_headers_length), yield "style", this.N(v) && this.autosize_cells(v, this.e.row_height), this.I(m, l);
|
|
761
|
+
}
|
|
762
|
+
let { cont_head: S, cont_body: A } = this.Ke(y, o, b, p, u, m, L, d, _, a);
|
|
763
|
+
if (T = A, L = false, !s) for (let { td: C, metadata: H } of T.tds) v.push([S?.th || C, S?.metadata || H]);
|
|
764
|
+
let g = this.e.indices[b + Math.floor(p)] || (D ? E : 0);
|
|
765
|
+
if (!g) {
|
|
766
|
+
if (g = S?.th?.offsetWidth || 0, !g) for (let { td: C } of T.tds) g += C?.offsetWidth || 0;
|
|
767
|
+
E = g;
|
|
768
|
+
}
|
|
769
|
+
if (m.viewport_width += g, m.row_height = m.row_height || T.row_height, b++, y++, this.I(m, l)) {
|
|
770
|
+
if (this.R(T, b), this.updateColumnWidthStyles(n, t.row_headers_length), yield "style", s) return true;
|
|
771
|
+
m.viewport_width = 0, this.N(v) && this.autosize_cells(v, this.e.row_height), E = 0;
|
|
772
|
+
let C = m.row_headers_length || 0;
|
|
773
|
+
for (let H = 0; H < v.length; H++) {
|
|
774
|
+
let R = H < C ? H : Math.floor(p) + H;
|
|
775
|
+
m.viewport_width += this.e.indices[R] || 0;
|
|
776
|
+
}
|
|
777
|
+
if (this.I(m, l)) return true;
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
return this.R(T, b), this.updateColumnWidthStyles(n, t.row_headers_length), yield "style", this.N(v) && this.autosize_cells(v, this.e.row_height), true;
|
|
781
|
+
} finally {
|
|
782
|
+
this.R(T, b);
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
I(e, t) {
|
|
786
|
+
return e.viewport_width - e.sub_cell_offset > t;
|
|
787
|
+
}
|
|
788
|
+
};
|
|
789
|
+
var Te = ["both", "horizontal", "vertical", "none"];
|
|
790
|
+
var J = class extends U {
|
|
791
|
+
X;
|
|
792
|
+
constructor() {
|
|
793
|
+
super(), this.e = { auto: [], override: {}, indices: [] }, this.n = [], this.X = false;
|
|
794
|
+
}
|
|
795
|
+
connectedCallback() {
|
|
796
|
+
this.X || (this.Le(), this.register_listeners(), this.setAttribute("tabindex", "0"), this.X = true, this.ye());
|
|
797
|
+
}
|
|
798
|
+
ye() {
|
|
799
|
+
this.table_model?.dispose(), this.table_model = new K(this.s, this.e, this), this.table_model.we = () => this.Ee(), this.table_model.body.h = this.h;
|
|
800
|
+
}
|
|
801
|
+
resetAutoSize(e) {
|
|
802
|
+
(!e || e.auto) && (this.e.auto = []), (!e || e.override) && (this.e.override = {}), (!e || e.indices) && (this.e.indices = []), (!e || e.row_height) && (this.e.row_height = void 0);
|
|
803
|
+
}
|
|
804
|
+
saveColumnSizes() {
|
|
805
|
+
return structuredClone(this.e.override);
|
|
806
|
+
}
|
|
807
|
+
restoreColumnSizes(e) {
|
|
808
|
+
this.e.override = structuredClone(e);
|
|
809
|
+
}
|
|
810
|
+
clear() {
|
|
811
|
+
this.ye();
|
|
812
|
+
}
|
|
813
|
+
addStyleListener(e) {
|
|
814
|
+
this.n.push(e);
|
|
815
|
+
let t = true;
|
|
816
|
+
return () => {
|
|
817
|
+
if (!t) return;
|
|
818
|
+
t = false, this.n = this.n.slice();
|
|
819
|
+
let s = this.n.indexOf(e);
|
|
820
|
+
this.n.splice(s, 1);
|
|
821
|
+
};
|
|
822
|
+
}
|
|
823
|
+
removeStyleListener(e) {
|
|
824
|
+
let t = this.n.length;
|
|
825
|
+
this.n = this.n.filter((i) => i !== e), console.assert(this.n.length === t - 1, "No listener found");
|
|
826
|
+
}
|
|
827
|
+
getMeta(e) {
|
|
828
|
+
if (e !== void 0) {
|
|
829
|
+
if (e instanceof HTMLElement) return P.get(e);
|
|
830
|
+
if ("row_header_x" in e && e.row_header_x && e.row_header_x >= 0) {
|
|
831
|
+
if (e.row_header_x < this.t.row_headers_length) {
|
|
832
|
+
let t = this.table_model.body.v(e.y, e.row_header_x);
|
|
833
|
+
return this.getMeta(t);
|
|
834
|
+
}
|
|
835
|
+
} else if ("column_header_y" in e && e.column_header_y >= 0) {
|
|
836
|
+
if (e.column_header_y < this.t.column_headers_length) {
|
|
837
|
+
let t = this.table_model.header.v(e.column_header_y, e.x);
|
|
838
|
+
return this.getMeta(t);
|
|
839
|
+
}
|
|
840
|
+
} else if ("dx" in e) return this.getMeta(this.table_model.body.v(e.dy, e.dx + (this.table_model.c || 0)));
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
getDrawFPS() {
|
|
844
|
+
return ie();
|
|
845
|
+
}
|
|
846
|
+
async scrollToCell(e, t) {
|
|
847
|
+
if (!this.t) {
|
|
848
|
+
console.warn("data listener not configured");
|
|
849
|
+
return;
|
|
850
|
+
}
|
|
851
|
+
let i = this.e.row_height || 0;
|
|
852
|
+
this.scrollTop = Math.ceil(i * t);
|
|
853
|
+
let s = 0;
|
|
854
|
+
for (; e > 0; ) e--, s += this.e.indices[e + this.t.row_headers_length] || 60;
|
|
855
|
+
this.scrollLeft = Math.ceil(s), await new Promise(requestAnimationFrame), await this.flush();
|
|
856
|
+
}
|
|
857
|
+
setDataListener(e, { virtual_mode: t = "both", preserve_state: i = false, column_classes: s = false } = {}) {
|
|
858
|
+
console.assert(Te.indexOf(t) > -1, `Unknown virtual_mode ${t}; valid options are "both" (default), "horizontal", "vertical" or "none"`);
|
|
859
|
+
let n = this.i !== t;
|
|
860
|
+
i ? (console.assert(!n, "preserve_state called with modified virtual_mode"), this.t.view = e) : (this.i = t, this.h = s, this.table_model && (this.table_model.body.h = s), this.p = true, this.t = { view: e, row_headers_length: 0, column_headers_length: 0 }, n && this.ne());
|
|
861
|
+
}
|
|
862
|
+
};
|
|
863
|
+
document.createElement("regular-table").constructor === HTMLElement && window.customElements.define("regular-table", J);
|
|
864
|
+
|
|
865
|
+
// src/ts/index.ts
|
|
866
|
+
function cellValue(value) {
|
|
867
|
+
if (value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
868
|
+
return value;
|
|
869
|
+
}
|
|
870
|
+
return value === void 0 ? "" : JSON.stringify(value);
|
|
871
|
+
}
|
|
872
|
+
function formattedCell(value, renderer) {
|
|
873
|
+
if (!renderer?.format) return String(cellValue(value) ?? "");
|
|
874
|
+
const number = Number(value);
|
|
875
|
+
if (!Number.isFinite(number)) return String(cellValue(value) ?? "");
|
|
876
|
+
const digits = Math.max(
|
|
877
|
+
0,
|
|
878
|
+
renderer.digits ?? (renderer.format === "percent" ? 2 : 0)
|
|
879
|
+
);
|
|
880
|
+
const displayedNumber = renderer.signed ? Math.abs(number) : number;
|
|
881
|
+
const text = renderer.format === "number" ? displayedNumber.toLocaleString(void 0, {
|
|
882
|
+
minimumFractionDigits: digits,
|
|
883
|
+
maximumFractionDigits: digits
|
|
884
|
+
}) : `${Math.abs(number).toFixed(digits)}%`;
|
|
885
|
+
if (!renderer.signed || number === 0)
|
|
886
|
+
return number < 0 && renderer.format === "percent" ? `-${text}` : text;
|
|
887
|
+
return `${number > 0 ? "+" : "-"}${text}`;
|
|
888
|
+
}
|
|
889
|
+
var SpadayRegularTable = class extends HTMLElement {
|
|
890
|
+
#table = null;
|
|
891
|
+
#rows = [];
|
|
892
|
+
#columns = [];
|
|
893
|
+
#explicitColumns = false;
|
|
894
|
+
#virtualMode = "both";
|
|
895
|
+
#rowHeader = null;
|
|
896
|
+
#rowHeight;
|
|
897
|
+
#rowPatch = null;
|
|
898
|
+
#patchRevision;
|
|
899
|
+
#streamUrl = null;
|
|
900
|
+
#stream = null;
|
|
901
|
+
#drawQueued = false;
|
|
902
|
+
connectedCallback() {
|
|
903
|
+
this.style.display ||= "block";
|
|
904
|
+
this.style.position ||= "relative";
|
|
905
|
+
this.#ensureTable();
|
|
906
|
+
this.#connectStream();
|
|
907
|
+
this.#scheduleDraw(false);
|
|
908
|
+
}
|
|
909
|
+
disconnectedCallback() {
|
|
910
|
+
this.#stream?.close();
|
|
911
|
+
this.#stream = null;
|
|
912
|
+
}
|
|
913
|
+
get rows() {
|
|
914
|
+
return this.#rows;
|
|
915
|
+
}
|
|
916
|
+
set rows(value) {
|
|
917
|
+
this.#rows = Array.isArray(value) ? value : [];
|
|
918
|
+
if (!this.#explicitColumns) this.#inferColumns();
|
|
919
|
+
this.#scheduleDraw(true);
|
|
920
|
+
}
|
|
921
|
+
/** Apply a small, serializable batch of row operations from a bound Python model. */
|
|
922
|
+
get rowPatch() {
|
|
923
|
+
return this.#rowPatch;
|
|
924
|
+
}
|
|
925
|
+
set rowPatch(value) {
|
|
926
|
+
this.#rowPatch = value;
|
|
927
|
+
if (!value || !Array.isArray(value.operations)) return;
|
|
928
|
+
if (value.revision !== void 0 && value.revision === this.#patchRevision)
|
|
929
|
+
return;
|
|
930
|
+
if (typeof value.revision === "number" && typeof this.#patchRevision === "number" && value.revision < this.#patchRevision)
|
|
931
|
+
return;
|
|
932
|
+
this.#patchRevision = value.revision;
|
|
933
|
+
for (const operation of value.operations) {
|
|
934
|
+
if (operation.type === "update")
|
|
935
|
+
this.updateRow(operation.index, operation.changes);
|
|
936
|
+
if (operation.type === "insert")
|
|
937
|
+
this.insertRow(operation.index, operation.row);
|
|
938
|
+
if (operation.type === "remove") this.removeRow(operation.index);
|
|
939
|
+
}
|
|
940
|
+
if (value.operations.length) {
|
|
941
|
+
this.dispatchEvent(
|
|
942
|
+
new CustomEvent("row-patch", {
|
|
943
|
+
bubbles: true,
|
|
944
|
+
composed: true,
|
|
945
|
+
detail: value
|
|
946
|
+
})
|
|
947
|
+
);
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
/** SSE endpoint whose messages are serializable row patches. */
|
|
951
|
+
get streamUrl() {
|
|
952
|
+
return this.#streamUrl;
|
|
953
|
+
}
|
|
954
|
+
set streamUrl(value) {
|
|
955
|
+
this.#streamUrl = value || null;
|
|
956
|
+
this.#connectStream();
|
|
957
|
+
}
|
|
958
|
+
/** Merge fields into one row without replacing the full dataset. */
|
|
959
|
+
updateRow(index, changes) {
|
|
960
|
+
if (!Number.isInteger(index) || index < 0 || index >= this.#rows.length) {
|
|
961
|
+
return false;
|
|
962
|
+
}
|
|
963
|
+
this.#rows[index] = { ...this.#rows[index], ...changes };
|
|
964
|
+
this.#rowsMutated(index === 0);
|
|
965
|
+
return true;
|
|
966
|
+
}
|
|
967
|
+
/** Insert one row at an exact virtual index. */
|
|
968
|
+
insertRow(index, row) {
|
|
969
|
+
if (!Number.isInteger(index) || index < 0 || index > this.#rows.length) {
|
|
970
|
+
return false;
|
|
971
|
+
}
|
|
972
|
+
this.#rows.splice(index, 0, row);
|
|
973
|
+
this.#rowsMutated(index === 0);
|
|
974
|
+
return true;
|
|
975
|
+
}
|
|
976
|
+
/** Remove and return one row at an exact virtual index. */
|
|
977
|
+
removeRow(index) {
|
|
978
|
+
if (!Number.isInteger(index) || index < 0 || index >= this.#rows.length) {
|
|
979
|
+
return void 0;
|
|
980
|
+
}
|
|
981
|
+
const [removed] = this.#rows.splice(index, 1);
|
|
982
|
+
this.#rowsMutated(index === 0);
|
|
983
|
+
return removed;
|
|
984
|
+
}
|
|
985
|
+
/** Resolve a rendered cell back to its virtual coordinates and source row. */
|
|
986
|
+
getMeta(element) {
|
|
987
|
+
if (!this.#table) return void 0;
|
|
988
|
+
const cell = element.closest("td,th");
|
|
989
|
+
if (!(cell instanceof HTMLElement)) return void 0;
|
|
990
|
+
const meta = this.#table.getMeta(cell);
|
|
991
|
+
if (!meta) return void 0;
|
|
992
|
+
return {
|
|
993
|
+
...meta,
|
|
994
|
+
column: meta.x === void 0 ? void 0 : this.#columns[meta.x]?.key,
|
|
995
|
+
row: meta.y === void 0 ? void 0 : this.#rows[meta.y]
|
|
996
|
+
};
|
|
997
|
+
}
|
|
998
|
+
get columns() {
|
|
999
|
+
return this.#columns;
|
|
1000
|
+
}
|
|
1001
|
+
set columns(value) {
|
|
1002
|
+
this.#explicitColumns = Array.isArray(value) && value.length > 0;
|
|
1003
|
+
this.#columns = this.#explicitColumns ? value.map(
|
|
1004
|
+
(column) => typeof column === "string" ? { key: column, label: column } : {
|
|
1005
|
+
key: column.key,
|
|
1006
|
+
label: column.label ?? column.key,
|
|
1007
|
+
cell: column.cell
|
|
1008
|
+
}
|
|
1009
|
+
) : [];
|
|
1010
|
+
if (!this.#explicitColumns) this.#inferColumns();
|
|
1011
|
+
this.#table?.resetAutoSize();
|
|
1012
|
+
this.#scheduleDraw(false);
|
|
1013
|
+
}
|
|
1014
|
+
get virtualMode() {
|
|
1015
|
+
return this.#virtualMode;
|
|
1016
|
+
}
|
|
1017
|
+
set virtualMode(value) {
|
|
1018
|
+
this.#virtualMode = ["both", "horizontal", "vertical", "none"].includes(
|
|
1019
|
+
value
|
|
1020
|
+
) ? value : "both";
|
|
1021
|
+
this.#configureListener();
|
|
1022
|
+
this.#scheduleDraw(false);
|
|
1023
|
+
}
|
|
1024
|
+
get rowHeader() {
|
|
1025
|
+
return this.#rowHeader;
|
|
1026
|
+
}
|
|
1027
|
+
set rowHeader(value) {
|
|
1028
|
+
this.#rowHeader = value || null;
|
|
1029
|
+
this.#table?.resetAutoSize();
|
|
1030
|
+
this.#scheduleDraw(false);
|
|
1031
|
+
}
|
|
1032
|
+
get rowHeight() {
|
|
1033
|
+
return this.#rowHeight;
|
|
1034
|
+
}
|
|
1035
|
+
set rowHeight(value) {
|
|
1036
|
+
this.#rowHeight = value && value > 0 ? value : void 0;
|
|
1037
|
+
this.#table?.resetAutoSize({
|
|
1038
|
+
row_height: true,
|
|
1039
|
+
auto: false,
|
|
1040
|
+
override: false,
|
|
1041
|
+
indices: false
|
|
1042
|
+
});
|
|
1043
|
+
this.#scheduleDraw(true);
|
|
1044
|
+
}
|
|
1045
|
+
#ensureTable() {
|
|
1046
|
+
if (this.#table) return;
|
|
1047
|
+
this.#table = document.createElement("regular-table");
|
|
1048
|
+
this.#table.addEventListener("click", (event) => this.#emitCell(event));
|
|
1049
|
+
this.#table.addStyleListener(() => {
|
|
1050
|
+
this.#renderCells();
|
|
1051
|
+
this.dispatchEvent(
|
|
1052
|
+
new CustomEvent("table-draw", {
|
|
1053
|
+
bubbles: true,
|
|
1054
|
+
composed: true
|
|
1055
|
+
})
|
|
1056
|
+
);
|
|
1057
|
+
});
|
|
1058
|
+
this.appendChild(this.#table);
|
|
1059
|
+
this.#configureListener();
|
|
1060
|
+
}
|
|
1061
|
+
#connectStream() {
|
|
1062
|
+
this.#stream?.close();
|
|
1063
|
+
this.#stream = null;
|
|
1064
|
+
if (!this.isConnected || !this.#streamUrl) return;
|
|
1065
|
+
this.#stream = new EventSource(this.#streamUrl);
|
|
1066
|
+
this.#stream.addEventListener("message", (event) => {
|
|
1067
|
+
try {
|
|
1068
|
+
const patch = JSON.parse(event.data);
|
|
1069
|
+
if (!patch || !Array.isArray(patch.operations)) throw new Error();
|
|
1070
|
+
this.rowPatch = patch;
|
|
1071
|
+
} catch {
|
|
1072
|
+
this.dispatchEvent(
|
|
1073
|
+
new CustomEvent("row-stream-error", {
|
|
1074
|
+
bubbles: true,
|
|
1075
|
+
composed: true,
|
|
1076
|
+
detail: { data: event.data }
|
|
1077
|
+
})
|
|
1078
|
+
);
|
|
1079
|
+
}
|
|
1080
|
+
});
|
|
1081
|
+
}
|
|
1082
|
+
#inferColumns() {
|
|
1083
|
+
const first = this.#rows[0];
|
|
1084
|
+
this.#columns = first ? Object.keys(first).filter((key) => key !== this.#rowHeader).map((key) => ({ key, label: key })) : [];
|
|
1085
|
+
}
|
|
1086
|
+
#rowsMutated(firstRowChanged) {
|
|
1087
|
+
if (!this.#explicitColumns && firstRowChanged) {
|
|
1088
|
+
this.#inferColumns();
|
|
1089
|
+
this.#table?.resetAutoSize();
|
|
1090
|
+
this.#scheduleDraw(false);
|
|
1091
|
+
return;
|
|
1092
|
+
}
|
|
1093
|
+
this.#scheduleDraw(true);
|
|
1094
|
+
}
|
|
1095
|
+
#configureListener() {
|
|
1096
|
+
if (!this.#table) return;
|
|
1097
|
+
this.#table.setDataListener(
|
|
1098
|
+
async (x0, y0, x1, y1) => this.#slice(x0, y0, x1, y1),
|
|
1099
|
+
{ virtual_mode: this.#virtualMode, column_classes: true }
|
|
1100
|
+
);
|
|
1101
|
+
}
|
|
1102
|
+
#slice(x0, y0, x1, y1) {
|
|
1103
|
+
const startRow = Math.max(0, y0);
|
|
1104
|
+
const endRow = Math.min(this.#rows.length, y1);
|
|
1105
|
+
const visibleColumns = this.#columns.slice(x0, x1);
|
|
1106
|
+
const data = visibleColumns.map(({ key }) => {
|
|
1107
|
+
const values = [];
|
|
1108
|
+
for (let y = startRow; y < endRow; y += 1) {
|
|
1109
|
+
values.push(cellValue(this.#rows[y]?.[key]));
|
|
1110
|
+
}
|
|
1111
|
+
return values;
|
|
1112
|
+
});
|
|
1113
|
+
const response = {
|
|
1114
|
+
num_rows: this.#rows.length,
|
|
1115
|
+
num_columns: this.#columns.length,
|
|
1116
|
+
data,
|
|
1117
|
+
column_headers: visibleColumns.map(({ label }) => [label])
|
|
1118
|
+
};
|
|
1119
|
+
if (this.#rowHeader) {
|
|
1120
|
+
response.row_headers = this.#rows.slice(startRow, endRow).map((row) => [cellValue(row[this.#rowHeader])]);
|
|
1121
|
+
}
|
|
1122
|
+
if (this.#rowHeight) response.row_height = this.#rowHeight;
|
|
1123
|
+
return response;
|
|
1124
|
+
}
|
|
1125
|
+
#scheduleDraw(preserveWidth) {
|
|
1126
|
+
if (!this.isConnected || !this.#table || this.#drawQueued) return;
|
|
1127
|
+
this.#drawQueued = true;
|
|
1128
|
+
requestAnimationFrame(() => {
|
|
1129
|
+
this.#drawQueued = false;
|
|
1130
|
+
void this.#table?.draw({ preserve_width: preserveWidth });
|
|
1131
|
+
});
|
|
1132
|
+
}
|
|
1133
|
+
#renderCells() {
|
|
1134
|
+
if (!this.#table) return;
|
|
1135
|
+
for (const cell of this.#table.querySelectorAll("tbody td")) {
|
|
1136
|
+
const element = cell;
|
|
1137
|
+
const priorClasses = element.dataset.spadayClasses?.split(" ").filter(Boolean) ?? [];
|
|
1138
|
+
element.classList.remove(...priorClasses);
|
|
1139
|
+
delete element.dataset.spadayClasses;
|
|
1140
|
+
const meta = this.#table.getMeta(element);
|
|
1141
|
+
if (meta?.x === void 0) continue;
|
|
1142
|
+
const renderer = this.#columns[meta.x]?.cell;
|
|
1143
|
+
if (!renderer) continue;
|
|
1144
|
+
const classes = [renderer.cell_class];
|
|
1145
|
+
const number = Number(meta.value);
|
|
1146
|
+
if (Number.isFinite(number)) {
|
|
1147
|
+
classes.push(
|
|
1148
|
+
number >= 0 ? renderer.positive_class : renderer.negative_class
|
|
1149
|
+
);
|
|
1150
|
+
}
|
|
1151
|
+
const appliedClasses = classes.filter(
|
|
1152
|
+
(name) => Boolean(name)
|
|
1153
|
+
);
|
|
1154
|
+
element.classList.add(...appliedClasses);
|
|
1155
|
+
if (appliedClasses.length)
|
|
1156
|
+
element.dataset.spadayClasses = appliedClasses.join(" ");
|
|
1157
|
+
const text = formattedCell(meta.value, renderer);
|
|
1158
|
+
if (!renderer.tag) {
|
|
1159
|
+
element.textContent = text;
|
|
1160
|
+
continue;
|
|
1161
|
+
}
|
|
1162
|
+
const content = document.createElement(renderer.tag);
|
|
1163
|
+
if (renderer.class) content.className = renderer.class;
|
|
1164
|
+
if (renderer.title) content.title = renderer.title;
|
|
1165
|
+
for (const [name, value] of Object.entries(renderer.attributes ?? {})) {
|
|
1166
|
+
content.setAttribute(name, value);
|
|
1167
|
+
}
|
|
1168
|
+
content.textContent = text;
|
|
1169
|
+
element.replaceChildren(content);
|
|
1170
|
+
}
|
|
1171
|
+
}
|
|
1172
|
+
#emitCell(event) {
|
|
1173
|
+
const target = event.target;
|
|
1174
|
+
if (!(target instanceof HTMLElement)) return;
|
|
1175
|
+
const detail = this.getMeta(target);
|
|
1176
|
+
if (!detail) return;
|
|
1177
|
+
this.dispatchEvent(
|
|
1178
|
+
new CustomEvent("cell-click", {
|
|
1179
|
+
bubbles: true,
|
|
1180
|
+
composed: true,
|
|
1181
|
+
detail
|
|
1182
|
+
})
|
|
1183
|
+
);
|
|
1184
|
+
const renderer = detail.x === void 0 ? void 0 : this.#columns[detail.x]?.cell;
|
|
1185
|
+
if (renderer?.event && renderer.event !== "cell-click") {
|
|
1186
|
+
this.dispatchEvent(
|
|
1187
|
+
new CustomEvent(renderer.event, {
|
|
1188
|
+
bubbles: true,
|
|
1189
|
+
composed: true,
|
|
1190
|
+
detail
|
|
1191
|
+
})
|
|
1192
|
+
);
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1195
|
+
};
|
|
1196
|
+
if (!customElements.get("spaday-regular-table")) {
|
|
1197
|
+
customElements.define("spaday-regular-table", SpadayRegularTable);
|
|
1198
|
+
}
|
|
1199
|
+
export {
|
|
1200
|
+
SpadayRegularTable
|
|
1201
|
+
};
|
|
1202
|
+
//# sourceMappingURL=index.js.map
|