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

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-WKe5XBeR.cjs +1 -0
  2. package/dist/api-ZK-H-MlI.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 +425 -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 +0 -4
  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,434 +1,425 @@
1
- import { g as p } from "../../../id-BW-g3y32.js";
2
- const a = {
3
- serialize(e) {
4
- return JSON.stringify(e);
5
- },
6
- deserialize(e) {
7
- return JSON.parse(e);
8
- }
9
- }, b = (e) => ({
10
- name: "create-experience",
11
- setup: (d) => {
12
- e.experiences.forEach((o) => {
13
- const n = o.serialize(), r = a.deserialize(n);
14
- r.component = o.component, d.registerExperience(r), r.fields.forEach((f) => {
15
- d.registerField(f);
16
- });
17
- });
18
- }
19
- }), y = (e, d) => ({
20
- id: p("node"),
21
- experience: d,
22
- type: "action",
23
- action: e.action,
24
- addNext(n) {
25
- if (!n.node) throw new Error("Cannot connect to node");
26
- const r = c(
27
- { sourceNode: this, destinationNode: n.node, sourceNodeHandle: null },
28
- d
29
- );
30
- d.edges.push(r);
31
- },
32
- onSuccess(n) {
33
- if (!n.node) throw new Error("Cannot connect to node");
34
- const r = c(
35
- { sourceNode: this, destinationNode: n.node, sourceNodeHandle: "true" },
36
- d
37
- );
38
- d.edges.push(r);
39
- },
40
- onFail(n) {
41
- if (!n.node) throw new Error("Cannot connect to node");
42
- const r = c(
43
- { sourceNode: this, destinationNode: n.node, sourceNodeHandle: "false" },
44
- d
45
- );
46
- d.edges.push(r);
47
- },
48
- serialize() {
49
- return a.serialize({
50
- id: this.id,
51
- type: this.type,
52
- action: this.action
53
- });
54
- }
55
- }), x = (e) => ({
56
- id: e.id ?? p("step"),
57
- label: e.label,
58
- fields: e.fields ?? [],
59
- addField(d) {
60
- const o = "serialize" in d ? d : N(d);
61
- return this.fields.includes(o) || this.fields.push(o), o;
62
- }
63
- }), z = (e, d) => {
64
- const o = {
65
- id: e.id ?? p("step"),
66
- label: e.label,
67
- experience: d,
68
- fields: e.fields ?? [],
69
- node: null,
70
- nextStep(n) {
71
- return this.experience.addStep(n, this);
72
- },
73
- nextConditional(n) {
74
- return this.experience.addConditional(n, this);
75
- },
76
- addNextExperience(n) {
77
- return this.experience.addExperience(n, this);
78
- },
79
- addField(n) {
80
- return this.experience.addField(n, this);
81
- },
82
- serialize() {
83
- return a.serialize({
84
- id: this.id,
85
- label: this.label,
86
- fieldIds: this.fields.map((n) => n.id)
87
- });
88
- }
89
- };
90
- return h({ step: o, type: "step" }, d), o;
91
- }, h = (e, d) => {
92
- const o = {
93
- id: p("node"),
94
- experience: d
95
- };
96
- if (e.type === "step") {
97
- const r = {
98
- ...o,
99
- type: "step",
100
- connectedStep: e.step,
101
- serialize() {
102
- return a.serialize({
103
- id: this.id,
104
- type: this.type,
105
- stepId: this.connectedStep.id,
106
- label: this.connectedStep.label
107
- });
108
- }
109
- };
110
- return r.connectedStep.node = r, r;
111
- }
112
- if (e.type === "conditional") {
113
- const r = {
114
- ...o,
115
- type: "conditional",
116
- connectedConditional: e.conditional,
117
- serialize() {
118
- return a.serialize({
119
- id: this.id,
120
- type: this.type,
121
- conditionalId: this.connectedConditional.id
122
- });
123
- }
124
- };
125
- return r.connectedConditional.node = r, r;
126
- }
127
- return e.type === "experience" ? {
128
- ...o,
129
- type: "experience",
130
- connectedExperience: e.experience,
131
- serialize() {
132
- return a.serialize({
133
- id: this.id,
134
- type: this.type,
135
- experienceId: this.connectedExperience.id
136
- });
137
- }
138
- } : {
139
- ...o,
140
- type: "origin",
141
- serialize() {
142
- return a.serialize({
143
- id: this.id,
144
- type: this.type
145
- });
146
- }
147
- };
148
- }, c = (e, d) => ({
149
- id: p("edge"),
150
- sourceNode: e.sourceNode,
151
- sourceNodeHandle: e.sourceNodeHandle,
152
- destinationNode: e.destinationNode,
153
- experience: d,
154
- serialize() {
155
- return a.serialize({
156
- id: this.id,
157
- sourceNodeHandle: this.sourceNodeHandle ?? void 0,
158
- sourceNodeId: this.sourceNode.id,
159
- destinationNodeId: this.destinationNode.id
160
- });
161
- }
162
- }), g = (e, d) => {
163
- const o = {
164
- id: p("conditional"),
165
- label: e.label,
166
- condition: e.condition,
167
- node: null,
168
- experience: d,
169
- addTrue(n) {
170
- if (!this.node || !n.node)
171
- throw new Error("todo no node");
172
- const r = c(
173
- { sourceNode: this.node, destinationNode: n.node, sourceNodeHandle: "true" },
174
- this.experience
175
- );
176
- this.experience.edges.push(r);
177
- },
178
- addFalse(n) {
179
- if (!this.node || !n.node)
180
- throw new Error("todo no node");
181
- const r = c(
182
- { sourceNode: this.node, destinationNode: n.node, sourceNodeHandle: "false" },
183
- this.experience
184
- );
185
- this.experience.edges.push(r);
186
- },
187
- serialize() {
188
- return a.serialize({
189
- id: this.id,
190
- label: this.label,
191
- condition: this.condition
192
- });
193
- }
194
- };
195
- return h({ conditional: o, type: "conditional" }, d), o;
196
- }, N = (e) => ({
197
- id: e.id,
198
- name: e.name,
199
- type: e.type,
200
- label: e.label,
201
- placeholder: e.placeholder,
202
- description: e.description,
203
- helpText: e.helpText,
204
- defaultValue: e.defaultValue ?? null,
205
- multiple: e.multiple,
206
- validation: e.validation ?? {},
207
- condition: e.condition,
208
- required: e.required,
209
- options: Array.isArray(e.options) ? e.options.map(({ id: o, ...n }) => ({
210
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- defensive fallback in case option id is omitted at runtime
211
- id: o ?? p("option"),
212
- ...n
213
- })) : null,
214
- policies: e.policies,
215
- // eslint-disable-next-line sonarjs/cognitive-complexity -- this function handles all field types and subtypes; splitting it would increase indirection without improving clarity. Addressed in PR #1372
216
- serialize() {
217
- const o = {
218
- id: this.id,
219
- name: this.name,
220
- label: this.label,
221
- placeholder: this.placeholder,
222
- required: this.required,
223
- description: this.description,
224
- helpText: this.helpText,
225
- validation: this.validation,
226
- condition: this.condition,
227
- policies: this.policies
228
- }, n = typeof this.defaultValue == "string" ? this.defaultValue : void 0, r = typeof this.defaultValue == "number" ? this.defaultValue : void 0, f = typeof this.defaultValue == "boolean" ? this.defaultValue : void 0, s = (t) => this.options ? this.options.map((i) => ({
229
- id: i.id,
230
- label: i.label,
231
- description: i.description,
232
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- option.value may be wider than JsonValue at this point; cast is safe before passing to castValue
233
- value: t(i.value),
234
- condition: i.condition
235
- })) : null;
236
- switch (this.type) {
237
- case "text":
238
- if (this.multiple) {
239
- let t;
240
- if (Array.isArray(this.defaultValue)) {
241
- t = [];
242
- for (const i of this.defaultValue)
243
- typeof i == "string" && t.push(i);
244
- t.length === 0 && (t = void 0);
245
- }
246
- return a.serialize({
247
- ...o,
248
- type: "text",
249
- multiple: !0,
250
- defaultValue: t,
251
- options: s((i) => `${i}`)
252
- });
253
- }
254
- return a.serialize({
255
- ...o,
256
- type: "text",
257
- multiple: !1,
258
- defaultValue: n,
259
- options: s((t) => `${t}`)
260
- });
261
- case "number":
262
- if (this.multiple) {
263
- let t;
264
- if (Array.isArray(this.defaultValue)) {
265
- t = [];
266
- for (const i of this.defaultValue)
267
- typeof i == "number" && t.push(i);
268
- t.length === 0 && (t = void 0);
269
- }
270
- return a.serialize({
271
- ...o,
272
- type: "number",
273
- multiple: !0,
274
- defaultValue: t,
275
- options: s((i) => Number(i))
276
- });
277
- }
278
- return a.serialize({
279
- ...o,
280
- type: "number",
281
- multiple: !1,
282
- defaultValue: r,
283
- options: s((t) => Number(t))
284
- });
285
- case "boolean":
286
- if (this.multiple) {
287
- let t;
288
- if (Array.isArray(this.defaultValue)) {
289
- t = [];
290
- for (const i of this.defaultValue)
291
- typeof i == "boolean" && t.push(i);
292
- t.length === 0 && (t = void 0);
293
- }
294
- return a.serialize({
295
- ...o,
296
- type: "boolean",
297
- multiple: !0,
298
- defaultValue: t,
299
- options: s((i) => !!i)
300
- });
301
- }
302
- return a.serialize({
303
- ...o,
304
- type: "boolean",
305
- multiple: !1,
306
- defaultValue: f,
307
- options: s((t) => !!t)
308
- });
309
- case "object":
310
- return this.multiple ? a.serialize({
311
- ...o,
312
- type: "object",
313
- multiple: !0,
314
- defaultValue: this.defaultValue,
315
- options: s((t) => t)
316
- }) : a.serialize({
317
- ...o,
318
- type: "object",
319
- multiple: !1,
320
- defaultValue: this.defaultValue,
321
- options: s((t) => t)
322
- });
323
- default:
324
- throw new Error("Unsupported field type");
325
- }
326
- }
327
- }), V = (e) => {
328
- const d = [], o = [], n = [], r = [], f = [];
329
- return {
330
- id: e.id,
331
- component: e.component,
332
- name: e.name,
333
- initializeOpen: e.initializeOpen,
334
- condition: e.decide ?? e.condition,
335
- targets: e.targets,
336
- steps: d,
337
- nodes: o,
338
- edges: n,
339
- fields: f,
340
- conditionals: r,
341
- addStep(s, t) {
342
- let i = t?.node;
343
- this.nodes.length === 0 && (i = h({ type: "origin" }, this), this.nodes.push(i));
344
- const l = "serialize" in s ? s : z(s, this);
345
- if (i) {
346
- if (!l.node)
347
- throw new Error("todo no node");
348
- const u = c(
349
- { sourceNode: i, destinationNode: l.node, sourceNodeHandle: null },
350
- this
351
- );
352
- this.edges.push(u);
353
- }
354
- return l.fields.length > 0 && l.fields.forEach((u) => {
355
- this.fields.includes(u) || this.fields.push(u);
356
- }), this.steps.includes(l) || (this.steps.push(l), l.node && this.nodes.push(l.node)), l;
357
- },
358
- addAction(s, t) {
359
- let i = t?.node;
360
- this.nodes.length === 0 && (i = h({ type: "origin" }, this), this.nodes.push(i));
361
- const l = "serialize" in s ? s : y(s, this);
362
- if (i) {
363
- const u = c(
364
- { sourceNode: i, destinationNode: l, sourceNodeHandle: null },
365
- this
366
- );
367
- this.edges.push(u);
368
- }
369
- return this.nodes.push(l), l;
370
- },
371
- addConditional(s, t) {
372
- let i = t?.node;
373
- this.nodes.length === 0 && (i = h({ type: "origin" }, this), this.nodes.push(i));
374
- const l = "serialize" in s ? s : g(s, this);
375
- if (i) {
376
- if (!l.node)
377
- throw new Error("todo no node");
378
- const u = c(
379
- { sourceNode: i, destinationNode: l.node, sourceNodeHandle: null },
380
- this
381
- );
382
- this.edges.push(u);
383
- }
384
- return this.conditionals.includes(l) || (this.conditionals.push(l), l.node && this.nodes.push(l.node)), l;
385
- },
386
- addExperience(s, t) {
387
- let i = t?.node;
388
- this.nodes.length === 0 && (i = h({ type: "origin" }, this), this.nodes.push(i));
389
- const l = h(
390
- { type: "experience", experience: s },
391
- this
392
- );
393
- if (this.nodes.push(l), i) {
394
- const u = c(
395
- { sourceNode: i, destinationNode: l, sourceNodeHandle: null },
396
- this
397
- );
398
- this.edges.push(u);
399
- }
400
- return s;
401
- },
402
- addField(s, t) {
403
- const i = "serialize" in s ? s : N(s);
404
- return t && t.fields.push(i), this.fields.includes(i) || this.fields.push(i), i;
405
- },
406
- serialize() {
407
- return a.serialize({
408
- id: this.id,
409
- component: this.component,
410
- name: this.name,
411
- initializeOpen: this.initializeOpen,
412
- condition: this.condition,
413
- targets: this.targets,
414
- steps: this.steps.map((s) => a.deserialize(s.serialize())),
415
- nodes: this.nodes.map((s) => a.deserialize(s.serialize())),
416
- edges: this.edges.map((s) => a.deserialize(s.serialize())),
417
- conditionals: this.conditionals.map(
418
- (s) => a.deserialize(s.serialize())
419
- ),
420
- fields: this.fields.map((s) => a.deserialize(s.serialize()))
421
- });
422
- }
423
- };
424
- };
425
- export {
426
- g as createConditional,
427
- c as createEdge,
428
- V as createExperience,
429
- b as createExperiencePlugin,
430
- N as createField,
431
- h as createNode,
432
- x as createStep,
433
- a as serialization
434
- };
1
+ import { t as e } from "../../../id-CRqy981z.js";
2
+ //#region src/plugins/create-experience/serialization.ts
3
+ var t = {
4
+ serialize(e) {
5
+ return JSON.stringify(e);
6
+ },
7
+ deserialize(e) {
8
+ return JSON.parse(e);
9
+ }
10
+ }, n = (e) => ({
11
+ name: "create-experience",
12
+ setup: (n) => {
13
+ e.experiences.forEach((e) => {
14
+ let r = e.serialize(), i = t.deserialize(r);
15
+ i.component = e.component, n.registerExperience(i), i.fields.forEach((e) => {
16
+ n.registerField(e);
17
+ });
18
+ });
19
+ }
20
+ }), r = (n, r) => ({
21
+ id: e("node"),
22
+ experience: r,
23
+ type: "action",
24
+ action: n.action,
25
+ addNext(e) {
26
+ if (!e.node) throw Error("Cannot connect to node");
27
+ let t = s({
28
+ sourceNode: this,
29
+ destinationNode: e.node,
30
+ sourceNodeHandle: null
31
+ }, r);
32
+ r.edges.push(t);
33
+ },
34
+ onSuccess(e) {
35
+ if (!e.node) throw Error("Cannot connect to node");
36
+ let t = s({
37
+ sourceNode: this,
38
+ destinationNode: e.node,
39
+ sourceNodeHandle: "true"
40
+ }, r);
41
+ r.edges.push(t);
42
+ },
43
+ onFail(e) {
44
+ if (!e.node) throw Error("Cannot connect to node");
45
+ let t = s({
46
+ sourceNode: this,
47
+ destinationNode: e.node,
48
+ sourceNodeHandle: "false"
49
+ }, r);
50
+ r.edges.push(t);
51
+ },
52
+ serialize() {
53
+ return t.serialize({
54
+ id: this.id,
55
+ type: this.type,
56
+ action: this.action
57
+ });
58
+ }
59
+ }), i = (t) => ({
60
+ id: t.id ?? e("step"),
61
+ label: t.label,
62
+ fields: t.fields ?? [],
63
+ addField(e) {
64
+ let t = "serialize" in e ? e : l(e);
65
+ return this.fields.includes(t) || this.fields.push(t), t;
66
+ }
67
+ }), a = (n, r) => {
68
+ let i = {
69
+ id: n.id ?? e("step"),
70
+ label: n.label,
71
+ experience: r,
72
+ fields: n.fields ?? [],
73
+ node: null,
74
+ nextStep(e) {
75
+ return this.experience.addStep(e, this);
76
+ },
77
+ nextConditional(e) {
78
+ return this.experience.addConditional(e, this);
79
+ },
80
+ addNextExperience(e) {
81
+ return this.experience.addExperience(e, this);
82
+ },
83
+ addField(e) {
84
+ return this.experience.addField(e, this);
85
+ },
86
+ serialize() {
87
+ return t.serialize({
88
+ id: this.id,
89
+ label: this.label,
90
+ fieldIds: this.fields.map((e) => e.id)
91
+ });
92
+ }
93
+ };
94
+ return o({
95
+ step: i,
96
+ type: "step"
97
+ }, r), i;
98
+ }, o = (n, r) => {
99
+ let i = {
100
+ id: e("node"),
101
+ experience: r
102
+ };
103
+ if (n.type === "step") {
104
+ let e = {
105
+ ...i,
106
+ type: "step",
107
+ connectedStep: n.step,
108
+ serialize() {
109
+ return t.serialize({
110
+ id: this.id,
111
+ type: this.type,
112
+ stepId: this.connectedStep.id,
113
+ label: this.connectedStep.label
114
+ });
115
+ }
116
+ };
117
+ return e.connectedStep.node = e, e;
118
+ }
119
+ if (n.type === "conditional") {
120
+ let e = {
121
+ ...i,
122
+ type: "conditional",
123
+ connectedConditional: n.conditional,
124
+ serialize() {
125
+ return t.serialize({
126
+ id: this.id,
127
+ type: this.type,
128
+ conditionalId: this.connectedConditional.id
129
+ });
130
+ }
131
+ };
132
+ return e.connectedConditional.node = e, e;
133
+ }
134
+ return n.type === "experience" ? {
135
+ ...i,
136
+ type: "experience",
137
+ connectedExperience: n.experience,
138
+ serialize() {
139
+ return t.serialize({
140
+ id: this.id,
141
+ type: this.type,
142
+ experienceId: this.connectedExperience.id
143
+ });
144
+ }
145
+ } : {
146
+ ...i,
147
+ type: "origin",
148
+ serialize() {
149
+ return t.serialize({
150
+ id: this.id,
151
+ type: this.type
152
+ });
153
+ }
154
+ };
155
+ }, s = (n, r) => ({
156
+ id: e("edge"),
157
+ sourceNode: n.sourceNode,
158
+ sourceNodeHandle: n.sourceNodeHandle,
159
+ destinationNode: n.destinationNode,
160
+ experience: r,
161
+ serialize() {
162
+ return t.serialize({
163
+ id: this.id,
164
+ sourceNodeHandle: this.sourceNodeHandle ?? void 0,
165
+ sourceNodeId: this.sourceNode.id,
166
+ destinationNodeId: this.destinationNode.id
167
+ });
168
+ }
169
+ }), c = (n, r) => {
170
+ let i = {
171
+ id: e("conditional"),
172
+ label: n.label,
173
+ condition: n.condition,
174
+ node: null,
175
+ experience: r,
176
+ addTrue(e) {
177
+ if (!this.node || !e.node) throw Error("todo no node");
178
+ let t = s({
179
+ sourceNode: this.node,
180
+ destinationNode: e.node,
181
+ sourceNodeHandle: "true"
182
+ }, this.experience);
183
+ this.experience.edges.push(t);
184
+ },
185
+ addFalse(e) {
186
+ if (!this.node || !e.node) throw Error("todo no node");
187
+ let t = s({
188
+ sourceNode: this.node,
189
+ destinationNode: e.node,
190
+ sourceNodeHandle: "false"
191
+ }, this.experience);
192
+ this.experience.edges.push(t);
193
+ },
194
+ serialize() {
195
+ return t.serialize({
196
+ id: this.id,
197
+ label: this.label,
198
+ condition: this.condition
199
+ });
200
+ }
201
+ };
202
+ return o({
203
+ conditional: i,
204
+ type: "conditional"
205
+ }, r), i;
206
+ }, l = (e) => ({
207
+ id: e.id,
208
+ name: e.name,
209
+ type: e.type,
210
+ label: e.label,
211
+ placeholder: e.placeholder,
212
+ description: e.description,
213
+ helpText: e.helpText,
214
+ defaultValue: e.defaultValue ?? null,
215
+ multiple: e.multiple,
216
+ validation: e.validation ?? {},
217
+ condition: e.condition,
218
+ required: e.required,
219
+ options: Array.isArray(e.options) ? e.options.map(({ id: e, ...t }) => ({
220
+ id: e,
221
+ ...t
222
+ })) : null,
223
+ policies: e.policies,
224
+ serialize() {
225
+ let e = {
226
+ id: this.id,
227
+ name: this.name,
228
+ label: this.label,
229
+ placeholder: this.placeholder,
230
+ required: this.required,
231
+ description: this.description,
232
+ helpText: this.helpText,
233
+ validation: this.validation,
234
+ condition: this.condition,
235
+ policies: this.policies
236
+ }, n = typeof this.defaultValue == "string" ? this.defaultValue : void 0, r = typeof this.defaultValue == "number" ? this.defaultValue : void 0, i = typeof this.defaultValue == "boolean" ? this.defaultValue : void 0, a = (e) => this.options ? this.options.map((t) => ({
237
+ id: t.id,
238
+ label: t.label,
239
+ description: t.description,
240
+ value: e(t.value),
241
+ condition: t.condition
242
+ })) : null;
243
+ switch (this.type) {
244
+ case "text":
245
+ if (this.multiple) {
246
+ let n;
247
+ if (Array.isArray(this.defaultValue)) {
248
+ n = [];
249
+ for (let e of this.defaultValue) typeof e == "string" && n.push(e);
250
+ n.length === 0 && (n = void 0);
251
+ }
252
+ return t.serialize({
253
+ ...e,
254
+ type: "text",
255
+ multiple: !0,
256
+ defaultValue: n,
257
+ options: a((e) => `${e}`)
258
+ });
259
+ }
260
+ return t.serialize({
261
+ ...e,
262
+ type: "text",
263
+ multiple: !1,
264
+ defaultValue: n,
265
+ options: a((e) => `${e}`)
266
+ });
267
+ case "number":
268
+ if (this.multiple) {
269
+ let n;
270
+ if (Array.isArray(this.defaultValue)) {
271
+ n = [];
272
+ for (let e of this.defaultValue) typeof e == "number" && n.push(e);
273
+ n.length === 0 && (n = void 0);
274
+ }
275
+ return t.serialize({
276
+ ...e,
277
+ type: "number",
278
+ multiple: !0,
279
+ defaultValue: n,
280
+ options: a((e) => Number(e))
281
+ });
282
+ }
283
+ return t.serialize({
284
+ ...e,
285
+ type: "number",
286
+ multiple: !1,
287
+ defaultValue: r,
288
+ options: a((e) => Number(e))
289
+ });
290
+ case "boolean":
291
+ if (this.multiple) {
292
+ let n;
293
+ if (Array.isArray(this.defaultValue)) {
294
+ n = [];
295
+ for (let e of this.defaultValue) typeof e == "boolean" && n.push(e);
296
+ n.length === 0 && (n = void 0);
297
+ }
298
+ return t.serialize({
299
+ ...e,
300
+ type: "boolean",
301
+ multiple: !0,
302
+ defaultValue: n,
303
+ options: a((e) => !!e)
304
+ });
305
+ }
306
+ return t.serialize({
307
+ ...e,
308
+ type: "boolean",
309
+ multiple: !1,
310
+ defaultValue: i,
311
+ options: a((e) => !!e)
312
+ });
313
+ case "object": return this.multiple ? t.serialize({
314
+ ...e,
315
+ type: "object",
316
+ multiple: !0,
317
+ defaultValue: this.defaultValue,
318
+ options: a((e) => e)
319
+ }) : t.serialize({
320
+ ...e,
321
+ type: "object",
322
+ multiple: !1,
323
+ defaultValue: this.defaultValue,
324
+ options: a((e) => e)
325
+ });
326
+ default: throw Error("Unsupported field type");
327
+ }
328
+ }
329
+ }), u = (e) => ({
330
+ id: e.id,
331
+ component: e.component,
332
+ name: e.name,
333
+ initializeOpen: e.initializeOpen,
334
+ condition: e.condition,
335
+ targets: e.targets,
336
+ steps: [],
337
+ nodes: [],
338
+ edges: [],
339
+ fields: [],
340
+ conditionals: [],
341
+ addStep(e, t) {
342
+ let n = t?.node;
343
+ this.nodes.length === 0 && (n = o({ type: "origin" }, this), this.nodes.push(n));
344
+ let r = "serialize" in e ? e : a(e, this);
345
+ if (n) {
346
+ if (!r.node) throw Error("todo no node");
347
+ let e = s({
348
+ sourceNode: n,
349
+ destinationNode: r.node,
350
+ sourceNodeHandle: null
351
+ }, this);
352
+ this.edges.push(e);
353
+ }
354
+ return r.fields.length > 0 && r.fields.forEach((e) => {
355
+ this.fields.includes(e) || this.fields.push(e);
356
+ }), this.steps.includes(r) || (this.steps.push(r), r.node && this.nodes.push(r.node)), r;
357
+ },
358
+ addAction(e, t) {
359
+ let n = t?.node;
360
+ this.nodes.length === 0 && (n = o({ type: "origin" }, this), this.nodes.push(n));
361
+ let i = "serialize" in e ? e : r(e, this);
362
+ if (n) {
363
+ let e = s({
364
+ sourceNode: n,
365
+ destinationNode: i,
366
+ sourceNodeHandle: null
367
+ }, this);
368
+ this.edges.push(e);
369
+ }
370
+ return this.nodes.push(i), i;
371
+ },
372
+ addConditional(e, t) {
373
+ let n = t?.node;
374
+ this.nodes.length === 0 && (n = o({ type: "origin" }, this), this.nodes.push(n));
375
+ let r = "serialize" in e ? e : c(e, this);
376
+ if (n) {
377
+ if (!r.node) throw Error("todo no node");
378
+ let e = s({
379
+ sourceNode: n,
380
+ destinationNode: r.node,
381
+ sourceNodeHandle: null
382
+ }, this);
383
+ this.edges.push(e);
384
+ }
385
+ return this.conditionals.includes(r) || (this.conditionals.push(r), r.node && this.nodes.push(r.node)), r;
386
+ },
387
+ addExperience(e, t) {
388
+ let n = t?.node;
389
+ this.nodes.length === 0 && (n = o({ type: "origin" }, this), this.nodes.push(n));
390
+ let r = o({
391
+ type: "experience",
392
+ experience: e
393
+ }, this);
394
+ if (this.nodes.push(r), n) {
395
+ let e = s({
396
+ sourceNode: n,
397
+ destinationNode: r,
398
+ sourceNodeHandle: null
399
+ }, this);
400
+ this.edges.push(e);
401
+ }
402
+ return e;
403
+ },
404
+ addField(e, t) {
405
+ let n = "serialize" in e ? e : l(e);
406
+ return t && t.fields.push(n), this.fields.includes(n) || this.fields.push(n), n;
407
+ },
408
+ serialize() {
409
+ return t.serialize({
410
+ id: this.id,
411
+ component: this.component,
412
+ name: this.name,
413
+ initializeOpen: this.initializeOpen,
414
+ condition: this.condition,
415
+ targets: this.targets,
416
+ steps: this.steps.map((e) => t.deserialize(e.serialize())),
417
+ nodes: this.nodes.map((e) => t.deserialize(e.serialize())),
418
+ edges: this.edges.map((e) => t.deserialize(e.serialize())),
419
+ conditionals: this.conditionals.map((e) => t.deserialize(e.serialize())),
420
+ fields: this.fields.map((e) => t.deserialize(e.serialize()))
421
+ });
422
+ }
423
+ });
424
+ //#endregion
425
+ export { c as createConditional, s as createEdge, u as createExperience, n as createExperiencePlugin, l as createField, o as createNode, i as createStep, t as serialization };