@calimero-network/mero-react 9.15.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 +14 -3
- package/dist/index.cjs +224 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +35 -1
- package/dist/index.d.ts +35 -1
- package/dist/index.js +222 -12
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -273,6 +273,7 @@ import {
|
|
|
273
273
|
primeInvitationCapture,
|
|
274
274
|
useInviteRedemption,
|
|
275
275
|
InvitationDialog,
|
|
276
|
+
InvitationGate,
|
|
276
277
|
buildInviteLink,
|
|
277
278
|
} from '@calimero-network/mero-react';
|
|
278
279
|
|
|
@@ -287,7 +288,13 @@ function Invitations() {
|
|
|
287
288
|
redeemer: { join, isMember }, // mero-js `InviteRedeemer`
|
|
288
289
|
onJoined: (namespaceId) => navigate(`/w/${namespaceId}`),
|
|
289
290
|
});
|
|
290
|
-
return
|
|
291
|
+
return (
|
|
292
|
+
<>
|
|
293
|
+
{/* Logged out: "You're invited", with the login. Logged in: nothing. */}
|
|
294
|
+
<InvitationGate parse={decodeMyToken} noun="workspace" appName="My App" />
|
|
295
|
+
<InvitationDialog redemption={redemption} noun="workspace" appName="My App" />
|
|
296
|
+
</>
|
|
297
|
+
);
|
|
291
298
|
}
|
|
292
299
|
|
|
293
300
|
// Sharing: one link shape for every app.
|
|
@@ -296,7 +303,9 @@ const link = buildInviteLink('com.example.my-app', token);
|
|
|
296
303
|
|
|
297
304
|
An app whose join does more than join the namespace (entering a context, choosing where to land) passes `redeem: (parsed) => Promise<RedeemOutcome>` instead of `redeemer`; `parse` may return extra fields, which reach `redeem` and come back as `parsed`. The dialog takes `detail` (the app's own words under the question) and `status` (the step a slow join is on).
|
|
298
305
|
|
|
299
|
-
`
|
|
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
|
+
|
|
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).
|
|
300
309
|
|
|
301
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:
|
|
302
311
|
|
|
@@ -306,7 +315,9 @@ An app whose join does more than join the namespace (entering a context, choosin
|
|
|
306
315
|
const { isSyncing, dismiss } = useJoinSync({ namespaceId, settled: !loading });
|
|
307
316
|
```
|
|
308
317
|
|
|
309
|
-
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
|
|
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.
|
|
310
321
|
|
|
311
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`.
|
|
312
323
|
|
package/dist/index.cjs
CHANGED
|
@@ -28,7 +28,7 @@ function styleInject(css, { insertAt } = {}) {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
// src/components/styles.css
|
|
31
|
-
styleInject(':root {\n --mero-bg: #0d1117;\n --mero-bg-secondary: #161b22;\n --mero-bg-tertiary: #1c2128;\n --mero-text: #e6edf3;\n --mero-text-secondary: #8b949e;\n --mero-accent: #a5ff11;\n --mero-accent-hover: #8ed40d;\n --mero-on-primary: #0d1117;\n --mero-error: #ff6b6b;\n --mero-border: #30363d;\n --mero-disabled: #555555;\n --mero-shadow: rgba(0, 0, 0, 0.5);\n --mero-overlay: rgba(0, 0, 0, 0.75);\n --mero-radius: 8px;\n}\n.mero-connect-button {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n gap: 8px;\n padding: 10px 20px;\n background-color: var(--mero-accent);\n border: 1px solid var(--mero-accent);\n border-radius: var(--mero-radius);\n cursor: pointer;\n font-size: 14px;\n font-weight: 600;\n letter-spacing: 0.01em;\n color: var(--mero-on-primary);\n transition:\n background-color 0.15s ease,\n border-color 0.15s ease,\n box-shadow 0.15s ease,\n transform 0.1s ease;\n min-width: 140px;\n box-sizing: border-box;\n font-family:\n "Inter",\n -apple-system,\n BlinkMacSystemFont,\n "Segoe UI",\n Roboto,\n Oxygen,\n Ubuntu,\n sans-serif;\n -webkit-font-smoothing: antialiased;\n -moz-osx-font-smoothing: grayscale;\n line-height: 1;\n}\n.mero-connect-button:hover:not(.mero-connected):not(.mero-reconnecting) {\n background-color: var(--mero-accent-hover);\n border-color: var(--mero-accent-hover);\n box-shadow: 0 0 0 4px rgba(165, 255, 17, 0.18);\n box-shadow: 0 0 0 4px color-mix(in srgb, var(--mero-accent) 18%, transparent);\n}\n.mero-connect-button:active:not(.mero-connected):not(.mero-reconnecting) {\n transform: translateY(1px);\n}\n.mero-connect-button:focus-visible {\n outline: none;\n box-shadow: 0 0 0 3px rgba(165, 255, 17, 0.45);\n box-shadow: 0 0 0 3px color-mix(in srgb, var(--mero-accent) 45%, transparent);\n}\n.mero-connect-button.mero-logo-only {\n min-width: 0;\n width: 40px;\n height: 40px;\n padding: 0;\n gap: 0;\n}\n.mero-connect-button.mero-connected {\n background-color: var(--mero-accent);\n color: var(--mero-on-primary);\n border-color: var(--mero-accent);\n}\n.mero-connect-button.mero-connected:hover {\n background-color: var(--mero-accent-hover);\n border-color: var(--mero-accent-hover);\n}\n.mero-connect-button.mero-reconnecting {\n background-color: var(--mero-bg-secondary);\n color: var(--mero-text-secondary);\n border-color: var(--mero-border);\n cursor: not-allowed;\n}\n.mero-connect-container {\n position: relative;\n display: inline-block;\n}\n.mero-dropdown {\n position: absolute;\n top: 100%;\n left: 0;\n background-color: var(--mero-bg-secondary);\n border: 1px solid var(--mero-border);\n border-radius: var(--mero-radius);\n margin-top: 6px;\n padding: 0;\n z-index: 1001;\n width: 100%;\n min-width: 180px;\n overflow: hidden;\n box-shadow: 0 8px 24px var(--mero-shadow);\n}\n.mero-dropdown-info {\n padding: 10px 16px;\n color: var(--mero-text-secondary);\n font-size: 13px;\n border-bottom: 1px solid var(--mero-border);\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n max-width: 220px;\n}\n.mero-dropdown-item {\n display: block;\n width: 100%;\n padding: 10px 16px;\n background: none;\n border: none;\n color: var(--mero-text);\n text-align: left;\n cursor: pointer;\n font-size: 14px;\n text-decoration: none;\n font-family: inherit;\n}\n.mero-dropdown-item:hover {\n background-color: var(--mero-accent);\n color: var(--mero-on-primary);\n}\n.mero-logo {\n width: 24px;\n height: 24px;\n color: currentColor;\n}\n@keyframes meroFadeIn {\n from {\n opacity: 0;\n }\n to {\n opacity: 1;\n }\n}\n@keyframes meroSlideIn {\n from {\n transform: translateY(-12px);\n opacity: 0;\n }\n to {\n transform: translateY(0);\n opacity: 1;\n }\n}\n@keyframes meroSpin {\n to {\n transform: rotate(360deg);\n }\n}\n.mero-invite-overlay {\n position: fixed;\n inset: 0;\n z-index: 2147483646;\n display: flex;\n align-items: center;\n justify-content: center;\n padding: 16px;\n background: var(--mero-overlay);\n font-family:\n "Inter",\n -apple-system,\n BlinkMacSystemFont,\n "Segoe UI",\n Roboto,\n Oxygen,\n Ubuntu,\n sans-serif;\n -webkit-font-smoothing: antialiased;\n}\n.mero-invite-dialog {\n box-sizing: border-box;\n width: min(420px, 100%);\n padding: 24px;\n border: 1px solid var(--mero-border);\n border-radius: calc(var(--mero-radius) * 1.5);\n background: var(--mero-bg-secondary);\n color: var(--mero-text);\n box-shadow: 0 16px 48px var(--mero-shadow);\n outline: none;\n animation: mero-invite-in 0.16s ease-out;\n}\n.mero-invite-app {\n margin: 0 0 12px;\n font-size: 12px;\n font-weight: 600;\n letter-spacing: 0.06em;\n text-transform: uppercase;\n color: var(--mero-text-secondary);\n}\n.mero-invite-head {\n display: flex;\n align-items: center;\n gap: 12px;\n}\n.mero-invite-title {\n margin: 0;\n min-width: 0;\n font-size: 18px;\n font-weight: 600;\n line-height: 1.3;\n overflow-wrap: anywhere;\n}\n.mero-invite-body {\n margin: 12px 0 0;\n font-size: 14px;\n line-height: 1.5;\n color: var(--mero-text-secondary);\n}\n.mero-invite-body-error {\n color: var(--mero-error);\n}\n.mero-invite-icon {\n flex: none;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n width: 36px;\n height: 36px;\n border-radius: 50%;\n background: var(--mero-bg-tertiary);\n color: var(--mero-accent);\n}\n.mero-invite-icon-error {\n color: var(--mero-error);\n}\n.mero-invite-spinner {\n box-sizing: border-box;\n width: 36px;\n height: 36px;\n border: 3px solid var(--mero-bg-tertiary);\n border-top-color: var(--mero-accent);\n background: none;\n animation: mero-invite-spin 0.8s linear infinite;\n}\n.mero-invite-progress {\n position: relative;\n height: 3px;\n margin-top: 16px;\n overflow: hidden;\n border-radius: 2px;\n background: var(--mero-bg-tertiary);\n}\n.mero-invite-progress-bar {\n position: absolute;\n top: 0;\n bottom: 0;\n width: 40%;\n border-radius: 2px;\n background: var(--mero-accent);\n animation: mero-invite-progress 1.4s ease-in-out infinite;\n}\n.mero-invite-actions {\n display: flex;\n flex-wrap: wrap;\n justify-content: flex-end;\n gap: 8px;\n margin-top: 20px;\n}\n.mero-invite-actions:empty {\n display: none;\n}\n.mero-invite-button {\n padding: 9px 16px;\n border-radius: var(--mero-radius);\n font: inherit;\n font-size: 14px;\n font-weight: 600;\n line-height: 1.2;\n cursor: pointer;\n transition: background-color 0.15s ease, border-color 0.15s ease;\n}\n.mero-invite-button:focus-visible {\n outline: 2px solid var(--mero-accent);\n outline-offset: 2px;\n}\n.mero-invite-primary {\n border: 1px solid var(--mero-accent);\n background: var(--mero-accent);\n color: var(--mero-on-primary);\n}\n.mero-invite-primary:hover {\n border-color: var(--mero-accent-hover);\n background: var(--mero-accent-hover);\n}\n.mero-invite-secondary {\n border: 1px solid var(--mero-border);\n background: transparent;\n color: var(--mero-text);\n}\n.mero-invite-secondary:hover {\n background: var(--mero-bg-tertiary);\n}\n@keyframes mero-invite-spin {\n to {\n transform: rotate(360deg);\n }\n}\n@keyframes mero-invite-progress {\n from {\n left: -40%;\n }\n to {\n left: 100%;\n }\n}\n@keyframes mero-invite-in {\n from {\n opacity: 0;\n transform: translateY(6px) scale(0.98);\n }\n}\n@media (prefers-reduced-motion: reduce) {\n .mero-invite-dialog,\n .mero-invite-spinner,\n .mero-invite-progress-bar {\n animation: none;\n }\n}\n');
|
|
31
|
+
styleInject(':root {\n --mero-bg: #0d1117;\n --mero-bg-secondary: #161b22;\n --mero-bg-tertiary: #1c2128;\n --mero-text: #e6edf3;\n --mero-text-secondary: #8b949e;\n --mero-accent: #a5ff11;\n --mero-accent-hover: #8ed40d;\n --mero-on-primary: #0d1117;\n --mero-error: #ff6b6b;\n --mero-border: #30363d;\n --mero-disabled: #555555;\n --mero-shadow: rgba(0, 0, 0, 0.5);\n --mero-overlay: rgba(0, 0, 0, 0.75);\n --mero-radius: 8px;\n}\n.mero-connect-button {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n gap: 8px;\n padding: 10px 20px;\n background-color: var(--mero-accent);\n border: 1px solid var(--mero-accent);\n border-radius: var(--mero-radius);\n cursor: pointer;\n font-size: 14px;\n font-weight: 600;\n letter-spacing: 0.01em;\n color: var(--mero-on-primary);\n transition:\n background-color 0.15s ease,\n border-color 0.15s ease,\n box-shadow 0.15s ease,\n transform 0.1s ease;\n min-width: 140px;\n box-sizing: border-box;\n font-family:\n "Inter",\n -apple-system,\n BlinkMacSystemFont,\n "Segoe UI",\n Roboto,\n Oxygen,\n Ubuntu,\n sans-serif;\n -webkit-font-smoothing: antialiased;\n -moz-osx-font-smoothing: grayscale;\n line-height: 1;\n}\n.mero-connect-button:hover:not(.mero-connected):not(.mero-reconnecting) {\n background-color: var(--mero-accent-hover);\n border-color: var(--mero-accent-hover);\n box-shadow: 0 0 0 4px rgba(165, 255, 17, 0.18);\n box-shadow: 0 0 0 4px color-mix(in srgb, var(--mero-accent) 18%, transparent);\n}\n.mero-connect-button:active:not(.mero-connected):not(.mero-reconnecting) {\n transform: translateY(1px);\n}\n.mero-connect-button:focus-visible {\n outline: none;\n box-shadow: 0 0 0 3px rgba(165, 255, 17, 0.45);\n box-shadow: 0 0 0 3px color-mix(in srgb, var(--mero-accent) 45%, transparent);\n}\n.mero-connect-button.mero-logo-only {\n min-width: 0;\n width: 40px;\n height: 40px;\n padding: 0;\n gap: 0;\n}\n.mero-connect-button.mero-connected {\n background-color: var(--mero-accent);\n color: var(--mero-on-primary);\n border-color: var(--mero-accent);\n}\n.mero-connect-button.mero-connected:hover {\n background-color: var(--mero-accent-hover);\n border-color: var(--mero-accent-hover);\n}\n.mero-connect-button.mero-reconnecting {\n background-color: var(--mero-bg-secondary);\n color: var(--mero-text-secondary);\n border-color: var(--mero-border);\n cursor: not-allowed;\n}\n.mero-connect-container {\n position: relative;\n display: inline-block;\n}\n.mero-dropdown {\n position: absolute;\n top: 100%;\n left: 0;\n background-color: var(--mero-bg-secondary);\n border: 1px solid var(--mero-border);\n border-radius: var(--mero-radius);\n margin-top: 6px;\n padding: 0;\n z-index: 1001;\n width: 100%;\n min-width: 180px;\n overflow: hidden;\n box-shadow: 0 8px 24px var(--mero-shadow);\n}\n.mero-dropdown-info {\n padding: 10px 16px;\n color: var(--mero-text-secondary);\n font-size: 13px;\n border-bottom: 1px solid var(--mero-border);\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n max-width: 220px;\n}\n.mero-dropdown-item {\n display: block;\n width: 100%;\n padding: 10px 16px;\n background: none;\n border: none;\n color: var(--mero-text);\n text-align: left;\n cursor: pointer;\n font-size: 14px;\n text-decoration: none;\n font-family: inherit;\n}\n.mero-dropdown-item:hover {\n background-color: var(--mero-accent);\n color: var(--mero-on-primary);\n}\n.mero-logo {\n width: 24px;\n height: 24px;\n color: currentColor;\n}\n@keyframes meroFadeIn {\n from {\n opacity: 0;\n }\n to {\n opacity: 1;\n }\n}\n@keyframes meroSlideIn {\n from {\n transform: translateY(-12px);\n opacity: 0;\n }\n to {\n transform: translateY(0);\n opacity: 1;\n }\n}\n@keyframes meroSpin {\n to {\n transform: rotate(360deg);\n }\n}\n.mero-invite-overlay {\n position: fixed;\n inset: 0;\n z-index: 2147483646;\n display: flex;\n align-items: center;\n justify-content: center;\n padding: 16px;\n background: var(--mero-overlay);\n font-family:\n "Inter",\n -apple-system,\n BlinkMacSystemFont,\n "Segoe UI",\n Roboto,\n Oxygen,\n Ubuntu,\n sans-serif;\n -webkit-font-smoothing: antialiased;\n}\n.mero-invite-dialog {\n box-sizing: border-box;\n width: min(420px, 100%);\n padding: 24px;\n border: 1px solid var(--mero-border);\n border-radius: calc(var(--mero-radius) * 1.5);\n background: var(--mero-bg-secondary);\n color: var(--mero-text);\n box-shadow: 0 16px 48px var(--mero-shadow);\n outline: none;\n animation: mero-invite-in 0.16s ease-out;\n}\n.mero-invite-app {\n margin: 0 0 12px;\n font-size: 12px;\n font-weight: 600;\n letter-spacing: 0.06em;\n text-transform: uppercase;\n color: var(--mero-text-secondary);\n}\n.mero-invite-head {\n display: flex;\n align-items: center;\n gap: 12px;\n}\n.mero-invite-title {\n margin: 0;\n min-width: 0;\n font-size: 18px;\n font-weight: 600;\n line-height: 1.3;\n overflow-wrap: anywhere;\n}\n.mero-invite-body {\n margin: 12px 0 0;\n font-size: 14px;\n line-height: 1.5;\n color: var(--mero-text-secondary);\n}\n.mero-invite-body-error {\n color: var(--mero-error);\n}\n.mero-invite-icon {\n flex: none;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n width: 36px;\n height: 36px;\n border-radius: 50%;\n background: var(--mero-bg-tertiary);\n color: var(--mero-accent);\n}\n.mero-invite-icon-error {\n color: var(--mero-error);\n}\n.mero-invite-spinner {\n box-sizing: border-box;\n width: 36px;\n height: 36px;\n border: 3px solid var(--mero-bg-tertiary);\n border-top-color: var(--mero-accent);\n background: none;\n animation: mero-invite-spin 0.8s linear infinite;\n}\n.mero-invite-progress {\n position: relative;\n height: 3px;\n margin-top: 16px;\n overflow: hidden;\n border-radius: 2px;\n background: var(--mero-bg-tertiary);\n}\n.mero-invite-progress-bar {\n position: absolute;\n top: 0;\n bottom: 0;\n width: 40%;\n border-radius: 2px;\n background: var(--mero-accent);\n animation: mero-invite-progress 1.4s ease-in-out infinite;\n}\n.mero-invite-actions {\n display: flex;\n flex-wrap: wrap;\n justify-content: flex-end;\n gap: 8px;\n margin-top: 20px;\n}\n.mero-invite-actions:empty {\n display: none;\n}\n.mero-invite-button {\n padding: 9px 16px;\n border-radius: var(--mero-radius);\n font: inherit;\n font-size: 14px;\n font-weight: 600;\n line-height: 1.2;\n cursor: pointer;\n transition: background-color 0.15s ease, border-color 0.15s ease;\n}\n.mero-invite-button:focus-visible {\n outline: 2px solid var(--mero-accent);\n outline-offset: 2px;\n}\n.mero-invite-primary {\n border: 1px solid var(--mero-accent);\n background: var(--mero-accent);\n color: var(--mero-on-primary);\n}\n.mero-invite-primary:hover {\n border-color: var(--mero-accent-hover);\n background: var(--mero-accent-hover);\n}\n.mero-invite-secondary {\n border: 1px solid var(--mero-border);\n background: transparent;\n color: var(--mero-text);\n}\n.mero-invite-secondary:hover {\n background: var(--mero-bg-tertiary);\n}\n.mero-invite-landing {\n position: fixed;\n inset: 0;\n z-index: 9999;\n display: flex;\n align-items: center;\n justify-content: center;\n padding: 16px;\n overflow-y: auto;\n background: var(--mero-bg);\n color: var(--mero-text);\n font-family:\n "Inter",\n -apple-system,\n BlinkMacSystemFont,\n "Segoe UI",\n Roboto,\n Oxygen,\n Ubuntu,\n sans-serif;\n -webkit-font-smoothing: antialiased;\n}\n.mero-invite-landing-card {\n width: min(460px, 100%);\n}\n.mero-invite-landing-card .mero-invite-title {\n font-size: 22px;\n}\n.mero-invite-landing-login {\n display: inline-flex;\n}\n.mero-invite-landing-login .mero-connect-button {\n min-width: 0;\n padding: 9px 16px;\n line-height: 1.2;\n}\n@keyframes mero-invite-spin {\n to {\n transform: rotate(360deg);\n }\n}\n@keyframes mero-invite-progress {\n from {\n left: -40%;\n }\n to {\n left: 100%;\n }\n}\n@keyframes mero-invite-in {\n from {\n opacity: 0;\n transform: translateY(6px) scale(0.98);\n }\n}\n@media (prefers-reduced-motion: reduce) {\n .mero-invite-dialog,\n .mero-invite-spinner,\n .mero-invite-progress-bar {\n animation: none;\n }\n}\n');
|
|
32
32
|
|
|
33
33
|
// src/types.ts
|
|
34
34
|
var AppMode = /* @__PURE__ */ ((AppMode2) => {
|
|
@@ -4051,6 +4051,10 @@ function buildInviteLink(slug, token, extra = {}) {
|
|
|
4051
4051
|
}
|
|
4052
4052
|
return createLink(slug, JOIN_ACTION, params);
|
|
4053
4053
|
}
|
|
4054
|
+
var watchers = /* @__PURE__ */ new Set();
|
|
4055
|
+
function notifyWatchers() {
|
|
4056
|
+
for (const watcher of watchers) watcher();
|
|
4057
|
+
}
|
|
4054
4058
|
var MAX_AUTO_JOIN_ATTEMPTS = 3;
|
|
4055
4059
|
var listeners = /* @__PURE__ */ new Set();
|
|
4056
4060
|
var buffered = null;
|
|
@@ -4136,6 +4140,7 @@ function urlWithoutInvitation(href) {
|
|
|
4136
4140
|
}
|
|
4137
4141
|
function deliver(invitation) {
|
|
4138
4142
|
current = invitation;
|
|
4143
|
+
notifyWatchers();
|
|
4139
4144
|
if (listeners.size === 0) {
|
|
4140
4145
|
buffered = invitation;
|
|
4141
4146
|
return;
|
|
@@ -4174,8 +4179,12 @@ function ensureController() {
|
|
|
4174
4179
|
params: { ...intent.params, [INVITATION_PARAM]: token },
|
|
4175
4180
|
resolve: () => {
|
|
4176
4181
|
forgetAttempts(token);
|
|
4177
|
-
if (
|
|
4182
|
+
if (buffered?.token === token) buffered = null;
|
|
4178
4183
|
intent.resolve();
|
|
4184
|
+
if (current?.token === token) {
|
|
4185
|
+
current = null;
|
|
4186
|
+
notifyWatchers();
|
|
4187
|
+
}
|
|
4179
4188
|
},
|
|
4180
4189
|
autoJoin: spendAttempt(token)
|
|
4181
4190
|
});
|
|
@@ -4203,6 +4212,13 @@ function peekInvitation() {
|
|
|
4203
4212
|
ensureController();
|
|
4204
4213
|
return current;
|
|
4205
4214
|
}
|
|
4215
|
+
function subscribeInvitation(watcher) {
|
|
4216
|
+
ensureController();
|
|
4217
|
+
watchers.add(watcher);
|
|
4218
|
+
return () => {
|
|
4219
|
+
watchers.delete(watcher);
|
|
4220
|
+
};
|
|
4221
|
+
}
|
|
4206
4222
|
function resetInvitationCaptureForTests() {
|
|
4207
4223
|
controller?.dispose();
|
|
4208
4224
|
controller = null;
|
|
@@ -4211,6 +4227,7 @@ function resetInvitationCaptureForTests() {
|
|
|
4211
4227
|
current = null;
|
|
4212
4228
|
attemptsKey = "calimero:invitation-attempts";
|
|
4213
4229
|
ownSlugs = /* @__PURE__ */ new Set();
|
|
4230
|
+
notifyWatchers();
|
|
4214
4231
|
}
|
|
4215
4232
|
|
|
4216
4233
|
// src/invitations/describeInviteFailure.ts
|
|
@@ -4504,24 +4521,33 @@ function InvitationDialog({
|
|
|
4504
4521
|
}) {
|
|
4505
4522
|
const { state, accept, decline, retry, dismiss } = redemption;
|
|
4506
4523
|
const joinedId = state.stage === "joined" ? state.namespaceId : null;
|
|
4507
|
-
const
|
|
4524
|
+
const [backgroundId, setBackgroundId] = react.useState(null);
|
|
4525
|
+
react.useEffect(() => {
|
|
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]);
|
|
4508
4534
|
react.useEffect(() => {
|
|
4509
|
-
if (
|
|
4510
|
-
}, [
|
|
4535
|
+
if (waitingId && flagged && synced) clearNamespaceJustJoined(waitingId);
|
|
4536
|
+
}, [waitingId, flagged, synced]);
|
|
4511
4537
|
const [slow, setSlow] = react.useState(false);
|
|
4512
4538
|
react.useEffect(() => {
|
|
4513
4539
|
setSlow(false);
|
|
4514
|
-
if (!
|
|
4540
|
+
if (!waitingId || !flagged) return;
|
|
4515
4541
|
const slowTimer = setTimeout(() => setSlow(true), JOIN_SYNC_WATCHDOG_MS);
|
|
4516
4542
|
const ceiling = setTimeout(
|
|
4517
|
-
() => clearNamespaceJustJoined(
|
|
4543
|
+
() => clearNamespaceJustJoined(waitingId),
|
|
4518
4544
|
JOIN_SYNC_MAX_MS
|
|
4519
4545
|
);
|
|
4520
4546
|
return () => {
|
|
4521
4547
|
clearTimeout(slowTimer);
|
|
4522
4548
|
clearTimeout(ceiling);
|
|
4523
4549
|
};
|
|
4524
|
-
}, [
|
|
4550
|
+
}, [waitingId, flagged]);
|
|
4525
4551
|
const stage = state.stage === "idle" ? null : state.stage === "joined" ? stillSyncing ? "syncing" : "ready" : state.stage;
|
|
4526
4552
|
react.useEffect(() => {
|
|
4527
4553
|
if (stage !== "ready") return;
|
|
@@ -4530,15 +4556,37 @@ function InvitationDialog({
|
|
|
4530
4556
|
}, [stage, dismiss]);
|
|
4531
4557
|
const titleId = react.useId();
|
|
4532
4558
|
const bodyId = react.useId();
|
|
4559
|
+
const overlayRef = react.useRef(null);
|
|
4533
4560
|
const dialogRef = react.useRef(null);
|
|
4534
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]);
|
|
4535
4583
|
react.useEffect(() => {
|
|
4536
4584
|
if (!stage) return;
|
|
4537
4585
|
(primaryRef.current ?? dialogRef.current)?.focus();
|
|
4538
4586
|
}, [stage]);
|
|
4539
4587
|
const close = react.useCallback(() => {
|
|
4540
4588
|
if (stage === "awaiting-confirmation") decline();
|
|
4541
|
-
else if (stage && stage !== "joining") dismiss();
|
|
4589
|
+
else if (stage && stage !== "joining" && stage !== "syncing") dismiss();
|
|
4542
4590
|
}, [stage, decline, dismiss]);
|
|
4543
4591
|
const onKeyDown = (event) => {
|
|
4544
4592
|
if (event.key === "Escape") {
|
|
@@ -4595,9 +4643,12 @@ function InvitationDialog({
|
|
|
4595
4643
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4596
4644
|
"div",
|
|
4597
4645
|
{
|
|
4646
|
+
ref: overlayRef,
|
|
4598
4647
|
className: "mero-invite-overlay",
|
|
4599
4648
|
onMouseDown: (event) => {
|
|
4600
|
-
if (event.target
|
|
4649
|
+
if (event.target !== event.currentTarget) return;
|
|
4650
|
+
event.preventDefault();
|
|
4651
|
+
close();
|
|
4601
4652
|
},
|
|
4602
4653
|
children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
4603
4654
|
"div",
|
|
@@ -4654,7 +4705,7 @@ function InvitationDialog({
|
|
|
4654
4705
|
}
|
|
4655
4706
|
)
|
|
4656
4707
|
] }) : null,
|
|
4657
|
-
stage === "syncing" ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
4708
|
+
stage === "syncing" && slow ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
4658
4709
|
"button",
|
|
4659
4710
|
{
|
|
4660
4711
|
ref: primaryRef,
|
|
@@ -4824,6 +4875,165 @@ function Spinner() {
|
|
|
4824
4875
|
}
|
|
4825
4876
|
);
|
|
4826
4877
|
}
|
|
4878
|
+
function usePendingInvitation() {
|
|
4879
|
+
return react.useSyncExternalStore(subscribeInvitation, peekInvitation, () => null);
|
|
4880
|
+
}
|
|
4881
|
+
function InvitationGate({
|
|
4882
|
+
children,
|
|
4883
|
+
parse,
|
|
4884
|
+
noun = "team",
|
|
4885
|
+
appName,
|
|
4886
|
+
detail,
|
|
4887
|
+
connectButtonProps
|
|
4888
|
+
}) {
|
|
4889
|
+
const session = react.useContext(MeroContext);
|
|
4890
|
+
const pending = usePendingInvitation();
|
|
4891
|
+
const parsed = react.useMemo(() => {
|
|
4892
|
+
if (!pending || !parse) return null;
|
|
4893
|
+
try {
|
|
4894
|
+
const result = parse(pending.token, pending.params);
|
|
4895
|
+
return result?.namespaceId ? result : void 0;
|
|
4896
|
+
} catch {
|
|
4897
|
+
return void 0;
|
|
4898
|
+
}
|
|
4899
|
+
}, [pending, parse]);
|
|
4900
|
+
const state = !pending || !session || session.isAuthenticated ? null : session.isLoading ? "checking" : parsed === void 0 ? "invalid" : "invited";
|
|
4901
|
+
if (!state) return children === void 0 ? null : /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children });
|
|
4902
|
+
const page = /* @__PURE__ */ jsxRuntime.jsx(
|
|
4903
|
+
InvitationScreen,
|
|
4904
|
+
{
|
|
4905
|
+
state,
|
|
4906
|
+
teamName: parsed?.teamName,
|
|
4907
|
+
noun,
|
|
4908
|
+
appName,
|
|
4909
|
+
detail,
|
|
4910
|
+
connectButtonProps,
|
|
4911
|
+
onDecline: () => pending?.resolve()
|
|
4912
|
+
}
|
|
4913
|
+
);
|
|
4914
|
+
if (children !== void 0 || typeof document === "undefined") return page;
|
|
4915
|
+
return reactDom.createPortal(page, document.body);
|
|
4916
|
+
}
|
|
4917
|
+
function InvitationScreen({
|
|
4918
|
+
state,
|
|
4919
|
+
teamName,
|
|
4920
|
+
noun,
|
|
4921
|
+
appName,
|
|
4922
|
+
detail,
|
|
4923
|
+
connectButtonProps,
|
|
4924
|
+
onDecline
|
|
4925
|
+
}) {
|
|
4926
|
+
const titleId = react.useId();
|
|
4927
|
+
const bodyId = react.useId();
|
|
4928
|
+
const cardRef = react.useRef(null);
|
|
4929
|
+
const loginRef = react.useRef(null);
|
|
4930
|
+
const continueRef = react.useRef(null);
|
|
4931
|
+
react.useEffect(() => {
|
|
4932
|
+
if (state === "checking") return;
|
|
4933
|
+
const target = state === "invited" ? loginRef.current?.querySelector("button") : continueRef.current;
|
|
4934
|
+
(target ?? cardRef.current)?.focus();
|
|
4935
|
+
}, [state]);
|
|
4936
|
+
const onKeyDown = (event) => {
|
|
4937
|
+
if (event.key !== "Tab" || !cardRef.current) return;
|
|
4938
|
+
const focusable = cardRef.current.querySelectorAll(
|
|
4939
|
+
'button:not([disabled]), [href], [tabindex]:not([tabindex="-1"])'
|
|
4940
|
+
);
|
|
4941
|
+
if (focusable.length === 0) return;
|
|
4942
|
+
const first = focusable[0];
|
|
4943
|
+
const last = focusable[focusable.length - 1];
|
|
4944
|
+
if (event.shiftKey && document.activeElement === first) {
|
|
4945
|
+
event.preventDefault();
|
|
4946
|
+
last.focus();
|
|
4947
|
+
} else if (!event.shiftKey && document.activeElement === last) {
|
|
4948
|
+
event.preventDefault();
|
|
4949
|
+
first.focus();
|
|
4950
|
+
}
|
|
4951
|
+
};
|
|
4952
|
+
if (state === "checking") {
|
|
4953
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
4954
|
+
"div",
|
|
4955
|
+
{
|
|
4956
|
+
className: "mero-invite-landing",
|
|
4957
|
+
role: "status",
|
|
4958
|
+
"aria-busy": "true",
|
|
4959
|
+
"aria-label": "Checking your session",
|
|
4960
|
+
"data-testid": "invite-landing",
|
|
4961
|
+
"data-state": "checking",
|
|
4962
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "mero-invite-icon mero-invite-spinner", "aria-hidden": "true" })
|
|
4963
|
+
}
|
|
4964
|
+
);
|
|
4965
|
+
}
|
|
4966
|
+
const invalid = state === "invalid";
|
|
4967
|
+
const title = invalid ? "This invitation can't be read" : teamName ? `You're invited to join \u201C${teamName}\u201D` : `You're invited to join a ${noun}`;
|
|
4968
|
+
const where = appName ? ` in ${appName}` : "";
|
|
4969
|
+
const body = invalid ? "The link may have been cut short when it was shared. Ask whoever sent it for a new one." : `Someone sent you a link to join this ${noun}${where}. Log in to accept it; you'll be asked to confirm before you join.`;
|
|
4970
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mero-invite-landing", children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
4971
|
+
"div",
|
|
4972
|
+
{
|
|
4973
|
+
ref: cardRef,
|
|
4974
|
+
className: "mero-invite-dialog mero-invite-landing-card",
|
|
4975
|
+
role: "dialog",
|
|
4976
|
+
"aria-modal": "true",
|
|
4977
|
+
"aria-labelledby": titleId,
|
|
4978
|
+
"aria-describedby": bodyId,
|
|
4979
|
+
tabIndex: -1,
|
|
4980
|
+
"data-testid": "invite-landing",
|
|
4981
|
+
"data-state": state,
|
|
4982
|
+
onKeyDown,
|
|
4983
|
+
children: [
|
|
4984
|
+
appName ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mero-invite-app", children: appName }) : null,
|
|
4985
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mero-invite-head", children: [
|
|
4986
|
+
/* @__PURE__ */ jsxRuntime.jsx(InviteIcon2, { error: invalid }),
|
|
4987
|
+
/* @__PURE__ */ jsxRuntime.jsx("h1", { id: titleId, className: "mero-invite-title", children: title })
|
|
4988
|
+
] }),
|
|
4989
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { id: bodyId, className: "mero-invite-body", children: body }),
|
|
4990
|
+
detail && !invalid ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mero-invite-body", children: detail }) : null,
|
|
4991
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "mero-invite-actions", children: invalid ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
4992
|
+
"button",
|
|
4993
|
+
{
|
|
4994
|
+
ref: continueRef,
|
|
4995
|
+
type: "button",
|
|
4996
|
+
className: "mero-invite-button mero-invite-primary",
|
|
4997
|
+
onClick: onDecline,
|
|
4998
|
+
"data-testid": "invite-landing-decline",
|
|
4999
|
+
children: "Continue"
|
|
5000
|
+
}
|
|
5001
|
+
) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
5002
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
5003
|
+
"button",
|
|
5004
|
+
{
|
|
5005
|
+
type: "button",
|
|
5006
|
+
className: "mero-invite-button mero-invite-secondary",
|
|
5007
|
+
onClick: onDecline,
|
|
5008
|
+
"data-testid": "invite-landing-decline",
|
|
5009
|
+
children: "Not now"
|
|
5010
|
+
}
|
|
5011
|
+
),
|
|
5012
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
5013
|
+
"div",
|
|
5014
|
+
{
|
|
5015
|
+
ref: loginRef,
|
|
5016
|
+
className: "mero-invite-landing-login",
|
|
5017
|
+
"data-testid": "invite-landing-login",
|
|
5018
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(ConnectButton, { ...connectButtonProps, label: "Log in to join" })
|
|
5019
|
+
}
|
|
5020
|
+
)
|
|
5021
|
+
] }) })
|
|
5022
|
+
]
|
|
5023
|
+
}
|
|
5024
|
+
) });
|
|
5025
|
+
}
|
|
5026
|
+
function InviteIcon2({ error }) {
|
|
5027
|
+
const path = error ? "M12 7v6m0 4h.01" : "M4 7l8 6 8-6M5 6h14a1 1 0 011 1v10a1 1 0 01-1 1H5a1 1 0 01-1-1V7a1 1 0 011-1z";
|
|
5028
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
5029
|
+
"span",
|
|
5030
|
+
{
|
|
5031
|
+
className: error ? "mero-invite-icon mero-invite-icon-error" : "mero-invite-icon",
|
|
5032
|
+
"aria-hidden": "true",
|
|
5033
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("svg", { viewBox: "0 0 24 24", width: "18", height: "18", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: path }) })
|
|
5034
|
+
}
|
|
5035
|
+
);
|
|
5036
|
+
}
|
|
4827
5037
|
function statusOf(err) {
|
|
4828
5038
|
if (!err || typeof err !== "object") return void 0;
|
|
4829
5039
|
const e = err;
|
|
@@ -5076,6 +5286,7 @@ exports.DEFAULT_MIGRATION_POLL_INTERVAL_MS = DEFAULT_MIGRATION_POLL_INTERVAL_MS;
|
|
|
5076
5286
|
exports.INVITATION_PARAM = INVITATION_PARAM;
|
|
5077
5287
|
exports.INVITATION_READY_MS = INVITATION_READY_MS;
|
|
5078
5288
|
exports.InvitationDialog = InvitationDialog;
|
|
5289
|
+
exports.InvitationGate = InvitationGate;
|
|
5079
5290
|
exports.JOIN_ACTION = JOIN_ACTION;
|
|
5080
5291
|
exports.JOIN_SYNC_MAX_MS = JOIN_SYNC_MAX_MS;
|
|
5081
5292
|
exports.JOIN_SYNC_POLL_MS = JOIN_SYNC_POLL_MS;
|
|
@@ -5122,6 +5333,7 @@ exports.setContextId = setContextId;
|
|
|
5122
5333
|
exports.setContextIdentity = setContextIdentity;
|
|
5123
5334
|
exports.setNodeUrl = setNodeUrl;
|
|
5124
5335
|
exports.setTokenNodeUrl = setTokenNodeUrl;
|
|
5336
|
+
exports.subscribeInvitation = subscribeInvitation;
|
|
5125
5337
|
exports.subscribeJustJoined = subscribeJustJoined;
|
|
5126
5338
|
exports.themeToCssVars = themeToCssVars;
|
|
5127
5339
|
exports.urlWithoutInvitation = urlWithoutInvitation;
|
|
@@ -5175,6 +5387,7 @@ exports.useNamespaceIdentity = useNamespaceIdentity;
|
|
|
5175
5387
|
exports.useNamespaces = useNamespaces;
|
|
5176
5388
|
exports.useNamespacesForApplication = useNamespacesForApplication;
|
|
5177
5389
|
exports.useNodeIdentity = useNodeIdentity;
|
|
5390
|
+
exports.usePendingInvitation = usePendingInvitation;
|
|
5178
5391
|
exports.useRedeemInvitation = useRedeemInvitation;
|
|
5179
5392
|
exports.useRemoveGroupMembers = useRemoveGroupMembers;
|
|
5180
5393
|
exports.useReparentGroup = useReparentGroup;
|