@picked/client 0.0.1-dev.1773804563218 → 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 (112) hide show
  1. package/dist/{api-CQ1Lb-dB.js → api-4YC7Dkcf.js} +1 -1
  2. package/dist/{api-C90ugp6M.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 -770
  15. package/dist/esm/plugins/create-experience/index.js +284 -359
  16. package/dist/esm/plugins/dynamic-experiences/index.js +80 -146
  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 +7 -7
  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 -46
  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 -2
  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-8P1fJuPC.js +0 -819
  104. package/dist/experience-instance-Bi3-1tP5.cjs +0 -1
  105. package/dist/object-BbFTsGh3.cjs +0 -1
  106. package/dist/storage-Be5xWNPC.cjs +0 -1
  107. package/dist/types/entities/condition/condition.d.ts +0 -17
  108. package/dist/types/entities/condition/condition.d.ts.map +0 -1
  109. package/dist/types/entities/step/step.d.ts +0 -20
  110. package/dist/types/entities/step/step.d.ts.map +0 -1
  111. package/dist/types/utils/key.d.ts +0 -12
  112. 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,96 +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
- name: this.connectedStep.name,
128
- label: this.connectedStep.name
105
+ stepId: this.connectedStep.id,
106
+ label: this.connectedStep.label
129
107
  });
130
108
  }
131
109
  };
132
- return n.connectedStep.node = n, n;
110
+ return r.connectedStep.node = r, r;
133
111
  }
134
- if (i.type === "conditional") {
135
- const n = {
136
- ...l,
112
+ if (e.type === "conditional") {
113
+ const r = {
114
+ ...o,
137
115
  type: "conditional",
138
- connectedCondition: i.conditional,
116
+ connectedConditional: e.conditional,
139
117
  serialize() {
140
118
  return a.serialize({
141
119
  id: this.id,
142
120
  type: this.type,
143
- conditionId: this.connectedCondition.id
121
+ conditionalId: this.connectedConditional.id
144
122
  });
145
123
  }
146
124
  };
147
- return n.connectedCondition.node = n, n;
125
+ return r.connectedConditional.node = r, r;
148
126
  }
149
- return i.type === "experience" ? {
150
- ...l,
127
+ return e.type === "experience" ? {
128
+ ...o,
151
129
  type: "experience",
152
- connectedExperience: i.experience,
130
+ connectedExperience: e.experience,
153
131
  serialize() {
154
132
  return a.serialize({
155
133
  id: this.id,
@@ -158,7 +136,7 @@ const z = (i, s) => ({
158
136
  });
159
137
  }
160
138
  } : {
161
- ...l,
139
+ ...o,
162
140
  type: "origin",
163
141
  serialize() {
164
142
  return a.serialize({
@@ -167,12 +145,12 @@ const z = (i, s) => ({
167
145
  });
168
146
  }
169
147
  };
170
- }, h = (i, s) => ({
148
+ }, c = (e, d) => ({
171
149
  id: p("edge"),
172
- sourceNode: i.sourceNode,
173
- sourceNodeHandle: i.sourceNodeHandle,
174
- destinationNode: i.destinationNode,
175
- experience: s,
150
+ sourceNode: e.sourceNode,
151
+ sourceNodeHandle: e.sourceNodeHandle,
152
+ destinationNode: e.destinationNode,
153
+ experience: d,
176
154
  serialize() {
177
155
  return a.serialize({
178
156
  id: this.id,
@@ -181,30 +159,30 @@ const z = (i, s) => ({
181
159
  destinationNodeId: this.destinationNode.id
182
160
  });
183
161
  }
184
- }), y = (i, s) => {
185
- const l = {
162
+ }), g = (e, d) => {
163
+ const o = {
186
164
  id: p("conditional"),
187
- label: i.label,
188
- condition: i.condition,
165
+ label: e.label,
166
+ condition: e.condition,
189
167
  node: null,
190
- experience: s,
191
- addTrue(d) {
192
- if (!this.node || !d.node)
168
+ experience: d,
169
+ addTrue(n) {
170
+ if (!this.node || !n.node)
193
171
  throw new Error("todo no node");
194
- const n = h(
195
- { sourceNode: this.node, destinationNode: d.node, sourceNodeHandle: "true" },
172
+ const r = c(
173
+ { sourceNode: this.node, destinationNode: n.node, sourceNodeHandle: "true" },
196
174
  this.experience
197
175
  );
198
- this.experience.edges.push(n);
176
+ this.experience.edges.push(r);
199
177
  },
200
- addFalse(d) {
201
- if (!this.node || !d.node)
178
+ addFalse(n) {
179
+ if (!this.node || !n.node)
202
180
  throw new Error("todo no node");
203
- const n = h(
204
- { sourceNode: this.node, destinationNode: d.node, sourceNodeHandle: "false" },
181
+ const r = c(
182
+ { sourceNode: this.node, destinationNode: n.node, sourceNodeHandle: "false" },
205
183
  this.experience
206
184
  );
207
- this.experience.edges.push(n);
185
+ this.experience.edges.push(r);
208
186
  },
209
187
  serialize() {
210
188
  return a.serialize({
@@ -214,269 +192,216 @@ const z = (i, s) => ({
214
192
  });
215
193
  }
216
194
  };
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
- });
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);
284
245
  }
285
246
  return a.serialize({
286
- ...n,
247
+ ...o,
287
248
  type: "text",
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
249
+ multiple: !0,
250
+ defaultValue: t,
251
+ options: s((i) => `${i}`)
296
252
  });
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
- });
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);
318
269
  }
319
270
  return a.serialize({
320
- ...n,
271
+ ...o,
321
272
  type: "number",
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
273
+ multiple: !0,
274
+ defaultValue: t,
275
+ options: s((i) => Number(i))
330
276
  });
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
- });
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);
352
293
  }
353
294
  return a.serialize({
354
- ...n,
295
+ ...o,
355
296
  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",
369
297
  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
- }) : 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
298
+ defaultValue: t,
299
+ options: s((i) => !!i)
390
300
  });
391
- default:
392
- throw new Error("Unsupported field type");
393
- }
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");
394
325
  }
395
- };
396
- }, k = (i) => {
397
- const s = [], l = [], d = [], n = [], r = [];
326
+ }
327
+ }), V = (e) => {
328
+ const d = [], o = [], n = [], r = [], f = [];
398
329
  return {
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)
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)
419
347
  throw new Error("todo no node");
420
- const c = h(
421
- { sourceNode: e, destinationNode: t.node, sourceNodeHandle: null },
348
+ const u = c(
349
+ { sourceNode: i, destinationNode: l.node, sourceNodeHandle: null },
422
350
  this
423
351
  );
424
- this.edges.push(c);
352
+ this.edges.push(u);
425
353
  }
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;
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;
429
357
  },
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 },
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 },
437
365
  this
438
366
  );
439
- this.edges.push(c);
367
+ this.edges.push(u);
440
368
  }
441
- return this.nodes.push(t), t;
369
+ return this.nodes.push(l), l;
442
370
  },
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)
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)
449
377
  throw new Error("todo no node");
450
- const c = h(
451
- { sourceNode: e, destinationNode: t.node, sourceNodeHandle: null },
378
+ const u = c(
379
+ { sourceNode: i, destinationNode: l.node, sourceNodeHandle: null },
452
380
  this
453
381
  );
454
- this.edges.push(c);
382
+ this.edges.push(u);
455
383
  }
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);
384
+ return this.conditionals.includes(l) || (this.conditionals.push(l), l.node && this.nodes.push(l.node)), l;
460
385
  },
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 },
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 },
466
391
  this
467
392
  );
468
- if (this.nodes.push(t), e) {
469
- const c = h(
470
- { sourceNode: e, destinationNode: t, sourceNodeHandle: null },
393
+ if (this.nodes.push(l), i) {
394
+ const u = c(
395
+ { sourceNode: i, destinationNode: l, sourceNodeHandle: null },
471
396
  this
472
397
  );
473
- this.edges.push(c);
398
+ this.edges.push(u);
474
399
  }
475
- return o;
400
+ return s;
476
401
  },
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;
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;
480
405
  },
481
406
  serialize() {
482
407
  return a.serialize({
@@ -486,24 +411,24 @@ const N = (i) => {
486
411
  initializeOpen: this.initializeOpen,
487
412
  condition: this.condition,
488
413
  targets: this.targets,
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
- )
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()))
495
421
  });
496
422
  }
497
423
  };
498
424
  };
499
425
  export {
500
- y as createCondition,
501
- w as createConditional,
502
- h as createEdge,
503
- k as createExperience,
504
- V as createExperiencePlugin,
426
+ g as createConditional,
427
+ c as createEdge,
428
+ V as createExperience,
429
+ b as createExperiencePlugin,
505
430
  N as createField,
506
- f as createNode,
507
- E as createStep,
431
+ h as createNode,
432
+ x as createStep,
508
433
  a as serialization
509
434
  };