@extable/core 0.3.6 → 0.3.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core.css +1 -1
- package/dist/dataModel.d.ts +1 -0
- package/dist/geometry.d.ts +3 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1121 -975
- package/dist/index.js.map +1 -1
- package/dist/numberIO-CGTV3-KW.js +1017 -0
- package/dist/numberIO-CGTV3-KW.js.map +1 -0
- package/dist/numberIO-CTEeBhef.js +1046 -0
- package/dist/numberIO-CTEeBhef.js.map +1 -0
- package/dist/numberIO-CYskf90V.js +1017 -0
- package/dist/numberIO-CYskf90V.js.map +1 -0
- package/dist/numberIO-DBddtK0s.js +1063 -0
- package/dist/numberIO-DBddtK0s.js.map +1 -0
- package/dist/numberIO-UZ5ksMqf.js +1063 -0
- package/dist/numberIO-UZ5ksMqf.js.map +1 -0
- package/dist/renderers.d.ts +2 -0
- package/dist/selectionManager.d.ts +10 -2
- package/dist/ssr/index.js +1 -1
- package/dist/types.d.ts +16 -12
- package/dist/uniqueBooleanCommit.d.ts +6 -0
- package/package.json +2 -2
- package/src/styles.css +36 -3
|
@@ -0,0 +1,1063 @@
|
|
|
1
|
+
function R() {
|
|
2
|
+
return typeof crypto < "u" && "randomUUID" in crypto ? crypto.randomUUID() : `row_${Math.random().toString(16).slice(2)}`;
|
|
3
|
+
}
|
|
4
|
+
function q(s) {
|
|
5
|
+
if (s !== void 0)
|
|
6
|
+
return Array.isArray(s) ? s : [s];
|
|
7
|
+
}
|
|
8
|
+
function U(s) {
|
|
9
|
+
if (s)
|
|
10
|
+
try {
|
|
11
|
+
s.remove();
|
|
12
|
+
} catch {
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
const w = (s, t = 2) => s.toString().padStart(t, "0"), D = {
|
|
16
|
+
yyyy: (s) => w(s.getFullYear(), 4),
|
|
17
|
+
MM: (s) => w(s.getMonth() + 1),
|
|
18
|
+
dd: (s) => w(s.getDate()),
|
|
19
|
+
HH: (s) => w(s.getHours()),
|
|
20
|
+
hh: (s) => {
|
|
21
|
+
const t = s.getHours() % 12 || 12;
|
|
22
|
+
return w(t);
|
|
23
|
+
},
|
|
24
|
+
mm: (s) => w(s.getMinutes()),
|
|
25
|
+
ss: (s) => w(s.getSeconds()),
|
|
26
|
+
a: (s) => s.getHours() >= 12 ? "PM" : "AM"
|
|
27
|
+
}, M = Object.keys(D).sort((s, t) => t.length - s.length), A = /* @__PURE__ */ new Set(["yyyy", "MM", "dd"]), j = /* @__PURE__ */ new Set(["HH", "hh", "mm", "ss", "a"]), T = /* @__PURE__ */ new Set([...A, ...j]), b = {
|
|
28
|
+
iso: "yyyy-MM-dd",
|
|
29
|
+
us: "MM/dd/yyyy",
|
|
30
|
+
eu: "dd.MM.yyyy"
|
|
31
|
+
}, C = {
|
|
32
|
+
iso: "HH:mm:ss",
|
|
33
|
+
"24h": "HH:mm",
|
|
34
|
+
"12h": "hh:mm a"
|
|
35
|
+
}, S = {
|
|
36
|
+
iso: "yyyy-MM-dd'T'HH:mm:ss'Z'",
|
|
37
|
+
"iso-24h": "yyyy-MM-dd'T'HH:mm:ss'Z'",
|
|
38
|
+
"iso-12h": "yyyy-MM-dd hh:mm a",
|
|
39
|
+
us: "MM/dd/yyyy HH:mm",
|
|
40
|
+
"us-24h": "MM/dd/yyyy HH:mm",
|
|
41
|
+
"us-12h": "MM/dd/yyyy hh:mm a",
|
|
42
|
+
eu: "dd.MM.yyyy HH:mm",
|
|
43
|
+
"eu-24h": "dd.MM.yyyy HH:mm",
|
|
44
|
+
"eu-12h": "dd.MM.yyyy hh:mm a"
|
|
45
|
+
};
|
|
46
|
+
function F(s) {
|
|
47
|
+
const t = new Date(s);
|
|
48
|
+
return Number.isNaN(t.getTime()) ? null : t;
|
|
49
|
+
}
|
|
50
|
+
function W(s, t) {
|
|
51
|
+
let e = "", n = 0, i = !1;
|
|
52
|
+
for (; n < t.length; ) {
|
|
53
|
+
const o = t[n];
|
|
54
|
+
if (o === "'") {
|
|
55
|
+
i = !i, n += 1;
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
if (i) {
|
|
59
|
+
e += o, n += 1;
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
let r = !1;
|
|
63
|
+
for (const l of M)
|
|
64
|
+
if (t.startsWith(l, n)) {
|
|
65
|
+
e += D[l](s), n += l.length, r = !0;
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
r || (e += o, n += 1);
|
|
69
|
+
}
|
|
70
|
+
return e;
|
|
71
|
+
}
|
|
72
|
+
function N(s, t) {
|
|
73
|
+
return t === "date" ? A.has(s) : t === "time" ? j.has(s) : T.has(s);
|
|
74
|
+
}
|
|
75
|
+
function O(s, t) {
|
|
76
|
+
let e = 0, n = !1;
|
|
77
|
+
for (; e < s.length; ) {
|
|
78
|
+
if (s[e] === "'") {
|
|
79
|
+
n = !n, e += 1;
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
if (n) {
|
|
83
|
+
e += 1;
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
let o = !1;
|
|
87
|
+
for (const r of M)
|
|
88
|
+
if (s.startsWith(r, e)) {
|
|
89
|
+
if (!N(r, t)) return !1;
|
|
90
|
+
e += r.length, o = !0;
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
o || (e += 1);
|
|
94
|
+
}
|
|
95
|
+
return !0;
|
|
96
|
+
}
|
|
97
|
+
function k(s, t) {
|
|
98
|
+
if (!s)
|
|
99
|
+
return t === "date" ? b.iso : t === "time" ? C.iso : S.iso;
|
|
100
|
+
if (t === "date" && b[s]) return b[s];
|
|
101
|
+
if (t === "time" && C[s]) return C[s];
|
|
102
|
+
if (t === "datetime" && S[s]) return S[s];
|
|
103
|
+
const e = t === "date" ? b.iso : t === "time" ? C.iso : S.iso;
|
|
104
|
+
return O(s, t) ? s : e;
|
|
105
|
+
}
|
|
106
|
+
const E = (s) => !Number.isNaN(s.getTime()), B = (s) => {
|
|
107
|
+
if (typeof s == "string") return s;
|
|
108
|
+
if (s && typeof s == "object") {
|
|
109
|
+
const t = s;
|
|
110
|
+
if (t.kind === "enum")
|
|
111
|
+
return typeof t.value == "string" ? t.value : null;
|
|
112
|
+
}
|
|
113
|
+
return null;
|
|
114
|
+
}, H = (s) => {
|
|
115
|
+
if (Array.isArray(s) && s.every((t) => typeof t == "string")) return s;
|
|
116
|
+
if (s && typeof s == "object") {
|
|
117
|
+
const t = s;
|
|
118
|
+
if (t.kind === "tags") {
|
|
119
|
+
const e = t.values;
|
|
120
|
+
return Array.isArray(e) && e.every((n) => typeof n == "string") ? e : null;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return null;
|
|
124
|
+
};
|
|
125
|
+
function $(s, t) {
|
|
126
|
+
if (s == null) return null;
|
|
127
|
+
switch (t.type) {
|
|
128
|
+
case "string": {
|
|
129
|
+
if (typeof s != "string") return "Expected a string";
|
|
130
|
+
const e = t.format;
|
|
131
|
+
if (e?.maxLength !== void 0 && s.length > e.maxLength)
|
|
132
|
+
return `Too long (max ${e.maxLength})`;
|
|
133
|
+
if (e?.regex)
|
|
134
|
+
try {
|
|
135
|
+
if (!new RegExp(e.regex).test(s)) return "Does not match pattern";
|
|
136
|
+
} catch {
|
|
137
|
+
}
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
case "number":
|
|
141
|
+
return typeof s != "number" || !Number.isFinite(s) ? "Expected a number" : t.format?.signed === !1 && s < 0 ? "Expected a non-negative number" : null;
|
|
142
|
+
case "int":
|
|
143
|
+
return typeof s != "number" || !Number.isSafeInteger(s) ? "Expected an integer" : null;
|
|
144
|
+
case "uint":
|
|
145
|
+
return typeof s != "number" || !Number.isSafeInteger(s) || s < 0 ? "Expected a non-negative integer" : null;
|
|
146
|
+
case "boolean":
|
|
147
|
+
return typeof s != "boolean" ? "Expected a boolean" : null;
|
|
148
|
+
case "enum": {
|
|
149
|
+
const e = B(s);
|
|
150
|
+
if (!e) return "Expected an enum value";
|
|
151
|
+
const n = t.enumAllowCustom ?? !1, i = Array.isArray(t.enum) ? t.enum : [];
|
|
152
|
+
return !n && i.length && !i.includes(e) ? "Not in allowed options" : null;
|
|
153
|
+
}
|
|
154
|
+
case "labeled": {
|
|
155
|
+
if (!s || typeof s != "object") return "Expected a labeled value";
|
|
156
|
+
const e = s;
|
|
157
|
+
if (typeof e.label != "string" || !Object.prototype.hasOwnProperty.call(e, "value"))
|
|
158
|
+
return "Expected a labeled value";
|
|
159
|
+
const n = t.enumAllowCustom ?? !1, i = Array.isArray(t.enum) ? t.enum : [];
|
|
160
|
+
if (!n && i.length) {
|
|
161
|
+
const o = i.map((l) => typeof l == "object" && l !== null ? String(l.value) : null).filter((l) => l !== null), r = String(e.value ?? "");
|
|
162
|
+
if (!o.includes(r)) return "Not in allowed options";
|
|
163
|
+
}
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
case "tags": {
|
|
167
|
+
const e = H(s);
|
|
168
|
+
if (!e) return "Expected a list of tags";
|
|
169
|
+
const n = t.tagsAllowCustom ?? !1, i = Array.isArray(t.tags) ? t.tags : [];
|
|
170
|
+
if (!n && i.length) {
|
|
171
|
+
for (const o of e)
|
|
172
|
+
if (!i.includes(o)) return "Contains an unknown tag";
|
|
173
|
+
}
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
case "date":
|
|
177
|
+
case "time":
|
|
178
|
+
case "datetime": {
|
|
179
|
+
const e = t.format;
|
|
180
|
+
if (t.type === "date" ? k(e, "date") : t.type === "time" ? k(e, "time") : k(e, "datetime"), s instanceof Date) return E(s) ? null : "Invalid date";
|
|
181
|
+
if (typeof s == "string") {
|
|
182
|
+
const n = F(s);
|
|
183
|
+
return n && E(n) ? null : "Invalid date/time";
|
|
184
|
+
}
|
|
185
|
+
return "Expected a date/time string";
|
|
186
|
+
}
|
|
187
|
+
default:
|
|
188
|
+
return null;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
class X {
|
|
192
|
+
constructor(t, e, n) {
|
|
193
|
+
this.rows = [], this.baseIndexById = /* @__PURE__ */ new Map(), this.dataVersion = 0, this.visibleRowsCache = null, this.distinctValueCache = /* @__PURE__ */ new Map(), this.pending = /* @__PURE__ */ new Map(), this.rowVersion = /* @__PURE__ */ new Map(), this.listeners = /* @__PURE__ */ new Set(), this.cellStyles = /* @__PURE__ */ new Map(), this.cellConditionalStyles = /* @__PURE__ */ new Map(), this.computedCache = /* @__PURE__ */ new Map(), this.conditionalCache = /* @__PURE__ */ new Map(), this.rowConditionalCache = /* @__PURE__ */ new Map(), this.formulaDiagnostics = /* @__PURE__ */ new Map(), this.conditionalDiagnostics = /* @__PURE__ */ new Map(), this.columnReadonlyCache = /* @__PURE__ */ new Map(), this.baseValidationErrors = /* @__PURE__ */ new Map(), this.uniqueValidationErrors = /* @__PURE__ */ new Map(), this.notifySuspended = !1, this.notifyDirty = !1, this.validateSchema(e), this.schema = e, this.view = n, this.setData(t ?? []);
|
|
194
|
+
}
|
|
195
|
+
subscribe(t) {
|
|
196
|
+
return this.listeners.add(t), () => this.listeners.delete(t);
|
|
197
|
+
}
|
|
198
|
+
notify() {
|
|
199
|
+
if (this.visibleRowsCache = null, this.distinctValueCache.clear(), this.notifySuspended) {
|
|
200
|
+
this.notifyDirty = !0;
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
for (const t of this.listeners) t();
|
|
204
|
+
}
|
|
205
|
+
batchUpdate(t) {
|
|
206
|
+
this.notifySuspended = !0;
|
|
207
|
+
try {
|
|
208
|
+
t();
|
|
209
|
+
} finally {
|
|
210
|
+
this.notifySuspended = !1, this.notifyDirty && (this.notifyDirty = !1, this.notify());
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
setData(t) {
|
|
214
|
+
this.dataVersion += 1, this.pending.clear(), this.cellStyles.clear(), this.cellConditionalStyles.clear(), this.computedCache.clear(), this.conditionalCache.clear(), this.columnReadonlyCache.clear(), this.rowConditionalCache.clear(), this.formulaDiagnostics.clear(), this.conditionalDiagnostics.clear(), this.baseValidationErrors.clear(), this.uniqueValidationErrors.clear(), this.rows = (t ?? []).map((e, n) => {
|
|
215
|
+
const i = e?.id, o = typeof i == "string" && i ? i : R();
|
|
216
|
+
return this.rowVersion.set(o, 0), {
|
|
217
|
+
id: o,
|
|
218
|
+
raw: e,
|
|
219
|
+
displayIndex: n + 1
|
|
220
|
+
};
|
|
221
|
+
}), this.rebuildBaseIndex(), this.recomputeValidationErrors(), this.notify();
|
|
222
|
+
}
|
|
223
|
+
setSchema(t) {
|
|
224
|
+
this.dataVersion += 1, this.validateSchema(t), this.schema = t, this.computedCache.clear(), this.conditionalCache.clear(), this.columnReadonlyCache.clear(), this.rowConditionalCache.clear(), this.formulaDiagnostics.clear(), this.conditionalDiagnostics.clear(), this.recomputeValidationErrors(), this.notify();
|
|
225
|
+
}
|
|
226
|
+
validateSchema(t) {
|
|
227
|
+
if (!(!t || !Array.isArray(t.columns)))
|
|
228
|
+
for (const e of t.columns) {
|
|
229
|
+
if (!e || typeof e != "object") continue;
|
|
230
|
+
const n = e.edit && e.edit.lookup && typeof e.edit.lookup.fetchCandidates == "function";
|
|
231
|
+
if (e.type === "enum") {
|
|
232
|
+
const i = Array.isArray(e.enum) ? e.enum : e.enum && typeof e.enum == "object" && Array.isArray(e.enum.options) ? e.enum.options : null, o = i !== null && i.length > 0;
|
|
233
|
+
if (!o && !n)
|
|
234
|
+
throw new Error(`Column '${e.key}' of type 'enum' must provide either 'enum' options or 'edit.lookup.fetchCandidates'.`);
|
|
235
|
+
if (o) {
|
|
236
|
+
if (i.some((l) => l && typeof l == "object") && String(e.type) !== "labeled")
|
|
237
|
+
throw new Error(`Column '${e.key}' of type 'enum' may not contain labeled option objects; use type 'labeled' instead.`);
|
|
238
|
+
if (String(e.type) === "labeled")
|
|
239
|
+
for (const l of i) {
|
|
240
|
+
if (!(l && typeof l == "object"))
|
|
241
|
+
throw new Error(`Column '${e.key}' labeled options must be objects with 'label' and 'value'.`);
|
|
242
|
+
const a = l;
|
|
243
|
+
if (!Object.prototype.hasOwnProperty.call(a, "label") || !Object.prototype.hasOwnProperty.call(a, "value"))
|
|
244
|
+
throw new Error(`Column '${e.key}' labeled options must include 'label' and 'value' properties.`);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
if (e.type === "tags") {
|
|
249
|
+
const i = Array.isArray(e.tags) ? e.tags : null, o = i !== null && i.length > 0;
|
|
250
|
+
if (!o && !n)
|
|
251
|
+
throw new Error(`Column '${e.key}' of type 'tags' must provide either 'tags' options or 'edit.lookup.fetchCandidates'.`);
|
|
252
|
+
if (o) {
|
|
253
|
+
for (const r of i)
|
|
254
|
+
if (typeof r != "string")
|
|
255
|
+
throw new Error(`Column '${e.key}' tags options must be an array of strings.`);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
setView(t) {
|
|
261
|
+
this.dataVersion += 1, Array.isArray(t.sorts) && t.sorts.length > 1 ? this.view = { ...t, sorts: t.sorts.slice(0, 1) } : this.view = t, this.notify();
|
|
262
|
+
}
|
|
263
|
+
getSchema() {
|
|
264
|
+
return { ...this.schema, columns: this.getColumns() };
|
|
265
|
+
}
|
|
266
|
+
getColumns() {
|
|
267
|
+
return this.schema.columns;
|
|
268
|
+
}
|
|
269
|
+
getRowConditionalStyleFn() {
|
|
270
|
+
return this.schema.row?.conditionalStyle ?? null;
|
|
271
|
+
}
|
|
272
|
+
getView() {
|
|
273
|
+
return this.view;
|
|
274
|
+
}
|
|
275
|
+
getDataVersion() {
|
|
276
|
+
return this.dataVersion;
|
|
277
|
+
}
|
|
278
|
+
getFullSchema() {
|
|
279
|
+
return this.schema;
|
|
280
|
+
}
|
|
281
|
+
listRows() {
|
|
282
|
+
return this.computeVisibleRows().rows;
|
|
283
|
+
}
|
|
284
|
+
listAllRows() {
|
|
285
|
+
return this.rows;
|
|
286
|
+
}
|
|
287
|
+
getAllRowCount() {
|
|
288
|
+
return this.rows.length;
|
|
289
|
+
}
|
|
290
|
+
findRow(t) {
|
|
291
|
+
const e = this.baseIndexById.get(t);
|
|
292
|
+
if (e === void 0) return null;
|
|
293
|
+
const n = this.rows[e];
|
|
294
|
+
if (n && n.id === t) return { row: n, index: e };
|
|
295
|
+
const i = this.rows.findIndex((r) => r.id === t);
|
|
296
|
+
if (i < 0) return null;
|
|
297
|
+
const o = this.rows[i];
|
|
298
|
+
return o ? (this.rebuildBaseIndex(), { row: o, index: i }) : null;
|
|
299
|
+
}
|
|
300
|
+
getRowHeight(t) {
|
|
301
|
+
return this.view.rowHeights?.[t];
|
|
302
|
+
}
|
|
303
|
+
setRowHeight(t, e) {
|
|
304
|
+
this.view.rowHeights || (this.view.rowHeights = {}), this.view.rowHeights[t] !== e && (this.view.rowHeights[t] = e, this.notify());
|
|
305
|
+
}
|
|
306
|
+
setRowHeightsBulk(t) {
|
|
307
|
+
const e = Object.entries(t);
|
|
308
|
+
if (e.length === 0) return;
|
|
309
|
+
this.view.rowHeights || (this.view.rowHeights = {});
|
|
310
|
+
let n = !1;
|
|
311
|
+
for (const [i, o] of e)
|
|
312
|
+
this.view.rowHeights[i] !== o && (this.view.rowHeights[i] = o, n = !0);
|
|
313
|
+
n && this.notify();
|
|
314
|
+
}
|
|
315
|
+
getCell(t, e) {
|
|
316
|
+
const n = this.findRow(t);
|
|
317
|
+
if (!n) return;
|
|
318
|
+
const i = n.row, o = this.pending.get(t);
|
|
319
|
+
return o && e in o ? o[e] : i.raw[e];
|
|
320
|
+
}
|
|
321
|
+
getRawCell(t, e) {
|
|
322
|
+
const n = this.findRow(t);
|
|
323
|
+
return n ? n.row.raw[e] : void 0;
|
|
324
|
+
}
|
|
325
|
+
isRowReadonly(t) {
|
|
326
|
+
const e = this.findRow(t);
|
|
327
|
+
return e ? !!e.row.raw._readonly : !1;
|
|
328
|
+
}
|
|
329
|
+
isActionType(t) {
|
|
330
|
+
return t === "button" || t === "link";
|
|
331
|
+
}
|
|
332
|
+
supportsConditionalReadonly(t) {
|
|
333
|
+
return t === "boolean" || t === "number" || t === "date" || t === "time" || t === "datetime" || t === "string" || t === "enum" || t === "tags";
|
|
334
|
+
}
|
|
335
|
+
isColumnReadonly(t) {
|
|
336
|
+
const e = this.schema.columns.find((n) => n.key === t);
|
|
337
|
+
return this.isActionType(e?.type) ? !0 : !!(e?.readonly === !0 || e?.formula);
|
|
338
|
+
}
|
|
339
|
+
evalReadonlyFn(t, e) {
|
|
340
|
+
try {
|
|
341
|
+
const n = t(e);
|
|
342
|
+
return n instanceof Error ? { value: !1, diagnostic: { level: "warning", message: n.message, source: "conditionalStyle" } } : { value: !!n, diagnostic: null };
|
|
343
|
+
} catch (n) {
|
|
344
|
+
return { value: !1, diagnostic: { level: "warning", message: n instanceof Error ? n.message : String(n ?? "error"), source: "conditionalStyle" } };
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
resolveColumnReadonly(t, e) {
|
|
348
|
+
const n = e.readonly;
|
|
349
|
+
if (!n || typeof n != "function") return { value: !1, diagnostic: null };
|
|
350
|
+
const i = this.getRowVersion(t), o = `${t}::${String(e.key)}::ro`, r = this.columnReadonlyCache.get(o);
|
|
351
|
+
if (r && r.version === i && r.fnRef === n)
|
|
352
|
+
return { value: r.value, diagnostic: r.diagnostic };
|
|
353
|
+
const l = this.getRowObjectEffective(t);
|
|
354
|
+
if (!l) {
|
|
355
|
+
const c = { version: i, fnRef: n, value: !1, diagnostic: null };
|
|
356
|
+
return this.columnReadonlyCache.set(o, c), { value: !1, diagnostic: null };
|
|
357
|
+
}
|
|
358
|
+
const a = this.evalReadonlyFn(n, l);
|
|
359
|
+
return this.columnReadonlyCache.set(o, { version: i, fnRef: n, value: a.value, diagnostic: a.diagnostic }), { value: a.value, diagnostic: a.diagnostic };
|
|
360
|
+
}
|
|
361
|
+
getCellInteraction(t, e) {
|
|
362
|
+
const n = this.schema.columns.find((h) => String(h.key) === String(e));
|
|
363
|
+
if (!n) return { readonly: !1, disabled: !1, muted: !1 };
|
|
364
|
+
const i = this.resolveColumnReadonly(t, n), o = this.isRowReadonly(t) || this.isColumnReadonly(e) || !!i.value, r = this.resolveConditionalStyle(t, n).delta, l = this.getCellStyle(t, e), c = this.supportsConditionalReadonly(n.type) && !!(n.style?.readonly || r?.readonly || l?.readonly), f = this.isActionType(n.type), d = f && !!(n.style?.disabled || r?.disabled || l?.disabled), g = o || c || d, y = !!n.formula;
|
|
365
|
+
return { readonly: g, disabled: d, muted: d || g && !f && !y };
|
|
366
|
+
}
|
|
367
|
+
isReadonly(t, e) {
|
|
368
|
+
return this.getCellInteraction(t, e).readonly;
|
|
369
|
+
}
|
|
370
|
+
setCell(t, e, n, i) {
|
|
371
|
+
this.dataVersion += 1;
|
|
372
|
+
const o = this.findRow(t);
|
|
373
|
+
if (!o) return;
|
|
374
|
+
const r = o.row, l = () => {
|
|
375
|
+
const c = this.rowVersion.get(t) ?? 0;
|
|
376
|
+
this.rowVersion.set(t, c + 1);
|
|
377
|
+
};
|
|
378
|
+
if (i)
|
|
379
|
+
r.raw[e] = n, this.pending.delete(t), l();
|
|
380
|
+
else {
|
|
381
|
+
const c = this.getRawCell(t, e), f = this.pending.get(t) ?? {};
|
|
382
|
+
this.isEqual(c, n) ? delete f[e] : f[e] = n, Object.keys(f).length > 0 ? this.pending.set(t, f) : this.pending.delete(t), l();
|
|
383
|
+
}
|
|
384
|
+
this.updateValidationForCell(t, e, this.getCell(t, e)), this.schema.columns.find((c) => c.key === e)?.unique && this.recomputeUniqueValidationForColumn(e), this.clearDiagnosticsForCell(t, e), this.notify();
|
|
385
|
+
}
|
|
386
|
+
applyPending(t) {
|
|
387
|
+
this.dataVersion += 1;
|
|
388
|
+
const e = this.pending.get(t);
|
|
389
|
+
if (!e) return;
|
|
390
|
+
const n = this.findRow(t);
|
|
391
|
+
if (!n) return;
|
|
392
|
+
const i = n.row, o = /* @__PURE__ */ new Set();
|
|
393
|
+
for (const [r, l] of Object.entries(e)) {
|
|
394
|
+
i.raw[r] = l, this.updateValidationForCell(t, r, l);
|
|
395
|
+
const a = this.schema.columns.find((c) => String(c.key) === String(r));
|
|
396
|
+
a?.unique && o.add(a.key), this.clearDiagnosticsForCell(t, r);
|
|
397
|
+
}
|
|
398
|
+
this.pending.delete(t);
|
|
399
|
+
for (const r of o) this.recomputeUniqueValidationForColumn(r);
|
|
400
|
+
this.notify();
|
|
401
|
+
}
|
|
402
|
+
clearPending(t) {
|
|
403
|
+
this.dataVersion += 1, this.pending.delete(t), this.notify();
|
|
404
|
+
}
|
|
405
|
+
getPending() {
|
|
406
|
+
return this.pending;
|
|
407
|
+
}
|
|
408
|
+
hasPending(t, e) {
|
|
409
|
+
const n = this.pending.get(t);
|
|
410
|
+
return n ? e in n : !1;
|
|
411
|
+
}
|
|
412
|
+
insertRow(t) {
|
|
413
|
+
return this.insertRowAt(t, this.rows.length);
|
|
414
|
+
}
|
|
415
|
+
insertRowAt(t, e, n) {
|
|
416
|
+
this.dataVersion += 1;
|
|
417
|
+
const i = n ?? R(), o = Math.max(0, Math.min(e, this.rows.length));
|
|
418
|
+
return this.rows.splice(o, 0, { id: i, raw: t, displayIndex: 0 }), this.reindexRows(), this.rowVersion.set(i, 0), this.rebuildBaseIndex(), this.recomputeValidationErrors(), this.notify(), i;
|
|
419
|
+
}
|
|
420
|
+
removeRow(t) {
|
|
421
|
+
this.dataVersion += 1;
|
|
422
|
+
const e = this.findRow(t);
|
|
423
|
+
if (!e) return null;
|
|
424
|
+
const n = this.rows.splice(e.index, 1)[0];
|
|
425
|
+
return n ? (this.pending.delete(t), this.rowVersion.delete(t), this.reindexRows(), this.rebuildBaseIndex(), this.recomputeValidationErrors(), this.notify(), { row: n, index: e.index }) : null;
|
|
426
|
+
}
|
|
427
|
+
getDisplayIndex(t) {
|
|
428
|
+
return this.findRow(t)?.row.displayIndex ?? null;
|
|
429
|
+
}
|
|
430
|
+
getRowIndex(t) {
|
|
431
|
+
return this.computeVisibleRows().indexById.get(t) ?? -1;
|
|
432
|
+
}
|
|
433
|
+
getBaseRowIndex(t) {
|
|
434
|
+
return this.baseIndexById.get(t) ?? -1;
|
|
435
|
+
}
|
|
436
|
+
getColumnIndex(t) {
|
|
437
|
+
return this.getColumns().findIndex((e) => e.key === t);
|
|
438
|
+
}
|
|
439
|
+
getColumnByIndex(t) {
|
|
440
|
+
return this.getColumns()[t] ?? null;
|
|
441
|
+
}
|
|
442
|
+
getRowByIndex(t) {
|
|
443
|
+
return this.listRows()[t] ?? null;
|
|
444
|
+
}
|
|
445
|
+
rebuildBaseIndex() {
|
|
446
|
+
this.baseIndexById.clear();
|
|
447
|
+
for (let t = 0; t < this.rows.length; t += 1) {
|
|
448
|
+
const e = this.rows[t];
|
|
449
|
+
e && this.baseIndexById.set(e.id, t);
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
getFilterSortKey(t) {
|
|
453
|
+
const e = t?.excludeColumnKey, n = t?.includeSort ?? !0, i = this.view, o = (i.filters ?? []).filter((a) => {
|
|
454
|
+
if (e === void 0) return !0;
|
|
455
|
+
const c = a?.key;
|
|
456
|
+
return String(c) !== String(e);
|
|
457
|
+
}).map((a) => {
|
|
458
|
+
if (a?.kind === "values") {
|
|
459
|
+
const d = a;
|
|
460
|
+
return {
|
|
461
|
+
kind: "values",
|
|
462
|
+
key: String(d.key),
|
|
463
|
+
includeBlanks: !!d.includeBlanks,
|
|
464
|
+
values: (d.values ?? []).map((g) => this.stableValueKey(g))
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
const f = a;
|
|
468
|
+
return {
|
|
469
|
+
kind: "op",
|
|
470
|
+
key: String(f.key),
|
|
471
|
+
op: String(f.op ?? ""),
|
|
472
|
+
value: this.stableValueKey(f.value)
|
|
473
|
+
};
|
|
474
|
+
}).sort((a, c) => a.key === c.key ? a.kind < c.kind ? -1 : 1 : a.key < c.key ? -1 : 1), r = Object.entries(i.columnDiagnostics ?? {}).filter(([a]) => e !== void 0 ? String(a) !== String(e) : !0).map(([a, c]) => ({
|
|
475
|
+
key: String(a),
|
|
476
|
+
errors: !!c?.errors,
|
|
477
|
+
warnings: !!c?.warnings
|
|
478
|
+
})).filter((a) => a.errors || a.warnings).sort((a, c) => a.key < c.key ? -1 : a.key > c.key ? 1 : 0), l = n ? (i.sorts ?? []).slice(0, 1).map((a) => ({ key: String(a.key), dir: a.dir })) : [];
|
|
479
|
+
return JSON.stringify({ filters: o, columnDiagnosticsEntries: r, sorts: l });
|
|
480
|
+
}
|
|
481
|
+
stableValueKey(t) {
|
|
482
|
+
if (t === null) return "null";
|
|
483
|
+
if (t === void 0) return "undefined";
|
|
484
|
+
if (t instanceof Date) return `date:${t.getTime()}`;
|
|
485
|
+
if (typeof t == "string") return `s:${t}`;
|
|
486
|
+
if (typeof t == "number") return `n:${Number.isNaN(t) ? "NaN" : String(t)}`;
|
|
487
|
+
if (typeof t == "boolean") return `b:${t ? "1" : "0"}`;
|
|
488
|
+
if (typeof t == "object") {
|
|
489
|
+
const e = t, n = e.kind;
|
|
490
|
+
if (n === "enum" && typeof e.value == "string") return `enum:${e.value}`;
|
|
491
|
+
if (n === "tags" && Array.isArray(e.values))
|
|
492
|
+
return `tags:${e.values.filter((i) => typeof i == "string").join("|")}`;
|
|
493
|
+
}
|
|
494
|
+
try {
|
|
495
|
+
return `json:${JSON.stringify(t)}`;
|
|
496
|
+
} catch {
|
|
497
|
+
return `str:${String(t)}`;
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
isBlankValue(t) {
|
|
501
|
+
return t == null || t === "";
|
|
502
|
+
}
|
|
503
|
+
resolveFilterColumnKey(t) {
|
|
504
|
+
return this.getColumns().find((i) => String(i.key) === String(t))?.key ?? t;
|
|
505
|
+
}
|
|
506
|
+
getFilterCellValue(t, e) {
|
|
507
|
+
const n = this.getColumns().find((i) => String(i.key) === String(e));
|
|
508
|
+
return n ? this.resolveCellValue(t, n).value : this.getCell(t, e);
|
|
509
|
+
}
|
|
510
|
+
valuesFilterMatches(t, e) {
|
|
511
|
+
const n = this.resolveFilterColumnKey(e.key), i = this.getFilterCellValue(t, n);
|
|
512
|
+
if (this.isBlankValue(i)) return !!e.includeBlanks;
|
|
513
|
+
if (!e.values || e.values.length === 0) return !1;
|
|
514
|
+
const o = this.stableValueKey(i);
|
|
515
|
+
for (const r of e.values)
|
|
516
|
+
if (this.stableValueKey(r) === o) return !0;
|
|
517
|
+
return !1;
|
|
518
|
+
}
|
|
519
|
+
rowPassesColumnDiagnostics(t, e, n) {
|
|
520
|
+
const i = !!n.errors, o = !!n.warnings;
|
|
521
|
+
if (!i && !o) return !0;
|
|
522
|
+
const r = this.resolveFilterColumnKey(e), l = this.getColumns().find((c) => String(c.key) === String(r));
|
|
523
|
+
l && (this.resolveCellValue(t, l), this.resolveConditionalStyle(t, l));
|
|
524
|
+
const a = this.getCellMarker(t, r);
|
|
525
|
+
return a ? a.level === "error" ? i : o : !1;
|
|
526
|
+
}
|
|
527
|
+
computeRowsAfterFilter(t) {
|
|
528
|
+
const e = t?.excludeColumnKey, n = t?.includeSort ?? !0, i = this.view, o = this.getSchema(), r = (i.filters ?? []).filter((u) => {
|
|
529
|
+
if (e === void 0) return !0;
|
|
530
|
+
const h = u?.key;
|
|
531
|
+
return String(h) !== String(e);
|
|
532
|
+
}), l = Object.entries(i.columnDiagnostics ?? {}).filter(
|
|
533
|
+
([u]) => e !== void 0 ? String(u) !== String(e) : !0
|
|
534
|
+
), a = [];
|
|
535
|
+
for (const u of this.rows) {
|
|
536
|
+
let h = !0;
|
|
537
|
+
for (const m of r)
|
|
538
|
+
if (m?.kind === "values" && !this.valuesFilterMatches(u.id, m)) {
|
|
539
|
+
h = !1;
|
|
540
|
+
break;
|
|
541
|
+
}
|
|
542
|
+
if (h) {
|
|
543
|
+
for (const [m, p] of l)
|
|
544
|
+
if (!this.rowPassesColumnDiagnostics(u.id, m, p)) {
|
|
545
|
+
h = !1;
|
|
546
|
+
break;
|
|
547
|
+
}
|
|
548
|
+
h && a.push(u);
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
if (!n) return a;
|
|
552
|
+
const c = (i.sorts ?? []).slice(0, 1)[0];
|
|
553
|
+
if (!c) return a;
|
|
554
|
+
const f = o.columns.find((u) => String(u.key) === String(c.key));
|
|
555
|
+
if (!f) return a;
|
|
556
|
+
const d = c.dir === "desc" ? -1 : 1, g = a.map((u) => {
|
|
557
|
+
const h = this.getFilterCellValue(u.id, f.key), m = this.isBlankValue(h), p = this.baseIndexById.get(u.id) ?? 0;
|
|
558
|
+
return { row: u, v: h, blank: m, baseIndex: p };
|
|
559
|
+
}), y = (u, h) => {
|
|
560
|
+
if (u === h) return 0;
|
|
561
|
+
if (u instanceof Date && h instanceof Date) return u.getTime() - h.getTime();
|
|
562
|
+
if (typeof u == "number" && typeof h == "number") return u - h;
|
|
563
|
+
if (typeof u == "boolean" && typeof h == "boolean") return u === h ? 0 : u ? 1 : -1;
|
|
564
|
+
const m = u instanceof Date ? u.toISOString() : typeof u == "string" ? u : String(u), p = h instanceof Date ? h.toISOString() : typeof h == "string" ? h : String(h);
|
|
565
|
+
return m === p ? 0 : m < p ? -1 : 1;
|
|
566
|
+
};
|
|
567
|
+
return g.sort((u, h) => {
|
|
568
|
+
if (u.blank && h.blank) return u.baseIndex - h.baseIndex;
|
|
569
|
+
if (u.blank) return 1;
|
|
570
|
+
if (h.blank) return -1;
|
|
571
|
+
const m = y(u.v, h.v);
|
|
572
|
+
return m !== 0 ? m * d : u.baseIndex - h.baseIndex;
|
|
573
|
+
}), g.map((u) => u.row);
|
|
574
|
+
}
|
|
575
|
+
computeVisibleRows() {
|
|
576
|
+
const t = this.getFilterSortKey(), e = this.visibleRowsCache;
|
|
577
|
+
if (e && e.version === this.dataVersion && e.key === t) return e;
|
|
578
|
+
const i = this.computeRowsAfterFilter({ includeSort: !0 }), o = /* @__PURE__ */ new Map();
|
|
579
|
+
for (let l = 0; l < i.length; l += 1) {
|
|
580
|
+
const a = i[l];
|
|
581
|
+
a && o.set(a.id, l);
|
|
582
|
+
}
|
|
583
|
+
const r = { version: this.dataVersion, key: t, rows: i, indexById: o };
|
|
584
|
+
return this.visibleRowsCache = r, r;
|
|
585
|
+
}
|
|
586
|
+
getDistinctValuesForColumn(t) {
|
|
587
|
+
const e = `${String(t)}|${this.getFilterSortKey({ excludeColumnKey: t, includeSort: !1 })}`, n = this.distinctValueCache.get(e);
|
|
588
|
+
if (n && n.version === this.dataVersion) return n;
|
|
589
|
+
const i = this.computeRowsAfterFilter({ excludeColumnKey: t, includeSort: !1 }), o = this.getSchema().columns.find((f) => String(f.key) === String(t));
|
|
590
|
+
if (!o) {
|
|
591
|
+
const f = { version: this.dataVersion, values: [], hasBlanks: !1, total: 0 };
|
|
592
|
+
return this.distinctValueCache.set(e, f), f;
|
|
593
|
+
}
|
|
594
|
+
const r = /* @__PURE__ */ new Map();
|
|
595
|
+
let l = !1;
|
|
596
|
+
for (const f of i) {
|
|
597
|
+
const d = this.getFilterCellValue(f.id, o.key);
|
|
598
|
+
if (this.isBlankValue(d)) {
|
|
599
|
+
l = !0;
|
|
600
|
+
continue;
|
|
601
|
+
}
|
|
602
|
+
const g = this.stableValueKey(d);
|
|
603
|
+
if (r.has(g)) continue;
|
|
604
|
+
const y = (() => {
|
|
605
|
+
if (d instanceof Date) return d.toISOString();
|
|
606
|
+
if (typeof d == "string") return d;
|
|
607
|
+
if (typeof d == "number" || typeof d == "boolean") return String(d);
|
|
608
|
+
if (typeof d == "object" && d) {
|
|
609
|
+
const u = d, h = u.kind;
|
|
610
|
+
if (h === "enum" && typeof u.value == "string") return u.value;
|
|
611
|
+
if (h === "tags" && Array.isArray(u.values))
|
|
612
|
+
return u.values.filter((m) => typeof m == "string").join(", ");
|
|
613
|
+
}
|
|
614
|
+
return String(d);
|
|
615
|
+
})();
|
|
616
|
+
r.set(g, { value: d, label: y });
|
|
617
|
+
}
|
|
618
|
+
const a = [...r.values()].sort(
|
|
619
|
+
(f, d) => f.label < d.label ? -1 : f.label > d.label ? 1 : 0
|
|
620
|
+
), c = {
|
|
621
|
+
version: this.dataVersion,
|
|
622
|
+
values: a,
|
|
623
|
+
hasBlanks: l,
|
|
624
|
+
total: a.length + (l ? 1 : 0)
|
|
625
|
+
};
|
|
626
|
+
return this.distinctValueCache.set(e, c), c;
|
|
627
|
+
}
|
|
628
|
+
cellStyleKey(t, e) {
|
|
629
|
+
return `${t}::${String(e)}`;
|
|
630
|
+
}
|
|
631
|
+
clearDiagnosticsForCell(t, e) {
|
|
632
|
+
const n = this.cellStyleKey(t, e);
|
|
633
|
+
this.formulaDiagnostics.delete(n), this.conditionalDiagnostics.delete(n);
|
|
634
|
+
}
|
|
635
|
+
getCellDiagnostic(t, e) {
|
|
636
|
+
const n = this.cellStyleKey(t, e), i = this.formulaDiagnostics.get(n) ?? null, o = this.conditionalDiagnostics.get(n) ?? null;
|
|
637
|
+
return i ? !o || i.level === "error" ? i : o.level === "error" ? o : i : o;
|
|
638
|
+
}
|
|
639
|
+
getDiagnostics() {
|
|
640
|
+
const t = /* @__PURE__ */ new Set();
|
|
641
|
+
for (const e of this.formulaDiagnostics.keys()) t.add(e);
|
|
642
|
+
for (const e of this.conditionalDiagnostics.keys()) t.add(e);
|
|
643
|
+
return [...t].map((e) => {
|
|
644
|
+
const n = e.indexOf("::"), i = n >= 0 ? e.slice(0, n) : e, o = n >= 0 ? e.slice(n + 2) : "";
|
|
645
|
+
return { rowId: i, colKey: o, diag: this.getCellDiagnostic(i, o) };
|
|
646
|
+
});
|
|
647
|
+
}
|
|
648
|
+
getRowObjectEffective(t) {
|
|
649
|
+
const e = this.findRow(t);
|
|
650
|
+
if (!e) return null;
|
|
651
|
+
const n = e.row, i = this.pending.get(t);
|
|
652
|
+
if (!i || Object.keys(i).length === 0)
|
|
653
|
+
return n.raw;
|
|
654
|
+
const o = { ...n.raw };
|
|
655
|
+
for (const [r, l] of Object.entries(i))
|
|
656
|
+
o[r] = l;
|
|
657
|
+
return o;
|
|
658
|
+
}
|
|
659
|
+
resolveCellValue(t, e) {
|
|
660
|
+
if (!e.formula)
|
|
661
|
+
return { value: this.getCell(t, e.key), diagnostic: null };
|
|
662
|
+
const n = this.getRowVersion(t), i = this.cellStyleKey(t, e.key), o = this.computedCache.get(i);
|
|
663
|
+
if (o && o.version === n && o.formulaRef === e.formula)
|
|
664
|
+
return o.diagnostic && this.formulaDiagnostics.set(i, o.diagnostic), {
|
|
665
|
+
value: o.value,
|
|
666
|
+
textOverride: o.textOverride,
|
|
667
|
+
diagnostic: o.diagnostic
|
|
668
|
+
};
|
|
669
|
+
const r = this.getRowObjectEffective(t);
|
|
670
|
+
if (!r) {
|
|
671
|
+
const l = this.getCell(t, e.key), a = {
|
|
672
|
+
version: n,
|
|
673
|
+
formulaRef: e.formula,
|
|
674
|
+
value: l,
|
|
675
|
+
diagnostic: null
|
|
676
|
+
};
|
|
677
|
+
return this.computedCache.set(i, a), { value: l, diagnostic: null };
|
|
678
|
+
}
|
|
679
|
+
try {
|
|
680
|
+
const l = e.formula(r);
|
|
681
|
+
if (Array.isArray(l) && l.length >= 2 && l[1] instanceof Error) {
|
|
682
|
+
const c = {
|
|
683
|
+
level: "warning",
|
|
684
|
+
message: l[1].message,
|
|
685
|
+
source: "formula"
|
|
686
|
+
}, f = l[0];
|
|
687
|
+
return this.computedCache.set(i, { version: n, formulaRef: e.formula, value: f, diagnostic: c }), this.formulaDiagnostics.set(i, c), { value: f, diagnostic: c };
|
|
688
|
+
}
|
|
689
|
+
const a = l;
|
|
690
|
+
return this.computedCache.set(i, { version: n, formulaRef: e.formula, value: a, diagnostic: null }), this.formulaDiagnostics.delete(i), { value: a, diagnostic: null };
|
|
691
|
+
} catch (l) {
|
|
692
|
+
const c = { level: "error", message: l instanceof Error ? l.message : String(l), source: "formula" };
|
|
693
|
+
return this.computedCache.set(i, {
|
|
694
|
+
version: n,
|
|
695
|
+
formulaRef: e.formula,
|
|
696
|
+
value: null,
|
|
697
|
+
textOverride: "#ERROR",
|
|
698
|
+
diagnostic: c
|
|
699
|
+
}), this.formulaDiagnostics.set(i, c), { value: null, textOverride: "#ERROR", diagnostic: c };
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
setCellConditionalStyle(t, e, n) {
|
|
703
|
+
const i = this.cellStyleKey(t, e);
|
|
704
|
+
n ? this.cellConditionalStyles.set(i, n) : this.cellConditionalStyles.delete(i), this.conditionalCache.delete(i), this.clearDiagnosticsForCell(t, e), this.notify();
|
|
705
|
+
}
|
|
706
|
+
evalConditionalStyleFn(t, e) {
|
|
707
|
+
try {
|
|
708
|
+
const n = t(e);
|
|
709
|
+
return n instanceof Error ? {
|
|
710
|
+
delta: null,
|
|
711
|
+
diagnostic: { level: "warning", message: n.message, source: "conditionalStyle" },
|
|
712
|
+
forceErrorText: !1
|
|
713
|
+
} : { delta: n ?? null, diagnostic: null, forceErrorText: !1 };
|
|
714
|
+
} catch (n) {
|
|
715
|
+
return {
|
|
716
|
+
delta: null,
|
|
717
|
+
diagnostic: { level: "error", message: n instanceof Error ? n.message : String(n), source: "conditionalStyle" },
|
|
718
|
+
forceErrorText: !0
|
|
719
|
+
};
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
resolveRowConditionalStyle(t) {
|
|
723
|
+
const e = this.getRowConditionalStyleFn();
|
|
724
|
+
if (!e) return { delta: null, diagnostic: null, forceErrorText: !1 };
|
|
725
|
+
const n = this.getRowVersion(t), i = this.rowConditionalCache.get(t);
|
|
726
|
+
if (i && i.version === n && i.fnRef === e)
|
|
727
|
+
return {
|
|
728
|
+
delta: i.delta,
|
|
729
|
+
diagnostic: i.diagnostic,
|
|
730
|
+
forceErrorText: i.forceErrorText
|
|
731
|
+
};
|
|
732
|
+
const o = this.getRowObjectEffective(t);
|
|
733
|
+
if (!o) {
|
|
734
|
+
const l = { version: n, fnRef: e, delta: null, diagnostic: null, forceErrorText: !1 };
|
|
735
|
+
return this.rowConditionalCache.set(t, l), { delta: null, diagnostic: null, forceErrorText: !1 };
|
|
736
|
+
}
|
|
737
|
+
const r = this.evalConditionalStyleFn(e, o);
|
|
738
|
+
return this.rowConditionalCache.set(t, { version: n, fnRef: e, ...r }), r;
|
|
739
|
+
}
|
|
740
|
+
resolveConditionalStyle(t, e) {
|
|
741
|
+
const n = this.getRowVersion(t), i = this.cellStyleKey(t, e.key), o = this.getRowObjectEffective(t), r = this.resolveRowConditionalStyle(t), l = (g, y) => y ? g ? { ...g, ...y } : { ...y } : g;
|
|
742
|
+
let a = null, c = null, f = !1;
|
|
743
|
+
if (a = l(a, r.delta), r.diagnostic && (c = r.diagnostic), f = f || r.forceErrorText, e.conditionalStyle && o) {
|
|
744
|
+
const g = `${t}::${String(e.key)}::col`, y = this.conditionalCache.get(g);
|
|
745
|
+
if (y && y.version === n && y.fnRef === e.conditionalStyle)
|
|
746
|
+
a = l(a, y.delta), y.diagnostic && (c === null || c.level !== "error") && (c = y.diagnostic), f = f || y.forceErrorText;
|
|
747
|
+
else {
|
|
748
|
+
const u = this.evalConditionalStyleFn(e.conditionalStyle, o);
|
|
749
|
+
this.conditionalCache.set(g, { version: n, fnRef: e.conditionalStyle, ...u }), a = l(a, u.delta), u.diagnostic && (c === null || c.level !== "error") && (c = u.diagnostic), f = f || u.forceErrorText;
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
const d = this.cellConditionalStyles.get(i);
|
|
753
|
+
if (d && o) {
|
|
754
|
+
const g = this.conditionalCache.get(i);
|
|
755
|
+
if (g && g.version === n && g.fnRef === d)
|
|
756
|
+
a = l(a, g.delta), g.diagnostic && (c === null || c.level !== "error") && (c = g.diagnostic), f = f || g.forceErrorText;
|
|
757
|
+
else {
|
|
758
|
+
const y = this.evalConditionalStyleFn(d, o);
|
|
759
|
+
this.conditionalCache.set(i, { version: n, fnRef: d, ...y }), a = l(a, y.delta), y.diagnostic && (c === null || c.level !== "error") && (c = y.diagnostic), f = f || y.forceErrorText;
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
return c ? this.conditionalDiagnostics.set(i, c) : this.conditionalDiagnostics.delete(i), { delta: a, diagnostic: c, forceErrorText: f };
|
|
763
|
+
}
|
|
764
|
+
getValidationErrors() {
|
|
765
|
+
const t = /* @__PURE__ */ new Map();
|
|
766
|
+
for (const [n, i] of this.baseValidationErrors.entries()) t.set(n, { ...i });
|
|
767
|
+
for (const [n, i] of this.uniqueValidationErrors.entries()) {
|
|
768
|
+
const o = t.get(n);
|
|
769
|
+
o ? t.set(n, { ...o, message: `${o.message}
|
|
770
|
+
${i.message}` }) : t.set(n, { ...i });
|
|
771
|
+
}
|
|
772
|
+
const e = [...t.values()];
|
|
773
|
+
return e.sort((n, i) => {
|
|
774
|
+
const o = this.getRowIndex(n.rowId), r = this.getRowIndex(i.rowId);
|
|
775
|
+
if (o !== r) return o - r;
|
|
776
|
+
const l = this.getColumnIndex(n.colKey), a = this.getColumnIndex(i.colKey);
|
|
777
|
+
return l - a;
|
|
778
|
+
}), e;
|
|
779
|
+
}
|
|
780
|
+
getCellValidationMessage(t, e) {
|
|
781
|
+
const n = this.cellStyleKey(t, e), i = this.baseValidationErrors.get(n)?.message ?? null, o = this.uniqueValidationErrors.get(n)?.message ?? null;
|
|
782
|
+
return i ? o ? `${i}
|
|
783
|
+
${o}` : i : o;
|
|
784
|
+
}
|
|
785
|
+
getCellMarker(t, e) {
|
|
786
|
+
const n = this.getCellDiagnostic(t, e), i = this.getCellValidationMessage(t, e);
|
|
787
|
+
if (!n && !i) return null;
|
|
788
|
+
const o = i ? "error" : n?.level ?? "warning", r = [n?.message ?? null, i].filter(Boolean).join(`
|
|
789
|
+
`);
|
|
790
|
+
return { level: o, message: r };
|
|
791
|
+
}
|
|
792
|
+
updateValidationForCell(t, e, n) {
|
|
793
|
+
const i = this.schema.columns.find((l) => String(l.key) === String(e));
|
|
794
|
+
if (!i) return;
|
|
795
|
+
const o = $(n, i), r = this.cellStyleKey(t, e);
|
|
796
|
+
o ? this.baseValidationErrors.set(r, { rowId: t, colKey: e, message: o }) : this.baseValidationErrors.delete(r);
|
|
797
|
+
}
|
|
798
|
+
recomputeValidationErrors() {
|
|
799
|
+
this.baseValidationErrors.clear(), this.uniqueValidationErrors.clear();
|
|
800
|
+
for (const t of this.rows)
|
|
801
|
+
for (const e of this.schema.columns) {
|
|
802
|
+
const n = this.getCell(t.id, e.key);
|
|
803
|
+
this.updateValidationForCell(t.id, e.key, n);
|
|
804
|
+
}
|
|
805
|
+
for (const t of this.getColumns())
|
|
806
|
+
t.unique && this.recomputeUniqueValidationForColumn(t.key);
|
|
807
|
+
}
|
|
808
|
+
normalizeUniqueValue(t) {
|
|
809
|
+
if (t == null) return null;
|
|
810
|
+
if (typeof t == "string") return t === "" ? null : t;
|
|
811
|
+
if (typeof t == "number" || typeof t == "boolean") return String(t);
|
|
812
|
+
if (t instanceof Date) return String(t.getTime());
|
|
813
|
+
if (typeof t == "object") {
|
|
814
|
+
const e = t, n = e.kind;
|
|
815
|
+
if (n === "enum" && typeof e.value == "string")
|
|
816
|
+
return e.value === "" ? null : e.value;
|
|
817
|
+
if (n === "tags" && Array.isArray(e.values)) {
|
|
818
|
+
const i = e.values.filter((o) => typeof o == "string").join(",");
|
|
819
|
+
return i === "" ? null : i;
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
return String(t);
|
|
823
|
+
}
|
|
824
|
+
recomputeUniqueValidationForColumn(t) {
|
|
825
|
+
const e = String(t);
|
|
826
|
+
if (this.schema.columns.find((o) => String(o.key) === e)?.type === "boolean") return;
|
|
827
|
+
for (const o of Array.from(this.uniqueValidationErrors.keys())) {
|
|
828
|
+
const r = o.indexOf("::");
|
|
829
|
+
(r >= 0 ? o.slice(r + 2) : "") === e && this.uniqueValidationErrors.delete(o);
|
|
830
|
+
}
|
|
831
|
+
const i = /* @__PURE__ */ new Map();
|
|
832
|
+
for (const o of this.rows) {
|
|
833
|
+
const r = this.getCell(o.id, t), l = this.normalizeUniqueValue(r);
|
|
834
|
+
if (!l) continue;
|
|
835
|
+
const a = i.get(l) ?? [];
|
|
836
|
+
a.push(o.id), i.set(l, a);
|
|
837
|
+
}
|
|
838
|
+
for (const o of i.values()) {
|
|
839
|
+
if (o.length < 2) continue;
|
|
840
|
+
const r = o.map((a) => this.getDisplayIndex(a)).filter((a) => typeof a == "number" && Number.isFinite(a)).sort((a, c) => a - c), l = r.length ? r.join(", ") : o.join(", ");
|
|
841
|
+
for (const a of o) {
|
|
842
|
+
const c = this.cellStyleKey(a, t);
|
|
843
|
+
this.uniqueValidationErrors.set(c, {
|
|
844
|
+
rowId: a,
|
|
845
|
+
colKey: t,
|
|
846
|
+
message: `Duplicate value
|
|
847
|
+
Rows: ${l}`
|
|
848
|
+
});
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
getCellStyle(t, e) {
|
|
853
|
+
return this.cellStyles.get(this.cellStyleKey(t, e)) ?? null;
|
|
854
|
+
}
|
|
855
|
+
setCellStyle(t, e, n) {
|
|
856
|
+
const i = this.cellStyleKey(t, e);
|
|
857
|
+
!n || Object.keys(n).length === 0 ? this.cellStyles.delete(i) : this.cellStyles.set(i, n), this.notify();
|
|
858
|
+
}
|
|
859
|
+
updateColumnStyle(t, e) {
|
|
860
|
+
const n = this.schema.columns.find((o) => String(o.key) === String(t));
|
|
861
|
+
if (!n) return;
|
|
862
|
+
const i = typeof e == "function" ? e(n.style) : e;
|
|
863
|
+
n.style = i, this.notify();
|
|
864
|
+
}
|
|
865
|
+
isEqual(t, e) {
|
|
866
|
+
return t instanceof Date && e instanceof Date ? t.getTime() === e.getTime() : Object.is(t, e);
|
|
867
|
+
}
|
|
868
|
+
getRowVersion(t) {
|
|
869
|
+
return this.rowVersion.get(t) ?? 0;
|
|
870
|
+
}
|
|
871
|
+
reindexRows() {
|
|
872
|
+
let t = 1;
|
|
873
|
+
for (const e of this.rows)
|
|
874
|
+
e.displayIndex = t, t += 1;
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
const x = 864e5;
|
|
878
|
+
function v(s) {
|
|
879
|
+
const t = F(s);
|
|
880
|
+
return t ? Number.isNaN(t.getTime()) ? null : t : null;
|
|
881
|
+
}
|
|
882
|
+
function I(s) {
|
|
883
|
+
const t = /* @__PURE__ */ new Date(`1970-01-01T${s}`);
|
|
884
|
+
return Number.isNaN(t.getTime()) ? null : t;
|
|
885
|
+
}
|
|
886
|
+
function G(s, t, e) {
|
|
887
|
+
if (t == null) return null;
|
|
888
|
+
if (typeof t == "object") {
|
|
889
|
+
const n = t;
|
|
890
|
+
if (n.kind === "lookup" && typeof n.value == "string")
|
|
891
|
+
return n.value;
|
|
892
|
+
if (typeof n.label == "string" && "value" in n && e.type === "labeled") {
|
|
893
|
+
const i = n.value;
|
|
894
|
+
return i == null ? null : typeof i == "string" ? i : typeof i == "number" || typeof i == "boolean" ? String(i) : i instanceof Date ? i.toISOString() : String(i);
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
if (e.type === "string" || e.type === "labeled") return null;
|
|
898
|
+
if (e.type === "boolean") return String(!!t);
|
|
899
|
+
if ((e.type === "number" || e.type === "int" || e.type === "uint") && typeof t == "number")
|
|
900
|
+
return String(t);
|
|
901
|
+
if (e.type === "datetime") {
|
|
902
|
+
const n = t instanceof Date ? t : v(String(t));
|
|
903
|
+
return n ? String(n.getTime()) : null;
|
|
904
|
+
}
|
|
905
|
+
if (e.type === "date") {
|
|
906
|
+
const n = t instanceof Date ? t : v(String(t));
|
|
907
|
+
if (!n) return null;
|
|
908
|
+
const i = Math.floor(n.getTime() / x) * x;
|
|
909
|
+
return String(i);
|
|
910
|
+
}
|
|
911
|
+
if (e.type === "time") {
|
|
912
|
+
const n = t instanceof Date ? t : I(String(t));
|
|
913
|
+
return n ? String(n.getTime() % x) : null;
|
|
914
|
+
}
|
|
915
|
+
return null;
|
|
916
|
+
}
|
|
917
|
+
const z = 35, Z = 48, J = 35, P = 80, Y = 6, Q = 8, tt = 4, et = 4;
|
|
918
|
+
function nt(s, t, e = 100) {
|
|
919
|
+
const n = {
|
|
920
|
+
// Reserve extra space for browser UI affordances (e.g. date picker icon) and formatting.
|
|
921
|
+
date: 8
|
|
922
|
+
};
|
|
923
|
+
return s.columns.map((i) => {
|
|
924
|
+
const o = t.columnWidths?.[String(i.key)] ?? i.width ?? e, r = n[i.type] ?? 0;
|
|
925
|
+
return o + r;
|
|
926
|
+
});
|
|
927
|
+
}
|
|
928
|
+
function it(s, t, e = P) {
|
|
929
|
+
const n = Math.max(1, e - t);
|
|
930
|
+
return Math.max(n, s);
|
|
931
|
+
}
|
|
932
|
+
function _(s) {
|
|
933
|
+
const t = s.style, e = t?.decorations;
|
|
934
|
+
return {
|
|
935
|
+
backgroundColor: t?.backgroundColor,
|
|
936
|
+
textColor: t?.textColor,
|
|
937
|
+
bold: e?.bold,
|
|
938
|
+
italic: e?.italic,
|
|
939
|
+
underline: e?.underline,
|
|
940
|
+
strike: e?.strike,
|
|
941
|
+
readonly: t?.readonly,
|
|
942
|
+
disabled: t?.disabled
|
|
943
|
+
};
|
|
944
|
+
}
|
|
945
|
+
function V(s, t) {
|
|
946
|
+
return t ? {
|
|
947
|
+
backgroundColor: t.backgroundColor ?? s.backgroundColor,
|
|
948
|
+
textColor: t.textColor ?? s.textColor,
|
|
949
|
+
bold: t.bold ?? s.bold,
|
|
950
|
+
italic: t.italic ?? s.italic,
|
|
951
|
+
underline: t.underline ?? s.underline,
|
|
952
|
+
strike: t.strike ?? s.strike,
|
|
953
|
+
readonly: t.readonly ?? s.readonly,
|
|
954
|
+
disabled: t.disabled ?? s.disabled
|
|
955
|
+
} : s;
|
|
956
|
+
}
|
|
957
|
+
function st(s, t, e) {
|
|
958
|
+
const n = _(e), i = s.resolveConditionalStyle(t, e).delta ?? {}, o = s.getCellStyle(t, e.key) ?? {}, r = V(V(n, i), o);
|
|
959
|
+
return { columnStyle: n, cellStyle: o, resolved: r };
|
|
960
|
+
}
|
|
961
|
+
function ot(s) {
|
|
962
|
+
let t = "";
|
|
963
|
+
s.backgroundColor && (t += `background-color:${s.backgroundColor};`), s.textColor && (t += `color:${s.textColor};`), s.bold && (t += "font-weight:600;"), s.italic && (t += "font-style:italic;");
|
|
964
|
+
const e = [];
|
|
965
|
+
return s.underline && e.push("underline"), s.strike && e.push("line-through"), e.length && (t += `text-decoration-line:${e.join(" ")};`), t;
|
|
966
|
+
}
|
|
967
|
+
function rt(s) {
|
|
968
|
+
if (typeof s == "string") return { label: s };
|
|
969
|
+
if (!s || typeof s != "object") return null;
|
|
970
|
+
const t = s, e = t.label, n = t.command, i = t.commandfor;
|
|
971
|
+
return typeof e != "string" ? null : typeof n == "string" && typeof i == "string" ? { label: e, command: n, commandfor: i } : null;
|
|
972
|
+
}
|
|
973
|
+
function lt(s) {
|
|
974
|
+
if (typeof s == "string") return s;
|
|
975
|
+
if (!s || typeof s != "object") return "";
|
|
976
|
+
const t = s.label;
|
|
977
|
+
return typeof t == "string" ? t : "";
|
|
978
|
+
}
|
|
979
|
+
function at(s) {
|
|
980
|
+
if (typeof s == "string") return { label: s, href: s };
|
|
981
|
+
if (!s || typeof s != "object") return null;
|
|
982
|
+
const t = s, e = t.label, n = t.href, i = t.target;
|
|
983
|
+
return typeof e != "string" || typeof n != "string" ? null : typeof i == "string" ? { label: e, href: n, target: i } : i === void 0 ? { label: e, href: n } : null;
|
|
984
|
+
}
|
|
985
|
+
function ct(s) {
|
|
986
|
+
if (typeof s == "string") return s;
|
|
987
|
+
if (!s || typeof s != "object") return "";
|
|
988
|
+
const t = s, e = t.label, n = t.href;
|
|
989
|
+
return typeof e == "string" ? e : typeof n == "string" ? n : "";
|
|
990
|
+
}
|
|
991
|
+
function K(s) {
|
|
992
|
+
return s.normalize("NFKC").trim();
|
|
993
|
+
}
|
|
994
|
+
const L = (s) => {
|
|
995
|
+
const t = s.trim(), e = /^([+-]?)(0[bBoOxX])([0-9a-fA-F]+)$/.exec(t);
|
|
996
|
+
if (!e) return null;
|
|
997
|
+
const n = e[1] === "-" ? -1 : 1, i = e[2].toLowerCase(), o = e[3] ?? "";
|
|
998
|
+
let r = 10, l = /^[0-9]+$/;
|
|
999
|
+
if (i === "0b" ? (r = 2, l = /^[01]+$/) : i === "0o" ? (r = 8, l = /^[0-7]+$/) : i === "0x" && (r = 16, l = /^[0-9a-fA-F]+$/), !o || !l.test(o)) return NaN;
|
|
1000
|
+
const a = Number.parseInt(o, r);
|
|
1001
|
+
return n * a;
|
|
1002
|
+
};
|
|
1003
|
+
function ut(s) {
|
|
1004
|
+
const t = K(s);
|
|
1005
|
+
if (t === "") return { ok: !1, reason: "empty" };
|
|
1006
|
+
const e = L(t);
|
|
1007
|
+
if (e !== null)
|
|
1008
|
+
return Number.isFinite(e) ? { ok: !0, value: e } : { ok: !1, reason: "invalid" };
|
|
1009
|
+
const n = Number(t);
|
|
1010
|
+
return Number.isFinite(n) ? { ok: !0, value: n } : { ok: !1, reason: Number.isNaN(n) ? "invalid" : "non-finite" };
|
|
1011
|
+
}
|
|
1012
|
+
function ft(s, t) {
|
|
1013
|
+
return Number.isFinite(s) ? t === "number" ? { ok: !0, value: s } : Number.isSafeInteger(s) ? t === "uint" && s < 0 ? { ok: !1, reason: "out-of-range" } : { ok: !0, value: s } : { ok: !1, reason: "not-integer" } : { ok: !1, reason: "non-finite" };
|
|
1014
|
+
}
|
|
1015
|
+
function dt(s, t) {
|
|
1016
|
+
const e = s < 0 ? "-" : "", n = Math.abs(s), i = t === "binary" ? n.toString(2) : t === "octal" ? n.toString(8) : n.toString(16);
|
|
1017
|
+
return `${e}${t === "binary" ? "0b" : t === "octal" ? "0o" : "0x"}${i}`;
|
|
1018
|
+
}
|
|
1019
|
+
function ht(s, t) {
|
|
1020
|
+
if (!Number.isFinite(s)) return "";
|
|
1021
|
+
if ((t?.format ?? "decimal") === "scientific") {
|
|
1022
|
+
const i = t?.precision;
|
|
1023
|
+
return i !== void 0 && Number.isFinite(i) && i > 0 ? s.toExponential(Math.max(0, Math.floor(i) - 1)) : s.toExponential();
|
|
1024
|
+
}
|
|
1025
|
+
const n = t?.scale;
|
|
1026
|
+
if (n !== void 0 && Number.isFinite(n)) {
|
|
1027
|
+
const i = Math.max(0, Math.floor(n));
|
|
1028
|
+
return s.toFixed(i);
|
|
1029
|
+
}
|
|
1030
|
+
return String(s);
|
|
1031
|
+
}
|
|
1032
|
+
export {
|
|
1033
|
+
tt as C,
|
|
1034
|
+
J as D,
|
|
1035
|
+
z as H,
|
|
1036
|
+
Z as R,
|
|
1037
|
+
rt as a,
|
|
1038
|
+
at as b,
|
|
1039
|
+
_ as c,
|
|
1040
|
+
lt as d,
|
|
1041
|
+
ct as e,
|
|
1042
|
+
et as f,
|
|
1043
|
+
nt as g,
|
|
1044
|
+
ht as h,
|
|
1045
|
+
dt as i,
|
|
1046
|
+
k as j,
|
|
1047
|
+
W as k,
|
|
1048
|
+
Q as l,
|
|
1049
|
+
V as m,
|
|
1050
|
+
Y as n,
|
|
1051
|
+
ut as o,
|
|
1052
|
+
F as p,
|
|
1053
|
+
ft as q,
|
|
1054
|
+
U as r,
|
|
1055
|
+
ot as s,
|
|
1056
|
+
G as t,
|
|
1057
|
+
K as u,
|
|
1058
|
+
it as v,
|
|
1059
|
+
X as w,
|
|
1060
|
+
q as x,
|
|
1061
|
+
st as y
|
|
1062
|
+
};
|
|
1063
|
+
//# sourceMappingURL=numberIO-DBddtK0s.js.map
|