@picked/client 0.0.50-next.4 → 0.0.51-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{api-C2lg7yBn.cjs → api-A3gUhQJc.cjs} +1 -1
- package/dist/{api-CHaIe0uL.js → api-Brluf3C1.js} +1 -1
- package/dist/cjs/form/index.js +1 -0
- package/dist/cjs/index.js +2 -2
- package/dist/cjs/plugins/create-experience/index.js +1 -1
- package/dist/cjs/plugins/dynamic-experiences/index.js +1 -1
- package/dist/cjs/plugins/experience-browser-storage/index.js +1 -1
- package/dist/cjs/plugins/history-browser-storage/index.js +1 -1
- package/dist/cjs/plugins/responses-browser-storage/index.js +1 -1
- package/dist/cjs/plugins/responses-indexeddb/index.js +1 -1
- package/dist/cjs/plugins/single-page-app/index.js +1 -1
- package/dist/cjs/server/index.js +1 -1
- package/dist/esm/form/index.js +466 -0
- package/dist/esm/index.js +330 -321
- package/dist/esm/plugins/create-experience/index.js +25 -19
- package/dist/esm/plugins/dynamic-experiences/index.js +1 -1
- package/dist/esm/plugins/experience-browser-storage/index.js +1 -1
- package/dist/esm/plugins/history-browser-storage/index.js +1 -1
- package/dist/esm/plugins/responses-browser-storage/index.js +1 -1
- package/dist/esm/plugins/responses-indexeddb/index.js +5 -9
- package/dist/esm/plugins/single-page-app/index.js +4 -4
- package/dist/esm/server/index.js +1 -1
- package/dist/experience-instance-CIbQp9D7.js +481 -0
- package/dist/experience-instance-Dri5yAp1.cjs +1 -0
- package/dist/{object-Clj5zVr1.js → object-C82v79xc.js} +2 -1
- package/dist/object-CUJOjanb.cjs +1 -0
- package/dist/rules-logic-BIkBWZmf.js +233 -0
- package/dist/rules-logic-DDxCiq4P.cjs +1 -0
- package/dist/{storage-DyxpJ0pg.js → storage-6Xk0uAxB.js} +3 -1
- package/dist/storage-B6lQtc4-.cjs +1 -0
- package/dist/types/entities/action/action.d.ts.map +1 -1
- package/dist/types/entities/experience/experience.d.ts +10 -10
- package/dist/types/entities/experience/experience.d.ts.map +1 -1
- package/dist/types/entities/experience-instance/experience-instance.d.ts.map +1 -1
- package/dist/types/entities/feature/feature.d.ts.map +1 -1
- package/dist/types/entities/field/field.d.ts +11 -8
- package/dist/types/entities/field/field.d.ts.map +1 -1
- package/dist/types/entities/history/history.d.ts.map +1 -1
- package/dist/types/entities/response/response.d.ts.map +1 -1
- package/dist/types/exports.d.ts +0 -1
- package/dist/types/exports.d.ts.map +1 -1
- package/dist/types/form/build-responses.d.ts +14 -0
- package/dist/types/form/build-responses.d.ts.map +1 -0
- package/dist/types/form/create-field-evaluator.d.ts +19 -0
- package/dist/types/form/create-field-evaluator.d.ts.map +1 -0
- package/dist/types/form/create-field-validation.d.ts +59 -0
- package/dist/types/form/create-field-validation.d.ts.map +1 -0
- package/dist/types/form/create-form.d.ts +96 -0
- package/dist/types/form/create-form.d.ts.map +1 -0
- package/dist/types/form/create-submit-pipeline.d.ts +58 -0
- package/dist/types/form/create-submit-pipeline.d.ts.map +1 -0
- package/dist/types/form/get-step-fields.d.ts +5 -0
- package/dist/types/form/get-step-fields.d.ts.map +1 -0
- package/dist/types/form/index.d.ts +10 -0
- package/dist/types/form/index.d.ts.map +1 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/logic-engine.d.ts +12 -10
- package/dist/types/logic-engine.d.ts.map +1 -1
- package/dist/types/picked.d.ts +4 -5
- package/dist/types/picked.d.ts.map +1 -1
- package/dist/types/plugins/create-experience/create-experience.d.ts +24 -22
- package/dist/types/plugins/create-experience/create-experience.d.ts.map +1 -1
- package/dist/types/plugins/create-experience/index.d.ts +1 -1
- package/dist/types/plugins/create-experience/index.d.ts.map +1 -1
- package/dist/types/plugins/experience-browser-storage/plugin.d.ts +2 -1
- package/dist/types/plugins/experience-browser-storage/plugin.d.ts.map +1 -1
- package/dist/types/plugins/history-browser-storage/plugin.d.ts +1 -0
- package/dist/types/plugins/history-browser-storage/plugin.d.ts.map +1 -1
- package/dist/types/plugins/responses-browser-storage/plugin.d.ts +2 -1
- package/dist/types/plugins/responses-browser-storage/plugin.d.ts.map +1 -1
- package/dist/types/plugins/responses-indexeddb/plugin.d.ts.map +1 -1
- package/dist/types/plugins/single-page-app/plugin.d.ts +1 -1
- package/dist/types/plugins/single-page-app/plugin.d.ts.map +1 -1
- package/dist/types/utils/dom.d.ts +0 -3
- package/dist/types/utils/dom.d.ts.map +1 -1
- package/dist/types/utils/events.d.ts +1 -1
- package/dist/types/utils/events.d.ts.map +1 -1
- package/dist/types/utils/global-obj.d.ts +0 -1
- package/dist/types/utils/global-obj.d.ts.map +1 -1
- package/dist/types/utils/indexed-db.d.ts +2 -1
- package/dist/types/utils/indexed-db.d.ts.map +1 -1
- package/dist/types/utils/logger.d.ts.map +1 -1
- package/dist/types/utils/node-tree/get-next-node-from-condition.d.ts +3 -0
- package/dist/types/utils/node-tree/get-next-node-from-condition.d.ts.map +1 -0
- package/dist/types/utils/node-tree/min-max-steps-to-leaf.d.ts.map +1 -1
- package/dist/types/utils/node-tree/min-max-steps-to-origin.d.ts.map +1 -1
- package/dist/types/utils/node-tree/next-reachable-step-nodes.d.ts.map +1 -1
- package/dist/types/utils/nodes.d.ts +2 -2
- package/dist/types/utils/nodes.d.ts.map +1 -1
- package/dist/types/utils/object.d.ts +0 -8
- package/dist/types/utils/object.d.ts.map +1 -1
- package/dist/types/utils/picked-config.d.ts +1 -1
- package/dist/types/utils/picked-config.d.ts.map +1 -1
- package/dist/types/utils/rules-logic.d.ts +31 -0
- package/dist/types/utils/rules-logic.d.ts.map +1 -1
- package/dist/types/utils/search-params.d.ts.map +1 -1
- package/dist/types/utils/storage.d.ts.map +1 -1
- package/package.json +43 -7
- package/dist/experience-instance-BRpI9I4s.js +0 -710
- package/dist/experience-instance-BUTnwbSJ.cjs +0 -1
- package/dist/object-BReQiaSS.cjs +0 -1
- package/dist/storage-BFjb8azI.cjs +0 -1
- package/dist/types/entities/project/project.d.ts +0 -9
- package/dist/types/entities/project/project.d.ts.map +0 -1
- package/dist/types/utils/get-step-fields.d.ts +0 -4
- package/dist/types/utils/get-step-fields.d.ts.map +0 -1
- package/dist/types/utils/node-tree/get-next-node-from-conditional.d.ts +0 -3
- package/dist/types/utils/node-tree/get-next-node-from-conditional.d.ts.map +0 -1
- /package/dist/{id-CIbS4P60.cjs → id-Bv44ilEo.cjs} +0 -0
- /package/dist/{id-BniPxOdF.js → id-CRqy981z.js} +0 -0
|
@@ -0,0 +1,466 @@
|
|
|
1
|
+
import { t as e } from "../../rules-logic-BIkBWZmf.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;
|
|
15
|
+
}
|
|
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;
|
|
39
|
+
}
|
|
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);
|
|
44
|
+
}
|
|
45
|
+
function d(e) {
|
|
46
|
+
return e.some((e) => e.condition || u(e));
|
|
47
|
+
}
|
|
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);
|
|
58
|
+
}
|
|
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 };
|
|
86
|
+
}
|
|
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;
|
|
91
|
+
}
|
|
92
|
+
function h(n, r, s) {
|
|
93
|
+
let c = i(), l = i(), u = i(), d = a({});
|
|
94
|
+
o({
|
|
95
|
+
clock: u,
|
|
96
|
+
source: d,
|
|
97
|
+
fn: (e, { fieldId: t }) => ({
|
|
98
|
+
...e,
|
|
99
|
+
[t]: !0
|
|
100
|
+
}),
|
|
101
|
+
target: d
|
|
102
|
+
});
|
|
103
|
+
let f = a({}), p = f.map((e) => Object.values(e).filter((e) => e !== void 0)), h = 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: d,
|
|
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: h
|
|
166
|
+
}), o({
|
|
167
|
+
clock: l,
|
|
168
|
+
source: d,
|
|
169
|
+
filter: (e, { fieldId: t }) => e[t] === !0,
|
|
170
|
+
fn: (e, { fieldId: t, value: n }) => ({
|
|
171
|
+
fieldId: t,
|
|
172
|
+
value: n,
|
|
173
|
+
checkRequired: !1
|
|
174
|
+
}),
|
|
175
|
+
target: h
|
|
176
|
+
}), o({
|
|
177
|
+
clock: u,
|
|
178
|
+
fn: ({ fieldId: e, value: t }) => ({
|
|
179
|
+
fieldId: e,
|
|
180
|
+
value: t,
|
|
181
|
+
checkRequired: !0
|
|
182
|
+
}),
|
|
183
|
+
target: h
|
|
184
|
+
}), s.on(c, (e, { fieldId: t, value: n }) => ({
|
|
185
|
+
...e,
|
|
186
|
+
[t]: n
|
|
187
|
+
})), s.on(l, (e, { fieldId: t, value: n }) => ({
|
|
188
|
+
...e,
|
|
189
|
+
[t]: n
|
|
190
|
+
})), s.on(u, (e, { fieldId: t, value: n }) => ({
|
|
191
|
+
...e,
|
|
192
|
+
[t]: n
|
|
193
|
+
})), f.on(h.doneData, (e, { fieldId: t, error: n }) => {
|
|
194
|
+
if (n === null) {
|
|
195
|
+
let n = { ...e };
|
|
196
|
+
return delete n[t], n;
|
|
197
|
+
}
|
|
198
|
+
return {
|
|
199
|
+
...e,
|
|
200
|
+
[t]: n
|
|
201
|
+
};
|
|
202
|
+
}), {
|
|
203
|
+
fieldInputEvent: c,
|
|
204
|
+
fieldChangeEvent: l,
|
|
205
|
+
fieldBlurEvent: u,
|
|
206
|
+
touchedStore: d,
|
|
207
|
+
fieldErrorsStore: f,
|
|
208
|
+
formErrorsStore: p,
|
|
209
|
+
stagedValuesStore: s
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
//#endregion
|
|
213
|
+
//#region src/form/create-submit-pipeline.ts
|
|
214
|
+
function g(e) {
|
|
215
|
+
let t = [];
|
|
216
|
+
return {
|
|
217
|
+
executeFx: r(async (...n) => await e(t, ...n)),
|
|
218
|
+
register: (e) => (t.push(e), () => {
|
|
219
|
+
t = t.filter((t) => t !== e);
|
|
220
|
+
})
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
function _({ client: e, experienceInstance: n, formId: c, title: u, stepStore: d, fieldsStore: f, goToNextStep: p }) {
|
|
224
|
+
let m = i(), h = i(), _ = i(), v = i(), y = i(), b = a(!1), x = a(!1);
|
|
225
|
+
x.on(v, () => !0).on(m, () => !1);
|
|
226
|
+
let S = m.map(() => void 0), C = g(async (e, t) => {
|
|
227
|
+
await Promise.all(e.map((e) => Promise.resolve(e(t))));
|
|
228
|
+
}), w = g(async (e, t) => {
|
|
229
|
+
await Promise.all(e.map((e) => Promise.resolve(e(t))));
|
|
230
|
+
}), T = g(async (e, t) => {
|
|
231
|
+
let n = t;
|
|
232
|
+
for (let t of e) {
|
|
233
|
+
let e = await Promise.resolve(t(n));
|
|
234
|
+
e !== void 0 && (n = e);
|
|
235
|
+
}
|
|
236
|
+
return n;
|
|
237
|
+
}), E = r(async (t) => ({
|
|
238
|
+
data: t,
|
|
239
|
+
errors: (await e.responses.commit(t)).errors
|
|
240
|
+
})), D = t({
|
|
241
|
+
source: {
|
|
242
|
+
step: d,
|
|
243
|
+
title: u
|
|
244
|
+
},
|
|
245
|
+
mapParams: (e, t) => ({
|
|
246
|
+
step: t.step,
|
|
247
|
+
title: t.title,
|
|
248
|
+
data: e.data
|
|
249
|
+
}),
|
|
250
|
+
effect: r(async ({ step: t, title: r, data: i }) => (e.eventBus({
|
|
251
|
+
type: "form_submit_success",
|
|
252
|
+
form: {
|
|
253
|
+
id: c,
|
|
254
|
+
title: r
|
|
255
|
+
},
|
|
256
|
+
experience: n,
|
|
257
|
+
step: t ?? void 0
|
|
258
|
+
}), i))
|
|
259
|
+
}), O = t({
|
|
260
|
+
source: {
|
|
261
|
+
step: d,
|
|
262
|
+
title: u
|
|
263
|
+
},
|
|
264
|
+
mapParams: (e, t) => ({
|
|
265
|
+
step: t.step,
|
|
266
|
+
title: t.title,
|
|
267
|
+
errors: e.errors
|
|
268
|
+
}),
|
|
269
|
+
effect: r(async ({ step: t, title: r, errors: i }) => (e.eventBus({
|
|
270
|
+
type: "form_submit_error",
|
|
271
|
+
form: {
|
|
272
|
+
id: c,
|
|
273
|
+
title: r
|
|
274
|
+
},
|
|
275
|
+
exception: { reason: i },
|
|
276
|
+
experience: n,
|
|
277
|
+
step: t ?? void 0
|
|
278
|
+
}), i.forEach((r) => {
|
|
279
|
+
e.eventBus({
|
|
280
|
+
type: "field_validation_error",
|
|
281
|
+
exception: { reason: [r] },
|
|
282
|
+
experience: n,
|
|
283
|
+
step: t ?? void 0
|
|
284
|
+
});
|
|
285
|
+
}), i))
|
|
286
|
+
});
|
|
287
|
+
return o({
|
|
288
|
+
clock: m,
|
|
289
|
+
fn: () => !0,
|
|
290
|
+
target: b
|
|
291
|
+
}), o({
|
|
292
|
+
clock: m,
|
|
293
|
+
source: {
|
|
294
|
+
step: d,
|
|
295
|
+
title: u
|
|
296
|
+
},
|
|
297
|
+
fn: ({ step: e, title: t }) => ({
|
|
298
|
+
formId: c,
|
|
299
|
+
title: t,
|
|
300
|
+
step: e
|
|
301
|
+
}),
|
|
302
|
+
target: r(({ formId: t, title: r, step: i }) => {
|
|
303
|
+
e.eventBus({
|
|
304
|
+
type: "form_submit",
|
|
305
|
+
form: {
|
|
306
|
+
id: t,
|
|
307
|
+
title: r
|
|
308
|
+
},
|
|
309
|
+
experience: n,
|
|
310
|
+
step: i ?? void 0
|
|
311
|
+
});
|
|
312
|
+
})
|
|
313
|
+
}), o({
|
|
314
|
+
clock: m,
|
|
315
|
+
source: { stepFields: f },
|
|
316
|
+
fn: ({ stepFields: e }, t) => (t.preventDefault(), l(e, new FormData(t.currentTarget))),
|
|
317
|
+
target: T.executeFx
|
|
318
|
+
}), o({
|
|
319
|
+
clock: T.executeFx.doneData,
|
|
320
|
+
target: E
|
|
321
|
+
}), s({
|
|
322
|
+
source: E.doneData,
|
|
323
|
+
match: { hasErrors: ({ errors: e }) => e.length > 0 },
|
|
324
|
+
cases: {
|
|
325
|
+
hasErrors: O,
|
|
326
|
+
__: D
|
|
327
|
+
}
|
|
328
|
+
}), o({
|
|
329
|
+
clock: D.doneData,
|
|
330
|
+
target: h
|
|
331
|
+
}), o({
|
|
332
|
+
clock: h,
|
|
333
|
+
fn: (e) => ({
|
|
334
|
+
data: e,
|
|
335
|
+
stopNavigation: v
|
|
336
|
+
}),
|
|
337
|
+
target: C.executeFx
|
|
338
|
+
}), o({
|
|
339
|
+
clock: C.executeFx.done,
|
|
340
|
+
target: y
|
|
341
|
+
}), o({
|
|
342
|
+
clock: y,
|
|
343
|
+
source: x,
|
|
344
|
+
filter: (e) => !e,
|
|
345
|
+
target: p
|
|
346
|
+
}), o({
|
|
347
|
+
clock: O.doneData,
|
|
348
|
+
target: _
|
|
349
|
+
}), o({
|
|
350
|
+
clock: _,
|
|
351
|
+
target: w.executeFx
|
|
352
|
+
}), o({
|
|
353
|
+
clock: [y, w.executeFx.done],
|
|
354
|
+
fn: () => !1,
|
|
355
|
+
target: b
|
|
356
|
+
}), {
|
|
357
|
+
submitEvent: m,
|
|
358
|
+
isFormSubmitting: b,
|
|
359
|
+
onBeforeSubmit: T.register,
|
|
360
|
+
onSuccess: C.register,
|
|
361
|
+
onError: w.register,
|
|
362
|
+
submitStarted: S,
|
|
363
|
+
validationErrorsReceived: _
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
//#endregion
|
|
367
|
+
//#region src/form/create-form.ts
|
|
368
|
+
function v(e) {
|
|
369
|
+
let t = e.currentTarget;
|
|
370
|
+
if (t instanceof HTMLInputElement) return t.type === "checkbox" ? t.checked : t.value;
|
|
371
|
+
if (t instanceof HTMLSelectElement || t instanceof HTMLTextAreaElement) return t.value;
|
|
372
|
+
}
|
|
373
|
+
function y(e, t, r, i) {
|
|
374
|
+
let { client: s, experienceInstance: c } = e, { currentStepStore: l, goToNextStep: u } = c, d = n(l, c, (e, t) => ({
|
|
375
|
+
stepId: e?.id,
|
|
376
|
+
experienceId: t.id
|
|
377
|
+
})), f = a({}), { fieldsStore: m } = p(s, i, f);
|
|
378
|
+
o({
|
|
379
|
+
clock: m,
|
|
380
|
+
source: f,
|
|
381
|
+
fn: (e, t) => {
|
|
382
|
+
let n = !1, r = { ...e };
|
|
383
|
+
for (let e of t) e.defaultValue != null && !(e.id in r) && (r[e.id] = e.defaultValue, n = !0);
|
|
384
|
+
return n ? r : e;
|
|
385
|
+
},
|
|
386
|
+
target: f
|
|
387
|
+
});
|
|
388
|
+
let { fieldInputEvent: g, fieldChangeEvent: y, fieldBlurEvent: b, touchedStore: x, fieldErrorsStore: S, formErrorsStore: C } = h(s, m, f), w = n({
|
|
389
|
+
fields: m,
|
|
390
|
+
responses: s.responses.listStore,
|
|
391
|
+
staged: f,
|
|
392
|
+
fieldErrors: S,
|
|
393
|
+
touched: x,
|
|
394
|
+
experienceAndStepId: d
|
|
395
|
+
}, ({ fields: e, responses: t, staged: n, fieldErrors: r, touched: i, experienceAndStepId: a }) => e.map((e) => {
|
|
396
|
+
let o = (t) => {
|
|
397
|
+
let n = v(t);
|
|
398
|
+
n !== void 0 && g({
|
|
399
|
+
fieldId: e.id,
|
|
400
|
+
value: n
|
|
401
|
+
});
|
|
402
|
+
}, s = (t) => {
|
|
403
|
+
let n = v(t);
|
|
404
|
+
n !== void 0 && y({
|
|
405
|
+
fieldId: e.id,
|
|
406
|
+
value: n
|
|
407
|
+
});
|
|
408
|
+
}, c = (t) => {
|
|
409
|
+
let n = v(t);
|
|
410
|
+
n !== void 0 && b({
|
|
411
|
+
fieldId: e.id,
|
|
412
|
+
value: n
|
|
413
|
+
});
|
|
414
|
+
}, l = n[e.id] ?? t.find((t) => t.fieldId === e.id)?.value ?? e.defaultValue, u = r[e.id], d = e.type === "number" ? "number" : "text", f = e.type === "boolean" ? "checkbox" : d, { experienceId: p, stepId: m } = a, h = `${p}-${m ?? "step"}-${e.id}`;
|
|
415
|
+
return {
|
|
416
|
+
...e,
|
|
417
|
+
value: l,
|
|
418
|
+
error: u,
|
|
419
|
+
touched: i[e.id] ?? !1,
|
|
420
|
+
props: {
|
|
421
|
+
id: h,
|
|
422
|
+
name: e.name,
|
|
423
|
+
value: l,
|
|
424
|
+
type: f,
|
|
425
|
+
required: e.required,
|
|
426
|
+
placeholder: e.placeholder,
|
|
427
|
+
oninput: o,
|
|
428
|
+
onchange: s,
|
|
429
|
+
onblur: c
|
|
430
|
+
}
|
|
431
|
+
};
|
|
432
|
+
})), { submitEvent: T, isFormSubmitting: E, onBeforeSubmit: D, onSuccess: O, onError: k, submitStarted: A, validationErrorsReceived: j } = _({
|
|
433
|
+
client: s,
|
|
434
|
+
experienceInstance: c,
|
|
435
|
+
formId: t,
|
|
436
|
+
title: r,
|
|
437
|
+
stepStore: l,
|
|
438
|
+
fieldsStore: m,
|
|
439
|
+
goToNextStep: u
|
|
440
|
+
});
|
|
441
|
+
return o({
|
|
442
|
+
clock: A,
|
|
443
|
+
fn: () => ({}),
|
|
444
|
+
target: x
|
|
445
|
+
}), o({
|
|
446
|
+
clock: A,
|
|
447
|
+
fn: () => ({}),
|
|
448
|
+
target: S
|
|
449
|
+
}), o({
|
|
450
|
+
clock: j,
|
|
451
|
+
fn: (e) => Object.fromEntries(e.map((e) => [e.fieldId, e])),
|
|
452
|
+
target: S
|
|
453
|
+
}), {
|
|
454
|
+
form: {
|
|
455
|
+
props: { onsubmit: T },
|
|
456
|
+
errors: C,
|
|
457
|
+
submitting: E,
|
|
458
|
+
onBeforeSubmit: D,
|
|
459
|
+
onSuccess: O,
|
|
460
|
+
onError: k
|
|
461
|
+
},
|
|
462
|
+
fields: w
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
//#endregion
|
|
466
|
+
export { l as buildResponsesFromFormData, p as createFieldEvaluator, h as createFieldValidation, y as createForm, _ as createSubmitPipeline, v as getEventValue, f as getStepFields };
|