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