@xmachines/json-render-react 0.20.0-xm.2 → 0.20.0-xm.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/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.mjs
CHANGED
|
@@ -183,7 +183,8 @@ import {
|
|
|
183
183
|
useContext as useContext4,
|
|
184
184
|
useState as useState2,
|
|
185
185
|
useCallback as useCallback3,
|
|
186
|
-
useMemo as useMemo4
|
|
186
|
+
useMemo as useMemo4,
|
|
187
|
+
useRef as useRef3
|
|
187
188
|
} from "react";
|
|
188
189
|
import {
|
|
189
190
|
resolveAction,
|
|
@@ -463,6 +464,7 @@ function ActionProvider({
|
|
|
463
464
|
const [handlers, setHandlers] = useState2(initialHandlers);
|
|
464
465
|
const [loadingActions, setLoadingActions] = useState2(/* @__PURE__ */ new Set());
|
|
465
466
|
const [pendingConfirmation, setPendingConfirmation] = useState2(null);
|
|
467
|
+
const pendingRef = useRef3(null);
|
|
466
468
|
const registerHandler = useCallback3(
|
|
467
469
|
(name, handler) => {
|
|
468
470
|
setHandlers((prev) => ({ ...prev, [name]: handler }));
|
|
@@ -482,6 +484,8 @@ function ActionProvider({
|
|
|
482
484
|
});
|
|
483
485
|
let __ok = true;
|
|
484
486
|
let __error = void 0;
|
|
487
|
+
let __cancelled = false;
|
|
488
|
+
let __confirmMs = void 0;
|
|
485
489
|
try {
|
|
486
490
|
if (resolved.action === "setState" && resolved.params) {
|
|
487
491
|
const statePath = resolved.params.statePath;
|
|
@@ -569,39 +573,32 @@ function ActionProvider({
|
|
|
569
573
|
return;
|
|
570
574
|
}
|
|
571
575
|
if (resolved.confirm) {
|
|
572
|
-
|
|
573
|
-
|
|
576
|
+
pendingRef.current?.reject();
|
|
577
|
+
const confirmOpenedAt = Date.now();
|
|
578
|
+
const confirmed = await new Promise((res) => {
|
|
579
|
+
const entry = {
|
|
574
580
|
action: resolved,
|
|
575
581
|
handler,
|
|
576
582
|
resolve: () => {
|
|
583
|
+
pendingRef.current = null;
|
|
577
584
|
setPendingConfirmation(null);
|
|
578
|
-
|
|
585
|
+
res(true);
|
|
579
586
|
},
|
|
580
587
|
reject: () => {
|
|
588
|
+
pendingRef.current = null;
|
|
581
589
|
setPendingConfirmation(null);
|
|
582
|
-
|
|
590
|
+
res(false);
|
|
583
591
|
}
|
|
584
|
-
}
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
try {
|
|
588
|
-
await executeAction({
|
|
589
|
-
action: resolved,
|
|
590
|
-
handler,
|
|
591
|
-
setState: set,
|
|
592
|
-
navigate,
|
|
593
|
-
executeAction: async (binding2) => {
|
|
594
|
-
await execute(binding2);
|
|
595
|
-
}
|
|
596
|
-
});
|
|
597
|
-
} finally {
|
|
598
|
-
setLoadingActions((prev) => {
|
|
599
|
-
const next = new Set(prev);
|
|
600
|
-
next.delete(resolved.action);
|
|
601
|
-
return next;
|
|
602
|
-
});
|
|
603
|
-
}
|
|
592
|
+
};
|
|
593
|
+
pendingRef.current = entry;
|
|
594
|
+
setPendingConfirmation(entry);
|
|
604
595
|
});
|
|
596
|
+
__confirmMs = Date.now() - confirmOpenedAt;
|
|
597
|
+
if (!confirmed) {
|
|
598
|
+
__ok = false;
|
|
599
|
+
__cancelled = true;
|
|
600
|
+
return;
|
|
601
|
+
}
|
|
605
602
|
}
|
|
606
603
|
setLoadingActions((prev) => new Set(prev).add(resolved.action));
|
|
607
604
|
try {
|
|
@@ -633,6 +630,8 @@ function ActionProvider({
|
|
|
633
630
|
ok: __ok,
|
|
634
631
|
at: now,
|
|
635
632
|
durationMs: now - dispatchedAt,
|
|
633
|
+
cancelled: __cancelled || void 0,
|
|
634
|
+
confirmMs: __confirmMs,
|
|
636
635
|
error: __error
|
|
637
636
|
});
|
|
638
637
|
}
|
|
@@ -640,11 +639,11 @@ function ActionProvider({
|
|
|
640
639
|
[handlers, get, set, getSnapshot, navigate, validation]
|
|
641
640
|
);
|
|
642
641
|
const confirm = useCallback3(() => {
|
|
643
|
-
|
|
644
|
-
}, [
|
|
642
|
+
pendingRef.current?.resolve();
|
|
643
|
+
}, []);
|
|
645
644
|
const cancel = useCallback3(() => {
|
|
646
|
-
|
|
647
|
-
}, [
|
|
645
|
+
pendingRef.current?.reject();
|
|
646
|
+
}, []);
|
|
648
647
|
const value = useMemo4(
|
|
649
648
|
() => ({
|
|
650
649
|
handlers,
|
|
@@ -805,7 +804,7 @@ import React5, {
|
|
|
805
804
|
useCallback as useCallback4,
|
|
806
805
|
useEffect as useEffect2,
|
|
807
806
|
useMemo as useMemo5,
|
|
808
|
-
useRef as
|
|
807
|
+
useRef as useRef4
|
|
809
808
|
} from "react";
|
|
810
809
|
import {
|
|
811
810
|
resolveElementProps,
|
|
@@ -957,8 +956,8 @@ var ElementRenderer = React5.memo(function ElementRenderer2({
|
|
|
957
956
|
[onBindings, emit]
|
|
958
957
|
);
|
|
959
958
|
const watchConfig = element.watch;
|
|
960
|
-
const prevWatchValues =
|
|
961
|
-
const stableWatchRef =
|
|
959
|
+
const prevWatchValues = useRef4(null);
|
|
960
|
+
const stableWatchRef = useRef4(void 0);
|
|
962
961
|
const watchedValues = useMemo5(() => {
|
|
963
962
|
if (!watchConfig) return void 0;
|
|
964
963
|
const values = {};
|
|
@@ -1365,7 +1364,7 @@ function createRenderer(catalog, components) {
|
|
|
1365
1364
|
}
|
|
1366
1365
|
|
|
1367
1366
|
// src/hooks.ts
|
|
1368
|
-
import { useState as useState3, useCallback as useCallback5, useRef as
|
|
1367
|
+
import { useState as useState3, useCallback as useCallback5, useRef as useRef5, useEffect as useEffect3 } from "react";
|
|
1369
1368
|
import {
|
|
1370
1369
|
setByPath,
|
|
1371
1370
|
getByPath as getByPath3,
|
|
@@ -1518,10 +1517,10 @@ function useUIStream({
|
|
|
1518
1517
|
const [error, setError] = useState3(null);
|
|
1519
1518
|
const [usage, setUsage] = useState3(null);
|
|
1520
1519
|
const [rawLines, setRawLines] = useState3([]);
|
|
1521
|
-
const abortControllerRef =
|
|
1522
|
-
const onCompleteRef =
|
|
1520
|
+
const abortControllerRef = useRef5(null);
|
|
1521
|
+
const onCompleteRef = useRef5(onComplete);
|
|
1523
1522
|
onCompleteRef.current = onComplete;
|
|
1524
|
-
const onErrorRef =
|
|
1523
|
+
const onErrorRef = useRef5(onError);
|
|
1525
1524
|
onErrorRef.current = onError;
|
|
1526
1525
|
const clear = useCallback5(() => {
|
|
1527
1526
|
setSpec(null);
|
|
@@ -1707,8 +1706,8 @@ function getTextFromParts(parts) {
|
|
|
1707
1706
|
).map((p) => p.text.trim()).filter(Boolean).join("\n\n");
|
|
1708
1707
|
}
|
|
1709
1708
|
function useJsonRenderMessage(parts) {
|
|
1710
|
-
const prevPartsRef =
|
|
1711
|
-
const prevResultRef =
|
|
1709
|
+
const prevPartsRef = useRef5([]);
|
|
1710
|
+
const prevResultRef = useRef5({
|
|
1712
1711
|
spec: null,
|
|
1713
1712
|
text: ""
|
|
1714
1713
|
});
|
|
@@ -1740,12 +1739,12 @@ function useChatUI({
|
|
|
1740
1739
|
const [messages, setMessages] = useState3([]);
|
|
1741
1740
|
const [isStreaming, setIsStreaming] = useState3(false);
|
|
1742
1741
|
const [error, setError] = useState3(null);
|
|
1743
|
-
const abortControllerRef =
|
|
1744
|
-
const messagesRef =
|
|
1742
|
+
const abortControllerRef = useRef5(null);
|
|
1743
|
+
const messagesRef = useRef5(messages);
|
|
1745
1744
|
messagesRef.current = messages;
|
|
1746
|
-
const onCompleteRef =
|
|
1745
|
+
const onCompleteRef = useRef5(onComplete);
|
|
1747
1746
|
onCompleteRef.current = onComplete;
|
|
1748
|
-
const onErrorRef =
|
|
1747
|
+
const onErrorRef = useRef5(onError);
|
|
1749
1748
|
onErrorRef.current = onError;
|
|
1750
1749
|
const clear = useCallback5(() => {
|
|
1751
1750
|
setMessages([]);
|