@clerk/react 6.9.0 → 6.9.1-canary.v20260610190754

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.
Files changed (75) hide show
  1. package/dist/ClerkProvider-9lxHp9j5.cjs +1623 -0
  2. package/dist/ClerkProvider-9lxHp9j5.cjs.map +1 -0
  3. package/dist/ClerkProvider-LQpPtmNL.mjs +1533 -0
  4. package/dist/ClerkProvider-LQpPtmNL.mjs.map +1 -0
  5. package/dist/errors.cjs +69 -0
  6. package/dist/errors.d.cts +2 -0
  7. package/dist/errors.d.mts +2 -1
  8. package/dist/errors.mjs +2 -29
  9. package/dist/experimental.cjs +270 -0
  10. package/dist/experimental.cjs.map +1 -0
  11. package/dist/{experimental.d.ts → experimental.d.cts} +18 -18
  12. package/dist/experimental.d.mts +18 -18
  13. package/dist/experimental.mjs +201 -165
  14. package/dist/experimental.mjs.map +1 -1
  15. package/dist/hooks-BiY5Zgpp.mjs +1369 -0
  16. package/dist/hooks-BiY5Zgpp.mjs.map +1 -0
  17. package/dist/hooks-CBghYU21.cjs +1606 -0
  18. package/dist/hooks-CBghYU21.cjs.map +1 -0
  19. package/dist/index.cjs +447 -0
  20. package/dist/index.cjs.map +1 -0
  21. package/dist/index.d.cts +345 -0
  22. package/dist/index.d.mts +183 -157
  23. package/dist/index.mjs +285 -380
  24. package/dist/index.mjs.map +1 -1
  25. package/dist/internal.cjs +107 -0
  26. package/dist/internal.cjs.map +1 -0
  27. package/dist/internal.d.cts +51 -0
  28. package/dist/internal.d.mts +24 -26
  29. package/dist/internal.mjs +39 -73
  30. package/dist/internal.mjs.map +1 -1
  31. package/dist/legacy.cjs +134 -0
  32. package/dist/legacy.cjs.map +1 -0
  33. package/dist/{legacy.d.ts → legacy.d.cts} +6 -3
  34. package/dist/legacy.d.mts +6 -3
  35. package/dist/legacy.mjs +126 -42
  36. package/dist/legacy.mjs.map +1 -1
  37. package/dist/types-Bwenmt7y.d.cts +10951 -0
  38. package/dist/types-CiIhevkA.d.mts +10951 -0
  39. package/dist/types.cjs +0 -0
  40. package/dist/types.d.cts +3 -0
  41. package/dist/types.d.mts +3 -109
  42. package/dist/types.mjs +1 -2
  43. package/dist/useAssertWrappedByClerkProvider-Cm0djUcB.cjs +52 -0
  44. package/dist/useAssertWrappedByClerkProvider-Cm0djUcB.cjs.map +1 -0
  45. package/dist/useAssertWrappedByClerkProvider-GaNwZpWo.mjs +29 -0
  46. package/dist/useAssertWrappedByClerkProvider-GaNwZpWo.mjs.map +1 -0
  47. package/dist/{useAuth-Dlg_G1_7.d.mts → useAuth-BK5Y4htK.d.mts} +58 -39
  48. package/dist/{useAuth-Cv6iRjL9.d.ts → useAuth-BMxaWktj.d.cts} +58 -39
  49. package/package.json +18 -18
  50. package/dist/chunk-E5QRIS4Z.mjs +0 -20
  51. package/dist/chunk-E5QRIS4Z.mjs.map +0 -1
  52. package/dist/chunk-FQVXBXXF.mjs +0 -1487
  53. package/dist/chunk-FQVXBXXF.mjs.map +0 -1
  54. package/dist/chunk-GVGS7DUS.mjs +0 -2097
  55. package/dist/chunk-GVGS7DUS.mjs.map +0 -1
  56. package/dist/chunk-RQWALB2R.mjs +0 -26
  57. package/dist/chunk-RQWALB2R.mjs.map +0 -1
  58. package/dist/errors.d.ts +0 -1
  59. package/dist/errors.js +0 -51
  60. package/dist/errors.js.map +0 -1
  61. package/dist/errors.mjs.map +0 -1
  62. package/dist/experimental.js +0 -1505
  63. package/dist/experimental.js.map +0 -1
  64. package/dist/index.d.ts +0 -319
  65. package/dist/index.js +0 -3919
  66. package/dist/index.js.map +0 -1
  67. package/dist/internal.d.ts +0 -53
  68. package/dist/internal.js +0 -3339
  69. package/dist/internal.js.map +0 -1
  70. package/dist/legacy.js +0 -90
  71. package/dist/legacy.js.map +0 -1
  72. package/dist/types.d.ts +0 -109
  73. package/dist/types.js +0 -19
  74. package/dist/types.js.map +0 -1
  75. package/dist/types.mjs.map +0 -1
@@ -1,1505 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/experimental.ts
31
- var experimental_exports = {};
32
- __export(experimental_exports, {
33
- CheckoutButton: () => CheckoutButton,
34
- CheckoutProvider: () => import_react24.__experimental_CheckoutProvider,
35
- PaymentElement: () => import_react24.__experimental_PaymentElement,
36
- PaymentElementProvider: () => import_react24.__experimental_PaymentElementProvider,
37
- PlanDetailsButton: () => PlanDetailsButton,
38
- SubscriptionDetailsButton: () => SubscriptionDetailsButton,
39
- useCheckout: () => import_react24.__experimental_useCheckout,
40
- usePaymentAttempts: () => import_react24.__experimental_usePaymentAttempts,
41
- usePaymentElement: () => import_react24.__experimental_usePaymentElement,
42
- usePaymentMethods: () => import_react24.__experimental_usePaymentMethods,
43
- usePlans: () => import_react24.__experimental_usePlans,
44
- useStatements: () => import_react24.__experimental_useStatements,
45
- useSubscription: () => import_react24.__experimental_useSubscription
46
- });
47
- module.exports = __toCommonJS(experimental_exports);
48
-
49
- // src/components/CheckoutButton.tsx
50
- var import_react21 = __toESM(require("react"));
51
-
52
- // src/hooks/useAuth.ts
53
- var import_authorization = require("@clerk/shared/authorization");
54
- var import_telemetry = require("@clerk/shared/telemetry");
55
- var import_react5 = require("react");
56
-
57
- // src/contexts/IsomorphicClerkContext.tsx
58
- var import_react = require("@clerk/shared/react");
59
- var useIsomorphicClerkContext = import_react.useClerkInstanceContext;
60
-
61
- // src/errors/errorThrower.ts
62
- var import_error = require("@clerk/shared/error");
63
- var errorThrower = (0, import_error.buildErrorThrower)({ packageName: "@clerk/react" });
64
-
65
- // src/errors/messages.ts
66
- var multipleChildrenInButtonComponent = (name) => `You've passed multiple children components to <${name}/>. You can only pass a single child component or text.`;
67
- var invalidStateError = "Invalid state. Feel free to submit a bug or reach out to support here: https://clerk.com/contact/support";
68
- var userProfilePageRenderedError = "<UserProfile.Page /> component needs to be a direct child of `<UserProfile />` or `<UserButton />`.";
69
- var userProfileLinkRenderedError = "<UserProfile.Link /> component needs to be a direct child of `<UserProfile />` or `<UserButton />`.";
70
- var organizationProfilePageRenderedError = "<OrganizationProfile.Page /> component needs to be a direct child of `<OrganizationProfile />` or `<OrganizationSwitcher />`.";
71
- var organizationProfileLinkRenderedError = "<OrganizationProfile.Link /> component needs to be a direct child of `<OrganizationProfile />` or `<OrganizationSwitcher />`.";
72
- var customPagesIgnoredComponent = (componentName) => `<${componentName} /> can only accept <${componentName}.Page /> and <${componentName}.Link /> as its children. Any other provided component will be ignored. Additionally, please ensure that the component is rendered in a client component.`;
73
- var customPageWrongProps = (componentName) => `Missing props. <${componentName}.Page /> component requires the following props: url, label, labelIcon, alongside with children to be rendered inside the page.`;
74
- var customLinkWrongProps = (componentName) => `Missing props. <${componentName}.Link /> component requires the following props: url, label and labelIcon.`;
75
- var userButtonIgnoredComponent = `<UserButton /> can only accept <UserButton.UserProfilePage />, <UserButton.UserProfileLink /> and <UserButton.MenuItems /> as its children. Any other provided component will be ignored. Additionally, please ensure that the component is rendered in a client component.`;
76
- var customMenuItemsIgnoredComponent = "<UserButton.MenuItems /> component can only accept <UserButton.Action /> and <UserButton.Link /> as its children. Any other provided component will be ignored. Additionally, please ensure that the component is rendered in a client component.";
77
- var userButtonMenuItemsRenderedError = "<UserButton.MenuItems /> component needs to be a direct child of `<UserButton />`.";
78
- var userButtonMenuActionRenderedError = "<UserButton.Action /> component needs to be a direct child of `<UserButton.MenuItems />`.";
79
- var userButtonMenuLinkRenderedError = "<UserButton.Link /> component needs to be a direct child of `<UserButton.MenuItems />`.";
80
- var userButtonMenuItemLinkWrongProps = "Missing props. <UserButton.Link /> component requires the following props: href, label and labelIcon.";
81
- var userButtonMenuItemsActionWrongsProps = "Missing props. <UserButton.Action /> component requires the following props: label.";
82
-
83
- // src/hooks/useAssertWrappedByClerkProvider.ts
84
- var import_react2 = require("@clerk/shared/react");
85
- var useAssertWrappedByClerkProvider = (source) => {
86
- (0, import_react2.useAssertWrappedByClerkProvider)(() => {
87
- errorThrower.throwMissingClerkProviderError({ source });
88
- });
89
- };
90
-
91
- // src/hooks/useAuthBase.tsx
92
- var import_deriveState = require("@clerk/shared/deriveState");
93
- var import_react3 = require("@clerk/shared/react");
94
- var import_react4 = require("react");
95
- var defaultDerivedInitialState = {
96
- actor: void 0,
97
- factorVerificationAge: null,
98
- orgId: void 0,
99
- orgPermissions: void 0,
100
- orgRole: void 0,
101
- orgSlug: void 0,
102
- sessionClaims: void 0,
103
- sessionId: void 0,
104
- sessionStatus: void 0,
105
- userId: void 0
106
- };
107
- function useAuthBase() {
108
- const clerk = (0, import_react3.useClerkInstanceContext)();
109
- const initialState = (0, import_react3.useInitialStateContext)();
110
- const getInitialState = (0, import_react4.useCallback)(() => initialState, [initialState]);
111
- const state = (0, import_react4.useSyncExternalStore)(
112
- (0, import_react4.useCallback)((callback) => clerk.addListener(callback, { skipInitialEmit: true }), [clerk]),
113
- (0, import_react4.useCallback)(() => {
114
- if (!clerk.loaded || !clerk.__internal_lastEmittedResources) {
115
- return getInitialState();
116
- }
117
- return clerk.__internal_lastEmittedResources;
118
- }, [clerk, getInitialState]),
119
- getInitialState
120
- );
121
- const authState = (0, import_react4.useMemo)(() => {
122
- if (!state) {
123
- return defaultDerivedInitialState;
124
- }
125
- const fullState = isInitialState(state) ? (0, import_deriveState.deriveState)(false, {}, state) : (0, import_deriveState.deriveState)(true, state, void 0);
126
- return authStateFromFull(fullState);
127
- }, [state]);
128
- return authState;
129
- }
130
- function authStateFromFull(derivedState) {
131
- return {
132
- sessionId: derivedState.sessionId,
133
- sessionStatus: derivedState.sessionStatus,
134
- sessionClaims: derivedState.sessionClaims,
135
- userId: derivedState.userId,
136
- actor: derivedState.actor,
137
- orgId: derivedState.orgId,
138
- orgRole: derivedState.orgRole,
139
- orgSlug: derivedState.orgSlug,
140
- orgPermissions: derivedState.orgPermissions,
141
- factorVerificationAge: derivedState.factorVerificationAge
142
- };
143
- }
144
- function isInitialState(state) {
145
- return !("client" in state);
146
- }
147
-
148
- // src/hooks/utils.ts
149
- var import_browser = require("@clerk/shared/browser");
150
- var import_error2 = require("@clerk/shared/error");
151
- var clerkLoaded = (isomorphicClerk) => {
152
- return new Promise((resolve) => {
153
- const handler = (status) => {
154
- if (["ready", "degraded"].includes(status)) {
155
- resolve();
156
- isomorphicClerk.off("status", handler);
157
- }
158
- };
159
- isomorphicClerk.on("status", handler, { notify: true });
160
- });
161
- };
162
- var createGetToken = (isomorphicClerk) => {
163
- return async (options) => {
164
- if (!(0, import_browser.inBrowser)()) {
165
- throw new import_error2.ClerkRuntimeError(
166
- "useAuth().getToken() can only be used in browser environments. To access auth data server-side, see the Auth object reference doc: https://clerk.com/docs/reference/backend/types/auth-object",
167
- {
168
- code: "clerk_runtime_not_browser"
169
- }
170
- );
171
- }
172
- await clerkLoaded(isomorphicClerk);
173
- if (!isomorphicClerk.session) {
174
- return null;
175
- }
176
- return isomorphicClerk.session.getToken(options);
177
- };
178
- };
179
- var createSignOut = (isomorphicClerk) => {
180
- return async (...args) => {
181
- await clerkLoaded(isomorphicClerk);
182
- return isomorphicClerk.signOut(...args);
183
- };
184
- };
185
-
186
- // src/hooks/useAuth.ts
187
- var useAuth = (options = {}) => {
188
- var _a;
189
- useAssertWrappedByClerkProvider("useAuth");
190
- const { treatPendingAsSignedOut } = options != null ? options : {};
191
- const authState = useAuthBase();
192
- const isomorphicClerk = useIsomorphicClerkContext();
193
- const getToken = (0, import_react5.useCallback)(createGetToken(isomorphicClerk), [isomorphicClerk]);
194
- const signOut = (0, import_react5.useCallback)(createSignOut(isomorphicClerk), [isomorphicClerk]);
195
- (_a = isomorphicClerk.telemetry) == null ? void 0 : _a.record((0, import_telemetry.eventMethodCalled)("useAuth", { treatPendingAsSignedOut }));
196
- return useDerivedAuth(
197
- {
198
- ...authState,
199
- getToken,
200
- signOut
201
- },
202
- {
203
- treatPendingAsSignedOut
204
- }
205
- );
206
- };
207
- function useDerivedAuth(authObject, { treatPendingAsSignedOut = true } = {}) {
208
- const { userId, orgId, orgRole, has, signOut, getToken, orgPermissions, factorVerificationAge, sessionClaims } = authObject != null ? authObject : {};
209
- const derivedHas = (0, import_react5.useCallback)(
210
- (params) => {
211
- if (has) {
212
- return has(params);
213
- }
214
- return (0, import_authorization.createCheckAuthorization)({
215
- userId,
216
- orgId,
217
- orgRole,
218
- orgPermissions,
219
- factorVerificationAge,
220
- features: (sessionClaims == null ? void 0 : sessionClaims.fea) || "",
221
- plans: (sessionClaims == null ? void 0 : sessionClaims.pla) || ""
222
- })(params);
223
- },
224
- [has, userId, orgId, orgRole, orgPermissions, factorVerificationAge, sessionClaims]
225
- );
226
- const payload = (0, import_authorization.resolveAuthState)({
227
- authObject: {
228
- ...authObject,
229
- getToken,
230
- signOut,
231
- has: derivedHas
232
- },
233
- options: {
234
- treatPendingAsSignedOut
235
- }
236
- });
237
- if (!payload) {
238
- return errorThrower.throw(invalidStateError);
239
- }
240
- return payload;
241
- }
242
-
243
- // src/hooks/useEmailLink.ts
244
- var import_react6 = __toESM(require("react"));
245
-
246
- // src/hooks/useClerkSignal.ts
247
- var import_telemetry2 = require("@clerk/shared/telemetry");
248
- var import_react7 = require("react");
249
-
250
- // src/hooks/index.ts
251
- var import_react8 = require("@clerk/shared/react");
252
-
253
- // src/utils/childrenUtils.tsx
254
- var import_react9 = __toESM(require("react"));
255
- var assertSingleChild = (children) => (name) => {
256
- try {
257
- return import_react9.default.Children.only(children);
258
- } catch {
259
- const childArray = import_react9.default.Children.toArray(children);
260
- if (childArray.length === 1 && import_react9.default.isValidElement(childArray[0])) {
261
- return childArray[0];
262
- }
263
- return errorThrower.throw(multipleChildrenInButtonComponent(name));
264
- }
265
- };
266
- var normalizeWithDefaultValue = (children, defaultText) => {
267
- if (!children) {
268
- children = defaultText;
269
- }
270
- if (typeof children === "string") {
271
- children = /* @__PURE__ */ import_react9.default.createElement("button", null, children);
272
- }
273
- return children;
274
- };
275
- var safeExecute = (cb) => (...args) => {
276
- if (cb && typeof cb === "function") {
277
- return cb(...args);
278
- }
279
- };
280
-
281
- // src/utils/envVariables.ts
282
- var import_getEnvVariable = require("@clerk/shared/getEnvVariable");
283
-
284
- // src/utils/useMaxAllowedInstancesGuard.tsx
285
- var import_react10 = __toESM(require("react"));
286
-
287
- // src/utils/useCustomElementPortal.tsx
288
- var import_react11 = require("react");
289
- var import_react_dom = require("react-dom");
290
- var useCustomElementPortal = (elements) => {
291
- const [nodeMap, setNodeMap] = (0, import_react11.useState)(/* @__PURE__ */ new Map());
292
- const nodeMapRef = (0, import_react11.useRef)(nodeMap);
293
- const elementsRef = (0, import_react11.useRef)(/* @__PURE__ */ new Map());
294
- const portalsRef = (0, import_react11.useRef)(/* @__PURE__ */ new Map());
295
- nodeMapRef.current = nodeMap;
296
- elementsRef.current = new Map(elements.map((el) => [el.id, el.component]));
297
- const elementIds = new Set(elements.map((el) => el.id));
298
- portalsRef.current.forEach((_, id) => {
299
- if (!elementIds.has(id)) {
300
- portalsRef.current.delete(id);
301
- }
302
- });
303
- return elements.map((el) => {
304
- const id = el.id;
305
- const existingPortal = portalsRef.current.get(id);
306
- if (existingPortal) {
307
- return existingPortal;
308
- }
309
- const portal = () => {
310
- const node = nodeMapRef.current.get(id);
311
- const component = elementsRef.current.get(id);
312
- return node ? (0, import_react_dom.createPortal)(component, node) : null;
313
- };
314
- const customElementPortal = {
315
- id: el.id,
316
- mount: (node) => setNodeMap((prev) => new Map(prev).set(id, node)),
317
- unmount: () => setNodeMap((prev) => {
318
- const newMap = new Map(prev);
319
- newMap.set(id, null);
320
- return newMap;
321
- }),
322
- portal
323
- };
324
- portalsRef.current.set(id, customElementPortal);
325
- return customElementPortal;
326
- });
327
- };
328
-
329
- // src/utils/useCustomPages.tsx
330
- var import_utils4 = require("@clerk/shared/utils");
331
- var import_react19 = __toESM(require("react"));
332
-
333
- // src/components/uiComponents.tsx
334
- var import_utils2 = require("@clerk/shared/utils");
335
- var import_react17 = __toESM(require("react"));
336
-
337
- // src/utils/useWaitForComponentMount.ts
338
- var import_react12 = require("react");
339
- var createAwaitableMutationObserver = (globalOptions) => {
340
- const isReady = globalOptions == null ? void 0 : globalOptions.isReady;
341
- return (options) => new Promise((resolve, reject) => {
342
- const { root = document == null ? void 0 : document.body, selector, timeout = 0 } = options;
343
- if (!root) {
344
- reject(new Error("No root element provided"));
345
- return;
346
- }
347
- let elementToWatch = root;
348
- if (selector) {
349
- elementToWatch = root == null ? void 0 : root.querySelector(selector);
350
- }
351
- if (isReady(elementToWatch, selector)) {
352
- resolve();
353
- return;
354
- }
355
- const observer = new MutationObserver((mutationsList) => {
356
- for (const mutation of mutationsList) {
357
- if (!elementToWatch && selector) {
358
- elementToWatch = root == null ? void 0 : root.querySelector(selector);
359
- }
360
- if (globalOptions.childList && mutation.type === "childList" || globalOptions.attributes && mutation.type === "attributes") {
361
- if (isReady(elementToWatch, selector)) {
362
- observer.disconnect();
363
- resolve();
364
- return;
365
- }
366
- }
367
- }
368
- });
369
- observer.observe(root, globalOptions);
370
- if (timeout > 0) {
371
- setTimeout(() => {
372
- observer.disconnect();
373
- reject(new Error(`Timeout waiting for ${selector}`));
374
- }, timeout);
375
- }
376
- });
377
- };
378
- var waitForElementChildren = createAwaitableMutationObserver({
379
- childList: true,
380
- subtree: true,
381
- isReady: (el, selector) => {
382
- var _a;
383
- return !!(el == null ? void 0 : el.childElementCount) && ((_a = el == null ? void 0 : el.matches) == null ? void 0 : _a.call(el, selector)) && el.childElementCount > 0;
384
- }
385
- });
386
- function useWaitForComponentMount(component, options) {
387
- const watcherRef = (0, import_react12.useRef)();
388
- const [status, setStatus] = (0, import_react12.useState)("rendering");
389
- (0, import_react12.useEffect)(() => {
390
- if (!component) {
391
- throw new Error("Clerk: no component name provided, unable to detect mount.");
392
- }
393
- if (typeof window !== "undefined" && !watcherRef.current) {
394
- const defaultSelector = `[data-clerk-component="${component}"]`;
395
- const selector = options == null ? void 0 : options.selector;
396
- watcherRef.current = waitForElementChildren({
397
- selector: selector ? (
398
- // Allows for `[data-clerk-component="xxxx"][data-some-attribute="123"] .my-class`
399
- defaultSelector + selector
400
- ) : defaultSelector
401
- }).then(() => {
402
- setStatus("rendered");
403
- }).catch(() => {
404
- setStatus("error");
405
- });
406
- }
407
- }, [component, options == null ? void 0 : options.selector]);
408
- return status;
409
- }
410
-
411
- // src/components/ClerkHostRenderer.tsx
412
- var import_object = require("@clerk/shared/object");
413
- var import_react13 = require("@clerk/shared/react");
414
- var import_react14 = __toESM(require("react"));
415
- var isMountProps = (props) => {
416
- return "mount" in props;
417
- };
418
- var isOpenProps = (props) => {
419
- return "open" in props;
420
- };
421
- var stripMenuItemIconHandlers = (menuItems) => {
422
- return menuItems == null ? void 0 : menuItems.map(({ mountIcon, unmountIcon, ...rest }) => rest);
423
- };
424
- var ClerkHostRenderer = class extends import_react14.default.PureComponent {
425
- constructor() {
426
- super(...arguments);
427
- this.rootRef = import_react14.default.createRef();
428
- }
429
- componentDidUpdate(_prevProps) {
430
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
431
- if (!isMountProps(_prevProps) || !isMountProps(this.props)) {
432
- return;
433
- }
434
- const prevProps = (0, import_object.without)(_prevProps.props || {}, "customPages", "customMenuItems", "children");
435
- const newProps = (0, import_object.without)(this.props.props || {}, "customPages", "customMenuItems", "children");
436
- const customPagesChanged = ((_b = (_a = _prevProps.props) == null ? void 0 : _a.customPages) == null ? void 0 : _b.length) !== ((_d = (_c = this.props.props) == null ? void 0 : _c.customPages) == null ? void 0 : _d.length);
437
- const customMenuItemsChanged = ((_f = (_e = _prevProps.props) == null ? void 0 : _e.customMenuItems) == null ? void 0 : _f.length) !== ((_h = (_g = this.props.props) == null ? void 0 : _g.customMenuItems) == null ? void 0 : _h.length);
438
- const prevMenuItemsWithoutHandlers = stripMenuItemIconHandlers((_i = _prevProps.props) == null ? void 0 : _i.customMenuItems);
439
- const newMenuItemsWithoutHandlers = stripMenuItemIconHandlers((_j = this.props.props) == null ? void 0 : _j.customMenuItems);
440
- if (!(0, import_react13.isDeeplyEqual)(prevProps, newProps) || !(0, import_react13.isDeeplyEqual)(prevMenuItemsWithoutHandlers, newMenuItemsWithoutHandlers) || customPagesChanged || customMenuItemsChanged) {
441
- if (this.rootRef.current) {
442
- this.props.updateProps({ node: this.rootRef.current, props: this.props.props });
443
- }
444
- }
445
- }
446
- componentDidMount() {
447
- if (this.rootRef.current) {
448
- if (isMountProps(this.props)) {
449
- this.props.mount(this.rootRef.current, this.props.props);
450
- }
451
- if (isOpenProps(this.props)) {
452
- this.props.open(this.props.props);
453
- }
454
- }
455
- }
456
- componentWillUnmount() {
457
- if (this.rootRef.current) {
458
- if (isMountProps(this.props)) {
459
- this.props.unmount(this.rootRef.current);
460
- }
461
- if (isOpenProps(this.props)) {
462
- this.props.close();
463
- }
464
- }
465
- }
466
- render() {
467
- const { hideRootHtmlElement = false } = this.props;
468
- const rootAttributes = {
469
- ref: this.rootRef,
470
- ...this.props.rootProps,
471
- ...this.props.component && { "data-clerk-component": this.props.component }
472
- };
473
- return /* @__PURE__ */ import_react14.default.createElement(import_react14.default.Fragment, null, !hideRootHtmlElement && /* @__PURE__ */ import_react14.default.createElement("div", { ...rootAttributes }), this.props.children);
474
- }
475
- };
476
-
477
- // src/components/withClerk.tsx
478
- var import_react15 = require("@clerk/shared/react");
479
- var import_react16 = __toESM(require("react"));
480
- var withClerk = (Component, displayNameOrOptions) => {
481
- const passedDisplayedName = typeof displayNameOrOptions === "string" ? displayNameOrOptions : displayNameOrOptions == null ? void 0 : displayNameOrOptions.component;
482
- const displayName = passedDisplayedName || Component.displayName || Component.name || "Component";
483
- Component.displayName = displayName;
484
- const options = typeof displayNameOrOptions === "string" ? void 0 : displayNameOrOptions;
485
- const HOC = (props) => {
486
- useAssertWrappedByClerkProvider(displayName || "withClerk");
487
- const clerk = useIsomorphicClerkContext();
488
- const getContainer = (0, import_react15.usePortalRoot)();
489
- if (!clerk.loaded && !(options == null ? void 0 : options.renderWhileLoading)) {
490
- return null;
491
- }
492
- return /* @__PURE__ */ import_react16.default.createElement(
493
- Component,
494
- {
495
- getContainer,
496
- ...props,
497
- component: displayName,
498
- clerk
499
- }
500
- );
501
- };
502
- HOC.displayName = `withClerk(${displayName})`;
503
- return HOC;
504
- };
505
-
506
- // src/components/uiComponents.tsx
507
- var CustomPortalsRenderer = (props) => {
508
- var _a, _b;
509
- return /* @__PURE__ */ import_react17.default.createElement(import_react17.default.Fragment, null, (_a = props == null ? void 0 : props.customPagesPortals) == null ? void 0 : _a.map(({ key, portal }) => (0, import_react17.createElement)(portal, { key })), (_b = props == null ? void 0 : props.customMenuItemsPortals) == null ? void 0 : _b.map(({ key, portal }) => (0, import_react17.createElement)(portal, { key })));
510
- };
511
- var SignIn = withClerk(
512
- ({ clerk, component, fallback, ...props }) => {
513
- const mountingStatus = useWaitForComponentMount(component);
514
- const shouldShowFallback = mountingStatus === "rendering" || !clerk.loaded;
515
- const rendererRootProps = {
516
- ...shouldShowFallback && fallback && { style: { display: "none" } }
517
- };
518
- return /* @__PURE__ */ import_react17.default.createElement(import_react17.default.Fragment, null, shouldShowFallback && fallback, clerk.loaded && /* @__PURE__ */ import_react17.default.createElement(
519
- ClerkHostRenderer,
520
- {
521
- component,
522
- mount: clerk.mountSignIn,
523
- unmount: clerk.unmountSignIn,
524
- updateProps: clerk.__internal_updateProps,
525
- props,
526
- rootProps: rendererRootProps
527
- }
528
- ));
529
- },
530
- { component: "SignIn", renderWhileLoading: true }
531
- );
532
- var SignUp = withClerk(
533
- ({ clerk, component, fallback, ...props }) => {
534
- const mountingStatus = useWaitForComponentMount(component);
535
- const shouldShowFallback = mountingStatus === "rendering" || !clerk.loaded;
536
- const rendererRootProps = {
537
- ...shouldShowFallback && fallback && { style: { display: "none" } }
538
- };
539
- return /* @__PURE__ */ import_react17.default.createElement(import_react17.default.Fragment, null, shouldShowFallback && fallback, clerk.loaded && /* @__PURE__ */ import_react17.default.createElement(
540
- ClerkHostRenderer,
541
- {
542
- component,
543
- mount: clerk.mountSignUp,
544
- unmount: clerk.unmountSignUp,
545
- updateProps: clerk.__internal_updateProps,
546
- props,
547
- rootProps: rendererRootProps
548
- }
549
- ));
550
- },
551
- { component: "SignUp", renderWhileLoading: true }
552
- );
553
- function UserProfilePage({ children }) {
554
- (0, import_utils2.logErrorInDevMode)(userProfilePageRenderedError);
555
- return /* @__PURE__ */ import_react17.default.createElement(import_react17.default.Fragment, null, children);
556
- }
557
- function UserProfileLink({ children }) {
558
- (0, import_utils2.logErrorInDevMode)(userProfileLinkRenderedError);
559
- return /* @__PURE__ */ import_react17.default.createElement(import_react17.default.Fragment, null, children);
560
- }
561
- var _UserProfile = withClerk(
562
- ({
563
- clerk,
564
- component,
565
- fallback,
566
- ...props
567
- }) => {
568
- const mountingStatus = useWaitForComponentMount(component);
569
- const shouldShowFallback = mountingStatus === "rendering" || !clerk.loaded;
570
- const rendererRootProps = {
571
- ...shouldShowFallback && fallback && { style: { display: "none" } }
572
- };
573
- const { customPages, customPagesPortals } = useUserProfileCustomPages(props.children);
574
- return /* @__PURE__ */ import_react17.default.createElement(import_react17.default.Fragment, null, shouldShowFallback && fallback, /* @__PURE__ */ import_react17.default.createElement(
575
- ClerkHostRenderer,
576
- {
577
- component,
578
- mount: clerk.mountUserProfile,
579
- unmount: clerk.unmountUserProfile,
580
- updateProps: clerk.__internal_updateProps,
581
- props: { ...props, customPages },
582
- rootProps: rendererRootProps
583
- },
584
- /* @__PURE__ */ import_react17.default.createElement(CustomPortalsRenderer, { customPagesPortals })
585
- ));
586
- },
587
- { component: "UserProfile", renderWhileLoading: true }
588
- );
589
- var UserProfile = Object.assign(_UserProfile, {
590
- Page: UserProfilePage,
591
- Link: UserProfileLink
592
- });
593
- var UserButtonContext = (0, import_react17.createContext)({
594
- mount: () => {
595
- },
596
- unmount: () => {
597
- },
598
- updateProps: () => {
599
- }
600
- });
601
- var _UserButton = withClerk(
602
- ({
603
- clerk,
604
- component,
605
- fallback,
606
- ...props
607
- }) => {
608
- const mountingStatus = useWaitForComponentMount(component);
609
- const shouldShowFallback = mountingStatus === "rendering" || !clerk.loaded;
610
- const rendererRootProps = {
611
- ...shouldShowFallback && fallback && { style: { display: "none" } }
612
- };
613
- const { customPages, customPagesPortals } = useUserProfileCustomPages(props.children, {
614
- allowForAnyChildren: !!props.__experimental_asProvider
615
- });
616
- const userProfileProps = { ...props.userProfileProps, customPages };
617
- const { customMenuItems, customMenuItemsPortals } = useUserButtonCustomMenuItems(props.children, {
618
- allowForAnyChildren: !!props.__experimental_asProvider
619
- });
620
- const sanitizedChildren = useSanitizedChildren(props.children);
621
- const passableProps = {
622
- mount: clerk.mountUserButton,
623
- unmount: clerk.unmountUserButton,
624
- updateProps: clerk.__internal_updateProps,
625
- props: { ...props, userProfileProps, customMenuItems }
626
- };
627
- const portalProps = {
628
- customPagesPortals,
629
- customMenuItemsPortals
630
- };
631
- return /* @__PURE__ */ import_react17.default.createElement(UserButtonContext.Provider, { value: passableProps }, shouldShowFallback && fallback, clerk.loaded && /* @__PURE__ */ import_react17.default.createElement(
632
- ClerkHostRenderer,
633
- {
634
- component,
635
- ...passableProps,
636
- hideRootHtmlElement: !!props.__experimental_asProvider,
637
- rootProps: rendererRootProps
638
- },
639
- props.__experimental_asProvider ? sanitizedChildren : null,
640
- /* @__PURE__ */ import_react17.default.createElement(CustomPortalsRenderer, { ...portalProps })
641
- ));
642
- },
643
- { component: "UserButton", renderWhileLoading: true }
644
- );
645
- function MenuItems({ children }) {
646
- (0, import_utils2.logErrorInDevMode)(userButtonMenuItemsRenderedError);
647
- return /* @__PURE__ */ import_react17.default.createElement(import_react17.default.Fragment, null, children);
648
- }
649
- function MenuAction({ children }) {
650
- (0, import_utils2.logErrorInDevMode)(userButtonMenuActionRenderedError);
651
- return /* @__PURE__ */ import_react17.default.createElement(import_react17.default.Fragment, null, children);
652
- }
653
- function MenuLink({ children }) {
654
- (0, import_utils2.logErrorInDevMode)(userButtonMenuLinkRenderedError);
655
- return /* @__PURE__ */ import_react17.default.createElement(import_react17.default.Fragment, null, children);
656
- }
657
- function UserButtonOutlet(outletProps) {
658
- const providerProps = (0, import_react17.useContext)(UserButtonContext);
659
- const portalProps = {
660
- ...providerProps,
661
- props: {
662
- ...providerProps.props,
663
- ...outletProps
664
- }
665
- };
666
- return /* @__PURE__ */ import_react17.default.createElement(ClerkHostRenderer, { ...portalProps });
667
- }
668
- var UserButton = Object.assign(_UserButton, {
669
- UserProfilePage,
670
- UserProfileLink,
671
- MenuItems,
672
- Action: MenuAction,
673
- Link: MenuLink,
674
- __experimental_Outlet: UserButtonOutlet
675
- });
676
- function OrganizationProfilePage({ children }) {
677
- (0, import_utils2.logErrorInDevMode)(organizationProfilePageRenderedError);
678
- return /* @__PURE__ */ import_react17.default.createElement(import_react17.default.Fragment, null, children);
679
- }
680
- function OrganizationProfileLink({ children }) {
681
- (0, import_utils2.logErrorInDevMode)(organizationProfileLinkRenderedError);
682
- return /* @__PURE__ */ import_react17.default.createElement(import_react17.default.Fragment, null, children);
683
- }
684
- var _OrganizationProfile = withClerk(
685
- ({
686
- clerk,
687
- component,
688
- fallback,
689
- ...props
690
- }) => {
691
- const mountingStatus = useWaitForComponentMount(component);
692
- const shouldShowFallback = mountingStatus === "rendering" || !clerk.loaded;
693
- const rendererRootProps = {
694
- ...shouldShowFallback && fallback && { style: { display: "none" } }
695
- };
696
- const { customPages, customPagesPortals } = useOrganizationProfileCustomPages(props.children);
697
- return /* @__PURE__ */ import_react17.default.createElement(import_react17.default.Fragment, null, shouldShowFallback && fallback, clerk.loaded && /* @__PURE__ */ import_react17.default.createElement(
698
- ClerkHostRenderer,
699
- {
700
- component,
701
- mount: clerk.mountOrganizationProfile,
702
- unmount: clerk.unmountOrganizationProfile,
703
- updateProps: clerk.__internal_updateProps,
704
- props: { ...props, customPages },
705
- rootProps: rendererRootProps
706
- },
707
- /* @__PURE__ */ import_react17.default.createElement(CustomPortalsRenderer, { customPagesPortals })
708
- ));
709
- },
710
- { component: "OrganizationProfile", renderWhileLoading: true }
711
- );
712
- var OrganizationProfile = Object.assign(_OrganizationProfile, {
713
- Page: OrganizationProfilePage,
714
- Link: OrganizationProfileLink
715
- });
716
- var CreateOrganization = withClerk(
717
- ({ clerk, component, fallback, ...props }) => {
718
- const mountingStatus = useWaitForComponentMount(component);
719
- const shouldShowFallback = mountingStatus === "rendering" || !clerk.loaded;
720
- const rendererRootProps = {
721
- ...shouldShowFallback && fallback && { style: { display: "none" } }
722
- };
723
- return /* @__PURE__ */ import_react17.default.createElement(import_react17.default.Fragment, null, shouldShowFallback && fallback, clerk.loaded && /* @__PURE__ */ import_react17.default.createElement(
724
- ClerkHostRenderer,
725
- {
726
- component,
727
- mount: clerk.mountCreateOrganization,
728
- unmount: clerk.unmountCreateOrganization,
729
- updateProps: clerk.__internal_updateProps,
730
- props,
731
- rootProps: rendererRootProps
732
- }
733
- ));
734
- },
735
- { component: "CreateOrganization", renderWhileLoading: true }
736
- );
737
- var OrganizationSwitcherContext = (0, import_react17.createContext)({
738
- mount: () => {
739
- },
740
- unmount: () => {
741
- },
742
- updateProps: () => {
743
- }
744
- });
745
- var _OrganizationSwitcher = withClerk(
746
- ({
747
- clerk,
748
- component,
749
- fallback,
750
- ...props
751
- }) => {
752
- const mountingStatus = useWaitForComponentMount(component);
753
- const shouldShowFallback = mountingStatus === "rendering" || !clerk.loaded;
754
- const rendererRootProps = {
755
- ...shouldShowFallback && fallback && { style: { display: "none" } }
756
- };
757
- const { customPages, customPagesPortals } = useOrganizationProfileCustomPages(props.children, {
758
- allowForAnyChildren: !!props.__experimental_asProvider
759
- });
760
- const organizationProfileProps = { ...props.organizationProfileProps, customPages };
761
- const sanitizedChildren = useSanitizedChildren(props.children);
762
- const passableProps = {
763
- mount: clerk.mountOrganizationSwitcher,
764
- unmount: clerk.unmountOrganizationSwitcher,
765
- updateProps: clerk.__internal_updateProps,
766
- props: { ...props, organizationProfileProps },
767
- rootProps: rendererRootProps,
768
- component
769
- };
770
- clerk.__experimental_prefetchOrganizationSwitcher();
771
- return /* @__PURE__ */ import_react17.default.createElement(OrganizationSwitcherContext.Provider, { value: passableProps }, /* @__PURE__ */ import_react17.default.createElement(import_react17.default.Fragment, null, shouldShowFallback && fallback, clerk.loaded && /* @__PURE__ */ import_react17.default.createElement(
772
- ClerkHostRenderer,
773
- {
774
- ...passableProps,
775
- hideRootHtmlElement: !!props.__experimental_asProvider
776
- },
777
- props.__experimental_asProvider ? sanitizedChildren : null,
778
- /* @__PURE__ */ import_react17.default.createElement(CustomPortalsRenderer, { customPagesPortals })
779
- )));
780
- },
781
- { component: "OrganizationSwitcher", renderWhileLoading: true }
782
- );
783
- function OrganizationSwitcherOutlet(outletProps) {
784
- const providerProps = (0, import_react17.useContext)(OrganizationSwitcherContext);
785
- const portalProps = {
786
- ...providerProps,
787
- props: {
788
- ...providerProps.props,
789
- ...outletProps
790
- }
791
- };
792
- return /* @__PURE__ */ import_react17.default.createElement(ClerkHostRenderer, { ...portalProps });
793
- }
794
- var OrganizationSwitcher = Object.assign(_OrganizationSwitcher, {
795
- OrganizationProfilePage,
796
- OrganizationProfileLink,
797
- __experimental_Outlet: OrganizationSwitcherOutlet
798
- });
799
- var OrganizationList = withClerk(
800
- ({ clerk, component, fallback, ...props }) => {
801
- const mountingStatus = useWaitForComponentMount(component);
802
- const shouldShowFallback = mountingStatus === "rendering" || !clerk.loaded;
803
- const rendererRootProps = {
804
- ...shouldShowFallback && fallback && { style: { display: "none" } }
805
- };
806
- return /* @__PURE__ */ import_react17.default.createElement(import_react17.default.Fragment, null, shouldShowFallback && fallback, clerk.loaded && /* @__PURE__ */ import_react17.default.createElement(
807
- ClerkHostRenderer,
808
- {
809
- component,
810
- mount: clerk.mountOrganizationList,
811
- unmount: clerk.unmountOrganizationList,
812
- updateProps: clerk.__internal_updateProps,
813
- props,
814
- rootProps: rendererRootProps
815
- }
816
- ));
817
- },
818
- { component: "OrganizationList", renderWhileLoading: true }
819
- );
820
- var GoogleOneTap = withClerk(
821
- ({ clerk, component, fallback, ...props }) => {
822
- const mountingStatus = useWaitForComponentMount(component);
823
- const shouldShowFallback = mountingStatus === "rendering" || !clerk.loaded;
824
- const rendererRootProps = {
825
- ...shouldShowFallback && fallback && { style: { display: "none" } }
826
- };
827
- return /* @__PURE__ */ import_react17.default.createElement(import_react17.default.Fragment, null, shouldShowFallback && fallback, clerk.loaded && /* @__PURE__ */ import_react17.default.createElement(
828
- ClerkHostRenderer,
829
- {
830
- component,
831
- open: clerk.openGoogleOneTap,
832
- close: clerk.closeGoogleOneTap,
833
- updateProps: clerk.__internal_updateProps,
834
- props,
835
- rootProps: rendererRootProps
836
- }
837
- ));
838
- },
839
- { component: "GoogleOneTap", renderWhileLoading: true }
840
- );
841
- var Waitlist = withClerk(
842
- ({ clerk, component, fallback, ...props }) => {
843
- const mountingStatus = useWaitForComponentMount(component);
844
- const shouldShowFallback = mountingStatus === "rendering" || !clerk.loaded;
845
- const rendererRootProps = {
846
- ...shouldShowFallback && fallback && { style: { display: "none" } }
847
- };
848
- return /* @__PURE__ */ import_react17.default.createElement(import_react17.default.Fragment, null, shouldShowFallback && fallback, clerk.loaded && /* @__PURE__ */ import_react17.default.createElement(
849
- ClerkHostRenderer,
850
- {
851
- component,
852
- mount: clerk.mountWaitlist,
853
- unmount: clerk.unmountWaitlist,
854
- updateProps: clerk.__internal_updateProps,
855
- props,
856
- rootProps: rendererRootProps
857
- }
858
- ));
859
- },
860
- { component: "Waitlist", renderWhileLoading: true }
861
- );
862
- var PricingTable = withClerk(
863
- ({ clerk, component, fallback, ...props }) => {
864
- const mountingStatus = useWaitForComponentMount(component, {
865
- // This attribute is added to the PricingTable root element after we've successfully fetched the plans asynchronously.
866
- selector: '[data-component-status="ready"]'
867
- });
868
- const shouldShowFallback = mountingStatus === "rendering" || !clerk.loaded;
869
- const rendererRootProps = {
870
- ...shouldShowFallback && fallback && { style: { display: "none" } }
871
- };
872
- return /* @__PURE__ */ import_react17.default.createElement(import_react17.default.Fragment, null, shouldShowFallback && fallback, clerk.loaded && /* @__PURE__ */ import_react17.default.createElement(
873
- ClerkHostRenderer,
874
- {
875
- component,
876
- mount: clerk.mountPricingTable,
877
- unmount: clerk.unmountPricingTable,
878
- updateProps: clerk.__internal_updateProps,
879
- props,
880
- rootProps: rendererRootProps
881
- }
882
- ));
883
- },
884
- { component: "PricingTable", renderWhileLoading: true }
885
- );
886
- var APIKeys = withClerk(
887
- ({ clerk, component, fallback, ...props }) => {
888
- const mountingStatus = useWaitForComponentMount(component);
889
- const shouldShowFallback = mountingStatus === "rendering" || !clerk.loaded;
890
- const rendererRootProps = {
891
- ...shouldShowFallback && fallback && { style: { display: "none" } }
892
- };
893
- return /* @__PURE__ */ import_react17.default.createElement(import_react17.default.Fragment, null, shouldShowFallback && fallback, clerk.loaded && /* @__PURE__ */ import_react17.default.createElement(
894
- ClerkHostRenderer,
895
- {
896
- component,
897
- mount: clerk.mountAPIKeys,
898
- unmount: clerk.unmountAPIKeys,
899
- updateProps: clerk.__internal_updateProps,
900
- props,
901
- rootProps: rendererRootProps
902
- }
903
- ));
904
- },
905
- { component: "ApiKeys", renderWhileLoading: true }
906
- );
907
- var OAuthConsent = withClerk(
908
- ({ clerk, component, fallback, ...props }) => {
909
- const mountingStatus = useWaitForComponentMount(component);
910
- const shouldShowFallback = mountingStatus === "rendering" || !clerk.loaded;
911
- const rendererRootProps = {
912
- ...shouldShowFallback && fallback && { style: { display: "none" } }
913
- };
914
- return /* @__PURE__ */ import_react17.default.createElement(import_react17.default.Fragment, null, shouldShowFallback && fallback, clerk.loaded && /* @__PURE__ */ import_react17.default.createElement(
915
- ClerkHostRenderer,
916
- {
917
- component,
918
- mount: clerk.__internal_mountOAuthConsent,
919
- unmount: clerk.__internal_unmountOAuthConsent,
920
- updateProps: clerk.__internal_updateProps,
921
- props,
922
- rootProps: rendererRootProps
923
- }
924
- ));
925
- },
926
- { component: "OAuthConsent", renderWhileLoading: true }
927
- );
928
- var UserAvatar = withClerk(
929
- ({ clerk, component, fallback, ...props }) => {
930
- const mountingStatus = useWaitForComponentMount(component);
931
- const shouldShowFallback = mountingStatus === "rendering" || !clerk.loaded;
932
- const rendererRootProps = {
933
- ...shouldShowFallback && fallback && { style: { display: "none" } }
934
- };
935
- return /* @__PURE__ */ import_react17.default.createElement(import_react17.default.Fragment, null, shouldShowFallback && fallback, clerk.loaded && /* @__PURE__ */ import_react17.default.createElement(
936
- ClerkHostRenderer,
937
- {
938
- component,
939
- mount: clerk.mountUserAvatar,
940
- unmount: clerk.unmountUserAvatar,
941
- updateProps: clerk.__internal_updateProps,
942
- props,
943
- rootProps: rendererRootProps
944
- }
945
- ));
946
- },
947
- { component: "UserAvatar", renderWhileLoading: true }
948
- );
949
- var TaskChooseOrganization = withClerk(
950
- ({ clerk, component, fallback, ...props }) => {
951
- const mountingStatus = useWaitForComponentMount(component);
952
- const shouldShowFallback = mountingStatus === "rendering" || !clerk.loaded;
953
- const rendererRootProps = {
954
- ...shouldShowFallback && fallback && { style: { display: "none" } }
955
- };
956
- return /* @__PURE__ */ import_react17.default.createElement(import_react17.default.Fragment, null, shouldShowFallback && fallback, clerk.loaded && /* @__PURE__ */ import_react17.default.createElement(
957
- ClerkHostRenderer,
958
- {
959
- component,
960
- mount: clerk.mountTaskChooseOrganization,
961
- unmount: clerk.unmountTaskChooseOrganization,
962
- updateProps: clerk.__internal_updateProps,
963
- props,
964
- rootProps: rendererRootProps
965
- }
966
- ));
967
- },
968
- { component: "TaskChooseOrganization", renderWhileLoading: true }
969
- );
970
- var TaskResetPassword = withClerk(
971
- ({ clerk, component, fallback, ...props }) => {
972
- const mountingStatus = useWaitForComponentMount(component);
973
- const shouldShowFallback = mountingStatus === "rendering" || !clerk.loaded;
974
- const rendererRootProps = {
975
- ...shouldShowFallback && fallback && { style: { display: "none" } }
976
- };
977
- return /* @__PURE__ */ import_react17.default.createElement(import_react17.default.Fragment, null, shouldShowFallback && fallback, clerk.loaded && /* @__PURE__ */ import_react17.default.createElement(
978
- ClerkHostRenderer,
979
- {
980
- component,
981
- mount: clerk.mountTaskResetPassword,
982
- unmount: clerk.unmountTaskResetPassword,
983
- updateProps: clerk.__internal_updateProps,
984
- props,
985
- rootProps: rendererRootProps
986
- }
987
- ));
988
- },
989
- { component: "TaskResetPassword", renderWhileLoading: true }
990
- );
991
- var TaskSetupMFA = withClerk(
992
- ({ clerk, component, fallback, ...props }) => {
993
- const mountingStatus = useWaitForComponentMount(component);
994
- const shouldShowFallback = mountingStatus === "rendering" || !clerk.loaded;
995
- const rendererRootProps = {
996
- ...shouldShowFallback && fallback && { style: { display: "none" } }
997
- };
998
- return /* @__PURE__ */ import_react17.default.createElement(import_react17.default.Fragment, null, shouldShowFallback && fallback, clerk.loaded && /* @__PURE__ */ import_react17.default.createElement(
999
- ClerkHostRenderer,
1000
- {
1001
- component,
1002
- mount: clerk.mountTaskSetupMFA,
1003
- unmount: clerk.unmountTaskSetupMFA,
1004
- updateProps: clerk.__internal_updateProps,
1005
- props,
1006
- rootProps: rendererRootProps
1007
- }
1008
- ));
1009
- },
1010
- { component: "TaskSetupMFA", renderWhileLoading: true }
1011
- );
1012
-
1013
- // src/utils/componentValidation.ts
1014
- var import_react18 = __toESM(require("react"));
1015
- var isThatComponent = (v, component) => {
1016
- return !!v && import_react18.default.isValidElement(v) && (v == null ? void 0 : v.type) === component;
1017
- };
1018
-
1019
- // src/utils/useCustomPages.tsx
1020
- var useUserProfileCustomPages = (children, options) => {
1021
- const reorderItemsLabels = ["account", "security", "billing", "apiKeys"];
1022
- return useCustomPages(
1023
- {
1024
- children,
1025
- reorderItemsLabels,
1026
- LinkComponent: UserProfileLink,
1027
- PageComponent: UserProfilePage,
1028
- MenuItemsComponent: MenuItems,
1029
- componentName: "UserProfile"
1030
- },
1031
- options
1032
- );
1033
- };
1034
- var useOrganizationProfileCustomPages = (children, options) => {
1035
- const reorderItemsLabels = ["general", "members", "billing", "apiKeys"];
1036
- return useCustomPages(
1037
- {
1038
- children,
1039
- reorderItemsLabels,
1040
- LinkComponent: OrganizationProfileLink,
1041
- PageComponent: OrganizationProfilePage,
1042
- componentName: "OrganizationProfile"
1043
- },
1044
- options
1045
- );
1046
- };
1047
- var useSanitizedChildren = (children) => {
1048
- const sanitizedChildren = [];
1049
- const excludedComponents = [
1050
- OrganizationProfileLink,
1051
- OrganizationProfilePage,
1052
- MenuItems,
1053
- UserProfilePage,
1054
- UserProfileLink
1055
- ];
1056
- import_react19.default.Children.forEach(children, (child) => {
1057
- if (!excludedComponents.some((component) => isThatComponent(child, component))) {
1058
- sanitizedChildren.push(child);
1059
- }
1060
- });
1061
- return sanitizedChildren;
1062
- };
1063
- var useCustomPages = (params, options) => {
1064
- const { children, LinkComponent, PageComponent, MenuItemsComponent, reorderItemsLabels, componentName } = params;
1065
- const { allowForAnyChildren = false } = options || {};
1066
- const validChildren = [];
1067
- const portalIdCounts = /* @__PURE__ */ new Map();
1068
- import_react19.default.Children.forEach(children, (child) => {
1069
- if (!isThatComponent(child, PageComponent) && !isThatComponent(child, LinkComponent) && !isThatComponent(child, MenuItemsComponent)) {
1070
- if (child && !allowForAnyChildren) {
1071
- (0, import_utils4.logErrorInDevMode)(customPagesIgnoredComponent(componentName));
1072
- }
1073
- return;
1074
- }
1075
- const { props } = child;
1076
- const { children: children2, label, url, labelIcon } = props;
1077
- const childKey = child.key;
1078
- if (isThatComponent(child, PageComponent)) {
1079
- if (isReorderItem(props, reorderItemsLabels)) {
1080
- validChildren.push({ label });
1081
- } else if (isCustomPage(props)) {
1082
- validChildren.push({
1083
- label,
1084
- labelIcon,
1085
- children: children2,
1086
- url,
1087
- portalId: getCustomPagePortalId("page", props, childKey, portalIdCounts)
1088
- });
1089
- } else {
1090
- (0, import_utils4.logErrorInDevMode)(customPageWrongProps(componentName));
1091
- return;
1092
- }
1093
- }
1094
- if (isThatComponent(child, LinkComponent)) {
1095
- if (isExternalLink(props)) {
1096
- validChildren.push({
1097
- label,
1098
- labelIcon,
1099
- url,
1100
- portalId: getCustomPagePortalId("link", props, childKey, portalIdCounts)
1101
- });
1102
- } else {
1103
- (0, import_utils4.logErrorInDevMode)(customLinkWrongProps(componentName));
1104
- return;
1105
- }
1106
- }
1107
- });
1108
- const customPageContents = [];
1109
- const customPageLabelIcons = [];
1110
- const customLinkLabelIcons = [];
1111
- validChildren.forEach((cp, index) => {
1112
- if (isCustomPage(cp)) {
1113
- customPageContents.push({ component: cp.children, id: cp.portalId || index });
1114
- customPageLabelIcons.push({ component: cp.labelIcon, id: cp.portalId || index });
1115
- return;
1116
- }
1117
- if (isExternalLink(cp)) {
1118
- customLinkLabelIcons.push({ component: cp.labelIcon, id: cp.portalId || index });
1119
- }
1120
- });
1121
- const customPageContentsPortals = useCustomElementPortal(customPageContents);
1122
- const customPageLabelIconsPortals = useCustomElementPortal(customPageLabelIcons);
1123
- const customLinkLabelIconsPortals = useCustomElementPortal(customLinkLabelIcons);
1124
- const customPages = [];
1125
- const customPagesPortals = [];
1126
- validChildren.forEach((cp, index) => {
1127
- if (isReorderItem(cp, reorderItemsLabels)) {
1128
- customPages.push({ label: cp.label });
1129
- return;
1130
- }
1131
- if (isCustomPage(cp)) {
1132
- const {
1133
- portal: contentPortal,
1134
- mount,
1135
- unmount
1136
- } = customPageContentsPortals.find((p) => p.id === (cp.portalId || index));
1137
- const {
1138
- portal: labelPortal,
1139
- mount: mountIcon,
1140
- unmount: unmountIcon
1141
- } = customPageLabelIconsPortals.find((p) => p.id === (cp.portalId || index));
1142
- customPages.push({ label: cp.label, url: cp.url, mount, unmount, mountIcon, unmountIcon });
1143
- customPagesPortals.push({ key: `content:${cp.portalId || index}`, portal: contentPortal });
1144
- customPagesPortals.push({ key: `label:${cp.portalId || index}`, portal: labelPortal });
1145
- return;
1146
- }
1147
- if (isExternalLink(cp)) {
1148
- const {
1149
- portal: labelPortal,
1150
- mount: mountIcon,
1151
- unmount: unmountIcon
1152
- } = customLinkLabelIconsPortals.find((p) => p.id === (cp.portalId || index));
1153
- customPages.push({ label: cp.label, url: cp.url, mountIcon, unmountIcon });
1154
- customPagesPortals.push({ key: `label:${cp.portalId || index}`, portal: labelPortal });
1155
- return;
1156
- }
1157
- });
1158
- return { customPages, customPagesPortals };
1159
- };
1160
- var getCustomPagePortalId = (type, props, key, portalIdCounts) => {
1161
- var _a;
1162
- if (key != null) {
1163
- return `${type}:key:${key}`;
1164
- }
1165
- const baseId = `${type}:${props.label}:${props.url}`;
1166
- const occurrence = (_a = portalIdCounts.get(baseId)) != null ? _a : 0;
1167
- portalIdCounts.set(baseId, occurrence + 1);
1168
- return `${baseId}:${occurrence}`;
1169
- };
1170
- var isReorderItem = (childProps, validItems) => {
1171
- const { children, label, url, labelIcon } = childProps;
1172
- return !children && !url && !labelIcon && validItems.some((v) => v === label);
1173
- };
1174
- var isCustomPage = (childProps) => {
1175
- const { children, label, url, labelIcon } = childProps;
1176
- return !!children && !!url && !!labelIcon && !!label;
1177
- };
1178
- var isExternalLink = (childProps) => {
1179
- const { children, label, url, labelIcon } = childProps;
1180
- return !children && !!url && !!labelIcon && !!label;
1181
- };
1182
-
1183
- // src/utils/useCustomMenuItems.tsx
1184
- var import_utils5 = require("@clerk/shared/utils");
1185
- var import_react20 = __toESM(require("react"));
1186
- var useUserButtonCustomMenuItems = (children, options) => {
1187
- var _a;
1188
- const reorderItemsLabels = ["manageAccount", "signOut"];
1189
- return useCustomMenuItems({
1190
- children,
1191
- reorderItemsLabels,
1192
- MenuItemsComponent: MenuItems,
1193
- MenuActionComponent: MenuAction,
1194
- MenuLinkComponent: MenuLink,
1195
- UserProfileLinkComponent: UserProfileLink,
1196
- UserProfilePageComponent: UserProfilePage,
1197
- allowForAnyChildren: (_a = options == null ? void 0 : options.allowForAnyChildren) != null ? _a : false
1198
- });
1199
- };
1200
- var useCustomMenuItems = ({
1201
- children,
1202
- MenuItemsComponent,
1203
- MenuActionComponent,
1204
- MenuLinkComponent,
1205
- UserProfileLinkComponent,
1206
- UserProfilePageComponent,
1207
- reorderItemsLabels,
1208
- allowForAnyChildren = false
1209
- }) => {
1210
- const validChildren = [];
1211
- const customMenuItems = [];
1212
- const customMenuItemsPortals = [];
1213
- const portalIdCounts = /* @__PURE__ */ new Map();
1214
- import_react20.default.Children.forEach(children, (child) => {
1215
- if (!isThatComponent(child, MenuItemsComponent) && !isThatComponent(child, UserProfileLinkComponent) && !isThatComponent(child, UserProfilePageComponent)) {
1216
- if (child && !allowForAnyChildren) {
1217
- (0, import_utils5.logErrorInDevMode)(userButtonIgnoredComponent);
1218
- }
1219
- return;
1220
- }
1221
- if (isThatComponent(child, UserProfileLinkComponent) || isThatComponent(child, UserProfilePageComponent)) {
1222
- return;
1223
- }
1224
- const { props } = child;
1225
- import_react20.default.Children.forEach(props.children, (child2) => {
1226
- if (!isThatComponent(child2, MenuActionComponent) && !isThatComponent(child2, MenuLinkComponent)) {
1227
- if (child2) {
1228
- (0, import_utils5.logErrorInDevMode)(customMenuItemsIgnoredComponent);
1229
- }
1230
- return;
1231
- }
1232
- const { props: props2 } = child2;
1233
- const childKey = child2.key;
1234
- const { label, labelIcon, href, onClick, open } = props2;
1235
- if (isThatComponent(child2, MenuActionComponent)) {
1236
- if (isReorderItem2(props2, reorderItemsLabels)) {
1237
- validChildren.push({ label });
1238
- } else if (isCustomMenuItem(props2)) {
1239
- const baseItem = {
1240
- label,
1241
- labelIcon
1242
- };
1243
- if (onClick !== void 0) {
1244
- validChildren.push({
1245
- ...baseItem,
1246
- onClick,
1247
- portalId: getCustomMenuItemPortalId("action", props2, childKey, portalIdCounts)
1248
- });
1249
- } else if (open !== void 0) {
1250
- validChildren.push({
1251
- ...baseItem,
1252
- open: open.startsWith("/") ? open : `/${open}`,
1253
- portalId: getCustomMenuItemPortalId("action", props2, childKey, portalIdCounts)
1254
- });
1255
- } else {
1256
- (0, import_utils5.logErrorInDevMode)("Custom menu item must have either onClick or open property");
1257
- return;
1258
- }
1259
- } else {
1260
- (0, import_utils5.logErrorInDevMode)(userButtonMenuItemsActionWrongsProps);
1261
- return;
1262
- }
1263
- }
1264
- if (isThatComponent(child2, MenuLinkComponent)) {
1265
- if (isExternalLink2(props2)) {
1266
- validChildren.push({
1267
- label,
1268
- labelIcon,
1269
- href,
1270
- portalId: getCustomMenuItemPortalId("link", props2, childKey, portalIdCounts)
1271
- });
1272
- } else {
1273
- (0, import_utils5.logErrorInDevMode)(userButtonMenuItemLinkWrongProps);
1274
- return;
1275
- }
1276
- }
1277
- });
1278
- });
1279
- const customMenuItemLabelIcons = [];
1280
- const customLinkLabelIcons = [];
1281
- validChildren.forEach((mi, index) => {
1282
- if (isCustomMenuItem(mi)) {
1283
- customMenuItemLabelIcons.push({ component: mi.labelIcon, id: mi.portalId || index });
1284
- }
1285
- if (isExternalLink2(mi)) {
1286
- customLinkLabelIcons.push({ component: mi.labelIcon, id: mi.portalId || index });
1287
- }
1288
- });
1289
- const customMenuItemLabelIconsPortals = useCustomElementPortal(customMenuItemLabelIcons);
1290
- const customLinkLabelIconsPortals = useCustomElementPortal(customLinkLabelIcons);
1291
- validChildren.forEach((mi, index) => {
1292
- if (isReorderItem2(mi, reorderItemsLabels)) {
1293
- customMenuItems.push({
1294
- label: mi.label
1295
- });
1296
- }
1297
- if (isCustomMenuItem(mi)) {
1298
- const {
1299
- portal: iconPortal,
1300
- mount: mountIcon,
1301
- unmount: unmountIcon
1302
- } = customMenuItemLabelIconsPortals.find((p) => p.id === (mi.portalId || index));
1303
- const menuItem = {
1304
- label: mi.label,
1305
- mountIcon,
1306
- unmountIcon
1307
- };
1308
- if ("onClick" in mi) {
1309
- menuItem.onClick = mi.onClick;
1310
- } else if ("open" in mi) {
1311
- menuItem.open = mi.open;
1312
- }
1313
- customMenuItems.push(menuItem);
1314
- customMenuItemsPortals.push({ key: `icon:${mi.portalId || index}`, portal: iconPortal });
1315
- }
1316
- if (isExternalLink2(mi)) {
1317
- const {
1318
- portal: iconPortal,
1319
- mount: mountIcon,
1320
- unmount: unmountIcon
1321
- } = customLinkLabelIconsPortals.find((p) => p.id === (mi.portalId || index));
1322
- customMenuItems.push({
1323
- label: mi.label,
1324
- href: mi.href,
1325
- mountIcon,
1326
- unmountIcon
1327
- });
1328
- customMenuItemsPortals.push({ key: `icon:${mi.portalId || index}`, portal: iconPortal });
1329
- }
1330
- });
1331
- return { customMenuItems, customMenuItemsPortals };
1332
- };
1333
- var getCustomMenuItemPortalId = (type, props, key, portalIdCounts) => {
1334
- var _a;
1335
- if (key != null) {
1336
- return `${type}:key:${key}`;
1337
- }
1338
- const target = props.href || props.open || "";
1339
- const baseId = `${type}:${props.label}:${target}`;
1340
- const occurrence = (_a = portalIdCounts.get(baseId)) != null ? _a : 0;
1341
- portalIdCounts.set(baseId, occurrence + 1);
1342
- return `${baseId}:${occurrence}`;
1343
- };
1344
- var isReorderItem2 = (childProps, validItems) => {
1345
- const { children, label, onClick, labelIcon } = childProps;
1346
- return !children && !onClick && !labelIcon && validItems.some((v) => v === label);
1347
- };
1348
- var isCustomMenuItem = (childProps) => {
1349
- const { label, labelIcon, onClick, open } = childProps;
1350
- return !!labelIcon && !!label && (typeof onClick === "function" || typeof open === "string");
1351
- };
1352
- var isExternalLink2 = (childProps) => {
1353
- const { label, href, labelIcon } = childProps;
1354
- return !!href && !!labelIcon && !!label;
1355
- };
1356
-
1357
- // src/components/CheckoutButton.tsx
1358
- var CheckoutButton = withClerk(
1359
- ({ clerk, children, ...props }) => {
1360
- const {
1361
- planId,
1362
- planPeriod,
1363
- seatsQuantity,
1364
- priceId,
1365
- for: _for,
1366
- onSubscriptionComplete,
1367
- newSubscriptionRedirectUrl,
1368
- checkoutProps,
1369
- getContainer,
1370
- component,
1371
- ...rest
1372
- } = props;
1373
- const { userId, orgId } = useAuth();
1374
- if (userId === null) {
1375
- throw new Error(
1376
- 'Clerk: Ensure that `<CheckoutButton />` is rendered only when the user is signed in (wrap with `<Show when="signed-in">` or guard with `useAuth()`).'
1377
- );
1378
- }
1379
- if (orgId === null && _for === "organization") {
1380
- throw new Error(
1381
- 'Clerk: Wrap `<CheckoutButton for="organization" />` with a check for an active organization. Retrieve `orgId` from `useAuth()` and confirm it is defined. For SSR, see: https://clerk.com/docs/reference/backend/types/auth-object#how-to-access-the-auth-object'
1382
- );
1383
- }
1384
- children = normalizeWithDefaultValue(children, "Checkout");
1385
- const child = assertSingleChild(children)("CheckoutButton");
1386
- const clickHandler = () => {
1387
- if (!clerk) {
1388
- return;
1389
- }
1390
- return clerk.__internal_openCheckout({
1391
- planId,
1392
- planPeriod,
1393
- seatsQuantity,
1394
- priceId,
1395
- for: _for,
1396
- onSubscriptionComplete,
1397
- newSubscriptionRedirectUrl,
1398
- ...checkoutProps
1399
- });
1400
- };
1401
- const wrappedChildClickHandler = async (e) => {
1402
- if (child && typeof child === "object" && "props" in child) {
1403
- await safeExecute(child.props.onClick)(e);
1404
- }
1405
- return clickHandler();
1406
- };
1407
- const childProps = { ...rest, onClick: wrappedChildClickHandler };
1408
- return import_react21.default.cloneElement(child, childProps);
1409
- },
1410
- { component: "CheckoutButton", renderWhileLoading: true }
1411
- );
1412
-
1413
- // src/components/PlanDetailsButton.tsx
1414
- var import_react22 = __toESM(require("react"));
1415
- var PlanDetailsButton = withClerk(
1416
- ({ clerk, children, ...props }) => {
1417
- const { plan, planId, initialPlanPeriod, planDetailsProps, getContainer, component, ...rest } = props;
1418
- children = normalizeWithDefaultValue(children, "Plan details");
1419
- const child = assertSingleChild(children)("PlanDetailsButton");
1420
- const clickHandler = () => {
1421
- if (!clerk) {
1422
- return;
1423
- }
1424
- return clerk.__internal_openPlanDetails({
1425
- plan,
1426
- planId,
1427
- initialPlanPeriod,
1428
- ...planDetailsProps
1429
- });
1430
- };
1431
- const wrappedChildClickHandler = async (e) => {
1432
- if (child && typeof child === "object" && "props" in child) {
1433
- await safeExecute(child.props.onClick)(e);
1434
- }
1435
- return clickHandler();
1436
- };
1437
- const childProps = { ...rest, onClick: wrappedChildClickHandler };
1438
- return import_react22.default.cloneElement(child, childProps);
1439
- },
1440
- { component: "PlanDetailsButton", renderWhileLoading: true }
1441
- );
1442
-
1443
- // src/components/SubscriptionDetailsButton.tsx
1444
- var import_react23 = __toESM(require("react"));
1445
- var SubscriptionDetailsButton = withClerk(
1446
- ({
1447
- clerk,
1448
- children,
1449
- ...props
1450
- }) => {
1451
- const { for: _for, subscriptionDetailsProps, onSubscriptionCancel, getContainer, component, ...rest } = props;
1452
- children = normalizeWithDefaultValue(children, "Subscription details");
1453
- const child = assertSingleChild(children)("SubscriptionDetailsButton");
1454
- const { userId, orgId } = useAuth();
1455
- if (userId === null) {
1456
- throw new Error(
1457
- 'Clerk: Ensure that `<SubscriptionDetailsButton />` is rendered only when the user is signed in (wrap with `<Show when="signed-in">` or guard with `useAuth()`).'
1458
- );
1459
- }
1460
- if (orgId === null && _for === "organization") {
1461
- throw new Error(
1462
- 'Clerk: Wrap `<SubscriptionDetailsButton for="organization" />` with a check for an active organization. Retrieve `orgId` from `useAuth()` and confirm it is defined. For SSR, see: https://clerk.com/docs/reference/backend/types/auth-object#how-to-access-the-auth-object'
1463
- );
1464
- }
1465
- const clickHandler = () => {
1466
- if (!clerk) {
1467
- return;
1468
- }
1469
- return clerk.__internal_openSubscriptionDetails({
1470
- for: _for,
1471
- onSubscriptionCancel,
1472
- ...subscriptionDetailsProps
1473
- });
1474
- };
1475
- const wrappedChildClickHandler = async (e) => {
1476
- if (child && typeof child === "object" && "props" in child) {
1477
- await safeExecute(child.props.onClick)(e);
1478
- }
1479
- return clickHandler();
1480
- };
1481
- const childProps = { ...rest, onClick: wrappedChildClickHandler };
1482
- return import_react23.default.cloneElement(child, childProps);
1483
- },
1484
- { component: "SubscriptionDetailsButton", renderWhileLoading: true }
1485
- );
1486
-
1487
- // src/experimental.ts
1488
- var import_react24 = require("@clerk/shared/react");
1489
- // Annotate the CommonJS export names for ESM import in node:
1490
- 0 && (module.exports = {
1491
- CheckoutButton,
1492
- CheckoutProvider,
1493
- PaymentElement,
1494
- PaymentElementProvider,
1495
- PlanDetailsButton,
1496
- SubscriptionDetailsButton,
1497
- useCheckout,
1498
- usePaymentAttempts,
1499
- usePaymentElement,
1500
- usePaymentMethods,
1501
- usePlans,
1502
- useStatements,
1503
- useSubscription
1504
- });
1505
- //# sourceMappingURL=experimental.js.map