@picked/client 0.0.1-dev.1773878362211 → 0.0.1-dev.1774231221701

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.
Files changed (74) hide show
  1. package/dist/api-BEXzPJHZ.cjs +1 -0
  2. package/dist/api-oudcFuUX.js +37 -0
  3. package/dist/cjs/form/index.js +1 -1
  4. package/dist/cjs/index.js +2 -2
  5. package/dist/cjs/plugins/create-experience/index.js +1 -1
  6. package/dist/cjs/plugins/dynamic-experiences/index.js +1 -1
  7. package/dist/cjs/plugins/experience-browser-storage/index.js +1 -1
  8. package/dist/cjs/plugins/history-browser-storage/index.js +1 -1
  9. package/dist/cjs/plugins/responses-browser-storage/index.js +1 -1
  10. package/dist/cjs/plugins/responses-indexeddb/index.js +1 -1
  11. package/dist/cjs/plugins/single-page-app/index.js +1 -1
  12. package/dist/cjs/plugins/web-components/index.js +1 -1
  13. package/dist/cjs/plugins/window-object/index.js +1 -1
  14. package/dist/cjs/server/index.js +1 -1
  15. package/dist/esm/form/index.js +416 -381
  16. package/dist/esm/index.js +1138 -1204
  17. package/dist/esm/plugins/create-experience/index.js +461 -434
  18. package/dist/esm/plugins/dynamic-experiences/index.js +106 -123
  19. package/dist/esm/plugins/experience-browser-storage/index.js +32 -37
  20. package/dist/esm/plugins/history-browser-storage/index.js +23 -25
  21. package/dist/esm/plugins/responses-browser-storage/index.js +36 -39
  22. package/dist/esm/plugins/responses-indexeddb/index.js +77 -85
  23. package/dist/esm/plugins/single-page-app/index.js +31 -35
  24. package/dist/esm/plugins/web-components/index.js +18 -20
  25. package/dist/esm/plugins/window-object/index.js +9 -9
  26. package/dist/esm/server/index.js +95 -89
  27. package/dist/experience-instance-DZiAwXph.js +481 -0
  28. package/dist/experience-instance-Ddk4Jktn.cjs +1 -0
  29. package/dist/id-Bv44ilEo.cjs +1 -0
  30. package/dist/id-CRqy981z.js +4 -0
  31. package/dist/logger-6z_gb4rA.js +4 -0
  32. package/dist/logger-fbvQC40v.cjs +1 -0
  33. package/dist/object-C82v79xc.js +25 -0
  34. package/dist/object-CUJOjanb.cjs +1 -0
  35. package/dist/rules-logic-B7vJrWyO.js +231 -0
  36. package/dist/rules-logic-CXr4wXcG.cjs +1 -0
  37. package/dist/storage-6Xk0uAxB.js +103 -0
  38. package/dist/storage-B6lQtc4-.cjs +1 -0
  39. package/dist/supports-0XIfd4-R.js +85 -0
  40. package/dist/supports-Dsjg-82e.cjs +1 -0
  41. package/dist/types/entities/field/field.d.ts +1 -1
  42. package/dist/types/entities/field/field.d.ts.map +1 -1
  43. package/dist/types/entities/response/response.d.ts.map +1 -1
  44. package/dist/types/form/create-form.d.ts +13 -3
  45. package/dist/types/form/create-form.d.ts.map +1 -1
  46. package/dist/types/form/create-submit-pipeline.d.ts +4 -4
  47. package/dist/types/form/create-submit-pipeline.d.ts.map +1 -1
  48. package/dist/types/index.d.ts +0 -1
  49. package/dist/types/index.d.ts.map +1 -1
  50. package/dist/types/picked.d.ts +0 -1
  51. package/dist/types/picked.d.ts.map +1 -1
  52. package/dist/types/plugins/create-experience/create-experience.d.ts +21 -26
  53. package/dist/types/plugins/create-experience/create-experience.d.ts.map +1 -1
  54. package/dist/types/plugins/history-browser-storage/plugin.d.ts +2 -2
  55. package/dist/types/plugins/history-browser-storage/plugin.d.ts.map +1 -1
  56. package/package.json +7 -21
  57. package/dist/api-4YC7Dkcf.js +0 -32
  58. package/dist/api-dQTozK5u.cjs +0 -1
  59. package/dist/experience-instance-Bd4kkjE6.js +0 -559
  60. package/dist/experience-instance-UAZPiG2b.cjs +0 -1
  61. package/dist/id-BKIWbSTy.cjs +0 -1
  62. package/dist/id-BW-g3y32.js +0 -6
  63. package/dist/logger-BsmHUUw1.cjs +0 -1
  64. package/dist/logger-C9a75KZn.js +0 -5
  65. package/dist/object-CJssU1Pm.js +0 -28
  66. package/dist/object-mwaxtjLG.cjs +0 -1
  67. package/dist/rules-logic-CZfip-Wl.js +0 -265
  68. package/dist/rules-logic-Cgia6n5p.cjs +0 -1
  69. package/dist/storage-58NoTSsc.cjs +0 -1
  70. package/dist/storage-B2d81EOI.js +0 -244
  71. package/dist/supports-8YT4QKI7.js +0 -95
  72. package/dist/supports-YvpQZxbh.cjs +0 -1
  73. package/dist/types/entities/project/project.d.ts +0 -9
  74. package/dist/types/entities/project/project.d.ts.map +0 -1
@@ -1,393 +1,428 @@
1
- import { e as N } from "../../rules-logic-CZfip-Wl.js";
2
- import { createStore as A, attach as B, createEffect as k, sample as m, createEvent as x, split as $, combine as z } from "effector";
3
- function T(r, t, i) {
4
- const s = r[t];
5
- if (s === void 0) {
6
- r[t] = i;
7
- return;
8
- }
9
- if (Array.isArray(s) && Array.isArray(i) && i.length > 0) {
10
- typeof s[0] == "string" ? r[t] = [...s, ...i].map(String) : typeof s[0] == "number" ? r[t] = [...s, ...i].map(Number) : typeof s[0] == "boolean" ? r[t] = [...s, ...i].map((e) => !!e) : r[t] = i;
11
- return;
12
- }
13
- r[t] = i;
1
+ import { t as e } from "../../rules-logic-B7vJrWyO.js";
2
+ import { attach as t, combine as n, createEffect as r, createEvent as i, createStore as a, sample as o, split as s } from "effector";
3
+ //#region src/form/build-responses.ts
4
+ function c(e, t, n) {
5
+ let r = e[t];
6
+ if (r === void 0) {
7
+ e[t] = n;
8
+ return;
9
+ }
10
+ if (Array.isArray(r) && Array.isArray(n) && n.length > 0) {
11
+ typeof r[0] == "string" ? e[t] = [...r, ...n].map(String) : typeof r[0] == "number" ? e[t] = [...r, ...n].map(Number) : typeof r[0] == "boolean" ? e[t] = [...r, ...n].map((e) => !!e) : e[t] = n;
12
+ return;
13
+ }
14
+ e[t] = n;
14
15
  }
15
- function G(r, t) {
16
- const i = Array.from(t.entries()), s = {};
17
- return r.forEach((e) => {
18
- let p = i.filter(([u]) => u === e.id);
19
- p.length === 0 && (p = [[e.id, ""]]), p.forEach(([, u]) => {
20
- if (u === "") {
21
- T(s, e.id, null);
22
- return;
23
- }
24
- switch (e.type) {
25
- case "text":
26
- case "object":
27
- T(s, e.id, e.multiple ? [String(u)] : String(u));
28
- break;
29
- case "number":
30
- T(s, e.id, e.multiple ? [Number(u)] : Number(u));
31
- break;
32
- case "boolean":
33
- T(
34
- s,
35
- e.id,
36
- e.multiple ? [u === "true"] : u === "true"
37
- );
38
- break;
39
- }
40
- });
41
- }), s;
16
+ function l(e, t) {
17
+ let n = Array.from(t.entries()), r = {};
18
+ return e.forEach((e) => {
19
+ let t = n.filter(([t]) => t === e.id);
20
+ t.length === 0 && (t = [[e.id, ""]]), t.forEach(([, t]) => {
21
+ if (t === "") {
22
+ c(r, e.id, null);
23
+ return;
24
+ }
25
+ switch (e.type) {
26
+ case "text":
27
+ case "object":
28
+ c(r, e.id, e.multiple ? [String(t)] : String(t));
29
+ break;
30
+ case "number":
31
+ c(r, e.id, e.multiple ? [Number(t)] : Number(t));
32
+ break;
33
+ case "boolean":
34
+ c(r, e.id, e.multiple ? [t === "true"] : t === "true");
35
+ break;
36
+ }
37
+ });
38
+ }), r;
42
39
  }
43
- function j(r) {
44
- return Array.isArray(r.options) && r.options.some((t) => "condition" in t);
40
+ //#endregion
41
+ //#region src/form/get-step-fields.ts
42
+ function u(e) {
43
+ return Array.isArray(e.options) && e.options.some((e) => "condition" in e);
45
44
  }
46
- function J(r) {
47
- return r.some((t) => t.condition || j(t));
45
+ function d(e) {
46
+ return e.some((e) => e.condition || u(e));
48
47
  }
49
- async function K(r, t, i) {
50
- return t.length === 0 || !J(t) ? t : (await Promise.all(
51
- t.map(async (e) => {
52
- if (!(e.condition ? await N(r, e.condition, i) : !0))
53
- return null;
54
- if (!Array.isArray(e.options) || !j(e))
55
- return e;
56
- const g = (await Promise.all(
57
- e.options.map(async (o) => o.condition ? await N(r, o.condition, i) ? o : null : o)
58
- )).filter((o) => o !== null);
59
- return g.length === e.options.length ? e : g.length === 0 ? null : { ...e, options: g };
60
- })
61
- )).filter((e) => e !== null);
48
+ async function f(t, n, r) {
49
+ return n.length === 0 || !d(n) ? n : (await Promise.all(n.map(async (n) => {
50
+ if (!(!n.condition || await e(t, n.condition, r))) return null;
51
+ if (!Array.isArray(n.options) || !u(n)) return n;
52
+ let i = (await Promise.all(n.options.map(async (n) => n.condition ? await e(t, n.condition, r) ? n : null : n))).filter((e) => e !== null);
53
+ return i.length === n.options.length ? n : i.length === 0 ? null : {
54
+ ...n,
55
+ options: i
56
+ };
57
+ }))).filter((e) => e !== null);
62
58
  }
63
- function Q(r, t, i) {
64
- const s = A([]), e = B({
65
- source: {
66
- allFields: r.fields.listStore,
67
- fieldIds: t,
68
- staged: i,
69
- committed: r.responses.getAllStore
70
- },
71
- effect: k(
72
- async ({
73
- allFields: p,
74
- fieldIds: u,
75
- staged: g,
76
- committed: v
77
- }) => {
78
- const o = p.filter((d) => u.includes(d.id)), c = { ...v, ...g };
79
- return await K(r, o, { responses: c });
80
- }
81
- )
82
- });
83
- return m({ clock: e.doneData, target: s }), e(), m({
84
- clock: [r.responses.listStore, t, r.fields.listStore, i],
85
- target: e
86
- }), { fieldsStore: s };
59
+ //#endregion
60
+ //#region src/form/create-field-evaluator.ts
61
+ function p(e, n, i) {
62
+ let s = a([]), c = t({
63
+ source: {
64
+ allFields: e.fields.listStore,
65
+ fieldIds: n,
66
+ staged: i,
67
+ committed: e.responses.getAllStore
68
+ },
69
+ effect: r(async ({ allFields: t, fieldIds: n, staged: r, committed: i }) => await f(e, t.filter((e) => n.includes(e.id)), { responses: {
70
+ ...i,
71
+ ...r
72
+ } }))
73
+ });
74
+ return o({
75
+ clock: c.doneData,
76
+ target: s
77
+ }), c(), o({
78
+ clock: [
79
+ e.responses.listStore,
80
+ n,
81
+ e.fields.listStore,
82
+ i
83
+ ],
84
+ target: c
85
+ }), { fieldsStore: s };
87
86
  }
88
- function U(r) {
89
- return r === null || r === "" || Array.isArray(r) && r.length === 0;
87
+ //#endregion
88
+ //#region src/form/create-field-validation.ts
89
+ function m(e) {
90
+ return e === null || e === "" || Array.isArray(e) && e.length === 0;
90
91
  }
91
- function W(r, t, i) {
92
- const s = x(), e = x(), p = A({});
93
- m({
94
- clock: e,
95
- source: p,
96
- fn: (o, { fieldId: c }) => ({ ...o, [c]: !0 }),
97
- target: p
98
- });
99
- const u = A({}), g = u.map(
100
- (o) => Object.values(o).filter((c) => c !== void 0)
101
- ), v = B({
102
- source: {
103
- fields: t,
104
- staged: i,
105
- committed: r.responses.getAllStore
106
- },
107
- effect: async ({
108
- fields: o,
109
- staged: c,
110
- committed: d
111
- }, {
112
- fieldId: l,
113
- value: y,
114
- checkRequired: R
115
- }) => {
116
- const b = o.find((h) => h.id === l);
117
- if (!b) return { fieldId: l, error: null };
118
- if (b.validation && Object.keys(b.validation).length > 0) {
119
- const h = { ...d, ...c }, E = await N(r, b.validation, {
120
- responses: h,
121
- $input: y
122
- });
123
- if (typeof E == "string")
124
- return {
125
- fieldId: l,
126
- error: {
127
- fieldId: l,
128
- userMessage: E,
129
- systemMessage: E,
130
- value: y
131
- }
132
- };
133
- if (E === !1)
134
- return {
135
- fieldId: l,
136
- error: {
137
- fieldId: l,
138
- userMessage: "This field is invalid",
139
- systemMessage: "Field validation rule returned false.",
140
- value: y
141
- }
142
- };
143
- }
144
- return R && b.required && U(y) ? {
145
- fieldId: l,
146
- error: {
147
- fieldId: l,
148
- userMessage: "This field is required",
149
- systemMessage: "Field is required.",
150
- value: y
151
- }
152
- } : { fieldId: l, error: null };
153
- }
154
- });
155
- return m({
156
- clock: s,
157
- source: p,
158
- filter: (o, { fieldId: c }) => o[c] === !0,
159
- fn: (o, { fieldId: c, value: d }) => ({ fieldId: c, value: d, checkRequired: !1 }),
160
- target: v
161
- }), m({
162
- clock: e,
163
- fn: ({ fieldId: o, value: c }) => ({ fieldId: o, value: c, checkRequired: !0 }),
164
- target: v
165
- }), i.on(s, (o, { fieldId: c, value: d }) => ({
166
- ...o,
167
- [c]: d
168
- })), i.on(e, (o, { fieldId: c, value: d }) => ({
169
- ...o,
170
- [c]: d
171
- })), u.on(v.doneData, (o, { fieldId: c, error: d }) => {
172
- if (d === null) {
173
- const l = { ...o };
174
- return delete l[c], l;
175
- }
176
- return { ...o, [c]: d };
177
- }), {
178
- fieldChangeEvent: s,
179
- fieldBlurEvent: e,
180
- touchedStore: p,
181
- fieldErrorsStore: u,
182
- formErrorsStore: g,
183
- stagedValuesStore: i
184
- };
92
+ function h(n, r, s) {
93
+ let c = i(), l = i(), u = a({});
94
+ o({
95
+ clock: l,
96
+ source: u,
97
+ fn: (e, { fieldId: t }) => ({
98
+ ...e,
99
+ [t]: !0
100
+ }),
101
+ target: u
102
+ });
103
+ let d = a({}), f = d.map((e) => Object.values(e).filter((e) => e !== void 0)), p = t({
104
+ source: {
105
+ fields: r,
106
+ staged: s,
107
+ committed: n.responses.getAllStore
108
+ },
109
+ effect: async ({ fields: t, staged: r, committed: i }, { fieldId: a, value: o, checkRequired: s }) => {
110
+ let c = t.find((e) => e.id === a);
111
+ if (!c) return {
112
+ fieldId: a,
113
+ error: null
114
+ };
115
+ if (c.validation && Object.keys(c.validation).length > 0) {
116
+ let t = {
117
+ ...i,
118
+ ...r
119
+ }, s = await e(n, c.validation, {
120
+ responses: t,
121
+ $input: o
122
+ });
123
+ if (typeof s == "string") return {
124
+ fieldId: a,
125
+ error: {
126
+ fieldId: a,
127
+ userMessage: s,
128
+ systemMessage: s,
129
+ value: o
130
+ }
131
+ };
132
+ if (s === !1) return {
133
+ fieldId: a,
134
+ error: {
135
+ fieldId: a,
136
+ userMessage: "This field is invalid",
137
+ systemMessage: "Field validation rule returned false.",
138
+ value: o
139
+ }
140
+ };
141
+ }
142
+ return s && c.required && m(o) ? {
143
+ fieldId: a,
144
+ error: {
145
+ fieldId: a,
146
+ userMessage: "This field is required",
147
+ systemMessage: "Field is required.",
148
+ value: o
149
+ }
150
+ } : {
151
+ fieldId: a,
152
+ error: null
153
+ };
154
+ }
155
+ });
156
+ return o({
157
+ clock: c,
158
+ source: u,
159
+ filter: (e, { fieldId: t }) => e[t] === !0,
160
+ fn: (e, { fieldId: t, value: n }) => ({
161
+ fieldId: t,
162
+ value: n,
163
+ checkRequired: !1
164
+ }),
165
+ target: p
166
+ }), o({
167
+ clock: l,
168
+ fn: ({ fieldId: e, value: t }) => ({
169
+ fieldId: e,
170
+ value: t,
171
+ checkRequired: !0
172
+ }),
173
+ target: p
174
+ }), s.on(c, (e, { fieldId: t, value: n }) => ({
175
+ ...e,
176
+ [t]: n
177
+ })), s.on(l, (e, { fieldId: t, value: n }) => ({
178
+ ...e,
179
+ [t]: n
180
+ })), d.on(p.doneData, (e, { fieldId: t, error: n }) => {
181
+ if (n === null) {
182
+ let n = { ...e };
183
+ return delete n[t], n;
184
+ }
185
+ return {
186
+ ...e,
187
+ [t]: n
188
+ };
189
+ }), {
190
+ fieldChangeEvent: c,
191
+ fieldBlurEvent: l,
192
+ touchedStore: u,
193
+ fieldErrorsStore: d,
194
+ formErrorsStore: f,
195
+ stagedValuesStore: s
196
+ };
185
197
  }
186
- function w(r) {
187
- let t = [];
188
- return { executeFx: k(async (...e) => await r(t, ...e)), register: (e) => (t.push(e), () => {
189
- t = t.filter((p) => p !== e);
190
- }) };
198
+ //#endregion
199
+ //#region src/form/create-submit-pipeline.ts
200
+ function g(e) {
201
+ let t = [];
202
+ return {
203
+ executeFx: r(async (...n) => await e(t, ...n)),
204
+ register: (e) => (t.push(e), () => {
205
+ t = t.filter((t) => t !== e);
206
+ })
207
+ };
191
208
  }
192
- function X({
193
- client: r,
194
- experienceInstance: t,
195
- formId: i,
196
- title: s,
197
- stepStore: e,
198
- fieldsStore: p,
199
- goToNextStep: u
200
- }) {
201
- const g = x(), v = x(), o = x(), c = x(), d = x(), l = A(!1), y = A(!1);
202
- y.on(c, () => !0).on(g, () => !1);
203
- const R = g.map(() => {
204
- }), b = w(async (n, a) => {
205
- await Promise.all(n.map((f) => Promise.resolve(f(a))));
206
- }), h = w(async (n, a) => {
207
- await Promise.all(n.map((f) => Promise.resolve(f(a))));
208
- }), E = w(
209
- async (n, a) => {
210
- let f = a;
211
- for (const F of n) {
212
- const O = await Promise.resolve(F(f));
213
- O !== void 0 && (f = O);
214
- }
215
- return f;
216
- }
217
- ), _ = k(async (n) => {
218
- const a = await r.responses.commit(n);
219
- return { data: n, errors: a.errors };
220
- }), C = B({
221
- source: { step: e, title: s },
222
- mapParams: (n, a) => ({
223
- step: a.step,
224
- title: a.title,
225
- data: n.data
226
- }),
227
- effect: k(
228
- async ({
229
- step: n,
230
- title: a,
231
- data: f
232
- }) => (r.eventBus({
233
- type: "form_submit_success",
234
- form: { id: i, title: a },
235
- experience: t,
236
- step: n ?? void 0
237
- }), f)
238
- )
239
- }), M = B({
240
- source: { step: e, title: s },
241
- mapParams: (n, a) => ({
242
- step: a.step,
243
- title: a.title,
244
- errors: n.errors
245
- }),
246
- effect: k(
247
- async ({
248
- step: n,
249
- title: a,
250
- errors: f
251
- }) => (r.eventBus({
252
- type: "form_submit_error",
253
- form: { id: i, title: a },
254
- exception: { reason: f },
255
- experience: t,
256
- step: n ?? void 0
257
- }), f.forEach((F) => {
258
- r.eventBus({
259
- type: "field_validation_error",
260
- exception: { reason: [F] },
261
- experience: t,
262
- step: n ?? void 0
263
- });
264
- }), f)
265
- )
266
- });
267
- return m({ clock: g, fn: () => !0, target: l }), m({
268
- clock: g,
269
- source: { step: e, title: s },
270
- fn: ({ step: n, title: a }) => ({ formId: i, title: a, step: n }),
271
- target: k(
272
- ({
273
- formId: n,
274
- title: a,
275
- step: f
276
- }) => {
277
- r.eventBus({
278
- type: "form_submit",
279
- form: { id: n, title: a },
280
- experience: t,
281
- step: f ?? void 0
282
- });
283
- }
284
- )
285
- }), m({
286
- clock: g,
287
- source: { stepFields: p },
288
- fn: ({ stepFields: n }, a) => (a.preventDefault(), G(n, new FormData(a.currentTarget))),
289
- target: E.executeFx
290
- }), m({ clock: E.executeFx.doneData, target: _ }), $({
291
- source: _.doneData,
292
- match: { hasErrors: ({ errors: n }) => n.length > 0 },
293
- cases: { hasErrors: M, __: C }
294
- }), m({ clock: C.doneData, target: v }), m({
295
- clock: v,
296
- fn: (n) => ({ data: n, stopNavigation: c }),
297
- target: b.executeFx
298
- }), m({ clock: b.executeFx.done, target: d }), m({
299
- clock: d,
300
- source: y,
301
- filter: (n) => !n,
302
- target: u
303
- }), m({ clock: M.doneData, target: o }), m({ clock: o, target: h.executeFx }), m({
304
- clock: [d, h.executeFx.done],
305
- fn: () => !1,
306
- target: l
307
- }), {
308
- submitEvent: g,
309
- isFormSubmitting: l,
310
- onSubmit: E.register,
311
- onSuccess: b.register,
312
- onError: h.register,
313
- submitStarted: R,
314
- // formErrorEvent is EventCallable<ValidationError[]>, assignable to Event<ValidationError[]>
315
- serverErrorsReceived: o
316
- };
209
+ function _({ client: e, experienceInstance: n, formId: c, title: u, stepStore: d, fieldsStore: f, goToNextStep: p }) {
210
+ let m = i(), h = i(), _ = i(), v = i(), y = i(), b = a(!1), x = a(!1);
211
+ x.on(v, () => !0).on(m, () => !1);
212
+ let S = m.map(() => void 0), C = g(async (e, t) => {
213
+ await Promise.all(e.map((e) => Promise.resolve(e(t))));
214
+ }), w = g(async (e, t) => {
215
+ await Promise.all(e.map((e) => Promise.resolve(e(t))));
216
+ }), T = g(async (e, t) => {
217
+ let n = t;
218
+ for (let t of e) {
219
+ let e = await Promise.resolve(t(n));
220
+ e !== void 0 && (n = e);
221
+ }
222
+ return n;
223
+ }), E = r(async (t) => ({
224
+ data: t,
225
+ errors: (await e.responses.commit(t)).errors
226
+ })), D = t({
227
+ source: {
228
+ step: d,
229
+ title: u
230
+ },
231
+ mapParams: (e, t) => ({
232
+ step: t.step,
233
+ title: t.title,
234
+ data: e.data
235
+ }),
236
+ effect: r(async ({ step: t, title: r, data: i }) => (e.eventBus({
237
+ type: "form_submit_success",
238
+ form: {
239
+ id: c,
240
+ title: r
241
+ },
242
+ experience: n,
243
+ step: t ?? void 0
244
+ }), i))
245
+ }), O = t({
246
+ source: {
247
+ step: d,
248
+ title: u
249
+ },
250
+ mapParams: (e, t) => ({
251
+ step: t.step,
252
+ title: t.title,
253
+ errors: e.errors
254
+ }),
255
+ effect: r(async ({ step: t, title: r, errors: i }) => (e.eventBus({
256
+ type: "form_submit_error",
257
+ form: {
258
+ id: c,
259
+ title: r
260
+ },
261
+ exception: { reason: i },
262
+ experience: n,
263
+ step: t ?? void 0
264
+ }), i.forEach((r) => {
265
+ e.eventBus({
266
+ type: "field_validation_error",
267
+ exception: { reason: [r] },
268
+ experience: n,
269
+ step: t ?? void 0
270
+ });
271
+ }), i))
272
+ });
273
+ return o({
274
+ clock: m,
275
+ fn: () => !0,
276
+ target: b
277
+ }), o({
278
+ clock: m,
279
+ source: {
280
+ step: d,
281
+ title: u
282
+ },
283
+ fn: ({ step: e, title: t }) => ({
284
+ formId: c,
285
+ title: t,
286
+ step: e
287
+ }),
288
+ target: r(({ formId: t, title: r, step: i }) => {
289
+ e.eventBus({
290
+ type: "form_submit",
291
+ form: {
292
+ id: t,
293
+ title: r
294
+ },
295
+ experience: n,
296
+ step: i ?? void 0
297
+ });
298
+ })
299
+ }), o({
300
+ clock: m,
301
+ source: { stepFields: f },
302
+ fn: ({ stepFields: e }, t) => (t.preventDefault(), l(e, new FormData(t.currentTarget))),
303
+ target: T.executeFx
304
+ }), o({
305
+ clock: T.executeFx.doneData,
306
+ target: E
307
+ }), s({
308
+ source: E.doneData,
309
+ match: { hasErrors: ({ errors: e }) => e.length > 0 },
310
+ cases: {
311
+ hasErrors: O,
312
+ __: D
313
+ }
314
+ }), o({
315
+ clock: D.doneData,
316
+ target: h
317
+ }), o({
318
+ clock: h,
319
+ fn: (e) => ({
320
+ data: e,
321
+ stopNavigation: v
322
+ }),
323
+ target: C.executeFx
324
+ }), o({
325
+ clock: C.executeFx.done,
326
+ target: y
327
+ }), o({
328
+ clock: y,
329
+ source: x,
330
+ filter: (e) => !e,
331
+ target: p
332
+ }), o({
333
+ clock: O.doneData,
334
+ target: _
335
+ }), o({
336
+ clock: _,
337
+ target: w.executeFx
338
+ }), o({
339
+ clock: [y, w.executeFx.done],
340
+ fn: () => !1,
341
+ target: b
342
+ }), {
343
+ submitEvent: m,
344
+ isFormSubmitting: b,
345
+ onSubmit: T.register,
346
+ onSuccess: C.register,
347
+ onError: w.register,
348
+ submitStarted: S,
349
+ validationErrorsReceived: _
350
+ };
317
351
  }
318
- function q(r) {
319
- const t = r.currentTarget;
320
- if (t instanceof HTMLInputElement)
321
- return t.type === "checkbox" ? t.checked : t.value;
322
- if (t instanceof HTMLSelectElement || t instanceof HTMLTextAreaElement)
323
- return t.value;
352
+ //#endregion
353
+ //#region src/form/create-form.ts
354
+ function v(e) {
355
+ let t = e.currentTarget;
356
+ if (t instanceof HTMLInputElement) return t.type === "checkbox" ? t.checked : t.value;
357
+ if (t instanceof HTMLSelectElement || t instanceof HTMLTextAreaElement) return t.value;
324
358
  }
325
- function V(r, t, i, s) {
326
- const { client: e, experienceInstance: p } = r, { currentStepStore: u, goToNextStep: g } = p, v = A({}), { fieldsStore: o } = Q(e, s, v), { fieldChangeEvent: c, fieldBlurEvent: d, touchedStore: l, fieldErrorsStore: y, formErrorsStore: R } = W(e, o, v), b = z(
327
- {
328
- fields: o,
329
- responses: e.responses.listStore,
330
- staged: v,
331
- fieldErrors: y,
332
- touched: l
333
- },
334
- ({ fields: f, responses: F, staged: O, fieldErrors: L, touched: H }) => f.map(
335
- (S) => ({
336
- ...S,
337
- // Staged value takes priority (live input); committed response is the fallback
338
- // for fields pre-filled from a previous submission or external update.
339
- value: O[S.id] ?? F.find((D) => D.fieldId === S.id)?.value,
340
- error: L[S.id],
341
- touched: H[S.id] ?? !1,
342
- onChange: (D) => {
343
- const P = q(D);
344
- P !== void 0 && c({ fieldId: S.id, value: P });
345
- },
346
- onBlur: (D) => {
347
- const P = q(D);
348
- P !== void 0 && d({ fieldId: S.id, value: P });
349
- }
350
- })
351
- )
352
- ), {
353
- submitEvent: h,
354
- isFormSubmitting: E,
355
- onSubmit: _,
356
- onSuccess: C,
357
- onError: M,
358
- submitStarted: n,
359
- serverErrorsReceived: a
360
- } = X({
361
- client: e,
362
- experienceInstance: p,
363
- formId: t,
364
- title: i,
365
- stepStore: u,
366
- fieldsStore: o,
367
- goToNextStep: g
368
- });
369
- return m({ clock: n, fn: () => ({}), target: l }), m({ clock: n, fn: () => ({}), target: y }), m({
370
- clock: a,
371
- fn: (f) => Object.fromEntries(f.map((F) => [F.fieldId, F])),
372
- target: y
373
- }), {
374
- form: {
375
- onsubmit: h,
376
- errors: R,
377
- submitting: E,
378
- onSubmit: _,
379
- onSuccess: C,
380
- onError: M
381
- },
382
- fields: b
383
- };
359
+ function y(e, t, r, i) {
360
+ let { client: s, experienceInstance: c } = e, { currentStepStore: l, goToNextStep: u } = c, d = a({}), { fieldsStore: f } = p(s, i, d), { fieldChangeEvent: m, fieldBlurEvent: g, touchedStore: y, fieldErrorsStore: b, formErrorsStore: x } = h(s, f, d), S = n({
361
+ fields: f,
362
+ responses: s.responses.listStore,
363
+ staged: d,
364
+ fieldErrors: b,
365
+ touched: y
366
+ }, ({ fields: e, responses: t, staged: n, fieldErrors: r, touched: i }) => e.map((e) => {
367
+ let a = (t) => {
368
+ let n = v(t);
369
+ n !== void 0 && m({
370
+ fieldId: e.id,
371
+ value: n
372
+ });
373
+ }, o = (t) => {
374
+ let n = v(t);
375
+ n !== void 0 && g({
376
+ fieldId: e.id,
377
+ value: n
378
+ });
379
+ };
380
+ return {
381
+ ...e,
382
+ value: n[e.id] ?? t.find((t) => t.fieldId === e.id)?.value,
383
+ error: r[e.id],
384
+ touched: i[e.id] ?? !1,
385
+ onChange: a,
386
+ onBlur: o,
387
+ props: {
388
+ name: e.id,
389
+ id: e.id,
390
+ oninput: a,
391
+ onblur: o
392
+ }
393
+ };
394
+ })), { submitEvent: C, isFormSubmitting: w, onSubmit: T, onSuccess: E, onError: D, submitStarted: O, validationErrorsReceived: k } = _({
395
+ client: s,
396
+ experienceInstance: c,
397
+ formId: t,
398
+ title: r,
399
+ stepStore: l,
400
+ fieldsStore: f,
401
+ goToNextStep: u
402
+ });
403
+ return o({
404
+ clock: O,
405
+ fn: () => ({}),
406
+ target: y
407
+ }), o({
408
+ clock: O,
409
+ fn: () => ({}),
410
+ target: b
411
+ }), o({
412
+ clock: k,
413
+ fn: (e) => Object.fromEntries(e.map((e) => [e.fieldId, e])),
414
+ target: b
415
+ }), {
416
+ form: {
417
+ props: { onsubmit: C },
418
+ errors: x,
419
+ submitting: w,
420
+ onSubmit: T,
421
+ onSuccess: E,
422
+ onError: D
423
+ },
424
+ fields: S
425
+ };
384
426
  }
385
- export {
386
- G as buildResponsesFromFormData,
387
- Q as createFieldEvaluator,
388
- W as createFieldValidation,
389
- V as createForm,
390
- X as createSubmitPipeline,
391
- q as getEventValue,
392
- K as getStepFields
393
- };
427
+ //#endregion
428
+ export { l as buildResponsesFromFormData, p as createFieldEvaluator, h as createFieldValidation, y as createForm, _ as createSubmitPipeline, v as getEventValue, f as getStepFields };