@picked/client 0.0.35-next.1 → 0.0.36-next.1

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.
@@ -1,50 +1,50 @@
1
- import { g as p } from "../../../id-BW-g3y32.js";
1
+ import { g as f } from "../../../id-BW-g3y32.js";
2
2
  const r = {
3
- serialize(i) {
4
- return JSON.stringify(i);
3
+ serialize(e) {
4
+ return JSON.stringify(e);
5
5
  },
6
- deserialize(i) {
7
- return JSON.parse(i);
6
+ deserialize(e) {
7
+ return JSON.parse(e);
8
8
  }
9
- }, v = (i) => ({
9
+ }, v = (e) => ({
10
10
  name: "create-experience",
11
11
  setup: (o) => {
12
- i.experiences.forEach((d) => {
13
- const s = d.serialize(), n = r.deserialize(s);
14
- n.component = d.component, o.registerExperience(n), n.fields.forEach((f) => {
15
- o.registerField(f);
12
+ e.experiences.forEach((n) => {
13
+ const s = n.serialize(), d = r.deserialize(s);
14
+ d.component = n.component, o.registerExperience(d), d.fields.forEach((N) => {
15
+ o.registerField(N);
16
16
  });
17
17
  });
18
18
  }
19
- }), g = (i, o) => ({
20
- id: p("node"),
19
+ }), g = (e, o) => ({
20
+ id: f("node"),
21
21
  position: [0, 0],
22
22
  experience: o,
23
23
  type: "action",
24
- action: i.action,
24
+ action: e.action,
25
25
  addNext(s) {
26
26
  if (!s.node) throw new Error("Cannot connect to node");
27
- const n = c(
27
+ const d = h(
28
28
  { sourceNode: this, destinationNode: s.node, sourceNodeHandle: null },
29
29
  o
30
30
  );
31
- o.edges.push(n);
31
+ o.edges.push(d);
32
32
  },
33
33
  onSuccess(s) {
34
34
  if (!s.node) throw new Error("Cannot connect to node");
35
- const n = c(
35
+ const d = h(
36
36
  { sourceNode: this, destinationNode: s.node, sourceNodeHandle: "true" },
37
37
  o
38
38
  );
39
- o.edges.push(n);
39
+ o.edges.push(d);
40
40
  },
41
41
  onFail(s) {
42
42
  if (!s.node) throw new Error("Cannot connect to node");
43
- const n = c(
43
+ const d = h(
44
44
  { sourceNode: this, destinationNode: s.node, sourceNodeHandle: "false" },
45
45
  o
46
46
  );
47
- o.edges.push(n);
47
+ o.edges.push(d);
48
48
  },
49
49
  serialize() {
50
50
  return r.serialize({
@@ -54,21 +54,20 @@ const r = {
54
54
  position: this.position
55
55
  });
56
56
  }
57
- }), E = (i) => ({
58
- id: i.id ?? p("step"),
59
- label: i.label,
60
- fields: i.fields ?? [],
57
+ }), E = (e) => ({
58
+ id: e.id ?? f("step"),
59
+ label: e.label,
60
+ fields: e.fields ?? [],
61
61
  addField(o) {
62
- var s, n;
63
- const d = "serialize" in o ? o : m(o);
64
- return (s = this.fields) != null && s.includes(d) || (n = this.fields) == null || n.push(d), d;
62
+ const n = "serialize" in o ? o : m(o);
63
+ return this.fields?.includes(n) || this.fields?.push(n), n;
65
64
  }
66
- }), y = (i, o) => {
67
- const d = {
68
- id: i.id ?? p("step"),
69
- label: i.label,
65
+ }), y = (e, o) => {
66
+ const n = {
67
+ id: e.id ?? f("step"),
68
+ label: e.label,
70
69
  experience: o,
71
- fields: i.fields ?? [],
70
+ fields: e.fields ?? [],
72
71
  node: null,
73
72
  nextStep(s) {
74
73
  return this.experience.addStep(s, this);
@@ -90,18 +89,18 @@ const r = {
90
89
  });
91
90
  }
92
91
  };
93
- return h({ step: d, type: "step" }, o), d;
94
- }, z = () => [0, 0], h = (i, o) => {
95
- const d = {
96
- id: p("node"),
92
+ return p({ step: n, type: "step" }, o), n;
93
+ }, z = () => [0, 0], p = (e, o) => {
94
+ const n = {
95
+ id: f("node"),
97
96
  position: z(),
98
97
  experience: o
99
98
  };
100
- if (i.type === "step") {
101
- const n = {
102
- ...d,
99
+ if (e.type === "step") {
100
+ const d = {
101
+ ...n,
103
102
  type: "step",
104
- connectedStep: i.step,
103
+ connectedStep: e.step,
105
104
  serialize() {
106
105
  return r.serialize({
107
106
  id: this.id,
@@ -112,13 +111,13 @@ const r = {
112
111
  });
113
112
  }
114
113
  };
115
- return n.connectedStep.node = n, n;
114
+ return d.connectedStep.node = d, d;
116
115
  }
117
- if (i.type === "conditional") {
118
- const n = {
119
- ...d,
116
+ if (e.type === "conditional") {
117
+ const d = {
118
+ ...n,
120
119
  type: "conditional",
121
- connectedConditional: i.conditional,
120
+ connectedConditional: e.conditional,
122
121
  serialize() {
123
122
  return r.serialize({
124
123
  id: this.id,
@@ -128,12 +127,12 @@ const r = {
128
127
  });
129
128
  }
130
129
  };
131
- return n.connectedConditional.node = n, n;
130
+ return d.connectedConditional.node = d, d;
132
131
  }
133
- return i.type === "experience" ? {
134
- ...d,
132
+ return e.type === "experience" ? {
133
+ ...n,
135
134
  type: "experience",
136
- connectedExperience: i.experience,
135
+ connectedExperience: e.experience,
137
136
  serialize() {
138
137
  return r.serialize({
139
138
  id: this.id,
@@ -143,7 +142,7 @@ const r = {
143
142
  });
144
143
  }
145
144
  } : {
146
- ...d,
145
+ ...n,
147
146
  type: "origin",
148
147
  serialize() {
149
148
  return r.serialize({
@@ -153,11 +152,11 @@ const r = {
153
152
  });
154
153
  }
155
154
  };
156
- }, c = (i, o) => ({
157
- id: p("edge"),
158
- sourceNode: i.sourceNode,
159
- sourceNodeHandle: i.sourceNodeHandle,
160
- destinationNode: i.destinationNode,
155
+ }, h = (e, o) => ({
156
+ id: f("edge"),
157
+ sourceNode: e.sourceNode,
158
+ sourceNodeHandle: e.sourceNodeHandle,
159
+ destinationNode: e.destinationNode,
161
160
  experience: o,
162
161
  serialize() {
163
162
  return r.serialize({
@@ -167,29 +166,29 @@ const r = {
167
166
  destinationNodeId: this.destinationNode.id
168
167
  });
169
168
  }
170
- }), b = (i, o) => {
171
- const d = {
172
- id: p("conditional"),
173
- condition: i.condition,
169
+ }), b = (e, o) => {
170
+ const n = {
171
+ id: f("conditional"),
172
+ condition: e.condition,
174
173
  node: null,
175
174
  experience: o,
176
175
  addTrue(s) {
177
176
  if (!this.node || !s.node)
178
177
  throw new Error("todo no node");
179
- const n = c(
178
+ const d = h(
180
179
  { sourceNode: this.node, destinationNode: s.node, sourceNodeHandle: "true" },
181
180
  this.experience
182
181
  );
183
- this.experience.edges.push(n);
182
+ this.experience.edges.push(d);
184
183
  },
185
184
  addFalse(s) {
186
185
  if (!this.node || !s.node)
187
186
  throw new Error("todo no node");
188
- const n = c(
187
+ const d = h(
189
188
  { sourceNode: this.node, destinationNode: s.node, sourceNodeHandle: "false" },
190
189
  this.experience
191
190
  );
192
- this.experience.edges.push(n);
191
+ this.experience.edges.push(d);
193
192
  },
194
193
  serialize() {
195
194
  return r.serialize({
@@ -198,244 +197,241 @@ const r = {
198
197
  });
199
198
  }
200
199
  };
201
- return h({ conditional: d, type: "conditional" }, o), d;
202
- }, m = (i) => {
203
- var d;
204
- return {
205
- id: i.id,
206
- name: i.name,
207
- type: i.type,
208
- label: i.label,
209
- placeholder: i.placeholder,
210
- description: i.description,
211
- helpText: i.helpText,
212
- defaultValue: i.defaultValue ?? null,
213
- multiple: i.multiple,
214
- validation: i.validation ?? {},
215
- condition: i.condition,
216
- required: i.required,
217
- options: ((d = i.options) == null ? void 0 : d.map((s) => ({
218
- ...s
219
- }))) ?? null,
220
- policies: i.policies,
221
- serialize() {
222
- const s = {
223
- id: this.id,
224
- name: this.name,
225
- label: this.label,
226
- placeholder: this.placeholder,
227
- required: this.required,
228
- description: this.description,
229
- helpText: this.helpText,
230
- validation: this.validation,
231
- condition: this.condition,
232
- policies: this.policies
233
- }, n = typeof this.defaultValue == "string" ? this.defaultValue : void 0, f = typeof this.defaultValue == "number" ? this.defaultValue : void 0, N = typeof this.defaultValue == "boolean" ? this.defaultValue : void 0;
234
- switch (this.type) {
235
- case "text":
236
- if (this.multiple) {
237
- let e;
238
- if (Array.isArray(this.defaultValue)) {
239
- e = [];
240
- for (const t of this.defaultValue)
241
- typeof t == "string" && e.push(t);
242
- e.length === 0 && (e = void 0);
243
- }
244
- return r.serialize({
245
- ...s,
246
- type: "text",
247
- multiple: !0,
248
- defaultValue: e,
249
- options: this.options ? this.options.map((t) => ({
250
- id: t.id,
251
- label: t.label,
252
- value: `${t.value}`,
253
- condition: t.condition
254
- })) : null
255
- });
200
+ return p({ conditional: n, type: "conditional" }, o), n;
201
+ }, m = (e) => ({
202
+ id: e.id,
203
+ name: e.name,
204
+ type: e.type,
205
+ label: e.label,
206
+ placeholder: e.placeholder,
207
+ description: e.description,
208
+ helpText: e.helpText,
209
+ defaultValue: e.defaultValue ?? null,
210
+ multiple: e.multiple,
211
+ validation: e.validation ?? {},
212
+ condition: e.condition,
213
+ required: e.required,
214
+ options: e.options?.map((n) => ({
215
+ ...n
216
+ })) ?? null,
217
+ policies: e.policies,
218
+ serialize() {
219
+ const n = {
220
+ id: this.id,
221
+ name: this.name,
222
+ label: this.label,
223
+ placeholder: this.placeholder,
224
+ required: this.required,
225
+ description: this.description,
226
+ helpText: this.helpText,
227
+ validation: this.validation,
228
+ condition: this.condition,
229
+ policies: this.policies
230
+ }, s = typeof this.defaultValue == "string" ? this.defaultValue : void 0, d = typeof this.defaultValue == "number" ? this.defaultValue : void 0, N = typeof this.defaultValue == "boolean" ? this.defaultValue : void 0;
231
+ switch (this.type) {
232
+ case "text":
233
+ if (this.multiple) {
234
+ let t;
235
+ if (Array.isArray(this.defaultValue)) {
236
+ t = [];
237
+ for (const i of this.defaultValue)
238
+ typeof i == "string" && t.push(i);
239
+ t.length === 0 && (t = void 0);
256
240
  }
257
241
  return r.serialize({
258
- ...s,
242
+ ...n,
259
243
  type: "text",
260
- multiple: !1,
261
- defaultValue: n,
262
- options: this.options ? this.options.map((e) => ({
263
- id: e.id,
264
- label: e.label,
265
- value: `${e.value}`,
266
- condition: e.condition
244
+ multiple: !0,
245
+ defaultValue: t,
246
+ options: this.options ? this.options.map((i) => ({
247
+ id: i.id,
248
+ label: i.label,
249
+ value: `${i.value}`,
250
+ condition: i.condition
267
251
  })) : null
268
252
  });
269
- case "number":
270
- if (this.multiple) {
271
- let e;
272
- if (Array.isArray(this.defaultValue)) {
273
- e = [];
274
- for (const t of this.defaultValue)
275
- typeof t == "number" && e.push(t);
276
- e.length === 0 && (e = void 0);
277
- }
278
- return r.serialize({
279
- ...s,
280
- type: "number",
281
- multiple: !0,
282
- defaultValue: e,
283
- options: this.options ? this.options.map((t) => ({
284
- id: t.id,
285
- label: t.label,
286
- value: Number(t.value),
287
- condition: t.condition
288
- })) : null
289
- });
253
+ }
254
+ return r.serialize({
255
+ ...n,
256
+ type: "text",
257
+ multiple: !1,
258
+ defaultValue: s,
259
+ options: this.options ? this.options.map((t) => ({
260
+ id: t.id,
261
+ label: t.label,
262
+ value: `${t.value}`,
263
+ condition: t.condition
264
+ })) : null
265
+ });
266
+ case "number":
267
+ if (this.multiple) {
268
+ let t;
269
+ if (Array.isArray(this.defaultValue)) {
270
+ t = [];
271
+ for (const i of this.defaultValue)
272
+ typeof i == "number" && t.push(i);
273
+ t.length === 0 && (t = void 0);
290
274
  }
291
275
  return r.serialize({
292
- ...s,
276
+ ...n,
293
277
  type: "number",
294
- multiple: !1,
295
- defaultValue: f,
296
- options: this.options ? this.options.map((e) => ({
297
- id: e.id,
298
- label: e.label,
299
- value: Number(e.value),
300
- condition: e.condition
278
+ multiple: !0,
279
+ defaultValue: t,
280
+ options: this.options ? this.options.map((i) => ({
281
+ id: i.id,
282
+ label: i.label,
283
+ value: Number(i.value),
284
+ condition: i.condition
301
285
  })) : null
302
286
  });
303
- case "boolean":
304
- if (this.multiple) {
305
- let e;
306
- if (Array.isArray(this.defaultValue)) {
307
- e = [];
308
- for (const t of this.defaultValue)
309
- typeof t == "boolean" && e.push(t);
310
- e.length === 0 && (e = void 0);
311
- }
312
- return r.serialize({
313
- ...s,
314
- type: "boolean",
315
- multiple: !0,
316
- defaultValue: e,
317
- options: this.options ? this.options.map((t) => ({
318
- id: t.id,
319
- label: t.label,
320
- value: !!t.value,
321
- condition: t.condition
322
- })) : null
323
- });
287
+ }
288
+ return r.serialize({
289
+ ...n,
290
+ type: "number",
291
+ multiple: !1,
292
+ defaultValue: d,
293
+ options: this.options ? this.options.map((t) => ({
294
+ id: t.id,
295
+ label: t.label,
296
+ value: Number(t.value),
297
+ condition: t.condition
298
+ })) : null
299
+ });
300
+ case "boolean":
301
+ if (this.multiple) {
302
+ let t;
303
+ if (Array.isArray(this.defaultValue)) {
304
+ t = [];
305
+ for (const i of this.defaultValue)
306
+ typeof i == "boolean" && t.push(i);
307
+ t.length === 0 && (t = void 0);
324
308
  }
325
309
  return r.serialize({
326
- ...s,
310
+ ...n,
327
311
  type: "boolean",
328
- multiple: !1,
329
- defaultValue: N,
330
- options: this.options ? this.options.map((e) => ({
331
- id: e.id,
332
- label: e.label,
333
- value: !!e.value,
334
- condition: e.condition
312
+ multiple: !0,
313
+ defaultValue: t,
314
+ options: this.options ? this.options.map((i) => ({
315
+ id: i.id,
316
+ label: i.label,
317
+ value: !!i.value,
318
+ condition: i.condition
335
319
  })) : null
336
320
  });
337
- // todo: support for object type fields
338
- // case 'object':
339
- // if (this.multiple) {
340
- // return serialization.serialize({
341
- // ...baseField,
342
- // type: 'object',
343
- // multiple: true,
344
- // defaultValue: this.defaultValue,
345
- // options: this.options,
346
- // })
347
- // }
348
- // return serialization.serialize({
349
- // ...baseField,
350
- // type: 'object',
351
- // multiple: false,
352
- // defaultValue: this.defaultValue,
353
- // options: this.options,
354
- // })
355
- default:
356
- throw new Error("Unsupported field type");
357
- }
321
+ }
322
+ return r.serialize({
323
+ ...n,
324
+ type: "boolean",
325
+ multiple: !1,
326
+ defaultValue: N,
327
+ options: this.options ? this.options.map((t) => ({
328
+ id: t.id,
329
+ label: t.label,
330
+ value: !!t.value,
331
+ condition: t.condition
332
+ })) : null
333
+ });
334
+ // todo: support for object type fields
335
+ // case 'object':
336
+ // if (this.multiple) {
337
+ // return serialization.serialize({
338
+ // ...baseField,
339
+ // type: 'object',
340
+ // multiple: true,
341
+ // defaultValue: this.defaultValue,
342
+ // options: this.options,
343
+ // })
344
+ // }
345
+ // return serialization.serialize({
346
+ // ...baseField,
347
+ // type: 'object',
348
+ // multiple: false,
349
+ // defaultValue: this.defaultValue,
350
+ // options: this.options,
351
+ // })
352
+ default:
353
+ throw new Error("Unsupported field type");
358
354
  }
359
- };
360
- }, V = (i) => {
361
- const o = [], d = [], s = [], n = [], f = [], N = i.condition ?? i.decide;
355
+ }
356
+ }), V = (e) => {
357
+ const o = [], n = [], s = [], d = [], N = [], t = e.condition ?? e.decide;
362
358
  return {
363
- id: i.id,
364
- component: i.component,
365
- name: i.name,
366
- initializeOpen: i.initializeOpen,
367
- condition: N,
368
- decide: i.decide,
369
- targets: i.targets,
359
+ id: e.id,
360
+ component: e.component,
361
+ name: e.name,
362
+ initializeOpen: e.initializeOpen,
363
+ condition: t,
364
+ decide: e.decide,
365
+ targets: e.targets,
370
366
  steps: o,
371
- nodes: d,
367
+ nodes: n,
372
368
  edges: s,
373
- fields: f,
374
- conditionals: n,
375
- addStep(e, t) {
376
- let l = t == null ? void 0 : t.node;
377
- this.nodes.length === 0 && (l = h({ type: "origin" }, this), this.nodes.push(l));
378
- const a = "serialize" in e ? e : y(e, this);
369
+ fields: N,
370
+ conditionals: d,
371
+ addStep(i, u) {
372
+ let l = u?.node;
373
+ this.nodes.length === 0 && (l = p({ type: "origin" }, this), this.nodes.push(l));
374
+ const a = "serialize" in i ? i : y(i, this);
379
375
  if (l) {
380
376
  if (!a.node)
381
377
  throw new Error("todo no node");
382
- const u = c(
378
+ const c = h(
383
379
  { sourceNode: l, destinationNode: a.node, sourceNodeHandle: null },
384
380
  this
385
381
  );
386
- this.edges.push(u);
382
+ this.edges.push(c);
387
383
  }
388
- return a.fields.length > 0 && a.fields.forEach((u) => {
389
- this.fields.includes(u) || this.fields.push(u);
384
+ return a.fields.length > 0 && a.fields.forEach((c) => {
385
+ this.fields.includes(c) || this.fields.push(c);
390
386
  }), this.steps.includes(a) || (this.steps.push(a), a.node && this.nodes.push(a.node)), a;
391
387
  },
392
- addAction(e, t) {
393
- let l = t == null ? void 0 : t.node;
394
- this.nodes.length === 0 && (l = h({ type: "origin" }, this), this.nodes.push(l));
395
- const a = "serialize" in e ? e : g(e, this);
388
+ addAction(i, u) {
389
+ let l = u?.node;
390
+ this.nodes.length === 0 && (l = p({ type: "origin" }, this), this.nodes.push(l));
391
+ const a = "serialize" in i ? i : g(i, this);
396
392
  if (l) {
397
- const u = c(
393
+ const c = h(
398
394
  { sourceNode: l, destinationNode: a, sourceNodeHandle: null },
399
395
  this
400
396
  );
401
- this.edges.push(u);
397
+ this.edges.push(c);
402
398
  }
403
399
  return this.nodes.push(a), a;
404
400
  },
405
- addConditional(e, t) {
406
- let l = t == null ? void 0 : t.node;
407
- this.nodes.length === 0 && (l = h({ type: "origin" }, this), this.nodes.push(l));
408
- const a = "serialize" in e ? e : b(e, this);
401
+ addConditional(i, u) {
402
+ let l = u?.node;
403
+ this.nodes.length === 0 && (l = p({ type: "origin" }, this), this.nodes.push(l));
404
+ const a = "serialize" in i ? i : b(i, this);
409
405
  if (l) {
410
406
  if (!a.node)
411
407
  throw new Error("todo no node");
412
- const u = c(
408
+ const c = h(
413
409
  { sourceNode: l, destinationNode: a.node, sourceNodeHandle: null },
414
410
  this
415
411
  );
416
- this.edges.push(u);
412
+ this.edges.push(c);
417
413
  }
418
414
  return this.conditionals.includes(a) || (this.conditionals.push(a), a.node && this.nodes.push(a.node)), a;
419
415
  },
420
- addExperience(e, t) {
421
- let l = t == null ? void 0 : t.node;
422
- this.nodes.length === 0 && (l = h({ type: "origin" }, this), this.nodes.push(l));
423
- const a = h(
424
- { type: "experience", experience: e },
416
+ addExperience(i, u) {
417
+ let l = u?.node;
418
+ this.nodes.length === 0 && (l = p({ type: "origin" }, this), this.nodes.push(l));
419
+ const a = p(
420
+ { type: "experience", experience: i },
425
421
  this
426
422
  );
427
423
  if (this.nodes.push(a), l) {
428
- const u = c(
424
+ const c = h(
429
425
  { sourceNode: l, destinationNode: a, sourceNodeHandle: null },
430
426
  this
431
427
  );
432
- this.edges.push(u);
428
+ this.edges.push(c);
433
429
  }
434
- return e;
430
+ return i;
435
431
  },
436
- addField(e, t) {
437
- const l = "serialize" in e ? e : m(e);
438
- return t && t.fields.push(l), this.fields.includes(l) || this.fields.push(l), l;
432
+ addField(i, u) {
433
+ const l = "serialize" in i ? i : m(i);
434
+ return u && u.fields.push(l), this.fields.includes(l) || this.fields.push(l), l;
439
435
  },
440
436
  serialize() {
441
437
  return r.serialize({
@@ -446,24 +442,24 @@ const r = {
446
442
  condition: this.condition ?? this.decide,
447
443
  decide: this.decide,
448
444
  targets: this.targets,
449
- steps: this.steps.map((e) => r.deserialize(e.serialize())),
450
- nodes: this.nodes.map((e) => r.deserialize(e.serialize())),
451
- edges: this.edges.map((e) => r.deserialize(e.serialize())),
445
+ steps: this.steps.map((i) => r.deserialize(i.serialize())),
446
+ nodes: this.nodes.map((i) => r.deserialize(i.serialize())),
447
+ edges: this.edges.map((i) => r.deserialize(i.serialize())),
452
448
  conditionals: this.conditionals.map(
453
- (e) => r.deserialize(e.serialize())
449
+ (i) => r.deserialize(i.serialize())
454
450
  ),
455
- fields: this.fields.map((e) => r.deserialize(e.serialize()))
451
+ fields: this.fields.map((i) => r.deserialize(i.serialize()))
456
452
  });
457
453
  }
458
454
  };
459
455
  };
460
456
  export {
461
457
  b as createConditional,
462
- c as createEdge,
458
+ h as createEdge,
463
459
  V as createExperience,
464
460
  v as createExperiencePlugin,
465
461
  m as createField,
466
- h as createNode,
462
+ p as createNode,
467
463
  E as createStep,
468
464
  r as serialization
469
465
  };