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

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