@calimero-network/mero-react 9.16.0 → 9.16.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/README.md +4 -2
- package/dist/index.cjs +43 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +43 -9
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4521,24 +4521,33 @@ function InvitationDialog({
|
|
|
4521
4521
|
}) {
|
|
4522
4522
|
const { state, accept, decline, retry, dismiss } = redemption;
|
|
4523
4523
|
const joinedId = state.stage === "joined" ? state.namespaceId : null;
|
|
4524
|
-
const
|
|
4524
|
+
const [backgroundId, setBackgroundId] = useState(null);
|
|
4525
4525
|
useEffect(() => {
|
|
4526
|
-
if (joinedId
|
|
4527
|
-
}, [joinedId
|
|
4526
|
+
if (joinedId) setBackgroundId(joinedId);
|
|
4527
|
+
}, [joinedId]);
|
|
4528
|
+
const waitingId = joinedId ?? backgroundId;
|
|
4529
|
+
const flagged = useJustJoined(waitingId);
|
|
4530
|
+
const stillSyncing = joinedId !== null && flagged;
|
|
4531
|
+
useEffect(() => {
|
|
4532
|
+
if (!joinedId && backgroundId && !flagged) setBackgroundId(null);
|
|
4533
|
+
}, [joinedId, backgroundId, flagged]);
|
|
4534
|
+
useEffect(() => {
|
|
4535
|
+
if (waitingId && flagged && synced) clearNamespaceJustJoined(waitingId);
|
|
4536
|
+
}, [waitingId, flagged, synced]);
|
|
4528
4537
|
const [slow, setSlow] = useState(false);
|
|
4529
4538
|
useEffect(() => {
|
|
4530
4539
|
setSlow(false);
|
|
4531
|
-
if (!
|
|
4540
|
+
if (!waitingId || !flagged) return;
|
|
4532
4541
|
const slowTimer = setTimeout(() => setSlow(true), JOIN_SYNC_WATCHDOG_MS);
|
|
4533
4542
|
const ceiling = setTimeout(
|
|
4534
|
-
() => clearNamespaceJustJoined(
|
|
4543
|
+
() => clearNamespaceJustJoined(waitingId),
|
|
4535
4544
|
JOIN_SYNC_MAX_MS
|
|
4536
4545
|
);
|
|
4537
4546
|
return () => {
|
|
4538
4547
|
clearTimeout(slowTimer);
|
|
4539
4548
|
clearTimeout(ceiling);
|
|
4540
4549
|
};
|
|
4541
|
-
}, [
|
|
4550
|
+
}, [waitingId, flagged]);
|
|
4542
4551
|
const stage = state.stage === "idle" ? null : state.stage === "joined" ? stillSyncing ? "syncing" : "ready" : state.stage;
|
|
4543
4552
|
useEffect(() => {
|
|
4544
4553
|
if (stage !== "ready") return;
|
|
@@ -4547,15 +4556,37 @@ function InvitationDialog({
|
|
|
4547
4556
|
}, [stage, dismiss]);
|
|
4548
4557
|
const titleId = useId();
|
|
4549
4558
|
const bodyId = useId();
|
|
4559
|
+
const overlayRef = useRef(null);
|
|
4550
4560
|
const dialogRef = useRef(null);
|
|
4551
4561
|
const primaryRef = useRef(null);
|
|
4562
|
+
const open = stage !== null;
|
|
4563
|
+
useEffect(() => {
|
|
4564
|
+
const overlay = overlayRef.current;
|
|
4565
|
+
if (!open || !overlay || typeof MutationObserver === "undefined") return;
|
|
4566
|
+
const made = /* @__PURE__ */ new Set();
|
|
4567
|
+
const shut = (el) => {
|
|
4568
|
+
if (el === overlay || el.hasAttribute("inert")) return;
|
|
4569
|
+
if (el.tagName === "SCRIPT" || el.tagName === "STYLE") return;
|
|
4570
|
+
el.setAttribute("inert", "");
|
|
4571
|
+
made.add(el);
|
|
4572
|
+
};
|
|
4573
|
+
Array.from(document.body.children).forEach(shut);
|
|
4574
|
+
const observer = new MutationObserver((records) => {
|
|
4575
|
+
for (const record of records) record.addedNodes.forEach((n) => n instanceof Element && shut(n));
|
|
4576
|
+
});
|
|
4577
|
+
observer.observe(document.body, { childList: true });
|
|
4578
|
+
return () => {
|
|
4579
|
+
observer.disconnect();
|
|
4580
|
+
made.forEach((el) => el.removeAttribute("inert"));
|
|
4581
|
+
};
|
|
4582
|
+
}, [open]);
|
|
4552
4583
|
useEffect(() => {
|
|
4553
4584
|
if (!stage) return;
|
|
4554
4585
|
(primaryRef.current ?? dialogRef.current)?.focus();
|
|
4555
4586
|
}, [stage]);
|
|
4556
4587
|
const close = useCallback(() => {
|
|
4557
4588
|
if (stage === "awaiting-confirmation") decline();
|
|
4558
|
-
else if (stage && stage !== "joining") dismiss();
|
|
4589
|
+
else if (stage && stage !== "joining" && stage !== "syncing") dismiss();
|
|
4559
4590
|
}, [stage, decline, dismiss]);
|
|
4560
4591
|
const onKeyDown = (event) => {
|
|
4561
4592
|
if (event.key === "Escape") {
|
|
@@ -4612,9 +4643,12 @@ function InvitationDialog({
|
|
|
4612
4643
|
/* @__PURE__ */ jsx(
|
|
4613
4644
|
"div",
|
|
4614
4645
|
{
|
|
4646
|
+
ref: overlayRef,
|
|
4615
4647
|
className: "mero-invite-overlay",
|
|
4616
4648
|
onMouseDown: (event) => {
|
|
4617
|
-
if (event.target
|
|
4649
|
+
if (event.target !== event.currentTarget) return;
|
|
4650
|
+
event.preventDefault();
|
|
4651
|
+
close();
|
|
4618
4652
|
},
|
|
4619
4653
|
children: /* @__PURE__ */ jsxs(
|
|
4620
4654
|
"div",
|
|
@@ -4671,7 +4705,7 @@ function InvitationDialog({
|
|
|
4671
4705
|
}
|
|
4672
4706
|
)
|
|
4673
4707
|
] }) : null,
|
|
4674
|
-
stage === "syncing" ? /* @__PURE__ */ jsx(
|
|
4708
|
+
stage === "syncing" && slow ? /* @__PURE__ */ jsx(
|
|
4675
4709
|
"button",
|
|
4676
4710
|
{
|
|
4677
4711
|
ref: primaryRef,
|