@lerx/promise-modal 0.0.76 → 0.0.77
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app/ModalManager.d.ts +1 -4
- package/dist/app/ModalManager.d.ts.map +1 -1
- package/dist/core/node/ModalNode/AbstractNode.d.ts +1 -4
- package/dist/core/node/ModalNode/AbstractNode.d.ts.map +1 -1
- package/dist/core/node/ModalNode/PromptNode.d.ts +1 -1
- package/dist/core/node/ModalNode/PromptNode.d.ts.map +1 -1
- package/dist/index.cjs.js +17 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +16 -1
- package/dist/index.esm.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs.js","sources":["../src/app/ModalManager.ts","../src/core/node/ModalNode/AbstractNode.ts","../src/core/node/ModalNode/AlertNode.ts","../src/core/node/ModalNode/ConfirmNode.ts","../src/core/node/ModalNode/PromptNode.ts","../src/core/node/nodeFactory.ts","../src/providers/ModalManagerContext/ModalManagerContext.ts","../src/providers/ModalManagerContext/ModalManagerContextProvider.tsx","../src/providers/ModalManagerContext/useModalManagerContext.ts","../src/components/FallbackComponents/classNames.emotion.ts","../src/components/FallbackComponents/FallbackTitle.tsx","../src/components/FallbackComponents/FallbackSubtitle.tsx","../src/components/FallbackComponents/FallbackContent.tsx","../src/components/FallbackComponents/FallbackFooter.tsx","../src/hooks/useActiveModalCount.ts","../src/components/FallbackComponents/FallbackForegroundFrame.tsx","../src/providers/ConfigurationContext/ConfigurationContext.ts","../src/providers/ConfigurationContext/ConfigurationContextProvider.tsx","../src/app/constant.ts","../src/providers/ConfigurationContext/useConfigurationContext.ts","../src/providers/UserDefinedContext/UserDefinedContext.ts","../src/providers/UserDefinedContext/UserDefinedContextProvider.tsx","../src/providers/UserDefinedContext/useUserDefinedContext.ts","../src/hooks/useDefaultPathname.ts","../src/components/Background/classNames.emotion.ts","../src/components/Background/Background.tsx","../src/components/Foreground/classNames.emotion.ts","../src/components/Foreground/components/AlertInner.tsx","../src/components/Foreground/components/ConfirmInner.tsx","../src/components/Foreground/components/PromptInner.tsx","../src/components/Foreground/Foreground.tsx","../src/hooks/useSubscribeModal.ts","../src/components/Presenter/classNames.emotion.ts","../src/components/Presenter/Presenter.tsx","../src/components/Anchor/classNames.emotion.ts","../src/components/Anchor/Anchor.tsx","../src/bootstrap/BootstrapProvider/helpers/bootstrap.tsx","../src/bootstrap/BootstrapProvider/hooks/useInitialize.ts","../src/bootstrap/BootstrapProvider/BootstrapProvider.tsx","../src/core/handle/alert.ts","../src/core/handle/confirm.ts","../src/core/handle/prompt.ts","../src/hooks/useDestroyAfter.ts","../src/bootstrap/BootstrapProvider/useBootstrap.tsx","../src/hooks/useModalAnimation.ts"],"sourcesContent":["import { getRandomString } from '@winglet/common-utils';\n\nimport type { Fn } from '@aileron/declare';\n\nimport type { Modal } from '@/promise-modal/types';\n\nexport class ModalManager {\n private static __active__ = false;\n static activate() {\n if (ModalManager.__active__) return false;\n return (ModalManager.__active__ = true);\n }\n\n private static __anchor__: HTMLElement | null = null;\n static anchor(options?: {\n tag?: string;\n prefix?: string;\n root?: HTMLElement;\n }): HTMLElement {\n if (ModalManager.__anchor__) {\n const anchor = document.getElementById(ModalManager.__anchor__.id);\n if (anchor) return anchor;\n }\n const {\n tag = 'div',\n prefix = 'promise-modal',\n root = document.body,\n } = options || {};\n const node = document.createElement(tag);\n node.setAttribute('id', `${prefix}-${getRandomString(36)}`);\n root.appendChild(node);\n ModalManager.__anchor__ = node;\n return node;\n }\n\n private static __prerenderList__: Modal[] = [];\n static get prerender() {\n return ModalManager.__prerenderList__;\n }\n\n private static __openHandler__: Fn<[Modal], void> = (modal: Modal) =>\n ModalManager.__prerenderList__.push(modal);\n static set openHandler(handler: Fn<[Modal], void>) {\n ModalManager.__openHandler__ = handler;\n ModalManager.__prerenderList__ = [];\n }\n\n static get unanchored() {\n return !ModalManager.__anchor__;\n }\n\n static reset() {\n ModalManager.__active__ = false;\n ModalManager.__anchor__ = null;\n ModalManager.__prerenderList__ = [];\n ModalManager.__openHandler__ = (modal: Modal) =>\n ModalManager.__prerenderList__.push(modal);\n }\n\n static open(modal: Modal) {\n ModalManager.__openHandler__(modal);\n }\n}\n","import type { ReactNode } from 'react';\n\nimport type { Fn } from '@aileron/declare';\n\nimport type {\n BackgroundComponent,\n BaseModal,\n ForegroundComponent,\n ManagedEntity,\n ModalBackground,\n} from '@/promise-modal/types';\n\ntype AbstractNodeProps<T, B> = BaseModal<T, B> & ManagedEntity;\n\nexport abstract class AbstractNode<T, B> {\n readonly id: number;\n readonly initiator: string;\n\n readonly title?: ReactNode;\n readonly subtitle?: ReactNode;\n readonly background?: ModalBackground<B>;\n\n readonly manualDestroy: boolean;\n readonly closeOnBackdropClick: boolean;\n readonly dimmed: boolean;\n\n readonly ForegroundComponent?: ForegroundComponent;\n readonly BackgroundComponent?: BackgroundComponent;\n\n private __alive__: boolean;\n get alive() {\n return this.__alive__;\n }\n private __visible__: boolean;\n get visible() {\n return this.__visible__;\n }\n\n private __resolve__: (result: T | null) => void;\n private __listeners__: Set<Fn> = new Set();\n\n constructor({\n id,\n initiator,\n title,\n subtitle,\n background,\n dimmed = true,\n manualDestroy = false,\n closeOnBackdropClick = true,\n resolve,\n ForegroundComponent,\n BackgroundComponent,\n }: AbstractNodeProps<T, B>) {\n this.id = id;\n this.initiator = initiator;\n this.title = title;\n this.subtitle = subtitle;\n this.background = background;\n\n this.dimmed = dimmed;\n this.manualDestroy = manualDestroy;\n this.closeOnBackdropClick = closeOnBackdropClick;\n\n this.ForegroundComponent = ForegroundComponent;\n this.BackgroundComponent = BackgroundComponent;\n\n this.__alive__ = true;\n this.__visible__ = true;\n this.__resolve__ = resolve;\n }\n\n subscribe(listener: Fn) {\n this.__listeners__.add(listener);\n return () => {\n this.__listeners__.delete(listener);\n };\n }\n publish() {\n for (const listener of this.__listeners__) listener();\n }\n protected resolve(result: T | null) {\n this.__resolve__(result);\n }\n onDestroy() {\n const needPublish = this.__alive__ === true;\n this.__alive__ = false;\n if (this.manualDestroy && needPublish) this.publish();\n }\n onShow() {\n const needPublish = this.__visible__ === false;\n this.__visible__ = true;\n if (needPublish) this.publish();\n }\n onHide() {\n const needPublish = this.__visible__ === true;\n this.__visible__ = false;\n if (needPublish) this.publish();\n }\n abstract onClose(): void;\n abstract onConfirm(): void;\n}\n","import type { ComponentType, ReactNode } from 'react';\n\nimport type {\n AlertContentProps,\n AlertFooterRender,\n AlertModal,\n FooterOptions,\n ManagedEntity,\n} from '@/promise-modal/types';\n\nimport { AbstractNode } from './AbstractNode';\n\ntype AlertNodeProps<B> = AlertModal<B> & ManagedEntity;\n\nexport class AlertNode<B> extends AbstractNode<null, B> {\n readonly type: 'alert';\n readonly subtype?: 'info' | 'success' | 'warning' | 'error';\n readonly content?: ReactNode | ComponentType<AlertContentProps>;\n readonly footer?:\n | AlertFooterRender\n | Pick<FooterOptions, 'confirm' | 'hideConfirm'>\n | false;\n\n constructor({\n id,\n initiator,\n type,\n subtype,\n title,\n subtitle,\n content,\n footer,\n background,\n dimmed,\n manualDestroy,\n closeOnBackdropClick,\n resolve,\n ForegroundComponent,\n BackgroundComponent,\n }: AlertNodeProps<B>) {\n super({\n id,\n initiator,\n title,\n subtitle,\n background,\n dimmed,\n manualDestroy,\n closeOnBackdropClick,\n resolve,\n ForegroundComponent,\n BackgroundComponent,\n });\n this.type = type;\n this.subtype = subtype;\n this.content = content;\n this.footer = footer;\n }\n onClose() {\n this.resolve(null);\n }\n onConfirm() {\n this.resolve(null);\n }\n}\n","import type { ComponentType, ReactNode } from 'react';\n\nimport type {\n ConfirmContentProps,\n ConfirmFooterRender,\n ConfirmModal,\n FooterOptions,\n ManagedEntity,\n} from '@/promise-modal/types';\n\nimport { AbstractNode } from './AbstractNode';\n\ntype ConfirmNodeProps<B> = ConfirmModal<B> & ManagedEntity;\n\nexport class ConfirmNode<B> extends AbstractNode<boolean, B> {\n readonly type: 'confirm';\n readonly subtype?: 'info' | 'success' | 'warning' | 'error';\n readonly content?: ReactNode | ComponentType<ConfirmContentProps>;\n readonly footer?: ConfirmFooterRender | FooterOptions | false;\n\n constructor({\n id,\n initiator,\n type,\n subtype,\n title,\n subtitle,\n content,\n footer,\n background,\n dimmed,\n manualDestroy,\n closeOnBackdropClick,\n resolve,\n ForegroundComponent,\n BackgroundComponent,\n }: ConfirmNodeProps<B>) {\n super({\n id,\n initiator,\n title,\n subtitle,\n background,\n dimmed,\n manualDestroy,\n closeOnBackdropClick,\n resolve,\n ForegroundComponent,\n BackgroundComponent,\n });\n this.type = type;\n this.subtype = subtype;\n this.content = content;\n this.footer = footer;\n }\n onClose() {\n this.resolve(false);\n }\n onConfirm() {\n this.resolve(true);\n }\n}\n","import type { ComponentType, ReactNode } from 'react';\n\nimport type {\n FooterOptions,\n ManagedEntity,\n PromptContentProps,\n PromptFooterRender,\n PromptInputProps,\n PromptModal,\n} from '@/promise-modal/types';\n\nimport { AbstractNode } from './AbstractNode';\n\ntype PromptNodeProps<T, B> = PromptModal<T, B> & ManagedEntity;\n\nexport class PromptNode<T, B> extends AbstractNode<T, B> {\n readonly type: 'prompt';\n readonly content?: ReactNode | ComponentType<PromptContentProps>;\n readonly defaultValue: T | undefined;\n readonly Input: (props: PromptInputProps<T>) => ReactNode;\n readonly disabled?: (value: T) => boolean;\n readonly returnOnCancel?: boolean;\n readonly footer?: PromptFooterRender<T> | FooterOptions | false;\n private __value__: T | undefined;\n\n constructor({\n id,\n initiator,\n type,\n title,\n subtitle,\n content,\n defaultValue,\n Input,\n disabled,\n returnOnCancel,\n footer,\n background,\n dimmed,\n manualDestroy,\n closeOnBackdropClick,\n resolve,\n ForegroundComponent,\n BackgroundComponent,\n }: PromptNodeProps<T, B>) {\n super({\n id,\n initiator,\n title,\n subtitle,\n background,\n dimmed,\n manualDestroy,\n closeOnBackdropClick,\n resolve,\n ForegroundComponent,\n BackgroundComponent,\n });\n this.type = type;\n this.content = content;\n this.Input = Input;\n this.defaultValue = defaultValue;\n this.__value__ = defaultValue;\n this.disabled = disabled;\n this.returnOnCancel = returnOnCancel;\n this.footer = footer;\n }\n\n onChange(value: T) {\n this.__value__ = value;\n }\n onConfirm() {\n this.resolve(this.__value__ ?? null);\n }\n onClose() {\n if (this.returnOnCancel) this.resolve(this.__value__ ?? null);\n else this.resolve(null);\n }\n}\n","import type { ManagedModal } from '@/promise-modal/types';\n\nimport { AlertNode, ConfirmNode, PromptNode } from './ModalNode';\n\nexport const nodeFactory = <T, B>(modal: ManagedModal<T, B>) => {\n switch (modal.type) {\n case 'alert':\n return new AlertNode<B>(modal);\n case 'confirm':\n return new ConfirmNode<B>(modal);\n case 'prompt':\n return new PromptNode<T, B>(modal);\n }\n // @ts-expect-error: This state is unreachable by design and should NEVER occur.\n throw new Error(`Unknown modal: ${modal.type}`, { modal });\n};\n","import { createContext } from 'react';\n\nimport type { Fn } from '@aileron/declare';\n\nimport type { ModalNode } from '@/promise-modal/core';\nimport type { ModalActions, ModalHandlersWithId } from '@/promise-modal/types';\n\nexport interface ModalManagerContextProps extends ModalHandlersWithId {\n modalIds: ModalNode['id'][];\n getModal: Fn<[id: ModalNode['id']], ModalActions>;\n getModalNode: Fn<[id: ModalNode['id']], ModalNode | undefined>;\n setUpdater: Fn<[updater: Fn]>;\n}\n\nexport const ModalManagerContext = createContext<ModalManagerContextProps>(\n {} as ModalManagerContextProps,\n);\n","import {\n type PropsWithChildren,\n memo,\n useCallback,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\n\nimport { convertMsFromDuration } from '@winglet/common-utils';\nimport { useOnMountLayout, useReference } from '@winglet/react-utils';\n\nimport type { Fn } from '@aileron/declare';\n\nimport { ModalManager } from '@/promise-modal/app/ModalManager';\nimport { type ModalNode, nodeFactory } from '@/promise-modal/core';\nimport { useConfigurationOptions } from '@/promise-modal/providers';\nimport type { Modal } from '@/promise-modal/types';\n\nimport { ModalManagerContext } from './ModalManagerContext';\n\ninterface ModalManagerContextProviderProps {\n usePathname: Fn<[], { pathname: string }>;\n}\n\nexport const ModalManagerContextProvider = memo(\n ({\n usePathname,\n children,\n }: PropsWithChildren<ModalManagerContextProviderProps>) => {\n const modalDictionary = useRef<Map<ModalNode['id'], ModalNode>>(new Map());\n\n const [modalIds, setModalIds] = useState<ModalNode['id'][]>([]);\n const modalIdsRef = useReference(modalIds);\n const { pathname } = usePathname();\n\n const initiator = useRef(pathname);\n const modalIdSequence = useRef(0);\n\n const options = useConfigurationOptions();\n\n const duration = useMemo(\n () => convertMsFromDuration(options.duration),\n [options],\n );\n\n useOnMountLayout(() => {\n const { manualDestroy, closeOnBackdropClick } = options;\n\n for (const data of ModalManager.prerender) {\n const modal = nodeFactory({\n ...data,\n id: modalIdSequence.current++,\n initiator: initiator.current,\n manualDestroy:\n data.manualDestroy !== undefined\n ? data.manualDestroy\n : manualDestroy,\n closeOnBackdropClick:\n data.closeOnBackdropClick !== undefined\n ? data.closeOnBackdropClick\n : closeOnBackdropClick,\n });\n modalDictionary.current.set(modal.id, modal);\n setModalIds((ids) => [...ids, modal.id]);\n }\n\n ModalManager.openHandler = (data: Modal) => {\n const modal = nodeFactory({\n ...data,\n id: modalIdSequence.current++,\n initiator: initiator.current,\n manualDestroy:\n data.manualDestroy !== undefined\n ? data.manualDestroy\n : manualDestroy,\n closeOnBackdropClick:\n data.closeOnBackdropClick !== undefined\n ? data.closeOnBackdropClick\n : closeOnBackdropClick,\n });\n modalDictionary.current.set(modal.id, modal);\n setModalIds((ids) => {\n const aliveIds: number[] = [];\n for (let index = 0; index < ids.length; index++) {\n const id = ids[index];\n const destroyed = !modalDictionary.current.get(id)?.alive;\n if (destroyed) modalDictionary.current.delete(id);\n else aliveIds.push(id);\n }\n return [...aliveIds, modal.id];\n });\n };\n return () => {\n ModalManager.reset();\n };\n });\n\n useLayoutEffect(() => {\n for (const id of modalIdsRef.current) {\n const modal = modalDictionary.current.get(id);\n if (!modal?.alive) continue;\n if (modal.initiator === pathname) modal.onShow();\n else modal.onHide();\n }\n initiator.current = pathname;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [pathname]);\n\n const getModalNode = useCallback((modalId: ModalNode['id']) => {\n return modalDictionary.current.get(modalId);\n }, []);\n\n const onDestroy = useCallback((modalId: ModalNode['id']) => {\n const modal = modalDictionary.current.get(modalId);\n if (!modal) return;\n modal.onDestroy();\n updaterRef.current?.();\n }, []);\n\n const updaterRef = useRef<Fn>(undefined);\n const hideModal = useCallback(\n (modalId: ModalNode['id']) => {\n const modal = modalDictionary.current.get(modalId);\n if (!modal) return;\n modal.onHide();\n updaterRef.current?.();\n if (!modal.manualDestroy)\n setTimeout(() => {\n modal.onDestroy();\n }, duration);\n },\n [duration],\n );\n\n const onChange = useCallback((modalId: ModalNode['id'], value: any) => {\n const modal = modalDictionary.current.get(modalId);\n if (!modal) return;\n if (modal.type === 'prompt') modal.onChange(value);\n }, []);\n\n const onConfirm = useCallback(\n (modalId: ModalNode['id']) => {\n const modal = modalDictionary.current.get(modalId);\n if (!modal) return;\n modal.onConfirm();\n hideModal(modalId);\n },\n [hideModal],\n );\n\n const onClose = useCallback(\n (modalId: ModalNode['id']) => {\n const modal = modalDictionary.current.get(modalId);\n if (!modal) return;\n modal.onClose();\n hideModal(modalId);\n },\n [hideModal],\n );\n\n const getModal = useCallback(\n (modalId: ModalNode['id']) => ({\n modal: getModalNode(modalId),\n onConfirm: () => onConfirm(modalId),\n onClose: () => onClose(modalId),\n onChange: (value: any) => onChange(modalId, value),\n onDestroy: () => onDestroy(modalId),\n }),\n [getModalNode, onConfirm, onClose, onChange, onDestroy],\n );\n\n const value = useMemo(() => {\n return {\n modalIds,\n getModalNode,\n onChange,\n onConfirm,\n onClose,\n onDestroy,\n getModal,\n setUpdater: (updater: Fn) => {\n updaterRef.current = updater;\n },\n };\n }, [\n modalIds,\n getModal,\n getModalNode,\n onChange,\n onConfirm,\n onClose,\n onDestroy,\n ]);\n\n return (\n <ModalManagerContext.Provider value={value}>\n {children}\n </ModalManagerContext.Provider>\n );\n },\n);\n","import { useContext, useMemo } from 'react';\n\nimport type { ManagedModal } from '@/promise-modal/types';\n\nimport { ModalManagerContext } from './ModalManagerContext';\n\nexport const useModalManagerContext = () => useContext(ModalManagerContext);\n\nexport const useModal = (id: ManagedModal['id']) => {\n const { getModal } = useModalManagerContext();\n return useMemo(() => getModal(id), [id, getModal]);\n};\n","import { css } from '@emotion/css';\n\nexport const fallback = css`\n margin: unset;\n`;\n\nexport const frame = css`\n display: flex;\n flex-direction: column;\n justify-content: center;\n align-items: center;\n background-color: white;\n padding: 20px 80px;\n gap: 10px;\n border: 1px solid black;\n`;\n","import type { PropsWithChildren } from 'react';\n\nimport { fallback } from './classNames.emotion';\n\nexport const FallbackTitle = ({ children }: PropsWithChildren) => {\n return <h2 className={fallback}>{children}</h2>;\n};\n","import type { PropsWithChildren } from 'react';\n\nimport { fallback } from './classNames.emotion';\n\nexport const FallbackSubtitle = ({ children }: PropsWithChildren) => {\n return <h3 className={fallback}>{children}</h3>;\n};\n","import type { PropsWithChildren } from 'react';\n\nimport { fallback } from './classNames.emotion';\n\nexport const FallbackContent = ({ children }: PropsWithChildren) => {\n return <div className={fallback}>{children}</div>;\n};\n","import type { FooterComponentProps } from '@/promise-modal/types';\n\nexport const FallbackFooter = ({\n confirmLabel,\n hideConfirm = false,\n cancelLabel,\n hideCancel = false,\n disabled,\n onConfirm,\n onCancel,\n}: FooterComponentProps) => {\n return (\n <div>\n {!hideConfirm && (\n <button onClick={onConfirm} disabled={disabled}>\n {confirmLabel || '확인'}\n </button>\n )}\n\n {!hideCancel && typeof onCancel === 'function' && (\n <button onClick={onCancel}>{cancelLabel || '취소'}</button>\n )}\n </div>\n );\n};\n","import { useMemo } from 'react';\n\nimport type { Fn } from '@aileron/declare';\n\nimport type { ModalNode } from '@/promise-modal/core';\nimport { useModalManagerContext } from '@/promise-modal/providers';\n\nconst defaultValidate = (modal?: ModalNode) => modal?.visible;\n\nexport const useActiveModalCount = (\n validate: Fn<[ModalNode?], boolean | undefined> = defaultValidate,\n refreshKey: string | number = 0,\n) => {\n const { modalIds, getModalNode } = useModalManagerContext();\n return useMemo(() => {\n let count = 0;\n for (const id of modalIds) {\n if (validate(getModalNode(id))) count++;\n }\n return count;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [getModalNode, modalIds, refreshKey]);\n};\n","import {\n type ForwardedRef,\n type PropsWithChildren,\n forwardRef,\n useMemo,\n} from 'react';\n\nimport { useActiveModalCount } from '@/promise-modal/hooks/useActiveModalCount';\nimport type { ModalFrameProps } from '@/promise-modal/types';\n\nimport { frame } from './classNames.emotion';\n\nconst MAX_MODAL_COUNT = 5;\nconst MAX_MODAL_LEVEL = 3;\n\nexport const FallbackForegroundFrame = forwardRef(\n (\n { id, onChangeOrder, children }: PropsWithChildren<ModalFrameProps>,\n ref: ForwardedRef<HTMLDivElement>,\n ) => {\n const activeCount = useActiveModalCount();\n const [level, offset] = useMemo(() => {\n const stacked = activeCount > 1;\n const level = stacked\n ? (Math.floor(id / MAX_MODAL_COUNT) % MAX_MODAL_LEVEL) * 100\n : 0;\n const offset = stacked ? (id % MAX_MODAL_COUNT) * 35 : 0;\n return [level, offset];\n }, [activeCount, id]);\n\n return (\n <div\n ref={ref}\n className={frame}\n onClick={onChangeOrder}\n style={{\n marginBottom: `calc(25vh + ${level}px)`,\n marginLeft: `${level}px`,\n transform: `translate(${offset}px, ${offset}px)`,\n }}\n >\n {children}\n </div>\n );\n },\n);\n","import { type ComponentType, createContext } from 'react';\n\nimport type { Color, Duration } from '@aileron/declare';\n\nimport type {\n BackgroundComponent,\n FooterComponentProps,\n ForegroundComponent,\n WrapperComponentProps,\n} from '@/promise-modal/types';\n\nexport interface ConfigurationContextProps {\n ForegroundComponent: ForegroundComponent;\n BackgroundComponent?: BackgroundComponent;\n TitleComponent: ComponentType<WrapperComponentProps>;\n SubtitleComponent: ComponentType<WrapperComponentProps>;\n ContentComponent: ComponentType<WrapperComponentProps>;\n FooterComponent: ComponentType<FooterComponentProps>;\n options: {\n duration: Duration;\n backdrop: Color;\n manualDestroy: boolean;\n closeOnBackdropClick: boolean;\n };\n}\n\nexport const ConfigurationContext = createContext<ConfigurationContextProps>(\n {} as ConfigurationContextProps,\n);\n","import {\n type ComponentType,\n type PropsWithChildren,\n memo,\n useMemo,\n} from 'react';\n\nimport type { Color, Duration } from '@aileron/declare';\n\nimport {\n DEFAULT_ANIMATION_DURATION,\n DEFAULT_BACKDROP_COLOR,\n} from '@/promise-modal/app/constant';\nimport {\n FallbackContent,\n FallbackFooter,\n FallbackForegroundFrame,\n FallbackSubtitle,\n FallbackTitle,\n} from '@/promise-modal/components/FallbackComponents';\nimport type {\n FooterComponentProps,\n ModalFrameProps,\n WrapperComponentProps,\n} from '@/promise-modal/types';\n\nimport { ConfigurationContext } from './ConfigurationContext';\n\nexport interface ConfigurationContextProviderProps {\n BackgroundComponent?: ComponentType<ModalFrameProps>;\n ForegroundComponent?: ComponentType<ModalFrameProps>;\n TitleComponent?: ComponentType<WrapperComponentProps>;\n SubtitleComponent?: ComponentType<WrapperComponentProps>;\n ContentComponent?: ComponentType<WrapperComponentProps>;\n FooterComponent?: ComponentType<FooterComponentProps>;\n options?: {\n /** Modal transition time(ms, s) */\n duration?: Duration;\n /** Modal backdrop color */\n backdrop?: Color;\n /** Whether to destroy the modal manually */\n manualDestroy?: boolean;\n /** Whether to close the modal when the backdrop is clicked */\n closeOnBackdropClick?: boolean;\n };\n}\n\nexport const ConfigurationContextProvider = memo(\n ({\n ForegroundComponent,\n BackgroundComponent,\n TitleComponent,\n SubtitleComponent,\n ContentComponent,\n FooterComponent,\n options,\n children,\n }: PropsWithChildren<ConfigurationContextProviderProps>) => {\n const value = useMemo(\n () => ({\n BackgroundComponent,\n ForegroundComponent: ForegroundComponent || FallbackForegroundFrame,\n TitleComponent: TitleComponent || FallbackTitle,\n SubtitleComponent: SubtitleComponent || FallbackSubtitle,\n ContentComponent: memo(ContentComponent || FallbackContent),\n FooterComponent: memo(FooterComponent || FallbackFooter),\n options: {\n duration: DEFAULT_ANIMATION_DURATION,\n backdrop: DEFAULT_BACKDROP_COLOR,\n closeOnBackdropClick: true,\n manualDestroy: false,\n ...options,\n } satisfies ConfigurationContextProviderProps['options'],\n }),\n [\n ForegroundComponent,\n BackgroundComponent,\n ContentComponent,\n FooterComponent,\n SubtitleComponent,\n TitleComponent,\n options,\n ],\n );\n return (\n <ConfigurationContext.Provider value={value}>\n {children}\n </ConfigurationContext.Provider>\n );\n },\n);\n","import type { Color, Duration } from '@aileron/declare';\n\nexport const DEFAULT_ANIMATION_DURATION: Duration = '300ms';\n\nexport const DEFAULT_BACKDROP_COLOR: Color = 'rgba(0, 0, 0, 0.5)';\n","import { useContext } from 'react';\n\nimport { convertMsFromDuration } from '@winglet/common-utils';\n\nimport { ConfigurationContext } from './ConfigurationContext';\n\nexport const useConfigurationContext = () => useContext(ConfigurationContext);\n\nexport const useConfigurationOptions = () => {\n const context = useContext(ConfigurationContext);\n return context.options;\n};\n\nexport const useConfigurationDuration = () => {\n const context = useConfigurationOptions();\n return {\n duration: context.duration,\n milliseconds: convertMsFromDuration(context.duration),\n };\n};\n\nexport const useConfigurationBackdrop = () => {\n const context = useConfigurationOptions();\n return context.backdrop;\n};\n","import { createContext } from 'react';\n\nimport type { Dictionary } from '@aileron/declare';\n\nexport interface UserDefinedContext {\n context: Dictionary;\n}\n\nexport const UserDefinedContext = createContext<UserDefinedContext>(\n {} as UserDefinedContext,\n);\n","import { PropsWithChildren, useMemo } from 'react';\n\nimport type { Dictionary } from '@aileron/declare';\n\nimport { UserDefinedContext } from './UserDefinedContext';\n\ninterface UserDefinedContextProviderProps {\n /** 사용자 정의 컨텍스트 */\n context?: Dictionary;\n}\n\nexport const UserDefinedContextProvider = ({\n context,\n children,\n}: PropsWithChildren<UserDefinedContextProviderProps>) => {\n const contextValue = useMemo(() => ({ context: context || {} }), [context]);\n return (\n <UserDefinedContext.Provider value={contextValue}>\n {children}\n </UserDefinedContext.Provider>\n );\n};\n","import { useContext } from 'react';\n\nimport { UserDefinedContext } from './UserDefinedContext';\n\nexport const useUserDefinedContext = () => {\n return useContext(UserDefinedContext);\n};\n","import { useLayoutEffect, useState } from 'react';\n\nexport const usePathname = () => {\n const [pathname, setPathname] = useState(window.location.pathname);\n useLayoutEffect(() => {\n let requestId: number;\n const checkPathname = () => {\n if (requestId) cancelAnimationFrame(requestId);\n if (pathname !== window.location.pathname) {\n setPathname(window.location.pathname);\n } else {\n requestId = requestAnimationFrame(checkPathname);\n }\n };\n requestId = requestAnimationFrame(checkPathname);\n return () => {\n if (requestId) cancelAnimationFrame(requestId);\n };\n }, [pathname]);\n return { pathname };\n};\n","import { css } from '@emotion/css';\n\nexport const background = css`\n display: none;\n position: fixed;\n inset: 0;\n z-index: -999;\n pointer-events: none;\n > * {\n pointer-events: none;\n }\n`;\n\nexport const active = css`\n pointer-events: all;\n`;\n\nexport const visible = css`\n display: flex;\n align-items: center;\n justify-content: center;\n`;\n","import { type MouseEvent, useCallback, useMemo } from 'react';\n\nimport { cx } from '@emotion/css';\n\nimport {\n useConfigurationContext,\n useModal,\n useUserDefinedContext,\n} from '@/promise-modal/providers';\nimport type { ModalLayerProps } from '@/promise-modal/types';\n\nimport { active, background, visible } from './classNames.emotion';\n\nexport const BackgroundFrame = ({\n modalId,\n onChangeOrder,\n}: ModalLayerProps) => {\n const { BackgroundComponent } = useConfigurationContext();\n const { context: userDefinedContext } = useUserDefinedContext();\n const { modal, onClose, onChange, onConfirm, onDestroy } = useModal(modalId);\n\n const handleClose = useCallback(\n (event: MouseEvent) => {\n if (modal && modal.closeOnBackdropClick && modal.visible) onClose();\n event.stopPropagation();\n },\n [modal, onClose],\n );\n\n const Background = useMemo(\n () => modal?.BackgroundComponent || BackgroundComponent,\n [BackgroundComponent, modal],\n );\n\n if (!modal) return null;\n\n return (\n <div\n className={cx(background, {\n [visible]: modal.manualDestroy ? modal.alive : modal.visible,\n [active]: modal.closeOnBackdropClick && modal.visible,\n })}\n onClick={handleClose}\n >\n {Background && (\n <Background\n id={modal.id}\n type={modal.type}\n alive={modal.alive}\n visible={modal.visible}\n initiator={modal.initiator}\n manualDestroy={modal.manualDestroy}\n closeOnBackdropClick={modal.closeOnBackdropClick}\n background={modal.background}\n onChange={onChange}\n onConfirm={onConfirm}\n onClose={onClose}\n onDestroy={onDestroy}\n onChangeOrder={onChangeOrder}\n context={userDefinedContext}\n />\n )}\n </div>\n );\n};\n","import { css } from '@emotion/css';\n\nexport const foreground = css`\n pointer-events: none;\n display: none;\n position: fixed;\n inset: 0;\n z-index: 1;\n`;\n\nexport const active = css`\n > * {\n pointer-events: all;\n }\n`;\n\nexport const visible = css`\n display: flex !important;\n justify-content: center;\n align-items: center;\n`;\n","import { Fragment, memo, useMemo } from 'react';\n\nimport { isString } from '@winglet/common-utils';\nimport { renderComponent, useHandle } from '@winglet/react-utils';\n\nimport type { AlertNode } from '@/promise-modal/core';\nimport {\n useConfigurationContext,\n useUserDefinedContext,\n} from '@/promise-modal/providers';\nimport type { ModalActions } from '@/promise-modal/types';\n\ninterface AlertInnerProps<B> {\n modal: AlertNode<B>;\n handlers: Pick<ModalActions, 'onConfirm'>;\n}\n\nexport const AlertInner = memo(\n <B,>({ modal, handlers }: AlertInnerProps<B>) => {\n const { title, subtitle, content, footer } = useMemo(() => modal, [modal]);\n const { context: userDefinedContext } = useUserDefinedContext();\n const { onConfirm } = useMemo(() => handlers, [handlers]);\n\n const handleConfirm = useHandle(onConfirm);\n\n const {\n TitleComponent,\n SubtitleComponent,\n ContentComponent,\n FooterComponent,\n } = useConfigurationContext();\n\n return (\n <Fragment>\n {title &&\n (isString(title) ? (\n <TitleComponent context={userDefinedContext}>\n {title}\n </TitleComponent>\n ) : (\n title\n ))}\n {subtitle &&\n (isString(subtitle) ? (\n <SubtitleComponent context={userDefinedContext}>\n {subtitle}\n </SubtitleComponent>\n ) : (\n subtitle\n ))}\n {content &&\n (isString(content) ? (\n <ContentComponent context={userDefinedContext}>\n {content}\n </ContentComponent>\n ) : (\n renderComponent(content, {\n onConfirm: handleConfirm,\n })\n ))}\n {footer !== false &&\n (typeof footer === 'function' ? (\n footer({\n onConfirm: handleConfirm,\n context: userDefinedContext,\n })\n ) : (\n <FooterComponent\n onConfirm={handleConfirm}\n confirmLabel={footer?.confirm}\n hideConfirm={footer?.hideConfirm}\n context={userDefinedContext}\n />\n ))}\n </Fragment>\n );\n },\n);\n","import { Fragment, memo, useMemo } from 'react';\n\nimport { isString } from '@winglet/common-utils';\nimport { renderComponent, useHandle } from '@winglet/react-utils';\n\nimport type { ConfirmNode } from '@/promise-modal/core';\nimport {\n useConfigurationContext,\n useUserDefinedContext,\n} from '@/promise-modal/providers';\nimport type { ModalActions } from '@/promise-modal/types';\n\ninterface ConfirmInnerProps<B> {\n modal: ConfirmNode<B>;\n handlers: Pick<ModalActions, 'onConfirm' | 'onClose'>;\n}\n\nexport const ConfirmInner = memo(\n <B,>({ modal, handlers }: ConfirmInnerProps<B>) => {\n const { title, subtitle, content, footer } = useMemo(() => modal, [modal]);\n const { context: userDefinedContext } = useUserDefinedContext();\n const { onConfirm, onClose } = useMemo(() => handlers, [handlers]);\n\n const handleConfirm = useHandle(onConfirm);\n const handleClose = useHandle(onClose);\n\n const {\n TitleComponent,\n SubtitleComponent,\n ContentComponent,\n FooterComponent,\n } = useConfigurationContext();\n\n return (\n <Fragment>\n {title &&\n (isString(title) ? (\n <TitleComponent context={userDefinedContext}>\n {title}\n </TitleComponent>\n ) : (\n title\n ))}\n {subtitle &&\n (isString(subtitle) ? (\n <SubtitleComponent context={userDefinedContext}>\n {subtitle}\n </SubtitleComponent>\n ) : (\n subtitle\n ))}\n {content &&\n (isString(content) ? (\n <ContentComponent context={userDefinedContext}>\n {content}\n </ContentComponent>\n ) : (\n renderComponent(content, {\n onConfirm: handleConfirm,\n onCancel: handleClose,\n context: userDefinedContext,\n })\n ))}\n {footer !== false &&\n (typeof footer === 'function' ? (\n footer({\n onConfirm: handleConfirm,\n onCancel: handleClose,\n context: userDefinedContext,\n })\n ) : (\n <FooterComponent\n onConfirm={handleConfirm}\n onCancel={handleClose}\n confirmLabel={footer?.confirm}\n cancelLabel={footer?.cancel}\n hideConfirm={footer?.hideConfirm}\n hideCancel={footer?.hideCancel}\n context={userDefinedContext}\n />\n ))}\n </Fragment>\n );\n },\n);\n","import { Fragment, memo, useCallback, useMemo, useState } from 'react';\n\nimport { isFunction, isString } from '@winglet/common-utils';\nimport {\n renderComponent,\n useHandle,\n withErrorBoundary,\n} from '@winglet/react-utils';\n\nimport type { PromptNode } from '@/promise-modal/core';\nimport {\n useConfigurationContext,\n useUserDefinedContext,\n} from '@/promise-modal/providers';\nimport type { ModalActions } from '@/promise-modal/types';\n\ninterface PromptInnerProps<T, B> {\n modal: PromptNode<T, B>;\n handlers: Pick<ModalActions, 'onChange' | 'onClose' | 'onConfirm'>;\n}\n\nexport const PromptInner = memo(\n <T, B>({ modal, handlers }: PromptInnerProps<T, B>) => {\n const {\n Input,\n defaultValue,\n disabled: checkDisabled,\n title,\n subtitle,\n content,\n footer,\n } = useMemo(\n () => ({\n ...modal,\n Input: memo(withErrorBoundary(modal.Input)),\n }),\n [modal],\n );\n\n const { context: userDefinedContext } = useUserDefinedContext();\n\n const [value, setValue] = useState<T | undefined>(defaultValue);\n\n const { onChange, onClose, onConfirm } = useMemo(\n () => handlers,\n [handlers],\n );\n\n const handleClose = useHandle(onClose);\n const handleChange = useHandle(\n (inputValue?: T | ((prevState: T | undefined) => T | undefined)) => {\n const input = isFunction(inputValue) ? inputValue(value) : inputValue;\n setValue(input);\n onChange(input);\n },\n );\n\n const handleConfirm = useCallback(() => {\n // NOTE: wait for the next tick to ensure the value is updated\n requestAnimationFrame(onConfirm);\n }, [onConfirm]);\n\n const disabled = useMemo(\n () => (value ? !!checkDisabled?.(value) : false),\n [checkDisabled, value],\n );\n\n const {\n TitleComponent,\n SubtitleComponent,\n ContentComponent,\n FooterComponent,\n } = useConfigurationContext();\n\n return (\n <Fragment>\n {title &&\n (isString(title) ? (\n <TitleComponent context={userDefinedContext}>\n {title}\n </TitleComponent>\n ) : (\n title\n ))}\n {subtitle &&\n (isString(subtitle) ? (\n <SubtitleComponent context={userDefinedContext}>\n {subtitle}\n </SubtitleComponent>\n ) : (\n subtitle\n ))}\n {content &&\n (isString(content) ? (\n <ContentComponent context={userDefinedContext}>\n {content}\n </ContentComponent>\n ) : (\n renderComponent(content, {\n onConfirm: handleConfirm,\n onCancel: handleClose,\n context: userDefinedContext,\n })\n ))}\n\n {Input && (\n <Input\n defaultValue={defaultValue}\n value={value}\n onChange={handleChange}\n onConfirm={handleConfirm}\n onCancel={handleClose}\n context={userDefinedContext}\n />\n )}\n\n {footer !== false &&\n (typeof footer === 'function' ? (\n footer({\n value,\n disabled,\n onChange: handleChange,\n onConfirm: handleConfirm,\n onCancel: handleClose,\n context: userDefinedContext,\n })\n ) : (\n <FooterComponent\n disabled={disabled}\n onConfirm={handleConfirm}\n onCancel={handleClose}\n confirmLabel={footer?.confirm}\n cancelLabel={footer?.cancel}\n hideConfirm={footer?.hideConfirm}\n hideCancel={footer?.hideCancel}\n context={userDefinedContext}\n />\n ))}\n </Fragment>\n );\n },\n);\n","import { useMemo } from 'react';\n\nimport { cx } from '@emotion/css';\n\nimport {\n useConfigurationContext,\n useModal,\n useUserDefinedContext,\n} from '@/promise-modal/providers';\nimport type { ModalLayerProps } from '@/promise-modal/types';\n\nimport { active, foreground, visible } from './classNames.emotion';\nimport { AlertInner, ConfirmInner, PromptInner } from './components';\n\nexport const ForegroundFrame = ({\n modalId,\n onChangeOrder,\n}: ModalLayerProps) => {\n const { ForegroundComponent } = useConfigurationContext();\n const { context: userDefinedContext } = useUserDefinedContext();\n\n const { modal, onChange, onConfirm, onClose, onDestroy } = useModal(modalId);\n\n const Foreground = useMemo(\n () => modal?.ForegroundComponent || ForegroundComponent,\n [ForegroundComponent, modal],\n );\n\n if (!modal) return null;\n\n return (\n <div\n className={cx(foreground, {\n [visible]: modal.manualDestroy ? modal.alive : modal.visible,\n [active]: modal.visible,\n })}\n >\n <Foreground\n id={modal.id}\n type={modal.type}\n alive={modal.alive}\n visible={modal.visible}\n initiator={modal.initiator}\n manualDestroy={modal.manualDestroy}\n closeOnBackdropClick={modal.closeOnBackdropClick}\n background={modal.background}\n onChange={onChange}\n onConfirm={onConfirm}\n onClose={onClose}\n onDestroy={onDestroy}\n onChangeOrder={onChangeOrder}\n context={userDefinedContext}\n >\n {modal.type === 'alert' && (\n <AlertInner modal={modal} handlers={{ onConfirm }} />\n )}\n {modal.type === 'confirm' && (\n <ConfirmInner modal={modal} handlers={{ onConfirm, onClose }} />\n )}\n {modal.type === 'prompt' && (\n <PromptInner\n modal={modal}\n handlers={{ onChange, onConfirm, onClose }}\n />\n )}\n </Foreground>\n </div>\n );\n};\n","import { useEffect } from 'react';\n\nimport { useVersion } from '@winglet/react-utils';\n\nimport type { ModalNode } from '@/promise-modal/core';\n\nexport const useSubscribeModal = (modal?: ModalNode) => {\n const [version, update] = useVersion();\n useEffect(() => {\n if (!modal) return;\n const unsubscribe = modal.subscribe(update);\n return unsubscribe;\n }, [modal, update]);\n return version;\n};\n","import { css } from '@emotion/css';\n\nexport const presenter = css`\n position: fixed;\n inset: 0;\n pointer-events: none;\n overflow: hidden;\n`;\n","import { memo, useRef } from 'react';\n\nimport { counterFactory } from '@winglet/common-utils';\nimport { useHandle } from '@winglet/react-utils';\n\nimport { Background } from '@/promise-modal/components/Background';\nimport { Foreground } from '@/promise-modal/components/Foreground';\nimport { useSubscribeModal } from '@/promise-modal/hooks/useSubscribeModal';\nimport { useModal } from '@/promise-modal/providers';\nimport type { ModalIdProps } from '@/promise-modal/types';\n\nimport { presenter } from './classNames.emotion';\n\nconst { increment } = counterFactory(1);\n\nexport const Presenter = memo(({ modalId }: ModalIdProps) => {\n const ref = useRef<HTMLDivElement>(null);\n const { modal } = useModal(modalId);\n useSubscribeModal(modal);\n const handleChangeOrder = useHandle(() => {\n if (ref.current) {\n ref.current.style.zIndex = `${increment()}`;\n }\n });\n return (\n <div ref={ref} className={presenter}>\n <Background modalId={modalId} onChangeOrder={handleChangeOrder} />\n <Foreground modalId={modalId} onChangeOrder={handleChangeOrder} />\n </div>\n );\n});\n","import { css } from '@emotion/css';\n\nexport const anchor = css`\n display: flex;\n align-items: center;\n justify-content: center;\n position: fixed;\n inset: 0;\n pointer-events: none;\n z-index: 1000;\n transition: background-color ease-in-out;\n`;\n","import { memo, useEffect } from 'react';\n\nimport { map } from '@winglet/common-utils';\nimport { useVersion, withErrorBoundary } from '@winglet/react-utils';\n\nimport { Presenter } from '@/promise-modal/components/Presenter';\nimport type { ModalNode } from '@/promise-modal/core';\nimport { useActiveModalCount } from '@/promise-modal/hooks/useActiveModalCount';\nimport {\n useConfigurationOptions,\n useModalManagerContext,\n} from '@/promise-modal/providers';\n\nimport { anchor } from './classNames.emotion';\n\nconst AnchorInner = () => {\n const [version, update] = useVersion();\n\n const { modalIds, setUpdater } = useModalManagerContext();\n\n useEffect(() => {\n setUpdater(update);\n }, [setUpdater, update]);\n\n const options = useConfigurationOptions();\n\n const dimmed = useActiveModalCount(validateDimmable, version);\n\n return (\n <div\n className={anchor}\n style={{\n transitionDuration: options.duration,\n backgroundColor: dimmed ? options.backdrop : 'transparent',\n }}\n >\n {map(modalIds, (id) => (\n <Presenter key={id} modalId={id} />\n ))}\n </div>\n );\n};\n\nconst validateDimmable = (modal?: ModalNode) => modal?.visible && modal.dimmed;\n\nexport const Anchor = memo(withErrorBoundary(AnchorInner));\n","import { createPortal } from 'react-dom';\n\nimport type { Dictionary, Fn } from '@aileron/declare';\n\nimport { Anchor } from '@/promise-modal/components/Anchor';\nimport {\n ConfigurationContextProvider,\n type ConfigurationContextProviderProps,\n} from '@/promise-modal/providers/ConfigurationContext';\nimport { ModalManagerContextProvider } from '@/promise-modal/providers/ModalManagerContext';\nimport { UserDefinedContextProvider } from '@/promise-modal/providers/UserDefinedContext';\n\ninterface BootstrapProps extends ConfigurationContextProviderProps {\n usePathname: Fn<[], { pathname: string }>;\n context?: Dictionary;\n anchor: HTMLElement;\n}\n\nexport const bootstrap = ({\n ForegroundComponent,\n BackgroundComponent,\n TitleComponent,\n SubtitleComponent,\n ContentComponent,\n FooterComponent,\n usePathname,\n options,\n context,\n anchor,\n}: BootstrapProps) =>\n createPortal(\n <UserDefinedContextProvider context={context}>\n <ConfigurationContextProvider\n ForegroundComponent={ForegroundComponent}\n BackgroundComponent={BackgroundComponent}\n TitleComponent={TitleComponent}\n SubtitleComponent={SubtitleComponent}\n ContentComponent={ContentComponent}\n FooterComponent={FooterComponent}\n options={options}\n >\n <ModalManagerContextProvider usePathname={usePathname}>\n <Anchor />\n </ModalManagerContextProvider>\n </ConfigurationContextProvider>\n </UserDefinedContextProvider>,\n anchor,\n );\n","import { useCallback, useRef } from 'react';\n\nimport { printError } from '@winglet/common-utils';\nimport { useVersion } from '@winglet/react-utils';\n\nimport { ModalManager } from '@/promise-modal/app/ModalManager';\n\nexport const useInitialize = () => {\n const permitted = useRef(ModalManager.activate());\n const anchorRef = useRef<HTMLElement | null>(null);\n const [, update] = useVersion();\n\n const handleInitialize = useCallback(\n (root?: HTMLElement) => {\n if (permitted.current) {\n anchorRef.current = ModalManager.anchor({ root });\n update();\n } else\n printError(\n 'ModalProvider is already initialized',\n [\n 'ModalProvider can only be initialized once.',\n 'Nesting ModalProvider will be ignored...',\n ],\n {\n info: 'Something is wrong with the ModalProvider initialization...',\n },\n );\n },\n [update],\n );\n\n return {\n anchorRef,\n handleInitialize,\n } as const;\n};\n","import {\n Fragment,\n type PropsWithChildren,\n forwardRef,\n useImperativeHandle,\n useMemo,\n} from 'react';\n\nimport { useOnMount } from '@winglet/react-utils';\n\nimport { usePathname as useDefaultPathname } from '@/promise-modal/hooks/useDefaultPathname';\n\nimport { bootstrap } from './helpers/bootstrap';\nimport { useInitialize } from './hooks/useInitialize';\nimport type { BootstrapProviderHandle, BootstrapProviderProps } from './type';\n\nexport const BootstrapProvider = forwardRef<\n BootstrapProviderHandle,\n PropsWithChildren<BootstrapProviderProps>\n>(\n (\n {\n usePathname: useExternalPathname,\n ForegroundComponent,\n BackgroundComponent,\n TitleComponent,\n SubtitleComponent,\n ContentComponent,\n FooterComponent,\n options,\n context,\n children,\n },\n handleRef,\n ) => {\n const usePathname = useMemo(\n () => useExternalPathname || useDefaultPathname,\n [useExternalPathname],\n );\n\n const { anchorRef, handleInitialize } = useInitialize();\n\n useImperativeHandle(\n handleRef,\n () => ({\n initialize: handleInitialize,\n }),\n [handleInitialize],\n );\n\n useOnMount(() => {\n /**\n * NOTE: `handleRef` being null indicates that no `ref` was provided.\n * In this case, the `ModalProvider`(=`BootstrapProvider`) is not receiving the `ref`,\n * so it should be initialized automatically.\n */\n if (handleRef === null) handleInitialize();\n return () => {\n if (anchorRef.current) anchorRef.current.remove();\n };\n });\n\n return (\n <Fragment>\n {children}\n {anchorRef.current &&\n bootstrap({\n ForegroundComponent,\n BackgroundComponent,\n TitleComponent,\n SubtitleComponent,\n ContentComponent,\n FooterComponent,\n usePathname,\n options,\n context,\n anchor: anchorRef.current,\n })}\n </Fragment>\n );\n },\n);\n","import type { ComponentType, ReactNode } from 'react';\n\nimport { ModalManager } from '@/promise-modal/app/ModalManager';\nimport type {\n AlertContentProps,\n AlertFooterRender,\n BackgroundComponent,\n FooterOptions,\n ForegroundComponent,\n ModalBackground,\n} from '@/promise-modal/types';\n\ninterface AlertProps<B> {\n subtype?: 'info' | 'success' | 'warning' | 'error';\n title?: ReactNode;\n subtitle?: ReactNode;\n content?: ReactNode | ComponentType<AlertContentProps>;\n background?: ModalBackground<B>;\n footer?:\n | AlertFooterRender\n | Pick<FooterOptions, 'confirm' | 'hideConfirm'>\n | false;\n dimmed?: boolean;\n manualDestroy?: boolean;\n closeOnBackdropClick?: boolean;\n ForegroundComponent?: ForegroundComponent;\n BackgroundComponent?: BackgroundComponent;\n}\n\nexport const alert = <B = any>({\n subtype,\n title,\n subtitle,\n content,\n background,\n footer,\n dimmed,\n manualDestroy,\n closeOnBackdropClick,\n ForegroundComponent,\n BackgroundComponent,\n}: AlertProps<B>) => {\n return new Promise<void>((resolve, reject) => {\n try {\n ModalManager.open({\n type: 'alert',\n subtype,\n resolve: () => resolve(),\n title,\n subtitle,\n content,\n background,\n footer,\n dimmed,\n manualDestroy,\n closeOnBackdropClick,\n ForegroundComponent,\n BackgroundComponent,\n });\n } catch (error) {\n reject(error);\n }\n });\n};\n","import type { ComponentType, ReactNode } from 'react';\n\nimport { ModalManager } from '@/promise-modal/app/ModalManager';\nimport type {\n BackgroundComponent,\n ConfirmContentProps,\n ConfirmFooterRender,\n FooterOptions,\n ForegroundComponent,\n ModalBackground,\n} from '@/promise-modal/types';\n\ninterface ConfirmProps<B> {\n subtype?: 'info' | 'success' | 'warning' | 'error';\n title?: ReactNode;\n subtitle?: ReactNode;\n content?: ReactNode | ComponentType<ConfirmContentProps>;\n background?: ModalBackground<B>;\n footer?: ConfirmFooterRender | FooterOptions | false;\n dimmed?: boolean;\n manualDestroy?: boolean;\n closeOnBackdropClick?: boolean;\n ForegroundComponent?: ForegroundComponent;\n BackgroundComponent?: BackgroundComponent;\n}\n\nexport const confirm = <B = any>({\n subtype,\n title,\n subtitle,\n content,\n background,\n footer,\n dimmed,\n manualDestroy,\n closeOnBackdropClick,\n ForegroundComponent,\n BackgroundComponent,\n}: ConfirmProps<B>) => {\n return new Promise<boolean>((resolve, reject) => {\n try {\n ModalManager.open({\n type: 'confirm',\n subtype,\n resolve: (result) => resolve(result ?? false),\n title,\n subtitle,\n content,\n background,\n footer,\n dimmed,\n manualDestroy,\n closeOnBackdropClick,\n ForegroundComponent,\n BackgroundComponent,\n });\n } catch (error) {\n reject(error);\n }\n });\n};\n","import type { ComponentType, ReactNode } from 'react';\n\nimport { ModalManager } from '@/promise-modal/app/ModalManager';\nimport type {\n BackgroundComponent,\n FooterOptions,\n ForegroundComponent,\n ModalBackground,\n PromptContentProps,\n PromptFooterRender,\n PromptInputProps,\n} from '@/promise-modal/types';\n\ninterface PromptProps<T, B = any> {\n title?: ReactNode;\n subtitle?: ReactNode;\n content?: ReactNode | ComponentType<PromptContentProps>;\n Input: (props: PromptInputProps<T>) => ReactNode;\n defaultValue?: T;\n disabled?: (value: T) => boolean;\n returnOnCancel?: boolean;\n background?: ModalBackground<B>;\n footer?: PromptFooterRender<T> | FooterOptions | false;\n dimmed?: boolean;\n manualDestroy?: boolean;\n closeOnBackdropClick?: boolean;\n ForegroundComponent?: ForegroundComponent;\n BackgroundComponent?: BackgroundComponent;\n}\n\nexport const prompt = <T, B = any>({\n defaultValue,\n title,\n subtitle,\n content,\n Input,\n disabled,\n returnOnCancel,\n background,\n footer,\n dimmed,\n manualDestroy,\n closeOnBackdropClick,\n ForegroundComponent,\n BackgroundComponent,\n}: PromptProps<T, B>) => {\n return new Promise<T>((resolve, reject) => {\n try {\n ModalManager.open({\n type: 'prompt',\n resolve: (result) => resolve(result as T),\n title,\n subtitle,\n content,\n Input,\n defaultValue,\n disabled,\n returnOnCancel,\n background,\n footer,\n dimmed,\n manualDestroy,\n closeOnBackdropClick,\n ForegroundComponent,\n BackgroundComponent,\n });\n } catch (error) {\n reject(error);\n }\n });\n};\n","import { useEffect, useRef } from 'react';\n\nimport { convertMsFromDuration, isString } from '@winglet/common-utils';\n\nimport type { Duration } from '@aileron/declare';\n\nimport type { ModalNode } from '@/promise-modal/core';\nimport { useModal } from '@/promise-modal/providers';\n\nimport { useSubscribeModal } from './useSubscribeModal';\n\nexport const useDestroyAfter = (\n modalId: ModalNode['id'],\n duration: Duration | number,\n) => {\n const { modal, onDestroy } = useModal(modalId);\n const tick = useSubscribeModal(modal);\n\n const reference = useRef({\n modal,\n onDestroy,\n milliseconds: isString(duration)\n ? convertMsFromDuration(duration)\n : duration,\n });\n\n useEffect(() => {\n const { modal, onDestroy, milliseconds } = reference.current;\n if (!modal || modal.visible || !modal.alive) return;\n const timer = setTimeout(() => {\n onDestroy();\n }, milliseconds);\n return () => {\n if (timer) clearTimeout(timer);\n };\n }, [tick]);\n};\n","import { useCallback, useMemo } from 'react';\n\nimport { useOnMount } from '@winglet/react-utils';\n\nimport { usePathname as useDefaultPathname } from '@/promise-modal/hooks/useDefaultPathname';\n\nimport { bootstrap } from './helpers/bootstrap';\nimport { useInitialize } from './hooks/useInitialize';\nimport type { BootstrapProviderProps } from './type';\n\nexport const useBootstrap = ({\n usePathname: useExternalPathname,\n ForegroundComponent,\n BackgroundComponent,\n TitleComponent,\n SubtitleComponent,\n ContentComponent,\n FooterComponent,\n options,\n context,\n mode = 'auto',\n}: BootstrapProviderProps & { mode?: 'manual' | 'auto' } = {}) => {\n const usePathname = useMemo(\n () => useExternalPathname || useDefaultPathname,\n [useExternalPathname],\n );\n\n const { anchorRef, handleInitialize } = useInitialize();\n\n useOnMount(() => {\n if (mode === 'auto') handleInitialize();\n return () => {\n if (anchorRef.current) anchorRef.current.remove();\n };\n });\n\n const initialize = useCallback(\n (element: HTMLElement) => {\n if (mode === 'manual') handleInitialize(element);\n },\n [mode, handleInitialize],\n );\n\n const portal =\n anchorRef.current &&\n bootstrap({\n usePathname,\n ForegroundComponent,\n BackgroundComponent,\n TitleComponent,\n SubtitleComponent,\n ContentComponent,\n FooterComponent,\n options,\n context,\n anchor: anchorRef.current,\n });\n\n return { portal, initialize };\n};\n","import { useLayoutEffect, useRef } from 'react';\n\nimport type { Fn } from '@aileron/declare';\n\ninterface ModalAnimationHandler {\n onVisible?: Fn;\n onHidden?: Fn;\n}\n\nexport const useModalAnimation = (\n visible: boolean,\n handler: ModalAnimationHandler,\n) => {\n const handlerRef = useRef(handler);\n handlerRef.current = handler;\n useLayoutEffect(() => {\n if (!handlerRef.current) return;\n let frame: ReturnType<typeof requestAnimationFrame>;\n if (visible)\n frame = requestAnimationFrame(() => handlerRef.current.onVisible?.());\n else frame = requestAnimationFrame(() => handlerRef.current.onHidden?.());\n return () => {\n if (frame) cancelAnimationFrame(frame);\n };\n }, [visible]);\n};\n"],"names":["ModalManager","activate","__active__","anchor","options","__anchor__","document","getElementById","id","tag","prefix","root","body","node","createElement","setAttribute","getRandomString","appendChild","prerender","__prerenderList__","openHandler","handler","__openHandler__","unanchored","reset","modal","push","open","AbstractNode","alive","this","__alive__","visible","__visible__","constructor","initiator","title","subtitle","background","dimmed","manualDestroy","closeOnBackdropClick","resolve","ForegroundComponent","BackgroundComponent","__listeners__","Set","__resolve__","subscribe","listener","add","delete","publish","result","onDestroy","needPublish","onShow","onHide","AlertNode","type","subtype","content","footer","super","onClose","onConfirm","ConfirmNode","PromptNode","defaultValue","Input","disabled","returnOnCancel","__value__","onChange","value","nodeFactory","Error","ModalManagerContext","createContext","ModalManagerContextProvider","memo","usePathname","children","modalDictionary","useRef","Map","modalIds","setModalIds","useState","modalIdsRef","useReference","pathname","modalIdSequence","useConfigurationOptions","duration","useMemo","convertMsFromDuration","useOnMountLayout","data","current","undefined","set","ids","aliveIds","index","length","get","useLayoutEffect","getModalNode","useCallback","modalId","updaterRef","hideModal","setTimeout","getModal","setUpdater","updater","_jsx","jsx","Provider","useModalManagerContext","useContext","useModal","fallback","css","process","env","NODE_ENV","name","styles","toString","_EMOTION_STRINGIFIED_CSS_ERROR__","frame","FallbackTitle","className","FallbackSubtitle","FallbackContent","FallbackFooter","confirmLabel","hideConfirm","cancelLabel","hideCancel","onCancel","_jsxs","onClick","defaultValidate","useActiveModalCount","validate","refreshKey","count","FallbackForegroundFrame","forwardRef","onChangeOrder","ref","activeCount","level","offset","stacked","Math","floor","style","marginBottom","marginLeft","transform","ConfigurationContext","ConfigurationContextProvider","TitleComponent","SubtitleComponent","ContentComponent","FooterComponent","backdrop","useConfigurationContext","UserDefinedContext","UserDefinedContextProvider","context","contextValue","useUserDefinedContext","setPathname","window","location","requestId","checkPathname","cancelAnimationFrame","requestAnimationFrame","active","BackgroundFrame","userDefinedContext","handleClose","event","stopPropagation","Background","cx","visible$1","active$1","foreground","AlertInner","handlers","handleConfirm","useHandle","Fragment","isString","renderComponent","confirm","ConfirmInner","cancel","PromptInner","checkDisabled","withErrorBoundary","setValue","handleChange","inputValue","input","isFunction","ForegroundFrame","Foreground","useSubscribeModal","version","update","useVersion","useEffect","presenter","increment","counterFactory","Presenter","handleChangeOrder","zIndex","validateDimmable","Anchor","transitionDuration","backgroundColor","map","bootstrap","createPortal","useInitialize","permitted","anchorRef","handleInitialize","printError","info","BootstrapProvider","useExternalPathname","handleRef","useDefaultPathname","useImperativeHandle","initialize","useOnMount","remove","Promise","reject","error","tick","reference","milliseconds","timer","clearTimeout","mode","element","portal","handlerRef","onVisible","onHidden"],"mappings":"+LAMaA,EAEX,eAAOC,GACL,OAAID,EAAaE,aACTF,EAAaE,YAAa,GAIpC,aAAOC,CAAOC,GAKZ,GAAIJ,EAAaK,WAAY,CAC3B,MAAMF,EAASG,SAASC,eAAeP,EAAaK,WAAWG,IAC/D,GAAIL,EAAQ,OAAOA,EAErB,MAAMM,IACJA,EAAM,MAAKC,OACXA,EAAS,gBAAeC,KACxBA,EAAOL,SAASM,MACdR,GAAW,CAAE,EACXS,EAAOP,SAASQ,cAAcL,GAIpC,OAHAI,EAAKE,aAAa,KAAM,GAAGL,KAAUM,EAAeA,gBAAC,OACrDL,EAAKM,YAAYJ,GACjBb,EAAaK,WAAaQ,EACnBA,EAIT,oBAAWK,GACT,OAAOlB,EAAamB,kBAKtB,sBAAWC,CAAYC,GACrBrB,EAAasB,gBAAkBD,EAC/BrB,EAAamB,kBAAoB,GAGnC,qBAAWI,GACT,OAAQvB,EAAaK,WAGvB,YAAOmB,GACLxB,EAAaE,YAAa,EAC1BF,EAAaK,WAAa,KAC1BL,EAAamB,kBAAoB,GACjCnB,EAAasB,gBAAmBG,GAC9BzB,EAAamB,kBAAkBO,KAAKD,GAGxC,WAAOE,CAAKF,GACVzB,EAAasB,gBAAgBG,IArDhBzB,EAAUE,YAAG,EAMbF,EAAUK,WAAuB,KAsBjCL,EAAiBmB,kBAAY,GAK7BnB,EAAAsB,gBAAsCG,GACnDz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ACAC,oBACAC,mBACAC,kBACArK,UACA0K,UACA3K,OAAQwO,EAAUxI,UAGLiJ,aAAY,4BCjDE,CAC/BpN,EACAX,KAEA,MAAM6O,EAAa9K,EAAMA,OAAC/D,GAC1B6O,EAAW/J,QAAU9E,EACrBsF,EAAAA,iBAAgB,KACd,IAAKuJ,EAAW/J,QAAS,OACzB,IAAIiC,EAIJ,OAFEA,EADEpG,EACMuJ,uBAAsB,IAAM2E,EAAW/J,QAAQgK,gBAC5C5E,uBAAsB,IAAM2E,EAAW/J,QAAQiK,eACrD,KACDhI,GAAOkD,qBAAqBlD,EAAM,CACvC,GACA,CAACpG,GAAS,2BzBHyB,IACtB6D,IACD6E,kCAVuB,KACtC,MAAMI,EAAUjF,IAChB,MAAO,CACLC,SAAUgF,EAAQhF,SAClB8J,aAAc5J,EAAAA,sBAAsB8E,EAAQhF,UAC7C"}
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":["../src/app/ModalManager.ts","../src/core/node/ModalNode/AbstractNode.ts","../src/core/node/ModalNode/AlertNode.ts","../src/core/node/ModalNode/ConfirmNode.ts","../src/core/node/ModalNode/PromptNode.ts","../src/core/node/nodeFactory.ts","../src/providers/ModalManagerContext/ModalManagerContext.ts","../src/providers/ModalManagerContext/ModalManagerContextProvider.tsx","../src/providers/ModalManagerContext/useModalManagerContext.ts","../src/components/FallbackComponents/classNames.emotion.ts","../src/components/FallbackComponents/FallbackTitle.tsx","../src/components/FallbackComponents/FallbackSubtitle.tsx","../src/components/FallbackComponents/FallbackContent.tsx","../src/components/FallbackComponents/FallbackFooter.tsx","../src/hooks/useActiveModalCount.ts","../src/components/FallbackComponents/FallbackForegroundFrame.tsx","../src/providers/ConfigurationContext/ConfigurationContext.ts","../src/providers/ConfigurationContext/ConfigurationContextProvider.tsx","../src/app/constant.ts","../src/providers/ConfigurationContext/useConfigurationContext.ts","../src/providers/UserDefinedContext/UserDefinedContext.ts","../src/providers/UserDefinedContext/UserDefinedContextProvider.tsx","../src/providers/UserDefinedContext/useUserDefinedContext.ts","../src/hooks/useDefaultPathname.ts","../src/components/Background/classNames.emotion.ts","../src/components/Background/Background.tsx","../src/components/Foreground/classNames.emotion.ts","../src/components/Foreground/components/AlertInner.tsx","../src/components/Foreground/components/ConfirmInner.tsx","../src/components/Foreground/components/PromptInner.tsx","../src/components/Foreground/Foreground.tsx","../src/hooks/useSubscribeModal.ts","../src/components/Presenter/classNames.emotion.ts","../src/components/Presenter/Presenter.tsx","../src/components/Anchor/classNames.emotion.ts","../src/components/Anchor/Anchor.tsx","../src/bootstrap/BootstrapProvider/helpers/bootstrap.tsx","../src/bootstrap/BootstrapProvider/hooks/useInitialize.ts","../src/bootstrap/BootstrapProvider/BootstrapProvider.tsx","../src/core/handle/alert.ts","../src/core/handle/confirm.ts","../src/core/handle/prompt.ts","../src/hooks/useDestroyAfter.ts","../src/bootstrap/BootstrapProvider/useBootstrap.tsx","../src/hooks/useModalAnimation.ts"],"sourcesContent":["import { getRandomString } from '@winglet/common-utils';\n\nimport type { Fn } from '@aileron/declare';\n\nimport type { Modal } from '@/promise-modal/types';\n\nexport class ModalManager {\n static #active = false;\n static activate() {\n if (ModalManager.#active) return false;\n return (ModalManager.#active = true);\n }\n\n static #anchor: HTMLElement | null = null;\n static anchor(options?: {\n tag?: string;\n prefix?: string;\n root?: HTMLElement;\n }): HTMLElement {\n if (ModalManager.#anchor) {\n const anchor = document.getElementById(ModalManager.#anchor.id);\n if (anchor) return anchor;\n }\n const {\n tag = 'div',\n prefix = 'promise-modal',\n root = document.body,\n } = options || {};\n const node = document.createElement(tag);\n node.setAttribute('id', `${prefix}-${getRandomString(36)}`);\n root.appendChild(node);\n ModalManager.#anchor = node;\n return node;\n }\n\n static #prerenderList: Modal[] = [];\n static get prerender() {\n return ModalManager.#prerenderList;\n }\n\n static #openHandler: Fn<[Modal], void> = (modal: Modal) =>\n ModalManager.#prerenderList.push(modal);\n static set openHandler(handler: Fn<[Modal], void>) {\n ModalManager.#openHandler = handler;\n ModalManager.#prerenderList = [];\n }\n\n static get unanchored() {\n return !ModalManager.#anchor;\n }\n\n static reset() {\n ModalManager.#active = false;\n ModalManager.#anchor = null;\n ModalManager.#prerenderList = [];\n ModalManager.#openHandler = (modal: Modal) =>\n ModalManager.#prerenderList.push(modal);\n }\n\n static open(modal: Modal) {\n ModalManager.#openHandler(modal);\n }\n}\n","import type { ReactNode } from 'react';\n\nimport type { Fn } from '@aileron/declare';\n\nimport type {\n BackgroundComponent,\n BaseModal,\n ForegroundComponent,\n ManagedEntity,\n ModalBackground,\n} from '@/promise-modal/types';\n\ntype AbstractNodeProps<T, B> = BaseModal<T, B> & ManagedEntity;\n\nexport abstract class AbstractNode<T, B> {\n readonly id: number;\n readonly initiator: string;\n\n readonly title?: ReactNode;\n readonly subtitle?: ReactNode;\n readonly background?: ModalBackground<B>;\n\n readonly manualDestroy: boolean;\n readonly closeOnBackdropClick: boolean;\n readonly dimmed: boolean;\n\n readonly ForegroundComponent?: ForegroundComponent;\n readonly BackgroundComponent?: BackgroundComponent;\n\n #alive: boolean;\n get alive() {\n return this.#alive;\n }\n #visible: boolean;\n get visible() {\n return this.#visible;\n }\n\n #resolve: (result: T | null) => void;\n #listeners: Set<Fn> = new Set();\n\n constructor({\n id,\n initiator,\n title,\n subtitle,\n background,\n dimmed = true,\n manualDestroy = false,\n closeOnBackdropClick = true,\n resolve,\n ForegroundComponent,\n BackgroundComponent,\n }: AbstractNodeProps<T, B>) {\n this.id = id;\n this.initiator = initiator;\n this.title = title;\n this.subtitle = subtitle;\n this.background = background;\n\n this.dimmed = dimmed;\n this.manualDestroy = manualDestroy;\n this.closeOnBackdropClick = closeOnBackdropClick;\n\n this.ForegroundComponent = ForegroundComponent;\n this.BackgroundComponent = BackgroundComponent;\n\n this.#alive = true;\n this.#visible = true;\n this.#resolve = resolve;\n }\n\n subscribe(listener: Fn) {\n this.#listeners.add(listener);\n return () => {\n this.#listeners.delete(listener);\n };\n }\n publish() {\n for (const listener of this.#listeners) listener();\n }\n protected resolve(result: T | null) {\n this.#resolve(result);\n }\n onDestroy() {\n const needPublish = this.#alive === true;\n this.#alive = false;\n if (this.manualDestroy && needPublish) this.publish();\n }\n onShow() {\n const needPublish = this.#visible === false;\n this.#visible = true;\n if (needPublish) this.publish();\n }\n onHide() {\n const needPublish = this.#visible === true;\n this.#visible = false;\n if (needPublish) this.publish();\n }\n abstract onClose(): void;\n abstract onConfirm(): void;\n}\n","import type { ComponentType, ReactNode } from 'react';\n\nimport type {\n AlertContentProps,\n AlertFooterRender,\n AlertModal,\n FooterOptions,\n ManagedEntity,\n} from '@/promise-modal/types';\n\nimport { AbstractNode } from './AbstractNode';\n\ntype AlertNodeProps<B> = AlertModal<B> & ManagedEntity;\n\nexport class AlertNode<B> extends AbstractNode<null, B> {\n readonly type: 'alert';\n readonly subtype?: 'info' | 'success' | 'warning' | 'error';\n readonly content?: ReactNode | ComponentType<AlertContentProps>;\n readonly footer?:\n | AlertFooterRender\n | Pick<FooterOptions, 'confirm' | 'hideConfirm'>\n | false;\n\n constructor({\n id,\n initiator,\n type,\n subtype,\n title,\n subtitle,\n content,\n footer,\n background,\n dimmed,\n manualDestroy,\n closeOnBackdropClick,\n resolve,\n ForegroundComponent,\n BackgroundComponent,\n }: AlertNodeProps<B>) {\n super({\n id,\n initiator,\n title,\n subtitle,\n background,\n dimmed,\n manualDestroy,\n closeOnBackdropClick,\n resolve,\n ForegroundComponent,\n BackgroundComponent,\n });\n this.type = type;\n this.subtype = subtype;\n this.content = content;\n this.footer = footer;\n }\n onClose() {\n this.resolve(null);\n }\n onConfirm() {\n this.resolve(null);\n }\n}\n","import type { ComponentType, ReactNode } from 'react';\n\nimport type {\n ConfirmContentProps,\n ConfirmFooterRender,\n ConfirmModal,\n FooterOptions,\n ManagedEntity,\n} from '@/promise-modal/types';\n\nimport { AbstractNode } from './AbstractNode';\n\ntype ConfirmNodeProps<B> = ConfirmModal<B> & ManagedEntity;\n\nexport class ConfirmNode<B> extends AbstractNode<boolean, B> {\n readonly type: 'confirm';\n readonly subtype?: 'info' | 'success' | 'warning' | 'error';\n readonly content?: ReactNode | ComponentType<ConfirmContentProps>;\n readonly footer?: ConfirmFooterRender | FooterOptions | false;\n\n constructor({\n id,\n initiator,\n type,\n subtype,\n title,\n subtitle,\n content,\n footer,\n background,\n dimmed,\n manualDestroy,\n closeOnBackdropClick,\n resolve,\n ForegroundComponent,\n BackgroundComponent,\n }: ConfirmNodeProps<B>) {\n super({\n id,\n initiator,\n title,\n subtitle,\n background,\n dimmed,\n manualDestroy,\n closeOnBackdropClick,\n resolve,\n ForegroundComponent,\n BackgroundComponent,\n });\n this.type = type;\n this.subtype = subtype;\n this.content = content;\n this.footer = footer;\n }\n onClose() {\n this.resolve(false);\n }\n onConfirm() {\n this.resolve(true);\n }\n}\n","import type { ComponentType, ReactNode } from 'react';\n\nimport type {\n FooterOptions,\n ManagedEntity,\n PromptContentProps,\n PromptFooterRender,\n PromptInputProps,\n PromptModal,\n} from '@/promise-modal/types';\n\nimport { AbstractNode } from './AbstractNode';\n\ntype PromptNodeProps<T, B> = PromptModal<T, B> & ManagedEntity;\n\nexport class PromptNode<T, B> extends AbstractNode<T, B> {\n readonly type: 'prompt';\n readonly content?: ReactNode | ComponentType<PromptContentProps>;\n readonly defaultValue: T | undefined;\n readonly Input: (props: PromptInputProps<T>) => ReactNode;\n readonly disabled?: (value: T) => boolean;\n readonly returnOnCancel?: boolean;\n readonly footer?: PromptFooterRender<T> | FooterOptions | false;\n\n #value: T | undefined;\n\n constructor({\n id,\n initiator,\n type,\n title,\n subtitle,\n content,\n defaultValue,\n Input,\n disabled,\n returnOnCancel,\n footer,\n background,\n dimmed,\n manualDestroy,\n closeOnBackdropClick,\n resolve,\n ForegroundComponent,\n BackgroundComponent,\n }: PromptNodeProps<T, B>) {\n super({\n id,\n initiator,\n title,\n subtitle,\n background,\n dimmed,\n manualDestroy,\n closeOnBackdropClick,\n resolve,\n ForegroundComponent,\n BackgroundComponent,\n });\n this.type = type;\n this.content = content;\n this.Input = Input;\n this.defaultValue = defaultValue;\n this.#value = defaultValue;\n this.disabled = disabled;\n this.returnOnCancel = returnOnCancel;\n this.footer = footer;\n }\n\n onChange(value: T) {\n this.#value = value;\n }\n onConfirm() {\n this.resolve(this.#value ?? null);\n }\n onClose() {\n if (this.returnOnCancel) this.resolve(this.#value ?? null);\n else this.resolve(null);\n }\n}\n","import type { ManagedModal } from '@/promise-modal/types';\n\nimport { AlertNode, ConfirmNode, PromptNode } from './ModalNode';\n\nexport const nodeFactory = <T, B>(modal: ManagedModal<T, B>) => {\n switch (modal.type) {\n case 'alert':\n return new AlertNode<B>(modal);\n case 'confirm':\n return new ConfirmNode<B>(modal);\n case 'prompt':\n return new PromptNode<T, B>(modal);\n }\n // @ts-expect-error: This state is unreachable by design and should NEVER occur.\n throw new Error(`Unknown modal: ${modal.type}`, { modal });\n};\n","import { createContext } from 'react';\n\nimport type { Fn } from '@aileron/declare';\n\nimport type { ModalNode } from '@/promise-modal/core';\nimport type { ModalActions, ModalHandlersWithId } from '@/promise-modal/types';\n\nexport interface ModalManagerContextProps extends ModalHandlersWithId {\n modalIds: ModalNode['id'][];\n getModal: Fn<[id: ModalNode['id']], ModalActions>;\n getModalNode: Fn<[id: ModalNode['id']], ModalNode | undefined>;\n setUpdater: Fn<[updater: Fn]>;\n}\n\nexport const ModalManagerContext = createContext<ModalManagerContextProps>(\n {} as ModalManagerContextProps,\n);\n","import {\n type PropsWithChildren,\n memo,\n useCallback,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\n\nimport { convertMsFromDuration } from '@winglet/common-utils';\nimport { useOnMountLayout, useReference } from '@winglet/react-utils';\n\nimport type { Fn } from '@aileron/declare';\n\nimport { ModalManager } from '@/promise-modal/app/ModalManager';\nimport { type ModalNode, nodeFactory } from '@/promise-modal/core';\nimport { useConfigurationOptions } from '@/promise-modal/providers';\nimport type { Modal } from '@/promise-modal/types';\n\nimport { ModalManagerContext } from './ModalManagerContext';\n\ninterface ModalManagerContextProviderProps {\n usePathname: Fn<[], { pathname: string }>;\n}\n\nexport const ModalManagerContextProvider = memo(\n ({\n usePathname,\n children,\n }: PropsWithChildren<ModalManagerContextProviderProps>) => {\n const modalDictionary = useRef<Map<ModalNode['id'], ModalNode>>(new Map());\n\n const [modalIds, setModalIds] = useState<ModalNode['id'][]>([]);\n const modalIdsRef = useReference(modalIds);\n const { pathname } = usePathname();\n\n const initiator = useRef(pathname);\n const modalIdSequence = useRef(0);\n\n const options = useConfigurationOptions();\n\n const duration = useMemo(\n () => convertMsFromDuration(options.duration),\n [options],\n );\n\n useOnMountLayout(() => {\n const { manualDestroy, closeOnBackdropClick } = options;\n\n for (const data of ModalManager.prerender) {\n const modal = nodeFactory({\n ...data,\n id: modalIdSequence.current++,\n initiator: initiator.current,\n manualDestroy:\n data.manualDestroy !== undefined\n ? data.manualDestroy\n : manualDestroy,\n closeOnBackdropClick:\n data.closeOnBackdropClick !== undefined\n ? data.closeOnBackdropClick\n : closeOnBackdropClick,\n });\n modalDictionary.current.set(modal.id, modal);\n setModalIds((ids) => [...ids, modal.id]);\n }\n\n ModalManager.openHandler = (data: Modal) => {\n const modal = nodeFactory({\n ...data,\n id: modalIdSequence.current++,\n initiator: initiator.current,\n manualDestroy:\n data.manualDestroy !== undefined\n ? data.manualDestroy\n : manualDestroy,\n closeOnBackdropClick:\n data.closeOnBackdropClick !== undefined\n ? data.closeOnBackdropClick\n : closeOnBackdropClick,\n });\n modalDictionary.current.set(modal.id, modal);\n setModalIds((ids) => {\n const aliveIds: number[] = [];\n for (let index = 0; index < ids.length; index++) {\n const id = ids[index];\n const destroyed = !modalDictionary.current.get(id)?.alive;\n if (destroyed) modalDictionary.current.delete(id);\n else aliveIds.push(id);\n }\n return [...aliveIds, modal.id];\n });\n };\n return () => {\n ModalManager.reset();\n };\n });\n\n useLayoutEffect(() => {\n for (const id of modalIdsRef.current) {\n const modal = modalDictionary.current.get(id);\n if (!modal?.alive) continue;\n if (modal.initiator === pathname) modal.onShow();\n else modal.onHide();\n }\n initiator.current = pathname;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [pathname]);\n\n const getModalNode = useCallback((modalId: ModalNode['id']) => {\n return modalDictionary.current.get(modalId);\n }, []);\n\n const onDestroy = useCallback((modalId: ModalNode['id']) => {\n const modal = modalDictionary.current.get(modalId);\n if (!modal) return;\n modal.onDestroy();\n updaterRef.current?.();\n }, []);\n\n const updaterRef = useRef<Fn>(undefined);\n const hideModal = useCallback(\n (modalId: ModalNode['id']) => {\n const modal = modalDictionary.current.get(modalId);\n if (!modal) return;\n modal.onHide();\n updaterRef.current?.();\n if (!modal.manualDestroy)\n setTimeout(() => {\n modal.onDestroy();\n }, duration);\n },\n [duration],\n );\n\n const onChange = useCallback((modalId: ModalNode['id'], value: any) => {\n const modal = modalDictionary.current.get(modalId);\n if (!modal) return;\n if (modal.type === 'prompt') modal.onChange(value);\n }, []);\n\n const onConfirm = useCallback(\n (modalId: ModalNode['id']) => {\n const modal = modalDictionary.current.get(modalId);\n if (!modal) return;\n modal.onConfirm();\n hideModal(modalId);\n },\n [hideModal],\n );\n\n const onClose = useCallback(\n (modalId: ModalNode['id']) => {\n const modal = modalDictionary.current.get(modalId);\n if (!modal) return;\n modal.onClose();\n hideModal(modalId);\n },\n [hideModal],\n );\n\n const getModal = useCallback(\n (modalId: ModalNode['id']) => ({\n modal: getModalNode(modalId),\n onConfirm: () => onConfirm(modalId),\n onClose: () => onClose(modalId),\n onChange: (value: any) => onChange(modalId, value),\n onDestroy: () => onDestroy(modalId),\n }),\n [getModalNode, onConfirm, onClose, onChange, onDestroy],\n );\n\n const value = useMemo(() => {\n return {\n modalIds,\n getModalNode,\n onChange,\n onConfirm,\n onClose,\n onDestroy,\n getModal,\n setUpdater: (updater: Fn) => {\n updaterRef.current = updater;\n },\n };\n }, [\n modalIds,\n getModal,\n getModalNode,\n onChange,\n onConfirm,\n onClose,\n onDestroy,\n ]);\n\n return (\n <ModalManagerContext.Provider value={value}>\n {children}\n </ModalManagerContext.Provider>\n );\n },\n);\n","import { useContext, useMemo } from 'react';\n\nimport type { ManagedModal } from '@/promise-modal/types';\n\nimport { ModalManagerContext } from './ModalManagerContext';\n\nexport const useModalManagerContext = () => useContext(ModalManagerContext);\n\nexport const useModal = (id: ManagedModal['id']) => {\n const { getModal } = useModalManagerContext();\n return useMemo(() => getModal(id), [id, getModal]);\n};\n","import { css } from '@emotion/css';\n\nexport const fallback = css`\n margin: unset;\n`;\n\nexport const frame = css`\n display: flex;\n flex-direction: column;\n justify-content: center;\n align-items: center;\n background-color: white;\n padding: 20px 80px;\n gap: 10px;\n border: 1px solid black;\n`;\n","import type { PropsWithChildren } from 'react';\n\nimport { fallback } from './classNames.emotion';\n\nexport const FallbackTitle = ({ children }: PropsWithChildren) => {\n return <h2 className={fallback}>{children}</h2>;\n};\n","import type { PropsWithChildren } from 'react';\n\nimport { fallback } from './classNames.emotion';\n\nexport const FallbackSubtitle = ({ children }: PropsWithChildren) => {\n return <h3 className={fallback}>{children}</h3>;\n};\n","import type { PropsWithChildren } from 'react';\n\nimport { fallback } from './classNames.emotion';\n\nexport const FallbackContent = ({ children }: PropsWithChildren) => {\n return <div className={fallback}>{children}</div>;\n};\n","import type { FooterComponentProps } from '@/promise-modal/types';\n\nexport const FallbackFooter = ({\n confirmLabel,\n hideConfirm = false,\n cancelLabel,\n hideCancel = false,\n disabled,\n onConfirm,\n onCancel,\n}: FooterComponentProps) => {\n return (\n <div>\n {!hideConfirm && (\n <button onClick={onConfirm} disabled={disabled}>\n {confirmLabel || '확인'}\n </button>\n )}\n\n {!hideCancel && typeof onCancel === 'function' && (\n <button onClick={onCancel}>{cancelLabel || '취소'}</button>\n )}\n </div>\n );\n};\n","import { useMemo } from 'react';\n\nimport type { Fn } from '@aileron/declare';\n\nimport type { ModalNode } from '@/promise-modal/core';\nimport { useModalManagerContext } from '@/promise-modal/providers';\n\nconst defaultValidate = (modal?: ModalNode) => modal?.visible;\n\nexport const useActiveModalCount = (\n validate: Fn<[ModalNode?], boolean | undefined> = defaultValidate,\n refreshKey: string | number = 0,\n) => {\n const { modalIds, getModalNode } = useModalManagerContext();\n return useMemo(() => {\n let count = 0;\n for (const id of modalIds) {\n if (validate(getModalNode(id))) count++;\n }\n return count;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [getModalNode, modalIds, refreshKey]);\n};\n","import {\n type ForwardedRef,\n type PropsWithChildren,\n forwardRef,\n useMemo,\n} from 'react';\n\nimport { useActiveModalCount } from '@/promise-modal/hooks/useActiveModalCount';\nimport type { ModalFrameProps } from '@/promise-modal/types';\n\nimport { frame } from './classNames.emotion';\n\nconst MAX_MODAL_COUNT = 5;\nconst MAX_MODAL_LEVEL = 3;\n\nexport const FallbackForegroundFrame = forwardRef(\n (\n { id, onChangeOrder, children }: PropsWithChildren<ModalFrameProps>,\n ref: ForwardedRef<HTMLDivElement>,\n ) => {\n const activeCount = useActiveModalCount();\n const [level, offset] = useMemo(() => {\n const stacked = activeCount > 1;\n const level = stacked\n ? (Math.floor(id / MAX_MODAL_COUNT) % MAX_MODAL_LEVEL) * 100\n : 0;\n const offset = stacked ? (id % MAX_MODAL_COUNT) * 35 : 0;\n return [level, offset];\n }, [activeCount, id]);\n\n return (\n <div\n ref={ref}\n className={frame}\n onClick={onChangeOrder}\n style={{\n marginBottom: `calc(25vh + ${level}px)`,\n marginLeft: `${level}px`,\n transform: `translate(${offset}px, ${offset}px)`,\n }}\n >\n {children}\n </div>\n );\n },\n);\n","import { type ComponentType, createContext } from 'react';\n\nimport type { Color, Duration } from '@aileron/declare';\n\nimport type {\n BackgroundComponent,\n FooterComponentProps,\n ForegroundComponent,\n WrapperComponentProps,\n} from '@/promise-modal/types';\n\nexport interface ConfigurationContextProps {\n ForegroundComponent: ForegroundComponent;\n BackgroundComponent?: BackgroundComponent;\n TitleComponent: ComponentType<WrapperComponentProps>;\n SubtitleComponent: ComponentType<WrapperComponentProps>;\n ContentComponent: ComponentType<WrapperComponentProps>;\n FooterComponent: ComponentType<FooterComponentProps>;\n options: {\n duration: Duration;\n backdrop: Color;\n manualDestroy: boolean;\n closeOnBackdropClick: boolean;\n };\n}\n\nexport const ConfigurationContext = createContext<ConfigurationContextProps>(\n {} as ConfigurationContextProps,\n);\n","import {\n type ComponentType,\n type PropsWithChildren,\n memo,\n useMemo,\n} from 'react';\n\nimport type { Color, Duration } from '@aileron/declare';\n\nimport {\n DEFAULT_ANIMATION_DURATION,\n DEFAULT_BACKDROP_COLOR,\n} from '@/promise-modal/app/constant';\nimport {\n FallbackContent,\n FallbackFooter,\n FallbackForegroundFrame,\n FallbackSubtitle,\n FallbackTitle,\n} from '@/promise-modal/components/FallbackComponents';\nimport type {\n FooterComponentProps,\n ModalFrameProps,\n WrapperComponentProps,\n} from '@/promise-modal/types';\n\nimport { ConfigurationContext } from './ConfigurationContext';\n\nexport interface ConfigurationContextProviderProps {\n BackgroundComponent?: ComponentType<ModalFrameProps>;\n ForegroundComponent?: ComponentType<ModalFrameProps>;\n TitleComponent?: ComponentType<WrapperComponentProps>;\n SubtitleComponent?: ComponentType<WrapperComponentProps>;\n ContentComponent?: ComponentType<WrapperComponentProps>;\n FooterComponent?: ComponentType<FooterComponentProps>;\n options?: {\n /** Modal transition time(ms, s) */\n duration?: Duration;\n /** Modal backdrop color */\n backdrop?: Color;\n /** Whether to destroy the modal manually */\n manualDestroy?: boolean;\n /** Whether to close the modal when the backdrop is clicked */\n closeOnBackdropClick?: boolean;\n };\n}\n\nexport const ConfigurationContextProvider = memo(\n ({\n ForegroundComponent,\n BackgroundComponent,\n TitleComponent,\n SubtitleComponent,\n ContentComponent,\n FooterComponent,\n options,\n children,\n }: PropsWithChildren<ConfigurationContextProviderProps>) => {\n const value = useMemo(\n () => ({\n BackgroundComponent,\n ForegroundComponent: ForegroundComponent || FallbackForegroundFrame,\n TitleComponent: TitleComponent || FallbackTitle,\n SubtitleComponent: SubtitleComponent || FallbackSubtitle,\n ContentComponent: memo(ContentComponent || FallbackContent),\n FooterComponent: memo(FooterComponent || FallbackFooter),\n options: {\n duration: DEFAULT_ANIMATION_DURATION,\n backdrop: DEFAULT_BACKDROP_COLOR,\n closeOnBackdropClick: true,\n manualDestroy: false,\n ...options,\n } satisfies ConfigurationContextProviderProps['options'],\n }),\n [\n ForegroundComponent,\n BackgroundComponent,\n ContentComponent,\n FooterComponent,\n SubtitleComponent,\n TitleComponent,\n options,\n ],\n );\n return (\n <ConfigurationContext.Provider value={value}>\n {children}\n </ConfigurationContext.Provider>\n );\n },\n);\n","import type { Color, Duration } from '@aileron/declare';\n\nexport const DEFAULT_ANIMATION_DURATION: Duration = '300ms';\n\nexport const DEFAULT_BACKDROP_COLOR: Color = 'rgba(0, 0, 0, 0.5)';\n","import { useContext } from 'react';\n\nimport { convertMsFromDuration } from '@winglet/common-utils';\n\nimport { ConfigurationContext } from './ConfigurationContext';\n\nexport const useConfigurationContext = () => useContext(ConfigurationContext);\n\nexport const useConfigurationOptions = () => {\n const context = useContext(ConfigurationContext);\n return context.options;\n};\n\nexport const useConfigurationDuration = () => {\n const context = useConfigurationOptions();\n return {\n duration: context.duration,\n milliseconds: convertMsFromDuration(context.duration),\n };\n};\n\nexport const useConfigurationBackdrop = () => {\n const context = useConfigurationOptions();\n return context.backdrop;\n};\n","import { createContext } from 'react';\n\nimport type { Dictionary } from '@aileron/declare';\n\nexport interface UserDefinedContext {\n context: Dictionary;\n}\n\nexport const UserDefinedContext = createContext<UserDefinedContext>(\n {} as UserDefinedContext,\n);\n","import { PropsWithChildren, useMemo } from 'react';\n\nimport type { Dictionary } from '@aileron/declare';\n\nimport { UserDefinedContext } from './UserDefinedContext';\n\ninterface UserDefinedContextProviderProps {\n /** 사용자 정의 컨텍스트 */\n context?: Dictionary;\n}\n\nexport const UserDefinedContextProvider = ({\n context,\n children,\n}: PropsWithChildren<UserDefinedContextProviderProps>) => {\n const contextValue = useMemo(() => ({ context: context || {} }), [context]);\n return (\n <UserDefinedContext.Provider value={contextValue}>\n {children}\n </UserDefinedContext.Provider>\n );\n};\n","import { useContext } from 'react';\n\nimport { UserDefinedContext } from './UserDefinedContext';\n\nexport const useUserDefinedContext = () => {\n return useContext(UserDefinedContext);\n};\n","import { useLayoutEffect, useState } from 'react';\n\nexport const usePathname = () => {\n const [pathname, setPathname] = useState(window.location.pathname);\n useLayoutEffect(() => {\n let requestId: number;\n const checkPathname = () => {\n if (requestId) cancelAnimationFrame(requestId);\n if (pathname !== window.location.pathname) {\n setPathname(window.location.pathname);\n } else {\n requestId = requestAnimationFrame(checkPathname);\n }\n };\n requestId = requestAnimationFrame(checkPathname);\n return () => {\n if (requestId) cancelAnimationFrame(requestId);\n };\n }, [pathname]);\n return { pathname };\n};\n","import { css } from '@emotion/css';\n\nexport const background = css`\n display: none;\n position: fixed;\n inset: 0;\n z-index: -999;\n pointer-events: none;\n > * {\n pointer-events: none;\n }\n`;\n\nexport const active = css`\n pointer-events: all;\n`;\n\nexport const visible = css`\n display: flex;\n align-items: center;\n justify-content: center;\n`;\n","import { type MouseEvent, useCallback, useMemo } from 'react';\n\nimport { cx } from '@emotion/css';\n\nimport {\n useConfigurationContext,\n useModal,\n useUserDefinedContext,\n} from '@/promise-modal/providers';\nimport type { ModalLayerProps } from '@/promise-modal/types';\n\nimport { active, background, visible } from './classNames.emotion';\n\nexport const BackgroundFrame = ({\n modalId,\n onChangeOrder,\n}: ModalLayerProps) => {\n const { BackgroundComponent } = useConfigurationContext();\n const { context: userDefinedContext } = useUserDefinedContext();\n const { modal, onClose, onChange, onConfirm, onDestroy } = useModal(modalId);\n\n const handleClose = useCallback(\n (event: MouseEvent) => {\n if (modal && modal.closeOnBackdropClick && modal.visible) onClose();\n event.stopPropagation();\n },\n [modal, onClose],\n );\n\n const Background = useMemo(\n () => modal?.BackgroundComponent || BackgroundComponent,\n [BackgroundComponent, modal],\n );\n\n if (!modal) return null;\n\n return (\n <div\n className={cx(background, {\n [visible]: modal.manualDestroy ? modal.alive : modal.visible,\n [active]: modal.closeOnBackdropClick && modal.visible,\n })}\n onClick={handleClose}\n >\n {Background && (\n <Background\n id={modal.id}\n type={modal.type}\n alive={modal.alive}\n visible={modal.visible}\n initiator={modal.initiator}\n manualDestroy={modal.manualDestroy}\n closeOnBackdropClick={modal.closeOnBackdropClick}\n background={modal.background}\n onChange={onChange}\n onConfirm={onConfirm}\n onClose={onClose}\n onDestroy={onDestroy}\n onChangeOrder={onChangeOrder}\n context={userDefinedContext}\n />\n )}\n </div>\n );\n};\n","import { css } from '@emotion/css';\n\nexport const foreground = css`\n pointer-events: none;\n display: none;\n position: fixed;\n inset: 0;\n z-index: 1;\n`;\n\nexport const active = css`\n > * {\n pointer-events: all;\n }\n`;\n\nexport const visible = css`\n display: flex !important;\n justify-content: center;\n align-items: center;\n`;\n","import { Fragment, memo, useMemo } from 'react';\n\nimport { isString } from '@winglet/common-utils';\nimport { renderComponent, useHandle } from '@winglet/react-utils';\n\nimport type { AlertNode } from '@/promise-modal/core';\nimport {\n useConfigurationContext,\n useUserDefinedContext,\n} from '@/promise-modal/providers';\nimport type { ModalActions } from '@/promise-modal/types';\n\ninterface AlertInnerProps<B> {\n modal: AlertNode<B>;\n handlers: Pick<ModalActions, 'onConfirm'>;\n}\n\nexport const AlertInner = memo(\n <B,>({ modal, handlers }: AlertInnerProps<B>) => {\n const { title, subtitle, content, footer } = useMemo(() => modal, [modal]);\n const { context: userDefinedContext } = useUserDefinedContext();\n const { onConfirm } = useMemo(() => handlers, [handlers]);\n\n const handleConfirm = useHandle(onConfirm);\n\n const {\n TitleComponent,\n SubtitleComponent,\n ContentComponent,\n FooterComponent,\n } = useConfigurationContext();\n\n return (\n <Fragment>\n {title &&\n (isString(title) ? (\n <TitleComponent context={userDefinedContext}>\n {title}\n </TitleComponent>\n ) : (\n title\n ))}\n {subtitle &&\n (isString(subtitle) ? (\n <SubtitleComponent context={userDefinedContext}>\n {subtitle}\n </SubtitleComponent>\n ) : (\n subtitle\n ))}\n {content &&\n (isString(content) ? (\n <ContentComponent context={userDefinedContext}>\n {content}\n </ContentComponent>\n ) : (\n renderComponent(content, {\n onConfirm: handleConfirm,\n })\n ))}\n {footer !== false &&\n (typeof footer === 'function' ? (\n footer({\n onConfirm: handleConfirm,\n context: userDefinedContext,\n })\n ) : (\n <FooterComponent\n onConfirm={handleConfirm}\n confirmLabel={footer?.confirm}\n hideConfirm={footer?.hideConfirm}\n context={userDefinedContext}\n />\n ))}\n </Fragment>\n );\n },\n);\n","import { Fragment, memo, useMemo } from 'react';\n\nimport { isString } from '@winglet/common-utils';\nimport { renderComponent, useHandle } from '@winglet/react-utils';\n\nimport type { ConfirmNode } from '@/promise-modal/core';\nimport {\n useConfigurationContext,\n useUserDefinedContext,\n} from '@/promise-modal/providers';\nimport type { ModalActions } from '@/promise-modal/types';\n\ninterface ConfirmInnerProps<B> {\n modal: ConfirmNode<B>;\n handlers: Pick<ModalActions, 'onConfirm' | 'onClose'>;\n}\n\nexport const ConfirmInner = memo(\n <B,>({ modal, handlers }: ConfirmInnerProps<B>) => {\n const { title, subtitle, content, footer } = useMemo(() => modal, [modal]);\n const { context: userDefinedContext } = useUserDefinedContext();\n const { onConfirm, onClose } = useMemo(() => handlers, [handlers]);\n\n const handleConfirm = useHandle(onConfirm);\n const handleClose = useHandle(onClose);\n\n const {\n TitleComponent,\n SubtitleComponent,\n ContentComponent,\n FooterComponent,\n } = useConfigurationContext();\n\n return (\n <Fragment>\n {title &&\n (isString(title) ? (\n <TitleComponent context={userDefinedContext}>\n {title}\n </TitleComponent>\n ) : (\n title\n ))}\n {subtitle &&\n (isString(subtitle) ? (\n <SubtitleComponent context={userDefinedContext}>\n {subtitle}\n </SubtitleComponent>\n ) : (\n subtitle\n ))}\n {content &&\n (isString(content) ? (\n <ContentComponent context={userDefinedContext}>\n {content}\n </ContentComponent>\n ) : (\n renderComponent(content, {\n onConfirm: handleConfirm,\n onCancel: handleClose,\n context: userDefinedContext,\n })\n ))}\n {footer !== false &&\n (typeof footer === 'function' ? (\n footer({\n onConfirm: handleConfirm,\n onCancel: handleClose,\n context: userDefinedContext,\n })\n ) : (\n <FooterComponent\n onConfirm={handleConfirm}\n onCancel={handleClose}\n confirmLabel={footer?.confirm}\n cancelLabel={footer?.cancel}\n hideConfirm={footer?.hideConfirm}\n hideCancel={footer?.hideCancel}\n context={userDefinedContext}\n />\n ))}\n </Fragment>\n );\n },\n);\n","import { Fragment, memo, useCallback, useMemo, useState } from 'react';\n\nimport { isFunction, isString } from '@winglet/common-utils';\nimport {\n renderComponent,\n useHandle,\n withErrorBoundary,\n} from '@winglet/react-utils';\n\nimport type { PromptNode } from '@/promise-modal/core';\nimport {\n useConfigurationContext,\n useUserDefinedContext,\n} from '@/promise-modal/providers';\nimport type { ModalActions } from '@/promise-modal/types';\n\ninterface PromptInnerProps<T, B> {\n modal: PromptNode<T, B>;\n handlers: Pick<ModalActions, 'onChange' | 'onClose' | 'onConfirm'>;\n}\n\nexport const PromptInner = memo(\n <T, B>({ modal, handlers }: PromptInnerProps<T, B>) => {\n const {\n Input,\n defaultValue,\n disabled: checkDisabled,\n title,\n subtitle,\n content,\n footer,\n } = useMemo(\n () => ({\n ...modal,\n Input: memo(withErrorBoundary(modal.Input)),\n }),\n [modal],\n );\n\n const { context: userDefinedContext } = useUserDefinedContext();\n\n const [value, setValue] = useState<T | undefined>(defaultValue);\n\n const { onChange, onClose, onConfirm } = useMemo(\n () => handlers,\n [handlers],\n );\n\n const handleClose = useHandle(onClose);\n const handleChange = useHandle(\n (inputValue?: T | ((prevState: T | undefined) => T | undefined)) => {\n const input = isFunction(inputValue) ? inputValue(value) : inputValue;\n setValue(input);\n onChange(input);\n },\n );\n\n const handleConfirm = useCallback(() => {\n // NOTE: wait for the next tick to ensure the value is updated\n requestAnimationFrame(onConfirm);\n }, [onConfirm]);\n\n const disabled = useMemo(\n () => (value ? !!checkDisabled?.(value) : false),\n [checkDisabled, value],\n );\n\n const {\n TitleComponent,\n SubtitleComponent,\n ContentComponent,\n FooterComponent,\n } = useConfigurationContext();\n\n return (\n <Fragment>\n {title &&\n (isString(title) ? (\n <TitleComponent context={userDefinedContext}>\n {title}\n </TitleComponent>\n ) : (\n title\n ))}\n {subtitle &&\n (isString(subtitle) ? (\n <SubtitleComponent context={userDefinedContext}>\n {subtitle}\n </SubtitleComponent>\n ) : (\n subtitle\n ))}\n {content &&\n (isString(content) ? (\n <ContentComponent context={userDefinedContext}>\n {content}\n </ContentComponent>\n ) : (\n renderComponent(content, {\n onConfirm: handleConfirm,\n onCancel: handleClose,\n context: userDefinedContext,\n })\n ))}\n\n {Input && (\n <Input\n defaultValue={defaultValue}\n value={value}\n onChange={handleChange}\n onConfirm={handleConfirm}\n onCancel={handleClose}\n context={userDefinedContext}\n />\n )}\n\n {footer !== false &&\n (typeof footer === 'function' ? (\n footer({\n value,\n disabled,\n onChange: handleChange,\n onConfirm: handleConfirm,\n onCancel: handleClose,\n context: userDefinedContext,\n })\n ) : (\n <FooterComponent\n disabled={disabled}\n onConfirm={handleConfirm}\n onCancel={handleClose}\n confirmLabel={footer?.confirm}\n cancelLabel={footer?.cancel}\n hideConfirm={footer?.hideConfirm}\n hideCancel={footer?.hideCancel}\n context={userDefinedContext}\n />\n ))}\n </Fragment>\n );\n },\n);\n","import { useMemo } from 'react';\n\nimport { cx } from '@emotion/css';\n\nimport {\n useConfigurationContext,\n useModal,\n useUserDefinedContext,\n} from '@/promise-modal/providers';\nimport type { ModalLayerProps } from '@/promise-modal/types';\n\nimport { active, foreground, visible } from './classNames.emotion';\nimport { AlertInner, ConfirmInner, PromptInner } from './components';\n\nexport const ForegroundFrame = ({\n modalId,\n onChangeOrder,\n}: ModalLayerProps) => {\n const { ForegroundComponent } = useConfigurationContext();\n const { context: userDefinedContext } = useUserDefinedContext();\n\n const { modal, onChange, onConfirm, onClose, onDestroy } = useModal(modalId);\n\n const Foreground = useMemo(\n () => modal?.ForegroundComponent || ForegroundComponent,\n [ForegroundComponent, modal],\n );\n\n if (!modal) return null;\n\n return (\n <div\n className={cx(foreground, {\n [visible]: modal.manualDestroy ? modal.alive : modal.visible,\n [active]: modal.visible,\n })}\n >\n <Foreground\n id={modal.id}\n type={modal.type}\n alive={modal.alive}\n visible={modal.visible}\n initiator={modal.initiator}\n manualDestroy={modal.manualDestroy}\n closeOnBackdropClick={modal.closeOnBackdropClick}\n background={modal.background}\n onChange={onChange}\n onConfirm={onConfirm}\n onClose={onClose}\n onDestroy={onDestroy}\n onChangeOrder={onChangeOrder}\n context={userDefinedContext}\n >\n {modal.type === 'alert' && (\n <AlertInner modal={modal} handlers={{ onConfirm }} />\n )}\n {modal.type === 'confirm' && (\n <ConfirmInner modal={modal} handlers={{ onConfirm, onClose }} />\n )}\n {modal.type === 'prompt' && (\n <PromptInner\n modal={modal}\n handlers={{ onChange, onConfirm, onClose }}\n />\n )}\n </Foreground>\n </div>\n );\n};\n","import { useEffect } from 'react';\n\nimport { useVersion } from '@winglet/react-utils';\n\nimport type { ModalNode } from '@/promise-modal/core';\n\nexport const useSubscribeModal = (modal?: ModalNode) => {\n const [version, update] = useVersion();\n useEffect(() => {\n if (!modal) return;\n const unsubscribe = modal.subscribe(update);\n return unsubscribe;\n }, [modal, update]);\n return version;\n};\n","import { css } from '@emotion/css';\n\nexport const presenter = css`\n position: fixed;\n inset: 0;\n pointer-events: none;\n overflow: hidden;\n`;\n","import { memo, useRef } from 'react';\n\nimport { counterFactory } from '@winglet/common-utils';\nimport { useHandle } from '@winglet/react-utils';\n\nimport { Background } from '@/promise-modal/components/Background';\nimport { Foreground } from '@/promise-modal/components/Foreground';\nimport { useSubscribeModal } from '@/promise-modal/hooks/useSubscribeModal';\nimport { useModal } from '@/promise-modal/providers';\nimport type { ModalIdProps } from '@/promise-modal/types';\n\nimport { presenter } from './classNames.emotion';\n\nconst { increment } = counterFactory(1);\n\nexport const Presenter = memo(({ modalId }: ModalIdProps) => {\n const ref = useRef<HTMLDivElement>(null);\n const { modal } = useModal(modalId);\n useSubscribeModal(modal);\n const handleChangeOrder = useHandle(() => {\n if (ref.current) {\n ref.current.style.zIndex = `${increment()}`;\n }\n });\n return (\n <div ref={ref} className={presenter}>\n <Background modalId={modalId} onChangeOrder={handleChangeOrder} />\n <Foreground modalId={modalId} onChangeOrder={handleChangeOrder} />\n </div>\n );\n});\n","import { css } from '@emotion/css';\n\nexport const anchor = css`\n display: flex;\n align-items: center;\n justify-content: center;\n position: fixed;\n inset: 0;\n pointer-events: none;\n z-index: 1000;\n transition: background-color ease-in-out;\n`;\n","import { memo, useEffect } from 'react';\n\nimport { map } from '@winglet/common-utils';\nimport { useVersion, withErrorBoundary } from '@winglet/react-utils';\n\nimport { Presenter } from '@/promise-modal/components/Presenter';\nimport type { ModalNode } from '@/promise-modal/core';\nimport { useActiveModalCount } from '@/promise-modal/hooks/useActiveModalCount';\nimport {\n useConfigurationOptions,\n useModalManagerContext,\n} from '@/promise-modal/providers';\n\nimport { anchor } from './classNames.emotion';\n\nconst AnchorInner = () => {\n const [version, update] = useVersion();\n\n const { modalIds, setUpdater } = useModalManagerContext();\n\n useEffect(() => {\n setUpdater(update);\n }, [setUpdater, update]);\n\n const options = useConfigurationOptions();\n\n const dimmed = useActiveModalCount(validateDimmable, version);\n\n return (\n <div\n className={anchor}\n style={{\n transitionDuration: options.duration,\n backgroundColor: dimmed ? options.backdrop : 'transparent',\n }}\n >\n {map(modalIds, (id) => (\n <Presenter key={id} modalId={id} />\n ))}\n </div>\n );\n};\n\nconst validateDimmable = (modal?: ModalNode) => modal?.visible && modal.dimmed;\n\nexport const Anchor = memo(withErrorBoundary(AnchorInner));\n","import { createPortal } from 'react-dom';\n\nimport type { Dictionary, Fn } from '@aileron/declare';\n\nimport { Anchor } from '@/promise-modal/components/Anchor';\nimport {\n ConfigurationContextProvider,\n type ConfigurationContextProviderProps,\n} from '@/promise-modal/providers/ConfigurationContext';\nimport { ModalManagerContextProvider } from '@/promise-modal/providers/ModalManagerContext';\nimport { UserDefinedContextProvider } from '@/promise-modal/providers/UserDefinedContext';\n\ninterface BootstrapProps extends ConfigurationContextProviderProps {\n usePathname: Fn<[], { pathname: string }>;\n context?: Dictionary;\n anchor: HTMLElement;\n}\n\nexport const bootstrap = ({\n ForegroundComponent,\n BackgroundComponent,\n TitleComponent,\n SubtitleComponent,\n ContentComponent,\n FooterComponent,\n usePathname,\n options,\n context,\n anchor,\n}: BootstrapProps) =>\n createPortal(\n <UserDefinedContextProvider context={context}>\n <ConfigurationContextProvider\n ForegroundComponent={ForegroundComponent}\n BackgroundComponent={BackgroundComponent}\n TitleComponent={TitleComponent}\n SubtitleComponent={SubtitleComponent}\n ContentComponent={ContentComponent}\n FooterComponent={FooterComponent}\n options={options}\n >\n <ModalManagerContextProvider usePathname={usePathname}>\n <Anchor />\n </ModalManagerContextProvider>\n </ConfigurationContextProvider>\n </UserDefinedContextProvider>,\n anchor,\n );\n","import { useCallback, useRef } from 'react';\n\nimport { printError } from '@winglet/common-utils';\nimport { useVersion } from '@winglet/react-utils';\n\nimport { ModalManager } from '@/promise-modal/app/ModalManager';\n\nexport const useInitialize = () => {\n const permitted = useRef(ModalManager.activate());\n const anchorRef = useRef<HTMLElement | null>(null);\n const [, update] = useVersion();\n\n const handleInitialize = useCallback(\n (root?: HTMLElement) => {\n if (permitted.current) {\n anchorRef.current = ModalManager.anchor({ root });\n update();\n } else\n printError(\n 'ModalProvider is already initialized',\n [\n 'ModalProvider can only be initialized once.',\n 'Nesting ModalProvider will be ignored...',\n ],\n {\n info: 'Something is wrong with the ModalProvider initialization...',\n },\n );\n },\n [update],\n );\n\n return {\n anchorRef,\n handleInitialize,\n } as const;\n};\n","import {\n Fragment,\n type PropsWithChildren,\n forwardRef,\n useImperativeHandle,\n useMemo,\n} from 'react';\n\nimport { useOnMount } from '@winglet/react-utils';\n\nimport { usePathname as useDefaultPathname } from '@/promise-modal/hooks/useDefaultPathname';\n\nimport { bootstrap } from './helpers/bootstrap';\nimport { useInitialize } from './hooks/useInitialize';\nimport type { BootstrapProviderHandle, BootstrapProviderProps } from './type';\n\nexport const BootstrapProvider = forwardRef<\n BootstrapProviderHandle,\n PropsWithChildren<BootstrapProviderProps>\n>(\n (\n {\n usePathname: useExternalPathname,\n ForegroundComponent,\n BackgroundComponent,\n TitleComponent,\n SubtitleComponent,\n ContentComponent,\n FooterComponent,\n options,\n context,\n children,\n },\n handleRef,\n ) => {\n const usePathname = useMemo(\n () => useExternalPathname || useDefaultPathname,\n [useExternalPathname],\n );\n\n const { anchorRef, handleInitialize } = useInitialize();\n\n useImperativeHandle(\n handleRef,\n () => ({\n initialize: handleInitialize,\n }),\n [handleInitialize],\n );\n\n useOnMount(() => {\n /**\n * NOTE: `handleRef` being null indicates that no `ref` was provided.\n * In this case, the `ModalProvider`(=`BootstrapProvider`) is not receiving the `ref`,\n * so it should be initialized automatically.\n */\n if (handleRef === null) handleInitialize();\n return () => {\n if (anchorRef.current) anchorRef.current.remove();\n };\n });\n\n return (\n <Fragment>\n {children}\n {anchorRef.current &&\n bootstrap({\n ForegroundComponent,\n BackgroundComponent,\n TitleComponent,\n SubtitleComponent,\n ContentComponent,\n FooterComponent,\n usePathname,\n options,\n context,\n anchor: anchorRef.current,\n })}\n </Fragment>\n );\n },\n);\n","import type { ComponentType, ReactNode } from 'react';\n\nimport { ModalManager } from '@/promise-modal/app/ModalManager';\nimport type {\n AlertContentProps,\n AlertFooterRender,\n BackgroundComponent,\n FooterOptions,\n ForegroundComponent,\n ModalBackground,\n} from '@/promise-modal/types';\n\ninterface AlertProps<B> {\n subtype?: 'info' | 'success' | 'warning' | 'error';\n title?: ReactNode;\n subtitle?: ReactNode;\n content?: ReactNode | ComponentType<AlertContentProps>;\n background?: ModalBackground<B>;\n footer?:\n | AlertFooterRender\n | Pick<FooterOptions, 'confirm' | 'hideConfirm'>\n | false;\n dimmed?: boolean;\n manualDestroy?: boolean;\n closeOnBackdropClick?: boolean;\n ForegroundComponent?: ForegroundComponent;\n BackgroundComponent?: BackgroundComponent;\n}\n\nexport const alert = <B = any>({\n subtype,\n title,\n subtitle,\n content,\n background,\n footer,\n dimmed,\n manualDestroy,\n closeOnBackdropClick,\n ForegroundComponent,\n BackgroundComponent,\n}: AlertProps<B>) => {\n return new Promise<void>((resolve, reject) => {\n try {\n ModalManager.open({\n type: 'alert',\n subtype,\n resolve: () => resolve(),\n title,\n subtitle,\n content,\n background,\n footer,\n dimmed,\n manualDestroy,\n closeOnBackdropClick,\n ForegroundComponent,\n BackgroundComponent,\n });\n } catch (error) {\n reject(error);\n }\n });\n};\n","import type { ComponentType, ReactNode } from 'react';\n\nimport { ModalManager } from '@/promise-modal/app/ModalManager';\nimport type {\n BackgroundComponent,\n ConfirmContentProps,\n ConfirmFooterRender,\n FooterOptions,\n ForegroundComponent,\n ModalBackground,\n} from '@/promise-modal/types';\n\ninterface ConfirmProps<B> {\n subtype?: 'info' | 'success' | 'warning' | 'error';\n title?: ReactNode;\n subtitle?: ReactNode;\n content?: ReactNode | ComponentType<ConfirmContentProps>;\n background?: ModalBackground<B>;\n footer?: ConfirmFooterRender | FooterOptions | false;\n dimmed?: boolean;\n manualDestroy?: boolean;\n closeOnBackdropClick?: boolean;\n ForegroundComponent?: ForegroundComponent;\n BackgroundComponent?: BackgroundComponent;\n}\n\nexport const confirm = <B = any>({\n subtype,\n title,\n subtitle,\n content,\n background,\n footer,\n dimmed,\n manualDestroy,\n closeOnBackdropClick,\n ForegroundComponent,\n BackgroundComponent,\n}: ConfirmProps<B>) => {\n return new Promise<boolean>((resolve, reject) => {\n try {\n ModalManager.open({\n type: 'confirm',\n subtype,\n resolve: (result) => resolve(result ?? false),\n title,\n subtitle,\n content,\n background,\n footer,\n dimmed,\n manualDestroy,\n closeOnBackdropClick,\n ForegroundComponent,\n BackgroundComponent,\n });\n } catch (error) {\n reject(error);\n }\n });\n};\n","import type { ComponentType, ReactNode } from 'react';\n\nimport { ModalManager } from '@/promise-modal/app/ModalManager';\nimport type {\n BackgroundComponent,\n FooterOptions,\n ForegroundComponent,\n ModalBackground,\n PromptContentProps,\n PromptFooterRender,\n PromptInputProps,\n} from '@/promise-modal/types';\n\ninterface PromptProps<T, B = any> {\n title?: ReactNode;\n subtitle?: ReactNode;\n content?: ReactNode | ComponentType<PromptContentProps>;\n Input: (props: PromptInputProps<T>) => ReactNode;\n defaultValue?: T;\n disabled?: (value: T) => boolean;\n returnOnCancel?: boolean;\n background?: ModalBackground<B>;\n footer?: PromptFooterRender<T> | FooterOptions | false;\n dimmed?: boolean;\n manualDestroy?: boolean;\n closeOnBackdropClick?: boolean;\n ForegroundComponent?: ForegroundComponent;\n BackgroundComponent?: BackgroundComponent;\n}\n\nexport const prompt = <T, B = any>({\n defaultValue,\n title,\n subtitle,\n content,\n Input,\n disabled,\n returnOnCancel,\n background,\n footer,\n dimmed,\n manualDestroy,\n closeOnBackdropClick,\n ForegroundComponent,\n BackgroundComponent,\n}: PromptProps<T, B>) => {\n return new Promise<T>((resolve, reject) => {\n try {\n ModalManager.open({\n type: 'prompt',\n resolve: (result) => resolve(result as T),\n title,\n subtitle,\n content,\n Input,\n defaultValue,\n disabled,\n returnOnCancel,\n background,\n footer,\n dimmed,\n manualDestroy,\n closeOnBackdropClick,\n ForegroundComponent,\n BackgroundComponent,\n });\n } catch (error) {\n reject(error);\n }\n });\n};\n","import { useEffect, useRef } from 'react';\n\nimport { convertMsFromDuration, isString } from '@winglet/common-utils';\n\nimport type { Duration } from '@aileron/declare';\n\nimport type { ModalNode } from '@/promise-modal/core';\nimport { useModal } from '@/promise-modal/providers';\n\nimport { useSubscribeModal } from './useSubscribeModal';\n\nexport const useDestroyAfter = (\n modalId: ModalNode['id'],\n duration: Duration | number,\n) => {\n const { modal, onDestroy } = useModal(modalId);\n const tick = useSubscribeModal(modal);\n\n const reference = useRef({\n modal,\n onDestroy,\n milliseconds: isString(duration)\n ? convertMsFromDuration(duration)\n : duration,\n });\n\n useEffect(() => {\n const { modal, onDestroy, milliseconds } = reference.current;\n if (!modal || modal.visible || !modal.alive) return;\n const timer = setTimeout(() => {\n onDestroy();\n }, milliseconds);\n return () => {\n if (timer) clearTimeout(timer);\n };\n }, [tick]);\n};\n","import { useCallback, useMemo } from 'react';\n\nimport { useOnMount } from '@winglet/react-utils';\n\nimport { usePathname as useDefaultPathname } from '@/promise-modal/hooks/useDefaultPathname';\n\nimport { bootstrap } from './helpers/bootstrap';\nimport { useInitialize } from './hooks/useInitialize';\nimport type { BootstrapProviderProps } from './type';\n\nexport const useBootstrap = ({\n usePathname: useExternalPathname,\n ForegroundComponent,\n BackgroundComponent,\n TitleComponent,\n SubtitleComponent,\n ContentComponent,\n FooterComponent,\n options,\n context,\n mode = 'auto',\n}: BootstrapProviderProps & { mode?: 'manual' | 'auto' } = {}) => {\n const usePathname = useMemo(\n () => useExternalPathname || useDefaultPathname,\n [useExternalPathname],\n );\n\n const { anchorRef, handleInitialize } = useInitialize();\n\n useOnMount(() => {\n if (mode === 'auto') handleInitialize();\n return () => {\n if (anchorRef.current) anchorRef.current.remove();\n };\n });\n\n const initialize = useCallback(\n (element: HTMLElement) => {\n if (mode === 'manual') handleInitialize(element);\n },\n [mode, handleInitialize],\n );\n\n const portal =\n anchorRef.current &&\n bootstrap({\n usePathname,\n ForegroundComponent,\n BackgroundComponent,\n TitleComponent,\n SubtitleComponent,\n ContentComponent,\n FooterComponent,\n options,\n context,\n anchor: anchorRef.current,\n });\n\n return { portal, initialize };\n};\n","import { useLayoutEffect, useRef } from 'react';\n\nimport type { Fn } from '@aileron/declare';\n\ninterface ModalAnimationHandler {\n onVisible?: Fn;\n onHidden?: Fn;\n}\n\nexport const useModalAnimation = (\n visible: boolean,\n handler: ModalAnimationHandler,\n) => {\n const handlerRef = useRef(handler);\n handlerRef.current = handler;\n useLayoutEffect(() => {\n if (!handlerRef.current) return;\n let frame: ReturnType<typeof requestAnimationFrame>;\n if (visible)\n frame = requestAnimationFrame(() => handlerRef.current.onVisible?.());\n else frame = requestAnimationFrame(() => handlerRef.current.onHidden?.());\n return () => {\n if (frame) cancelAnimationFrame(frame);\n };\n }, [visible]);\n};\n"],"names":["ModalManager","activate","__classPrivateFieldGet","_a","_ModalManager_active","__classPrivateFieldSet","anchor","options","_ModalManager_anchor","document","getElementById","id","tag","prefix","root","body","node","createElement","setAttribute","getRandomString","appendChild","prerender","_ModalManager_prerenderList","openHandler","handler","_ModalManager_openHandler","unanchored","reset","modal","push","open","call","value","AbstractNode","alive","this","_AbstractNode_alive","visible","_AbstractNode_visible","constructor","initiator","title","subtitle","background","dimmed","manualDestroy","closeOnBackdropClick","resolve","ForegroundComponent","BackgroundComponent","set","_AbstractNode_resolve","_AbstractNode_listeners","Set","subscribe","listener","add","delete","publish","result","onDestroy","needPublish","onShow","onHide","AlertNode","type","subtype","content","footer","super","onClose","onConfirm","ConfirmNode","PromptNode","defaultValue","Input","disabled","returnOnCancel","_PromptNode_value","onChange","nodeFactory","Error","ModalManagerContext","createContext","ModalManagerContextProvider","memo","usePathname","children","modalDictionary","useRef","Map","modalIds","setModalIds","useState","modalIdsRef","useReference","pathname","modalIdSequence","useConfigurationOptions","duration","useMemo","convertMsFromDuration","useOnMountLayout","data","current","undefined","ids","aliveIds","index","length","get","useLayoutEffect","getModalNode","useCallback","modalId","updaterRef","hideModal","setTimeout","getModal","setUpdater","updater","_jsx","jsx","Provider","useModalManagerContext","useContext","useModal","fallback","css","process","env","NODE_ENV","name","styles","toString","_EMOTION_STRINGIFIED_CSS_ERROR__","frame","FallbackTitle","className","FallbackSubtitle","FallbackContent","FallbackFooter","confirmLabel","hideConfirm","cancelLabel","hideCancel","onCancel","_jsxs","onClick","defaultValidate","useActiveModalCount","validate","refreshKey","count","FallbackForegroundFrame","forwardRef","onChangeOrder","ref","activeCount","level","offset","stacked","Math","floor","style","marginBottom","marginLeft","transform","ConfigurationContext","ConfigurationContextProvider","TitleComponent","SubtitleComponent","ContentComponent","FooterComponent","backdrop","useConfigurationContext","UserDefinedContext","UserDefinedContextProvider","context","contextValue","useUserDefinedContext","setPathname","window","location","requestId","checkPathname","cancelAnimationFrame","requestAnimationFrame","active","BackgroundFrame","userDefinedContext","handleClose","event","stopPropagation","Background","cx","visible$1","active$1","foreground","AlertInner","handlers","handleConfirm","useHandle","Fragment","isString","renderComponent","confirm","ConfirmInner","cancel","PromptInner","checkDisabled","withErrorBoundary","setValue","handleChange","inputValue","input","isFunction","ForegroundFrame","Foreground","useSubscribeModal","version","update","useVersion","useEffect","presenter","increment","counterFactory","Presenter","handleChangeOrder","zIndex","validateDimmable","Anchor","transitionDuration","backgroundColor","map","bootstrap","createPortal","useInitialize","permitted","anchorRef","handleInitialize","printError","info","BootstrapProvider","useExternalPathname","handleRef","useDefaultPathname","useImperativeHandle","initialize","useOnMount","remove","Promise","reject","error","tick","reference","milliseconds","timer","clearTimeout","mode","element","portal","handlerRef","onVisible","onHidden"],"mappings":";;;;;;;;;;;;;;;;4sBAMaA,EAEX,eAAOC,GACL,OAAIC,EAAAC,EAAoBA,EAAA,IAAAC,IAChBC,EAAAF,KAAuB,EAAI,IAAAC,GAIrC,aAAOE,CAAOC,GAKZ,GAAIL,EAAAC,EAAoBA,EAAA,IAAAK,GAAE,CACxB,MAAMF,EAASG,SAASC,eAAeR,EAAAC,EAAoBA,EAAA,IAAAK,GAACG,IAC5D,GAAIL,EAAQ,OAAOA,EAErB,MAAMM,IACJA,EAAM,MAAKC,OACXA,EAAS,gBAAeC,KACxBA,EAAOL,SAASM,MACdR,GAAW,CAAE,EACXS,EAAOP,SAASQ,cAAcL,GAIpC,OAHAI,EAAKE,aAAa,KAAM,GAAGL,KAAUM,EAAeA,gBAAC,OACrDL,EAAKM,YAAYJ,GACjBX,EAAAF,EAAYA,EAAWa,EAAI,IAAAR,GACpBQ,EAIT,oBAAWK,GACT,OAAOnB,EAAAC,EAAYA,EAAA,IAAAmB,GAKrB,sBAAWC,CAAYC,GACrBnB,EAAAF,EAAYA,EAAgBqB,EAAO,IAAAC,GACnCpB,EAAAF,EAAYA,EAAkB,GAAE,IAAAmB,GAGlC,qBAAWI,GACT,OAAQxB,EAAAC,EAAYA,EAAA,IAAAK,GAGtB,YAAOmB,GACLtB,EAAAF,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9J,QAAQgK,eACrD,KACDhI,GAAOkD,qBAAqBlD,EAAM,CACvC,GACA,CAACnG,GAAS,2BzBHyB,IACtB6D,IACD4E,kCAVuB,KACtC,MAAMI,EAAUhF,IAChB,MAAO,CACLC,SAAU+E,EAAQ/E,SAClB6J,aAAc3J,EAAAA,sBAAsB6E,EAAQ/E,UAC7C"}
|
package/dist/index.esm.js
CHANGED
|
@@ -1,2 +1,17 @@
|
|
|
1
|
-
import{jsx as e,jsxs as n}from"react/jsx-runtime";import{createContext as o,memo as t,useRef as r,useState as i,useMemo as s,useLayoutEffect as a,useCallback as l,useContext as c,forwardRef as d,Fragment as u,useEffect as m,useImperativeHandle as p}from"react";import{getRandomString as h,convertMsFromDuration as C,isString as _,isFunction as f,counterFactory as g,map as b,printError as v}from"@winglet/common-utils";import{useReference as y,useOnMountLayout as k,useHandle as x,renderComponent as B,withErrorBoundary as D,useVersion as O,useOnMount as F}from"@winglet/react-utils";import{css as N,cx as w}from"@emotion/css";import{createPortal as I}from"react-dom";class S{static activate(){return!S.__active__&&(S.__active__=!0)}static anchor(e){if(S.__anchor__){const e=document.getElementById(S.__anchor__.id);if(e)return e}const{tag:n="div",prefix:o="promise-modal",root:t=document.body}=e||{},r=document.createElement(n);return r.setAttribute("id",`${o}-${h(36)}`),t.appendChild(r),S.__anchor__=r,r}static get prerender(){return S.__prerenderList__}static set openHandler(e){S.__openHandler__=e,S.__prerenderList__=[]}static get unanchored(){return!S.__anchor__}static reset(){S.__active__=!1,S.__anchor__=null,S.__prerenderList__=[],S.__openHandler__=e=>S.__prerenderList__.push(e)}static open(e){S.__openHandler__(e)}}S.__active__=!1,S.__anchor__=null,S.__prerenderList__=[],S.__openHandler__=e=>S.__prerenderList__.push(e);const E=({subtype:e,title:n,subtitle:o,content:t,background:r,footer:i,dimmed:s,manualDestroy:a,closeOnBackdropClick:l,ForegroundComponent:c,BackgroundComponent:d})=>new Promise(((u,m)=>{try{S.open({type:"alert",subtype:e,resolve:()=>u(),title:n,subtitle:o,content:t,background:r,footer:i,dimmed:s,manualDestroy:a,closeOnBackdropClick:l,ForegroundComponent:c,BackgroundComponent:d})}catch(e){m(e)}})),j=({subtype:e,title:n,subtitle:o,content:t,background:r,footer:i,dimmed:s,manualDestroy:a,closeOnBackdropClick:l,ForegroundComponent:c,BackgroundComponent:d})=>new Promise(((u,m)=>{try{S.open({type:"confirm",subtype:e,resolve:e=>u(e??!1),title:n,subtitle:o,content:t,background:r,footer:i,dimmed:s,manualDestroy:a,closeOnBackdropClick:l,ForegroundComponent:c,BackgroundComponent:d})}catch(e){m(e)}})),P=({defaultValue:e,title:n,subtitle:o,content:t,Input:r,disabled:i,returnOnCancel:s,background:a,footer:l,dimmed:c,manualDestroy:d,closeOnBackdropClick:u,ForegroundComponent:m,BackgroundComponent:p})=>new Promise(((h,C)=>{try{S.open({type:"prompt",resolve:e=>h(e),title:n,subtitle:o,content:t,Input:r,defaultValue:e,disabled:i,returnOnCancel:s,background:a,footer:l,dimmed:c,manualDestroy:d,closeOnBackdropClick:u,ForegroundComponent:m,BackgroundComponent:p})}catch(e){C(e)}}));class z{get alive(){return this.__alive__}get visible(){return this.__visible__}constructor({id:e,initiator:n,title:o,subtitle:t,background:r,dimmed:i=!0,manualDestroy:s=!1,closeOnBackdropClick:a=!0,resolve:l,ForegroundComponent:c,BackgroundComponent:d}){this.__listeners__=new Set,this.id=e,this.initiator=n,this.title=o,this.subtitle=t,this.background=r,this.dimmed=i,this.manualDestroy=s,this.closeOnBackdropClick=a,this.ForegroundComponent=c,this.BackgroundComponent=d,this.__alive__=!0,this.__visible__=!0,this.__resolve__=l}subscribe(e){return this.__listeners__.add(e),()=>{this.__listeners__.delete(e)}}publish(){for(const e of this.__listeners__)e()}resolve(e){this.__resolve__(e)}onDestroy(){const e=!0===this.__alive__;this.__alive__=!1,this.manualDestroy&&e&&this.publish()}onShow(){const e=!1===this.__visible__;this.__visible__=!0,e&&this.publish()}onHide(){const e=!0===this.__visible__;this.__visible__=!1,e&&this.publish()}}class V extends z{constructor({id:e,initiator:n,type:o,subtype:t,title:r,subtitle:i,content:s,footer:a,background:l,dimmed:c,manualDestroy:d,closeOnBackdropClick:u,resolve:m,ForegroundComponent:p,BackgroundComponent:h}){super({id:e,initiator:n,title:r,subtitle:i,background:l,dimmed:c,manualDestroy:d,closeOnBackdropClick:u,resolve:m,ForegroundComponent:p,BackgroundComponent:h}),this.type=o,this.subtype=t,this.content=s,this.footer=a}onClose(){this.resolve(null)}onConfirm(){this.resolve(null)}}class M extends z{constructor({id:e,initiator:n,type:o,subtype:t,title:r,subtitle:i,content:s,footer:a,background:l,dimmed:c,manualDestroy:d,closeOnBackdropClick:u,resolve:m,ForegroundComponent:p,BackgroundComponent:h}){super({id:e,initiator:n,title:r,subtitle:i,background:l,dimmed:c,manualDestroy:d,closeOnBackdropClick:u,resolve:m,ForegroundComponent:p,BackgroundComponent:h}),this.type=o,this.subtype=t,this.content=s,this.footer=a}onClose(){this.resolve(!1)}onConfirm(){this.resolve(!0)}}class L extends z{constructor({id:e,initiator:n,type:o,title:t,subtitle:r,content:i,defaultValue:s,Input:a,disabled:l,returnOnCancel:c,footer:d,background:u,dimmed:m,manualDestroy:p,closeOnBackdropClick:h,resolve:C,ForegroundComponent:_,BackgroundComponent:f}){super({id:e,initiator:n,title:t,subtitle:r,background:u,dimmed:m,manualDestroy:p,closeOnBackdropClick:h,resolve:C,ForegroundComponent:_,BackgroundComponent:f}),this.type=o,this.content=i,this.Input=a,this.defaultValue=s,this.__value__=s,this.disabled=l,this.returnOnCancel=c,this.footer=d}onChange(e){this.__value__=e}onConfirm(){this.resolve(this.__value__??null)}onClose(){this.returnOnCancel?this.resolve(this.__value__??null):this.resolve(null)}}const T=e=>{switch(e.type){case"alert":return new V(e);case"confirm":return new M(e);case"prompt":return new L(e)}throw new Error(`Unknown modal: ${e.type}`,{modal:e})},H=o({}),A=t((({usePathname:n,children:o})=>{const t=r(new Map),[c,d]=i([]),u=y(c),{pathname:m}=n(),p=r(m),h=r(0),_=te(),f=s((()=>C(_.duration)),[_]);k((()=>{const{manualDestroy:e,closeOnBackdropClick:n}=_;for(const o of S.prerender){const r=T({...o,id:h.current++,initiator:p.current,manualDestroy:void 0!==o.manualDestroy?o.manualDestroy:e,closeOnBackdropClick:void 0!==o.closeOnBackdropClick?o.closeOnBackdropClick:n});t.current.set(r.id,r),d((e=>[...e,r.id]))}return S.openHandler=o=>{const r=T({...o,id:h.current++,initiator:p.current,manualDestroy:void 0!==o.manualDestroy?o.manualDestroy:e,closeOnBackdropClick:void 0!==o.closeOnBackdropClick?o.closeOnBackdropClick:n});t.current.set(r.id,r),d((e=>{const n=[];for(let o=0;o<e.length;o++){const r=e[o];t.current.get(r)?.alive?n.push(r):t.current.delete(r)}return[...n,r.id]}))},()=>{S.reset()}})),a((()=>{for(const e of u.current){const n=t.current.get(e);n?.alive&&(n.initiator===m?n.onShow():n.onHide())}p.current=m}),[m]);const g=l((e=>t.current.get(e)),[]),b=l((e=>{const n=t.current.get(e);n&&(n.onDestroy(),v.current?.())}),[]),v=r(void 0),x=l((e=>{const n=t.current.get(e);n&&(n.onHide(),v.current?.(),n.manualDestroy||setTimeout((()=>{n.onDestroy()}),f))}),[f]),B=l(((e,n)=>{const o=t.current.get(e);o&&"prompt"===o.type&&o.onChange(n)}),[]),D=l((e=>{const n=t.current.get(e);n&&(n.onConfirm(),x(e))}),[x]),O=l((e=>{const n=t.current.get(e);n&&(n.onClose(),x(e))}),[x]),F=l((e=>({modal:g(e),onConfirm:()=>D(e),onClose:()=>O(e),onChange:n=>B(e,n),onDestroy:()=>b(e)})),[g,D,O,B,b]),N=s((()=>({modalIds:c,getModalNode:g,onChange:B,onConfirm:D,onClose:O,onDestroy:b,getModal:F,setUpdater:e=>{v.current=e}})),[c,F,g,B,D,O,b]);return e(H.Provider,{value:N,children:o})})),$=()=>c(H),q=e=>{const{getModal:n}=$();return s((()=>n(e)),[e,n])};function Y(){return"You have tried to stringify object returned from `css` function. It isn't supposed to be used directly (e.g. as value of the `className` prop), but rather handed to emotion so it can handle it (e.g. as value of `css` prop)."}const R=N("production"===process.env.NODE_ENV?{name:"131j9g2",styles:"margin:unset"}:{name:"1w3kbco-fallback",styles:"margin:unset;label:fallback;",toString:Y}),U=N("production"===process.env.NODE_ENV?{name:"1kuk3a3",styles:"display:flex;flex-direction:column;justify-content:center;align-items:center;background-color:white;padding:20px 80px;gap:10px;border:1px solid black"}:{name:"16dbbea-frame",styles:"display:flex;flex-direction:column;justify-content:center;align-items:center;background-color:white;padding:20px 80px;gap:10px;border:1px solid black;label:frame;",toString:Y}),G=({children:n})=>e("h2",{className:R,children:n}),J=({children:n})=>e("h3",{className:R,children:n}),K=({children:n})=>e("div",{className:R,children:n}),Q=({confirmLabel:o,hideConfirm:t=!1,cancelLabel:r,hideCancel:i=!1,disabled:s,onConfirm:a,onCancel:l})=>n("div",{children:[!t&&e("button",{onClick:a,disabled:s,children:o||"확인"}),!i&&"function"==typeof l&&e("button",{onClick:l,children:r||"취소"})]}),W=e=>e?.visible,X=(e=W,n=0)=>{const{modalIds:o,getModalNode:t}=$();return s((()=>{let n=0;for(const r of o)e(t(r))&&n++;return n}),[t,o,n])},Z=d((({id:n,onChangeOrder:o,children:t},r)=>{const i=X(),[a,l]=s((()=>{const e=i>1;return[e?Math.floor(n/5)%3*100:0,e?n%5*35:0]}),[i,n]);return e("div",{ref:r,className:U,onClick:o,style:{marginBottom:`calc(25vh + ${a}px)`,marginLeft:`${a}px`,transform:`translate(${l}px, ${l}px)`},children:t})})),ee=o({}),ne=t((({ForegroundComponent:n,BackgroundComponent:o,TitleComponent:r,SubtitleComponent:i,ContentComponent:a,FooterComponent:l,options:c,children:d})=>{const u=s((()=>({BackgroundComponent:o,ForegroundComponent:n||Z,TitleComponent:r||G,SubtitleComponent:i||J,ContentComponent:t(a||K),FooterComponent:t(l||Q),options:{duration:"300ms",backdrop:"rgba(0, 0, 0, 0.5)",closeOnBackdropClick:!0,manualDestroy:!1,...c}})),[n,o,a,l,i,r,c]);return e(ee.Provider,{value:u,children:d})})),oe=()=>c(ee),te=()=>c(ee).options,re=()=>{const e=te();return{duration:e.duration,milliseconds:C(e.duration)}},ie=()=>te().backdrop,se=o({}),ae=({context:n,children:o})=>{const t=s((()=>({context:n||{}})),[n]);return e(se.Provider,{value:t,children:o})},le=()=>c(se),ce=()=>{const[e,n]=i(window.location.pathname);return a((()=>{let o;const t=()=>{o&&cancelAnimationFrame(o),e!==window.location.pathname?n(window.location.pathname):o=requestAnimationFrame(t)};return o=requestAnimationFrame(t),()=>{o&&cancelAnimationFrame(o)}}),[e]),{pathname:e}};function de(){return"You have tried to stringify object returned from `css` function. It isn't supposed to be used directly (e.g. as value of the `className` prop), but rather handed to emotion so it can handle it (e.g. as value of `css` prop)."}const ue=N("production"===process.env.NODE_ENV?{name:"u7uu4v",styles:"display:none;position:fixed;inset:0;z-index:-999;pointer-events:none;>*{pointer-events:none;}"}:{name:"coymdj-background",styles:"display:none;position:fixed;inset:0;z-index:-999;pointer-events:none;>*{pointer-events:none;};label:background;",toString:de}),me=N("production"===process.env.NODE_ENV?{name:"n07k1x",styles:"pointer-events:all"}:{name:"1hektcs-active",styles:"pointer-events:all;label:active;",toString:de}),pe=N("production"===process.env.NODE_ENV?{name:"1wnowod",styles:"display:flex;align-items:center;justify-content:center"}:{name:"xppew7-visible",styles:"display:flex;align-items:center;justify-content:center;label:visible;",toString:de}),he=({modalId:n,onChangeOrder:o})=>{const{BackgroundComponent:t}=oe(),{context:r}=le(),{modal:i,onClose:a,onChange:c,onConfirm:d,onDestroy:u}=q(n),m=l((e=>{i&&i.closeOnBackdropClick&&i.visible&&a(),e.stopPropagation()}),[i,a]),p=s((()=>i?.BackgroundComponent||t),[t,i]);return i?e("div",{className:w(ue,{[pe]:i.manualDestroy?i.alive:i.visible,[me]:i.closeOnBackdropClick&&i.visible}),onClick:m,children:p&&e(p,{id:i.id,type:i.type,alive:i.alive,visible:i.visible,initiator:i.initiator,manualDestroy:i.manualDestroy,closeOnBackdropClick:i.closeOnBackdropClick,background:i.background,onChange:c,onConfirm:d,onClose:a,onDestroy:u,onChangeOrder:o,context:r})}):null};function Ce(){return"You have tried to stringify object returned from `css` function. It isn't supposed to be used directly (e.g. as value of the `className` prop), but rather handed to emotion so it can handle it (e.g. as value of `css` prop)."}const _e=N("production"===process.env.NODE_ENV?{name:"12g0hx0",styles:"pointer-events:none;display:none;position:fixed;inset:0;z-index:1"}:{name:"1hcczik-foreground",styles:"pointer-events:none;display:none;position:fixed;inset:0;z-index:1;label:foreground;",toString:Ce}),fe=N("production"===process.env.NODE_ENV?{name:"1g95xyq",styles:">*{pointer-events:all;}"}:{name:"123csva-active",styles:">*{pointer-events:all;};label:active;",toString:Ce}),ge=N("production"===process.env.NODE_ENV?{name:"1fmljv2",styles:"display:flex!important;justify-content:center;align-items:center"}:{name:"1p4unab-visible",styles:"display:flex!important;justify-content:center;align-items:center;label:visible;",toString:Ce}),be=t((({modal:o,handlers:t})=>{const{title:r,subtitle:i,content:a,footer:l}=s((()=>o),[o]),{context:c}=le(),{onConfirm:d}=s((()=>t),[t]),m=x(d),{TitleComponent:p,SubtitleComponent:h,ContentComponent:C,FooterComponent:f}=oe();return n(u,{children:[r&&(_(r)?e(p,{context:c,children:r}):r),i&&(_(i)?e(h,{context:c,children:i}):i),a&&(_(a)?e(C,{context:c,children:a}):B(a,{onConfirm:m})),!1!==l&&("function"==typeof l?l({onConfirm:m,context:c}):e(f,{onConfirm:m,confirmLabel:l?.confirm,hideConfirm:l?.hideConfirm,context:c}))]})})),ve=t((({modal:o,handlers:t})=>{const{title:r,subtitle:i,content:a,footer:l}=s((()=>o),[o]),{context:c}=le(),{onConfirm:d,onClose:m}=s((()=>t),[t]),p=x(d),h=x(m),{TitleComponent:C,SubtitleComponent:f,ContentComponent:g,FooterComponent:b}=oe();return n(u,{children:[r&&(_(r)?e(C,{context:c,children:r}):r),i&&(_(i)?e(f,{context:c,children:i}):i),a&&(_(a)?e(g,{context:c,children:a}):B(a,{onConfirm:p,onCancel:h,context:c})),!1!==l&&("function"==typeof l?l({onConfirm:p,onCancel:h,context:c}):e(b,{onConfirm:p,onCancel:h,confirmLabel:l?.confirm,cancelLabel:l?.cancel,hideConfirm:l?.hideConfirm,hideCancel:l?.hideCancel,context:c}))]})})),ye=t((({modal:o,handlers:r})=>{const{Input:a,defaultValue:c,disabled:d,title:m,subtitle:p,content:h,footer:C}=s((()=>({...o,Input:t(D(o.Input))})),[o]),{context:g}=le(),[b,v]=i(c),{onChange:y,onClose:k,onConfirm:O}=s((()=>r),[r]),F=x(k),N=x((e=>{const n=f(e)?e(b):e;v(n),y(n)})),w=l((()=>{requestAnimationFrame(O)}),[O]),I=s((()=>!!b&&!!d?.(b)),[d,b]),{TitleComponent:S,SubtitleComponent:E,ContentComponent:j,FooterComponent:P}=oe();return n(u,{children:[m&&(_(m)?e(S,{context:g,children:m}):m),p&&(_(p)?e(E,{context:g,children:p}):p),h&&(_(h)?e(j,{context:g,children:h}):B(h,{onConfirm:w,onCancel:F,context:g})),a&&e(a,{defaultValue:c,value:b,onChange:N,onConfirm:w,onCancel:F,context:g}),!1!==C&&("function"==typeof C?C({value:b,disabled:I,onChange:N,onConfirm:w,onCancel:F,context:g}):e(P,{disabled:I,onConfirm:w,onCancel:F,confirmLabel:C?.confirm,cancelLabel:C?.cancel,hideConfirm:C?.hideConfirm,hideCancel:C?.hideCancel,context:g}))]})})),ke=({modalId:o,onChangeOrder:t})=>{const{ForegroundComponent:r}=oe(),{context:i}=le(),{modal:a,onChange:l,onConfirm:c,onClose:d,onDestroy:u}=q(o),m=s((()=>a?.ForegroundComponent||r),[r,a]);return a?e("div",{className:w(_e,{[ge]:a.manualDestroy?a.alive:a.visible,[fe]:a.visible}),children:n(m,{id:a.id,type:a.type,alive:a.alive,visible:a.visible,initiator:a.initiator,manualDestroy:a.manualDestroy,closeOnBackdropClick:a.closeOnBackdropClick,background:a.background,onChange:l,onConfirm:c,onClose:d,onDestroy:u,onChangeOrder:t,context:i,children:["alert"===a.type&&e(be,{modal:a,handlers:{onConfirm:c}}),"confirm"===a.type&&e(ve,{modal:a,handlers:{onConfirm:c,onClose:d}}),"prompt"===a.type&&e(ye,{modal:a,handlers:{onChange:l,onConfirm:c,onClose:d}})]})}):null},xe=e=>{const[n,o]=O();return m((()=>{if(e)return e.subscribe(o)}),[e,o]),n},Be=N("production"===process.env.NODE_ENV?{name:"13dmkf4",styles:"position:fixed;inset:0;pointer-events:none;overflow:hidden"}:{name:"yjeu12-presenter",styles:"position:fixed;inset:0;pointer-events:none;overflow:hidden;label:presenter;",toString:function(){return"You have tried to stringify object returned from `css` function. It isn't supposed to be used directly (e.g. as value of the `className` prop), but rather handed to emotion so it can handle it (e.g. as value of `css` prop)."}}),{increment:De}=g(1),Oe=t((({modalId:o})=>{const t=r(null),{modal:i}=q(o);xe(i);const s=x((()=>{t.current&&(t.current.style.zIndex=`${De()}`)}));return n("div",{ref:t,className:Be,children:[e(he,{modalId:o,onChangeOrder:s}),e(ke,{modalId:o,onChangeOrder:s})]})})),Fe=N("production"===process.env.NODE_ENV?{name:"2hpasy",styles:"display:flex;align-items:center;justify-content:center;position:fixed;inset:0;pointer-events:none;z-index:1000;transition:background-color ease-in-out"}:{name:"lhj8co-anchor",styles:"display:flex;align-items:center;justify-content:center;position:fixed;inset:0;pointer-events:none;z-index:1000;transition:background-color ease-in-out;label:anchor;",toString:function(){return"You have tried to stringify object returned from `css` function. It isn't supposed to be used directly (e.g. as value of the `className` prop), but rather handed to emotion so it can handle it (e.g. as value of `css` prop)."}}),Ne=e=>e?.visible&&e.dimmed,we=t(D((()=>{const[n,o]=O(),{modalIds:t,setUpdater:r}=$();m((()=>{r(o)}),[r,o]);const i=te(),s=X(Ne,n);return e("div",{className:Fe,style:{transitionDuration:i.duration,backgroundColor:s?i.backdrop:"transparent"},children:b(t,(n=>e(Oe,{modalId:n},n)))})}))),Ie=({ForegroundComponent:n,BackgroundComponent:o,TitleComponent:t,SubtitleComponent:r,ContentComponent:i,FooterComponent:s,usePathname:a,options:l,context:c,anchor:d})=>I(e(ae,{context:c,children:e(ne,{ForegroundComponent:n,BackgroundComponent:o,TitleComponent:t,SubtitleComponent:r,ContentComponent:i,FooterComponent:s,options:l,children:e(A,{usePathname:a,children:e(we,{})})})}),d),Se=()=>{const e=r(S.activate()),n=r(null),[,o]=O(),t=l((t=>{e.current?(n.current=S.anchor({root:t}),o()):v("ModalProvider is already initialized",["ModalProvider can only be initialized once.","Nesting ModalProvider will be ignored..."],{info:"Something is wrong with the ModalProvider initialization..."})}),[o]);return{anchorRef:n,handleInitialize:t}},Ee=d((({usePathname:e,ForegroundComponent:o,BackgroundComponent:t,TitleComponent:r,SubtitleComponent:i,ContentComponent:a,FooterComponent:l,options:c,context:d,children:m},h)=>{const C=s((()=>e||ce),[e]),{anchorRef:_,handleInitialize:f}=Se();return p(h,(()=>({initialize:f})),[f]),F((()=>(null===h&&f(),()=>{_.current&&_.current.remove()}))),n(u,{children:[m,_.current&&Ie({ForegroundComponent:o,BackgroundComponent:t,TitleComponent:r,SubtitleComponent:i,ContentComponent:a,FooterComponent:l,usePathname:C,options:c,context:d,anchor:_.current})]})})),je=({usePathname:e,ForegroundComponent:n,BackgroundComponent:o,TitleComponent:t,SubtitleComponent:r,ContentComponent:i,FooterComponent:a,options:c,context:d,mode:u="auto"}={})=>{const m=s((()=>e||ce),[e]),{anchorRef:p,handleInitialize:h}=Se();F((()=>("auto"===u&&h(),()=>{p.current&&p.current.remove()})));const C=l((e=>{"manual"===u&&h(e)}),[u,h]);return{portal:p.current&&Ie({usePathname:m,ForegroundComponent:n,BackgroundComponent:o,TitleComponent:t,SubtitleComponent:r,ContentComponent:i,FooterComponent:a,options:c,context:d,anchor:p.current}),initialize:C}},Pe=(e,n)=>{const{modal:o,onDestroy:t}=q(e),i=xe(o),s=r({modal:o,onDestroy:t,milliseconds:_(n)?C(n):n});m((()=>{const{modal:e,onDestroy:n,milliseconds:o}=s.current;if(!e||e.visible||!e.alive)return;const t=setTimeout((()=>{n()}),o);return()=>{t&&clearTimeout(t)}}),[i])},ze=(e,n)=>{const o=r(n);o.current=n,a((()=>{if(!o.current)return;let n;return n=e?requestAnimationFrame((()=>o.current.onVisible?.())):requestAnimationFrame((()=>o.current.onHidden?.())),()=>{n&&cancelAnimationFrame(n)}}),[e])};export{Ee as ModalProvider,E as alert,j as confirm,P as prompt,X as useActiveModalCount,Pe as useDestroyAfter,je as useInitializeModal,ze as useModalAnimation,ie as useModalBackdrop,re as useModalDuration,te as useModalOptions,xe as useSubscribeModal};
|
|
1
|
+
import{jsx as e,jsxs as n}from"react/jsx-runtime";import{createContext as o,memo as t,useRef as r,useState as i,useMemo as s,useLayoutEffect as a,useCallback as l,useContext as c,forwardRef as d,Fragment as u,useEffect as m,useImperativeHandle as p}from"react";import{getRandomString as h,convertMsFromDuration as C,isString as f,isFunction as g,counterFactory as b,map as y,printError as v}from"@winglet/common-utils";import{useReference as k,useOnMountLayout as x,useHandle as w,renderComponent as B,withErrorBoundary as D,useVersion as O,useOnMount as F}from"@winglet/react-utils";import{css as N,cx as E}from"@emotion/css";import{createPortal as I}from"react-dom";
|
|
2
|
+
/******************************************************************************
|
|
3
|
+
Copyright (c) Microsoft Corporation.
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted.
|
|
7
|
+
|
|
8
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
9
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
10
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
11
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
12
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
13
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
14
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
15
|
+
***************************************************************************** */
|
|
16
|
+
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */function S(e,n,o,t){if("a"===o&&!t)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof n?e!==n||!t:!n.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===o?t:"a"===o?t.call(e):t?t.value:n.get(e)}function P(e,n,o,t,r){if("m"===t)throw new TypeError("Private method is not writable");if("a"===t&&!r)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof n?e!==n||!r:!n.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===t?r.call(e,o):r?r.value=o:n.set(e,o),o}var j,M,T,z,V;"function"==typeof SuppressedError&&SuppressedError;class _{static activate(){return!S(j,j,"f",M)&&P(j,j,!0,"f",M)}static anchor(e){if(S(j,j,"f",T)){const e=document.getElementById(S(j,j,"f",T).id);if(e)return e}const{tag:n="div",prefix:o="promise-modal",root:t=document.body}=e||{},r=document.createElement(n);return r.setAttribute("id",`${o}-${h(36)}`),t.appendChild(r),P(j,j,r,"f",T),r}static get prerender(){return S(j,j,"f",z)}static set openHandler(e){P(j,j,e,"f",V),P(j,j,[],"f",z)}static get unanchored(){return!S(j,j,"f",T)}static reset(){P(j,j,!1,"f",M),P(j,j,null,"f",T),P(j,j,[],"f",z),P(j,j,(e=>S(j,j,"f",z).push(e)),"f",V)}static open(e){S(j,j,"f",V).call(j,e)}}j=_,M={value:!1},T={value:null},z={value:[]},V={value:e=>S(j,j,"f",z).push(e)};const A=({subtype:e,title:n,subtitle:o,content:t,background:r,footer:i,dimmed:s,manualDestroy:a,closeOnBackdropClick:l,ForegroundComponent:c,BackgroundComponent:d})=>new Promise(((u,m)=>{try{_.open({type:"alert",subtype:e,resolve:()=>u(),title:n,subtitle:o,content:t,background:r,footer:i,dimmed:s,manualDestroy:a,closeOnBackdropClick:l,ForegroundComponent:c,BackgroundComponent:d})}catch(e){m(e)}})),L=({subtype:e,title:n,subtitle:o,content:t,background:r,footer:i,dimmed:s,manualDestroy:a,closeOnBackdropClick:l,ForegroundComponent:c,BackgroundComponent:d})=>new Promise(((u,m)=>{try{_.open({type:"confirm",subtype:e,resolve:e=>u(e??!1),title:n,subtitle:o,content:t,background:r,footer:i,dimmed:s,manualDestroy:a,closeOnBackdropClick:l,ForegroundComponent:c,BackgroundComponent:d})}catch(e){m(e)}})),$=({defaultValue:e,title:n,subtitle:o,content:t,Input:r,disabled:i,returnOnCancel:s,background:a,footer:l,dimmed:c,manualDestroy:d,closeOnBackdropClick:u,ForegroundComponent:m,BackgroundComponent:p})=>new Promise(((h,C)=>{try{_.open({type:"prompt",resolve:e=>h(e),title:n,subtitle:o,content:t,Input:r,defaultValue:e,disabled:i,returnOnCancel:s,background:a,footer:l,dimmed:c,manualDestroy:d,closeOnBackdropClick:u,ForegroundComponent:m,BackgroundComponent:p})}catch(e){C(e)}}));var q,H,W,Y,R;class U{get alive(){return S(this,q,"f")}get visible(){return S(this,H,"f")}constructor({id:e,initiator:n,title:o,subtitle:t,background:r,dimmed:i=!0,manualDestroy:s=!1,closeOnBackdropClick:a=!0,resolve:l,ForegroundComponent:c,BackgroundComponent:d}){q.set(this,void 0),H.set(this,void 0),W.set(this,void 0),Y.set(this,new Set),this.id=e,this.initiator=n,this.title=o,this.subtitle=t,this.background=r,this.dimmed=i,this.manualDestroy=s,this.closeOnBackdropClick=a,this.ForegroundComponent=c,this.BackgroundComponent=d,P(this,q,!0,"f"),P(this,H,!0,"f"),P(this,W,l,"f")}subscribe(e){return S(this,Y,"f").add(e),()=>{S(this,Y,"f").delete(e)}}publish(){for(const e of S(this,Y,"f"))e()}resolve(e){S(this,W,"f").call(this,e)}onDestroy(){const e=!0===S(this,q,"f");P(this,q,!1,"f"),this.manualDestroy&&e&&this.publish()}onShow(){const e=!1===S(this,H,"f");P(this,H,!0,"f"),e&&this.publish()}onHide(){const e=!0===S(this,H,"f");P(this,H,!1,"f"),e&&this.publish()}}q=new WeakMap,H=new WeakMap,W=new WeakMap,Y=new WeakMap;class G extends U{constructor({id:e,initiator:n,type:o,subtype:t,title:r,subtitle:i,content:s,footer:a,background:l,dimmed:c,manualDestroy:d,closeOnBackdropClick:u,resolve:m,ForegroundComponent:p,BackgroundComponent:h}){super({id:e,initiator:n,title:r,subtitle:i,background:l,dimmed:c,manualDestroy:d,closeOnBackdropClick:u,resolve:m,ForegroundComponent:p,BackgroundComponent:h}),this.type=o,this.subtype=t,this.content=s,this.footer=a}onClose(){this.resolve(null)}onConfirm(){this.resolve(null)}}class J extends U{constructor({id:e,initiator:n,type:o,subtype:t,title:r,subtitle:i,content:s,footer:a,background:l,dimmed:c,manualDestroy:d,closeOnBackdropClick:u,resolve:m,ForegroundComponent:p,BackgroundComponent:h}){super({id:e,initiator:n,title:r,subtitle:i,background:l,dimmed:c,manualDestroy:d,closeOnBackdropClick:u,resolve:m,ForegroundComponent:p,BackgroundComponent:h}),this.type=o,this.subtype=t,this.content=s,this.footer=a}onClose(){this.resolve(!1)}onConfirm(){this.resolve(!0)}}class K extends U{constructor({id:e,initiator:n,type:o,title:t,subtitle:r,content:i,defaultValue:s,Input:a,disabled:l,returnOnCancel:c,footer:d,background:u,dimmed:m,manualDestroy:p,closeOnBackdropClick:h,resolve:C,ForegroundComponent:f,BackgroundComponent:g}){super({id:e,initiator:n,title:t,subtitle:r,background:u,dimmed:m,manualDestroy:p,closeOnBackdropClick:h,resolve:C,ForegroundComponent:f,BackgroundComponent:g}),R.set(this,void 0),this.type=o,this.content=i,this.Input=a,this.defaultValue=s,P(this,R,s,"f"),this.disabled=l,this.returnOnCancel=c,this.footer=d}onChange(e){P(this,R,e,"f")}onConfirm(){this.resolve(S(this,R,"f")??null)}onClose(){this.returnOnCancel?this.resolve(S(this,R,"f")??null):this.resolve(null)}}R=new WeakMap;const Q=e=>{switch(e.type){case"alert":return new G(e);case"confirm":return new J(e);case"prompt":return new K(e)}throw new Error(`Unknown modal: ${e.type}`,{modal:e})},X=o({}),Z=t((({usePathname:n,children:o})=>{const t=r(new Map),[c,d]=i([]),u=k(c),{pathname:m}=n(),p=r(m),h=r(0),f=Ce(),g=s((()=>C(f.duration)),[f]);x((()=>{const{manualDestroy:e,closeOnBackdropClick:n}=f;for(const o of _.prerender){const r=Q({...o,id:h.current++,initiator:p.current,manualDestroy:void 0!==o.manualDestroy?o.manualDestroy:e,closeOnBackdropClick:void 0!==o.closeOnBackdropClick?o.closeOnBackdropClick:n});t.current.set(r.id,r),d((e=>[...e,r.id]))}return _.openHandler=o=>{const r=Q({...o,id:h.current++,initiator:p.current,manualDestroy:void 0!==o.manualDestroy?o.manualDestroy:e,closeOnBackdropClick:void 0!==o.closeOnBackdropClick?o.closeOnBackdropClick:n});t.current.set(r.id,r),d((e=>{const n=[];for(let o=0;o<e.length;o++){const r=e[o];t.current.get(r)?.alive?n.push(r):t.current.delete(r)}return[...n,r.id]}))},()=>{_.reset()}})),a((()=>{for(const e of u.current){const n=t.current.get(e);n?.alive&&(n.initiator===m?n.onShow():n.onHide())}p.current=m}),[m]);const b=l((e=>t.current.get(e)),[]),y=l((e=>{const n=t.current.get(e);n&&(n.onDestroy(),v.current?.())}),[]),v=r(void 0),w=l((e=>{const n=t.current.get(e);n&&(n.onHide(),v.current?.(),n.manualDestroy||setTimeout((()=>{n.onDestroy()}),g))}),[g]),B=l(((e,n)=>{const o=t.current.get(e);o&&"prompt"===o.type&&o.onChange(n)}),[]),D=l((e=>{const n=t.current.get(e);n&&(n.onConfirm(),w(e))}),[w]),O=l((e=>{const n=t.current.get(e);n&&(n.onClose(),w(e))}),[w]),F=l((e=>({modal:b(e),onConfirm:()=>D(e),onClose:()=>O(e),onChange:n=>B(e,n),onDestroy:()=>y(e)})),[b,D,O,B,y]),N=s((()=>({modalIds:c,getModalNode:b,onChange:B,onConfirm:D,onClose:O,onDestroy:y,getModal:F,setUpdater:e=>{v.current=e}})),[c,F,b,B,D,O,y]);return e(X.Provider,{value:N,children:o})})),ee=()=>c(X),ne=e=>{const{getModal:n}=ee();return s((()=>n(e)),[e,n])};function oe(){return"You have tried to stringify object returned from `css` function. It isn't supposed to be used directly (e.g. as value of the `className` prop), but rather handed to emotion so it can handle it (e.g. as value of `css` prop)."}const te=N("production"===process.env.NODE_ENV?{name:"131j9g2",styles:"margin:unset"}:{name:"1w3kbco-fallback",styles:"margin:unset;label:fallback;",toString:oe}),re=N("production"===process.env.NODE_ENV?{name:"1kuk3a3",styles:"display:flex;flex-direction:column;justify-content:center;align-items:center;background-color:white;padding:20px 80px;gap:10px;border:1px solid black"}:{name:"16dbbea-frame",styles:"display:flex;flex-direction:column;justify-content:center;align-items:center;background-color:white;padding:20px 80px;gap:10px;border:1px solid black;label:frame;",toString:oe}),ie=({children:n})=>e("h2",{className:te,children:n}),se=({children:n})=>e("h3",{className:te,children:n}),ae=({children:n})=>e("div",{className:te,children:n}),le=({confirmLabel:o,hideConfirm:t=!1,cancelLabel:r,hideCancel:i=!1,disabled:s,onConfirm:a,onCancel:l})=>n("div",{children:[!t&&e("button",{onClick:a,disabled:s,children:o||"확인"}),!i&&"function"==typeof l&&e("button",{onClick:l,children:r||"취소"})]}),ce=e=>e?.visible,de=(e=ce,n=0)=>{const{modalIds:o,getModalNode:t}=ee();return s((()=>{let n=0;for(const r of o)e(t(r))&&n++;return n}),[t,o,n])},ue=d((({id:n,onChangeOrder:o,children:t},r)=>{const i=de(),[a,l]=s((()=>{const e=i>1;return[e?Math.floor(n/5)%3*100:0,e?n%5*35:0]}),[i,n]);return e("div",{ref:r,className:re,onClick:o,style:{marginBottom:`calc(25vh + ${a}px)`,marginLeft:`${a}px`,transform:`translate(${l}px, ${l}px)`},children:t})})),me=o({}),pe=t((({ForegroundComponent:n,BackgroundComponent:o,TitleComponent:r,SubtitleComponent:i,ContentComponent:a,FooterComponent:l,options:c,children:d})=>{const u=s((()=>({BackgroundComponent:o,ForegroundComponent:n||ue,TitleComponent:r||ie,SubtitleComponent:i||se,ContentComponent:t(a||ae),FooterComponent:t(l||le),options:{duration:"300ms",backdrop:"rgba(0, 0, 0, 0.5)",closeOnBackdropClick:!0,manualDestroy:!1,...c}})),[n,o,a,l,i,r,c]);return e(me.Provider,{value:u,children:d})})),he=()=>c(me),Ce=()=>c(me).options,fe=()=>{const e=Ce();return{duration:e.duration,milliseconds:C(e.duration)}},ge=()=>Ce().backdrop,be=o({}),ye=({context:n,children:o})=>{const t=s((()=>({context:n||{}})),[n]);return e(be.Provider,{value:t,children:o})},ve=()=>c(be),ke=()=>{const[e,n]=i(window.location.pathname);return a((()=>{let o;const t=()=>{o&&cancelAnimationFrame(o),e!==window.location.pathname?n(window.location.pathname):o=requestAnimationFrame(t)};return o=requestAnimationFrame(t),()=>{o&&cancelAnimationFrame(o)}}),[e]),{pathname:e}};function xe(){return"You have tried to stringify object returned from `css` function. It isn't supposed to be used directly (e.g. as value of the `className` prop), but rather handed to emotion so it can handle it (e.g. as value of `css` prop)."}const we=N("production"===process.env.NODE_ENV?{name:"u7uu4v",styles:"display:none;position:fixed;inset:0;z-index:-999;pointer-events:none;>*{pointer-events:none;}"}:{name:"coymdj-background",styles:"display:none;position:fixed;inset:0;z-index:-999;pointer-events:none;>*{pointer-events:none;};label:background;",toString:xe}),Be=N("production"===process.env.NODE_ENV?{name:"n07k1x",styles:"pointer-events:all"}:{name:"1hektcs-active",styles:"pointer-events:all;label:active;",toString:xe}),De=N("production"===process.env.NODE_ENV?{name:"1wnowod",styles:"display:flex;align-items:center;justify-content:center"}:{name:"xppew7-visible",styles:"display:flex;align-items:center;justify-content:center;label:visible;",toString:xe}),Oe=({modalId:n,onChangeOrder:o})=>{const{BackgroundComponent:t}=he(),{context:r}=ve(),{modal:i,onClose:a,onChange:c,onConfirm:d,onDestroy:u}=ne(n),m=l((e=>{i&&i.closeOnBackdropClick&&i.visible&&a(),e.stopPropagation()}),[i,a]),p=s((()=>i?.BackgroundComponent||t),[t,i]);return i?e("div",{className:E(we,{[De]:i.manualDestroy?i.alive:i.visible,[Be]:i.closeOnBackdropClick&&i.visible}),onClick:m,children:p&&e(p,{id:i.id,type:i.type,alive:i.alive,visible:i.visible,initiator:i.initiator,manualDestroy:i.manualDestroy,closeOnBackdropClick:i.closeOnBackdropClick,background:i.background,onChange:c,onConfirm:d,onClose:a,onDestroy:u,onChangeOrder:o,context:r})}):null};function Fe(){return"You have tried to stringify object returned from `css` function. It isn't supposed to be used directly (e.g. as value of the `className` prop), but rather handed to emotion so it can handle it (e.g. as value of `css` prop)."}const Ne=N("production"===process.env.NODE_ENV?{name:"12g0hx0",styles:"pointer-events:none;display:none;position:fixed;inset:0;z-index:1"}:{name:"1hcczik-foreground",styles:"pointer-events:none;display:none;position:fixed;inset:0;z-index:1;label:foreground;",toString:Fe}),Ee=N("production"===process.env.NODE_ENV?{name:"1g95xyq",styles:">*{pointer-events:all;}"}:{name:"123csva-active",styles:">*{pointer-events:all;};label:active;",toString:Fe}),Ie=N("production"===process.env.NODE_ENV?{name:"1fmljv2",styles:"display:flex!important;justify-content:center;align-items:center"}:{name:"1p4unab-visible",styles:"display:flex!important;justify-content:center;align-items:center;label:visible;",toString:Fe}),Se=t((({modal:o,handlers:t})=>{const{title:r,subtitle:i,content:a,footer:l}=s((()=>o),[o]),{context:c}=ve(),{onConfirm:d}=s((()=>t),[t]),m=w(d),{TitleComponent:p,SubtitleComponent:h,ContentComponent:C,FooterComponent:g}=he();return n(u,{children:[r&&(f(r)?e(p,{context:c,children:r}):r),i&&(f(i)?e(h,{context:c,children:i}):i),a&&(f(a)?e(C,{context:c,children:a}):B(a,{onConfirm:m})),!1!==l&&("function"==typeof l?l({onConfirm:m,context:c}):e(g,{onConfirm:m,confirmLabel:l?.confirm,hideConfirm:l?.hideConfirm,context:c}))]})})),Pe=t((({modal:o,handlers:t})=>{const{title:r,subtitle:i,content:a,footer:l}=s((()=>o),[o]),{context:c}=ve(),{onConfirm:d,onClose:m}=s((()=>t),[t]),p=w(d),h=w(m),{TitleComponent:C,SubtitleComponent:g,ContentComponent:b,FooterComponent:y}=he();return n(u,{children:[r&&(f(r)?e(C,{context:c,children:r}):r),i&&(f(i)?e(g,{context:c,children:i}):i),a&&(f(a)?e(b,{context:c,children:a}):B(a,{onConfirm:p,onCancel:h,context:c})),!1!==l&&("function"==typeof l?l({onConfirm:p,onCancel:h,context:c}):e(y,{onConfirm:p,onCancel:h,confirmLabel:l?.confirm,cancelLabel:l?.cancel,hideConfirm:l?.hideConfirm,hideCancel:l?.hideCancel,context:c}))]})})),je=t((({modal:o,handlers:r})=>{const{Input:a,defaultValue:c,disabled:d,title:m,subtitle:p,content:h,footer:C}=s((()=>({...o,Input:t(D(o.Input))})),[o]),{context:b}=ve(),[y,v]=i(c),{onChange:k,onClose:x,onConfirm:O}=s((()=>r),[r]),F=w(x),N=w((e=>{const n=g(e)?e(y):e;v(n),k(n)})),E=l((()=>{requestAnimationFrame(O)}),[O]),I=s((()=>!!y&&!!d?.(y)),[d,y]),{TitleComponent:S,SubtitleComponent:P,ContentComponent:j,FooterComponent:M}=he();return n(u,{children:[m&&(f(m)?e(S,{context:b,children:m}):m),p&&(f(p)?e(P,{context:b,children:p}):p),h&&(f(h)?e(j,{context:b,children:h}):B(h,{onConfirm:E,onCancel:F,context:b})),a&&e(a,{defaultValue:c,value:y,onChange:N,onConfirm:E,onCancel:F,context:b}),!1!==C&&("function"==typeof C?C({value:y,disabled:I,onChange:N,onConfirm:E,onCancel:F,context:b}):e(M,{disabled:I,onConfirm:E,onCancel:F,confirmLabel:C?.confirm,cancelLabel:C?.cancel,hideConfirm:C?.hideConfirm,hideCancel:C?.hideCancel,context:b}))]})})),Me=({modalId:o,onChangeOrder:t})=>{const{ForegroundComponent:r}=he(),{context:i}=ve(),{modal:a,onChange:l,onConfirm:c,onClose:d,onDestroy:u}=ne(o),m=s((()=>a?.ForegroundComponent||r),[r,a]);return a?e("div",{className:E(Ne,{[Ie]:a.manualDestroy?a.alive:a.visible,[Ee]:a.visible}),children:n(m,{id:a.id,type:a.type,alive:a.alive,visible:a.visible,initiator:a.initiator,manualDestroy:a.manualDestroy,closeOnBackdropClick:a.closeOnBackdropClick,background:a.background,onChange:l,onConfirm:c,onClose:d,onDestroy:u,onChangeOrder:t,context:i,children:["alert"===a.type&&e(Se,{modal:a,handlers:{onConfirm:c}}),"confirm"===a.type&&e(Pe,{modal:a,handlers:{onConfirm:c,onClose:d}}),"prompt"===a.type&&e(je,{modal:a,handlers:{onChange:l,onConfirm:c,onClose:d}})]})}):null},Te=e=>{const[n,o]=O();return m((()=>{if(e)return e.subscribe(o)}),[e,o]),n},ze=N("production"===process.env.NODE_ENV?{name:"13dmkf4",styles:"position:fixed;inset:0;pointer-events:none;overflow:hidden"}:{name:"yjeu12-presenter",styles:"position:fixed;inset:0;pointer-events:none;overflow:hidden;label:presenter;",toString:function(){return"You have tried to stringify object returned from `css` function. It isn't supposed to be used directly (e.g. as value of the `className` prop), but rather handed to emotion so it can handle it (e.g. as value of `css` prop)."}}),{increment:Ve}=b(1),_e=t((({modalId:o})=>{const t=r(null),{modal:i}=ne(o);Te(i);const s=w((()=>{t.current&&(t.current.style.zIndex=`${Ve()}`)}));return n("div",{ref:t,className:ze,children:[e(Oe,{modalId:o,onChangeOrder:s}),e(Me,{modalId:o,onChangeOrder:s})]})})),Ae=N("production"===process.env.NODE_ENV?{name:"2hpasy",styles:"display:flex;align-items:center;justify-content:center;position:fixed;inset:0;pointer-events:none;z-index:1000;transition:background-color ease-in-out"}:{name:"lhj8co-anchor",styles:"display:flex;align-items:center;justify-content:center;position:fixed;inset:0;pointer-events:none;z-index:1000;transition:background-color ease-in-out;label:anchor;",toString:function(){return"You have tried to stringify object returned from `css` function. It isn't supposed to be used directly (e.g. as value of the `className` prop), but rather handed to emotion so it can handle it (e.g. as value of `css` prop)."}}),Le=e=>e?.visible&&e.dimmed,$e=t(D((()=>{const[n,o]=O(),{modalIds:t,setUpdater:r}=ee();m((()=>{r(o)}),[r,o]);const i=Ce(),s=de(Le,n);return e("div",{className:Ae,style:{transitionDuration:i.duration,backgroundColor:s?i.backdrop:"transparent"},children:y(t,(n=>e(_e,{modalId:n},n)))})}))),qe=({ForegroundComponent:n,BackgroundComponent:o,TitleComponent:t,SubtitleComponent:r,ContentComponent:i,FooterComponent:s,usePathname:a,options:l,context:c,anchor:d})=>I(e(ye,{context:c,children:e(pe,{ForegroundComponent:n,BackgroundComponent:o,TitleComponent:t,SubtitleComponent:r,ContentComponent:i,FooterComponent:s,options:l,children:e(Z,{usePathname:a,children:e($e,{})})})}),d),He=()=>{const e=r(_.activate()),n=r(null),[,o]=O(),t=l((t=>{e.current?(n.current=_.anchor({root:t}),o()):v("ModalProvider is already initialized",["ModalProvider can only be initialized once.","Nesting ModalProvider will be ignored..."],{info:"Something is wrong with the ModalProvider initialization..."})}),[o]);return{anchorRef:n,handleInitialize:t}},We=d((({usePathname:e,ForegroundComponent:o,BackgroundComponent:t,TitleComponent:r,SubtitleComponent:i,ContentComponent:a,FooterComponent:l,options:c,context:d,children:m},h)=>{const C=s((()=>e||ke),[e]),{anchorRef:f,handleInitialize:g}=He();return p(h,(()=>({initialize:g})),[g]),F((()=>(null===h&&g(),()=>{f.current&&f.current.remove()}))),n(u,{children:[m,f.current&&qe({ForegroundComponent:o,BackgroundComponent:t,TitleComponent:r,SubtitleComponent:i,ContentComponent:a,FooterComponent:l,usePathname:C,options:c,context:d,anchor:f.current})]})})),Ye=({usePathname:e,ForegroundComponent:n,BackgroundComponent:o,TitleComponent:t,SubtitleComponent:r,ContentComponent:i,FooterComponent:a,options:c,context:d,mode:u="auto"}={})=>{const m=s((()=>e||ke),[e]),{anchorRef:p,handleInitialize:h}=He();F((()=>("auto"===u&&h(),()=>{p.current&&p.current.remove()})));const C=l((e=>{"manual"===u&&h(e)}),[u,h]);return{portal:p.current&&qe({usePathname:m,ForegroundComponent:n,BackgroundComponent:o,TitleComponent:t,SubtitleComponent:r,ContentComponent:i,FooterComponent:a,options:c,context:d,anchor:p.current}),initialize:C}},Re=(e,n)=>{const{modal:o,onDestroy:t}=ne(e),i=Te(o),s=r({modal:o,onDestroy:t,milliseconds:f(n)?C(n):n});m((()=>{const{modal:e,onDestroy:n,milliseconds:o}=s.current;if(!e||e.visible||!e.alive)return;const t=setTimeout((()=>{n()}),o);return()=>{t&&clearTimeout(t)}}),[i])},Ue=(e,n)=>{const o=r(n);o.current=n,a((()=>{if(!o.current)return;let n;return n=e?requestAnimationFrame((()=>o.current.onVisible?.())):requestAnimationFrame((()=>o.current.onHidden?.())),()=>{n&&cancelAnimationFrame(n)}}),[e])};export{We as ModalProvider,A as alert,L as confirm,$ as prompt,de as useActiveModalCount,Re as useDestroyAfter,Ye as useInitializeModal,Ue as useModalAnimation,ge as useModalBackdrop,fe as useModalDuration,Ce as useModalOptions,Te as useSubscribeModal};
|
|
2
17
|
//# sourceMappingURL=index.esm.js.map
|