@picked/client 0.0.1-dev.1773729274420 → 0.0.1-dev.1773807602703

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