@calimero-network/mero-react 9.15.0 → 9.16.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 +10 -1
- package/dist/index.cjs +181 -2
- 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 +179 -3
- 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,6 +303,8 @@ 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
|
|
|
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
|
+
|
|
299
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).
|
|
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:
|
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
|
|
@@ -4824,6 +4841,165 @@ function Spinner() {
|
|
|
4824
4841
|
}
|
|
4825
4842
|
);
|
|
4826
4843
|
}
|
|
4844
|
+
function usePendingInvitation() {
|
|
4845
|
+
return react.useSyncExternalStore(subscribeInvitation, peekInvitation, () => null);
|
|
4846
|
+
}
|
|
4847
|
+
function InvitationGate({
|
|
4848
|
+
children,
|
|
4849
|
+
parse,
|
|
4850
|
+
noun = "team",
|
|
4851
|
+
appName,
|
|
4852
|
+
detail,
|
|
4853
|
+
connectButtonProps
|
|
4854
|
+
}) {
|
|
4855
|
+
const session = react.useContext(MeroContext);
|
|
4856
|
+
const pending = usePendingInvitation();
|
|
4857
|
+
const parsed = react.useMemo(() => {
|
|
4858
|
+
if (!pending || !parse) return null;
|
|
4859
|
+
try {
|
|
4860
|
+
const result = parse(pending.token, pending.params);
|
|
4861
|
+
return result?.namespaceId ? result : void 0;
|
|
4862
|
+
} catch {
|
|
4863
|
+
return void 0;
|
|
4864
|
+
}
|
|
4865
|
+
}, [pending, parse]);
|
|
4866
|
+
const state = !pending || !session || session.isAuthenticated ? null : session.isLoading ? "checking" : parsed === void 0 ? "invalid" : "invited";
|
|
4867
|
+
if (!state) return children === void 0 ? null : /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children });
|
|
4868
|
+
const page = /* @__PURE__ */ jsxRuntime.jsx(
|
|
4869
|
+
InvitationScreen,
|
|
4870
|
+
{
|
|
4871
|
+
state,
|
|
4872
|
+
teamName: parsed?.teamName,
|
|
4873
|
+
noun,
|
|
4874
|
+
appName,
|
|
4875
|
+
detail,
|
|
4876
|
+
connectButtonProps,
|
|
4877
|
+
onDecline: () => pending?.resolve()
|
|
4878
|
+
}
|
|
4879
|
+
);
|
|
4880
|
+
if (children !== void 0 || typeof document === "undefined") return page;
|
|
4881
|
+
return reactDom.createPortal(page, document.body);
|
|
4882
|
+
}
|
|
4883
|
+
function InvitationScreen({
|
|
4884
|
+
state,
|
|
4885
|
+
teamName,
|
|
4886
|
+
noun,
|
|
4887
|
+
appName,
|
|
4888
|
+
detail,
|
|
4889
|
+
connectButtonProps,
|
|
4890
|
+
onDecline
|
|
4891
|
+
}) {
|
|
4892
|
+
const titleId = react.useId();
|
|
4893
|
+
const bodyId = react.useId();
|
|
4894
|
+
const cardRef = react.useRef(null);
|
|
4895
|
+
const loginRef = react.useRef(null);
|
|
4896
|
+
const continueRef = react.useRef(null);
|
|
4897
|
+
react.useEffect(() => {
|
|
4898
|
+
if (state === "checking") return;
|
|
4899
|
+
const target = state === "invited" ? loginRef.current?.querySelector("button") : continueRef.current;
|
|
4900
|
+
(target ?? cardRef.current)?.focus();
|
|
4901
|
+
}, [state]);
|
|
4902
|
+
const onKeyDown = (event) => {
|
|
4903
|
+
if (event.key !== "Tab" || !cardRef.current) return;
|
|
4904
|
+
const focusable = cardRef.current.querySelectorAll(
|
|
4905
|
+
'button:not([disabled]), [href], [tabindex]:not([tabindex="-1"])'
|
|
4906
|
+
);
|
|
4907
|
+
if (focusable.length === 0) return;
|
|
4908
|
+
const first = focusable[0];
|
|
4909
|
+
const last = focusable[focusable.length - 1];
|
|
4910
|
+
if (event.shiftKey && document.activeElement === first) {
|
|
4911
|
+
event.preventDefault();
|
|
4912
|
+
last.focus();
|
|
4913
|
+
} else if (!event.shiftKey && document.activeElement === last) {
|
|
4914
|
+
event.preventDefault();
|
|
4915
|
+
first.focus();
|
|
4916
|
+
}
|
|
4917
|
+
};
|
|
4918
|
+
if (state === "checking") {
|
|
4919
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
4920
|
+
"div",
|
|
4921
|
+
{
|
|
4922
|
+
className: "mero-invite-landing",
|
|
4923
|
+
role: "status",
|
|
4924
|
+
"aria-busy": "true",
|
|
4925
|
+
"aria-label": "Checking your session",
|
|
4926
|
+
"data-testid": "invite-landing",
|
|
4927
|
+
"data-state": "checking",
|
|
4928
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "mero-invite-icon mero-invite-spinner", "aria-hidden": "true" })
|
|
4929
|
+
}
|
|
4930
|
+
);
|
|
4931
|
+
}
|
|
4932
|
+
const invalid = state === "invalid";
|
|
4933
|
+
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}`;
|
|
4934
|
+
const where = appName ? ` in ${appName}` : "";
|
|
4935
|
+
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.`;
|
|
4936
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mero-invite-landing", children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
4937
|
+
"div",
|
|
4938
|
+
{
|
|
4939
|
+
ref: cardRef,
|
|
4940
|
+
className: "mero-invite-dialog mero-invite-landing-card",
|
|
4941
|
+
role: "dialog",
|
|
4942
|
+
"aria-modal": "true",
|
|
4943
|
+
"aria-labelledby": titleId,
|
|
4944
|
+
"aria-describedby": bodyId,
|
|
4945
|
+
tabIndex: -1,
|
|
4946
|
+
"data-testid": "invite-landing",
|
|
4947
|
+
"data-state": state,
|
|
4948
|
+
onKeyDown,
|
|
4949
|
+
children: [
|
|
4950
|
+
appName ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mero-invite-app", children: appName }) : null,
|
|
4951
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mero-invite-head", children: [
|
|
4952
|
+
/* @__PURE__ */ jsxRuntime.jsx(InviteIcon2, { error: invalid }),
|
|
4953
|
+
/* @__PURE__ */ jsxRuntime.jsx("h1", { id: titleId, className: "mero-invite-title", children: title })
|
|
4954
|
+
] }),
|
|
4955
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { id: bodyId, className: "mero-invite-body", children: body }),
|
|
4956
|
+
detail && !invalid ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mero-invite-body", children: detail }) : null,
|
|
4957
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "mero-invite-actions", children: invalid ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
4958
|
+
"button",
|
|
4959
|
+
{
|
|
4960
|
+
ref: continueRef,
|
|
4961
|
+
type: "button",
|
|
4962
|
+
className: "mero-invite-button mero-invite-primary",
|
|
4963
|
+
onClick: onDecline,
|
|
4964
|
+
"data-testid": "invite-landing-decline",
|
|
4965
|
+
children: "Continue"
|
|
4966
|
+
}
|
|
4967
|
+
) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
4968
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4969
|
+
"button",
|
|
4970
|
+
{
|
|
4971
|
+
type: "button",
|
|
4972
|
+
className: "mero-invite-button mero-invite-secondary",
|
|
4973
|
+
onClick: onDecline,
|
|
4974
|
+
"data-testid": "invite-landing-decline",
|
|
4975
|
+
children: "Not now"
|
|
4976
|
+
}
|
|
4977
|
+
),
|
|
4978
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4979
|
+
"div",
|
|
4980
|
+
{
|
|
4981
|
+
ref: loginRef,
|
|
4982
|
+
className: "mero-invite-landing-login",
|
|
4983
|
+
"data-testid": "invite-landing-login",
|
|
4984
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(ConnectButton, { ...connectButtonProps, label: "Log in to join" })
|
|
4985
|
+
}
|
|
4986
|
+
)
|
|
4987
|
+
] }) })
|
|
4988
|
+
]
|
|
4989
|
+
}
|
|
4990
|
+
) });
|
|
4991
|
+
}
|
|
4992
|
+
function InviteIcon2({ error }) {
|
|
4993
|
+
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";
|
|
4994
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
4995
|
+
"span",
|
|
4996
|
+
{
|
|
4997
|
+
className: error ? "mero-invite-icon mero-invite-icon-error" : "mero-invite-icon",
|
|
4998
|
+
"aria-hidden": "true",
|
|
4999
|
+
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 }) })
|
|
5000
|
+
}
|
|
5001
|
+
);
|
|
5002
|
+
}
|
|
4827
5003
|
function statusOf(err) {
|
|
4828
5004
|
if (!err || typeof err !== "object") return void 0;
|
|
4829
5005
|
const e = err;
|
|
@@ -5076,6 +5252,7 @@ exports.DEFAULT_MIGRATION_POLL_INTERVAL_MS = DEFAULT_MIGRATION_POLL_INTERVAL_MS;
|
|
|
5076
5252
|
exports.INVITATION_PARAM = INVITATION_PARAM;
|
|
5077
5253
|
exports.INVITATION_READY_MS = INVITATION_READY_MS;
|
|
5078
5254
|
exports.InvitationDialog = InvitationDialog;
|
|
5255
|
+
exports.InvitationGate = InvitationGate;
|
|
5079
5256
|
exports.JOIN_ACTION = JOIN_ACTION;
|
|
5080
5257
|
exports.JOIN_SYNC_MAX_MS = JOIN_SYNC_MAX_MS;
|
|
5081
5258
|
exports.JOIN_SYNC_POLL_MS = JOIN_SYNC_POLL_MS;
|
|
@@ -5122,6 +5299,7 @@ exports.setContextId = setContextId;
|
|
|
5122
5299
|
exports.setContextIdentity = setContextIdentity;
|
|
5123
5300
|
exports.setNodeUrl = setNodeUrl;
|
|
5124
5301
|
exports.setTokenNodeUrl = setTokenNodeUrl;
|
|
5302
|
+
exports.subscribeInvitation = subscribeInvitation;
|
|
5125
5303
|
exports.subscribeJustJoined = subscribeJustJoined;
|
|
5126
5304
|
exports.themeToCssVars = themeToCssVars;
|
|
5127
5305
|
exports.urlWithoutInvitation = urlWithoutInvitation;
|
|
@@ -5175,6 +5353,7 @@ exports.useNamespaceIdentity = useNamespaceIdentity;
|
|
|
5175
5353
|
exports.useNamespaces = useNamespaces;
|
|
5176
5354
|
exports.useNamespacesForApplication = useNamespacesForApplication;
|
|
5177
5355
|
exports.useNodeIdentity = useNodeIdentity;
|
|
5356
|
+
exports.usePendingInvitation = usePendingInvitation;
|
|
5178
5357
|
exports.useRedeemInvitation = useRedeemInvitation;
|
|
5179
5358
|
exports.useRemoveGroupMembers = useRemoveGroupMembers;
|
|
5180
5359
|
exports.useReparentGroup = useReparentGroup;
|