@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 CHANGED
@@ -305,7 +305,7 @@ An app whose join does more than join the namespace (entering a context, choosin
305
305
 
306
306
  `InvitationGate` is what a link shows someone who is not logged in. Without it they land on the app's ordinary logged-out page (usually its marketing landing), with nothing saying they were invited, while the invitation waits in storage for a login they have to think of themselves. The gate shows a full page instead: **You're invited to join “Design team”** (decoded by the app's own `parse`, which needs no session), in which app, with **Log in to join** (`ConnectButton` and its Node / Cloud dialog) and **Not now** (acks the invitation, so it does not come back). While the session is still restoring it shows a blank page with a spinner, so neither the landing page nor the invite screen flashes; once logged in it renders nothing and the dialog takes over. Mounted with no children it covers the page as a full-page layer; wrapped around the app (`<InvitationGate …>{app}</InvitationGate>`) it renders instead of the app. Test ids: `invite-landing` (with `data-state`: `checking`, `invited`, `invalid`), `invite-landing-login`, `invite-landing-decline`.
307
307
 
308
- `InvitationDialog` walks through every stage in one modal: **ask** (Join / Not now) → **joining** (cannot be closed) → **syncing** → **ready** (closes by itself), or **already a member**, or **failed** (the reason in plain words, with Try again when a retry can help).
308
+ `InvitationDialog` walks through every stage in one modal: **ask** (Join / Not now) → **joining** → **syncing** → **ready** (closes by itself), or **already a member**, or **failed** (the reason in plain words, with Try again when a retry can help).
309
309
 
310
310
  **Syncing** lasts until the joined namespace's data has arrived. Redemption marks the namespace just-joined, and the page that reads its data clears that mark:
311
311
 
@@ -315,7 +315,9 @@ An app whose join does more than join the namespace (entering a context, choosin
315
315
  const { isSyncing, dismiss } = useJoinSync({ namespaceId, settled: !loading });
316
316
  ```
317
317
 
318
- An app whose root already knows can pass `synced` to the dialog instead. A sync that never settles says so after `JOIN_SYNC_WATCHDOG_MS` and lets go at `JOIN_SYNC_MAX_MS`. `JoinSyncBanner` is the matching in-page strip.
318
+ An app whose root already knows can pass `synced` to the dialog instead. A sync that never settles says so after `JOIN_SYNC_WATCHDOG_MS`, offering **Continue in background**, and lets go at `JOIN_SYNC_MAX_MS`. `JoinSyncBanner` is the matching in-page strip: a page that can be reached while its namespace is still syncing shows it rather than its empty state.
319
+
320
+ Joining and syncing cannot be closed by a click on the backdrop or by Escape, and while the dialog is up the rest of the page is `inert`. After **Continue in background** the dialog keeps the flag's `JOIN_SYNC_MAX_MS` ceiling running, so a person who navigates away from the page that would clear it is not left with a namespace flagged for the rest of the session.
319
321
 
320
322
  The dialog is styled with the same `--mero-*` variables as `<ConnectButton>` and `<LoginModal>` (see [Theming](#theming)). Its test ids are `invite-prompt` (with `data-stage`), `invite-accept`, `invite-decline`, `invite-continue`, `invite-done`, `invite-retry` and `invite-error`.
321
323
 
package/dist/index.cjs 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 stillSyncing = useJustJoined(joinedId);
4524
+ const [backgroundId, setBackgroundId] = react.useState(null);
4525
4525
  react.useEffect(() => {
4526
- if (joinedId && stillSyncing && synced) clearNamespaceJustJoined(joinedId);
4527
- }, [joinedId, stillSyncing, synced]);
4526
+ if (joinedId) setBackgroundId(joinedId);
4527
+ }, [joinedId]);
4528
+ const waitingId = joinedId ?? backgroundId;
4529
+ const flagged = useJustJoined(waitingId);
4530
+ const stillSyncing = joinedId !== null && flagged;
4531
+ react.useEffect(() => {
4532
+ if (!joinedId && backgroundId && !flagged) setBackgroundId(null);
4533
+ }, [joinedId, backgroundId, flagged]);
4534
+ react.useEffect(() => {
4535
+ if (waitingId && flagged && synced) clearNamespaceJustJoined(waitingId);
4536
+ }, [waitingId, flagged, synced]);
4528
4537
  const [slow, setSlow] = react.useState(false);
4529
4538
  react.useEffect(() => {
4530
4539
  setSlow(false);
4531
- if (!joinedId || !stillSyncing) return;
4540
+ if (!waitingId || !flagged) return;
4532
4541
  const slowTimer = setTimeout(() => setSlow(true), JOIN_SYNC_WATCHDOG_MS);
4533
4542
  const ceiling = setTimeout(
4534
- () => clearNamespaceJustJoined(joinedId),
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
- }, [joinedId, stillSyncing]);
4550
+ }, [waitingId, flagged]);
4542
4551
  const stage = state.stage === "idle" ? null : state.stage === "joined" ? stillSyncing ? "syncing" : "ready" : state.stage;
4543
4552
  react.useEffect(() => {
4544
4553
  if (stage !== "ready") return;
@@ -4547,15 +4556,37 @@ function InvitationDialog({
4547
4556
  }, [stage, dismiss]);
4548
4557
  const titleId = react.useId();
4549
4558
  const bodyId = react.useId();
4559
+ const overlayRef = react.useRef(null);
4550
4560
  const dialogRef = react.useRef(null);
4551
4561
  const primaryRef = react.useRef(null);
4562
+ const open = stage !== null;
4563
+ react.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
  react.useEffect(() => {
4553
4584
  if (!stage) return;
4554
4585
  (primaryRef.current ?? dialogRef.current)?.focus();
4555
4586
  }, [stage]);
4556
4587
  const close = react.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__ */ jsxRuntime.jsx(
4613
4644
  "div",
4614
4645
  {
4646
+ ref: overlayRef,
4615
4647
  className: "mero-invite-overlay",
4616
4648
  onMouseDown: (event) => {
4617
- if (event.target === event.currentTarget) close();
4649
+ if (event.target !== event.currentTarget) return;
4650
+ event.preventDefault();
4651
+ close();
4618
4652
  },
4619
4653
  children: /* @__PURE__ */ jsxRuntime.jsxs(
4620
4654
  "div",
@@ -4671,7 +4705,7 @@ function InvitationDialog({
4671
4705
  }
4672
4706
  )
4673
4707
  ] }) : null,
4674
- stage === "syncing" ? /* @__PURE__ */ jsxRuntime.jsx(
4708
+ stage === "syncing" && slow ? /* @__PURE__ */ jsxRuntime.jsx(
4675
4709
  "button",
4676
4710
  {
4677
4711
  ref: primaryRef,