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