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