@nivaro/react 0.3.58 → 0.3.60
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/components/fields/RelationField.js +110 -80
- package/dist/full.css +1 -1
- package/dist/hooks/useRelationOptions.js +1 -0
- package/dist/hooks/useSessionRecorder.js +1 -1
- package/dist/index.d.ts +32 -1
- package/dist/index.js +523 -520
- package/dist/shared/components/CollectionBrowserView.js +2083 -2052
- package/dist/shared/components/DataTable.js +497 -465
- package/dist/shared/components/ItemEditForm.js +4430 -4282
- package/dist/shared/components/PageRenderer.js +537 -508
- package/dist/shared/components/QueryTable.js +74 -74
- package/dist/shared/components/WidgetSlot.js +543 -520
- package/dist/shared/components/alerts/AlertManagerView.js +269 -275
- package/dist/shared/components/alerts/types.js +37 -14
- package/dist/shared/components/item-edit/FieldRenderer.js +22 -20
- package/dist/shared/components/item-edit/GridBulkEditDialog.js +55 -54
- package/dist/shared/components/item-edit/InlineTableField.js +2461 -2421
- package/dist/shared/components/item-edit/M2MCombobox.js +141 -137
- package/dist/shared/components/item-edit/PlanGrid.js +876 -820
- package/dist/shared/components/item-edit/QuickCreateButton.js +323 -130
- package/dist/shared/components/item-edit/RelationCombobox.js +408 -375
- package/dist/shared/components/item-edit/RelationGroupedCombobox.js +255 -156
- package/dist/shared/components/item-edit/SummaryPanel.js +356 -343
- package/dist/shared/components/item-edit/duplicate-rehearsal.js +47 -0
- package/dist/shared/components/item-edit/line-midair.js +82 -75
- package/dist/shared/components/item-edit/save-outcome.js +6 -4
- package/dist/shared/components/panels/ItemLockBanner.js +212 -209
- package/dist/shared/components/panels/PipelinePanel.js +775 -737
- package/dist/shared/components/panels/RecordIntegrityBanner.js +114 -86
- package/dist/shared/components/panels/RevisionsPanel.js +313 -299
- package/dist/shared/components/pipeline/PipelineEditorView.js +26 -16
- package/dist/shared/components/queue/QueueQuickFilters.js +13 -13
- package/dist/shared/components/queue/QueueWorklist.js +978 -953
- package/dist/shared/components/queue/live-state-aspect.js +9 -5
- package/dist/shared/components/widgets/ReviewListWidget.js +152 -149
- package/dist/shared/lib/display-prefs.js +60 -52
- package/dist/shared/lib/draft-store.js +71 -48
- package/dist/shared/lib/expression.js +53 -53
- package/dist/shared/lib/list-page-memory.js +42 -20
- package/dist/shared/lib/money-input.js +45 -0
- package/dist/shared/lib/sanitize-html.js +10 -6
- package/dist/shared/lib/staged-row-labels.js +18 -0
- package/package.json +1 -1
|
@@ -1,90 +1,98 @@
|
|
|
1
|
-
import { useQuery as
|
|
2
|
-
import { useEffect as
|
|
3
|
-
import { useOptionalNivaroClient as
|
|
4
|
-
import { get as
|
|
5
|
-
import { resolveAccentColor as
|
|
6
|
-
import { setDisplayTimezone as k, setTimeDisplay as
|
|
7
|
-
function
|
|
1
|
+
import { useQuery as g } from "@tanstack/react-query";
|
|
2
|
+
import { useEffect as a } from "react";
|
|
3
|
+
import { useOptionalNivaroClient as z } from "../context.js";
|
|
4
|
+
import { get as S } from "./commands.js";
|
|
5
|
+
import { resolveAccentColor as _, parseThemeAccents as h } from "./theme-accents.js";
|
|
6
|
+
import { setDisplayTimezone as k, setTimeDisplay as N, setNumberFormat as v } from "./utils.js";
|
|
7
|
+
function P(n) {
|
|
8
8
|
return n === "small" ? "15px" : n === "large" ? "17.5px" : "";
|
|
9
9
|
}
|
|
10
|
-
function m(n, r = null,
|
|
10
|
+
function m(n, r = null, f = typeof document > "u" ? null : document.documentElement) {
|
|
11
11
|
const e = n ?? {};
|
|
12
|
-
k(typeof e.timezone == "string" && e.timezone ? e.timezone : r),
|
|
12
|
+
k(typeof e.timezone == "string" && e.timezone ? e.timezone : r), N(e.time_display ?? null), v(e.number_format ?? null), f && (f.style.fontSize = P(e.font_size));
|
|
13
13
|
}
|
|
14
|
-
function
|
|
14
|
+
function i(n) {
|
|
15
15
|
const r = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(n.trim());
|
|
16
16
|
if (!r) return null;
|
|
17
|
-
const
|
|
17
|
+
const f = r[1].length === 3 ? r[1].split("").map((t) => t + t).join("") : r[1], e = Number.parseInt(f, 16);
|
|
18
18
|
return `${e >> 16 & 255} ${e >> 8 & 255} ${e & 255}`;
|
|
19
19
|
}
|
|
20
|
-
function
|
|
21
|
-
const r =
|
|
20
|
+
function p(n) {
|
|
21
|
+
const r = i(n);
|
|
22
22
|
if (!r) return 0;
|
|
23
|
-
const [
|
|
24
|
-
const u = Number(
|
|
23
|
+
const [f, e, t] = r.split(" ").map((l) => {
|
|
24
|
+
const u = Number(l) / 255;
|
|
25
25
|
return u <= 0.03928 ? u / 12.92 : ((u + 0.055) / 1.055) ** 2.4;
|
|
26
26
|
});
|
|
27
|
-
return 0.2126 *
|
|
27
|
+
return 0.2126 * f + 0.7152 * e + 0.0722 * t;
|
|
28
28
|
}
|
|
29
|
-
function
|
|
30
|
-
const [
|
|
31
|
-
return (
|
|
29
|
+
function c(n, r) {
|
|
30
|
+
const [f, e] = [p(n), p(r)].sort((t, l) => l - t);
|
|
31
|
+
return (f + 0.05) / (e + 0.05);
|
|
32
32
|
}
|
|
33
|
-
function
|
|
34
|
-
const e = (
|
|
35
|
-
return `#${e.map((
|
|
33
|
+
function d(n, r, f) {
|
|
34
|
+
const e = (i(n) ?? "0 0 0").split(" ").map(Number), t = (i(r) ?? "0 0 0").split(" ").map(Number);
|
|
35
|
+
return `#${e.map((l, u) => Math.round(l + (t[u] - l) * f)).map((l) => l.toString(16).padStart(2, "0")).join("")}`;
|
|
36
36
|
}
|
|
37
|
-
function
|
|
37
|
+
function D(n, r, f = 4.5) {
|
|
38
38
|
let e = n;
|
|
39
|
-
for (let t = 1; t <= 20 &&
|
|
40
|
-
e =
|
|
39
|
+
for (let t = 1; t <= 20 && c(e, r) < f; t++)
|
|
40
|
+
e = d(n, "#ffffff", t * 0.05);
|
|
41
41
|
return e;
|
|
42
42
|
}
|
|
43
|
-
function
|
|
44
|
-
|
|
43
|
+
function E(n, r = "#ffffff", f = 4.5) {
|
|
44
|
+
if (!i(n)) return n;
|
|
45
|
+
let e = n;
|
|
46
|
+
for (let t = 1; t <= 20 && c(e, r) < f; t++)
|
|
47
|
+
e = d(n, "#000000", t * 0.05);
|
|
48
|
+
return e;
|
|
49
|
+
}
|
|
50
|
+
function F(n, r = "#080f1c") {
|
|
51
|
+
return c(n, "#ffffff") >= c(n, r) ? "light" : "dark";
|
|
45
52
|
}
|
|
46
|
-
function
|
|
47
|
-
if (!
|
|
48
|
-
const e = n ?
|
|
53
|
+
function y(n, r, f = typeof document > "u" ? null : document.documentElement) {
|
|
54
|
+
if (!f) return;
|
|
55
|
+
const e = n ? i(n) : null;
|
|
49
56
|
for (const t of r.hex ?? [])
|
|
50
|
-
n && e ?
|
|
57
|
+
n && e ? f.style.setProperty(t, n) : f.style.removeProperty(t);
|
|
51
58
|
for (const t of r.rgb ?? [])
|
|
52
|
-
e ?
|
|
53
|
-
n && e ?
|
|
59
|
+
e ? f.style.setProperty(t, e) : f.style.removeProperty(t);
|
|
60
|
+
n && e ? f.dataset.accentInk = F(n) : delete f.dataset.accentInk;
|
|
54
61
|
}
|
|
55
|
-
function
|
|
56
|
-
const
|
|
62
|
+
function K(n, r = {}) {
|
|
63
|
+
const f = z(), { data: e } = g({
|
|
57
64
|
queryKey: ["nvr-display-settings"],
|
|
58
|
-
queryFn: () =>
|
|
59
|
-
|
|
65
|
+
queryFn: () => f.request(
|
|
66
|
+
S("/settings")
|
|
60
67
|
).then((o) => o.data ?? {}),
|
|
61
|
-
enabled: !!
|
|
68
|
+
enabled: !!f && !!n,
|
|
62
69
|
staleTime: 5 * 6e4,
|
|
63
70
|
retry: !1
|
|
64
|
-
}), t = n ?? null,
|
|
71
|
+
}), t = n ?? null, l = JSON.stringify([
|
|
65
72
|
(t == null ? void 0 : t.timezone) ?? null,
|
|
66
73
|
(t == null ? void 0 : t.time_display) ?? null,
|
|
67
74
|
(t == null ? void 0 : t.number_format) ?? null,
|
|
68
75
|
(t == null ? void 0 : t.font_size) ?? null,
|
|
69
76
|
(e == null ? void 0 : e.default_timezone) ?? null
|
|
70
77
|
]);
|
|
71
|
-
|
|
78
|
+
a(() => {
|
|
72
79
|
t && m(t, (e == null ? void 0 : e.default_timezone) ?? null);
|
|
73
|
-
}, [
|
|
74
|
-
const u = t ?
|
|
75
|
-
|
|
80
|
+
}, [l]), a(() => () => m(null), []);
|
|
81
|
+
const u = t ? _(t.theme_accent, h(e == null ? void 0 : e.theme_accents)) : null, s = u && r.dark && r.darkSurface ? D(u, r.darkSurface) : u, b = JSON.stringify(r.accent ?? {});
|
|
82
|
+
a(() => {
|
|
76
83
|
if (!r.accent) return;
|
|
77
84
|
const o = r.accent;
|
|
78
|
-
return
|
|
79
|
-
}, [s,
|
|
85
|
+
return y(s, o), () => y(null, o);
|
|
86
|
+
}, [s, b]);
|
|
80
87
|
}
|
|
81
88
|
export {
|
|
82
|
-
|
|
83
|
-
|
|
89
|
+
F as accentInk,
|
|
90
|
+
y as applyAccentVars,
|
|
84
91
|
m as applyDisplayPrefs,
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
92
|
+
c as contrastRatio,
|
|
93
|
+
E as deepenForLightSurface,
|
|
94
|
+
i as hexToRgbChannels,
|
|
95
|
+
D as liftForDarkSurface,
|
|
96
|
+
P as rootFontSize,
|
|
97
|
+
K as useDisplayPreferences
|
|
90
98
|
};
|
|
@@ -1,68 +1,68 @@
|
|
|
1
|
-
const
|
|
1
|
+
const d = "nivaro-drafts", a = "drafts";
|
|
2
2
|
function m(e) {
|
|
3
3
|
if (e.item_id !== "new") return /* @__PURE__ */ new Set();
|
|
4
|
-
const t = Object.keys(e.fields ?? {}), n = new Set((e.filled ?? []).filter((
|
|
4
|
+
const t = Object.keys(e.fields ?? {}), n = new Set((e.filled ?? []).filter((r) => t.includes(r)));
|
|
5
5
|
return n.size === t.length ? /* @__PURE__ */ new Set() : n;
|
|
6
6
|
}
|
|
7
|
-
function
|
|
7
|
+
function b(e) {
|
|
8
8
|
if (e == null) return null;
|
|
9
9
|
const t = JSON.stringify(
|
|
10
10
|
e,
|
|
11
|
-
(
|
|
11
|
+
(r, i) => i && typeof i == "object" && !Array.isArray(i) ? Object.fromEntries(Object.entries(i).sort(([s], [o]) => s < o ? -1 : s > o ? 1 : 0)) : i
|
|
12
12
|
);
|
|
13
13
|
if (!t || t === "{}" || t === "[]") return null;
|
|
14
14
|
let n = 5381;
|
|
15
|
-
for (let
|
|
15
|
+
for (let r = 0; r < t.length; r++) n = (n << 5) + n + t.charCodeAt(r) | 0;
|
|
16
16
|
return `p${(n >>> 0).toString(36)}:${t.length}`;
|
|
17
17
|
}
|
|
18
|
-
function
|
|
18
|
+
function w(e, t) {
|
|
19
19
|
return (e.prefill_sig ?? null) === t;
|
|
20
20
|
}
|
|
21
|
-
function
|
|
21
|
+
function S(e, t, n) {
|
|
22
22
|
return `${e}:${t && t !== "new" ? t : "new"}:${n || "anon"}`;
|
|
23
23
|
}
|
|
24
|
-
function
|
|
24
|
+
function g() {
|
|
25
25
|
return new Promise((e) => {
|
|
26
26
|
try {
|
|
27
27
|
if (typeof indexedDB > "u") return e(null);
|
|
28
|
-
const t = indexedDB.open(
|
|
28
|
+
const t = indexedDB.open(d, 1);
|
|
29
29
|
t.onupgradeneeded = () => {
|
|
30
30
|
const n = t.result;
|
|
31
|
-
n.objectStoreNames.contains(
|
|
31
|
+
n.objectStoreNames.contains(a) || n.createObjectStore(a, { keyPath: "key" });
|
|
32
32
|
}, t.onsuccess = () => e(t.result), t.onerror = () => e(null), t.onblocked = () => e(null);
|
|
33
33
|
} catch {
|
|
34
34
|
e(null);
|
|
35
35
|
}
|
|
36
36
|
});
|
|
37
37
|
}
|
|
38
|
-
async function
|
|
39
|
-
const n = await
|
|
40
|
-
return n ? new Promise((
|
|
38
|
+
async function u(e, t) {
|
|
39
|
+
const n = await g();
|
|
40
|
+
return n ? new Promise((r) => {
|
|
41
41
|
try {
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
n.close(),
|
|
42
|
+
const i = n.transaction(a, e), s = t(i.objectStore(a));
|
|
43
|
+
s.onsuccess = () => r(s.result), s.onerror = () => r(null), i.oncomplete = () => n.close(), i.onerror = () => {
|
|
44
|
+
n.close(), r(null);
|
|
45
45
|
};
|
|
46
46
|
} catch {
|
|
47
|
-
n.close(),
|
|
47
|
+
n.close(), r(null);
|
|
48
48
|
}
|
|
49
49
|
}) : null;
|
|
50
50
|
}
|
|
51
|
-
async function
|
|
52
|
-
return await
|
|
51
|
+
async function O(e) {
|
|
52
|
+
return await u("readwrite", (n) => n.put(e)) != null;
|
|
53
53
|
}
|
|
54
|
-
async function
|
|
55
|
-
const t = await
|
|
54
|
+
async function h(e) {
|
|
55
|
+
const t = await u("readonly", (n) => n.get(e));
|
|
56
56
|
return t && typeof t == "object" && t.key === e ? t : null;
|
|
57
57
|
}
|
|
58
|
-
async function
|
|
59
|
-
await
|
|
58
|
+
async function _(e) {
|
|
59
|
+
await u("readwrite", (t) => t.delete(e));
|
|
60
60
|
}
|
|
61
|
-
const
|
|
62
|
-
function
|
|
61
|
+
const l = "nvr:draft-created:", y = 7 * 864e5;
|
|
62
|
+
function p(e, t, n = /* @__PURE__ */ new Date()) {
|
|
63
63
|
try {
|
|
64
64
|
localStorage.setItem(
|
|
65
|
-
|
|
65
|
+
l + e,
|
|
66
66
|
JSON.stringify({ id: t, at: n.toISOString() })
|
|
67
67
|
);
|
|
68
68
|
} catch {
|
|
@@ -70,23 +70,44 @@ function h(e, t, n = /* @__PURE__ */ new Date()) {
|
|
|
70
70
|
}
|
|
71
71
|
function k(e, t, n = /* @__PURE__ */ new Date()) {
|
|
72
72
|
try {
|
|
73
|
-
const
|
|
74
|
-
if (!
|
|
75
|
-
const
|
|
76
|
-
if (!
|
|
77
|
-
const
|
|
78
|
-
if (!Number.isFinite(
|
|
79
|
-
return localStorage.removeItem(
|
|
80
|
-
const
|
|
81
|
-
return !Number.isFinite(
|
|
73
|
+
const r = localStorage.getItem(l + e);
|
|
74
|
+
if (!r) return null;
|
|
75
|
+
const i = JSON.parse(r);
|
|
76
|
+
if (!i || typeof i.id != "string" || typeof i.at != "string") return null;
|
|
77
|
+
const s = Date.parse(i.at);
|
|
78
|
+
if (!Number.isFinite(s) || n.getTime() - s > y)
|
|
79
|
+
return localStorage.removeItem(l + e), null;
|
|
80
|
+
const o = t ? Date.parse(t) : Number.NaN;
|
|
81
|
+
return !Number.isFinite(o) || o > s ? null : { id: i.id, at: i.at };
|
|
82
82
|
} catch {
|
|
83
83
|
return null;
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
|
-
function
|
|
86
|
+
async function D(e, t) {
|
|
87
|
+
const n = {};
|
|
88
|
+
for (const [r, i] of Object.entries(e ?? {})) {
|
|
89
|
+
const s = r.includes(".") ? r.slice(0, r.indexOf(".")) : r;
|
|
90
|
+
for (const o of Object.keys(i ?? {})) {
|
|
91
|
+
if (!o || o === "new" || o.startsWith("pending:")) continue;
|
|
92
|
+
let c;
|
|
93
|
+
try {
|
|
94
|
+
c = await t(s, o);
|
|
95
|
+
} catch {
|
|
96
|
+
c = null;
|
|
97
|
+
}
|
|
98
|
+
typeof c == "number" && Number.isFinite(c) && c > 0 && (n[`${s}:${o}`] = c);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return n;
|
|
102
|
+
}
|
|
103
|
+
function j(e) {
|
|
104
|
+
const { isDirty: t, forReload: n, staged: r, stagedLines: i } = e;
|
|
105
|
+
return t ? "store" : n && r > 0 ? "hold" : i > 0 ? "store" : "drop";
|
|
106
|
+
}
|
|
107
|
+
function N(e) {
|
|
87
108
|
return Object.keys(e.fields ?? {}).length > 0 || Object.values(e.pending_rows ?? {}).some((t) => t.length > 0) || Object.values(e.pending_edits ?? {}).some((t) => Object.keys(t).length > 0) || Object.values(e.pending_deletes ?? {}).some((t) => t.length > 0) || Object.values(e.m2m_links ?? {}).some((t) => t.length > 0) || Object.values(e.m2m_unlinks ?? {}).some((t) => t.length > 0);
|
|
88
109
|
}
|
|
89
|
-
function
|
|
110
|
+
function f(e) {
|
|
90
111
|
return JSON.stringify([
|
|
91
112
|
e.fields ?? {},
|
|
92
113
|
e.pending_rows ?? {},
|
|
@@ -96,19 +117,21 @@ function u(e) {
|
|
|
96
117
|
e.m2m_unlinks ?? {}
|
|
97
118
|
]);
|
|
98
119
|
}
|
|
99
|
-
function
|
|
100
|
-
return !(t != null && t.saved_at) || t.key !== e.key ? e :
|
|
120
|
+
function E(e, t) {
|
|
121
|
+
return !(t != null && t.saved_at) || t.key !== e.key ? e : f(t) === f(e) ? { ...e, saved_at: t.saved_at } : e;
|
|
101
122
|
}
|
|
102
123
|
export {
|
|
103
|
-
|
|
124
|
+
_ as deleteDraft,
|
|
104
125
|
k as draftCreatedAs,
|
|
105
126
|
m as draftFilledBack,
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
j as
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
127
|
+
N as draftHasContent,
|
|
128
|
+
S as draftKey,
|
|
129
|
+
w as draftMatchesPrefill,
|
|
130
|
+
j as draftPersistDecision,
|
|
131
|
+
E as keepDraftSavedAt,
|
|
132
|
+
D as lineBasesForDraft,
|
|
133
|
+
h as loadDraft,
|
|
134
|
+
p as markDraftCreated,
|
|
135
|
+
b as prefillSignature,
|
|
136
|
+
O as saveDraft
|
|
114
137
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { fiscalYearOf as N, fiscalQuarterOf as $ } from "./fiscal.js";
|
|
2
2
|
const v = /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*|\[\d+\])*/;
|
|
3
|
-
class
|
|
3
|
+
class g extends Error {
|
|
4
4
|
constructor(i, n) {
|
|
5
5
|
super(i), this.at = n;
|
|
6
6
|
}
|
|
@@ -17,29 +17,29 @@ function D(e) {
|
|
|
17
17
|
}
|
|
18
18
|
if (o === "{" && e[n + 1] === "{") {
|
|
19
19
|
const s = e.indexOf("}}", n + 2);
|
|
20
|
-
if (s === -1) throw new
|
|
20
|
+
if (s === -1) throw new g("Unclosed {{", n);
|
|
21
21
|
const a = e.slice(n + 2, s).trim();
|
|
22
|
-
if (!a) throw new
|
|
22
|
+
if (!a) throw new g("Empty {{ }}", n);
|
|
23
23
|
const p = v.exec(a);
|
|
24
|
-
if (!p || p[0] !== a) throw new
|
|
24
|
+
if (!p || p[0] !== a) throw new g(`Invalid field path: ${a}`, n + 2);
|
|
25
25
|
i.push({ t: "tok", v: a, at: n }), n = s + 2;
|
|
26
26
|
continue;
|
|
27
27
|
}
|
|
28
28
|
if (o === "'" || o === '"') {
|
|
29
29
|
const s = e.indexOf(o, n + 1);
|
|
30
|
-
if (s === -1) throw new
|
|
30
|
+
if (s === -1) throw new g("Unclosed string", n);
|
|
31
31
|
i.push({ t: "str", v: e.slice(n + 1, s), at: n }), n = s + 1;
|
|
32
32
|
continue;
|
|
33
33
|
}
|
|
34
34
|
if (o >= "0" && o <= "9") {
|
|
35
35
|
const s = /^\d+(\.\d+)?/.exec(e.slice(n));
|
|
36
|
-
if (!s) throw new
|
|
36
|
+
if (!s) throw new g("Bad number", n);
|
|
37
37
|
i.push({ t: "num", v: Number(s[0]), at: n }), n += s[0].length;
|
|
38
38
|
continue;
|
|
39
39
|
}
|
|
40
40
|
if (/[A-Za-z_$]/.test(o)) {
|
|
41
41
|
const s = v.exec(e.slice(n));
|
|
42
|
-
if (!s) throw new
|
|
42
|
+
if (!s) throw new g("Bad identifier", n);
|
|
43
43
|
i.push({ t: "word", v: s[0], at: n }), n += s[0].length;
|
|
44
44
|
continue;
|
|
45
45
|
}
|
|
@@ -52,7 +52,7 @@ function D(e) {
|
|
|
52
52
|
i.push({ t: "op", v: o, at: n }), n++;
|
|
53
53
|
continue;
|
|
54
54
|
}
|
|
55
|
-
throw o === "=" ? new
|
|
55
|
+
throw o === "=" ? new g("Use == for comparison", n) : new g(`Unexpected character: ${o}`, n);
|
|
56
56
|
}
|
|
57
57
|
return i.push({ t: "end", at: e.length }), i;
|
|
58
58
|
}
|
|
@@ -75,7 +75,7 @@ function b(e) {
|
|
|
75
75
|
try {
|
|
76
76
|
i = D(e);
|
|
77
77
|
} catch (t) {
|
|
78
|
-
return t instanceof
|
|
78
|
+
return t instanceof g ? { ok: !1, error: t.message, position: t.at } : { ok: !1, error: "Could not read the expression", position: 0 };
|
|
79
79
|
}
|
|
80
80
|
let n = 0;
|
|
81
81
|
const o = () => i[n], l = [];
|
|
@@ -89,11 +89,11 @@ function b(e) {
|
|
|
89
89
|
for (; ; ) {
|
|
90
90
|
const u = o();
|
|
91
91
|
if (u.t !== "op") break;
|
|
92
|
-
const
|
|
93
|
-
if (
|
|
92
|
+
const c = T[u.v];
|
|
93
|
+
if (c === void 0 || c < t) break;
|
|
94
94
|
n++;
|
|
95
|
-
const
|
|
96
|
-
r = { kind: "binary", op: u.v, left: r, right:
|
|
95
|
+
const f = a(c + 1);
|
|
96
|
+
r = { kind: "binary", op: u.v, left: r, right: f };
|
|
97
97
|
}
|
|
98
98
|
return r;
|
|
99
99
|
}
|
|
@@ -113,20 +113,20 @@ function b(e) {
|
|
|
113
113
|
const r = i[n + 1];
|
|
114
114
|
if (r && r.t === "op" && r.v === "(") {
|
|
115
115
|
n += 2;
|
|
116
|
-
const
|
|
116
|
+
const c = [];
|
|
117
117
|
if (!(o().t === "op" && o().v === ")"))
|
|
118
118
|
for (; ; ) {
|
|
119
|
-
|
|
120
|
-
const
|
|
121
|
-
if (
|
|
119
|
+
c.push(a(0));
|
|
120
|
+
const h = o();
|
|
121
|
+
if (h.t === "op" && h.v === ",") {
|
|
122
122
|
n++;
|
|
123
123
|
continue;
|
|
124
124
|
}
|
|
125
125
|
break;
|
|
126
126
|
}
|
|
127
|
-
const
|
|
128
|
-
if (
|
|
129
|
-
return n++, { kind: "call", name: t.v, args:
|
|
127
|
+
const f = o();
|
|
128
|
+
if (f.t !== "op" || f.v !== ")") throw new s("Expected )", f.at);
|
|
129
|
+
return n++, { kind: "call", name: t.v, args: c };
|
|
130
130
|
}
|
|
131
131
|
if (n++, t.v === "true" || t.v === "false")
|
|
132
132
|
return { kind: "boolean", value: t.v === "true" };
|
|
@@ -207,7 +207,7 @@ function C(e, i, n = {}) {
|
|
|
207
207
|
const r = i(t.path);
|
|
208
208
|
if (_(r)) {
|
|
209
209
|
if (/^[A-Z][A-Z0-9_]*$/.test(t.path)) {
|
|
210
|
-
const u =
|
|
210
|
+
const u = U(t.path);
|
|
211
211
|
if (u !== null) return u;
|
|
212
212
|
}
|
|
213
213
|
return null;
|
|
@@ -217,8 +217,8 @@ function C(e, i, n = {}) {
|
|
|
217
217
|
case "call": {
|
|
218
218
|
const r = t.name.toLowerCase();
|
|
219
219
|
if (r === "networkdays" && t.args.length >= 2) {
|
|
220
|
-
const u = y(s(t.args[0])),
|
|
221
|
-
return !u || !
|
|
220
|
+
const u = y(s(t.args[0])), c = y(s(t.args[1]));
|
|
221
|
+
return !u || !c ? null : M(u, c);
|
|
222
222
|
}
|
|
223
223
|
if (r === "abs" && t.args.length === 1) {
|
|
224
224
|
const u = l(t.args[0]);
|
|
@@ -233,8 +233,8 @@ function C(e, i, n = {}) {
|
|
|
233
233
|
if (u === null) return null;
|
|
234
234
|
if (r === "floor") return Math.floor(u);
|
|
235
235
|
if (r === "ceil") return Math.ceil(u);
|
|
236
|
-
const
|
|
237
|
-
return Math.
|
|
236
|
+
const f = 10 ** (t.args[1] ? l(t.args[1]) ?? 0 : 0), h = Number((u * f).toPrecision(15));
|
|
237
|
+
return Math.sign(h) * Math.round(Math.abs(h)) / f;
|
|
238
238
|
}
|
|
239
239
|
return null;
|
|
240
240
|
}
|
|
@@ -255,40 +255,40 @@ function C(e, i, n = {}) {
|
|
|
255
255
|
if (r === "&&") return a(s(t.left)) ? a(s(t.right)) : !1;
|
|
256
256
|
if (r === "||") return a(s(t.left)) ? !0 : a(s(t.right));
|
|
257
257
|
if (r === "==" || r === "!=") {
|
|
258
|
-
const
|
|
259
|
-
return r === "==" ?
|
|
258
|
+
const f = s(t.left), h = s(t.right), m = d(f, h);
|
|
259
|
+
return r === "==" ? m : !m;
|
|
260
260
|
}
|
|
261
261
|
if (r === "<" || r === "<=" || r === ">" || r === ">=") {
|
|
262
|
-
const
|
|
263
|
-
if (
|
|
262
|
+
const f = s(t.left), h = s(t.right), m = k(f), w = k(h);
|
|
263
|
+
if (m === null || w === null) return !1;
|
|
264
264
|
switch (r) {
|
|
265
265
|
case "<":
|
|
266
|
-
return
|
|
266
|
+
return m < w;
|
|
267
267
|
case "<=":
|
|
268
|
-
return
|
|
268
|
+
return m <= w;
|
|
269
269
|
case ">":
|
|
270
|
-
return
|
|
270
|
+
return m > w;
|
|
271
271
|
default:
|
|
272
|
-
return
|
|
272
|
+
return m >= w;
|
|
273
273
|
}
|
|
274
274
|
}
|
|
275
|
-
const u = l(t.left),
|
|
276
|
-
if (u === null ||
|
|
275
|
+
const u = l(t.left), c = l(t.right);
|
|
276
|
+
if (u === null || c === null) return null;
|
|
277
277
|
switch (r) {
|
|
278
278
|
case "+":
|
|
279
|
-
return u +
|
|
279
|
+
return u + c;
|
|
280
280
|
case "-":
|
|
281
|
-
return u -
|
|
281
|
+
return u - c;
|
|
282
282
|
case "*":
|
|
283
|
-
return u *
|
|
283
|
+
return u * c;
|
|
284
284
|
default:
|
|
285
|
-
return
|
|
285
|
+
return c === 0 ? null : u / c;
|
|
286
286
|
}
|
|
287
287
|
}
|
|
288
288
|
function d(t, r) {
|
|
289
289
|
if (t === null || r === null) return t === r;
|
|
290
|
-
const u = k(t),
|
|
291
|
-
return u !== null &&
|
|
290
|
+
const u = k(t), c = k(r);
|
|
291
|
+
return u !== null && c !== null ? u === c : String(t) === String(r);
|
|
292
292
|
}
|
|
293
293
|
return s(e);
|
|
294
294
|
}
|
|
@@ -298,15 +298,15 @@ function x(e, i, n = {}) {
|
|
|
298
298
|
const l = typeof i == "function" ? i : (s) => A(i, s);
|
|
299
299
|
return C(o.ast, l, n);
|
|
300
300
|
}
|
|
301
|
-
function
|
|
301
|
+
function z(e, i, n = {}) {
|
|
302
302
|
const o = x(e, i, n);
|
|
303
303
|
return typeof o == "number" ? Number.isFinite(o) ? o : null : typeof o == "boolean" ? o ? 1 : 0 : null;
|
|
304
304
|
}
|
|
305
|
-
function
|
|
305
|
+
function B(e, i, n = {}) {
|
|
306
306
|
const o = x(e, i, n);
|
|
307
307
|
return o === null ? !1 : typeof o == "boolean" ? o : typeof o == "number" ? o !== 0 : o !== "";
|
|
308
308
|
}
|
|
309
|
-
function
|
|
309
|
+
function F(e, i) {
|
|
310
310
|
if (!e.trim())
|
|
311
311
|
return { ok: !1, error: "Expression is empty", position: 0, tokens: [], unknownTokens: [] };
|
|
312
312
|
const n = b(e);
|
|
@@ -323,7 +323,7 @@ function O(e, i) {
|
|
|
323
323
|
) : [];
|
|
324
324
|
return { ok: !0, tokens: n.tokens, unknownTokens: o };
|
|
325
325
|
}
|
|
326
|
-
function
|
|
326
|
+
function O(e) {
|
|
327
327
|
const i = b(e);
|
|
328
328
|
return i.ok ? i.tokens : [];
|
|
329
329
|
}
|
|
@@ -332,7 +332,7 @@ function y(e) {
|
|
|
332
332
|
const i = e.length === 10 ? /* @__PURE__ */ new Date(`${e}T00:00:00`) : new Date(e);
|
|
333
333
|
return Number.isNaN(i.getTime()) ? null : i;
|
|
334
334
|
}
|
|
335
|
-
function
|
|
335
|
+
function M(e, i) {
|
|
336
336
|
const n = i.getTime() >= e.getTime() ? 1 : -1;
|
|
337
337
|
let [o, l] = n === 1 ? [e, i] : [i, e];
|
|
338
338
|
o = new Date(o.getFullYear(), o.getMonth(), o.getDate()), l = new Date(l.getFullYear(), l.getMonth(), l.getDate());
|
|
@@ -348,20 +348,20 @@ let E = {};
|
|
|
348
348
|
function Z(e) {
|
|
349
349
|
E = e && typeof e == "object" ? e : {};
|
|
350
350
|
}
|
|
351
|
-
function
|
|
351
|
+
function U(e) {
|
|
352
352
|
const i = E[e];
|
|
353
353
|
return Number.isFinite(i) ? i : null;
|
|
354
354
|
}
|
|
355
355
|
export {
|
|
356
356
|
C as evaluateAst,
|
|
357
|
-
|
|
357
|
+
B as evaluateBoolean,
|
|
358
358
|
x as evaluateExpression,
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
359
|
+
z as evaluateNumeric,
|
|
360
|
+
O as extractExpressionTokens,
|
|
361
|
+
U as formulaConstant,
|
|
362
|
+
M as networkdaysBetween,
|
|
363
363
|
b as parseExpression,
|
|
364
364
|
A as readPath,
|
|
365
365
|
Z as setFormulaConstants,
|
|
366
|
-
|
|
366
|
+
F as validateExpression
|
|
367
367
|
};
|