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

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 (135) hide show
  1. package/dist/api-WKe5XBeR.cjs +1 -0
  2. package/dist/api-ZK-H-MlI.js +37 -0
  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/plugins/web-components/index.js +1 -1
  13. package/dist/cjs/plugins/window-object/index.js +1 -1
  14. package/dist/cjs/server/index.js +1 -1
  15. package/dist/esm/form/index.js +428 -0
  16. package/dist/esm/index.js +1138 -1291
  17. package/dist/esm/plugins/create-experience/index.js +424 -509
  18. package/dist/esm/plugins/dynamic-experiences/index.js +120 -204
  19. package/dist/esm/plugins/experience-browser-storage/index.js +32 -37
  20. package/dist/esm/plugins/history-browser-storage/index.js +23 -25
  21. package/dist/esm/plugins/responses-browser-storage/index.js +36 -39
  22. package/dist/esm/plugins/responses-indexeddb/index.js +77 -80
  23. package/dist/esm/plugins/single-page-app/index.js +31 -35
  24. package/dist/esm/plugins/web-components/index.js +18 -20
  25. package/dist/esm/plugins/window-object/index.js +9 -9
  26. package/dist/esm/server/index.js +95 -89
  27. package/dist/experience-instance-DZiAwXph.js +481 -0
  28. package/dist/experience-instance-Ddk4Jktn.cjs +1 -0
  29. package/dist/id-Bv44ilEo.cjs +1 -0
  30. package/dist/id-CRqy981z.js +4 -0
  31. package/dist/logger-6z_gb4rA.js +4 -0
  32. package/dist/logger-fbvQC40v.cjs +1 -0
  33. package/dist/object-C82v79xc.js +25 -0
  34. package/dist/object-CUJOjanb.cjs +1 -0
  35. package/dist/rules-logic-B7vJrWyO.js +231 -0
  36. package/dist/rules-logic-CXr4wXcG.cjs +1 -0
  37. package/dist/storage-6Xk0uAxB.js +103 -0
  38. package/dist/storage-B6lQtc4-.cjs +1 -0
  39. package/dist/supports-0XIfd4-R.js +85 -0
  40. package/dist/supports-Dsjg-82e.cjs +1 -0
  41. package/dist/types/entities/action/action.d.ts.map +1 -1
  42. package/dist/types/entities/experience/experience.d.ts +31 -48
  43. package/dist/types/entities/experience/experience.d.ts.map +1 -1
  44. package/dist/types/entities/experience-instance/experience-instance.d.ts +2 -2
  45. package/dist/types/entities/experience-instance/experience-instance.d.ts.map +1 -1
  46. package/dist/types/entities/feature/feature.d.ts.map +1 -1
  47. package/dist/types/entities/field/field.d.ts +12 -17
  48. package/dist/types/entities/field/field.d.ts.map +1 -1
  49. package/dist/types/entities/history/history.d.ts.map +1 -1
  50. package/dist/types/entities/response/response.d.ts +7 -9
  51. package/dist/types/entities/response/response.d.ts.map +1 -1
  52. package/dist/types/form/build-responses.d.ts +14 -0
  53. package/dist/types/form/build-responses.d.ts.map +1 -0
  54. package/dist/types/form/create-field-evaluator.d.ts +19 -0
  55. package/dist/types/form/create-field-evaluator.d.ts.map +1 -0
  56. package/dist/types/form/create-field-validation.d.ts +44 -0
  57. package/dist/types/form/create-field-validation.d.ts.map +1 -0
  58. package/dist/types/form/create-form.d.ts +66 -0
  59. package/dist/types/form/create-form.d.ts.map +1 -0
  60. package/dist/types/form/create-submit-pipeline.d.ts +58 -0
  61. package/dist/types/form/create-submit-pipeline.d.ts.map +1 -0
  62. package/dist/types/form/get-step-fields.d.ts +5 -0
  63. package/dist/types/form/get-step-fields.d.ts.map +1 -0
  64. package/dist/types/form/index.d.ts +10 -0
  65. package/dist/types/form/index.d.ts.map +1 -0
  66. package/dist/types/index.d.ts +1 -3
  67. package/dist/types/index.d.ts.map +1 -1
  68. package/dist/types/logic-engine.d.ts +2 -8
  69. package/dist/types/logic-engine.d.ts.map +1 -1
  70. package/dist/types/picked.d.ts +23 -42
  71. package/dist/types/picked.d.ts.map +1 -1
  72. package/dist/types/plugins/create-experience/create-experience.d.ts +37 -70
  73. package/dist/types/plugins/create-experience/create-experience.d.ts.map +1 -1
  74. package/dist/types/plugins/create-experience/index.d.ts +1 -1
  75. package/dist/types/plugins/create-experience/index.d.ts.map +1 -1
  76. package/dist/types/plugins/create-experience/plugin.d.ts.map +1 -1
  77. package/dist/types/plugins/dynamic-experiences/plugin.d.ts +5 -20
  78. package/dist/types/plugins/dynamic-experiences/plugin.d.ts.map +1 -1
  79. package/dist/types/plugins/dynamic-experiences/types.d.ts +0 -46
  80. package/dist/types/plugins/dynamic-experiences/types.d.ts.map +1 -1
  81. package/dist/types/plugins/experience-browser-storage/plugin.d.ts +2 -1
  82. package/dist/types/plugins/experience-browser-storage/plugin.d.ts.map +1 -1
  83. package/dist/types/plugins/history-browser-storage/plugin.d.ts +1 -0
  84. package/dist/types/plugins/history-browser-storage/plugin.d.ts.map +1 -1
  85. package/dist/types/plugins/responses-browser-storage/plugin.d.ts +2 -1
  86. package/dist/types/plugins/responses-browser-storage/plugin.d.ts.map +1 -1
  87. package/dist/types/plugins/responses-indexeddb/plugin.d.ts.map +1 -1
  88. package/dist/types/plugins/single-page-app/plugin.d.ts +1 -1
  89. package/dist/types/plugins/single-page-app/plugin.d.ts.map +1 -1
  90. package/dist/types/utils/dom.d.ts +0 -3
  91. package/dist/types/utils/dom.d.ts.map +1 -1
  92. package/dist/types/utils/events.d.ts +2 -2
  93. package/dist/types/utils/events.d.ts.map +1 -1
  94. package/dist/types/utils/global-obj.d.ts +0 -1
  95. package/dist/types/utils/global-obj.d.ts.map +1 -1
  96. package/dist/types/utils/indexed-db.d.ts +2 -1
  97. package/dist/types/utils/indexed-db.d.ts.map +1 -1
  98. package/dist/types/utils/logger.d.ts.map +1 -1
  99. package/dist/types/utils/node-tree/min-max-steps-to-leaf.d.ts.map +1 -1
  100. package/dist/types/utils/node-tree/min-max-steps-to-origin.d.ts.map +1 -1
  101. package/dist/types/utils/node-tree/next-reachable-step-nodes.d.ts +3 -3
  102. package/dist/types/utils/node-tree/next-reachable-step-nodes.d.ts.map +1 -1
  103. package/dist/types/utils/nodes.d.ts +2 -7
  104. package/dist/types/utils/nodes.d.ts.map +1 -1
  105. package/dist/types/utils/object.d.ts +0 -8
  106. package/dist/types/utils/object.d.ts.map +1 -1
  107. package/dist/types/utils/picked-config.d.ts +1 -1
  108. package/dist/types/utils/picked-config.d.ts.map +1 -1
  109. package/dist/types/utils/search-params.d.ts.map +1 -1
  110. package/dist/types/utils/storage.d.ts.map +1 -1
  111. package/package.json +18 -8
  112. package/dist/api-GlH9T8_1.js +0 -32
  113. package/dist/api-GvmToTw0.cjs +0 -1
  114. package/dist/experience-instance-CxiOyYPf.cjs +0 -1
  115. package/dist/experience-instance-DCknHRkX.js +0 -804
  116. package/dist/id-BKIWbSTy.cjs +0 -1
  117. package/dist/id-BW-g3y32.js +0 -6
  118. package/dist/logger-BsmHUUw1.cjs +0 -1
  119. package/dist/logger-C9a75KZn.js +0 -5
  120. package/dist/nodes-DQt4TfuO.js +0 -26
  121. package/dist/nodes-DsL8kMSX.cjs +0 -1
  122. package/dist/object-BbFTsGh3.cjs +0 -1
  123. package/dist/object-JwZ58NOH.js +0 -28
  124. package/dist/storage-Be5xWNPC.cjs +0 -1
  125. package/dist/storage-Co_LbKr_.js +0 -239
  126. package/dist/supports-8YT4QKI7.js +0 -95
  127. package/dist/supports-YvpQZxbh.cjs +0 -1
  128. package/dist/types/entities/condition/condition.d.ts +0 -17
  129. package/dist/types/entities/condition/condition.d.ts.map +0 -1
  130. package/dist/types/entities/project/project.d.ts +0 -9
  131. package/dist/types/entities/project/project.d.ts.map +0 -1
  132. package/dist/types/entities/step/step.d.ts +0 -20
  133. package/dist/types/entities/step/step.d.ts.map +0 -1
  134. package/dist/types/utils/key.d.ts +0 -12
  135. package/dist/types/utils/key.d.ts.map +0 -1
@@ -1,804 +0,0 @@
1
- import { createDomain as bt, createEvent as I, combine as R, createApi as dt, createEffect as $, attach as O, sample as m, split as vt } from "effector";
2
- import { createFactory as pt, invoke as gt } from "@withease/factories";
3
- import { i as C, r as Y, a as Z, b as at, c as ct, d as ut } from "./nodes-DQt4TfuO.js";
4
- import { a as At, s as mt, j as Ot } from "./supports-8YT4QKI7.js";
5
- import { l as E } from "./logger-C9a75KZn.js";
6
- import { i as Ft } from "./object-JwZ58NOH.js";
7
- function Bt(t) {
8
- return typeof t == "number" && !isNaN(t);
9
- }
10
- function U(t) {
11
- return typeof t == "string";
12
- }
13
- function N(t) {
14
- return Array.isArray(t);
15
- }
16
- function St(t) {
17
- return t instanceof Promise;
18
- }
19
- function ft(t) {
20
- return typeof t == "object" && t !== null && !Array.isArray(t) && Object.keys(t).length === 1;
21
- }
22
- function g(t) {
23
- if (Bt(t)) return t;
24
- const e = parseFloat(`${t}`);
25
- return isNaN(e) ? 0 : e;
26
- }
27
- function P(t) {
28
- return `${t}`;
29
- }
30
- const _t = {
31
- // eslint-disable-next-line eqeqeq
32
- "==": (t, e) => t == e,
33
- "===": (t, e) => t === e,
34
- // eslint-disable-next-line eqeqeq
35
- "!=": (t, e) => t != e,
36
- "!==": (t, e) => t !== e,
37
- ">": (t, e) => g(t) > g(e),
38
- ">=": (t, e) => g(t) >= g(e),
39
- "<": (t, e, r) => {
40
- const n = g(t), s = g(e);
41
- if (r === void 0) return n < s;
42
- const a = g(r);
43
- return n < s && s < a;
44
- },
45
- "<=": (t, e, r) => {
46
- const n = g(t), s = g(e);
47
- if (r === void 0) return n <= s;
48
- const a = g(r);
49
- return n <= s && s <= a;
50
- },
51
- "!!": async (t) => await v(t),
52
- "!": async (t) => !await v(t),
53
- "%": (t, e) => g(t) % g(e),
54
- // eslint-disable-next-line sonarjs/function-return-type
55
- log: (t) => (console.log(t), t),
56
- in: (t, e) => e ? U(e) ? e.indexOf(P(t)) !== -1 : N(e) ? e.includes(t) : !1 : !1,
57
- cat: (...t) => t.map(P).join(""),
58
- /* eslint-disable sonarjs/deprecation */
59
- substr: (t, e, r) => {
60
- const n = P(t), s = g(e);
61
- if (r === void 0) return n.substr(s);
62
- const a = g(r);
63
- if (a < 0) {
64
- const o = n.substr(s);
65
- return o.substr(0, o.length + a);
66
- }
67
- return n.substr(s, a);
68
- },
69
- /* eslint-enable sonarjs/deprecation */
70
- "+": (...t) => t.reduce((e, r) => g(e) + g(r), 0),
71
- "*": (...t) => t.reduce((e, r) => g(e) * g(r), 1),
72
- "-": (t, e) => {
73
- const r = g(t);
74
- return e === void 0 ? -r : r - g(e);
75
- },
76
- "/": (t, e) => g(t) / g(e),
77
- min: (...t) => Math.min(...t.map(g)),
78
- max: (...t) => Math.max(...t.map(g)),
79
- merge: (...t) => t.reduce((e, r) => N(r) ? e.concat(r) : e.concat([r]), []),
80
- var(t, e) {
81
- const r = arguments.length > 1 ? e : null;
82
- if (t === "" || t === "." || t === null || t === void 0)
83
- return this;
84
- if (typeof t == "number" && Array.isArray(this))
85
- return t >= 0 && t < this.length ? this[t] : r;
86
- const n = P(t);
87
- if (n === "" || n === ".")
88
- return this;
89
- const s = n.split(".");
90
- let a = this;
91
- for (const o of s) {
92
- if (a == null)
93
- return r;
94
- if (Array.isArray(a)) {
95
- const u = parseInt(o, 10);
96
- isNaN(u) ? a = a[o] : a = a[u];
97
- } else
98
- a = a[o];
99
- }
100
- return a !== void 0 ? a : r;
101
- },
102
- async missing(...t) {
103
- const e = N(t[0]) ? t[0] : t, r = [];
104
- for (const n of e) {
105
- const s = await p({ var: n }, this);
106
- (s === null || s === "") && r.push(`${n}`);
107
- }
108
- return r;
109
- },
110
- async missing_some(t, e) {
111
- const r = await p({ missing: e }, this);
112
- if (!N(r) || !N(e)) return [];
113
- const n = r.filter(U);
114
- return e.filter(U).length - n.length >= g(t) ? [] : n;
115
- },
116
- /**
117
- * Invoke operator - executes a function with optional arguments
118
- *
119
- * Object format (no arguments):
120
- * { "invoke": { "var": "functionName" } }
121
- *
122
- * Array format (with arguments):
123
- * { "invoke": [{ "var": "functionName" }, arg1, arg2, ...] }
124
- *
125
- * Arguments are evaluated as JSONLogic expressions before being passed to the function.
126
- */
127
- // eslint-disable-next-line sonarjs/function-return-type
128
- invoke(...t) {
129
- const [e, ...r] = t;
130
- return typeof e != "function" ? null : Reflect.apply(e, null, r);
131
- },
132
- regexp_matches(t, e) {
133
- let r = t, n = "";
134
- if (N(t)) {
135
- const [a, o] = t;
136
- r = a, n = o;
137
- }
138
- return !U(r) || !U(n) ? !1 : new RegExp(r, n).test(P(e));
139
- },
140
- throw(t) {
141
- throw new Error(P(t));
142
- }
143
- };
144
- async function p(t, e) {
145
- if (!t) return t;
146
- if (St(t))
147
- return p(await t, e);
148
- if (N(t))
149
- return Promise.all(t.map((o) => p(o, e)));
150
- if (!ft(t)) return t;
151
- const r = $t(t);
152
- let n = r ? t[r] ?? [] : [];
153
- switch (N(n) || (n = [n]), r) {
154
- case "if":
155
- case "?:":
156
- for (let o = 0; o < n.length - 1; o += 2)
157
- if (await v(await p(n[o], e)))
158
- return p(n[o + 1], e);
159
- return n.length % 2 === 1 ? p(n[n.length - 1], e) : null;
160
- case "and": {
161
- let o = null;
162
- for (const u of n)
163
- if (o = await p(u, e), !await v(o))
164
- return o;
165
- return o;
166
- }
167
- case "or": {
168
- let o = null;
169
- for (const u of n)
170
- if (o = await p(u, e), await v(o)) return o;
171
- return o;
172
- }
173
- case "map": {
174
- const o = await p(n[0], e);
175
- return N(o) ? await Promise.all(o.map((u) => p(n[1], u))) : [];
176
- }
177
- case "filter": {
178
- const o = await p(n[0], e);
179
- return N(o) ? (await Promise.all(
180
- o.map(async (d) => {
181
- const h = await v(await p(n[1], d));
182
- return { item: d, shouldInclude: h };
183
- })
184
- )).filter(({ shouldInclude: d }) => d).map(({ item: d }) => d) : [];
185
- }
186
- case "reduce": {
187
- const o = await p(n[0], e);
188
- if (!N(o))
189
- return n.length > 2 ? await p(n[2], e) : null;
190
- const u = n[1];
191
- let h = n.length > 2 ? await p(n[2], e) : null;
192
- for (const b of o)
193
- h = await p(u, { current: b, accumulator: h });
194
- return h;
195
- }
196
- case "all": {
197
- const o = await p(n[0], e);
198
- if (!N(o) || o.length === 0) return !1;
199
- for (const u of o)
200
- if (!await v(await p(n[1], u))) return !1;
201
- return !0;
202
- }
203
- case "some": {
204
- const o = await p(n[0], e);
205
- if (!N(o)) return !1;
206
- for (const u of o)
207
- if (await v(await p(n[1], u))) return !0;
208
- return !1;
209
- }
210
- case "none": {
211
- const o = await p(n[0], e);
212
- if (!N(o)) return !0;
213
- for (const u of o)
214
- if (await v(await p(n[1], u))) return !1;
215
- return !0;
216
- }
217
- case "catch":
218
- try {
219
- return await p(n[0], e);
220
- } catch (o) {
221
- return ft(o) ? await p(o, e) : n[1] ? await p(n[1], o) : o instanceof Error ? o.message : o;
222
- }
223
- }
224
- const s = await Promise.all(n.map((o) => p(o, e))), a = r ? _t[r] : void 0;
225
- if (!a) throw new Error(`Unrecognized operation ${r}`);
226
- return a.apply(e, s);
227
- }
228
- async function v(t) {
229
- return St(t) ? v(await t) : !(Array.isArray(t) && t.length === 0) && !!t;
230
- }
231
- function $t(t) {
232
- return Object.keys(t)[0];
233
- }
234
- function Mt(t) {
235
- return !Ft(t);
236
- }
237
- async function lt(t, e, r) {
238
- const n = t.getStateSnapshot(), s = t.predicates.listStore.getState().reduce((u, d) => ({
239
- ...u,
240
- [d.name]: (...h) => d.predicate({ ...n, args: h })
241
- }), {}), a = t.features.listStore.getState().reduce((u, d) => ({
242
- ...u,
243
- [d.id]: async () => {
244
- const { bucket: h } = await d.getBucket();
245
- return h;
246
- }
247
- }), {}), o = {
248
- ...r,
249
- responses: t.responses.getAllStore.getState(),
250
- location: typeof n.location == "object" ? {
251
- hash: n.location.hash,
252
- host: n.location.host,
253
- hostname: n.location.hostname,
254
- href: n.location.href,
255
- origin: n.location.origin,
256
- pathname: n.location.pathname,
257
- port: n.location.port,
258
- protocol: n.location.protocol,
259
- search: n.location.search
260
- } : void 0,
261
- predicates: s,
262
- features: a
263
- };
264
- return await p(e, o);
265
- }
266
- function Tt(t) {
267
- return !At() || !mt() ? [] : Array.from(window.document.querySelectorAll(t)).filter(
268
- (e) => e instanceof HTMLElement
269
- );
270
- }
271
- const Lt = "open";
272
- function Dt(t) {
273
- if (!Ot())
274
- throw new Error("Shadow DOM is not supported in this environment");
275
- return t.attachShadow({ mode: Lt });
276
- }
277
- function ne() {
278
- return new Promise((t, e) => {
279
- if (!mt()) {
280
- e();
281
- return;
282
- }
283
- document.readyState !== "loading" ? t() : document.addEventListener("readystatechange", () => t(), { once: !0 });
284
- });
285
- }
286
- function Rt(t, e) {
287
- const r = new MutationObserver((n) => {
288
- document.contains(t) || (r.disconnect(), e());
289
- });
290
- r.observe(document.body, { childList: !0, subtree: !0 });
291
- }
292
- const G = "picked-root", V = "picked-target", Pt = "picked-root";
293
- function re(t, e) {
294
- return [
295
- ...t,
296
- // Target and replace picked-root web components
297
- {
298
- selector: `${Pt}[experience-id="${e}"]`,
299
- placement: "replace"
300
- }
301
- ].flatMap((n) => {
302
- const s = Tt(n.selector).filter(
303
- (a) => !Ct(a, e) && !Ht(a, e)
304
- );
305
- return {
306
- ...n,
307
- elements: s
308
- };
309
- });
310
- }
311
- function oe(t, e) {
312
- return t.flatMap((r) => r.elements.map((n) => Ut(n, r.placement, e)));
313
- }
314
- function ie(t, e) {
315
- t.classList.add(V), t.classList.add(`${V}-${e}`);
316
- }
317
- function Ct(t, e) {
318
- return e ? t.classList.contains(`${V}-${e}`) : t.classList.contains(`${V}`);
319
- }
320
- function Ht(t, e) {
321
- return e ? t.classList.contains(`${G}-${e}`) : t.classList.contains(G);
322
- }
323
- function jt(t) {
324
- const e = document.createElement("div");
325
- return e.style.display = "block", e.classList.add(G), e.classList.add(`${G}-${t}`), e;
326
- }
327
- function Ut(t, e, r) {
328
- let n;
329
- const s = jt(r);
330
- if (t instanceof Document)
331
- n = t.body.appendChild(s);
332
- else {
333
- switch (e) {
334
- case "replace":
335
- t.replaceWith(s);
336
- break;
337
- case "before":
338
- t.before(s);
339
- break;
340
- case "after":
341
- t.after(s);
342
- break;
343
- case "prepend":
344
- t.prepend(s);
345
- break;
346
- default:
347
- t.append(s);
348
- break;
349
- }
350
- n = s;
351
- }
352
- return n;
353
- }
354
- const ht = (t, e, r, n, s = /* @__PURE__ */ new Set()) => s.has(r.id) ? [] : (s.add(r.id), C(r) && !n ? [r] : e.filter((o) => o.sourceNodeId === r.id).flatMap((o) => {
355
- const u = t.find((d) => d.id === o.destinationNodeId);
356
- return u ? ht(t, e, u, !1, s) : [];
357
- })), Kt = (t, e, r) => ht(t, e, r, !0, /* @__PURE__ */ new Set()), yt = (t, e, r, n, s = /* @__PURE__ */ new Set()) => {
358
- if (s.has(r.id)) return [-1, -1];
359
- s.add(r.id);
360
- const a = e.filter((d) => d.sourceNodeId === r.id);
361
- if (a.length === 0) return [0, 0];
362
- let o = 1 / 0, u = -1 / 0;
363
- for (const d of a) {
364
- const h = t.find((T) => T.id === d.destinationNodeId);
365
- if (!h) continue;
366
- const [b, F] = yt(
367
- t,
368
- e,
369
- h,
370
- !1,
371
- new Set(s)
372
- );
373
- b !== -1 && (o = Math.min(o, b + 1), u = Math.max(u, F + 1));
374
- }
375
- return o === 1 / 0 ? [-1, -1] : [o, u];
376
- }, Wt = (t, e, r) => yt(t, e, r, !0, /* @__PURE__ */ new Set()), wt = (t, e, r, n = /* @__PURE__ */ new Set()) => {
377
- if (n.has(r.id)) return [-1, -1];
378
- if (n.add(r.id), r.type === "origin") return [0, 0];
379
- const s = e.filter((u) => u.destinationNodeId === r.id);
380
- if (s.length === 0) return [-1, -1];
381
- let a = 1 / 0, o = -1 / 0;
382
- for (const u of s) {
383
- const d = t.find((F) => F.id === u.sourceNodeId);
384
- if (!d) continue;
385
- const [h, b] = wt(
386
- t,
387
- e,
388
- d,
389
- new Set(n)
390
- );
391
- h !== -1 && (a = Math.min(a, h + 1), o = Math.max(o, b + 1));
392
- }
393
- return a === 1 / 0 ? [-1, -1] : [a, o];
394
- }, Gt = (t, e, r) => wt(t, e, r, /* @__PURE__ */ new Set()), xt = (t) => t.find((r) => r.type === "origin") || null, tt = (t, e, r) => {
395
- if (!t)
396
- return xt(e);
397
- const n = r.find((a) => a.sourceNodeId === t.id);
398
- if (!n)
399
- return null;
400
- const s = e.find((a) => a.id === n.destinationNodeId);
401
- return s || null;
402
- };
403
- async function Vt(t, e, r, n) {
404
- const s = t ? "true" : "false", a = n.find(
405
- (o) => o.sourceNodeHandle === s && o.sourceNodeId === e
406
- );
407
- return r.find((o) => o.id === a?.destinationNodeId);
408
- }
409
- const et = bt("experience-instance"), qt = pt(
410
- ({
411
- client: t,
412
- experience: e,
413
- target: r,
414
- options: n
415
- }) => {
416
- const s = I(), a = I(), o = I(), u = I(), d = I(), h = I(), b = e.componentStore, F = et.store("transitioning"), T = t.history.entriesStore.map((i) => i.filter((l) => l.experienceId === e.id)), K = T.map((i) => i.filter((l) => C(l.node))), c = T.map((i) => i.at(-1)?.node || null), S = R(
417
- t.steps.listStore,
418
- c,
419
- (i, l) => i.find((f) => l && C(l) && f.key === Y(l)) || null
420
- ), x = R(
421
- t.steps.listStore,
422
- K,
423
- (i, l) => {
424
- const f = l.at(-2);
425
- if (!f || !C(f.node))
426
- return null;
427
- const y = f.node;
428
- return i.find((B) => B.key === Y(y)) || null;
429
- }
430
- ), L = R(
431
- e.treeStore,
432
- c,
433
- ({ nodes: i, edges: l }, f) => f ? Kt(i, l, f) : []
434
- ), H = R(
435
- e.treeStore,
436
- c,
437
- ({ nodes: i, edges: l }, f) => f ? Gt(i, l, f) : [-1, -1]
438
- ), q = R(
439
- e.treeStore,
440
- c,
441
- ({ nodes: i, edges: l }, f) => f ? Wt(i, l, f) : [-1, -1]
442
- ), D = et.store(!1), W = dt(D, {
443
- open: () => !0,
444
- close: () => !1,
445
- toggle: (i) => !i,
446
- set: (i, l) => l
447
- }), Nt = $(async () => {
448
- t.history.back({ experienceId: e.id });
449
- }), Et = O({
450
- source: e.treeStore,
451
- effect: async (i, l) => {
452
- const f = i.nodes.find((y) => C(y) && Y(y) === l);
453
- f && t.history.push({ experienceId: e.id, node: f });
454
- }
455
- }), nt = O({
456
- source: c,
457
- effect: (i) => {
458
- }
459
- }), z = O({
460
- source: e.treeStore,
461
- effect: async ({ nodes: i }) => xt(i)
462
- }), X = O({
463
- source: e.treeStore,
464
- effect: async ({ nodes: i, edges: l }, f) => {
465
- if (Z(f))
466
- return tt(f, i, l);
467
- }
468
- }), J = O({
469
- source: e.treeStore,
470
- effect: async ({ nodes: i, edges: l, conditions: f }, y) => {
471
- if (!at(y))
472
- return;
473
- const B = y.conditionId ?? y.conditionalId, w = t.conditions.listStore.getState().find((_) => _.id === B)?.condition ?? f.find((_) => _.id === B)?.condition;
474
- if (!w)
475
- return;
476
- const A = await lt(t, w);
477
- return Vt(!!A, y.id, i, l);
478
- }
479
- }), rt = O({
480
- source: e.treeStore,
481
- effect: async ({ nodes: i, edges: l }, f) => {
482
- if (!ct(f))
483
- return;
484
- const y = f.action;
485
- if (!y) {
486
- E("warn", `Action node ${f.id} has no action name`);
487
- return;
488
- }
489
- const B = t.actions.getByName(y).getState();
490
- if (!B) {
491
- E("warn", `Action '${y}' not registered on client`);
492
- const k = l.find(
493
- (w) => w.sourceNodeId === f.id && w.sourceNodeHandle === "false"
494
- );
495
- return k ? i.find((w) => w.id === k.destinationNodeId) : null;
496
- }
497
- if (typeof B.action != "function") {
498
- E("warn", `Action '${y}' is not a function`);
499
- const k = l.find(
500
- (w) => w.sourceNodeId === f.id && w.sourceNodeHandle === "false"
501
- );
502
- return k ? i.find((w) => w.id === k.destinationNodeId) : null;
503
- }
504
- try {
505
- E("info", `Executing action: ${y}`), await B.action(y);
506
- const k = l.find(
507
- (A) => A.sourceNodeId === f.id && A.sourceNodeHandle === "true"
508
- );
509
- if (!k)
510
- return E("warn", `No 'true' edge found for action node ${f.id}`), null;
511
- const w = i.find((A) => A.id === k.destinationNodeId);
512
- return E("info", `Action '${y}' succeeded, moving to node ${w?.id}`), w || null;
513
- } catch (k) {
514
- E("warn", `Action '${y}' failed:`, k);
515
- const w = l.find(
516
- (_) => _.sourceNodeId === f.id && _.sourceNodeHandle === "false"
517
- );
518
- if (!w)
519
- return E("warn", `No 'false' edge found for action node ${f.id}`), null;
520
- const A = i.find((_) => _.id === w.destinationNodeId);
521
- return E("info", `Action '${y}' failed, moving to node ${A?.id}`), A || null;
522
- }
523
- }
524
- }), It = $((i) => {
525
- ut(i) && t.experiences.launch({ id: i.experienceId });
526
- }), ot = O({
527
- source: [c, e.treeStore],
528
- effect: async ([i, { nodes: l, edges: f }]) => tt(i, l, f)
529
- }), j = O({
530
- source: [c, e.treeStore],
531
- effect: async ([i, { nodes: l, edges: f }]) => tt(i, l, f)
532
- }), kt = $((i) => {
533
- t.history.push({ experienceId: e.id, node: i });
534
- }), it = O({
535
- source: e.configStore,
536
- effect: async ({ initializeOpenLogic: i }) => n?.initialiseOpen !== void 0 ? n.initialiseOpen : Mt(i) ? !!await lt(t, i) : i ?? !1
537
- }), M = Object.freeze({
538
- // eslint-disable-next-line sonarjs/pseudo-random -- instance ID is non-security-sensitive
539
- id: Math.random().toString(36).substring(7),
540
- // config
541
- experienceId: e.id,
542
- configStore: e.configStore,
543
- target: r,
544
- componentStore: b,
545
- // state
546
- stateStore: F,
547
- // open close
548
- isOpenStore: D,
549
- open: W.open,
550
- close: W.close,
551
- toggleOpen: W.toggle,
552
- setOpen: W.set,
553
- // nodes
554
- treeStore: e.treeStore,
555
- currentNodeStore: c,
556
- currentStepStore: S,
557
- previousStepStore: x,
558
- nextReachableStepNodesStore: L,
559
- stepsToOriginStore: H,
560
- stepsToLeafStore: q,
561
- // history
562
- goToNextStep: a,
563
- goToPreviousStep: o,
564
- goToStepById: u,
565
- stepsHistoryStore: K
566
- }), Q = I(), st = I();
567
- return m({
568
- source: c,
569
- target: Q
570
- }), m({
571
- clock: Q,
572
- filter: (i) => i === null,
573
- target: z
574
- }), m({
575
- clock: Q,
576
- filter: (i) => i !== null,
577
- target: st
578
- }), vt({
579
- source: st,
580
- match: (i) => at(i) ? "condition" : C(i) ? "step" : ut(i) ? "launchExperience" : Z(i) ? "origin" : ct(i) ? "action" : "other",
581
- cases: {
582
- origin: X,
583
- condition: J,
584
- step: nt,
585
- launchExperience: It,
586
- action: rt,
587
- __: I()
588
- }
589
- }), m({
590
- clock: [
591
- J.doneData,
592
- X.doneData,
593
- z.doneData,
594
- j.doneData,
595
- ot.doneData,
596
- rt.doneData
597
- ],
598
- filter: Boolean,
599
- target: kt
600
- }), m({
601
- clock: a,
602
- target: j
603
- }), m({
604
- clock: a,
605
- source: S,
606
- filter: Boolean,
607
- target: t.eventBus.prepend((i) => ({
608
- type: "step_submit",
609
- step: i,
610
- experience: M
611
- }))
612
- }), m({
613
- clock: j.done,
614
- source: S,
615
- filter: Boolean,
616
- target: t.eventBus.prepend((i) => ({
617
- type: "step_submit_success",
618
- step: i,
619
- experience: M
620
- }))
621
- }), m({
622
- clock: j.fail,
623
- source: S,
624
- filter: Boolean,
625
- target: t.eventBus.prepend((i) => ({
626
- type: "step_submit_error",
627
- step: i,
628
- experience: M
629
- }))
630
- }), m({
631
- clock: o,
632
- target: Nt
633
- }), m({ clock: u, target: Et }), m({
634
- source: R([
635
- J.pending,
636
- X.pending,
637
- z.pending,
638
- j.pending
639
- ]),
640
- fn: (i) => i.some(Boolean) ? "transitioning" : "ready",
641
- target: F
642
- }), m({
643
- clock: nt.doneData,
644
- source: S,
645
- filter: Boolean,
646
- target: t.eventBus.prepend((i) => ({
647
- type: "step_enter",
648
- step: i,
649
- experience: M
650
- }))
651
- }), m({
652
- clock: h,
653
- target: it
654
- }), m({
655
- source: it.doneData,
656
- fn: Boolean,
657
- target: D
658
- }), m({
659
- source: c,
660
- clock: s,
661
- filter: (i) => i ? Z(i) : !0,
662
- target: ot
663
- }), m({
664
- source: D,
665
- filter: Boolean,
666
- target: s
667
- }), m({
668
- source: D,
669
- filter: Boolean,
670
- target: t.eventBus.prepend(() => ({
671
- type: "experience_open",
672
- experience: M
673
- }))
674
- }), m({
675
- source: D,
676
- filter: (i) => !i,
677
- target: t.eventBus.prepend(() => ({
678
- type: "experience_close",
679
- experience: M
680
- }))
681
- }), m({
682
- clock: d,
683
- target: [h]
684
- }), d(), M;
685
- }
686
- );
687
- function zt(t) {
688
- return gt(qt, t);
689
- }
690
- const Xt = pt(({ client: t }) => {
691
- const e = et.store({}), r = I(), n = I(), s = I(), a = dt(e, {
692
- register(c, S) {
693
- const x = [
694
- ...c[S.experienceId] ?? []
695
- ];
696
- return x.push(S), {
697
- ...c,
698
- [S.experienceId]: x
699
- };
700
- },
701
- unregister(c, S) {
702
- const x = S.experienceId, L = c[x]?.filter(
703
- (H) => H !== S
704
- );
705
- return {
706
- ...c,
707
- [x]: L ?? []
708
- };
709
- }
710
- }), o = $(
711
- ({
712
- experience: c,
713
- target: S,
714
- options: x
715
- }) => zt({ client: t, experience: c, target: S, options: x })
716
- ), u = $((c) => {
717
- a.register(c);
718
- }), d = $(
719
- (c) => {
720
- c.target && Rt(c.target, () => {
721
- s(c);
722
- });
723
- }
724
- ), h = $((c) => {
725
- a.unregister(c);
726
- }), b = $((c) => {
727
- const S = c.componentStore.getState();
728
- if (!S) {
729
- E("warn", "No app component registered. Skipping init.");
730
- return;
731
- }
732
- const x = S.frameworkStore.getState();
733
- if (!x) {
734
- E(
735
- "error",
736
- `No framework registered for component '${S.name}'. Skipping rendering.`
737
- );
738
- return;
739
- }
740
- const L = c.target;
741
- if (!L) {
742
- E(
743
- "error",
744
- `No target element registered for experience '${c.experienceId}'. Skipping rendering.`
745
- );
746
- return;
747
- }
748
- const H = Dt(L);
749
- try {
750
- x.render(H, S.component, t, c);
751
- } catch (q) {
752
- E("error", q);
753
- }
754
- });
755
- m({
756
- clock: r,
757
- target: o
758
- }), m({
759
- clock: s,
760
- target: h
761
- }), m({
762
- clock: o.doneData,
763
- target: [
764
- u,
765
- d,
766
- n
767
- ]
768
- }), m({
769
- clock: o.doneData,
770
- target: t.eventBus.prepend((c) => ({
771
- type: "experience_initialize",
772
- experience: c
773
- }))
774
- }), m({
775
- clock: n,
776
- target: b
777
- });
778
- function F(c, S, x) {
779
- r({ experience: c, target: S, options: x });
780
- }
781
- const T = e.map((c) => Object.values(c).flat());
782
- function K(c) {
783
- return e.map((S) => S[c] || [], { skipVoid: !1 });
784
- }
785
- return {
786
- spawn: F,
787
- getByExperienceId: K,
788
- listStore: T
789
- };
790
- });
791
- function se(t) {
792
- return gt(Xt, t);
793
- }
794
- export {
795
- se as a,
796
- Ht as b,
797
- oe as c,
798
- ne as d,
799
- lt as e,
800
- zt as f,
801
- re as g,
802
- Mt as i,
803
- ie as t
804
- };