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