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

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 (112) hide show
  1. package/dist/{api-CQ1Lb-dB.js → api-4YC7Dkcf.js} +1 -1
  2. package/dist/{api-C90ugp6M.cjs → api-dQTozK5u.cjs} +1 -1
  3. package/dist/cjs/form/index.js +1 -0
  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/server/index.js +1 -1
  13. package/dist/esm/form/index.js +393 -0
  14. package/dist/esm/index.js +684 -770
  15. package/dist/esm/plugins/create-experience/index.js +284 -359
  16. package/dist/esm/plugins/dynamic-experiences/index.js +80 -146
  17. package/dist/esm/plugins/experience-browser-storage/index.js +1 -1
  18. package/dist/esm/plugins/history-browser-storage/index.js +1 -1
  19. package/dist/esm/plugins/responses-browser-storage/index.js +1 -1
  20. package/dist/esm/plugins/responses-indexeddb/index.js +51 -46
  21. package/dist/esm/plugins/single-page-app/index.js +24 -24
  22. package/dist/esm/server/index.js +7 -7
  23. package/dist/experience-instance-Bd4kkjE6.js +559 -0
  24. package/dist/experience-instance-UAZPiG2b.cjs +1 -0
  25. package/dist/{object-JwZ58NOH.js → object-CJssU1Pm.js} +1 -1
  26. package/dist/object-mwaxtjLG.cjs +1 -0
  27. package/dist/rules-logic-CZfip-Wl.js +265 -0
  28. package/dist/rules-logic-Cgia6n5p.cjs +1 -0
  29. package/dist/storage-58NoTSsc.cjs +1 -0
  30. package/dist/{storage-Co_LbKr_.js → storage-B2d81EOI.js} +35 -30
  31. package/dist/types/entities/action/action.d.ts.map +1 -1
  32. package/dist/types/entities/experience/experience.d.ts +31 -46
  33. package/dist/types/entities/experience/experience.d.ts.map +1 -1
  34. package/dist/types/entities/experience-instance/experience-instance.d.ts +2 -2
  35. package/dist/types/entities/experience-instance/experience-instance.d.ts.map +1 -1
  36. package/dist/types/entities/feature/feature.d.ts.map +1 -1
  37. package/dist/types/entities/field/field.d.ts +12 -17
  38. package/dist/types/entities/field/field.d.ts.map +1 -1
  39. package/dist/types/entities/history/history.d.ts.map +1 -1
  40. package/dist/types/entities/project/project.d.ts.map +1 -1
  41. package/dist/types/entities/response/response.d.ts +7 -9
  42. package/dist/types/entities/response/response.d.ts.map +1 -1
  43. package/dist/types/form/build-responses.d.ts +14 -0
  44. package/dist/types/form/build-responses.d.ts.map +1 -0
  45. package/dist/types/form/create-field-evaluator.d.ts +19 -0
  46. package/dist/types/form/create-field-evaluator.d.ts.map +1 -0
  47. package/dist/types/form/create-field-validation.d.ts +44 -0
  48. package/dist/types/form/create-field-validation.d.ts.map +1 -0
  49. package/dist/types/form/create-form.d.ts +56 -0
  50. package/dist/types/form/create-form.d.ts.map +1 -0
  51. package/dist/types/form/create-submit-pipeline.d.ts +58 -0
  52. package/dist/types/form/create-submit-pipeline.d.ts.map +1 -0
  53. package/dist/types/form/get-step-fields.d.ts +5 -0
  54. package/dist/types/form/get-step-fields.d.ts.map +1 -0
  55. package/dist/types/form/index.d.ts +10 -0
  56. package/dist/types/form/index.d.ts.map +1 -0
  57. package/dist/types/index.d.ts +1 -2
  58. package/dist/types/index.d.ts.map +1 -1
  59. package/dist/types/logic-engine.d.ts +2 -8
  60. package/dist/types/logic-engine.d.ts.map +1 -1
  61. package/dist/types/picked.d.ts +23 -41
  62. package/dist/types/picked.d.ts.map +1 -1
  63. package/dist/types/plugins/create-experience/create-experience.d.ts +41 -70
  64. package/dist/types/plugins/create-experience/create-experience.d.ts.map +1 -1
  65. package/dist/types/plugins/create-experience/index.d.ts +1 -1
  66. package/dist/types/plugins/create-experience/index.d.ts.map +1 -1
  67. package/dist/types/plugins/create-experience/plugin.d.ts.map +1 -1
  68. package/dist/types/plugins/dynamic-experiences/plugin.d.ts +5 -20
  69. package/dist/types/plugins/dynamic-experiences/plugin.d.ts.map +1 -1
  70. package/dist/types/plugins/dynamic-experiences/types.d.ts +0 -46
  71. package/dist/types/plugins/dynamic-experiences/types.d.ts.map +1 -1
  72. package/dist/types/plugins/experience-browser-storage/plugin.d.ts +2 -1
  73. package/dist/types/plugins/experience-browser-storage/plugin.d.ts.map +1 -1
  74. package/dist/types/plugins/history-browser-storage/plugin.d.ts +2 -1
  75. package/dist/types/plugins/history-browser-storage/plugin.d.ts.map +1 -1
  76. package/dist/types/plugins/responses-browser-storage/plugin.d.ts +2 -1
  77. package/dist/types/plugins/responses-browser-storage/plugin.d.ts.map +1 -1
  78. package/dist/types/plugins/responses-indexeddb/plugin.d.ts.map +1 -1
  79. package/dist/types/plugins/single-page-app/plugin.d.ts +1 -1
  80. package/dist/types/plugins/single-page-app/plugin.d.ts.map +1 -1
  81. package/dist/types/utils/dom.d.ts +0 -3
  82. package/dist/types/utils/dom.d.ts.map +1 -1
  83. package/dist/types/utils/events.d.ts +2 -2
  84. package/dist/types/utils/events.d.ts.map +1 -1
  85. package/dist/types/utils/global-obj.d.ts +0 -1
  86. package/dist/types/utils/global-obj.d.ts.map +1 -1
  87. package/dist/types/utils/indexed-db.d.ts +2 -1
  88. package/dist/types/utils/indexed-db.d.ts.map +1 -1
  89. package/dist/types/utils/logger.d.ts.map +1 -1
  90. package/dist/types/utils/node-tree/min-max-steps-to-leaf.d.ts.map +1 -1
  91. package/dist/types/utils/node-tree/min-max-steps-to-origin.d.ts.map +1 -1
  92. package/dist/types/utils/node-tree/next-reachable-step-nodes.d.ts +3 -3
  93. package/dist/types/utils/node-tree/next-reachable-step-nodes.d.ts.map +1 -1
  94. package/dist/types/utils/nodes.d.ts +2 -2
  95. package/dist/types/utils/nodes.d.ts.map +1 -1
  96. package/dist/types/utils/object.d.ts +0 -8
  97. package/dist/types/utils/object.d.ts.map +1 -1
  98. package/dist/types/utils/picked-config.d.ts +1 -1
  99. package/dist/types/utils/picked-config.d.ts.map +1 -1
  100. package/dist/types/utils/search-params.d.ts.map +1 -1
  101. package/dist/types/utils/storage.d.ts.map +1 -1
  102. package/package.json +27 -3
  103. package/dist/experience-instance-8P1fJuPC.js +0 -819
  104. package/dist/experience-instance-Bi3-1tP5.cjs +0 -1
  105. package/dist/object-BbFTsGh3.cjs +0 -1
  106. package/dist/storage-Be5xWNPC.cjs +0 -1
  107. package/dist/types/entities/condition/condition.d.ts +0 -17
  108. package/dist/types/entities/condition/condition.d.ts.map +0 -1
  109. package/dist/types/entities/step/step.d.ts +0 -20
  110. package/dist/types/entities/step/step.d.ts.map +0 -1
  111. package/dist/types/utils/key.d.ts +0 -12
  112. package/dist/types/utils/key.d.ts.map +0 -1
@@ -0,0 +1,393 @@
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;
14
+ }
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;
42
+ }
43
+ function j(r) {
44
+ return Array.isArray(r.options) && r.options.some((t) => "condition" in t);
45
+ }
46
+ function J(r) {
47
+ return r.some((t) => t.condition || j(t));
48
+ }
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);
62
+ }
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 };
87
+ }
88
+ function U(r) {
89
+ return r === null || r === "" || Array.isArray(r) && r.length === 0;
90
+ }
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
+ };
185
+ }
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
+ }) };
191
+ }
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
+ };
317
+ }
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;
324
+ }
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
+ };
384
+ }
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
+ };