@picked/client 0.0.1-dev.1774231221701 → 0.0.1-dev.1774244905386

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