@a-ludi/rjsf-formulas 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/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -0
- package/dist/index.d.mts +11 -0
- package/dist/index.mjs +265 -251
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,74 +1,74 @@
|
|
|
1
|
-
import { findSchemaDefinition as
|
|
2
|
-
import { jsx as
|
|
3
|
-
import { useState as
|
|
4
|
-
import
|
|
5
|
-
const
|
|
6
|
-
function
|
|
7
|
-
const
|
|
8
|
-
return
|
|
1
|
+
import { findSchemaDefinition as ct } from "@rjsf/utils";
|
|
2
|
+
import { jsx as it } from "react/jsx-runtime";
|
|
3
|
+
import { useState as ut, useRef as m, useEffect as w, useCallback as Q, forwardRef as at, useMemo as V } from "react";
|
|
4
|
+
import lt from "@rjsf/core";
|
|
5
|
+
const X = Symbol("arrayIndex");
|
|
6
|
+
function pt(t, r) {
|
|
7
|
+
const e = (r == null ? void 0 : r.formulaKey) ?? "x-formula", s = (r == null ? void 0 : r.formulaContextKey) ?? "x-formula-context", n = (r == null ? void 0 : r.formulaConflictBehavior) ?? "warn", o = [];
|
|
8
|
+
return O(t, [], o, e, s, n, !0, t), o;
|
|
9
9
|
}
|
|
10
|
-
function
|
|
11
|
-
if (t === !0) return
|
|
12
|
-
const
|
|
13
|
-
return Array.isArray(
|
|
10
|
+
function G(t, r) {
|
|
11
|
+
if (t === !0) return r;
|
|
12
|
+
const e = t;
|
|
13
|
+
return Array.isArray(e.allOf) ? { allOf: [...e.allOf, r] } : { allOf: [t, r] };
|
|
14
14
|
}
|
|
15
|
-
function yt(t,
|
|
15
|
+
function yt(t, r) {
|
|
16
16
|
return t === void 0 || t === "siblings" ? "siblings" : t === "extended" ? "extended" : (console.warn(
|
|
17
|
-
`[rjsf-formulas] Unknown x-formula-context value "${t}" at path [${
|
|
17
|
+
`[rjsf-formulas] Unknown x-formula-context value "${t}" at path [${Y(r)}], treating as "siblings"`
|
|
18
18
|
), "siblings");
|
|
19
19
|
}
|
|
20
|
-
function
|
|
21
|
-
return t.map((
|
|
20
|
+
function Y(t) {
|
|
21
|
+
return t.map((r) => typeof r == "symbol" ? "[*]" : String(r)).join(", ");
|
|
22
22
|
}
|
|
23
|
-
function
|
|
24
|
-
return t.map((
|
|
23
|
+
function W(t) {
|
|
24
|
+
return t.map((r) => typeof r == "symbol" ? "[*]" : String(r)).join(".");
|
|
25
25
|
}
|
|
26
|
-
function
|
|
27
|
-
const s =
|
|
28
|
-
if (
|
|
26
|
+
function dt(t, r, e) {
|
|
27
|
+
const s = W(t.path);
|
|
28
|
+
if (e === "error")
|
|
29
29
|
throw new TypeError(
|
|
30
|
-
`[rjsf-formulas] Formula conflict at path [${
|
|
30
|
+
`[rjsf-formulas] Formula conflict at path [${Y(t.path)}]: "${t.formula}" vs "${r.formula}". Resolve the conflict or set formulaConflictBehavior to 'ignore' or 'warn'.`
|
|
31
31
|
);
|
|
32
|
-
|
|
33
|
-
`[rjsf-formulas] Formula conflict at path [${s}]: "${t.formula}" (earlier allOf branch) is overridden by "${
|
|
32
|
+
e === "warn" && console.warn(
|
|
33
|
+
`[rjsf-formulas] Formula conflict at path [${s}]: "${t.formula}" (earlier allOf branch) is overridden by "${r.formula}" (later allOf branch).`
|
|
34
34
|
);
|
|
35
35
|
}
|
|
36
|
-
function
|
|
37
|
-
for (const s of
|
|
38
|
-
const n =
|
|
39
|
-
o !== -1 ? (
|
|
36
|
+
function mt(t, r, e) {
|
|
37
|
+
for (const s of r) {
|
|
38
|
+
const n = W(s.path), o = t.findIndex((i) => W(i.path) === n);
|
|
39
|
+
o !== -1 ? (dt(t[o], s, e), t[o] = s) : t.push(s);
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
|
-
function
|
|
42
|
+
function O(t, r, e, s, n, o, i, u) {
|
|
43
43
|
const f = t;
|
|
44
44
|
if (typeof f.$ref == "string") {
|
|
45
|
-
const c =
|
|
46
|
-
|
|
45
|
+
const c = ct(f.$ref, u);
|
|
46
|
+
O(c, r, e, s, n, o, i, u);
|
|
47
47
|
return;
|
|
48
48
|
}
|
|
49
49
|
if (s in t) {
|
|
50
50
|
const c = f[s];
|
|
51
51
|
if (typeof c != "string") {
|
|
52
52
|
console.warn(
|
|
53
|
-
`[rjsf-formulas] Formula at path [${
|
|
53
|
+
`[rjsf-formulas] Formula at path [${Y(r)}] is not a string (got ${typeof c}), skipping.`
|
|
54
54
|
);
|
|
55
55
|
return;
|
|
56
56
|
}
|
|
57
|
-
|
|
58
|
-
path:
|
|
57
|
+
e.push({
|
|
58
|
+
path: r,
|
|
59
59
|
formula: c,
|
|
60
|
-
contextMode: yt(f[n],
|
|
60
|
+
contextMode: yt(f[n], r),
|
|
61
61
|
condition: i
|
|
62
62
|
});
|
|
63
63
|
return;
|
|
64
64
|
}
|
|
65
|
-
const l = t.type === "array" || t.type == null && (Array.isArray(f.prefixItems) || t.items != null
|
|
65
|
+
const l = t.type === "array" || t.type == null && (Array.isArray(f.prefixItems) || t.items != null);
|
|
66
66
|
if (t.properties && !l)
|
|
67
67
|
for (const [c, a] of Object.entries(t.properties))
|
|
68
|
-
|
|
68
|
+
O(
|
|
69
69
|
a,
|
|
70
|
-
[...
|
|
71
|
-
|
|
70
|
+
[...r, c],
|
|
71
|
+
e,
|
|
72
72
|
s,
|
|
73
73
|
n,
|
|
74
74
|
o,
|
|
@@ -76,11 +76,13 @@ function x(t, e, r, s, n, o, i, u) {
|
|
|
76
76
|
u
|
|
77
77
|
);
|
|
78
78
|
if (l && (Array.isArray(f.prefixItems) && f.prefixItems.forEach((a, d) => {
|
|
79
|
-
|
|
80
|
-
}), t.items &&
|
|
79
|
+
O(a, [...r, d], e, s, n, o, i, u);
|
|
80
|
+
}), Array.isArray(t.items) && t.items.forEach((c, a) => {
|
|
81
|
+
O(c, [...r, a], e, s, n, o, i, u);
|
|
82
|
+
}), t.items && !Array.isArray(t.items) && O(
|
|
81
83
|
t.items,
|
|
82
|
-
[...
|
|
83
|
-
|
|
84
|
+
[...r, X],
|
|
85
|
+
e,
|
|
84
86
|
s,
|
|
85
87
|
n,
|
|
86
88
|
o,
|
|
@@ -90,137 +92,137 @@ function x(t, e, r, s, n, o, i, u) {
|
|
|
90
92
|
const c = f.allOf;
|
|
91
93
|
for (const a of c) {
|
|
92
94
|
const d = [];
|
|
93
|
-
|
|
95
|
+
O(a, r, d, s, n, o, i, u), mt(e, d, o);
|
|
94
96
|
}
|
|
95
97
|
}
|
|
96
98
|
for (const c of ["oneOf", "anyOf"])
|
|
97
99
|
if (Array.isArray(f[c])) {
|
|
98
100
|
const a = f[c];
|
|
99
101
|
for (const d of a) {
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
+
const g = G(i, d);
|
|
103
|
+
O(d, r, e, s, n, o, g, u);
|
|
102
104
|
}
|
|
103
105
|
}
|
|
104
106
|
if ("if" in f) {
|
|
105
107
|
const c = f.if, a = f.then, d = f.else;
|
|
106
108
|
if (s in c && console.warn(
|
|
107
|
-
`[rjsf-formulas] Formula key "${s}" found inside an "if" schema at path [${
|
|
109
|
+
`[rjsf-formulas] Formula key "${s}" found inside an "if" schema at path [${Y(r)}]. The "if" schema is a validation predicate and is never rendered — the formula will be ignored.`
|
|
108
110
|
), a !== void 0) {
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
+
const g = G(i, c);
|
|
112
|
+
O(a, r, e, s, n, o, g, u);
|
|
111
113
|
}
|
|
112
114
|
if (d !== void 0) {
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
+
const g = G(i, { not: c });
|
|
116
|
+
O(d, r, e, s, n, o, g, u);
|
|
115
117
|
}
|
|
116
118
|
}
|
|
117
119
|
}
|
|
118
|
-
function
|
|
120
|
+
function gt(t) {
|
|
119
121
|
return t && t.__esModule && Object.prototype.hasOwnProperty.call(t, "default") ? t.default : t;
|
|
120
122
|
}
|
|
121
|
-
var
|
|
122
|
-
function
|
|
123
|
-
return
|
|
124
|
-
if (
|
|
125
|
-
if (
|
|
126
|
-
if (
|
|
123
|
+
var H, tt;
|
|
124
|
+
function ht() {
|
|
125
|
+
return tt || (tt = 1, H = function t(r, e) {
|
|
126
|
+
if (r === e) return !0;
|
|
127
|
+
if (r && e && typeof r == "object" && typeof e == "object") {
|
|
128
|
+
if (r.constructor !== e.constructor) return !1;
|
|
127
129
|
var s, n, o;
|
|
128
|
-
if (Array.isArray(
|
|
129
|
-
if (s =
|
|
130
|
+
if (Array.isArray(r)) {
|
|
131
|
+
if (s = r.length, s != e.length) return !1;
|
|
130
132
|
for (n = s; n-- !== 0; )
|
|
131
|
-
if (!t(
|
|
133
|
+
if (!t(r[n], e[n])) return !1;
|
|
132
134
|
return !0;
|
|
133
135
|
}
|
|
134
|
-
if (
|
|
135
|
-
if (
|
|
136
|
-
if (
|
|
137
|
-
if (o = Object.keys(
|
|
136
|
+
if (r.constructor === RegExp) return r.source === e.source && r.flags === e.flags;
|
|
137
|
+
if (r.valueOf !== Object.prototype.valueOf) return r.valueOf() === e.valueOf();
|
|
138
|
+
if (r.toString !== Object.prototype.toString) return r.toString() === e.toString();
|
|
139
|
+
if (o = Object.keys(r), s = o.length, s !== Object.keys(e).length) return !1;
|
|
138
140
|
for (n = s; n-- !== 0; )
|
|
139
|
-
if (!Object.prototype.hasOwnProperty.call(
|
|
141
|
+
if (!Object.prototype.hasOwnProperty.call(e, o[n])) return !1;
|
|
140
142
|
for (n = s; n-- !== 0; ) {
|
|
141
143
|
var i = o[n];
|
|
142
|
-
if (!t(
|
|
144
|
+
if (!t(r[i], e[i])) return !1;
|
|
143
145
|
}
|
|
144
146
|
return !0;
|
|
145
147
|
}
|
|
146
|
-
return
|
|
147
|
-
}),
|
|
148
|
+
return r !== r && e !== e;
|
|
149
|
+
}), H;
|
|
148
150
|
}
|
|
149
|
-
var
|
|
150
|
-
const jt = /* @__PURE__ */
|
|
151
|
-
function
|
|
152
|
-
const o =
|
|
151
|
+
var wt = ht();
|
|
152
|
+
const jt = /* @__PURE__ */ gt(wt);
|
|
153
|
+
function At(t, r, e, s) {
|
|
154
|
+
const o = r.slice(0, -1).reduce((u, f) => {
|
|
153
155
|
if (!(u == null || typeof u != "object"))
|
|
154
156
|
return u[f];
|
|
155
|
-
},
|
|
157
|
+
}, e), i = o != null && typeof o == "object" && !Array.isArray(o) ? { ...o } : {};
|
|
156
158
|
return t.contextMode === "extended" ? ((s.formulaDataKey in i || s.formulaPathKey in i) && console.warn(
|
|
157
159
|
`[rjsf-formulas] Extended context key collision: sibling field named "${s.formulaDataKey in i ? s.formulaDataKey : s.formulaPathKey}" will be overwritten by the injected context. Use formulaDataKey/formulaPathKey props to choose a different key.`
|
|
158
160
|
), {
|
|
159
161
|
...i,
|
|
160
|
-
[s.formulaDataKey]:
|
|
161
|
-
[s.formulaPathKey]: [...
|
|
162
|
+
[s.formulaDataKey]: e,
|
|
163
|
+
[s.formulaPathKey]: [...r]
|
|
162
164
|
}) : i;
|
|
163
165
|
}
|
|
164
|
-
function
|
|
165
|
-
return t.map((
|
|
166
|
+
function rt(t) {
|
|
167
|
+
return t.map((r) => typeof r == "symbol" ? "[*]" : String(r)).join(", ");
|
|
166
168
|
}
|
|
167
|
-
function
|
|
168
|
-
return
|
|
169
|
-
if (!(
|
|
170
|
-
return
|
|
169
|
+
function F(t, r) {
|
|
170
|
+
return r.reduce((e, s) => {
|
|
171
|
+
if (!(e == null || typeof e != "object"))
|
|
172
|
+
return e[s];
|
|
171
173
|
}, t);
|
|
172
174
|
}
|
|
173
|
-
function
|
|
174
|
-
if (
|
|
175
|
-
const s =
|
|
176
|
-
s != null && typeof s == "object" && (s[
|
|
175
|
+
function Z(t, r, e) {
|
|
176
|
+
if (r.length === 0) return;
|
|
177
|
+
const s = F(t, r.slice(0, -1));
|
|
178
|
+
s != null && typeof s == "object" && (s[r[r.length - 1]] = e);
|
|
177
179
|
}
|
|
178
|
-
function
|
|
179
|
-
if (t.length === 0) return [
|
|
180
|
+
function M(t, r, e = []) {
|
|
181
|
+
if (t.length === 0) return [e];
|
|
180
182
|
const [s, ...n] = t;
|
|
181
|
-
if (s ===
|
|
182
|
-
const o =
|
|
183
|
+
if (s === X) {
|
|
184
|
+
const o = F(r, e);
|
|
183
185
|
if (!Array.isArray(o)) return [];
|
|
184
186
|
const i = [];
|
|
185
187
|
for (let u = 0; u < o.length; u++)
|
|
186
|
-
i.push(...
|
|
188
|
+
i.push(...M(n, r, [...e, u]));
|
|
187
189
|
return i;
|
|
188
190
|
}
|
|
189
|
-
return
|
|
191
|
+
return M(n, r, [...e, s]);
|
|
190
192
|
}
|
|
191
|
-
function
|
|
192
|
-
return jt(t,
|
|
193
|
+
function B(t, r) {
|
|
194
|
+
return jt(t, r);
|
|
193
195
|
}
|
|
194
|
-
async function et(t,
|
|
196
|
+
async function et(t, r, e, s) {
|
|
195
197
|
const n = structuredClone(t), o = [];
|
|
196
|
-
for (const f of
|
|
197
|
-
for (const l of
|
|
198
|
-
const c =
|
|
198
|
+
for (const f of r)
|
|
199
|
+
for (const l of M(f.path, n)) {
|
|
200
|
+
const c = At(f, l, n, s);
|
|
199
201
|
o.push({ field: f, concretePath: l, context: c });
|
|
200
202
|
}
|
|
201
203
|
const i = await Promise.allSettled(
|
|
202
|
-
o.map(({ field: f, context: l }) => new Promise((c) => c(
|
|
204
|
+
o.map(({ field: f, context: l }) => new Promise((c) => c(e(f.formula, l))))
|
|
203
205
|
), u = [];
|
|
204
206
|
for (let f = 0; f < o.length; f++) {
|
|
205
207
|
const { concretePath: l } = o[f], c = i[f];
|
|
206
208
|
if (c.status === "fulfilled")
|
|
207
|
-
|
|
209
|
+
Z(n, l, c.value);
|
|
208
210
|
else {
|
|
209
211
|
const a = c.reason instanceof Error ? c.reason : new Error(String(c.reason));
|
|
210
|
-
u.push({ path: l, error: a }),
|
|
212
|
+
u.push({ path: l, error: a }), Z(n, l, void 0);
|
|
211
213
|
}
|
|
212
214
|
}
|
|
213
215
|
return { data: n, errors: u };
|
|
214
216
|
}
|
|
215
|
-
function
|
|
216
|
-
for (const s of
|
|
217
|
-
for (const n of
|
|
218
|
-
if (!
|
|
217
|
+
function Ot(t, r, e) {
|
|
218
|
+
for (const s of e)
|
|
219
|
+
for (const n of M(s.path, r))
|
|
220
|
+
if (!B(F(t, n), F(r, n)))
|
|
219
221
|
return !1;
|
|
220
222
|
return !0;
|
|
221
223
|
}
|
|
222
|
-
async function
|
|
223
|
-
const l =
|
|
224
|
+
async function xt(t, r, e, s, n, o, i, u, f) {
|
|
225
|
+
const l = r.filter(
|
|
224
226
|
(p) => p.condition === !0 || u(p.condition, t)
|
|
225
227
|
);
|
|
226
228
|
if (l.length === 0) return t;
|
|
@@ -230,10 +232,10 @@ async function Ot(t, e, r, s, n, o, i, u, f) {
|
|
|
230
232
|
if (c.has(y)) {
|
|
231
233
|
if (f === "error")
|
|
232
234
|
throw new TypeError(
|
|
233
|
-
`[rjsf-formulas] Formula conflict: two active fields share path [${
|
|
235
|
+
`[rjsf-formulas] Formula conflict: two active fields share path [${rt(p.path)}]`
|
|
234
236
|
);
|
|
235
237
|
f === "warn" && console.warn(
|
|
236
|
-
`[rjsf-formulas] Formula conflict: two active fields share path [${
|
|
238
|
+
`[rjsf-formulas] Formula conflict: two active fields share path [${rt(p.path)}]; taking last`
|
|
237
239
|
);
|
|
238
240
|
const h = a.indexOf(c.get(y));
|
|
239
241
|
a[h] = p, c.set(y, p);
|
|
@@ -241,140 +243,140 @@ async function Ot(t, e, r, s, n, o, i, u, f) {
|
|
|
241
243
|
c.set(y, p), a.push(p);
|
|
242
244
|
}
|
|
243
245
|
const d = { formulaDataKey: o, formulaPathKey: i };
|
|
244
|
-
let
|
|
246
|
+
let g = t;
|
|
245
247
|
for (let p = 0; p < s; p++) {
|
|
246
|
-
const { data: y, errors: h } = await et(
|
|
247
|
-
if (
|
|
248
|
-
for (const { path:
|
|
249
|
-
n == null || n(
|
|
248
|
+
const { data: y, errors: h } = await et(g, a, e, d);
|
|
249
|
+
if (Ot(g, y, a)) {
|
|
250
|
+
for (const { path: j, error: b } of h)
|
|
251
|
+
n == null || n(j, b);
|
|
250
252
|
return y;
|
|
251
253
|
}
|
|
252
|
-
|
|
254
|
+
g = y;
|
|
253
255
|
}
|
|
254
|
-
const { data:
|
|
256
|
+
const { data: x } = await et(g, a, e, d), v = structuredClone(x);
|
|
255
257
|
for (const p of a)
|
|
256
|
-
for (const y of
|
|
257
|
-
|
|
258
|
+
for (const y of M(p.path, x))
|
|
259
|
+
B(F(g, y), F(x, y)) || (n == null || n(
|
|
258
260
|
y,
|
|
259
261
|
new Error(
|
|
260
262
|
`[rjsf-formulas] Formula at [${y.join(", ")}] did not converge after ${s} passes`
|
|
261
263
|
)
|
|
262
|
-
),
|
|
263
|
-
return
|
|
264
|
+
), Z(v, y, void 0));
|
|
265
|
+
return v;
|
|
264
266
|
}
|
|
265
|
-
function
|
|
267
|
+
function bt(t) {
|
|
266
268
|
return JSON.stringify(t);
|
|
267
269
|
}
|
|
268
|
-
function
|
|
269
|
-
const [
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
}, [o]),
|
|
273
|
-
|
|
274
|
-
}, [i]),
|
|
275
|
-
|
|
276
|
-
}, [
|
|
277
|
-
|
|
278
|
-
}, [
|
|
279
|
-
|
|
280
|
-
}, [n]),
|
|
281
|
-
|
|
282
|
-
}, [u]),
|
|
283
|
-
|
|
284
|
-
}, [f]),
|
|
285
|
-
|
|
270
|
+
function Rt(t, r, e, s, n, o, i, u, f, l, c) {
|
|
271
|
+
const [a, d] = ut(t), g = m(t), x = m(t), v = m(/* @__PURE__ */ new Map()), p = m(null), y = m(!1), h = m(o), j = m(i), b = m(e), S = m(r), U = m(n), E = m(u), k = m(f), _ = m(l);
|
|
272
|
+
w(() => {
|
|
273
|
+
h.current = o;
|
|
274
|
+
}, [o]), w(() => {
|
|
275
|
+
j.current = i;
|
|
276
|
+
}, [i]), w(() => {
|
|
277
|
+
b.current = e;
|
|
278
|
+
}, [e]), w(() => {
|
|
279
|
+
S.current = r;
|
|
280
|
+
}, [r]), w(() => {
|
|
281
|
+
U.current = n;
|
|
282
|
+
}, [n]), w(() => {
|
|
283
|
+
E.current = u;
|
|
284
|
+
}, [u]), w(() => {
|
|
285
|
+
k.current = f;
|
|
286
|
+
}, [f]), w(() => {
|
|
287
|
+
_.current = l;
|
|
286
288
|
}, [l]);
|
|
287
|
-
const
|
|
288
|
-
if (
|
|
289
|
+
const D = Q(() => {
|
|
290
|
+
if (y.current) return;
|
|
289
291
|
(async () => {
|
|
290
|
-
var
|
|
291
|
-
|
|
292
|
+
var R, K;
|
|
293
|
+
y.current = !0;
|
|
292
294
|
try {
|
|
293
295
|
for (; ; ) {
|
|
294
|
-
const
|
|
295
|
-
(
|
|
296
|
-
),
|
|
297
|
-
for (const
|
|
298
|
-
for (const
|
|
299
|
-
|
|
300
|
-
const
|
|
301
|
-
|
|
302
|
-
for (const
|
|
303
|
-
|
|
304
|
-
const
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
296
|
+
const P = g.current, C = S.current, nt = C.filter(
|
|
297
|
+
(I) => I.condition === !0 || k.current(I.condition, P)
|
|
298
|
+
), T = [];
|
|
299
|
+
for (const I of nt)
|
|
300
|
+
for (const ft of M(I.path, P))
|
|
301
|
+
T.push(ft);
|
|
302
|
+
const z = v.current;
|
|
303
|
+
z.clear();
|
|
304
|
+
for (const I of T) z.set(bt(I), "running");
|
|
305
|
+
T.length > 0 && ((R = j.current) == null || R.call(j, T));
|
|
306
|
+
const st = await xt(
|
|
307
|
+
P,
|
|
308
|
+
C,
|
|
309
|
+
b.current,
|
|
310
|
+
U.current,
|
|
311
|
+
h.current,
|
|
312
|
+
E.current.formulaDataKey,
|
|
313
|
+
E.current.formulaPathKey,
|
|
314
|
+
k.current,
|
|
315
|
+
_.current
|
|
314
316
|
);
|
|
315
|
-
if (
|
|
316
|
-
const
|
|
317
|
-
if (
|
|
318
|
-
|
|
317
|
+
if (J.current) break;
|
|
318
|
+
const ot = [...z.values()].some((I) => I === "dirty");
|
|
319
|
+
if (z.clear(), !ot) {
|
|
320
|
+
d(st), T.length > 0 && ((K = j.current) == null || K.call(j, []));
|
|
319
321
|
break;
|
|
320
322
|
}
|
|
321
323
|
}
|
|
322
324
|
} finally {
|
|
323
|
-
|
|
325
|
+
y.current = !1;
|
|
324
326
|
}
|
|
325
327
|
})();
|
|
326
|
-
}, []),
|
|
327
|
-
(
|
|
328
|
-
|
|
329
|
-
const
|
|
330
|
-
for (const [
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
328
|
+
}, []), q = Q(
|
|
329
|
+
(A) => {
|
|
330
|
+
g.current = A;
|
|
331
|
+
const R = v.current;
|
|
332
|
+
for (const [K, P] of R)
|
|
333
|
+
P === "running" && R.set(K, "dirty");
|
|
334
|
+
y.current || (p.current !== null && clearTimeout(p.current), p.current = setTimeout(() => {
|
|
335
|
+
p.current = null, D();
|
|
334
336
|
}, s));
|
|
335
337
|
},
|
|
336
|
-
[s,
|
|
337
|
-
),
|
|
338
|
-
return
|
|
339
|
-
|
|
340
|
-
}),
|
|
341
|
-
|
|
342
|
-
}), []), { enrichedFormData:
|
|
338
|
+
[s, D]
|
|
339
|
+
), $ = m(!1), J = m(!1);
|
|
340
|
+
return w(() => {
|
|
341
|
+
$.current ? B(t, x.current) || (x.current = t, q(t)) : ($.current = !0, x.current = t, c !== "skip" && q(t));
|
|
342
|
+
}), w(() => (J.current = !1, () => {
|
|
343
|
+
J.current = !0, $.current = !1, p.current !== null && clearTimeout(p.current);
|
|
344
|
+
}), []), { enrichedFormData: a, handleInput: q };
|
|
343
345
|
}
|
|
344
|
-
function
|
|
345
|
-
const
|
|
346
|
-
for (const n of
|
|
347
|
-
|
|
348
|
-
return
|
|
346
|
+
function $t(t, r) {
|
|
347
|
+
const e = structuredClone(t ?? {}), s = It(r);
|
|
348
|
+
for (const n of r)
|
|
349
|
+
N(e, n.path, s);
|
|
350
|
+
return e;
|
|
349
351
|
}
|
|
350
|
-
function
|
|
351
|
-
const
|
|
352
|
-
for (let
|
|
353
|
-
const s = t[
|
|
352
|
+
function It(t) {
|
|
353
|
+
const r = /* @__PURE__ */ new Set();
|
|
354
|
+
for (let e = 0; e < t.length; e++) {
|
|
355
|
+
const s = t[e].path;
|
|
354
356
|
for (let n = 0; n < s.length; n++) {
|
|
355
357
|
const o = s[n];
|
|
356
|
-
if (typeof o != "number" && o !==
|
|
357
|
-
const i =
|
|
358
|
+
if (typeof o != "number" && o !== X) continue;
|
|
359
|
+
const i = L(s.slice(0, n)), u = typeof o == "number";
|
|
358
360
|
t.some((l, c) => {
|
|
359
|
-
if (c ===
|
|
361
|
+
if (c === e || l.path.length <= n || L(l.path.slice(0, n)) !== i) return !1;
|
|
360
362
|
const a = l.path[n];
|
|
361
|
-
return u ? a ===
|
|
362
|
-
}) &&
|
|
363
|
+
return u ? a === X : typeof a == "number";
|
|
364
|
+
}) && r.add(i);
|
|
363
365
|
}
|
|
364
366
|
}
|
|
365
|
-
return
|
|
367
|
+
return r;
|
|
366
368
|
}
|
|
367
|
-
function
|
|
368
|
-
return JSON.stringify(t.map((
|
|
369
|
+
function L(t) {
|
|
370
|
+
return JSON.stringify(t.map((r) => typeof r == "symbol" ? "__ARRAY_INDEX__" : r));
|
|
369
371
|
}
|
|
370
|
-
function
|
|
371
|
-
if (
|
|
372
|
+
function N(t, r, e, s = []) {
|
|
373
|
+
if (r.length === 0) {
|
|
372
374
|
t["ui:readonly"] = !0;
|
|
373
375
|
return;
|
|
374
376
|
}
|
|
375
|
-
const [n, ...o] =
|
|
377
|
+
const [n, ...o] = r;
|
|
376
378
|
if (typeof n == "string") {
|
|
377
|
-
(!t[n] || typeof t[n] != "object" || Array.isArray(t[n])) && (t[n] = {}),
|
|
379
|
+
(!t[n] || typeof t[n] != "object" || Array.isArray(t[n])) && (t[n] = {}), N(t[n], o, e, [...s, n]);
|
|
378
380
|
return;
|
|
379
381
|
}
|
|
380
382
|
if (typeof n == "number") {
|
|
@@ -384,86 +386,98 @@ function P(t, e, r, s = []) {
|
|
|
384
386
|
}
|
|
385
387
|
Array.isArray(t.items) || (t.items = []);
|
|
386
388
|
const f = t.items;
|
|
387
|
-
(!f[n] || typeof f[n] != "object") && (f[n] = {}),
|
|
389
|
+
(!f[n] || typeof f[n] != "object") && (f[n] = {}), N(f[n], o, e, [...s, n]);
|
|
388
390
|
return;
|
|
389
391
|
}
|
|
390
|
-
const i =
|
|
391
|
-
if (
|
|
392
|
-
(!t.additionalItems || typeof t.additionalItems != "object") && (t.additionalItems = {}),
|
|
392
|
+
const i = L(s);
|
|
393
|
+
if (e.has(i))
|
|
394
|
+
(!t.additionalItems || typeof t.additionalItems != "object") && (t.additionalItems = {}), N(t.additionalItems, o, e, [...s, n]);
|
|
393
395
|
else {
|
|
394
396
|
if (Array.isArray(t.items)) {
|
|
395
397
|
console.warn("[rjsf-formulas] mergeReadOnly: cannot inject ui:readonly for uniform array because existing uiSchema has items as an array. Skipping.");
|
|
396
398
|
return;
|
|
397
399
|
}
|
|
398
|
-
(!t.items || typeof t.items != "object") && (t.items = {}),
|
|
400
|
+
(!t.items || typeof t.items != "object") && (t.items = {}), N(t.items, o, e, [...s, n]);
|
|
399
401
|
}
|
|
400
402
|
}
|
|
401
|
-
function vt(t,
|
|
403
|
+
function vt(t, r) {
|
|
402
404
|
const {
|
|
403
|
-
schema:
|
|
405
|
+
schema: e,
|
|
404
406
|
formData: s,
|
|
405
407
|
validator: n,
|
|
406
408
|
uiSchema: o,
|
|
407
409
|
evaluator: i,
|
|
408
|
-
Form: u =
|
|
410
|
+
Form: u = lt,
|
|
409
411
|
formulaKey: f = "x-formula",
|
|
410
412
|
formulaContextKey: l = "x-formula-context",
|
|
411
413
|
formulaDataKey: c = "__formData__",
|
|
412
414
|
formulaPathKey: a = "__path__",
|
|
413
415
|
maxConvergencePasses: d = 10,
|
|
414
|
-
debounceMs:
|
|
415
|
-
onFormulaError:
|
|
416
|
-
onLoadingChange:
|
|
416
|
+
debounceMs: g = 300,
|
|
417
|
+
onFormulaError: x,
|
|
418
|
+
onLoadingChange: v,
|
|
417
419
|
formulaConflictBehavior: p = "warn",
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
420
|
+
initialComputationMode: y = "always",
|
|
421
|
+
onChange: h,
|
|
422
|
+
...j
|
|
423
|
+
} = t, b = V(
|
|
424
|
+
() => pt(e, { formulaKey: f, formulaContextKey: l }),
|
|
425
|
+
[e, f, l]
|
|
426
|
+
), S = V(
|
|
424
427
|
() => ({ formulaDataKey: c, formulaPathKey: a }),
|
|
425
428
|
[c, a]
|
|
426
|
-
),
|
|
427
|
-
() =>
|
|
428
|
-
[o,
|
|
429
|
-
),
|
|
430
|
-
(A,
|
|
431
|
-
[n,
|
|
432
|
-
),
|
|
429
|
+
), U = V(
|
|
430
|
+
() => $t(o, b),
|
|
431
|
+
[o, b]
|
|
432
|
+
), E = Q(
|
|
433
|
+
(A, R) => n.isValid(A, R, e),
|
|
434
|
+
[n, e]
|
|
435
|
+
), k = y === "always" ? 0 : y === "skip" ? 1 : 2, _ = m(k);
|
|
436
|
+
w(() => (_.current = k, () => {
|
|
437
|
+
_.current = k;
|
|
438
|
+
}), []);
|
|
439
|
+
const { enrichedFormData: D, handleInput: q } = Rt(
|
|
433
440
|
s,
|
|
434
|
-
|
|
441
|
+
b,
|
|
435
442
|
i,
|
|
436
|
-
|
|
443
|
+
g,
|
|
437
444
|
d,
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
p
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
445
|
+
x,
|
|
446
|
+
v,
|
|
447
|
+
S,
|
|
448
|
+
E,
|
|
449
|
+
p,
|
|
450
|
+
y
|
|
451
|
+
), $ = m(h);
|
|
452
|
+
return w(() => {
|
|
453
|
+
$.current = h;
|
|
454
|
+
}, [h]), w(() => {
|
|
447
455
|
var A;
|
|
448
|
-
|
|
449
|
-
|
|
456
|
+
if (b.length !== 0) {
|
|
457
|
+
if (_.current > 0) {
|
|
458
|
+
_.current--;
|
|
459
|
+
return;
|
|
460
|
+
}
|
|
461
|
+
(A = $.current) == null || A.call($, { formData: D }, void 0);
|
|
462
|
+
}
|
|
463
|
+
}, [D]), /* @__PURE__ */ it(
|
|
450
464
|
u,
|
|
451
465
|
{
|
|
452
|
-
ref:
|
|
453
|
-
...
|
|
454
|
-
schema:
|
|
466
|
+
ref: r,
|
|
467
|
+
...j,
|
|
468
|
+
schema: e,
|
|
455
469
|
validator: n,
|
|
456
|
-
formData:
|
|
457
|
-
uiSchema:
|
|
458
|
-
onChange: (A,
|
|
459
|
-
|
|
470
|
+
formData: D,
|
|
471
|
+
uiSchema: U,
|
|
472
|
+
onChange: (A, R) => {
|
|
473
|
+
q(A.formData), h == null || h(A, R);
|
|
460
474
|
}
|
|
461
475
|
}
|
|
462
476
|
);
|
|
463
477
|
}
|
|
464
|
-
const
|
|
478
|
+
const Mt = at(vt);
|
|
465
479
|
export {
|
|
466
|
-
|
|
467
|
-
|
|
480
|
+
Mt as FormulaForm,
|
|
481
|
+
pt as analyzeSchema
|
|
468
482
|
};
|
|
469
483
|
//# sourceMappingURL=index.mjs.map
|