@ifhover/leaf-ui 0.17.1 → 0.17.3
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/cjs/browser/modules/drawer/drawer.cjs +8 -0
- package/dist/cjs/browser/modules/drawer/drawer.cjs.map +1 -1
- package/dist/cjs/browser/modules/image/viewer.cjs +2 -0
- package/dist/cjs/browser/modules/image/viewer.cjs.map +1 -1
- package/dist/cjs/browser/modules/modal/base.cjs +8 -0
- package/dist/cjs/browser/modules/modal/base.cjs.map +1 -1
- package/dist/cjs/browser/modules/popover/popover.cjs +32 -41
- package/dist/cjs/browser/modules/popover/popover.cjs.map +1 -1
- package/dist/cjs/browser/modules/shared/dialog.cjs +74 -2
- package/dist/cjs/browser/modules/shared/dialog.cjs.map +1 -1
- package/dist/cjs/browser/modules/shared/floating.cjs +121 -0
- package/dist/cjs/browser/modules/shared/floating.cjs.map +1 -1
- package/dist/cjs/browser/modules/tooltip/tooltip.cjs +29 -40
- package/dist/cjs/browser/modules/tooltip/tooltip.cjs.map +1 -1
- package/dist/cjs/browser/modules/tour/tour.cjs +75 -64
- package/dist/cjs/browser/modules/tour/tour.cjs.map +1 -1
- package/dist/cjs/drawer/drawer.cjs +8 -0
- package/dist/cjs/drawer/drawer.cjs.map +1 -1
- package/dist/cjs/drawer/drawer.d.cts.map +1 -1
- package/dist/cjs/image/viewer.cjs +2 -0
- package/dist/cjs/image/viewer.cjs.map +1 -1
- package/dist/cjs/modal/base.cjs +8 -0
- package/dist/cjs/modal/base.cjs.map +1 -1
- package/dist/cjs/modal/base.d.cts.map +1 -1
- package/dist/cjs/popover/popover.cjs +32 -41
- package/dist/cjs/popover/popover.cjs.map +1 -1
- package/dist/cjs/popover/popover.d.cts.map +1 -1
- package/dist/cjs/shared/dialog.cjs +74 -2
- package/dist/cjs/shared/dialog.cjs.map +1 -1
- package/dist/cjs/shared/dialog.d.cts +10 -1
- package/dist/cjs/shared/dialog.d.cts.map +1 -1
- package/dist/cjs/shared/floating.cjs +121 -0
- package/dist/cjs/shared/floating.cjs.map +1 -1
- package/dist/cjs/shared/floating.d.cts +22 -1
- package/dist/cjs/shared/floating.d.cts.map +1 -1
- package/dist/cjs/styles/colorpicker.css +1 -1
- package/dist/cjs/styles/components/popover.css +1 -1
- package/dist/cjs/styles/components/tooltip.css +1 -1
- package/dist/cjs/styles/components/tour.css +1 -1
- package/dist/cjs/styles/floatbutton.css +1 -1
- package/dist/cjs/styles/index.css +26 -18
- package/dist/cjs/styles/index.css.map +1 -1
- package/dist/cjs/styles/popconfirm.css +1 -1
- package/dist/cjs/styles/popover.css +1 -1
- package/dist/cjs/styles/slider.css +1 -1
- package/dist/cjs/styles/tooltip.css +1 -1
- package/dist/cjs/styles/tour.css +1 -1
- package/dist/cjs/tooltip/tooltip.cjs +29 -40
- package/dist/cjs/tooltip/tooltip.cjs.map +1 -1
- package/dist/cjs/tooltip/tooltip.d.cts.map +1 -1
- package/dist/cjs/tour/tour.cjs +75 -64
- package/dist/cjs/tour/tour.cjs.map +1 -1
- package/dist/cjs/tour/tour.d.cts.map +1 -1
- package/dist/esm/browser/modules/drawer/drawer.js +9 -1
- package/dist/esm/browser/modules/drawer/drawer.js.map +1 -1
- package/dist/esm/browser/modules/image/viewer.js +3 -1
- package/dist/esm/browser/modules/image/viewer.js.map +1 -1
- package/dist/esm/browser/modules/modal/base.js +9 -1
- package/dist/esm/browser/modules/modal/base.js.map +1 -1
- package/dist/esm/browser/modules/popover/popover.js +33 -42
- package/dist/esm/browser/modules/popover/popover.js.map +1 -1
- package/dist/esm/browser/modules/shared/dialog.js +71 -2
- package/dist/esm/browser/modules/shared/dialog.js.map +1 -1
- package/dist/esm/browser/modules/shared/floating.js +119 -1
- package/dist/esm/browser/modules/shared/floating.js.map +1 -1
- package/dist/esm/browser/modules/tooltip/tooltip.js +30 -41
- package/dist/esm/browser/modules/tooltip/tooltip.js.map +1 -1
- package/dist/esm/browser/modules/tour/tour.js +76 -65
- package/dist/esm/browser/modules/tour/tour.js.map +1 -1
- package/dist/esm/drawer/drawer.d.ts.map +1 -1
- package/dist/esm/drawer/drawer.js +9 -1
- package/dist/esm/drawer/drawer.js.map +1 -1
- package/dist/esm/image/viewer.js +3 -1
- package/dist/esm/image/viewer.js.map +1 -1
- package/dist/esm/modal/base.d.ts.map +1 -1
- package/dist/esm/modal/base.js +9 -1
- package/dist/esm/modal/base.js.map +1 -1
- package/dist/esm/popover/popover.d.ts.map +1 -1
- package/dist/esm/popover/popover.js +33 -42
- package/dist/esm/popover/popover.js.map +1 -1
- package/dist/esm/shared/dialog.d.ts +10 -1
- package/dist/esm/shared/dialog.d.ts.map +1 -1
- package/dist/esm/shared/dialog.js +71 -2
- package/dist/esm/shared/dialog.js.map +1 -1
- package/dist/esm/shared/floating.d.ts +22 -1
- package/dist/esm/shared/floating.d.ts.map +1 -1
- package/dist/esm/shared/floating.js +119 -1
- package/dist/esm/shared/floating.js.map +1 -1
- package/dist/esm/styles/colorpicker.css +1 -1
- package/dist/esm/styles/components/popover.css +1 -1
- package/dist/esm/styles/components/tooltip.css +1 -1
- package/dist/esm/styles/components/tour.css +1 -1
- package/dist/esm/styles/floatbutton.css +1 -1
- package/dist/esm/styles/index.css +26 -18
- package/dist/esm/styles/index.css.map +1 -1
- package/dist/esm/styles/popconfirm.css +1 -1
- package/dist/esm/styles/popover.css +1 -1
- package/dist/esm/styles/slider.css +1 -1
- package/dist/esm/styles/tooltip.css +1 -1
- package/dist/esm/styles/tour.css +1 -1
- package/dist/esm/tooltip/tooltip.d.ts.map +1 -1
- package/dist/esm/tooltip/tooltip.js +30 -41
- package/dist/esm/tooltip/tooltip.js.map +1 -1
- package/dist/esm/tour/tour.d.ts.map +1 -1
- package/dist/esm/tour/tour.js +76 -65
- package/dist/esm/tour/tour.js.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"modal/base.js","sources":["../../../../../src/modal/base.tsx"],"sourcesContent":["import { X } from 'lucide-react';\nimport {\n type ComponentType,\n type ReactNode,\n type Ref,\n useEffect,\n useId,\n useRef,\n useState,\n} from 'react';\nimport { ButtonControl } from '../button/button';\nimport { useLeafConfig } from '../config-provider/context';\nimport { ScrollbarControl as Scrollbar } from '../scrollbar/scrollbar';\nimport { classes } from '../shared/classes';\nimport { useDialog } from '../shared/dialog';\nimport { inertProps } from '../shared/inert';\nimport { OverlayOwner } from '../shared/overlay-owner';\nimport { useNaturalHeightTransition, usePresence } from '../shared/presence';\nimport { ScopedPortal } from '../shared/scoped-portal';\nimport type { ModalFooterActions, ModalProps, ModalTabsProps } from './modal';\n\nexport interface ModalTabsRenderProps {\n open: boolean;\n tabs: ModalTabsProps;\n title?: ReactNode;\n titleId: string;\n hasHeading: boolean;\n closeButton: ReactNode;\n contentRef: Ref<HTMLDivElement>;\n snapHeight: () => void;\n ariaLabel?: string;\n ariaLabelledBy?: string;\n scrollbarLabel?: string;\n scrollbarLabelledBy?: string;\n error?: string;\n children?: ReactNode;\n}\n\nexport interface ModalBaseProps extends ModalProps {\n renderTabsLayout?: ComponentType<ModalTabsRenderProps>;\n}\n\nfunction ModalSurface({\n open,\n title,\n description,\n icon,\n divided = true,\n tabs,\n footer,\n confirmText,\n cancelText,\n confirmLoading = false,\n confirmButtonProps,\n cancelButtonProps,\n onConfirm,\n onCancel,\n width = 480,\n closable = true,\n maskClosable = true,\n keyboard = true,\n onClose,\n afterClose,\n forceRender = false,\n destroyOnClose = false,\n preserve,\n initialFocus,\n returnFocus,\n container: _container,\n renderTabsLayout: RenderTabsLayout,\n children,\n className,\n style,\n ...props\n}: ModalBaseProps) {\n const { messages, maskBlur } = useLeafConfig();\n const [pending, setPending] = useState(false);\n const [error, setError] = useState<string>();\n const mounted = useRef(true);\n const accepting = useRef(false);\n const generation = useRef(0);\n useEffect(() => {\n mounted.current = true;\n return () => {\n mounted.current = false;\n };\n }, []);\n useEffect(() => {\n generation.current++;\n accepting.current = false;\n setPending(false);\n if (open) setError(undefined);\n }, [open]);\n const busy = pending || confirmLoading;\n async function accept() {\n if (accepting.current || busy) return;\n if (!onConfirm) {\n if (confirmButtonProps?.type !== 'submit') onClose?.();\n return;\n }\n accepting.current = true;\n const request = generation.current;\n setPending(true);\n setError(undefined);\n try {\n await onConfirm();\n } catch (reason) {\n if (mounted.current && generation.current === request)\n setError(reason instanceof Error ? reason.message : String(reason));\n } finally {\n if (generation.current === request) {\n accepting.current = false;\n if (mounted.current) setPending(false);\n }\n }\n }\n const cancel = () => {\n if (!busy) (onCancel ?? onClose)?.();\n };\n const actions: ModalFooterActions = {\n cancelButton: (\n <ButtonControl\n type=\"button\"\n variant=\"outline\"\n {...cancelButtonProps}\n disabled={busy || cancelButtonProps?.disabled}\n onClick={(event) => {\n cancelButtonProps?.onClick?.(event);\n if (!event.defaultPrevented) cancel();\n }}\n >\n {cancelText ?? messages.common.cancel}\n </ButtonControl>\n ),\n confirmButton: (\n <ButtonControl\n type=\"button\"\n variant=\"solid\"\n {...confirmButtonProps}\n loading={busy || confirmButtonProps?.loading}\n onClick={(event) => {\n confirmButtonProps?.onClick?.(event);\n if (!event.defaultPrevented) void accept();\n }}\n >\n {confirmText ?? messages.common.confirm}\n </ButtonControl>\n ),\n };\n const renderedFooter =\n typeof footer === 'function' ? (\n footer(actions)\n ) : footer === undefined ? (\n <div className=\"leaf-modal__actions\">\n {actions.cancelButton}\n {actions.confirmButton}\n </div>\n ) : (\n footer\n );\n const panel = useRef<HTMLDivElement>(null);\n const content = useRef<HTMLDivElement>(null);\n const backdrop = useRef<HTMLButtonElement>(null);\n const present = usePresence(open, backdrop);\n const snapHeight = useNaturalHeightTransition(panel, content, open);\n const titleId = `${useId()}-title`;\n const descriptionId = `${useId()}-description`;\n const modalId = `${useId()}-dialog`;\n const close = useRef(cancel);\n close.current = cancel;\n const wasPresent = useRef(false);\n useEffect(() => {\n if (wasPresent.current && !present) afterClose?.();\n wasPresent.current = present;\n }, [present, afterClose]);\n useDialog(open, panel, modalId, cancel, keyboard, { initialFocus, returnFocus });\n const visited = useRef(false);\n if (open) visited.current = true;\n if (\n !present &&\n !forceRender &&\n ((preserve === undefined ? destroyOnClose : !preserve) || !visited.current)\n )\n return null;\n\n const hasTabs = Boolean(tabs?.items?.length);\n const hasHeading = title != null || description != null || icon != null;\n const closeButton = closable ? (\n <button\n type=\"button\"\n className=\"leaf-modal__close\"\n aria-label={messages.common.close}\n onClick={() => close.current?.()}\n >\n <X size={18} aria-hidden=\"true\" />\n </button>\n ) : null;\n const scrollbarLabel =\n title == null\n ? (props['aria-label'] ?? tabs?.['aria-label'] ?? messages.common.confirm)\n : undefined;\n const scrollbarLabelledBy = title != null ? titleId : undefined;\n\n return (\n <div\n hidden={!present}\n className=\"leaf-modal-mask\"\n data-blur={maskBlur ? undefined : 'off'}\n data-state={open ? 'open' : 'closing'}\n aria-hidden={!open || undefined}\n {...inertProps(!open)}\n >\n <button\n ref={backdrop}\n type=\"button\"\n className=\"leaf-modal-backdrop\"\n tabIndex={-1}\n aria-label={messages.common.close}\n onClick={() => {\n if (maskClosable) close.current?.();\n }}\n />\n {/* biome-ignore lint/a11y/useAriaPropsSupportedByRole: dialog and alertdialog both support aria-modal. */}\n <div\n {...props}\n ref={panel}\n id={props.id ?? modalId}\n role={props.role ?? 'dialog'}\n aria-modal=\"true\"\n aria-labelledby={title != null ? titleId : props['aria-labelledby']}\n aria-describedby={\n [props['aria-describedby'], description != null && descriptionId]\n .filter(Boolean)\n .join(' ') || undefined\n }\n tabIndex={-1}\n className={classes(\n 'leaf-modal',\n divided && 'leaf-modal--divided',\n hasTabs && 'leaf-modal--tabbed',\n hasHeading && 'leaf-modal--headed',\n className,\n )}\n style={{ width, ...style }}\n >\n <OverlayOwner.Provider value={modalId}>\n {(hasHeading || (!hasTabs && closable)) && (\n <div\n className={classes(\n 'leaf-modal__header',\n description == null && 'leaf-modal__header--simple',\n icon != null && 'leaf-modal__header--icon',\n !hasHeading && 'leaf-modal__header--compact',\n )}\n >\n {icon != null && (\n <span className=\"leaf-modal__icon\" aria-hidden=\"true\">\n {icon}\n </span>\n )}\n {(title != null || description != null) && (\n <div className=\"leaf-modal__heading\">\n {title != null && <h2 id={titleId}>{title}</h2>}\n {description != null && (\n <div id={descriptionId} className=\"leaf-modal__description\">\n {description}\n </div>\n )}\n </div>\n )}\n {closeButton}\n </div>\n )}\n {hasTabs && tabs && RenderTabsLayout ? (\n <RenderTabsLayout\n open={open}\n tabs={tabs}\n title={title}\n titleId={titleId}\n hasHeading={hasHeading}\n closeButton={!hasHeading ? closeButton : null}\n contentRef={content}\n snapHeight={snapHeight}\n ariaLabel={props['aria-label']}\n ariaLabelledBy={props['aria-labelledby']}\n scrollbarLabel={scrollbarLabel}\n scrollbarLabelledBy={scrollbarLabelledBy}\n error={error}\n >\n {children}\n </RenderTabsLayout>\n ) : (\n ((children != null && children !== false) || error != null) && (\n <Scrollbar\n className=\"leaf-modal__body\"\n viewportClassName=\"leaf-modal__viewport\"\n orientation=\"vertical\"\n aria-labelledby={scrollbarLabelledBy}\n aria-label={scrollbarLabel}\n >\n <div ref={content} className=\"leaf-modal__content\">\n {children}\n {error && (\n <p role=\"alert\" className=\"leaf-confirm-error\">\n {error}\n </p>\n )}\n </div>\n </Scrollbar>\n )\n )}\n {renderedFooter != null && <div className=\"leaf-modal__footer\">{renderedFooter}</div>}\n </OverlayOwner.Provider>\n </div>\n </div>\n );\n}\n\n// 内部复用的对话框基础容器,避免 Confirm / FileList 继承公开 Modal 默认配置或引入 Tabs。\nexport function ModalBase(props: ModalBaseProps) {\n return (\n <ScopedPortal container={props.container}>\n <ModalSurface {...props} />\n </ScopedPortal>\n );\n}\n"],"names":["ModalSurface","open","title","description","icon","divided","tabs","footer","confirmText","cancelText","confirmLoading","confirmButtonProps","cancelButtonProps","onConfirm","onCancel","width","closable","maskClosable","keyboard","onClose","afterClose","forceRender","destroyOnClose","preserve","initialFocus","returnFocus","_container","RenderTabsLayout","children","className","style","props","messages","maskBlur","useLeafConfig","pending","setPending","useState","error","setError","mounted","useRef","accepting","generation","useEffect","undefined","busy","accept","request","reason","Error","String","cancel","actions","ButtonControl","event","renderedFooter","panel","content","backdrop","present","usePresence","snapHeight","useNaturalHeightTransition","titleId","useId","descriptionId","modalId","close","wasPresent","useDialog","visited","hasTabs","Boolean","hasHeading","closeButton","X","scrollbarLabel","scrollbarLabelledBy","inertProps","classes","OverlayOwner","Scrollbar","ModalBase","ScopedPortal"],"mappings":";;;;;;;;;;;;;;;AA0CA,SAASA,aAAa,EACpBC,IAAI,EACJC,KAAK,EACLC,WAAW,EACXC,IAAI,EACJC,UAAU,IAAI,EACdC,IAAI,EACJC,MAAM,EACNC,WAAW,EACXC,UAAU,EACVC,iBAAiB,KAAK,EACtBC,kBAAkB,EAClBC,iBAAiB,EACjBC,SAAS,EACTC,QAAQ,EACRC,QAAQ,GAAG,EACXC,WAAW,IAAI,EACfC,eAAe,IAAI,EACnBC,WAAW,IAAI,EACfC,OAAO,EACPC,UAAU,EACVC,cAAc,KAAK,EACnBC,iBAAiB,KAAK,EACtBC,QAAQ,EACRC,YAAY,EACZC,WAAW,EACX,WAAWC,UAAU,EACrB,kBAAkBC,gBAAgB,EAClCC,QAAQ,EACRC,SAAS,EACTC,KAAK,EACL,GAAGC,OACY;IACf,MAAM,EAAEC,QAAQ,EAAEC,QAAQ,EAAE,GAAGC;IAC/B,MAAM,CAACC,SAASC,WAAW,GAAGC,SAAS;IACvC,MAAM,CAACC,OAAOC,SAAS,GAAGF;IAC1B,MAAMG,UAAUC,OAAO;IACvB,MAAMC,YAAYD,OAAO;IACzB,MAAME,aAAaF,OAAO;IAC1BG,UAAU;QACRJ,QAAQ,OAAO,GAAG;QAClB,OAAO;YACLA,QAAQ,OAAO,GAAG;QACpB;IACF,GAAG,EAAE;IACLI,UAAU;QACRD,WAAW,OAAO;QAClBD,UAAU,OAAO,GAAG;QACpBN,WAAW;QACX,IAAInC,MAAMsC,SAASM;IACrB,GAAG;QAAC5C;KAAK;IACT,MAAM6C,OAAOX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,WAAkB,mBACnC,KAAC;oCAAI,WAAU;;wCACH,QAATD,SAAiB,WAAR,GAAQ,IAAC;4CAAG,IAAI8D;sDAAU9D;;wCACpB,QAAfC,eAAuB,WAAR,GACd,IAAC;4CAAI,IAAI+D;4CAAe,WAAU;sDAC/B/D;;;;gCAKRwE;;;wBAGJH,WAAWlE,QAAQqB,mBAAmB,WAAnBA,GAClB,IAACA,kBAAAA;4BACC,MAAM1B;4BACN,MAAMK;4BACN,OAAOJ;4BACP,SAAS8D;4BACT,YAAYU;4BACZ,aAAa,AAACA,aAA2B,OAAdC;4BAC3B,YAAYjB;4BACZ,YAAYI;4BACZ,WAAW/B,KAAK,CAAC,aAAa;4BAC9B,gBAAgBA,KAAK,CAAC,kBAAkB;4BACxC,gBAAgB8C;4BAChB,qBAAqBC;4BACrB,OAAOxC;sCAENV;6BAGF,AAACA,CAAAA,AAAY,QAAZA,YAAoBA,AAAa,UAAbA,YAAuBU,AAAS,QAATA,KAAY,mBACvD,IAAC4C,kBAASA;4BACR,WAAU;4BACV,mBAAkB;4BAClB,aAAY;4BACZ,mBAAiBJ;4BACjB,cAAYD;sCAEZ,mBAAC;gCAAI,KAAKnB;gCAAS,WAAU;;oCAC1B9B;oCACAU,SAAS,WAATA,GACC,IAAC;wCAAE,MAAK;wCAAQ,WAAU;kDACvBA;;;;;wBAOM,QAAlBkB,kBAA0B,WAAR,GAAQ,IAAC;4BAAI,WAAU;sCAAsBA;;;;;;;AAK1E;AAGO,SAAS2B,UAAUpD,KAAqB;IAC7C,OAAO,WAAP,GACE,IAACqD,cAAYA;QAAC,WAAWrD,MAAM,SAAS;kBACtC,kBAAC/B,cAAYA;YAAE,GAAG+B,KAAK;;;AAG7B"}
|
|
1
|
+
{"version":3,"file":"modal/base.js","sources":["../../../../../src/modal/base.tsx"],"sourcesContent":["import { X } from 'lucide-react';\nimport {\n type ComponentType,\n type ReactNode,\n type Ref,\n useEffect,\n useId,\n useRef,\n useState,\n} from 'react';\nimport { ButtonControl } from '../button/button';\nimport { useLeafConfig } from '../config-provider/context';\nimport { ScrollbarControl as Scrollbar } from '../scrollbar/scrollbar';\nimport { classes } from '../shared/classes';\nimport { useDialog, useOverlayLayer } from '../shared/dialog';\nimport { inertProps } from '../shared/inert';\nimport { OverlayOwner } from '../shared/overlay-owner';\nimport { useNaturalHeightTransition, usePresence } from '../shared/presence';\nimport { ScopedPortal } from '../shared/scoped-portal';\nimport type { ModalFooterActions, ModalProps, ModalTabsProps } from './modal';\n\nexport interface ModalTabsRenderProps {\n open: boolean;\n tabs: ModalTabsProps;\n title?: ReactNode;\n titleId: string;\n hasHeading: boolean;\n closeButton: ReactNode;\n contentRef: Ref<HTMLDivElement>;\n snapHeight: () => void;\n ariaLabel?: string;\n ariaLabelledBy?: string;\n scrollbarLabel?: string;\n scrollbarLabelledBy?: string;\n error?: string;\n children?: ReactNode;\n}\n\nexport interface ModalBaseProps extends ModalProps {\n renderTabsLayout?: ComponentType<ModalTabsRenderProps>;\n}\n\nfunction ModalSurface({\n open,\n title,\n description,\n icon,\n divided = true,\n tabs,\n footer,\n confirmText,\n cancelText,\n confirmLoading = false,\n confirmButtonProps,\n cancelButtonProps,\n onConfirm,\n onCancel,\n width = 480,\n closable = true,\n maskClosable = true,\n keyboard = true,\n onClose,\n afterClose,\n forceRender = false,\n destroyOnClose = false,\n preserve,\n initialFocus,\n returnFocus,\n container: _container,\n renderTabsLayout: RenderTabsLayout,\n children,\n className,\n style,\n ...props\n}: ModalBaseProps) {\n const { messages, maskBlur } = useLeafConfig();\n const [pending, setPending] = useState(false);\n const [error, setError] = useState<string>();\n const mounted = useRef(true);\n const accepting = useRef(false);\n const generation = useRef(0);\n useEffect(() => {\n mounted.current = true;\n return () => {\n mounted.current = false;\n };\n }, []);\n useEffect(() => {\n generation.current++;\n accepting.current = false;\n setPending(false);\n if (open) setError(undefined);\n }, [open]);\n const busy = pending || confirmLoading;\n async function accept() {\n if (accepting.current || busy) return;\n if (!onConfirm) {\n if (confirmButtonProps?.type !== 'submit') onClose?.();\n return;\n }\n accepting.current = true;\n const request = generation.current;\n setPending(true);\n setError(undefined);\n try {\n await onConfirm();\n } catch (reason) {\n if (mounted.current && generation.current === request)\n setError(reason instanceof Error ? reason.message : String(reason));\n } finally {\n if (generation.current === request) {\n accepting.current = false;\n if (mounted.current) setPending(false);\n }\n }\n }\n const cancel = () => {\n if (!busy) (onCancel ?? onClose)?.();\n };\n const actions: ModalFooterActions = {\n cancelButton: (\n <ButtonControl\n type=\"button\"\n variant=\"outline\"\n {...cancelButtonProps}\n disabled={busy || cancelButtonProps?.disabled}\n onClick={(event) => {\n cancelButtonProps?.onClick?.(event);\n if (!event.defaultPrevented) cancel();\n }}\n >\n {cancelText ?? messages.common.cancel}\n </ButtonControl>\n ),\n confirmButton: (\n <ButtonControl\n type=\"button\"\n variant=\"solid\"\n {...confirmButtonProps}\n loading={busy || confirmButtonProps?.loading}\n onClick={(event) => {\n confirmButtonProps?.onClick?.(event);\n if (!event.defaultPrevented) void accept();\n }}\n >\n {confirmText ?? messages.common.confirm}\n </ButtonControl>\n ),\n };\n const renderedFooter =\n typeof footer === 'function' ? (\n footer(actions)\n ) : footer === undefined ? (\n <div className=\"leaf-modal__actions\">\n {actions.cancelButton}\n {actions.confirmButton}\n </div>\n ) : (\n footer\n );\n const panel = useRef<HTMLDivElement>(null);\n const content = useRef<HTMLDivElement>(null);\n const backdrop = useRef<HTMLButtonElement>(null);\n const present = usePresence(open, backdrop);\n const layer = useOverlayLayer(present, open);\n const snapHeight = useNaturalHeightTransition(panel, content, open);\n const titleId = `${useId()}-title`;\n const descriptionId = `${useId()}-description`;\n const modalId = `${useId()}-dialog`;\n const close = useRef(cancel);\n close.current = cancel;\n const wasPresent = useRef(false);\n useEffect(() => {\n if (wasPresent.current && !present) afterClose?.();\n wasPresent.current = present;\n }, [present, afterClose]);\n useDialog(open, panel, modalId, cancel, keyboard, { initialFocus, returnFocus });\n const visited = useRef(false);\n if (open) visited.current = true;\n if (\n !present &&\n !forceRender &&\n ((preserve === undefined ? destroyOnClose : !preserve) || !visited.current)\n )\n return null;\n\n const hasTabs = Boolean(tabs?.items?.length);\n const hasHeading = title != null || description != null || icon != null;\n const closeButton = closable ? (\n <button\n type=\"button\"\n className=\"leaf-modal__close\"\n aria-label={messages.common.close}\n onClick={() => close.current?.()}\n >\n <X size={18} aria-hidden=\"true\" />\n </button>\n ) : null;\n const scrollbarLabel =\n title == null\n ? (props['aria-label'] ?? tabs?.['aria-label'] ?? messages.common.confirm)\n : undefined;\n const scrollbarLabelledBy = title != null ? titleId : undefined;\n\n return (\n <div\n hidden={!present}\n className=\"leaf-modal-mask\"\n style={layer.maskStyle}\n data-blur={maskBlur ? undefined : 'off'}\n data-state={open ? 'open' : 'closing'}\n aria-hidden={!open || undefined}\n {...inertProps(!open)}\n >\n <button\n ref={backdrop}\n type=\"button\"\n className=\"leaf-modal-backdrop\"\n tabIndex={-1}\n aria-label={messages.common.close}\n onClick={() => {\n if (maskClosable) close.current?.();\n }}\n />\n {/* biome-ignore lint/a11y/useAriaPropsSupportedByRole: dialog and alertdialog both support aria-modal. */}\n <div\n {...props}\n ref={panel}\n id={props.id ?? modalId}\n role={props.role ?? 'dialog'}\n aria-modal=\"true\"\n aria-labelledby={title != null ? titleId : props['aria-labelledby']}\n aria-describedby={\n [props['aria-describedby'], description != null && descriptionId]\n .filter(Boolean)\n .join(' ') || undefined\n }\n tabIndex={-1}\n className={classes(\n 'leaf-modal',\n divided && 'leaf-modal--divided',\n hasTabs && 'leaf-modal--tabbed',\n hasHeading && 'leaf-modal--headed',\n className,\n )}\n style={{ width, ...layer.popupStyle, ...style }}\n >\n <OverlayOwner.Provider value={modalId}>\n {(hasHeading || (!hasTabs && closable)) && (\n <div\n className={classes(\n 'leaf-modal__header',\n description == null && 'leaf-modal__header--simple',\n icon != null && 'leaf-modal__header--icon',\n !hasHeading && 'leaf-modal__header--compact',\n )}\n >\n {icon != null && (\n <span className=\"leaf-modal__icon\" aria-hidden=\"true\">\n {icon}\n </span>\n )}\n {(title != null || description != null) && (\n <div className=\"leaf-modal__heading\">\n {title != null && <h2 id={titleId}>{title}</h2>}\n {description != null && (\n <div id={descriptionId} className=\"leaf-modal__description\">\n {description}\n </div>\n )}\n </div>\n )}\n {closeButton}\n </div>\n )}\n {hasTabs && tabs && RenderTabsLayout ? (\n <RenderTabsLayout\n open={open}\n tabs={tabs}\n title={title}\n titleId={titleId}\n hasHeading={hasHeading}\n closeButton={!hasHeading ? closeButton : null}\n contentRef={content}\n snapHeight={snapHeight}\n ariaLabel={props['aria-label']}\n ariaLabelledBy={props['aria-labelledby']}\n scrollbarLabel={scrollbarLabel}\n scrollbarLabelledBy={scrollbarLabelledBy}\n error={error}\n >\n {children}\n </RenderTabsLayout>\n ) : (\n ((children != null && children !== false) || error != null) && (\n <Scrollbar\n className=\"leaf-modal__body\"\n viewportClassName=\"leaf-modal__viewport\"\n orientation=\"vertical\"\n aria-labelledby={scrollbarLabelledBy}\n aria-label={scrollbarLabel}\n >\n <div ref={content} className=\"leaf-modal__content\">\n {children}\n {error && (\n <p role=\"alert\" className=\"leaf-confirm-error\">\n {error}\n </p>\n )}\n </div>\n </Scrollbar>\n )\n )}\n {renderedFooter != null && <div className=\"leaf-modal__footer\">{renderedFooter}</div>}\n </OverlayOwner.Provider>\n </div>\n </div>\n );\n}\n\n// 内部复用的对话框基础容器,避免 Confirm / FileList 继承公开 Modal 默认配置或引入 Tabs。\nexport function ModalBase(props: ModalBaseProps) {\n const visited = useRef(false);\n // 首次打开或显式 forceRender 前保留行内锚点并延迟挂载 ScopedPortal,避免提前在 body 占位。\n if (props.open || props.forceRender) visited.current = true;\n if (!visited.current) return <span hidden />;\n return (\n <ScopedPortal container={props.container}>\n <ModalSurface {...props} />\n </ScopedPortal>\n );\n}\n"],"names":["ModalSurface","open","title","description","icon","divided","tabs","footer","confirmText","cancelText","confirmLoading","confirmButtonProps","cancelButtonProps","onConfirm","onCancel","width","closable","maskClosable","keyboard","onClose","afterClose","forceRender","destroyOnClose","preserve","initialFocus","returnFocus","_container","RenderTabsLayout","children","className","style","props","messages","maskBlur","useLeafConfig","pending","setPending","useState","error","setError","mounted","useRef","accepting","generation","useEffect","undefined","busy","accept","request","reason","Error","String","cancel","actions","ButtonControl","event","renderedFooter","panel","content","backdrop","present","usePresence","layer","useOverlayLayer","snapHeight","useNaturalHeightTransition","titleId","useId","descriptionId","modalId","close","wasPresent","useDialog","visited","hasTabs","Boolean","hasHeading","closeButton","X","scrollbarLabel","scrollbarLabelledBy","inertProps","classes","OverlayOwner","Scrollbar","ModalBase","ScopedPortal"],"mappings":";;;;;;;;;;;;;;;AA0CA,SAASA,aAAa,EACpBC,IAAI,EACJC,KAAK,EACLC,WAAW,EACXC,IAAI,EACJC,UAAU,IAAI,EACdC,IAAI,EACJC,MAAM,EACNC,WAAW,EACXC,UAAU,EACVC,iBAAiB,KAAK,EACtBC,kBAAkB,EAClBC,iBAAiB,EACjBC,SAAS,EACTC,QAAQ,EACRC,QAAQ,GAAG,EACXC,WAAW,IAAI,EACfC,eAAe,IAAI,EACnBC,WAAW,IAAI,EACfC,OAAO,EACPC,UAAU,EACVC,cAAc,KAAK,EACnBC,iBAAiB,KAAK,EACtBC,QAAQ,EACRC,YAAY,EACZC,WAAW,EACX,WAAWC,UAAU,EACrB,kBAAkBC,gBAAgB,EAClCC,QAAQ,EACRC,SAAS,EACTC,KAAK,EACL,GAAGC,OACY;IACf,MAAM,EAAEC,QAAQ,EAAEC,QAAQ,EAAE,GAAGC;IAC/B,MAAM,CAACC,SAASC,WAAW,GAAGC,SAAS;IACvC,MAAM,CAACC,OAAOC,SAAS,GAAGF;IAC1B,MAAMG,UAAUC,OAAO;IACvB,MAAMC,YAAYD,OAAO;IACzB,MAAME,aAAaF,OAAO;IAC1BG,UAAU;QACRJ,QAAQ,OAAO,GAAG;QAClB,OAAO;YACLA,QAAQ,OAAO,GAAG;QACpB;IACF,GAAG,EAAE;IACLI,UAAU;QACRD,WAAW,OAAO;QAClBD,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GAAG;IACvD,IAAI,CAACA,QAAQ,OAAO,EAAE,OAAO,WAAP,GAAO,IAAC;QAAK,QAAM;;IACzC,OAAO,WAAP,GACE,IAACa,cAAYA;QAAC,WAAWvD,MAAM,SAAS;kBACtC,kBAAC/B,cAAYA;YAAE,GAAG+B,KAAK;;;AAG7B"}
|
|
@@ -6,13 +6,15 @@ import { tabbable } from "tabbable";
|
|
|
6
6
|
import { useComponentProps } from "../config-provider/component-defaults.js";
|
|
7
7
|
import { classes } from "../shared/classes.js";
|
|
8
8
|
import { useMergedRef } from "../shared/field.js";
|
|
9
|
-
import { FloatingPanel,
|
|
9
|
+
import { FloatingPanel, useHoverFocus } from "../shared/floating.js";
|
|
10
10
|
import { useNaturalHeightTransition } from "../shared/presence.js";
|
|
11
11
|
import '../../../styles/components/popover.css';
|
|
12
12
|
function PopoverControl({ children, title, content, trigger: mode = 'click', placement = 'top', open: controlled, defaultOpen = false, onOpenChange, disabled = false, autoFocus = true, enterDelay = 100, leaveDelay = 100, width = 'max-content', maxWidth = 320, className, popupPlacement, popupClassName, popupStyle, popupRender, getPopupContainer, style, 'aria-label': label }) {
|
|
13
13
|
const [internal, setInternal] = useState(defaultOpen);
|
|
14
|
-
const inactive = disabled || children.props.disabled;
|
|
14
|
+
const inactive = Boolean(disabled || children.props.disabled);
|
|
15
15
|
const open = !inactive && (controlled ?? internal);
|
|
16
|
+
const openRef = useRef(open);
|
|
17
|
+
openRef.current = open;
|
|
16
18
|
const trigger = useRef(null);
|
|
17
19
|
const panel = useRef(null);
|
|
18
20
|
const body = useRef(null);
|
|
@@ -20,28 +22,28 @@ function PopoverControl({ children, title, content, trigger: mode = 'click', pla
|
|
|
20
22
|
const childRef = version.startsWith('18.') ? children.ref : children.props.ref;
|
|
21
23
|
const ref = useMergedRef(trigger, childRef);
|
|
22
24
|
const id = `${useId()}-popover`;
|
|
23
|
-
const timer = useRef(void 0);
|
|
24
|
-
const focused = useRef(false);
|
|
25
|
-
const hovered = useRef(false);
|
|
26
25
|
const change = (next)=>{
|
|
27
|
-
if (
|
|
28
|
-
if (next
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const schedule = (next, delay)=>{
|
|
35
|
-
clearTimeout(timer.current);
|
|
36
|
-
timer.current = setTimeout(()=>change(next), Math.max(0, delay));
|
|
26
|
+
if (inactive && next) return;
|
|
27
|
+
if (next === openRef.current) return;
|
|
28
|
+
if (void 0 === controlled) {
|
|
29
|
+
openRef.current = next;
|
|
30
|
+
setInternal(next);
|
|
31
|
+
}
|
|
32
|
+
onOpenChange?.(next);
|
|
37
33
|
};
|
|
38
|
-
|
|
39
|
-
|
|
34
|
+
const hoverFocus = useHoverFocus({
|
|
35
|
+
enabled: 'hover' === mode,
|
|
36
|
+
inactive,
|
|
37
|
+
open,
|
|
38
|
+
change,
|
|
39
|
+
enterDelay,
|
|
40
|
+
leaveDelay,
|
|
41
|
+
triggerRef: trigger,
|
|
42
|
+
panelRef: panel,
|
|
43
|
+
keepPanelFocus: true
|
|
44
|
+
});
|
|
40
45
|
useEffect(()=>{
|
|
41
|
-
if (inactive)
|
|
42
|
-
clearTimeout(timer.current);
|
|
43
|
-
setInternal(false);
|
|
44
|
-
}
|
|
46
|
+
if (inactive) setInternal(false);
|
|
45
47
|
}, [
|
|
46
48
|
inactive
|
|
47
49
|
]);
|
|
@@ -81,28 +83,23 @@ function PopoverControl({ children, title, content, trigger: mode = 'click', pla
|
|
|
81
83
|
},
|
|
82
84
|
onPointerEnter: (event)=>{
|
|
83
85
|
children.props.onPointerEnter?.(event);
|
|
84
|
-
|
|
85
|
-
hovered.current = true;
|
|
86
|
-
schedule(true, enterDelay);
|
|
87
|
-
}
|
|
86
|
+
hoverFocus.onTriggerPointerEnter(event);
|
|
88
87
|
},
|
|
89
88
|
onPointerLeave: (event)=>{
|
|
90
89
|
children.props.onPointerLeave?.(event);
|
|
91
|
-
|
|
92
|
-
|
|
90
|
+
hoverFocus.onTriggerPointerLeave();
|
|
91
|
+
},
|
|
92
|
+
onPointerDown: (event)=>{
|
|
93
|
+
children.props.onPointerDown?.(event);
|
|
94
|
+
hoverFocus.onTriggerPointerDown(event);
|
|
93
95
|
},
|
|
94
96
|
onFocus: (event)=>{
|
|
95
97
|
children.props.onFocus?.(event);
|
|
96
|
-
|
|
97
|
-
focused.current = true;
|
|
98
|
-
clearTimeout(timer.current);
|
|
99
|
-
change(true);
|
|
100
|
-
}
|
|
98
|
+
hoverFocus.onTriggerFocus(event);
|
|
101
99
|
},
|
|
102
100
|
onBlur: (event)=>{
|
|
103
101
|
children.props.onBlur?.(event);
|
|
104
|
-
|
|
105
|
-
if ('hover' === mode && !hovered.current && !panel.current?.contains(event.relatedTarget)) schedule(false, leaveDelay);
|
|
102
|
+
hoverFocus.onTriggerBlur(event);
|
|
106
103
|
}
|
|
107
104
|
}),
|
|
108
105
|
/*#__PURE__*/ jsxs(FloatingPanel, {
|
|
@@ -125,14 +122,8 @@ function PopoverControl({ children, title, content, trigger: mode = 'click', pla
|
|
|
125
122
|
},
|
|
126
123
|
"aria-label": label ?? ('string' == typeof title ? title : void 0),
|
|
127
124
|
"aria-labelledby": null != title ? `${id}-title` : void 0,
|
|
128
|
-
onPointerEnter:
|
|
129
|
-
|
|
130
|
-
clearTimeout(timer.current);
|
|
131
|
-
},
|
|
132
|
-
onPointerLeave: ()=>{
|
|
133
|
-
hovered.current = false;
|
|
134
|
-
if ('hover' === mode && !focused.current && !panel.current?.contains(document.activeElement)) schedule(false, leaveDelay);
|
|
135
|
-
},
|
|
125
|
+
onPointerEnter: hoverFocus.onPanelPointerEnter,
|
|
126
|
+
onPointerLeave: hoverFocus.onPanelPointerLeave,
|
|
136
127
|
children: [
|
|
137
128
|
null != title && /*#__PURE__*/ jsx("div", {
|
|
138
129
|
id: `${id}-title`,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"popover/popover.js","sources":["../../../../../src/popover/popover.tsx"],"sourcesContent":["import {\n type CSSProperties,\n cloneElement,\n type HTMLAttributes,\n type ReactElement,\n type ReactNode,\n type Ref,\n useEffect,\n useId,\n useRef,\n useState,\n version,\n} from 'react';\nimport { tabbable } from 'tabbable';\nimport { useComponentProps } from '../config-provider/component-defaults';\nimport { classes } from '../shared/classes';\nimport { useMergedRef } from '../shared/field';\nimport { FloatingPanel, type PopupOptions, useFloatingDismiss } from '../shared/floating';\nimport { useNaturalHeightTransition } from '../shared/presence';\n\nexport interface PopoverProps extends PopupOptions {\n children: ReactElement<\n HTMLAttributes<HTMLElement> & { ref?: Ref<HTMLElement>; disabled?: boolean }\n >;\n title?: ReactNode;\n content: ReactNode;\n trigger?: 'click' | 'hover';\n placement?:\n | 'top'\n | 'top-start'\n | 'top-end'\n | 'bottom'\n | 'bottom-start'\n | 'bottom-end'\n | 'left'\n | 'left-start'\n | 'left-end'\n | 'right'\n | 'right-start'\n | 'right-end';\n open?: boolean;\n defaultOpen?: boolean;\n onOpenChange?: (open: boolean) => void;\n disabled?: boolean;\n autoFocus?: boolean;\n enterDelay?: number;\n leaveDelay?: number;\n width?: number | string;\n maxWidth?: number | string;\n className?: string;\n style?: CSSProperties;\n 'aria-label'?: string;\n}\nexport function PopoverControl({\n children,\n title,\n content,\n trigger: mode = 'click',\n placement = 'top',\n open: controlled,\n defaultOpen = false,\n onOpenChange,\n disabled = false,\n autoFocus = true,\n enterDelay = 100,\n leaveDelay = 100,\n width = 'max-content',\n maxWidth = 320,\n className,\n popupPlacement,\n popupClassName,\n popupStyle,\n popupRender,\n getPopupContainer,\n style,\n 'aria-label': label,\n}: PopoverProps) {\n const [internal, setInternal] = useState(defaultOpen);\n const inactive = disabled || children.props.disabled;\n const open = !inactive && (controlled ?? internal);\n const trigger = useRef<HTMLElement>(null);\n const panel = useRef<HTMLDivElement>(null);\n const body = useRef<HTMLDivElement>(null);\n useNaturalHeightTransition(panel, body, open);\n const childRef = version.startsWith('18.')\n ? (children as typeof children & { ref?: Ref<HTMLElement> }).ref\n : children.props.ref;\n const ref = useMergedRef(trigger, childRef);\n const id = `${useId()}-popover`;\n const timer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);\n const focused = useRef(false);\n const hovered = useRef(false);\n const change = (next: boolean) => {\n if (controlled === undefined) setInternal(next);\n if (next !== open) onOpenChange?.(next);\n };\n const dismiss = () => {\n clearTimeout(timer.current);\n change(false);\n };\n const schedule = (next: boolean, delay: number) => {\n clearTimeout(timer.current);\n timer.current = setTimeout(() => change(next), Math.max(0, delay));\n };\n useFloatingDismiss(open, dismiss, trigger, panel);\n useEffect(() => () => clearTimeout(timer.current), []);\n useEffect(() => {\n if (inactive) {\n clearTimeout(timer.current);\n setInternal(false);\n }\n }, [inactive]);\n useEffect(() => {\n const node = panel.current;\n if (!open || mode !== 'click' || !node || !autoFocus) return;\n (tabbable(node)[0] ?? node).focus();\n return () => {\n if (node.contains(document.activeElement)) trigger.current?.focus();\n };\n }, [open, mode, autoFocus]);\n return (\n <>\n {cloneElement(children, {\n ref,\n 'aria-haspopup': mode === 'click' ? 'dialog' : children.props['aria-haspopup'],\n 'aria-expanded': mode === 'click' ? open : children.props['aria-expanded'],\n 'aria-controls': open ? id : children.props['aria-controls'],\n 'aria-describedby':\n mode === 'hover' && open\n ? [children.props['aria-describedby'], id].filter(Boolean).join(' ')\n : children.props['aria-describedby'],\n onClick: (event) => {\n children.props.onClick?.(event);\n if (mode === 'click' && !inactive && !event.defaultPrevented) change(!open);\n },\n onKeyDown: (event) => {\n children.props.onKeyDown?.(event);\n if (\n mode === 'click' &&\n !inactive &&\n !event.defaultPrevented &&\n event.key === 'ArrowDown'\n ) {\n event.preventDefault();\n change(true);\n }\n },\n onPointerEnter: (event) => {\n children.props.onPointerEnter?.(event);\n if (\n mode === 'hover' &&\n !inactive &&\n !event.defaultPrevented &&\n event.pointerType !== 'touch'\n ) {\n hovered.current = true;\n schedule(true, enterDelay);\n }\n },\n onPointerLeave: (event) => {\n children.props.onPointerLeave?.(event);\n hovered.current = false;\n if (mode === 'hover' && !focused.current) schedule(false, leaveDelay);\n },\n onFocus: (event) => {\n children.props.onFocus?.(event);\n if (mode === 'hover' && !inactive && !event.defaultPrevented) {\n focused.current = true;\n clearTimeout(timer.current);\n change(true);\n }\n },\n onBlur: (event) => {\n children.props.onBlur?.(event);\n focused.current = false;\n if (mode === 'hover' && !hovered.current && !panel.current?.contains(event.relatedTarget))\n schedule(false, leaveDelay);\n },\n })}\n <FloatingPanel\n open={open}\n render={popupRender}\n container={getPopupContainer}\n triggerRef={trigger}\n panelRef={panel}\n id={id}\n role={mode === 'click' ? 'dialog' : 'tooltip'}\n tabIndex={-1}\n data-arrow=\"true\"\n placement={popupPlacement ?? placement}\n width={width}\n maxWidth={maxWidth}\n className={classes('leaf-floating', 'leaf-popover', className, popupClassName)}\n style={{ ...style, ...popupStyle }}\n aria-label={label ?? (typeof title === 'string' ? title : undefined)}\n aria-labelledby={title != null ? `${id}-title` : undefined}\n onPointerEnter={() => {\n hovered.current = true;\n clearTimeout(timer.current);\n }}\n onPointerLeave={() => {\n hovered.current = false;\n if (\n mode === 'hover' &&\n !focused.current &&\n !panel.current?.contains(document.activeElement)\n )\n schedule(false, leaveDelay);\n }}\n >\n {title != null && (\n <div id={`${id}-title`} className=\"leaf-popover__title\">\n {title}\n </div>\n )}\n <div ref={body} className=\"leaf-popover__content\">\n {content}\n </div>\n </FloatingPanel>\n </>\n );\n}\n\nexport function Popover(rawProps: PopoverProps) {\n const props = useComponentProps('Popover', rawProps);\n return <PopoverControl {...props} />;\n}\n"],"names":["PopoverControl","children","title","content","mode","placement","controlled","defaultOpen","onOpenChange","disabled","autoFocus","enterDelay","leaveDelay","width","maxWidth","className","popupPlacement","popupClassName","popupStyle","popupRender","getPopupContainer","style","label","internal","setInternal","useState","inactive","open","trigger","useRef","panel","body","useNaturalHeightTransition","childRef","version","ref","useMergedRef","id","useId","timer","undefined","focused","hovered","change","next","dismiss","clearTimeout","schedule","delay","setTimeout","Math","useFloatingDismiss","useEffect","node","tabbable","document","cloneElement","Boolean","event","FloatingPanel","classes","Popover","rawProps","props","useComponentProps"],"mappings":";;;;;;;;;;;AAqDO,SAASA,eAAe,EAC7BC,QAAQ,EACRC,KAAK,EACLC,OAAO,EACP,SAASC,OAAO,OAAO,EACvBC,YAAY,KAAK,EACjB,MAAMC,UAAU,EAChBC,cAAc,KAAK,EACnBC,YAAY,EACZC,WAAW,KAAK,EAChBC,YAAY,IAAI,EAChBC,aAAa,GAAG,EAChBC,aAAa,GAAG,EAChBC,QAAQ,aAAa,EACrBC,WAAW,GAAG,EACdC,SAAS,EACTC,cAAc,EACdC,cAAc,EACdC,UAAU,EACVC,WAAW,EACXC,iBAAiB,EACjBC,KAAK,EACL,cAAcC,KAAK,EACN;IACb,MAAM,CAACC,UAAUC,YAAY,GAAGC,SAASlB;IACzC,MAAMmB,WAAWjB,YAAYR,SAAS,KAAK,CAAC,QAAQ;IACpD,MAAM0B,OAAO,CAACD,YAAapB,CAAAA,cAAciB,QAAO;IAChD,MAAMK,UAAUC,OAAoB;IACpC,MAAMC,QAAQD,OAAuB;IACrC,MAAME,OAAOF,OAAuB;IACpCG,2BAA2BF,OAAOC,MAAMJ;IACxC,MAAMM,WAAWC,QAAQ,UAAU,CAAC,SAC/BjC,SAA0D,GAAG,GAC9DA,SAAS,KAAK,CAAC,GAAG;IACtB,MAAMkC,MAAMC,aAAaR,SAASK;IAClC,MAAMI,KAAK,GAAGC,QAAQ,QAAQ,CAAC;IAC/B,MAAMC,QAAQV,OAAkDW;IAChE,MAAMC,UAAUZ,OAAO;IACvB,MAAMa,UAAUb,OAAO;IACvB,MAAMc,SAAS,CAACC;QACd,IAAItC,AAAekC,WAAflC,YAA0BkB,YAAYoB;QAC1C,IAAIA,SAASjB,MAAMnB,eAAeoC;IACpC;IACA,MAAMC,UAAU;QACdC,aAAaP,MAAM,OAAO;QAC1BI,OAAO;IACT;IACA,MAAMI,WAAW,CAACH,MAAeI;QAC/BF,aAAaP,MAAM,OAAO;QAC1BA,MAAM,O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,UAAUC;gBACV,WAAW8C,QAAQ,iBAAiB,gBAAgB7C,WAAWE;gBAC/D,OAAO;oBAAE,GAAGI,KAAK;oBAAE,GAAGH,UAAU;gBAAC;gBACjC,cAAYI,SAAU,CAAiB,YAAjB,OAAOpB,QAAqBA,QAAQsC,MAAQ;gBAClE,mBAAiBtC,AAAS,QAATA,QAAgB,GAAGmC,GAAG,MAAM,CAAC,GAAGG;gBACjD,gBAAgB;oBACdE,QAAQ,OAAO,GAAG;oBAClBI,aAAaP,MAAM,OAAO;gBAC5B;gBACA,gBAAgB;oBACdG,QAAQ,OAAO,GAAG;oBAClB,IACEtC,AAAS,YAATA,QACA,CAACqC,QAAQ,OAAO,IAChB,CAACX,MAAM,OAAO,EAAE,SAASyB,SAAS,aAAa,GAE/CR,SAAS,OAAOnC;gBACpB;;oBAEU,QAATV,SAAiB,WAAR,GACR,IAAC;wBAAI,IAAI,GAAGmC,GAAG,MAAM,CAAC;wBAAE,WAAU;kCAC/BnC;;kCAGL,IAAC;wBAAI,KAAK6B;wBAAM,WAAU;kCACvB5B;;;;;;AAKX;AAEO,SAAS0D,QAAQC,QAAsB;IAC5C,MAAMC,QAAQC,kBAAkB,WAAWF;IAC3C,OAAO,WAAP,GAAO,IAAC9D,gBAAcA;QAAE,GAAG+D,KAAK;;AAClC"}
|
|
1
|
+
{"version":3,"file":"popover/popover.js","sources":["../../../../../src/popover/popover.tsx"],"sourcesContent":["import {\n type CSSProperties,\n cloneElement,\n type HTMLAttributes,\n type ReactElement,\n type ReactNode,\n type Ref,\n useEffect,\n useId,\n useRef,\n useState,\n version,\n} from 'react';\nimport { tabbable } from 'tabbable';\nimport { useComponentProps } from '../config-provider/component-defaults';\nimport { classes } from '../shared/classes';\nimport { useMergedRef } from '../shared/field';\nimport { FloatingPanel, type PopupOptions, useHoverFocus } from '../shared/floating';\nimport { useNaturalHeightTransition } from '../shared/presence';\n\nexport interface PopoverProps extends PopupOptions {\n children: ReactElement<\n HTMLAttributes<HTMLElement> & { ref?: Ref<HTMLElement>; disabled?: boolean }\n >;\n title?: ReactNode;\n content: ReactNode;\n trigger?: 'click' | 'hover';\n placement?:\n | 'top'\n | 'top-start'\n | 'top-end'\n | 'bottom'\n | 'bottom-start'\n | 'bottom-end'\n | 'left'\n | 'left-start'\n | 'left-end'\n | 'right'\n | 'right-start'\n | 'right-end';\n open?: boolean;\n defaultOpen?: boolean;\n onOpenChange?: (open: boolean) => void;\n disabled?: boolean;\n autoFocus?: boolean;\n enterDelay?: number;\n leaveDelay?: number;\n width?: number | string;\n maxWidth?: number | string;\n className?: string;\n style?: CSSProperties;\n 'aria-label'?: string;\n}\nexport function PopoverControl({\n children,\n title,\n content,\n trigger: mode = 'click',\n placement = 'top',\n open: controlled,\n defaultOpen = false,\n onOpenChange,\n disabled = false,\n autoFocus = true,\n enterDelay = 100,\n leaveDelay = 100,\n width = 'max-content',\n maxWidth = 320,\n className,\n popupPlacement,\n popupClassName,\n popupStyle,\n popupRender,\n getPopupContainer,\n style,\n 'aria-label': label,\n}: PopoverProps) {\n const [internal, setInternal] = useState(defaultOpen);\n const inactive = Boolean(disabled || children.props.disabled);\n const open = !inactive && (controlled ?? internal);\n const openRef = useRef(open);\n openRef.current = open;\n const trigger = useRef<HTMLElement>(null);\n const panel = useRef<HTMLDivElement>(null);\n const body = useRef<HTMLDivElement>(null);\n useNaturalHeightTransition(panel, body, open);\n const childRef = version.startsWith('18.')\n ? (children as typeof children & { ref?: Ref<HTMLElement> }).ref\n : children.props.ref;\n const ref = useMergedRef(trigger, childRef);\n const id = `${useId()}-popover`;\n const change = (next: boolean) => {\n if (inactive && next) return;\n if (next === openRef.current) return;\n if (controlled === undefined) {\n openRef.current = next;\n setInternal(next);\n }\n onOpenChange?.(next);\n };\n const hoverFocus = useHoverFocus({\n enabled: mode === 'hover',\n inactive,\n open,\n change,\n enterDelay,\n leaveDelay,\n triggerRef: trigger,\n panelRef: panel,\n keepPanelFocus: true,\n });\n useEffect(() => {\n if (inactive) setInternal(false);\n }, [inactive]);\n useEffect(() => {\n const node = panel.current;\n if (!open || mode !== 'click' || !node || !autoFocus) return;\n (tabbable(node)[0] ?? node).focus();\n return () => {\n if (node.contains(document.activeElement)) trigger.current?.focus();\n };\n }, [open, mode, autoFocus]);\n return (\n <>\n {cloneElement(children, {\n ref,\n 'aria-haspopup': mode === 'click' ? 'dialog' : children.props['aria-haspopup'],\n 'aria-expanded': mode === 'click' ? open : children.props['aria-expanded'],\n 'aria-controls': open ? id : children.props['aria-controls'],\n 'aria-describedby':\n mode === 'hover' && open\n ? [children.props['aria-describedby'], id].filter(Boolean).join(' ')\n : children.props['aria-describedby'],\n onClick: (event) => {\n children.props.onClick?.(event);\n if (mode === 'click' && !inactive && !event.defaultPrevented) change(!open);\n },\n onKeyDown: (event) => {\n children.props.onKeyDown?.(event);\n if (\n mode === 'click' &&\n !inactive &&\n !event.defaultPrevented &&\n event.key === 'ArrowDown'\n ) {\n event.preventDefault();\n change(true);\n }\n },\n onPointerEnter: (event) => {\n children.props.onPointerEnter?.(event);\n hoverFocus.onTriggerPointerEnter(event);\n },\n onPointerLeave: (event) => {\n children.props.onPointerLeave?.(event);\n hoverFocus.onTriggerPointerLeave();\n },\n onPointerDown: (event) => {\n children.props.onPointerDown?.(event);\n hoverFocus.onTriggerPointerDown(event);\n },\n onFocus: (event) => {\n children.props.onFocus?.(event);\n hoverFocus.onTriggerFocus(event);\n },\n onBlur: (event) => {\n children.props.onBlur?.(event);\n hoverFocus.onTriggerBlur(event);\n },\n })}\n <FloatingPanel\n open={open}\n render={popupRender}\n container={getPopupContainer}\n triggerRef={trigger}\n panelRef={panel}\n id={id}\n role={mode === 'click' ? 'dialog' : 'tooltip'}\n tabIndex={-1}\n data-arrow=\"true\"\n placement={popupPlacement ?? placement}\n width={width}\n maxWidth={maxWidth}\n className={classes('leaf-floating', 'leaf-popover', className, popupClassName)}\n style={{ ...style, ...popupStyle }}\n aria-label={label ?? (typeof title === 'string' ? title : undefined)}\n aria-labelledby={title != null ? `${id}-title` : undefined}\n onPointerEnter={hoverFocus.onPanelPointerEnter}\n onPointerLeave={hoverFocus.onPanelPointerLeave}\n >\n {title != null && (\n <div id={`${id}-title`} className=\"leaf-popover__title\">\n {title}\n </div>\n )}\n <div ref={body} className=\"leaf-popover__content\">\n {content}\n </div>\n </FloatingPanel>\n </>\n );\n}\n\nexport function Popover(rawProps: PopoverProps) {\n const props = useComponentProps('Popover', rawProps);\n return <PopoverControl {...props} />;\n}\n"],"names":["PopoverControl","children","title","content","mode","placement","controlled","defaultOpen","onOpenChange","disabled","autoFocus","enterDelay","leaveDelay","width","maxWidth","className","popupPlacement","popupClassName","popupStyle","popupRender","getPopupContainer","style","label","internal","setInternal","useState","inactive","Boolean","open","openRef","useRef","trigger","panel","body","useNaturalHeightTransition","childRef","version","ref","useMergedRef","id","useId","change","next","undefined","hoverFocus","useHoverFocus","useEffect","node","tabbable","document","cloneElement","event","FloatingPanel","classes","Popover","rawProps","props","useComponentProps"],"mappings":";;;;;;;;;;;AAqDO,SAASA,eAAe,EAC7BC,QAAQ,EACRC,KAAK,EACLC,OAAO,EACP,SAASC,OAAO,OAAO,EACvBC,YAAY,KAAK,EACjB,MAAMC,UAAU,EAChBC,cAAc,KAAK,EACnBC,YAAY,EACZC,WAAW,KAAK,EAChBC,YAAY,IAAI,EAChBC,aAAa,GAAG,EAChBC,aAAa,GAAG,EAChBC,QAAQ,aAAa,EACrBC,WAAW,GAAG,EACdC,SAAS,EACTC,cAAc,EACdC,cAAc,EACdC,UAAU,EACVC,WAAW,EACXC,iBAAiB,EACjBC,KAAK,EACL,cAAcC,KAAK,EACN;IACb,MAAM,CAACC,UAAUC,YAAY,GAAGC,SAASlB;IACzC,MAAMmB,WAAWC,QAAQlB,YAAYR,SAAS,KAAK,CAAC,QAAQ;IAC5D,MAAM2B,OAAO,CAACF,YAAapB,CAAAA,cAAciB,QAAO;IAChD,MAAMM,UAAUC,OAAOF;IACvBC,QAAQ,OAAO,GAAGD;IAClB,MAAMG,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AAOQ;gBACP,UAAUC;gBACV,WAAWuC,QAAQ,iBAAiB,gBAAgBtC,WAAWE;gBAC/D,OAAO;oBAAE,GAAGI,KAAK;oBAAE,GAAGH,UAAU;gBAAC;gBACjC,cAAYI,SAAU,CAAiB,YAAjB,OAAOpB,QAAqBA,QAAQyC,MAAQ;gBAClE,mBAAiBzC,AAAS,QAATA,QAAgB,GAAGqC,GAAG,MAAM,CAAC,GAAGI;gBACjD,gBAAgBC,WAAW,mBAAmB;gBAC9C,gBAAgBA,WAAW,mBAAmB;;oBAEpC,QAAT1C,SAAiB,WAAR,GACR,IAAC;wBAAI,IAAI,GAAGqC,GAAG,MAAM,CAAC;wBAAE,WAAU;kCAC/BrC;;kCAGL,IAAC;wBAAI,KAAK+B;wBAAM,WAAU;kCACvB9B;;;;;;AAKX;AAEO,SAASmD,QAAQC,QAAsB;IAC5C,MAAMC,QAAQC,kBAAkB,WAAWF;IAC3C,OAAO,WAAP,GAAO,IAACvD,gBAAcA;QAAE,GAAGwD,KAAK;;AAClC"}
|
|
@@ -1,8 +1,77 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { useEffect, useRef } from "react";
|
|
2
|
+
import { useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
3
3
|
import { tabbable } from "tabbable";
|
|
4
4
|
import { composedEventTarget, deepActiveElement } from "./dom.js";
|
|
5
5
|
const stack = [];
|
|
6
|
+
const dialog_layers = [];
|
|
7
|
+
const OVERLAY_Z_STEP = 2;
|
|
8
|
+
const useBrowserLayoutEffect = "u" < typeof window ? useEffect : useLayoutEffect;
|
|
9
|
+
const overlayZIndex = (addend)=>`calc(var(--leaf-z-index-modal, 1100) + ${addend})`;
|
|
10
|
+
function releaseLayer(current) {
|
|
11
|
+
if (current) {
|
|
12
|
+
const index = dialog_layers.indexOf(current);
|
|
13
|
+
if (index >= 0) dialog_layers.splice(index, 1);
|
|
14
|
+
}
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
function useOverlayLayer(present, open = present) {
|
|
18
|
+
const [level, setLevel] = useState(null);
|
|
19
|
+
const entry = useRef(null);
|
|
20
|
+
const wasOpen = useRef(false);
|
|
21
|
+
useBrowserLayoutEffect(()=>{
|
|
22
|
+
const opened = open && !wasOpen.current;
|
|
23
|
+
wasOpen.current = open;
|
|
24
|
+
if (!present) {
|
|
25
|
+
entry.current = releaseLayer(entry.current);
|
|
26
|
+
setLevel(null);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
if (!entry.current || opened) {
|
|
30
|
+
entry.current = releaseLayer(entry.current);
|
|
31
|
+
const next = dialog_layers.length ? Math.max(...dialog_layers.map((item)=>item.level)) + 1 : 0;
|
|
32
|
+
const item = {
|
|
33
|
+
id: Symbol(),
|
|
34
|
+
level: next
|
|
35
|
+
};
|
|
36
|
+
dialog_layers.push(item);
|
|
37
|
+
entry.current = item;
|
|
38
|
+
setLevel(next);
|
|
39
|
+
}
|
|
40
|
+
}, [
|
|
41
|
+
present,
|
|
42
|
+
open
|
|
43
|
+
]);
|
|
44
|
+
useBrowserLayoutEffect(()=>()=>{
|
|
45
|
+
entry.current = releaseLayer(entry.current);
|
|
46
|
+
}, []);
|
|
47
|
+
return useMemo(()=>{
|
|
48
|
+
const offset = null !== level && level > 0 ? level * OVERLAY_Z_STEP : 0;
|
|
49
|
+
if (0 === offset) return {
|
|
50
|
+
level,
|
|
51
|
+
offset: 0,
|
|
52
|
+
maskStyle: void 0,
|
|
53
|
+
popupStyle: void 0,
|
|
54
|
+
floatingStyle: void 0
|
|
55
|
+
};
|
|
56
|
+
const popupValue = overlayZIndex(offset + 1);
|
|
57
|
+
return {
|
|
58
|
+
level,
|
|
59
|
+
offset,
|
|
60
|
+
maskStyle: {
|
|
61
|
+
zIndex: overlayZIndex(offset)
|
|
62
|
+
},
|
|
63
|
+
popupStyle: {
|
|
64
|
+
'--leaf-z-index-popup': popupValue
|
|
65
|
+
},
|
|
66
|
+
floatingStyle: {
|
|
67
|
+
zIndex: popupValue,
|
|
68
|
+
'--leaf-z-index-popup': popupValue
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
}, [
|
|
72
|
+
level
|
|
73
|
+
]);
|
|
74
|
+
}
|
|
6
75
|
let savedOverflow = '';
|
|
7
76
|
let scrollLocks = 0;
|
|
8
77
|
function useDialog(open, panel, owner, onClose, keyboard, options = {}, ready = true, modal = true) {
|
|
@@ -78,6 +147,6 @@ function useDialog(open, panel, owner, onClose, keyboard, options = {}, ready =
|
|
|
78
147
|
modal
|
|
79
148
|
]);
|
|
80
149
|
}
|
|
81
|
-
export { useDialog };
|
|
150
|
+
export { useDialog, useOverlayLayer };
|
|
82
151
|
|
|
83
152
|
//# sourceMappingURL=dialog.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared/dialog.js","sources":["../../../../../src/shared/dialog.ts"],"sourcesContent":["import { type RefObject, useEffect, useRef } from 'react';\nimport { tabbable } from 'tabbable';\nimport { composedEventTarget, deepActiveElement } from './dom';\n\nconst stack: HTMLElement[] = [];\nexport type FocusTarget = RefObject<HTMLElement | null> | (() => HTMLElement | null);\nexport interface DialogFocusOptions {\n initialFocus?: FocusTarget;\n returnFocus?: boolean | FocusTarget;\n}\nlet savedOverflow = '';\nlet scrollLocks = 0;\n\n/** Share focus, Escape and scroll ownership between nested dialogs and drawers. */\nexport function useDialog(\n open: boolean,\n panel: RefObject<HTMLDivElement | null>,\n owner: string,\n onClose: () => void,\n keyboard: boolean,\n options: DialogFocusOptions = {},\n ready = true,\n modal = true,\n) {\n const focusOptions = useRef(options);\n focusOptions.current = options;\n const close = useRef(onClose);\n close.current = onClose;\n const keyboardRef = useRef(keyboard);\n keyboardRef.current = keyboard;\n useEffect(() => {\n const node = panel.current;\n if (!open || !node || !ready) return;\n const active = deepActiveElement();\n const previous = active instanceof HTMLElement ? active : null;\n const focusable = () =>\n tabbable(node, { getShadowRoot: (element) => element.shadowRoot ?? undefined });\n if (modal && scrollLocks++ === 0) {\n savedOverflow = document.body.style.overflow;\n document.body.style.overflow = 'hidden';\n }\n stack.push(node);\n const resolve = (target?: FocusTarget) =>\n typeof target === 'function' ? target() : target?.current;\n (resolve(focusOptions.current.initialFocus) ?? focusable()[0] ?? node).focus();\n const key = (event: KeyboardEvent) => {\n if (stack.at(-1) !== node || event.defaultPrevented) return;\n if (event.key === 'Escape' && keyboardRef.current) {\n event.preventDefault();\n event.stopPropagation();\n close.current();\n }\n if (event.key === 'Tab') {\n if (!modal) return;\n const items = focusable();\n if (!items.length) {\n event.preventDefault();\n node.focus();\n return;\n }\n const index = items.indexOf(deepActiveElement() as HTMLElement);\n if (event.shiftKey && index <= 0) {\n event.preventDefault();\n items.at(-1)?.focus();\n } else if (!event.shiftKey && (index < 0 || index === items.length - 1)) {\n event.preventDefault();\n items[0]?.focus();\n }\n }\n };\n const focus = (event: FocusEvent) => {\n const target = composedEventTarget(event);\n if (\n stack.at(-1) === node &&\n modal &&\n target instanceof HTMLElement &&\n !event.composedPath().includes(node) &&\n target.closest('[data-leaf-owner]')?.getAttribute('data-leaf-owner') !== owner\n )\n (focusable()[0] ?? node).focus();\n };\n document.addEventListener('keydown', key);\n document.addEventListener('focusin', focus);\n return () => {\n document.removeEventListener('keydown', key);\n document.removeEventListener('focusin', focus);\n const wasTop = stack.at(-1) === node;\n const index = stack.indexOf(node);\n if (index >= 0) stack.splice(index, 1);\n if (modal && --scrollLocks === 0) document.body.style.overflow = savedOverflow;\n if (wasTop && focusOptions.current.returnFocus !== false) {\n const destination =\n typeof focusOptions.current.returnFocus === 'object' ||\n typeof focusOptions.current.returnFocus === 'function'\n ? resolve(focusOptions.current.returnFocus)\n : previous;\n if (destination?.isConnected) destination.focus();\n }\n };\n }, [open, panel, owner, ready, modal]);\n}\n"],"names":["stack","savedOverflow","scrollLocks","useDialog","open","panel","owner","onClose","keyboard","options","ready","modal","focusOptions","useRef","close","keyboardRef","useEffect","node","active","deepActiveElement","previous","HTMLElement","focusable","tabbable","element","undefined","document","res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a,OAAO,CAAC,WAAW,EAAY;gBACxD,MAAMwB,cACJ,AAA4C,YAA5C,OAAOxB,aAAa,OAAO,CAAC,WAAW,IACvC,AAA4C,cAA5C,OAAOA,aAAa,OAAO,CAAC,WAAW,GACnCe,QAAQf,aAAa,OAAO,CAAC,WAAW,IACxCQ;gBACN,IAAIgB,aAAa,aAAaA,YAAY,KAAK;YACjD;QACF;IACF,GAAG;QAAChC;QAAMC;QAAOC;QAAOI;QAAOC;KAAM;AACvC"}
|
|
1
|
+
{"version":3,"file":"shared/dialog.js","sources":["../../../../../src/shared/dialog.ts"],"sourcesContent":["import {\n type CSSProperties,\n type RefObject,\n useEffect,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { tabbable } from 'tabbable';\nimport { composedEventTarget, deepActiveElement } from './dom';\n\nconst stack: HTMLElement[] = [];\nconst layers: { id: symbol; level: number }[] = [];\nconst OVERLAY_Z_STEP = 2;\nconst useBrowserLayoutEffect = typeof window === 'undefined' ? useEffect : useLayoutEffect;\n\nconst overlayZIndex = (addend: number) => `calc(var(--leaf-z-index-modal, 1100) + ${addend})`;\n\nfunction releaseLayer(current: { id: symbol; level: number } | null) {\n if (current) {\n const index = layers.indexOf(current);\n if (index >= 0) layers.splice(index, 1);\n }\n return null;\n}\n\nexport interface OverlayLayer {\n level: number | null;\n offset: number;\n maskStyle: CSSProperties | undefined;\n popupStyle: CSSProperties | undefined;\n floatingStyle: CSSProperties | undefined;\n}\n\n/** 按浮层实际激活生命周期分配递增叠层,退场期间保留原层级直至完全卸载/隐藏。 */\nexport function useOverlayLayer(present: boolean, open = present): OverlayLayer {\n const [level, setLevel] = useState<number | null>(null);\n const entry = useRef<{ id: symbol; level: number } | null>(null);\n const wasOpen = useRef(false);\n\n useBrowserLayoutEffect(() => {\n const opened = open && !wasOpen.current;\n wasOpen.current = open;\n if (!present) {\n entry.current = releaseLayer(entry.current);\n setLevel(null);\n return;\n }\n // 首次进入展示态,或在关闭动画尚未结束时重新打开,都分配当前最高叠层。\n if (!entry.current || opened) {\n entry.current = releaseLayer(entry.current);\n const next = layers.length ? Math.max(...layers.map((item) => item.level)) + 1 : 0;\n const item = { id: Symbol(), level: next };\n layers.push(item);\n entry.current = item;\n setLevel(next);\n }\n }, [present, open]);\n\n useBrowserLayoutEffect(\n () => () => {\n entry.current = releaseLayer(entry.current);\n },\n [],\n );\n\n return useMemo(() => {\n const offset = level !== null && level > 0 ? level * OVERLAY_Z_STEP : 0;\n if (offset === 0) {\n return {\n level,\n offset: 0,\n maskStyle: undefined,\n popupStyle: undefined,\n floatingStyle: undefined,\n };\n }\n const popupValue = overlayZIndex(offset + 1);\n return {\n level,\n offset,\n maskStyle: { zIndex: overlayZIndex(offset) },\n popupStyle: { '--leaf-z-index-popup': popupValue } as CSSProperties,\n floatingStyle: {\n zIndex: popupValue,\n '--leaf-z-index-popup': popupValue,\n } as CSSProperties,\n };\n }, [level]);\n}\nexport type FocusTarget = RefObject<HTMLElement | null> | (() => HTMLElement | null);\nexport interface DialogFocusOptions {\n initialFocus?: FocusTarget;\n returnFocus?: boolean | FocusTarget;\n}\nlet savedOverflow = '';\nlet scrollLocks = 0;\n\n/** Share focus, Escape and scroll ownership between nested dialogs and drawers. */\nexport function useDialog(\n open: boolean,\n panel: RefObject<HTMLDivElement | null>,\n owner: string,\n onClose: () => void,\n keyboard: boolean,\n options: DialogFocusOptions = {},\n ready = true,\n modal = true,\n) {\n const focusOptions = useRef(options);\n focusOptions.current = options;\n const close = useRef(onClose);\n close.current = onClose;\n const keyboardRef = useRef(keyboard);\n keyboardRef.current = keyboard;\n useEffect(() => {\n const node = panel.current;\n if (!open || !node || !ready) return;\n const active = deepActiveElement();\n const previous = active instanceof HTMLElement ? active : null;\n const focusable = () =>\n tabbable(node, { getShadowRoot: (element) => element.shadowRoot ?? undefined });\n if (modal && scrollLocks++ === 0) {\n savedOverflow = document.body.style.overflow;\n document.body.style.overflow = 'hidden';\n }\n stack.push(node);\n const resolve = (target?: FocusTarget) =>\n typeof target === 'function' ? target() : target?.current;\n (resolve(focusOptions.current.initialFocus) ?? focusable()[0] ?? node).focus();\n const key = (event: KeyboardEvent) => {\n if (stack.at(-1) !== node || event.defaultPrevented) return;\n if (event.key === 'Escape' && keyboardRef.current) {\n event.preventDefault();\n event.stopPropagation();\n close.current();\n }\n if (event.key === 'Tab') {\n if (!modal) return;\n const items = focusable();\n if (!items.length) {\n event.preventDefault();\n node.focus();\n return;\n }\n const index = items.indexOf(deepActiveElement() as HTMLElement);\n if (event.shiftKey && index <= 0) {\n event.preventDefault();\n items.at(-1)?.focus();\n } else if (!event.shiftKey && (index < 0 || index === items.length - 1)) {\n event.preventDefault();\n items[0]?.focus();\n }\n }\n };\n const focus = (event: FocusEvent) => {\n const target = composedEventTarget(event);\n if (\n stack.at(-1) === node &&\n modal &&\n target instanceof HTMLElement &&\n !event.composedPath().includes(node) &&\n target.closest('[data-leaf-owner]')?.getAttribute('data-leaf-owner') !== owner\n )\n (focusable()[0] ?? node).focus();\n };\n document.addEventListener('keydown', key);\n document.addEventListener('focusin', focus);\n return () => {\n document.removeEventListener('keydown', key);\n document.removeEventListener('focusin', focus);\n const wasTop = stack.at(-1) === node;\n const index = stack.indexOf(node);\n if (index >= 0) stack.splice(index, 1);\n if (modal && --scrollLocks === 0) document.body.style.overflow = savedOverflow;\n if (wasTop && focusOptions.current.returnFocus !== false) {\n const destination =\n typeof focusOptions.current.returnFocus === 'object' ||\n typeof focusOptions.current.returnFocus === 'function'\n ? resolve(focusOptions.current.returnFocus)\n : previous;\n if (destination?.isConnected) destination.focus();\n }\n };\n }, [open, panel, owner, ready, modal]);\n}\n"],"names":["stack","layers","OVERLAY_Z_STEP","useBrowserLayoutEffect","window","useEffect","useLayoutEffect","overlayZIndex","addend","releaseLayer","current","index","useOverlayLayer","present","open","level","setLevel","useState","entry","useRef","wasOpen","opened","next","Math","item","Symbol","useMemo","offset","undefined","popupValue","savedOverflow","scrollLocks","useDialog","panel","owner","onClose","keyboard","options","ready","modal","focusOptions","close","keyboardRef","node","active","deepActiveElement","previous","HTMLElement","focusable","tabbable","element","document","resolve","target","key","event","items","focus","composedEventTarget","wasTop","destination"],"mappings":";;;;AAYA,MAAMA,QAAuB,EAAE;AAC/B,MAAMC,gBAA0C,EAAE;AAClD,MAAMC,iBAAiB;AACvB,MAAMC,yBAAyB,AAAkB,MAAlB,OAAOC,SAAyBC,YAAYC;AAE3E,MAAMC,gBAAgB,CAACC,SAAmB,CAAC,uCAAuC,EAAEA,OAAO,CAAC,CAAC;AAE7F,SAASC,aAAaC,OAA6C;IACjE,IAAIA,SAAS;QACX,MAAMC,QAAQV,cAAO,OAAO,CAACS;QAC7B,IAAIC,SAAS,GAAGV,cAAO,MAAM,CAACU,OAAO;IACvC;IACA,OAAO;AACT;AAWO,SAASC,gBAAgBC,OAAgB,EAAEC,OAAOD,OAAO;IAC9D,MAAM,CAACE,OAAOC,SAAS,GAAGC,SAAwB;IAClD,MAAMC,QAAQC,OAA6C;IAC3D,MAAMC,UAAUD,OAAO;IAEvBhB,uBAAuB;QACrB,MAAMkB,SAASP,QAAQ,CAACM,QAAQ,OAAO;QACvCA,QAAQ,OAAO,GAAGN;QAClB,IAAI,CAACD,SAAS;YACZK,MAAM,OAAO,GAAGT,aAAaS,MAAM,OAAO;YAC1CF,SAAS;YACT;QACF;QAEA,IAAI,CAACE,MAAM,OAAO,IAAIG,QAAQ;YAC5BH,MAAM,OAAO,GAAGT,aAAaS,MAAM,OAAO;YAC1C,MAAMI,OAAOrB,cAAO,MAAM,GAAGsB,KAAK,GAAG,IAAItB,cAAO,GAAG,CAAC,CAACuB,OAASA,KAAK,KAAK,KAAK,IAAI;YACjF,MAAMA,OAAO;gBAAE,IAAIC;gBAAU,OAAOH;YAAK;YACzCrB,cAAO,IAAI,CAACuB;YACZN,MAAM,OAAO,GAAGM;YAChBR,SAASM;QACX;IACF,GAAG;QAACT;QAASC;KAAK;IAElBX,uBACE,IAAM;YACJe,MAAM,OAAO,GAAGT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AC,WAAWG;QACrCH,SAAS,gBAAgB,CAAC,WAAWM;QACrC,OAAO;YACLN,SAAS,mBAAmB,CAAC,WAAWG;YACxCH,SAAS,mBAAmB,CAAC,WAAWM;YACxC,MAAME,SAAS3D,MAAM,EAAE,CAAC,QAAQ2C;YAChC,MAAMhC,QAAQX,MAAM,OAAO,CAAC2C;YAC5B,IAAIhC,SAAS,GAAGX,MAAM,MAAM,CAACW,OAAO;YACpC,IAAI4B,SAAS,AAAkB,MAAlB,EAAER,aAAmBoB,SAAS,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAGrB;YACjE,IAAI6B,UAAUnB,AAAqC,UAArCA,aAAa,OAAO,CAAC,WAAW,EAAY;gBACxD,MAAMoB,cACJ,AAA4C,YAA5C,OAAOpB,aAAa,OAAO,CAAC,WAAW,IACvC,AAA4C,cAA5C,OAAOA,aAAa,OAAO,CAAC,WAAW,GACnCY,QAAQZ,aAAa,OAAO,CAAC,WAAW,IACxCM;gBACN,IAAIc,aAAa,aAAaA,YAAY,KAAK;YACjD;QACF;IACF,GAAG;QAAC9C;QAAMmB;QAAOC;QAAOI;QAAOC;KAAM;AACvC"}
|
|
@@ -313,6 +313,124 @@ function useActiveOption(open, optionId, panelRef) {
|
|
|
313
313
|
panelRef
|
|
314
314
|
]);
|
|
315
315
|
}
|
|
316
|
-
|
|
316
|
+
const MODIFIER_KEYS = new Set([
|
|
317
|
+
'Shift',
|
|
318
|
+
'Control',
|
|
319
|
+
'Alt',
|
|
320
|
+
'Meta'
|
|
321
|
+
]);
|
|
322
|
+
const pointerModalities = new WeakMap();
|
|
323
|
+
const modalityRefs = new WeakMap();
|
|
324
|
+
const modalityCleanups = new WeakMap();
|
|
325
|
+
function markPointerModality(doc) {
|
|
326
|
+
if (doc) pointerModalities.set(doc, true);
|
|
327
|
+
}
|
|
328
|
+
function isPointerModality(doc) {
|
|
329
|
+
return doc ? pointerModalities.get(doc) ?? false : false;
|
|
330
|
+
}
|
|
331
|
+
function subscribeModality(doc) {
|
|
332
|
+
const count = modalityRefs.get(doc) ?? 0;
|
|
333
|
+
if (0 === count) {
|
|
334
|
+
const onPointer = ()=>{
|
|
335
|
+
pointerModalities.set(doc, true);
|
|
336
|
+
};
|
|
337
|
+
const onKey = (event)=>{
|
|
338
|
+
if (!MODIFIER_KEYS.has(event.key)) pointerModalities.set(doc, false);
|
|
339
|
+
};
|
|
340
|
+
doc.addEventListener('pointerdown', onPointer, true);
|
|
341
|
+
doc.addEventListener('mousedown', onPointer, true);
|
|
342
|
+
doc.addEventListener('keydown', onKey, true);
|
|
343
|
+
modalityCleanups.set(doc, ()=>{
|
|
344
|
+
doc.removeEventListener('pointerdown', onPointer, true);
|
|
345
|
+
doc.removeEventListener('mousedown', onPointer, true);
|
|
346
|
+
doc.removeEventListener('keydown', onKey, true);
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
modalityRefs.set(doc, count + 1);
|
|
350
|
+
return ()=>{
|
|
351
|
+
const next = (modalityRefs.get(doc) ?? 1) - 1;
|
|
352
|
+
if (next <= 0) {
|
|
353
|
+
modalityRefs.delete(doc);
|
|
354
|
+
modalityCleanups.get(doc)?.();
|
|
355
|
+
modalityCleanups.delete(doc);
|
|
356
|
+
pointerModalities.delete(doc);
|
|
357
|
+
} else modalityRefs.set(doc, next);
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
function useHoverFocus({ enabled = true, inactive, open, change, enterDelay, leaveDelay, triggerRef, panelRef, keepPanelFocus = false }) {
|
|
361
|
+
const timer = useRef(void 0);
|
|
362
|
+
const focused = useRef(false);
|
|
363
|
+
const hovered = useRef(false);
|
|
364
|
+
const changeRef = useRef(change);
|
|
365
|
+
changeRef.current = change;
|
|
366
|
+
const schedule = useCallback((next, delay)=>{
|
|
367
|
+
clearTimeout(timer.current);
|
|
368
|
+
timer.current = setTimeout(()=>changeRef.current(next), Math.max(0, delay));
|
|
369
|
+
}, []);
|
|
370
|
+
const dismiss = useCallback((reason)=>{
|
|
371
|
+
clearTimeout(timer.current);
|
|
372
|
+
focused.current = false;
|
|
373
|
+
if ('outside' === reason) hovered.current = false;
|
|
374
|
+
changeRef.current(false);
|
|
375
|
+
}, []);
|
|
376
|
+
useFloatingDismiss(open, dismiss, triggerRef, panelRef);
|
|
377
|
+
useEffect(()=>()=>clearTimeout(timer.current), []);
|
|
378
|
+
useEffect(()=>{
|
|
379
|
+
if (!enabled || inactive) {
|
|
380
|
+
clearTimeout(timer.current);
|
|
381
|
+
focused.current = false;
|
|
382
|
+
hovered.current = false;
|
|
383
|
+
}
|
|
384
|
+
}, [
|
|
385
|
+
enabled,
|
|
386
|
+
inactive
|
|
387
|
+
]);
|
|
388
|
+
useEffect(()=>{
|
|
389
|
+
if (!enabled || "u" < typeof document) return;
|
|
390
|
+
return subscribeModality(triggerRef.current?.ownerDocument ?? document);
|
|
391
|
+
}, [
|
|
392
|
+
enabled,
|
|
393
|
+
triggerRef
|
|
394
|
+
]);
|
|
395
|
+
const panelContains = (node)=>keepPanelFocus && node instanceof Node && Boolean(panelRef.current?.contains(node));
|
|
396
|
+
return {
|
|
397
|
+
onTriggerPointerEnter: (event)=>{
|
|
398
|
+
if (enabled && !inactive && !event.defaultPrevented && 'touch' !== event.pointerType) {
|
|
399
|
+
hovered.current = true;
|
|
400
|
+
schedule(true, enterDelay);
|
|
401
|
+
}
|
|
402
|
+
},
|
|
403
|
+
onTriggerPointerLeave: ()=>{
|
|
404
|
+
hovered.current = false;
|
|
405
|
+
if (enabled && !focused.current && !(keepPanelFocus && panelContains(deepActiveElement()))) schedule(false, leaveDelay);
|
|
406
|
+
},
|
|
407
|
+
onTriggerPointerDown: (event)=>{
|
|
408
|
+
if (!enabled) return;
|
|
409
|
+
markPointerModality(event.currentTarget.ownerDocument);
|
|
410
|
+
focused.current = false;
|
|
411
|
+
},
|
|
412
|
+
onTriggerFocus: (event)=>{
|
|
413
|
+
if (enabled && !inactive && !event.defaultPrevented && !isPointerModality(event.currentTarget.ownerDocument)) {
|
|
414
|
+
focused.current = true;
|
|
415
|
+
clearTimeout(timer.current);
|
|
416
|
+
changeRef.current(true);
|
|
417
|
+
}
|
|
418
|
+
},
|
|
419
|
+
onTriggerBlur: (event)=>{
|
|
420
|
+
focused.current = false;
|
|
421
|
+
if (enabled && !hovered.current && !panelContains(event.relatedTarget)) schedule(false, leaveDelay);
|
|
422
|
+
},
|
|
423
|
+
onPanelPointerEnter: ()=>{
|
|
424
|
+
if (!enabled) return;
|
|
425
|
+
hovered.current = true;
|
|
426
|
+
clearTimeout(timer.current);
|
|
427
|
+
},
|
|
428
|
+
onPanelPointerLeave: ()=>{
|
|
429
|
+
hovered.current = false;
|
|
430
|
+
if (enabled && !focused.current && !panelContains(deepActiveElement())) schedule(false, leaveDelay);
|
|
431
|
+
}
|
|
432
|
+
};
|
|
433
|
+
}
|
|
434
|
+
export { FloatingPanel, useActiveOption, useFloatingDismiss, useHoverFocus, usePopupState };
|
|
317
435
|
|
|
318
436
|
//# sourceMappingURL=floating.js.map
|