@sonata-innovations/fiber-fbre 2.0.0 → 2.0.3

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.
@@ -1,240 +1,240 @@
1
- import { jsx as m, jsxs as k } from "react/jsx-runtime";
2
- import { createContext as Je, useContext as xe, useMemo as Ee, useState as P, useRef as ce, useEffect as K, useCallback as z } from "react";
3
- import { useStore as W, createStore as Ye } from "zustand";
4
- import { normalizeOptions as tn } from "@sonata-innovations/fiber-types";
5
- import { validateValue as on, isHiddenByCondition as Q, extractFormulaReferences as Ie, evaluateFormula as ne, evaluateConditionConfig as rn, formatCalculationResult as sn } from "@sonata-innovations/fiber-shared";
6
- const cn = /* @__PURE__ */ new Map(), an = (e) => cn.get(e), ln = /* @__PURE__ */ new Set([
1
+ import { jsx as m, jsxs as B, Fragment as fn } from "react/jsx-runtime";
2
+ import { createContext as Ke, useContext as Ie, useMemo as ke, useState as J, useRef as Z, useEffect as H, useCallback as z } from "react";
3
+ import { useStore as Q, createStore as Qe } from "zustand";
4
+ import { normalizeOptions as mn } from "@sonata-innovations/fiber-types";
5
+ import { validateValue as vn, isHiddenByCondition as te, extractFormulaReferences as Be, evaluateFormula as ie, evaluateConditionConfig as hn, formatCalculationResult as yn } from "@sonata-innovations/fiber-shared";
6
+ const gn = /* @__PURE__ */ new Map(), bn = (n) => gn.get(n), Cn = /* @__PURE__ */ new Set([
7
7
  "header",
8
8
  "text",
9
9
  "divider",
10
10
  "callout",
11
11
  "table"
12
- ]), me = (e) => ln.has(e), dn = (e, r) => {
13
- var o, t, n, s;
12
+ ]), ve = (n) => Cn.has(n), Sn = (n, r) => {
13
+ var o, t, e, s;
14
14
  if (r.includes(":")) {
15
- const i = r.split(":"), a = e.components[i[0]];
16
- return (n = (t = (o = a == null ? void 0 : a.addedComponents) == null ? void 0 : o[parseInt(i[1])]) == null ? void 0 : t[parseInt(i[2])]) == null ? void 0 : n.value;
15
+ const c = r.split(":"), i = n.components[c[0]];
16
+ return (e = (t = (o = i == null ? void 0 : i.addedComponents) == null ? void 0 : o[parseInt(c[1])]) == null ? void 0 : t[parseInt(c[2])]) == null ? void 0 : e.value;
17
17
  }
18
- return (s = e.components[r]) == null ? void 0 : s.value;
19
- }, F = (e, r) => {
18
+ return (s = n.components[r]) == null ? void 0 : s.value;
19
+ }, M = (n, r) => {
20
20
  var t;
21
- const o = (t = e.properties) == null ? void 0 : t.validation;
22
- return !o || !o.rules || o.rules.length === 0 ? [] : on(
23
- e.value,
21
+ const o = (t = n.properties) == null ? void 0 : t.validation;
22
+ return !o || !o.rules || o.rules.length === 0 ? [] : vn(
23
+ n.value,
24
24
  o,
25
- r ? (n) => dn(r, n) : void 0
25
+ r ? (e) => Sn(r, e) : void 0
26
26
  );
27
- }, un = (e) => {
27
+ }, wn = (n) => {
28
28
  var o;
29
- const r = (o = e.properties) == null ? void 0 : o.validation;
29
+ const r = (o = n.properties) == null ? void 0 : o.validation;
30
30
  return !r || !r.rules ? !1 : r.rules.some((t) => t.type === "required");
31
- }, Y = (e) => {
31
+ }, X = (n) => {
32
32
  var o, t;
33
- const r = { ...e };
33
+ const r = { ...n };
34
34
  return Array.isArray((o = r.properties) == null ? void 0 : o.options) && (r.properties = {
35
35
  ...r.properties,
36
- options: tn(r.properties.options)
37
- }), e.type === "computed" ? (r.value = null, r.valid = !0) : !me(e.type) && e.type !== "group" && e.type !== "repeater" && (r.value = null, r.valid = !un(e)), (e.type === "checkbox" || e.type === "dropDownMulti") && (r.value = []), e.type === "radio" && "options" in e.properties && e.properties.options.length > 0 && (r.value = e.properties.options[0].value), e.type === "toggleSwitch" && (r.value = !1), e.type === "colorPicker" && ((t = e.properties) != null && t.defaultValue) && (r.value = e.properties.defaultValue), e.type === "slider" && (r.value = "initValue" in e.properties ? e.properties.initValue : "min" in e.properties ? e.properties.min : 0), r;
38
- }, ae = (e, r, o) => {
36
+ options: mn(r.properties.options)
37
+ }), n.type === "computed" ? (r.value = null, r.valid = !0) : !ve(n.type) && n.type !== "group" && n.type !== "repeater" && (r.value = null, r.valid = !wn(n)), (n.type === "checkbox" || n.type === "dropDownMulti") && (r.value = []), n.type === "radio" && "options" in n.properties && n.properties.options.length > 0 && (r.value = n.properties.options[0].value), n.type === "toggleSwitch" && (r.value = !1), n.type === "colorPicker" && ((t = n.properties) != null && t.defaultValue) && (r.value = n.properties.defaultValue), n.type === "slider" && (r.value = "initValue" in n.properties ? n.properties.initValue : "min" in n.properties ? n.properties.min : 0), r;
38
+ }, le = (n, r, o) => {
39
39
  var t;
40
- for (const n of o.rules)
41
- if (n.type === "matchesField" && ((t = n.params) != null && t.field)) {
42
- const s = n.params.field;
43
- e[s] || (e[s] = []), e[s].push({
40
+ for (const e of o.rules)
41
+ if (e.type === "matchesField" && ((t = e.params) != null && t.field)) {
42
+ const s = e.params.field;
43
+ n[s] || (n[s] = []), n[s].push({
44
44
  target: r,
45
45
  config: o
46
46
  });
47
47
  }
48
- }, Z = (e, r) => {
49
- const o = e.screens[r];
50
- return o ? !o.components.some((n) => {
51
- var a;
52
- const s = e.components[n.uuid];
48
+ }, oe = (n, r) => {
49
+ const o = n.screens[r];
50
+ return o ? !o.components.some((e) => {
51
+ var i;
52
+ const s = n.components[e.uuid];
53
53
  if (!s) return !1;
54
54
  if (s.type === "group" || s.type === "repeater")
55
- return (a = s.addedComponents) == null ? void 0 : a.some(
56
- (c) => c.some((d) => {
57
- const l = d.conditions && "when" in d.conditions ? d.conditions : void 0;
58
- return l && Q(l, e.conditionResults[d.uuid]) ? !1 : !d.valid;
55
+ return (i = s.addedComponents) == null ? void 0 : i.some(
56
+ (l) => l.some((a) => {
57
+ const u = a.conditions && "when" in a.conditions ? a.conditions : void 0;
58
+ return u && te(u, n.conditionResults[a.uuid]) ? !1 : !a.valid;
59
59
  })
60
60
  );
61
- const i = s.conditions && "when" in s.conditions ? s.conditions : void 0;
62
- return Q(i, e.conditionResults[s.uuid]) ? !1 : s && "valid" in s && !s.valid;
61
+ const c = s.conditions && "when" in s.conditions ? s.conditions : void 0;
62
+ return te(c, n.conditionResults[s.uuid]) ? !1 : s && "valid" in s && !s.valid;
63
63
  }) : !0;
64
64
  };
65
- function pn(e) {
65
+ function Nn(n) {
66
66
  const r = {};
67
- for (const o of e) {
68
- const t = Ie(o.formula);
69
- for (const n of t)
70
- r[n] || (r[n] = []), r[n].includes(o.uuid) || r[n].push(o.uuid);
67
+ for (const o of n) {
68
+ const t = Be(o.formula);
69
+ for (const e of t)
70
+ r[e] || (r[e] = []), r[e].includes(o.uuid) || r[e].push(o.uuid);
71
71
  }
72
72
  return r;
73
73
  }
74
- function qe(e) {
75
- const r = new Map(e.map((i) => [i.uuid, i])), o = new Set(e.map((i) => i.uuid)), t = /* @__PURE__ */ new Set(), n = [];
76
- function s(i, a) {
77
- if (t.has(i) || a.has(i)) return;
78
- a.add(i);
79
- const c = r.get(i);
80
- if (!c) return;
81
- const d = Ie(c.formula);
82
- for (const l of d)
83
- o.has(l) && s(l, a);
84
- a.delete(i), t.add(i), n.push(c);
74
+ function Ze(n) {
75
+ const r = new Map(n.map((c) => [c.uuid, c])), o = new Set(n.map((c) => c.uuid)), t = /* @__PURE__ */ new Set(), e = [];
76
+ function s(c, i) {
77
+ if (t.has(c) || i.has(c)) return;
78
+ i.add(c);
79
+ const l = r.get(c);
80
+ if (!l) return;
81
+ const a = Be(l.formula);
82
+ for (const u of a)
83
+ o.has(u) && s(u, i);
84
+ i.delete(c), t.add(c), e.push(l);
85
85
  }
86
- for (const i of e)
87
- s(i.uuid, /* @__PURE__ */ new Set());
88
- return n;
86
+ for (const c of n)
87
+ s(c.uuid, /* @__PURE__ */ new Set());
88
+ return e;
89
89
  }
90
- function He(e, r) {
90
+ function en(n, r) {
91
91
  return {
92
92
  resolveValue: (o) => {
93
93
  if (o in r)
94
94
  return r[o];
95
- const t = q(e, o);
95
+ const t = ee(n, o);
96
96
  if (!t) return null;
97
- const n = t.value;
98
- if (n == null || n === "") return null;
99
- const s = Number(n);
97
+ const e = t.value;
98
+ if (e == null || e === "") return null;
99
+ const s = Number(e);
100
100
  return isNaN(s) ? null : s;
101
101
  },
102
102
  resolveOptionMetadata: (o, t) => {
103
- var l;
104
- const n = q(e, o);
105
- if (!n) return null;
106
- const s = n.value;
103
+ var u;
104
+ const e = ee(n, o);
105
+ if (!e) return null;
106
+ const s = e.value;
107
107
  if (!s) return null;
108
- const i = (l = n.properties) == null ? void 0 : l.options;
109
- if (!Array.isArray(i)) return null;
110
- const a = i.find(
111
- (u) => u.value === s || u.label === s
108
+ const c = (u = e.properties) == null ? void 0 : u.options;
109
+ if (!Array.isArray(c)) return null;
110
+ const i = c.find(
111
+ (d) => d.value === s || d.label === s
112
112
  );
113
- if (!(a != null && a.metadata)) return null;
114
- const c = a.metadata[t];
115
- if (c == null) return null;
116
- const d = Number(c);
117
- return isNaN(d) ? null : d;
113
+ if (!(i != null && i.metadata)) return null;
114
+ const l = i.metadata[t];
115
+ if (l == null) return null;
116
+ const a = Number(l);
117
+ return isNaN(a) ? null : a;
118
118
  },
119
119
  resolveRepeaterValues: (o) => {
120
- for (const t of Object.keys(e.components)) {
121
- const n = e.components[t];
122
- if (n.type !== "repeater" || !n.addedComponents || !n.components) continue;
123
- const s = n.components.findIndex((a) => a.uuid === o);
120
+ for (const t of Object.keys(n.components)) {
121
+ const e = n.components[t];
122
+ if (e.type !== "repeater" || !e.addedComponents || !e.components) continue;
123
+ const s = e.components.findIndex((i) => i.uuid === o);
124
124
  if (s === -1) continue;
125
- const i = [];
126
- for (const a of n.addedComponents) {
127
- const c = a[s];
128
- if (!c) continue;
129
- const d = c.value;
130
- if (d == null || d === "") continue;
131
- const l = Number(d);
132
- isNaN(l) || i.push(l);
125
+ const c = [];
126
+ for (const i of e.addedComponents) {
127
+ const l = i[s];
128
+ if (!l) continue;
129
+ const a = l.value;
130
+ if (a == null || a === "") continue;
131
+ const u = Number(a);
132
+ isNaN(u) || c.push(u);
133
133
  }
134
- return i.length > 0 ? i : null;
134
+ return c.length > 0 ? c : null;
135
135
  }
136
136
  return null;
137
137
  }
138
138
  };
139
139
  }
140
- function Se(e) {
141
- const r = e.calculations ?? [];
140
+ function Ee(n) {
141
+ const r = n.calculations ?? [];
142
142
  if (r.length === 0) return {};
143
- const o = qe(r), t = {}, n = He(e, t);
143
+ const o = Ze(r), t = {}, e = en(n, t);
144
144
  for (const s of o)
145
- t[s.uuid] = ne(s.formula, n);
145
+ t[s.uuid] = ie(s.formula, e);
146
146
  return t;
147
147
  }
148
- function be(e, r) {
149
- const o = e.calculationsByDependency, t = e.calculations ?? [];
148
+ function we(n, r) {
149
+ const o = n.calculationsByDependency, t = n.calculations ?? [];
150
150
  if (t.length === 0 || !o) return null;
151
- const n = /* @__PURE__ */ new Set(), s = [r];
151
+ const e = /* @__PURE__ */ new Set(), s = [r];
152
152
  for (; s.length > 0; ) {
153
- const l = s.shift(), u = o[l];
154
- if (u)
155
- for (const p of u)
156
- n.has(p) || (n.add(p), s.push(p));
153
+ const u = s.shift(), d = o[u];
154
+ if (d)
155
+ for (const f of d)
156
+ e.has(f) || (e.add(f), s.push(f));
157
157
  }
158
- if (n.size === 0) return null;
159
- const i = qe(t), a = { ...e.calculationResults }, c = He(e, a);
160
- let d = !1;
161
- for (const l of i)
162
- if (n.has(l.uuid)) {
163
- const u = ne(l.formula, c);
164
- a[l.uuid] !== u && (a[l.uuid] = u, d = !0);
158
+ if (e.size === 0) return null;
159
+ const c = Ze(t), i = { ...n.calculationResults }, l = en(n, i);
160
+ let a = !1;
161
+ for (const u of c)
162
+ if (e.has(u.uuid)) {
163
+ const d = ie(u.formula, l);
164
+ i[u.uuid] !== d && (i[u.uuid] = d, a = !0);
165
165
  }
166
- return d ? a : null;
166
+ return a ? i : null;
167
167
  }
168
- function fn(e) {
168
+ function Rn(n) {
169
169
  const r = {}, o = (t) => {
170
170
  var s;
171
171
  if (t.type !== "computed" || !((s = t.properties) != null && s.formula)) return;
172
- const n = Ie(t.properties.formula);
173
- for (const i of n)
174
- r[i] || (r[i] = []), r[i].includes(t.uuid) || r[i].push(t.uuid);
172
+ const e = Be(t.properties.formula);
173
+ for (const c of e)
174
+ r[c] || (r[c] = []), r[c].includes(t.uuid) || r[c].push(t.uuid);
175
175
  };
176
- for (const t of Object.values(e))
176
+ for (const t of Object.values(n))
177
177
  if (o(t), (t.type === "repeater" || t.type === "group") && t.components)
178
- for (const n of t.components)
179
- o(n);
178
+ for (const e of t.components)
179
+ o(e);
180
180
  return r;
181
181
  }
182
- function We(e, r, o, t) {
183
- var c, d;
184
- const n = e.components[o], s = ((c = n == null ? void 0 : n.components) == null ? void 0 : c.map((l) => l.uuid)) ?? [], i = (d = n == null ? void 0 : n.addedComponents) == null ? void 0 : d[t], a = /* @__PURE__ */ new Map();
185
- if (i)
186
- for (let l = 0; l < i.length; l++) {
187
- const u = s[l];
188
- u && a.set(u, i[l]);
182
+ function nn(n, r, o, t) {
183
+ var l, a;
184
+ const e = n.components[o], s = ((l = e == null ? void 0 : e.components) == null ? void 0 : l.map((u) => u.uuid)) ?? [], c = (a = e == null ? void 0 : e.addedComponents) == null ? void 0 : a[t], i = /* @__PURE__ */ new Map();
185
+ if (c)
186
+ for (let u = 0; u < c.length; u++) {
187
+ const d = s[u];
188
+ d && i.set(d, c[u]);
189
189
  }
190
190
  return {
191
- resolveValue: (l) => {
192
- if (l in r)
193
- return r[l];
194
- const u = a.get(l);
195
- if (u) {
196
- const g = u.value;
191
+ resolveValue: (u) => {
192
+ if (u in r)
193
+ return r[u];
194
+ const d = i.get(u);
195
+ if (d) {
196
+ const g = d.value;
197
197
  if (g == null || g === "") return null;
198
- const h = Number(g);
199
- return isNaN(h) ? null : h;
198
+ const v = Number(g);
199
+ return isNaN(v) ? null : v;
200
200
  }
201
- const p = q(e, l);
202
- if (!p) return null;
203
- const f = p.value;
204
- if (f == null || f === "") return null;
205
- const y = Number(f);
201
+ const f = ee(n, u);
202
+ if (!f) return null;
203
+ const p = f.value;
204
+ if (p == null || p === "") return null;
205
+ const y = Number(p);
206
206
  return isNaN(y) ? null : y;
207
207
  },
208
- resolveOptionMetadata: (l, u) => {
209
- var w;
210
- const f = a.get(l) ?? q(e, l);
211
- if (!f) return null;
212
- const y = f.value;
208
+ resolveOptionMetadata: (u, d) => {
209
+ var C;
210
+ const p = i.get(u) ?? ee(n, u);
211
+ if (!p) return null;
212
+ const y = p.value;
213
213
  if (!y) return null;
214
- const g = (w = f.properties) == null ? void 0 : w.options;
214
+ const g = (C = p.properties) == null ? void 0 : C.options;
215
215
  if (!Array.isArray(g)) return null;
216
- const h = g.find(
217
- (C) => C.value === y || C.label === y
216
+ const v = g.find(
217
+ (S) => S.value === y || S.label === y
218
218
  );
219
- if (!(h != null && h.metadata)) return null;
220
- const v = h.metadata[u];
221
- if (v == null) return null;
222
- const b = Number(v);
219
+ if (!(v != null && v.metadata)) return null;
220
+ const h = v.metadata[d];
221
+ if (h == null) return null;
222
+ const b = Number(h);
223
223
  return isNaN(b) ? null : b;
224
224
  },
225
- resolveRepeaterValues: (l) => {
226
- for (const u of Object.keys(e.components)) {
227
- const p = e.components[u];
228
- if (p.type !== "repeater" || !p.addedComponents || !p.components) continue;
229
- const f = p.components.findIndex((g) => g.uuid === l);
230
- if (f === -1) continue;
225
+ resolveRepeaterValues: (u) => {
226
+ for (const d of Object.keys(n.components)) {
227
+ const f = n.components[d];
228
+ if (f.type !== "repeater" || !f.addedComponents || !f.components) continue;
229
+ const p = f.components.findIndex((g) => g.uuid === u);
230
+ if (p === -1) continue;
231
231
  const y = [];
232
- for (const g of p.addedComponents) {
233
- const h = g[f];
234
- if (!h) continue;
235
- const v = h.value;
236
- if (v == null || v === "") continue;
237
- const b = Number(v);
232
+ for (const g of f.addedComponents) {
233
+ const v = g[p];
234
+ if (!v) continue;
235
+ const h = v.value;
236
+ if (h == null || h === "") continue;
237
+ const b = Number(h);
238
238
  isNaN(b) || y.push(b);
239
239
  }
240
240
  return y.length > 0 ? y : null;
@@ -243,423 +243,427 @@ function We(e, r, o, t) {
243
243
  }
244
244
  };
245
245
  }
246
- function ve(e, r) {
246
+ function he(n, r) {
247
247
  return {
248
248
  resolveValue: (o) => {
249
249
  if (o in r)
250
250
  return r[o];
251
- const t = q(e, o);
251
+ const t = ee(n, o);
252
252
  if (!t) return null;
253
- const n = t.value;
254
- if (n == null || n === "") return null;
255
- const s = Number(n);
253
+ const e = t.value;
254
+ if (e == null || e === "") return null;
255
+ const s = Number(e);
256
256
  return isNaN(s) ? null : s;
257
257
  },
258
258
  resolveOptionMetadata: (o, t) => {
259
- var l;
260
- const n = q(e, o);
261
- if (!n) return null;
262
- const s = n.value;
259
+ var u;
260
+ const e = ee(n, o);
261
+ if (!e) return null;
262
+ const s = e.value;
263
263
  if (!s) return null;
264
- const i = (l = n.properties) == null ? void 0 : l.options;
265
- if (!Array.isArray(i)) return null;
266
- const a = i.find(
267
- (u) => u.value === s || u.label === s
264
+ const c = (u = e.properties) == null ? void 0 : u.options;
265
+ if (!Array.isArray(c)) return null;
266
+ const i = c.find(
267
+ (d) => d.value === s || d.label === s
268
268
  );
269
- if (!(a != null && a.metadata)) return null;
270
- const c = a.metadata[t];
271
- if (c == null) return null;
272
- const d = Number(c);
273
- return isNaN(d) ? null : d;
269
+ if (!(i != null && i.metadata)) return null;
270
+ const l = i.metadata[t];
271
+ if (l == null) return null;
272
+ const a = Number(l);
273
+ return isNaN(a) ? null : a;
274
274
  },
275
275
  resolveRepeaterValues: (o) => {
276
- for (const t of Object.keys(e.components)) {
277
- const n = e.components[t];
278
- if (n.type !== "repeater" || !n.addedComponents || !n.components) continue;
279
- const s = n.components.findIndex((a) => a.uuid === o);
276
+ for (const t of Object.keys(n.components)) {
277
+ const e = n.components[t];
278
+ if (e.type !== "repeater" || !e.addedComponents || !e.components) continue;
279
+ const s = e.components.findIndex((i) => i.uuid === o);
280
280
  if (s === -1) continue;
281
- const i = [];
282
- for (const a of n.addedComponents) {
283
- const c = a[s];
284
- if (!c) continue;
285
- const d = c.value;
286
- if (d == null || d === "") continue;
287
- const l = Number(d);
288
- isNaN(l) || i.push(l);
281
+ const c = [];
282
+ for (const i of e.addedComponents) {
283
+ const l = i[s];
284
+ if (!l) continue;
285
+ const a = l.value;
286
+ if (a == null || a === "") continue;
287
+ const u = Number(a);
288
+ isNaN(u) || c.push(u);
289
289
  }
290
- return i.length > 0 ? i : null;
290
+ return c.length > 0 ? c : null;
291
291
  }
292
292
  return null;
293
293
  }
294
294
  };
295
295
  }
296
- function Re(e) {
296
+ function xe(n) {
297
297
  var o, t;
298
- const r = e.calculationResults ?? {};
299
- for (const n of Object.values(e.components))
300
- if (n.type === "computed" && ((o = n.properties) != null && o.formula)) {
301
- const s = ve(e, r), i = ne(n.properties.formula, s);
302
- n.value = i;
298
+ const r = n.calculationResults ?? {};
299
+ for (const e of Object.values(n.components))
300
+ if (e.type === "computed" && ((o = e.properties) != null && o.formula)) {
301
+ const s = he(n, r), c = ie(e.properties.formula, s);
302
+ e.value = c;
303
303
  }
304
- for (const n of Object.values(e.components))
305
- if ((n.type === "repeater" || n.type === "group") && n.addedComponents && n.components)
306
- for (let s = 0; s < n.addedComponents.length; s++) {
307
- const i = n.addedComponents[s];
308
- for (let a = 0; a < i.length; a++) {
309
- const c = i[a], d = n.components[a];
310
- if ((d == null ? void 0 : d.type) === "computed" && ((t = d.properties) != null && t.formula)) {
311
- const l = n.type === "repeater" ? We(e, r, n.uuid, s) : ve(e, r), u = ne(d.properties.formula, l);
312
- c.value = u;
304
+ for (const e of Object.values(n.components))
305
+ if ((e.type === "repeater" || e.type === "group") && e.addedComponents && e.components)
306
+ for (let s = 0; s < e.addedComponents.length; s++) {
307
+ const c = e.addedComponents[s];
308
+ for (let i = 0; i < c.length; i++) {
309
+ const l = c[i], a = e.components[i];
310
+ if ((a == null ? void 0 : a.type) === "computed" && ((t = a.properties) != null && t.formula)) {
311
+ const u = e.type === "repeater" ? nn(n, r, e.uuid, s) : he(n, r), d = ie(a.properties.formula, u);
312
+ l.value = d;
313
313
  }
314
314
  }
315
315
  }
316
316
  }
317
- function mn(e, r) {
318
- var i, a;
319
- const o = e.computedByDependency;
317
+ function En(n, r) {
318
+ var c, i;
319
+ const o = n.computedByDependency;
320
320
  if (!o) return !1;
321
321
  const t = o[r];
322
322
  if (!t || t.length === 0) return !1;
323
- const n = e.calculationResults ?? {};
323
+ const e = n.calculationResults ?? {};
324
324
  let s = !1;
325
- for (const c of t) {
326
- const d = e.components[c];
327
- if (d && d.type === "computed" && ((i = d.properties) != null && i.formula)) {
328
- const l = ve(e, n), u = ne(d.properties.formula, l);
329
- d.value !== u && (e.components[c] = { ...d, value: u }, s = !0);
325
+ for (const l of t) {
326
+ const a = n.components[l];
327
+ if (a && a.type === "computed" && ((c = a.properties) != null && c.formula)) {
328
+ const u = he(n, e), d = ie(a.properties.formula, u);
329
+ a.value !== d && (n.components[l] = { ...a, value: d }, s = !0);
330
330
  continue;
331
331
  }
332
- for (const l of Object.values(e.components))
333
- if ((l.type === "repeater" || l.type === "group") && l.components && l.addedComponents) {
334
- const u = l.components.findIndex((f) => f.uuid === c);
335
- if (u === -1) continue;
336
- const p = l.components[u];
337
- if ((p == null ? void 0 : p.type) !== "computed" || !((a = p.properties) != null && a.formula)) continue;
338
- for (let f = 0; f < l.addedComponents.length; f++) {
339
- const y = l.addedComponents[f][u];
332
+ for (const u of Object.values(n.components))
333
+ if ((u.type === "repeater" || u.type === "group") && u.components && u.addedComponents) {
334
+ const d = u.components.findIndex((p) => p.uuid === l);
335
+ if (d === -1) continue;
336
+ const f = u.components[d];
337
+ if ((f == null ? void 0 : f.type) !== "computed" || !((i = f.properties) != null && i.formula)) continue;
338
+ for (let p = 0; p < u.addedComponents.length; p++) {
339
+ const y = u.addedComponents[p][d];
340
340
  if (!y) continue;
341
- const g = l.type === "repeater" ? We(e, n, l.uuid, f) : ve(e, n), h = ne(p.properties.formula, g);
342
- y.value !== h && (l.addedComponents[f][u] = { ...y, value: h }, s = !0);
341
+ const g = u.type === "repeater" ? nn(n, e, u.uuid, p) : he(n, e), v = ie(f.properties.formula, g);
342
+ y.value !== v && (u.addedComponents[p][d] = { ...y, value: v }, s = !0);
343
343
  }
344
344
  }
345
345
  }
346
346
  return s;
347
347
  }
348
- const Xe = (e, r) => {
348
+ const tn = (n, r) => {
349
349
  var o, t;
350
350
  if (r.includes(":")) {
351
- const n = r.split(":"), s = e[n[0]];
352
- return (t = (o = s == null ? void 0 : s.addedComponents) == null ? void 0 : o[parseInt(n[1])]) == null ? void 0 : t[parseInt(n[2])];
351
+ const e = r.split(":"), s = n[e[0]];
352
+ return (t = (o = s == null ? void 0 : s.addedComponents) == null ? void 0 : o[parseInt(e[1])]) == null ? void 0 : t[parseInt(e[2])];
353
353
  }
354
- return e[r];
355
- }, pe = (e, r) => {
356
- for (const o of e.screenOrder)
357
- if (e.screens[o].components.some((n) => n.uuid === r))
354
+ return n[r];
355
+ }, fe = (n, r) => {
356
+ for (const o of n.screenOrder)
357
+ if (n.screens[o].components.some((e) => e.uuid === r))
358
358
  return o;
359
359
  return null;
360
- }, vn = (e, r) => {
360
+ }, xn = (n, r) => {
361
361
  if (!r.includes(":")) return null;
362
362
  const o = r.split(":");
363
363
  if (o.length !== 3) return null;
364
- const t = o[0], n = parseInt(o[2]), s = e.components[t];
364
+ const t = o[0], e = parseInt(o[2]), s = n.components[t];
365
365
  if (!s || s.type !== "repeater" || !s.components) return null;
366
- const i = s.components[n];
367
- return (i == null ? void 0 : i.uuid) ?? null;
368
- }, Ae = (e, r, o, t, n) => {
369
- const s = r(), i = s.groupComponentMap[o] ?? o, a = gn(e, r, i), c = {
366
+ const c = s.components[e];
367
+ return (c == null ? void 0 : c.uuid) ?? null;
368
+ }, Ye = (n, r, o, t, e) => {
369
+ const s = r(), c = s.groupComponentMap[o] ?? o, i = kn(n, r, c), l = {
370
370
  components: s.components,
371
371
  groupComponentMap: s.groupComponentMap
372
- }, d = F(t, c);
373
- t.valid = d.length === 0;
374
- const l = {
372
+ }, a = M(t, l);
373
+ t.valid = a.length === 0;
374
+ const u = {
375
375
  ...s.validationErrors,
376
- [o]: d
377
- }, u = s.validationsByDependency[o];
378
- if (u)
379
- for (const w of u) {
380
- const C = q(s, w.target);
381
- if (C) {
382
- const N = F(C, c);
383
- C.valid = N.length === 0, l[w.target] = N;
376
+ [o]: a
377
+ }, d = s.validationsByDependency[o];
378
+ if (d)
379
+ for (const C of d) {
380
+ const S = ee(s, C.target);
381
+ if (S) {
382
+ const w = M(S, l);
383
+ S.valid = w.length === 0, u[C.target] = w;
384
384
  }
385
385
  }
386
- const p = pe(s, n), f = {
386
+ const f = fe(s, e), p = {
387
387
  components: { ...s.components },
388
- validationErrors: l
388
+ validationErrors: u
389
389
  };
390
- if (a && (f.conditionResults = a), p) {
391
- const w = { ...s, ...f };
392
- f.screenValidity = {
390
+ if (i && (p.conditionResults = i), f) {
391
+ const C = { ...s, ...p };
392
+ p.screenValidity = {
393
393
  ...s.screenValidity,
394
- [p]: Z(w, p)
394
+ [f]: oe(C, f)
395
395
  };
396
396
  }
397
- const y = { ...s, ...f }, g = o.includes(":") ? vn(y, o) : null, h = [], v = (w) => {
398
- if (mn(y, w)) {
399
- const C = y.computedByDependency[w] ?? [];
400
- for (const N of C)
401
- h.includes(N) || (h.push(N), v(N));
397
+ const y = { ...s, ...p }, g = o.includes(":") ? xn(y, o) : null, v = [], h = (C) => {
398
+ if (En(y, C)) {
399
+ const S = y.computedByDependency[C] ?? [];
400
+ for (const w of S)
401
+ v.includes(w) || (v.push(w), h(w));
402
402
  }
403
403
  };
404
- v(i), g && g !== i && v(g);
405
- let b = be(y, i);
406
- if (g && g !== i) {
407
- const w = b ? { ...y, calculationResults: b } : y, C = be(w, g);
408
- C && (b = C);
404
+ h(c), g && g !== c && h(g);
405
+ let b = we(y, c);
406
+ if (g && g !== c) {
407
+ const C = b ? { ...y, calculationResults: b } : y, S = we(C, g);
408
+ S && (b = S);
409
409
  }
410
- for (const w of h) {
411
- const C = b ? { ...y, calculationResults: b } : y, N = be(C, w);
412
- N && (b = N);
410
+ for (const C of v) {
411
+ const S = b ? { ...y, calculationResults: b } : y, w = we(S, C);
412
+ w && (b = w);
413
413
  }
414
- b && (f.calculationResults = b), e(f);
415
- }, hn = (e, r) => ({
414
+ b && (p.calculationResults = b), n(p);
415
+ }, Dn = (n, r) => ({
416
416
  updateComponentValue: (o, t) => {
417
- var i, a;
418
- const n = r();
417
+ var c, i;
418
+ const e = r();
419
419
  if (o.includes(":")) {
420
- const c = o.split(":"), d = c[0], l = parseInt(c[1]), u = parseInt(c[2]), p = n.components[d];
421
- if (!((a = (i = p == null ? void 0 : p.addedComponents) == null ? void 0 : i[l]) != null && a[u])) return;
422
- const f = p.addedComponents[l][u].value !== t;
423
- if (p.addedComponents[l][u] = { ...p.addedComponents[l][u], value: t }, f) {
424
- Ae(
425
- e,
420
+ const l = o.split(":"), a = l[0], u = parseInt(l[1]), d = parseInt(l[2]), f = e.components[a];
421
+ if (!((i = (c = f == null ? void 0 : f.addedComponents) == null ? void 0 : c[u]) != null && i[d])) return;
422
+ const p = f.addedComponents[u][d].value !== t;
423
+ if (f.addedComponents[u][d] = { ...f.addedComponents[u][d], value: t }, p) {
424
+ Ye(
425
+ n,
426
426
  r,
427
427
  o,
428
- p.addedComponents[l][u],
429
- d
428
+ f.addedComponents[u][d],
429
+ a
430
430
  );
431
431
  return;
432
432
  }
433
- e({ components: { ...n.components } });
433
+ n({ components: { ...e.components } });
434
434
  return;
435
435
  }
436
- const s = n.components[o];
436
+ const s = e.components[o];
437
437
  if (s) {
438
438
  if (s.type === "group" || s.type === "repeater") {
439
- e({ components: { ...n.components } });
439
+ n({ components: { ...e.components } });
440
440
  return;
441
441
  }
442
- t !== s.value && (s.value = t, Ae(e, r, o, s, o));
442
+ if (t === s.value) {
443
+ n({ selectionTick: r().selectionTick + 1 });
444
+ return;
445
+ }
446
+ s.value = t, Ye(n, r, o, s, o);
443
447
  }
444
448
  },
445
449
  addGroupIteration: (o) => {
446
- const t = r(), n = t.components[o];
447
- if (!n || n.type !== "group" || !n.components)
450
+ const t = r(), e = t.components[o];
451
+ if (!e || e.type !== "group" || !e.components)
448
452
  return;
449
- n.addedComponents || (n.addedComponents = []);
450
- const s = { ...t.conditionsByDependency }, i = n.components.map((d, l) => {
451
- const u = Y(d);
452
- if (u.uuid = [o, n.addedComponents.length, l].join(
453
+ e.addedComponents || (e.addedComponents = []);
454
+ const s = { ...t.conditionsByDependency }, c = e.components.map((a, u) => {
455
+ const d = X(a);
456
+ if (d.uuid = [o, e.addedComponents.length, u].join(
453
457
  ":"
454
- ), t.groupComponentMap[u.uuid] = d.uuid, u.conditions && Object.keys(u.conditions).length > 0) {
455
- const f = "when" in u.conditions ? u.conditions : null;
456
- f && (u.conditions = f, X(
458
+ ), t.groupComponentMap[d.uuid] = a.uuid, d.conditions && Object.keys(d.conditions).length > 0) {
459
+ const p = "when" in d.conditions ? d.conditions : null;
460
+ p && (d.conditions = p, ne(
457
461
  s,
458
- u.uuid,
459
- f,
462
+ d.uuid,
463
+ p,
460
464
  "component"
461
465
  ));
462
466
  }
463
- const p = F(u);
464
- return u.valid = p.length === 0, u;
467
+ const f = M(d);
468
+ return d.valid = f.length === 0, d;
465
469
  });
466
- n.addedComponents.push(i);
467
- const a = pe(t, o), c = { ...t.screenValidity };
468
- return a && (c[a] = Z(
470
+ e.addedComponents.push(c);
471
+ const i = fe(t, o), l = { ...t.screenValidity };
472
+ return i && (l[i] = oe(
469
473
  {
470
474
  ...t
471
475
  },
472
- a
473
- )), e({
476
+ i
477
+ )), n({
474
478
  components: { ...t.components },
475
479
  groupComponentMap: { ...t.groupComponentMap },
476
480
  conditionsByDependency: s,
477
- screenValidity: c
478
- }), n.addedComponents;
481
+ screenValidity: l
482
+ }), e.addedComponents;
479
483
  },
480
484
  addRepeaterIteration: (o) => {
481
- const t = r(), n = t.components[o];
482
- if (!n || n.type !== "repeater" || !n.components)
485
+ const t = r(), e = t.components[o];
486
+ if (!e || e.type !== "repeater" || !e.components)
483
487
  return;
484
- n.addedComponents || (n.addedComponents = []);
485
- const s = { ...t.conditionsByDependency }, i = n.components.map((u, p) => {
486
- const f = Y(u);
487
- if (f.uuid = [
488
+ e.addedComponents || (e.addedComponents = []);
489
+ const s = { ...t.conditionsByDependency }, c = e.components.map((d, f) => {
490
+ const p = X(d);
491
+ if (p.uuid = [
488
492
  o,
489
- n.addedComponents.length,
490
- p
491
- ].join(":"), f.conditions && Object.keys(f.conditions).length > 0) {
492
- const g = "when" in f.conditions ? f.conditions : null;
493
- g && (f.conditions = g, X(
493
+ e.addedComponents.length,
494
+ f
495
+ ].join(":"), p.conditions && Object.keys(p.conditions).length > 0) {
496
+ const g = "when" in p.conditions ? p.conditions : null;
497
+ g && (p.conditions = g, ne(
494
498
  s,
495
- f.uuid,
499
+ p.uuid,
496
500
  g,
497
501
  "component"
498
502
  ));
499
503
  }
500
- const y = F(f);
501
- return f.valid = y.length === 0, f;
504
+ const y = M(p);
505
+ return p.valid = y.length === 0, p;
502
506
  });
503
- n.addedComponents.push(i);
504
- const a = pe(t, o), c = { ...t.screenValidity };
505
- a && (c[a] = Z(
507
+ e.addedComponents.push(c);
508
+ const i = fe(t, o), l = { ...t.screenValidity };
509
+ i && (l[i] = oe(
506
510
  {
507
511
  ...t
508
512
  },
509
- a
513
+ i
510
514
  ));
511
- const d = {
515
+ const a = {
512
516
  ...t,
513
517
  components: { ...t.components }
514
518
  };
515
- Re(d);
516
- const l = Se(d);
517
- return e({
519
+ xe(a);
520
+ const u = Ee(a);
521
+ return n({
518
522
  components: { ...t.components },
519
523
  conditionsByDependency: s,
520
- screenValidity: c,
521
- calculationResults: l
522
- }), n.addedComponents;
524
+ screenValidity: l,
525
+ calculationResults: u
526
+ }), e.addedComponents;
523
527
  },
524
528
  removeRepeaterIteration: (o, t) => {
525
529
  var g;
526
- const n = r(), s = n.components[o];
530
+ const e = r(), s = e.components[o];
527
531
  if (!s || s.type !== "repeater" || !s.addedComponents)
528
532
  return;
529
- const i = ((g = s.properties) == null ? void 0 : g.minIterations) ?? 1;
530
- if (s.addedComponents.length <= i) return;
531
- const a = s.addedComponents[t], c = new Set(a.map((h) => h.uuid));
533
+ const c = ((g = s.properties) == null ? void 0 : g.minIterations) ?? 1;
534
+ if (s.addedComponents.length <= c) return;
535
+ const i = s.addedComponents[t], l = new Set(i.map((v) => v.uuid));
532
536
  s.addedComponents.splice(t, 1);
533
- const d = { ...n.conditionsByDependency }, l = { ...n.validationErrors };
534
- for (const h of c)
535
- delete l[h], delete d[h];
536
- for (const h of Object.keys(d)) {
537
- const v = d[h], b = v.filter((w) => !c.has(w.target));
538
- b.length === 0 ? delete d[h] : b.length !== v.length && (d[h] = b);
537
+ const a = { ...e.conditionsByDependency }, u = { ...e.validationErrors };
538
+ for (const v of l)
539
+ delete u[v], delete a[v];
540
+ for (const v of Object.keys(a)) {
541
+ const h = a[v], b = h.filter((C) => !l.has(C.target));
542
+ b.length === 0 ? delete a[v] : b.length !== h.length && (a[v] = b);
539
543
  }
540
- for (let h = t; h < s.addedComponents.length; h++)
541
- s.addedComponents[h].forEach((v, b) => {
542
- const w = v.uuid, C = [o, h, b].join(":");
543
- if (w !== C) {
544
- v.uuid = C, w in l && (l[C] = l[w], delete l[w]), w in d && (d[C] = d[w], delete d[w]);
545
- for (const N of Object.values(d))
546
- for (const T of N)
547
- T.target === w && (T.target = C);
544
+ for (let v = t; v < s.addedComponents.length; v++)
545
+ s.addedComponents[v].forEach((h, b) => {
546
+ const C = h.uuid, S = [o, v, b].join(":");
547
+ if (C !== S) {
548
+ h.uuid = S, C in u && (u[S] = u[C], delete u[C]), C in a && (a[S] = a[C], delete a[C]);
549
+ for (const w of Object.values(a))
550
+ for (const V of w)
551
+ V.target === C && (V.target = S);
548
552
  }
549
553
  });
550
- const u = pe(n, o), p = { ...n.screenValidity };
551
- u && (p[u] = Z(
554
+ const d = fe(e, o), f = { ...e.screenValidity };
555
+ d && (f[d] = oe(
552
556
  {
553
- ...n
557
+ ...e
554
558
  },
555
- u
559
+ d
556
560
  ));
557
- const f = {
558
- ...n,
559
- components: { ...n.components }
561
+ const p = {
562
+ ...e,
563
+ components: { ...e.components }
560
564
  };
561
- Re(f);
562
- const y = Se(f);
563
- e({
564
- components: { ...n.components },
565
- conditionsByDependency: d,
566
- validationErrors: l,
567
- screenValidity: p,
565
+ xe(p);
566
+ const y = Ee(p);
567
+ n({
568
+ components: { ...e.components },
569
+ conditionsByDependency: a,
570
+ validationErrors: u,
571
+ screenValidity: f,
568
572
  calculationResults: y
569
573
  });
570
574
  }
571
- }), q = (e, r) => Xe(e.components, r), X = (e, r, o, t) => {
572
- const n = /* @__PURE__ */ new Set();
573
- for (const i of o.when.rules)
574
- n.add(i.source);
575
+ }), ee = (n, r) => tn(n.components, r), ne = (n, r, o, t) => {
576
+ const e = /* @__PURE__ */ new Set();
577
+ for (const c of o.when.rules)
578
+ e.add(c.source);
575
579
  const s = { target: r, type: t, config: o };
576
- for (const i of n)
577
- e[i] || (e[i] = []), e[i].push(s);
578
- }, yn = (e, r) => {
580
+ for (const c of e)
581
+ n[c] || (n[c] = []), n[c].push(s);
582
+ }, In = (n, r) => {
579
583
  var o, t;
580
- return r.includes(":") ? (o = q(e, r)) == null ? void 0 : o.value : (t = e.components[r]) == null ? void 0 : t.value;
581
- }, te = (e, r) => rn(r, (o, t) => (t == null ? void 0 : t.sourceType) === "context" ? e.externalContext[t.source] : yn(e, o)), gn = (e, r, o) => {
582
- const t = r(), n = t.conditionsByDependency[o];
583
- if (!n || n.length === 0) return null;
584
+ return r.includes(":") ? (o = ee(n, r)) == null ? void 0 : o.value : (t = n.components[r]) == null ? void 0 : t.value;
585
+ }, ce = (n, r) => hn(r, (o, t) => (t == null ? void 0 : t.sourceType) === "context" ? n.externalContext[t.source] : In(n, o)), kn = (n, r, o) => {
586
+ const t = r(), e = t.conditionsByDependency[o];
587
+ if (!e || e.length === 0) return null;
584
588
  let s = !1;
585
- const i = { ...t.conditionResults };
586
- for (const a of n) {
587
- const c = te(t, a.config);
588
- i[a.target] !== c && (i[a.target] = c, s = !0);
589
+ const c = { ...t.conditionResults };
590
+ for (const i of e) {
591
+ const l = ce(t, i.config);
592
+ c[i.target] !== l && (c[i.target] = l, s = !0);
589
593
  }
590
- return s ? i : null;
591
- }, bn = (e) => {
594
+ return s ? c : null;
595
+ }, Bn = (n) => {
592
596
  const r = {}, o = /* @__PURE__ */ new Set();
593
- for (const t of Object.values(e.conditionsByDependency))
594
- for (const n of t)
595
- o.has(n.target) || (o.add(n.target), r[n.target] = te(e, n.config));
597
+ for (const t of Object.values(n.conditionsByDependency))
598
+ for (const e of t)
599
+ o.has(e.target) || (o.add(e.target), r[e.target] = ce(n, e.config));
596
600
  return r;
597
- }, Ce = (e) => {
598
- if (!e || me(e.type)) return null;
599
- const r = "label" in e.properties ? e.properties.label : "", o = {
600
- uuid: e.uuid,
601
- type: e.type,
602
- value: e.value
601
+ }, Ne = (n) => {
602
+ if (!n || ve(n.type)) return null;
603
+ const r = "label" in n.properties ? n.properties.label : "", o = {
604
+ uuid: n.uuid,
605
+ type: n.type,
606
+ value: n.value
603
607
  };
604
608
  return r && (o.label = r), o;
605
- }, je = (e) => {
606
- if (e.conditions && "when" in e.conditions)
607
- return e.conditions;
608
- }, Cn = (e) => {
609
+ }, Ge = (n) => {
610
+ if (n.conditions && "when" in n.conditions)
611
+ return n.conditions;
612
+ }, On = (n) => {
609
613
  const r = {
610
- uuid: e.flowUUID,
611
- metadata: e.metadata,
614
+ uuid: n.flowUUID,
615
+ metadata: n.metadata,
612
616
  screens: []
613
617
  }, o = (t) => {
614
- const n = e.screens[t];
615
- if (!n) return !1;
616
- const s = n.conditions && "when" in n.conditions ? n.conditions : void 0;
617
- return Q(s, e.conditionResults[t]);
618
+ const e = n.screens[t];
619
+ if (!e) return !1;
620
+ const s = e.conditions && "when" in e.conditions ? e.conditions : void 0;
621
+ return te(s, n.conditionResults[t]);
618
622
  };
619
- return r.screens = e.screenOrder.filter((t) => !o(t)).map((t) => {
620
- const n = e.screens[t], s = {
623
+ return r.screens = n.screenOrder.filter((t) => !o(t)).map((t) => {
624
+ const e = n.screens[t], s = {
621
625
  uuid: t,
622
- components: n.components.map((i) => {
623
- const a = e.components[i.uuid];
624
- if (!a) return null;
625
- const c = je(a);
626
- if (Q(c, e.conditionResults[i.uuid]))
626
+ components: e.components.map((c) => {
627
+ const i = n.components[c.uuid];
628
+ if (!i) return null;
629
+ const l = Ge(i);
630
+ if (te(l, n.conditionResults[c.uuid]))
627
631
  return null;
628
- if ((a.type === "group" || a.type === "repeater") && a.addedComponents) {
629
- const d = Ce(a);
630
- return d ? {
631
- ...d,
632
- components: a.addedComponents.map(
633
- (l) => l.filter((u) => {
634
- const p = je(u);
635
- return !Q(
636
- p,
637
- e.conditionResults[u.uuid]
632
+ if ((i.type === "group" || i.type === "repeater") && i.addedComponents) {
633
+ const a = Ne(i);
634
+ return a ? {
635
+ ...a,
636
+ components: i.addedComponents.map(
637
+ (u) => u.filter((d) => {
638
+ const f = Ge(d);
639
+ return !te(
640
+ f,
641
+ n.conditionResults[d.uuid]
638
642
  );
639
- }).map((u) => Ce(u)).filter((u) => u !== null)
643
+ }).map((d) => Ne(d)).filter((d) => d !== null)
640
644
  )
641
645
  } : null;
642
646
  }
643
- return Ce(a);
644
- }).filter((i) => i !== null)
647
+ return Ne(i);
648
+ }).filter((c) => c !== null)
645
649
  };
646
- return n.label && (s.label = n.label), s;
650
+ return e.label && (s.label = e.label), s;
647
651
  }), r;
648
- }, ye = Je(
652
+ }, be = Ke(
649
653
  null
650
654
  );
651
- function L(e) {
652
- const r = xe(ye);
655
+ function P(n) {
656
+ const r = Ie(be);
653
657
  if (!r)
654
658
  throw new Error("useFBREStore must be used within an FBRE provider");
655
- return W(r, e);
659
+ return Q(r, n);
656
660
  }
657
- const Ke = () => {
658
- const e = xe(ye);
659
- if (!e)
661
+ const Ce = () => {
662
+ const n = Ie(be);
663
+ if (!n)
660
664
  throw new Error("useFBREStoreApi must be used within an FBRE provider");
661
- return e;
662
- }, le = (e) => !e || Object.keys(e).length === 0 ? null : "when" in e ? e : null, wn = [], Sn = () => Ye((e, r) => ({
665
+ return n;
666
+ }, ue = (n) => !n || Object.keys(n).length === 0 ? null : "when" in n ? n : null, Vn = [], Tn = () => Qe((n, r) => ({
663
667
  // Identity
664
668
  flowUUID: "",
665
669
  metadata: {},
@@ -685,206 +689,208 @@ const Ke = () => {
685
689
  calculationsByDependency: {},
686
690
  // Computed components
687
691
  computedByDependency: {},
692
+ // Selection re-click tracking
693
+ selectionTick: 0,
688
694
  // Actions
689
- loadFlow: (o, t, n) => {
690
- var T;
691
- const s = {}, i = [], a = {}, c = {}, d = {}, l = {}, u = {}, p = {}, f = {};
692
- o.screens.forEach((x) => {
693
- const M = le(x.conditions), U = M ? { ...x, conditions: M } : { ...x };
694
- s[x.uuid] = U, i.push(x.uuid), M && X(
695
- l,
696
- x.uuid,
697
- M,
695
+ loadFlow: (o, t, e) => {
696
+ var V;
697
+ const s = {}, c = [], i = {}, l = {}, a = {}, u = {}, d = {}, f = {}, p = {};
698
+ o.screens.forEach((E) => {
699
+ const T = ue(E.conditions), _ = T ? { ...E, conditions: T } : { ...E };
700
+ s[E.uuid] = _, c.push(E.uuid), T && ne(
701
+ u,
702
+ E.uuid,
703
+ T,
698
704
  "screen"
699
- ), x.components.forEach((S) => {
700
- var V;
701
- const D = le(S.conditions), B = Y(S);
702
- if (D && (B.conditions = D), a[S.uuid] = B, D && X(
703
- l,
704
- S.uuid,
705
- D,
706
- "component"
707
- ), (V = B.properties) != null && V.validation && ae(
705
+ ), E.components.forEach((N) => {
706
+ var U;
707
+ const I = ue(N.conditions), k = X(N);
708
+ if (I && (k.conditions = I), i[N.uuid] = k, I && ne(
708
709
  u,
709
- S.uuid,
710
- B.properties.validation
711
- ), (S.type === "group" || S.type === "repeater") && S.components) {
712
- const $ = a[S.uuid];
713
- $.addedComponents || ($.addedComponents = []);
714
- const J = S.properties ?? {}, R = S.type === "repeater" ? J.initialData : void 0, E = S.type === "repeater" ? J.minIterations : void 0, _ = R ? R.length : S.type === "repeater" && E && E > 1 ? E : 1;
715
- for (let O = 0; O < _; O++) {
716
- const ee = S.components.map((H, ge) => {
717
- var ie;
718
- const A = Y(H);
719
- A.uuid = [
720
- S.uuid,
721
- $.addedComponents.length,
722
- ge
723
- ].join(":"), R && R[O] && H.uuid in R[O] && (A.value = R[O][H.uuid]), S.type === "group" && (c[A.uuid] = H.uuid), O === 0 && (d[H.uuid] = A.uuid);
724
- const re = le(A.conditions);
725
- re && (A.conditions = re, X(
726
- l,
727
- A.uuid,
728
- re,
729
- "component"
730
- )), (ie = A.properties) != null && ie.validation && ae(
710
+ N.uuid,
711
+ I,
712
+ "component"
713
+ ), (U = k.properties) != null && U.validation && le(
714
+ d,
715
+ N.uuid,
716
+ k.properties.validation
717
+ ), (N.type === "group" || N.type === "repeater") && N.components) {
718
+ const A = i[N.uuid];
719
+ A.addedComponents || (A.addedComponents = []);
720
+ const q = N.properties ?? {}, j = N.type === "repeater" ? q.initialData : void 0, O = N.type === "repeater" ? q.minIterations : void 0, $ = j ? j.length : N.type === "repeater" && O && O > 1 ? O : 1;
721
+ for (let Y = 0; Y < $; Y++) {
722
+ const K = N.components.map((R, G) => {
723
+ var se;
724
+ const x = X(R);
725
+ x.uuid = [
726
+ N.uuid,
727
+ A.addedComponents.length,
728
+ G
729
+ ].join(":"), j && j[Y] && R.uuid in j[Y] && (x.value = j[Y][R.uuid]), N.type === "group" && (l[x.uuid] = R.uuid), Y === 0 && (a[R.uuid] = x.uuid);
730
+ const L = ue(x.conditions);
731
+ L && (x.conditions = L, ne(
731
732
  u,
732
- A.uuid,
733
- A.properties.validation
733
+ x.uuid,
734
+ L,
735
+ "component"
736
+ )), (se = x.properties) != null && se.validation && le(
737
+ d,
738
+ x.uuid,
739
+ x.properties.validation
734
740
  );
735
- const se = F(A);
736
- return A.valid = se.length === 0, se.length > 0 && (p[A.uuid] = se), A;
741
+ const re = M(x);
742
+ return x.valid = re.length === 0, re.length > 0 && (f[x.uuid] = re), x;
737
743
  });
738
- $.addedComponents.push(ee);
744
+ A.addedComponents.push(K);
739
745
  }
740
746
  }
741
747
  });
742
- }), t && t.screens.forEach((x) => {
743
- const M = i.indexOf(x.uuid);
744
- M < 0 || x.components.forEach((U) => {
745
- const S = a[U.uuid];
746
- if (S)
747
- if ((S.type === "group" || S.type === "repeater") && U.components && S.addedComponents) {
748
- if (U.components.length > 1) {
749
- const D = S.addedComponents.length, B = U.components.length - D, G = o.screens[M].components.find(
750
- (V) => V.uuid === S.uuid
748
+ }), t && t.screens.forEach((E) => {
749
+ const T = c.indexOf(E.uuid);
750
+ T < 0 || E.components.forEach((_) => {
751
+ const N = i[_.uuid];
752
+ if (N)
753
+ if ((N.type === "group" || N.type === "repeater") && _.components && N.addedComponents) {
754
+ if (_.components.length > 1) {
755
+ const I = N.addedComponents.length, k = _.components.length - I, W = o.screens[T].components.find(
756
+ (U) => U.uuid === N.uuid
751
757
  );
752
- for (let V = 0; V < B; V++)
753
- if (G != null && G.components) {
754
- const $ = G.components.map(
755
- (J, R) => {
756
- var ee;
757
- const E = Y(J);
758
- E.uuid = [
759
- S.uuid,
760
- S.addedComponents.length,
761
- R
762
- ].join(":"), S.type === "group" && (c[E.uuid] = J.uuid), d[J.uuid] || (d[J.uuid] = E.uuid);
763
- const _ = le(
764
- E.conditions
758
+ for (let U = 0; U < k; U++)
759
+ if (W != null && W.components) {
760
+ const A = W.components.map(
761
+ (q, j) => {
762
+ var K;
763
+ const O = X(q);
764
+ O.uuid = [
765
+ N.uuid,
766
+ N.addedComponents.length,
767
+ j
768
+ ].join(":"), N.type === "group" && (l[O.uuid] = q.uuid), a[q.uuid] || (a[q.uuid] = O.uuid);
769
+ const $ = ue(
770
+ O.conditions
765
771
  );
766
- _ && (E.conditions = _, X(
767
- l,
768
- E.uuid,
769
- _,
770
- "component"
771
- )), (ee = E.properties) != null && ee.validation && ae(
772
+ $ && (O.conditions = $, ne(
772
773
  u,
773
- E.uuid,
774
- E.properties.validation
774
+ O.uuid,
775
+ $,
776
+ "component"
777
+ )), (K = O.properties) != null && K.validation && le(
778
+ d,
779
+ O.uuid,
780
+ O.properties.validation
775
781
  );
776
- const O = F(E);
777
- return E.valid = O.length === 0, O.length > 0 && (p[E.uuid] = O), E;
782
+ const Y = M(O);
783
+ return O.valid = Y.length === 0, Y.length > 0 && (f[O.uuid] = Y), O;
778
784
  }
779
785
  );
780
- S.addedComponents.push($);
786
+ N.addedComponents.push(A);
781
787
  }
782
788
  }
783
- U.components.forEach((D) => {
784
- D.forEach((B) => {
785
- for (const G of S.addedComponents) {
786
- const V = G.find(($) => $.uuid === B.uuid);
787
- if (V) {
788
- V.value = B.value;
789
- const $ = F(V);
790
- V.valid = $.length === 0, p[V.uuid] = $;
789
+ _.components.forEach((I) => {
790
+ I.forEach((k) => {
791
+ for (const W of N.addedComponents) {
792
+ const U = W.find((A) => A.uuid === k.uuid);
793
+ if (U) {
794
+ U.value = k.value;
795
+ const A = M(U);
796
+ U.valid = A.length === 0, f[U.uuid] = A;
791
797
  break;
792
798
  }
793
799
  }
794
800
  });
795
801
  });
796
802
  } else {
797
- S.value = U.value;
798
- const D = F(S);
799
- S.valid = D.length === 0, p[S.uuid] = D;
803
+ N.value = _.value;
804
+ const I = M(N);
805
+ N.valid = I.length === 0, f[N.uuid] = I;
800
806
  }
801
807
  });
802
808
  });
803
- for (const x of Object.keys(a)) {
804
- const M = a[x];
805
- if (!(M.type === "group" || M.type === "repeater" || !((T = M.properties) != null && T.validation)) && !(x in p)) {
806
- const U = F(M);
807
- M.valid = U.length === 0, U.length > 0 && (p[x] = U);
809
+ for (const E of Object.keys(i)) {
810
+ const T = i[E];
811
+ if (!(T.type === "group" || T.type === "repeater" || !((V = T.properties) != null && V.validation)) && !(E in f)) {
812
+ const _ = M(T);
813
+ T.valid = _.length === 0, _.length > 0 && (f[E] = _);
808
814
  }
809
815
  }
810
816
  const y = {
811
817
  ...r(),
812
- externalContext: n ?? {},
818
+ externalContext: e ?? {},
813
819
  screens: s,
814
- screenOrder: i,
815
- components: a,
816
- groupComponentMap: c,
817
- templateComponentMap: d,
818
- conditionsByDependency: l,
820
+ screenOrder: c,
821
+ components: i,
822
+ groupComponentMap: l,
823
+ templateComponentMap: a,
824
+ conditionsByDependency: u,
819
825
  conditionResults: {},
820
- validationErrors: p,
821
- validationsByDependency: u
822
- }, g = bn(y);
823
- y.conditionResults = g, i.forEach((x) => {
824
- f[x] = Z(y, x);
826
+ validationErrors: f,
827
+ validationsByDependency: d
828
+ }, g = Bn(y);
829
+ y.conditionResults = g, c.forEach((E) => {
830
+ p[E] = oe(y, E);
825
831
  });
826
- const h = fn(a), v = {
832
+ const v = Rn(i), h = {
827
833
  ...y,
828
- computedByDependency: h,
834
+ computedByDependency: v,
829
835
  calculationResults: {},
830
- screenValidity: f
836
+ screenValidity: p
831
837
  };
832
- Re(v);
833
- const b = o.calculations ?? [], w = pn(b), C = {
834
- ...v,
838
+ xe(h);
839
+ const b = o.calculations ?? [], C = Nn(b), S = {
840
+ ...h,
835
841
  calculations: b
836
- }, N = Se(C);
837
- e({
842
+ }, w = Ee(S);
843
+ n({
838
844
  flowUUID: o.uuid,
839
845
  metadata: o.metadata,
840
846
  config: o.config ?? {},
841
- externalContext: n ?? {},
847
+ externalContext: e ?? {},
842
848
  screens: s,
843
- screenOrder: i,
844
- components: a,
845
- groupComponentMap: c,
846
- templateComponentMap: d,
847
- conditionsByDependency: l,
849
+ screenOrder: c,
850
+ components: i,
851
+ groupComponentMap: l,
852
+ templateComponentMap: a,
853
+ conditionsByDependency: u,
848
854
  conditionResults: g,
849
- screenValidity: f,
850
- validationErrors: p,
851
- validationsByDependency: u,
855
+ screenValidity: p,
856
+ validationErrors: f,
857
+ validationsByDependency: d,
852
858
  calculations: b,
853
- calculationResults: N,
854
- calculationsByDependency: w,
855
- computedByDependency: h
859
+ calculationResults: w,
860
+ calculationsByDependency: C,
861
+ computedByDependency: v
856
862
  });
857
863
  },
858
864
  updateContext: (o) => {
859
- const t = r(), n = t.externalContext, s = [];
860
- for (const d of Object.keys(o))
861
- n[d] !== o[d] && s.push(d);
862
- for (const d of Object.keys(n))
863
- !(d in o) && !s.includes(d) && s.push(d);
865
+ const t = r(), e = t.externalContext, s = [];
866
+ for (const a of Object.keys(o))
867
+ e[a] !== o[a] && s.push(a);
868
+ for (const a of Object.keys(e))
869
+ !(a in o) && !s.includes(a) && s.push(a);
864
870
  if (s.length === 0) return;
865
- const i = { ...t.conditionResults };
866
- let a = !1;
867
- const c = /* @__PURE__ */ new Set();
868
- for (const d of s) {
869
- const l = t.conditionsByDependency[d];
870
- if (!(!l || l.length === 0))
871
- for (const u of l) {
872
- if (c.has(u.target)) continue;
873
- c.add(u.target);
874
- const p = { ...t, externalContext: o }, f = te(p, u.config);
875
- i[u.target] !== f && (i[u.target] = f, a = !0);
871
+ const c = { ...t.conditionResults };
872
+ let i = !1;
873
+ const l = /* @__PURE__ */ new Set();
874
+ for (const a of s) {
875
+ const u = t.conditionsByDependency[a];
876
+ if (!(!u || u.length === 0))
877
+ for (const d of u) {
878
+ if (l.has(d.target)) continue;
879
+ l.add(d.target);
880
+ const f = { ...t, externalContext: o }, p = ce(f, d.config);
881
+ c[d.target] !== p && (c[d.target] = p, i = !0);
876
882
  }
877
883
  }
878
- if (a) {
879
- const d = { ...t, conditionResults: i }, l = {};
880
- for (const u of t.screenOrder)
881
- l[u] = Z(d, u);
882
- e({ externalContext: o, conditionResults: i, screenValidity: l });
884
+ if (i) {
885
+ const a = { ...t, conditionResults: c }, u = {};
886
+ for (const d of t.screenOrder)
887
+ u[d] = oe(a, d);
888
+ n({ externalContext: o, conditionResults: c, screenValidity: u });
883
889
  } else
884
- e({ externalContext: o });
890
+ n({ externalContext: o });
885
891
  },
886
- ...hn(e, r),
887
- getFlowData: () => Cn(r()),
892
+ ...Dn(n, r),
893
+ getFlowData: () => On(r()),
888
894
  getScreenByIndex: (o) => {
889
895
  const t = r();
890
896
  return o < 0 || o >= t.screenOrder.length ? null : t.screens[t.screenOrder[o]];
@@ -893,39 +899,39 @@ const Ke = () => {
893
899
  const t = r();
894
900
  return o < 0 || o >= t.screenOrder.length ? !0 : t.screenValidity[t.screenOrder[o]] ?? !0;
895
901
  },
896
- getValidationErrors: (o) => r().validationErrors[o] ?? wn,
902
+ getValidationErrors: (o) => r().validationErrors[o] ?? Vn,
897
903
  evaluateFlowValidation: () => {
898
904
  const o = r(), t = {};
899
- let n = !0;
905
+ let e = !0;
900
906
  return o.screenOrder.forEach((s) => {
901
- const i = Z(o, s);
902
- t[s] = i, i || (n = !1);
903
- }), e({ screenValidity: t }), n;
907
+ const c = oe(o, s);
908
+ t[s] = c, c || (e = !1);
909
+ }), n({ screenValidity: t }), e;
904
910
  },
905
911
  getMaxScreenCount: () => r().screenOrder.length - 1,
906
912
  getCalculationResult: (o) => r().calculationResults[o] ?? null
907
- })), Rn = ({ uuid: e }) => {
908
- var a;
909
- const r = L((c) => c.components[e]), o = L((c) => c.conditionResults[e]);
913
+ })), _n = ({ uuid: n }) => {
914
+ var i;
915
+ const r = P((l) => l.components[n]), o = P((l) => l.conditionResults[n]);
910
916
  if (!r) return null;
911
917
  const t = r.conditions && "when" in r.conditions ? r.conditions : void 0;
912
- if (Q(t, o)) return null;
913
- const n = an(r.type);
914
- if (!n)
918
+ if (te(t, o)) return null;
919
+ const e = bn(r.type);
920
+ if (!e)
915
921
  return console.warn(`FBRE: No renderer for component type "${r.type}"`), null;
916
- const s = (a = r.properties) == null ? void 0 : a.width, i = s && s !== "full" ? `fbre-component fbre-width-${s}` : "fbre-component";
917
- return /* @__PURE__ */ m("div", { className: i, "data-uuid": e, children: /* @__PURE__ */ m(n, { uuid: e }) });
918
- }, Ne = ({ screenIndex: e }) => {
919
- const r = L((o) => {
920
- const t = o.screenOrder[e];
922
+ const s = (i = r.properties) == null ? void 0 : i.width, c = s && s !== "full" ? `fbre-component fbre-width-${s}` : "fbre-component";
923
+ return /* @__PURE__ */ m("div", { className: c, "data-uuid": n, children: /* @__PURE__ */ m(e, { uuid: n }) });
924
+ }, De = ({ screenIndex: n }) => {
925
+ const r = P((o) => {
926
+ const t = o.screenOrder[n];
921
927
  return t ? o.screens[t] : null;
922
928
  });
923
- return r ? /* @__PURE__ */ m("div", { className: "fbre-screen", children: r.components.map((o) => /* @__PURE__ */ m(Rn, { uuid: o.uuid }, o.uuid)) }) : null;
924
- }, Le = ({ size: e = 14 }) => /* @__PURE__ */ m(
929
+ return r ? /* @__PURE__ */ m("div", { className: "fbre-screen", children: r.components.map((o) => /* @__PURE__ */ m(_n, { uuid: o.uuid }, o.uuid)) }) : null;
930
+ }, Je = ({ size: n = 14 }) => /* @__PURE__ */ m(
925
931
  "svg",
926
932
  {
927
- width: e,
928
- height: e,
933
+ width: n,
934
+ height: n,
929
935
  viewBox: "0 0 24 24",
930
936
  fill: "none",
931
937
  stroke: "currentColor",
@@ -934,109 +940,126 @@ const Ke = () => {
934
940
  strokeLinejoin: "round",
935
941
  children: /* @__PURE__ */ m("polyline", { points: "4,12 9.5,17.5 20,7" })
936
942
  }
937
- ), Nn = ({ size: e = 12 }) => /* @__PURE__ */ m("svg", { width: e, height: e, viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ m("path", { d: "M7 10l5 5 5-5z" }) }), xn = ({ size: e = 16 }) => /* @__PURE__ */ m("svg", { width: e, height: e, viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ m("path", { d: "M15.41 7.41L14 6l-6 6 6 6 1.41-1.41L10.83 12z" }) }), En = ({ size: e = 16 }) => /* @__PURE__ */ m("svg", { width: e, height: e, viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ m("path", { d: "M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z" }) }), $e = ({
938
- position: e,
943
+ ), Mn = ({ size: n = 12 }) => /* @__PURE__ */ m("svg", { width: n, height: n, viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ m("path", { d: "M7 10l5 5 5-5z" }) }), Un = ({ size: n = 16 }) => /* @__PURE__ */ m("svg", { width: n, height: n, viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ m("path", { d: "M15.41 7.41L14 6l-6 6 6 6 1.41-1.41L10.83 12z" }) }), An = ({ size: n = 16 }) => /* @__PURE__ */ m("svg", { width: n, height: n, viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ m("path", { d: "M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z" }) }), ze = ({
944
+ position: n,
939
945
  screenIndex: r,
940
946
  maxScreenIndex: o,
941
947
  allowInvalidTransition: t,
942
- screenValidity: n,
948
+ screenValidity: e,
943
949
  summaryEnabled: s,
944
- summaryActive: i,
945
- atMaxScreen: a,
946
- nextButtonLabel: c,
947
- backButtonLabel: d,
948
- completionLoading: l,
949
- nextScreen: u,
950
- prevScreen: p,
951
- onFlowComplete: f
950
+ summaryActive: c,
951
+ atMaxScreen: i,
952
+ nextButtonLabel: l,
953
+ backButtonLabel: a,
954
+ completionLoading: u,
955
+ nextScreen: d,
956
+ prevScreen: f,
957
+ onFlowComplete: p
952
958
  }) => {
953
- const y = l ?? !1;
954
- if (e === "back")
955
- return /* @__PURE__ */ k(
959
+ const y = u ?? !1;
960
+ if (n === "back")
961
+ return /* @__PURE__ */ B(
956
962
  "button",
957
963
  {
958
964
  type: "button",
959
965
  className: "fbre-btn fbre-btn--secondary",
960
- disabled: r === 0 && !i || y,
961
- onClick: p,
966
+ disabled: r === 0 && !c || y,
967
+ onClick: f,
962
968
  children: [
963
- /* @__PURE__ */ m(xn, {}),
964
- d || "Back"
969
+ /* @__PURE__ */ m(Un, {}),
970
+ a || "Back"
965
971
  ]
966
972
  }
967
973
  );
968
- const g = s ? a && i : a, h = s ? a ? i ? "Done" : "Review" : "Next" : a ? "Done" : "Next";
969
- return o === 0 ? /* @__PURE__ */ k(
974
+ const g = s ? i && c : i, v = s ? i ? c ? "Done" : "Review" : "Next" : i ? "Done" : "Next";
975
+ return o === 0 ? /* @__PURE__ */ B(
970
976
  "button",
971
977
  {
972
978
  type: "button",
973
979
  className: "fbre-btn fbre-btn--primary",
974
- disabled: y || !n,
980
+ disabled: y || !e,
975
981
  onClick: () => {
976
- s && !i ? u() : f();
982
+ s && !c ? d() : p();
977
983
  },
978
984
  children: [
979
- c || (s ? i ? "Complete" : "Review" : "Complete"),
980
- y ? /* @__PURE__ */ m("span", { className: "fbre-btn__spinner" }) : /* @__PURE__ */ m(Le, { size: 16 })
985
+ l || (s ? c ? "Complete" : "Review" : "Complete"),
986
+ y ? /* @__PURE__ */ m("span", { className: "fbre-btn__spinner" }) : /* @__PURE__ */ m(Je, { size: 16 })
981
987
  ]
982
988
  }
983
- ) : /* @__PURE__ */ k(
989
+ ) : /* @__PURE__ */ B(
984
990
  "button",
985
991
  {
986
992
  type: "button",
987
993
  className: "fbre-btn fbre-btn--primary",
988
- disabled: y || !t && !n || h === "Done" && !n,
994
+ disabled: y || !t && !e || v === "Done" && !e,
989
995
  onClick: () => {
990
- g ? f() : u();
996
+ g ? p() : d();
991
997
  },
992
998
  children: [
993
- c || h,
994
- y ? /* @__PURE__ */ m("span", { className: "fbre-btn__spinner" }) : g ? /* @__PURE__ */ m(Le, { size: 16 }) : /* @__PURE__ */ m(En, {})
999
+ l || v,
1000
+ y ? /* @__PURE__ */ m("span", { className: "fbre-btn__spinner" }) : g ? /* @__PURE__ */ m(Je, { size: 16 }) : /* @__PURE__ */ m(An, {})
995
1001
  ]
996
1002
  }
997
1003
  );
998
- }, In = ({ current: e, total: r }) => {
1004
+ }, Fn = ({ current: n, total: r, stepperStyle: o }) => {
999
1005
  if (r <= 1) return null;
1000
- const o = (e + 1) / r * 100;
1001
- return r <= 6 ? /* @__PURE__ */ m("div", { className: "fbre-stepper fbre-stepper--dots", children: Array.from({ length: r }, (t, n) => /* @__PURE__ */ m(
1002
- "div",
1003
- {
1004
- className: `fbre-stepper__dot${n === e ? " active" : n < e ? " completed" : ""}`
1005
- },
1006
- n
1007
- )) }) : /* @__PURE__ */ m("div", { className: "fbre-stepper fbre-stepper--bar", children: /* @__PURE__ */ m(
1008
- "div",
1009
- {
1010
- className: "fbre-stepper__fill",
1011
- style: { width: `${o}%` }
1012
- }
1013
- ) });
1014
- }, Dn = ({ current: e, total: r }) => r <= 1 ? null : /* @__PURE__ */ k("div", { className: "fbre-stepper-text", children: [
1006
+ const t = r > 1 ? n / (r - 1) * 100 : 100, s = !!o && o !== "default" || r <= 6;
1007
+ return /* @__PURE__ */ B(fn, { children: [
1008
+ s && /* @__PURE__ */ m("div", { className: "fbre-stepper fbre-stepper--dots", children: Array.from({ length: r }, (c, i) => /* @__PURE__ */ m(
1009
+ "div",
1010
+ {
1011
+ className: `fbre-stepper__dot${i === n ? " active" : i < n ? " completed" : ""}`
1012
+ },
1013
+ i
1014
+ )) }),
1015
+ s && /* @__PURE__ */ B("div", { className: "fbre-stepper fbre-stepper--bar-alt", children: [
1016
+ /* @__PURE__ */ m("div", { className: "fbre-stepper__track", children: /* @__PURE__ */ m(
1017
+ "div",
1018
+ {
1019
+ className: "fbre-stepper__fill",
1020
+ style: { width: `${t}%` }
1021
+ }
1022
+ ) }),
1023
+ /* @__PURE__ */ B("span", { className: "fbre-stepper__counter", children: [
1024
+ n + 1,
1025
+ " of ",
1026
+ r
1027
+ ] })
1028
+ ] }),
1029
+ !s && /* @__PURE__ */ m("div", { className: "fbre-stepper fbre-stepper--bar", children: /* @__PURE__ */ m(
1030
+ "div",
1031
+ {
1032
+ className: "fbre-stepper__fill",
1033
+ style: { width: `${t}%` }
1034
+ }
1035
+ ) })
1036
+ ] });
1037
+ }, jn = ({ current: n, total: r }) => r <= 1 ? null : /* @__PURE__ */ B("div", { className: "fbre-stepper-text", children: [
1015
1038
  "Step ",
1016
- e + 1,
1039
+ n + 1,
1017
1040
  " of ",
1018
1041
  r
1019
- ] }), Bn = (e) => {
1020
- const r = e.controlsLayout === "stacked", o = e.showStepper !== !1 && (e.stepperStyle ?? "default") === "default";
1021
- return /* @__PURE__ */ k(
1042
+ ] }), Ln = (n) => {
1043
+ const r = n.controlsLayout === "stacked", o = n.showStepper !== !1 && (n.stepperStyle ?? "default") !== "text";
1044
+ return /* @__PURE__ */ B(
1022
1045
  "div",
1023
1046
  {
1024
1047
  className: r ? "fbre-controls fbre-controls--stacked" : "fbre-controls",
1025
1048
  children: [
1026
- e.screenIndex > 0 || e.summaryActive ? /* @__PURE__ */ m($e, { position: "back", ...e }) : /* @__PURE__ */ m("div", {}),
1027
- o && e.maxScreenIndex > 0 && /* @__PURE__ */ m(In, { current: e.screenIndex, total: e.maxScreenIndex + 1 }),
1028
- /* @__PURE__ */ m($e, { position: "next", ...e })
1049
+ n.screenIndex > 0 || n.summaryActive ? /* @__PURE__ */ m(ze, { position: "back", ...n }) : /* @__PURE__ */ m("div", {}),
1050
+ o && n.maxScreenIndex > 0 ? /* @__PURE__ */ m(Fn, { current: n.screenIndex, total: n.maxScreenIndex + 1, stepperStyle: n.stepperStyle }) : /* @__PURE__ */ m("div", {}),
1051
+ /* @__PURE__ */ m(ze, { position: "next", ...n })
1029
1052
  ]
1030
1053
  }
1031
1054
  );
1032
- }, Qe = ({
1033
- component: e
1055
+ }, on = ({
1056
+ component: n
1034
1057
  }) => {
1035
- const { uuid: r, label: o, type: t, value: n, components: s } = e, i = () => {
1036
- if (n != null)
1058
+ const { uuid: r, label: o, type: t, value: e, components: s } = n, c = () => {
1059
+ if (e != null)
1037
1060
  switch (t) {
1038
1061
  case "fileUpload":
1039
- return n.name;
1062
+ return e.name;
1040
1063
  case "inputText":
1041
1064
  case "inputTextArea":
1042
1065
  case "inputNumber":
@@ -1044,33 +1067,33 @@ const Ke = () => {
1044
1067
  case "radio":
1045
1068
  case "rating":
1046
1069
  case "slider":
1047
- return n.toString();
1070
+ return e.toString();
1048
1071
  case "computed":
1049
- return typeof n == "number" ? n.toString() : "—";
1072
+ return typeof e == "number" ? e.toString() : "—";
1050
1073
  case "toggleSwitch":
1051
- return n ? "Yes" : "No";
1074
+ return e ? "Yes" : "No";
1052
1075
  case "checkbox":
1053
1076
  case "dropDownMulti":
1054
- return n.length === 0 ? "No options selected" : n.join(", ");
1077
+ return e.length === 0 ? "No options selected" : e.join(", ");
1055
1078
  }
1056
1079
  return "No response given";
1057
1080
  };
1058
- if (t === "signature" && n) {
1059
- const d = typeof n == "string" && n.startsWith("data:");
1060
- return /* @__PURE__ */ k("div", { className: "fbre-summary__item", children: [
1081
+ if (t === "signature" && e) {
1082
+ const a = typeof e == "string" && e.startsWith("data:");
1083
+ return /* @__PURE__ */ B("div", { className: "fbre-summary__item", children: [
1061
1084
  /* @__PURE__ */ m("div", { className: "fbre-summary__item-label", children: o }),
1062
- /* @__PURE__ */ m("div", { className: "fbre-summary__item-value", children: d ? /* @__PURE__ */ m(
1085
+ /* @__PURE__ */ m("div", { className: "fbre-summary__item-value", children: a ? /* @__PURE__ */ m(
1063
1086
  "img",
1064
1087
  {
1065
- src: n,
1088
+ src: e,
1066
1089
  alt: "Signature",
1067
1090
  style: { maxWidth: "100%", maxHeight: 80 }
1068
1091
  }
1069
- ) : /* @__PURE__ */ m("span", { style: { fontFamily: '"Brush Script MT", "Segoe Script", "Dancing Script", cursive', fontSize: 24 }, children: n }) })
1092
+ ) : /* @__PURE__ */ m("span", { style: { fontFamily: '"Brush Script MT", "Segoe Script", "Dancing Script", cursive', fontSize: 24 }, children: e }) })
1070
1093
  ] });
1071
1094
  }
1072
- const a = () => s ? s.map((d, l) => /* @__PURE__ */ m("div", { children: d.map((u) => /* @__PURE__ */ m(Qe, { component: u }, u.uuid)) }, `${r}-${l}`)) : null, c = n == null || typeof n == "string" && n.length === 0 || Array.isArray(n) && n.length === 0;
1073
- return /* @__PURE__ */ k(
1095
+ const i = () => s ? s.map((a, u) => /* @__PURE__ */ m("div", { children: a.map((d) => /* @__PURE__ */ m(on, { component: d }, d.uuid)) }, `${r}-${u}`)) : null, l = e == null || typeof e == "string" && e.length === 0 || Array.isArray(e) && e.length === 0;
1096
+ return /* @__PURE__ */ B(
1074
1097
  "div",
1075
1098
  {
1076
1099
  className: `fbre-summary__item${t === "group" || t === "repeater" ? " fbre-summary__item--group" : ""}`,
@@ -1079,68 +1102,68 @@ const Ke = () => {
1079
1102
  t !== "group" && t !== "repeater" && /* @__PURE__ */ m(
1080
1103
  "div",
1081
1104
  {
1082
- className: `fbre-summary__item-value${c ? " fbre-summary__item-value--empty" : ""}`,
1083
- children: i()
1105
+ className: `fbre-summary__item-value${l ? " fbre-summary__item-value--empty" : ""}`,
1106
+ children: c()
1084
1107
  }
1085
1108
  ),
1086
- (t === "group" || t === "repeater") && a()
1109
+ (t === "group" || t === "repeater") && i()
1087
1110
  ]
1088
1111
  }
1089
1112
  );
1090
- }, Vn = /\$\{([^}]+)\}/g, On = (e, r) => e.replace(Vn, (o, t) => {
1091
- const n = r.resolveCalculation(t);
1092
- if (n !== null) return n;
1113
+ }, Pn = /\$\{([^}]+)\}/g, $n = (n, r) => n.replace(Pn, (o, t) => {
1114
+ const e = r.resolveCalculation(t);
1115
+ if (e !== null) return e;
1093
1116
  const s = r.resolveComponentValue(t);
1094
1117
  return s !== null ? s : "";
1095
1118
  });
1096
- function kn() {
1097
- const e = L((n) => n.components), r = L((n) => n.templateComponentMap), o = L((n) => n.calculations), t = L((n) => n.calculationResults);
1098
- return Ee(() => {
1099
- const n = new Map(o.map((i) => [i.uuid, i])), s = (i) => {
1100
- var u, p;
1101
- const a = e[i];
1102
- if (a) return a;
1103
- const c = r[i];
1104
- if (!c) return;
1105
- const d = c.split(":"), l = e[d[0]];
1106
- return (p = (u = l == null ? void 0 : l.addedComponents) == null ? void 0 : u[parseInt(d[1])]) == null ? void 0 : p[parseInt(d[2])];
1119
+ function Yn() {
1120
+ const n = P((e) => e.components), r = P((e) => e.templateComponentMap), o = P((e) => e.calculations), t = P((e) => e.calculationResults);
1121
+ return ke(() => {
1122
+ const e = new Map(o.map((c) => [c.uuid, c])), s = (c) => {
1123
+ var d, f;
1124
+ const i = n[c];
1125
+ if (i) return i;
1126
+ const l = r[c];
1127
+ if (!l) return;
1128
+ const a = l.split(":"), u = n[a[0]];
1129
+ return (f = (d = u == null ? void 0 : u.addedComponents) == null ? void 0 : d[parseInt(a[1])]) == null ? void 0 : f[parseInt(a[2])];
1107
1130
  };
1108
1131
  return {
1109
- resolveComponentValue: (i) => {
1110
- const a = s(i);
1111
- if (!a) return null;
1112
- const c = a.value;
1113
- return c == null || c === "" ? null : Array.isArray(c) ? c.join(", ") : String(c);
1132
+ resolveComponentValue: (c) => {
1133
+ const i = s(c);
1134
+ if (!i) return null;
1135
+ const l = i.value;
1136
+ return l == null || l === "" ? null : Array.isArray(l) ? l.join(", ") : String(l);
1114
1137
  },
1115
- resolveCalculation: (i) => {
1116
- const a = n.get(i);
1117
- if (!a) return null;
1118
- const c = t[i] ?? null;
1119
- return sn(
1120
- c,
1121
- a.format,
1122
- a.decimalPlaces,
1123
- a.currencySymbol
1138
+ resolveCalculation: (c) => {
1139
+ const i = e.get(c);
1140
+ if (!i) return null;
1141
+ const l = t[c] ?? null;
1142
+ return yn(
1143
+ l,
1144
+ i.format,
1145
+ i.decimalPlaces,
1146
+ i.currencySymbol
1124
1147
  );
1125
1148
  }
1126
1149
  };
1127
- }, [e, r, o, t]);
1150
+ }, [n, r, o, t]);
1128
1151
  }
1129
- const Mn = ({ screen: e, showToggle: r }) => {
1130
- const o = kn(), [t, n] = P(!0);
1131
- return /* @__PURE__ */ k("div", { children: [
1132
- /* @__PURE__ */ k(
1152
+ const Gn = ({ screen: n, showToggle: r }) => {
1153
+ const o = Yn(), [t, e] = J(!0);
1154
+ return /* @__PURE__ */ B("div", { children: [
1155
+ /* @__PURE__ */ B(
1133
1156
  "div",
1134
1157
  {
1135
1158
  className: "fbre-summary__screen-header",
1136
- onClick: () => r && n(!t),
1159
+ onClick: () => r && e(!t),
1137
1160
  children: [
1138
- e.label && /* @__PURE__ */ m("span", { className: "fbre-summary__screen-label", children: On(e.label, o) }),
1161
+ n.label && /* @__PURE__ */ m("span", { className: "fbre-summary__screen-label", children: $n(n.label, o) }),
1139
1162
  r && /* @__PURE__ */ m(
1140
1163
  "span",
1141
1164
  {
1142
1165
  className: `fbre-summary__screen-toggle${t ? "" : " collapsed"}`,
1143
- children: /* @__PURE__ */ m(Nn, { size: 20 })
1166
+ children: /* @__PURE__ */ m(Mn, { size: 20 })
1144
1167
  }
1145
1168
  )
1146
1169
  ]
@@ -1150,134 +1173,221 @@ const Mn = ({ screen: e, showToggle: r }) => {
1150
1173
  "div",
1151
1174
  {
1152
1175
  className: `fbre-summary__screen-body${t ? "" : " collapsed"}`,
1153
- children: e.components.map((s) => /* @__PURE__ */ m(Qe, { component: s }, s.uuid))
1176
+ children: n.components.map((s) => /* @__PURE__ */ m(on, { component: s }, s.uuid))
1154
1177
  }
1155
1178
  )
1156
1179
  ] });
1157
- }, Pe = () => {
1158
- const e = Ke(), r = L((n) => n.components), o = Ee(
1159
- () => e.getState().getFlowData(),
1160
- [e, r]
1180
+ }, qe = () => {
1181
+ const n = Ce(), r = P((e) => e.components), o = ke(
1182
+ () => n.getState().getFlowData(),
1183
+ [n, r]
1161
1184
  ), t = o.screens.length;
1162
- return /* @__PURE__ */ k("div", { className: "fbre-summary", children: [
1185
+ return /* @__PURE__ */ B("div", { className: "fbre-summary", children: [
1163
1186
  /* @__PURE__ */ m("h2", { className: "fbre-summary__title", children: "Review" }),
1164
- /* @__PURE__ */ m("div", { className: "fbre-summary__body", children: o.screens.map((n) => /* @__PURE__ */ m(
1165
- Mn,
1187
+ /* @__PURE__ */ m("div", { className: "fbre-summary__body", children: o.screens.map((e) => /* @__PURE__ */ m(
1188
+ Gn,
1166
1189
  {
1167
- screen: n,
1190
+ screen: e,
1168
1191
  showToggle: t > 1
1169
1192
  },
1170
- n.uuid
1193
+ e.uuid
1171
1194
  )) })
1172
1195
  ] });
1173
- }, Ze = (e, r, o) => r ? !Q(r, o[e]) : !0, Ge = (e, r) => {
1174
- const o = e.screenOrder.length - 1;
1196
+ }, rn = (n, r, o) => r ? !te(r, o[n]) : !0, ye = (n, r) => {
1197
+ const o = n.screenOrder.length - 1;
1175
1198
  let t = r + 1;
1176
1199
  for (; t <= o; ) {
1177
- const n = e.screenOrder[t], s = e.screens[n], i = s != null && s.conditions && "when" in s.conditions ? s.conditions : void 0;
1178
- if (Ze(n, i, e.conditionResults)) return t;
1200
+ const e = n.screenOrder[t], s = n.screens[e], c = s != null && s.conditions && "when" in s.conditions ? s.conditions : void 0;
1201
+ if (rn(e, c, n.conditionResults)) return t;
1179
1202
  t++;
1180
1203
  }
1181
1204
  return null;
1182
- }, _n = (e, r) => {
1205
+ }, Jn = (n, r) => {
1183
1206
  let o = r - 1;
1184
1207
  for (; o >= 0; ) {
1185
- const t = e.screenOrder[o], n = e.screens[t], s = n != null && n.conditions && "when" in n.conditions ? n.conditions : void 0;
1186
- if (Ze(t, s, e.conditionResults)) return o;
1208
+ const t = n.screenOrder[o], e = n.screens[t], s = e != null && e.conditions && "when" in e.conditions ? e.conditions : void 0;
1209
+ if (rn(t, s, n.conditionResults)) return o;
1187
1210
  o--;
1188
1211
  }
1189
1212
  return 0;
1190
- }, fe = /* @__PURE__ */ new Map(), rt = (e, r) => {
1191
- fe.has(e) || fe.set(e, /* @__PURE__ */ new Set()), fe.get(e).add(r);
1192
- }, st = (e, r) => {
1213
+ }, Oe = /* @__PURE__ */ new Set([
1214
+ "radio",
1215
+ "yesNo",
1216
+ "cardSelect",
1217
+ "dropDown"
1218
+ ]), zn = 500;
1219
+ function sn(n, r, o) {
1220
+ const t = Ce(), e = Z(null), s = Z(""), c = Z(0);
1221
+ H(() => {
1222
+ if (!n) return;
1223
+ const i = t.getState(), l = He(i, r);
1224
+ l && (s.current = We(i.components, l)), c.current = i.selectionTick;
1225
+ }, [n, r, t]), H(() => {
1226
+ if (!n) return;
1227
+ const i = t.subscribe((l) => {
1228
+ const a = He(l, r);
1229
+ if (!a) return;
1230
+ const u = l.selectionTick, d = u !== c.current;
1231
+ d && (c.current = u);
1232
+ const f = We(l.components, a);
1233
+ if (f === s.current && !d) return;
1234
+ const p = s.current;
1235
+ if (s.current = f, !(f !== p ? qn(l.components, a, p) : d && Hn(l.components, a)) || ye(l, r) === null) return;
1236
+ const v = l.screenOrder[r];
1237
+ v && l.screenValidity[v] === !1 || (e.current && clearTimeout(e.current), e.current = setTimeout(() => {
1238
+ e.current = null, o();
1239
+ }, zn));
1240
+ });
1241
+ return () => {
1242
+ i(), e.current && (clearTimeout(e.current), e.current = null);
1243
+ };
1244
+ }, [n, r, t, o]), H(() => () => {
1245
+ e.current && (clearTimeout(e.current), e.current = null);
1246
+ }, [r]);
1247
+ }
1248
+ function He(n, r) {
1249
+ const o = n.screenOrder[r];
1250
+ if (!o) return null;
1251
+ const t = n.screens[o];
1252
+ return t ? t.components.map((e) => e.uuid) : null;
1253
+ }
1254
+ function We(n, r) {
1255
+ const o = [];
1256
+ for (const t of r) {
1257
+ const e = n[t];
1258
+ !e || !Oe.has(e.type) || o.push(`${t}=${JSON.stringify(e.value ?? null)}`);
1259
+ }
1260
+ return o.join("|");
1261
+ }
1262
+ function qn(n, r, o) {
1263
+ const t = /* @__PURE__ */ new Map();
1264
+ for (const e of o.split("|")) {
1265
+ const s = e.indexOf("=");
1266
+ s > 0 && t.set(e.slice(0, s), e.slice(s + 1));
1267
+ }
1268
+ for (const e of r) {
1269
+ const s = n[e];
1270
+ if (!s || !Oe.has(s.type)) continue;
1271
+ const c = JSON.stringify(s.value ?? null), i = t.get(e) ?? "null";
1272
+ if (c !== i && c !== "null") return !0;
1273
+ }
1274
+ return !1;
1275
+ }
1276
+ function Hn(n, r) {
1277
+ for (const o of r) {
1278
+ const t = n[o];
1279
+ if (!(!t || !Oe.has(t.type)) && t.value !== null && t.value !== void 0)
1280
+ return !0;
1281
+ }
1282
+ return !1;
1283
+ }
1284
+ function cn(n, r, o) {
1285
+ const t = Ce();
1286
+ H(() => {
1287
+ if (!n) return;
1288
+ const e = (s) => {
1289
+ if (s.key !== "Enter") return;
1290
+ const c = s.target;
1291
+ if (c.tagName !== "INPUT" || !c.closest(".fbre-container")) return;
1292
+ const i = t.getState();
1293
+ if (ye(i, r) === null) return;
1294
+ const a = i.screenOrder[r];
1295
+ a && i.screenValidity[a] === !1 || (s.preventDefault(), o());
1296
+ };
1297
+ return document.addEventListener("keydown", e), () => document.removeEventListener("keydown", e);
1298
+ }, [n, r, o, t]);
1299
+ }
1300
+ const me = /* @__PURE__ */ new Map(), bt = (n, r) => {
1301
+ me.has(n) || me.set(n, /* @__PURE__ */ new Set()), me.get(n).add(r);
1302
+ }, Ct = (n, r) => {
1193
1303
  var o;
1194
- (o = fe.get(e)) == null || o.delete(r);
1195
- }, en = Je(null);
1196
- function it() {
1197
- return xe(en);
1304
+ (o = me.get(n)) == null || o.delete(r);
1305
+ }, an = Ke(null);
1306
+ function St() {
1307
+ return Ie(an);
1198
1308
  }
1199
- class he extends Error {
1200
- constructor(r, o, t, n) {
1201
- super(r), this.name = "ApiError", this.status = o, this.code = t, this.validationErrors = n;
1309
+ class ge extends Error {
1310
+ constructor(r, o, t, e) {
1311
+ super(r), this.name = "ApiError", this.status = o, this.code = t, this.validationErrors = e;
1202
1312
  }
1203
1313
  }
1204
- class Tn extends he {
1314
+ class Wn extends ge {
1205
1315
  constructor(r, o) {
1206
1316
  super(`Request timed out after ${o}ms: ${r}`, 0, "TIMEOUT"), this.name = "TimeoutError";
1207
1317
  }
1208
1318
  }
1209
- const Un = /* @__PURE__ */ new Set([502, 503, 504]), de = 2, Fn = [500, 1500];
1210
- function An(e) {
1211
- return new Promise((r) => setTimeout(r, e));
1319
+ const Xn = /* @__PURE__ */ new Set([502, 503, 504]), de = 2, Kn = [500, 1500];
1320
+ function Qn(n) {
1321
+ return new Promise((r) => setTimeout(r, n));
1212
1322
  }
1213
- async function oe(e, r, o = {}) {
1214
- const n = `${e.apiEndpoint || ""}${r}`, s = e.timeout ?? 3e4, i = {
1323
+ async function ae(n, r, o = {}) {
1324
+ const e = `${n.apiEndpoint || ""}${r}`, s = n.timeout ?? 3e4, c = {
1215
1325
  ...o.body ? { "Content-Type": "application/json" } : {},
1216
1326
  ...o.headers
1217
1327
  };
1218
- e.apiKey && (i.Authorization = `Bearer ${e.apiKey}`);
1219
- let a;
1220
- for (let c = 0; c <= de; c++) {
1221
- c > 0 && await An(Fn[c - 1]);
1328
+ n.apiKey && (c.Authorization = `Bearer ${n.apiKey}`);
1329
+ let i;
1330
+ for (let l = 0; l <= de; l++) {
1331
+ l > 0 && await Qn(Kn[l - 1]);
1222
1332
  try {
1223
- const d = new AbortController(), l = setTimeout(() => d.abort(), s);
1224
- let u;
1333
+ const a = new AbortController(), u = setTimeout(() => a.abort(), s);
1334
+ let d;
1225
1335
  try {
1226
- u = await fetch(n, {
1336
+ d = await fetch(e, {
1227
1337
  ...o,
1228
- headers: i,
1229
- signal: d.signal
1338
+ headers: c,
1339
+ signal: a.signal
1230
1340
  });
1231
1341
  } finally {
1232
- clearTimeout(l);
1342
+ clearTimeout(u);
1233
1343
  }
1234
- if (!u.ok) {
1235
- const p = await u.json().catch(() => ({})), f = new he(
1236
- p.error || `HTTP ${u.status}`,
1237
- u.status,
1238
- p.code,
1239
- p.validationErrors
1344
+ if (!d.ok) {
1345
+ const f = await d.json().catch(() => ({})), p = new ge(
1346
+ f.error || `HTTP ${d.status}`,
1347
+ d.status,
1348
+ f.code,
1349
+ f.validationErrors
1240
1350
  );
1241
- if (c < de && Un.has(u.status)) {
1242
- a = f;
1351
+ if (l < de && Xn.has(d.status)) {
1352
+ i = p;
1243
1353
  continue;
1244
1354
  }
1245
- throw f;
1355
+ throw p;
1246
1356
  }
1247
- return u.json();
1248
- } catch (d) {
1249
- if (d instanceof he)
1250
- throw d;
1251
- if (d instanceof DOMException && d.name === "AbortError") {
1252
- const l = new Tn(n, s);
1253
- if (c < de) {
1254
- a = l;
1357
+ return d.json();
1358
+ } catch (a) {
1359
+ if (a instanceof ge)
1360
+ throw a;
1361
+ if (a instanceof DOMException && a.name === "AbortError") {
1362
+ const u = new Wn(e, s);
1363
+ if (l < de) {
1364
+ i = u;
1255
1365
  continue;
1256
1366
  }
1257
- throw l;
1367
+ throw u;
1258
1368
  }
1259
- if (d instanceof TypeError && c < de) {
1260
- a = d;
1369
+ if (a instanceof TypeError && l < de) {
1370
+ i = a;
1261
1371
  continue;
1262
1372
  }
1263
- throw d;
1373
+ throw a;
1264
1374
  }
1265
1375
  }
1266
- throw a;
1376
+ throw i;
1267
1377
  }
1268
- async function jn(e, r) {
1269
- return oe(e, `/api/v1/public/flows/${r}`);
1378
+ async function Zn(n, r) {
1379
+ return ae(n, `/api/v1/public/flows/${r}`);
1270
1380
  }
1271
- async function Ln(e, r, o) {
1381
+ async function et(n, r, o) {
1272
1382
  const t = { flowId: r };
1273
- return o && Object.keys(o).length > 0 && (t.context = o), oe(e, "/api/v1/public/sessions", {
1383
+ return o && Object.keys(o).length > 0 && (t.context = o), ae(n, "/api/v1/public/sessions", {
1274
1384
  method: "POST",
1275
1385
  body: JSON.stringify(t)
1276
1386
  });
1277
1387
  }
1278
- async function $n(e, r, o) {
1279
- return oe(
1280
- e,
1388
+ async function nt(n, r, o) {
1389
+ return ae(
1390
+ n,
1281
1391
  `/api/v1/public/sessions/${r}/next`,
1282
1392
  {
1283
1393
  method: "POST",
@@ -1285,9 +1395,9 @@ async function $n(e, r, o) {
1285
1395
  }
1286
1396
  );
1287
1397
  }
1288
- async function Pn(e, r, o) {
1289
- return oe(
1290
- e,
1398
+ async function tt(n, r, o) {
1399
+ return ae(
1400
+ n,
1291
1401
  `/api/v1/public/sessions/${r}/prev`,
1292
1402
  {
1293
1403
  method: "POST",
@@ -1295,9 +1405,9 @@ async function Pn(e, r, o) {
1295
1405
  }
1296
1406
  );
1297
1407
  }
1298
- async function Gn(e, r, o) {
1299
- return oe(
1300
- e,
1408
+ async function ot(n, r, o) {
1409
+ return ae(
1410
+ n,
1301
1411
  `/api/v1/public/sessions/${r}/complete`,
1302
1412
  {
1303
1413
  method: "POST",
@@ -1305,149 +1415,172 @@ async function Gn(e, r, o) {
1305
1415
  }
1306
1416
  );
1307
1417
  }
1308
- async function zn(e, r) {
1309
- return oe(
1310
- e,
1418
+ async function rt(n, r) {
1419
+ return ae(
1420
+ n,
1311
1421
  `/api/v1/public/sessions/${r}`
1312
1422
  );
1313
1423
  }
1314
- const Jn = ({
1315
- screenIndex: e,
1424
+ const st = {
1425
+ clean: "dots",
1426
+ outlined: "dots",
1427
+ "refined-clean": "pill",
1428
+ "airy-clean": "glow",
1429
+ "soft-outlined": "glow",
1430
+ "defined-outlined": "bar",
1431
+ "centered-minimal": "dots",
1432
+ "stacked-cards": "dots",
1433
+ "soft-float": "glow",
1434
+ "bold-statement": "bar"
1435
+ }, it = ({
1436
+ screenIndex: n,
1316
1437
  onFlowComplete: r,
1317
1438
  onScreenChange: o
1318
1439
  }) => {
1319
- var ie, De, Be, Ve, Oe, ke, Me, _e, Te, Ue, Fe;
1320
- const t = L((I) => I.config), n = L((I) => I.screenOrder.length), s = L((I) => Object.keys(I.components).length > 0), i = Ke(), a = Math.max(
1440
+ var Ve, Te, _e, Me, Ue, Ae, Fe, je, Le, Pe, $e;
1441
+ const t = P((D) => D.config), e = P((D) => D.screenOrder.length), s = P((D) => Object.keys(D.components).length > 0), c = Ce(), i = Math.max(
1321
1442
  0,
1322
- Math.min(e, n - 1)
1323
- ), [c, d] = P(a), [l, u] = P(
1324
- !!(t != null && t.summary && e >= n)
1325
- ), p = ((ie = t == null ? void 0 : t.navigation) == null ? void 0 : ie.transition) ?? "none", f = p !== "none", [y, g] = P(null), [h, v] = P(!1), [b, w] = P("forward"), [C, N] = P(!1), T = ce(null);
1326
- K(() => {
1327
- const I = Math.max(0, Math.min(e, n - 1));
1328
- d(I);
1329
- }, [e]);
1330
- const x = L((I) => I.screenOrder[c]), M = L(
1331
- (I) => x ? I.screenValidity[x] ?? !0 : !0
1332
- ), U = L(
1333
- (I) => {
1334
- var j;
1335
- return x ? (j = I.screens[x]) == null ? void 0 : j.nextButtonLabel : void 0;
1443
+ Math.min(n, e - 1)
1444
+ ), [l, a] = J(i), [u, d] = J(
1445
+ !!(t != null && t.summary && n >= e)
1446
+ ), f = ((Ve = t == null ? void 0 : t.navigation) == null ? void 0 : Ve.transition) ?? "none", p = f !== "none", [y, g] = J(null), [v, h] = J(!1), [b, C] = J("forward"), [S, w] = J(!1), V = Z(null);
1447
+ H(() => {
1448
+ const D = Math.max(0, Math.min(n, e - 1));
1449
+ a(D);
1450
+ }, [n]);
1451
+ const E = P((D) => D.screenOrder[l]), T = P(
1452
+ (D) => E ? D.screenValidity[E] ?? !0 : !0
1453
+ ), _ = P(
1454
+ (D) => {
1455
+ var F;
1456
+ return E ? (F = D.screens[E]) == null ? void 0 : F.nextButtonLabel : void 0;
1336
1457
  }
1337
- ), S = L(
1338
- (I) => {
1339
- var j;
1340
- return x ? (j = I.screens[x]) == null ? void 0 : j.backButtonLabel : void 0;
1458
+ ), N = P(
1459
+ (D) => {
1460
+ var F;
1461
+ return E ? (F = D.screens[E]) == null ? void 0 : F.backButtonLabel : void 0;
1341
1462
  }
1342
- ), D = z(
1343
- (I) => {
1344
- o && o(I, i.getState().getFlowData());
1463
+ ), I = z(
1464
+ (D) => {
1465
+ o && o(D, c.getState().getFlowData());
1345
1466
  },
1346
- [o, i]
1347
- ), B = z(
1348
- (I) => {
1349
- g(c), v(l), w(I), N(!0), T.current && (T.current.scrollTop = 0);
1467
+ [o, c]
1468
+ ), k = z(
1469
+ (D) => {
1470
+ g(l), h(u), C(D), w(!0), V.current && (V.current.scrollTop = 0);
1350
1471
  },
1351
- [c, l]
1352
- ), G = z(() => {
1353
- N(!1), g(null);
1354
- }, []), V = z(() => {
1355
- if (!C)
1356
- if (l)
1357
- f && B("back"), u(!1), D(c);
1472
+ [l, u]
1473
+ ), W = z(() => {
1474
+ w(!1), g(null);
1475
+ }, []), U = z(() => {
1476
+ if (!S)
1477
+ if (u)
1478
+ p && k("back"), d(!1), I(l);
1358
1479
  else {
1359
- const I = i.getState(), j = _n(I, c);
1360
- j !== c && (f && B("back"), d(j), D(j));
1480
+ const D = c.getState(), F = Jn(D, l);
1481
+ F !== l && (p && k("back"), a(F), I(F));
1361
1482
  }
1362
1483
  }, [
1363
- C,
1484
+ S,
1485
+ u,
1364
1486
  l,
1365
- c,
1366
- f,
1367
- B,
1368
- D,
1369
- i
1370
- ]), $ = z(() => {
1371
- if (C) return;
1372
- const I = i.getState(), j = Ge(I, c);
1373
- j !== null ? (f && B("forward"), d(j), D(j)) : t != null && t.summary && (f && B("forward"), u(!0), D(c + 1));
1487
+ p,
1488
+ k,
1489
+ I,
1490
+ c
1491
+ ]), A = z(() => {
1492
+ if (S) return;
1493
+ const D = c.getState(), F = ye(D, l);
1494
+ F !== null ? (p && k("forward"), a(F), I(F)) : t != null && t.summary && (p && k("forward"), d(!0), I(l + 1));
1374
1495
  }, [
1375
- C,
1376
- c,
1496
+ S,
1497
+ l,
1377
1498
  t,
1378
- f,
1379
- B,
1380
- D,
1381
- i
1382
- ]), [J, R] = P(!1), [E, _] = P(null), O = z(() => {
1383
- _(null);
1384
- const I = r(i.getState().getFlowData());
1385
- I && typeof I.then == "function" && (R(!0), I.then(() => {
1386
- R(!1);
1387
- }).catch((j) => {
1388
- R(!1), _(j instanceof Error ? j.message : String(j));
1499
+ p,
1500
+ k,
1501
+ I,
1502
+ c
1503
+ ]), [q, j] = J(!1), [O, $] = J(null), Y = z(() => {
1504
+ $(null);
1505
+ const D = r(c.getState().getFlowData());
1506
+ D && typeof D.then == "function" && (j(!0), D.then(() => {
1507
+ j(!1);
1508
+ }).catch((F) => {
1509
+ j(!1), $(F instanceof Error ? F.message : String(F));
1389
1510
  }));
1390
- }, [r, i]), ee = L((I) => Ge(I, c) === null), H = ((De = t == null ? void 0 : t.theme) == null ? void 0 : De.darkMode) ?? !1, ge = ((Be = t == null ? void 0 : t.controls) == null ? void 0 : Be.showStepper) !== !1 && ((Ve = t == null ? void 0 : t.controls) == null ? void 0 : Ve.stepperStyle) === "text", A = {};
1391
- (Oe = t == null ? void 0 : t.theme) != null && Oe.color && (A["--fbre-theme-color"] = t.theme.color);
1392
- const re = () => h ? /* @__PURE__ */ m(Pe, {}) : y !== null ? /* @__PURE__ */ m(Ne, { screenIndex: y }) : null, se = C ? "fbre-screen-wrapper fbre-screen-wrapper--transitioning" : "fbre-screen-wrapper";
1393
- return /* @__PURE__ */ k(
1511
+ }, [r, c]), K = P((D) => ye(D, l) === null), R = ((Te = t == null ? void 0 : t.theme) == null ? void 0 : Te.darkMode) ?? !1, x = ((t == null ? void 0 : t.mode) ?? "standard") === "conversational";
1512
+ sn(
1513
+ x && !u,
1514
+ l,
1515
+ A
1516
+ ), cn(
1517
+ x && !u,
1518
+ l,
1519
+ A
1520
+ );
1521
+ const L = ((_e = t == null ? void 0 : t.theme) == null ? void 0 : _e.style) ?? "clean", re = ((Me = t == null ? void 0 : t.controls) == null ? void 0 : Me.stepperStyle) ?? "default", se = re === "default" ? st[L] ?? "dots" : re, un = ((Ue = t == null ? void 0 : t.controls) == null ? void 0 : Ue.showStepper) !== !1 && se === "text", Se = {};
1522
+ (Ae = t == null ? void 0 : t.theme) != null && Ae.color && (Se["--fbre-theme-color"] = t.theme.color);
1523
+ const dn = () => v ? /* @__PURE__ */ m(qe, {}) : y !== null ? /* @__PURE__ */ m(De, { screenIndex: y }) : null, pn = S ? "fbre-screen-wrapper fbre-screen-wrapper--transitioning" : "fbre-screen-wrapper";
1524
+ return /* @__PURE__ */ B(
1394
1525
  "div",
1395
1526
  {
1396
1527
  className: "fbre-container",
1397
- "data-style": ((ke = t == null ? void 0 : t.theme) == null ? void 0 : ke.style) ?? "clean",
1398
- "data-mode": H ? "dark" : "light",
1399
- "data-transition": f ? p : void 0,
1400
- style: Object.keys(A).length > 0 ? A : void 0,
1528
+ "data-style": L,
1529
+ "data-mode": R ? "dark" : "light",
1530
+ "data-form-mode": x ? "conversational" : void 0,
1531
+ "data-stepper": se !== "text" ? se : void 0,
1532
+ "data-transition": p ? f : void 0,
1533
+ style: Object.keys(Se).length > 0 ? Se : void 0,
1401
1534
  children: [
1402
- ge && /* @__PURE__ */ m(Dn, { current: c, total: n }),
1403
- /* @__PURE__ */ k("div", { className: se, ref: T, children: [
1404
- C && /* @__PURE__ */ m(
1535
+ un && /* @__PURE__ */ m(jn, { current: l, total: e }),
1536
+ /* @__PURE__ */ B("div", { className: pn, ref: V, children: [
1537
+ S && /* @__PURE__ */ m(
1405
1538
  "div",
1406
1539
  {
1407
1540
  className: "fbre-screen--exiting",
1408
1541
  "data-direction": b,
1409
- onAnimationEnd: G,
1410
- children: re()
1542
+ onAnimationEnd: W,
1543
+ children: dn()
1411
1544
  }
1412
1545
  ),
1413
- /* @__PURE__ */ k(
1546
+ /* @__PURE__ */ B(
1414
1547
  "div",
1415
1548
  {
1416
- className: C ? "fbre-screen--entering" : void 0,
1417
- "data-direction": C ? b : void 0,
1549
+ className: S ? "fbre-screen--entering" : void 0,
1550
+ "data-direction": S ? b : void 0,
1418
1551
  children: [
1419
- !l && /* @__PURE__ */ m(Ne, { screenIndex: c }),
1420
- l && /* @__PURE__ */ m(Pe, {})
1552
+ !u && /* @__PURE__ */ m(De, { screenIndex: l }),
1553
+ u && /* @__PURE__ */ m(qe, {})
1421
1554
  ]
1422
1555
  }
1423
1556
  )
1424
1557
  ] }),
1425
- E && /* @__PURE__ */ m("div", { className: "fbre-completion-error", children: E }),
1426
- ((Me = t == null ? void 0 : t.controls) == null ? void 0 : Me.show) !== !1 && s && /* @__PURE__ */ m(
1427
- Bn,
1558
+ O && /* @__PURE__ */ m("div", { className: "fbre-completion-error", children: O }),
1559
+ ((Fe = t == null ? void 0 : t.controls) == null ? void 0 : Fe.show) !== !1 && s && /* @__PURE__ */ m(
1560
+ Ln,
1428
1561
  {
1429
- screenIndex: c,
1430
- maxScreenIndex: n - 1,
1431
- allowInvalidTransition: (_e = t == null ? void 0 : t.navigation) == null ? void 0 : _e.allowInvalidTransition,
1432
- screenValidity: M,
1562
+ screenIndex: l,
1563
+ maxScreenIndex: e - 1,
1564
+ allowInvalidTransition: (je = t == null ? void 0 : t.navigation) == null ? void 0 : je.allowInvalidTransition,
1565
+ screenValidity: T,
1433
1566
  summaryEnabled: (t == null ? void 0 : t.summary) ?? !1,
1434
- summaryActive: l,
1435
- atMaxScreen: ee,
1436
- nextButtonLabel: U,
1437
- backButtonLabel: S,
1438
- completionLoading: J,
1439
- showStepper: (Te = t == null ? void 0 : t.controls) == null ? void 0 : Te.showStepper,
1440
- stepperStyle: (Ue = t == null ? void 0 : t.controls) == null ? void 0 : Ue.stepperStyle,
1441
- controlsLayout: (Fe = t == null ? void 0 : t.controls) == null ? void 0 : Fe.layout,
1442
- nextScreen: $,
1443
- prevScreen: V,
1444
- onFlowComplete: O
1567
+ summaryActive: u,
1568
+ atMaxScreen: K,
1569
+ nextButtonLabel: _,
1570
+ backButtonLabel: N,
1571
+ completionLoading: q,
1572
+ showStepper: (Le = t == null ? void 0 : t.controls) == null ? void 0 : Le.showStepper,
1573
+ stepperStyle: (Pe = t == null ? void 0 : t.controls) == null ? void 0 : Pe.stepperStyle,
1574
+ controlsLayout: ($e = t == null ? void 0 : t.controls) == null ? void 0 : $e.layout,
1575
+ nextScreen: A,
1576
+ prevScreen: U,
1577
+ onFlowComplete: Y
1445
1578
  }
1446
1579
  )
1447
1580
  ]
1448
1581
  }
1449
1582
  );
1450
- }, Yn = [], qn = () => Ye((e, r) => ({
1583
+ }, ct = [], at = () => Qe((n, r) => ({
1451
1584
  // Identity (minimal — server drives the flow)
1452
1585
  flowUUID: "",
1453
1586
  metadata: {},
@@ -1473,6 +1606,8 @@ const Jn = ({
1473
1606
  calculationsByDependency: {},
1474
1607
  // Computed components
1475
1608
  computedByDependency: {},
1609
+ // Selection re-click tracking
1610
+ selectionTick: 0,
1476
1611
  // Server-driven specific
1477
1612
  sessionId: "",
1478
1613
  navigation: {
@@ -1487,7 +1622,7 @@ const Jn = ({
1487
1622
  error: "",
1488
1623
  // Actions
1489
1624
  clearError: () => {
1490
- e({ error: "" });
1625
+ n({ error: "" });
1491
1626
  },
1492
1627
  /**
1493
1628
  * loadFlow is repurposed to load a server screen payload.
@@ -1496,288 +1631,291 @@ const Jn = ({
1496
1631
  loadFlow: () => {
1497
1632
  },
1498
1633
  updateContext: (o) => {
1499
- e({ externalContext: o });
1634
+ n({ externalContext: o });
1500
1635
  },
1501
1636
  updateComponentValue: (o, t) => {
1502
- var p, f;
1503
- const n = r();
1637
+ var f, p;
1638
+ const e = r();
1504
1639
  if (o.includes(":")) {
1505
- const y = o.split(":"), g = y[0], h = parseInt(y[1]), v = parseInt(y[2]), b = n.components[g];
1506
- if (!((f = (p = b == null ? void 0 : b.addedComponents) == null ? void 0 : p[h]) != null && f[v])) return;
1507
- b.addedComponents[h][v] = { ...b.addedComponents[h][v], value: t };
1508
- const w = n.groupComponentMap[o] ?? o, C = n.conditionsByDependency[w];
1509
- let N = n.conditionResults;
1510
- if (C && C.length > 0) {
1511
- N = { ...n.conditionResults };
1512
- for (const S of C)
1513
- N[S.target] = te(
1514
- { ...n },
1515
- S.config
1640
+ const y = o.split(":"), g = y[0], v = parseInt(y[1]), h = parseInt(y[2]), b = e.components[g];
1641
+ if (!((p = (f = b == null ? void 0 : b.addedComponents) == null ? void 0 : f[v]) != null && p[h])) return;
1642
+ b.addedComponents[v][h] = { ...b.addedComponents[v][h], value: t };
1643
+ const C = e.groupComponentMap[o] ?? o, S = e.conditionsByDependency[C];
1644
+ let w = e.conditionResults;
1645
+ if (S && S.length > 0) {
1646
+ w = { ...e.conditionResults };
1647
+ for (const N of S)
1648
+ w[N.target] = ce(
1649
+ { ...e },
1650
+ N.config
1516
1651
  );
1517
1652
  }
1518
- const T = {
1519
- components: n.components,
1520
- groupComponentMap: n.groupComponentMap
1521
- }, x = F(
1522
- b.addedComponents[h][v],
1523
- T
1653
+ const V = {
1654
+ components: e.components,
1655
+ groupComponentMap: e.groupComponentMap
1656
+ }, E = M(
1657
+ b.addedComponents[v][h],
1658
+ V
1524
1659
  );
1525
- b.addedComponents[h][v].valid = x.length === 0;
1526
- const M = {
1527
- ...n.validationErrors,
1528
- [o]: x
1529
- }, U = n.validationsByDependency[o];
1530
- if (U)
1531
- for (const S of U) {
1532
- const D = ze(n, S.target);
1533
- if (D) {
1534
- const B = F(D, T);
1535
- D.valid = B.length === 0, M[S.target] = B;
1660
+ b.addedComponents[v][h].valid = E.length === 0;
1661
+ const T = {
1662
+ ...e.validationErrors,
1663
+ [o]: E
1664
+ }, _ = e.validationsByDependency[o];
1665
+ if (_)
1666
+ for (const N of _) {
1667
+ const I = Xe(e, N.target);
1668
+ if (I) {
1669
+ const k = M(I, V);
1670
+ I.valid = k.length === 0, T[N.target] = k;
1536
1671
  }
1537
1672
  }
1538
- e({
1539
- components: { ...n.components },
1540
- conditionResults: N,
1541
- validationErrors: M
1673
+ n({
1674
+ components: { ...e.components },
1675
+ conditionResults: w,
1676
+ validationErrors: T
1542
1677
  });
1543
1678
  return;
1544
1679
  }
1545
- const s = n.components[o];
1680
+ const s = e.components[o];
1546
1681
  if (!s) return;
1547
1682
  if (s.type === "group" || s.type === "repeater") {
1548
- e({ components: { ...n.components } });
1683
+ n({ components: { ...e.components } });
1684
+ return;
1685
+ }
1686
+ if (t === s.value) {
1687
+ n({ selectionTick: (r().selectionTick ?? 0) + 1 });
1549
1688
  return;
1550
1689
  }
1551
- if (t === s.value) return;
1552
1690
  s.value = t;
1553
- const i = n.conditionsByDependency[o];
1554
- let a = n.conditionResults;
1555
- if (i && i.length > 0) {
1556
- a = { ...n.conditionResults };
1557
- for (const y of i)
1558
- a[y.target] = te(
1559
- { ...n },
1691
+ const c = e.conditionsByDependency[o];
1692
+ let i = e.conditionResults;
1693
+ if (c && c.length > 0) {
1694
+ i = { ...e.conditionResults };
1695
+ for (const y of c)
1696
+ i[y.target] = ce(
1697
+ { ...e },
1560
1698
  y.config
1561
1699
  );
1562
1700
  }
1563
- const c = {
1564
- components: n.components,
1565
- groupComponentMap: n.groupComponentMap
1566
- }, d = F(s, c);
1567
- s.valid = d.length === 0;
1568
- const l = { ...n.validationErrors, [o]: d }, u = n.validationsByDependency[o];
1569
- if (u)
1570
- for (const y of u) {
1571
- const g = ze(n, y.target);
1701
+ const l = {
1702
+ components: e.components,
1703
+ groupComponentMap: e.groupComponentMap
1704
+ }, a = M(s, l);
1705
+ s.valid = a.length === 0;
1706
+ const u = { ...e.validationErrors, [o]: a }, d = e.validationsByDependency[o];
1707
+ if (d)
1708
+ for (const y of d) {
1709
+ const g = Xe(e, y.target);
1572
1710
  if (g) {
1573
- const h = F(g, c);
1574
- g.valid = h.length === 0, l[y.target] = h;
1711
+ const v = M(g, l);
1712
+ g.valid = v.length === 0, u[y.target] = v;
1575
1713
  }
1576
1714
  }
1577
- e({
1578
- components: { ...n.components },
1579
- conditionResults: a,
1580
- validationErrors: l
1715
+ n({
1716
+ components: { ...e.components },
1717
+ conditionResults: i,
1718
+ validationErrors: u
1581
1719
  });
1582
1720
  },
1583
1721
  addGroupIteration: (o) => {
1584
- const t = r(), n = t.components[o];
1585
- if (!n || n.type !== "group" || !n.components)
1722
+ const t = r(), e = t.components[o];
1723
+ if (!e || e.type !== "group" || !e.components)
1586
1724
  return;
1587
- n.addedComponents || (n.addedComponents = []);
1588
- const s = n.components.map((i, a) => {
1589
- const c = Y(i);
1590
- c.uuid = [o, n.addedComponents.length, a].join(
1725
+ e.addedComponents || (e.addedComponents = []);
1726
+ const s = e.components.map((c, i) => {
1727
+ const l = X(c);
1728
+ l.uuid = [o, e.addedComponents.length, i].join(
1591
1729
  ":"
1592
- ), t.groupComponentMap[c.uuid] = i.uuid;
1593
- const d = F(c);
1594
- return c.valid = d.length === 0, c;
1730
+ ), t.groupComponentMap[l.uuid] = c.uuid;
1731
+ const a = M(l);
1732
+ return l.valid = a.length === 0, l;
1595
1733
  });
1596
- return n.addedComponents.push(s), e({
1734
+ return e.addedComponents.push(s), n({
1597
1735
  components: { ...t.components },
1598
1736
  groupComponentMap: { ...t.groupComponentMap }
1599
- }), n.addedComponents;
1737
+ }), e.addedComponents;
1600
1738
  },
1601
1739
  addRepeaterIteration: (o) => {
1602
- const t = r(), n = t.components[o];
1603
- if (!n || n.type !== "repeater" || !n.components)
1740
+ const t = r(), e = t.components[o];
1741
+ if (!e || e.type !== "repeater" || !e.components)
1604
1742
  return;
1605
- n.addedComponents || (n.addedComponents = []);
1606
- const s = n.components.map((i, a) => {
1607
- const c = Y(i);
1608
- c.uuid = [
1743
+ e.addedComponents || (e.addedComponents = []);
1744
+ const s = e.components.map((c, i) => {
1745
+ const l = X(c);
1746
+ l.uuid = [
1609
1747
  o,
1610
- n.addedComponents.length,
1611
- a
1748
+ e.addedComponents.length,
1749
+ i
1612
1750
  ].join(":");
1613
- const d = F(c);
1614
- return c.valid = d.length === 0, c;
1751
+ const a = M(l);
1752
+ return l.valid = a.length === 0, l;
1615
1753
  });
1616
- return n.addedComponents.push(s), e({ components: { ...t.components } }), n.addedComponents;
1754
+ return e.addedComponents.push(s), n({ components: { ...t.components } }), e.addedComponents;
1617
1755
  },
1618
1756
  removeRepeaterIteration: (o, t) => {
1619
- const n = r(), s = n.components[o];
1757
+ const e = r(), s = e.components[o];
1620
1758
  if (!(!s || s.type !== "repeater" || !s.addedComponents || s.addedComponents.length <= 1)) {
1621
1759
  s.addedComponents.splice(t, 1);
1622
- for (let i = t; i < s.addedComponents.length; i++)
1623
- s.addedComponents[i].forEach((a, c) => {
1624
- a.uuid = [o, i, c].join(":");
1760
+ for (let c = t; c < s.addedComponents.length; c++)
1761
+ s.addedComponents[c].forEach((i, l) => {
1762
+ i.uuid = [o, c, l].join(":");
1625
1763
  });
1626
- e({ components: { ...n.components } });
1764
+ n({ components: { ...e.components } });
1627
1765
  }
1628
1766
  },
1629
1767
  getFlowData: () => ({ uuid: "", metadata: {}, screens: [] }),
1630
1768
  getScreenByIndex: (o) => {
1631
1769
  const t = r();
1632
1770
  if (o !== 0) return null;
1633
- const n = t.screenOrder[0];
1634
- return n ? t.screens[n] : null;
1771
+ const e = t.screenOrder[0];
1772
+ return e ? t.screens[e] : null;
1635
1773
  },
1636
1774
  getScreenValidity: (o) => {
1637
1775
  const t = r();
1638
1776
  if (o !== 0) return !0;
1639
- const n = t.screenOrder[0];
1640
- return n ? t.screenValidity[n] ?? !0 : !0;
1777
+ const e = t.screenOrder[0];
1778
+ return e ? t.screenValidity[e] ?? !0 : !0;
1641
1779
  },
1642
- getValidationErrors: (o) => r().validationErrors[o] ?? Yn,
1780
+ getValidationErrors: (o) => r().validationErrors[o] ?? ct,
1643
1781
  evaluateFlowValidation: () => {
1644
1782
  const o = r(), t = o.screenOrder[0];
1645
1783
  if (!t) return !0;
1646
- const n = o.screens[t];
1647
- if (!n) return !0;
1784
+ const e = o.screens[t];
1785
+ if (!e) return !0;
1648
1786
  let s = !0;
1649
- const i = {
1787
+ const c = {
1650
1788
  components: o.components,
1651
1789
  groupComponentMap: o.groupComponentMap
1652
- }, a = { ...o.validationErrors };
1653
- for (const d of n.components) {
1654
- const l = o.components[d.uuid];
1655
- if (!l) continue;
1656
- if ((l.type === "group" || l.type === "repeater") && l.addedComponents) {
1657
- for (const f of l.addedComponents)
1658
- for (const y of f) {
1790
+ }, i = { ...o.validationErrors };
1791
+ for (const a of e.components) {
1792
+ const u = o.components[a.uuid];
1793
+ if (!u) continue;
1794
+ if ((u.type === "group" || u.type === "repeater") && u.addedComponents) {
1795
+ for (const p of u.addedComponents)
1796
+ for (const y of p) {
1659
1797
  const g = y.conditions && "when" in y.conditions ? y.conditions : void 0;
1660
1798
  if (g) {
1661
- const v = o.conditionResults[y.uuid] ?? !1;
1662
- if (g.action === "show" && !v || g.action === "hide" && v)
1799
+ const h = o.conditionResults[y.uuid] ?? !1;
1800
+ if (g.action === "show" && !h || g.action === "hide" && h)
1663
1801
  continue;
1664
1802
  }
1665
- const h = F(y, i);
1666
- y.valid = h.length === 0, a[y.uuid] = h, h.length > 0 && (s = !1);
1803
+ const v = M(y, c);
1804
+ y.valid = v.length === 0, i[y.uuid] = v, v.length > 0 && (s = !1);
1667
1805
  }
1668
1806
  continue;
1669
1807
  }
1670
- const u = l.conditions && "when" in l.conditions ? l.conditions : void 0;
1671
- if (u) {
1672
- const f = o.conditionResults[l.uuid] ?? !1;
1673
- if (u.action === "show" && !f || u.action === "hide" && f)
1808
+ const d = u.conditions && "when" in u.conditions ? u.conditions : void 0;
1809
+ if (d) {
1810
+ const p = o.conditionResults[u.uuid] ?? !1;
1811
+ if (d.action === "show" && !p || d.action === "hide" && p)
1674
1812
  continue;
1675
1813
  }
1676
- const p = F(l, i);
1677
- l.valid = p.length === 0, a[l.uuid] = p, p.length > 0 && (s = !1);
1814
+ const f = M(u, c);
1815
+ u.valid = f.length === 0, i[u.uuid] = f, f.length > 0 && (s = !1);
1678
1816
  }
1679
- const c = { ...o.screenValidity, [t]: s };
1680
- return e({
1817
+ const l = { ...o.screenValidity, [t]: s };
1818
+ return n({
1681
1819
  components: { ...o.components },
1682
- validationErrors: a,
1683
- screenValidity: c
1820
+ validationErrors: i,
1821
+ screenValidity: l
1684
1822
  }), s;
1685
1823
  },
1686
1824
  getMaxScreenCount: () => 0,
1687
1825
  getCalculationResult: (o) => r().calculationResults[o] ?? null
1688
- })), ue = (e, r) => {
1826
+ })), pe = (n, r) => {
1689
1827
  var y, g;
1690
- const o = {}, t = {}, n = {}, s = {}, i = {}, a = {}, c = r.screen.uuid;
1691
- for (const h of r.screen.components) {
1692
- const v = Y(h);
1693
- if (o[v.uuid] = v, (v.type === "group" || v.type === "repeater") && h.components) {
1694
- v.addedComponents || (v.addedComponents = []);
1695
- const b = h.components.map((w, C) => {
1696
- var T;
1697
- const N = Y(w);
1698
- if (N.uuid = [v.uuid, 0, C].join(":"), v.type === "group" && (t[N.uuid] = w.uuid), n[w.uuid] = N.uuid, (T = N.properties) != null && T.validation) {
1699
- const x = N.properties.validation;
1700
- x.rules && x.rules.length > 0 && ae(i, N.uuid, x);
1828
+ const o = {}, t = {}, e = {}, s = {}, c = {}, i = {}, l = r.screen.uuid;
1829
+ for (const v of r.screen.components) {
1830
+ const h = X(v);
1831
+ if (o[h.uuid] = h, (h.type === "group" || h.type === "repeater") && v.components) {
1832
+ h.addedComponents || (h.addedComponents = []);
1833
+ const b = v.components.map((C, S) => {
1834
+ var V;
1835
+ const w = X(C);
1836
+ if (w.uuid = [h.uuid, 0, S].join(":"), h.type === "group" && (t[w.uuid] = C.uuid), e[C.uuid] = w.uuid, (V = w.properties) != null && V.validation) {
1837
+ const E = w.properties.validation;
1838
+ E.rules && E.rules.length > 0 && le(c, w.uuid, E);
1701
1839
  }
1702
- return N;
1840
+ return w;
1703
1841
  });
1704
- v.addedComponents.push(b);
1842
+ h.addedComponents.push(b);
1705
1843
  }
1706
- if ((y = v.properties) != null && y.validation) {
1707
- const b = v.properties.validation;
1708
- b.rules && b.rules.length > 0 && ae(i, v.uuid, b);
1844
+ if ((y = h.properties) != null && y.validation) {
1845
+ const b = h.properties.validation;
1846
+ b.rules && b.rules.length > 0 && le(c, h.uuid, b);
1709
1847
  }
1710
1848
  }
1711
- for (const { targetUUID: h, config: v } of r.conditions)
1712
- X(s, h, v, h === c ? "screen" : "component");
1849
+ for (const { targetUUID: v, config: h } of r.conditions)
1850
+ ne(s, v, h, v === l ? "screen" : "component");
1713
1851
  if (r.previousData)
1714
- for (const h of r.previousData) {
1715
- const v = o[h.uuid];
1716
- v && (v.value = h.value);
1852
+ for (const v of r.previousData) {
1853
+ const h = o[v.uuid];
1854
+ h && (h.value = v.value);
1717
1855
  }
1718
- const d = { components: o };
1719
- for (const h of Object.keys(o)) {
1720
- const v = o[h];
1721
- if (v.type === "group" || v.type === "repeater") {
1722
- if (v.addedComponents)
1723
- for (const w of v.addedComponents)
1724
- for (const C of w) {
1725
- const N = F(C, d);
1726
- C.valid = N.length === 0, N.length > 0 && (a[C.uuid] = N);
1856
+ const a = { components: o };
1857
+ for (const v of Object.keys(o)) {
1858
+ const h = o[v];
1859
+ if (h.type === "group" || h.type === "repeater") {
1860
+ if (h.addedComponents)
1861
+ for (const C of h.addedComponents)
1862
+ for (const S of C) {
1863
+ const w = M(S, a);
1864
+ S.valid = w.length === 0, w.length > 0 && (i[S.uuid] = w);
1727
1865
  }
1728
1866
  continue;
1729
1867
  }
1730
- if (!((g = v.properties) != null && g.validation)) continue;
1731
- const b = F(v, d);
1732
- v.valid = b.length === 0, b.length > 0 && (a[h] = b);
1868
+ if (!((g = h.properties) != null && g.validation)) continue;
1869
+ const b = M(h, a);
1870
+ h.valid = b.length === 0, b.length > 0 && (i[v] = b);
1733
1871
  }
1734
- const l = {}, u = {
1872
+ const u = {}, d = {
1735
1873
  components: o
1736
- }, p = /* @__PURE__ */ new Set();
1737
- for (const h of Object.values(s))
1738
- for (const v of h)
1739
- p.has(v.target) || (p.add(v.target), l[v.target] = te(
1740
- u,
1741
- v.config
1874
+ }, f = /* @__PURE__ */ new Set();
1875
+ for (const v of Object.values(s))
1876
+ for (const h of v)
1877
+ f.has(h.target) || (f.add(h.target), u[h.target] = ce(
1878
+ d,
1879
+ h.config
1742
1880
  ));
1743
- let f = !0;
1744
- for (const h of r.screen.components) {
1745
- const v = o[h.uuid];
1746
- if (v)
1747
- if ((v.type === "group" || v.type === "repeater") && v.addedComponents)
1748
- for (const b of v.addedComponents) {
1749
- for (const w of b)
1750
- if (!w.valid) {
1751
- f = !1;
1881
+ let p = !0;
1882
+ for (const v of r.screen.components) {
1883
+ const h = o[v.uuid];
1884
+ if (h)
1885
+ if ((h.type === "group" || h.type === "repeater") && h.addedComponents)
1886
+ for (const b of h.addedComponents) {
1887
+ for (const C of b)
1888
+ if (!C.valid) {
1889
+ p = !1;
1752
1890
  break;
1753
1891
  }
1754
- if (!f) break;
1892
+ if (!p) break;
1755
1893
  }
1756
- else v.valid === !1 && (f = !1);
1894
+ else h.valid === !1 && (p = !1);
1757
1895
  }
1758
- e.setState({
1896
+ n.setState({
1759
1897
  // Screen (single screen)
1760
- screenOrder: [c],
1898
+ screenOrder: [l],
1761
1899
  screens: {
1762
- [c]: {
1763
- uuid: c,
1900
+ [l]: {
1901
+ uuid: l,
1764
1902
  label: r.screen.label,
1765
1903
  components: r.screen.components,
1766
1904
  nextButtonLabel: r.screen.nextButtonLabel,
1767
1905
  backButtonLabel: r.screen.backButtonLabel
1768
1906
  }
1769
1907
  },
1770
- screenValidity: { [c]: f },
1908
+ screenValidity: { [l]: p },
1771
1909
  // Components
1772
1910
  components: o,
1773
1911
  groupComponentMap: t,
1774
- templateComponentMap: n,
1912
+ templateComponentMap: e,
1775
1913
  // Conditions
1776
1914
  conditionsByDependency: s,
1777
- conditionResults: l,
1915
+ conditionResults: u,
1778
1916
  // Validation
1779
- validationErrors: a,
1780
- validationsByDependency: i,
1917
+ validationErrors: i,
1918
+ validationsByDependency: c,
1781
1919
  // Calculations (not used in server-driven mode yet)
1782
1920
  calculations: [],
1783
1921
  calculationResults: {},
@@ -1794,69 +1932,73 @@ const Jn = ({
1794
1932
  // Config
1795
1933
  config: r.config ?? {}
1796
1934
  });
1797
- }, we = (e) => {
1935
+ }, Re = (n) => {
1798
1936
  var s;
1799
- const r = e.getState(), o = r.screenOrder[0];
1937
+ const r = n.getState(), o = r.screenOrder[0];
1800
1938
  if (!o) return [];
1801
1939
  const t = r.screens[o];
1802
1940
  if (!t) return [];
1803
- const n = [];
1804
- for (const i of t.components) {
1805
- const a = r.components[i.uuid];
1806
- if (!a || me(a.type)) continue;
1807
- const c = {
1808
- uuid: a.uuid,
1809
- type: a.type,
1810
- value: a.value
1941
+ const e = [];
1942
+ for (const c of t.components) {
1943
+ const i = r.components[c.uuid];
1944
+ if (!i || ve(i.type)) continue;
1945
+ const l = {
1946
+ uuid: i.uuid,
1947
+ type: i.type,
1948
+ value: i.value
1811
1949
  };
1812
- (s = a.properties) != null && s.label && (c.label = a.properties.label), (a.type === "group" || a.type === "repeater") && a.addedComponents && (c.components = a.addedComponents.map(
1813
- (d) => d.filter((l) => !me(l.type)).map((l) => ({
1814
- uuid: l.uuid,
1815
- type: l.type,
1816
- value: l.value
1950
+ (s = i.properties) != null && s.label && (l.label = i.properties.label), (i.type === "group" || i.type === "repeater") && i.addedComponents && (l.components = i.addedComponents.map(
1951
+ (a) => a.filter((u) => !ve(u.type)).map((u) => ({
1952
+ uuid: u.uuid,
1953
+ type: u.type,
1954
+ value: u.value
1817
1955
  }))
1818
- )), n.push(c);
1956
+ )), e.push(l);
1819
1957
  }
1820
- return n;
1821
- }, ze = (e, r) => Xe(e.components, r), Hn = 6e4, Wn = ({
1822
- sessionEndpoint: e,
1958
+ return e;
1959
+ }, Xe = (n, r) => tn(n.components, r), lt = 6e4, ut = ({
1960
+ sessionEndpoint: n,
1823
1961
  flowId: r,
1824
1962
  apiKey: o,
1825
- theme: t,
1826
- context: n,
1827
- onFlowComplete: s,
1963
+ mode: t,
1964
+ theme: e,
1965
+ context: s,
1966
+ onFlowComplete: c,
1828
1967
  onScreenChange: i
1829
1968
  }) => {
1830
- const a = ce(null);
1831
- a.current || (a.current = qn());
1832
- const c = a.current, d = W(c, (R) => R.loading), l = W(c, (R) => R.error), u = W(c, (R) => R.navigation), p = W(c, (R) => R.config), f = W(c, (R) => R.screenOrder), y = W(c, (R) => R.screens), [g, h] = P(""), v = ce(null), b = ce(Date.now()), w = Ee(
1833
- () => ({ apiEndpoint: e, apiKey: o }),
1834
- [e, o]
1835
- ), C = z((R) => {
1836
- h(R), v.current && clearTimeout(v.current), v.current = setTimeout(() => h(""), 8e3);
1837
- }, []), N = z(() => {
1838
- h(""), v.current && (clearTimeout(v.current), v.current = null);
1969
+ const l = Z(null);
1970
+ l.current || (l.current = at());
1971
+ const a = l.current, u = Q(a, (R) => R.loading), d = Q(a, (R) => R.error), f = Q(a, (R) => R.navigation), p = Q(a, (R) => R.config), y = Q(a, (R) => {
1972
+ var G;
1973
+ return (G = R.config) == null ? void 0 : G.mode;
1974
+ }), g = Q(a, (R) => R.screenOrder), v = Q(a, (R) => R.screens), [h, b] = J(""), C = Z(null), S = Z(Date.now()), w = ke(
1975
+ () => ({ apiEndpoint: n, apiKey: o }),
1976
+ [n, o]
1977
+ ), V = z((R) => {
1978
+ b(R), C.current && clearTimeout(C.current), C.current = setTimeout(() => b(""), 8e3);
1979
+ }, []), E = z(() => {
1980
+ b(""), C.current && (clearTimeout(C.current), C.current = null);
1839
1981
  }, []), T = z(async () => {
1840
- c.setState({ loading: !0, error: "" });
1982
+ a.setState({ loading: !0, error: "" });
1841
1983
  try {
1842
- const R = await Ln(w, r, n);
1843
- ue(c, R);
1984
+ const R = await et(w, r, s);
1985
+ pe(a, R);
1844
1986
  } catch (R) {
1845
- c.setState({ loading: !1, error: R.message });
1987
+ a.setState({ loading: !1, error: R.message });
1846
1988
  }
1847
- }, [r, e, o, n]);
1848
- K(() => {
1989
+ }, [r, n, o, s]);
1990
+ H(() => {
1849
1991
  T();
1850
- }, [T]), K(() => {
1992
+ }, [T]), H(() => {
1851
1993
  const R = async () => {
1852
1994
  if (document.visibilityState !== "visible") return;
1853
- const E = c.getState();
1854
- if (!(!E.sessionId || Date.now() - b.current < Hn))
1995
+ const G = a.getState();
1996
+ if (!(!G.sessionId || Date.now() - S.current < lt))
1855
1997
  try {
1856
- const O = await zn(w, E.sessionId);
1857
- ue(c, O);
1858
- } catch (O) {
1859
- O instanceof he && O.status === 404 && c.setState({
1998
+ const L = await rt(w, G.sessionId);
1999
+ pe(a, L);
2000
+ } catch (L) {
2001
+ L instanceof ge && L.status === 404 && a.setState({
1860
2002
  loading: !1,
1861
2003
  error: "Session expired. Please start over.",
1862
2004
  screenOrder: [],
@@ -1865,49 +2007,51 @@ const Jn = ({
1865
2007
  }
1866
2008
  };
1867
2009
  return document.addEventListener("visibilitychange", R), () => document.removeEventListener("visibilitychange", R);
1868
- }, [e, o]);
1869
- const x = z(async () => {
1870
- const R = c.getState();
2010
+ }, [n, o]);
2011
+ const _ = z(async () => {
2012
+ const R = a.getState();
1871
2013
  if (!(R.loading || !R.evaluateFlowValidation())) {
1872
- c.setState({ loading: !0 }), c.getState().clearError(), N();
2014
+ a.setState({ loading: !0 }), a.getState().clearError(), E();
1873
2015
  try {
1874
- const _ = we(c), O = await $n(w, R.sessionId, _);
1875
- ue(c, O), b.current = Date.now(), i == null || i(O.navigation.screenNumber);
1876
- } catch (_) {
1877
- c.setState({ loading: !1 }), C(_.message);
2016
+ const x = Re(a), L = await nt(w, R.sessionId, x);
2017
+ pe(a, L), S.current = Date.now(), i == null || i(L.navigation.screenNumber);
2018
+ } catch (x) {
2019
+ a.setState({ loading: !1 }), V(x.message);
1878
2020
  }
1879
2021
  }
1880
- }, [w, c, i, C, N]), M = z(async () => {
1881
- const R = c.getState();
2022
+ }, [w, a, i, V, E]), N = z(async () => {
2023
+ const R = a.getState();
1882
2024
  if (!R.loading) {
1883
- c.setState({ loading: !0 }), c.getState().clearError(), N();
2025
+ a.setState({ loading: !0 }), a.getState().clearError(), E();
1884
2026
  try {
1885
- const E = we(c), _ = await Pn(w, R.sessionId, E);
1886
- ue(c, _), b.current = Date.now(), i == null || i(_.navigation.screenNumber);
1887
- } catch (E) {
1888
- c.setState({ loading: !1 }), C(E.message);
2027
+ const G = Re(a), x = await tt(w, R.sessionId, G);
2028
+ pe(a, x), S.current = Date.now(), i == null || i(x.navigation.screenNumber);
2029
+ } catch (G) {
2030
+ a.setState({ loading: !1 }), V(G.message);
1889
2031
  }
1890
2032
  }
1891
- }, [w, c, i, C, N]), U = z(async () => {
1892
- const R = c.getState();
2033
+ }, [w, a, i, V, E]), I = z(async () => {
2034
+ const R = a.getState();
1893
2035
  if (!(R.loading || !R.evaluateFlowValidation())) {
1894
- c.setState({ loading: !0 }), c.getState().clearError(), N();
2036
+ a.setState({ loading: !0 }), a.getState().clearError(), E();
1895
2037
  try {
1896
- const _ = we(c), O = await Gn(w, R.sessionId, _);
1897
- b.current = Date.now(), s(O);
1898
- } catch (_) {
1899
- c.setState({ loading: !1 }), C(_.message);
2038
+ const x = Re(a), L = await ot(w, R.sessionId, x);
2039
+ S.current = Date.now(), c(L);
2040
+ } catch (x) {
2041
+ a.setState({ loading: !1 }), V(x.message);
1900
2042
  }
1901
2043
  }
1902
- }, [w, c, s, C, N]), S = { ...p == null ? void 0 : p.theme, ...t }, D = S.darkMode ?? !1, B = {};
1903
- S.color && (B["--fbre-theme-color"] = S.color);
1904
- const G = f[0], V = G ? y[G] : void 0, $ = V == null ? void 0 : V.nextButtonLabel, J = V == null ? void 0 : V.backButtonLabel;
1905
- return d && f.length === 0 ? /* @__PURE__ */ m("div", { className: "fbre-container", children: /* @__PURE__ */ k("div", { className: "fbre-remote-loading", children: [
2044
+ }, [w, a, c, V, E]), k = { ...p == null ? void 0 : p.theme, ...e }, U = (t ?? y ?? "standard") === "conversational", A = U && !f.isLastScreen;
2045
+ sn(A, 0, _), cn(A, 0, _);
2046
+ const q = k.darkMode ?? !1, j = {};
2047
+ k.color && (j["--fbre-theme-color"] = k.color);
2048
+ const O = g[0], $ = O ? v[O] : void 0, Y = $ == null ? void 0 : $.nextButtonLabel, K = $ == null ? void 0 : $.backButtonLabel;
2049
+ return u && g.length === 0 ? /* @__PURE__ */ m("div", { className: "fbre-container", children: /* @__PURE__ */ B("div", { className: "fbre-remote-loading", children: [
1906
2050
  /* @__PURE__ */ m("div", { className: "fbre-spinner" }),
1907
2051
  /* @__PURE__ */ m("p", { children: "Loading form..." })
1908
- ] }) }) : l && f.length === 0 ? /* @__PURE__ */ m("div", { className: "fbre-container", children: /* @__PURE__ */ k("div", { className: "fbre-remote-error", children: [
2052
+ ] }) }) : d && g.length === 0 ? /* @__PURE__ */ m("div", { className: "fbre-container", children: /* @__PURE__ */ B("div", { className: "fbre-remote-error", children: [
1909
2053
  /* @__PURE__ */ m("p", { children: "Failed to load form" }),
1910
- /* @__PURE__ */ m("p", { className: "fbre-remote-error__detail", children: l }),
2054
+ /* @__PURE__ */ m("p", { className: "fbre-remote-error__detail", children: d }),
1911
2055
  /* @__PURE__ */ m(
1912
2056
  "button",
1913
2057
  {
@@ -1918,39 +2062,40 @@ const Jn = ({
1918
2062
  children: "Retry"
1919
2063
  }
1920
2064
  )
1921
- ] }) }) : f.length === 0 ? null : /* @__PURE__ */ m(
1922
- ye.Provider,
2065
+ ] }) }) : g.length === 0 ? null : /* @__PURE__ */ m(
2066
+ be.Provider,
1923
2067
  {
1924
- value: c,
1925
- children: /* @__PURE__ */ k(
2068
+ value: a,
2069
+ children: /* @__PURE__ */ B(
1926
2070
  "div",
1927
2071
  {
1928
2072
  className: "fbre-container",
1929
- "data-style": S.style ?? "clean",
1930
- "data-mode": D ? "dark" : "light",
1931
- style: Object.keys(B).length > 0 ? B : void 0,
2073
+ "data-style": k.style ?? "clean",
2074
+ "data-mode": q ? "dark" : "light",
2075
+ "data-form-mode": U ? "conversational" : void 0,
2076
+ style: Object.keys(j).length > 0 ? j : void 0,
1932
2077
  children: [
1933
- /* @__PURE__ */ m("div", { className: "fbre-screen-wrapper", children: /* @__PURE__ */ m(Ne, { screenIndex: 0 }) }),
2078
+ /* @__PURE__ */ m("div", { className: "fbre-screen-wrapper", children: /* @__PURE__ */ m(De, { screenIndex: 0 }) }),
1934
2079
  /* @__PURE__ */ m(
1935
- Xn,
2080
+ dt,
1936
2081
  {
1937
- navigation: u,
1938
- loading: d,
1939
- onPrev: M,
1940
- onNext: x,
1941
- onComplete: U,
1942
- nextButtonLabel: $,
1943
- backButtonLabel: J
2082
+ navigation: f,
2083
+ loading: u,
2084
+ onPrev: N,
2085
+ onNext: _,
2086
+ onComplete: I,
2087
+ nextButtonLabel: Y,
2088
+ backButtonLabel: K
1944
2089
  }
1945
2090
  ),
1946
- /* @__PURE__ */ k("div", { className: `fbre-toast${g ? " visible" : ""}`, children: [
1947
- /* @__PURE__ */ m("span", { children: g }),
2091
+ /* @__PURE__ */ B("div", { className: `fbre-toast${h ? " visible" : ""}`, children: [
2092
+ /* @__PURE__ */ m("span", { children: h }),
1948
2093
  /* @__PURE__ */ m(
1949
2094
  "button",
1950
2095
  {
1951
2096
  type: "button",
1952
2097
  className: "fbre-toast__close",
1953
- onClick: N,
2098
+ onClick: E,
1954
2099
  "aria-label": "Dismiss",
1955
2100
  children: "×"
1956
2101
  }
@@ -1961,36 +2106,36 @@ const Jn = ({
1961
2106
  )
1962
2107
  }
1963
2108
  );
1964
- }, Xn = ({
1965
- navigation: e,
2109
+ }, dt = ({
2110
+ navigation: n,
1966
2111
  loading: r,
1967
2112
  onPrev: o,
1968
2113
  onNext: t,
1969
- onComplete: n,
2114
+ onComplete: e,
1970
2115
  nextButtonLabel: s,
1971
- backButtonLabel: i
1972
- }) => /* @__PURE__ */ k("div", { className: "fbre-controls", children: [
1973
- /* @__PURE__ */ m("div", { className: "fbre-controls__left", children: e.canGoBack && /* @__PURE__ */ m(
2116
+ backButtonLabel: c
2117
+ }) => /* @__PURE__ */ B("div", { className: "fbre-controls", children: [
2118
+ /* @__PURE__ */ m("div", { className: "fbre-controls__left", children: n.canGoBack && /* @__PURE__ */ m(
1974
2119
  "button",
1975
2120
  {
1976
2121
  type: "button",
1977
2122
  className: "fbre-btn fbre-btn--back",
1978
2123
  onClick: o,
1979
2124
  disabled: r,
1980
- children: i || "Back"
2125
+ children: c || "Back"
1981
2126
  }
1982
2127
  ) }),
1983
- /* @__PURE__ */ m("div", { className: "fbre-controls__center", children: /* @__PURE__ */ k("span", { className: "fbre-controls__progress", children: [
1984
- e.screenNumber,
2128
+ /* @__PURE__ */ m("div", { className: "fbre-controls__center", children: /* @__PURE__ */ B("span", { className: "fbre-controls__progress", children: [
2129
+ n.screenNumber,
1985
2130
  " / ",
1986
- e.totalScreens
2131
+ n.totalScreens
1987
2132
  ] }) }),
1988
- /* @__PURE__ */ m("div", { className: "fbre-controls__right", children: e.isLastScreen ? /* @__PURE__ */ m(
2133
+ /* @__PURE__ */ m("div", { className: "fbre-controls__right", children: n.isLastScreen ? /* @__PURE__ */ m(
1989
2134
  "button",
1990
2135
  {
1991
2136
  type: "button",
1992
2137
  className: "fbre-btn fbre-btn--complete",
1993
- onClick: n,
2138
+ onClick: e,
1994
2139
  disabled: r,
1995
2140
  children: r ? "Submitting..." : s || "Complete"
1996
2141
  }
@@ -2005,109 +2150,113 @@ const Jn = ({
2005
2150
  }
2006
2151
  ) })
2007
2152
  ] });
2008
- function Kn(e, r, o, t) {
2009
- return !r && !o && !t ? e : {
2010
- ...e,
2011
- ...r && { theme: { ...e.theme, ...r } },
2012
- ...o && { navigation: { ...e.navigation, ...o } },
2013
- ...t && { controls: { ...e.controls, ...t } }
2153
+ function pt(n, r, o, t, e) {
2154
+ return !r && !o && !t && !e ? n : {
2155
+ ...n,
2156
+ ...e && { mode: e },
2157
+ ...r && { theme: { ...n.theme, ...r } },
2158
+ ...o && { navigation: { ...n.navigation, ...o } },
2159
+ ...t && { controls: { ...n.controls, ...t } }
2014
2160
  };
2015
2161
  }
2016
- const nn = ({
2017
- flow: e,
2162
+ const ln = ({
2163
+ flow: n,
2018
2164
  data: r,
2019
- theme: o,
2020
- navigation: t,
2021
- controls: n,
2022
- screenIndex: s,
2165
+ mode: o,
2166
+ theme: t,
2167
+ navigation: e,
2168
+ controls: s,
2169
+ screenIndex: c,
2023
2170
  context: i,
2024
- storeRef: a,
2025
- onFlowComplete: c,
2026
- onScreenChange: d,
2027
- onScreenValidationChange: l,
2028
- apiCtx: u
2171
+ storeRef: l,
2172
+ onFlowComplete: a,
2173
+ onScreenChange: u,
2174
+ onScreenValidationChange: d,
2175
+ apiCtx: f
2029
2176
  }) => {
2030
- const p = ce(null);
2031
- p.current || (p.current = Sn(), p.current.getState().loadFlow(e, r, i)), a && (a.current = p.current), K(() => {
2032
- p.current && p.current.getState().loadFlow(e, r, i);
2033
- }, [e.uuid]), K(() => {
2177
+ const p = Z(null);
2178
+ p.current || (p.current = Tn(), p.current.getState().loadFlow(n, r, i)), l && (l.current = p.current), H(() => {
2179
+ p.current && p.current.getState().loadFlow(n, r, i);
2180
+ }, [n.uuid]), H(() => {
2034
2181
  if (p.current) {
2035
- const g = p.current.getState(), h = Kn(g.config, o, t, n);
2036
- h !== g.config && p.current.setState({ config: h });
2182
+ const v = p.current.getState(), h = pt(v.config, t, e, s, o);
2183
+ h !== v.config && p.current.setState({ config: h });
2037
2184
  }
2038
- }, [o, t, n]);
2039
- const f = i ? JSON.stringify(i) : "";
2040
- K(() => {
2185
+ }, [o, t, e, s]);
2186
+ const y = i ? JSON.stringify(i) : "";
2187
+ H(() => {
2041
2188
  p.current && i && p.current.getState().updateContext(i);
2042
- }, [f]);
2043
- const y = /* @__PURE__ */ m(ye.Provider, { value: p.current, children: /* @__PURE__ */ m(
2044
- Jn,
2189
+ }, [y]);
2190
+ const g = /* @__PURE__ */ m(be.Provider, { value: p.current, children: /* @__PURE__ */ m(
2191
+ it,
2045
2192
  {
2046
- screenIndex: s ?? 0,
2047
- onFlowComplete: c,
2048
- onScreenChange: d,
2049
- onScreenValidationChange: l
2193
+ screenIndex: c ?? 0,
2194
+ onFlowComplete: a,
2195
+ onScreenChange: u,
2196
+ onScreenValidationChange: d
2050
2197
  }
2051
2198
  ) });
2052
- return u ? /* @__PURE__ */ m(en.Provider, { value: u, children: y }) : y;
2053
- }, Qn = ({
2054
- flowId: e,
2199
+ return f ? /* @__PURE__ */ m(an.Provider, { value: f, children: g }) : g;
2200
+ }, ft = ({
2201
+ flowId: n,
2055
2202
  apiEndpoint: r,
2056
2203
  apiKey: o,
2057
2204
  data: t,
2058
- theme: n,
2059
- navigation: s,
2205
+ mode: e,
2206
+ theme: s,
2207
+ navigation: c,
2060
2208
  controls: i,
2061
- screenIndex: a,
2062
- context: c,
2063
- storeRef: d,
2064
- onFlowComplete: l,
2065
- onScreenChange: u,
2209
+ screenIndex: l,
2210
+ context: a,
2211
+ storeRef: u,
2212
+ onFlowComplete: d,
2213
+ onScreenChange: f,
2066
2214
  onScreenValidationChange: p
2067
2215
  }) => {
2068
- const [f, y] = P(null), [g, h] = P(""), [v, b] = P(null);
2069
- return K(() => {
2070
- y(null), h("");
2071
- const w = { apiEndpoint: r, apiKey: o };
2072
- jn(w, e).then((C) => {
2073
- y(C.data), b({
2074
- config: w,
2075
- flowId: C.id,
2076
- flowVersionId: C.versionId,
2077
- tenantId: C.tenantId
2216
+ const [y, g] = J(null), [v, h] = J(""), [b, C] = J(null);
2217
+ return H(() => {
2218
+ g(null), h("");
2219
+ const S = { apiEndpoint: r, apiKey: o };
2220
+ Zn(S, n).then((w) => {
2221
+ g(w.data), C({
2222
+ config: S,
2223
+ flowId: w.id,
2224
+ flowVersionId: w.versionId,
2225
+ tenantId: w.tenantId
2078
2226
  });
2079
- }).catch((C) => h(C.message));
2080
- }, [e, r, o]), g ? /* @__PURE__ */ m("div", { className: "fbre-container", children: /* @__PURE__ */ k("div", { className: "fbre-remote-error", children: [
2227
+ }).catch((w) => h(w.message));
2228
+ }, [n, r, o]), v ? /* @__PURE__ */ m("div", { className: "fbre-container", children: /* @__PURE__ */ B("div", { className: "fbre-remote-error", children: [
2081
2229
  /* @__PURE__ */ m("p", { children: "Failed to load form" }),
2082
- /* @__PURE__ */ m("p", { className: "fbre-remote-error__detail", children: g })
2083
- ] }) }) : !f || !v ? /* @__PURE__ */ m("div", { className: "fbre-container", children: /* @__PURE__ */ k("div", { className: "fbre-remote-loading", children: [
2230
+ /* @__PURE__ */ m("p", { className: "fbre-remote-error__detail", children: v })
2231
+ ] }) }) : !y || !b ? /* @__PURE__ */ m("div", { className: "fbre-container", children: /* @__PURE__ */ B("div", { className: "fbre-remote-loading", children: [
2084
2232
  /* @__PURE__ */ m("div", { className: "fbre-spinner" }),
2085
2233
  /* @__PURE__ */ m("p", { children: "Loading form..." })
2086
2234
  ] }) }) : /* @__PURE__ */ m(
2087
- nn,
2235
+ ln,
2088
2236
  {
2089
- flow: f,
2237
+ flow: y,
2090
2238
  data: t,
2091
- theme: n,
2092
- navigation: s,
2239
+ mode: e,
2240
+ theme: s,
2241
+ navigation: c,
2093
2242
  controls: i,
2094
- screenIndex: a,
2095
- context: c,
2096
- storeRef: d,
2097
- onFlowComplete: l,
2098
- onScreenChange: u,
2243
+ screenIndex: l,
2244
+ context: a,
2245
+ storeRef: u,
2246
+ onFlowComplete: d,
2247
+ onScreenChange: f,
2099
2248
  onScreenValidationChange: p,
2100
- apiCtx: v
2249
+ apiCtx: b
2101
2250
  }
2102
2251
  );
2103
- }, ct = (e) => "sessionEndpoint" in e ? /* @__PURE__ */ m(Wn, { ...e }) : "flowId" in e && e.flowId ? /* @__PURE__ */ m(Qn, { ...e }) : /* @__PURE__ */ m(nn, { ...e });
2252
+ }, wt = (n) => "sessionEndpoint" in n ? /* @__PURE__ */ m(ut, { ...n }) : "flowId" in n && n.flowId ? /* @__PURE__ */ m(ft, { ...n }) : /* @__PURE__ */ m(ln, { ...n });
2104
2253
  export {
2105
- he as ApiError,
2106
- ct as FBRE,
2107
- Tn as TimeoutError,
2108
- rt as addFBREEventListener,
2109
- st as removeFBREEventListener,
2110
- it as useFBREApi,
2111
- L as useFBREStore,
2112
- Ke as useFBREStoreApi
2254
+ ge as ApiError,
2255
+ wt as FBRE,
2256
+ Wn as TimeoutError,
2257
+ bt as addFBREEventListener,
2258
+ Ct as removeFBREEventListener,
2259
+ St as useFBREApi,
2260
+ P as useFBREStore,
2261
+ Ce as useFBREStoreApi
2113
2262
  };