@a-ludi/rjsf-formulas 0.4.0 → 0.5.0

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