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