@plitzi/sdk-interactions 0.39.0 → 0.39.2
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/CHANGELOG.md +22 -0
- package/dist/InteractionsContext.mjs +1 -2
- package/dist/InteractionsContextProvider.mjs +5 -6
- package/dist/InteractionsHelper.mjs +40 -42
- package/dist/InteractionsManager.d.ts +13 -0
- package/dist/InteractionsManager.mjs +79 -37
- package/dist/InteractionsSourcesProvider.mjs +1 -2
- package/dist/declarations/index.mjs +9 -9
- package/dist/helpers/coerceDeclaredParams.mjs +1 -2
- package/dist/hooks/useInteractions.mjs +1 -2
- package/dist/index.mjs +6 -6
- package/dist/sources/ActionsSource/ActionInteractions.mjs +205 -196
- package/dist/sources/ActionsSource/ServerActionContext.mjs +2 -3
- package/dist/sources/ActionsSource/callbacks.mjs +1 -2
- package/dist/sources/ActionsSource/deliverCall.d.ts +45 -0
- package/dist/sources/ActionsSource/deliverCall.mjs +80 -0
- package/dist/sources/ActionsSource/index.mjs +3 -3
- package/dist/sources/AuthSource/AuthInteractions.mjs +5 -6
- package/dist/sources/AuthSource/callbacks.mjs +1 -2
- package/dist/sources/HostSource/HostInteractions.mjs +5 -6
- package/dist/sources/HostSource/callbacks.mjs +1 -2
- package/dist/sources/HostSource/index.mjs +3 -3
- package/dist/sources/NavigationSource/NavigationInteractions.mjs +9 -10
- package/dist/sources/NavigationSource/callbacks.mjs +1 -2
- package/dist/sources/NavigationSource/navigateHow.mjs +1 -2
- package/dist/sources/QueriesSource/QueriesInteractions.mjs +5 -6
- package/dist/sources/QueriesSource/callbacks.mjs +1 -2
- package/dist/sources/QueriesSource/writeParams.mjs +1 -2
- package/dist/sources/StateSource/StateInteractions.mjs +5 -6
- package/dist/sources/StateSource/callbacks.mjs +1 -2
- package/dist/utility/copyToClipboard.mjs +1 -2
- package/dist/utility/copyToClipboardSpec.mjs +1 -2
- package/dist/utility/delayTime.mjs +1 -2
- package/dist/utility/index.mjs +1 -2
- package/dist/utility/twigTemplate.mjs +1 -2
- package/dist/utility/webHook.mjs +1 -2
- package/dist/utility/webHookSpec.mjs +1 -2
- package/package.json +14 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# @plitzi/sdk-interactions
|
|
2
2
|
|
|
3
|
+
## 0.39.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- fad1264: Released with every `@plitzi` package at this version. What changed in each, and what to do when you upgrade, is in
|
|
8
|
+
`@plitzi/cli`'s `CHANGELOG.md`: one copy of the notes, not one per package.
|
|
9
|
+
- Updated dependencies [fad1264]
|
|
10
|
+
- @plitzi/sdk-auth@0.39.2
|
|
11
|
+
- @plitzi/sdk-event-bridge@0.39.2
|
|
12
|
+
- @plitzi/sdk-shared@0.39.2
|
|
13
|
+
|
|
14
|
+
## 0.39.1
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- f174a61: Released with every `@plitzi` package at this version. What changed in each, and what to do when you upgrade, is in
|
|
19
|
+
`@plitzi/cli`'s `CHANGELOG.md`: one copy of the notes, not one per package.
|
|
20
|
+
- Updated dependencies [f174a61]
|
|
21
|
+
- @plitzi/sdk-auth@0.39.1
|
|
22
|
+
- @plitzi/sdk-event-bridge@0.39.1
|
|
23
|
+
- @plitzi/sdk-shared@0.39.1
|
|
24
|
+
|
|
3
25
|
## 0.39.0
|
|
4
26
|
|
|
5
27
|
### Minor Changes
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import e from "./
|
|
2
|
-
import t from "./
|
|
1
|
+
import e from "./hooks/useInteractions.mjs";
|
|
2
|
+
import t from "./InteractionsContext.mjs";
|
|
3
3
|
import n from "./InteractionsManager.mjs";
|
|
4
4
|
import { useMemo as r, useState as i } from "react";
|
|
5
5
|
import { jsx as a } from "react/jsx-runtime";
|
|
6
|
-
|
|
6
|
+
// src/InteractionsContextProvider.tsx
|
|
7
7
|
var o = ({ children: o, currentPageId: s, routeParams: c, queryParams: l }) => {
|
|
8
8
|
let [u] = i(() => new n(s, c, l));
|
|
9
9
|
u.interactionsData = r(() => ({
|
|
@@ -17,12 +17,11 @@ var o = ({ children: o, currentPageId: s, routeParams: c, queryParams: l }) => {
|
|
|
17
17
|
]);
|
|
18
18
|
let d = r(() => ({
|
|
19
19
|
interactionsManager: u,
|
|
20
|
-
useInteractions:
|
|
20
|
+
useInteractions: e
|
|
21
21
|
}), [u]);
|
|
22
|
-
return /* @__PURE__ */ a(
|
|
22
|
+
return /* @__PURE__ */ a(t, {
|
|
23
23
|
value: d,
|
|
24
24
|
children: o
|
|
25
25
|
});
|
|
26
26
|
};
|
|
27
|
-
//#endregion
|
|
28
27
|
export { o as default };
|
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
import { coerceDeclaredParams as e } from "./helpers/coerceDeclaredParams.mjs";
|
|
2
2
|
import t from "./utility/index.mjs";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { pConsole as o } from "@plitzi/sdk-shared/devTools";
|
|
3
|
+
import { get as n, omit as r } from "@plitzi/plitzi-ui/helpers";
|
|
4
|
+
import { pConsole as i } from "@plitzi/sdk-shared/devTools";
|
|
5
|
+
import { evaluateRuleGroup as a, ruleValuesOf as o } from "@plitzi/sdk-shared/conditions";
|
|
7
6
|
import { MAX_PARAM_PASSES as s, resolveStepParam as c } from "@plitzi/sdk-shared/helpers/twigWrapper";
|
|
8
7
|
import { Fragment as l, jsx as u, jsxs as d } from "react/jsx-runtime";
|
|
9
|
-
|
|
10
|
-
var f = 5, p = (e, t, n, r,
|
|
11
|
-
if (e === "utility" &&
|
|
12
|
-
let
|
|
8
|
+
// src/InteractionsHelper.tsx
|
|
9
|
+
var f = 5, p = (e, t, n, r, a) => {
|
|
10
|
+
if (e === "utility" && a === "twigTemplate") return t;
|
|
11
|
+
let o = {
|
|
13
12
|
...n,
|
|
14
13
|
...r
|
|
15
14
|
}, l = (e, t, n) => {
|
|
16
15
|
if (typeof e == "string") {
|
|
17
|
-
let { value: n, unresolved: r } = c(e,
|
|
18
|
-
return r &&
|
|
16
|
+
let { value: n, unresolved: r } = c(e, o);
|
|
17
|
+
return r && i.warning("interactions", /* @__PURE__ */ d("span", { children: [
|
|
19
18
|
"Twig token resolution exceeded ",
|
|
20
19
|
s,
|
|
21
20
|
" passes for ",
|
|
@@ -35,14 +34,14 @@ var f = 5, p = (e, t, n, r, i) => {
|
|
|
35
34
|
[r]: i
|
|
36
35
|
};
|
|
37
36
|
}, {});
|
|
38
|
-
}, m = (e) => typeof e == "object" && !!e && "then" in e && typeof e.then == "function", h = (
|
|
39
|
-
let h = [], { id: g, action: _, enabled: v, params: y, elementId: b, type: x, when: S } =
|
|
37
|
+
}, m = (e) => typeof e == "object" && !!e && "then" in e && typeof e.then == "function", h = (r, s = {}, c = {}, l = {}, f = {}) => {
|
|
38
|
+
let h = [], { id: g, action: _, enabled: v, params: y, elementId: b, type: x, when: S } = r;
|
|
40
39
|
if (!_ || !v) return {
|
|
41
40
|
status: "disabled",
|
|
42
41
|
result: {},
|
|
43
42
|
postCallbacks: h
|
|
44
43
|
};
|
|
45
|
-
let C =
|
|
44
|
+
let C = o({
|
|
46
45
|
...l,
|
|
47
46
|
...c,
|
|
48
47
|
[g]: y
|
|
@@ -53,9 +52,9 @@ var f = 5, p = (e, t, n, r, i) => {
|
|
|
53
52
|
postCallbacks: h,
|
|
54
53
|
whenParams: C
|
|
55
54
|
};
|
|
56
|
-
let w = (e) => (
|
|
55
|
+
let w = (e) => (i.danger("interactions", /* @__PURE__ */ d("span", { children: ["Interaction node failed ", /* @__PURE__ */ u("b", { children: _ })] }), {
|
|
57
56
|
error: e instanceof Error ? e.message : String(e),
|
|
58
|
-
node:
|
|
57
|
+
node: r
|
|
59
58
|
}), {
|
|
60
59
|
status: "failed",
|
|
61
60
|
result: {},
|
|
@@ -65,23 +64,23 @@ var f = 5, p = (e, t, n, r, i) => {
|
|
|
65
64
|
switch (x) {
|
|
66
65
|
case "callback":
|
|
67
66
|
case "globalCallback":
|
|
68
|
-
if (!b) return
|
|
67
|
+
if (!b) return i.warning("interactions", /* @__PURE__ */ d("span", { children: [
|
|
69
68
|
"Step ",
|
|
70
69
|
/* @__PURE__ */ u("b", { children: _ }),
|
|
71
70
|
" names no element, so there is nothing to run it on"
|
|
72
|
-
] }), { node:
|
|
71
|
+
] }), { node: r }), {
|
|
73
72
|
status: "failed",
|
|
74
73
|
result: {},
|
|
75
74
|
postCallbacks: h,
|
|
76
75
|
whenParams: C
|
|
77
76
|
};
|
|
78
|
-
if (T =
|
|
77
|
+
if (T = n(s, `${b}.${_}`), !T) return i.warning("interactions", /* @__PURE__ */ d("span", { children: [
|
|
79
78
|
"Nothing is registered as ",
|
|
80
79
|
/* @__PURE__ */ u("b", { children: `${b}.${_}` }),
|
|
81
80
|
", so this step did nothing"
|
|
82
81
|
] }), {
|
|
83
|
-
node:
|
|
84
|
-
available: Object.keys(
|
|
82
|
+
node: r,
|
|
83
|
+
available: Object.keys(n(s, b, {}))
|
|
85
84
|
}), {
|
|
86
85
|
status: "failed",
|
|
87
86
|
result: {},
|
|
@@ -90,7 +89,7 @@ var f = 5, p = (e, t, n, r, i) => {
|
|
|
90
89
|
};
|
|
91
90
|
break;
|
|
92
91
|
case "utility":
|
|
93
|
-
T =
|
|
92
|
+
T = n(t, _, {});
|
|
94
93
|
break;
|
|
95
94
|
default: return {
|
|
96
95
|
status: "success",
|
|
@@ -123,40 +122,40 @@ var f = 5, p = (e, t, n, r, i) => {
|
|
|
123
122
|
}
|
|
124
123
|
}, g = async (e = []) => {
|
|
125
124
|
let t = {};
|
|
126
|
-
return await Promise.all(e.reverse().map(async ({ id: e, callback: n, params:
|
|
127
|
-
t[e] = await n?.(i
|
|
125
|
+
return await Promise.all(e.reverse().map(async ({ id: e, callback: n, params: i }) => {
|
|
126
|
+
t[e] = await n?.(r(i, [e]), i[e]);
|
|
128
127
|
})), t;
|
|
129
|
-
}, _ = () => ({}), v = async (e, t = {},
|
|
130
|
-
let u = e, d =
|
|
128
|
+
}, _ = () => ({}), v = async (e, t = {}, r = {}, a = {}, o = _, s = [], c = {}, l = {}) => {
|
|
129
|
+
let u = e, d = a;
|
|
131
130
|
for (; u;) {
|
|
132
131
|
if (l.signal?.aborted) return c;
|
|
133
|
-
let e =
|
|
132
|
+
let e = n(t, u.afterNode);
|
|
134
133
|
if (!e) return s.length > 0 && await g(s), c;
|
|
135
|
-
let
|
|
134
|
+
let a = i.getTime().valueOf(), f = h(e, r, d, o(), l), p = m(f) ? await f : f, { result: _, postCallbacks: v, whenParams: y } = p, b = p.status === "failed" && l.signal?.aborted ? "skipped" : p.status;
|
|
136
135
|
c[e.id] = {
|
|
137
136
|
node: e,
|
|
138
137
|
status: b,
|
|
139
138
|
result: _,
|
|
140
139
|
postCallbacks: v,
|
|
141
140
|
whenParams: y,
|
|
142
|
-
startTime:
|
|
143
|
-
endTime:
|
|
141
|
+
startTime: a,
|
|
142
|
+
endTime: i.getTime().valueOf()
|
|
144
143
|
}, s.push(...v), d = {
|
|
145
144
|
...d,
|
|
146
145
|
[e.id]: _
|
|
147
146
|
}, u = e;
|
|
148
147
|
}
|
|
149
148
|
return c;
|
|
150
|
-
}, y = (e, t, n = {}, r,
|
|
151
|
-
let
|
|
149
|
+
}, y = (e, t, n = {}, r, a) => {
|
|
150
|
+
let o = i.getTime().valueOf(), s = r === "skipped" ? "skipped" : "success", c = /* @__PURE__ */ d("span", { children: [
|
|
152
151
|
"Interaction triggered ",
|
|
153
152
|
/* @__PURE__ */ u("b", { children: `${e.title} [${e.action}]` }),
|
|
154
|
-
|
|
153
|
+
a ? /* @__PURE__ */ d(l, { children: [" on ", /* @__PURE__ */ u("b", { children: a })] }) : null
|
|
155
154
|
] }), f = {
|
|
156
155
|
status: r,
|
|
157
156
|
node: e,
|
|
158
157
|
elementId: e.elementId,
|
|
159
|
-
hostElementId:
|
|
158
|
+
hostElementId: a,
|
|
160
159
|
nodes: {
|
|
161
160
|
...n,
|
|
162
161
|
[e.id]: {
|
|
@@ -165,27 +164,26 @@ var f = 5, p = (e, t, n, r, i) => {
|
|
|
165
164
|
result: void 0,
|
|
166
165
|
postCallbacks: [],
|
|
167
166
|
startTime: t,
|
|
168
|
-
endTime:
|
|
167
|
+
endTime: o
|
|
169
168
|
}
|
|
170
169
|
},
|
|
171
170
|
startTime: t,
|
|
172
|
-
endTime:
|
|
171
|
+
endTime: o
|
|
173
172
|
};
|
|
174
|
-
r === "failed" ?
|
|
175
|
-
}, b = (e) => Object.values(e).some(({ status: e }) => e === "failed") ? "failed" : "completed", x = async (e, t = {},
|
|
176
|
-
let d =
|
|
177
|
-
if (!f || !p || m && !a(m,
|
|
173
|
+
r === "failed" ? i.danger("interactions", c, f) : i.info("interactions", c, f);
|
|
174
|
+
}, b = (e) => Object.values(e).some(({ status: e }) => e === "failed") ? "failed" : "completed", x = async (e, t = {}, n = {}, r = {}, s = _, c, l, u = []) => {
|
|
175
|
+
let d = i.getTime().valueOf(), { action: f, enabled: p, when: m } = e;
|
|
176
|
+
if (!f || !p || m && !a(m, o({
|
|
178
177
|
...s(),
|
|
179
|
-
...
|
|
178
|
+
...r
|
|
180
179
|
}))) {
|
|
181
180
|
y(e, d, {}, "skipped", c);
|
|
182
181
|
return;
|
|
183
182
|
}
|
|
184
|
-
let h = await v(e, t,
|
|
183
|
+
let h = await v(e, t, n, r, s, u, {}, {
|
|
185
184
|
hostElementId: c,
|
|
186
185
|
...l ? { signal: l } : {}
|
|
187
186
|
});
|
|
188
187
|
y(e, d, h, b(h), c);
|
|
189
188
|
}, S = { flowTrigger: x };
|
|
190
|
-
//#endregion
|
|
191
189
|
export { S as default, x as flowTrigger };
|
|
@@ -17,6 +17,14 @@ declare class InteractionsManager implements InteractionsManagerApi {
|
|
|
17
17
|
private latestRuns;
|
|
18
18
|
lastUpdate: number;
|
|
19
19
|
private listeners;
|
|
20
|
+
/**
|
|
21
|
+
* Triggers fired at an element that has not subscribed yet, by element: fired once it wires its flows (`update`).
|
|
22
|
+
*
|
|
23
|
+
* An element's handlers are React's from the commit, its flows are wired from an effect React runs after it: a tap in
|
|
24
|
+
* between — on a page that has just hydrated, before its effects have run — fired a trigger no flow answered, and
|
|
25
|
+
* the tap did nothing, with nothing said. Kept a few seconds, a few per element.
|
|
26
|
+
*/
|
|
27
|
+
private parked;
|
|
20
28
|
constructor(currentPageId?: string, routeParams?: RouteParams, queryParams?: QueryParams);
|
|
21
29
|
eventBridgeCallback: (interactions?: Record<string, ElementInteraction>) => (subscriptorId: string, eventName: string, params: Record<string, unknown>) => Promise<void>;
|
|
22
30
|
/** One firing of one flow, as its trigger's `whileRunning` says — see {@link WhileRunning}. */
|
|
@@ -48,6 +56,11 @@ declare class InteractionsManager implements InteractionsManagerApi {
|
|
|
48
56
|
[x: string]: Record<string, InteractionCallback> | Record<string, InteractionCallback<any>>;
|
|
49
57
|
};
|
|
50
58
|
interactionTrigger(subscriptorId: string | undefined, eventName: string, params?: Record<string, unknown>): Promise<unknown[]> | undefined;
|
|
59
|
+
private park;
|
|
60
|
+
private replayParked;
|
|
61
|
+
private dropParked;
|
|
62
|
+
/** A trigger no element took up: said, so a tap that did nothing is not silent. */
|
|
63
|
+
private settleUnanswered;
|
|
51
64
|
createChildManager: (routeParams?: Record<string, string>, queryParams?: Record<string, string>) => InteractionsManager;
|
|
52
65
|
removeChildManager: (childManager: InteractionsManagerApi) => void;
|
|
53
66
|
onUpdate(listener: InteractionUpdateListener): () => void;
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { flowTrigger as e } from "./InteractionsHelper.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
2
|
+
import { get as t, set as n } from "@plitzi/plitzi-ui/helpers";
|
|
3
|
+
import r from "@plitzi/sdk-event-bridge";
|
|
4
|
+
import { pConsole as i } from "@plitzi/sdk-shared/devTools";
|
|
5
|
+
import { INTERVAL_TRIGGER as a, KEY_TRIGGER as o, intervalOf as s } from "@plitzi/sdk-shared/helpers";
|
|
6
|
+
// src/InteractionsManager.ts
|
|
7
|
+
var c = (e, t) => {
|
|
8
|
+
if (e.action === o) {
|
|
9
|
+
let { shortcuts: n } = t;
|
|
10
|
+
return Array.isArray(n) && n.includes(e.params.keys);
|
|
11
|
+
}
|
|
12
|
+
return e.action !== a || s(e.params.interval) === t.interval;
|
|
13
|
+
}, l = 5e3, u = 20, d = class a {
|
|
13
14
|
eventBridge;
|
|
14
15
|
parentManager;
|
|
15
16
|
childManagers;
|
|
@@ -20,22 +21,23 @@ var s = (e, i) => {
|
|
|
20
21
|
latestRuns = /* @__PURE__ */ new Map();
|
|
21
22
|
lastUpdate;
|
|
22
23
|
listeners = /* @__PURE__ */ new Set();
|
|
24
|
+
parked = /* @__PURE__ */ new Map();
|
|
23
25
|
constructor(e = "", t = {}, n = {}) {
|
|
24
|
-
this.eventBridge = new
|
|
26
|
+
this.eventBridge = new r(), this.parentManager = void 0, this.childManagers = [], this.subscriptors = {}, this.callbacksAvailables = {}, this.interactionsData = {
|
|
25
27
|
currentPageId: e,
|
|
26
28
|
...t,
|
|
27
29
|
...n
|
|
28
30
|
}, this.lastUpdate = Date.now();
|
|
29
31
|
}
|
|
30
|
-
eventBridgeCallback = (
|
|
31
|
-
if (!
|
|
32
|
-
let o = this.subscriptors[
|
|
33
|
-
if (await Promise.resolve(), !o || this.subscriptors[
|
|
34
|
-
let
|
|
32
|
+
eventBridgeCallback = (n) => async (r, i, a) => {
|
|
33
|
+
if (!n || !i || !r) return;
|
|
34
|
+
let o = this.subscriptors[r];
|
|
35
|
+
if (await Promise.resolve(), !o || this.subscriptors[r] !== o) return;
|
|
36
|
+
let s = t(this.subscriptors, `${r}.getAdditionalParams`, void 0), l = () => ({
|
|
35
37
|
...this.interactionsData,
|
|
36
|
-
...typeof
|
|
37
|
-
}), u = Object.values(
|
|
38
|
-
await Promise.all(u.map((
|
|
38
|
+
...typeof s == "function" ? s().dataSource : void 0
|
|
39
|
+
}), u = Object.values(n).filter((e) => e.type === "trigger" && e.action === i && e.enabled && c(e, a));
|
|
40
|
+
await Promise.all(u.map((t) => this.runFlow(`${r}.${t.id}`, t.whileRunning ?? "skip", (i) => e(t, n, this.getCallbacksAvailables(), { [t.id]: a }, l, r, i))));
|
|
39
41
|
};
|
|
40
42
|
runFlow(e, t, n) {
|
|
41
43
|
if (t === "latest") {
|
|
@@ -53,16 +55,16 @@ var s = (e, i) => {
|
|
|
53
55
|
});
|
|
54
56
|
return this.flowsRunning.set(e, i), i;
|
|
55
57
|
}
|
|
56
|
-
subscribe(e, t = {},
|
|
57
|
-
return !e || this.subscriptors[e] ? !1 : (
|
|
58
|
+
subscribe(e, t = {}, r = {}, i = {}, a) {
|
|
59
|
+
return !e || this.subscriptors[e] ? !1 : (n(this.subscriptors, e, {
|
|
58
60
|
id: e,
|
|
59
|
-
triggers:
|
|
60
|
-
getAdditionalParams:
|
|
61
|
-
}), this.wire(e, t,
|
|
61
|
+
triggers: r,
|
|
62
|
+
getAdditionalParams: a
|
|
63
|
+
}), this.wire(e, t, r, i), this.touch(), !0);
|
|
62
64
|
}
|
|
63
65
|
update(e, t = {}, n = {}, r = {}, i) {
|
|
64
66
|
let a = this.subscriptors[e];
|
|
65
|
-
return a ? (a.triggers = n, a.getAdditionalParams = i, this.wire(e, t, n, r), this.touch(), !0) : !1;
|
|
67
|
+
return a ? (a.triggers = n, a.getAdditionalParams = i, this.wire(e, t, n, r), this.touch(), this.replayParked(e), !0) : !1;
|
|
66
68
|
}
|
|
67
69
|
wire(e, t, n, r) {
|
|
68
70
|
let i = Object.keys(r);
|
|
@@ -84,17 +86,17 @@ var s = (e, i) => {
|
|
|
84
86
|
}, {}) : delete this.callbacksAvailables[e], Object.keys(n).length > 0 ? this.eventBridge.on("interaction", e, this.eventBridgeCallback(t), { override: !0 }) : this.eventBridge.off("interaction", e);
|
|
85
87
|
}
|
|
86
88
|
unsubscribe(e) {
|
|
87
|
-
return this.subscriptors[e] ? (this.eventBridge.off("interaction", e), delete this.subscriptors[e], this.callbacksAvailables[e] && delete this.callbacksAvailables[e], this.touch(), !0) : !1;
|
|
89
|
+
return this.subscriptors[e] ? (this.eventBridge.off("interaction", e), delete this.subscriptors[e], this.dropParked(e), this.callbacksAvailables[e] && delete this.callbacksAvailables[e], this.touch(), !0) : !1;
|
|
88
90
|
}
|
|
89
91
|
getRootManager() {
|
|
90
92
|
return this.parentManager ? this.parentManager.getRootManager() : this;
|
|
91
93
|
}
|
|
92
94
|
getSubscriptorInternal(e) {
|
|
93
|
-
let
|
|
94
|
-
if (!
|
|
95
|
-
for (let
|
|
95
|
+
let n = t(this.subscriptors, e);
|
|
96
|
+
if (!n && this.childManagers.length > 0) {
|
|
97
|
+
for (let t of this.childManagers) if (n = t.getSubscriptorInternal(e), n) break;
|
|
96
98
|
}
|
|
97
|
-
return
|
|
99
|
+
return n;
|
|
98
100
|
}
|
|
99
101
|
getSubscriptor(e) {
|
|
100
102
|
return this.parentManager ? this.getRootManager()?.getSubscriptorInternal(e) : this.getSubscriptorInternal(e);
|
|
@@ -125,11 +127,52 @@ var s = (e, i) => {
|
|
|
125
127
|
};
|
|
126
128
|
}
|
|
127
129
|
interactionTrigger(e, t, n = {}) {
|
|
128
|
-
if (e) return this.eventBridge.emit("interaction", e, e, t, n);
|
|
130
|
+
if (e) return this.subscriptors[e] ? this.eventBridge.emit("interaction", e, e, t, n) : this.park(e, t, n);
|
|
131
|
+
}
|
|
132
|
+
park(e, t, n) {
|
|
133
|
+
let r = Date.now(), i = (this.parked.get(e) ?? []).filter((t) => r - t.at <= l || (this.settleUnanswered(e, t), !1));
|
|
134
|
+
if (i.length >= u) {
|
|
135
|
+
let t = i.shift();
|
|
136
|
+
t && this.settleUnanswered(e, t);
|
|
137
|
+
}
|
|
138
|
+
return new Promise((a) => {
|
|
139
|
+
i.push({
|
|
140
|
+
eventName: t,
|
|
141
|
+
params: n,
|
|
142
|
+
at: r,
|
|
143
|
+
settle: a
|
|
144
|
+
}), this.parked.set(e, i);
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
replayParked(e) {
|
|
148
|
+
let t = this.parked.get(e);
|
|
149
|
+
if (!t) return;
|
|
150
|
+
this.parked.delete(e);
|
|
151
|
+
let n = Date.now();
|
|
152
|
+
t.forEach((t) => {
|
|
153
|
+
n - t.at > l ? this.settleUnanswered(e, t) : this.eventBridge.emit("interaction", e, e, t.eventName, t.params).then(t.settle, (n) => {
|
|
154
|
+
i.danger("interactions", `${t.eventName} on "${e}" failed once its flows were wired`, {
|
|
155
|
+
id: e,
|
|
156
|
+
eventName: t.eventName,
|
|
157
|
+
error: n
|
|
158
|
+
}), t.settle([]);
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
dropParked(e) {
|
|
163
|
+
this.parked.get(e)?.forEach((t) => {
|
|
164
|
+
this.settleUnanswered(e, t);
|
|
165
|
+
}), this.parked.delete(e);
|
|
166
|
+
}
|
|
167
|
+
settleUnanswered(e, t) {
|
|
168
|
+
i.warning("interactions", `${t.eventName} on "${e}" was not run: the element never wired its flows (unmounted, or not on this page)`, {
|
|
169
|
+
id: e,
|
|
170
|
+
eventName: t.eventName
|
|
171
|
+
}), t.settle([]);
|
|
129
172
|
}
|
|
130
|
-
createChildManager = (e = {},
|
|
131
|
-
let
|
|
132
|
-
return
|
|
173
|
+
createChildManager = (e = {}, t = {}) => {
|
|
174
|
+
let n = new a(this.interactionsData.currentPageId, e, t);
|
|
175
|
+
return n.parentManager = this, this.childManagers.push(n), n;
|
|
133
176
|
};
|
|
134
177
|
removeChildManager = (e) => {
|
|
135
178
|
this.childManagers = this.childManagers.filter((t) => t !== e);
|
|
@@ -145,5 +188,4 @@ var s = (e, i) => {
|
|
|
145
188
|
for (let t of this.listeners) t(e);
|
|
146
189
|
}
|
|
147
190
|
};
|
|
148
|
-
|
|
149
|
-
export { c as default };
|
|
191
|
+
export { d as default };
|
|
@@ -7,7 +7,7 @@ import a from "./sources/QueriesSource/QueriesInteractions.mjs";
|
|
|
7
7
|
import o from "./sources/StateSource/StateInteractions.mjs";
|
|
8
8
|
import { jsx as s } from "react/jsx-runtime";
|
|
9
9
|
import { useRenderSettings as c, useSdkStore as l } from "@plitzi/sdk-shared/store";
|
|
10
|
-
|
|
10
|
+
// src/InteractionsSourcesProvider.tsx
|
|
11
11
|
var u = ({ children: u, hostActions: d }) => {
|
|
12
12
|
let [[f, p, m]] = l([
|
|
13
13
|
"navigation.routeParams",
|
|
@@ -27,5 +27,4 @@ var u = ({ children: u, hostActions: d }) => {
|
|
|
27
27
|
}) }) }) }) })
|
|
28
28
|
});
|
|
29
29
|
};
|
|
30
|
-
//#endregion
|
|
31
30
|
export { u as default };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import i from "../sources/
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
export {
|
|
1
|
+
import { actionsCallbacks as e } from "../sources/ActionsSource/callbacks.mjs";
|
|
2
|
+
import { authCallbacks as t } from "../sources/AuthSource/callbacks.mjs";
|
|
3
|
+
import n from "../sources/HostSource/callbacks.mjs";
|
|
4
|
+
import { navigationCallbacks as r } from "../sources/NavigationSource/callbacks.mjs";
|
|
5
|
+
import { queriesCallbacks as i } from "../sources/QueriesSource/callbacks.mjs";
|
|
6
|
+
import { stateCallbacks as a } from "../sources/StateSource/callbacks.mjs";
|
|
7
|
+
import { copyToClipboardSpec as o } from "../utility/copyToClipboardSpec.mjs";
|
|
8
|
+
import { webHookSpec as s } from "../utility/webHookSpec.mjs";
|
|
9
|
+
export { e as actionsCallbacks, t as authCallbacks, o as copyToClipboardSpec, n as hostCallbacks, r as navigationCallbacks, i as queriesCallbacks, a as stateCallbacks, s as webHookSpec };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/helpers/coerceDeclaredParams.ts
|
|
2
2
|
var e = (e, t) => typeof e.type == "function" ? e.type(t) : e.type, t = (e, t) => {
|
|
3
3
|
if (typeof t != "string") return t;
|
|
4
4
|
if (e === "number") {
|
|
@@ -14,5 +14,4 @@ var e = (e, t) => typeof e.type == "function" ? e.type(t) : e.type, t = (e, t) =
|
|
|
14
14
|
for (let [n, o] of Object.entries(i)) Object.hasOwn(r, n) && (a[n] = t(e(o, r), r[n]));
|
|
15
15
|
return a;
|
|
16
16
|
};
|
|
17
|
-
//#endregion
|
|
18
17
|
export { n as coerceDeclaredParams };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import e from "../InteractionsContext.mjs";
|
|
2
2
|
import { use as t, useEffect as n } from "react";
|
|
3
|
-
|
|
3
|
+
// src/hooks/useInteractions.ts
|
|
4
4
|
var r = ({ id: r, interactions: i, triggers: a, callbacks: o, getAdditionalParams: s }) => {
|
|
5
5
|
let { interactionsManager: c } = t(e);
|
|
6
6
|
n(() => {
|
|
@@ -18,5 +18,4 @@ var r = ({ id: r, interactions: i, triggers: a, callbacks: o, getAdditionalParam
|
|
|
18
18
|
c
|
|
19
19
|
]);
|
|
20
20
|
};
|
|
21
|
-
//#endregion
|
|
22
21
|
export { r as default };
|
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import e from "./
|
|
2
|
-
import t from "./
|
|
3
|
-
import n from "./
|
|
1
|
+
import e from "./hooks/useInteractions.mjs";
|
|
2
|
+
import t from "./InteractionsContext.mjs";
|
|
3
|
+
import n from "./InteractionsContextProvider.mjs";
|
|
4
4
|
import r, { flowTrigger as i } from "./InteractionsHelper.mjs";
|
|
5
5
|
import a from "./InteractionsManager.mjs";
|
|
6
|
-
import o from "./
|
|
6
|
+
import o from "./InteractionsSourcesProvider.mjs";
|
|
7
7
|
import { ServerActionContext as s } from "./sources/ActionsSource/ServerActionContext.mjs";
|
|
8
8
|
import c from "./sources/ActionsSource/ActionInteractions.mjs";
|
|
9
9
|
import l from "./sources/AuthSource/AuthInteractions.mjs";
|
|
@@ -12,5 +12,5 @@ import d from "./sources/HostSource/HostInteractions.mjs";
|
|
|
12
12
|
import f from "./sources/NavigationSource/NavigationInteractions.mjs";
|
|
13
13
|
import p from "./sources/QueriesSource/QueriesInteractions.mjs";
|
|
14
14
|
import m from "./sources/StateSource/StateInteractions.mjs";
|
|
15
|
-
import h from "./
|
|
16
|
-
export { c as ActionInteractions, l as AuthInteractions, d as HostInteractions,
|
|
15
|
+
import h from "./utility/index.mjs";
|
|
16
|
+
export { c as ActionInteractions, l as AuthInteractions, d as HostInteractions, t as InteractionsContext, n as InteractionsContextProvider, r as InteractionsHelper, a as InteractionsManager, o as InteractionsSourcesProvider, f as NavigationInteractions, p as QueriesInteractions, s as ServerActionContext, m as StateInteractions, i as flowTrigger, u as hostCallbacks, e as useInteractions, h as utility };
|