@xmachines/json-render-react 0.20.0-xm.2 → 0.20.0-xm.4
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/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +26 -28
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +41 -42
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -104,9 +104,9 @@ interface PendingConfirmation {
|
|
|
104
104
|
action: ResolvedAction;
|
|
105
105
|
/** The action handler */
|
|
106
106
|
handler: ActionHandler;
|
|
107
|
-
/**
|
|
107
|
+
/** Accept the confirmation — the action runs */
|
|
108
108
|
resolve: () => void;
|
|
109
|
-
/**
|
|
109
|
+
/** Decline the confirmation — the action is skipped, nothing throws */
|
|
110
110
|
reject: () => void;
|
|
111
111
|
}
|
|
112
112
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -104,9 +104,9 @@ interface PendingConfirmation {
|
|
|
104
104
|
action: ResolvedAction;
|
|
105
105
|
/** The action handler */
|
|
106
106
|
handler: ActionHandler;
|
|
107
|
-
/**
|
|
107
|
+
/** Accept the confirmation — the action runs */
|
|
108
108
|
resolve: () => void;
|
|
109
|
-
/**
|
|
109
|
+
/** Decline the confirmation — the action is skipped, nothing throws */
|
|
110
110
|
reject: () => void;
|
|
111
111
|
}
|
|
112
112
|
/**
|
package/dist/index.js
CHANGED
|
@@ -486,6 +486,7 @@ function ActionProvider({
|
|
|
486
486
|
const [handlers, setHandlers] = (0, import_react4.useState)(initialHandlers);
|
|
487
487
|
const [loadingActions, setLoadingActions] = (0, import_react4.useState)(/* @__PURE__ */ new Set());
|
|
488
488
|
const [pendingConfirmation, setPendingConfirmation] = (0, import_react4.useState)(null);
|
|
489
|
+
const pendingRef = (0, import_react4.useRef)(null);
|
|
489
490
|
const registerHandler = (0, import_react4.useCallback)(
|
|
490
491
|
(name, handler) => {
|
|
491
492
|
setHandlers((prev) => ({ ...prev, [name]: handler }));
|
|
@@ -505,6 +506,8 @@ function ActionProvider({
|
|
|
505
506
|
});
|
|
506
507
|
let __ok = true;
|
|
507
508
|
let __error = void 0;
|
|
509
|
+
let __cancelled = false;
|
|
510
|
+
let __confirmMs = void 0;
|
|
508
511
|
try {
|
|
509
512
|
if (resolved.action === "setState" && resolved.params) {
|
|
510
513
|
const statePath = resolved.params.statePath;
|
|
@@ -592,39 +595,32 @@ function ActionProvider({
|
|
|
592
595
|
return;
|
|
593
596
|
}
|
|
594
597
|
if (resolved.confirm) {
|
|
595
|
-
|
|
596
|
-
|
|
598
|
+
pendingRef.current?.reject();
|
|
599
|
+
const confirmOpenedAt = Date.now();
|
|
600
|
+
const confirmed = await new Promise((res) => {
|
|
601
|
+
const entry = {
|
|
597
602
|
action: resolved,
|
|
598
603
|
handler,
|
|
599
604
|
resolve: () => {
|
|
605
|
+
pendingRef.current = null;
|
|
600
606
|
setPendingConfirmation(null);
|
|
601
|
-
|
|
607
|
+
res(true);
|
|
602
608
|
},
|
|
603
609
|
reject: () => {
|
|
610
|
+
pendingRef.current = null;
|
|
604
611
|
setPendingConfirmation(null);
|
|
605
|
-
|
|
612
|
+
res(false);
|
|
606
613
|
}
|
|
607
|
-
}
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
try {
|
|
611
|
-
await (0, import_core4.executeAction)({
|
|
612
|
-
action: resolved,
|
|
613
|
-
handler,
|
|
614
|
-
setState: set,
|
|
615
|
-
navigate,
|
|
616
|
-
executeAction: async (binding2) => {
|
|
617
|
-
await execute(binding2);
|
|
618
|
-
}
|
|
619
|
-
});
|
|
620
|
-
} finally {
|
|
621
|
-
setLoadingActions((prev) => {
|
|
622
|
-
const next = new Set(prev);
|
|
623
|
-
next.delete(resolved.action);
|
|
624
|
-
return next;
|
|
625
|
-
});
|
|
626
|
-
}
|
|
614
|
+
};
|
|
615
|
+
pendingRef.current = entry;
|
|
616
|
+
setPendingConfirmation(entry);
|
|
627
617
|
});
|
|
618
|
+
__confirmMs = Date.now() - confirmOpenedAt;
|
|
619
|
+
if (!confirmed) {
|
|
620
|
+
__ok = false;
|
|
621
|
+
__cancelled = true;
|
|
622
|
+
return;
|
|
623
|
+
}
|
|
628
624
|
}
|
|
629
625
|
setLoadingActions((prev) => new Set(prev).add(resolved.action));
|
|
630
626
|
try {
|
|
@@ -656,6 +652,8 @@ function ActionProvider({
|
|
|
656
652
|
ok: __ok,
|
|
657
653
|
at: now,
|
|
658
654
|
durationMs: now - dispatchedAt,
|
|
655
|
+
cancelled: __cancelled || void 0,
|
|
656
|
+
confirmMs: __confirmMs,
|
|
659
657
|
error: __error
|
|
660
658
|
});
|
|
661
659
|
}
|
|
@@ -663,11 +661,11 @@ function ActionProvider({
|
|
|
663
661
|
[handlers, get, set, getSnapshot, navigate, validation]
|
|
664
662
|
);
|
|
665
663
|
const confirm = (0, import_react4.useCallback)(() => {
|
|
666
|
-
|
|
667
|
-
}, [
|
|
664
|
+
pendingRef.current?.resolve();
|
|
665
|
+
}, []);
|
|
668
666
|
const cancel = (0, import_react4.useCallback)(() => {
|
|
669
|
-
|
|
670
|
-
}, [
|
|
667
|
+
pendingRef.current?.reject();
|
|
668
|
+
}, []);
|
|
671
669
|
const value = (0, import_react4.useMemo)(
|
|
672
670
|
() => ({
|
|
673
671
|
handlers,
|