@picked/client 0.0.1-dev.1773724362573 → 0.0.1-dev.1773804563218

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