@picked/client 0.0.35 → 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.
- package/dist/cjs/index.js +2 -2
- package/dist/cjs/plugins/create-experience/index.js +1 -1
- package/dist/cjs/plugins/responses-browser-storage/index.js +1 -1
- package/dist/cjs/plugins/responses-indexeddb/index.js +1 -1
- package/dist/cjs/server/index.js +1 -1
- package/dist/esm/index.js +538 -547
- package/dist/esm/plugins/create-experience/index.js +251 -255
- package/dist/esm/plugins/responses-browser-storage/index.js +23 -25
- package/dist/esm/plugins/responses-indexeddb/index.js +49 -67
- package/dist/esm/plugins/single-page-app/index.js +1 -1
- 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 +15 -15
- package/dist/experience-instance-CsMhH0DN.cjs +1 -0
- package/dist/{experience-instance-BstMURAM.js → experience-instance-CwXYJkRx.js} +107 -111
- package/dist/{supports-BjhuLJ8z.js → supports-COb-sl36.js} +1 -1
- package/package.json +5 -5
- package/dist/experience-instance-CqwH_Ayg.cjs +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { createDomain as
|
|
1
|
+
import { createDomain as xt, createEvent as k, combine as C, createApi as ct, createEffect as $, attach as F, sample as m, split as It } from "effector";
|
|
2
2
|
import { createFactory as ut, invoke as ft } from "@withease/factories";
|
|
3
|
-
import { i as Et, s as lt, a as kt } from "./supports-
|
|
4
|
-
import { l as
|
|
3
|
+
import { i as Et, s as lt, a as kt } from "./supports-COb-sl36.js";
|
|
4
|
+
import { l as x } from "./logger-C9a75KZn.js";
|
|
5
5
|
import { i as At } from "./object-JwZ58NOH.js";
|
|
6
6
|
function bt(t) {
|
|
7
7
|
return typeof t == "number" && !isNaN(t);
|
|
@@ -47,8 +47,8 @@ const vt = {
|
|
|
47
47
|
const a = g(r);
|
|
48
48
|
return n <= s && s <= a;
|
|
49
49
|
},
|
|
50
|
-
"!!": async (t) => await
|
|
51
|
-
"!": async (t) => !await
|
|
50
|
+
"!!": async (t) => await O(t),
|
|
51
|
+
"!": async (t) => !await O(t),
|
|
52
52
|
"%": (t, e) => g(t) % g(e),
|
|
53
53
|
// eslint-disable-next-line sonarjs/function-return-type
|
|
54
54
|
log: (t) => (console.log(t), t),
|
|
@@ -153,20 +153,20 @@ async function p(t, e) {
|
|
|
153
153
|
case "if":
|
|
154
154
|
case "?:":
|
|
155
155
|
for (let o = 0; o < n.length - 1; o += 2)
|
|
156
|
-
if (await
|
|
156
|
+
if (await O(await p(n[o], e)))
|
|
157
157
|
return p(n[o + 1], e);
|
|
158
158
|
return n.length % 2 === 1 ? p(n[n.length - 1], e) : null;
|
|
159
159
|
case "and": {
|
|
160
160
|
let o = null;
|
|
161
161
|
for (const c of n)
|
|
162
|
-
if (o = await p(c, e), !await
|
|
162
|
+
if (o = await p(c, e), !await O(o))
|
|
163
163
|
return o;
|
|
164
164
|
return o;
|
|
165
165
|
}
|
|
166
166
|
case "or": {
|
|
167
167
|
let o = null;
|
|
168
168
|
for (const c of n)
|
|
169
|
-
if (o = await p(c, e), await
|
|
169
|
+
if (o = await p(c, e), await O(o)) return o;
|
|
170
170
|
return o;
|
|
171
171
|
}
|
|
172
172
|
case "map": {
|
|
@@ -177,7 +177,7 @@ async function p(t, e) {
|
|
|
177
177
|
const o = await p(n[0], e);
|
|
178
178
|
return N(o) ? (await Promise.all(
|
|
179
179
|
o.map(async (d) => {
|
|
180
|
-
const S = await
|
|
180
|
+
const S = await O(await p(n[1], d));
|
|
181
181
|
return { item: d, shouldInclude: S };
|
|
182
182
|
})
|
|
183
183
|
)).filter(({ shouldInclude: d }) => d).map(({ item: d }) => d) : [];
|
|
@@ -196,21 +196,21 @@ async function p(t, e) {
|
|
|
196
196
|
const o = await p(n[0], e);
|
|
197
197
|
if (!N(o) || o.length === 0) return !1;
|
|
198
198
|
for (const c of o)
|
|
199
|
-
if (!await
|
|
199
|
+
if (!await O(await p(n[1], c))) return !1;
|
|
200
200
|
return !0;
|
|
201
201
|
}
|
|
202
202
|
case "some": {
|
|
203
203
|
const o = await p(n[0], e);
|
|
204
204
|
if (!N(o)) return !1;
|
|
205
205
|
for (const c of o)
|
|
206
|
-
if (await
|
|
206
|
+
if (await O(await p(n[1], c))) return !0;
|
|
207
207
|
return !1;
|
|
208
208
|
}
|
|
209
209
|
case "none": {
|
|
210
210
|
const o = await p(n[0], e);
|
|
211
211
|
if (!N(o)) return !0;
|
|
212
212
|
for (const c of o)
|
|
213
|
-
if (await
|
|
213
|
+
if (await O(await p(n[1], c))) return !1;
|
|
214
214
|
return !0;
|
|
215
215
|
}
|
|
216
216
|
case "catch":
|
|
@@ -224,8 +224,8 @@ async function p(t, e) {
|
|
|
224
224
|
if (!a) throw new Error(`Unrecognized operation ${r}`);
|
|
225
225
|
return a.apply(e, s);
|
|
226
226
|
}
|
|
227
|
-
async function
|
|
228
|
-
return dt(t) ?
|
|
227
|
+
async function O(t) {
|
|
228
|
+
return dt(t) ? O(await t) : !(Array.isArray(t) && t.length === 0) && !!t;
|
|
229
229
|
}
|
|
230
230
|
function Ot(t) {
|
|
231
231
|
return Object.keys(t)[0];
|
|
@@ -418,48 +418,45 @@ async function Ut(t, e, r, n) {
|
|
|
418
418
|
const s = t ? "true" : "false", a = n.find(
|
|
419
419
|
(o) => o.sourceNodeHandle === s && o.sourceNodeId === e
|
|
420
420
|
);
|
|
421
|
-
return r.find((o) => o.id ===
|
|
421
|
+
return r.find((o) => o.id === a?.destinationNodeId);
|
|
422
422
|
}
|
|
423
|
-
const Q =
|
|
423
|
+
const Q = xt("experience-instance"), Wt = ut(
|
|
424
424
|
({
|
|
425
425
|
client: t,
|
|
426
426
|
experience: e,
|
|
427
427
|
target: r
|
|
428
428
|
}) => {
|
|
429
|
-
const n = k(), s = k(), a = k(), o = k(), c = k(), d = k(), S = e.componentStore, A = Q.store("transitioning"), _ = t.history.entriesStore.map((i) => i.filter((
|
|
430
|
-
var f;
|
|
431
|
-
return ((f = i[i.length - 1]) == null ? void 0 : f.node) || null;
|
|
432
|
-
}), u = C(
|
|
429
|
+
const n = k(), s = k(), a = k(), o = k(), c = k(), d = k(), S = e.componentStore, A = Q.store("transitioning"), _ = t.history.entriesStore.map((i) => i.filter((l) => l.experienceId === e.id)), R = _.map((i) => i.filter((l) => j(l.node))), I = _.map((i) => i[i.length - 1]?.node || null), u = C(
|
|
433
430
|
e.treeStore,
|
|
434
|
-
|
|
435
|
-
({ steps: i },
|
|
431
|
+
I,
|
|
432
|
+
({ steps: i }, l) => i.find((f) => l && j(l) && f.id === l.stepId) || null
|
|
436
433
|
), h = C(
|
|
437
434
|
e.treeStore,
|
|
438
|
-
|
|
439
|
-
({ nodes: i, edges:
|
|
440
|
-
),
|
|
435
|
+
I,
|
|
436
|
+
({ nodes: i, edges: l }, f) => f ? Ct(i, l, f) : []
|
|
437
|
+
), b = C(
|
|
441
438
|
e.treeStore,
|
|
442
|
-
|
|
443
|
-
({ nodes: i, edges:
|
|
444
|
-
),
|
|
439
|
+
I,
|
|
440
|
+
({ nodes: i, edges: l }, f) => f ? jt(i, l, f) : [-1, -1]
|
|
441
|
+
), M = C(
|
|
445
442
|
e.treeStore,
|
|
446
|
-
|
|
447
|
-
({ nodes: i, edges:
|
|
448
|
-
),
|
|
443
|
+
I,
|
|
444
|
+
({ nodes: i, edges: l }, f) => f ? Ht(i, l, f) : [-1, -1]
|
|
445
|
+
), v = Q.store(!1), T = ct(v, {
|
|
449
446
|
open: () => !0,
|
|
450
447
|
close: () => !1,
|
|
451
448
|
toggle: (i) => !i,
|
|
452
|
-
set: (i,
|
|
453
|
-
}), ht =
|
|
449
|
+
set: (i, l) => l
|
|
450
|
+
}), ht = $(async () => {
|
|
454
451
|
t.history.back({ experienceId: e.id });
|
|
455
452
|
}), yt = F({
|
|
456
453
|
source: e.treeStore,
|
|
457
|
-
effect: async (i,
|
|
458
|
-
const
|
|
459
|
-
|
|
454
|
+
effect: async (i, l) => {
|
|
455
|
+
const f = i.nodes.find((w) => j(w) && w.stepId === l);
|
|
456
|
+
f && t.history.push({ experienceId: e.id, node: f });
|
|
460
457
|
}
|
|
461
458
|
}), Y = F({
|
|
462
|
-
source:
|
|
459
|
+
source: I,
|
|
463
460
|
effect: (i) => {
|
|
464
461
|
}
|
|
465
462
|
}), K = F({
|
|
@@ -467,83 +464,83 @@ const Q = It("experience-instance"), Wt = ut(
|
|
|
467
464
|
effect: async ({ nodes: i }) => St(i)
|
|
468
465
|
}), V = F({
|
|
469
466
|
source: e.treeStore,
|
|
470
|
-
effect: async ({ nodes: i, edges:
|
|
471
|
-
if (z(
|
|
472
|
-
return J(
|
|
467
|
+
effect: async ({ nodes: i, edges: l }, f) => {
|
|
468
|
+
if (z(f))
|
|
469
|
+
return J(f, i, l);
|
|
473
470
|
}
|
|
474
471
|
}), q = F({
|
|
475
472
|
source: e.treeStore,
|
|
476
|
-
effect: async ({ nodes: i, edges:
|
|
473
|
+
effect: async ({ nodes: i, edges: l, conditionals: f }, w) => {
|
|
477
474
|
if (!it(w))
|
|
478
475
|
return;
|
|
479
|
-
const L =
|
|
476
|
+
const L = f.find((B) => B.id === w.conditionalId);
|
|
480
477
|
if (!L)
|
|
481
478
|
return;
|
|
482
479
|
const E = w.id, y = await ot(t, L.condition);
|
|
483
|
-
return Ut(!!y, E, i,
|
|
480
|
+
return Ut(!!y, E, i, l);
|
|
484
481
|
}
|
|
485
482
|
}), Z = F({
|
|
486
483
|
source: e.treeStore,
|
|
487
|
-
effect: async ({ nodes: i, edges:
|
|
488
|
-
if (!at(
|
|
484
|
+
effect: async ({ nodes: i, edges: l }, f) => {
|
|
485
|
+
if (!at(f))
|
|
489
486
|
return;
|
|
490
|
-
const w =
|
|
487
|
+
const w = f.action;
|
|
491
488
|
if (!w) {
|
|
492
|
-
|
|
489
|
+
x("warn", `Action node ${f.id} has no action name`);
|
|
493
490
|
return;
|
|
494
491
|
}
|
|
495
492
|
const L = t.actions.getByName(w).getState();
|
|
496
493
|
if (!L) {
|
|
497
|
-
|
|
498
|
-
const E =
|
|
499
|
-
(y) => y.sourceNodeId ===
|
|
494
|
+
x("warn", `Action '${w}' not registered on client`);
|
|
495
|
+
const E = l.find(
|
|
496
|
+
(y) => y.sourceNodeId === f.id && y.sourceNodeHandle === "false"
|
|
500
497
|
);
|
|
501
498
|
return E ? i.find((y) => y.id === E.destinationNodeId) : null;
|
|
502
499
|
}
|
|
503
500
|
if (typeof L.action != "function") {
|
|
504
|
-
|
|
505
|
-
const E =
|
|
506
|
-
(y) => y.sourceNodeId ===
|
|
501
|
+
x("warn", `Action '${w}' is not a function`);
|
|
502
|
+
const E = l.find(
|
|
503
|
+
(y) => y.sourceNodeId === f.id && y.sourceNodeHandle === "false"
|
|
507
504
|
);
|
|
508
505
|
return E ? i.find((y) => y.id === E.destinationNodeId) : null;
|
|
509
506
|
}
|
|
510
507
|
try {
|
|
511
|
-
|
|
512
|
-
const E =
|
|
513
|
-
(
|
|
508
|
+
x("info", `Executing action: ${w}`), await L.action(w);
|
|
509
|
+
const E = l.find(
|
|
510
|
+
(B) => B.sourceNodeId === f.id && B.sourceNodeHandle === "true"
|
|
514
511
|
);
|
|
515
512
|
if (!E)
|
|
516
|
-
return
|
|
517
|
-
const y = i.find((
|
|
518
|
-
return
|
|
513
|
+
return x("warn", `No 'true' edge found for action node ${f.id}`), null;
|
|
514
|
+
const y = i.find((B) => B.id === E.destinationNodeId);
|
|
515
|
+
return x("info", `Action '${w}' succeeded, moving to node ${y?.id}`), y || null;
|
|
519
516
|
} catch (E) {
|
|
520
|
-
|
|
521
|
-
const y =
|
|
522
|
-
(U) => U.sourceNodeId ===
|
|
517
|
+
x("warn", `Action '${w}' failed:`, E);
|
|
518
|
+
const y = l.find(
|
|
519
|
+
(U) => U.sourceNodeId === f.id && U.sourceNodeHandle === "false"
|
|
523
520
|
);
|
|
524
521
|
if (!y)
|
|
525
|
-
return
|
|
526
|
-
const
|
|
527
|
-
return
|
|
522
|
+
return x("warn", `No 'false' edge found for action node ${f.id}`), null;
|
|
523
|
+
const B = i.find((U) => U.id === y.destinationNodeId);
|
|
524
|
+
return x("info", `Action '${w}' failed, moving to node ${B?.id}`), B || null;
|
|
528
525
|
}
|
|
529
526
|
}
|
|
530
|
-
}), wt =
|
|
527
|
+
}), wt = $((i) => {
|
|
531
528
|
if (st(i))
|
|
532
529
|
return t.launchExperienceById(i.experienceId);
|
|
533
530
|
}), tt = F({
|
|
534
|
-
source: [
|
|
535
|
-
effect: async ([i, { nodes:
|
|
531
|
+
source: [I, e.treeStore],
|
|
532
|
+
effect: async ([i, { nodes: l, edges: f }]) => J(i, l, f)
|
|
536
533
|
}), P = F({
|
|
537
|
-
source: [
|
|
538
|
-
effect: async ([i, { nodes:
|
|
539
|
-
}), Nt =
|
|
534
|
+
source: [I, e.treeStore],
|
|
535
|
+
effect: async ([i, { nodes: l, edges: f }]) => J(i, l, f)
|
|
536
|
+
}), Nt = $((i) => {
|
|
540
537
|
t.history.push({ experienceId: e.id, node: i });
|
|
541
538
|
}), et = F({
|
|
542
539
|
source: e.configStore,
|
|
543
540
|
effect: async ({ initializeOpenLogic: i }) => Bt(i) ? !!await ot(t, i) : i ?? !1
|
|
544
541
|
}), X = k(), nt = k();
|
|
545
542
|
return m({
|
|
546
|
-
source:
|
|
543
|
+
source: I,
|
|
547
544
|
target: X
|
|
548
545
|
}), m({
|
|
549
546
|
clock: X,
|
|
@@ -553,7 +550,7 @@ const Q = It("experience-instance"), Wt = ut(
|
|
|
553
550
|
clock: X,
|
|
554
551
|
filter: (i) => i !== null,
|
|
555
552
|
target: nt
|
|
556
|
-
}),
|
|
553
|
+
}), It({
|
|
557
554
|
source: nt,
|
|
558
555
|
match: (i) => it(i) ? "condition" : j(i) ? "step" : st(i) ? "launchExperience" : z(i) ? "origin" : at(i) ? "action" : "other",
|
|
559
556
|
cases: {
|
|
@@ -632,25 +629,25 @@ const Q = It("experience-instance"), Wt = ut(
|
|
|
632
629
|
}), m({
|
|
633
630
|
source: et.doneData,
|
|
634
631
|
fn: Boolean,
|
|
635
|
-
target:
|
|
632
|
+
target: v
|
|
636
633
|
}), m({
|
|
637
|
-
source:
|
|
634
|
+
source: I,
|
|
638
635
|
clock: n,
|
|
639
636
|
filter: (i) => i ? z(i) : !0,
|
|
640
637
|
target: tt
|
|
641
638
|
}), m({
|
|
642
|
-
source:
|
|
639
|
+
source: v,
|
|
643
640
|
filter: Boolean,
|
|
644
641
|
target: n
|
|
645
642
|
}), m({
|
|
646
|
-
source:
|
|
643
|
+
source: v,
|
|
647
644
|
filter: Boolean,
|
|
648
645
|
target: t.eventBus.prepend(() => ({
|
|
649
646
|
type: "experience_open",
|
|
650
647
|
experience: e
|
|
651
648
|
}))
|
|
652
649
|
}), m({
|
|
653
|
-
source:
|
|
650
|
+
source: v,
|
|
654
651
|
filter: (i) => !i,
|
|
655
652
|
target: t.eventBus.prepend(() => ({
|
|
656
653
|
type: "experience_close",
|
|
@@ -669,18 +666,18 @@ const Q = It("experience-instance"), Wt = ut(
|
|
|
669
666
|
// state
|
|
670
667
|
stateStore: A,
|
|
671
668
|
// open close
|
|
672
|
-
isOpenStore:
|
|
673
|
-
open:
|
|
674
|
-
close:
|
|
675
|
-
toggleOpen:
|
|
676
|
-
setOpen:
|
|
669
|
+
isOpenStore: v,
|
|
670
|
+
open: T.open,
|
|
671
|
+
close: T.close,
|
|
672
|
+
toggleOpen: T.toggle,
|
|
673
|
+
setOpen: T.set,
|
|
677
674
|
// nodes
|
|
678
675
|
treeStore: e.treeStore,
|
|
679
|
-
currentNodeStore:
|
|
676
|
+
currentNodeStore: I,
|
|
680
677
|
currentStepStore: u,
|
|
681
678
|
nextReachableStepNodesStore: h,
|
|
682
|
-
stepsToOriginStore:
|
|
683
|
-
stepsToLeafStore:
|
|
679
|
+
stepsToOriginStore: b,
|
|
680
|
+
stepsToLeafStore: M,
|
|
684
681
|
// history
|
|
685
682
|
goToNextStep: s,
|
|
686
683
|
goToPreviousStep: a,
|
|
@@ -695,63 +692,62 @@ function Gt(t) {
|
|
|
695
692
|
const Kt = ut(({ client: t }) => {
|
|
696
693
|
const e = Q.store({}), r = k(), n = k(), s = k(), a = ct(e, {
|
|
697
694
|
register(u, h) {
|
|
698
|
-
const
|
|
695
|
+
const b = [
|
|
699
696
|
...u[h.experienceId] ?? []
|
|
700
697
|
];
|
|
701
|
-
return
|
|
698
|
+
return b.push(h), {
|
|
702
699
|
...u,
|
|
703
|
-
[h.experienceId]:
|
|
700
|
+
[h.experienceId]: b
|
|
704
701
|
};
|
|
705
702
|
},
|
|
706
703
|
unregister(u, h) {
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
($) => $ !== h
|
|
704
|
+
const b = h.experienceId, M = u[b]?.filter(
|
|
705
|
+
(v) => v !== h
|
|
710
706
|
);
|
|
711
707
|
return {
|
|
712
708
|
...u,
|
|
713
|
-
[
|
|
709
|
+
[b]: M ?? []
|
|
714
710
|
};
|
|
715
711
|
}
|
|
716
|
-
}), o =
|
|
712
|
+
}), o = $(
|
|
717
713
|
({ experience: u, target: h }) => Gt({ client: t, experience: u, target: h })
|
|
718
|
-
), c =
|
|
714
|
+
), c = $((u) => {
|
|
719
715
|
a.register(u);
|
|
720
|
-
}), d =
|
|
716
|
+
}), d = $(
|
|
721
717
|
(u) => {
|
|
722
718
|
u.target && Mt(u.target, () => {
|
|
723
719
|
s(u);
|
|
724
720
|
});
|
|
725
721
|
}
|
|
726
|
-
), S =
|
|
722
|
+
), S = $((u) => {
|
|
727
723
|
a.unregister(u);
|
|
728
|
-
}), A =
|
|
724
|
+
}), A = $((u) => {
|
|
729
725
|
const h = u.componentStore.getState();
|
|
730
726
|
if (!h) {
|
|
731
|
-
|
|
727
|
+
x("warn", "No app component registered. Skipping init.");
|
|
732
728
|
return;
|
|
733
729
|
}
|
|
734
|
-
const
|
|
735
|
-
if (!
|
|
736
|
-
|
|
730
|
+
const b = h.frameworkStore.getState();
|
|
731
|
+
if (!b) {
|
|
732
|
+
x(
|
|
737
733
|
"error",
|
|
738
734
|
`No framework registered for component '${h.name}'. Skipping rendering.`
|
|
739
735
|
);
|
|
740
736
|
return;
|
|
741
737
|
}
|
|
742
|
-
const
|
|
743
|
-
if (!
|
|
744
|
-
|
|
738
|
+
const M = u.target;
|
|
739
|
+
if (!M) {
|
|
740
|
+
x(
|
|
745
741
|
"error",
|
|
746
742
|
`No target element registered for experience '${u.experienceId}'. Skipping rendering.`
|
|
747
743
|
);
|
|
748
744
|
return;
|
|
749
745
|
}
|
|
750
|
-
const
|
|
746
|
+
const v = $t(M);
|
|
751
747
|
try {
|
|
752
|
-
|
|
753
|
-
} catch (
|
|
754
|
-
|
|
748
|
+
b.render(v, h.component, t, u);
|
|
749
|
+
} catch (T) {
|
|
750
|
+
x("error", T);
|
|
755
751
|
}
|
|
756
752
|
});
|
|
757
753
|
m({
|
|
@@ -781,12 +777,12 @@ const Kt = ut(({ client: t }) => {
|
|
|
781
777
|
r({ experience: u, target: h });
|
|
782
778
|
}
|
|
783
779
|
const R = e.map((u) => Object.values(u).flat());
|
|
784
|
-
function
|
|
780
|
+
function I(u) {
|
|
785
781
|
return e.map((h) => h[u] || [], { skipVoid: !1 });
|
|
786
782
|
}
|
|
787
783
|
return {
|
|
788
784
|
spawn: _,
|
|
789
|
-
getByExperienceId:
|
|
785
|
+
getByExperienceId: I,
|
|
790
786
|
listStore: R
|
|
791
787
|
};
|
|
792
788
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@picked/client",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.36-next.1",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"@withease/factories": "^1.0.5"
|
|
6
6
|
},
|
|
@@ -9,16 +9,16 @@
|
|
|
9
9
|
"@repo/typescript-config": "workspace:*",
|
|
10
10
|
"@rollup/plugin-replace": "^6.0.2",
|
|
11
11
|
"@testing-library/dom": "^10.4.0",
|
|
12
|
-
"@vitest/browser": "^
|
|
13
|
-
"@vitest/coverage-istanbul": "^
|
|
12
|
+
"@vitest/browser": "^4.0.17",
|
|
13
|
+
"@vitest/coverage-istanbul": "^4.0.17",
|
|
14
14
|
"effector": "^23.3.0",
|
|
15
15
|
"happy-dom": "^20.0.2",
|
|
16
16
|
"tslib": "^2.8.1",
|
|
17
17
|
"typedoc": "^0.28.5",
|
|
18
18
|
"typedoc-plugin-markdown": "^4.6.3",
|
|
19
|
-
"vite": "^
|
|
19
|
+
"vite": "^7.3.1",
|
|
20
20
|
"vite-plugin-dts": "^4.5.4",
|
|
21
|
-
"vitest": "^
|
|
21
|
+
"vitest": "^4.0.17"
|
|
22
22
|
},
|
|
23
23
|
"exports": {
|
|
24
24
|
".": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const i=require("effector"),q=require("@withease/factories"),H=require("./supports-YvpQZxbh.cjs"),N=require("./logger-BsmHUUw1.cjs"),ye=require("./object-BbFTsGh3.cjs");function we(e){return typeof e=="number"&&!isNaN(e)}function R(e){return typeof e=="string"}function E(e){return Array.isArray(e)}function ie(e){return e instanceof Promise}function ne(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&Object.keys(e).length===1}function m(e){if(we(e))return e;const t=parseFloat(`${e}`);return isNaN(t)?0:t}function T(e){return`${e}`}const Ee={"==":(e,t)=>e==t,"===":(e,t)=>e===t,"!=":(e,t)=>e!=t,"!==":(e,t)=>e!==t,">":(e,t)=>m(e)>m(t),">=":(e,t)=>m(e)>=m(t),"<":(e,t,r)=>{const n=m(e),a=m(t);if(r===void 0)return n<a;const c=m(r);return n<a&&a<c},"<=":(e,t,r)=>{const n=m(e),a=m(t);if(r===void 0)return n<=a;const c=m(r);return n<=a&&a<=c},"!!":async e=>await O(e),"!":async e=>!await O(e),"%":(e,t)=>m(e)%m(t),log:e=>(console.log(e),e),in:(e,t)=>t?R(t)?t.indexOf(T(e))!==-1:E(t)?t.includes(e):!1:!1,cat:(...e)=>e.map(T).join(""),substr:(e,t,r)=>{const n=T(e),a=m(t);if(r===void 0)return n.substr(a);const c=m(r);if(c<0){const o=n.substr(a);return o.substr(0,o.length+c)}return n.substr(a,c)},"+":(...e)=>e.reduce((t,r)=>m(t)+m(r),0),"*":(...e)=>e.reduce((t,r)=>m(t)*m(r),1),"-":(e,t)=>{const r=m(e);return t===void 0?-r:r-m(t)},"/":(e,t)=>m(e)/m(t),min:(...e)=>Math.min(...e.map(m)),max:(...e)=>Math.max(...e.map(m)),merge:(...e)=>e.reduce((t,r)=>E(r)?t.concat(r):t.concat([r]),[]),var(e,t){const r=arguments.length>1?t:null;if(e===""||e==="."||e===null||e===void 0)return this;if(typeof e=="number"&&Array.isArray(this))return e>=0&&e<this.length?this[e]:r;const n=T(e);if(n===""||n===".")return this;const a=n.split(".");let c=this;for(const o of a){if(c==null)return r;if(Array.isArray(c)){const u=parseInt(o,10);isNaN(u)?c=c[o]:c=c[u]}else c=c[o]}return c!==void 0?c:r},async missing(...e){const t=E(e[0])?e[0]:e,r=[];for(const n of t){const a=await g({var:n},this);(a===null||a==="")&&r.push(`${n}`)}return r},async missing_some(e,t){const r=await g({missing:t},this);if(!E(r)||!E(t))return[];const n=r.filter(R);return t.filter(R).length-n.length>=m(e)?[]:n},invoke(...e){const[t,...r]=e;return typeof t!="function"?null:Reflect.apply(t,null,r)},regexp_matches(e,t){let r=e,n="";if(E(e)){const[c,o]=e;r=c,n=o}return!R(r)||!R(n)?!1:new RegExp(r,n).test(T(t))},throw(e){throw new Error(T(e))}};async function g(e,t){if(!e)return e;if(ie(e))return g(await e,t);if(E(e))return Promise.all(e.map(o=>g(o,t)));if(!ne(e))return e;const r=Ne(e);let n=r?e[r]??[]:[];switch(E(n)||(n=[n]),r){case"if":case"?:":for(let o=0;o<n.length-1;o+=2)if(await O(await g(n[o],t)))return g(n[o+1],t);return n.length%2===1?g(n[n.length-1],t):null;case"and":{let o=null;for(const u of n)if(o=await g(u,t),!await O(o))return o;return o}case"or":{let o=null;for(const u of n)if(o=await g(u,t),await O(o))return o;return o}case"map":{const o=await g(n[0],t);return E(o)?await Promise.all(o.map(u=>g(n[1],u))):[]}case"filter":{const o=await g(n[0],t);return E(o)?(await Promise.all(o.map(async p=>{const h=await O(await g(n[1],p));return{item:p,shouldInclude:h}}))).filter(({shouldInclude:p})=>p).map(({item:p})=>p):[]}case"reduce":{const o=await g(n[0],t);if(!E(o))return n.length>2?await g(n[2],t):null;const u=n[1];let h=n.length>2?await g(n[2],t):null;for(const k of o)h=await g(u,{current:k,accumulator:h});return h}case"all":{const o=await g(n[0],t);if(!E(o)||o.length===0)return!1;for(const u of o)if(!await O(await g(n[1],u)))return!1;return!0}case"some":{const o=await g(n[0],t);if(!E(o))return!1;for(const u of o)if(await O(await g(n[1],u)))return!0;return!1}case"none":{const o=await g(n[0],t);if(!E(o))return!0;for(const u of o)if(await O(await g(n[1],u)))return!1;return!0}case"catch":try{return await g(n[0],t)}catch(o){return ne(o)?await g(o,t):n[1]?await g(n[1],o):o instanceof Error?o.message:o}}const a=await Promise.all(n.map(o=>g(o,t))),c=r?Ee[r]:void 0;if(!c)throw new Error(`Unrecognized operation ${r}`);return c.apply(t,a)}async function O(e){return ie(e)?O(await e):!(Array.isArray(e)&&e.length===0)&&!!e}function Ne(e){return Object.keys(e)[0]}function ae(e){return!ye.isEmpty(e)}async function z(e,t,r){const n=e.getStateSnapshot(),a=e.predicates.listStore.getState().reduce((u,p)=>({...u,[p.name]:(...h)=>p.predicate({...n,args:h})}),{}),c=e.features.listStore.getState().reduce((u,p)=>({...u,[p.id]:async()=>{const{bucket:h}=await p.getBucket();return h}}),{}),o={...r,responses:e.responses.getAllStore.getState(),location:typeof n.location=="object"?{hash:n.location.hash,host:n.location.host,hostname:n.location.hostname,href:n.location.href,origin:n.location.origin,pathname:n.location.pathname,port:n.location.port,protocol:n.location.protocol,search:n.location.search}:void 0,predicates:a,features:c};return await g(t,o)}function Ie(e){return!H.supportsWindow()||!H.supportsDocument()?[]:Array.from(window.document.querySelectorAll(e)).filter(t=>t instanceof HTMLElement)}const xe="open";function ke(e){if(!H.supportsShadowRoot())throw new Error("Shadow DOM is not supported in this environment");return e.attachShadow({mode:xe})}function ve(){return new Promise((e,t)=>{if(!H.supportsDocument()){t();return}document.readyState!=="loading"?e():document.addEventListener("readystatechange",()=>e(),{once:!0})})}function be(e,t){const r=new MutationObserver(n=>{document.contains(e)||(r.disconnect(),t())});r.observe(document.body,{childList:!0,subtree:!0})}const C="picked-root",j="picked-target",Ae="picked-root";function Oe(e,t){return[...e,{selector:`${Ae}[experience-id="${t}"]`,placement:"replace"}].flatMap(n=>{const a=Ie(n.selector).filter(c=>!_e(c,t)&&!ce(c,t));return{...n,elements:a}})}function Fe(e,t){return e.flatMap(r=>r.elements.map(n=>Te(n,r.placement,t)))}function Be(e,t){e.classList.add(j),e.classList.add(`${j}-${t}`)}function _e(e,t){return t?e.classList.contains(`${j}-${t}`):e.classList.contains(`${j}`)}function ce(e,t){return t?e.classList.contains(`${C}-${t}`):e.classList.contains(C)}function $e(e){const t=document.createElement("div");return t.style.display="block",t.classList.add(C),t.classList.add(`${C}-${e}`),t}function Te(e,t,r){let n;const a=$e(r);if(e instanceof Document)n=e.body.appendChild(a);else{switch(t){case"replace":e.replaceWith(a);break;case"before":e.before(a);break;case"after":e.after(a);break;case"prepend":e.prepend(a);break;default:e.append(a);break}n=a}return n}function re(e){return e.type==="conditional"}function M(e){return e.type==="step"}function oe(e){return e.type==="experience"}function V(e){return e.type==="origin"}function se(e){return e.type==="action"}const ue=(e,t,r,n,a=new Set)=>a.has(r.id)?[]:(a.add(r.id),M(r)&&!n?[r]:t.filter(o=>o.sourceNodeId===r.id).flatMap(o=>{const u=e.find(p=>p.id===o.destinationNodeId);return u?ue(e,t,u,!1,a):[]})),Me=(e,t,r)=>ue(e,t,r,!0,new Set),fe=(e,t,r,n,a=new Set)=>{if(a.has(r.id))return[-1,-1];a.add(r.id);const c=t.filter(p=>p.sourceNodeId===r.id);if(c.length===0)return[0,0];let o=1/0,u=-1/0;for(const p of c){const h=e.find(L=>L.id===p.destinationNodeId);if(!h)continue;const[k,F]=fe(e,t,h,!1,new Set(a));k!==-1&&(o=Math.min(o,k+1),u=Math.max(u,F+1))}return o===1/0?[-1,-1]:[o,u]},Le=(e,t,r)=>fe(e,t,r,!0,new Set),le=(e,t,r,n=new Set)=>{if(n.has(r.id))return[-1,-1];if(n.add(r.id),r.type==="origin")return[0,0];const a=t.filter(u=>u.destinationNodeId===r.id);if(a.length===0)return[-1,-1];let c=1/0,o=-1/0;for(const u of a){const p=e.find(F=>F.id===u.sourceNodeId);if(!p)continue;const[h,k]=le(e,t,p,new Set(n));h!==-1&&(c=Math.min(c,h+1),o=Math.max(o,k+1))}return c===1/0?[-1,-1]:[c,o]},De=(e,t,r)=>le(e,t,r,new Set),de=e=>e.find(r=>r.type==="origin")||null,X=(e,t,r)=>{if(!e)return de(t);const n=r.find(c=>c.sourceNodeId===e.id);if(!n)return null;const a=t.find(c=>c.id===n.destinationNodeId);return a||null};async function Re(e,t,r,n){const a=e?"true":"false",c=n.find(o=>o.sourceNodeHandle===a&&o.sourceNodeId===t);return r.find(o=>o.id===(c==null?void 0:c.destinationNodeId))}const J=i.createDomain("experience-instance"),Pe=q.createFactory(({client:e,experience:t,target:r})=>{const n=i.createEvent(),a=i.createEvent(),c=i.createEvent(),o=i.createEvent(),u=i.createEvent(),p=i.createEvent(),h=t.componentStore,k=J.store("transitioning"),F=e.history.entriesStore.map(s=>s.filter(l=>l.experienceId===t.id)),L=F.map(s=>s.filter(l=>M(l.node))),I=F.map(s=>{var l;return((l=s[s.length-1])==null?void 0:l.node)||null}),f=i.combine(t.treeStore,I,({steps:s},l)=>s.find(d=>l&&M(l)&&d.id===l.stepId)||null),S=i.combine(t.treeStore,I,({nodes:s,edges:l},d)=>d?Me(s,l,d):[]),A=i.combine(t.treeStore,I,({nodes:s,edges:l},d)=>d?De(s,l,d):[-1,-1]),_=i.combine(t.treeStore,I,({nodes:s,edges:l},d)=>d?Le(s,l,d):[-1,-1]),v=J.store(!1),B=i.createApi(v,{open:()=>!0,close:()=>!1,toggle:s=>!s,set:(s,l)=>l}),ge=i.createEffect(async()=>{e.history.back({experienceId:t.id})}),me=i.attach({source:t.treeStore,effect:async(s,l)=>{const d=s.nodes.find(w=>M(w)&&w.stepId===l);d&&e.history.push({experienceId:t.id,node:d})}}),Q=i.attach({source:I,effect:s=>{}}),U=i.attach({source:t.treeStore,effect:async({nodes:s})=>de(s)}),W=i.attach({source:t.treeStore,effect:async({nodes:s,edges:l},d)=>{if(V(d))return X(d,s,l)}}),G=i.attach({source:t.treeStore,effect:async({nodes:s,edges:l,conditionals:d},w)=>{if(!re(w))return;const $=d.find(b=>b.id===w.conditionalId);if(!$)return;const x=w.id,y=await z(e,$.condition);return Re(!!y,x,s,l)}}),Y=i.attach({source:t.treeStore,effect:async({nodes:s,edges:l},d)=>{if(!se(d))return;const w=d.action;if(!w){N.logger("warn",`Action node ${d.id} has no action name`);return}const $=e.actions.getByName(w).getState();if(!$){N.logger("warn",`Action '${w}' not registered on client`);const x=l.find(y=>y.sourceNodeId===d.id&&y.sourceNodeHandle==="false");return x?s.find(y=>y.id===x.destinationNodeId):null}if(typeof $.action!="function"){N.logger("warn",`Action '${w}' is not a function`);const x=l.find(y=>y.sourceNodeId===d.id&&y.sourceNodeHandle==="false");return x?s.find(y=>y.id===x.destinationNodeId):null}try{N.logger("info",`Executing action: ${w}`),await $.action(w);const x=l.find(b=>b.sourceNodeId===d.id&&b.sourceNodeHandle==="true");if(!x)return N.logger("warn",`No 'true' edge found for action node ${d.id}`),null;const y=s.find(b=>b.id===x.destinationNodeId);return N.logger("info",`Action '${w}' succeeded, moving to node ${y==null?void 0:y.id}`),y||null}catch(x){N.logger("warn",`Action '${w}' failed:`,x);const y=l.find(P=>P.sourceNodeId===d.id&&P.sourceNodeHandle==="false");if(!y)return N.logger("warn",`No 'false' edge found for action node ${d.id}`),null;const b=s.find(P=>P.id===y.destinationNodeId);return N.logger("info",`Action '${w}' failed, moving to node ${b==null?void 0:b.id}`),b||null}}}),he=i.createEffect(s=>{if(oe(s))return e.launchExperienceById(s.experienceId)}),Z=i.attach({source:[I,t.treeStore],effect:async([s,{nodes:l,edges:d}])=>X(s,l,d)}),D=i.attach({source:[I,t.treeStore],effect:async([s,{nodes:l,edges:d}])=>X(s,l,d)}),Se=i.createEffect(s=>{e.history.push({experienceId:t.id,node:s})}),ee=i.attach({source:t.configStore,effect:async({initializeOpenLogic:s})=>ae(s)?!!await z(e,s):s??!1}),K=i.createEvent(),te=i.createEvent();return i.sample({source:I,target:K}),i.sample({clock:K,filter:s=>s===null,target:U}),i.sample({clock:K,filter:s=>s!==null,target:te}),i.split({source:te,match:s=>re(s)?"condition":M(s)?"step":oe(s)?"launchExperience":V(s)?"origin":se(s)?"action":"other",cases:{origin:W,condition:G,step:Q,launchExperience:he,action:Y,__:i.createEvent()}}),i.sample({clock:[G.doneData,W.doneData,U.doneData,D.doneData,Z.doneData,Y.doneData],filter:Boolean,target:Se}),i.sample({clock:a,target:D}),i.sample({clock:a,source:f,filter:Boolean,target:e.eventBus.prepend(s=>({type:"step_submit",step:s,experience:t}))}),i.sample({clock:D.done,source:f,filter:Boolean,target:e.eventBus.prepend(s=>({type:"step_submit_success",step:s,experience:t}))}),i.sample({clock:D.fail,source:f,filter:Boolean,target:e.eventBus.prepend(s=>({type:"step_submit_error",step:s,experience:t}))}),i.sample({clock:c,target:ge}),i.sample({clock:o,target:me}),i.sample({source:i.combine([G.pending,W.pending,U.pending,D.pending]),fn:s=>s.some(Boolean)?"transitioning":"ready",target:k}),i.sample({clock:Q.doneData,source:f,filter:Boolean,target:e.eventBus.prepend(s=>({type:"step_enter",step:s,experience:t}))}),i.sample({clock:p,target:ee}),i.sample({source:ee.doneData,fn:Boolean,target:v}),i.sample({source:I,clock:n,filter:s=>s?V(s):!0,target:Z}),i.sample({source:v,filter:Boolean,target:n}),i.sample({source:v,filter:Boolean,target:e.eventBus.prepend(()=>({type:"experience_open",experience:t}))}),i.sample({source:v,filter:s=>!s,target:e.eventBus.prepend(()=>({type:"experience_close",experience:t}))}),i.sample({clock:u,target:[p]}),u(),{id:Math.random().toString(36).substring(7),experienceId:t.id,configStore:t.configStore,target:r,componentStore:h,stateStore:k,isOpenStore:v,open:B.open,close:B.close,toggleOpen:B.toggle,setOpen:B.set,treeStore:t.treeStore,currentNodeStore:I,currentStepStore:f,nextReachableStepNodesStore:S,stepsToOriginStore:A,stepsToLeafStore:_,goToNextStep:a,goToPreviousStep:c,goToStepById:o,stepsHistoryStore:L}});function pe(e){return q.invoke(Pe,e)}const He=q.createFactory(({client:e})=>{const t=J.store({}),r=i.createEvent(),n=i.createEvent(),a=i.createEvent(),c=i.createApi(t,{register(f,S){const A=[...f[S.experienceId]??[]];return A.push(S),{...f,[S.experienceId]:A}},unregister(f,S){var v;const A=S.experienceId,_=(v=f[A])==null?void 0:v.filter(B=>B!==S);return{...f,[A]:_??[]}}}),o=i.createEffect(({experience:f,target:S})=>pe({client:e,experience:f,target:S})),u=i.createEffect(f=>{c.register(f)}),p=i.createEffect(f=>{f.target&&be(f.target,()=>{a(f)})}),h=i.createEffect(f=>{c.unregister(f)}),k=i.createEffect(f=>{const S=f.componentStore.getState();if(!S){N.logger("warn","No app component registered. Skipping init.");return}const A=S.frameworkStore.getState();if(!A){N.logger("error",`No framework registered for component '${S.name}'. Skipping rendering.`);return}const _=f.target;if(!_){N.logger("error",`No target element registered for experience '${f.experienceId}'. Skipping rendering.`);return}const v=ke(_);try{A.render(v,S.component,e,f)}catch(B){N.logger("error",B)}});i.sample({clock:r,target:o}),i.sample({clock:a,target:h}),i.sample({clock:o.doneData,target:[u,p,n]}),i.sample({clock:o.doneData,target:e.eventBus.prepend(f=>({type:"experience_initialize",experienceInstance:f}))}),i.sample({clock:n,target:k});function F(f,S){r({experience:f,target:S})}const L=t.map(f=>Object.values(f).flat());function I(f){return t.map(S=>S[f]||[],{skipVoid:!1})}return{spawn:F,getByExperienceId:I,listStore:L}});function Ce(e){return q.invoke(He,e)}exports.createAppHosts=Fe;exports.createExperienceInstance=pe;exports.createExperienceInstanceIndex=Ce;exports.domInteractive=ve;exports.evaluateRuleLogic=z;exports.getTargetElements=Oe;exports.isPickedRoot=ce;exports.isRulesLogic=ae;exports.isStepNode=M;exports.tagTargetElement=Be;
|