@picked/client 0.0.50-next.3 → 0.0.50

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 (51) hide show
  1. package/dist/api-BwTaomem.cjs +1 -0
  2. package/dist/api-DWBcrf98.js +37 -0
  3. package/dist/cjs/index.js +2 -2
  4. package/dist/cjs/plugins/create-experience/index.js +1 -1
  5. package/dist/cjs/plugins/dynamic-experiences/index.js +1 -1
  6. package/dist/cjs/plugins/experience-browser-storage/index.js +1 -1
  7. package/dist/cjs/plugins/history-browser-storage/index.js +1 -1
  8. package/dist/cjs/plugins/responses-browser-storage/index.js +1 -1
  9. package/dist/cjs/plugins/responses-indexeddb/index.js +1 -1
  10. package/dist/cjs/plugins/single-page-app/index.js +1 -1
  11. package/dist/cjs/plugins/web-components/index.js +1 -1
  12. package/dist/cjs/plugins/window-object/index.js +1 -1
  13. package/dist/cjs/server/index.js +1 -1
  14. package/dist/esm/index.js +1126 -1220
  15. package/dist/esm/plugins/create-experience/index.js +461 -468
  16. package/dist/esm/plugins/dynamic-experiences/index.js +106 -123
  17. package/dist/esm/plugins/experience-browser-storage/index.js +32 -37
  18. package/dist/esm/plugins/history-browser-storage/index.js +23 -25
  19. package/dist/esm/plugins/responses-browser-storage/index.js +36 -39
  20. package/dist/esm/plugins/responses-indexeddb/index.js +81 -80
  21. package/dist/esm/plugins/single-page-app/index.js +31 -35
  22. package/dist/esm/plugins/web-components/index.js +18 -20
  23. package/dist/esm/plugins/window-object/index.js +9 -9
  24. package/dist/esm/server/index.js +95 -89
  25. package/dist/experience-instance-BRpI9I4s.js +710 -0
  26. package/dist/experience-instance-BUTnwbSJ.cjs +1 -0
  27. package/dist/id-BniPxOdF.js +4 -0
  28. package/dist/id-CIbS4P60.cjs +1 -0
  29. package/dist/logger-6z_gb4rA.js +4 -0
  30. package/dist/logger-fbvQC40v.cjs +1 -0
  31. package/dist/object-BReQiaSS.cjs +1 -0
  32. package/dist/object-Clj5zVr1.js +24 -0
  33. package/dist/storage-BFjb8azI.cjs +1 -0
  34. package/dist/storage-DyxpJ0pg.js +101 -0
  35. package/dist/supports-0XIfd4-R.js +85 -0
  36. package/dist/supports-Dsjg-82e.cjs +1 -0
  37. package/package.json +5 -5
  38. package/dist/api-4mY9vhi4.cjs +0 -1
  39. package/dist/api-D1FqIUly.js +0 -32
  40. package/dist/experience-instance-BsXG5XJ4.cjs +0 -1
  41. package/dist/experience-instance-fvSEb72i.js +0 -819
  42. package/dist/id-BKIWbSTy.cjs +0 -1
  43. package/dist/id-BW-g3y32.js +0 -6
  44. package/dist/logger-BsmHUUw1.cjs +0 -1
  45. package/dist/logger-C9a75KZn.js +0 -5
  46. package/dist/object-BbFTsGh3.cjs +0 -1
  47. package/dist/object-JwZ58NOH.js +0 -28
  48. package/dist/storage-Be5xWNPC.cjs +0 -1
  49. package/dist/storage-Co_LbKr_.js +0 -239
  50. package/dist/supports-8YT4QKI7.js +0 -95
  51. package/dist/supports-YvpQZxbh.cjs +0 -1
@@ -1,468 +1,461 @@
1
- import { g as p } from "../../../id-BW-g3y32.js";
2
- const r = {
3
- serialize(i) {
4
- return JSON.stringify(i);
5
- },
6
- deserialize(i) {
7
- return JSON.parse(i);
8
- }
9
- }, b = (i) => ({
10
- name: "create-experience",
11
- setup: (o) => {
12
- i.experiences.forEach((t) => {
13
- const n = t.serialize(), d = r.deserialize(n);
14
- d.component = t.component, o.registerExperience(d), d.fields.forEach((f) => {
15
- o.registerField(f);
16
- });
17
- });
18
- }
19
- }), m = (i, o) => ({
20
- id: p("node"),
21
- experience: o,
22
- type: "action",
23
- action: i.action,
24
- addNext(n) {
25
- if (!n.node) throw new Error("Cannot connect to node");
26
- const d = c(
27
- { sourceNode: this, destinationNode: n.node, sourceNodeHandle: null },
28
- o
29
- );
30
- o.edges.push(d);
31
- },
32
- onSuccess(n) {
33
- if (!n.node) throw new Error("Cannot connect to node");
34
- const d = c(
35
- { sourceNode: this, destinationNode: n.node, sourceNodeHandle: "true" },
36
- o
37
- );
38
- o.edges.push(d);
39
- },
40
- onFail(n) {
41
- if (!n.node) throw new Error("Cannot connect to node");
42
- const d = c(
43
- { sourceNode: this, destinationNode: n.node, sourceNodeHandle: "false" },
44
- o
45
- );
46
- o.edges.push(d);
47
- },
48
- serialize() {
49
- return r.serialize({
50
- id: this.id,
51
- type: this.type,
52
- action: this.action
53
- });
54
- }
55
- }), v = (i) => ({
56
- id: i.id ?? p("step"),
57
- label: i.label,
58
- fields: i.fields ?? [],
59
- addField(o) {
60
- const t = "serialize" in o ? o : N(o);
61
- return this.fields.includes(t) || this.fields.push(t), t;
62
- }
63
- }), y = (i, o) => {
64
- const t = {
65
- id: i.id ?? p("step"),
66
- label: i.label,
67
- experience: o,
68
- fields: i.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 r.serialize({
84
- id: this.id,
85
- label: this.label,
86
- fieldIds: this.fields.map((n) => n.id)
87
- });
88
- }
89
- };
90
- return h({ step: t, type: "step" }, o), t;
91
- }, h = (i, o) => {
92
- const t = {
93
- id: p("node"),
94
- experience: o
95
- };
96
- if (i.type === "step") {
97
- const d = {
98
- ...t,
99
- type: "step",
100
- connectedStep: i.step,
101
- serialize() {
102
- return r.serialize({
103
- id: this.id,
104
- type: this.type,
105
- stepId: this.connectedStep.id,
106
- label: this.connectedStep.label
107
- });
108
- }
109
- };
110
- return d.connectedStep.node = d, d;
111
- }
112
- if (i.type === "conditional") {
113
- const d = {
114
- ...t,
115
- type: "conditional",
116
- connectedConditional: i.conditional,
117
- serialize() {
118
- return r.serialize({
119
- id: this.id,
120
- type: this.type,
121
- conditionalId: this.connectedConditional.id
122
- });
123
- }
124
- };
125
- return d.connectedConditional.node = d, d;
126
- }
127
- return i.type === "experience" ? {
128
- ...t,
129
- type: "experience",
130
- connectedExperience: i.experience,
131
- serialize() {
132
- return r.serialize({
133
- id: this.id,
134
- type: this.type,
135
- experienceId: this.connectedExperience.id
136
- });
137
- }
138
- } : {
139
- ...t,
140
- type: "origin",
141
- serialize() {
142
- return r.serialize({
143
- id: this.id,
144
- type: this.type
145
- });
146
- }
147
- };
148
- }, c = (i, o) => ({
149
- id: p("edge"),
150
- sourceNode: i.sourceNode,
151
- sourceNodeHandle: i.sourceNodeHandle,
152
- destinationNode: i.destinationNode,
153
- experience: o,
154
- serialize() {
155
- return r.serialize({
156
- id: this.id,
157
- sourceNodeHandle: this.sourceNodeHandle ?? void 0,
158
- sourceNodeId: this.sourceNode.id,
159
- destinationNodeId: this.destinationNode.id
160
- });
161
- }
162
- }), z = (i, o) => {
163
- const t = {
164
- id: p("conditional"),
165
- label: i.label,
166
- condition: i.condition,
167
- node: null,
168
- experience: o,
169
- addTrue(n) {
170
- if (!this.node || !n.node)
171
- throw new Error("todo no node");
172
- const d = c(
173
- { sourceNode: this.node, destinationNode: n.node, sourceNodeHandle: "true" },
174
- this.experience
175
- );
176
- this.experience.edges.push(d);
177
- },
178
- addFalse(n) {
179
- if (!this.node || !n.node)
180
- throw new Error("todo no node");
181
- const d = c(
182
- { sourceNode: this.node, destinationNode: n.node, sourceNodeHandle: "false" },
183
- this.experience
184
- );
185
- this.experience.edges.push(d);
186
- },
187
- serialize() {
188
- return r.serialize({
189
- id: this.id,
190
- label: this.label,
191
- condition: this.condition
192
- });
193
- }
194
- };
195
- return h({ conditional: t, type: "conditional" }, o), t;
196
- }, N = (i) => ({
197
- id: i.id,
198
- name: i.name,
199
- type: i.type,
200
- label: i.label,
201
- placeholder: i.placeholder,
202
- description: i.description,
203
- helpText: i.helpText,
204
- defaultValue: i.defaultValue ?? null,
205
- multiple: i.multiple,
206
- validation: i.validation ?? {},
207
- condition: i.condition,
208
- required: i.required,
209
- options: i.options?.map((t) => ({
210
- id: "id" in t ? t.id : p("option"),
211
- ...t
212
- })) ?? null,
213
- policies: i.policies,
214
- // 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
215
- serialize() {
216
- const t = {
217
- id: this.id,
218
- name: this.name,
219
- label: this.label,
220
- placeholder: this.placeholder,
221
- required: this.required,
222
- description: this.description,
223
- helpText: this.helpText,
224
- validation: this.validation,
225
- condition: this.condition,
226
- policies: this.policies
227
- }, n = typeof this.defaultValue == "string" ? this.defaultValue : void 0, d = typeof this.defaultValue == "number" ? this.defaultValue : void 0, f = typeof this.defaultValue == "boolean" ? this.defaultValue : void 0;
228
- switch (this.type) {
229
- case "text":
230
- if (this.multiple) {
231
- let e;
232
- if (Array.isArray(this.defaultValue)) {
233
- e = [];
234
- for (const s of this.defaultValue)
235
- typeof s == "string" && e.push(s);
236
- e.length === 0 && (e = void 0);
237
- }
238
- return r.serialize({
239
- ...t,
240
- type: "text",
241
- multiple: !0,
242
- defaultValue: e,
243
- options: this.options ? this.options.map((s) => ({
244
- id: s.id,
245
- label: s.label,
246
- value: `${s.value}`,
247
- condition: s.condition
248
- })) : null
249
- });
250
- }
251
- return r.serialize({
252
- ...t,
253
- type: "text",
254
- multiple: !1,
255
- defaultValue: n,
256
- options: this.options ? this.options.map((e) => ({
257
- id: e.id,
258
- label: e.label,
259
- value: `${e.value}`,
260
- condition: e.condition
261
- })) : null
262
- });
263
- case "number":
264
- if (this.multiple) {
265
- let e;
266
- if (Array.isArray(this.defaultValue)) {
267
- e = [];
268
- for (const s of this.defaultValue)
269
- typeof s == "number" && e.push(s);
270
- e.length === 0 && (e = void 0);
271
- }
272
- return r.serialize({
273
- ...t,
274
- type: "number",
275
- multiple: !0,
276
- defaultValue: e,
277
- options: this.options ? this.options.map((s) => ({
278
- id: s.id,
279
- label: s.label,
280
- value: Number(s.value),
281
- condition: s.condition
282
- })) : null
283
- });
284
- }
285
- return r.serialize({
286
- ...t,
287
- type: "number",
288
- multiple: !1,
289
- defaultValue: d,
290
- options: this.options ? this.options.map((e) => ({
291
- id: e.id,
292
- label: e.label,
293
- value: Number(e.value),
294
- condition: e.condition
295
- })) : null
296
- });
297
- case "boolean":
298
- if (this.multiple) {
299
- let e;
300
- if (Array.isArray(this.defaultValue)) {
301
- e = [];
302
- for (const s of this.defaultValue)
303
- typeof s == "boolean" && e.push(s);
304
- e.length === 0 && (e = void 0);
305
- }
306
- return r.serialize({
307
- ...t,
308
- type: "boolean",
309
- multiple: !0,
310
- defaultValue: e,
311
- options: this.options ? this.options.map((s) => ({
312
- id: s.id,
313
- label: s.label,
314
- value: !!s.value,
315
- condition: s.condition
316
- })) : null
317
- });
318
- }
319
- return r.serialize({
320
- ...t,
321
- type: "boolean",
322
- multiple: !1,
323
- defaultValue: f,
324
- options: this.options ? this.options.map((e) => ({
325
- id: e.id,
326
- label: e.label,
327
- value: !!e.value,
328
- condition: e.condition
329
- })) : null
330
- });
331
- case "object":
332
- return this.multiple ? r.serialize({
333
- ...t,
334
- type: "object",
335
- multiple: !0,
336
- defaultValue: this.defaultValue,
337
- options: this.options ? this.options.map((e) => ({
338
- id: e.id,
339
- label: e.label,
340
- description: e.description,
341
- value: e.value,
342
- condition: e.condition
343
- })) : null
344
- }) : r.serialize({
345
- ...t,
346
- type: "object",
347
- multiple: !1,
348
- defaultValue: this.defaultValue,
349
- options: this.options ? this.options.map((e) => ({
350
- id: e.id,
351
- label: e.label,
352
- description: e.description,
353
- value: e.value,
354
- condition: e.condition
355
- })) : null
356
- });
357
- default:
358
- throw new Error("Unsupported field type");
359
- }
360
- }
361
- }), x = (i) => {
362
- const o = [], t = [], n = [], d = [], f = [];
363
- return {
364
- id: i.id,
365
- component: i.component,
366
- name: i.name,
367
- initializeOpen: i.initializeOpen,
368
- condition: i.condition,
369
- targets: i.targets,
370
- steps: o,
371
- nodes: t,
372
- edges: n,
373
- fields: f,
374
- conditionals: d,
375
- addStep(e, s) {
376
- let l = s?.node;
377
- this.nodes.length === 0 && (l = h({ type: "origin" }, this), this.nodes.push(l));
378
- const a = "serialize" in e ? e : y(e, this);
379
- if (l) {
380
- if (!a.node)
381
- throw new Error("todo no node");
382
- const u = c(
383
- { sourceNode: l, destinationNode: a.node, sourceNodeHandle: null },
384
- this
385
- );
386
- this.edges.push(u);
387
- }
388
- return a.fields.length > 0 && a.fields.forEach((u) => {
389
- this.fields.includes(u) || this.fields.push(u);
390
- }), this.steps.includes(a) || (this.steps.push(a), a.node && this.nodes.push(a.node)), a;
391
- },
392
- addAction(e, s) {
393
- let l = s?.node;
394
- this.nodes.length === 0 && (l = h({ type: "origin" }, this), this.nodes.push(l));
395
- const a = "serialize" in e ? e : m(e, this);
396
- if (l) {
397
- const u = c(
398
- { sourceNode: l, destinationNode: a, sourceNodeHandle: null },
399
- this
400
- );
401
- this.edges.push(u);
402
- }
403
- return this.nodes.push(a), a;
404
- },
405
- addConditional(e, s) {
406
- let l = s?.node;
407
- this.nodes.length === 0 && (l = h({ type: "origin" }, this), this.nodes.push(l));
408
- const a = "serialize" in e ? e : z(e, this);
409
- if (l) {
410
- if (!a.node)
411
- throw new Error("todo no node");
412
- const u = c(
413
- { sourceNode: l, destinationNode: a.node, sourceNodeHandle: null },
414
- this
415
- );
416
- this.edges.push(u);
417
- }
418
- return this.conditionals.includes(a) || (this.conditionals.push(a), a.node && this.nodes.push(a.node)), a;
419
- },
420
- addExperience(e, s) {
421
- let l = s?.node;
422
- this.nodes.length === 0 && (l = h({ type: "origin" }, this), this.nodes.push(l));
423
- const a = h(
424
- { type: "experience", experience: e },
425
- this
426
- );
427
- if (this.nodes.push(a), l) {
428
- const u = c(
429
- { sourceNode: l, destinationNode: a, sourceNodeHandle: null },
430
- this
431
- );
432
- this.edges.push(u);
433
- }
434
- return e;
435
- },
436
- addField(e, s) {
437
- const l = "serialize" in e ? e : N(e);
438
- return s && s.fields.push(l), this.fields.includes(l) || this.fields.push(l), l;
439
- },
440
- serialize() {
441
- return r.serialize({
442
- id: this.id,
443
- component: this.component,
444
- name: this.name,
445
- initializeOpen: this.initializeOpen,
446
- condition: this.condition,
447
- targets: this.targets,
448
- steps: this.steps.map((e) => r.deserialize(e.serialize())),
449
- nodes: this.nodes.map((e) => r.deserialize(e.serialize())),
450
- edges: this.edges.map((e) => r.deserialize(e.serialize())),
451
- conditionals: this.conditionals.map(
452
- (e) => r.deserialize(e.serialize())
453
- ),
454
- fields: this.fields.map((e) => r.deserialize(e.serialize()))
455
- });
456
- }
457
- };
458
- };
459
- export {
460
- z as createConditional,
461
- c as createEdge,
462
- x as createExperience,
463
- b as createExperiencePlugin,
464
- N as createField,
465
- h as createNode,
466
- v as createStep,
467
- r as serialization
468
- };
1
+ import { t as e } from "../../../id-BniPxOdF.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 = (n) => ({
207
+ id: n.id,
208
+ name: n.name,
209
+ type: n.type,
210
+ label: n.label,
211
+ placeholder: n.placeholder,
212
+ description: n.description,
213
+ helpText: n.helpText,
214
+ defaultValue: n.defaultValue ?? null,
215
+ multiple: n.multiple,
216
+ validation: n.validation ?? {},
217
+ condition: n.condition,
218
+ required: n.required,
219
+ options: n.options?.map((t) => ({
220
+ id: "id" in t ? t.id : e("option"),
221
+ ...t
222
+ })) ?? null,
223
+ policies: n.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;
237
+ switch (this.type) {
238
+ case "text":
239
+ if (this.multiple) {
240
+ let n;
241
+ if (Array.isArray(this.defaultValue)) {
242
+ n = [];
243
+ for (let e of this.defaultValue) typeof e == "string" && n.push(e);
244
+ n.length === 0 && (n = void 0);
245
+ }
246
+ return t.serialize({
247
+ ...e,
248
+ type: "text",
249
+ multiple: !0,
250
+ defaultValue: n,
251
+ options: this.options ? this.options.map((e) => ({
252
+ id: e.id,
253
+ label: e.label,
254
+ value: `${e.value}`,
255
+ condition: e.condition
256
+ })) : null
257
+ });
258
+ }
259
+ return t.serialize({
260
+ ...e,
261
+ type: "text",
262
+ multiple: !1,
263
+ defaultValue: n,
264
+ options: this.options ? this.options.map((e) => ({
265
+ id: e.id,
266
+ label: e.label,
267
+ value: `${e.value}`,
268
+ condition: e.condition
269
+ })) : null
270
+ });
271
+ case "number":
272
+ if (this.multiple) {
273
+ let n;
274
+ if (Array.isArray(this.defaultValue)) {
275
+ n = [];
276
+ for (let e of this.defaultValue) typeof e == "number" && n.push(e);
277
+ n.length === 0 && (n = void 0);
278
+ }
279
+ return t.serialize({
280
+ ...e,
281
+ type: "number",
282
+ multiple: !0,
283
+ defaultValue: n,
284
+ options: this.options ? this.options.map((e) => ({
285
+ id: e.id,
286
+ label: e.label,
287
+ value: Number(e.value),
288
+ condition: e.condition
289
+ })) : null
290
+ });
291
+ }
292
+ return t.serialize({
293
+ ...e,
294
+ type: "number",
295
+ multiple: !1,
296
+ defaultValue: r,
297
+ options: this.options ? this.options.map((e) => ({
298
+ id: e.id,
299
+ label: e.label,
300
+ value: Number(e.value),
301
+ condition: e.condition
302
+ })) : null
303
+ });
304
+ case "boolean":
305
+ if (this.multiple) {
306
+ let n;
307
+ if (Array.isArray(this.defaultValue)) {
308
+ n = [];
309
+ for (let e of this.defaultValue) typeof e == "boolean" && n.push(e);
310
+ n.length === 0 && (n = void 0);
311
+ }
312
+ return t.serialize({
313
+ ...e,
314
+ type: "boolean",
315
+ multiple: !0,
316
+ defaultValue: n,
317
+ options: this.options ? this.options.map((e) => ({
318
+ id: e.id,
319
+ label: e.label,
320
+ value: !!e.value,
321
+ condition: e.condition
322
+ })) : null
323
+ });
324
+ }
325
+ return t.serialize({
326
+ ...e,
327
+ type: "boolean",
328
+ multiple: !1,
329
+ defaultValue: i,
330
+ options: this.options ? this.options.map((e) => ({
331
+ id: e.id,
332
+ label: e.label,
333
+ value: !!e.value,
334
+ condition: e.condition
335
+ })) : null
336
+ });
337
+ case "object": return this.multiple ? t.serialize({
338
+ ...e,
339
+ type: "object",
340
+ multiple: !0,
341
+ defaultValue: this.defaultValue,
342
+ options: this.options ? this.options.map((e) => ({
343
+ id: e.id,
344
+ label: e.label,
345
+ description: e.description,
346
+ value: e.value,
347
+ condition: e.condition
348
+ })) : null
349
+ }) : t.serialize({
350
+ ...e,
351
+ type: "object",
352
+ multiple: !1,
353
+ defaultValue: this.defaultValue,
354
+ options: this.options ? this.options.map((e) => ({
355
+ id: e.id,
356
+ label: e.label,
357
+ description: e.description,
358
+ value: e.value,
359
+ condition: e.condition
360
+ })) : null
361
+ });
362
+ default: throw Error("Unsupported field type");
363
+ }
364
+ }
365
+ }), u = (e) => ({
366
+ id: e.id,
367
+ component: e.component,
368
+ name: e.name,
369
+ initializeOpen: e.initializeOpen,
370
+ condition: e.condition,
371
+ targets: e.targets,
372
+ steps: [],
373
+ nodes: [],
374
+ edges: [],
375
+ fields: [],
376
+ conditionals: [],
377
+ addStep(e, t) {
378
+ let n = t?.node;
379
+ this.nodes.length === 0 && (n = o({ type: "origin" }, this), this.nodes.push(n));
380
+ let r = "serialize" in e ? e : a(e, this);
381
+ if (n) {
382
+ if (!r.node) throw Error("todo no node");
383
+ let e = s({
384
+ sourceNode: n,
385
+ destinationNode: r.node,
386
+ sourceNodeHandle: null
387
+ }, this);
388
+ this.edges.push(e);
389
+ }
390
+ return r.fields.length > 0 && r.fields.forEach((e) => {
391
+ this.fields.includes(e) || this.fields.push(e);
392
+ }), this.steps.includes(r) || (this.steps.push(r), r.node && this.nodes.push(r.node)), r;
393
+ },
394
+ addAction(e, t) {
395
+ let n = t?.node;
396
+ this.nodes.length === 0 && (n = o({ type: "origin" }, this), this.nodes.push(n));
397
+ let i = "serialize" in e ? e : r(e, this);
398
+ if (n) {
399
+ let e = s({
400
+ sourceNode: n,
401
+ destinationNode: i,
402
+ sourceNodeHandle: null
403
+ }, this);
404
+ this.edges.push(e);
405
+ }
406
+ return this.nodes.push(i), i;
407
+ },
408
+ addConditional(e, t) {
409
+ let n = t?.node;
410
+ this.nodes.length === 0 && (n = o({ type: "origin" }, this), this.nodes.push(n));
411
+ let r = "serialize" in e ? e : c(e, this);
412
+ if (n) {
413
+ if (!r.node) throw Error("todo no node");
414
+ let e = s({
415
+ sourceNode: n,
416
+ destinationNode: r.node,
417
+ sourceNodeHandle: null
418
+ }, this);
419
+ this.edges.push(e);
420
+ }
421
+ return this.conditionals.includes(r) || (this.conditionals.push(r), r.node && this.nodes.push(r.node)), r;
422
+ },
423
+ addExperience(e, t) {
424
+ let n = t?.node;
425
+ this.nodes.length === 0 && (n = o({ type: "origin" }, this), this.nodes.push(n));
426
+ let r = o({
427
+ type: "experience",
428
+ experience: e
429
+ }, this);
430
+ if (this.nodes.push(r), n) {
431
+ let e = s({
432
+ sourceNode: n,
433
+ destinationNode: r,
434
+ sourceNodeHandle: null
435
+ }, this);
436
+ this.edges.push(e);
437
+ }
438
+ return e;
439
+ },
440
+ addField(e, t) {
441
+ let n = "serialize" in e ? e : l(e);
442
+ return t && t.fields.push(n), this.fields.includes(n) || this.fields.push(n), n;
443
+ },
444
+ serialize() {
445
+ return t.serialize({
446
+ id: this.id,
447
+ component: this.component,
448
+ name: this.name,
449
+ initializeOpen: this.initializeOpen,
450
+ condition: this.condition,
451
+ targets: this.targets,
452
+ steps: this.steps.map((e) => t.deserialize(e.serialize())),
453
+ nodes: this.nodes.map((e) => t.deserialize(e.serialize())),
454
+ edges: this.edges.map((e) => t.deserialize(e.serialize())),
455
+ conditionals: this.conditionals.map((e) => t.deserialize(e.serialize())),
456
+ fields: this.fields.map((e) => t.deserialize(e.serialize()))
457
+ });
458
+ }
459
+ });
460
+ //#endregion
461
+ 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 };