@picked/client 0.0.1-dev.1773807602703 → 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 (135) 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 -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/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 +428 -0
  16. package/dist/esm/index.js +1138 -1291
  17. package/dist/esm/plugins/create-experience/index.js +424 -509
  18. package/dist/esm/plugins/dynamic-experiences/index.js +120 -204
  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 -80
  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/action/action.d.ts.map +1 -1
  42. package/dist/types/entities/experience/experience.d.ts +31 -48
  43. package/dist/types/entities/experience/experience.d.ts.map +1 -1
  44. package/dist/types/entities/experience-instance/experience-instance.d.ts +2 -2
  45. package/dist/types/entities/experience-instance/experience-instance.d.ts.map +1 -1
  46. package/dist/types/entities/feature/feature.d.ts.map +1 -1
  47. package/dist/types/entities/field/field.d.ts +12 -17
  48. package/dist/types/entities/field/field.d.ts.map +1 -1
  49. package/dist/types/entities/history/history.d.ts.map +1 -1
  50. package/dist/types/entities/response/response.d.ts +7 -9
  51. package/dist/types/entities/response/response.d.ts.map +1 -1
  52. package/dist/types/form/build-responses.d.ts +14 -0
  53. package/dist/types/form/build-responses.d.ts.map +1 -0
  54. package/dist/types/form/create-field-evaluator.d.ts +19 -0
  55. package/dist/types/form/create-field-evaluator.d.ts.map +1 -0
  56. package/dist/types/form/create-field-validation.d.ts +44 -0
  57. package/dist/types/form/create-field-validation.d.ts.map +1 -0
  58. package/dist/types/form/create-form.d.ts +66 -0
  59. package/dist/types/form/create-form.d.ts.map +1 -0
  60. package/dist/types/form/create-submit-pipeline.d.ts +58 -0
  61. package/dist/types/form/create-submit-pipeline.d.ts.map +1 -0
  62. package/dist/types/form/get-step-fields.d.ts +5 -0
  63. package/dist/types/form/get-step-fields.d.ts.map +1 -0
  64. package/dist/types/form/index.d.ts +10 -0
  65. package/dist/types/form/index.d.ts.map +1 -0
  66. package/dist/types/index.d.ts +1 -3
  67. package/dist/types/index.d.ts.map +1 -1
  68. package/dist/types/logic-engine.d.ts +2 -8
  69. package/dist/types/logic-engine.d.ts.map +1 -1
  70. package/dist/types/picked.d.ts +23 -42
  71. package/dist/types/picked.d.ts.map +1 -1
  72. package/dist/types/plugins/create-experience/create-experience.d.ts +37 -70
  73. package/dist/types/plugins/create-experience/create-experience.d.ts.map +1 -1
  74. package/dist/types/plugins/create-experience/index.d.ts +1 -1
  75. package/dist/types/plugins/create-experience/index.d.ts.map +1 -1
  76. package/dist/types/plugins/create-experience/plugin.d.ts.map +1 -1
  77. package/dist/types/plugins/dynamic-experiences/plugin.d.ts +5 -20
  78. package/dist/types/plugins/dynamic-experiences/plugin.d.ts.map +1 -1
  79. package/dist/types/plugins/dynamic-experiences/types.d.ts +0 -46
  80. package/dist/types/plugins/dynamic-experiences/types.d.ts.map +1 -1
  81. package/dist/types/plugins/experience-browser-storage/plugin.d.ts +2 -1
  82. package/dist/types/plugins/experience-browser-storage/plugin.d.ts.map +1 -1
  83. package/dist/types/plugins/history-browser-storage/plugin.d.ts +1 -0
  84. package/dist/types/plugins/history-browser-storage/plugin.d.ts.map +1 -1
  85. package/dist/types/plugins/responses-browser-storage/plugin.d.ts +2 -1
  86. package/dist/types/plugins/responses-browser-storage/plugin.d.ts.map +1 -1
  87. package/dist/types/plugins/responses-indexeddb/plugin.d.ts.map +1 -1
  88. package/dist/types/plugins/single-page-app/plugin.d.ts +1 -1
  89. package/dist/types/plugins/single-page-app/plugin.d.ts.map +1 -1
  90. package/dist/types/utils/dom.d.ts +0 -3
  91. package/dist/types/utils/dom.d.ts.map +1 -1
  92. package/dist/types/utils/events.d.ts +2 -2
  93. package/dist/types/utils/events.d.ts.map +1 -1
  94. package/dist/types/utils/global-obj.d.ts +0 -1
  95. package/dist/types/utils/global-obj.d.ts.map +1 -1
  96. package/dist/types/utils/indexed-db.d.ts +2 -1
  97. package/dist/types/utils/indexed-db.d.ts.map +1 -1
  98. package/dist/types/utils/logger.d.ts.map +1 -1
  99. package/dist/types/utils/node-tree/min-max-steps-to-leaf.d.ts.map +1 -1
  100. package/dist/types/utils/node-tree/min-max-steps-to-origin.d.ts.map +1 -1
  101. package/dist/types/utils/node-tree/next-reachable-step-nodes.d.ts +3 -3
  102. package/dist/types/utils/node-tree/next-reachable-step-nodes.d.ts.map +1 -1
  103. package/dist/types/utils/nodes.d.ts +2 -7
  104. package/dist/types/utils/nodes.d.ts.map +1 -1
  105. package/dist/types/utils/object.d.ts +0 -8
  106. package/dist/types/utils/object.d.ts.map +1 -1
  107. package/dist/types/utils/picked-config.d.ts +1 -1
  108. package/dist/types/utils/picked-config.d.ts.map +1 -1
  109. package/dist/types/utils/search-params.d.ts.map +1 -1
  110. package/dist/types/utils/storage.d.ts.map +1 -1
  111. package/package.json +18 -8
  112. package/dist/api-GlH9T8_1.js +0 -32
  113. package/dist/api-GvmToTw0.cjs +0 -1
  114. package/dist/experience-instance-CxiOyYPf.cjs +0 -1
  115. package/dist/experience-instance-DCknHRkX.js +0 -804
  116. package/dist/id-BKIWbSTy.cjs +0 -1
  117. package/dist/id-BW-g3y32.js +0 -6
  118. package/dist/logger-BsmHUUw1.cjs +0 -1
  119. package/dist/logger-C9a75KZn.js +0 -5
  120. package/dist/nodes-DQt4TfuO.js +0 -26
  121. package/dist/nodes-DsL8kMSX.cjs +0 -1
  122. package/dist/object-BbFTsGh3.cjs +0 -1
  123. package/dist/object-JwZ58NOH.js +0 -28
  124. package/dist/storage-Be5xWNPC.cjs +0 -1
  125. package/dist/storage-Co_LbKr_.js +0 -239
  126. package/dist/supports-8YT4QKI7.js +0 -95
  127. package/dist/supports-YvpQZxbh.cjs +0 -1
  128. package/dist/types/entities/condition/condition.d.ts +0 -17
  129. package/dist/types/entities/condition/condition.d.ts.map +0 -1
  130. package/dist/types/entities/project/project.d.ts +0 -9
  131. package/dist/types/entities/project/project.d.ts.map +0 -1
  132. package/dist/types/entities/step/step.d.ts +0 -20
  133. package/dist/types/entities/step/step.d.ts.map +0 -1
  134. package/dist/types/utils/key.d.ts +0 -12
  135. package/dist/types/utils/key.d.ts.map +0 -1
@@ -1,510 +1,425 @@
1
- import { g as p } from "../../../id-BW-g3y32.js";
2
- import { l as g } from "../../../logger-C9a75KZn.js";
3
- const a = {
4
- serialize(i) {
5
- return JSON.stringify(i);
6
- },
7
- deserialize(i) {
8
- return JSON.parse(i);
9
- }
10
- }, V = (i) => ({
11
- name: "create-experience",
12
- setup: (s) => {
13
- i.experiences.forEach((l) => {
14
- l.fields.forEach((r) => {
15
- s.registerField(a.deserialize(r.serialize()));
16
- }), l.steps.forEach((r) => {
17
- s.registerStep(a.deserialize(r.serialize()));
18
- });
19
- const d = l.serialize(), n = a.deserialize(d);
20
- n.component = l.component, s.registerExperience(n);
21
- });
22
- }
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
+ }
23
423
  });
24
- function m(i) {
25
- return i.toLowerCase().replaceAll(/[^a-z0-9\s-]/g, "").trim().replaceAll(/\s+/g, "-");
26
- }
27
- const z = (i, s) => ({
28
- id: p("node"),
29
- experience: s,
30
- type: "action",
31
- action: i.action,
32
- addNext(d) {
33
- if (!d.node) throw new Error("Cannot connect to node");
34
- const n = h(
35
- { sourceNode: this, destinationNode: d.node, sourceNodeHandle: null },
36
- s
37
- );
38
- s.edges.push(n);
39
- },
40
- onSuccess(d) {
41
- if (!d.node) throw new Error("Cannot connect to node");
42
- const n = h(
43
- { sourceNode: this, destinationNode: d.node, sourceNodeHandle: "true" },
44
- s
45
- );
46
- s.edges.push(n);
47
- },
48
- onFail(d) {
49
- if (!d.node) throw new Error("Cannot connect to node");
50
- const n = h(
51
- { sourceNode: this, destinationNode: d.node, sourceNodeHandle: "false" },
52
- s
53
- );
54
- s.edges.push(n);
55
- },
56
- serialize() {
57
- return a.serialize({
58
- id: this.id,
59
- type: this.type,
60
- action: this.action
61
- });
62
- }
63
- }), E = (i) => {
64
- const s = i.name ?? i.label ?? "", l = i.key ?? i.id ?? m(s);
65
- return {
66
- id: i.id ?? p("step"),
67
- name: s,
68
- key: l,
69
- label: s,
70
- fields: i.fields ?? [],
71
- addField(d) {
72
- const n = "serialize" in d ? d : N(d);
73
- return this.fields.includes(n) || this.fields.push(n), n;
74
- }
75
- };
76
- }, b = (i, s) => {
77
- const l = i.name ?? i.label ?? "", d = i.key ?? i.id ?? m(l), n = {
78
- id: i.id ?? p("step"),
79
- name: l,
80
- key: d,
81
- label: l,
82
- experience: s,
83
- fields: i.fields ?? [],
84
- node: null,
85
- nextStep(r) {
86
- return this.experience.addStep(r, this);
87
- },
88
- nextCondition(r) {
89
- return this.experience.addCondition(r, this);
90
- },
91
- nextConditional(r) {
92
- return this.experience.addCondition(r, this);
93
- },
94
- addNextExperience(r) {
95
- return this.experience.addExperience(r, this);
96
- },
97
- addField(r) {
98
- return this.experience.addField(r, this);
99
- },
100
- serialize() {
101
- return a.serialize({
102
- id: this.id,
103
- name: this.name,
104
- key: this.key,
105
- label: this.name,
106
- fieldKeys: this.fields.map((r) => r.key),
107
- fieldIds: this.fields.map((r) => r.id)
108
- });
109
- }
110
- };
111
- return f({ step: n, type: "step" }, s), n;
112
- }, f = (i, s) => {
113
- const l = {
114
- id: p("node"),
115
- experience: s
116
- };
117
- if (i.type === "step") {
118
- const n = {
119
- ...l,
120
- type: "step",
121
- connectedStep: i.step,
122
- serialize() {
123
- return a.serialize({
124
- id: this.id,
125
- type: this.type,
126
- stepKey: this.connectedStep.key,
127
- stepId: this.connectedStep.key,
128
- name: this.connectedStep.name,
129
- label: this.connectedStep.name
130
- });
131
- }
132
- };
133
- return n.connectedStep.node = n, n;
134
- }
135
- if (i.type === "conditional") {
136
- const n = {
137
- ...l,
138
- type: "conditional",
139
- connectedCondition: i.conditional,
140
- serialize() {
141
- return a.serialize({
142
- id: this.id,
143
- type: this.type,
144
- conditionId: this.connectedCondition.id
145
- });
146
- }
147
- };
148
- return n.connectedCondition.node = n, n;
149
- }
150
- return i.type === "experience" ? {
151
- ...l,
152
- type: "experience",
153
- connectedExperience: i.experience,
154
- serialize() {
155
- return a.serialize({
156
- id: this.id,
157
- type: this.type,
158
- experienceId: this.connectedExperience.id
159
- });
160
- }
161
- } : {
162
- ...l,
163
- type: "origin",
164
- serialize() {
165
- return a.serialize({
166
- id: this.id,
167
- type: this.type
168
- });
169
- }
170
- };
171
- }, h = (i, s) => ({
172
- id: p("edge"),
173
- sourceNode: i.sourceNode,
174
- sourceNodeHandle: i.sourceNodeHandle,
175
- destinationNode: i.destinationNode,
176
- experience: s,
177
- serialize() {
178
- return a.serialize({
179
- id: this.id,
180
- sourceNodeHandle: this.sourceNodeHandle ?? void 0,
181
- sourceNodeId: this.sourceNode.id,
182
- destinationNodeId: this.destinationNode.id
183
- });
184
- }
185
- }), y = (i, s) => {
186
- const l = {
187
- id: p("conditional"),
188
- label: i.label,
189
- condition: i.condition,
190
- node: null,
191
- experience: s,
192
- addTrue(d) {
193
- if (!this.node || !d.node)
194
- throw new Error("todo no node");
195
- const n = h(
196
- { sourceNode: this.node, destinationNode: d.node, sourceNodeHandle: "true" },
197
- this.experience
198
- );
199
- this.experience.edges.push(n);
200
- },
201
- addFalse(d) {
202
- if (!this.node || !d.node)
203
- throw new Error("todo no node");
204
- const n = h(
205
- { sourceNode: this.node, destinationNode: d.node, sourceNodeHandle: "false" },
206
- this.experience
207
- );
208
- this.experience.edges.push(n);
209
- },
210
- serialize() {
211
- return a.serialize({
212
- id: this.id,
213
- label: this.label,
214
- condition: this.condition
215
- });
216
- }
217
- };
218
- return f({ conditional: l, type: "conditional" }, s), l;
219
- };
220
- function w(...i) {
221
- return y(...i);
222
- }
223
- const N = (i) => {
224
- const s = i.key ?? i.id ?? m(i.name);
225
- return i.id !== void 0 && g(
226
- "warn",
227
- // eslint-disable-next-line sonarjs/deprecation -- reading deprecated id to build deprecation message
228
- `createField: 'id' is deprecated. Use 'key' instead of id="${i.id}". The field key "${s}" will be used for lookups.`
229
- ), {
230
- id: i.id ?? p("field"),
231
- key: s,
232
- name: i.name,
233
- type: i.type,
234
- label: i.label,
235
- placeholder: i.placeholder,
236
- description: i.description,
237
- helpText: i.helpText,
238
- defaultValue: i.defaultValue ?? null,
239
- multiple: i.multiple,
240
- validation: i.validation ?? {},
241
- condition: i.condition,
242
- required: i.required,
243
- options: i.options?.map((n) => ({
244
- id: "id" in n ? n.id : p("option"),
245
- ...n
246
- })) ?? null,
247
- policies: i.policies,
248
- // 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
249
- serialize() {
250
- const n = {
251
- id: this.id,
252
- key: this.key,
253
- name: this.name,
254
- label: this.label,
255
- placeholder: this.placeholder,
256
- required: this.required,
257
- description: this.description,
258
- helpText: this.helpText,
259
- validation: this.validation,
260
- condition: this.condition,
261
- policies: this.policies
262
- }, r = typeof this.defaultValue == "string" ? this.defaultValue : void 0, o = typeof this.defaultValue == "number" ? this.defaultValue : void 0, u = typeof this.defaultValue == "boolean" ? this.defaultValue : void 0;
263
- switch (this.type) {
264
- case "text":
265
- if (this.multiple) {
266
- let e;
267
- if (Array.isArray(this.defaultValue)) {
268
- e = [];
269
- for (const t of this.defaultValue)
270
- typeof t == "string" && e.push(t);
271
- e.length === 0 && (e = void 0);
272
- }
273
- return a.serialize({
274
- ...n,
275
- type: "text",
276
- multiple: !0,
277
- defaultValue: e,
278
- options: this.options ? this.options.map((t) => ({
279
- id: t.id,
280
- label: t.label,
281
- value: `${t.value}`,
282
- condition: t.condition
283
- })) : null
284
- });
285
- }
286
- return a.serialize({
287
- ...n,
288
- type: "text",
289
- multiple: !1,
290
- defaultValue: r,
291
- options: this.options ? this.options.map((e) => ({
292
- id: e.id,
293
- label: e.label,
294
- value: `${e.value}`,
295
- condition: e.condition
296
- })) : null
297
- });
298
- case "number":
299
- if (this.multiple) {
300
- let e;
301
- if (Array.isArray(this.defaultValue)) {
302
- e = [];
303
- for (const t of this.defaultValue)
304
- typeof t == "number" && e.push(t);
305
- e.length === 0 && (e = void 0);
306
- }
307
- return a.serialize({
308
- ...n,
309
- type: "number",
310
- multiple: !0,
311
- defaultValue: e,
312
- options: this.options ? this.options.map((t) => ({
313
- id: t.id,
314
- label: t.label,
315
- value: Number(t.value),
316
- condition: t.condition
317
- })) : null
318
- });
319
- }
320
- return a.serialize({
321
- ...n,
322
- type: "number",
323
- multiple: !1,
324
- defaultValue: o,
325
- options: this.options ? this.options.map((e) => ({
326
- id: e.id,
327
- label: e.label,
328
- value: Number(e.value),
329
- condition: e.condition
330
- })) : null
331
- });
332
- case "boolean":
333
- if (this.multiple) {
334
- let e;
335
- if (Array.isArray(this.defaultValue)) {
336
- e = [];
337
- for (const t of this.defaultValue)
338
- typeof t == "boolean" && e.push(t);
339
- e.length === 0 && (e = void 0);
340
- }
341
- return a.serialize({
342
- ...n,
343
- type: "boolean",
344
- multiple: !0,
345
- defaultValue: e,
346
- options: this.options ? this.options.map((t) => ({
347
- id: t.id,
348
- label: t.label,
349
- value: !!t.value,
350
- condition: t.condition
351
- })) : null
352
- });
353
- }
354
- return a.serialize({
355
- ...n,
356
- type: "boolean",
357
- multiple: !1,
358
- defaultValue: u,
359
- options: this.options ? this.options.map((e) => ({
360
- id: e.id,
361
- label: e.label,
362
- value: !!e.value,
363
- condition: e.condition
364
- })) : null
365
- });
366
- case "object":
367
- return this.multiple ? a.serialize({
368
- ...n,
369
- type: "object",
370
- multiple: !0,
371
- defaultValue: this.defaultValue,
372
- options: this.options ? this.options.map((e) => ({
373
- id: e.id,
374
- label: e.label,
375
- description: e.description,
376
- value: e.value,
377
- condition: e.condition
378
- })) : null
379
- }) : a.serialize({
380
- ...n,
381
- type: "object",
382
- multiple: !1,
383
- defaultValue: this.defaultValue,
384
- options: this.options ? this.options.map((e) => ({
385
- id: e.id,
386
- label: e.label,
387
- description: e.description,
388
- value: e.value,
389
- condition: e.condition
390
- })) : null
391
- });
392
- default:
393
- throw new Error("Unsupported field type");
394
- }
395
- }
396
- };
397
- }, k = (i) => {
398
- const s = [], l = [], d = [], n = [], r = [];
399
- return {
400
- id: i.id,
401
- component: i.component,
402
- name: i.name,
403
- initializeOpen: i.initializeOpen,
404
- condition: i.condition,
405
- targets: i.targets,
406
- steps: s,
407
- nodes: l,
408
- edges: d,
409
- fields: r,
410
- conditions: n,
411
- get conditionals() {
412
- return this.conditions;
413
- },
414
- addStep(o, u) {
415
- let e = u?.node;
416
- this.nodes.length === 0 && (e = f({ type: "origin" }, this), this.nodes.push(e));
417
- const t = "serialize" in o ? o : b(o, this);
418
- if (e) {
419
- if (!t.node)
420
- throw new Error("todo no node");
421
- const c = h(
422
- { sourceNode: e, destinationNode: t.node, sourceNodeHandle: null },
423
- this
424
- );
425
- this.edges.push(c);
426
- }
427
- return t.fields.length > 0 && t.fields.forEach((c) => {
428
- this.fields.includes(c) || this.fields.push(c);
429
- }), this.steps.includes(t) || (this.steps.push(t), t.node && this.nodes.push(t.node)), t;
430
- },
431
- addAction(o, u) {
432
- let e = u?.node;
433
- this.nodes.length === 0 && (e = f({ type: "origin" }, this), this.nodes.push(e));
434
- const t = "serialize" in o ? o : z(o, this);
435
- if (e) {
436
- const c = h(
437
- { sourceNode: e, destinationNode: t, sourceNodeHandle: null },
438
- this
439
- );
440
- this.edges.push(c);
441
- }
442
- return this.nodes.push(t), t;
443
- },
444
- addCondition(o, u) {
445
- let e = u?.node;
446
- this.nodes.length === 0 && (e = f({ type: "origin" }, this), this.nodes.push(e));
447
- const t = "serialize" in o ? o : y(o, this);
448
- if (e) {
449
- if (!t.node)
450
- throw new Error("todo no node");
451
- const c = h(
452
- { sourceNode: e, destinationNode: t.node, sourceNodeHandle: null },
453
- this
454
- );
455
- this.edges.push(c);
456
- }
457
- return this.conditions.includes(t) || (this.conditions.push(t), t.node && this.nodes.push(t.node)), t;
458
- },
459
- addConditional(o, u) {
460
- return this.addCondition(o, u);
461
- },
462
- addExperience(o, u) {
463
- let e = u?.node;
464
- this.nodes.length === 0 && (e = f({ type: "origin" }, this), this.nodes.push(e));
465
- const t = f(
466
- { type: "experience", experience: o },
467
- this
468
- );
469
- if (this.nodes.push(t), e) {
470
- const c = h(
471
- { sourceNode: e, destinationNode: t, sourceNodeHandle: null },
472
- this
473
- );
474
- this.edges.push(c);
475
- }
476
- return o;
477
- },
478
- addField(o, u) {
479
- const e = "serialize" in o ? o : N(o);
480
- return u && u.fields.push(e), this.fields.includes(e) || this.fields.push(e), e;
481
- },
482
- serialize() {
483
- return a.serialize({
484
- id: this.id,
485
- component: this.component,
486
- name: this.name,
487
- initializeOpen: this.initializeOpen,
488
- condition: this.condition,
489
- targets: this.targets,
490
- steps: this.steps.map((o) => o.id),
491
- nodes: this.nodes.map((o) => a.deserialize(o.serialize())),
492
- edges: this.edges.map((o) => a.deserialize(o.serialize())),
493
- conditions: this.conditions.map(
494
- (o) => a.deserialize(o.serialize())
495
- )
496
- });
497
- }
498
- };
499
- };
500
- export {
501
- y as createCondition,
502
- w as createConditional,
503
- h as createEdge,
504
- k as createExperience,
505
- V as createExperiencePlugin,
506
- N as createField,
507
- f as createNode,
508
- E as createStep,
509
- a as serialization
510
- };
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 };