@calimero-network/mero-react 9.16.0 → 10.0.0

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
 
@@ -503,7 +505,7 @@ useGroupMetadata, useMemberMetadata, useUpdateMemberRole
503
505
  useSetDefaultCapabilities, useDefaultCapabilities
504
506
  useSetSubgroupVisibility, useSubgroupVisibility, useSetTeeAdmissionPolicy
505
507
  useDetachContextFromGroup
506
- useNamespaces, useNamespace, useNamespaceGroups, useNamespaceIdentity
508
+ useNamespaces, useNamespace, useNamespaceGroups, useNodeIdentity
507
509
  useNamespacesForApplication, useCreateNamespace, useDeleteNamespace
508
510
  useJoinNamespace, useRedeemInvitation, useCreateNamespaceInvitation, useCreateGroupInNamespace
509
511
  useBlobInfo, useBlobUrl, useUploadBlob
package/dist/index.cjs CHANGED
@@ -2880,15 +2880,6 @@ function useNodeIdentity() {
2880
2880
  );
2881
2881
  return { identity: data, loading, error, refetch };
2882
2882
  }
2883
- function useNamespaceIdentity(namespaceId) {
2884
- const { admin } = useMero();
2885
- const { data, loading, error, refetch } = useAsyncResource(
2886
- admin && namespaceId ? () => admin.getNamespaceIdentity(namespaceId) : null,
2887
- null,
2888
- [admin, namespaceId]
2889
- );
2890
- return { identity: data, loading, error, refetch };
2891
- }
2892
2883
  function useNamespacesForApplication(applicationId) {
2893
2884
  const { admin, isDelegated } = useMero();
2894
2885
  const { data, loading, error, refetch } = useAsyncResource(
@@ -4521,24 +4512,33 @@ function InvitationDialog({
4521
4512
  }) {
4522
4513
  const { state, accept, decline, retry, dismiss } = redemption;
4523
4514
  const joinedId = state.stage === "joined" ? state.namespaceId : null;
4524
- const stillSyncing = useJustJoined(joinedId);
4515
+ const [backgroundId, setBackgroundId] = react.useState(null);
4525
4516
  react.useEffect(() => {
4526
- if (joinedId && stillSyncing && synced) clearNamespaceJustJoined(joinedId);
4527
- }, [joinedId, stillSyncing, synced]);
4517
+ if (joinedId) setBackgroundId(joinedId);
4518
+ }, [joinedId]);
4519
+ const waitingId = joinedId ?? backgroundId;
4520
+ const flagged = useJustJoined(waitingId);
4521
+ const stillSyncing = joinedId !== null && flagged;
4522
+ react.useEffect(() => {
4523
+ if (!joinedId && backgroundId && !flagged) setBackgroundId(null);
4524
+ }, [joinedId, backgroundId, flagged]);
4525
+ react.useEffect(() => {
4526
+ if (waitingId && flagged && synced) clearNamespaceJustJoined(waitingId);
4527
+ }, [waitingId, flagged, synced]);
4528
4528
  const [slow, setSlow] = react.useState(false);
4529
4529
  react.useEffect(() => {
4530
4530
  setSlow(false);
4531
- if (!joinedId || !stillSyncing) return;
4531
+ if (!waitingId || !flagged) return;
4532
4532
  const slowTimer = setTimeout(() => setSlow(true), JOIN_SYNC_WATCHDOG_MS);
4533
4533
  const ceiling = setTimeout(
4534
- () => clearNamespaceJustJoined(joinedId),
4534
+ () => clearNamespaceJustJoined(waitingId),
4535
4535
  JOIN_SYNC_MAX_MS
4536
4536
  );
4537
4537
  return () => {
4538
4538
  clearTimeout(slowTimer);
4539
4539
  clearTimeout(ceiling);
4540
4540
  };
4541
- }, [joinedId, stillSyncing]);
4541
+ }, [waitingId, flagged]);
4542
4542
  const stage = state.stage === "idle" ? null : state.stage === "joined" ? stillSyncing ? "syncing" : "ready" : state.stage;
4543
4543
  react.useEffect(() => {
4544
4544
  if (stage !== "ready") return;
@@ -4547,15 +4547,37 @@ function InvitationDialog({
4547
4547
  }, [stage, dismiss]);
4548
4548
  const titleId = react.useId();
4549
4549
  const bodyId = react.useId();
4550
+ const overlayRef = react.useRef(null);
4550
4551
  const dialogRef = react.useRef(null);
4551
4552
  const primaryRef = react.useRef(null);
4553
+ const open = stage !== null;
4554
+ react.useEffect(() => {
4555
+ const overlay = overlayRef.current;
4556
+ if (!open || !overlay || typeof MutationObserver === "undefined") return;
4557
+ const made = /* @__PURE__ */ new Set();
4558
+ const shut = (el) => {
4559
+ if (el === overlay || el.hasAttribute("inert")) return;
4560
+ if (el.tagName === "SCRIPT" || el.tagName === "STYLE") return;
4561
+ el.setAttribute("inert", "");
4562
+ made.add(el);
4563
+ };
4564
+ Array.from(document.body.children).forEach(shut);
4565
+ const observer = new MutationObserver((records) => {
4566
+ for (const record of records) record.addedNodes.forEach((n) => n instanceof Element && shut(n));
4567
+ });
4568
+ observer.observe(document.body, { childList: true });
4569
+ return () => {
4570
+ observer.disconnect();
4571
+ made.forEach((el) => el.removeAttribute("inert"));
4572
+ };
4573
+ }, [open]);
4552
4574
  react.useEffect(() => {
4553
4575
  if (!stage) return;
4554
4576
  (primaryRef.current ?? dialogRef.current)?.focus();
4555
4577
  }, [stage]);
4556
4578
  const close = react.useCallback(() => {
4557
4579
  if (stage === "awaiting-confirmation") decline();
4558
- else if (stage && stage !== "joining") dismiss();
4580
+ else if (stage && stage !== "joining" && stage !== "syncing") dismiss();
4559
4581
  }, [stage, decline, dismiss]);
4560
4582
  const onKeyDown = (event) => {
4561
4583
  if (event.key === "Escape") {
@@ -4612,9 +4634,12 @@ function InvitationDialog({
4612
4634
  /* @__PURE__ */ jsxRuntime.jsx(
4613
4635
  "div",
4614
4636
  {
4637
+ ref: overlayRef,
4615
4638
  className: "mero-invite-overlay",
4616
4639
  onMouseDown: (event) => {
4617
- if (event.target === event.currentTarget) close();
4640
+ if (event.target !== event.currentTarget) return;
4641
+ event.preventDefault();
4642
+ close();
4618
4643
  },
4619
4644
  children: /* @__PURE__ */ jsxRuntime.jsxs(
4620
4645
  "div",
@@ -4671,7 +4696,7 @@ function InvitationDialog({
4671
4696
  }
4672
4697
  )
4673
4698
  ] }) : null,
4674
- stage === "syncing" ? /* @__PURE__ */ jsxRuntime.jsx(
4699
+ stage === "syncing" && slow ? /* @__PURE__ */ jsxRuntime.jsx(
4675
4700
  "button",
4676
4701
  {
4677
4702
  ref: primaryRef,
@@ -5349,7 +5374,6 @@ exports.useMigrationStatus = useMigrationStatus;
5349
5374
  exports.useMyAuthoredMigration = useMyAuthoredMigration;
5350
5375
  exports.useNamespace = useNamespace;
5351
5376
  exports.useNamespaceGroups = useNamespaceGroups;
5352
- exports.useNamespaceIdentity = useNamespaceIdentity;
5353
5377
  exports.useNamespaces = useNamespaces;
5354
5378
  exports.useNamespacesForApplication = useNamespacesForApplication;
5355
5379
  exports.useNodeIdentity = useNodeIdentity;