@a-ludi/rjsf-formulas 0.4.0 → 0.4.1
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.mjs +203 -201
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,74 +1,74 @@
|
|
|
1
1
|
import { findSchemaDefinition as ft } from "@rjsf/utils";
|
|
2
2
|
import { jsx as ct } from "react/jsx-runtime";
|
|
3
|
-
import { useState as it, useRef as
|
|
3
|
+
import { useState as it, useRef as m, useEffect as j, useCallback as G, forwardRef as ut, useMemo as X } from "react";
|
|
4
4
|
import at from "@rjsf/core";
|
|
5
|
-
const
|
|
6
|
-
function lt(t,
|
|
7
|
-
const
|
|
8
|
-
return
|
|
5
|
+
const K = Symbol("arrayIndex");
|
|
6
|
+
function lt(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 Y(t,
|
|
11
|
-
if (t === !0) return
|
|
12
|
-
const
|
|
13
|
-
return Array.isArray(
|
|
10
|
+
function Y(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
|
|
15
|
+
function pt(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 [${z(
|
|
17
|
+
`[rjsf-formulas] Unknown x-formula-context value "${t}" at path [${z(r)}], treating as "siblings"`
|
|
18
18
|
), "siblings");
|
|
19
19
|
}
|
|
20
20
|
function z(t) {
|
|
21
|
-
return t.map((
|
|
21
|
+
return t.map((r) => typeof r == "symbol" ? "[*]" : String(r)).join(", ");
|
|
22
22
|
}
|
|
23
23
|
function H(t) {
|
|
24
|
-
return t.map((
|
|
24
|
+
return t.map((r) => typeof r == "symbol" ? "[*]" : String(r)).join(".");
|
|
25
25
|
}
|
|
26
|
-
function
|
|
26
|
+
function yt(t, r, e) {
|
|
27
27
|
const s = H(t.path);
|
|
28
|
-
if (
|
|
28
|
+
if (e === "error")
|
|
29
29
|
throw new TypeError(
|
|
30
|
-
`[rjsf-formulas] Formula conflict at path [${z(t.path)}]: "${t.formula}" vs "${
|
|
30
|
+
`[rjsf-formulas] Formula conflict at path [${z(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 dt(t,
|
|
37
|
-
for (const s of
|
|
36
|
+
function dt(t, r, e) {
|
|
37
|
+
for (const s of r) {
|
|
38
38
|
const n = H(s.path), o = t.findIndex((i) => H(i.path) === n);
|
|
39
|
-
o !== -1 ? (
|
|
39
|
+
o !== -1 ? (yt(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
45
|
const c = ft(f.$ref, u);
|
|
46
|
-
|
|
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 [${z(
|
|
53
|
+
`[rjsf-formulas] Formula at path [${z(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:
|
|
60
|
+
contextMode: pt(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, K],
|
|
85
|
+
e,
|
|
84
86
|
s,
|
|
85
87
|
n,
|
|
86
88
|
o,
|
|
@@ -90,116 +92,116 @@ 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), dt(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 = Y(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 [${z(
|
|
109
|
+
`[rjsf-formulas] Formula key "${s}" found inside an "if" schema at path [${z(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 = Y(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 = Y(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
123
|
var V, C;
|
|
122
|
-
function
|
|
123
|
-
return C || (C = 1, V = function t(
|
|
124
|
-
if (
|
|
125
|
-
if (
|
|
126
|
-
if (
|
|
124
|
+
function mt() {
|
|
125
|
+
return C || (C = 1, V = 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
|
|
148
|
+
return r !== r && e !== e;
|
|
147
149
|
}), V;
|
|
148
150
|
}
|
|
149
|
-
var ht =
|
|
150
|
-
const jt = /* @__PURE__ */
|
|
151
|
-
function wt(t,
|
|
152
|
-
const o =
|
|
151
|
+
var ht = mt();
|
|
152
|
+
const jt = /* @__PURE__ */ gt(ht);
|
|
153
|
+
function wt(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
166
|
function tt(t) {
|
|
165
|
-
return t.map((
|
|
167
|
+
return t.map((r) => typeof r == "symbol" ? "[*]" : String(r)).join(", ");
|
|
166
168
|
}
|
|
167
|
-
function k(t,
|
|
168
|
-
return
|
|
169
|
-
if (!(
|
|
170
|
-
return
|
|
169
|
+
function k(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 Q(t,
|
|
174
|
-
if (
|
|
175
|
-
const s = k(t,
|
|
176
|
-
s != null && typeof s == "object" && (s[
|
|
175
|
+
function Q(t, r, e) {
|
|
176
|
+
if (r.length === 0) return;
|
|
177
|
+
const s = k(t, r.slice(0, -1));
|
|
178
|
+
s != null && typeof s == "object" && (s[r[r.length - 1]] = e);
|
|
177
179
|
}
|
|
178
|
-
function D(t,
|
|
179
|
-
if (t.length === 0) return [
|
|
180
|
+
function D(t, r, e = []) {
|
|
181
|
+
if (t.length === 0) return [e];
|
|
180
182
|
const [s, ...n] = t;
|
|
181
|
-
if (s ===
|
|
182
|
-
const o = k(
|
|
183
|
+
if (s === K) {
|
|
184
|
+
const o = k(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(...D(n,
|
|
188
|
+
i.push(...D(n, r, [...e, u]));
|
|
187
189
|
return i;
|
|
188
190
|
}
|
|
189
|
-
return D(n,
|
|
191
|
+
return D(n, r, [...e, s]);
|
|
190
192
|
}
|
|
191
|
-
function Z(t,
|
|
192
|
-
return jt(t,
|
|
193
|
+
function Z(t, r) {
|
|
194
|
+
return jt(t, r);
|
|
193
195
|
}
|
|
194
|
-
async function
|
|
196
|
+
async function rt(t, r, e, s) {
|
|
195
197
|
const n = structuredClone(t), o = [];
|
|
196
|
-
for (const f of
|
|
198
|
+
for (const f of r)
|
|
197
199
|
for (const l of D(f.path, n)) {
|
|
198
200
|
const c = wt(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];
|
|
@@ -212,169 +214,169 @@ async function et(t, e, r, s) {
|
|
|
212
214
|
}
|
|
213
215
|
return { data: n, errors: u };
|
|
214
216
|
}
|
|
215
|
-
function At(t,
|
|
216
|
-
for (const s of
|
|
217
|
-
for (const n of D(s.path,
|
|
218
|
-
if (!Z(k(t, n), k(
|
|
217
|
+
function At(t, r, e) {
|
|
218
|
+
for (const s of e)
|
|
219
|
+
for (const n of D(s.path, r))
|
|
220
|
+
if (!Z(k(t, n), k(r, n)))
|
|
219
221
|
return !1;
|
|
220
222
|
return !0;
|
|
221
223
|
}
|
|
222
|
-
async function Ot(t,
|
|
223
|
-
const l =
|
|
224
|
-
(
|
|
224
|
+
async function Ot(t, r, e, s, n, o, i, u, f) {
|
|
225
|
+
const l = r.filter(
|
|
226
|
+
(y) => y.condition === !0 || u(y.condition, t)
|
|
225
227
|
);
|
|
226
228
|
if (l.length === 0) return t;
|
|
227
229
|
const c = /* @__PURE__ */ new Map(), a = [];
|
|
228
|
-
for (const
|
|
229
|
-
const
|
|
230
|
-
if (c.has(
|
|
230
|
+
for (const y of l) {
|
|
231
|
+
const p = JSON.stringify(y.path);
|
|
232
|
+
if (c.has(p)) {
|
|
231
233
|
if (f === "error")
|
|
232
234
|
throw new TypeError(
|
|
233
|
-
`[rjsf-formulas] Formula conflict: two active fields share path [${tt(
|
|
235
|
+
`[rjsf-formulas] Formula conflict: two active fields share path [${tt(y.path)}]`
|
|
234
236
|
);
|
|
235
237
|
f === "warn" && console.warn(
|
|
236
|
-
`[rjsf-formulas] Formula conflict: two active fields share path [${tt(
|
|
238
|
+
`[rjsf-formulas] Formula conflict: two active fields share path [${tt(y.path)}]; taking last`
|
|
237
239
|
);
|
|
238
|
-
const h = a.indexOf(c.get(
|
|
239
|
-
a[h] =
|
|
240
|
+
const h = a.indexOf(c.get(p));
|
|
241
|
+
a[h] = y, c.set(p, y);
|
|
240
242
|
} else
|
|
241
|
-
c.set(
|
|
243
|
+
c.set(p, y), a.push(y);
|
|
242
244
|
}
|
|
243
245
|
const d = { formulaDataKey: o, formulaPathKey: i };
|
|
244
|
-
let
|
|
245
|
-
for (let
|
|
246
|
-
const { data:
|
|
247
|
-
if (At(
|
|
248
|
-
for (const { path:
|
|
249
|
-
n == null || n(
|
|
250
|
-
return
|
|
246
|
+
let g = t;
|
|
247
|
+
for (let y = 0; y < s; y++) {
|
|
248
|
+
const { data: p, errors: h } = await rt(g, a, e, d);
|
|
249
|
+
if (At(g, p, a)) {
|
|
250
|
+
for (const { path: x, error: _ } of h)
|
|
251
|
+
n == null || n(x, _);
|
|
252
|
+
return p;
|
|
251
253
|
}
|
|
252
|
-
|
|
254
|
+
g = p;
|
|
253
255
|
}
|
|
254
|
-
const { data: b } = await
|
|
255
|
-
for (const
|
|
256
|
-
for (const
|
|
257
|
-
Z(k(
|
|
258
|
-
|
|
256
|
+
const { data: b } = await rt(g, a, e, d), w = structuredClone(b);
|
|
257
|
+
for (const y of a)
|
|
258
|
+
for (const p of D(y.path, b))
|
|
259
|
+
Z(k(g, p), k(b, p)) || (n == null || n(
|
|
260
|
+
p,
|
|
259
261
|
new Error(
|
|
260
|
-
`[rjsf-formulas] Formula at [${
|
|
262
|
+
`[rjsf-formulas] Formula at [${p.join(", ")}] did not converge after ${s} passes`
|
|
261
263
|
)
|
|
262
|
-
), Q(w,
|
|
264
|
+
), Q(w, p, void 0));
|
|
263
265
|
return w;
|
|
264
266
|
}
|
|
265
267
|
function xt(t) {
|
|
266
268
|
return JSON.stringify(t);
|
|
267
269
|
}
|
|
268
|
-
function bt(t,
|
|
269
|
-
const [c, a] = it(t), d =
|
|
270
|
+
function bt(t, r, e, s, n, o, i, u, f, l) {
|
|
271
|
+
const [c, a] = it(t), d = m(t), g = m(t), b = m(/* @__PURE__ */ new Map()), w = m(null), y = m(!1), p = m(o), h = m(i), x = m(e), _ = m(r), T = m(n), F = m(u), $ = m(f), N = m(l);
|
|
270
272
|
j(() => {
|
|
271
|
-
|
|
273
|
+
p.current = o;
|
|
272
274
|
}, [o]), j(() => {
|
|
273
275
|
h.current = i;
|
|
274
276
|
}, [i]), j(() => {
|
|
275
|
-
|
|
276
|
-
}, [r]), j(() => {
|
|
277
|
-
_.current = e;
|
|
277
|
+
x.current = e;
|
|
278
278
|
}, [e]), j(() => {
|
|
279
|
+
_.current = r;
|
|
280
|
+
}, [r]), j(() => {
|
|
279
281
|
T.current = n;
|
|
280
282
|
}, [n]), j(() => {
|
|
281
283
|
F.current = u;
|
|
282
284
|
}, [u]), j(() => {
|
|
283
285
|
$.current = f;
|
|
284
286
|
}, [f]), j(() => {
|
|
285
|
-
|
|
287
|
+
N.current = l;
|
|
286
288
|
}, [l]);
|
|
287
|
-
const
|
|
288
|
-
if (
|
|
289
|
+
const I = G(() => {
|
|
290
|
+
if (y.current) return;
|
|
289
291
|
(async () => {
|
|
290
|
-
var M,
|
|
291
|
-
|
|
292
|
+
var M, U;
|
|
293
|
+
y.current = !0;
|
|
292
294
|
try {
|
|
293
295
|
for (; ; ) {
|
|
294
|
-
const E = d.current,
|
|
296
|
+
const E = d.current, B = _.current, et = B.filter(
|
|
295
297
|
(R) => R.condition === !0 || $.current(R.condition, E)
|
|
296
298
|
), q = [];
|
|
297
|
-
for (const R of
|
|
299
|
+
for (const R of et)
|
|
298
300
|
for (const ot of D(R.path, E))
|
|
299
301
|
q.push(ot);
|
|
300
|
-
const
|
|
301
|
-
|
|
302
|
-
for (const R of q)
|
|
302
|
+
const J = b.current;
|
|
303
|
+
J.clear();
|
|
304
|
+
for (const R of q) J.set(xt(R), "running");
|
|
303
305
|
q.length > 0 && ((M = h.current) == null || M.call(h, q));
|
|
304
306
|
const nt = await Ot(
|
|
305
307
|
E,
|
|
306
|
-
|
|
307
|
-
|
|
308
|
+
B,
|
|
309
|
+
x.current,
|
|
308
310
|
T.current,
|
|
309
|
-
|
|
311
|
+
p.current,
|
|
310
312
|
F.current.formulaDataKey,
|
|
311
313
|
F.current.formulaPathKey,
|
|
312
314
|
$.current,
|
|
313
|
-
|
|
315
|
+
N.current
|
|
314
316
|
);
|
|
315
|
-
if (
|
|
316
|
-
const st = [...
|
|
317
|
-
if (
|
|
318
|
-
a(nt), q.length > 0 && ((
|
|
317
|
+
if (v.current) break;
|
|
318
|
+
const st = [...J.values()].some((R) => R === "dirty");
|
|
319
|
+
if (J.clear(), !st) {
|
|
320
|
+
a(nt), q.length > 0 && ((U = h.current) == null || U.call(h, []));
|
|
319
321
|
break;
|
|
320
322
|
}
|
|
321
323
|
}
|
|
322
324
|
} finally {
|
|
323
|
-
|
|
325
|
+
y.current = !1;
|
|
324
326
|
}
|
|
325
327
|
})();
|
|
326
|
-
}, []),
|
|
327
|
-
(
|
|
328
|
-
d.current =
|
|
328
|
+
}, []), S = G(
|
|
329
|
+
(L) => {
|
|
330
|
+
d.current = L;
|
|
329
331
|
const M = b.current;
|
|
330
|
-
for (const [
|
|
331
|
-
E === "running" && M.set(
|
|
332
|
-
|
|
333
|
-
w.current = null,
|
|
332
|
+
for (const [U, E] of M)
|
|
333
|
+
E === "running" && M.set(U, "dirty");
|
|
334
|
+
y.current || (w.current !== null && clearTimeout(w.current), w.current = setTimeout(() => {
|
|
335
|
+
w.current = null, I();
|
|
334
336
|
}, s));
|
|
335
337
|
},
|
|
336
|
-
[s,
|
|
337
|
-
), A =
|
|
338
|
+
[s, I]
|
|
339
|
+
), A = m(!1), v = m(!1);
|
|
338
340
|
return j(() => {
|
|
339
|
-
A.current ? Z(t,
|
|
340
|
-
}), j(() => (
|
|
341
|
-
|
|
342
|
-
}), []), { enrichedFormData: c, handleInput:
|
|
341
|
+
A.current ? Z(t, g.current) || (g.current = t, S(t)) : (A.current = !0, g.current = t, S(t));
|
|
342
|
+
}), j(() => (v.current = !1, () => {
|
|
343
|
+
v.current = !0, A.current = !1, w.current !== null && clearTimeout(w.current);
|
|
344
|
+
}), []), { enrichedFormData: c, handleInput: S };
|
|
343
345
|
}
|
|
344
|
-
function Rt(t,
|
|
345
|
-
const
|
|
346
|
-
for (const n of
|
|
347
|
-
P(
|
|
348
|
-
return
|
|
346
|
+
function Rt(t, r) {
|
|
347
|
+
const e = structuredClone(t ?? {}), s = $t(r);
|
|
348
|
+
for (const n of r)
|
|
349
|
+
P(e, n.path, s);
|
|
350
|
+
return e;
|
|
349
351
|
}
|
|
350
352
|
function $t(t) {
|
|
351
|
-
const
|
|
352
|
-
for (let
|
|
353
|
-
const s = 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 !==
|
|
358
|
+
if (typeof o != "number" && o !== K) continue;
|
|
357
359
|
const i = W(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 || W(l.path.slice(0, n)) !== i) return !1;
|
|
360
362
|
const a = l.path[n];
|
|
361
|
-
return u ? a ===
|
|
362
|
-
}) &&
|
|
363
|
+
return u ? a === K : typeof a == "number";
|
|
364
|
+
}) && r.add(i);
|
|
363
365
|
}
|
|
364
366
|
}
|
|
365
|
-
return
|
|
367
|
+
return r;
|
|
366
368
|
}
|
|
367
369
|
function W(t) {
|
|
368
|
-
return JSON.stringify(t.map((
|
|
370
|
+
return JSON.stringify(t.map((r) => typeof r == "symbol" ? "__ARRAY_INDEX__" : r));
|
|
369
371
|
}
|
|
370
|
-
function P(t,
|
|
371
|
-
if (
|
|
372
|
+
function P(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] = {}), P(t[n], o,
|
|
379
|
+
(!t[n] || typeof t[n] != "object" || Array.isArray(t[n])) && (t[n] = {}), P(t[n], o, e, [...s, n]);
|
|
378
380
|
return;
|
|
379
381
|
}
|
|
380
382
|
if (typeof n == "number") {
|
|
@@ -384,23 +386,23 @@ 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] = {}), P(f[n], o,
|
|
389
|
+
(!f[n] || typeof f[n] != "object") && (f[n] = {}), P(f[n], o, e, [...s, n]);
|
|
388
390
|
return;
|
|
389
391
|
}
|
|
390
392
|
const i = W(s);
|
|
391
|
-
if (
|
|
392
|
-
(!t.additionalItems || typeof t.additionalItems != "object") && (t.additionalItems = {}), P(t.additionalItems, o,
|
|
393
|
+
if (e.has(i))
|
|
394
|
+
(!t.additionalItems || typeof t.additionalItems != "object") && (t.additionalItems = {}), P(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 = {}), P(t.items, o,
|
|
400
|
+
(!t.items || typeof t.items != "object") && (t.items = {}), P(t.items, o, e, [...s, n]);
|
|
399
401
|
}
|
|
400
402
|
}
|
|
401
|
-
function
|
|
403
|
+
function It(t, r) {
|
|
402
404
|
const {
|
|
403
|
-
schema:
|
|
405
|
+
schema: e,
|
|
404
406
|
formData: s,
|
|
405
407
|
validator: n,
|
|
406
408
|
uiSchema: o,
|
|
@@ -411,57 +413,57 @@ function vt(t, e) {
|
|
|
411
413
|
formulaDataKey: c = "__formData__",
|
|
412
414
|
formulaPathKey: a = "__path__",
|
|
413
415
|
maxConvergencePasses: d = 10,
|
|
414
|
-
debounceMs:
|
|
416
|
+
debounceMs: g = 300,
|
|
415
417
|
onFormulaError: b,
|
|
416
418
|
onLoadingChange: w,
|
|
417
|
-
formulaConflictBehavior:
|
|
418
|
-
onChange:
|
|
419
|
+
formulaConflictBehavior: y = "warn",
|
|
420
|
+
onChange: p,
|
|
419
421
|
...h
|
|
420
|
-
} = t,
|
|
421
|
-
() => lt(
|
|
422
|
-
[
|
|
422
|
+
} = t, x = X(
|
|
423
|
+
() => lt(e, { formulaKey: f, formulaContextKey: l }),
|
|
424
|
+
[e, f, l]
|
|
423
425
|
), _ = X(
|
|
424
426
|
() => ({ formulaDataKey: c, formulaPathKey: a }),
|
|
425
427
|
[c, a]
|
|
426
428
|
), T = X(
|
|
427
|
-
() => Rt(o,
|
|
428
|
-
[o,
|
|
429
|
+
() => Rt(o, x),
|
|
430
|
+
[o, x]
|
|
429
431
|
), F = G(
|
|
430
|
-
(A,
|
|
431
|
-
[n,
|
|
432
|
-
), { enrichedFormData: $, handleInput:
|
|
432
|
+
(A, v) => n.isValid(A, v, e),
|
|
433
|
+
[n, e]
|
|
434
|
+
), { enrichedFormData: $, handleInput: N } = bt(
|
|
433
435
|
s,
|
|
434
|
-
|
|
436
|
+
x,
|
|
435
437
|
i,
|
|
436
|
-
|
|
438
|
+
g,
|
|
437
439
|
d,
|
|
438
440
|
b,
|
|
439
441
|
w,
|
|
440
442
|
_,
|
|
441
443
|
F,
|
|
442
|
-
|
|
443
|
-
),
|
|
444
|
+
y
|
|
445
|
+
), I = m(p);
|
|
444
446
|
return j(() => {
|
|
445
|
-
|
|
446
|
-
}, [
|
|
447
|
+
I.current = p;
|
|
448
|
+
}, [p]), j(() => {
|
|
447
449
|
var A;
|
|
448
|
-
|
|
450
|
+
x.length !== 0 && ((A = I.current) == null || A.call(I, { formData: $ }, void 0));
|
|
449
451
|
}, [$]), /* @__PURE__ */ ct(
|
|
450
452
|
u,
|
|
451
453
|
{
|
|
452
|
-
ref:
|
|
454
|
+
ref: r,
|
|
453
455
|
...h,
|
|
454
|
-
schema:
|
|
456
|
+
schema: e,
|
|
455
457
|
validator: n,
|
|
456
458
|
formData: $,
|
|
457
459
|
uiSchema: T,
|
|
458
|
-
onChange: (A,
|
|
459
|
-
|
|
460
|
+
onChange: (A, v) => {
|
|
461
|
+
N(A.formData), p == null || p(A, v);
|
|
460
462
|
}
|
|
461
463
|
}
|
|
462
464
|
);
|
|
463
465
|
}
|
|
464
|
-
const Ft = ut(
|
|
466
|
+
const Ft = ut(It);
|
|
465
467
|
export {
|
|
466
468
|
Ft as FormulaForm,
|
|
467
469
|
lt as analyzeSchema
|