@picked/client 0.0.50-next.4 → 0.0.51-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.
Files changed (111) hide show
  1. package/dist/{api-C2lg7yBn.cjs → api-A3gUhQJc.cjs} +1 -1
  2. package/dist/{api-CHaIe0uL.js → api-Brluf3C1.js} +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 +466 -0
  14. package/dist/esm/index.js +330 -321
  15. package/dist/esm/plugins/create-experience/index.js +25 -19
  16. package/dist/esm/plugins/dynamic-experiences/index.js +1 -1
  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 +5 -9
  21. package/dist/esm/plugins/single-page-app/index.js +4 -4
  22. package/dist/esm/server/index.js +1 -1
  23. package/dist/experience-instance-CIbQp9D7.js +481 -0
  24. package/dist/experience-instance-Dri5yAp1.cjs +1 -0
  25. package/dist/{object-Clj5zVr1.js → object-C82v79xc.js} +2 -1
  26. package/dist/object-CUJOjanb.cjs +1 -0
  27. package/dist/rules-logic-BIkBWZmf.js +233 -0
  28. package/dist/rules-logic-DDxCiq4P.cjs +1 -0
  29. package/dist/{storage-DyxpJ0pg.js → storage-6Xk0uAxB.js} +3 -1
  30. package/dist/storage-B6lQtc4-.cjs +1 -0
  31. package/dist/types/entities/action/action.d.ts.map +1 -1
  32. package/dist/types/entities/experience/experience.d.ts +10 -10
  33. package/dist/types/entities/experience/experience.d.ts.map +1 -1
  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 +11 -8
  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/response/response.d.ts.map +1 -1
  40. package/dist/types/exports.d.ts +0 -1
  41. package/dist/types/exports.d.ts.map +1 -1
  42. package/dist/types/form/build-responses.d.ts +14 -0
  43. package/dist/types/form/build-responses.d.ts.map +1 -0
  44. package/dist/types/form/create-field-evaluator.d.ts +19 -0
  45. package/dist/types/form/create-field-evaluator.d.ts.map +1 -0
  46. package/dist/types/form/create-field-validation.d.ts +59 -0
  47. package/dist/types/form/create-field-validation.d.ts.map +1 -0
  48. package/dist/types/form/create-form.d.ts +96 -0
  49. package/dist/types/form/create-form.d.ts.map +1 -0
  50. package/dist/types/form/create-submit-pipeline.d.ts +58 -0
  51. package/dist/types/form/create-submit-pipeline.d.ts.map +1 -0
  52. package/dist/types/form/get-step-fields.d.ts +5 -0
  53. package/dist/types/form/get-step-fields.d.ts.map +1 -0
  54. package/dist/types/form/index.d.ts +10 -0
  55. package/dist/types/form/index.d.ts.map +1 -0
  56. package/dist/types/index.d.ts +1 -1
  57. package/dist/types/index.d.ts.map +1 -1
  58. package/dist/types/logic-engine.d.ts +12 -10
  59. package/dist/types/logic-engine.d.ts.map +1 -1
  60. package/dist/types/picked.d.ts +4 -5
  61. package/dist/types/picked.d.ts.map +1 -1
  62. package/dist/types/plugins/create-experience/create-experience.d.ts +24 -22
  63. package/dist/types/plugins/create-experience/create-experience.d.ts.map +1 -1
  64. package/dist/types/plugins/create-experience/index.d.ts +1 -1
  65. package/dist/types/plugins/create-experience/index.d.ts.map +1 -1
  66. package/dist/types/plugins/experience-browser-storage/plugin.d.ts +2 -1
  67. package/dist/types/plugins/experience-browser-storage/plugin.d.ts.map +1 -1
  68. package/dist/types/plugins/history-browser-storage/plugin.d.ts +1 -0
  69. package/dist/types/plugins/history-browser-storage/plugin.d.ts.map +1 -1
  70. package/dist/types/plugins/responses-browser-storage/plugin.d.ts +2 -1
  71. package/dist/types/plugins/responses-browser-storage/plugin.d.ts.map +1 -1
  72. package/dist/types/plugins/responses-indexeddb/plugin.d.ts.map +1 -1
  73. package/dist/types/plugins/single-page-app/plugin.d.ts +1 -1
  74. package/dist/types/plugins/single-page-app/plugin.d.ts.map +1 -1
  75. package/dist/types/utils/dom.d.ts +0 -3
  76. package/dist/types/utils/dom.d.ts.map +1 -1
  77. package/dist/types/utils/events.d.ts +1 -1
  78. package/dist/types/utils/events.d.ts.map +1 -1
  79. package/dist/types/utils/global-obj.d.ts +0 -1
  80. package/dist/types/utils/global-obj.d.ts.map +1 -1
  81. package/dist/types/utils/indexed-db.d.ts +2 -1
  82. package/dist/types/utils/indexed-db.d.ts.map +1 -1
  83. package/dist/types/utils/logger.d.ts.map +1 -1
  84. package/dist/types/utils/node-tree/get-next-node-from-condition.d.ts +3 -0
  85. package/dist/types/utils/node-tree/get-next-node-from-condition.d.ts.map +1 -0
  86. package/dist/types/utils/node-tree/min-max-steps-to-leaf.d.ts.map +1 -1
  87. package/dist/types/utils/node-tree/min-max-steps-to-origin.d.ts.map +1 -1
  88. package/dist/types/utils/node-tree/next-reachable-step-nodes.d.ts.map +1 -1
  89. package/dist/types/utils/nodes.d.ts +2 -2
  90. package/dist/types/utils/nodes.d.ts.map +1 -1
  91. package/dist/types/utils/object.d.ts +0 -8
  92. package/dist/types/utils/object.d.ts.map +1 -1
  93. package/dist/types/utils/picked-config.d.ts +1 -1
  94. package/dist/types/utils/picked-config.d.ts.map +1 -1
  95. package/dist/types/utils/rules-logic.d.ts +31 -0
  96. package/dist/types/utils/rules-logic.d.ts.map +1 -1
  97. package/dist/types/utils/search-params.d.ts.map +1 -1
  98. package/dist/types/utils/storage.d.ts.map +1 -1
  99. package/package.json +43 -7
  100. package/dist/experience-instance-BRpI9I4s.js +0 -710
  101. package/dist/experience-instance-BUTnwbSJ.cjs +0 -1
  102. package/dist/object-BReQiaSS.cjs +0 -1
  103. package/dist/storage-BFjb8azI.cjs +0 -1
  104. package/dist/types/entities/project/project.d.ts +0 -9
  105. package/dist/types/entities/project/project.d.ts.map +0 -1
  106. package/dist/types/utils/get-step-fields.d.ts +0 -4
  107. package/dist/types/utils/get-step-fields.d.ts.map +0 -1
  108. package/dist/types/utils/node-tree/get-next-node-from-conditional.d.ts +0 -3
  109. package/dist/types/utils/node-tree/get-next-node-from-conditional.d.ts.map +0 -1
  110. /package/dist/{id-CIbS4P60.cjs → id-Bv44ilEo.cjs} +0 -0
  111. /package/dist/{id-BniPxOdF.js → id-CRqy981z.js} +0 -0
@@ -1,4 +1,4 @@
1
- import { t as e } from "../../../id-BniPxOdF.js";
1
+ import { t as e } from "../../../id-CRqy981z.js";
2
2
  //#region src/plugins/create-experience/serialization.ts
3
3
  var t = {
4
4
  serialize(e) {
@@ -61,7 +61,7 @@ var t = {
61
61
  label: t.label,
62
62
  fields: t.fields ?? [],
63
63
  addField(e) {
64
- let t = "serialize" in e ? e : l(e);
64
+ let t = "serialize" in e ? e : u(e);
65
65
  return this.fields.includes(t) || this.fields.push(t), t;
66
66
  }
67
67
  }), a = (n, r) => {
@@ -74,8 +74,11 @@ var t = {
74
74
  nextStep(e) {
75
75
  return this.experience.addStep(e, this);
76
76
  },
77
+ nextCondition(e) {
78
+ return this.experience.addCondition(e, this);
79
+ },
77
80
  nextConditional(e) {
78
- return this.experience.addConditional(e, this);
81
+ return this.nextCondition(e);
79
82
  },
80
83
  addNextExperience(e) {
81
84
  return this.experience.addExperience(e, this);
@@ -116,20 +119,20 @@ var t = {
116
119
  };
117
120
  return e.connectedStep.node = e, e;
118
121
  }
119
- if (n.type === "conditional") {
122
+ if (n.type === "condition") {
120
123
  let e = {
121
124
  ...i,
122
- type: "conditional",
123
- connectedConditional: n.conditional,
125
+ type: "condition",
126
+ connectedCondition: n.condition,
124
127
  serialize() {
125
128
  return t.serialize({
126
129
  id: this.id,
127
130
  type: this.type,
128
- conditionalId: this.connectedConditional.id
131
+ conditionId: this.connectedCondition.id
129
132
  });
130
133
  }
131
134
  };
132
- return e.connectedConditional.node = e, e;
135
+ return e.connectedCondition.node = e, e;
133
136
  }
134
137
  return n.type === "experience" ? {
135
138
  ...i,
@@ -168,7 +171,7 @@ var t = {
168
171
  }
169
172
  }), c = (n, r) => {
170
173
  let i = {
171
- id: e("conditional"),
174
+ id: e("condition"),
172
175
  label: n.label,
173
176
  condition: n.condition,
174
177
  node: null,
@@ -200,10 +203,10 @@ var t = {
200
203
  }
201
204
  };
202
205
  return o({
203
- conditional: i,
204
- type: "conditional"
206
+ condition: i,
207
+ type: "condition"
205
208
  }, r), i;
206
- }, l = (n) => ({
209
+ }, l = c, u = (n) => ({
207
210
  id: n.id,
208
211
  name: n.name,
209
212
  type: n.type,
@@ -362,7 +365,7 @@ var t = {
362
365
  default: throw Error("Unsupported field type");
363
366
  }
364
367
  }
365
- }), u = (e) => ({
368
+ }), d = (e) => ({
366
369
  id: e.id,
367
370
  component: e.component,
368
371
  name: e.name,
@@ -373,7 +376,7 @@ var t = {
373
376
  nodes: [],
374
377
  edges: [],
375
378
  fields: [],
376
- conditionals: [],
379
+ conditions: [],
377
380
  addStep(e, t) {
378
381
  let n = t?.node;
379
382
  this.nodes.length === 0 && (n = o({ type: "origin" }, this), this.nodes.push(n));
@@ -405,7 +408,7 @@ var t = {
405
408
  }
406
409
  return this.nodes.push(i), i;
407
410
  },
408
- addConditional(e, t) {
411
+ addCondition(e, t) {
409
412
  let n = t?.node;
410
413
  this.nodes.length === 0 && (n = o({ type: "origin" }, this), this.nodes.push(n));
411
414
  let r = "serialize" in e ? e : c(e, this);
@@ -418,7 +421,10 @@ var t = {
418
421
  }, this);
419
422
  this.edges.push(e);
420
423
  }
421
- return this.conditionals.includes(r) || (this.conditionals.push(r), r.node && this.nodes.push(r.node)), r;
424
+ return this.conditions.includes(r) || (this.conditions.push(r), r.node && this.nodes.push(r.node)), r;
425
+ },
426
+ addConditional(e, t) {
427
+ return this.addCondition(e, t);
422
428
  },
423
429
  addExperience(e, t) {
424
430
  let n = t?.node;
@@ -438,7 +444,7 @@ var t = {
438
444
  return e;
439
445
  },
440
446
  addField(e, t) {
441
- let n = "serialize" in e ? e : l(e);
447
+ let n = "serialize" in e ? e : u(e);
442
448
  return t && t.fields.push(n), this.fields.includes(n) || this.fields.push(n), n;
443
449
  },
444
450
  serialize() {
@@ -452,10 +458,10 @@ var t = {
452
458
  steps: this.steps.map((e) => t.deserialize(e.serialize())),
453
459
  nodes: this.nodes.map((e) => t.deserialize(e.serialize())),
454
460
  edges: this.edges.map((e) => t.deserialize(e.serialize())),
455
- conditionals: this.conditionals.map((e) => t.deserialize(e.serialize())),
461
+ conditions: this.conditions.map((e) => t.deserialize(e.serialize())),
456
462
  fields: this.fields.map((e) => t.deserialize(e.serialize()))
457
463
  });
458
464
  }
459
465
  });
460
466
  //#endregion
461
- export { c as createConditional, s as createEdge, u as createExperience, n as createExperiencePlugin, l as createField, o as createNode, i as createStep, t as serialization };
467
+ export { c as createCondition, l as createConditional, s as createEdge, d as createExperience, n as createExperiencePlugin, u as createField, o as createNode, i as createStep, t as serialization };
@@ -1,5 +1,5 @@
1
1
  import "../../../logger-6z_gb4rA.js";
2
- import { i as e, t } from "../../../api-CHaIe0uL.js";
2
+ import { i as e, t } from "../../../api-Brluf3C1.js";
3
3
  //#region src/plugins/dynamic-experiences/hash.ts
4
4
  function n(e) {
5
5
  let t = 2166136261;
@@ -1,5 +1,5 @@
1
1
  import "../../../logger-6z_gb4rA.js";
2
- import { n as e, r as t, t as n } from "../../../storage-DyxpJ0pg.js";
2
+ import { n as e, r as t, t as n } from "../../../storage-6Xk0uAxB.js";
3
3
  import { createEffect as r, sample as i } from "effector";
4
4
  //#region src/plugins/experience-browser-storage/plugin.ts
5
5
  var a = ({ storage: a = "local" } = {}) => ({
@@ -1,4 +1,4 @@
1
- import { n as e, r as t, t as n } from "../../../storage-DyxpJ0pg.js";
1
+ import { n as e, r as t, t as n } from "../../../storage-6Xk0uAxB.js";
2
2
  import { createEffect as r, sample as i } from "effector";
3
3
  //#region src/plugins/history-browser-storage/plugin.ts
4
4
  var a = n("history", "global"), o = ({ storage: n = "local" } = {}) => ({
@@ -1,4 +1,4 @@
1
- import { n as e, r as t, t as n } from "../../../storage-DyxpJ0pg.js";
1
+ import { n as e, r as t, t as n } from "../../../storage-6Xk0uAxB.js";
2
2
  import { attach as r, createEffect as i, sample as a } from "effector";
3
3
  //#region src/plugins/responses-browser-storage/plugin.ts
4
4
  var o = n("responses", "global"), s = (e, t) => {
@@ -47,13 +47,9 @@ var c = "responses", l = {
47
47
  let e = (await i(await r(l), c)).reduce((e, { fieldId: t, value: n }) => (e[t] = n, e), {});
48
48
  await n.responses.commit(e);
49
49
  }), d = e(async (e) => {
50
- e.forEach((e) => {
51
- r(l).then((t) => {
52
- a(t, c, e);
53
- }).catch((e) => {
54
- console.error("Failed to store response in IndexedDB:", e);
55
- });
56
- });
50
+ await Promise.allSettled(e.map(async (e) => {
51
+ await a(await r(l), c, e);
52
+ }));
57
53
  }), f = e(async () => {
58
54
  await s(await r(l), c);
59
55
  }), p = e(async (e) => {
@@ -70,8 +66,8 @@ var c = "responses", l = {
70
66
  fields: n.fields.listStore
71
67
  },
72
68
  fn: ({ responses: e, fields: t }) => {
73
- let n = t.filter((e) => !e.policies?.doNotStoreValue);
74
- return e.filter((e) => n.some((t) => t.id === e.fieldId));
69
+ let n = new Set(t.filter((e) => !e.policies?.doNotStoreValue).map((e) => e.id));
70
+ return e.filter((e) => n.has(e.fieldId));
75
71
  },
76
72
  target: d
77
73
  }), t({
@@ -1,12 +1,12 @@
1
- import { n as e } from "../../../object-Clj5zVr1.js";
1
+ import { n as e } from "../../../object-C82v79xc.js";
2
2
  import { d as t, f as n, i as r } from "../../../supports-0XIfd4-R.js";
3
3
  //#region src/plugins/single-page-app/plugin.ts
4
4
  var i = n, a, o = (e) => ({
5
5
  name: "single-page-app",
6
- setup: (n) => {
7
- e.instrumentHistory && t() && s(() => {
6
+ setup: (e) => {
7
+ t() && s(() => {
8
8
  requestAnimationFrame(() => {
9
- n.start();
9
+ e.start();
10
10
  });
11
11
  });
12
12
  }
@@ -1,4 +1,4 @@
1
- import { t as e } from "../../experience-instance-BRpI9I4s.js";
1
+ import { t as e } from "../../experience-instance-CIbQp9D7.js";
2
2
  import { attach as t, createEffect as n, createEvent as r, createStore as i, sample as a } from "effector";
3
3
  //#region src/server/index.ts
4
4
  function o() {
@@ -0,0 +1,481 @@
1
+ import { n as e, t } from "./rules-logic-BIkBWZmf.js";
2
+ import "./logger-6z_gb4rA.js";
3
+ import { d as n, l as r, r as i } from "./supports-0XIfd4-R.js";
4
+ import { attach as a, combine as o, createApi as s, createDomain as c, createEffect as l, createEvent as u, sample as d, split as f } from "effector";
5
+ import { createFactory as p, invoke as m } from "@withease/factories";
6
+ //#region src/utils/dom.ts
7
+ function h(e) {
8
+ return !n() || !i() ? [] : Array.from(window.document.querySelectorAll(e)).filter((e) => e instanceof HTMLElement);
9
+ }
10
+ var g = "open";
11
+ function _(e) {
12
+ if (!r()) throw Error("Shadow DOM is not supported in this environment");
13
+ return e.attachShadow({ mode: g });
14
+ }
15
+ function v() {
16
+ return new Promise((e, t) => {
17
+ if (!i()) {
18
+ t();
19
+ return;
20
+ }
21
+ document.readyState === "loading" ? document.addEventListener("readystatechange", () => e(), { once: !0 }) : e();
22
+ });
23
+ }
24
+ function y(e, t) {
25
+ let n = new MutationObserver((r) => {
26
+ document.contains(e) || (n.disconnect(), t());
27
+ });
28
+ n.observe(document.body, {
29
+ childList: !0,
30
+ subtree: !0
31
+ });
32
+ }
33
+ var b = "picked-root", x = "picked-target", S = "picked-root";
34
+ function C(e, t) {
35
+ return [...e, {
36
+ selector: `${S}[experience-id="${t}"]`,
37
+ placement: "replace"
38
+ }].flatMap((e) => {
39
+ let n = h(e.selector).filter((e) => !E(e, t) && !D(e, t));
40
+ return {
41
+ ...e,
42
+ elements: n
43
+ };
44
+ });
45
+ }
46
+ function w(e, t) {
47
+ return e.flatMap((e) => e.elements.map((n) => k(n, e.placement, t)));
48
+ }
49
+ function T(e, t) {
50
+ e.classList.add(x), e.classList.add(`${x}-${t}`);
51
+ }
52
+ function E(e, t) {
53
+ return t ? e.classList.contains(`${x}-${t}`) : e.classList.contains(`${x}`);
54
+ }
55
+ function D(e, t) {
56
+ return t ? e.classList.contains(`${b}-${t}`) : e.classList.contains(b);
57
+ }
58
+ function O(e) {
59
+ let t = document.createElement("div");
60
+ return t.style.display = "block", t.classList.add(b), t.classList.add(`${b}-${e}`), t;
61
+ }
62
+ function k(e, t, n) {
63
+ let r, i = O(n);
64
+ if (e instanceof Document) r = e.body.appendChild(i);
65
+ else {
66
+ switch (t) {
67
+ case "replace":
68
+ e.replaceWith(i);
69
+ break;
70
+ case "before":
71
+ e.before(i);
72
+ break;
73
+ case "after":
74
+ e.after(i);
75
+ break;
76
+ case "prepend":
77
+ e.prepend(i);
78
+ break;
79
+ case "append":
80
+ e.append(i);
81
+ break;
82
+ }
83
+ r = i;
84
+ }
85
+ return r;
86
+ }
87
+ //#endregion
88
+ //#region src/utils/nodes.ts
89
+ function A(e) {
90
+ return e.type === "condition";
91
+ }
92
+ function j(e) {
93
+ return e.type === "step";
94
+ }
95
+ function M(e) {
96
+ return e.type === "experience";
97
+ }
98
+ function N(e) {
99
+ return e.type === "origin";
100
+ }
101
+ function P(e) {
102
+ return e.type === "action";
103
+ }
104
+ //#endregion
105
+ //#region src/utils/node-tree/next-reachable-step-nodes.ts
106
+ var F = (e, t, n, r, i = /* @__PURE__ */ new Set()) => i.has(n.id) ? [] : (i.add(n.id), j(n) && !r ? [n] : t.filter((e) => e.sourceNodeId === n.id).flatMap((n) => {
107
+ let r = e.find((e) => e.id === n.destinationNodeId);
108
+ return r ? F(e, t, r, !1, i) : [];
109
+ })), ee = (e, t, n) => F(e, t, n, !0, /* @__PURE__ */ new Set()), I = (e, t, n, r, i = /* @__PURE__ */ new Set()) => {
110
+ if (i.has(n.id)) return [-1, -1];
111
+ i.add(n.id);
112
+ let a = t.filter((e) => e.sourceNodeId === n.id);
113
+ if (a.length === 0) return [0, 0];
114
+ let o = Infinity, s = -Infinity;
115
+ for (let n of a) {
116
+ let r = e.find((e) => e.id === n.destinationNodeId);
117
+ if (!r) continue;
118
+ let [a, c] = I(e, t, r, !1, new Set(i));
119
+ a !== -1 && (o = Math.min(o, a + 1), s = Math.max(s, c + 1));
120
+ }
121
+ return o === Infinity ? [-1, -1] : [o, s];
122
+ }, te = (e, t, n) => I(e, t, n, !0, /* @__PURE__ */ new Set()), L = (e, t, n, r = /* @__PURE__ */ new Set()) => {
123
+ if (r.has(n.id)) return [-1, -1];
124
+ if (r.add(n.id), n.type === "origin") return [0, 0];
125
+ let i = t.filter((e) => e.destinationNodeId === n.id);
126
+ if (i.length === 0) return [-1, -1];
127
+ let a = Infinity, o = -Infinity;
128
+ for (let n of i) {
129
+ let i = e.find((e) => e.id === n.sourceNodeId);
130
+ if (!i) continue;
131
+ let [s, c] = L(e, t, i, new Set(r));
132
+ s !== -1 && (a = Math.min(a, s + 1), o = Math.max(o, c + 1));
133
+ }
134
+ return a === Infinity ? [-1, -1] : [a, o];
135
+ }, R = (e, t, n) => L(e, t, n, /* @__PURE__ */ new Set()), z = (e) => e.find((e) => e.type === "origin") || null, B = (e, t, n) => {
136
+ if (!e) return z(t);
137
+ let r = n.find((t) => t.sourceNodeId === e.id);
138
+ return r && t.find((e) => e.id === r.destinationNodeId) || null;
139
+ };
140
+ //#endregion
141
+ //#region src/utils/node-tree/get-next-node-from-condition.ts
142
+ async function V(e, t, n, r) {
143
+ let i = e ? "true" : "false", a = r.find((e) => e.sourceNodeHandle === i && e.sourceNodeId === t);
144
+ return n.find((e) => e.id === a?.destinationNodeId);
145
+ }
146
+ //#endregion
147
+ //#region src/entities/experience-instance/experience-instance.ts
148
+ var H = c("experience-instance"), U = p(({ client: n, experience: r, target: i, options: c }) => {
149
+ let p = u(), m = u(), h = u(), g = u(), _ = u(), v = u(), y = r.componentStore, b = H.store("transitioning"), x = n.history.entriesStore.map((e) => e.filter((e) => e.experienceId === r.id)), S = x.map((e) => e.filter((e) => j(e.node))), C = x.map((e) => e.at(-1)?.node || null), w = o(r.treeStore, C, ({ steps: e }, t) => e.find((e) => t && j(t) && e.id === t.stepId) || null), T = o(r.treeStore, S, ({ steps: e }, t) => {
150
+ let n = t.at(-2);
151
+ if (!n || !j(n.node)) return null;
152
+ let r = n.node;
153
+ return e.find((e) => e.id === r.stepId) || null;
154
+ }), E = o(r.treeStore, C, ({ nodes: e, edges: t }, n) => n ? ee(e, t, n) : []), D = o(r.treeStore, C, ({ nodes: e, edges: t }, n) => n ? R(e, t, n) : [-1, -1]), O = o(r.treeStore, C, ({ nodes: e, edges: t }, n) => n ? te(e, t, n) : [-1, -1]), k = H.store(!1), F = s(k, {
155
+ open: () => !0,
156
+ close: () => !1,
157
+ toggle: (e) => !e,
158
+ set: (e, t) => t
159
+ }), I = l(async () => {
160
+ n.history.back({ experienceId: r.id });
161
+ }), L = a({
162
+ source: r.treeStore,
163
+ effect: async (e, t) => {
164
+ let i = e.nodes.find((e) => j(e) && e.stepId === t);
165
+ i && n.history.push({
166
+ experienceId: r.id,
167
+ node: i
168
+ });
169
+ }
170
+ }), U = a({
171
+ source: C,
172
+ effect: (e) => {}
173
+ }), W = a({
174
+ source: r.treeStore,
175
+ effect: async ({ nodes: e }) => z(e)
176
+ }), G = a({
177
+ source: r.treeStore,
178
+ effect: async ({ nodes: e, edges: t }, n) => {
179
+ if (N(n)) return B(n, e, t);
180
+ }
181
+ }), K = a({
182
+ source: r.treeStore,
183
+ effect: async ({ nodes: e, edges: r, conditions: i }, a) => {
184
+ if (!A(a)) return;
185
+ let o = i.find((e) => e.id === a.conditionId);
186
+ if (!o) return;
187
+ let s = a.id;
188
+ return V(!!await t(n, o.condition), s, e, r);
189
+ }
190
+ }), q = a({
191
+ source: r.treeStore,
192
+ effect: async ({ nodes: e, edges: t }, r) => {
193
+ if (!P(r)) return;
194
+ let i = r.action;
195
+ if (!i) {
196
+ `${r.id}`;
197
+ return;
198
+ }
199
+ let a = n.actions.getByName(i).getState();
200
+ if (!a) {
201
+ `${i}`;
202
+ let n = t.find((e) => e.sourceNodeId === r.id && e.sourceNodeHandle === "false");
203
+ return n ? e.find((e) => e.id === n.destinationNodeId) : null;
204
+ }
205
+ if (typeof a.action != "function") {
206
+ `${i}`;
207
+ let n = t.find((e) => e.sourceNodeId === r.id && e.sourceNodeHandle === "false");
208
+ return n ? e.find((e) => e.id === n.destinationNodeId) : null;
209
+ }
210
+ try {
211
+ `${i}`, await a.action(i);
212
+ let n = t.find((e) => e.sourceNodeId === r.id && e.sourceNodeHandle === "true");
213
+ if (!n) return `${r.id}`, null;
214
+ let o = e.find((e) => e.id === n.destinationNodeId);
215
+ return `${i}${o?.id}`, o || null;
216
+ } catch {
217
+ `${i}`;
218
+ let n = t.find((e) => e.sourceNodeId === r.id && e.sourceNodeHandle === "false");
219
+ if (!n) return `${r.id}`, null;
220
+ let a = e.find((e) => e.id === n.destinationNodeId);
221
+ return `${i}${a?.id}`, a || null;
222
+ }
223
+ }
224
+ }), ne = l((e) => {
225
+ M(e) && n.experiences.launch({ id: e.experienceId });
226
+ }), J = a({
227
+ source: [C, r.treeStore],
228
+ effect: async ([e, { nodes: t, edges: n }]) => B(e, t, n)
229
+ }), Y = a({
230
+ source: [C, r.treeStore],
231
+ effect: async ([e, { nodes: t, edges: n }]) => B(e, t, n)
232
+ }), re = l((e) => {
233
+ n.history.push({
234
+ experienceId: r.id,
235
+ node: e
236
+ });
237
+ }), X = a({
238
+ source: r.configStore,
239
+ effect: async ({ initializeOpenLogic: r }) => c?.initialiseOpen === void 0 ? e(r) ? !!await t(n, r) : r ?? !1 : c.initialiseOpen
240
+ }), Z = Object.freeze({
241
+ id: Math.random().toString(36).substring(7),
242
+ experienceId: r.id,
243
+ configStore: r.configStore,
244
+ target: i,
245
+ componentStore: y,
246
+ stateStore: b,
247
+ isOpenStore: k,
248
+ open: F.open,
249
+ close: F.close,
250
+ toggleOpen: F.toggle,
251
+ setOpen: F.set,
252
+ treeStore: r.treeStore,
253
+ fieldsStore: r.fieldsStore,
254
+ currentNodeStore: C,
255
+ currentStepStore: w,
256
+ previousStepStore: T,
257
+ nextReachableStepNodesStore: E,
258
+ stepsToOriginStore: D,
259
+ stepsToLeafStore: O,
260
+ goToNextStep: m,
261
+ goToPreviousStep: h,
262
+ goToStepById: g,
263
+ stepsHistoryStore: S
264
+ }), Q = u(), $ = u();
265
+ return d({
266
+ source: C,
267
+ target: Q
268
+ }), d({
269
+ clock: Q,
270
+ filter: (e) => e === null,
271
+ target: W
272
+ }), d({
273
+ clock: Q,
274
+ filter: (e) => e !== null,
275
+ target: $
276
+ }), f({
277
+ source: $,
278
+ match: (e) => A(e) ? "condition" : j(e) ? "step" : M(e) ? "launchExperience" : N(e) ? "origin" : P(e) ? "action" : "other",
279
+ cases: {
280
+ origin: G,
281
+ condition: K,
282
+ step: U,
283
+ launchExperience: ne,
284
+ action: q,
285
+ __: u()
286
+ }
287
+ }), d({
288
+ clock: [
289
+ K.doneData,
290
+ G.doneData,
291
+ W.doneData,
292
+ Y.doneData,
293
+ J.doneData,
294
+ q.doneData
295
+ ],
296
+ filter: Boolean,
297
+ target: re
298
+ }), d({
299
+ clock: m,
300
+ target: Y
301
+ }), d({
302
+ clock: m,
303
+ source: w,
304
+ filter: Boolean,
305
+ target: n.eventBus.prepend((e) => ({
306
+ type: "step_submit",
307
+ step: e,
308
+ experience: Z
309
+ }))
310
+ }), d({
311
+ clock: Y.done,
312
+ source: w,
313
+ filter: Boolean,
314
+ target: n.eventBus.prepend((e) => ({
315
+ type: "step_submit_success",
316
+ step: e,
317
+ experience: Z
318
+ }))
319
+ }), d({
320
+ clock: Y.fail,
321
+ source: w,
322
+ filter: Boolean,
323
+ target: n.eventBus.prepend((e) => ({
324
+ type: "step_submit_error",
325
+ step: e,
326
+ experience: Z
327
+ }))
328
+ }), d({
329
+ clock: h,
330
+ target: I
331
+ }), d({
332
+ clock: g,
333
+ target: L
334
+ }), d({
335
+ source: o([
336
+ K.pending,
337
+ G.pending,
338
+ W.pending,
339
+ Y.pending
340
+ ]),
341
+ fn: (e) => e.some(Boolean) ? "transitioning" : "ready",
342
+ target: b
343
+ }), d({
344
+ clock: U.doneData,
345
+ source: w,
346
+ filter: Boolean,
347
+ target: n.eventBus.prepend((e) => ({
348
+ type: "step_enter",
349
+ step: e,
350
+ experience: Z
351
+ }))
352
+ }), d({
353
+ clock: v,
354
+ target: X
355
+ }), d({
356
+ source: X.doneData,
357
+ fn: Boolean,
358
+ target: k
359
+ }), d({
360
+ source: C,
361
+ clock: p,
362
+ filter: (e) => e ? N(e) : !0,
363
+ target: J
364
+ }), d({
365
+ source: k,
366
+ filter: Boolean,
367
+ target: p
368
+ }), d({
369
+ source: k,
370
+ filter: Boolean,
371
+ target: n.eventBus.prepend(() => ({
372
+ type: "experience_open",
373
+ experience: Z
374
+ }))
375
+ }), d({
376
+ source: k,
377
+ filter: (e) => !e,
378
+ target: n.eventBus.prepend(() => ({
379
+ type: "experience_close",
380
+ experience: Z
381
+ }))
382
+ }), d({
383
+ clock: _,
384
+ target: [v]
385
+ }), _(), Z;
386
+ });
387
+ function W(e) {
388
+ return m(U, e);
389
+ }
390
+ var G = p(({ client: e }) => {
391
+ let t = H.store({}), n = u(), r = u(), i = u(), a = s(t, {
392
+ register(e, t) {
393
+ let n = [...e[t.experienceId] ?? []];
394
+ return n.push(t), {
395
+ ...e,
396
+ [t.experienceId]: n
397
+ };
398
+ },
399
+ unregister(e, t) {
400
+ let n = t.experienceId, r = e[n]?.filter((e) => e !== t);
401
+ return {
402
+ ...e,
403
+ [n]: r ?? []
404
+ };
405
+ }
406
+ }), o = l(({ experience: t, target: n, options: r }) => W({
407
+ client: e,
408
+ experience: t,
409
+ target: n,
410
+ options: r
411
+ })), c = l((e) => {
412
+ a.register(e);
413
+ }), f = l((e) => {
414
+ e.target && y(e.target, () => {
415
+ i(e);
416
+ });
417
+ }), p = l((e) => {
418
+ a.unregister(e);
419
+ }), m = l((t) => {
420
+ let n = t.componentStore.getState();
421
+ if (!n) return;
422
+ let r = n.frameworkStore.getState();
423
+ if (!r) {
424
+ `${n.name}`;
425
+ return;
426
+ }
427
+ let i = t.target;
428
+ if (!i) {
429
+ `${t.experienceId}`;
430
+ return;
431
+ }
432
+ let a = _(i);
433
+ try {
434
+ r.render(a, n.component, e, t);
435
+ } catch {}
436
+ });
437
+ d({
438
+ clock: n,
439
+ target: o
440
+ }), d({
441
+ clock: i,
442
+ target: p
443
+ }), d({
444
+ clock: o.doneData,
445
+ target: [
446
+ c,
447
+ f,
448
+ r
449
+ ]
450
+ }), d({
451
+ clock: o.doneData,
452
+ target: e.eventBus.prepend((e) => ({
453
+ type: "experience_initialize",
454
+ experience: e
455
+ }))
456
+ }), d({
457
+ clock: r,
458
+ target: m
459
+ });
460
+ function h(e, t, r) {
461
+ n({
462
+ experience: e,
463
+ target: t,
464
+ options: r
465
+ });
466
+ }
467
+ let g = t.map((e) => Object.values(e).flat());
468
+ function v(e) {
469
+ return t.map((t) => t[e] || [], { skipVoid: !1 });
470
+ }
471
+ return {
472
+ spawn: h,
473
+ getByExperienceId: v,
474
+ listStore: g
475
+ };
476
+ });
477
+ function K(e) {
478
+ return m(G, e);
479
+ }
480
+ //#endregion
481
+ export { v as a, T as c, w as i, K as n, C as o, j as r, D as s, W as t };