UNPKG

@clerk/clerk-react

Version:

Clerk React library

1 lines • 68.4 kB
{"version":3,"sources":["../src/components/uiComponents.tsx","../src/utils/childrenUtils.tsx","../src/utils/isConstructor.ts","../src/utils/useMaxAllowedInstancesGuard.tsx","../src/utils/useCustomElementPortal.tsx","../src/utils/useCustomPages.tsx","../src/utils/componentValidation.ts","../src/utils/useCustomMenuItems.tsx","../src/utils/useWaitForComponentMount.ts","../src/components/ClerkHostRenderer.tsx"],"sourcesContent":["import { logErrorInDevMode } from '@clerk/shared/utils';\nimport type {\n APIKeysProps,\n CreateOrganizationProps,\n GoogleOneTapProps,\n OrganizationListProps,\n OrganizationProfileProps,\n OrganizationSwitcherProps,\n PricingTableProps,\n SignInProps,\n SignUpProps,\n TaskChooseOrganizationProps,\n UserButtonProps,\n UserProfileProps,\n WaitlistProps,\n Without,\n} from '@clerk/types';\nimport type { PropsWithChildren, ReactNode } from 'react';\nimport React, { createContext, createElement, useContext } from 'react';\n\nimport {\n organizationProfileLinkRenderedError,\n organizationProfilePageRenderedError,\n userButtonMenuActionRenderedError,\n userButtonMenuItemsRenderedError,\n userButtonMenuLinkRenderedError,\n userProfileLinkRenderedError,\n userProfilePageRenderedError,\n} from '../errors/messages';\nimport type {\n CustomPortalsRendererProps,\n MountProps,\n OrganizationProfileLinkProps,\n OrganizationProfilePageProps,\n UserButtonActionProps,\n UserButtonLinkProps,\n UserProfileLinkProps,\n UserProfilePageProps,\n WithClerkProp,\n} from '../types';\nimport {\n useOrganizationProfileCustomPages,\n useSanitizedChildren,\n useUserButtonCustomMenuItems,\n useUserProfileCustomPages,\n} from '../utils';\nimport { useWaitForComponentMount } from '../utils/useWaitForComponentMount';\nimport { ClerkHostRenderer } from './ClerkHostRenderer';\nimport { withClerk } from './withClerk';\n\ntype FallbackProp = {\n /**\n * An optional element to render while the component is mounting.\n */\n fallback?: ReactNode;\n};\n\ntype UserProfileExportType = typeof _UserProfile & {\n Page: typeof UserProfilePage;\n Link: typeof UserProfileLink;\n};\n\ntype UserButtonExportType = typeof _UserButton & {\n UserProfilePage: typeof UserProfilePage;\n UserProfileLink: typeof UserProfileLink;\n MenuItems: typeof MenuItems;\n Action: typeof MenuAction;\n Link: typeof MenuLink;\n /**\n * The `<Outlet />` component can be used in conjunction with `asProvider` in order to control rendering\n * of the `<UserButton />` without affecting its configuration or any custom pages that could be mounted\n * @experimental This API is experimental and may change at any moment.\n */\n __experimental_Outlet: typeof UserButtonOutlet;\n};\n\ntype UserButtonPropsWithoutCustomPages = Without<\n UserButtonProps,\n 'userProfileProps' | '__experimental_asStandalone'\n> & {\n userProfileProps?: Pick<UserProfileProps, 'additionalOAuthScopes' | 'appearance'>;\n /**\n * Adding `asProvider` will defer rendering until the `<Outlet />` component is mounted.\n * This API is experimental and may change at any moment.\n * @experimental\n * @default undefined\n */\n __experimental_asProvider?: boolean;\n};\n\ntype OrganizationProfileExportType = typeof _OrganizationProfile & {\n Page: typeof OrganizationProfilePage;\n Link: typeof OrganizationProfileLink;\n};\n\ntype OrganizationSwitcherExportType = typeof _OrganizationSwitcher & {\n OrganizationProfilePage: typeof OrganizationProfilePage;\n OrganizationProfileLink: typeof OrganizationProfileLink;\n /**\n * The `<Outlet />` component can be used in conjunction with `asProvider` in order to control rendering\n * of the `<OrganizationSwitcher />` without affecting its configuration or any custom pages that could be mounted\n * @experimental This API is experimental and may change at any moment.\n */\n __experimental_Outlet: typeof OrganizationSwitcherOutlet;\n};\n\ntype OrganizationSwitcherPropsWithoutCustomPages = Without<\n OrganizationSwitcherProps,\n 'organizationProfileProps' | '__experimental_asStandalone'\n> & {\n organizationProfileProps?: Pick<OrganizationProfileProps, 'appearance'>;\n /**\n * Adding `asProvider` will defer rendering until the `<Outlet />` component is mounted.\n * This API is experimental and may change at any moment.\n * @experimental\n * @default undefined\n */\n __experimental_asProvider?: boolean;\n};\n\nconst CustomPortalsRenderer = (props: CustomPortalsRendererProps) => {\n return (\n <>\n {props?.customPagesPortals?.map((portal, index) => createElement(portal, { key: index }))}\n {props?.customMenuItemsPortals?.map((portal, index) => createElement(portal, { key: index }))}\n </>\n );\n};\n\nexport const SignIn = withClerk(\n ({ clerk, component, fallback, ...props }: WithClerkProp<SignInProps & FallbackProp>) => {\n const mountingStatus = useWaitForComponentMount(component);\n const shouldShowFallback = mountingStatus === 'rendering' || !clerk.loaded;\n\n const rendererRootProps = {\n ...(shouldShowFallback && fallback && { style: { display: 'none' } }),\n };\n\n return (\n <>\n {shouldShowFallback && fallback}\n {clerk.loaded && (\n <ClerkHostRenderer\n component={component}\n mount={clerk.mountSignIn}\n unmount={clerk.unmountSignIn}\n updateProps={(clerk as any).__unstable__updateProps}\n props={props}\n rootProps={rendererRootProps}\n />\n )}\n </>\n );\n },\n { component: 'SignIn', renderWhileLoading: true },\n);\n\nexport const SignUp = withClerk(\n ({ clerk, component, fallback, ...props }: WithClerkProp<SignUpProps & FallbackProp>) => {\n const mountingStatus = useWaitForComponentMount(component);\n const shouldShowFallback = mountingStatus === 'rendering' || !clerk.loaded;\n\n const rendererRootProps = {\n ...(shouldShowFallback && fallback && { style: { display: 'none' } }),\n };\n\n return (\n <>\n {shouldShowFallback && fallback}\n {clerk.loaded && (\n <ClerkHostRenderer\n component={component}\n mount={clerk.mountSignUp}\n unmount={clerk.unmountSignUp}\n updateProps={(clerk as any).__unstable__updateProps}\n props={props}\n rootProps={rendererRootProps}\n />\n )}\n </>\n );\n },\n { component: 'SignUp', renderWhileLoading: true },\n);\n\nexport function UserProfilePage({ children }: PropsWithChildren<UserProfilePageProps>) {\n logErrorInDevMode(userProfilePageRenderedError);\n return <>{children}</>;\n}\n\nexport function UserProfileLink({ children }: PropsWithChildren<UserProfileLinkProps>) {\n logErrorInDevMode(userProfileLinkRenderedError);\n return <>{children}</>;\n}\n\nconst _UserProfile = withClerk(\n ({\n clerk,\n component,\n fallback,\n ...props\n }: WithClerkProp<PropsWithChildren<Without<UserProfileProps, 'customPages'>> & FallbackProp>) => {\n const mountingStatus = useWaitForComponentMount(component);\n const shouldShowFallback = mountingStatus === 'rendering' || !clerk.loaded;\n\n const rendererRootProps = {\n ...(shouldShowFallback && fallback && { style: { display: 'none' } }),\n };\n\n const { customPages, customPagesPortals } = useUserProfileCustomPages(props.children);\n return (\n <>\n {shouldShowFallback && fallback}\n <ClerkHostRenderer\n component={component}\n mount={clerk.mountUserProfile}\n unmount={clerk.unmountUserProfile}\n updateProps={(clerk as any).__unstable__updateProps}\n props={{ ...props, customPages }}\n rootProps={rendererRootProps}\n >\n <CustomPortalsRenderer customPagesPortals={customPagesPortals} />\n </ClerkHostRenderer>\n </>\n );\n },\n { component: 'UserProfile', renderWhileLoading: true },\n);\n\nexport const UserProfile: UserProfileExportType = Object.assign(_UserProfile, {\n Page: UserProfilePage,\n Link: UserProfileLink,\n});\n\nconst UserButtonContext = createContext<MountProps>({\n mount: () => {},\n unmount: () => {},\n updateProps: () => {},\n});\n\nconst _UserButton = withClerk(\n ({\n clerk,\n component,\n fallback,\n ...props\n }: WithClerkProp<PropsWithChildren<UserButtonPropsWithoutCustomPages> & FallbackProp>) => {\n const mountingStatus = useWaitForComponentMount(component);\n const shouldShowFallback = mountingStatus === 'rendering' || !clerk.loaded;\n\n const rendererRootProps = {\n ...(shouldShowFallback && fallback && { style: { display: 'none' } }),\n };\n\n const { customPages, customPagesPortals } = useUserProfileCustomPages(props.children, {\n allowForAnyChildren: !!props.__experimental_asProvider,\n });\n const userProfileProps = Object.assign(props.userProfileProps || {}, { customPages });\n const { customMenuItems, customMenuItemsPortals } = useUserButtonCustomMenuItems(props.children);\n const sanitizedChildren = useSanitizedChildren(props.children);\n\n const passableProps = {\n mount: clerk.mountUserButton,\n unmount: clerk.unmountUserButton,\n updateProps: (clerk as any).__unstable__updateProps,\n props: { ...props, userProfileProps, customMenuItems },\n };\n const portalProps = {\n customPagesPortals: customPagesPortals,\n customMenuItemsPortals: customMenuItemsPortals,\n };\n\n return (\n <UserButtonContext.Provider value={passableProps}>\n {shouldShowFallback && fallback}\n {clerk.loaded && (\n <ClerkHostRenderer\n component={component}\n {...passableProps}\n hideRootHtmlElement={!!props.__experimental_asProvider}\n rootProps={rendererRootProps}\n >\n {/*This mimics the previous behaviour before asProvider existed*/}\n {props.__experimental_asProvider ? sanitizedChildren : null}\n <CustomPortalsRenderer {...portalProps} />\n </ClerkHostRenderer>\n )}\n </UserButtonContext.Provider>\n );\n },\n { component: 'UserButton', renderWhileLoading: true },\n);\n\nexport function MenuItems({ children }: PropsWithChildren) {\n logErrorInDevMode(userButtonMenuItemsRenderedError);\n return <>{children}</>;\n}\n\nexport function MenuAction({ children }: PropsWithChildren<UserButtonActionProps>) {\n logErrorInDevMode(userButtonMenuActionRenderedError);\n return <>{children}</>;\n}\n\nexport function MenuLink({ children }: PropsWithChildren<UserButtonLinkProps>) {\n logErrorInDevMode(userButtonMenuLinkRenderedError);\n return <>{children}</>;\n}\n\nexport function UserButtonOutlet(outletProps: Without<UserButtonProps, 'userProfileProps'>) {\n const providerProps = useContext(UserButtonContext);\n\n const portalProps = {\n ...providerProps,\n props: {\n ...providerProps.props,\n ...outletProps,\n },\n } satisfies MountProps;\n\n return <ClerkHostRenderer {...portalProps} />;\n}\n\nexport const UserButton: UserButtonExportType = Object.assign(_UserButton, {\n UserProfilePage,\n UserProfileLink,\n MenuItems,\n Action: MenuAction,\n Link: MenuLink,\n __experimental_Outlet: UserButtonOutlet,\n});\n\nexport function OrganizationProfilePage({ children }: PropsWithChildren<OrganizationProfilePageProps>) {\n logErrorInDevMode(organizationProfilePageRenderedError);\n return <>{children}</>;\n}\n\nexport function OrganizationProfileLink({ children }: PropsWithChildren<OrganizationProfileLinkProps>) {\n logErrorInDevMode(organizationProfileLinkRenderedError);\n return <>{children}</>;\n}\n\nconst _OrganizationProfile = withClerk(\n ({\n clerk,\n component,\n fallback,\n ...props\n }: WithClerkProp<PropsWithChildren<Without<OrganizationProfileProps, 'customPages'>> & FallbackProp>) => {\n const mountingStatus = useWaitForComponentMount(component);\n const shouldShowFallback = mountingStatus === 'rendering' || !clerk.loaded;\n\n const rendererRootProps = {\n ...(shouldShowFallback && fallback && { style: { display: 'none' } }),\n };\n\n const { customPages, customPagesPortals } = useOrganizationProfileCustomPages(props.children);\n return (\n <>\n {shouldShowFallback && fallback}\n {clerk.loaded && (\n <ClerkHostRenderer\n component={component}\n mount={clerk.mountOrganizationProfile}\n unmount={clerk.unmountOrganizationProfile}\n updateProps={(clerk as any).__unstable__updateProps}\n props={{ ...props, customPages }}\n rootProps={rendererRootProps}\n >\n <CustomPortalsRenderer customPagesPortals={customPagesPortals} />\n </ClerkHostRenderer>\n )}\n </>\n );\n },\n { component: 'OrganizationProfile', renderWhileLoading: true },\n);\n\nexport const OrganizationProfile: OrganizationProfileExportType = Object.assign(_OrganizationProfile, {\n Page: OrganizationProfilePage,\n Link: OrganizationProfileLink,\n});\n\nexport const CreateOrganization = withClerk(\n ({ clerk, component, fallback, ...props }: WithClerkProp<CreateOrganizationProps & FallbackProp>) => {\n const mountingStatus = useWaitForComponentMount(component);\n const shouldShowFallback = mountingStatus === 'rendering' || !clerk.loaded;\n\n const rendererRootProps = {\n ...(shouldShowFallback && fallback && { style: { display: 'none' } }),\n };\n\n return (\n <>\n {shouldShowFallback && fallback}\n {clerk.loaded && (\n <ClerkHostRenderer\n component={component}\n mount={clerk.mountCreateOrganization}\n unmount={clerk.unmountCreateOrganization}\n updateProps={(clerk as any).__unstable__updateProps}\n props={props}\n rootProps={rendererRootProps}\n />\n )}\n </>\n );\n },\n { component: 'CreateOrganization', renderWhileLoading: true },\n);\n\nconst OrganizationSwitcherContext = createContext<MountProps>({\n mount: () => {},\n unmount: () => {},\n updateProps: () => {},\n});\n\nconst _OrganizationSwitcher = withClerk(\n ({\n clerk,\n component,\n fallback,\n ...props\n }: WithClerkProp<PropsWithChildren<OrganizationSwitcherPropsWithoutCustomPages> & FallbackProp>) => {\n const mountingStatus = useWaitForComponentMount(component);\n const shouldShowFallback = mountingStatus === 'rendering' || !clerk.loaded;\n\n const rendererRootProps = {\n ...(shouldShowFallback && fallback && { style: { display: 'none' } }),\n };\n\n const { customPages, customPagesPortals } = useOrganizationProfileCustomPages(props.children, {\n allowForAnyChildren: !!props.__experimental_asProvider,\n });\n const organizationProfileProps = Object.assign(props.organizationProfileProps || {}, { customPages });\n const sanitizedChildren = useSanitizedChildren(props.children);\n\n const passableProps = {\n mount: clerk.mountOrganizationSwitcher,\n unmount: clerk.unmountOrganizationSwitcher,\n updateProps: (clerk as any).__unstable__updateProps,\n props: { ...props, organizationProfileProps },\n rootProps: rendererRootProps,\n component,\n };\n\n /**\n * Prefetch organization list\n */\n clerk.__experimental_prefetchOrganizationSwitcher();\n\n return (\n <OrganizationSwitcherContext.Provider value={passableProps}>\n <>\n {shouldShowFallback && fallback}\n {clerk.loaded && (\n <ClerkHostRenderer\n {...passableProps}\n hideRootHtmlElement={!!props.__experimental_asProvider}\n >\n {/*This mimics the previous behaviour before asProvider existed*/}\n {props.__experimental_asProvider ? sanitizedChildren : null}\n <CustomPortalsRenderer customPagesPortals={customPagesPortals} />\n </ClerkHostRenderer>\n )}\n </>\n </OrganizationSwitcherContext.Provider>\n );\n },\n { component: 'OrganizationSwitcher', renderWhileLoading: true },\n);\n\nexport function OrganizationSwitcherOutlet(\n outletProps: Without<OrganizationSwitcherProps, 'organizationProfileProps'>,\n) {\n const providerProps = useContext(OrganizationSwitcherContext);\n\n const portalProps = {\n ...providerProps,\n props: {\n ...providerProps.props,\n ...outletProps,\n },\n } satisfies MountProps;\n\n return <ClerkHostRenderer {...portalProps} />;\n}\n\nexport const OrganizationSwitcher: OrganizationSwitcherExportType = Object.assign(_OrganizationSwitcher, {\n OrganizationProfilePage,\n OrganizationProfileLink,\n __experimental_Outlet: OrganizationSwitcherOutlet,\n});\n\nexport const OrganizationList = withClerk(\n ({ clerk, component, fallback, ...props }: WithClerkProp<OrganizationListProps & FallbackProp>) => {\n const mountingStatus = useWaitForComponentMount(component);\n const shouldShowFallback = mountingStatus === 'rendering' || !clerk.loaded;\n\n const rendererRootProps = {\n ...(shouldShowFallback && fallback && { style: { display: 'none' } }),\n };\n\n return (\n <>\n {shouldShowFallback && fallback}\n {clerk.loaded && (\n <ClerkHostRenderer\n component={component}\n mount={clerk.mountOrganizationList}\n unmount={clerk.unmountOrganizationList}\n updateProps={(clerk as any).__unstable__updateProps}\n props={props}\n rootProps={rendererRootProps}\n />\n )}\n </>\n );\n },\n { component: 'OrganizationList', renderWhileLoading: true },\n);\n\nexport const GoogleOneTap = withClerk(\n ({ clerk, component, fallback, ...props }: WithClerkProp<GoogleOneTapProps & FallbackProp>) => {\n const mountingStatus = useWaitForComponentMount(component);\n const shouldShowFallback = mountingStatus === 'rendering' || !clerk.loaded;\n\n const rendererRootProps = {\n ...(shouldShowFallback && fallback && { style: { display: 'none' } }),\n };\n\n return (\n <>\n {shouldShowFallback && fallback}\n {clerk.loaded && (\n <ClerkHostRenderer\n component={component}\n open={clerk.openGoogleOneTap}\n close={clerk.closeGoogleOneTap}\n updateProps={(clerk as any).__unstable__updateProps}\n props={props}\n rootProps={rendererRootProps}\n />\n )}\n </>\n );\n },\n { component: 'GoogleOneTap', renderWhileLoading: true },\n);\n\nexport const Waitlist = withClerk(\n ({ clerk, component, fallback, ...props }: WithClerkProp<WaitlistProps & FallbackProp>) => {\n const mountingStatus = useWaitForComponentMount(component);\n const shouldShowFallback = mountingStatus === 'rendering' || !clerk.loaded;\n\n const rendererRootProps = {\n ...(shouldShowFallback && fallback && { style: { display: 'none' } }),\n };\n\n return (\n <>\n {shouldShowFallback && fallback}\n {clerk.loaded && (\n <ClerkHostRenderer\n component={component}\n mount={clerk.mountWaitlist}\n unmount={clerk.unmountWaitlist}\n updateProps={(clerk as any).__unstable__updateProps}\n props={props}\n rootProps={rendererRootProps}\n />\n )}\n </>\n );\n },\n { component: 'Waitlist', renderWhileLoading: true },\n);\n\nexport const PricingTable = withClerk(\n ({ clerk, component, fallback, ...props }: WithClerkProp<PricingTableProps & FallbackProp>) => {\n const mountingStatus = useWaitForComponentMount(component);\n const shouldShowFallback = mountingStatus === 'rendering' || !clerk.loaded;\n\n const rendererRootProps = {\n ...(shouldShowFallback && fallback && { style: { display: 'none' } }),\n };\n\n return (\n <>\n {shouldShowFallback && fallback}\n {clerk.loaded && (\n <ClerkHostRenderer\n component={component}\n mount={clerk.mountPricingTable}\n unmount={clerk.unmountPricingTable}\n updateProps={(clerk as any).__unstable__updateProps}\n props={props}\n rootProps={rendererRootProps}\n />\n )}\n </>\n );\n },\n { component: 'PricingTable', renderWhileLoading: true },\n);\n\n/**\n * @experimental\n * This component is in early access and may change in future releases.\n */\nexport const APIKeys = withClerk(\n ({ clerk, component, fallback, ...props }: WithClerkProp<APIKeysProps & FallbackProp>) => {\n const mountingStatus = useWaitForComponentMount(component);\n const shouldShowFallback = mountingStatus === 'rendering' || !clerk.loaded;\n\n const rendererRootProps = {\n ...(shouldShowFallback && fallback && { style: { display: 'none' } }),\n };\n\n return (\n <>\n {shouldShowFallback && fallback}\n {clerk.loaded && (\n <ClerkHostRenderer\n component={component}\n mount={clerk.mountApiKeys}\n unmount={clerk.unmountApiKeys}\n updateProps={(clerk as any).__unstable__updateProps}\n props={props}\n rootProps={rendererRootProps}\n />\n )}\n </>\n );\n },\n { component: 'ApiKeys', renderWhileLoading: true },\n);\n\nexport const TaskChooseOrganization = withClerk(\n ({ clerk, component, fallback, ...props }: WithClerkProp<TaskChooseOrganizationProps & FallbackProp>) => {\n const mountingStatus = useWaitForComponentMount(component);\n const shouldShowFallback = mountingStatus === 'rendering' || !clerk.loaded;\n\n const rendererRootProps = {\n ...(shouldShowFallback && fallback && { style: { display: 'none' } }),\n };\n\n return (\n <>\n {shouldShowFallback && fallback}\n {clerk.loaded && (\n <ClerkHostRenderer\n component={component}\n mount={clerk.mountTaskChooseOrganization}\n unmount={clerk.unmountTaskChooseOrganization}\n updateProps={(clerk as any).__unstable__updateProps}\n props={props}\n rootProps={rendererRootProps}\n />\n )}\n </>\n );\n },\n { component: 'TaskChooseOrganization', renderWhileLoading: true },\n);\n","import React from 'react';\n\nimport { errorThrower } from '../errors/errorThrower';\nimport { multipleChildrenInButtonComponent } from '../errors/messages';\n\nexport const assertSingleChild =\n (children: React.ReactNode) =>\n (\n name:\n | 'SignInButton'\n | 'SignUpButton'\n | 'SignOutButton'\n | 'SignInWithMetamaskButton'\n | 'CheckoutButton'\n | 'SubscriptionDetailsButton'\n | 'PlanDetailsButton',\n ) => {\n try {\n return React.Children.only(children);\n } catch {\n return errorThrower.throw(multipleChildrenInButtonComponent(name));\n }\n };\n\nexport const normalizeWithDefaultValue = (children: React.ReactNode | undefined, defaultText: string) => {\n if (!children) {\n children = defaultText;\n }\n if (typeof children === 'string') {\n children = <button>{children}</button>;\n }\n return children;\n};\n\nexport const safeExecute =\n (cb: unknown) =>\n (...args: any) => {\n if (cb && typeof cb === 'function') {\n return cb(...args);\n }\n };\n","export function isConstructor<T>(f: any): f is T {\n return typeof f === 'function';\n}\n","import React from 'react';\n\nimport { errorThrower } from '../errors/errorThrower';\n\nconst counts = new Map<string, number>();\n\nexport function useMaxAllowedInstancesGuard(name: string, error: string, maxCount = 1): void {\n React.useEffect(() => {\n const count = counts.get(name) || 0;\n if (count == maxCount) {\n return errorThrower.throw(error);\n }\n counts.set(name, count + 1);\n\n return () => {\n counts.set(name, (counts.get(name) || 1) - 1);\n };\n }, []);\n}\n\nexport function withMaxAllowedInstancesGuard<P>(\n WrappedComponent: React.ComponentType<P>,\n name: string,\n error: string,\n): React.ComponentType<P> {\n const displayName = WrappedComponent.displayName || WrappedComponent.name || name || 'Component';\n const Hoc = (props: P) => {\n useMaxAllowedInstancesGuard(name, error);\n return <WrappedComponent {...(props as any)} />;\n };\n Hoc.displayName = `withMaxAllowedInstancesGuard(${displayName})`;\n return Hoc;\n}\n","import type React from 'react';\nimport { useState } from 'react';\nimport { createPortal } from 'react-dom';\n\nexport type UseCustomElementPortalParams = {\n component: React.ReactNode;\n id: number;\n};\n\nexport type UseCustomElementPortalReturn = {\n portal: () => React.JSX.Element;\n mount: (node: Element) => void;\n unmount: () => void;\n id: number;\n};\n\n// This function takes a component as prop, and returns functions that mount and unmount\n// the given component into a given node\nexport const useCustomElementPortal = (elements: UseCustomElementPortalParams[]) => {\n const [nodeMap, setNodeMap] = useState<Map<string, Element | null>>(new Map());\n\n return elements.map(el => ({\n id: el.id,\n mount: (node: Element) => setNodeMap(prev => new Map(prev).set(String(el.id), node)),\n unmount: () =>\n setNodeMap(prev => {\n const newMap = new Map(prev);\n newMap.set(String(el.id), null);\n return newMap;\n }),\n portal: () => {\n const node = nodeMap.get(String(el.id));\n return node ? createPortal(el.component, node) : null;\n },\n }));\n};\n","import { logErrorInDevMode } from '@clerk/shared/utils';\nimport type { CustomPage } from '@clerk/types';\nimport type { ReactElement } from 'react';\nimport React from 'react';\n\nimport {\n MenuItems,\n OrganizationProfileLink,\n OrganizationProfilePage,\n UserProfileLink,\n UserProfilePage,\n} from '../components/uiComponents';\nimport { customLinkWrongProps, customPagesIgnoredComponent, customPageWrongProps } from '../errors/messages';\nimport type { UserProfilePageProps } from '../types';\nimport { isThatComponent } from './componentValidation';\nimport type { UseCustomElementPortalParams, UseCustomElementPortalReturn } from './useCustomElementPortal';\nimport { useCustomElementPortal } from './useCustomElementPortal';\n\nexport const useUserProfileCustomPages = (\n children: React.ReactNode | React.ReactNode[],\n options?: UseCustomPagesOptions,\n) => {\n const reorderItemsLabels = ['account', 'security'];\n return useCustomPages(\n {\n children,\n reorderItemsLabels,\n LinkComponent: UserProfileLink,\n PageComponent: UserProfilePage,\n MenuItemsComponent: MenuItems,\n componentName: 'UserProfile',\n },\n options,\n );\n};\n\nexport const useOrganizationProfileCustomPages = (\n children: React.ReactNode | React.ReactNode[],\n options?: UseCustomPagesOptions,\n) => {\n const reorderItemsLabels = ['general', 'members'];\n return useCustomPages(\n {\n children,\n reorderItemsLabels,\n LinkComponent: OrganizationProfileLink,\n PageComponent: OrganizationProfilePage,\n componentName: 'OrganizationProfile',\n },\n options,\n );\n};\n\ntype UseCustomPagesParams = {\n children: React.ReactNode | React.ReactNode[];\n LinkComponent: any;\n PageComponent: any;\n MenuItemsComponent?: any;\n reorderItemsLabels: string[];\n componentName: string;\n};\n\ntype UseCustomPagesOptions = {\n allowForAnyChildren: boolean;\n};\n\ntype CustomPageWithIdType = UserProfilePageProps & { children?: React.ReactNode };\n\n/**\n * Exclude any children that is used for identifying Custom Pages or Custom Items.\n * Passing:\n * ```tsx\n * <UserProfile.Page/>\n * <OrganizationProfile.Link/>\n * <MyComponent>\n * <UserButton.MenuItems/>\n * ```\n * Gives back\n * ```tsx\n * <MyComponent>\n * ````\n */\nexport const useSanitizedChildren = (children: React.ReactNode) => {\n const sanitizedChildren: React.ReactNode[] = [];\n\n const excludedComponents: any[] = [\n OrganizationProfileLink,\n OrganizationProfilePage,\n MenuItems,\n UserProfilePage,\n UserProfileLink,\n ];\n\n React.Children.forEach(children, child => {\n if (!excludedComponents.some(component => isThatComponent(child, component))) {\n sanitizedChildren.push(child);\n }\n });\n\n return sanitizedChildren;\n};\n\nconst useCustomPages = (params: UseCustomPagesParams, options?: UseCustomPagesOptions) => {\n const { children, LinkComponent, PageComponent, MenuItemsComponent, reorderItemsLabels, componentName } = params;\n const { allowForAnyChildren = false } = options || {};\n const validChildren: CustomPageWithIdType[] = [];\n\n React.Children.forEach(children, child => {\n if (\n !isThatComponent(child, PageComponent) &&\n !isThatComponent(child, LinkComponent) &&\n !isThatComponent(child, MenuItemsComponent)\n ) {\n if (child && !allowForAnyChildren) {\n logErrorInDevMode(customPagesIgnoredComponent(componentName));\n }\n return;\n }\n\n const { props } = child as ReactElement;\n\n const { children, label, url, labelIcon } = props;\n\n if (isThatComponent(child, PageComponent)) {\n if (isReorderItem(props, reorderItemsLabels)) {\n // This is a reordering item\n validChildren.push({ label });\n } else if (isCustomPage(props)) {\n // this is a custom page\n validChildren.push({ label, labelIcon, children, url });\n } else {\n logErrorInDevMode(customPageWrongProps(componentName));\n return;\n }\n }\n\n if (isThatComponent(child, LinkComponent)) {\n if (isExternalLink(props)) {\n // This is an external link\n validChildren.push({ label, labelIcon, url });\n } else {\n logErrorInDevMode(customLinkWrongProps(componentName));\n return;\n }\n }\n });\n\n const customPageContents: UseCustomElementPortalParams[] = [];\n const customPageLabelIcons: UseCustomElementPortalParams[] = [];\n const customLinkLabelIcons: UseCustomElementPortalParams[] = [];\n\n validChildren.forEach((cp, index) => {\n if (isCustomPage(cp)) {\n customPageContents.push({ component: cp.children, id: index });\n customPageLabelIcons.push({ component: cp.labelIcon, id: index });\n return;\n }\n if (isExternalLink(cp)) {\n customLinkLabelIcons.push({ component: cp.labelIcon, id: index });\n }\n });\n\n const customPageContentsPortals = useCustomElementPortal(customPageContents);\n const customPageLabelIconsPortals = useCustomElementPortal(customPageLabelIcons);\n const customLinkLabelIconsPortals = useCustomElementPortal(customLinkLabelIcons);\n\n const customPages: CustomPage[] = [];\n const customPagesPortals: React.ComponentType[] = [];\n\n validChildren.forEach((cp, index) => {\n if (isReorderItem(cp, reorderItemsLabels)) {\n customPages.push({ label: cp.label });\n return;\n }\n if (isCustomPage(cp)) {\n const {\n portal: contentPortal,\n mount,\n unmount,\n } = customPageContentsPortals.find(p => p.id === index) as UseCustomElementPortalReturn;\n const {\n portal: labelPortal,\n mount: mountIcon,\n unmount: unmountIcon,\n } = customPageLabelIconsPortals.find(p => p.id === index) as UseCustomElementPortalReturn;\n customPages.push({ label: cp.label, url: cp.url, mount, unmount, mountIcon, unmountIcon });\n customPagesPortals.push(contentPortal);\n customPagesPortals.push(labelPortal);\n return;\n }\n if (isExternalLink(cp)) {\n const {\n portal: labelPortal,\n mount: mountIcon,\n unmount: unmountIcon,\n } = customLinkLabelIconsPortals.find(p => p.id === index) as UseCustomElementPortalReturn;\n customPages.push({ label: cp.label, url: cp.url, mountIcon, unmountIcon });\n customPagesPortals.push(labelPortal);\n return;\n }\n });\n\n return { customPages, customPagesPortals };\n};\n\nconst isReorderItem = (childProps: any, validItems: string[]): boolean => {\n const { children, label, url, labelIcon } = childProps;\n return !children && !url && !labelIcon && validItems.some(v => v === label);\n};\n\nconst isCustomPage = (childProps: any): boolean => {\n const { children, label, url, labelIcon } = childProps;\n return !!children && !!url && !!labelIcon && !!label;\n};\n\nconst isExternalLink = (childProps: any): boolean => {\n const { children, label, url, labelIcon } = childProps;\n return !children && !!url && !!labelIcon && !!label;\n};\n","import React from 'react';\n\nexport const isThatComponent = (v: any, component: React.ReactNode): v is React.ReactNode => {\n return !!v && React.isValidElement(v) && (v as React.ReactElement)?.type === component;\n};\n","import { logErrorInDevMode } from '@clerk/shared/utils';\nimport type { CustomMenuItem } from '@clerk/types';\nimport type { ReactElement } from 'react';\nimport React from 'react';\n\nimport { MenuAction, MenuItems, MenuLink, UserProfileLink, UserProfilePage } from '../components/uiComponents';\nimport {\n customMenuItemsIgnoredComponent,\n userButtonIgnoredComponent,\n userButtonMenuItemLinkWrongProps,\n userButtonMenuItemsActionWrongsProps,\n} from '../errors/messages';\nimport type { UserButtonActionProps, UserButtonLinkProps } from '../types';\nimport { isThatComponent } from './componentValidation';\nimport type { UseCustomElementPortalParams, UseCustomElementPortalReturn } from './useCustomElementPortal';\nimport { useCustomElementPortal } from './useCustomElementPortal';\n\nexport const useUserButtonCustomMenuItems = (children: React.ReactNode | React.ReactNode[]) => {\n const reorderItemsLabels = ['manageAccount', 'signOut'];\n return useCustomMenuItems({\n children,\n reorderItemsLabels,\n MenuItemsComponent: MenuItems,\n MenuActionComponent: MenuAction,\n MenuLinkComponent: MenuLink,\n UserProfileLinkComponent: UserProfileLink,\n UserProfilePageComponent: UserProfilePage,\n });\n};\n\ntype UseCustomMenuItemsParams = {\n children: React.ReactNode | React.ReactNode[];\n MenuItemsComponent?: any;\n MenuActionComponent?: any;\n MenuLinkComponent?: any;\n UserProfileLinkComponent?: any;\n UserProfilePageComponent?: any;\n reorderItemsLabels: string[];\n};\n\ntype CustomMenuItemType = UserButtonActionProps | UserButtonLinkProps;\n\nconst useCustomMenuItems = ({\n children,\n MenuItemsComponent,\n MenuActionComponent,\n MenuLinkComponent,\n UserProfileLinkComponent,\n UserProfilePageComponent,\n reorderItemsLabels,\n}: UseCustomMenuItemsParams) => {\n const validChildren: CustomMenuItemType[] = [];\n const customMenuItems: CustomMenuItem[] = [];\n const customMenuItemsPortals: React.ComponentType[] = [];\n\n React.Children.forEach(children, child => {\n if (\n !isThatComponent(child, MenuItemsComponent) &&\n !isThatComponent(child, UserProfileLinkComponent) &&\n !isThatComponent(child, UserProfilePageComponent)\n ) {\n if (child) {\n logErrorInDevMode(userButtonIgnoredComponent);\n }\n return;\n }\n\n // Ignore UserProfileLinkComponent and UserProfilePageComponent\n if (isThatComponent(child, UserProfileLinkComponent) || isThatComponent(child, UserProfilePageComponent)) {\n return;\n }\n\n // Menu items children\n const { props } = child as ReactElement;\n\n React.Children.forEach(props.children, child => {\n if (!isThatComponent(child, MenuActionComponent) && !isThatComponent(child, MenuLinkComponent)) {\n if (child) {\n logErrorInDevMode(customMenuItemsIgnoredComponent);\n }\n\n return;\n }\n\n const { props } = child as ReactElement;\n\n const { label, labelIcon, href, onClick, open } = props;\n\n if (isThatComponent(child, MenuActionComponent)) {\n if (isReorderItem(props, reorderItemsLabels)) {\n // This is a reordering item\n validChildren.push({ label });\n } else if (isCustomMenuItem(props)) {\n const baseItem = {\n label,\n labelIcon,\n };\n\n if (onClick !== undefined) {\n validChildren.push({\n ...baseItem,\n onClick,\n });\n } else if (open !== undefined) {\n validChildren.push({\n ...baseItem,\n open: open.startsWith('/') ? open : `/${open}`,\n });\n } else {\n // Handle the case where neither onClick nor open is defined\n logErrorInDevMode('Custom menu item must have either onClick or open property');\n return;\n }\n } else {\n logErrorInDevMode(userButtonMenuItemsActionWrongsProps);\n return;\n }\n }\n\n if (isThatComponent(child, MenuLinkComponent)) {\n if (isExternalLink(props)) {\n validChildren.push({ label, labelIcon, href });\n } else {\n logErrorInDevMode(userButtonMenuItemLinkWrongProps);\n return;\n }\n }\n });\n });\n\n const customMenuItemLabelIcons: UseCustomElementPortalParams[] = [];\n const customLinkLabelIcons: UseCustomElementPortalParams[] = [];\n validChildren.forEach((mi, index) => {\n if (isCustomMenuItem(mi)) {\n customMenuItemLabelIcons.push({ component: mi.labelIcon, id: index });\n }\n if (isExternalLink(mi)) {\n customLinkLabelIcons.push({ component: mi.labelIcon, id: index });\n }\n });\n\n const customMenuItemLabelIconsPortals = useCustomElementPortal(customMenuItemLabelIcons);\n const customLinkLabelIconsPortals = useCustomElementPortal(customLinkLabelIcons);\n\n validChildren.forEach((mi, index) => {\n if (isReorderItem(mi, reorderItemsLabels)) {\n customMenuItems.push({\n label: mi.label,\n });\n }\n if (isCustomMenuItem(mi)) {\n const {\n portal: iconPortal,\n mount: mountIcon,\n unmount: unmountIcon,\n } = customMenuItemLabelIconsPortals.find(p => p.id === index) as UseCustomElementPortalReturn;\n const menuItem: CustomMenuItem = {\n label: mi.label,\n mountIcon,\n unmountIcon,\n };\n\n if ('onClick' in mi) {\n menuItem.onClick = mi.onClick;\n } else if ('open' in mi) {\n menuItem.open = mi.open;\n }\n customMenuItems.push(menuItem);\n customMenuItemsPortals.push(iconPortal);\n }\n if (isExternalLink(mi)) {\n const {\n portal: iconPortal,\n mount: mountIcon,\n unmount: unmountIcon,\n } = customLinkLabelIconsPortals.find(p => p.id === index) as UseCustomElementPortalReturn;\n customMenuItems.push({\n label: mi.label,\n href: mi.href,\n mountIcon,\n unmountIcon,\n });\n customMenuItemsPortals.push(iconPortal);\n }\n });\n\n return { customMenuItems, customMenuItemsPortals };\n};\n\nconst isReorderItem = (childProps: any, validItems: string[]): boolean => {\n const { children, label, onClick, labelIcon } = childProps;\n return !children && !onClick && !labelIcon && validItems.some(v => v === label);\n};\n\nconst isCustomMenuItem = (childProps: any): childProps is UserButtonActionProps => {\n const { label, labelIcon, onClick, open } = childProps;\n return !!labelIcon && !!label && (typeof onClick === 'function' || typeof open === 'string');\n};\n\nconst isExternalLink = (childProps: any): childProps is UserButtonLinkProps => {\n const { label, href, labelIcon } = childProps;\n return !!href && !!labelIcon && !!label;\n};\n","import { useEffect, useRef, useState } from 'react';\n\n/**\n * Used to detect when a Clerk component has been added to the DOM.\n */\nfunction waitForElementChildren(options: { selector?: string; root?: HTMLElement | null; timeout?: number }) {\n const { root = document?.body, selector, timeout = 0 } = options;\n\n return new Promise<void>((resolve, reject) => {\n if (!root) {\n reject(new Error('No root element provided'));\n return;\n }\n\n let elementToWatch: HTMLElement | null = root;\n if (selector) {\n elementToWatch = root?.querySelector(selector);\n }\n\n // Check if the element already has child nodes\n const isElementAlreadyPresent = elementToWatch?.childElementCount && elementToWatch.childElementCount > 0;\n if (isElementAlreadyPresent) {\n resolve();\n return;\n }\n\n // Set up a MutationObserver to detect when the element has children\n const observer = new MutationObserver(mutationsList => {\n for (const mutation of mutationsList) {\n if (mutation.type === 'childList') {\n if (!elementToWatch && selector) {\n elementToWatch = root?.querySelector(selector);\n }\n\n if (elementToWatch?.childElementCount && elementToWatch.childElementCount > 0) {\n observer.disconnect();\n resolve();\n return;\n }\n }\n }\n });\n\n observer.observe(root, { childList: true, subtree: true });\n\n // Set up an optional timeout to reject the promise if the element never gets child nodes\n if (timeout > 0) {\n setTimeout(() => {\n observer.disconnect();\n reject(new Error(`Timeout waiting for element children`));\n }, timeout);\n }\n });\n}\n\n/**\n * Detect when a Clerk component has mounted by watching DOM updates to an element with a `data-clerk-component=\"${component}\"` property.\n */\nexport function useWaitForComponentMount(component?: string) {\n const watcherRef = useRef<Promise<void>>();\n const [status, setStatus] = useState<'rendering' | 'rendered' | 'error'>('rendering');\n\n useEffect(() => {\n if (!component) {\n throw new Error('Clerk: no component name provided, unable to detect mount.');\n }\n\n if (typeof window !== 'undefined' && !watcherRef.current) {\n watcherRef.current = waitForElementChildren({ selector: `[data-clerk-component=\"${component}\"]` })\n .then(() => {\n setStatus('rendered');\n })\n .catch(() => {\n setStatus('error');\n });\n }\n }, [component]);\n\n return status;\n}\n","import { without } from '@clerk/shared/object';\nimport { isDeeplyEqual } from '@clerk/shared/react';\nimport type { PropsWithChildren } from 'react';\nimport React from 'react';\n\nimport type { MountProps, OpenProps } from '../types';\n\nconst isMountProps = (props: any): props is MountProps => {\n return 'mount' in props;\n};\n\nconst isOpenProps = (props: any): props is OpenProps => {\n return 'open' in props;\n};\n\nconst stripMenuItemIconHandlers = (\n menuItems?: Array<{\n mountIcon?: (el: HTMLDivElement) => void;\n unmountIcon?: (el: HTMLDivElement) => void;\n [key: string]: any;\n }>,\n) => {\n return menuItems?.map(({ mountIcon, unmountIcon, ...rest }) => rest);\n};\n\n// README: <ClerkHostRenderer/> should be a class pure component in order for mount and unmount\n// lifecycle props to be invoked correctly. Replacing the class component with a\n// functional component wrapped with a React.memo is not identical to the original\n// class implementation due to React intricacies such as the useEffect’s cleanup\n// seems to run AFTER unmount, while componentWillUnmount runs BEFORE.\n\n// More information can be found at https://clerk.slack.com/archives/C015S0BGH8R/p1624891993016300\n\n// The function Portal implementation is commented out for future reference.\n\n// const Portal = React.memo(({ props, mount, unmount }: MountProps) => {\n// const portalRef = React.createRef<HTMLDivElement>();\n\n// useEffect(() => {\n// if (portalRef.current) {\n// mount(portalRef.current, props);\n// }\n// return () => {\n// if (portalRef.current) {\n// unmount(portalRef.current);\n// }\n// };\n// }, []);\n\n// return <div ref={portalRef} />;\n// });\n\n// Portal.displayName = 'ClerkPortal';\n\n/**\n * Used to orchestrate mounting of Clerk components in a host React application.\n * Components are rendered into a specific DOM node using mount/unmount methods provided by the Clerk class.\n */\nexport class ClerkHostRenderer extends React.PureComponent<\n PropsWithChildren<\n (MountProps | OpenProps) & {\n component?: string;\n hideRootHtmlElement?: boolean;\n rootProps?: JSX.IntrinsicElements['div'];\n }\n >\n> {\n private rootRef = React.createRef<HTMLDivElement>();\n\n componentDidUpdate(_prevProps: Readonly<MountProps | OpenProps>) {\n if (!isMountProps(_prevProps) || !isMountProps(this.props)) {\n return;\n }\n\n // Remove children and customPages from props before comparing\n // children might hold circular references which deepEqual can't handle\n // and the implementation of customPages relies on props getting new references\n const prevProps = without(_prevProps.props, 'customPages', 'customMenuItems', 'children');\n const newProps = without(this.props.props, 'customPages', 'customMenuItems', 'children');\n\n // instead, we simply use the length of customPages to determine if it changed or not\n const customPagesChanged = prevProps.customPages?.length !== newProps.customPages?.length;\n const customMenuItemsChanged = prevProps.customMenuItems?.length !== newProps.customMenuItems?.length;\n\n // Strip out mountIcon and unmountIcon handlers since they're always generated as new function references,\n // which would cause unnecessary re-renders in deep equality checks\n const prevMenuItemsWithoutHandlers = stripMenuItemIconHandlers(_prevProps.props.customMenuItems);\n const newMenuItemsWithoutHandlers = stripMenuItemIconHandlers(this.props.props.customMenuItems);\n\n if (\n !isDeeplyEqual(prevProps, newProps) ||\n !isDeeplyEqual(prevMenuItemsWithoutHandlers, newMenuItemsWithoutHandlers) ||\n customPagesChanged ||\n customMenuItemsChanged\n ) {\n if (this.rootRef.current) {\n this.props.updateProps({ node: this.rootRef.current, props: this.props.props });\n }\n }\n }\n\n componentDidMount() {\n if (this.rootRef.current) {\n if (isMountProps(this.props)) {\n this.props.mount(this.rootRef.current, this.props.props);\n }\n\n if (isOpenProps(this.props)) {\n this.props.open(this.props.props);\n }\n }\n }\n\n componentWillUnmount() {\n if (this.rootRef.current) {\n if (isMountProps(this.props)) {\n this.props.unmount(this.rootRef.current);\n }\n if (isOpenProps(this.props)) {\n this.props.close();\n }\n }\n }\n\n render() {\n const { hideRootHtmlElement = false } = this.props;\n const rootAttributes = {\n ref: this.rootRef,\n ...this.props.rootProps,\n ...(this.props.component && { 'data-clerk-component': this.props.component }),\n };\n\n return (\n <>\n {!hideRootHtmlElement && <div {...rootAttributes} />}\n {this.props.children}\n </>\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,qBAAAA,0BAAyB;AAkBlC,OAAOC,UAAS,eAAe,eAAe,kBAAkB;;;AClBhE,OAAO,WAAW;AAKX,IAAM,oBACX,CAAC,aACD,CACE,SAQG;AACH,MAAI;AACF,WAAO,MAAM,SAAS,KAAK,QAA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