@nouxwell/tabula-core 0.4.0 → 0.5.0
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/columns.d.ts +15 -1
- package/dist/index.d.ts +6 -6
- package/dist/index.js +1132 -936
- package/dist/index.js.map +1 -1
- package/dist/table.d.ts +102 -2
- package/dist/templates.d.ts +6 -1
- package/dist/validation.d.ts +7 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -340,7 +340,7 @@ var Ie = /* @__PURE__ */ new Set([
|
|
|
340
340
|
"hayir",
|
|
341
341
|
"h"
|
|
342
342
|
]);
|
|
343
|
-
function
|
|
343
|
+
function g(e, t, n) {
|
|
344
344
|
let r = l(t);
|
|
345
345
|
if (r === "") return {
|
|
346
346
|
value: null,
|
|
@@ -351,33 +351,33 @@ function Re(e, t, n) {
|
|
|
351
351
|
value: r,
|
|
352
352
|
problem: null
|
|
353
353
|
};
|
|
354
|
-
case "lookup": return
|
|
354
|
+
case "lookup": return x(e, r, "not_matched");
|
|
355
355
|
case "integer": {
|
|
356
356
|
let i = te(t, n);
|
|
357
|
-
return i === null ?
|
|
357
|
+
return i === null ? x(e, r, "not_a_number") : ee(i) && !h(i) ? {
|
|
358
358
|
value: i,
|
|
359
359
|
problem: null
|
|
360
|
-
} :
|
|
360
|
+
} : x(e, r, "not_an_integer");
|
|
361
361
|
}
|
|
362
362
|
case "decimal":
|
|
363
|
-
case "quantity": return
|
|
364
|
-
case "money": return
|
|
365
|
-
case "percent": return
|
|
366
|
-
case "bool": return
|
|
363
|
+
case "quantity": return Be(e, r, te(t, n));
|
|
364
|
+
case "money": return Be(e, r, ne(t, e.currency, n));
|
|
365
|
+
case "percent": return Be(e, r, re(t, n));
|
|
366
|
+
case "bool": return Ve(e, r, n);
|
|
367
367
|
case "date":
|
|
368
|
-
case "datetime": return
|
|
369
|
-
case "options": return
|
|
368
|
+
case "datetime": return He(e, r, n);
|
|
369
|
+
case "options": return We(e, r);
|
|
370
370
|
}
|
|
371
371
|
}
|
|
372
|
-
function
|
|
373
|
-
return t === null ||
|
|
372
|
+
function Re(e, t, n) {
|
|
373
|
+
return t === null || v(e, t) ? null : g(e, y(t), n).problem;
|
|
374
374
|
}
|
|
375
|
-
function
|
|
376
|
-
if (t === null ||
|
|
377
|
-
let r =
|
|
375
|
+
function _(e, t, n) {
|
|
376
|
+
if (t === null || v(e, t)) return t;
|
|
377
|
+
let r = y(t), i = g(e, r, n);
|
|
378
378
|
return i.problem === null ? i.value : i.problem.code === "not_an_integer" ? te(r, n) ?? t : t;
|
|
379
379
|
}
|
|
380
|
-
function
|
|
380
|
+
function v(e, t) {
|
|
381
381
|
switch (e.type) {
|
|
382
382
|
case "string": return typeof t == "string";
|
|
383
383
|
case "integer": return typeof t == "number" && Number.isSafeInteger(t) || typeof t == "string" && ee(t) && !h(t);
|
|
@@ -388,11 +388,11 @@ function _(e, t) {
|
|
|
388
388
|
case "bool": return typeof t == "boolean";
|
|
389
389
|
case "date": return De(t, !1);
|
|
390
390
|
case "datetime": return De(t, !0);
|
|
391
|
-
case "options": return e.multiple ? Array.isArray(t) && t.every((t) =>
|
|
392
|
-
case "lookup": return
|
|
391
|
+
case "options": return e.multiple ? Array.isArray(t) && t.every((t) => ze(e, t)) : ze(e, t);
|
|
392
|
+
case "lookup": return b(t);
|
|
393
393
|
}
|
|
394
394
|
}
|
|
395
|
-
function
|
|
395
|
+
function y(e) {
|
|
396
396
|
if (e === null) return "";
|
|
397
397
|
switch (typeof e) {
|
|
398
398
|
case "string": return e;
|
|
@@ -401,21 +401,21 @@ function v(e) {
|
|
|
401
401
|
}
|
|
402
402
|
return JSON.stringify(e);
|
|
403
403
|
}
|
|
404
|
-
function
|
|
404
|
+
function b(e) {
|
|
405
405
|
if (typeof e != "object" || !e || Array.isArray(e)) return !1;
|
|
406
406
|
let t = e;
|
|
407
407
|
return (typeof t.id == "string" || typeof t.id == "number") && typeof t.label == "string";
|
|
408
408
|
}
|
|
409
|
-
function
|
|
409
|
+
function ze(e, t) {
|
|
410
410
|
return e.options.some((e) => e.value === t);
|
|
411
411
|
}
|
|
412
|
-
function
|
|
413
|
-
return n === null ?
|
|
412
|
+
function Be(e, t, n) {
|
|
413
|
+
return n === null ? x(e, t, "not_a_number") : {
|
|
414
414
|
value: n,
|
|
415
415
|
problem: null
|
|
416
416
|
};
|
|
417
417
|
}
|
|
418
|
-
function
|
|
418
|
+
function Ve(e, t, n) {
|
|
419
419
|
let r = u(t);
|
|
420
420
|
return r === u(n.trueWord) ? {
|
|
421
421
|
value: !0,
|
|
@@ -429,7 +429,7 @@ function He(e, t, n) {
|
|
|
429
429
|
} : Le.has(r) ? {
|
|
430
430
|
value: !1,
|
|
431
431
|
problem: null
|
|
432
|
-
} :
|
|
432
|
+
} : x(e, t, "not_a_boolean", { accepted: Ke([
|
|
433
433
|
n.trueWord,
|
|
434
434
|
n.falseWord,
|
|
435
435
|
"Evet",
|
|
@@ -440,21 +440,21 @@ function He(e, t, n) {
|
|
|
440
440
|
"false"
|
|
441
441
|
]).join(", ") });
|
|
442
442
|
}
|
|
443
|
-
function
|
|
444
|
-
let r = e.type === "datetime", i =
|
|
445
|
-
return a === null ?
|
|
443
|
+
function He(e, t, n) {
|
|
444
|
+
let r = e.type === "datetime", i = Ue(e, n), a = Ee(t, r, i, r ? n.datePattern : n.dateTimePattern);
|
|
445
|
+
return a === null ? x(e, t, "not_a_date", { format: i }) : {
|
|
446
446
|
value: a,
|
|
447
447
|
problem: null
|
|
448
448
|
};
|
|
449
449
|
}
|
|
450
|
-
function
|
|
450
|
+
function Ue(e, t) {
|
|
451
451
|
return e.pattern ?? (e.type === "datetime" ? t.dateTimePattern : t.datePattern);
|
|
452
452
|
}
|
|
453
|
-
function
|
|
453
|
+
function We(e, t) {
|
|
454
454
|
let n = e.multiple ? t.split(",").map((e) => l(e)).filter((e) => e !== "") : [t], r = [];
|
|
455
455
|
for (let i of n) {
|
|
456
456
|
let n = u(i), a = e.options.find((e) => u(e.label) === n) ?? e.options.find((e) => u(String(e.value)) === n);
|
|
457
|
-
if (!a) return
|
|
457
|
+
if (!a) return x(e, t, "not_an_option", { options: Ke(e.options.map((e) => e.label)).join(", ") });
|
|
458
458
|
r.push(a.value);
|
|
459
459
|
}
|
|
460
460
|
return {
|
|
@@ -462,7 +462,7 @@ function Ge(e, t) {
|
|
|
462
462
|
problem: null
|
|
463
463
|
};
|
|
464
464
|
}
|
|
465
|
-
function
|
|
465
|
+
function x(e, t, n, r = {}) {
|
|
466
466
|
let i = Object.freeze({
|
|
467
467
|
field: e.key,
|
|
468
468
|
type: e.type,
|
|
@@ -473,12 +473,12 @@ function b(e, t, n, r = {}) {
|
|
|
473
473
|
value: t,
|
|
474
474
|
problem: Object.freeze({
|
|
475
475
|
code: n,
|
|
476
|
-
message:
|
|
476
|
+
message: Ge(n, i),
|
|
477
477
|
params: i
|
|
478
478
|
})
|
|
479
479
|
};
|
|
480
480
|
}
|
|
481
|
-
function
|
|
481
|
+
function Ge(e, t) {
|
|
482
482
|
let n = t.value ?? "";
|
|
483
483
|
switch (e) {
|
|
484
484
|
case "not_a_number": return `"${n}" could not be read as a number.`;
|
|
@@ -489,7 +489,7 @@ function Ke(e, t) {
|
|
|
489
489
|
case "not_matched": return `"${n}" is not matched to a record; pick one from the list.`;
|
|
490
490
|
}
|
|
491
491
|
}
|
|
492
|
-
function
|
|
492
|
+
function Ke(e) {
|
|
493
493
|
let t = /* @__PURE__ */ new Map();
|
|
494
494
|
for (let n of e) {
|
|
495
495
|
let e = u(n);
|
|
@@ -498,80 +498,80 @@ function qe(e) {
|
|
|
498
498
|
return [...t.values()];
|
|
499
499
|
}
|
|
500
500
|
// src/checks.ts
|
|
501
|
-
var
|
|
501
|
+
var qe = Object.freeze([
|
|
502
502
|
"=",
|
|
503
503
|
"!=",
|
|
504
504
|
"<",
|
|
505
505
|
"<=",
|
|
506
506
|
">",
|
|
507
507
|
">="
|
|
508
|
-
]),
|
|
509
|
-
...
|
|
508
|
+
]), Je = Object.freeze([
|
|
509
|
+
...qe,
|
|
510
510
|
"filled",
|
|
511
511
|
"empty"
|
|
512
|
-
]),
|
|
512
|
+
]), Ye = /* @__PURE__ */ new Set([
|
|
513
513
|
"integer",
|
|
514
514
|
"decimal",
|
|
515
515
|
"money",
|
|
516
516
|
"quantity",
|
|
517
517
|
"percent"
|
|
518
|
-
]),
|
|
519
|
-
...
|
|
518
|
+
]), Xe = /* @__PURE__ */ new Set([
|
|
519
|
+
...Ye,
|
|
520
520
|
"date",
|
|
521
521
|
"datetime"
|
|
522
|
-
]),
|
|
522
|
+
]), Ze = [
|
|
523
523
|
"id",
|
|
524
524
|
"assert",
|
|
525
525
|
"when",
|
|
526
526
|
"severity",
|
|
527
527
|
"message"
|
|
528
|
-
],
|
|
528
|
+
], Qe = [
|
|
529
529
|
"field",
|
|
530
530
|
"op",
|
|
531
531
|
"value",
|
|
532
532
|
"other"
|
|
533
533
|
];
|
|
534
|
-
function
|
|
534
|
+
function $e(e, t, n) {
|
|
535
535
|
if (e == null) return [];
|
|
536
536
|
if (!Array.isArray(e)) return n("checks", "must be an array of checks"), [];
|
|
537
537
|
let r = new Map(t.map((e) => [e.key, e])), i = /* @__PURE__ */ new Map(), a = [];
|
|
538
538
|
return e.forEach((e, t) => {
|
|
539
|
-
let o = `checks[${t}]`, s =
|
|
539
|
+
let o = `checks[${t}]`, s = lt(e, o, r, n);
|
|
540
540
|
if (!s) return;
|
|
541
541
|
let c = i.get(s.id);
|
|
542
542
|
c === void 0 ? (i.set(s.id, t), a.push(s)) : n(`${o}.id`, `"${s.id}" is already the id of checks[${c}]; an id names one check only`);
|
|
543
543
|
}), a;
|
|
544
544
|
}
|
|
545
|
-
function
|
|
545
|
+
function et(e) {
|
|
546
546
|
let t = {
|
|
547
547
|
id: e.id,
|
|
548
|
-
assert:
|
|
548
|
+
assert: pt(e.assert)
|
|
549
549
|
};
|
|
550
|
-
return e.when.length > 0 && (t.when = e.when.map(
|
|
550
|
+
return e.when.length > 0 && (t.when = e.when.map(pt)), t.severity = e.severity, e.message !== null && (t.message = { ...e.message }), t;
|
|
551
551
|
}
|
|
552
|
-
function
|
|
552
|
+
function tt(e) {
|
|
553
553
|
let t = /* @__PURE__ */ new Set();
|
|
554
554
|
for (let n of [e.assert, ...e.when]) t.add(n.field), n.other !== null && t.add(n.other);
|
|
555
555
|
return [...t];
|
|
556
556
|
}
|
|
557
|
+
function nt(e, t, n, r) {
|
|
558
|
+
for (let i of e.when) if (at(i, t, n, r) !== !0) return !1;
|
|
559
|
+
return at(e.assert, t, n, r) === !1;
|
|
560
|
+
}
|
|
557
561
|
function rt(e, t, n, r) {
|
|
558
|
-
|
|
559
|
-
return
|
|
562
|
+
let i = (t) => e.field(t);
|
|
563
|
+
return t.rowIds().filter((e) => nt(n, i, (n) => t.get(e, n), r));
|
|
560
564
|
}
|
|
561
565
|
function it(e, t, n, r) {
|
|
562
|
-
|
|
563
|
-
return t.rowIds().filter((e) => rt(n, i, (n) => t.get(e, n), r));
|
|
566
|
+
return at(e, t, n, r) === !0;
|
|
564
567
|
}
|
|
565
568
|
function at(e, t, n, r) {
|
|
566
|
-
return ot(e, t, n, r) === !0;
|
|
567
|
-
}
|
|
568
|
-
function ot(e, t, n, r) {
|
|
569
569
|
let i = t(e.field), a = n(e.field);
|
|
570
570
|
if (e.op === "filled") return a !== null;
|
|
571
571
|
if (e.op === "empty") return a === null;
|
|
572
|
-
let o =
|
|
572
|
+
let o = ot(i, a, r), s = e.other === null ? e.value : ot(t(e.other), n(e.other), r);
|
|
573
573
|
if (o === null || s === null) return null;
|
|
574
|
-
let c =
|
|
574
|
+
let c = st(i, o, s);
|
|
575
575
|
switch (e.op) {
|
|
576
576
|
case "=": return c === 0;
|
|
577
577
|
case "!=": return c !== 0;
|
|
@@ -581,35 +581,35 @@ function ot(e, t, n, r) {
|
|
|
581
581
|
case ">=": return c >= 0;
|
|
582
582
|
}
|
|
583
583
|
}
|
|
584
|
-
function
|
|
585
|
-
return t === null ||
|
|
584
|
+
function ot(e, t, n) {
|
|
585
|
+
return t === null || Re(e, t, n) !== null ? null : _(e, t, n);
|
|
586
586
|
}
|
|
587
|
-
function
|
|
588
|
-
if (
|
|
587
|
+
function st(e, t, n) {
|
|
588
|
+
if (Ye.has(e.type)) {
|
|
589
589
|
let e = r(m(t) ?? ""), a = r(m(n) ?? "");
|
|
590
590
|
return e === null || a === null ? 1 : i(e, a);
|
|
591
591
|
}
|
|
592
|
-
return e.type === "date" || e.type === "datetime" ? String(t) < String(n) ? -1 : +(String(t) > String(n)) : +!
|
|
592
|
+
return e.type === "date" || e.type === "datetime" ? String(t) < String(n) ? -1 : +(String(t) > String(n)) : +!ct(t, n);
|
|
593
593
|
}
|
|
594
|
-
function
|
|
595
|
-
return
|
|
594
|
+
function ct(e, t) {
|
|
595
|
+
return b(e) && b(t) ? String(e.id) === String(t.id) : Array.isArray(e) && Array.isArray(t) ? JSON.stringify([...e].map(String).sort()) === JSON.stringify([...t].map(String).sort()) : e === t || typeof e != "object" && typeof t != "object" && String(e) === String(t);
|
|
596
596
|
}
|
|
597
|
-
function
|
|
598
|
-
if (!
|
|
597
|
+
function lt(e, t, n, r) {
|
|
598
|
+
if (!mt(e)) return r(t, "must be an object such as { \"id\": \"…\", \"assert\": { \"field\": \"…\", \"op\": \"filled\" } }"), null;
|
|
599
599
|
let i = !1, a = (e, t) => {
|
|
600
600
|
i = !0, r(e, t);
|
|
601
601
|
};
|
|
602
|
-
for (let n of Object.keys(e))
|
|
602
|
+
for (let n of Object.keys(e)) Ze.includes(n) || a(`${t}.${n}`, `is not a check property; a check takes ${Ze.join(", ")}`);
|
|
603
603
|
let o = typeof e.id == "string" && e.id.trim() !== "" ? e.id : null;
|
|
604
604
|
o === null && a(`${t}.id`, "must be a non-empty string");
|
|
605
|
-
let s =
|
|
605
|
+
let s = ut(e.assert, `${t}.assert`, n, a), c = [];
|
|
606
606
|
e.when !== void 0 && e.when !== null && (Array.isArray(e.when) ? e.when.forEach((e, r) => {
|
|
607
|
-
let i =
|
|
607
|
+
let i = ut(e, `${t}.when[${r}]`, n, a);
|
|
608
608
|
i && c.push(i);
|
|
609
609
|
}) : a(`${t}.when`, "must be an array of conditions, every one of which must hold"));
|
|
610
610
|
let l = e.severity === void 0 || e.severity === null ? "error" : e.severity;
|
|
611
611
|
l !== "error" && l !== "warning" && a(`${t}.severity`, `must be "error" or "warning"; got ${JSON.stringify(l)}`);
|
|
612
|
-
let u =
|
|
612
|
+
let u = ft(e.message, `${t}.message`, a);
|
|
613
613
|
return i || o === null || s === null ? null : Object.freeze({
|
|
614
614
|
id: o,
|
|
615
615
|
assert: s,
|
|
@@ -618,16 +618,16 @@ function ut(e, t, n, r) {
|
|
|
618
618
|
message: u
|
|
619
619
|
});
|
|
620
620
|
}
|
|
621
|
-
function
|
|
622
|
-
if (!
|
|
621
|
+
function ut(e, t, n, r) {
|
|
622
|
+
if (!mt(e)) return r(t, "must be an object such as { \"field\": \"active\", \"op\": \"=\", \"value\": false }"), null;
|
|
623
623
|
let i = { failed: !1 }, a = (e, t) => {
|
|
624
624
|
i.failed = !0, r(e, t);
|
|
625
625
|
};
|
|
626
|
-
for (let n of Object.keys(e))
|
|
626
|
+
for (let n of Object.keys(e)) Qe.includes(n) || a(`${t}.${n}`, `is not a condition property; a condition takes ${Qe.join(", ")}`);
|
|
627
627
|
let o = typeof e.field == "string" ? n.get(e.field) : void 0;
|
|
628
628
|
o || a(`${t}.field`, `${JSON.stringify(e.field)} is not a field of this schema`);
|
|
629
629
|
let s = e.op;
|
|
630
|
-
if (!
|
|
630
|
+
if (!Je.includes(s)) return a(`${t}.op`, `${JSON.stringify(e.op)} is not a condition; expected one of ${Je.join(", ")}`), null;
|
|
631
631
|
let c = e.value !== void 0 && e.value !== null, l = e.other !== void 0 && e.other !== null;
|
|
632
632
|
if (s === "filled" || s === "empty") return (c || l) && a(t, `${s} takes no value and no other field`), i.failed || !o ? null : Object.freeze({
|
|
633
633
|
field: o.key,
|
|
@@ -636,14 +636,14 @@ function dt(e, t, n, r) {
|
|
|
636
636
|
other: null
|
|
637
637
|
});
|
|
638
638
|
if (c === l) return a(t, `${s} compares with a value or with another field: give one of value and other`), null;
|
|
639
|
-
o && (s === "<" || s === "<=" || s === ">" || s === ">=") && !
|
|
639
|
+
o && (s === "<" || s === "<=" || s === ">" || s === ">=") && !Xe.has(o.type) && a(`${t}.op`, `${s} needs an order; a ${o.type} field only takes = and !=`);
|
|
640
640
|
let u = null, d = null;
|
|
641
641
|
if (l) {
|
|
642
642
|
let r = typeof e.other == "string" ? n.get(e.other) : void 0;
|
|
643
|
-
r ? o && !
|
|
643
|
+
r ? o && !dt(o.type, r.type) ? a(`${t}.other`, `a ${o.type} field cannot be compared with a ${r.type} field`) : o && r.key === o.key ? a(`${t}.other`, "is the field itself") : u = r.key : a(`${t}.other`, `${JSON.stringify(e.other)} is not a field of this schema`);
|
|
644
644
|
} else if (o) {
|
|
645
|
-
let n =
|
|
646
|
-
o.type === "lookup" || !
|
|
645
|
+
let n = Ye.has(o.type) ? m(e.value) ?? e.value : e.value;
|
|
646
|
+
o.type === "lookup" || !v(o, n) ? a(`${t}.value`, `${JSON.stringify(e.value)} is not a value of the ${o.type} field "${o.key}"`) : d = Array.isArray(n) ? Object.freeze([...n]) : n;
|
|
647
647
|
}
|
|
648
648
|
return i.failed || !o ? null : Object.freeze({
|
|
649
649
|
field: o.key,
|
|
@@ -652,27 +652,27 @@ function dt(e, t, n, r) {
|
|
|
652
652
|
other: u
|
|
653
653
|
});
|
|
654
654
|
}
|
|
655
|
-
function
|
|
656
|
-
return
|
|
655
|
+
function dt(e, t) {
|
|
656
|
+
return Ye.has(e) && Ye.has(t) || e === t;
|
|
657
657
|
}
|
|
658
|
-
function
|
|
658
|
+
function ft(e, t, n) {
|
|
659
659
|
if (e == null) return null;
|
|
660
|
-
if (!
|
|
660
|
+
if (!mt(e) || Object.keys(e).length === 0) return n(t, "must be an object of words by language, such as { \"tr\": \"…\", \"en\": \"…\" }"), null;
|
|
661
661
|
for (let [r, i] of Object.entries(e)) (typeof i != "string" || i.trim() === "") && n(`${t}.${r}`, "must be a non-empty string");
|
|
662
662
|
return Object.freeze({ ...e });
|
|
663
663
|
}
|
|
664
|
-
function
|
|
664
|
+
function pt(e) {
|
|
665
665
|
let t = {
|
|
666
666
|
field: e.field,
|
|
667
667
|
op: e.op
|
|
668
668
|
};
|
|
669
669
|
return e.other === null ? e.value !== null && (t.value = e.value) : t.other = e.other, t;
|
|
670
670
|
}
|
|
671
|
-
function
|
|
671
|
+
function mt(e) {
|
|
672
672
|
return typeof e == "object" && !!e && !Array.isArray(e);
|
|
673
673
|
}
|
|
674
674
|
// src/listeners.ts
|
|
675
|
-
var
|
|
675
|
+
var S = class {
|
|
676
676
|
#e = /* @__PURE__ */ new Set();
|
|
677
677
|
add(e) {
|
|
678
678
|
let t = (t) => e(t);
|
|
@@ -684,16 +684,16 @@ var x = class {
|
|
|
684
684
|
for (let t of [...this.#e]) if (this.#e.has(t)) try {
|
|
685
685
|
t(e);
|
|
686
686
|
} catch (e) {
|
|
687
|
-
|
|
687
|
+
ht(e);
|
|
688
688
|
}
|
|
689
689
|
}
|
|
690
690
|
};
|
|
691
|
-
function
|
|
691
|
+
function ht(e) {
|
|
692
692
|
let t = globalThis;
|
|
693
693
|
typeof t.reportError == "function" ? t.reportError(e) : Promise.reject(e);
|
|
694
694
|
}
|
|
695
695
|
// src/marks.ts
|
|
696
|
-
var
|
|
696
|
+
var C = Object.freeze([
|
|
697
697
|
"yellow",
|
|
698
698
|
"green",
|
|
699
699
|
"blue",
|
|
@@ -702,14 +702,14 @@ var S = Object.freeze([
|
|
|
702
702
|
"orange",
|
|
703
703
|
"grey",
|
|
704
704
|
"red"
|
|
705
|
-
]),
|
|
705
|
+
]), gt = class {
|
|
706
706
|
#e = /* @__PURE__ */ new Map();
|
|
707
707
|
#t;
|
|
708
|
-
#n = new
|
|
708
|
+
#n = new S();
|
|
709
709
|
#r = 0;
|
|
710
710
|
constructor(e = {}) {
|
|
711
711
|
this.#t = e.history ?? null;
|
|
712
|
-
for (let [t, n] of Object.entries(e.marks ?? {})) for (let [e, r] of Object.entries(n)) this.#o(t, e,
|
|
712
|
+
for (let [t, n] of Object.entries(e.marks ?? {})) for (let [e, r] of Object.entries(n)) this.#o(t, e, bt(r));
|
|
713
713
|
}
|
|
714
714
|
get version() {
|
|
715
715
|
return this.#r;
|
|
@@ -729,7 +729,7 @@ var S = Object.freeze([
|
|
|
729
729
|
return [...this.#e.keys()];
|
|
730
730
|
}
|
|
731
731
|
mark(e, t) {
|
|
732
|
-
|
|
732
|
+
yt(t), this.#i(e, (e) => {
|
|
733
733
|
let n = { ...e };
|
|
734
734
|
for (let e of ["fill", "color"]) t[e] === null ? delete n[e] : t[e] !== void 0 && (n[e] = t[e]);
|
|
735
735
|
for (let e of ["bold", "italic"]) t[e] === !1 ? delete n[e] : t[e] === !0 && (n[e] = !0);
|
|
@@ -754,8 +754,8 @@ var S = Object.freeze([
|
|
|
754
754
|
#i(e, t) {
|
|
755
755
|
let n = [], r = [];
|
|
756
756
|
for (let i of e) {
|
|
757
|
-
let e = this.get(i.rowId, i.field), a =
|
|
758
|
-
|
|
757
|
+
let e = this.get(i.rowId, i.field), a = bt(t(e ?? {})), o = Object.keys(a).length === 0 ? null : a;
|
|
758
|
+
xt(e, o) || (n.push([i, e]), r.push([i, o]));
|
|
759
759
|
}
|
|
760
760
|
r.length !== 0 && (this.#a(r), this.#t?.record({
|
|
761
761
|
undo: () => this.#a(n),
|
|
@@ -771,25 +771,25 @@ var S = Object.freeze([
|
|
|
771
771
|
n === null || Object.keys(n).length === 0 ? (r?.delete(t), r?.size === 0 && this.#e.delete(e)) : r ? r.set(t, n) : this.#e.set(e, /* @__PURE__ */ new Map([[t, n]]));
|
|
772
772
|
}
|
|
773
773
|
};
|
|
774
|
-
function
|
|
774
|
+
function _t(e) {
|
|
775
775
|
return (t) => e.hasRow(t);
|
|
776
776
|
}
|
|
777
|
-
function
|
|
777
|
+
function vt(e, t, n) {
|
|
778
778
|
if (e == null) return {};
|
|
779
|
-
let r =
|
|
779
|
+
let r = St(e);
|
|
780
780
|
if (!r) return n(t, "must be an object of marks by row id, then field key."), {};
|
|
781
781
|
let i = {};
|
|
782
782
|
for (let [e, a] of Object.entries(r)) {
|
|
783
|
-
let r =
|
|
783
|
+
let r = St(a);
|
|
784
784
|
if (!r) n(`${t}.${e}`, "must be an object of marks by field key.");
|
|
785
785
|
else for (let [a, o] of Object.entries(r)) {
|
|
786
|
-
let r =
|
|
786
|
+
let r = St(o), s = `${t}.${e}.${a}`;
|
|
787
787
|
if (!r) {
|
|
788
788
|
n(s, "must be an object such as { fill: \"yellow\", bold: true }.");
|
|
789
789
|
continue;
|
|
790
790
|
}
|
|
791
791
|
let c = {};
|
|
792
|
-
for (let e of ["fill", "color"]) r[e] !== void 0 && (
|
|
792
|
+
for (let e of ["fill", "color"]) r[e] !== void 0 && (C.includes(r[e]) ? c[e] = r[e] : n(`${s}.${e}`, `must be one of ${C.join(", ")}.`));
|
|
793
793
|
for (let e of ["bold", "italic"]) r[e] === !0 ? c[e] = !0 : r[e] !== void 0 && r[e] !== !1 && n(`${s}.${e}`, "must be true or false.");
|
|
794
794
|
Object.keys(c).length > 0 && (i[e] = {
|
|
795
795
|
...i[e],
|
|
@@ -799,13 +799,13 @@ function yt(e, t, n) {
|
|
|
799
799
|
}
|
|
800
800
|
return i;
|
|
801
801
|
}
|
|
802
|
-
function
|
|
802
|
+
function yt(t) {
|
|
803
803
|
for (let n of ["fill", "color"]) {
|
|
804
804
|
let r = t[n];
|
|
805
|
-
if (r != null && !
|
|
805
|
+
if (r != null && !C.includes(r)) throw new e("invalid_argument", `A mark's ${n} is one of ${C.join(", ")}; got ${r}.`);
|
|
806
806
|
}
|
|
807
807
|
}
|
|
808
|
-
function
|
|
808
|
+
function bt(e) {
|
|
809
809
|
return Object.freeze({
|
|
810
810
|
...e.fill ? { fill: e.fill } : {},
|
|
811
811
|
...e.color ? { color: e.color } : {},
|
|
@@ -813,14 +813,14 @@ function xt(e) {
|
|
|
813
813
|
...e.italic ? { italic: !0 } : {}
|
|
814
814
|
});
|
|
815
815
|
}
|
|
816
|
-
function
|
|
816
|
+
function xt(e, t) {
|
|
817
817
|
return (e?.fill ?? null) === (t?.fill ?? null) && (e?.color ?? null) === (t?.color ?? null) && (e?.bold ?? !1) === (t?.bold ?? !1) && (e?.italic ?? !1) === (t?.italic ?? !1);
|
|
818
818
|
}
|
|
819
|
-
function
|
|
819
|
+
function St(e) {
|
|
820
820
|
return typeof e == "object" && e && !Array.isArray(e) ? e : null;
|
|
821
821
|
}
|
|
822
822
|
// src/styles.ts
|
|
823
|
-
var
|
|
823
|
+
var Ct = [
|
|
824
824
|
"id",
|
|
825
825
|
"when",
|
|
826
826
|
"field",
|
|
@@ -828,34 +828,34 @@ var wt = [
|
|
|
828
828
|
"color",
|
|
829
829
|
"bold"
|
|
830
830
|
];
|
|
831
|
-
function
|
|
831
|
+
function wt(e, t, n) {
|
|
832
832
|
if (e == null) return [];
|
|
833
833
|
if (!Array.isArray(e)) return n("styles", "must be an array of colour rules"), [];
|
|
834
834
|
let r = new Map(t.map((e) => [e.key, e])), i = /* @__PURE__ */ new Map(), a = [];
|
|
835
835
|
return e.forEach((e, t) => {
|
|
836
|
-
let o = `styles[${t}]`, s =
|
|
836
|
+
let o = `styles[${t}]`, s = kt(e, o, r, n);
|
|
837
837
|
if (s === null) return;
|
|
838
838
|
let c = i.get(s.id);
|
|
839
839
|
c === void 0 ? (i.set(s.id, t), a.push(s)) : n(`${o}.id`, `"${s.id}" is the id of styles[${c}] too`);
|
|
840
840
|
}), a;
|
|
841
841
|
}
|
|
842
|
-
function
|
|
842
|
+
function Tt(e) {
|
|
843
843
|
return {
|
|
844
844
|
id: e.id,
|
|
845
|
-
when: e.when.map(
|
|
845
|
+
when: e.when.map(pt),
|
|
846
846
|
...e.field === null ? {} : { field: e.field },
|
|
847
847
|
...e.fill === null ? {} : { fill: e.fill },
|
|
848
848
|
...e.color === null ? {} : { color: e.color },
|
|
849
849
|
...e.bold ? { bold: !0 } : {}
|
|
850
850
|
};
|
|
851
851
|
}
|
|
852
|
-
function
|
|
853
|
-
return e.when.every((e) =>
|
|
852
|
+
function Et(e, t, n, r) {
|
|
853
|
+
return e.when.every((e) => it(e, t, n, r));
|
|
854
854
|
}
|
|
855
|
-
function
|
|
855
|
+
function Dt(e, t, n, r) {
|
|
856
856
|
let i = /* @__PURE__ */ new Map();
|
|
857
857
|
for (let a of e) {
|
|
858
|
-
if (!
|
|
858
|
+
if (!Et(a, t, n, r)) continue;
|
|
859
859
|
let e = i.get(a.field);
|
|
860
860
|
i.set(a.field, {
|
|
861
861
|
fill: a.fill ?? e?.fill ?? null,
|
|
@@ -865,28 +865,28 @@ function Ot(e, t, n, r) {
|
|
|
865
865
|
}
|
|
866
866
|
return i;
|
|
867
867
|
}
|
|
868
|
-
function
|
|
868
|
+
function Ot(e, t, n, r) {
|
|
869
869
|
let i = (t) => e.field(t);
|
|
870
|
-
return t.rowIds().filter((e) =>
|
|
870
|
+
return t.rowIds().filter((e) => Et(n, i, (n) => t.get(e, n), r));
|
|
871
871
|
}
|
|
872
|
-
function
|
|
873
|
-
if (!
|
|
872
|
+
function kt(e, t, n, r) {
|
|
873
|
+
if (!At(e)) return r(t, "must be an object such as { \"id\": \"…\", \"when\": [{ \"field\": \"…\", \"op\": \"<\", \"value\": 100 }], \"fill\": \"orange\" }"), null;
|
|
874
874
|
let i = !1, a = (e, t) => {
|
|
875
875
|
i = !0, r(e, t);
|
|
876
876
|
};
|
|
877
|
-
for (let n of Object.keys(e))
|
|
877
|
+
for (let n of Object.keys(e)) Ct.includes(n) || a(`${t}.${n}`, `is not a colour rule property; a rule takes ${Ct.join(", ")}`);
|
|
878
878
|
let o = typeof e.id == "string" && e.id.trim() !== "" ? e.id : null;
|
|
879
879
|
o === null && a(`${t}.id`, "must be a non-empty string");
|
|
880
880
|
let s = [];
|
|
881
881
|
!Array.isArray(e.when) || e.when.length === 0 ? a(`${t}.when`, "must be an array of one condition or more, every one of which must hold") : e.when.forEach((e, r) => {
|
|
882
|
-
let i =
|
|
882
|
+
let i = ut(e, `${t}.when[${r}]`, n, a);
|
|
883
883
|
i && s.push(i);
|
|
884
884
|
});
|
|
885
885
|
let c = null;
|
|
886
886
|
e.field !== void 0 && e.field !== null && (typeof e.field == "string" && n.has(e.field) ? c = e.field : a(`${t}.field`, `${JSON.stringify(e.field)} is not a field of this schema`));
|
|
887
887
|
let l = (n) => {
|
|
888
888
|
let r = e[n];
|
|
889
|
-
return r == null ? null :
|
|
889
|
+
return r == null ? null : C.includes(r) ? r : (a(`${t}.${n}`, `must be one of ${C.join(", ")}`), null);
|
|
890
890
|
}, u = l("fill"), d = l("color");
|
|
891
891
|
e.bold !== void 0 && typeof e.bold != "boolean" && a(`${t}.bold`, "must be true or false");
|
|
892
892
|
let f = e.bold === !0;
|
|
@@ -899,11 +899,11 @@ function At(e, t, n, r) {
|
|
|
899
899
|
bold: f
|
|
900
900
|
});
|
|
901
901
|
}
|
|
902
|
-
function
|
|
902
|
+
function At(e) {
|
|
903
903
|
return typeof e == "object" && !!e && !Array.isArray(e);
|
|
904
904
|
}
|
|
905
905
|
// src/formula/parse.ts
|
|
906
|
-
var
|
|
906
|
+
var jt = [
|
|
907
907
|
[
|
|
908
908
|
"=",
|
|
909
909
|
"<>",
|
|
@@ -917,13 +917,13 @@ var Mt = [
|
|
|
917
917
|
["*", "/"],
|
|
918
918
|
["^"]
|
|
919
919
|
];
|
|
920
|
-
function
|
|
921
|
-
let n =
|
|
920
|
+
function Mt(t) {
|
|
921
|
+
let n = It(t), r = 0, i = () => n[r], a = () => n[r++], o = (n, r) => {
|
|
922
922
|
throw new e("invalid_formula", `${r} at character ${n.at + 1} of "${t}".`);
|
|
923
923
|
}, s = (e) => {
|
|
924
|
-
if (e >=
|
|
924
|
+
if (e >= jt.length) return c();
|
|
925
925
|
let t = s(e + 1);
|
|
926
|
-
for (; i().kind === "op" &&
|
|
926
|
+
for (; i().kind === "op" && jt[e].includes(i().text);) {
|
|
927
927
|
let n = a().text;
|
|
928
928
|
t = Object.freeze({
|
|
929
929
|
kind: "binary",
|
|
@@ -997,7 +997,7 @@ function Nt(t) {
|
|
|
997
997
|
}, f = s(0);
|
|
998
998
|
return i().kind !== "end" && o(i(), `"${i().text}" is not expected here`), f;
|
|
999
999
|
}
|
|
1000
|
-
function
|
|
1000
|
+
function Nt(e) {
|
|
1001
1001
|
let t = /* @__PURE__ */ new Set(), n = (e) => {
|
|
1002
1002
|
switch (e.kind) {
|
|
1003
1003
|
case "field":
|
|
@@ -1015,12 +1015,12 @@ function Pt(e) {
|
|
|
1015
1015
|
};
|
|
1016
1016
|
return n(e), [...t];
|
|
1017
1017
|
}
|
|
1018
|
-
var
|
|
1018
|
+
var Pt = [
|
|
1019
1019
|
"<>",
|
|
1020
1020
|
"<=",
|
|
1021
1021
|
">="
|
|
1022
|
-
],
|
|
1023
|
-
function
|
|
1022
|
+
], Ft = "+-*/^&=<>(),;%";
|
|
1023
|
+
function It(t) {
|
|
1024
1024
|
let n = [], r = t.trimStart().startsWith("=") ? t.indexOf("=") + 1 : 0, i = (n, r) => {
|
|
1025
1025
|
throw new e("invalid_formula", `${r} at character ${n + 1} of "${t}".`);
|
|
1026
1026
|
};
|
|
@@ -1074,11 +1074,11 @@ function Lt(t) {
|
|
|
1074
1074
|
text: e[0],
|
|
1075
1075
|
at: a
|
|
1076
1076
|
});
|
|
1077
|
-
} else
|
|
1077
|
+
} else Pt.includes(t.slice(r, r + 2)) ? (n.push({
|
|
1078
1078
|
kind: "op",
|
|
1079
1079
|
text: t.slice(r, r + 2),
|
|
1080
1080
|
at: a
|
|
1081
|
-
}), r += 2) :
|
|
1081
|
+
}), r += 2) : Ft.includes(e) ? (n.push({
|
|
1082
1082
|
kind: "op",
|
|
1083
1083
|
text: e,
|
|
1084
1084
|
at: a
|
|
@@ -1091,7 +1091,7 @@ function Lt(t) {
|
|
|
1091
1091
|
}), n;
|
|
1092
1092
|
}
|
|
1093
1093
|
// src/schema.ts
|
|
1094
|
-
var
|
|
1094
|
+
var Lt = Object.freeze([
|
|
1095
1095
|
"string",
|
|
1096
1096
|
"integer",
|
|
1097
1097
|
"decimal",
|
|
@@ -1103,11 +1103,11 @@ var Rt = Object.freeze([
|
|
|
1103
1103
|
"datetime",
|
|
1104
1104
|
"options",
|
|
1105
1105
|
"lookup"
|
|
1106
|
-
]),
|
|
1106
|
+
]), Rt = Object.freeze([
|
|
1107
1107
|
"fixed",
|
|
1108
1108
|
"controlled",
|
|
1109
1109
|
"free"
|
|
1110
|
-
]),
|
|
1110
|
+
]), zt = [
|
|
1111
1111
|
"module",
|
|
1112
1112
|
"schemaVersion",
|
|
1113
1113
|
"title",
|
|
@@ -1115,7 +1115,7 @@ var Rt = Object.freeze([
|
|
|
1115
1115
|
"fields",
|
|
1116
1116
|
"checks",
|
|
1117
1117
|
"styles"
|
|
1118
|
-
],
|
|
1118
|
+
], Bt = [
|
|
1119
1119
|
"key",
|
|
1120
1120
|
"type",
|
|
1121
1121
|
"label",
|
|
@@ -1126,7 +1126,7 @@ var Rt = Object.freeze([
|
|
|
1126
1126
|
"example",
|
|
1127
1127
|
"formula",
|
|
1128
1128
|
"default"
|
|
1129
|
-
],
|
|
1129
|
+
], Vt = [
|
|
1130
1130
|
"string",
|
|
1131
1131
|
"integer",
|
|
1132
1132
|
"decimal",
|
|
@@ -1135,7 +1135,7 @@ var Rt = Object.freeze([
|
|
|
1135
1135
|
"money",
|
|
1136
1136
|
"bool",
|
|
1137
1137
|
"date"
|
|
1138
|
-
],
|
|
1138
|
+
], Ht = {
|
|
1139
1139
|
string: [],
|
|
1140
1140
|
integer: ["tone"],
|
|
1141
1141
|
decimal: ["decimals", "tone"],
|
|
@@ -1151,19 +1151,19 @@ var Rt = Object.freeze([
|
|
|
1151
1151
|
datetime: ["pattern"],
|
|
1152
1152
|
options: ["options", "multiple"],
|
|
1153
1153
|
lookup: ["lookup"]
|
|
1154
|
-
},
|
|
1154
|
+
}, Ut = new Set(Object.values(Ht).flat()), Wt = /* @__PURE__ */ new Set([
|
|
1155
1155
|
"integer",
|
|
1156
1156
|
"decimal",
|
|
1157
1157
|
"money",
|
|
1158
1158
|
"quantity",
|
|
1159
1159
|
"percent"
|
|
1160
|
-
]),
|
|
1160
|
+
]), Gt = [
|
|
1161
1161
|
"min",
|
|
1162
1162
|
"max",
|
|
1163
1163
|
"minLength",
|
|
1164
1164
|
"maxLength",
|
|
1165
1165
|
"unique"
|
|
1166
|
-
],
|
|
1166
|
+
], Kt = class n {
|
|
1167
1167
|
module;
|
|
1168
1168
|
schemaVersion;
|
|
1169
1169
|
title;
|
|
@@ -1176,8 +1176,8 @@ var Rt = Object.freeze([
|
|
|
1176
1176
|
this.module = e.module, this.schemaVersion = e.schemaVersion, this.title = e.title, this.customization = e.customization, this.fields = Object.freeze([...e.fields]), this.checks = Object.freeze([...e.checks]), this.styles = Object.freeze([...e.styles]), this.#e = new Map(e.fields.map((e) => [e.key, e])), Object.freeze(this);
|
|
1177
1177
|
}
|
|
1178
1178
|
static from(e) {
|
|
1179
|
-
let r = new
|
|
1180
|
-
if (i === null || r.items.length > 0) throw new t(
|
|
1179
|
+
let r = new Jt(), i = Yt(e, r);
|
|
1180
|
+
if (i === null || r.items.length > 0) throw new t(yn(e) && typeof e.module == "string" && e.module.trim() !== "" ? `Module schema "${e.module}"` : "The module schema", r.items);
|
|
1181
1181
|
return new n(i);
|
|
1182
1182
|
}
|
|
1183
1183
|
has(e) {
|
|
@@ -1196,12 +1196,12 @@ var Rt = Object.freeze([
|
|
|
1196
1196
|
module: this.module,
|
|
1197
1197
|
schemaVersion: this.schemaVersion,
|
|
1198
1198
|
customization: this.customization,
|
|
1199
|
-
fields: this.fields.map(
|
|
1199
|
+
fields: this.fields.map(qt)
|
|
1200
1200
|
};
|
|
1201
|
-
return this.title !== null && (e.title = this.title), this.checks.length > 0 && (e.checks = this.checks.map(
|
|
1201
|
+
return this.title !== null && (e.title = this.title), this.checks.length > 0 && (e.checks = this.checks.map(et)), this.styles.length > 0 && (e.styles = this.styles.map(Tt)), e;
|
|
1202
1202
|
}
|
|
1203
1203
|
};
|
|
1204
|
-
function
|
|
1204
|
+
function qt(e) {
|
|
1205
1205
|
let t = {
|
|
1206
1206
|
key: e.key,
|
|
1207
1207
|
type: e.type,
|
|
@@ -1233,7 +1233,7 @@ function Jt(e) {
|
|
|
1233
1233
|
}
|
|
1234
1234
|
return t;
|
|
1235
1235
|
}
|
|
1236
|
-
var
|
|
1236
|
+
var Jt = class {
|
|
1237
1237
|
items = [];
|
|
1238
1238
|
add(e, t) {
|
|
1239
1239
|
this.items.push(Object.freeze({
|
|
@@ -1242,10 +1242,10 @@ var Yt = class {
|
|
|
1242
1242
|
}));
|
|
1243
1243
|
}
|
|
1244
1244
|
};
|
|
1245
|
-
function
|
|
1246
|
-
if (!
|
|
1247
|
-
for (let n of Object.keys(e))
|
|
1248
|
-
let n =
|
|
1245
|
+
function Yt(e, t) {
|
|
1246
|
+
if (!yn(e)) return t.add("(root)", `must be an object; got ${E(e)}`), null;
|
|
1247
|
+
for (let n of Object.keys(e)) zt.includes(n) || t.add(n, `is not a module schema property; expected one of ${zt.join(", ")}`);
|
|
1248
|
+
let n = w(e, "module", "", t, !0), r = Xt(e, t), i = w(e, "title", "", t, !1), a = Zt(e, t), o = Qt(e.fields, t), s = o === null ? [] : $e(e.checks, o, (e, n) => t.add(e, n)), c = o === null ? [] : wt(e.styles, o, (e, n) => t.add(e, n));
|
|
1249
1249
|
return n === null || r === null || o === null ? null : {
|
|
1250
1250
|
module: n,
|
|
1251
1251
|
schemaVersion: r,
|
|
@@ -1256,36 +1256,36 @@ function Xt(e, t) {
|
|
|
1256
1256
|
styles: c
|
|
1257
1257
|
};
|
|
1258
1258
|
}
|
|
1259
|
-
function
|
|
1259
|
+
function Xt(e, t) {
|
|
1260
1260
|
let n = e.schemaVersion;
|
|
1261
|
-
return n == null ? (t.add("schemaVersion", "is required"), null) : typeof n != "number" || !Number.isSafeInteger(n) || n < 1 ? (t.add("schemaVersion", `must be a whole number, 1 or more; got ${
|
|
1261
|
+
return n == null ? (t.add("schemaVersion", "is required"), null) : typeof n != "number" || !Number.isSafeInteger(n) || n < 1 ? (t.add("schemaVersion", `must be a whole number, 1 or more; got ${E(n)}`), null) : n;
|
|
1262
1262
|
}
|
|
1263
|
-
function
|
|
1263
|
+
function Zt(e, t) {
|
|
1264
1264
|
let n = e.customization;
|
|
1265
|
-
return n == null ? "fixed" : typeof n != "string" || !
|
|
1265
|
+
return n == null ? "fixed" : typeof n != "string" || !Rt.includes(n) ? (t.add("customization", `${E(n)} is not a customization; expected one of ${Rt.join(", ")}`), "fixed") : n;
|
|
1266
1266
|
}
|
|
1267
|
-
function
|
|
1267
|
+
function Qt(e, t) {
|
|
1268
1268
|
if (e == null) return t.add("fields", "is required"), null;
|
|
1269
|
-
if (!Array.isArray(e) || e.length === 0) return t.add("fields", `must be a non-empty array of fields; got ${
|
|
1269
|
+
if (!Array.isArray(e) || e.length === 0) return t.add("fields", `must be a non-empty array of fields; got ${E(e)}`), null;
|
|
1270
1270
|
let n = e, r = /* @__PURE__ */ new Map();
|
|
1271
1271
|
n.forEach((e, n) => {
|
|
1272
|
-
if (!
|
|
1272
|
+
if (!yn(e) || typeof e.key != "string") return;
|
|
1273
1273
|
let i = r.get(e.key);
|
|
1274
1274
|
i === void 0 ? r.set(e.key, n) : t.add(`fields[${n}].key`, `"${e.key}" is already the key of fields[${i}]; a key names one field only`);
|
|
1275
1275
|
});
|
|
1276
1276
|
let i = [];
|
|
1277
1277
|
return n.forEach((e, n) => {
|
|
1278
|
-
let r =
|
|
1278
|
+
let r = en(e, `fields[${n}]`, t);
|
|
1279
1279
|
r && i.push(r);
|
|
1280
|
-
}),
|
|
1280
|
+
}), $t(i, r, t), i;
|
|
1281
1281
|
}
|
|
1282
|
-
function
|
|
1282
|
+
function $t(e, t, n) {
|
|
1283
1283
|
let r = new Set(e.map((e) => e.key)), i = /* @__PURE__ */ new Map();
|
|
1284
1284
|
for (let a of e) {
|
|
1285
1285
|
if (a.formula === null) continue;
|
|
1286
1286
|
let e = `fields[${t.get(a.key) ?? 0}].formula`, o;
|
|
1287
1287
|
try {
|
|
1288
|
-
o =
|
|
1288
|
+
o = Nt(Mt(a.formula));
|
|
1289
1289
|
} catch (t) {
|
|
1290
1290
|
n.add(e, t instanceof Error ? t.message : String(t));
|
|
1291
1291
|
continue;
|
|
@@ -1306,13 +1306,13 @@ function en(e, t, n) {
|
|
|
1306
1306
|
};
|
|
1307
1307
|
for (let e of i.keys()) s(e, []);
|
|
1308
1308
|
}
|
|
1309
|
-
function
|
|
1310
|
-
if (!
|
|
1311
|
-
let r = n.items.length, i =
|
|
1312
|
-
|
|
1313
|
-
let a =
|
|
1309
|
+
function en(e, t, n) {
|
|
1310
|
+
if (!yn(e)) return n.add(t, `must be an object; got ${E(e)}`), null;
|
|
1311
|
+
let r = n.items.length, i = an(e, t, n);
|
|
1312
|
+
on(e, i, t, n);
|
|
1313
|
+
let a = sn(e, t, n), o = w(e, "label", t, n, !1), s = _n(e, "required", !1, t, n), c = _n(e, "editable", !0, t, n), l = _n(e, "submit", !0, t, n), u = w(e, "example", t, n, !1), d = w(e, "formula", t, n, !1), f = fn(e.rules, T(t, "rules"), i, n);
|
|
1314
1314
|
if (i === null || a === null) return null;
|
|
1315
|
-
d !== null && !
|
|
1315
|
+
d !== null && !Vt.includes(i) && n.add(T(t, "formula"), `cannot fill ${vn(i)}; a formula works out a text, a number, a date or yes and no`);
|
|
1316
1316
|
let p = {
|
|
1317
1317
|
key: a,
|
|
1318
1318
|
label: o ?? a,
|
|
@@ -1336,7 +1336,7 @@ function tn(e, t, n) {
|
|
|
1336
1336
|
m = {
|
|
1337
1337
|
...p,
|
|
1338
1338
|
type: i,
|
|
1339
|
-
tone:
|
|
1339
|
+
tone: un(e, t, n)
|
|
1340
1340
|
};
|
|
1341
1341
|
break;
|
|
1342
1342
|
case "date":
|
|
@@ -1344,7 +1344,7 @@ function tn(e, t, n) {
|
|
|
1344
1344
|
m = {
|
|
1345
1345
|
...p,
|
|
1346
1346
|
type: i,
|
|
1347
|
-
pattern:
|
|
1347
|
+
pattern: cn(e, t, n)
|
|
1348
1348
|
};
|
|
1349
1349
|
break;
|
|
1350
1350
|
case "decimal":
|
|
@@ -1353,62 +1353,62 @@ function tn(e, t, n) {
|
|
|
1353
1353
|
m = {
|
|
1354
1354
|
...p,
|
|
1355
1355
|
type: i,
|
|
1356
|
-
decimals:
|
|
1357
|
-
tone:
|
|
1356
|
+
decimals: ln(e, t, n),
|
|
1357
|
+
tone: un(e, t, n)
|
|
1358
1358
|
};
|
|
1359
1359
|
break;
|
|
1360
1360
|
case "money":
|
|
1361
1361
|
m = {
|
|
1362
1362
|
...p,
|
|
1363
1363
|
type: i,
|
|
1364
|
-
decimals:
|
|
1365
|
-
currency:
|
|
1366
|
-
tone:
|
|
1364
|
+
decimals: ln(e, t, n),
|
|
1365
|
+
currency: w(e, "currency", t, n, !1),
|
|
1366
|
+
tone: un(e, t, n)
|
|
1367
1367
|
};
|
|
1368
1368
|
break;
|
|
1369
1369
|
case "options":
|
|
1370
1370
|
m = {
|
|
1371
1371
|
...p,
|
|
1372
1372
|
type: i,
|
|
1373
|
-
options: Object.freeze(
|
|
1374
|
-
multiple:
|
|
1373
|
+
options: Object.freeze(dn(e.options, T(t, "options"), n)),
|
|
1374
|
+
multiple: _n(e, "multiple", !1, t, n)
|
|
1375
1375
|
};
|
|
1376
1376
|
break;
|
|
1377
1377
|
case "lookup": m = {
|
|
1378
1378
|
...p,
|
|
1379
1379
|
type: i,
|
|
1380
|
-
lookup:
|
|
1380
|
+
lookup: w(e, "lookup", t, n, !0) ?? ""
|
|
1381
1381
|
};
|
|
1382
1382
|
}
|
|
1383
1383
|
if (n.items.length > r) return null;
|
|
1384
|
-
let ee =
|
|
1384
|
+
let ee = tn(e, m, t, n);
|
|
1385
1385
|
return n.items.length > r ? null : Object.freeze({
|
|
1386
1386
|
...m,
|
|
1387
1387
|
default: ee
|
|
1388
1388
|
});
|
|
1389
1389
|
}
|
|
1390
|
-
function
|
|
1391
|
-
let i = e.default, a =
|
|
1390
|
+
function tn(e, t, n, r) {
|
|
1391
|
+
let i = e.default, a = T(n, "default");
|
|
1392
1392
|
if (i == null) return null;
|
|
1393
1393
|
if (t.type === "lookup" || t.formula !== null || t.rules.some((e) => e.rule === "unique")) {
|
|
1394
1394
|
let e = t.type === "lookup" ? "a lookup's value is a record the backend gives" : t.formula === null ? "every new row would hold the same value, and it is unique" : "its value is worked out by its formula";
|
|
1395
1395
|
return r.add(a, `cannot be given: ${e}`), null;
|
|
1396
1396
|
}
|
|
1397
|
-
let o =
|
|
1398
|
-
if (!
|
|
1399
|
-
let s =
|
|
1400
|
-
return s === null ? Array.isArray(o) ? Object.freeze([...o]) : o : (r.add(a, `${
|
|
1397
|
+
let o = Wt.has(t.type) ? m(i) ?? i : i;
|
|
1398
|
+
if (!v(t, o)) return r.add(a, `${E(i)} is not a value of ${vn(t.type)}${nn(t)}`), null;
|
|
1399
|
+
let s = rn(t, o);
|
|
1400
|
+
return s === null ? Array.isArray(o) ? Object.freeze([...o]) : o : (r.add(a, `${E(i)} breaks the field's ${s} rule`), null);
|
|
1401
1401
|
}
|
|
1402
|
-
function
|
|
1402
|
+
function nn(e) {
|
|
1403
1403
|
switch (e.type) {
|
|
1404
1404
|
case "options": return `; it takes ${e.multiple ? "a list of " : "one of "}${e.options.map((e) => JSON.stringify(e.value)).join(", ")}`;
|
|
1405
1405
|
case "date": return "; write it as \"2026-12-31\"";
|
|
1406
1406
|
case "datetime": return "; write it as \"2026-12-31T09:30:00\"";
|
|
1407
1407
|
case "bool": return "; it takes true or false";
|
|
1408
|
-
default: return
|
|
1408
|
+
default: return Wt.has(e.type) ? "; write it as a number or decimal text, such as \"12.5\"" : "";
|
|
1409
1409
|
}
|
|
1410
1410
|
}
|
|
1411
|
-
function
|
|
1411
|
+
function rn(e, t) {
|
|
1412
1412
|
for (let n of e.rules) {
|
|
1413
1413
|
if ((n.rule === "min" || n.rule === "max") && typeof t == "string") {
|
|
1414
1414
|
let e = i(r(t) ?? t, n.value);
|
|
@@ -1421,196 +1421,196 @@ function an(e, t) {
|
|
|
1421
1421
|
}
|
|
1422
1422
|
return null;
|
|
1423
1423
|
}
|
|
1424
|
-
function
|
|
1424
|
+
function an(e, t, n) {
|
|
1425
1425
|
let r = e.type;
|
|
1426
|
-
return r == null ? (n.add(
|
|
1426
|
+
return r == null ? (n.add(T(t, "type"), "is required"), null) : typeof r != "string" || !Lt.includes(r) ? (n.add(T(t, "type"), `${E(r)} is not a field type; expected one of ${Lt.join(", ")}`), null) : r;
|
|
1427
1427
|
}
|
|
1428
|
-
function
|
|
1429
|
-
let i = /* @__PURE__ */ new Set([...
|
|
1430
|
-
for (let a of Object.keys(e)) i.has(a) || (t !== null &&
|
|
1428
|
+
function on(e, t, n, r) {
|
|
1429
|
+
let i = /* @__PURE__ */ new Set([...Bt, ...t === null ? Ut : Ht[t]]);
|
|
1430
|
+
for (let a of Object.keys(e)) i.has(a) || (t !== null && Ut.has(a) ? r.add(T(n, a), `does not apply to ${vn(t)}`) : t === null ? r.add(T(n, a), "is not a field property") : r.add(T(n, a), `is not a field property; ${vn(t)} takes ${[...i].join(", ")}`));
|
|
1431
|
+
}
|
|
1432
|
+
function sn(e, t, n) {
|
|
1433
|
+
let r = w(e, "key", t, n, !0);
|
|
1434
|
+
return r !== null && r.trim() !== r ? (n.add(T(t, "key"), `"${r}" starts or ends with a space; a key is an identifier, not a label`), null) : r;
|
|
1431
1435
|
}
|
|
1432
1436
|
function cn(e, t, n) {
|
|
1433
|
-
let r =
|
|
1434
|
-
return r !== null && r
|
|
1437
|
+
let r = w(e, "pattern", t, n, !1);
|
|
1438
|
+
return r !== null && Te(r) === null ? (n.add(T(t, "pattern"), `"${r}" uses a letter that is not one of d, j, m, n, Y, y, H, G, i, s; write other letters with a backslash before them`), null) : r;
|
|
1435
1439
|
}
|
|
1436
1440
|
function ln(e, t, n) {
|
|
1437
|
-
let r = C(e, "pattern", t, n, !1);
|
|
1438
|
-
return r !== null && Te(r) === null ? (n.add(w(t, "pattern"), `"${r}" uses a letter that is not one of d, j, m, n, Y, y, H, G, i, s; write other letters with a backslash before them`), null) : r;
|
|
1439
|
-
}
|
|
1440
|
-
function un(e, t, n) {
|
|
1441
1441
|
let r = e.decimals;
|
|
1442
|
-
return r == null ? null : typeof r != "number" || !Number.isSafeInteger(r) || r < 0 ? (n.add(
|
|
1442
|
+
return r == null ? null : typeof r != "number" || !Number.isSafeInteger(r) || r < 0 ? (n.add(T(t, "decimals"), `must be a whole number, 0 or more; got ${E(r)}`), null) : r;
|
|
1443
1443
|
}
|
|
1444
|
-
function
|
|
1444
|
+
function un(e, t, n) {
|
|
1445
1445
|
let r = e.tone;
|
|
1446
|
-
return r == null ? null : r === "sign" ? r : (n.add(
|
|
1446
|
+
return r == null ? null : r === "sign" ? r : (n.add(T(t, "tone"), `must be "sign"; got ${E(r)}`), null);
|
|
1447
1447
|
}
|
|
1448
|
-
function
|
|
1448
|
+
function dn(e, t, n) {
|
|
1449
1449
|
if (e == null) return n.add(t, "is required for an options field"), [];
|
|
1450
|
-
if (!Array.isArray(e)) return n.add(t, `must be an array of options; got ${
|
|
1450
|
+
if (!Array.isArray(e)) return n.add(t, `must be an array of options; got ${E(e)}`), [];
|
|
1451
1451
|
let r = [], i = /* @__PURE__ */ new Map();
|
|
1452
1452
|
return e.forEach((e, a) => {
|
|
1453
1453
|
let o = `${t}[${a}]`;
|
|
1454
|
-
if (!
|
|
1455
|
-
n.add(o, `must be an object such as { "value": "in", "label": "In" }; got ${
|
|
1454
|
+
if (!yn(e)) {
|
|
1455
|
+
n.add(o, `must be an object such as { "value": "in", "label": "In" }; got ${E(e)}`);
|
|
1456
1456
|
return;
|
|
1457
1457
|
}
|
|
1458
|
-
for (let t of Object.keys(e)) t !== "value" && t !== "label" && n.add(
|
|
1458
|
+
for (let t of Object.keys(e)) t !== "value" && t !== "label" && n.add(T(o, t), "is not an option property; an option takes value, label");
|
|
1459
1459
|
let s = e.value;
|
|
1460
1460
|
if ((typeof s != "string" || s === "") && !(typeof s == "number" && Number.isFinite(s))) {
|
|
1461
|
-
n.add(
|
|
1461
|
+
n.add(T(o, "value"), `must be a non-empty string or a finite number; got ${E(s)}`);
|
|
1462
1462
|
return;
|
|
1463
1463
|
}
|
|
1464
1464
|
let c = String(s), l = i.get(c);
|
|
1465
1465
|
if (l !== void 0) {
|
|
1466
|
-
n.add(
|
|
1466
|
+
n.add(T(o, "value"), `${E(s)} is already the value of ${t}[${l}]`);
|
|
1467
1467
|
return;
|
|
1468
1468
|
}
|
|
1469
1469
|
i.set(c, a);
|
|
1470
|
-
let u =
|
|
1470
|
+
let u = w(e, "label", o, n, !1);
|
|
1471
1471
|
r.push(Object.freeze({
|
|
1472
1472
|
value: s,
|
|
1473
1473
|
label: u ?? c
|
|
1474
1474
|
}));
|
|
1475
1475
|
}), r;
|
|
1476
1476
|
}
|
|
1477
|
-
function
|
|
1477
|
+
function fn(e, t, n, r) {
|
|
1478
1478
|
if (e == null) return [];
|
|
1479
|
-
if (!Array.isArray(e)) return r.add(t, `must be an array of rules; got ${
|
|
1479
|
+
if (!Array.isArray(e)) return r.add(t, `must be an array of rules; got ${E(e)}`), [];
|
|
1480
1480
|
let a = [], o = /* @__PURE__ */ new Map();
|
|
1481
1481
|
e.forEach((e, i) => {
|
|
1482
|
-
let s = `${t}[${i}]`, c =
|
|
1482
|
+
let s = `${t}[${i}]`, c = hn(e, s, n, r);
|
|
1483
1483
|
if (!c) return;
|
|
1484
1484
|
let l = o.get(c.rule);
|
|
1485
1485
|
l === void 0 ? (o.set(c.rule, i), a.push(c)) : r.add(s, `${c.rule} is already given at ${t}[${l}]; give each rule once`);
|
|
1486
1486
|
});
|
|
1487
|
-
let s =
|
|
1487
|
+
let s = pn(a, "min"), c = pn(a, "max");
|
|
1488
1488
|
s !== void 0 && c !== void 0 && i(s, c) > 0 && r.add(t, `min ${s} is above max ${c}; no value can satisfy both`);
|
|
1489
|
-
let l =
|
|
1489
|
+
let l = mn(a, "minLength"), u = mn(a, "maxLength");
|
|
1490
1490
|
return l !== void 0 && u !== void 0 && l > u && r.add(t, `minLength ${l} is above maxLength ${u}; no text can satisfy both`), a;
|
|
1491
1491
|
}
|
|
1492
|
-
function
|
|
1492
|
+
function pn(e, t) {
|
|
1493
1493
|
for (let n of e) if ((n.rule === "min" || n.rule === "max") && n.rule === t) return n.value;
|
|
1494
1494
|
}
|
|
1495
|
-
function
|
|
1495
|
+
function mn(e, t) {
|
|
1496
1496
|
for (let n of e) if ((n.rule === "minLength" || n.rule === "maxLength") && n.rule === t) return n.value;
|
|
1497
1497
|
}
|
|
1498
|
-
function
|
|
1499
|
-
if (!
|
|
1498
|
+
function hn(e, t, n, i) {
|
|
1499
|
+
if (!yn(e)) return i.add(t, `must be an object such as { "rule": "min", "value": "0" }; got ${E(e)}`), null;
|
|
1500
1500
|
let a = e.rule;
|
|
1501
|
-
if (typeof a != "string" || !
|
|
1501
|
+
if (typeof a != "string" || !Gt.includes(a)) return i.add(T(t, "rule"), `${E(a)} is not a rule; expected one of ${Gt.join(", ")}`), null;
|
|
1502
1502
|
let o = a;
|
|
1503
|
-
for (let n of Object.keys(e)) n === "rule" || n === "value" && o !== "unique" || i.add(
|
|
1504
|
-
if (n !== null && !
|
|
1503
|
+
for (let n of Object.keys(e)) n === "rule" || n === "value" && o !== "unique" || i.add(T(t, n), o === "unique" && n === "value" ? "unique takes no value" : `is not a property of a ${o} rule`);
|
|
1504
|
+
if (n !== null && !gn(o, n)) return i.add(t, `${o} does not apply to ${vn(n)}`), null;
|
|
1505
1505
|
let s = e.value;
|
|
1506
1506
|
switch (o) {
|
|
1507
1507
|
case "min":
|
|
1508
1508
|
case "max": {
|
|
1509
1509
|
let e = typeof s == "string" || typeof s == "number" ? r(s) : null;
|
|
1510
|
-
return e === null ? (i.add(
|
|
1510
|
+
return e === null ? (i.add(T(t, "value"), s === void 0 ? "is required" : `must be a decimal number such as "0" or "12.5", with a point and no exponent; got ${E(s)}`), null) : Object.freeze({
|
|
1511
1511
|
rule: o,
|
|
1512
1512
|
value: e
|
|
1513
1513
|
});
|
|
1514
1514
|
}
|
|
1515
1515
|
case "minLength":
|
|
1516
|
-
case "maxLength": return typeof s != "number" || !Number.isSafeInteger(s) || s < 0 ? (i.add(
|
|
1516
|
+
case "maxLength": return typeof s != "number" || !Number.isSafeInteger(s) || s < 0 ? (i.add(T(t, "value"), s === void 0 ? "is required" : `must be a whole number of characters, 0 or more; got ${E(s)}`), null) : Object.freeze({
|
|
1517
1517
|
rule: o,
|
|
1518
1518
|
value: s
|
|
1519
1519
|
});
|
|
1520
1520
|
case "unique": return Object.freeze({ rule: o });
|
|
1521
1521
|
}
|
|
1522
1522
|
}
|
|
1523
|
-
function
|
|
1523
|
+
function gn(e, t) {
|
|
1524
1524
|
switch (e) {
|
|
1525
1525
|
case "min":
|
|
1526
|
-
case "max": return
|
|
1526
|
+
case "max": return Wt.has(t);
|
|
1527
1527
|
case "minLength":
|
|
1528
1528
|
case "maxLength": return t === "string";
|
|
1529
1529
|
case "unique": return !0;
|
|
1530
1530
|
}
|
|
1531
1531
|
}
|
|
1532
|
-
function
|
|
1532
|
+
function w(e, t, n, r, i) {
|
|
1533
1533
|
let a = e[t];
|
|
1534
|
-
return a == null ? (i && r.add(
|
|
1534
|
+
return a == null ? (i && r.add(T(n, t), "is required"), null) : typeof a != "string" || a.trim() === "" ? (r.add(T(n, t), `must be a non-empty string; got ${E(a)}`), null) : a;
|
|
1535
1535
|
}
|
|
1536
|
-
function
|
|
1536
|
+
function _n(e, t, n, r, i) {
|
|
1537
1537
|
let a = e[t];
|
|
1538
|
-
return a == null ? n : typeof a == "boolean" ? a : (i.add(
|
|
1538
|
+
return a == null ? n : typeof a == "boolean" ? a : (i.add(T(r, t), `must be true or false; got ${E(a)}`), n);
|
|
1539
1539
|
}
|
|
1540
|
-
function
|
|
1540
|
+
function vn(e) {
|
|
1541
1541
|
return `${/^[aeiou]/.test(e) ? "an" : "a"} ${e} field`;
|
|
1542
1542
|
}
|
|
1543
|
-
function
|
|
1543
|
+
function yn(e) {
|
|
1544
1544
|
return typeof e == "object" && !!e && !Array.isArray(e);
|
|
1545
1545
|
}
|
|
1546
|
-
function
|
|
1546
|
+
function T(e, t) {
|
|
1547
1547
|
return e === "" ? t : `${e}.${t}`;
|
|
1548
1548
|
}
|
|
1549
|
-
function
|
|
1549
|
+
function E(e) {
|
|
1550
1550
|
return e === void 0 ? "nothing" : Array.isArray(e) ? "an array" : typeof e == "object" && e ? "an object" : JSON.stringify(e) ?? String(e);
|
|
1551
1551
|
}
|
|
1552
1552
|
// src/ids.ts
|
|
1553
|
-
function
|
|
1553
|
+
function bn() {
|
|
1554
1554
|
let e = globalThis, t = /* @__PURE__ */ new Uint32Array(1);
|
|
1555
1555
|
return typeof e.crypto?.getRandomValues == "function" ? e.crypto.getRandomValues(t) : t[0] = Math.floor(Math.random() * 2 ** 32), (t[0] ?? 0).toString(36).padStart(7, "0");
|
|
1556
1556
|
}
|
|
1557
|
-
function
|
|
1558
|
-
let t =
|
|
1557
|
+
function xn(e) {
|
|
1558
|
+
let t = bn(), n = 0;
|
|
1559
1559
|
return () => `${e}_${t}_${(++n).toString(36)}`;
|
|
1560
1560
|
}
|
|
1561
1561
|
// src/value.ts
|
|
1562
|
-
var
|
|
1563
|
-
function
|
|
1564
|
-
return
|
|
1562
|
+
var Sn = 32;
|
|
1563
|
+
function Cn(e, t = "A cell value") {
|
|
1564
|
+
return wn(e, t, 0);
|
|
1565
1565
|
}
|
|
1566
|
-
function
|
|
1566
|
+
function wn(t, n, r) {
|
|
1567
1567
|
if (t == null) return null;
|
|
1568
1568
|
switch (typeof t) {
|
|
1569
1569
|
case "boolean":
|
|
1570
1570
|
case "string": return t;
|
|
1571
1571
|
case "number":
|
|
1572
|
-
if (!Number.isFinite(t)) throw
|
|
1572
|
+
if (!Number.isFinite(t)) throw Tn(n, String(t));
|
|
1573
1573
|
return t === 0 ? 0 : t;
|
|
1574
1574
|
case "object": break;
|
|
1575
|
-
default: throw
|
|
1575
|
+
default: throw Tn(n, `a ${typeof t}`);
|
|
1576
1576
|
}
|
|
1577
|
-
if (r >=
|
|
1578
|
-
if (Array.isArray(t)) return Object.freeze(Array.from(t, (e) =>
|
|
1577
|
+
if (r >= Sn) throw new e("invalid_value", `${n} is nested more than ${Sn} levels deep. A value that contains itself never ends.`);
|
|
1578
|
+
if (Array.isArray(t)) return Object.freeze(Array.from(t, (e) => wn(e, n, r + 1)));
|
|
1579
1579
|
let i = Object.getPrototypeOf(t);
|
|
1580
1580
|
if (i !== Object.prototype && i !== null) {
|
|
1581
1581
|
let e = t.constructor?.name;
|
|
1582
|
-
throw
|
|
1582
|
+
throw Tn(n, e ? `a ${e}` : "an object that is not a plain object");
|
|
1583
1583
|
}
|
|
1584
1584
|
let a = Object.create(null);
|
|
1585
|
-
for (let [e, i] of Object.entries(t)) i !== void 0 && (a[e] =
|
|
1585
|
+
for (let [e, i] of Object.entries(t)) i !== void 0 && (a[e] = wn(i, n, r + 1));
|
|
1586
1586
|
return Object.freeze(a);
|
|
1587
1587
|
}
|
|
1588
|
-
function
|
|
1588
|
+
function Tn(t, n) {
|
|
1589
1589
|
return new e("invalid_value", `${t} must be null, a boolean, a finite number, a string, or an array or plain object of these; got ${n}.`);
|
|
1590
1590
|
}
|
|
1591
|
-
function
|
|
1591
|
+
function En(e, t) {
|
|
1592
1592
|
if (e === t) return !0;
|
|
1593
1593
|
if (typeof e != "object" || typeof t != "object" || e === null || t === null) return !1;
|
|
1594
1594
|
if (Array.isArray(e) || Array.isArray(t)) {
|
|
1595
1595
|
if (!Array.isArray(e) || !Array.isArray(t) || e.length !== t.length) return !1;
|
|
1596
1596
|
let n = t;
|
|
1597
|
-
return e.every((e, t) =>
|
|
1597
|
+
return e.every((e, t) => En(e, n[t] ?? null));
|
|
1598
1598
|
}
|
|
1599
1599
|
let n = e, r = t, i = Object.keys(n);
|
|
1600
|
-
return i.length === Object.keys(r).length && i.every((e) => Object.hasOwn(r, e) &&
|
|
1600
|
+
return i.length === Object.keys(r).length && i.every((e) => Object.hasOwn(r, e) && En(n[e] ?? null, r[e] ?? null));
|
|
1601
1601
|
}
|
|
1602
1602
|
// src/rows.ts
|
|
1603
|
-
var
|
|
1603
|
+
var Dn = class {
|
|
1604
1604
|
#e = [];
|
|
1605
1605
|
#t = /* @__PURE__ */ new Map();
|
|
1606
1606
|
#n = null;
|
|
1607
1607
|
#r = 0;
|
|
1608
1608
|
#i = null;
|
|
1609
1609
|
#a;
|
|
1610
|
-
#o = new
|
|
1610
|
+
#o = new S();
|
|
1611
1611
|
#s = /* @__PURE__ */ new Set();
|
|
1612
1612
|
constructor(e = {}) {
|
|
1613
|
-
this.#a = e.createRowId ??
|
|
1613
|
+
this.#a = e.createRowId ?? Nn();
|
|
1614
1614
|
for (let { rowId: t, row: n } of this.#d(e.rows ?? [])) this.#t.set(t, n), this.#e.push(t);
|
|
1615
1615
|
}
|
|
1616
1616
|
get revision() {
|
|
@@ -1635,12 +1635,12 @@ var On = class {
|
|
|
1635
1635
|
return this.#u(e)[t] ?? null;
|
|
1636
1636
|
}
|
|
1637
1637
|
values(e) {
|
|
1638
|
-
return
|
|
1638
|
+
return An(this.#u(e));
|
|
1639
1639
|
}
|
|
1640
1640
|
snapshot() {
|
|
1641
1641
|
return this.#e.map((e) => Object.freeze({
|
|
1642
1642
|
rowId: e,
|
|
1643
|
-
values:
|
|
1643
|
+
values: An(this.#u(e))
|
|
1644
1644
|
}));
|
|
1645
1645
|
}
|
|
1646
1646
|
subscribe(e) {
|
|
@@ -1675,9 +1675,9 @@ var On = class {
|
|
|
1675
1675
|
setCell(e, t, n) {
|
|
1676
1676
|
this.#c(() => {
|
|
1677
1677
|
let r = this.#u(e);
|
|
1678
|
-
|
|
1679
|
-
let i =
|
|
1680
|
-
|
|
1678
|
+
jn(t);
|
|
1679
|
+
let i = Cn(n, `The value of "${t}" in row "${e}"`), a = r[t] ?? null;
|
|
1680
|
+
En(a, i) || (kn(r, t, i), this.#l({
|
|
1681
1681
|
kind: "set",
|
|
1682
1682
|
rowId: e,
|
|
1683
1683
|
field: t,
|
|
@@ -1693,7 +1693,7 @@ var On = class {
|
|
|
1693
1693
|
}
|
|
1694
1694
|
insertRows(t, n) {
|
|
1695
1695
|
if (!Number.isInteger(t) || t < 0 || t > this.#e.length) throw new e("invalid_argument", `Rows can be inserted at 0 to ${this.#e.length}; got ${t}.`);
|
|
1696
|
-
let r = typeof n == "number" ?
|
|
1696
|
+
let r = typeof n == "number" ? Mn(n) : n, i = [];
|
|
1697
1697
|
return this.#c(() => {
|
|
1698
1698
|
let e = this.#d(r);
|
|
1699
1699
|
if (e.length !== 0) {
|
|
@@ -1708,7 +1708,7 @@ var On = class {
|
|
|
1708
1708
|
index: t,
|
|
1709
1709
|
rows: Object.freeze(e.map(({ rowId: e, row: t }) => Object.freeze({
|
|
1710
1710
|
rowId: e,
|
|
1711
|
-
values:
|
|
1711
|
+
values: An(t)
|
|
1712
1712
|
})))
|
|
1713
1713
|
});
|
|
1714
1714
|
}
|
|
@@ -1726,7 +1726,7 @@ var On = class {
|
|
|
1726
1726
|
t.has(r) ? (e.push(Object.freeze({
|
|
1727
1727
|
index: i,
|
|
1728
1728
|
rowId: r,
|
|
1729
|
-
values:
|
|
1729
|
+
values: An(this.#u(r))
|
|
1730
1730
|
})), this.#t.delete(r)) : n.push(r);
|
|
1731
1731
|
}), this.#e = n, this.#n = null, this.#l({
|
|
1732
1732
|
kind: "remove",
|
|
@@ -1735,7 +1735,7 @@ var On = class {
|
|
|
1735
1735
|
});
|
|
1736
1736
|
}
|
|
1737
1737
|
revert(e, t = {}) {
|
|
1738
|
-
let n =
|
|
1738
|
+
let n = On(e);
|
|
1739
1739
|
return this.#p("revert", t, () => {
|
|
1740
1740
|
for (let e = n.length - 1; e >= 0; e--) {
|
|
1741
1741
|
let t = n[e].operations;
|
|
@@ -1744,7 +1744,7 @@ var On = class {
|
|
|
1744
1744
|
});
|
|
1745
1745
|
}
|
|
1746
1746
|
replay(e, t = {}) {
|
|
1747
|
-
let n =
|
|
1747
|
+
let n = On(e);
|
|
1748
1748
|
return this.#p("replay", t, () => {
|
|
1749
1749
|
for (let e of n) for (let t of e.operations) this.#h(t);
|
|
1750
1750
|
});
|
|
@@ -1769,8 +1769,8 @@ var On = class {
|
|
|
1769
1769
|
n.add(i);
|
|
1770
1770
|
let a = Object.create(null);
|
|
1771
1771
|
for (let [e, n] of Object.entries(t.values ?? {})) {
|
|
1772
|
-
|
|
1773
|
-
let t =
|
|
1772
|
+
jn(e);
|
|
1773
|
+
let t = Cn(n, `The value of "${e}" in row "${i}"`);
|
|
1774
1774
|
t !== null && (a[e] = t);
|
|
1775
1775
|
}
|
|
1776
1776
|
return {
|
|
@@ -1782,7 +1782,7 @@ var On = class {
|
|
|
1782
1782
|
#f(e) {
|
|
1783
1783
|
switch (e.kind) {
|
|
1784
1784
|
case "set":
|
|
1785
|
-
|
|
1785
|
+
kn(this.#u(e.rowId), e.field, e.before);
|
|
1786
1786
|
break;
|
|
1787
1787
|
case "insert": {
|
|
1788
1788
|
let t = new Set(e.rows.map((e) => e.rowId));
|
|
@@ -1824,8 +1824,8 @@ var On = class {
|
|
|
1824
1824
|
#g(t, n, r, i) {
|
|
1825
1825
|
let a = this.#t.get(t);
|
|
1826
1826
|
if (!a) throw new e("conflict", `There is no row "${t}" in this sheet any more.`);
|
|
1827
|
-
if (!
|
|
1828
|
-
|
|
1827
|
+
if (!En(a[n] ?? null, r)) throw new e("conflict", `The cell "${n}" in row "${t}" has changed since.`);
|
|
1828
|
+
kn(a, n, i), this.#l({
|
|
1829
1829
|
kind: "set",
|
|
1830
1830
|
rowId: t,
|
|
1831
1831
|
field: n,
|
|
@@ -1870,29 +1870,29 @@ var On = class {
|
|
|
1870
1870
|
this.#e = t;
|
|
1871
1871
|
}
|
|
1872
1872
|
};
|
|
1873
|
-
function
|
|
1873
|
+
function On(e) {
|
|
1874
1874
|
return "operations" in e ? [e] : e;
|
|
1875
1875
|
}
|
|
1876
|
-
function
|
|
1876
|
+
function kn(e, t, n) {
|
|
1877
1877
|
n === null ? delete e[t] : e[t] = n;
|
|
1878
1878
|
}
|
|
1879
|
-
function
|
|
1879
|
+
function An(e) {
|
|
1880
1880
|
return Object.freeze(Object.assign(Object.create(null), e));
|
|
1881
1881
|
}
|
|
1882
|
-
function
|
|
1882
|
+
function jn(t) {
|
|
1883
1883
|
if (typeof t != "string" || t === "") throw new e("invalid_argument", `A field key must be a non-empty string; got ${String(t)}.`);
|
|
1884
1884
|
}
|
|
1885
|
-
function
|
|
1885
|
+
function Mn(t) {
|
|
1886
1886
|
if (!Number.isSafeInteger(t) || t < 0) throw new e("invalid_argument", `A number of rows must be a whole number, 0 or more; got ${t}.`);
|
|
1887
1887
|
return Array.from({ length: t }, () => ({}));
|
|
1888
1888
|
}
|
|
1889
|
-
function
|
|
1890
|
-
return
|
|
1889
|
+
function Nn() {
|
|
1890
|
+
return xn("r");
|
|
1891
1891
|
}
|
|
1892
1892
|
// src/async.ts
|
|
1893
|
-
function
|
|
1893
|
+
function D(e, t) {
|
|
1894
1894
|
return new Promise((n, r) => {
|
|
1895
|
-
let i = () => r(
|
|
1895
|
+
let i = () => r(Fn());
|
|
1896
1896
|
t.aborted ? i() : (t.addEventListener("abort", i, { once: !0 }), e.then((e) => {
|
|
1897
1897
|
t.removeEventListener("abort", i), n(e);
|
|
1898
1898
|
}, (e) => {
|
|
@@ -1900,18 +1900,18 @@ function E(e, t) {
|
|
|
1900
1900
|
}));
|
|
1901
1901
|
});
|
|
1902
1902
|
}
|
|
1903
|
-
function
|
|
1904
|
-
return
|
|
1903
|
+
function Pn(e, t) {
|
|
1904
|
+
return D(new Promise((t) => setTimeout(t, e)), t);
|
|
1905
1905
|
}
|
|
1906
|
-
function
|
|
1906
|
+
function Fn() {
|
|
1907
1907
|
let e = /* @__PURE__ */ Error("The request was cancelled.");
|
|
1908
1908
|
return e.name = "AbortError", e;
|
|
1909
1909
|
}
|
|
1910
|
-
function
|
|
1910
|
+
function In() {
|
|
1911
1911
|
return new AbortController().signal;
|
|
1912
1912
|
}
|
|
1913
1913
|
// src/lookup.ts
|
|
1914
|
-
var
|
|
1914
|
+
var Ln = "lookup", Rn = 200, zn = 6e4, Bn = class {
|
|
1915
1915
|
#e;
|
|
1916
1916
|
#t;
|
|
1917
1917
|
#n;
|
|
@@ -1919,7 +1919,7 @@ var Rn = "lookup", zn = 200, Bn = 6e4, Vn = class {
|
|
|
1919
1919
|
#i;
|
|
1920
1920
|
#a;
|
|
1921
1921
|
#o;
|
|
1922
|
-
#s = new
|
|
1922
|
+
#s = new S();
|
|
1923
1923
|
#c;
|
|
1924
1924
|
#l = /* @__PURE__ */ new Map();
|
|
1925
1925
|
#u = /* @__PURE__ */ new Map();
|
|
@@ -1931,9 +1931,9 @@ var Rn = "lookup", zn = 200, Bn = 6e4, Vn = class {
|
|
|
1931
1931
|
#g = 0;
|
|
1932
1932
|
#_ = !1;
|
|
1933
1933
|
constructor(t) {
|
|
1934
|
-
let n = t.batchSize ??
|
|
1934
|
+
let n = t.batchSize ?? Rn;
|
|
1935
1935
|
if (!Number.isSafeInteger(n) || n < 1) throw new e("invalid_argument", `batchSize must be a whole number, 1 or more; got ${n}.`);
|
|
1936
|
-
this.#e = t.schema, this.#t = t.store, this.#n = t.adapters, this.#r = n, this.#i = t.cacheFor ??
|
|
1936
|
+
this.#e = t.schema, this.#t = t.store, this.#n = t.adapters, this.#r = n, this.#i = t.cacheFor ?? zn, this.#a = t.now ?? (() => Date.now()), this.#o = t.createRequestId ?? xn("lookup"), this.#c = this.#t.subscribe((e) => this.#v(e));
|
|
1937
1937
|
}
|
|
1938
1938
|
get version() {
|
|
1939
1939
|
return this.#g;
|
|
@@ -1947,12 +1947,12 @@ var Rn = "lookup", zn = 200, Bn = 6e4, Vn = class {
|
|
|
1947
1947
|
subscribe(e) {
|
|
1948
1948
|
return this.#s.add(e);
|
|
1949
1949
|
}
|
|
1950
|
-
async search(t, n, r =
|
|
1950
|
+
async search(t, n, r = In(), i = 20) {
|
|
1951
1951
|
let a = this.#w(t);
|
|
1952
1952
|
if (!a) throw new e("invalid_argument", `"${t}" is not a lookup field.`);
|
|
1953
1953
|
let o = `${a.lookup}\u0000${i}\u0000${l(n)}`, s = this.#T(this.#l.get(o));
|
|
1954
1954
|
if (s) return s;
|
|
1955
|
-
let c = this.#o(), u =
|
|
1955
|
+
let c = this.#o(), u = Hn(await D(this.#n.search({
|
|
1956
1956
|
lookup: a.lookup,
|
|
1957
1957
|
field: t,
|
|
1958
1958
|
query: n,
|
|
@@ -1993,7 +1993,7 @@ var Rn = "lookup", zn = 200, Bn = 6e4, Vn = class {
|
|
|
1993
1993
|
label: n,
|
|
1994
1994
|
cells: /* @__PURE__ */ new Set()
|
|
1995
1995
|
};
|
|
1996
|
-
o.cells.add(
|
|
1996
|
+
o.cells.add(Vn(e, t)), i.set(a, o), this.#b();
|
|
1997
1997
|
}
|
|
1998
1998
|
#b() {
|
|
1999
1999
|
this.#p || this.#_ || (this.#p = !0, this.#f = this.#f.then(async () => {
|
|
@@ -2012,10 +2012,10 @@ var Rn = "lookup", zn = 200, Bn = 6e4, Vn = class {
|
|
|
2012
2012
|
lookup: n,
|
|
2013
2013
|
labels: a
|
|
2014
2014
|
}, {
|
|
2015
|
-
signal:
|
|
2015
|
+
signal: In(),
|
|
2016
2016
|
requestId: this.#o()
|
|
2017
2017
|
});
|
|
2018
|
-
this.#S(e, a,
|
|
2018
|
+
this.#S(e, a, Un(r)), this.#D(null);
|
|
2019
2019
|
} catch (e) {
|
|
2020
2020
|
this.#D(e);
|
|
2021
2021
|
} finally {
|
|
@@ -2052,7 +2052,7 @@ var Rn = "lookup", zn = 200, Bn = 6e4, Vn = class {
|
|
|
2052
2052
|
});
|
|
2053
2053
|
}
|
|
2054
2054
|
}
|
|
2055
|
-
n.length > 0 && this.#t.setCells(n, { origin:
|
|
2055
|
+
n.length > 0 && this.#t.setCells(n, { origin: Ln });
|
|
2056
2056
|
}
|
|
2057
2057
|
#w(e) {
|
|
2058
2058
|
if (!this.#e.has(e)) return null;
|
|
@@ -2075,31 +2075,31 @@ var Rn = "lookup", zn = 200, Bn = 6e4, Vn = class {
|
|
|
2075
2075
|
this.#g++, this.#s.emit(this);
|
|
2076
2076
|
}
|
|
2077
2077
|
};
|
|
2078
|
-
function
|
|
2078
|
+
function Vn(e, t) {
|
|
2079
2079
|
return `${e}\u0000${t}`;
|
|
2080
2080
|
}
|
|
2081
|
-
function
|
|
2082
|
-
let n =
|
|
2081
|
+
function Hn(t) {
|
|
2082
|
+
let n = Gn(t);
|
|
2083
2083
|
if (!n || !Array.isArray(n.items)) throw new e("invalid_response", "A lookup search answer must be an object with an items array.");
|
|
2084
2084
|
return Object.freeze({
|
|
2085
|
-
items: Object.freeze(n.items.map((e, t) =>
|
|
2085
|
+
items: Object.freeze(n.items.map((e, t) => Wn(e, `items[${t}]`))),
|
|
2086
2086
|
more: n.more === !0
|
|
2087
2087
|
});
|
|
2088
2088
|
}
|
|
2089
|
-
function
|
|
2090
|
-
let n =
|
|
2089
|
+
function Un(t) {
|
|
2090
|
+
let n = Gn(t);
|
|
2091
2091
|
if (!n || !Array.isArray(n.matches)) throw new e("invalid_response", "A lookup resolve answer must be an object with a matches array.");
|
|
2092
2092
|
return Object.freeze({ matches: Object.freeze(n.matches.map((t, n) => {
|
|
2093
|
-
let r =
|
|
2093
|
+
let r = Gn(t);
|
|
2094
2094
|
if (!r || typeof r.label != "string" || !Array.isArray(r.items)) throw new e("invalid_response", `matches[${n}] must have a label and an items array.`);
|
|
2095
2095
|
return Object.freeze({
|
|
2096
2096
|
label: r.label,
|
|
2097
|
-
items: Object.freeze(r.items.map((e, t) =>
|
|
2097
|
+
items: Object.freeze(r.items.map((e, t) => Wn(e, `matches[${n}].items[${t}]`)))
|
|
2098
2098
|
});
|
|
2099
2099
|
})) });
|
|
2100
2100
|
}
|
|
2101
|
-
function
|
|
2102
|
-
let r =
|
|
2101
|
+
function Wn(t, n) {
|
|
2102
|
+
let r = Gn(t), i = r?.id;
|
|
2103
2103
|
if (!r || typeof i != "string" && typeof i != "number" || typeof r.label != "string") throw new e("invalid_response", `${n} must have an id (text or a number) and a label.`);
|
|
2104
2104
|
return Object.freeze({
|
|
2105
2105
|
id: i,
|
|
@@ -2108,11 +2108,11 @@ function Gn(t, n) {
|
|
|
2108
2108
|
...r.disabled === !0 ? { disabled: !0 } : {}
|
|
2109
2109
|
});
|
|
2110
2110
|
}
|
|
2111
|
-
function
|
|
2111
|
+
function Gn(e) {
|
|
2112
2112
|
return typeof e == "object" && e && !Array.isArray(e) ? e : null;
|
|
2113
2113
|
}
|
|
2114
2114
|
// src/history.ts
|
|
2115
|
-
var
|
|
2115
|
+
var Kn = "undo", qn = "redo", Jn = 100, Yn = class {
|
|
2116
2116
|
#e;
|
|
2117
2117
|
#t;
|
|
2118
2118
|
#n;
|
|
@@ -2121,10 +2121,10 @@ var qn = "undo", Jn = "redo", Yn = 100, Xn = class {
|
|
|
2121
2121
|
#a = -1;
|
|
2122
2122
|
#o = 0;
|
|
2123
2123
|
#s = 0;
|
|
2124
|
-
#c = new
|
|
2124
|
+
#c = new S();
|
|
2125
2125
|
#l;
|
|
2126
2126
|
constructor(t, n = {}) {
|
|
2127
|
-
let r = n.limit ??
|
|
2127
|
+
let r = n.limit ?? Jn;
|
|
2128
2128
|
if (!Number.isSafeInteger(r) || r < 1) throw new e("invalid_argument", `The limit of an undo history must be a whole number, 1 or more; got ${r}.`);
|
|
2129
2129
|
this.#e = t, this.#t = r, this.#n = n.joins ?? ((e) => e.origin === "lookup"), this.#l = t.subscribe((e) => this.#d(e));
|
|
2130
2130
|
}
|
|
@@ -2138,10 +2138,10 @@ var qn = "undo", Jn = "redo", Yn = 100, Xn = class {
|
|
|
2138
2138
|
return this.#i.length > 0;
|
|
2139
2139
|
}
|
|
2140
2140
|
get nextUndo() {
|
|
2141
|
-
return
|
|
2141
|
+
return Xn(this.#r[this.#r.length - 1]);
|
|
2142
2142
|
}
|
|
2143
2143
|
get nextRedo() {
|
|
2144
|
-
return
|
|
2144
|
+
return Xn(this.#i[this.#i.length - 1]);
|
|
2145
2145
|
}
|
|
2146
2146
|
record(e) {
|
|
2147
2147
|
this.#r.push(e), this.#f(), this.#i = [], this.#p();
|
|
@@ -2150,14 +2150,14 @@ var qn = "undo", Jn = "redo", Yn = 100, Xn = class {
|
|
|
2150
2150
|
let e = this.#r.pop();
|
|
2151
2151
|
if (e === void 0) return null;
|
|
2152
2152
|
if (!Array.isArray(e)) return e.undo(), this.#i.push(e), this.#p(), null;
|
|
2153
|
-
let t = this.#o, n = this.#u(e, this.#r, () => this.#e.revert(e, { origin:
|
|
2153
|
+
let t = this.#o, n = this.#u(e, this.#r, () => this.#e.revert(e, { origin: Kn }));
|
|
2154
2154
|
return this.#o === t && this.#i.push(e), this.#p(), n;
|
|
2155
2155
|
}
|
|
2156
2156
|
redo() {
|
|
2157
2157
|
let e = this.#i.pop();
|
|
2158
2158
|
if (e === void 0) return null;
|
|
2159
2159
|
if (!Array.isArray(e)) return e.redo(), this.#r.push(e), this.#f(), this.#p(), null;
|
|
2160
|
-
let t = this.#o, n = this.#u(e, this.#i, () => this.#e.replay(e, { origin:
|
|
2160
|
+
let t = this.#o, n = this.#u(e, this.#i, () => this.#e.replay(e, { origin: qn }));
|
|
2161
2161
|
return this.#r.splice(Math.max(0, this.#r.length - (this.#o - t)), 0, e), this.#f(), this.#p(), n;
|
|
2162
2162
|
}
|
|
2163
2163
|
clear() {
|
|
@@ -2192,247 +2192,247 @@ var qn = "undo", Jn = "redo", Yn = 100, Xn = class {
|
|
|
2192
2192
|
this.#s++, this.#c.emit(this);
|
|
2193
2193
|
}
|
|
2194
2194
|
};
|
|
2195
|
-
function
|
|
2195
|
+
function Xn(e) {
|
|
2196
2196
|
return Array.isArray(e) ? e[0] ?? null : null;
|
|
2197
2197
|
}
|
|
2198
|
-
var
|
|
2199
|
-
units:
|
|
2198
|
+
var Zn = /^([+-]?)(\d+)(?:\.(\d+))?$/, O = BigInt(0), Qn = BigInt(1), $n = BigInt(2), k = BigInt(10), er = BigInt(1e3), A = Object.freeze({
|
|
2199
|
+
units: O,
|
|
2200
2200
|
scale: 0
|
|
2201
|
-
}),
|
|
2202
|
-
units:
|
|
2201
|
+
}), tr = Object.freeze({
|
|
2202
|
+
units: Qn,
|
|
2203
2203
|
scale: 0
|
|
2204
2204
|
});
|
|
2205
|
-
function
|
|
2206
|
-
let t =
|
|
2205
|
+
function j(e) {
|
|
2206
|
+
let t = Zn.exec(e.trim());
|
|
2207
2207
|
if (!t) return null;
|
|
2208
2208
|
let n = t[3] ?? "", r = BigInt(`${t[2] ?? "0"}${n}`);
|
|
2209
|
-
return
|
|
2209
|
+
return ur({
|
|
2210
2210
|
units: t[1] === "-" ? -r : r,
|
|
2211
2211
|
scale: n.length
|
|
2212
2212
|
});
|
|
2213
2213
|
}
|
|
2214
|
-
function
|
|
2215
|
-
let t = e.units <
|
|
2214
|
+
function M(e) {
|
|
2215
|
+
let t = e.units < O, n = (t ? -e.units : e.units).toString().padStart(e.scale + 1, "0"), r = n.slice(0, n.length - e.scale), i = n.slice(n.length - e.scale).replace(/0+$/, ""), a = i === "" ? r : `${r}.${i}`;
|
|
2216
2216
|
return t && a !== "0" ? `-${a}` : a;
|
|
2217
2217
|
}
|
|
2218
|
-
function
|
|
2219
|
-
let [n, r, i] =
|
|
2220
|
-
return
|
|
2218
|
+
function N(e, t) {
|
|
2219
|
+
let [n, r, i] = lr(e, t);
|
|
2220
|
+
return ur({
|
|
2221
2221
|
units: n + r,
|
|
2222
2222
|
scale: i
|
|
2223
2223
|
});
|
|
2224
2224
|
}
|
|
2225
|
-
function
|
|
2226
|
-
let [n, r, i] =
|
|
2227
|
-
return
|
|
2225
|
+
function nr(e, t) {
|
|
2226
|
+
let [n, r, i] = lr(e, t);
|
|
2227
|
+
return ur({
|
|
2228
2228
|
units: n - r,
|
|
2229
2229
|
scale: i
|
|
2230
2230
|
});
|
|
2231
2231
|
}
|
|
2232
|
-
function
|
|
2233
|
-
return
|
|
2232
|
+
function rr(e, t) {
|
|
2233
|
+
return ur({
|
|
2234
2234
|
units: e.units * t.units,
|
|
2235
2235
|
scale: e.scale + t.scale
|
|
2236
2236
|
});
|
|
2237
2237
|
}
|
|
2238
|
-
function
|
|
2239
|
-
return t.units ===
|
|
2240
|
-
units: e.units *
|
|
2238
|
+
function P(e, t) {
|
|
2239
|
+
return t.units === O ? null : I({
|
|
2240
|
+
units: e.units * k ** BigInt(21 + t.scale) / (t.units * k ** BigInt(e.scale)),
|
|
2241
2241
|
scale: 21
|
|
2242
2242
|
}, 20, "half");
|
|
2243
2243
|
}
|
|
2244
|
-
function
|
|
2244
|
+
function ir(e) {
|
|
2245
2245
|
return {
|
|
2246
2246
|
units: -e.units,
|
|
2247
2247
|
scale: e.scale
|
|
2248
2248
|
};
|
|
2249
2249
|
}
|
|
2250
|
-
function
|
|
2251
|
-
return e.units <
|
|
2250
|
+
function ar(e) {
|
|
2251
|
+
return e.units < O ? ir(e) : e;
|
|
2252
2252
|
}
|
|
2253
|
-
function
|
|
2254
|
-
let [n, r] =
|
|
2253
|
+
function F(e, t) {
|
|
2254
|
+
let [n, r] = lr(e, t);
|
|
2255
2255
|
return n < r ? -1 : +(n > r);
|
|
2256
2256
|
}
|
|
2257
|
-
function
|
|
2258
|
-
return e.units ===
|
|
2257
|
+
function or(e) {
|
|
2258
|
+
return e.units === O;
|
|
2259
2259
|
}
|
|
2260
|
-
function
|
|
2260
|
+
function sr(e) {
|
|
2261
2261
|
return e.scale === 0;
|
|
2262
2262
|
}
|
|
2263
|
-
function
|
|
2263
|
+
function I(e, t, n) {
|
|
2264
2264
|
if (e.scale <= t) return e;
|
|
2265
|
-
let r =
|
|
2266
|
-
s !==
|
|
2265
|
+
let r = k ** BigInt(e.scale - t), i = e.units < O, a = i ? -e.units : e.units, o = a / r, s = a % r;
|
|
2266
|
+
s !== O && (n === "up" || n === "half" && s * $n >= r) && (o += Qn);
|
|
2267
2267
|
let c = i ? -o : o;
|
|
2268
|
-
return
|
|
2268
|
+
return ur(t >= 0 ? {
|
|
2269
2269
|
units: c,
|
|
2270
2270
|
scale: t
|
|
2271
2271
|
} : {
|
|
2272
|
-
units: c *
|
|
2272
|
+
units: c * k ** BigInt(-t),
|
|
2273
2273
|
scale: 0
|
|
2274
2274
|
});
|
|
2275
2275
|
}
|
|
2276
|
-
function
|
|
2277
|
-
if (!
|
|
2278
|
-
let n = Number(t.units <
|
|
2279
|
-
for (let t = 0; t < n; t++) r =
|
|
2280
|
-
return t.units <
|
|
2276
|
+
function cr(e, t) {
|
|
2277
|
+
if (!sr(t) || t.units > er || t.units < -er) return null;
|
|
2278
|
+
let n = Number(t.units < O ? -t.units : t.units), r = tr;
|
|
2279
|
+
for (let t = 0; t < n; t++) r = rr(r, e);
|
|
2280
|
+
return t.units < O ? P(tr, r) : r;
|
|
2281
2281
|
}
|
|
2282
|
-
function
|
|
2282
|
+
function lr(e, t) {
|
|
2283
2283
|
let n = Math.max(e.scale, t.scale);
|
|
2284
2284
|
return [
|
|
2285
|
-
e.units *
|
|
2286
|
-
t.units *
|
|
2285
|
+
e.units * k ** BigInt(n - e.scale),
|
|
2286
|
+
t.units * k ** BigInt(n - t.scale),
|
|
2287
2287
|
n
|
|
2288
2288
|
];
|
|
2289
2289
|
}
|
|
2290
|
-
function
|
|
2290
|
+
function ur(e) {
|
|
2291
2291
|
let { units: t, scale: n } = e;
|
|
2292
|
-
for (; n > 0 && t %
|
|
2292
|
+
for (; n > 0 && t % k === O;) t /= k, n--;
|
|
2293
2293
|
return Object.freeze({
|
|
2294
2294
|
units: t,
|
|
2295
2295
|
scale: n
|
|
2296
2296
|
});
|
|
2297
2297
|
}
|
|
2298
2298
|
// src/formula/error.ts
|
|
2299
|
-
function
|
|
2299
|
+
function L(e) {
|
|
2300
2300
|
return typeof e == "object" && !!e && !Array.isArray(e) && typeof e.formulaError == "string";
|
|
2301
2301
|
}
|
|
2302
|
-
function
|
|
2302
|
+
function dr(e) {
|
|
2303
2303
|
return Object.freeze({ formulaError: e });
|
|
2304
2304
|
}
|
|
2305
2305
|
// src/formula/evaluate.ts
|
|
2306
|
-
var
|
|
2307
|
-
function
|
|
2306
|
+
var fr = Object.freeze({ type: "empty" });
|
|
2307
|
+
function R(e) {
|
|
2308
2308
|
return Object.freeze({
|
|
2309
2309
|
type: "number",
|
|
2310
2310
|
value: e
|
|
2311
2311
|
});
|
|
2312
2312
|
}
|
|
2313
|
-
function
|
|
2313
|
+
function z(e) {
|
|
2314
2314
|
return Object.freeze({
|
|
2315
2315
|
type: "text",
|
|
2316
2316
|
value: e
|
|
2317
2317
|
});
|
|
2318
2318
|
}
|
|
2319
|
-
function z(e) {
|
|
2320
|
-
return e ? gr : _r;
|
|
2321
|
-
}
|
|
2322
2319
|
function B(e) {
|
|
2320
|
+
return e ? hr : gr;
|
|
2321
|
+
}
|
|
2322
|
+
function V(e) {
|
|
2323
2323
|
return Object.freeze({
|
|
2324
2324
|
type: "error",
|
|
2325
2325
|
code: e
|
|
2326
2326
|
});
|
|
2327
2327
|
}
|
|
2328
|
-
function
|
|
2329
|
-
let t = typeof e == "number" && !Number.isFinite(e) ? null :
|
|
2330
|
-
return t ?
|
|
2328
|
+
function pr(e) {
|
|
2329
|
+
let t = typeof e == "number" && !Number.isFinite(e) ? null : j(String(e));
|
|
2330
|
+
return t ? R(t) : V("#NUM!");
|
|
2331
2331
|
}
|
|
2332
|
-
function
|
|
2333
|
-
let t =
|
|
2334
|
-
return
|
|
2332
|
+
function mr(e) {
|
|
2333
|
+
let t = U(e);
|
|
2334
|
+
return H(t) ? null : M(t);
|
|
2335
2335
|
}
|
|
2336
|
-
var
|
|
2336
|
+
var hr = Object.freeze({
|
|
2337
2337
|
type: "bool",
|
|
2338
2338
|
value: !0
|
|
2339
|
-
}),
|
|
2339
|
+
}), gr = Object.freeze({
|
|
2340
2340
|
type: "bool",
|
|
2341
2341
|
value: !1
|
|
2342
|
-
}),
|
|
2343
|
-
function
|
|
2342
|
+
}), _r = j("100");
|
|
2343
|
+
function H(e) {
|
|
2344
2344
|
return typeof e == "object" && !!e && e.type === "error";
|
|
2345
2345
|
}
|
|
2346
|
-
function
|
|
2346
|
+
function U(e) {
|
|
2347
2347
|
switch (e.type) {
|
|
2348
2348
|
case "number": return e.value;
|
|
2349
|
-
case "empty": return
|
|
2350
|
-
case "bool": return e.value ?
|
|
2351
|
-
case "text": return
|
|
2349
|
+
case "empty": return A;
|
|
2350
|
+
case "bool": return e.value ? tr : A;
|
|
2351
|
+
case "text": return j(e.value) ?? V("#VALUE!");
|
|
2352
2352
|
case "error": return e;
|
|
2353
2353
|
}
|
|
2354
2354
|
}
|
|
2355
|
-
function
|
|
2355
|
+
function vr(e) {
|
|
2356
2356
|
switch (e.type) {
|
|
2357
|
-
case "number": return
|
|
2357
|
+
case "number": return M(e.value);
|
|
2358
2358
|
case "empty": return "";
|
|
2359
2359
|
case "bool": return e.value ? "TRUE" : "FALSE";
|
|
2360
2360
|
case "text": return e.value;
|
|
2361
2361
|
case "error": return e;
|
|
2362
2362
|
}
|
|
2363
2363
|
}
|
|
2364
|
-
function
|
|
2364
|
+
function yr(e) {
|
|
2365
2365
|
switch (e.type) {
|
|
2366
2366
|
case "bool": return e.value;
|
|
2367
|
-
case "number": return !
|
|
2367
|
+
case "number": return !or(e.value);
|
|
2368
2368
|
case "empty": return !1;
|
|
2369
2369
|
case "text": {
|
|
2370
2370
|
let t = e.value.trim().toUpperCase();
|
|
2371
|
-
return t === "TRUE" || t !== "FALSE" &&
|
|
2371
|
+
return t === "TRUE" || t !== "FALSE" && V("#VALUE!");
|
|
2372
2372
|
}
|
|
2373
2373
|
case "error": return e;
|
|
2374
2374
|
}
|
|
2375
2375
|
}
|
|
2376
|
-
function
|
|
2376
|
+
function W(e, t) {
|
|
2377
2377
|
switch (e.kind) {
|
|
2378
|
-
case "number": return
|
|
2379
|
-
case "text": return
|
|
2380
|
-
case "bool": return
|
|
2378
|
+
case "number": return R(j(e.value) ?? A);
|
|
2379
|
+
case "text": return z(e.value);
|
|
2380
|
+
case "bool": return B(e.value);
|
|
2381
2381
|
case "field": return t.field(e.key);
|
|
2382
|
-
case "negate": return W(
|
|
2383
|
-
case "percent": return W(
|
|
2384
|
-
case "binary": return
|
|
2385
|
-
case "call": return
|
|
2382
|
+
case "negate": return G(W(e.operand, t), R(A), (e, t) => nr(t, e));
|
|
2383
|
+
case "percent": return G(W(e.operand, t), R(_r), P);
|
|
2384
|
+
case "binary": return br(e.op, W(e.left, t), W(e.right, t));
|
|
2385
|
+
case "call": return wr(e.name, e.args, t);
|
|
2386
2386
|
}
|
|
2387
2387
|
}
|
|
2388
|
-
function
|
|
2389
|
-
let i =
|
|
2390
|
-
if (
|
|
2391
|
-
let a =
|
|
2392
|
-
if (
|
|
2388
|
+
function G(e, t, n, r = "#DIV/0!") {
|
|
2389
|
+
let i = U(e);
|
|
2390
|
+
if (H(i)) return i;
|
|
2391
|
+
let a = U(t);
|
|
2392
|
+
if (H(a)) return a;
|
|
2393
2393
|
let o = n(i, a);
|
|
2394
|
-
return o === null ?
|
|
2394
|
+
return o === null ? V(r) : R(o);
|
|
2395
2395
|
}
|
|
2396
|
-
function
|
|
2396
|
+
function br(e, t, n) {
|
|
2397
2397
|
switch (e) {
|
|
2398
|
-
case "+": return
|
|
2399
|
-
case "-": return
|
|
2400
|
-
case "*": return
|
|
2401
|
-
case "/": return
|
|
2402
|
-
case "^": return
|
|
2398
|
+
case "+": return G(t, n, N);
|
|
2399
|
+
case "-": return G(t, n, nr);
|
|
2400
|
+
case "*": return G(t, n, rr);
|
|
2401
|
+
case "/": return G(t, n, P);
|
|
2402
|
+
case "^": return G(t, n, cr, "#NUM!");
|
|
2403
2403
|
case "&": {
|
|
2404
|
-
let e =
|
|
2405
|
-
if (
|
|
2406
|
-
let r =
|
|
2407
|
-
return
|
|
2404
|
+
let e = vr(t);
|
|
2405
|
+
if (H(e)) return e;
|
|
2406
|
+
let r = vr(n);
|
|
2407
|
+
return H(r) ? r : z(e + r);
|
|
2408
2408
|
}
|
|
2409
2409
|
default: {
|
|
2410
|
-
let r =
|
|
2411
|
-
return
|
|
2410
|
+
let r = xr(t, n);
|
|
2411
|
+
return H(r) ? r : B(e === "=" ? r === 0 : e === "<>" ? r !== 0 : e === "<" ? r < 0 : e === ">" ? r > 0 : e === "<=" ? r <= 0 : r >= 0);
|
|
2412
2412
|
}
|
|
2413
2413
|
}
|
|
2414
2414
|
}
|
|
2415
|
-
function
|
|
2415
|
+
function xr(e, t) {
|
|
2416
2416
|
if (e.type === "error") return e;
|
|
2417
2417
|
if (t.type === "error") return t;
|
|
2418
|
-
let n = e.type === "empty" ?
|
|
2418
|
+
let n = e.type === "empty" ? Sr(t) : e, r = t.type === "empty" ? Sr(n) : t, i = {
|
|
2419
2419
|
number: 0,
|
|
2420
2420
|
text: 1,
|
|
2421
2421
|
bool: 2,
|
|
2422
2422
|
empty: 0
|
|
2423
2423
|
};
|
|
2424
2424
|
if (n.type !== r.type) return i[n.type] < i[r.type] ? -1 : 1;
|
|
2425
|
-
if (n.type === "number" && r.type === "number") return
|
|
2425
|
+
if (n.type === "number" && r.type === "number") return F(n.value, r.value);
|
|
2426
2426
|
if (n.type === "text" && r.type === "text") {
|
|
2427
2427
|
let e = n.value.toLowerCase(), t = r.value.toLowerCase();
|
|
2428
2428
|
return e < t ? -1 : +(e > t);
|
|
2429
2429
|
}
|
|
2430
2430
|
return n.type === "bool" && r.type === "bool" ? n.value === r.value ? 0 : n.value ? 1 : -1 : 0;
|
|
2431
2431
|
}
|
|
2432
|
-
function
|
|
2433
|
-
return e.type === "text" ?
|
|
2432
|
+
function Sr(e) {
|
|
2433
|
+
return e.type === "text" ? z("") : e.type === "bool" ? gr : R(A);
|
|
2434
2434
|
}
|
|
2435
|
-
var
|
|
2435
|
+
var Cr = [
|
|
2436
2436
|
"ABS",
|
|
2437
2437
|
"AND",
|
|
2438
2438
|
"AVERAGE",
|
|
@@ -2450,111 +2450,111 @@ var wr = [
|
|
|
2450
2450
|
"ROUNDUP",
|
|
2451
2451
|
"SUM"
|
|
2452
2452
|
];
|
|
2453
|
-
function
|
|
2453
|
+
function wr(e, t, n) {
|
|
2454
2454
|
switch (e) {
|
|
2455
2455
|
case "IF": {
|
|
2456
|
-
if (t.length < 2 || t.length > 3) return
|
|
2457
|
-
let e =
|
|
2458
|
-
if (
|
|
2456
|
+
if (t.length < 2 || t.length > 3) return V("#VALUE!");
|
|
2457
|
+
let e = yr(W(t[0], n));
|
|
2458
|
+
if (H(e)) return e;
|
|
2459
2459
|
let r = e ? t[1] : t[2];
|
|
2460
|
-
return r ?
|
|
2460
|
+
return r ? W(r, n) : gr;
|
|
2461
2461
|
}
|
|
2462
2462
|
case "IFERROR": {
|
|
2463
|
-
if (t.length !== 2) return
|
|
2464
|
-
let e =
|
|
2465
|
-
return e.type === "error" ?
|
|
2463
|
+
if (t.length !== 2) return V("#VALUE!");
|
|
2464
|
+
let e = W(t[0], n);
|
|
2465
|
+
return e.type === "error" ? W(t[1], n) : e;
|
|
2466
2466
|
}
|
|
2467
|
-
case "ISBLANK": return t.length === 1 ?
|
|
2467
|
+
case "ISBLANK": return t.length === 1 ? B(W(t[0], n).type === "empty") : V("#VALUE!");
|
|
2468
2468
|
}
|
|
2469
|
-
let r = t.map((e) =>
|
|
2469
|
+
let r = t.map((e) => W(e, n)), i = Or[e];
|
|
2470
2470
|
if (i) return i(r);
|
|
2471
2471
|
let a = n.functions[e];
|
|
2472
|
-
if (!a) return
|
|
2472
|
+
if (!a) return V("#NAME?");
|
|
2473
2473
|
try {
|
|
2474
2474
|
return a(r);
|
|
2475
2475
|
} catch {
|
|
2476
|
-
return
|
|
2476
|
+
return V("#VALUE!");
|
|
2477
2477
|
}
|
|
2478
2478
|
}
|
|
2479
|
-
function
|
|
2479
|
+
function Tr(e) {
|
|
2480
2480
|
let t = [];
|
|
2481
2481
|
for (let n of e) {
|
|
2482
2482
|
if (n.type === "empty") continue;
|
|
2483
|
-
let e =
|
|
2484
|
-
if (
|
|
2483
|
+
let e = U(n);
|
|
2484
|
+
if (H(e)) return e;
|
|
2485
2485
|
t.push(e);
|
|
2486
2486
|
}
|
|
2487
2487
|
return t;
|
|
2488
2488
|
}
|
|
2489
|
-
function
|
|
2489
|
+
function Er(e) {
|
|
2490
2490
|
return (t) => {
|
|
2491
|
-
if (t.length < 1 || t.length > 2) return
|
|
2492
|
-
let n =
|
|
2493
|
-
return
|
|
2491
|
+
if (t.length < 1 || t.length > 2) return V("#VALUE!");
|
|
2492
|
+
let n = U(t[0]), r = U(t[1] ?? R(A));
|
|
2493
|
+
return H(n) ? n : H(r) ? r : R(I(n, Number(M(I(r, 0, "down"))), e));
|
|
2494
2494
|
};
|
|
2495
2495
|
}
|
|
2496
|
-
function
|
|
2496
|
+
function Dr(e) {
|
|
2497
2497
|
return (t) => {
|
|
2498
|
-
if (t.length === 0) return
|
|
2498
|
+
if (t.length === 0) return V("#VALUE!");
|
|
2499
2499
|
let n = e;
|
|
2500
2500
|
for (let r of t) {
|
|
2501
|
-
let t =
|
|
2502
|
-
if (
|
|
2501
|
+
let t = yr(r);
|
|
2502
|
+
if (H(t)) return t;
|
|
2503
2503
|
n = e ? n && t : n || t;
|
|
2504
2504
|
}
|
|
2505
|
-
return
|
|
2505
|
+
return B(n);
|
|
2506
2506
|
};
|
|
2507
2507
|
}
|
|
2508
|
-
var
|
|
2508
|
+
var Or = {
|
|
2509
2509
|
SUM: (e) => {
|
|
2510
|
-
let t =
|
|
2511
|
-
return
|
|
2510
|
+
let t = Tr(e);
|
|
2511
|
+
return H(t) ? t : R(t.reduce(N, A));
|
|
2512
2512
|
},
|
|
2513
2513
|
AVERAGE: (e) => {
|
|
2514
|
-
let t =
|
|
2515
|
-
if (
|
|
2516
|
-
if (t.length === 0) return
|
|
2517
|
-
let n =
|
|
2518
|
-
return n === null ?
|
|
2514
|
+
let t = Tr(e);
|
|
2515
|
+
if (H(t)) return t;
|
|
2516
|
+
if (t.length === 0) return V("#DIV/0!");
|
|
2517
|
+
let n = P(t.reduce(N, A), j(String(t.length)));
|
|
2518
|
+
return n === null ? V("#DIV/0!") : R(n);
|
|
2519
2519
|
},
|
|
2520
2520
|
MIN: (e) => {
|
|
2521
|
-
let t =
|
|
2522
|
-
return
|
|
2521
|
+
let t = Tr(e);
|
|
2522
|
+
return H(t) ? t : R(t.reduce((e, t) => F(e, t) <= 0 ? e : t, t[0] ?? A));
|
|
2523
2523
|
},
|
|
2524
2524
|
MAX: (e) => {
|
|
2525
|
-
let t =
|
|
2526
|
-
return
|
|
2525
|
+
let t = Tr(e);
|
|
2526
|
+
return H(t) ? t : R(t.reduce((e, t) => F(e, t) >= 0 ? e : t, t[0] ?? A));
|
|
2527
2527
|
},
|
|
2528
|
-
ROUND:
|
|
2529
|
-
ROUNDUP:
|
|
2530
|
-
ROUNDDOWN:
|
|
2528
|
+
ROUND: Er("half"),
|
|
2529
|
+
ROUNDUP: Er("up"),
|
|
2530
|
+
ROUNDDOWN: Er("down"),
|
|
2531
2531
|
ABS: (e) => {
|
|
2532
|
-
if (e.length !== 1) return
|
|
2533
|
-
let t =
|
|
2534
|
-
return
|
|
2532
|
+
if (e.length !== 1) return V("#VALUE!");
|
|
2533
|
+
let t = U(e[0]);
|
|
2534
|
+
return H(t) ? t : R(ar(t));
|
|
2535
2535
|
},
|
|
2536
|
-
AND:
|
|
2537
|
-
OR:
|
|
2536
|
+
AND: Dr(!0),
|
|
2537
|
+
OR: Dr(!1),
|
|
2538
2538
|
NOT: (e) => {
|
|
2539
|
-
if (e.length !== 1) return
|
|
2540
|
-
let t =
|
|
2541
|
-
return
|
|
2539
|
+
if (e.length !== 1) return V("#VALUE!");
|
|
2540
|
+
let t = yr(e[0]);
|
|
2541
|
+
return H(t) ? t : B(!t);
|
|
2542
2542
|
},
|
|
2543
2543
|
LEN: (e) => {
|
|
2544
|
-
if (e.length !== 1) return
|
|
2545
|
-
let t =
|
|
2546
|
-
return
|
|
2544
|
+
if (e.length !== 1) return V("#VALUE!");
|
|
2545
|
+
let t = vr(e[0]);
|
|
2546
|
+
return H(t) ? t : R(j(String(Array.from(t).length)));
|
|
2547
2547
|
},
|
|
2548
2548
|
CONCAT: (e) => {
|
|
2549
2549
|
let t = "";
|
|
2550
2550
|
for (let n of e) {
|
|
2551
|
-
let e =
|
|
2552
|
-
if (
|
|
2551
|
+
let e = vr(n);
|
|
2552
|
+
if (H(e)) return e;
|
|
2553
2553
|
t += e;
|
|
2554
2554
|
}
|
|
2555
|
-
return
|
|
2555
|
+
return z(t);
|
|
2556
2556
|
}
|
|
2557
|
-
},
|
|
2557
|
+
}, kr = "formula", Ar = class {
|
|
2558
2558
|
#e;
|
|
2559
2559
|
#t;
|
|
2560
2560
|
#n;
|
|
@@ -2562,9 +2562,9 @@ var kr = {
|
|
|
2562
2562
|
#i;
|
|
2563
2563
|
#a;
|
|
2564
2564
|
constructor(e) {
|
|
2565
|
-
this.#e = e.schema, this.#t = e.store, this.#n =
|
|
2565
|
+
this.#e = e.schema, this.#t = e.store, this.#n = Lr(e.functions ?? {}), this.#r = Fr(e.schema), this.#i = Ir(this.#r), this.#a = this.#t.derive((e) => this.#o(e)), this.#t.transact(() => {
|
|
2566
2566
|
for (let e of this.#t.rowIds()) this.#s(e, this.#r);
|
|
2567
|
-
}, { origin:
|
|
2567
|
+
}, { origin: kr });
|
|
2568
2568
|
}
|
|
2569
2569
|
compute(e, t) {
|
|
2570
2570
|
let n = this.#r.find((e) => e.field.key === t);
|
|
@@ -2584,7 +2584,7 @@ var kr = {
|
|
|
2584
2584
|
for (let [e, n] of t) this.#t.has(e) && this.#s(e, n === "all" ? this.#r : this.#c(n));
|
|
2585
2585
|
}
|
|
2586
2586
|
#s(e, t) {
|
|
2587
|
-
for (let [n, r] of this.#l(e, t))
|
|
2587
|
+
for (let [n, r] of this.#l(e, t)) En(this.#t.get(e, n), r) || this.#t.setCell(e, n, r);
|
|
2588
2588
|
}
|
|
2589
2589
|
#c(e) {
|
|
2590
2590
|
let t = /* @__PURE__ */ new Set();
|
|
@@ -2593,31 +2593,31 @@ var kr = {
|
|
|
2593
2593
|
}
|
|
2594
2594
|
#l(e, t) {
|
|
2595
2595
|
let n = /* @__PURE__ */ new Map(), r = (t) => n.has(t) ? n.get(t) : this.#t.get(e, t);
|
|
2596
|
-
for (let e of t) n.set(e.field.key,
|
|
2596
|
+
for (let e of t) n.set(e.field.key, Mr(e, this.#e, r, this.#n));
|
|
2597
2597
|
return n;
|
|
2598
2598
|
}
|
|
2599
2599
|
};
|
|
2600
|
-
function
|
|
2601
|
-
let r =
|
|
2600
|
+
function jr(e, t, n = {}) {
|
|
2601
|
+
let r = Fr(e), i = Lr(n);
|
|
2602
2602
|
return r.length === 0 ? [...t] : t.map((t) => {
|
|
2603
2603
|
let n = { ...t.values }, a = (e) => n[e] ?? null;
|
|
2604
|
-
for (let t of r) n[t.field.key] =
|
|
2604
|
+
for (let t of r) n[t.field.key] = Mr(t, e, a, i);
|
|
2605
2605
|
return {
|
|
2606
2606
|
...t,
|
|
2607
2607
|
values: n
|
|
2608
2608
|
};
|
|
2609
2609
|
});
|
|
2610
2610
|
}
|
|
2611
|
-
function
|
|
2612
|
-
let i =
|
|
2613
|
-
field: (e) => t.has(e) ?
|
|
2611
|
+
function Mr(e, t, n, r) {
|
|
2612
|
+
let i = W(e.tree, {
|
|
2613
|
+
field: (e) => t.has(e) ? Nr(t.field(e), n(e)) : fr,
|
|
2614
2614
|
functions: r
|
|
2615
2615
|
});
|
|
2616
|
-
return
|
|
2616
|
+
return Pr(e.field, i);
|
|
2617
2617
|
}
|
|
2618
|
-
function
|
|
2619
|
-
if (t === null) return
|
|
2620
|
-
if (
|
|
2618
|
+
function Nr(e, t) {
|
|
2619
|
+
if (t === null) return fr;
|
|
2620
|
+
if (L(t)) return {
|
|
2621
2621
|
type: "error",
|
|
2622
2622
|
code: t.formulaError
|
|
2623
2623
|
};
|
|
@@ -2627,21 +2627,21 @@ function Pr(e, t) {
|
|
|
2627
2627
|
case "quantity":
|
|
2628
2628
|
case "money":
|
|
2629
2629
|
case "percent": {
|
|
2630
|
-
let e = m(t), n = e === null ? null :
|
|
2631
|
-
return n ?
|
|
2630
|
+
let e = m(t), n = e === null ? null : j(e);
|
|
2631
|
+
return n ? R(n) : z(y(t));
|
|
2632
2632
|
}
|
|
2633
|
-
case "bool": return typeof t == "boolean" ?
|
|
2634
|
-
case "lookup": return
|
|
2633
|
+
case "bool": return typeof t == "boolean" ? B(t) : z(y(t));
|
|
2634
|
+
case "lookup": return z(b(t) ? t.label : y(t));
|
|
2635
2635
|
case "options": {
|
|
2636
|
-
if (Array.isArray(t)) return
|
|
2637
|
-
let e = typeof t == "number" ?
|
|
2638
|
-
return e ?
|
|
2636
|
+
if (Array.isArray(t)) return z(t.map(y).join(", "));
|
|
2637
|
+
let e = typeof t == "number" ? j(y(t)) : null;
|
|
2638
|
+
return e ? R(e) : z(y(t));
|
|
2639
2639
|
}
|
|
2640
|
-
default: return
|
|
2640
|
+
default: return z(y(t));
|
|
2641
2641
|
}
|
|
2642
2642
|
}
|
|
2643
|
-
function
|
|
2644
|
-
if (t.type === "error") return
|
|
2643
|
+
function Pr(e, t) {
|
|
2644
|
+
if (t.type === "error") return dr(t.code);
|
|
2645
2645
|
if (t.type === "empty") return null;
|
|
2646
2646
|
switch (e.type) {
|
|
2647
2647
|
case "integer":
|
|
@@ -2649,29 +2649,29 @@ function Fr(e, t) {
|
|
|
2649
2649
|
case "quantity":
|
|
2650
2650
|
case "money":
|
|
2651
2651
|
case "percent": {
|
|
2652
|
-
let n =
|
|
2653
|
-
if ("type" in n) return
|
|
2652
|
+
let n = U(t);
|
|
2653
|
+
if ("type" in n) return dr(n.code);
|
|
2654
2654
|
let r = e.type === "integer" ? 0 : e.decimals;
|
|
2655
|
-
return
|
|
2655
|
+
return M(r === null ? n : I(n, r, "half"));
|
|
2656
2656
|
}
|
|
2657
2657
|
case "bool": {
|
|
2658
|
-
let e =
|
|
2659
|
-
return typeof e == "boolean" ? e :
|
|
2658
|
+
let e = yr(t);
|
|
2659
|
+
return typeof e == "boolean" ? e : dr(e.code);
|
|
2660
2660
|
}
|
|
2661
2661
|
default: {
|
|
2662
|
-
let e =
|
|
2663
|
-
return typeof e == "string" ? e :
|
|
2662
|
+
let e = vr(t);
|
|
2663
|
+
return typeof e == "string" ? e : dr(e.code);
|
|
2664
2664
|
}
|
|
2665
2665
|
}
|
|
2666
2666
|
}
|
|
2667
|
-
function
|
|
2667
|
+
function Fr(e) {
|
|
2668
2668
|
let t = /* @__PURE__ */ new Map();
|
|
2669
2669
|
for (let n of e.fields) if (n.formula !== null) {
|
|
2670
|
-
let e =
|
|
2670
|
+
let e = Mt(n.formula);
|
|
2671
2671
|
t.set(n.key, {
|
|
2672
2672
|
field: n,
|
|
2673
2673
|
tree: e,
|
|
2674
|
-
reads:
|
|
2674
|
+
reads: Nt(e)
|
|
2675
2675
|
});
|
|
2676
2676
|
}
|
|
2677
2677
|
let n = [], r = /* @__PURE__ */ new Set(), i = (e) => {
|
|
@@ -2684,9 +2684,9 @@ function Ir(e) {
|
|
|
2684
2684
|
for (let e of t.keys()) i(e);
|
|
2685
2685
|
return n;
|
|
2686
2686
|
}
|
|
2687
|
-
function
|
|
2687
|
+
function Ir(e) {
|
|
2688
2688
|
let t = /* @__PURE__ */ new Map();
|
|
2689
|
-
for (let n of e) for (let e of
|
|
2689
|
+
for (let n of e) for (let e of Nt(n.tree)) {
|
|
2690
2690
|
let r = t.get(e) ?? [];
|
|
2691
2691
|
r.push(n), t.set(e, r);
|
|
2692
2692
|
}
|
|
@@ -2699,12 +2699,12 @@ function Lr(e) {
|
|
|
2699
2699
|
}
|
|
2700
2700
|
return n;
|
|
2701
2701
|
}
|
|
2702
|
-
function
|
|
2702
|
+
function Lr(e) {
|
|
2703
2703
|
return Object.fromEntries(Object.entries(e).map(([e, t]) => [e.toUpperCase(), t]));
|
|
2704
2704
|
}
|
|
2705
2705
|
// src/formula/assist.ts
|
|
2706
|
-
var
|
|
2707
|
-
function
|
|
2706
|
+
var Rr = /[A-Za-z_]/, zr = /[A-Za-z0-9_.]/;
|
|
2707
|
+
function Br(e, t) {
|
|
2708
2708
|
let n = Math.max(0, Math.min(t, e.length)), r = [], i = !1, a = -1, o = "";
|
|
2709
2709
|
for (let t = 0; t < n; t++) {
|
|
2710
2710
|
let s = e.charAt(t);
|
|
@@ -2720,23 +2720,23 @@ function Vr(e, t) {
|
|
|
2720
2720
|
else if (s === "," || s === ";") {
|
|
2721
2721
|
let e = r[r.length - 1];
|
|
2722
2722
|
e && e.argument++, o = "";
|
|
2723
|
-
} else (o === "" ?
|
|
2723
|
+
} else (o === "" ? Rr.test(s) : zr.test(s)) ? o += s : o = "";
|
|
2724
2724
|
}
|
|
2725
2725
|
return {
|
|
2726
|
-
token:
|
|
2727
|
-
call:
|
|
2726
|
+
token: Ur(e, n, i, a, o),
|
|
2727
|
+
call: Wr(r)
|
|
2728
2728
|
};
|
|
2729
2729
|
}
|
|
2730
|
-
function
|
|
2730
|
+
function Vr(e, t) {
|
|
2731
2731
|
let n = new Map(t.map((e) => [e.key, e.label]));
|
|
2732
|
-
return
|
|
2732
|
+
return Gr(e, (e) => n.get(e) ?? e);
|
|
2733
2733
|
}
|
|
2734
|
-
function
|
|
2734
|
+
function Hr(e, t) {
|
|
2735
2735
|
let n = new Set(t.map((e) => e.key)), r = /* @__PURE__ */ new Map();
|
|
2736
2736
|
for (let e of t) r.set(e.label, r.has(e.label) ? null : e.key);
|
|
2737
|
-
return
|
|
2737
|
+
return Gr(e, (e) => n.has(e) ? e : r.get(e) ?? e);
|
|
2738
2738
|
}
|
|
2739
|
-
function
|
|
2739
|
+
function Ur(e, t, n, r, i) {
|
|
2740
2740
|
if (n) return null;
|
|
2741
2741
|
if (r >= 0) {
|
|
2742
2742
|
let n = e.indexOf("]", t), i = e.indexOf("[", t), a = n >= 0 && (i < 0 || n < i) ? n + 1 : t;
|
|
@@ -2749,7 +2749,7 @@ function Wr(e, t, n, r, i) {
|
|
|
2749
2749
|
}
|
|
2750
2750
|
if (i === "" || /^[0-9.]/.test(i)) return null;
|
|
2751
2751
|
let a = t;
|
|
2752
|
-
for (; a < e.length &&
|
|
2752
|
+
for (; a < e.length && zr.test(e.charAt(a));) a++;
|
|
2753
2753
|
return {
|
|
2754
2754
|
kind: "function",
|
|
2755
2755
|
query: i,
|
|
@@ -2757,7 +2757,7 @@ function Wr(e, t, n, r, i) {
|
|
|
2757
2757
|
end: a
|
|
2758
2758
|
};
|
|
2759
2759
|
}
|
|
2760
|
-
function
|
|
2760
|
+
function Wr(e) {
|
|
2761
2761
|
for (let t = e.length - 1; t >= 0; t--) {
|
|
2762
2762
|
let n = e[t];
|
|
2763
2763
|
if (n?.name) return {
|
|
@@ -2767,7 +2767,7 @@ function Gr(e) {
|
|
|
2767
2767
|
}
|
|
2768
2768
|
return null;
|
|
2769
2769
|
}
|
|
2770
|
-
function
|
|
2770
|
+
function Gr(e, t) {
|
|
2771
2771
|
let n = "", r = !1;
|
|
2772
2772
|
for (let i = 0; i < e.length; i++) {
|
|
2773
2773
|
let a = e.charAt(i);
|
|
@@ -2784,32 +2784,32 @@ function Kr(e, t) {
|
|
|
2784
2784
|
}
|
|
2785
2785
|
return n;
|
|
2786
2786
|
}
|
|
2787
|
-
var
|
|
2788
|
-
function
|
|
2787
|
+
var Kr = /^([A-Za-z]{1,3})([0-9]*)$/;
|
|
2788
|
+
function qr(e, t) {
|
|
2789
2789
|
let n = "", r = 0;
|
|
2790
2790
|
for (; r < e.length;) {
|
|
2791
2791
|
let i = e.charAt(r);
|
|
2792
2792
|
if (i === "\"") {
|
|
2793
|
-
let t =
|
|
2793
|
+
let t = Yr(e, r);
|
|
2794
2794
|
n += e.slice(r, t), r = t;
|
|
2795
2795
|
} else if (i === "[") {
|
|
2796
2796
|
let t = e.indexOf("]", r + 1), i = t < 0 ? e.length : t + 1;
|
|
2797
2797
|
n += e.slice(r, i), r = i;
|
|
2798
|
-
} else if (
|
|
2798
|
+
} else if (Rr.test(i) && !zr.test(e.charAt(r - 1))) {
|
|
2799
2799
|
let i = r;
|
|
2800
|
-
for (; i < e.length &&
|
|
2801
|
-
let a = e.slice(r, i), o =
|
|
2800
|
+
for (; i < e.length && zr.test(e.charAt(i));) i++;
|
|
2801
|
+
let a = e.slice(r, i), o = Xr(a, e.slice(i)), s = o === null ? void 0 : t[o];
|
|
2802
2802
|
n += s ? `[${s.label}]` : a, r = i;
|
|
2803
2803
|
} else n += i, r++;
|
|
2804
2804
|
}
|
|
2805
2805
|
return n;
|
|
2806
2806
|
}
|
|
2807
|
-
function
|
|
2807
|
+
function Jr(e, t) {
|
|
2808
2808
|
let n = new Map(t.map((e) => [e.key, e.label])), r = [], i = "", a = 0;
|
|
2809
2809
|
for (; a < e.length;) {
|
|
2810
2810
|
let t = e.charAt(a);
|
|
2811
2811
|
if (t === "\"") {
|
|
2812
|
-
let t =
|
|
2812
|
+
let t = Yr(e, a);
|
|
2813
2813
|
i += e.slice(a, t), a = t;
|
|
2814
2814
|
} else if (t === "[") {
|
|
2815
2815
|
let t = e.indexOf("]", a + 1);
|
|
@@ -2832,7 +2832,7 @@ function Yr(e, t) {
|
|
|
2832
2832
|
field: null
|
|
2833
2833
|
}), r;
|
|
2834
2834
|
}
|
|
2835
|
-
function
|
|
2835
|
+
function Yr(e, t) {
|
|
2836
2836
|
let n = t + 1;
|
|
2837
2837
|
for (; n < e.length;) {
|
|
2838
2838
|
if (e.charAt(n) === "\"") {
|
|
@@ -2846,17 +2846,17 @@ function Xr(e, t) {
|
|
|
2846
2846
|
}
|
|
2847
2847
|
return e.length;
|
|
2848
2848
|
}
|
|
2849
|
-
function
|
|
2850
|
-
let n =
|
|
2849
|
+
function Xr(e, t) {
|
|
2850
|
+
let n = Kr.exec(e), r = e.toUpperCase();
|
|
2851
2851
|
if (!n || t.trimStart().startsWith("(") || r === "TRUE" || r === "FALSE") return null;
|
|
2852
2852
|
let i = 0;
|
|
2853
2853
|
for (let e of (n[1] ?? "").toUpperCase()) i = i * 26 + (e.charCodeAt(0) - 64);
|
|
2854
2854
|
return i - 1;
|
|
2855
2855
|
}
|
|
2856
2856
|
// src/view.ts
|
|
2857
|
-
var
|
|
2857
|
+
var Zr = "default", Qr = class {
|
|
2858
2858
|
store;
|
|
2859
|
-
#e = new
|
|
2859
|
+
#e = new S();
|
|
2860
2860
|
#t;
|
|
2861
2861
|
#n = /* @__PURE__ */ new Map();
|
|
2862
2862
|
#r = null;
|
|
@@ -2887,7 +2887,7 @@ var Qr = "default", $r = class {
|
|
|
2887
2887
|
indexOf(e) {
|
|
2888
2888
|
return this.#i ? (this.#a ||= new Map(this.#i.map((e, t) => [e, t])), this.#a.get(e) ?? -1) : this.store.indexOf(e);
|
|
2889
2889
|
}
|
|
2890
|
-
filter(e, t =
|
|
2890
|
+
filter(e, t = Zr) {
|
|
2891
2891
|
this.#n.set(t, e), this.#s();
|
|
2892
2892
|
}
|
|
2893
2893
|
sort(e) {
|
|
@@ -2944,29 +2944,29 @@ var Qr = "default", $r = class {
|
|
|
2944
2944
|
this.#o++, this.#e.emit(this);
|
|
2945
2945
|
}
|
|
2946
2946
|
};
|
|
2947
|
-
function
|
|
2947
|
+
function $r(e) {
|
|
2948
2948
|
return (t) => e.hasIssues(t);
|
|
2949
2949
|
}
|
|
2950
|
-
function
|
|
2950
|
+
function ei(e, t) {
|
|
2951
2951
|
return (n) => {
|
|
2952
2952
|
let r = e.resultOf(n)?.outcome;
|
|
2953
2953
|
return r !== void 0 && t.includes(r);
|
|
2954
2954
|
};
|
|
2955
2955
|
}
|
|
2956
2956
|
// src/summary.ts
|
|
2957
|
-
var
|
|
2957
|
+
var ti = /* @__PURE__ */ new Set([
|
|
2958
2958
|
"integer",
|
|
2959
2959
|
"decimal",
|
|
2960
2960
|
"money",
|
|
2961
2961
|
"quantity",
|
|
2962
2962
|
"percent"
|
|
2963
|
-
]),
|
|
2964
|
-
function
|
|
2965
|
-
let t = 0, n = 0, r =
|
|
2963
|
+
]), ni = 10;
|
|
2964
|
+
function ri(e) {
|
|
2965
|
+
let t = 0, n = 0, r = A, i = null, a = null;
|
|
2966
2966
|
for (let { field: o, value: s } of e) {
|
|
2967
|
-
if (s === null || (t++, !
|
|
2968
|
-
let e = m(s), c = e === null ? null :
|
|
2969
|
-
c !== null && (n++, r =
|
|
2967
|
+
if (s === null || (t++, !ti.has(o.type) || L(s))) continue;
|
|
2968
|
+
let e = m(s), c = e === null ? null : j(e);
|
|
2969
|
+
c !== null && (n++, r = N(r, c), i = i === null || F(c, i) < 0 ? c : i, a = a === null || F(c, a) > 0 ? c : a);
|
|
2970
2970
|
}
|
|
2971
2971
|
if (n === 0 || i === null || a === null) return Object.freeze({
|
|
2972
2972
|
filled: t,
|
|
@@ -2976,21 +2976,21 @@ function ii(e) {
|
|
|
2976
2976
|
min: null,
|
|
2977
2977
|
max: null
|
|
2978
2978
|
});
|
|
2979
|
-
let o =
|
|
2979
|
+
let o = P(r, j(String(n)) ?? A);
|
|
2980
2980
|
return Object.freeze({
|
|
2981
2981
|
filled: t,
|
|
2982
2982
|
numbers: n,
|
|
2983
|
-
sum:
|
|
2984
|
-
average: o === null ? null :
|
|
2985
|
-
min:
|
|
2986
|
-
max:
|
|
2983
|
+
sum: M(r),
|
|
2984
|
+
average: o === null ? null : M(I(o, ni, "half")),
|
|
2985
|
+
min: M(i),
|
|
2986
|
+
max: M(a)
|
|
2987
2987
|
});
|
|
2988
2988
|
}
|
|
2989
2989
|
// src/values/format.ts
|
|
2990
|
-
function
|
|
2990
|
+
function ii(e, t, n, r = {}) {
|
|
2991
2991
|
if (t === null) return "";
|
|
2992
|
-
if (
|
|
2993
|
-
if (!
|
|
2992
|
+
if (L(t)) return t.formulaError;
|
|
2993
|
+
if (!v(e, t)) return y(t);
|
|
2994
2994
|
switch (e.type) {
|
|
2995
2995
|
case "integer":
|
|
2996
2996
|
case "decimal":
|
|
@@ -3002,25 +3002,25 @@ function G(e, t, n, r = {}) {
|
|
|
3002
3002
|
}
|
|
3003
3003
|
case "bool": return t ? n.trueWord : n.falseWord;
|
|
3004
3004
|
case "date":
|
|
3005
|
-
case "datetime": return Oe(t, e.type === "datetime",
|
|
3006
|
-
case "options": return (Array.isArray(t) ? t : [t]).map((t) => e.options.find((e) => e.value === t)?.label ??
|
|
3007
|
-
case "lookup": return
|
|
3008
|
-
case "string": return
|
|
3005
|
+
case "datetime": return Oe(t, e.type === "datetime", Ue(e, n)) ?? y(t);
|
|
3006
|
+
case "options": return (Array.isArray(t) ? t : [t]).map((t) => e.options.find((e) => e.value === t)?.label ?? y(t)).join(", ");
|
|
3007
|
+
case "lookup": return b(t) ? t.label : y(t);
|
|
3008
|
+
case "string": return y(t);
|
|
3009
3009
|
}
|
|
3010
3010
|
}
|
|
3011
3011
|
function ai(e, t, n) {
|
|
3012
3012
|
if (t === null) return "";
|
|
3013
|
-
if (
|
|
3013
|
+
if (L(t)) return t.formulaError;
|
|
3014
3014
|
switch (e.type) {
|
|
3015
3015
|
case "integer":
|
|
3016
3016
|
case "decimal":
|
|
3017
3017
|
case "quantity":
|
|
3018
3018
|
case "percent":
|
|
3019
3019
|
case "money": {
|
|
3020
|
-
let r =
|
|
3021
|
-
return r === null ?
|
|
3020
|
+
let r = v(e, t) ? m(t) : null;
|
|
3021
|
+
return r === null ? y(t) : oe(r, n);
|
|
3022
3022
|
}
|
|
3023
|
-
default: return
|
|
3023
|
+
default: return ii(e, t, n);
|
|
3024
3024
|
}
|
|
3025
3025
|
}
|
|
3026
3026
|
function oi(e, t) {
|
|
@@ -3101,8 +3101,8 @@ function di(e) {
|
|
|
3101
3101
|
}
|
|
3102
3102
|
function fi(e, t) {
|
|
3103
3103
|
if (t === null) return "";
|
|
3104
|
-
if (
|
|
3105
|
-
if (e.type === "lookup") return
|
|
3104
|
+
if (L(t)) return `error:${t.formulaError}`;
|
|
3105
|
+
if (e.type === "lookup") return b(t) ? `id:${typeof t.id}:${t.id}` : `text:${String(t)}`;
|
|
3106
3106
|
if (li.has(e.type)) {
|
|
3107
3107
|
let e = m(t), n = e === null ? null : r(e);
|
|
3108
3108
|
if (n !== null) return `number:${n}`;
|
|
@@ -3137,7 +3137,7 @@ function gi(e, t, n, r = {}) {
|
|
|
3137
3137
|
let c = (e) => e.toLocaleLowerCase(i).includes(o);
|
|
3138
3138
|
return (t) => s.some((n) => {
|
|
3139
3139
|
let r = e.get(t, n.key);
|
|
3140
|
-
return r !== null && (c(
|
|
3140
|
+
return r !== null && (c(ii(n, r, a)) || li.has(n.type) && c(ai(n, r, a)));
|
|
3141
3141
|
});
|
|
3142
3142
|
}
|
|
3143
3143
|
function _i(e, t, n, r) {
|
|
@@ -3147,7 +3147,7 @@ function _i(e, t, n, r) {
|
|
|
3147
3147
|
return (n === null || a(i, n) >= 0) && (r === null || a(i, r) <= 0);
|
|
3148
3148
|
}
|
|
3149
3149
|
function vi(e, t) {
|
|
3150
|
-
if (t === null ||
|
|
3150
|
+
if (t === null || L(t)) return null;
|
|
3151
3151
|
if (li.has(e.type)) {
|
|
3152
3152
|
let e = m(t);
|
|
3153
3153
|
return e === null ? null : r(e);
|
|
@@ -3163,7 +3163,7 @@ function bi(e, t) {
|
|
|
3163
3163
|
}
|
|
3164
3164
|
function xi(e, t) {
|
|
3165
3165
|
if (t === null) return 2;
|
|
3166
|
-
if (
|
|
3166
|
+
if (L(t)) return 1;
|
|
3167
3167
|
switch (e.type) {
|
|
3168
3168
|
case "integer":
|
|
3169
3169
|
case "decimal":
|
|
@@ -3173,12 +3173,12 @@ function xi(e, t) {
|
|
|
3173
3173
|
case "date":
|
|
3174
3174
|
case "datetime": return +(vi(e, t) === null);
|
|
3175
3175
|
case "bool": return typeof t == "boolean" ? 0 : 1;
|
|
3176
|
-
case "lookup": return +!
|
|
3176
|
+
case "lookup": return +!b(t);
|
|
3177
3177
|
default: return 0;
|
|
3178
3178
|
}
|
|
3179
3179
|
}
|
|
3180
3180
|
function Si(e, t) {
|
|
3181
|
-
return e.type === "options" ? (Array.isArray(t) ? t : [t]).map((t) => e.options.find((e) => e.value === t)?.label ?? String(t)).join(", ") :
|
|
3181
|
+
return e.type === "options" ? (Array.isArray(t) ? t : [t]).map((t) => e.options.find((e) => e.value === t)?.label ?? String(t)).join(", ") : b(t) ? t.label : L(t) ? t.formulaError : typeof t == "string" ? t : JSON.stringify(t);
|
|
3182
3182
|
}
|
|
3183
3183
|
function Ci(e, t, n, r = "tr") {
|
|
3184
3184
|
let i = xi(e, t), a = xi(e, n);
|
|
@@ -3247,7 +3247,7 @@ function Ni(e, t) {
|
|
|
3247
3247
|
let n = zi(e.map((e) => m(e)));
|
|
3248
3248
|
if (n === null) return null;
|
|
3249
3249
|
let r = Li(n, t);
|
|
3250
|
-
return r === null ? null : (e) =>
|
|
3250
|
+
return r === null ? null : (e) => M(Ri(n, r, e));
|
|
3251
3251
|
}
|
|
3252
3252
|
function Pi(e, t) {
|
|
3253
3253
|
let n = e.map((e) => typeof e == "string" ? ki.exec(e) : null), r = n[0]?.[1];
|
|
@@ -3256,7 +3256,7 @@ function Pi(e, t) {
|
|
|
3256
3256
|
if (a === null || o === null) return null;
|
|
3257
3257
|
let s = i.some((e) => e.length > 1 && e.startsWith("0")) ? Math.max(...i.map((e) => e.length)) : 0;
|
|
3258
3258
|
return (e) => {
|
|
3259
|
-
let t =
|
|
3259
|
+
let t = M(Ri(a, o, e)).replace(/^-/, "");
|
|
3260
3260
|
return r + t.padStart(s, "0");
|
|
3261
3261
|
};
|
|
3262
3262
|
}
|
|
@@ -3267,7 +3267,7 @@ function Fi(e, t, n) {
|
|
|
3267
3267
|
if (a !== null) return a;
|
|
3268
3268
|
let o = zi(i.map((e) => String(t ? Hi(e) : Vi(e)))), s = o === null ? null : Li(o, n, !0, t ? Oi : 1);
|
|
3269
3269
|
return o === null || s === null ? null : (e) => {
|
|
3270
|
-
let n = Number(
|
|
3270
|
+
let n = Number(M(Ri(o, s, e)));
|
|
3271
3271
|
return t ? Ki(Wi(n), !0) : Ki(Ui(n), !1);
|
|
3272
3272
|
};
|
|
3273
3273
|
}
|
|
@@ -3288,23 +3288,23 @@ function Ii(e, t, n) {
|
|
|
3288
3288
|
function Li(e, t, n = !1, r = 1) {
|
|
3289
3289
|
let [i, a] = e;
|
|
3290
3290
|
if (i === void 0) return null;
|
|
3291
|
-
if (a === void 0) return (t === "alternate" ? !n : n) ?
|
|
3291
|
+
if (a === void 0) return (t === "alternate" ? !n : n) ? j(String(r)) ?? null : null;
|
|
3292
3292
|
if (t === "alternate") return null;
|
|
3293
|
-
let o =
|
|
3293
|
+
let o = nr(a, i);
|
|
3294
3294
|
for (let t = 2; t < e.length; t++) {
|
|
3295
3295
|
let n = e[t], r = e[t - 1];
|
|
3296
|
-
if (n === void 0 || r === void 0 ||
|
|
3296
|
+
if (n === void 0 || r === void 0 || F(nr(n, r), o) !== 0) return null;
|
|
3297
3297
|
}
|
|
3298
3298
|
return o;
|
|
3299
3299
|
}
|
|
3300
3300
|
function Ri(e, t, n) {
|
|
3301
3301
|
let r = e[0];
|
|
3302
|
-
return
|
|
3302
|
+
return N(r, rr(t, j(String(n))));
|
|
3303
3303
|
}
|
|
3304
3304
|
function zi(e) {
|
|
3305
3305
|
let t = [];
|
|
3306
3306
|
for (let n of e) {
|
|
3307
|
-
let e = n === null ? null :
|
|
3307
|
+
let e = n === null ? null : j(n);
|
|
3308
3308
|
if (e === null) return null;
|
|
3309
3309
|
t.push(e);
|
|
3310
3310
|
}
|
|
@@ -3382,25 +3382,25 @@ function Yi(e) {
|
|
|
3382
3382
|
function Xi(e, t, n, i = K.tr) {
|
|
3383
3383
|
let a = Zi(n);
|
|
3384
3384
|
if (!Yi(e) || t === null) return null;
|
|
3385
|
-
let o = m(
|
|
3385
|
+
let o = m(_(e, t, i)), s = o === null ? null : j(o);
|
|
3386
3386
|
if (o === null || s === null) return null;
|
|
3387
3387
|
let c;
|
|
3388
3388
|
switch (n.kind) {
|
|
3389
3389
|
case "percent":
|
|
3390
|
-
c =
|
|
3390
|
+
c = rr(s, N(tr, P(a, Ji) ?? A));
|
|
3391
3391
|
break;
|
|
3392
3392
|
case "add":
|
|
3393
|
-
c =
|
|
3393
|
+
c = N(s, a);
|
|
3394
3394
|
break;
|
|
3395
|
-
case "round": c =
|
|
3395
|
+
case "round": c = rr(I(P(s, a) ?? A, 0, n.mode ?? "half"), a);
|
|
3396
3396
|
}
|
|
3397
|
-
let l =
|
|
3397
|
+
let l = M(I(c, oi(e, i), "half"));
|
|
3398
3398
|
return l === r(o) ? null : l;
|
|
3399
3399
|
}
|
|
3400
3400
|
function Zi(t) {
|
|
3401
|
-
let n = t.kind === "round" ? t.step : t.by, r = typeof n == "string" ?
|
|
3401
|
+
let n = t.kind === "round" ? t.step : t.by, r = typeof n == "string" ? j(n) : null;
|
|
3402
3402
|
if (r === null) throw new e("invalid_argument", `An adjustment's ${t.kind === "round" ? "step" : "amount"} must be decimal text such as "5" or "0.05"; got ${JSON.stringify(n)}.`);
|
|
3403
|
-
if (t.kind === "round" &&
|
|
3403
|
+
if (t.kind === "round" && F(r, A) <= 0) throw new e("invalid_argument", `A rounding step must be above zero; got "${n}".`);
|
|
3404
3404
|
return r;
|
|
3405
3405
|
}
|
|
3406
3406
|
// src/changes.ts
|
|
@@ -3410,7 +3410,7 @@ var Qi = class {
|
|
|
3410
3410
|
#e;
|
|
3411
3411
|
#t;
|
|
3412
3412
|
#n;
|
|
3413
|
-
#r = new
|
|
3413
|
+
#r = new S();
|
|
3414
3414
|
#i;
|
|
3415
3415
|
#a = /* @__PURE__ */ new Map();
|
|
3416
3416
|
#o = /* @__PURE__ */ new Map();
|
|
@@ -3492,7 +3492,7 @@ var Qi = class {
|
|
|
3492
3492
|
}
|
|
3493
3493
|
#g(e, t) {
|
|
3494
3494
|
if (t == null || t === "") return $i;
|
|
3495
|
-
let n = e.type === "lookup" ? t :
|
|
3495
|
+
let n = e.type === "lookup" ? t : _(e, t, this.#n);
|
|
3496
3496
|
return JSON.stringify(pi(e, n).sort());
|
|
3497
3497
|
}
|
|
3498
3498
|
#_() {
|
|
@@ -3575,19 +3575,37 @@ function da(e, t, n) {
|
|
|
3575
3575
|
for (let t of ["align", "decimals"]) {
|
|
3576
3576
|
if (!(t in n)) continue;
|
|
3577
3577
|
let r = n[t];
|
|
3578
|
-
r === void 0 ? delete e[t] : t === "align" ? e.align =
|
|
3578
|
+
r === void 0 ? delete e[t] : t === "align" ? e.align = va(r) : e.decimals = ya(r);
|
|
3579
3579
|
}
|
|
3580
3580
|
Object.keys(e).length === 0 ? delete r[t] : r[t] = e;
|
|
3581
3581
|
}
|
|
3582
3582
|
let i = Object.fromEntries(Object.entries(e).filter(([e]) => e !== "formats"));
|
|
3583
|
-
return
|
|
3583
|
+
return ha(Object.keys(r).length === 0 ? i : {
|
|
3584
3584
|
...i,
|
|
3585
3585
|
formats: r
|
|
3586
3586
|
});
|
|
3587
3587
|
}
|
|
3588
|
-
function fa(e
|
|
3588
|
+
function fa(...e) {
|
|
3589
|
+
let t = {};
|
|
3590
|
+
for (let n of e) for (let [e, r] of Object.entries(n ?? {})) {
|
|
3591
|
+
let n = { ...t[e] };
|
|
3592
|
+
r.align !== void 0 && (n.align = r.align), r.decimals !== void 0 && (n.decimals = r.decimals), Object.keys(n).length > 0 && (t[e] = n);
|
|
3593
|
+
}
|
|
3594
|
+
return Object.freeze(Object.fromEntries(Object.entries(t).map(([e, t]) => [e, Object.freeze(t)])));
|
|
3595
|
+
}
|
|
3596
|
+
function pa(e, t) {
|
|
3597
|
+
let n = e;
|
|
3598
|
+
for (let [r, i] of Object.entries(e.formats ?? {})) {
|
|
3599
|
+
let e = t?.[r];
|
|
3600
|
+
if (!e) continue;
|
|
3601
|
+
let a = {};
|
|
3602
|
+
i.align !== void 0 && i.align === e.align && (a.align = void 0), i.decimals !== void 0 && i.decimals === e.decimals && (a.decimals = void 0), Object.keys(a).length > 0 && (n = da(n, r, a));
|
|
3603
|
+
}
|
|
3604
|
+
return n;
|
|
3605
|
+
}
|
|
3606
|
+
function ma(e, t, n) {
|
|
3589
3607
|
if (e == null) return;
|
|
3590
|
-
let r =
|
|
3608
|
+
let r = xa(e);
|
|
3591
3609
|
if (!r) {
|
|
3592
3610
|
n(t, "must be an object.");
|
|
3593
3611
|
return;
|
|
@@ -3602,25 +3620,25 @@ function fa(e, t, n) {
|
|
|
3602
3620
|
a !== void 0 && (!Array.isArray(a) || a.some((e) => typeof e != "string") ? n(`${t}.${e}`, "must be a list of field keys.") : i[e] = a);
|
|
3603
3621
|
}
|
|
3604
3622
|
if (r.formats !== void 0 && r.formats !== null) {
|
|
3605
|
-
let e =
|
|
3623
|
+
let e = xa(r.formats);
|
|
3606
3624
|
if (!e) n(`${t}.formats`, "must be an object of formats by field key.");
|
|
3607
3625
|
else {
|
|
3608
3626
|
let r = {};
|
|
3609
3627
|
for (let [i, a] of Object.entries(e)) {
|
|
3610
|
-
let e =
|
|
3628
|
+
let e = xa(a), o = `${t}.formats.${i}`;
|
|
3611
3629
|
if (!e) {
|
|
3612
3630
|
n(o, "must be an object such as { align: \"center\", decimals: 2 }.");
|
|
3613
3631
|
continue;
|
|
3614
3632
|
}
|
|
3615
3633
|
let s = {};
|
|
3616
|
-
e.align !== void 0 && (sa.includes(e.align) ? s.align = e.align : n(`${o}.align`, `must be one of ${sa.join(", ")}.`)), e.decimals !== void 0 && (
|
|
3634
|
+
e.align !== void 0 && (sa.includes(e.align) ? s.align = e.align : n(`${o}.align`, `must be one of ${sa.join(", ")}.`)), e.decimals !== void 0 && (ba(e.decimals) ? s.decimals = e.decimals : n(`${o}.decimals`, "must be a whole number from 0 to 6.")), Object.keys(s).length > 0 && (r[i] = s);
|
|
3617
3635
|
}
|
|
3618
3636
|
Object.keys(r).length > 0 && (i.formats = r);
|
|
3619
3637
|
}
|
|
3620
3638
|
}
|
|
3621
|
-
return
|
|
3639
|
+
return ha(i);
|
|
3622
3640
|
}
|
|
3623
|
-
function
|
|
3641
|
+
function ha(e) {
|
|
3624
3642
|
return Object.freeze({
|
|
3625
3643
|
...e.order ? { order: Object.freeze([...e.order]) } : {},
|
|
3626
3644
|
...e.hidden ? { hidden: Object.freeze([...e.hidden]) } : {},
|
|
@@ -3628,55 +3646,55 @@ function pa(e) {
|
|
|
3628
3646
|
...e.formats && Object.keys(e.formats).length > 0 ? { formats: Object.freeze(Object.fromEntries(Object.entries(e.formats).map(([e, t]) => [e, Object.freeze({ ...t })]))) } : {}
|
|
3629
3647
|
});
|
|
3630
3648
|
}
|
|
3631
|
-
function
|
|
3649
|
+
function ga(e, t) {
|
|
3632
3650
|
let n = (e) => e.map(t).filter((e) => e !== null), r = {};
|
|
3633
3651
|
for (let [n, i] of Object.entries(e.formats ?? {})) {
|
|
3634
3652
|
let e = t(n);
|
|
3635
3653
|
e !== null && (r[e] = i);
|
|
3636
3654
|
}
|
|
3637
|
-
return
|
|
3655
|
+
return ha({
|
|
3638
3656
|
...e.order ? { order: n(e.order) } : {},
|
|
3639
3657
|
...e.hidden ? { hidden: n(e.hidden) } : {},
|
|
3640
3658
|
...e.pinned ? { pinned: n(e.pinned) } : {},
|
|
3641
3659
|
...Object.keys(r).length > 0 ? { formats: r } : {}
|
|
3642
3660
|
});
|
|
3643
3661
|
}
|
|
3644
|
-
function
|
|
3662
|
+
function _a(e, t) {
|
|
3645
3663
|
let n = e.formats ?? {}, r = t.formats ?? {}, i = Object.keys(n);
|
|
3646
3664
|
return i.length === Object.keys(r).length && i.every((e) => n[e]?.align === r[e]?.align && n[e]?.decimals === r[e]?.decimals);
|
|
3647
3665
|
}
|
|
3648
|
-
function
|
|
3666
|
+
function va(t) {
|
|
3649
3667
|
if (!sa.includes(t)) throw new e("invalid_argument", `A column aligns ${sa.join(", ")}; got ${String(t)}.`);
|
|
3650
3668
|
return t;
|
|
3651
3669
|
}
|
|
3652
|
-
function
|
|
3653
|
-
if (!
|
|
3670
|
+
function ya(t) {
|
|
3671
|
+
if (!ba(t)) throw new e("invalid_argument", `A column shows 0 to 6 digits after the point; got ${String(t)}.`);
|
|
3654
3672
|
return t;
|
|
3655
3673
|
}
|
|
3656
|
-
function
|
|
3674
|
+
function ba(e) {
|
|
3657
3675
|
return Number.isSafeInteger(e) && e >= 0 && e <= 6;
|
|
3658
3676
|
}
|
|
3659
|
-
function
|
|
3677
|
+
function xa(e) {
|
|
3660
3678
|
return typeof e == "object" && e && !Array.isArray(e) ? e : null;
|
|
3661
3679
|
}
|
|
3662
3680
|
// src/views.ts
|
|
3663
|
-
var
|
|
3681
|
+
var Sa = "tabula-grid.views", Ca = 1, wa = 60, Ta = Object.freeze({
|
|
3664
3682
|
columns: Object.freeze({}),
|
|
3665
3683
|
columnWidths: Object.freeze({}),
|
|
3666
3684
|
filters: Object.freeze({}),
|
|
3667
3685
|
sort: null
|
|
3668
3686
|
});
|
|
3669
|
-
function
|
|
3670
|
-
return
|
|
3687
|
+
function Ea(e) {
|
|
3688
|
+
return Za({
|
|
3671
3689
|
module: e,
|
|
3672
3690
|
views: [],
|
|
3673
3691
|
defaultId: null
|
|
3674
3692
|
});
|
|
3675
3693
|
}
|
|
3676
|
-
function
|
|
3694
|
+
function Da(e, t) {
|
|
3677
3695
|
let n = (e) => t.has(e), r = (e) => e === void 0 ? void 0 : e.filter(n), i = e.columns, a = r(i.order), o = r(i.hidden), s = r(i.pinned), c = Object.fromEntries(Object.entries(i.formats ?? {}).filter(([e]) => n(e))), l = {};
|
|
3678
3696
|
for (let [r, i] of Object.entries(e.filters)) n(r) && (i.kind === "values" || di(t.field(r))) && (l[r] = i);
|
|
3679
|
-
return
|
|
3697
|
+
return Xa({
|
|
3680
3698
|
columns: {
|
|
3681
3699
|
...a ? { order: a } : {},
|
|
3682
3700
|
...o ? { hidden: o } : {},
|
|
@@ -3688,24 +3706,24 @@ function Ta(e, t) {
|
|
|
3688
3706
|
sort: e.sort && n(e.sort.key) ? e.sort : null
|
|
3689
3707
|
});
|
|
3690
3708
|
}
|
|
3691
|
-
function
|
|
3692
|
-
let r =
|
|
3709
|
+
function Oa(e, t, n) {
|
|
3710
|
+
let r = Da(t, e), i = Da(n, e), a = (t) => {
|
|
3693
3711
|
let { fields: n, pinned: r } = la(e.fields, t.columns);
|
|
3694
3712
|
return `${r}|${n.map((e) => e.key).join(",")}`;
|
|
3695
3713
|
};
|
|
3696
|
-
return a(r) === a(i) &&
|
|
3714
|
+
return a(r) === a(i) && _a(r.columns, i.columns) && Ha(r.columnWidths, i.columnWidths, (e, t) => e === t) && Ha(r.filters, i.filters, Ua) && (r.sort === null || i.sort === null ? r.sort === i.sort : r.sort.key === i.sort.key && r.sort.direction === i.sort.direction);
|
|
3697
3715
|
}
|
|
3698
|
-
function
|
|
3716
|
+
function ka(e, t, n = {}) {
|
|
3699
3717
|
let r = t.trim();
|
|
3700
3718
|
if (r === "") return "empty";
|
|
3701
3719
|
if ([...r].length > 60) return "too_long";
|
|
3702
|
-
let i =
|
|
3720
|
+
let i = La(n.locale), a = n.except ?? null;
|
|
3703
3721
|
return e.views.some((e) => e.id !== a && i.compare(e.name, r) === 0) ? "taken" : null;
|
|
3704
3722
|
}
|
|
3705
|
-
function
|
|
3723
|
+
function Aa(t, n, r = {}) {
|
|
3706
3724
|
if (n.id === "" || t.views.some((e) => e.id === n.id)) throw new e("invalid_argument", `A view's id must be new and not empty: "${n.id}".`);
|
|
3707
|
-
let i =
|
|
3708
|
-
return
|
|
3725
|
+
let i = Ra(t, n.name, { locale: r.locale });
|
|
3726
|
+
return Za({
|
|
3709
3727
|
...t,
|
|
3710
3728
|
views: [...t.views, {
|
|
3711
3729
|
...n,
|
|
@@ -3713,76 +3731,76 @@ function Oa(t, n, r = {}) {
|
|
|
3713
3731
|
}]
|
|
3714
3732
|
});
|
|
3715
3733
|
}
|
|
3716
|
-
function
|
|
3717
|
-
return
|
|
3734
|
+
function ja(e, t, n) {
|
|
3735
|
+
return Ba(e, t, (e) => ({
|
|
3718
3736
|
...e,
|
|
3719
|
-
...
|
|
3737
|
+
...Va(n)
|
|
3720
3738
|
}));
|
|
3721
3739
|
}
|
|
3722
|
-
function
|
|
3723
|
-
let i =
|
|
3740
|
+
function Ma(e, t, n, r = {}) {
|
|
3741
|
+
let i = Ra(e, n, {
|
|
3724
3742
|
except: t,
|
|
3725
3743
|
locale: r.locale
|
|
3726
3744
|
});
|
|
3727
|
-
return
|
|
3745
|
+
return Ba(e, t, (e) => ({
|
|
3728
3746
|
...e,
|
|
3729
3747
|
name: i
|
|
3730
3748
|
}));
|
|
3731
3749
|
}
|
|
3732
|
-
function
|
|
3733
|
-
return
|
|
3750
|
+
function Na(e, t) {
|
|
3751
|
+
return za(e, t), Za({
|
|
3734
3752
|
...e,
|
|
3735
3753
|
views: e.views.filter((e) => e.id !== t),
|
|
3736
3754
|
defaultId: e.defaultId === t ? null : e.defaultId
|
|
3737
3755
|
});
|
|
3738
3756
|
}
|
|
3739
|
-
function
|
|
3740
|
-
return t !== null &&
|
|
3757
|
+
function Pa(e, t) {
|
|
3758
|
+
return t !== null && za(e, t), Za({
|
|
3741
3759
|
...e,
|
|
3742
3760
|
defaultId: t
|
|
3743
3761
|
});
|
|
3744
3762
|
}
|
|
3745
|
-
function
|
|
3763
|
+
function Fa(t, n) {
|
|
3746
3764
|
let r = [], i = (e, t) => {
|
|
3747
3765
|
r.push(`${e}: ${t}`);
|
|
3748
3766
|
}, a = q(t);
|
|
3749
3767
|
if (!a) throw new e("invalid_views", "Saved views must be an object.");
|
|
3750
|
-
a.format !== "tabula-grid.views" && i("format", `must be "${
|
|
3768
|
+
a.format !== "tabula-grid.views" && i("format", `must be "${Sa}".`), a.version !== 1 && i("version", "must be 1; views of another version of this format cannot be read."), a.module !== n && i("module", `must be "${n}", the module these views are read for.`);
|
|
3751
3769
|
let o = [], s = /* @__PURE__ */ new Set();
|
|
3752
3770
|
Array.isArray(a.views) ? a.views.forEach((e, t) => {
|
|
3753
|
-
let n =
|
|
3771
|
+
let n = Ga(e, `views[${t}]`, i);
|
|
3754
3772
|
n && s.has(n.id) ? i(`views[${t}].id`, `"${n.id}" is the id of another view.`) : n && (s.add(n.id), o.push(n));
|
|
3755
3773
|
}) : i("views", "must be a list.");
|
|
3756
3774
|
let c = a.defaultId === void 0 || a.defaultId === null ? null : a.defaultId;
|
|
3757
3775
|
if (c === null || typeof c == "string" && s.has(c) || i("defaultId", "must be the id of one of the views, or null."), r.length > 0) throw new e("invalid_views", `The views cannot be read:\n${r.map((e) => ` ${e}`).join("\n")}`);
|
|
3758
|
-
return
|
|
3776
|
+
return Za({
|
|
3759
3777
|
module: n,
|
|
3760
3778
|
views: o,
|
|
3761
3779
|
defaultId: c
|
|
3762
3780
|
});
|
|
3763
3781
|
}
|
|
3764
|
-
var
|
|
3765
|
-
function
|
|
3766
|
-
let t = e ?? "", n =
|
|
3767
|
-
return n || (n = new Intl.Collator(e, { sensitivity: "accent" }),
|
|
3782
|
+
var Ia = /* @__PURE__ */ new Map();
|
|
3783
|
+
function La(e) {
|
|
3784
|
+
let t = e ?? "", n = Ia.get(t);
|
|
3785
|
+
return n || (n = new Intl.Collator(e, { sensitivity: "accent" }), Ia.set(t, n)), n;
|
|
3768
3786
|
}
|
|
3769
|
-
function
|
|
3770
|
-
let i =
|
|
3787
|
+
function Ra(t, n, r) {
|
|
3788
|
+
let i = ka(t, n, r);
|
|
3771
3789
|
if (i !== null) throw new e("invalid_argument", `"${n}" cannot be a view's name: ${i}.`);
|
|
3772
3790
|
return n.trim();
|
|
3773
3791
|
}
|
|
3774
|
-
function
|
|
3792
|
+
function za(t, n) {
|
|
3775
3793
|
let r = t.views.find((e) => e.id === n);
|
|
3776
3794
|
if (!r) throw new e("invalid_argument", `There is no view "${n}".`);
|
|
3777
3795
|
return r;
|
|
3778
3796
|
}
|
|
3779
|
-
function
|
|
3780
|
-
return
|
|
3797
|
+
function Ba(e, t, n) {
|
|
3798
|
+
return za(e, t), Za({
|
|
3781
3799
|
...e,
|
|
3782
3800
|
views: e.views.map((e) => e.id === t ? n(e) : e)
|
|
3783
3801
|
});
|
|
3784
3802
|
}
|
|
3785
|
-
function
|
|
3803
|
+
function Va(e) {
|
|
3786
3804
|
return {
|
|
3787
3805
|
columns: e.columns,
|
|
3788
3806
|
columnWidths: e.columnWidths,
|
|
@@ -3790,32 +3808,32 @@ function za(e) {
|
|
|
3790
3808
|
sort: e.sort
|
|
3791
3809
|
};
|
|
3792
3810
|
}
|
|
3793
|
-
function
|
|
3811
|
+
function Ha(e, t, n) {
|
|
3794
3812
|
let r = Object.keys(e);
|
|
3795
3813
|
return r.length === Object.keys(t).length && r.every((r) => r in t && n(e[r], t[r]));
|
|
3796
3814
|
}
|
|
3797
|
-
function
|
|
3815
|
+
function Ua(e, t) {
|
|
3798
3816
|
if (e.kind === "range" || t.kind === "range") return e.kind === "range" && t.kind === "range" && e.from === t.from && e.to === t.to;
|
|
3799
3817
|
let n = new Set(e.keys);
|
|
3800
3818
|
return n.size === new Set(t.keys).size && t.keys.every((e) => n.has(e));
|
|
3801
3819
|
}
|
|
3802
|
-
function
|
|
3820
|
+
function Wa(e, t, n) {
|
|
3803
3821
|
let r = q(e);
|
|
3804
|
-
return r ?
|
|
3805
|
-
columns:
|
|
3806
|
-
columnWidths:
|
|
3807
|
-
filters:
|
|
3808
|
-
sort:
|
|
3809
|
-
}) : (n(t, "must be an object."),
|
|
3810
|
-
}
|
|
3811
|
-
function
|
|
3822
|
+
return r ? Xa({
|
|
3823
|
+
columns: Ka(r.columns, `${t}.columns`, n),
|
|
3824
|
+
columnWidths: qa(r.columnWidths, `${t}.columnWidths`, n),
|
|
3825
|
+
filters: Ja(r.filters, `${t}.filters`, n),
|
|
3826
|
+
sort: Ya(r.sort, `${t}.sort`, n)
|
|
3827
|
+
}) : (n(t, "must be an object."), Ta);
|
|
3828
|
+
}
|
|
3829
|
+
function Ga(e, t, n) {
|
|
3812
3830
|
let r = q(e);
|
|
3813
3831
|
if (!r) return n(t, "must be an object."), null;
|
|
3814
3832
|
let i = !1, a = (e, t) => {
|
|
3815
3833
|
i = !0, n(e, t);
|
|
3816
3834
|
}, o = typeof r.id == "string" && r.id !== "" ? r.id : null, s = typeof r.name == "string" && r.name.trim() !== "" ? r.name.trim() : null;
|
|
3817
3835
|
o === null && a(`${t}.id`, "must be a non-empty string."), s === null && a(`${t}.name`, "must be a non-empty string.");
|
|
3818
|
-
let c =
|
|
3836
|
+
let c = Ka(r.columns, `${t}.columns`, a), l = qa(r.columnWidths, `${t}.columnWidths`, a), u = Ja(r.filters, `${t}.filters`, a), d = Ya(r.sort, `${t}.sort`, a);
|
|
3819
3837
|
return i || o === null || s === null ? null : {
|
|
3820
3838
|
id: o,
|
|
3821
3839
|
name: s,
|
|
@@ -3825,10 +3843,10 @@ function Ua(e, t, n) {
|
|
|
3825
3843
|
sort: d
|
|
3826
3844
|
};
|
|
3827
3845
|
}
|
|
3828
|
-
function
|
|
3829
|
-
return
|
|
3846
|
+
function Ka(e, t, n) {
|
|
3847
|
+
return ma(e, t, n) ?? {};
|
|
3830
3848
|
}
|
|
3831
|
-
function
|
|
3849
|
+
function qa(e, t, n) {
|
|
3832
3850
|
if (e == null) return {};
|
|
3833
3851
|
let r = q(e);
|
|
3834
3852
|
if (!r) return n(t, "must be an object of widths by field key."), {};
|
|
@@ -3836,7 +3854,7 @@ function Ga(e, t, n) {
|
|
|
3836
3854
|
for (let [e, a] of Object.entries(r)) typeof a == "number" && Number.isFinite(a) && a > 0 ? i[e] = a : n(`${t}.${e}`, "must be a number of pixels.");
|
|
3837
3855
|
return i;
|
|
3838
3856
|
}
|
|
3839
|
-
function
|
|
3857
|
+
function Ja(e, t, n) {
|
|
3840
3858
|
if (e == null) return {};
|
|
3841
3859
|
let r = q(e);
|
|
3842
3860
|
if (!r) return n(t, "must be an object of conditions by field key."), {};
|
|
@@ -3854,7 +3872,7 @@ function Ka(e, t, n) {
|
|
|
3854
3872
|
}
|
|
3855
3873
|
return i;
|
|
3856
3874
|
}
|
|
3857
|
-
function
|
|
3875
|
+
function Ya(e, t, n) {
|
|
3858
3876
|
if (e == null) return null;
|
|
3859
3877
|
let r = q(e);
|
|
3860
3878
|
return r && typeof r.key == "string" && r.key !== "" && (r.direction === "asc" || r.direction === "desc") ? {
|
|
@@ -3862,10 +3880,10 @@ function qa(e, t, n) {
|
|
|
3862
3880
|
direction: r.direction
|
|
3863
3881
|
} : (n(t, "must be { key, direction: \"asc\" or \"desc\" }, or null."), null);
|
|
3864
3882
|
}
|
|
3865
|
-
function
|
|
3883
|
+
function Xa(e) {
|
|
3866
3884
|
let t = e.columns;
|
|
3867
3885
|
return Object.freeze({
|
|
3868
|
-
columns:
|
|
3886
|
+
columns: ha(t),
|
|
3869
3887
|
columnWidths: Object.freeze({ ...e.columnWidths }),
|
|
3870
3888
|
filters: Object.freeze(Object.fromEntries(Object.entries(e.filters).map(([e, t]) => [e, Object.freeze(t.kind === "values" ? {
|
|
3871
3889
|
kind: "values",
|
|
@@ -3877,15 +3895,15 @@ function Ja(e) {
|
|
|
3877
3895
|
}) : null
|
|
3878
3896
|
});
|
|
3879
3897
|
}
|
|
3880
|
-
function
|
|
3898
|
+
function Za(e) {
|
|
3881
3899
|
return Object.freeze({
|
|
3882
|
-
format:
|
|
3900
|
+
format: Sa,
|
|
3883
3901
|
version: 1,
|
|
3884
3902
|
module: e.module,
|
|
3885
3903
|
views: Object.freeze(e.views.map((e) => Object.freeze({
|
|
3886
3904
|
id: e.id,
|
|
3887
3905
|
name: e.name,
|
|
3888
|
-
...
|
|
3906
|
+
...Xa(e)
|
|
3889
3907
|
}))),
|
|
3890
3908
|
defaultId: e.defaultId
|
|
3891
3909
|
});
|
|
@@ -3894,20 +3912,20 @@ function q(e) {
|
|
|
3894
3912
|
return typeof e == "object" && e && !Array.isArray(e) ? e : null;
|
|
3895
3913
|
}
|
|
3896
3914
|
// src/templates.ts
|
|
3897
|
-
var
|
|
3915
|
+
var Qa = "tabula-grid.template", $a = 1, eo = [
|
|
3898
3916
|
"label",
|
|
3899
3917
|
"required",
|
|
3900
3918
|
"editable",
|
|
3901
3919
|
"rules",
|
|
3902
3920
|
"default"
|
|
3903
|
-
],
|
|
3921
|
+
], to = /* @__PURE__ */ new Set([
|
|
3904
3922
|
"integer",
|
|
3905
3923
|
"decimal",
|
|
3906
3924
|
"money",
|
|
3907
3925
|
"quantity",
|
|
3908
3926
|
"percent"
|
|
3909
3927
|
]);
|
|
3910
|
-
function
|
|
3928
|
+
function no(t, n) {
|
|
3911
3929
|
let r = [], i = (e, t) => {
|
|
3912
3930
|
r.push({
|
|
3913
3931
|
path: e,
|
|
@@ -3915,7 +3933,7 @@ function eo(t, n) {
|
|
|
3915
3933
|
});
|
|
3916
3934
|
}, a = J(t);
|
|
3917
3935
|
if (!a) throw new e("invalid_template", "A template must be an object.");
|
|
3918
|
-
a.format !== "tabula-grid.template" && i("format", `must be "${
|
|
3936
|
+
a.format !== "tabula-grid.template" && i("format", `must be "${Qa}".`), a.version !== 1 && i("version", "must be 1; a template of another version of this format cannot be read."), a.module !== n && i("module", `must be "${n}", the module the template is read for.`);
|
|
3919
3937
|
let o = (e) => {
|
|
3920
3938
|
let t = a[e];
|
|
3921
3939
|
return typeof t != "string" || t.trim() === "" ? (i(e, "must be a non-empty string."), "") : e === "name" ? t.trim() : t;
|
|
@@ -3934,10 +3952,10 @@ function eo(t, n) {
|
|
|
3934
3952
|
a.styles !== void 0 && !Array.isArray(a.styles) ? i("styles", "must be a list of colour rules.") : (a.styles ?? []).forEach((e, t) => {
|
|
3935
3953
|
J(e) ? p.push(e) : i(`styles[${t}]`, "must be an object, written as a schema's colour rule.");
|
|
3936
3954
|
});
|
|
3937
|
-
let m = a.view === void 0 || a.view === null ? null :
|
|
3938
|
-
if (r.length > 0) throw new e("invalid_template",
|
|
3955
|
+
let m = a.view === void 0 || a.view === null ? null : Wa(a.view, "view", i);
|
|
3956
|
+
if (r.length > 0) throw new e("invalid_template", lo("The template cannot be read", r));
|
|
3939
3957
|
return Object.freeze({
|
|
3940
|
-
format:
|
|
3958
|
+
format: Qa,
|
|
3941
3959
|
version: 1,
|
|
3942
3960
|
module: n,
|
|
3943
3961
|
id: s,
|
|
@@ -3949,15 +3967,15 @@ function eo(t, n) {
|
|
|
3949
3967
|
view: m
|
|
3950
3968
|
});
|
|
3951
3969
|
}
|
|
3952
|
-
function
|
|
3953
|
-
return
|
|
3970
|
+
function ro(e, t) {
|
|
3971
|
+
return oo(e, t).problems;
|
|
3954
3972
|
}
|
|
3955
|
-
function
|
|
3956
|
-
let { problems: r, applied: i } =
|
|
3957
|
-
if (r.length > 0 || i === null) throw new e("invalid_template",
|
|
3973
|
+
function io(t, n) {
|
|
3974
|
+
let { problems: r, applied: i } = oo(t, n);
|
|
3975
|
+
if (r.length > 0 || i === null) throw new e("invalid_template", lo(`Template "${n.name}" cannot be applied to module "${t.module}"`, r));
|
|
3958
3976
|
return i;
|
|
3959
3977
|
}
|
|
3960
|
-
function
|
|
3978
|
+
function ao(e, t) {
|
|
3961
3979
|
let n = typeof t == "number" ? Array.from({ length: t }, () => ({})) : t, r = e.fields.filter((e) => e.default !== null);
|
|
3962
3980
|
return r.length === 0 ? [...n] : n.map((e) => {
|
|
3963
3981
|
let t = {};
|
|
@@ -3969,7 +3987,7 @@ function ro(e, t) {
|
|
|
3969
3987
|
};
|
|
3970
3988
|
});
|
|
3971
3989
|
}
|
|
3972
|
-
function
|
|
3990
|
+
function oo(e, n) {
|
|
3973
3991
|
let r = [], i = (e, t) => {
|
|
3974
3992
|
r.push({
|
|
3975
3993
|
path: e,
|
|
@@ -3980,7 +3998,7 @@ function io(e, n) {
|
|
|
3980
3998
|
for (let t of Object.keys(n.fields)) e.has(t) || i(`fields.${t}`, `is not a field of module "${e.module}".`);
|
|
3981
3999
|
let a = e.toJSON(), o = a.fields.map((t) => {
|
|
3982
4000
|
let r = n.fields[t.key];
|
|
3983
|
-
return r ?
|
|
4001
|
+
return r ? so(t, e.field(t.key), r, `fields.${t.key}`, i) : t;
|
|
3984
4002
|
}), s = n.columns.map((t, n) => {
|
|
3985
4003
|
let r = `columns[${n}]`;
|
|
3986
4004
|
return typeof t.key == "string" && e.has(t.key) && i(`${r}.key`, `"${t.key}" is a field of the module; a template's column needs a key of its own.`), t.type === "lookup" && i(`${r}.type`, "cannot be lookup: a record is something the backend gives, and a template's column is never sent."), t.submit === !0 && i(`${r}.submit`, "cannot be true: a template's column is never sent for processing."), {
|
|
@@ -4001,7 +4019,7 @@ function io(e, n) {
|
|
|
4001
4019
|
try {
|
|
4002
4020
|
return {
|
|
4003
4021
|
problems: r,
|
|
4004
|
-
applied:
|
|
4022
|
+
applied: Kt.from(u)
|
|
4005
4023
|
};
|
|
4006
4024
|
} catch (e) {
|
|
4007
4025
|
if (!(e instanceof t)) throw e;
|
|
@@ -4019,12 +4037,12 @@ function io(e, n) {
|
|
|
4019
4037
|
};
|
|
4020
4038
|
}
|
|
4021
4039
|
}
|
|
4022
|
-
function
|
|
4040
|
+
function so(e, t, n, r, i) {
|
|
4023
4041
|
let a = { ...e };
|
|
4024
|
-
for (let e of Object.keys(n))
|
|
4025
|
-
return n.label !== void 0 && (a.label = n.label), n.required !== void 0 && (typeof n.required == "boolean" ? !n.required && t.required ? i(`${r}.required`, "would make the field optional; the schema requires it, and a template only narrows.") : n.required && (a.required = !0) : i(`${r}.required`, "must be true or false.")), n.editable !== void 0 && (typeof n.editable == "boolean" ? n.editable && !t.editable ? i(`${r}.editable`, "would open the column for typing; the schema keeps it read-only, and a template only narrows.") : n.editable || (a.editable = !1) : i(`${r}.editable`, "must be true or false.")), n.rules !== void 0 && (a.rules =
|
|
4042
|
+
for (let e of Object.keys(n)) eo.includes(e) || i(`${r}.${e}`, `is not something a template changes; it changes ${eo.join(", ")}.`);
|
|
4043
|
+
return n.label !== void 0 && (a.label = n.label), n.required !== void 0 && (typeof n.required == "boolean" ? !n.required && t.required ? i(`${r}.required`, "would make the field optional; the schema requires it, and a template only narrows.") : n.required && (a.required = !0) : i(`${r}.required`, "must be true or false.")), n.editable !== void 0 && (typeof n.editable == "boolean" ? n.editable && !t.editable ? i(`${r}.editable`, "would open the column for typing; the schema keeps it read-only, and a template only narrows.") : n.editable || (a.editable = !1) : i(`${r}.editable`, "must be true or false.")), n.rules !== void 0 && (a.rules = co(t, n.rules, `${r}.rules`, i)), n.default !== void 0 && (a.default = n.default), a;
|
|
4026
4044
|
}
|
|
4027
|
-
function
|
|
4045
|
+
function co(e, t, n, a) {
|
|
4028
4046
|
let o = new Map(e.rules.map((e) => [e.rule, { ...e }]));
|
|
4029
4047
|
return Array.isArray(t) ? (t.forEach((t, s) => {
|
|
4030
4048
|
let c = `${n}[${s}]`, l = J(t), u = l?.rule, d = e.rules.find((e) => e.rule === u);
|
|
@@ -4033,7 +4051,7 @@ function oo(e, t, n, a) {
|
|
|
4033
4051
|
case "min":
|
|
4034
4052
|
case "max": {
|
|
4035
4053
|
let t = typeof l.value == "string" || typeof l.value == "number" ? r(l.value) : null;
|
|
4036
|
-
|
|
4054
|
+
to.has(e.type) ? t === null ? a(`${c}.value`, "must be a decimal number such as \"1\" or \"12.5\".") : d && "value" in d && i(t, String(d.value)) * (u === "min" ? 1 : -1) < 0 ? a(c, `${u} ${t} would let through what the schema's ${u} ${d.value} refuses; a template only narrows.`) : o.set(u, {
|
|
4037
4055
|
rule: u,
|
|
4038
4056
|
value: t
|
|
4039
4057
|
}) : a(c, `${u} does not apply to a ${e.type} field.`);
|
|
@@ -4055,14 +4073,14 @@ function oo(e, t, n, a) {
|
|
|
4055
4073
|
}
|
|
4056
4074
|
}), [...o.values()]) : (a(n, "must be a list of rules."), [...o.values()]);
|
|
4057
4075
|
}
|
|
4058
|
-
function
|
|
4076
|
+
function lo(e, t) {
|
|
4059
4077
|
return `${e}:\n${t.map((e) => ` ${e.path}: ${e.message}`).join("\n")}`;
|
|
4060
4078
|
}
|
|
4061
4079
|
function J(e) {
|
|
4062
4080
|
return typeof e == "object" && e && !Array.isArray(e) ? e : null;
|
|
4063
4081
|
}
|
|
4064
4082
|
// src/selection.ts
|
|
4065
|
-
var
|
|
4083
|
+
var uo = {
|
|
4066
4084
|
up: {
|
|
4067
4085
|
row: -1,
|
|
4068
4086
|
col: 0
|
|
@@ -4079,15 +4097,15 @@ var co = {
|
|
|
4079
4097
|
row: 0,
|
|
4080
4098
|
col: 1
|
|
4081
4099
|
}
|
|
4082
|
-
},
|
|
4100
|
+
}, fo = class {
|
|
4083
4101
|
#e;
|
|
4084
4102
|
#t;
|
|
4085
4103
|
#n = null;
|
|
4086
4104
|
#r = null;
|
|
4087
4105
|
#i = null;
|
|
4088
|
-
#a = new
|
|
4106
|
+
#a = new S();
|
|
4089
4107
|
constructor(e, t) {
|
|
4090
|
-
this.#e =
|
|
4108
|
+
this.#e = vo(e, "rowCount"), this.#t = vo(t, "colCount"), this.#o() || (this.#n = this.#r = this.#i = mo(0, 0));
|
|
4091
4109
|
}
|
|
4092
4110
|
get rowCount() {
|
|
4093
4111
|
return this.#e;
|
|
@@ -4102,11 +4120,11 @@ var co = {
|
|
|
4102
4120
|
return this.#i;
|
|
4103
4121
|
}
|
|
4104
4122
|
get range() {
|
|
4105
|
-
return this.#r && this.#i ?
|
|
4123
|
+
return this.#r && this.#i ? ho(this.#r, this.#i) : null;
|
|
4106
4124
|
}
|
|
4107
4125
|
contains(e, t) {
|
|
4108
4126
|
let n = this.range;
|
|
4109
|
-
return n !== null &&
|
|
4127
|
+
return n !== null && go(n, mo(e, t));
|
|
4110
4128
|
}
|
|
4111
4129
|
isActive(e, t) {
|
|
4112
4130
|
return this.#n !== null && this.#n.row === e && this.#n.col === t;
|
|
@@ -4122,7 +4140,7 @@ var co = {
|
|
|
4122
4140
|
jump(e, t, n = {}) {
|
|
4123
4141
|
let r = n.extend ? this.#i : this.#n;
|
|
4124
4142
|
if (r === null) return;
|
|
4125
|
-
let i =
|
|
4143
|
+
let i = po(r, uo[e], this.#e, this.#t, t);
|
|
4126
4144
|
this.moveTo(i.row, i.col, n);
|
|
4127
4145
|
}
|
|
4128
4146
|
selectRows(e, t = e) {
|
|
@@ -4138,11 +4156,11 @@ var co = {
|
|
|
4138
4156
|
e !== null && t !== null && this.#n !== null && this.#l(this.#n, e, t);
|
|
4139
4157
|
}
|
|
4140
4158
|
resize(e, t) {
|
|
4141
|
-
if (this.#e =
|
|
4159
|
+
if (this.#e = vo(e, "rowCount"), this.#t = vo(t, "colCount"), this.#o()) {
|
|
4142
4160
|
this.#n !== null && (this.#n = this.#r = this.#i = null, this.#a.emit(this));
|
|
4143
4161
|
return;
|
|
4144
4162
|
}
|
|
4145
|
-
let n = this.#n ??
|
|
4163
|
+
let n = this.#n ?? mo(0, 0), r = this.#r ?? n, i = this.#i ?? n;
|
|
4146
4164
|
this.#l(this.#c(n), this.#c(r), this.#c(i));
|
|
4147
4165
|
}
|
|
4148
4166
|
subscribe(e) {
|
|
@@ -4153,18 +4171,18 @@ var co = {
|
|
|
4153
4171
|
}
|
|
4154
4172
|
#s(t, n) {
|
|
4155
4173
|
if (Number.isNaN(t) || Number.isNaN(n)) throw new e("invalid_argument", `A cell position must be a number; got ${t}, ${n}.`);
|
|
4156
|
-
return this.#o() ? null : this.#c(
|
|
4174
|
+
return this.#o() ? null : this.#c(mo(t, n));
|
|
4157
4175
|
}
|
|
4158
4176
|
#c(e) {
|
|
4159
|
-
return
|
|
4177
|
+
return mo(Math.min(this.#e - 1, Math.max(0, Math.trunc(e.row))), Math.min(this.#t - 1, Math.max(0, Math.trunc(e.col))));
|
|
4160
4178
|
}
|
|
4161
4179
|
#l(e, t, n) {
|
|
4162
|
-
let r =
|
|
4163
|
-
|
|
4180
|
+
let r = go(ho(t, n), e) ? e : t;
|
|
4181
|
+
_o(r, this.#n) && _o(t, this.#r) && _o(n, this.#i) || (this.#n = r, this.#r = t, this.#i = n, this.#a.emit(this));
|
|
4164
4182
|
}
|
|
4165
4183
|
};
|
|
4166
|
-
function
|
|
4167
|
-
let a = (e) => e.row >= 0 && e.row < n && e.col >= 0 && e.col < r, o = (e) => i(e.row, e.col), s = (e) =>
|
|
4184
|
+
function po(e, t, n, r, i) {
|
|
4185
|
+
let a = (e) => e.row >= 0 && e.row < n && e.col >= 0 && e.col < r, o = (e) => i(e.row, e.col), s = (e) => mo(e.row + t.row, e.col + t.col), c = e, l = s(c);
|
|
4168
4186
|
if (!a(l)) return c;
|
|
4169
4187
|
if (!o(c) && !o(l)) {
|
|
4170
4188
|
for (; a(l) && !o(l);) c = l, l = s(l);
|
|
@@ -4176,13 +4194,13 @@ function uo(e, t, n, r, i) {
|
|
|
4176
4194
|
}
|
|
4177
4195
|
return c;
|
|
4178
4196
|
}
|
|
4179
|
-
function
|
|
4197
|
+
function mo(e, t) {
|
|
4180
4198
|
return Object.freeze({
|
|
4181
4199
|
row: e,
|
|
4182
4200
|
col: t
|
|
4183
4201
|
});
|
|
4184
4202
|
}
|
|
4185
|
-
function
|
|
4203
|
+
function ho(e, t) {
|
|
4186
4204
|
return Object.freeze({
|
|
4187
4205
|
top: Math.min(e.row, t.row),
|
|
4188
4206
|
left: Math.min(e.col, t.col),
|
|
@@ -4190,18 +4208,18 @@ function po(e, t) {
|
|
|
4190
4208
|
right: Math.max(e.col, t.col)
|
|
4191
4209
|
});
|
|
4192
4210
|
}
|
|
4193
|
-
function
|
|
4211
|
+
function go(e, t) {
|
|
4194
4212
|
return t.row >= e.top && t.row <= e.bottom && t.col >= e.left && t.col <= e.right;
|
|
4195
4213
|
}
|
|
4196
|
-
function
|
|
4214
|
+
function _o(e, t) {
|
|
4197
4215
|
return t !== null && e.row === t.row && e.col === t.col;
|
|
4198
4216
|
}
|
|
4199
|
-
function
|
|
4217
|
+
function vo(t, n) {
|
|
4200
4218
|
if (!Number.isSafeInteger(t) || t < 0) throw new e("invalid_argument", `${n} must be a whole number, 0 or more; got ${t}.`);
|
|
4201
4219
|
return t;
|
|
4202
4220
|
}
|
|
4203
4221
|
// src/clipboard.ts
|
|
4204
|
-
function
|
|
4222
|
+
function yo(e) {
|
|
4205
4223
|
if (e === "") return [];
|
|
4206
4224
|
let t = [], n = [], r = "", i = 0, a = !0, o = -1, s = -1;
|
|
4207
4225
|
for (;;) {
|
|
@@ -4219,22 +4237,22 @@ function _o(e) {
|
|
|
4219
4237
|
}
|
|
4220
4238
|
return n.push(r), t.push(n), t;
|
|
4221
4239
|
}
|
|
4222
|
-
function
|
|
4223
|
-
return e.map((e) => e.map(
|
|
4240
|
+
function bo(e) {
|
|
4241
|
+
return e.map((e) => e.map(xo).join(" ")).join("\r\n");
|
|
4224
4242
|
}
|
|
4225
|
-
function
|
|
4243
|
+
function xo(e) {
|
|
4226
4244
|
return /[\t\n\r"]/.test(e) ? `"${e.replace(/"/g, "\"\"")}"` : e;
|
|
4227
4245
|
}
|
|
4228
4246
|
// src/csv.ts
|
|
4229
|
-
var
|
|
4247
|
+
var So = [
|
|
4230
4248
|
";",
|
|
4231
4249
|
",",
|
|
4232
4250
|
" "
|
|
4233
4251
|
];
|
|
4234
|
-
function
|
|
4252
|
+
function Co(e, t = {}) {
|
|
4235
4253
|
let n = e.startsWith("") ? e.slice(1) : e;
|
|
4236
4254
|
if (n === "") return [];
|
|
4237
|
-
let r = t.delimiter ??
|
|
4255
|
+
let r = t.delimiter ?? wo(n), i = [], a = [], o = "", s = !1, c = !1, l = 0, u = () => {
|
|
4238
4256
|
a.push(o), o = "";
|
|
4239
4257
|
}, d = () => {
|
|
4240
4258
|
u(), i.push(a), a = [], c = !1;
|
|
@@ -4245,20 +4263,20 @@ function xo(e, t = {}) {
|
|
|
4245
4263
|
}
|
|
4246
4264
|
return c && d(), i;
|
|
4247
4265
|
}
|
|
4248
|
-
function
|
|
4249
|
-
let t = new Map(
|
|
4266
|
+
function wo(e) {
|
|
4267
|
+
let t = new Map(So.map((e) => [e, 0])), n = !1;
|
|
4250
4268
|
for (let r of e) if (r === "\"") n = !n;
|
|
4251
4269
|
else if (!n && (r === "\n" || r === "\r")) break;
|
|
4252
4270
|
else !n && t.has(r) && t.set(r, (t.get(r) ?? 0) + 1);
|
|
4253
4271
|
let r = ";";
|
|
4254
|
-
for (let e of
|
|
4272
|
+
for (let e of So) (t.get(e) ?? 0) > (t.get(r) ?? 0) && (r = e);
|
|
4255
4273
|
return r;
|
|
4256
4274
|
}
|
|
4257
|
-
function
|
|
4275
|
+
function To(e, t = {}) {
|
|
4258
4276
|
let n = t.delimiter ?? ",", r = RegExp(`["\\r\\n${n === " " ? "\\t" : n}]`), i = e.map((e) => e.map((e) => r.test(e) ? `"${e.replace(/"/g, "\"\"")}"` : e).join(n)).join("\r\n");
|
|
4259
4277
|
return `${t.bom === !1 ? "" : ""}${i}\r\n`;
|
|
4260
4278
|
}
|
|
4261
|
-
function
|
|
4279
|
+
function Eo(e, t = "windows-1254") {
|
|
4262
4280
|
try {
|
|
4263
4281
|
return new TextDecoder("utf-8", { fatal: !0 }).decode(e);
|
|
4264
4282
|
} catch {
|
|
@@ -4266,45 +4284,63 @@ function wo(e, t = "windows-1254") {
|
|
|
4266
4284
|
}
|
|
4267
4285
|
}
|
|
4268
4286
|
// src/table.ts
|
|
4269
|
-
var
|
|
4287
|
+
var Do = /^[=+\-@\t\r]/, Oo = /* @__PURE__ */ new Set([
|
|
4270
4288
|
"integer",
|
|
4271
4289
|
"decimal",
|
|
4272
4290
|
"quantity",
|
|
4273
4291
|
"money",
|
|
4274
4292
|
"percent"
|
|
4275
4293
|
]);
|
|
4276
|
-
function
|
|
4277
|
-
let { store: t, fields: n, settings: r } = e, i = []
|
|
4278
|
-
|
|
4279
|
-
|
|
4280
|
-
|
|
4281
|
-
|
|
4282
|
-
|
|
4294
|
+
function ko(e) {
|
|
4295
|
+
let { store: t, fields: n, settings: r } = e, i = (e.extra ?? []).filter((e) => e.at === "start"), a = (e.extra ?? []).filter((e) => e.at !== "start"), o = (e, t) => e.map((e) => {
|
|
4296
|
+
let n = e.text(t);
|
|
4297
|
+
return Do.test(n) ? `'${n}` : n;
|
|
4298
|
+
}), s = [];
|
|
4299
|
+
(e.header ?? "label") !== "none" && s.push([
|
|
4300
|
+
...i.map((e) => e.header),
|
|
4301
|
+
...n.map((t) => e.header === "key" ? t.key : t.label),
|
|
4302
|
+
...a.map((e) => e.header)
|
|
4303
|
+
]);
|
|
4304
|
+
for (let c of e.rowIds ?? t.rowIds()) s.push([
|
|
4305
|
+
...o(i, c),
|
|
4306
|
+
...n.map((e) => Ao(e, t.get(c, e.key), r)),
|
|
4307
|
+
...o(a, c)
|
|
4308
|
+
]);
|
|
4309
|
+
return s;
|
|
4310
|
+
}
|
|
4311
|
+
function Ao(e, t, n) {
|
|
4283
4312
|
let r = ai(e, t, n);
|
|
4284
|
-
return !(
|
|
4313
|
+
return !(Oo.has(e.type) && t !== null && v(e, t)) && Do.test(r) ? `'${r}` : r;
|
|
4285
4314
|
}
|
|
4286
|
-
function
|
|
4315
|
+
function jo(e) {
|
|
4287
4316
|
return e.decimalSeparator === "," ? ";" : ",";
|
|
4288
4317
|
}
|
|
4289
|
-
|
|
4290
|
-
|
|
4318
|
+
var Mo = 3;
|
|
4319
|
+
function No(e, t) {
|
|
4320
|
+
let { schema: n, settings: r } = t, [i = [], ...a] = e, o = a.filter((e) => !e.every((e) => e.trim() === "")), s = t.key ?? null, c = /* @__PURE__ */ new Set(), l = i.map((e, r) => {
|
|
4291
4321
|
let i = e.trim(), a = t.columns?.[r];
|
|
4322
|
+
if (r === s) return {
|
|
4323
|
+
index: r,
|
|
4324
|
+
header: i,
|
|
4325
|
+
field: null,
|
|
4326
|
+
status: "key"
|
|
4327
|
+
};
|
|
4292
4328
|
if (a === null) return {
|
|
4293
4329
|
index: r,
|
|
4294
4330
|
header: i,
|
|
4295
4331
|
field: null,
|
|
4296
4332
|
status: "skipped"
|
|
4297
4333
|
};
|
|
4298
|
-
let
|
|
4299
|
-
return
|
|
4334
|
+
let o = a === void 0 ? Zo(n, i) : n.has(a) ? n.field(a) : null;
|
|
4335
|
+
return o ? o.editable ? c.has(o.key) ? {
|
|
4300
4336
|
index: r,
|
|
4301
4337
|
header: i,
|
|
4302
4338
|
field: null,
|
|
4303
4339
|
status: "duplicate"
|
|
4304
|
-
} : (
|
|
4340
|
+
} : (c.add(o.key), {
|
|
4305
4341
|
index: r,
|
|
4306
4342
|
header: i,
|
|
4307
|
-
field:
|
|
4343
|
+
field: o.key,
|
|
4308
4344
|
status: "matched"
|
|
4309
4345
|
}) : {
|
|
4310
4346
|
index: r,
|
|
@@ -4317,30 +4353,181 @@ function Ao(e, t) {
|
|
|
4317
4353
|
field: null,
|
|
4318
4354
|
status: "unknown"
|
|
4319
4355
|
};
|
|
4320
|
-
}),
|
|
4321
|
-
for (let e of
|
|
4322
|
-
if (e.every((e) => e.trim() === "")) continue;
|
|
4356
|
+
}), u = [], d = [], f = l.map(() => 0);
|
|
4357
|
+
for (let e of o) {
|
|
4323
4358
|
let t = {};
|
|
4324
|
-
for (let i of
|
|
4359
|
+
for (let i of l) {
|
|
4325
4360
|
if (i.field === null) continue;
|
|
4326
|
-
let a = n.field(i.field), o =
|
|
4327
|
-
o.value !== null && (t[a.key] = o.value), o.problem && o.problem.code !== "not_matched" &&
|
|
4361
|
+
let a = n.field(i.field), o = g(a, e[i.index] ?? "", r);
|
|
4362
|
+
o.value !== null && (t[a.key] = o.value), o.problem && o.problem.code !== "not_matched" && (f[i.index] = (f[i.index] ?? 0) + 1);
|
|
4328
4363
|
}
|
|
4329
|
-
|
|
4364
|
+
u.push({ values: t }), s !== null && d.push((e[s] ?? "").trim());
|
|
4330
4365
|
}
|
|
4331
4366
|
return {
|
|
4332
|
-
columns:
|
|
4333
|
-
|
|
4334
|
-
|
|
4335
|
-
|
|
4367
|
+
columns: l.map((e) => ({
|
|
4368
|
+
...e,
|
|
4369
|
+
samples: Ho(o, e.index, Mo),
|
|
4370
|
+
unreadable: f[e.index] ?? 0
|
|
4371
|
+
})),
|
|
4372
|
+
rows: u,
|
|
4373
|
+
keys: d,
|
|
4374
|
+
missing: n.fields.filter((e) => e.required && e.editable && !c.has(e.key)).map((e) => e.key),
|
|
4375
|
+
unreadable: f.reduce((e, t) => e + t, 0)
|
|
4376
|
+
};
|
|
4377
|
+
}
|
|
4378
|
+
var Po = 50, Fo = .6;
|
|
4379
|
+
function Io(e, t) {
|
|
4380
|
+
let { schema: n, settings: r } = t, [i = [], ...a] = e, o = a.filter((e) => !e.every((e) => e.trim() === "")), s = n.fields.filter((e) => e.editable), c = /* @__PURE__ */ new Set(), l = i.map(() => void 0), u = (e, t, n) => {
|
|
4381
|
+
l[e] = {
|
|
4382
|
+
field: t,
|
|
4383
|
+
reason: n
|
|
4384
|
+
}, t !== null && c.add(t);
|
|
4385
|
+
}, d = (e) => !c.has(e.key);
|
|
4386
|
+
return i.forEach((e, r) => {
|
|
4387
|
+
let i = Lo(e);
|
|
4388
|
+
if (t.remembered && Object.hasOwn(t.remembered, i)) {
|
|
4389
|
+
let e = t.remembered[i] ?? null;
|
|
4390
|
+
e === null ? u(r, null, "remembered") : n.has(e) && n.field(e).editable && !c.has(e) && u(r, e, "remembered");
|
|
4391
|
+
}
|
|
4392
|
+
}), i.forEach((e, t) => {
|
|
4393
|
+
let r = l[t] ? null : Zo(n, e.trim());
|
|
4394
|
+
r?.editable && d(r) && u(t, r.key, "name");
|
|
4395
|
+
}), i.forEach((e, t) => {
|
|
4396
|
+
let n = Bo(e);
|
|
4397
|
+
if (l[t] || n.size === 0) return;
|
|
4398
|
+
let r = s.filter(d).map((e) => ({
|
|
4399
|
+
field: e,
|
|
4400
|
+
score: Vo(n, Bo(e.label))
|
|
4401
|
+
})), i = Math.max(0, ...r.map((e) => e.score)), a = r.filter((e) => e.score === i);
|
|
4402
|
+
i > 0 && a.length === 1 && a[0] && u(t, a[0].field.key, "similar");
|
|
4403
|
+
}), i.forEach((e, t) => {
|
|
4404
|
+
if (l[t]) return;
|
|
4405
|
+
let n = Ho(o, t, Po), i = s.filter((e) => d(e) && e.type !== "string" && e.type !== "lookup" && Ro(e, n, r));
|
|
4406
|
+
n.length > 0 && i.length === 1 && i[0] && u(t, i[0].key, "values");
|
|
4407
|
+
}), l.map((e) => e ?? {
|
|
4408
|
+
field: null,
|
|
4409
|
+
reason: null
|
|
4410
|
+
});
|
|
4411
|
+
}
|
|
4412
|
+
function Lo(e) {
|
|
4413
|
+
return e.trim().toLocaleLowerCase("tr");
|
|
4414
|
+
}
|
|
4415
|
+
function Ro(e, t, n) {
|
|
4416
|
+
let r = t.filter((t) => g(e, t, n).problem === null).length;
|
|
4417
|
+
return t.length > 0 && r / t.length >= Fo;
|
|
4418
|
+
}
|
|
4419
|
+
var zo = {
|
|
4420
|
+
ç: "c",
|
|
4421
|
+
ğ: "g",
|
|
4422
|
+
ı: "i",
|
|
4423
|
+
ö: "o",
|
|
4424
|
+
ş: "s",
|
|
4425
|
+
ü: "u"
|
|
4426
|
+
};
|
|
4427
|
+
function Bo(e) {
|
|
4428
|
+
let t = e.toLocaleLowerCase("tr").replace(/[çğıöşü]/g, (e) => zo[e] ?? e).normalize("NFD").replace(/[\u0300-\u036f]/g, "");
|
|
4429
|
+
return new Set(t.split(/[^a-z0-9]+/).filter((e) => e.length > 1));
|
|
4430
|
+
}
|
|
4431
|
+
function Vo(e, t) {
|
|
4432
|
+
let n = [...e].filter((e) => t.has(e)).length;
|
|
4433
|
+
return n === 0 ? 0 : n / (/* @__PURE__ */ new Set([...e, ...t])).size;
|
|
4434
|
+
}
|
|
4435
|
+
function Ho(e, t, n) {
|
|
4436
|
+
let r = [];
|
|
4437
|
+
for (let i of e) {
|
|
4438
|
+
let e = (i[t] ?? "").trim();
|
|
4439
|
+
if (e !== "" && (r.push(e), r.length === n)) break;
|
|
4440
|
+
}
|
|
4441
|
+
return r;
|
|
4442
|
+
}
|
|
4443
|
+
var Uo = /* @__PURE__ */ new Set([
|
|
4444
|
+
"string",
|
|
4445
|
+
"integer",
|
|
4446
|
+
"lookup"
|
|
4447
|
+
]);
|
|
4448
|
+
function Wo(e, t, n) {
|
|
4449
|
+
let { schema: r, settings: i } = n, [a = [], ...o] = e, s = o.filter((e) => !e.every((e) => e.trim() === "")), c = r.fields.filter((e) => Uo.has(e.type)), l = /* @__PURE__ */ new Map(), u = null, d = 0;
|
|
4450
|
+
for (let e = 0; e < a.length; e++) {
|
|
4451
|
+
let n = Ho(s, e, Po);
|
|
4452
|
+
for (let r of n.length === 0 ? [] : c) {
|
|
4453
|
+
let a = l.get(r.key) ?? Ko(t, r, i);
|
|
4454
|
+
l.set(r.key, a);
|
|
4455
|
+
let o = n.filter((e) => {
|
|
4456
|
+
let t = qo(r, e, i);
|
|
4457
|
+
return t !== null && a.has(t);
|
|
4458
|
+
}).length / n.length;
|
|
4459
|
+
o >= .5 && o > d && (u = {
|
|
4460
|
+
column: e,
|
|
4461
|
+
field: r.key
|
|
4462
|
+
}, d = o);
|
|
4463
|
+
}
|
|
4464
|
+
}
|
|
4465
|
+
return u;
|
|
4466
|
+
}
|
|
4467
|
+
function Go(e, t, n, r) {
|
|
4468
|
+
let i = Ko(e, t, r);
|
|
4469
|
+
return n.map((e) => {
|
|
4470
|
+
let n = qo(t, e, r);
|
|
4471
|
+
return n === null ? [] : [...i.get(n) ?? []];
|
|
4472
|
+
});
|
|
4473
|
+
}
|
|
4474
|
+
function Ko(e, t, n) {
|
|
4475
|
+
let r = /* @__PURE__ */ new Map();
|
|
4476
|
+
for (let i of e.rowIds()) {
|
|
4477
|
+
let a = Jo(t, e.get(i, t.key), n);
|
|
4478
|
+
if (a !== null) {
|
|
4479
|
+
let e = r.get(a);
|
|
4480
|
+
e ? e.push(i) : r.set(a, [i]);
|
|
4481
|
+
}
|
|
4482
|
+
}
|
|
4483
|
+
return r;
|
|
4484
|
+
}
|
|
4485
|
+
function qo(e, t, n) {
|
|
4486
|
+
return t.trim() === "" ? null : e.type === "lookup" ? u(t) : Jo(e, g(e, t, n).value, n);
|
|
4487
|
+
}
|
|
4488
|
+
function Jo(e, t, n) {
|
|
4489
|
+
if (t === null) return null;
|
|
4490
|
+
if (b(t)) return u(t.label);
|
|
4491
|
+
let r = _(e, t, n);
|
|
4492
|
+
return typeof r == "string" ? u(r) : JSON.stringify(r);
|
|
4493
|
+
}
|
|
4494
|
+
var Yo = "import";
|
|
4495
|
+
function Xo(e, t, n, r = {}) {
|
|
4496
|
+
let i = n.columns.flatMap((e) => e.status === "matched" && e.field ? [e.field] : []), a = [], o = /* @__PURE__ */ new Set(), s = [], c = 0;
|
|
4497
|
+
return e.transact(() => {
|
|
4498
|
+
n.rows.forEach((t, n) => {
|
|
4499
|
+
let s = r.matches?.[n] ?? [];
|
|
4500
|
+
if (s.length === 0) {
|
|
4501
|
+
r.matches && r.unmatched === "skip" ? c++ : a.push(t);
|
|
4502
|
+
return;
|
|
4503
|
+
}
|
|
4504
|
+
let l = s.filter((t) => e.has(t) && !r.locked?.(t));
|
|
4505
|
+
if (l.length === 0) c++;
|
|
4506
|
+
else for (let n of l) {
|
|
4507
|
+
for (let r of i) e.setCell(n, r, t.values?.[r] ?? null);
|
|
4508
|
+
o.add(n);
|
|
4509
|
+
}
|
|
4510
|
+
}), a.length > 0 && (s = e.appendRows(ao(t, a)));
|
|
4511
|
+
}, { origin: r.origin ?? "import" }), {
|
|
4512
|
+
added: s,
|
|
4513
|
+
updated: o.size,
|
|
4514
|
+
skipped: c
|
|
4336
4515
|
};
|
|
4337
4516
|
}
|
|
4338
|
-
function
|
|
4517
|
+
function Zo(e, t) {
|
|
4339
4518
|
let n = (e, t) => e.toLocaleLowerCase("tr") === t.toLocaleLowerCase("tr") || e.toLowerCase() === t.toLowerCase();
|
|
4340
4519
|
return e.fields.find((e) => n(e.label.trim(), t)) ?? e.fields.find((e) => n(e.key, t)) ?? null;
|
|
4341
4520
|
}
|
|
4342
4521
|
// src/validation.ts
|
|
4343
|
-
var
|
|
4522
|
+
var Qo = 10;
|
|
4523
|
+
function $o(e, t) {
|
|
4524
|
+
return e.fields.every((e) => {
|
|
4525
|
+
if (e.formula !== null) return !0;
|
|
4526
|
+
let n = t(e.key);
|
|
4527
|
+
return n === null || n === "" || Array.isArray(n) && n.length === 0 || e.default !== null && En(n, e.default);
|
|
4528
|
+
});
|
|
4529
|
+
}
|
|
4530
|
+
var es = class {
|
|
4344
4531
|
#e;
|
|
4345
4532
|
#t;
|
|
4346
4533
|
#n;
|
|
@@ -4350,20 +4537,21 @@ var Mo = 10, No = class {
|
|
|
4350
4537
|
#o = /* @__PURE__ */ new Map();
|
|
4351
4538
|
#s = /* @__PURE__ */ new Map();
|
|
4352
4539
|
#c = /* @__PURE__ */ new Map();
|
|
4353
|
-
#l = new
|
|
4354
|
-
#u;
|
|
4355
|
-
#d
|
|
4540
|
+
#l = /* @__PURE__ */ new Set();
|
|
4541
|
+
#u = new S();
|
|
4542
|
+
#d;
|
|
4543
|
+
#f = 0;
|
|
4356
4544
|
constructor(e, t, n = K.tr) {
|
|
4357
4545
|
this.#e = e, this.#t = t, this.#n = n;
|
|
4358
|
-
for (let t of e.fields)
|
|
4359
|
-
for (let t of e.checks) for (let e of
|
|
4360
|
-
this.#
|
|
4546
|
+
for (let t of e.fields) os(t, "unique") && (this.#i.set(t.key, /* @__PURE__ */ new Map()), this.#a.set(t.key, /* @__PURE__ */ new Map()));
|
|
4547
|
+
for (let t of e.checks) for (let e of tt(t)) this.#s.set(e, [...this.#s.get(e) ?? [], t]);
|
|
4548
|
+
this.#p(), this.#d = t.subscribe((e) => this.#m(e));
|
|
4361
4549
|
}
|
|
4362
4550
|
get version() {
|
|
4363
|
-
return this.#
|
|
4551
|
+
return this.#f;
|
|
4364
4552
|
}
|
|
4365
4553
|
issuesAt(e, t) {
|
|
4366
|
-
let n = this.#r.get(e)?.get(t) ?? [], r = this.#c.get(e), i = r ? [...r.values()].filter((e) => e.field === t) : [], a = this.#
|
|
4554
|
+
let n = this.#r.get(e)?.get(t) ?? [], r = this.#c.get(e), i = r ? [...r.values()].filter((e) => e.field === t) : [], a = this.#S(e, t);
|
|
4367
4555
|
return i.length === 0 && !a ? n : a ? [
|
|
4368
4556
|
...n,
|
|
4369
4557
|
...i,
|
|
@@ -4414,54 +4602,62 @@ var Mo = 10, No = class {
|
|
|
4414
4602
|
return this.#n;
|
|
4415
4603
|
}
|
|
4416
4604
|
setSettings(e) {
|
|
4417
|
-
e !== this.#n && (this.#n = e, this.#
|
|
4605
|
+
e !== this.#n && (this.#n = e, this.#p(), this.#h());
|
|
4418
4606
|
}
|
|
4419
4607
|
subscribe(e) {
|
|
4420
|
-
return this.#
|
|
4608
|
+
return this.#u.add(e);
|
|
4421
4609
|
}
|
|
4422
4610
|
dispose() {
|
|
4423
|
-
this.#
|
|
4611
|
+
this.#d();
|
|
4424
4612
|
}
|
|
4425
|
-
#
|
|
4426
|
-
this.#r.clear(), this.#c.clear();
|
|
4613
|
+
#p() {
|
|
4614
|
+
this.#r.clear(), this.#c.clear(), this.#l.clear();
|
|
4427
4615
|
for (let e of this.#i.values()) e.clear();
|
|
4428
4616
|
for (let e of this.#a.values()) e.clear();
|
|
4429
|
-
for (let e of this.#t.rowIds()) this.#
|
|
4617
|
+
for (let e of this.#t.rowIds()) this.#g(e);
|
|
4430
4618
|
}
|
|
4431
|
-
#
|
|
4619
|
+
#m(e) {
|
|
4432
4620
|
for (let t of e.operations) switch (t.kind) {
|
|
4433
4621
|
case "set":
|
|
4434
|
-
this.#t.has(t.rowId)
|
|
4622
|
+
if (!this.#t.has(t.rowId) || !this.#e.has(t.field)) break;
|
|
4623
|
+
this.#l.has(t.rowId) || this.#y(t.rowId) ? this.#g(t.rowId) : (this.#v(t.rowId, this.#e.field(t.field)), this.#_(t.rowId, this.#s.get(t.field) ?? []));
|
|
4435
4624
|
break;
|
|
4436
4625
|
case "insert":
|
|
4437
|
-
for (let e of t.rows) this.#t.has(e.rowId) && this.#
|
|
4626
|
+
for (let e of t.rows) this.#t.has(e.rowId) && this.#g(e.rowId);
|
|
4438
4627
|
break;
|
|
4439
|
-
case "remove": for (let e of t.rows) this.#
|
|
4628
|
+
case "remove": for (let e of t.rows) this.#b(e.rowId);
|
|
4440
4629
|
}
|
|
4441
|
-
this.#
|
|
4630
|
+
this.#h();
|
|
4442
4631
|
}
|
|
4443
|
-
#
|
|
4444
|
-
this.#o.clear(), this.#
|
|
4632
|
+
#h() {
|
|
4633
|
+
this.#o.clear(), this.#f++, this.#u.emit(this);
|
|
4445
4634
|
}
|
|
4446
|
-
#
|
|
4447
|
-
|
|
4448
|
-
|
|
4635
|
+
#g(e) {
|
|
4636
|
+
if (this.#y(e)) this.#b(e), this.#l.add(e);
|
|
4637
|
+
else {
|
|
4638
|
+
this.#l.delete(e);
|
|
4639
|
+
for (let t of this.#e.fields) this.#v(e, t);
|
|
4640
|
+
this.#_(e, this.#e.checks);
|
|
4641
|
+
}
|
|
4449
4642
|
}
|
|
4450
|
-
#
|
|
4643
|
+
#_(e, t) {
|
|
4451
4644
|
if (t.length === 0) return;
|
|
4452
4645
|
let n = (t) => this.#t.get(e, t), r = (e) => this.#e.field(e), i = this.#c.get(e);
|
|
4453
|
-
for (let a of t)
|
|
4646
|
+
for (let a of t) nt(a, r, n, this.#n) ? (i || (i = /* @__PURE__ */ new Map(), this.#c.set(e, i)), i.set(a.id, as(e, a, this.#e, this.#n))) : i?.delete(a.id);
|
|
4454
4647
|
i?.size === 0 && this.#c.delete(e);
|
|
4455
4648
|
}
|
|
4456
|
-
#
|
|
4457
|
-
let n = this.#t.get(e, t.key), r =
|
|
4458
|
-
r.length > 0 ? (i || (i = /* @__PURE__ */ new Map(), this.#r.set(e, i)), i.set(t.key, r)) : i && (i.delete(t.key), i.size === 0 && this.#r.delete(e)), this.#i.has(t.key) && this.#
|
|
4649
|
+
#v(e, t) {
|
|
4650
|
+
let n = this.#t.get(e, t.key), r = ts(e, t, n, this.#n), i = this.#r.get(e);
|
|
4651
|
+
r.length > 0 ? (i || (i = /* @__PURE__ */ new Map(), this.#r.set(e, i)), i.set(t.key, r)) : i && (i.delete(t.key), i.size === 0 && this.#r.delete(e)), this.#i.has(t.key) && this.#x(e, t.key, r.length === 0 ? ss(_(t, n, this.#n)) : null);
|
|
4459
4652
|
}
|
|
4460
|
-
#
|
|
4461
|
-
this.#
|
|
4462
|
-
for (let t of this.#i.keys()) this.#y(e, t, null);
|
|
4653
|
+
#y(e) {
|
|
4654
|
+
return $o(this.#e, (t) => this.#t.get(e, t));
|
|
4463
4655
|
}
|
|
4464
|
-
#
|
|
4656
|
+
#b(e) {
|
|
4657
|
+
this.#r.delete(e), this.#c.delete(e), this.#l.delete(e);
|
|
4658
|
+
for (let t of this.#i.keys()) this.#x(e, t, null);
|
|
4659
|
+
}
|
|
4660
|
+
#x(e, t, n) {
|
|
4465
4661
|
let r = this.#i.get(t), i = this.#a.get(t);
|
|
4466
4662
|
if (!r || !i) return;
|
|
4467
4663
|
let a = i.get(e);
|
|
@@ -4474,12 +4670,12 @@ var Mo = 10, No = class {
|
|
|
4474
4670
|
t.add(e), r.set(n, t), i.set(e, n);
|
|
4475
4671
|
}
|
|
4476
4672
|
}
|
|
4477
|
-
#
|
|
4673
|
+
#S(e, t) {
|
|
4478
4674
|
let n = this.#a.get(t)?.get(e), r = n === void 0 ? void 0 : this.#i.get(t)?.get(n);
|
|
4479
4675
|
if (!r || r.size < 2) return null;
|
|
4480
4676
|
let i = `${t}\u0000${n}`, a = this.#o.get(i);
|
|
4481
4677
|
a || (a = [...r].sort((e, t) => this.#t.indexOf(e) - this.#t.indexOf(t)), this.#o.set(i, a));
|
|
4482
|
-
let o = a.slice(0, 11).filter((t) => t !== e).slice(0,
|
|
4678
|
+
let o = a.slice(0, 11).filter((t) => t !== e).slice(0, Qo), s = ls(this.#t.get(e, t)), c = Object.freeze({
|
|
4483
4679
|
field: t,
|
|
4484
4680
|
value: s,
|
|
4485
4681
|
count: String(r.size)
|
|
@@ -4503,25 +4699,25 @@ var Mo = 10, No = class {
|
|
|
4503
4699
|
});
|
|
4504
4700
|
}
|
|
4505
4701
|
};
|
|
4506
|
-
function
|
|
4507
|
-
if (
|
|
4508
|
-
let i =
|
|
4702
|
+
function ts(e, t, n, r) {
|
|
4703
|
+
if (L(n)) return [Y(e, t, "formula_error", `The formula gives ${n.formulaError}.`, { error: n.formulaError })];
|
|
4704
|
+
let i = Re(t, n, r);
|
|
4509
4705
|
if (i) return [Y(e, t, i.code, i.message, i.params)];
|
|
4510
4706
|
if (n === null) return t.required ? [Y(e, t, "required", "This field is required and cannot be left empty.", {})] : [];
|
|
4511
|
-
let a = [], o =
|
|
4707
|
+
let a = [], o = _(t, n, r);
|
|
4512
4708
|
for (let n of t.rules) {
|
|
4513
|
-
let r =
|
|
4709
|
+
let r = ns(e, t, n, o);
|
|
4514
4710
|
r && a.push(r);
|
|
4515
4711
|
}
|
|
4516
4712
|
return a;
|
|
4517
4713
|
}
|
|
4518
|
-
function
|
|
4714
|
+
function ns(e, t, n, r) {
|
|
4519
4715
|
switch (n.rule) {
|
|
4520
4716
|
case "min":
|
|
4521
4717
|
case "max": {
|
|
4522
4718
|
let a = m(r);
|
|
4523
4719
|
if (a === null) return null;
|
|
4524
|
-
let o = i(
|
|
4720
|
+
let o = i(cs(a), n.value);
|
|
4525
4721
|
return n.rule === "min" && o < 0 ? Y(e, t, "min_value", `${a} is below the minimum of ${n.value}.`, {
|
|
4526
4722
|
value: a,
|
|
4527
4723
|
min: n.value
|
|
@@ -4567,7 +4763,7 @@ function Y(e, t, n, r, i) {
|
|
|
4567
4763
|
})
|
|
4568
4764
|
});
|
|
4569
4765
|
}
|
|
4570
|
-
var
|
|
4766
|
+
var rs = {
|
|
4571
4767
|
"=": "=",
|
|
4572
4768
|
"!=": "≠",
|
|
4573
4769
|
"<": "<",
|
|
@@ -4576,7 +4772,7 @@ var Io = {
|
|
|
4576
4772
|
">=": "≥",
|
|
4577
4773
|
filled: "filled",
|
|
4578
4774
|
empty: "empty"
|
|
4579
|
-
},
|
|
4775
|
+
}, is = {
|
|
4580
4776
|
"=": "equal to",
|
|
4581
4777
|
"!=": "different from",
|
|
4582
4778
|
"<": "less than",
|
|
@@ -4584,8 +4780,8 @@ var Io = {
|
|
|
4584
4780
|
">": "greater than",
|
|
4585
4781
|
">=": "at least"
|
|
4586
4782
|
};
|
|
4587
|
-
function
|
|
4588
|
-
let i = n.field(t.assert.field), a = (e) => n.field(e).label, o = (e) => e.other === null ? e.value === null ? "" :
|
|
4783
|
+
function as(e, t, n, r) {
|
|
4784
|
+
let i = n.field(t.assert.field), a = (e) => n.field(e).label, o = (e) => e.other === null ? e.value === null ? "" : ii(n.field(e.field), e.value, r) : a(e.other), s = t.assert.op, c = s === "filled" ? "check_filled" : s === "empty" ? "check_empty" : "check_compare", l = {
|
|
4589
4785
|
field: i.key,
|
|
4590
4786
|
type: i.type,
|
|
4591
4787
|
check: t.id,
|
|
@@ -4596,7 +4792,7 @@ function Ro(e, t, n, r) {
|
|
|
4596
4792
|
l[`when${t}Field`] = a(e.field), l[`when${t}Op`] = e.op, l[`when${t}Value`] = o(e);
|
|
4597
4793
|
});
|
|
4598
4794
|
for (let [e, n] of Object.entries(t.message ?? {})) l[`message.${e}`] = n;
|
|
4599
|
-
let u = t.when.length === 0 ? "" : ` when ${t.when.map((e) => e.op === "filled" || e.op === "empty" ? `${a(e.field)} is ${e.op}` : `${a(e.field)} ${
|
|
4795
|
+
let u = t.when.length === 0 ? "" : ` when ${t.when.map((e) => e.op === "filled" || e.op === "empty" ? `${a(e.field)} is ${e.op}` : `${a(e.field)} ${rs[e.op]} ${o(e)}`).join(" and ")}`, d = c === "check_filled" ? `${i.label} is required${u}.` : c === "check_empty" ? `${i.label} must be left empty${u}.` : `${i.label} must be ${is[s] ?? s} ${l.operand}${u}.`;
|
|
4600
4796
|
return Object.freeze({
|
|
4601
4797
|
id: `local|check|${t.id}|${e}`,
|
|
4602
4798
|
scope: "cell",
|
|
@@ -4615,55 +4811,55 @@ function Ro(e, t, n, r) {
|
|
|
4615
4811
|
params: Object.freeze(l)
|
|
4616
4812
|
});
|
|
4617
4813
|
}
|
|
4618
|
-
function
|
|
4814
|
+
function os(e, t) {
|
|
4619
4815
|
return e.rules.some((e) => e.rule === t);
|
|
4620
4816
|
}
|
|
4621
|
-
function
|
|
4817
|
+
function ss(e) {
|
|
4622
4818
|
if (e === null) return null;
|
|
4623
|
-
if (
|
|
4819
|
+
if (b(e)) return `id:${typeof e.id}:${e.id}`;
|
|
4624
4820
|
let t = typeof e == "number" || typeof e == "string" ? m(e) : null;
|
|
4625
|
-
return t === null ? `value:${JSON.stringify(e)}` : `number:${
|
|
4821
|
+
return t === null ? `value:${JSON.stringify(e)}` : `number:${cs(t)}`;
|
|
4626
4822
|
}
|
|
4627
|
-
function
|
|
4823
|
+
function cs(e) {
|
|
4628
4824
|
let t = e.startsWith("-"), [n = "0", r = ""] = (t ? e.slice(1) : e).split("."), i = n.replace(/^0+(?=\d)/, ""), a = r.replace(/0+$/, ""), o = a === "" ? i : `${i}.${a}`;
|
|
4629
4825
|
return o === "0" || !t ? o : `-${o}`;
|
|
4630
4826
|
}
|
|
4631
|
-
function
|
|
4632
|
-
return
|
|
4827
|
+
function ls(e) {
|
|
4828
|
+
return b(e) ? e.label : typeof e == "string" ? e : JSON.stringify(e);
|
|
4633
4829
|
}
|
|
4634
4830
|
// src/contract.ts
|
|
4635
|
-
var
|
|
4831
|
+
var us = [
|
|
4636
4832
|
"cell",
|
|
4637
4833
|
"row",
|
|
4638
4834
|
"sheet",
|
|
4639
4835
|
"workbook"
|
|
4640
|
-
],
|
|
4836
|
+
], ds = ["error", "warning"], fs = [
|
|
4641
4837
|
"pending",
|
|
4642
4838
|
"succeeded",
|
|
4643
4839
|
"partial",
|
|
4644
4840
|
"failed",
|
|
4645
4841
|
"cancelled"
|
|
4646
|
-
],
|
|
4842
|
+
], ps = [
|
|
4647
4843
|
"succeeded",
|
|
4648
4844
|
"failed",
|
|
4649
4845
|
"skipped"
|
|
4650
|
-
],
|
|
4846
|
+
], ms = [
|
|
4651
4847
|
"create",
|
|
4652
4848
|
"update",
|
|
4653
4849
|
"unchanged"
|
|
4654
4850
|
];
|
|
4655
|
-
function
|
|
4656
|
-
let t = new
|
|
4851
|
+
function hs(e) {
|
|
4852
|
+
let t = new _s(), n = t.object(e, "(root)");
|
|
4657
4853
|
return n === null ? t.done({}) : t.done({
|
|
4658
4854
|
...X("requestId", t.string(n.requestId, "requestId", !0)),
|
|
4659
4855
|
...X("issues", t.issues(n.issues, "issues")),
|
|
4660
4856
|
...X("plan", t.plans(n.plan, "plan"))
|
|
4661
4857
|
});
|
|
4662
4858
|
}
|
|
4663
|
-
function
|
|
4664
|
-
let t = new
|
|
4859
|
+
function gs(e) {
|
|
4860
|
+
let t = new _s(), n = t.object(e, "(root)");
|
|
4665
4861
|
if (n === null) return t.done({ status: "failed" });
|
|
4666
|
-
let r = t.oneOf(n.status, "status",
|
|
4862
|
+
let r = t.oneOf(n.status, "status", fs);
|
|
4667
4863
|
return t.done({
|
|
4668
4864
|
status: r ?? "failed",
|
|
4669
4865
|
...X("requestId", t.string(n.requestId, "requestId", !0)),
|
|
@@ -4676,7 +4872,7 @@ function Yo(e) {
|
|
|
4676
4872
|
function X(e, t) {
|
|
4677
4873
|
return t === void 0 ? {} : { [e]: t };
|
|
4678
4874
|
}
|
|
4679
|
-
var
|
|
4875
|
+
var _s = class {
|
|
4680
4876
|
#e = [];
|
|
4681
4877
|
done(t) {
|
|
4682
4878
|
if (this.#e.length > 0) throw new e("invalid_response", `The backend's answer is not in the expected shape:\n${this.#e.map((e) => ` ${e}`).join("\n")}`);
|
|
@@ -4686,12 +4882,12 @@ var Xo = class {
|
|
|
4686
4882
|
this.#e.push(`${e}: ${t}`);
|
|
4687
4883
|
}
|
|
4688
4884
|
object(e, t) {
|
|
4689
|
-
return typeof e == "object" && e && !Array.isArray(e) ? e : (this.problem(t, `must be an object; got ${
|
|
4885
|
+
return typeof e == "object" && e && !Array.isArray(e) ? e : (this.problem(t, `must be an object; got ${vs(e)}.`), null);
|
|
4690
4886
|
}
|
|
4691
4887
|
string(e, t, n = !1) {
|
|
4692
4888
|
if (!(e === void 0 && n)) {
|
|
4693
4889
|
if (typeof e == "string" && e !== "") return e;
|
|
4694
|
-
this.problem(t, `must be a non-empty string; got ${
|
|
4890
|
+
this.problem(t, `must be a non-empty string; got ${vs(e)}.`);
|
|
4695
4891
|
}
|
|
4696
4892
|
}
|
|
4697
4893
|
nullableString(e, t) {
|
|
@@ -4700,13 +4896,13 @@ var Xo = class {
|
|
|
4700
4896
|
oneOf(e, t, n, r = !1) {
|
|
4701
4897
|
if (!(e === void 0 && r)) {
|
|
4702
4898
|
if (typeof e == "string" && n.includes(e)) return e;
|
|
4703
|
-
this.problem(t, `must be one of ${n.join(", ")}; got ${
|
|
4899
|
+
this.problem(t, `must be one of ${n.join(", ")}; got ${vs(e)}.`);
|
|
4704
4900
|
}
|
|
4705
4901
|
}
|
|
4706
4902
|
array(e, t) {
|
|
4707
4903
|
if (e !== void 0) {
|
|
4708
4904
|
if (Array.isArray(e)) return e;
|
|
4709
|
-
this.problem(t, `must be an array; got ${
|
|
4905
|
+
this.problem(t, `must be an array; got ${vs(e)}.`);
|
|
4710
4906
|
}
|
|
4711
4907
|
}
|
|
4712
4908
|
issues(e, t) {
|
|
@@ -4716,14 +4912,14 @@ var Xo = class {
|
|
|
4716
4912
|
let n = this.object(e, t);
|
|
4717
4913
|
if (n === null) return null;
|
|
4718
4914
|
let r = this.string(n.code, `${t}.code`), i = n.blocking;
|
|
4719
|
-
return i !== void 0 && typeof i != "boolean" && this.problem(`${t}.blocking`, `must be true or false; got ${
|
|
4915
|
+
return i !== void 0 && typeof i != "boolean" && this.problem(`${t}.blocking`, `must be true or false; got ${vs(i)}.`), {
|
|
4720
4916
|
code: r ?? "",
|
|
4721
|
-
...X("scope", this.oneOf(n.scope, `${t}.scope`,
|
|
4917
|
+
...X("scope", this.oneOf(n.scope, `${t}.scope`, us, !0)),
|
|
4722
4918
|
...X("sheetId", this.nullableString(n.sheetId, `${t}.sheetId`)),
|
|
4723
4919
|
...X("rowId", this.nullableString(n.rowId, `${t}.rowId`)),
|
|
4724
4920
|
...X("field", this.nullableString(n.field, `${t}.field`)),
|
|
4725
4921
|
...X("targets", this.targets(n.targets, `${t}.targets`)),
|
|
4726
|
-
...X("severity", this.oneOf(n.severity, `${t}.severity`,
|
|
4922
|
+
...X("severity", this.oneOf(n.severity, `${t}.severity`, ds, !0)),
|
|
4727
4923
|
...X("blocking", typeof i == "boolean" ? i : void 0),
|
|
4728
4924
|
...X("message", this.string(n.message, `${t}.message`, !0)),
|
|
4729
4925
|
...X("params", this.params(n.params, `${t}.params`))
|
|
@@ -4746,7 +4942,7 @@ var Xo = class {
|
|
|
4746
4942
|
"string",
|
|
4747
4943
|
"number",
|
|
4748
4944
|
"boolean"
|
|
4749
|
-
].includes(typeof r) && this.problem(`${t}.${e}`, `must be text, a number, true, false or null; got ${
|
|
4945
|
+
].includes(typeof r) && this.problem(`${t}.${e}`, `must be text, a number, true, false or null; got ${vs(r)}.`);
|
|
4750
4946
|
return n;
|
|
4751
4947
|
}
|
|
4752
4948
|
}
|
|
@@ -4756,7 +4952,7 @@ var Xo = class {
|
|
|
4756
4952
|
row(e, t) {
|
|
4757
4953
|
let n = this.object(e, t);
|
|
4758
4954
|
if (n === null) return null;
|
|
4759
|
-
let r = this.string(n.rowId, `${t}.rowId`), i = this.oneOf(n.result, `${t}.result`,
|
|
4955
|
+
let r = this.string(n.rowId, `${t}.rowId`), i = this.oneOf(n.result, `${t}.result`, ps), a = n.data === void 0 ? void 0 : this.object(n.data, `${t}.data`);
|
|
4760
4956
|
return r === void 0 || i === void 0 ? null : {
|
|
4761
4957
|
rowId: r,
|
|
4762
4958
|
result: i,
|
|
@@ -4770,7 +4966,7 @@ var Xo = class {
|
|
|
4770
4966
|
plan(e, t) {
|
|
4771
4967
|
let n = this.object(e, t);
|
|
4772
4968
|
if (n === null) return null;
|
|
4773
|
-
let r = this.string(n.rowId, `${t}.rowId`), i = this.oneOf(n.action, `${t}.action`,
|
|
4969
|
+
let r = this.string(n.rowId, `${t}.rowId`), i = this.oneOf(n.action, `${t}.action`, ms), a = n.previous === void 0 ? void 0 : this.object(n.previous, `${t}.previous`);
|
|
4774
4970
|
return r === void 0 || i === void 0 ? null : {
|
|
4775
4971
|
rowId: r,
|
|
4776
4972
|
action: i,
|
|
@@ -4789,15 +4985,15 @@ var Xo = class {
|
|
|
4789
4985
|
}
|
|
4790
4986
|
}
|
|
4791
4987
|
};
|
|
4792
|
-
function
|
|
4988
|
+
function vs(e) {
|
|
4793
4989
|
return e === null ? "null" : Array.isArray(e) ? "an array" : typeof e == "string" ? JSON.stringify(e) : typeof e;
|
|
4794
4990
|
}
|
|
4795
4991
|
// src/draft.ts
|
|
4796
|
-
var
|
|
4797
|
-
function
|
|
4992
|
+
var ys = "tabula-grid.draft", bs = 1;
|
|
4993
|
+
function xs(e) {
|
|
4798
4994
|
let { schema: t, store: n, session: r } = e, i = e.marks ? e.marks.toJSON(n.rowIds()) : {};
|
|
4799
4995
|
return Object.freeze({
|
|
4800
|
-
format:
|
|
4996
|
+
format: ys,
|
|
4801
4997
|
version: 1,
|
|
4802
4998
|
id: e.id,
|
|
4803
4999
|
name: e.name ?? null,
|
|
@@ -4818,17 +5014,17 @@ function es(e) {
|
|
|
4818
5014
|
}),
|
|
4819
5015
|
view: Object.freeze({
|
|
4820
5016
|
columnWidths: Object.freeze({ ...e.view?.columnWidths }),
|
|
4821
|
-
...e.view?.columns ? { columns:
|
|
5017
|
+
...e.view?.columns ? { columns: ha(e.view.columns) } : {}
|
|
4822
5018
|
}),
|
|
4823
|
-
...Object.keys(i).length > 0 ? { marks:
|
|
5019
|
+
...Object.keys(i).length > 0 ? { marks: js(i) } : {}
|
|
4824
5020
|
});
|
|
4825
5021
|
}
|
|
4826
|
-
function
|
|
5022
|
+
function Ss(e, t, n = {}) {
|
|
4827
5023
|
if (e.module !== t.module) return {
|
|
4828
5024
|
status: "wrong_module",
|
|
4829
5025
|
module: e.module
|
|
4830
5026
|
};
|
|
4831
|
-
let r =
|
|
5027
|
+
let r = Cs(e, t, n.rename ?? {}), i = ks(e, t, r);
|
|
4832
5028
|
if (i && !n.accept) return {
|
|
4833
5029
|
status: "review",
|
|
4834
5030
|
changes: i
|
|
@@ -4851,7 +5047,7 @@ function ts(e, t, n = {}) {
|
|
|
4851
5047
|
let e = a(t);
|
|
4852
5048
|
e !== null && (s[e] = n);
|
|
4853
5049
|
}
|
|
4854
|
-
let c = e.view.columns ?
|
|
5050
|
+
let c = e.view.columns ? ga(e.view.columns, a) : void 0, l = {};
|
|
4855
5051
|
for (let [t, n] of Object.entries(e.marks ?? {})) for (let [e, r] of Object.entries(n)) {
|
|
4856
5052
|
let n = a(e);
|
|
4857
5053
|
n !== null && (l[t] = {
|
|
@@ -4867,11 +5063,11 @@ function ts(e, t, n = {}) {
|
|
|
4867
5063
|
columnWidths: Object.freeze(s),
|
|
4868
5064
|
...c ? { columns: c } : {}
|
|
4869
5065
|
}),
|
|
4870
|
-
marks:
|
|
5066
|
+
marks: js(l),
|
|
4871
5067
|
changes: i
|
|
4872
5068
|
};
|
|
4873
5069
|
}
|
|
4874
|
-
function
|
|
5070
|
+
function Cs(t, n, r) {
|
|
4875
5071
|
let i = new Set(t.fields.map((e) => e.key)), a = /* @__PURE__ */ new Map();
|
|
4876
5072
|
for (let [t, o] of Object.entries(r)) {
|
|
4877
5073
|
if (!i.has(t)) throw new e("invalid_argument", `The draft has no field "${t}" to rename.`);
|
|
@@ -4880,9 +5076,9 @@ function ns(t, n, r) {
|
|
|
4880
5076
|
}
|
|
4881
5077
|
return a;
|
|
4882
5078
|
}
|
|
4883
|
-
function
|
|
4884
|
-
let r =
|
|
4885
|
-
let o = r.get(n.key) ?? n.key, s = t.has(o) ? o : null, c = e.rows.map((e) => e.values[n.key] ?? null).filter((e) => e !== null), l = s !== null && (s !== n.key || t.field(s).type !== n.type) ? c.filter((e) =>
|
|
5079
|
+
function ws(e, t, n = {}) {
|
|
5080
|
+
let r = Cs(e, t, n.rename ?? {}), i = n.settings ?? K.tr, a = /* @__PURE__ */ new Set(), o = 0, s = e.fields.map((n) => {
|
|
5081
|
+
let o = r.get(n.key) ?? n.key, s = t.has(o) ? o : null, c = e.rows.map((e) => e.values[n.key] ?? null).filter((e) => e !== null), l = s !== null && (s !== n.key || t.field(s).type !== n.type) ? c.filter((e) => Re(t.field(s), e, i) !== null).length : 0;
|
|
4886
5082
|
return s !== null && a.add(s), Object.freeze({
|
|
4887
5083
|
key: n.key,
|
|
4888
5084
|
label: n.label ?? null,
|
|
@@ -4900,10 +5096,10 @@ function rs(e, t, n = {}) {
|
|
|
4900
5096
|
losing: o
|
|
4901
5097
|
});
|
|
4902
5098
|
}
|
|
4903
|
-
function
|
|
5099
|
+
function Ts(e, t) {
|
|
4904
5100
|
let n = new Set(e.fields.map((e) => e.key)), r = t.fields.filter((e) => !n.has(e.key)), i = [];
|
|
4905
5101
|
for (let n of e.fields.filter((e) => !t.has(e.key))) for (let e of r) {
|
|
4906
|
-
let t = e.type === n.type ?
|
|
5102
|
+
let t = e.type === n.type ? Es(n, e) : 0;
|
|
4907
5103
|
t > 0 && i.push({
|
|
4908
5104
|
from: n.key,
|
|
4909
5105
|
to: e.key,
|
|
@@ -4915,17 +5111,17 @@ function is(e, t) {
|
|
|
4915
5111
|
for (let e of i) !(e.from in a) && !o.has(e.to) && (a[e.from] = e.to, o.add(e.to));
|
|
4916
5112
|
return a;
|
|
4917
5113
|
}
|
|
4918
|
-
function
|
|
5114
|
+
function Es(e, t) {
|
|
4919
5115
|
let n = (e, t) => e.filter((e) => t.includes(e)).length;
|
|
4920
|
-
return 2 * n(
|
|
5116
|
+
return 2 * n(Ds(e.label ?? ""), Ds(t.label)) + n(Os(e.key), Os(t.key));
|
|
4921
5117
|
}
|
|
4922
|
-
function
|
|
5118
|
+
function Ds(e) {
|
|
4923
5119
|
return e.toLocaleLowerCase("tr").split(/[^\p{L}\p{N}]+/u).filter((e) => e.length > 1);
|
|
4924
5120
|
}
|
|
4925
|
-
function
|
|
4926
|
-
return
|
|
5121
|
+
function Os(e) {
|
|
5122
|
+
return Ds(e.replace(/([a-z0-9])([A-Z])/g, "$1 $2"));
|
|
4927
5123
|
}
|
|
4928
|
-
function
|
|
5124
|
+
function ks(e, t, n) {
|
|
4929
5125
|
let r = new Map(e.fields.map((e) => [n.get(e.key) ?? e.key, e])), i = t.fields.filter((e) => !r.has(e.key)).map((e) => e.key), a = e.fields.filter((e) => !t.has(n.get(e.key) ?? e.key)).map((e) => e.key), o = t.fields.flatMap((e) => {
|
|
4930
5126
|
let t = r.get(e.key);
|
|
4931
5127
|
return t && t.type !== e.type ? [{
|
|
@@ -4949,33 +5145,33 @@ function cs(e, t, n) {
|
|
|
4949
5145
|
losing: l
|
|
4950
5146
|
};
|
|
4951
5147
|
}
|
|
4952
|
-
function
|
|
5148
|
+
function As(t) {
|
|
4953
5149
|
let n = [], r = (e, t) => {
|
|
4954
5150
|
n.push(`${e}: ${t}`);
|
|
4955
5151
|
}, i = Z(t);
|
|
4956
5152
|
if (!i) throw new e("invalid_draft", "A draft must be an object.");
|
|
4957
|
-
i.format !== "tabula-grid.draft" && r("format", `must be "${
|
|
4958
|
-
let a = (e, t) => typeof e != "string" || e === "" ? (r(t, "must be a non-empty string."), "") : e, o = (e, t) => !Number.isSafeInteger(e) || e < 0 ? (r(t, "must be a whole number, 0 or more."), 0) : e, s = a(i.id, "id"), c = i.name === null || i.name === void 0 ? null : a(i.name, "name"), l = a(i.module, "module"), u = o(i.schemaVersion, "schemaVersion"), d = a(i.sheetId, "sheetId"), f = a(i.savedAt, "savedAt"), p = o(i.revision, "revision"), m =
|
|
5153
|
+
i.format !== "tabula-grid.draft" && r("format", `must be "${ys}".`), i.version !== 1 && r("version", "must be 1; a draft of another version of this format cannot be read.");
|
|
5154
|
+
let a = (e, t) => typeof e != "string" || e === "" ? (r(t, "must be a non-empty string."), "") : e, o = (e, t) => !Number.isSafeInteger(e) || e < 0 ? (r(t, "must be a whole number, 0 or more."), 0) : e, s = a(i.id, "id"), c = i.name === null || i.name === void 0 ? null : a(i.name, "name"), l = a(i.module, "module"), u = o(i.schemaVersion, "schemaVersion"), d = a(i.sheetId, "sheetId"), f = a(i.savedAt, "savedAt"), p = o(i.revision, "revision"), m = Ms(i.fields, "fields", r).flatMap((e, t) => {
|
|
4959
5155
|
let n = Z(e), i = n?.type;
|
|
4960
|
-
if (!n || !
|
|
5156
|
+
if (!n || !Lt.includes(i)) return r(`fields[${t}]`, `must have a key and one of the field types (${Lt.join(", ")}).`), [];
|
|
4961
5157
|
let o = n.label === void 0 ? void 0 : a(n.label, `fields[${t}].label`);
|
|
4962
5158
|
return [{
|
|
4963
5159
|
key: a(n.key, `fields[${t}].key`),
|
|
4964
5160
|
type: i,
|
|
4965
5161
|
...o ? { label: o } : {}
|
|
4966
5162
|
}];
|
|
4967
|
-
}), ee =
|
|
4968
|
-
let n =
|
|
5163
|
+
}), ee = Ms(i.rows, "rows", r).flatMap((e, t) => {
|
|
5164
|
+
let n = Ns(e, `rows[${t}]`, r);
|
|
4969
5165
|
return n ? [n] : [];
|
|
4970
|
-
}), h = Z(i.session), te =
|
|
4971
|
-
let n =
|
|
5166
|
+
}), h = Z(i.session), te = Ms(h?.results, "session.results", r).flatMap((e, t) => {
|
|
5167
|
+
let n = Ps(e, `session.results[${t}]`, r);
|
|
4972
5168
|
return n ? [n] : [];
|
|
4973
|
-
}), ne = h?.pending === null || h?.pending === void 0 ? null :
|
|
5169
|
+
}), ne = h?.pending === null || h?.pending === void 0 ? null : Fs(h.pending, "session.pending", r), re = Z(Z(i.view)?.columnWidths) ?? {}, ie = {};
|
|
4974
5170
|
for (let [e, t] of Object.entries(re)) typeof t == "number" && Number.isFinite(t) && t > 0 ? ie[e] = t : r(`view.columnWidths.${e}`, "must be a number of pixels.");
|
|
4975
|
-
let ae =
|
|
5171
|
+
let ae = ma(Z(i.view)?.columns, "view.columns", r), oe = vt(i.marks, "marks", r);
|
|
4976
5172
|
if (n.length > 0) throw new e("invalid_draft", `The draft cannot be read:\n${n.map((e) => ` ${e}`).join("\n")}`);
|
|
4977
5173
|
return Object.freeze({
|
|
4978
|
-
format:
|
|
5174
|
+
format: ys,
|
|
4979
5175
|
version: 1,
|
|
4980
5176
|
id: s,
|
|
4981
5177
|
name: c,
|
|
@@ -4994,24 +5190,24 @@ function ls(t) {
|
|
|
4994
5190
|
columnWidths: Object.freeze(ie),
|
|
4995
5191
|
...ae ? { columns: ae } : {}
|
|
4996
5192
|
}),
|
|
4997
|
-
...Object.keys(oe).length > 0 ? { marks:
|
|
5193
|
+
...Object.keys(oe).length > 0 ? { marks: js(oe) } : {}
|
|
4998
5194
|
});
|
|
4999
5195
|
}
|
|
5000
|
-
function
|
|
5196
|
+
function js(e) {
|
|
5001
5197
|
return Object.freeze(Object.fromEntries(Object.entries(e).map(([e, t]) => [e, Object.freeze({ ...t })])));
|
|
5002
5198
|
}
|
|
5003
5199
|
function Z(e) {
|
|
5004
5200
|
return typeof e == "object" && e && !Array.isArray(e) ? e : null;
|
|
5005
5201
|
}
|
|
5006
|
-
function
|
|
5202
|
+
function Ms(e, t, n) {
|
|
5007
5203
|
return Array.isArray(e) ? e : (n(t, "must be an array."), []);
|
|
5008
5204
|
}
|
|
5009
|
-
function
|
|
5205
|
+
function Ns(e, t, n) {
|
|
5010
5206
|
let r = Z(e), i = Z(r?.values);
|
|
5011
5207
|
if (!r || typeof r.rowId != "string" || r.rowId === "" || !i) return n(t, "must have a rowId and values."), null;
|
|
5012
5208
|
let a = {};
|
|
5013
5209
|
for (let [e, r] of Object.entries(i)) try {
|
|
5014
|
-
a[e] =
|
|
5210
|
+
a[e] = Cn(r, `${t}.values.${e}`);
|
|
5015
5211
|
} catch (r) {
|
|
5016
5212
|
n(`${t}.values.${e}`, r instanceof Error ? r.message : String(r));
|
|
5017
5213
|
}
|
|
@@ -5020,12 +5216,12 @@ function fs(e, t, n) {
|
|
|
5020
5216
|
values: Object.freeze(a)
|
|
5021
5217
|
});
|
|
5022
5218
|
}
|
|
5023
|
-
function
|
|
5219
|
+
function Ps(e, t, n) {
|
|
5024
5220
|
let r = Z(e), i = r?.outcome;
|
|
5025
5221
|
if (!r || typeof r.rowId != "string" || typeof r.requestId != "string" || i !== "succeeded" && i !== "failed" && i !== "skipped") return n(t, "must have a rowId, a requestId and an outcome of succeeded, failed or skipped."), null;
|
|
5026
5222
|
let a = {};
|
|
5027
5223
|
try {
|
|
5028
|
-
a =
|
|
5224
|
+
a = Cn(Z(r.data) ?? {}, `${t}.data`);
|
|
5029
5225
|
} catch (e) {
|
|
5030
5226
|
n(`${t}.data`, e instanceof Error ? e.message : String(e));
|
|
5031
5227
|
}
|
|
@@ -5036,7 +5232,7 @@ function ps(e, t, n) {
|
|
|
5036
5232
|
data: a
|
|
5037
5233
|
});
|
|
5038
5234
|
}
|
|
5039
|
-
function
|
|
5235
|
+
function Fs(e, t, n) {
|
|
5040
5236
|
let r = Z(e), i = Z(r?.request);
|
|
5041
5237
|
if (!r || !i || [
|
|
5042
5238
|
"requestId",
|
|
@@ -5044,8 +5240,8 @@ function ms(e, t, n) {
|
|
|
5044
5240
|
"module",
|
|
5045
5241
|
"sheetId"
|
|
5046
5242
|
].some((e) => typeof i[e] != "string") || ["schemaVersion", "revision"].some((e) => !Number.isSafeInteger(i[e])) || r.operationId !== null && typeof r.operationId != "string") return n(t, "must hold the request of the run with no answer, and its operationId or null."), null;
|
|
5047
|
-
let a =
|
|
5048
|
-
let i =
|
|
5243
|
+
let a = Ms(i.rows, `${t}.request.rows`, n).flatMap((e, r) => {
|
|
5244
|
+
let i = Ns(e, `${t}.request.rows[${r}]`, n);
|
|
5049
5245
|
return i ? [i] : [];
|
|
5050
5246
|
});
|
|
5051
5247
|
return Object.freeze({
|
|
@@ -5057,11 +5253,11 @@ function ms(e, t, n) {
|
|
|
5057
5253
|
});
|
|
5058
5254
|
}
|
|
5059
5255
|
// src/workbook.ts
|
|
5060
|
-
var
|
|
5061
|
-
function
|
|
5062
|
-
let t =
|
|
5256
|
+
var Is = "tabula-grid.workbook", Ls = 1;
|
|
5257
|
+
function Rs(e) {
|
|
5258
|
+
let t = Ks(Bs([]), e.sheet);
|
|
5063
5259
|
return Q({
|
|
5064
|
-
format:
|
|
5260
|
+
format: Is,
|
|
5065
5261
|
version: 1,
|
|
5066
5262
|
id: e.id,
|
|
5067
5263
|
module: e.module,
|
|
@@ -5069,13 +5265,13 @@ function _s(e) {
|
|
|
5069
5265
|
sheets: [t]
|
|
5070
5266
|
});
|
|
5071
5267
|
}
|
|
5072
|
-
function
|
|
5268
|
+
function zs(t, n = {}) {
|
|
5073
5269
|
let r = typeof t == "object" && t && !Array.isArray(t) ? t : null;
|
|
5074
5270
|
if (!r) throw new e("invalid_workbook", "A workbook must be an object.");
|
|
5075
5271
|
if (r.format === "tabula-grid.draft") {
|
|
5076
|
-
let e =
|
|
5272
|
+
let e = As(t);
|
|
5077
5273
|
return Q({
|
|
5078
|
-
format:
|
|
5274
|
+
format: Is,
|
|
5079
5275
|
version: 1,
|
|
5080
5276
|
id: e.id,
|
|
5081
5277
|
module: e.module,
|
|
@@ -5092,7 +5288,7 @@ function vs(t, n = {}) {
|
|
|
5092
5288
|
let i = [], a = (e, t) => {
|
|
5093
5289
|
i.push(`${e}: ${t}`);
|
|
5094
5290
|
}, o = (e, t) => typeof e != "string" || e.trim() === "" ? (a(t, "must be a non-empty string."), "") : e;
|
|
5095
|
-
r.format !== "tabula-grid.workbook" && a("format", `must be "${
|
|
5291
|
+
r.format !== "tabula-grid.workbook" && a("format", `must be "${Is}".`), r.version !== 1 && a("version", "must be 1.");
|
|
5096
5292
|
let s = o(r.id, "id"), c = o(r.module, "module"), l = Array.isArray(r.sheets) ? r.sheets : [], u = /* @__PURE__ */ new Set();
|
|
5097
5293
|
Array.isArray(r.sheets) && l.length !== 0 || a("sheets", "must be a list of one sheet or more.");
|
|
5098
5294
|
let d = l.flatMap((e, t) => {
|
|
@@ -5102,7 +5298,7 @@ function vs(t, n = {}) {
|
|
|
5102
5298
|
u.has(i) && a(`${n}.sheetId`, `"${i}" is another sheet's too.`), u.add(i);
|
|
5103
5299
|
let s = r.template === null || r.template === void 0 ? null : o(r.template, `${n}.template`), l = null;
|
|
5104
5300
|
if (r.draft !== null && r.draft !== void 0) try {
|
|
5105
|
-
l =
|
|
5301
|
+
l = As(r.draft), l.module !== c && a(`${n}.draft.module`, `must be "${c}", the workbook's.`);
|
|
5106
5302
|
} catch (e) {
|
|
5107
5303
|
a(`${n}.draft`, e instanceof Error ? e.message.split("\n")[0] ?? "" : String(e));
|
|
5108
5304
|
}
|
|
@@ -5111,12 +5307,12 @@ function vs(t, n = {}) {
|
|
|
5111
5307
|
name: o(r.name, `${n}.name`),
|
|
5112
5308
|
template: s,
|
|
5113
5309
|
draft: l,
|
|
5114
|
-
meta:
|
|
5310
|
+
meta: Js(r.meta, `${n}.meta`, a)
|
|
5115
5311
|
}];
|
|
5116
5312
|
});
|
|
5117
5313
|
if (i.length > 0) throw new e("invalid_workbook", `The workbook cannot be read:\n${i.map((e) => ` ${e}`).join("\n")}`);
|
|
5118
5314
|
return Q({
|
|
5119
|
-
format:
|
|
5315
|
+
format: Is,
|
|
5120
5316
|
version: 1,
|
|
5121
5317
|
id: s,
|
|
5122
5318
|
module: c,
|
|
@@ -5124,13 +5320,13 @@ function vs(t, n = {}) {
|
|
|
5124
5320
|
sheets: d
|
|
5125
5321
|
});
|
|
5126
5322
|
}
|
|
5127
|
-
function
|
|
5323
|
+
function Bs(e) {
|
|
5128
5324
|
let t = new Set(e.map((e) => e.sheetId)), n = 1;
|
|
5129
5325
|
for (; t.has(`sheet-${n}`);) n++;
|
|
5130
5326
|
return `sheet-${n}`;
|
|
5131
5327
|
}
|
|
5132
|
-
function
|
|
5133
|
-
let r =
|
|
5328
|
+
function Vs(e, t, n) {
|
|
5329
|
+
let r = Ks(Bs(e.sheets), t), i = n === void 0 ? -1 : e.sheets.findIndex((e) => e.sheetId === n), a = [...e.sheets];
|
|
5134
5330
|
return a.splice(i < 0 ? a.length : i + 1, 0, r), {
|
|
5135
5331
|
workbook: Q({
|
|
5136
5332
|
...e,
|
|
@@ -5140,8 +5336,8 @@ function bs(e, t, n) {
|
|
|
5140
5336
|
sheetId: r.sheetId
|
|
5141
5337
|
};
|
|
5142
5338
|
}
|
|
5143
|
-
function
|
|
5144
|
-
if (
|
|
5339
|
+
function Hs(t, n, r) {
|
|
5340
|
+
if (qs(t, n), r.name !== void 0 && r.name.trim() === "") throw new e("invalid_argument", "A sheet's name must not be empty.");
|
|
5145
5341
|
return Q({
|
|
5146
5342
|
...t,
|
|
5147
5343
|
sheets: t.sheets.map((e) => e.sheetId === n ? {
|
|
@@ -5151,8 +5347,8 @@ function xs(t, n, r) {
|
|
|
5151
5347
|
} : e)
|
|
5152
5348
|
});
|
|
5153
5349
|
}
|
|
5154
|
-
function
|
|
5155
|
-
if (
|
|
5350
|
+
function Us(t, n) {
|
|
5351
|
+
if (qs(t, n), t.sheets.length === 1) throw new e("invalid_argument", "A workbook keeps one sheet at least.");
|
|
5156
5352
|
let r = t.sheets.findIndex((e) => e.sheetId === n), i = t.sheets.filter((e) => e.sheetId !== n), a = t.active === n ? i[Math.min(r, i.length - 1)]?.sheetId ?? "" : t.active;
|
|
5157
5353
|
return Q({
|
|
5158
5354
|
...t,
|
|
@@ -5160,20 +5356,20 @@ function Ss(t, n) {
|
|
|
5160
5356
|
sheets: i
|
|
5161
5357
|
});
|
|
5162
5358
|
}
|
|
5163
|
-
function
|
|
5164
|
-
let r =
|
|
5359
|
+
function Ws(e, t, n) {
|
|
5360
|
+
let r = qs(e, t), i = e.sheets.filter((e) => e.sheetId !== t);
|
|
5165
5361
|
return i.splice(Math.max(0, Math.min(Math.trunc(n), i.length)), 0, r), Q({
|
|
5166
5362
|
...e,
|
|
5167
5363
|
sheets: i
|
|
5168
5364
|
});
|
|
5169
5365
|
}
|
|
5170
|
-
function
|
|
5171
|
-
return
|
|
5366
|
+
function Gs(e, t) {
|
|
5367
|
+
return qs(e, t), Q({
|
|
5172
5368
|
...e,
|
|
5173
5369
|
active: t
|
|
5174
5370
|
});
|
|
5175
5371
|
}
|
|
5176
|
-
function
|
|
5372
|
+
function Ks(t, n) {
|
|
5177
5373
|
if (n.name.trim() === "") throw new e("invalid_argument", "A sheet's name must not be empty.");
|
|
5178
5374
|
return {
|
|
5179
5375
|
sheetId: t,
|
|
@@ -5183,12 +5379,12 @@ function Ts(t, n) {
|
|
|
5183
5379
|
meta: n.meta ?? {}
|
|
5184
5380
|
};
|
|
5185
5381
|
}
|
|
5186
|
-
function
|
|
5382
|
+
function qs(t, n) {
|
|
5187
5383
|
let r = t.sheets.find((e) => e.sheetId === n);
|
|
5188
5384
|
if (!r) throw new e("invalid_argument", `The workbook has no sheet "${n}".`);
|
|
5189
5385
|
return r;
|
|
5190
5386
|
}
|
|
5191
|
-
function
|
|
5387
|
+
function Js(e, t, n) {
|
|
5192
5388
|
if (e == null) return {};
|
|
5193
5389
|
if (typeof e != "object" || Array.isArray(e)) return n(t, "must be an object."), {};
|
|
5194
5390
|
let r = {};
|
|
@@ -5209,11 +5405,11 @@ function Q(e) {
|
|
|
5209
5405
|
});
|
|
5210
5406
|
}
|
|
5211
5407
|
// src/saver.ts
|
|
5212
|
-
var
|
|
5408
|
+
var Ys = 2e3, Xs = class {
|
|
5213
5409
|
id;
|
|
5214
5410
|
#e;
|
|
5215
5411
|
#t;
|
|
5216
|
-
#n = new
|
|
5412
|
+
#n = new S();
|
|
5217
5413
|
#r = [];
|
|
5218
5414
|
#i;
|
|
5219
5415
|
#a = Object.freeze({
|
|
@@ -5228,9 +5424,9 @@ var Os = 2e3, ks = class {
|
|
|
5228
5424
|
#u = null;
|
|
5229
5425
|
#d = !1;
|
|
5230
5426
|
constructor(t) {
|
|
5231
|
-
let n = t.delay ??
|
|
5427
|
+
let n = t.delay ?? Ys;
|
|
5232
5428
|
if (!Number.isFinite(n) || n < 0) throw new e("invalid_argument", `delay must be 0 or more milliseconds; got ${n}.`);
|
|
5233
|
-
this.#e = t, this.#t = n, this.#i = t.name ?? null, this.id = t.id ?? (t.createId ??
|
|
5429
|
+
this.#e = t, this.#t = n, this.#i = t.name ?? null, this.id = t.id ?? (t.createId ?? xn("d"))(), this.#r.push(t.store.subscribe(() => this.changed())), t.marks && this.#r.push(t.marks.subscribe(() => this.changed())), t.session && (this.#r.push(t.session.results.subscribe(() => this.changed())), this.#r.push(t.session.subscribe(() => this.#p())));
|
|
5234
5430
|
}
|
|
5235
5431
|
get version() {
|
|
5236
5432
|
return this.#o;
|
|
@@ -5273,7 +5469,7 @@ var Os = 2e3, ks = class {
|
|
|
5273
5469
|
for (let e of this.#r) e();
|
|
5274
5470
|
}
|
|
5275
5471
|
async #f() {
|
|
5276
|
-
let e = this.#e, t = this.#s, n =
|
|
5472
|
+
let e = this.#e, t = this.#s, n = xs({
|
|
5277
5473
|
id: this.id,
|
|
5278
5474
|
name: this.#i,
|
|
5279
5475
|
schema: e.schema,
|
|
@@ -5324,7 +5520,7 @@ var Os = 2e3, ks = class {
|
|
|
5324
5520
|
...e
|
|
5325
5521
|
}), this.#o++, this.#n.emit(this);
|
|
5326
5522
|
}
|
|
5327
|
-
},
|
|
5523
|
+
}, Zs = 1e3, Qs = class {
|
|
5328
5524
|
schema;
|
|
5329
5525
|
store;
|
|
5330
5526
|
sheetId;
|
|
@@ -5338,7 +5534,7 @@ var Os = 2e3, ks = class {
|
|
|
5338
5534
|
#i;
|
|
5339
5535
|
#a;
|
|
5340
5536
|
#o;
|
|
5341
|
-
#s = new
|
|
5537
|
+
#s = new S();
|
|
5342
5538
|
#c;
|
|
5343
5539
|
#l = /* @__PURE__ */ new Map();
|
|
5344
5540
|
#u = /* @__PURE__ */ new Map();
|
|
@@ -5355,9 +5551,9 @@ var Os = 2e3, ks = class {
|
|
|
5355
5551
|
#g = null;
|
|
5356
5552
|
#_ = !1;
|
|
5357
5553
|
constructor(t) {
|
|
5358
|
-
let n = t.pollInterval ??
|
|
5554
|
+
let n = t.pollInterval ?? Zs;
|
|
5359
5555
|
if (!Number.isFinite(n) || n < 0) throw new e("invalid_argument", `pollInterval must be 0 or more milliseconds; got ${n}.`);
|
|
5360
|
-
this.schema = t.schema, this.store = t.store, this.sheetId = t.sheetId ?? t.schema.module, this.#n = t.validator === void 0, this.validator = t.validator ?? new
|
|
5556
|
+
this.schema = t.schema, this.store = t.store, this.sheetId = t.sheetId ?? t.schema.module, this.#n = t.validator === void 0, this.validator = t.validator ?? new es(t.schema, t.store, t.settings), this.#e = t.adapters, this.#t = t.history ?? null, this.#r = t.createRequestId ?? xn("req"), this.#i = n, this.#a = new $s(this.validator, this.store, this.schema), this.#o = new ec(), this.issues = this.#a, this.results = this.#o, this.#c = this.store.subscribe((e) => this.#A(e)), t.restore && this.#j(t.restore);
|
|
5361
5557
|
}
|
|
5362
5558
|
persisted() {
|
|
5363
5559
|
let e = [];
|
|
@@ -5407,16 +5603,16 @@ var Os = 2e3, ks = class {
|
|
|
5407
5603
|
});
|
|
5408
5604
|
let i;
|
|
5409
5605
|
try {
|
|
5410
|
-
let r = await
|
|
5606
|
+
let r = await D(e(n, {
|
|
5411
5607
|
signal: t.signal,
|
|
5412
5608
|
requestId: n.requestId
|
|
5413
5609
|
}), t.signal);
|
|
5414
|
-
i = this.#D(n.requestId,
|
|
5610
|
+
i = this.#D(n.requestId, hs(r));
|
|
5415
5611
|
} catch (e) {
|
|
5416
5612
|
return this.#p === r ? (this.#p = null, this.#M({
|
|
5417
5613
|
phase: "idle",
|
|
5418
|
-
check:
|
|
5419
|
-
failure:
|
|
5614
|
+
check: tc(n, "failed"),
|
|
5615
|
+
failure: nc("preflight", e)
|
|
5420
5616
|
}), {
|
|
5421
5617
|
status: "failed",
|
|
5422
5618
|
issues: 0
|
|
@@ -5432,7 +5628,7 @@ var Os = 2e3, ks = class {
|
|
|
5432
5628
|
this.#p = null;
|
|
5433
5629
|
let a = (i.issues ?? []).map((e, t) => this.#O(e, "preflight", String(t), n.revision, null)).filter((e) => e !== null);
|
|
5434
5630
|
this.#a.replace((e) => e.source === "preflight", a);
|
|
5435
|
-
let o = a.some((e) => e.blocking && !e.stale) ? "invalid" : "valid", s =
|
|
5631
|
+
let o = a.some((e) => e.blocking && !e.stale) ? "invalid" : "valid", s = tc(n, o), c = /* @__PURE__ */ new Map(), l = new Set(n.rows.map((e) => e.rowId));
|
|
5436
5632
|
for (let e of i.plan ?? []) l.has(e.rowId) && !c.has(e.rowId) && c.set(e.rowId, e);
|
|
5437
5633
|
return this.#g = {
|
|
5438
5634
|
record: s,
|
|
@@ -5461,7 +5657,7 @@ var Os = 2e3, ks = class {
|
|
|
5461
5657
|
};
|
|
5462
5658
|
t = Object.freeze({
|
|
5463
5659
|
...this.#w(e),
|
|
5464
|
-
idempotencyKey: `${this.sheetId}:${this.store.revision}:${
|
|
5660
|
+
idempotencyKey: `${this.sheetId}:${this.store.revision}:${bn()}`
|
|
5465
5661
|
}), this.#t?.clear();
|
|
5466
5662
|
}
|
|
5467
5663
|
let n = t, r = new AbortController();
|
|
@@ -5480,11 +5676,11 @@ var Os = 2e3, ks = class {
|
|
|
5480
5676
|
});
|
|
5481
5677
|
let i;
|
|
5482
5678
|
try {
|
|
5483
|
-
let t = await
|
|
5679
|
+
let t = await D(e(n, {
|
|
5484
5680
|
signal: r.signal,
|
|
5485
5681
|
requestId: n.requestId
|
|
5486
5682
|
}), r.signal);
|
|
5487
|
-
i = this.#D(n.requestId,
|
|
5683
|
+
i = this.#D(n.requestId, gs(t));
|
|
5488
5684
|
} catch (e) {
|
|
5489
5685
|
return this.#y("process", e);
|
|
5490
5686
|
}
|
|
@@ -5521,11 +5717,11 @@ var Os = 2e3, ks = class {
|
|
|
5521
5717
|
});
|
|
5522
5718
|
let r;
|
|
5523
5719
|
try {
|
|
5524
|
-
let i = await
|
|
5720
|
+
let i = await D(e(this.#S(), {
|
|
5525
5721
|
signal: n.signal,
|
|
5526
5722
|
requestId: t.requestId
|
|
5527
5723
|
}), n.signal);
|
|
5528
|
-
r = this.#D(t.requestId,
|
|
5724
|
+
r = this.#D(t.requestId, gs(i));
|
|
5529
5725
|
} catch (e) {
|
|
5530
5726
|
return this.#y("status", e);
|
|
5531
5727
|
}
|
|
@@ -5536,7 +5732,7 @@ var Os = 2e3, ks = class {
|
|
|
5536
5732
|
if (e) {
|
|
5537
5733
|
this.#p = null, e.controller.abort(), this.#M({
|
|
5538
5734
|
phase: "idle",
|
|
5539
|
-
check:
|
|
5735
|
+
check: tc(e.request, "cancelled")
|
|
5540
5736
|
});
|
|
5541
5737
|
return;
|
|
5542
5738
|
}
|
|
@@ -5544,11 +5740,11 @@ var Os = 2e3, ks = class {
|
|
|
5544
5740
|
if (this.#d.phase === "processing" && t) {
|
|
5545
5741
|
if (t.operationId !== null && n) try {
|
|
5546
5742
|
await n(this.#S(), {
|
|
5547
|
-
signal:
|
|
5743
|
+
signal: In(),
|
|
5548
5744
|
requestId: t.requestId
|
|
5549
5745
|
});
|
|
5550
5746
|
} catch (e) {
|
|
5551
|
-
this.#M({ failure:
|
|
5747
|
+
this.#M({ failure: nc("cancel", e) });
|
|
5552
5748
|
}
|
|
5553
5749
|
else this.#m?.abort();
|
|
5554
5750
|
}
|
|
@@ -5571,12 +5767,12 @@ var Os = 2e3, ks = class {
|
|
|
5571
5767
|
let n = this.#e.processStatus;
|
|
5572
5768
|
if (!n) return this.#y("status", new e("invalid_argument", "The run is still going, and there is no processStatus adapter to follow it."), "unavailable");
|
|
5573
5769
|
try {
|
|
5574
|
-
await
|
|
5575
|
-
let e = await
|
|
5770
|
+
await Pn(this.#i, r.signal);
|
|
5771
|
+
let e = await D(n(this.#S(), {
|
|
5576
5772
|
signal: r.signal,
|
|
5577
5773
|
requestId: t.requestId
|
|
5578
5774
|
}), r.signal);
|
|
5579
|
-
i = this.#D(t.requestId,
|
|
5775
|
+
i = this.#D(t.requestId, gs(e));
|
|
5580
5776
|
} catch (e) {
|
|
5581
5777
|
return this.#y("status", e);
|
|
5582
5778
|
}
|
|
@@ -5612,7 +5808,7 @@ var Os = 2e3, ks = class {
|
|
|
5612
5808
|
let r = this.#d.run;
|
|
5613
5809
|
this.#m = null, this.#M({
|
|
5614
5810
|
phase: "unknown",
|
|
5615
|
-
failure:
|
|
5811
|
+
failure: nc(e, t, n),
|
|
5616
5812
|
run: r ? Object.freeze({
|
|
5617
5813
|
...r,
|
|
5618
5814
|
status: "unknown"
|
|
@@ -5663,7 +5859,7 @@ var Os = 2e3, ks = class {
|
|
|
5663
5859
|
let n = [], r = t.previous ?? {};
|
|
5664
5860
|
for (let i of this.schema.fields) {
|
|
5665
5861
|
if (!i.submit) continue;
|
|
5666
|
-
let a = this.store.get(e, i.key), o =
|
|
5862
|
+
let a = this.store.get(e, i.key), o = L(a) ? null : a;
|
|
5667
5863
|
t.action === "create" && o !== null ? n.push(Object.freeze({
|
|
5668
5864
|
field: i.key,
|
|
5669
5865
|
before: null,
|
|
@@ -5711,12 +5907,12 @@ var Os = 2e3, ks = class {
|
|
|
5711
5907
|
let t = {};
|
|
5712
5908
|
for (let n of this.schema.fields) if (n.submit) {
|
|
5713
5909
|
let r = this.store.get(e, n.key);
|
|
5714
|
-
t[n.key] =
|
|
5910
|
+
t[n.key] = L(r) ? null : n.type === "lookup" ? ic(r) : _(n, r, this.validator.settings);
|
|
5715
5911
|
}
|
|
5716
5912
|
return Object.freeze(t);
|
|
5717
5913
|
}
|
|
5718
5914
|
#E(e) {
|
|
5719
|
-
return this.schema.fields.every((t) => !t.submit || this.store.get(e, t.key) === null);
|
|
5915
|
+
return this.schema.fields.every((t) => !t.submit || this.store.get(e, t.key) === null) || $o(this.schema, (t) => this.store.get(e, t));
|
|
5720
5916
|
}
|
|
5721
5917
|
#D(t, n) {
|
|
5722
5918
|
if (n.requestId !== void 0 && n.requestId !== t) throw new e("invalid_response", `The answer is to request "${n.requestId}", not to "${t}", the one it came back for.`);
|
|
@@ -5730,7 +5926,7 @@ var Os = 2e3, ks = class {
|
|
|
5730
5926
|
for (let [t, n] of Object.entries(e.params ?? {})) o[t] = n === null ? "" : String(n);
|
|
5731
5927
|
let s = e.field ?? null;
|
|
5732
5928
|
s !== null && !this.schema.has(s) && (o.field ??= s, s = null);
|
|
5733
|
-
let c =
|
|
5929
|
+
let c = rc(e.scope, a, s), l = e.severity ?? "error", u = {
|
|
5734
5930
|
id: `${t}|${n}|${e.code}|${a ?? ""}|${s ?? ""}`,
|
|
5735
5931
|
scope: c,
|
|
5736
5932
|
source: t,
|
|
@@ -5798,11 +5994,11 @@ var Os = 2e3, ks = class {
|
|
|
5798
5994
|
...e
|
|
5799
5995
|
}) });
|
|
5800
5996
|
}
|
|
5801
|
-
},
|
|
5997
|
+
}, $s = class {
|
|
5802
5998
|
#e;
|
|
5803
5999
|
#t;
|
|
5804
6000
|
#n;
|
|
5805
|
-
#r = new
|
|
6001
|
+
#r = new S();
|
|
5806
6002
|
#i;
|
|
5807
6003
|
#a = [];
|
|
5808
6004
|
#o = null;
|
|
@@ -5871,19 +6067,19 @@ var Os = 2e3, ks = class {
|
|
|
5871
6067
|
cells: /* @__PURE__ */ new Map()
|
|
5872
6068
|
};
|
|
5873
6069
|
for (let t of this.#a) if (t.rowId === null) e.sheet.push(t);
|
|
5874
|
-
else if (t.field === null)
|
|
6070
|
+
else if (t.field === null) ac(e.rows, t.rowId, t);
|
|
5875
6071
|
else {
|
|
5876
6072
|
let n = e.cells.get(t.rowId);
|
|
5877
|
-
n || (n = /* @__PURE__ */ new Map(), e.cells.set(t.rowId, n)),
|
|
6073
|
+
n || (n = /* @__PURE__ */ new Map(), e.cells.set(t.rowId, n)), ac(n, t.field, t);
|
|
5878
6074
|
}
|
|
5879
6075
|
return this.#o = e, e;
|
|
5880
6076
|
}
|
|
5881
6077
|
#l() {
|
|
5882
6078
|
this.#s++, this.#r.emit(this);
|
|
5883
6079
|
}
|
|
5884
|
-
},
|
|
6080
|
+
}, ec = class {
|
|
5885
6081
|
#e = /* @__PURE__ */ new Map();
|
|
5886
|
-
#t = new
|
|
6082
|
+
#t = new S();
|
|
5887
6083
|
#n = /* @__PURE__ */ new Set();
|
|
5888
6084
|
#r = 0;
|
|
5889
6085
|
get version() {
|
|
@@ -5920,14 +6116,14 @@ function $(e) {
|
|
|
5920
6116
|
blocked: 0
|
|
5921
6117
|
};
|
|
5922
6118
|
}
|
|
5923
|
-
function
|
|
6119
|
+
function tc(e, t) {
|
|
5924
6120
|
return Object.freeze({
|
|
5925
6121
|
requestId: e.requestId,
|
|
5926
6122
|
revision: e.revision,
|
|
5927
6123
|
outcome: t
|
|
5928
6124
|
});
|
|
5929
6125
|
}
|
|
5930
|
-
function
|
|
6126
|
+
function nc(t, n, r) {
|
|
5931
6127
|
let i = n instanceof e && n.code === "invalid_response";
|
|
5932
6128
|
return Object.freeze({
|
|
5933
6129
|
stage: t,
|
|
@@ -5936,29 +6132,29 @@ function Fs(t, n, r) {
|
|
|
5936
6132
|
error: n
|
|
5937
6133
|
});
|
|
5938
6134
|
}
|
|
5939
|
-
function
|
|
6135
|
+
function rc(e, t, n) {
|
|
5940
6136
|
let r = e ?? (t === null ? "sheet" : n === null ? "row" : "cell");
|
|
5941
6137
|
return r === "cell" && n === null ? t === null ? "sheet" : "row" : r === "row" && t === null ? "sheet" : r;
|
|
5942
6138
|
}
|
|
5943
|
-
function
|
|
5944
|
-
return
|
|
6139
|
+
function ic(e) {
|
|
6140
|
+
return b(e) ? e.id : typeof e == "string" ? Object.freeze({ label: e }) : e;
|
|
5945
6141
|
}
|
|
5946
|
-
function
|
|
6142
|
+
function ac(e, t, n) {
|
|
5947
6143
|
let r = e.get(t);
|
|
5948
6144
|
r ? r.push(n) : e.set(t, [n]);
|
|
5949
6145
|
}
|
|
5950
6146
|
// src/find.ts
|
|
5951
|
-
var
|
|
5952
|
-
function
|
|
6147
|
+
var oc = "replace";
|
|
6148
|
+
function sc(e, t, n, r, i, a) {
|
|
5953
6149
|
if (i === "") return [];
|
|
5954
|
-
let o =
|
|
5955
|
-
for (let r of n) for (let n of s) o(
|
|
6150
|
+
let o = lc(i, a), s = r.filter((e) => t.has(e)), c = [];
|
|
6151
|
+
for (let r of n) for (let n of s) o(ii(t.field(n), e.get(r, n), a.settings)) && c.push({
|
|
5956
6152
|
rowId: r,
|
|
5957
6153
|
field: n
|
|
5958
6154
|
});
|
|
5959
6155
|
return c;
|
|
5960
6156
|
}
|
|
5961
|
-
function
|
|
6157
|
+
function cc(e, t, n, r, i, a) {
|
|
5962
6158
|
if (r === "") return {
|
|
5963
6159
|
replaced: 0,
|
|
5964
6160
|
skipped: 0,
|
|
@@ -5972,11 +6168,11 @@ function Vs(e, t, n, r, i, a) {
|
|
|
5972
6168
|
s++;
|
|
5973
6169
|
continue;
|
|
5974
6170
|
}
|
|
5975
|
-
let l =
|
|
6171
|
+
let l = uc(ii(n, e.get(c.rowId, c.field), a.settings), r, i, a);
|
|
5976
6172
|
l !== null && o.push({
|
|
5977
6173
|
rowId: c.rowId,
|
|
5978
6174
|
field: c.field,
|
|
5979
|
-
value:
|
|
6175
|
+
value: g(n, l, a.settings).value
|
|
5980
6176
|
});
|
|
5981
6177
|
}
|
|
5982
6178
|
let c = o.length === 0 ? null : e.setCells(o, { origin: a.origin ?? "replace" });
|
|
@@ -5986,11 +6182,11 @@ function Vs(e, t, n, r, i, a) {
|
|
|
5986
6182
|
change: c
|
|
5987
6183
|
};
|
|
5988
6184
|
}
|
|
5989
|
-
function
|
|
6185
|
+
function lc(e, t) {
|
|
5990
6186
|
let n = (e) => t.matchCase ? e : e.toLocaleLowerCase(t.locale), r = n(e);
|
|
5991
6187
|
return (e) => t.whole ? n(e) === r : n(e).includes(r);
|
|
5992
6188
|
}
|
|
5993
|
-
function
|
|
6189
|
+
function uc(e, t, n, r) {
|
|
5994
6190
|
let i = (e) => r.matchCase ? e : e.toLocaleLowerCase(r.locale);
|
|
5995
6191
|
if (r.whole) return i(e) === i(t) ? n : null;
|
|
5996
6192
|
let a = i(e), o = i(t), s = a.indexOf(o);
|
|
@@ -6001,7 +6197,7 @@ function Us(e, t, n, r) {
|
|
|
6001
6197
|
return c + e.slice(l);
|
|
6002
6198
|
}
|
|
6003
6199
|
// src/index.ts
|
|
6004
|
-
var
|
|
6005
|
-
export { sa as COLUMN_ALIGNS,
|
|
6200
|
+
var dc = "0.5.0";
|
|
6201
|
+
export { sa as COLUMN_ALIGNS, qe as COMPARISONS, Je as CONDITION_OPS, Rt as CUSTOMIZATIONS, gt as CellMarks, ta as DEFAULT_COLUMN_SIZING, ys as DRAFT_FORMAT, bs as DRAFT_VERSION, Xs as DraftSaver, Lt as FIELD_TYPES, fr as FORMULA_EMPTY, Cr as FORMULA_FUNCTIONS, kr as FORMULA_ORIGIN, Ar as FormulaEngine, Yo as IMPORT_ORIGIN, Ln as LOOKUP_ORIGIN, Bn as LookupResolver, C as MARK_COLORS, ca as MAX_SHOWN_DECIMALS, Kt as ModuleSchema, Ta as PLAIN_VIEW, qn as REDO_ORIGIN, oc as REPLACE_ORIGIN, Dn as RowStore, Qr as RowView, t as SchemaError, fo as Selection, Qi as SheetChanges, Qs as SheetSession, es as SheetValidator, Qa as TEMPLATE_FORMAT, $a as TEMPLATE_VERSION, e as TabulaError, Kn as UNDO_ORIGIN, Yn as UndoHistory, K as VALUE_SETTINGS, Sa as VIEWS_FORMAT, Ca as VIEWS_VERSION, wa as VIEW_NAME_LIMIT, Is as WORKBOOK_FORMAT, Ls as WORKBOOK_VERSION, Vs as addSheet, Aa as addView, Xi as adjustValue, jr as applyFormulas, Xo as applyImport, io as applyTemplate, la as arrangeColumns, ia as autoColumnWidth, nt as breaksCheck, tt as checkFields, ts as checkValue, aa as clampColumnWidth, Ci as compareValues, it as conditionHolds, xs as createDraft, Rs as createWorkbook, jo as csvDelimiterFor, Eo as decodeText, ci as defineValueSettings, wo as detectDelimiter, oi as digitsFor, Ti as distinctValues, ai as editText, Ea as emptyViews, ko as exportTable, ji as fillValues, fi as filterKey, pi as filterKeys, sc as findCells, ii as formatCell, B as formulaBool, Br as formulaCaret, V as formulaError, Nt as formulaFields, qr as formulaFromAddresses, pr as formulaNumber, Jr as formulaParts, z as formulaText, Hr as formulaWithKeys, Vr as formulaWithLabels, Bs as freeSheetId, ha as freezeColumnLayout, di as hasRange, ra as headerDisplayText, Lo as headerKey, No as importTable, Yi as isAdjustable, $o as isBlankRow, v as isFieldValue, L as isFormulaError, ga as mapColumnLayout, ws as mapDraft, Go as matchRows, fa as mergeColumnFormats, Ws as moveSheet, mr as numberArgument, Ss as openDraft, Gs as openSheet, Co as parseCsv, Mt as parseFormula, yo as parseTsv, hs as readCheckResponse, ma as readColumnLayout, As as readDraft, g as readInput, vt as readMarks, gs as readProcessResponse, wt as readStyleRules, no as readTemplate, Wa as readViewState, Fa as readViews, zs as readWorkbook, Us as removeSheet, Na as removeView, Ma as renameView, cc as replaceCells, na as resolveColumnSizing, wi as rowOrder, Dt as rowStyles, rt as rowsBreaking, ea as rowsChanged, gi as rowsContaining, _t as rowsMarked, hi as rowsMatching, Ot as rowsStyled, $r as rowsWithIssues, ei as rowsWithResult, _a as sameColumnFormats, Oa as sameView, Pa as setDefaultView, Et as styleApplies, Tt as styleRuleToJson, Io as suggestColumns, Wo as suggestMatch, Ts as suggestRenames, ri as summarizeCells, ro as templateProblems, To as toCsv, bo as toTsv, ja as updateView, Re as valueProblem, dc as version, Da as viewFor, ka as viewNameProblem, ua as withColumn, da as withColumnFormat, ao as withDefaults, Hs as withSheet, pa as withoutColumnFormats };
|
|
6006
6202
|
|
|
6007
6203
|
//# sourceMappingURL=index.js.map
|