@yamada-ui/react 2.2.7-dev-20260817094722 → 2.2.7-dev-20260819081352

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.
@@ -65,10 +65,9 @@ const usePopover = ({ autoFocus = true, autoUpdate, modal = false, blockScrollOn
65
65
  ]);
66
66
  const onBlur = (0, react.useCallback)((ev) => {
67
67
  const relatedTarget = require_dom.getEventRelatedTarget(ev);
68
- const popup = relatedTarget?.hasAttribute("data-popup");
68
+ if (relatedTarget?.closest("[data-popup]")) return;
69
69
  if ((0, require_utils_index.utils_exports.contains)(triggerRef.current, relatedTarget)) return;
70
70
  if ((0, require_utils_index.utils_exports.contains)(contentRef.current, relatedTarget)) return;
71
- if ((0, require_utils_index.utils_exports.contains)(contentRef.current, ev.target) && popup) return;
72
71
  if (closeOnBlur) onClose();
73
72
  }, [closeOnBlur, onClose]);
74
73
  require_hooks_use_event_listener_index.useEventListener(getDocument(), "scroll", () => {
@@ -1 +1 @@
1
- {"version":3,"file":"use-popover.cjs","names":["useEnvironment","useId","useRef","useDisclosure","usePopper","useCallback","getEventRelatedTarget","mergeRefs","popperProps","useSplitProps"],"sources":["../../../../src/components/popover/use-popover.tsx"],"sourcesContent":["\"use client\"\n\nimport type { FocusEvent, KeyboardEvent, RefObject } from \"react\"\nimport type { Direction, PropGetter } from \"../../core\"\nimport type { UseDisclosureProps } from \"../../hooks/use-disclosure\"\nimport type { UsePopperProps } from \"../../hooks/use-popper\"\nimport type { Dict } from \"../../utils\"\nimport type { UsePopupAnimationProps } from \"./popover\"\nimport { useCallback, useEffect, useId, useRef } from \"react\"\nimport { useEnvironment, useSplitProps } from \"../../core\"\nimport { useDisclosure } from \"../../hooks/use-disclosure\"\nimport { useEventListener } from \"../../hooks/use-event-listener\"\nimport { useFocusOnShow } from \"../../hooks/use-focus\"\nimport { useOutsideClick } from \"../../hooks/use-outside-click\"\nimport { popperProps, usePopper } from \"../../hooks/use-popper\"\nimport {\n ariaAttr,\n assignRef,\n contains,\n dataAttr,\n focusTransfer,\n focusTrap,\n getEventRelatedTarget,\n handlerAll,\n mergeRefs,\n runKeyAction,\n scrollLock,\n setAttribute,\n useSafeLayoutEffect,\n useUnmountEffect,\n} from \"../../utils\"\n\nexport interface UsePopoverProps\n extends Omit<UseDisclosureProps, \"timing\">, UsePopperProps<\"button\"> {\n /**\n * If `true`, focus will be transferred to the first interactive element when the popover opens.\n *\n * @default true\n */\n autoFocus?: boolean\n /**\n * If `true`, scrolling will be disabled on the `body` when the modal opens.\n *\n * @default false\n */\n blockScrollOnMount?: boolean\n /**\n * If `true`, the popover will close when you blur out it by clicking outside or tabbing out.\n *\n * @default true\n */\n closeOnBlur?: boolean\n /**\n * If `true`, the popover will hide on pressing Esc key.\n *\n * @default true\n */\n closeOnEsc?: boolean\n /**\n * If `true`, the popover will hide on scroll.\n *\n * @default false\n */\n closeOnScroll?: boolean\n /**\n * If `true`, the popover will be disabled.\n *\n * @default false\n */\n disabled?: boolean\n /**\n * The `ref` of the element that should receive focus when the popover opens.\n */\n initialFocusRef?: RefObject<HTMLElement | null>\n /**\n * If `true`, the popover will be modal.\n *\n * - scrolling is blocked.\n * - focus is trapped within the popover.\n *\n * @default false\n */\n modal?: boolean\n /**\n * If `true`, the popover will be opened when click on the field.\n *\n * @default true\n */\n openOnClick?: boolean\n /**\n * The placement of the popper relative to its reference.\n *\n * @default 'end'\n */\n placement?: Direction\n /**\n * If `true`, the focus will be transferred to the popover content when the tab key is pressed.\n *\n * @default true\n */\n transferFocus?: boolean\n /**\n * Update the position of the floating element, re-rendering the component if required.\n */\n updateRef?: RefObject<() => void>\n}\n\nexport const usePopover = ({\n autoFocus = true,\n autoUpdate,\n modal = false,\n blockScrollOnMount = modal,\n closeOnBlur = true,\n closeOnEsc = true,\n closeOnScroll,\n defaultOpen,\n disabled,\n elements,\n flip,\n gutter,\n initialFocusRef,\n matchWidth,\n middleware,\n offset,\n open: openProp,\n openOnClick = true,\n placement = \"end\",\n platform,\n preventOverflow,\n strategy,\n transferFocus = true,\n transform,\n updateRef,\n whileElementsMounted,\n onClose: onCloseProp,\n onOpen: onOpenProp,\n}: UsePopoverProps = {}) => {\n const { getDocument } = useEnvironment()\n const headerId = useId()\n const bodyId = useId()\n const contentId = useId()\n const anchorRef = useRef<HTMLElement>(null)\n const triggerRef = useRef<HTMLButtonElement>(null)\n const contentRef = useRef<HTMLElement>(null)\n const openTimeout = useRef<NodeJS.Timeout>(undefined)\n const closeTimeout = useRef<NodeJS.Timeout>(undefined)\n const { open, onClose, onOpen } = useDisclosure({\n defaultOpen,\n open: openProp,\n onClose: onCloseProp,\n onOpen: onOpenProp,\n })\n const { refs, update, getPopperProps } = usePopper<\"button\">({\n autoUpdate,\n elements,\n flip,\n gutter,\n matchWidth,\n middleware,\n offset,\n open,\n placement,\n platform,\n preventOverflow,\n strategy,\n transform,\n whileElementsMounted,\n })\n\n assignRef(updateRef, update)\n\n const onRestoreFocus = useCallback(() => {\n clearTimeout(closeTimeout.current)\n closeTimeout.current = setTimeout(() => {\n triggerRef.current?.focus()\n })\n }, [])\n\n const onKeyDown = useCallback(\n (ev: KeyboardEvent<HTMLElement>) => {\n runKeyAction(ev, {\n Escape: () => {\n if (!closeOnEsc) return\n\n onClose()\n onRestoreFocus()\n },\n })\n },\n [closeOnEsc, onClose, onRestoreFocus],\n )\n\n const onBlur = useCallback(\n (ev: FocusEvent<HTMLDivElement>) => {\n const relatedTarget = getEventRelatedTarget(ev)\n const popup = relatedTarget?.hasAttribute(\"data-popup\")\n\n if (contains(triggerRef.current, relatedTarget)) return\n if (contains(contentRef.current, relatedTarget)) return\n if (contains(contentRef.current, ev.target) && popup) return\n\n if (closeOnBlur) onClose()\n },\n [closeOnBlur, onClose],\n )\n\n useEventListener(getDocument(), \"scroll\", () => {\n if (open && closeOnScroll) onClose()\n })\n\n useFocusOnShow(contentRef, {\n focusTarget: initialFocusRef,\n shouldFocus: autoFocus,\n visible: open,\n })\n\n useOutsideClick({\n ref: [contentRef, triggerRef],\n enabled: open && closeOnBlur,\n handler: onClose,\n })\n\n useSafeLayoutEffect(() => {\n const el = contentRef.current\n const hasHeader = !!getDocument()?.getElementById(headerId)\n const hasBody = !!getDocument()?.getElementById(bodyId)\n\n if (el && hasHeader) setAttribute(el, \"aria-labelledby\", headerId)\n if (el && hasBody) setAttribute(el, \"aria-describedby\", bodyId)\n }, [open, headerId, bodyId])\n\n useEffect(() => {\n if (!open || !modal) return\n\n return focusTrap(contentRef.current)\n }, [open, modal])\n\n useEffect(() => {\n if (!open || !blockScrollOnMount) return\n\n return scrollLock(contentRef.current)\n }, [open, modal, blockScrollOnMount])\n\n useEffect(() => {\n if (!open || modal || !transferFocus) return\n\n return focusTransfer(contentRef.current, triggerRef.current)\n }, [open, modal, transferFocus])\n\n useUnmountEffect(() => {\n clearTimeout(openTimeout.current)\n clearTimeout(closeTimeout.current)\n })\n\n const getTriggerProps: PropGetter<\"button\"> = useCallback(\n ({ ref, ...props } = {}) => ({\n \"aria-controls\": open ? contentId : undefined,\n \"aria-disabled\": ariaAttr(disabled),\n \"aria-expanded\": open,\n \"aria-haspopup\": \"dialog\",\n role: \"button\",\n ...props,\n ref: mergeRefs(ref, triggerRef, (node) => {\n if (anchorRef.current == null) refs.setReference(node)\n }),\n onBlur: handlerAll(props.onBlur, (ev) =>\n !contains(contentRef.current, getEventRelatedTarget(ev)) && closeOnBlur\n ? onClose()\n : void 0,\n ),\n onClick: handlerAll(\n props.onClick,\n !open ? (!disabled && openOnClick ? onOpen : undefined) : onClose,\n ),\n onKeyDown: handlerAll(props.onKeyDown, onKeyDown),\n }),\n [\n closeOnBlur,\n contentId,\n disabled,\n onClose,\n onKeyDown,\n onOpen,\n open,\n openOnClick,\n refs,\n ],\n )\n\n const getAnchorProps: PropGetter = useCallback(\n ({ ref, ...props } = {}) => ({\n ...props,\n ref: mergeRefs(ref, anchorRef, refs.setReference),\n }),\n [refs.setReference],\n )\n\n const getPositionerProps: PropGetter = useCallback(\n (props) => getPopperProps(props),\n [getPopperProps],\n )\n\n const getContentProps: PropGetter = useCallback(\n ({ ref, ...props } = {}) => ({\n id: contentId,\n \"aria-hidden\": !open,\n \"aria-modal\": modal ? \"true\" : undefined,\n \"data-close\": dataAttr(!open),\n \"data-open\": dataAttr(open),\n \"data-popup\": dataAttr(true),\n role: \"dialog\",\n tabIndex: -1,\n ...props,\n ref: mergeRefs(ref, contentRef),\n onBlur: handlerAll(props.onBlur, onBlur),\n onKeyDown: handlerAll(props.onKeyDown, onKeyDown),\n }),\n [contentId, open, modal, onBlur, onKeyDown],\n )\n\n const getHeaderProps: PropGetter = useCallback(\n (props) => ({ id: headerId, ...props }),\n [headerId],\n )\n\n const getBodyProps: PropGetter = useCallback(\n (props) => ({ id: bodyId, ...props }),\n [bodyId],\n )\n\n const getFooterProps: PropGetter = useCallback((props) => ({ ...props }), [])\n\n const getCloseTriggerProps: PropGetter<\"button\"> = useCallback(\n (props = {}) => ({\n ...props,\n onClick: handlerAll(props.onClick, () => {\n onClose()\n onRestoreFocus()\n }),\n }),\n [onClose, onRestoreFocus],\n )\n\n return {\n open,\n getAnchorProps,\n getBodyProps,\n getCloseTriggerProps,\n getContentProps,\n getFooterProps,\n getHeaderProps,\n getPositionerProps,\n getTriggerProps,\n onClose,\n onOpen,\n }\n}\n\nexport type UsePopoverReturn = ReturnType<typeof usePopover>\n\nexport const popoverProps: (\n | keyof UsePopoverProps\n | keyof UsePopupAnimationProps\n)[] = [\n ...popperProps,\n \"autoFocus\",\n \"transferFocus\",\n \"blockScrollOnMount\",\n \"closeOnBlur\",\n \"closeOnEsc\",\n \"closeOnScroll\",\n \"openOnClick\",\n \"disabled\",\n \"initialFocusRef\",\n \"modal\",\n \"updateRef\",\n \"defaultOpen\",\n \"onOpen\",\n \"onClose\",\n \"animationScheme\",\n \"duration\",\n]\n\nexport const usePopoverProps = <\n Y extends Dict = Dict,\n M extends keyof UsePopoverProps | keyof UsePopupAnimationProps =\n | keyof UsePopoverProps\n | keyof UsePopupAnimationProps,\n>(\n props: Y,\n omitKeys?: M[],\n) => {\n return useSplitProps(\n props,\n popoverProps.filter((key) => !omitKeys?.includes(key as M)),\n ) as unknown as [\n keyof UsePopoverProps | keyof UsePopupAnimationProps extends M\n ? UsePopoverProps & UsePopupAnimationProps\n : Omit<UsePopoverProps & UsePopupAnimationProps, M>,\n Omit<\n Y,\n keyof UsePopoverProps | keyof UsePopupAnimationProps extends M\n ? keyof UsePopoverProps | keyof UsePopupAnimationProps\n : Exclude<keyof UsePopoverProps | keyof UsePopupAnimationProps, M>\n >,\n ]\n}\n"],"mappings":";;;;;;;;;;;;;;;AA2GA,MAAa,cAAc,EACzB,YAAY,MACZ,YACA,QAAQ,OACR,qBAAqB,OACrB,cAAc,MACd,aAAa,MACb,eACA,aACA,UACA,UACA,MACA,QACA,iBACA,YACA,YACA,QACA,MAAM,UACN,cAAc,MACd,YAAY,OACZ,UACA,iBACA,UACA,gBAAgB,MAChB,WACA,WACA,sBACA,SAAS,aACT,QAAQ,eACW,CAAC,MAAM;CAC1B,MAAM,EAAE,gBAAgBA,6BAAAA,eAAe;CACvC,MAAM,YAAA,GAAWC,MAAAA,MAAAA,CAAM;CACvB,MAAM,UAAA,GAASA,MAAAA,MAAAA,CAAM;CACrB,MAAM,aAAA,GAAYA,MAAAA,MAAAA,CAAM;CACxB,MAAM,aAAA,GAAYC,MAAAA,OAAAA,CAAoB,IAAI;CAC1C,MAAM,cAAA,GAAaA,MAAAA,OAAAA,CAA0B,IAAI;CACjD,MAAM,cAAA,GAAaA,MAAAA,OAAAA,CAAoB,IAAI;CAC3C,MAAM,eAAA,GAAcA,MAAAA,OAAAA,CAAuB,KAAA,CAAS;CACpD,MAAM,gBAAA,GAAeA,MAAAA,OAAAA,CAAuB,KAAA,CAAS;CACrD,MAAM,EAAE,MAAM,SAAS,WAAWC,uBAAAA,cAAc;EAC9C;EACA,MAAM;EACN,SAAS;EACT,QAAQ;CACV,CAAC;CACD,MAAM,EAAE,MAAM,QA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AS,CAC5C;CAEA,MAAM,kBAAA,GAA6BF,MAAAA,YAAAA,EAChC,WAAW;EAAE,IAAI;EAAU,GAAG;CAAM,IACrC,CAAC,QAAQ,CACX;CAEA,MAAM,gBAAA,GAA2BA,MAAAA,YAAAA,EAC9B,WAAW;EAAE,IAAI;EAAQ,GAAG;CAAM,IACnC,CAAC,MAAM,CACT;CAEA,MAAM,kBAAA,GAA6BA,MAAAA,YAAAA,EAAa,WAAW,EAAE,GAAG,MAAM,IAAI,CAAC,CAAC;CAa5E,OAAO;EACL;EACA;EACA;EACA,uBAAA,GAfiDA,MAAAA,YAAAA,EAChD,QAAQ,CAAC,OAAO;GACf,GAAG;GACH,UAAA,GAAA,oBAAA,cAAS,WAAA,CAAW,MAAM,eAAe;IACvC,QAAQ;IACR,eAAe;GACjB,CAAC;EACH,IACA,CAAC,SAAS,cAAc,CAOL;EACnB;EACA;EACA;EACA;EACA;EACA;EACA;CACF;AACF;AAIA,MAAa,eAGP;CACJ,GAAGG,+BAAAA;CACH;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,MAAa,mBAMX,OACA,aACG;CACH,OAAOC,cAAAA,cACL,OACA,aAAa,QAAQ,QAAQ,CAAC,UAAU,SAAS,GAAQ,CAAC,CAC5D;AAWF"}
1
+ {"version":3,"file":"use-popover.cjs","names":["useEnvironment","useId","useRef","useDisclosure","usePopper","useCallback","getEventRelatedTarget","mergeRefs","popperProps","useSplitProps"],"sources":["../../../../src/components/popover/use-popover.tsx"],"sourcesContent":["\"use client\"\n\nimport type { FocusEvent, KeyboardEvent, RefObject } from \"react\"\nimport type { Direction, PropGetter } from \"../../core\"\nimport type { UseDisclosureProps } from \"../../hooks/use-disclosure\"\nimport type { UsePopperProps } from \"../../hooks/use-popper\"\nimport type { Dict } from \"../../utils\"\nimport type { UsePopupAnimationProps } from \"./popover\"\nimport { useCallback, useEffect, useId, useRef } from \"react\"\nimport { useEnvironment, useSplitProps } from \"../../core\"\nimport { useDisclosure } from \"../../hooks/use-disclosure\"\nimport { useEventListener } from \"../../hooks/use-event-listener\"\nimport { useFocusOnShow } from \"../../hooks/use-focus\"\nimport { useOutsideClick } from \"../../hooks/use-outside-click\"\nimport { popperProps, usePopper } from \"../../hooks/use-popper\"\nimport {\n ariaAttr,\n assignRef,\n contains,\n dataAttr,\n focusTransfer,\n focusTrap,\n getEventRelatedTarget,\n handlerAll,\n mergeRefs,\n runKeyAction,\n scrollLock,\n setAttribute,\n useSafeLayoutEffect,\n useUnmountEffect,\n} from \"../../utils\"\n\nexport interface UsePopoverProps\n extends Omit<UseDisclosureProps, \"timing\">, UsePopperProps<\"button\"> {\n /**\n * If `true`, focus will be transferred to the first interactive element when the popover opens.\n *\n * @default true\n */\n autoFocus?: boolean\n /**\n * If `true`, scrolling will be disabled on the `body` when the modal opens.\n *\n * @default false\n */\n blockScrollOnMount?: boolean\n /**\n * If `true`, the popover will close when you blur out it by clicking outside or tabbing out.\n *\n * @default true\n */\n closeOnBlur?: boolean\n /**\n * If `true`, the popover will hide on pressing Esc key.\n *\n * @default true\n */\n closeOnEsc?: boolean\n /**\n * If `true`, the popover will hide on scroll.\n *\n * @default false\n */\n closeOnScroll?: boolean\n /**\n * If `true`, the popover will be disabled.\n *\n * @default false\n */\n disabled?: boolean\n /**\n * The `ref` of the element that should receive focus when the popover opens.\n */\n initialFocusRef?: RefObject<HTMLElement | null>\n /**\n * If `true`, the popover will be modal.\n *\n * - scrolling is blocked.\n * - focus is trapped within the popover.\n *\n * @default false\n */\n modal?: boolean\n /**\n * If `true`, the popover will be opened when click on the field.\n *\n * @default true\n */\n openOnClick?: boolean\n /**\n * The placement of the popper relative to its reference.\n *\n * @default 'end'\n */\n placement?: Direction\n /**\n * If `true`, the focus will be transferred to the popover content when the tab key is pressed.\n *\n * @default true\n */\n transferFocus?: boolean\n /**\n * Update the position of the floating element, re-rendering the component if required.\n */\n updateRef?: RefObject<() => void>\n}\n\nexport const usePopover = ({\n autoFocus = true,\n autoUpdate,\n modal = false,\n blockScrollOnMount = modal,\n closeOnBlur = true,\n closeOnEsc = true,\n closeOnScroll,\n defaultOpen,\n disabled,\n elements,\n flip,\n gutter,\n initialFocusRef,\n matchWidth,\n middleware,\n offset,\n open: openProp,\n openOnClick = true,\n placement = \"end\",\n platform,\n preventOverflow,\n strategy,\n transferFocus = true,\n transform,\n updateRef,\n whileElementsMounted,\n onClose: onCloseProp,\n onOpen: onOpenProp,\n}: UsePopoverProps = {}) => {\n const { getDocument } = useEnvironment()\n const headerId = useId()\n const bodyId = useId()\n const contentId = useId()\n const anchorRef = useRef<HTMLElement>(null)\n const triggerRef = useRef<HTMLButtonElement>(null)\n const contentRef = useRef<HTMLElement>(null)\n const openTimeout = useRef<NodeJS.Timeout>(undefined)\n const closeTimeout = useRef<NodeJS.Timeout>(undefined)\n const { open, onClose, onOpen } = useDisclosure({\n defaultOpen,\n open: openProp,\n onClose: onCloseProp,\n onOpen: onOpenProp,\n })\n const { refs, update, getPopperProps } = usePopper<\"button\">({\n autoUpdate,\n elements,\n flip,\n gutter,\n matchWidth,\n middleware,\n offset,\n open,\n placement,\n platform,\n preventOverflow,\n strategy,\n transform,\n whileElementsMounted,\n })\n\n assignRef(updateRef, update)\n\n const onRestoreFocus = useCallback(() => {\n clearTimeout(closeTimeout.current)\n closeTimeout.current = setTimeout(() => {\n triggerRef.current?.focus()\n })\n }, [])\n\n const onKeyDown = useCallback(\n (ev: KeyboardEvent<HTMLElement>) => {\n runKeyAction(ev, {\n Escape: () => {\n if (!closeOnEsc) return\n\n onClose()\n onRestoreFocus()\n },\n })\n },\n [closeOnEsc, onClose, onRestoreFocus],\n )\n\n const onBlur = useCallback(\n (ev: FocusEvent<HTMLDivElement>) => {\n const relatedTarget = getEventRelatedTarget(ev)\n const popup = relatedTarget?.closest(\"[data-popup]\")\n\n if (popup) return\n if (contains(triggerRef.current, relatedTarget)) return\n if (contains(contentRef.current, relatedTarget)) return\n\n if (closeOnBlur) onClose()\n },\n [closeOnBlur, onClose],\n )\n\n useEventListener(getDocument(), \"scroll\", () => {\n if (open && closeOnScroll) onClose()\n })\n\n useFocusOnShow(contentRef, {\n focusTarget: initialFocusRef,\n shouldFocus: autoFocus,\n visible: open,\n })\n\n useOutsideClick({\n ref: [contentRef, triggerRef],\n enabled: open && closeOnBlur,\n handler: onClose,\n })\n\n useSafeLayoutEffect(() => {\n const el = contentRef.current\n const hasHeader = !!getDocument()?.getElementById(headerId)\n const hasBody = !!getDocument()?.getElementById(bodyId)\n\n if (el && hasHeader) setAttribute(el, \"aria-labelledby\", headerId)\n if (el && hasBody) setAttribute(el, \"aria-describedby\", bodyId)\n }, [open, headerId, bodyId])\n\n useEffect(() => {\n if (!open || !modal) return\n\n return focusTrap(contentRef.current)\n }, [open, modal])\n\n useEffect(() => {\n if (!open || !blockScrollOnMount) return\n\n return scrollLock(contentRef.current)\n }, [open, modal, blockScrollOnMount])\n\n useEffect(() => {\n if (!open || modal || !transferFocus) return\n\n return focusTransfer(contentRef.current, triggerRef.current)\n }, [open, modal, transferFocus])\n\n useUnmountEffect(() => {\n clearTimeout(openTimeout.current)\n clearTimeout(closeTimeout.current)\n })\n\n const getTriggerProps: PropGetter<\"button\"> = useCallback(\n ({ ref, ...props } = {}) => ({\n \"aria-controls\": open ? contentId : undefined,\n \"aria-disabled\": ariaAttr(disabled),\n \"aria-expanded\": open,\n \"aria-haspopup\": \"dialog\",\n role: \"button\",\n ...props,\n ref: mergeRefs(ref, triggerRef, (node) => {\n if (anchorRef.current == null) refs.setReference(node)\n }),\n onBlur: handlerAll(props.onBlur, (ev) =>\n !contains(contentRef.current, getEventRelatedTarget(ev)) && closeOnBlur\n ? onClose()\n : void 0,\n ),\n onClick: handlerAll(\n props.onClick,\n !open ? (!disabled && openOnClick ? onOpen : undefined) : onClose,\n ),\n onKeyDown: handlerAll(props.onKeyDown, onKeyDown),\n }),\n [\n closeOnBlur,\n contentId,\n disabled,\n onClose,\n onKeyDown,\n onOpen,\n open,\n openOnClick,\n refs,\n ],\n )\n\n const getAnchorProps: PropGetter = useCallback(\n ({ ref, ...props } = {}) => ({\n ...props,\n ref: mergeRefs(ref, anchorRef, refs.setReference),\n }),\n [refs.setReference],\n )\n\n const getPositionerProps: PropGetter = useCallback(\n (props) => getPopperProps(props),\n [getPopperProps],\n )\n\n const getContentProps: PropGetter = useCallback(\n ({ ref, ...props } = {}) => ({\n id: contentId,\n \"aria-hidden\": !open,\n \"aria-modal\": modal ? \"true\" : undefined,\n \"data-close\": dataAttr(!open),\n \"data-open\": dataAttr(open),\n \"data-popup\": dataAttr(true),\n role: \"dialog\",\n tabIndex: -1,\n ...props,\n ref: mergeRefs(ref, contentRef),\n onBlur: handlerAll(props.onBlur, onBlur),\n onKeyDown: handlerAll(props.onKeyDown, onKeyDown),\n }),\n [contentId, open, modal, onBlur, onKeyDown],\n )\n\n const getHeaderProps: PropGetter = useCallback(\n (props) => ({ id: headerId, ...props }),\n [headerId],\n )\n\n const getBodyProps: PropGetter = useCallback(\n (props) => ({ id: bodyId, ...props }),\n [bodyId],\n )\n\n const getFooterProps: PropGetter = useCallback((props) => ({ ...props }), [])\n\n const getCloseTriggerProps: PropGetter<\"button\"> = useCallback(\n (props = {}) => ({\n ...props,\n onClick: handlerAll(props.onClick, () => {\n onClose()\n onRestoreFocus()\n }),\n }),\n [onClose, onRestoreFocus],\n )\n\n return {\n open,\n getAnchorProps,\n getBodyProps,\n getCloseTriggerProps,\n getContentProps,\n getFooterProps,\n getHeaderProps,\n getPositionerProps,\n getTriggerProps,\n onClose,\n onOpen,\n }\n}\n\nexport type UsePopoverReturn = ReturnType<typeof usePopover>\n\nexport const popoverProps: (\n | keyof UsePopoverProps\n | keyof UsePopupAnimationProps\n)[] = [\n ...popperProps,\n \"autoFocus\",\n \"transferFocus\",\n \"blockScrollOnMount\",\n \"closeOnBlur\",\n \"closeOnEsc\",\n \"closeOnScroll\",\n \"openOnClick\",\n \"disabled\",\n \"initialFocusRef\",\n \"modal\",\n \"updateRef\",\n \"defaultOpen\",\n \"onOpen\",\n \"onClose\",\n \"animationScheme\",\n \"duration\",\n]\n\nexport const usePopoverProps = <\n Y extends Dict = Dict,\n M extends keyof UsePopoverProps | keyof UsePopupAnimationProps =\n | keyof UsePopoverProps\n | keyof UsePopupAnimationProps,\n>(\n props: Y,\n omitKeys?: M[],\n) => {\n return useSplitProps(\n props,\n popoverProps.filter((key) => !omitKeys?.includes(key as M)),\n ) as unknown as [\n keyof UsePopoverProps | keyof UsePopupAnimationProps extends M\n ? UsePopoverProps & UsePopupAnimationProps\n : Omit<UsePopoverProps & UsePopupAnimationProps, M>,\n Omit<\n Y,\n keyof UsePopoverProps | keyof UsePopupAnimationProps extends M\n ? keyof UsePopoverProps | keyof UsePopupAnimationProps\n : Exclude<keyof UsePopoverProps | keyof UsePopupAnimationProps, M>\n >,\n ]\n}\n"],"mappings":";;;;;;;;;;;;;;;AA2GA,MAAa,cAAc,EACzB,YAAY,MACZ,YACA,QAAQ,OACR,qBAAqB,OACrB,cAAc,MACd,aAAa,MACb,eACA,aACA,UACA,UACA,MACA,QACA,iBACA,YACA,YACA,QACA,MAAM,UACN,cAAc,MACd,YAAY,OACZ,UACA,iBACA,UACA,gBAAgB,MAChB,WACA,WACA,sBACA,SAAS,aACT,QAAQ,eACW,CAAC,MAAM;CAC1B,MAAM,EAAE,gBAAgBA,6BAAAA,eAAe;CACvC,MAAM,YAAA,GAAWC,MAAAA,MAAAA,CAAM;CACvB,MAAM,UAAA,GAASA,MAAAA,MAAAA,CAAM;CACrB,MAAM,aAAA,GAAYA,MAAAA,MAAAA,CAAM;CACxB,MAAM,aAAA,GAAYC,MAAAA,OAAAA,CAAoB,IAAI;CAC1C,MAAM,cAAA,GAAaA,MAAAA,OAAAA,CAA0B,IAAI;CACjD,MAAM,cAAA,GAAaA,MAAAA,OAAAA,CAAoB,IAAI;CAC3C,MAAM,eAAA,GAAcA,MAAAA,OAAAA,CAAuB,KAAA,CAAS;CAC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ACvC,YAAA,GAAA,oBAAA,cAAW,WAAA,CAAW,MAAM,WAAW,SAAS;CAClD,IACA;EAAC;EAAW;EAAM;EAAO;EAAQ;CAAS,CAC5C;CAEA,MAAM,kBAAA,GAA6BF,MAAAA,YAAAA,EAChC,WAAW;EAAE,IAAI;EAAU,GAAG;CAAM,IACrC,CAAC,QAAQ,CACX;CAEA,MAAM,gBAAA,GAA2BA,MAAAA,YAAAA,EAC9B,WAAW;EAAE,IAAI;EAAQ,GAAG;CAAM,IACnC,CAAC,MAAM,CACT;CAEA,MAAM,kBAAA,GAA6BA,MAAAA,YAAAA,EAAa,WAAW,EAAE,GAAG,MAAM,IAAI,CAAC,CAAC;CAa5E,OAAO;EACL;EACA;EACA;EACA,uBAAA,GAfiDA,MAAAA,YAAAA,EAChD,QAAQ,CAAC,OAAO;GACf,GAAG;GACH,UAAA,GAAA,oBAAA,cAAS,WAAA,CAAW,MAAM,eAAe;IACvC,QAAQ;IACR,eAAe;GACjB,CAAC;EACH,IACA,CAAC,SAAS,cAAc,CAOL;EACnB;EACA;EACA;EACA;EACA;EACA;EACA;CACF;AACF;AAIA,MAAa,eAGP;CACJ,GAAGG,+BAAAA;CACH;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,MAAa,mBAMX,OACA,aACG;CACH,OAAOC,cAAAA,cACL,OACA,aAAa,QAAQ,QAAQ,CAAC,UAAU,SAAS,GAAQ,CAAC,CAC5D;AAWF"}
@@ -4814,7 +4814,6 @@ var src_exports = /* @__PURE__ */ require_runtime.__exportAll({
4814
4814
  getInputHeightStyle: () => require_input_style.getInputHeightStyle,
4815
4815
  getInputPaddingEndResetStyle: () => require_input_style.getInputPaddingEndResetStyle,
4816
4816
  getInputPaddingStartResetStyle: () => require_input_style.getInputPaddingStartResetStyle,
4817
- getLanguage: () => require_i18n_provider.getLanguage,
4818
4817
  getLoadingComponent: () => require_use_loading_component.getLoadingComponent,
4819
4818
  getMonthDays: () => require_use_calendar.getMonthDays,
4820
4819
  getPreventTransition: () => require_theme_provider.getPreventTransition,
@@ -8245,7 +8244,6 @@ exports.getFormatNumber = require_use_format_number.getFormatNumber;
8245
8244
  exports.getInputHeightStyle = require_input_style.getInputHeightStyle;
8246
8245
  exports.getInputPaddingEndResetStyle = require_input_style.getInputPaddingEndResetStyle;
8247
8246
  exports.getInputPaddingStartResetStyle = require_input_style.getInputPaddingStartResetStyle;
8248
- exports.getLanguage = require_i18n_provider.getLanguage;
8249
8247
  exports.getLoadingComponent = require_use_loading_component.getLoadingComponent;
8250
8248
  exports.getMonthDays = require_use_calendar.getMonthDays;
8251
8249
  exports.getPreventTransition = require_theme_provider.getPreventTransition;
@@ -14,36 +14,72 @@ const DEFAULT_LANGUAGE = {
14
14
  locale: require_constant.DEFAULT_LOCALE
15
15
  };
16
16
  const LOCALES = Object.keys(require_providers_i18n_provider_intl_index);
17
- function getLanguage(locale, dir) {
18
- locale ??= (0, require_utils_index.utils_exports.createdDom)() ? navigator.language : require_constant.DEFAULT_LOCALE;
19
- try {
20
- Intl.DateTimeFormat.supportedLocalesOf([locale]);
21
- } catch (_err) {
22
- locale = require_constant.DEFAULT_LOCALE;
23
- }
24
- dir ??= (0, require_utils_index.utils_exports.isRtl)(locale) ? "rtl" : "ltr";
25
- return {
26
- dir,
27
- locale
28
- };
29
- }
30
17
  const I18nContext = (0, react.createContext)({
31
18
  ...DEFAULT_LANGUAGE,
32
19
  changeLanguage: require_utils_index.utils_exports.noop,
33
20
  getTranslation: () => () => "",
34
21
  t: () => ""
35
22
  });
36
- const I18nProvider = ({ children, dir: forcedDir, formats, intl = require_providers_i18n_provider_intl_index, intlMessageFormatOptions, locale: forcedLocale }) => {
37
- const [language, setLanguage] = (0, react.useState)(getLanguage(forcedLocale, forcedDir));
23
+ const I18nProvider = ({ children, dir: forcedDir, fallbackLocale = require_constant.DEFAULT_LOCALE, formats, intl: forcedIntl, intlMessageFormatOptions, locale: forcedLocale }) => {
24
+ const intl = (0, react.useMemo)(() => {
25
+ if (!forcedIntl) return require_providers_i18n_provider_intl_index;
26
+ if ((0, require_utils_index.utils_exports.isEmptyObject)(forcedIntl)) return require_providers_i18n_provider_intl_index;
27
+ return forcedIntl;
28
+ }, [forcedIntl]);
29
+ const locales = (0, react.useMemo)(() => Object.keys(intl), [intl]);
30
+ const getFallbackLocale = (0, react.useCallback)((language) => {
31
+ if (language) {
32
+ for (const key of locales) if (key.startsWith(language)) return key;
33
+ }
34
+ if (locales.includes(fallbackLocale)) return fallbackLocale;
35
+ if ((0, require_utils_index.utils_exports.createdDom)()) try {
36
+ const { language } = new Intl.Locale(fallbackLocale);
37
+ for (const key of locales) if (key.startsWith(language)) return key;
38
+ } catch {
39
+ return locales[0];
40
+ }
41
+ else {
42
+ const language = fallbackLocale.split("-")[0];
43
+ for (const key of locales) if (key.startsWith(language)) return key;
44
+ }
45
+ return locales[0];
46
+ }, [locales, fallbackLocale]);
47
+ const getLocale = (0, react.useCallback)((forcedLocale) => {
48
+ if (forcedLocale) {
49
+ if (locales.includes(forcedLocale)) return forcedLocale;
50
+ const language = forcedLocale.split("-")[0];
51
+ return getFallbackLocale(language);
52
+ } else if ((0, require_utils_index.utils_exports.createdDom)()) try {
53
+ const { language, region } = new Intl.Locale(navigator.language);
54
+ const locale = `${language}-${region}`;
55
+ return locales.includes(locale) ? locale : getFallbackLocale(language);
56
+ } catch {
57
+ return getFallbackLocale();
58
+ }
59
+ else return getFallbackLocale();
60
+ }, [locales, getFallbackLocale]);
61
+ const getLanguage = (0, react.useCallback)((locale, dir) => {
62
+ locale = getLocale(locale);
63
+ try {
64
+ Intl.DateTimeFormat.supportedLocalesOf([locale]);
65
+ } catch {
66
+ locale = getFallbackLocale();
67
+ }
68
+ dir ??= (0, require_utils_index.utils_exports.isRtl)(locale) ? "rtl" : "ltr";
69
+ return {
70
+ dir,
71
+ locale
72
+ };
73
+ }, [getLocale, getFallbackLocale]);
74
+ const [{ dir, locale }, setLanguage] = (0, react.useState)(getLanguage(forcedLocale, forcedDir));
38
75
  const controlled = !(0, require_utils_index.utils_exports.isUndefined)(forcedLocale);
39
- const { locale } = language;
40
76
  const messages = (0, react.useMemo)(() => intl[locale], [intl, locale]);
41
77
  const changeSystemLanguage = (0, react.useCallback)(() => {
42
78
  setLanguage(getLanguage());
43
- }, []);
79
+ }, [getLanguage]);
44
80
  const changeLanguage = (0, react.useCallback)((locale, dir) => {
45
81
  setLanguage(getLanguage(locale, dir));
46
- }, []);
82
+ }, [getLanguage]);
47
83
  const getValue = (0, react.useCallback)((path) => {
48
84
  const value = (0, require_utils_index.utils_exports.getMemoizedObject)(messages, path);
49
85
  if (!(0, require_utils_index.utils_exports.isUndefined)(value)) return value;
@@ -74,20 +110,17 @@ const I18nProvider = ({ children, dir: forcedDir, formats, intl = require_provid
74
110
  formats,
75
111
  intlMessageFormatOptions
76
112
  ]);
77
- const value = (0, react.useMemo)(() => {
78
- const rest = {
79
- changeLanguage,
80
- getTranslation,
81
- t: getTranslation()
82
- };
83
- return {
84
- ...language,
85
- ...rest
86
- };
87
- }, [
113
+ const value = (0, react.useMemo)(() => ({
114
+ changeLanguage,
115
+ dir,
116
+ getTranslation,
117
+ locale,
118
+ t: getTranslation()
119
+ }), [
88
120
  changeLanguage,
121
+ dir,
89
122
  getTranslation,
90
- language
123
+ locale
91
124
  ]);
92
125
  (0, react.useEffect)(() => {
93
126
  if (controlled) return;
@@ -98,7 +131,11 @@ const I18nProvider = ({ children, dir: forcedDir, formats, intl = require_provid
98
131
  }, [controlled, changeSystemLanguage]);
99
132
  require_effect.useUpdateEffect(() => {
100
133
  setLanguage(getLanguage(forcedLocale, forcedDir));
101
- }, [forcedLocale, forcedDir]);
134
+ }, [
135
+ forcedLocale,
136
+ forcedDir,
137
+ getLanguage
138
+ ]);
102
139
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(I18nContext, {
103
140
  value,
104
141
  children
@@ -122,7 +159,6 @@ function useI18n(key) {
122
159
  exports.I18nContext = I18nContext;
123
160
  exports.I18nProvider = I18nProvider;
124
161
  exports.LOCALES = LOCALES;
125
- exports.getLanguage = getLanguage;
126
162
  exports.useI18n = useI18n;
127
163
 
128
164
  //# sourceMappingURL=i18n-provider.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"i18n-provider.cjs","names":["DEFAULT_LOCALE","INTL","createContext","useState","useMemo","useCallback","get","IntlMessageFormat","useContext"],"sources":["../../../../src/providers/i18n-provider/i18n-provider.tsx"],"sourcesContent":["\"use client\"\n\nimport type { Formats, Options } from \"intl-messageformat\"\nimport type { FC, ReactNode } from \"react\"\nimport type { TextDirection } from \"../../core\"\nimport type { AnyString, Dict, Path, Value } from \"../../utils\"\nimport type { IcuArgs } from \"./icu.types\"\nimport type { DefaultIntlData } from \"./intl\"\nimport IntlMessageFormat from \"intl-messageformat\"\nimport {\n createContext,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useState,\n} from \"react\"\nimport { DEFAULT_DIRECTION, DEFAULT_LOCALE } from \"../../core\"\nimport {\n createdDom,\n getMemoizedObject as get,\n isEmptyObject,\n isRtl,\n isString,\n isUndefined,\n noop,\n useUpdateEffect,\n} from \"../../utils\"\nimport INTL from \"./intl\"\n\nexport interface Language {\n dir: TextDirection\n locale: string\n}\n\nconst DEFAULT_LANGUAGE: Language = {\n dir: DEFAULT_DIRECTION,\n locale: DEFAULT_LOCALE,\n}\n\nexport const LOCALES = Object.keys(INTL) as readonly Locale[]\n\nexport function getLanguage(locale?: string, dir?: TextDirection): Language {\n locale ??= createdDom() ? navigator.language : DEFAULT_LOCALE\n\n try {\n Intl.DateTimeFormat.supportedLocalesOf([locale])\n } catch (_err) {\n locale = DEFAULT_LOCALE\n }\n\n dir ??= isRtl(locale) ? \"rtl\" : \"ltr\"\n\n return { dir, locale }\n}\n\ntype IntlData = DefaultIntlData\ntype IntlKey = keyof IntlData\ntype IntlPath = Path<IntlData>\n\nexport type Locale = keyof typeof INTL\n\ntype Translation<Y extends object = IntlData, M extends string = IntlPath> = <\n D extends M,\n>(\n path: D,\n ...args: IcuArgs<Value<Y, D>> extends never\n ? [replaceValues?: IcuArgs<Value<Y, D>, IntlPath | M>]\n : [replaceValues: IcuArgs<Value<Y, D>, IntlPath | M>]\n) => string\n\ninterface I18nContext<\n Y extends object = IntlData,\n M extends string = IntlPath,\n> extends Language {\n t: Translation<Y, M>\n changeLanguage: (locale?: string, dir?: TextDirection) => void\n getTranslation: (key?: IntlKey) => Translation<Y, M>\n}\n\nexport const I18nContext = createContext<I18nContext>({\n ...DEFAULT_LANGUAGE,\n changeLanguage: noop,\n getTranslation: () => () => \"\",\n t: () => \"\",\n})\n\nexport interface I18nProviderProps {\n children?: ReactNode\n /**\n * The text direction to apply to the application.\n *\n * If not provided, the direction will be determined by the locale.\n */\n dir?: TextDirection\n /**\n * The formats to pass to the `intlMessageFormat` instance.\n */\n formats?: Formats\n /**\n * The internationalization messages to apply to the application.\n *\n * This prop expects a dictionary object where the keys are locale strings (e.g., \"en-US\").\n */\n intl?: Dict\n /**\n * The options to pass to the `intlMessageFormat` instance.\n */\n intlMessageFormatOptions?: Options\n /**\n * The locale to apply to the application.\n *\n * If not provided, the locale will be determined by the browser.\n */\n locale?: AnyString | Locale\n}\n\nexport const I18nProvider: FC<I18nProviderProps> = ({\n children,\n dir: forcedDir,\n formats,\n intl = INTL as Dict,\n intlMessageFormatOptions,\n locale: forcedLocale,\n}) => {\n const [language, setLanguage] = useState(getLanguage(forcedLocale, forcedDir))\n const controlled = !isUndefined(forcedLocale)\n const { locale } = language\n\n const messages = useMemo(() => intl[locale], [intl, locale])\n\n const changeSystemLanguage = useCallback(() => {\n setLanguage(getLanguage())\n }, [])\n\n const changeLanguage = useCallback((locale?: string, dir?: TextDirection) => {\n setLanguage(getLanguage(locale, dir))\n }, [])\n\n const getValue = useCallback(\n (path: number | string) => {\n const value = get<string | undefined>(messages, path)\n\n if (!isUndefined(value)) {\n return value\n } else {\n path = path.toString().replace(/^[^.]+\\./g, \"\")\n\n return get<string | undefined>(messages, path)\n }\n },\n [messages],\n )\n\n const getTranslation = useCallback(\n (key?: IntlKey) =>\n <Y extends IntlPath>(\n path: Y,\n replaceValues?: IcuArgs<Value<IntlData, Y>, IntlPath>,\n ) => {\n const value = getValue(key ? `${key}.${path}` : path) ?? path\n\n if (isUndefined(replaceValues)) return value\n\n try {\n const resolvedReplaceValues = Object.entries(replaceValues).reduce<{\n [key: string]: any\n }>((prev, [key, pathOrValue]) => {\n if (isString(pathOrValue)) {\n const resolvedPathOrValue = String(pathOrValue)\n const value =\n getValue(\n key ? `${key}.${resolvedPathOrValue}` : resolvedPathOrValue,\n ) ?? resolvedPathOrValue\n\n prev[key] = value\n } else {\n prev[key] = pathOrValue\n }\n\n return prev\n }, {})\n\n const message = new IntlMessageFormat(\n value,\n locale,\n formats,\n intlMessageFormatOptions,\n )\n\n return message.format(resolvedReplaceValues) as string\n } catch (e) {\n if (e instanceof Error) console.warn(e.message)\n\n return value\n }\n },\n [getValue, locale, formats, intlMessageFormatOptions],\n )\n\n const value = useMemo(() => {\n const rest = { changeLanguage, getTranslation, t: getTranslation() }\n\n return { ...language, ...rest }\n }, [changeLanguage, getTranslation, language])\n\n useEffect(() => {\n if (controlled) return\n\n window.addEventListener(\"languagechange\", changeSystemLanguage)\n\n return () => {\n window.removeEventListener(\"languagechange\", changeSystemLanguage)\n }\n }, [controlled, changeSystemLanguage])\n\n useUpdateEffect(() => {\n setLanguage(getLanguage(forcedLocale, forcedDir))\n }, [forcedLocale, forcedDir])\n\n return <I18nContext value={value}>{children}</I18nContext>\n}\n\nexport function useI18n(): I18nContext\n\nexport function useI18n<Y extends IntlKey>(\n key: Y,\n): I18nContext<IntlData[Y], Path<IntlData[Y]>>\n\nexport function useI18n<Y extends IntlKey>(key?: Y) {\n const context = useContext(I18nContext)\n\n const translation = useCallback(\n <M extends Path<IntlData[Y]>>(\n path: M,\n replaceValues?: IcuArgs<\n Value<IntlData[Y], M>,\n IntlPath | Path<IntlData[Y]>\n >,\n ) => context.getTranslation(key)(path as any, replaceValues as any),\n [key, context],\n )\n\n if (isEmptyObject(context))\n return {\n ...DEFAULT_LANGUAGE,\n changeLanguage: noop,\n t: () => \"\",\n }\n\n if (key) return { ...context, t: translation }\n else return context\n}\n"],"mappings":";;;;;;;;;;;AAmCA,MAAM,mBAA6B;CACjC,KAAA;CACA,QAAQA,iBAAAA;AACV;AAEA,MAAa,UAAU,OAAO,KAAKC,0CAAI;AAEvC,SAAgB,YAAY,QAAiB,KAA+B;CAC1E,YAAA,GAAA,oBAAA,cAAW,WAAA,CAAW,IAAI,UAAU,WAAWD,iBAAAA;CAE/C,IAAI;EACF,KAAK,eAAe,mBAAmB,CAAC,MAAM,CAAC;CACjD,SAAS,MAAM;EACb,SAASA,iBAAAA;CACX;CAEA,SAAA,GAAA,oBAAA,cAAQ,MAAA,CAAM,MAAM,IAAI,QAAQ;CAEhC,OAAO;EAAE;EAAK;CAAO;AACvB;AA0BA,MAAa,eAAA,GAAcE,MAAAA,cAAAA,CAA2B;CACpD,GAAG;CACH,gBAAA,oBAAA,cAAgB;CAChB,4BAA4B;CAC5B,SAAS;AACX,CAAC;AAgCD,MAAa,gBAAuC,EAClD,UACA,KAAK,WACL,SACA,OAAOD,4CACP,0BACA,QAAQ,mBACJ;CACJ,MAAM,CAAC,UAAU,gBAAA,GAAeE,MAAAA,SAAAA,CAAS,YAAY,cAAc,SAAS,CAAC;CAC7E,MAAM,aAAa,EAAA,GAAA,oBAAA,cAAC,YAAA,CAAY,YAAY;CAC5C,MAAM,EAAE,WAAW;CAEnB,MAAM,YAAA,GAAWC,MAAAA,QAAAA,OAAc,KAAK,SAAS,CAAC,MAAM,MAAM,CAAC;CAE3D,MAAM,wBAAA,GAAuBC,MAAAA,YAAAA,OAAkB;EAC7C,YAAY,YAAY,CAAC;CAC3B,GAAG,CAAC,CAAC;CAEL,MAAM,kBAAA,GAAiBA,MAAAA,YAAAA,EAAa,QAAiB,QAAwB;EAC3E,YAAY,YAA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GAAG;GAAU,GAAG;EAAK;CAChC,GAAG;EAAC;EAAgB;EAAgB;CAAQ,CAAC;CAE7C,CAAA,GAAA,MAAA,UAAA,OAAgB;EACd,IAAI,YAAY;EAEhB,OAAO,iBAAiB,kBAAkB,oBAAoB;EAE9D,aAAa;GACX,OAAO,oBAAoB,kBAAkB,oBAAoB;EACnE;CACF,GAAG,CAAC,YAAY,oBAAoB,CAAC;CAErC,eAAA,sBAAsB;EACpB,YAAY,YAAY,cAAc,SAAS,CAAC;CAClD,GAAG,CAAC,cAAc,SAAS,CAAC;CAE5B,OAAO,iBAAA,GAAA,kBAAA,IAAA,CAAC,aAAD;EAAoB;EAAQ;CAAsB,CAAA;AAC3D;AAQA,SAAgB,QAA2B,KAAS;CAClD,MAAM,WAAA,GAAUI,MAAAA,WAAAA,CAAW,WAAW;CAEtC,MAAM,eAAA,GAAcH,MAAAA,YAAAA,EAEhB,MACA,kBAIG,QAAQ,eAAe,GAAG,CAAC,CAAC,MAAa,aAAoB,GAClE,CAAC,KAAK,OAAO,CACf;CAEA,KAAA,GAAA,oBAAA,cAAI,cAAA,CAAc,OAAO,GACvB,OAAO;EACL,GAAG;EACH,gBAAA,oBAAA,cAAgB;EAChB,SAAS;CACX;CAEF,IAAI,KAAK,OAAO;EAAE,GAAG;EAAS,GAAG;CAAY;MACxC,OAAO;AACd"}
1
+ {"version":3,"file":"i18n-provider.cjs","names":["DEFAULT_LOCALE","INTL","createContext","useMemo","useCallback","useState","get","IntlMessageFormat","useContext"],"sources":["../../../../src/providers/i18n-provider/i18n-provider.tsx"],"sourcesContent":["\"use client\"\n\nimport type { Formats, Options } from \"intl-messageformat\"\nimport type { FC, ReactNode } from \"react\"\nimport type { TextDirection } from \"../../core\"\nimport type { AnyString, Dict, Path, Value } from \"../../utils\"\nimport type { IcuArgs } from \"./icu.types\"\nimport type { DefaultIntlData } from \"./intl\"\nimport IntlMessageFormat from \"intl-messageformat\"\nimport {\n createContext,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useState,\n} from \"react\"\nimport { DEFAULT_DIRECTION, DEFAULT_LOCALE } from \"../../core\"\nimport {\n createdDom,\n getMemoizedObject as get,\n isEmptyObject,\n isRtl,\n isString,\n isUndefined,\n noop,\n useUpdateEffect,\n} from \"../../utils\"\nimport INTL from \"./intl\"\n\nexport interface Language {\n dir: TextDirection\n locale: string\n}\n\nconst DEFAULT_LANGUAGE: Language = {\n dir: DEFAULT_DIRECTION,\n locale: DEFAULT_LOCALE,\n}\n\nexport const LOCALES = Object.keys(INTL) as readonly Locale[]\n\ntype IntlData = DefaultIntlData\ntype IntlKey = keyof IntlData\ntype IntlPath = Path<IntlData>\n\nexport type Locale = keyof typeof INTL\n\ntype Translation<Y extends object = IntlData, M extends string = IntlPath> = <\n D extends M,\n>(\n path: D,\n ...args: IcuArgs<Value<Y, D>> extends never\n ? [replaceValues?: IcuArgs<Value<Y, D>, IntlPath | M>]\n : [replaceValues: IcuArgs<Value<Y, D>, IntlPath | M>]\n) => string\n\ninterface I18nContext<\n Y extends object = IntlData,\n M extends string = IntlPath,\n> extends Language {\n t: Translation<Y, M>\n changeLanguage: (locale?: string, dir?: TextDirection) => void\n getTranslation: (key?: IntlKey) => Translation<Y, M>\n}\n\nexport const I18nContext = createContext<I18nContext>({\n ...DEFAULT_LANGUAGE,\n changeLanguage: noop,\n getTranslation: () => () => \"\",\n t: () => \"\",\n})\n\nexport interface I18nProviderProps {\n children?: ReactNode\n /**\n * The text direction to apply to the application.\n *\n * If not provided, the direction will be determined by the locale.\n */\n dir?: TextDirection\n /**\n * The fallback locale to use if no matching locale is available.\n */\n fallbackLocale?: AnyString | Locale\n /**\n * The formats to pass to the `intlMessageFormat` instance.\n */\n formats?: Formats\n /**\n * The internationalization messages to apply to the application.\n *\n * This prop expects a dictionary object where the keys are locale strings (e.g., \"en-US\").\n */\n intl?: Dict\n /**\n * The options to pass to the `intlMessageFormat` instance.\n */\n intlMessageFormatOptions?: Options\n /**\n * The locale to apply to the application.\n *\n * If not provided, the locale will be determined by the browser.\n */\n locale?: AnyString | Locale\n}\n\nexport const I18nProvider: FC<I18nProviderProps> = ({\n children,\n dir: forcedDir,\n fallbackLocale = DEFAULT_LOCALE,\n formats,\n intl: forcedIntl,\n intlMessageFormatOptions,\n locale: forcedLocale,\n}) => {\n const intl = useMemo<Dict>(() => {\n if (!forcedIntl) return INTL\n\n if (isEmptyObject(forcedIntl)) return INTL\n\n return forcedIntl\n }, [forcedIntl])\n const locales = useMemo(() => Object.keys(intl), [intl])\n\n const getFallbackLocale = useCallback(\n (language?: string) => {\n if (language)\n for (const key of locales) if (key.startsWith(language)) return key\n\n if (locales.includes(fallbackLocale)) return fallbackLocale\n\n if (createdDom()) {\n try {\n const { language } = new Intl.Locale(fallbackLocale)\n\n for (const key of locales) if (key.startsWith(language)) return key\n } catch {\n return locales[0]!\n }\n } else {\n const language = fallbackLocale.split(\"-\")[0]!\n\n for (const key of locales) if (key.startsWith(language)) return key\n }\n\n return locales[0]!\n },\n [locales, fallbackLocale],\n )\n\n const getLocale = useCallback(\n (forcedLocale?: string) => {\n if (forcedLocale) {\n if (locales.includes(forcedLocale)) return forcedLocale\n\n const language = forcedLocale.split(\"-\")[0]!\n\n return getFallbackLocale(language)\n } else if (createdDom()) {\n try {\n const { language, region } = new Intl.Locale(navigator.language)\n const locale = `${language}-${region}`\n\n return locales.includes(locale) ? locale : getFallbackLocale(language)\n } catch {\n return getFallbackLocale()\n }\n } else {\n return getFallbackLocale()\n }\n },\n [locales, getFallbackLocale],\n )\n\n const getLanguage = useCallback(\n (locale?: string, dir?: TextDirection): Language => {\n locale = getLocale(locale)\n\n try {\n Intl.DateTimeFormat.supportedLocalesOf([locale])\n } catch {\n locale = getFallbackLocale()\n }\n\n dir ??= isRtl(locale) ? \"rtl\" : \"ltr\"\n\n return { dir, locale }\n },\n [getLocale, getFallbackLocale],\n )\n\n const [{ dir, locale }, setLanguage] = useState(\n getLanguage(forcedLocale, forcedDir),\n )\n const controlled = !isUndefined(forcedLocale)\n\n const messages = useMemo(() => intl[locale], [intl, locale])\n\n const changeSystemLanguage = useCallback(() => {\n setLanguage(getLanguage())\n }, [getLanguage])\n\n const changeLanguage = useCallback(\n (locale?: string, dir?: TextDirection) => {\n setLanguage(getLanguage(locale, dir))\n },\n [getLanguage],\n )\n\n const getValue = useCallback(\n (path: number | string) => {\n const value = get<string | undefined>(messages, path)\n\n if (!isUndefined(value)) {\n return value\n } else {\n path = path.toString().replace(/^[^.]+\\./g, \"\")\n\n return get<string | undefined>(messages, path)\n }\n },\n [messages],\n )\n\n const getTranslation = useCallback(\n (key?: IntlKey) =>\n <Y extends IntlPath>(\n path: Y,\n replaceValues?: IcuArgs<Value<IntlData, Y>, IntlPath>,\n ) => {\n const value = getValue(key ? `${key}.${path}` : path) ?? path\n\n if (isUndefined(replaceValues)) return value\n\n try {\n const resolvedReplaceValues = Object.entries(replaceValues).reduce<{\n [key: string]: any\n }>((prev, [key, pathOrValue]) => {\n if (isString(pathOrValue)) {\n const resolvedPathOrValue = String(pathOrValue)\n const value =\n getValue(\n key ? `${key}.${resolvedPathOrValue}` : resolvedPathOrValue,\n ) ?? resolvedPathOrValue\n\n prev[key] = value\n } else {\n prev[key] = pathOrValue\n }\n\n return prev\n }, {})\n\n const message = new IntlMessageFormat(\n value,\n locale,\n formats,\n intlMessageFormatOptions,\n )\n\n return message.format(resolvedReplaceValues) as string\n } catch (e) {\n if (e instanceof Error) console.warn(e.message)\n\n return value\n }\n },\n [getValue, locale, formats, intlMessageFormatOptions],\n )\n\n const value = useMemo(\n () => ({\n changeLanguage,\n dir,\n getTranslation,\n locale,\n t: getTranslation(),\n }),\n [changeLanguage, dir, getTranslation, locale],\n )\n\n useEffect(() => {\n if (controlled) return\n\n window.addEventListener(\"languagechange\", changeSystemLanguage)\n\n return () => {\n window.removeEventListener(\"languagechange\", changeSystemLanguage)\n }\n }, [controlled, changeSystemLanguage])\n\n useUpdateEffect(() => {\n setLanguage(getLanguage(forcedLocale, forcedDir))\n }, [forcedLocale, forcedDir, getLanguage])\n\n return <I18nContext value={value}>{children}</I18nContext>\n}\n\nexport function useI18n(): I18nContext\n\nexport function useI18n<Y extends IntlKey>(\n key: Y,\n): I18nContext<IntlData[Y], Path<IntlData[Y]>>\n\nexport function useI18n<Y extends IntlKey>(key?: Y) {\n const context = useContext(I18nContext)\n\n const translation = useCallback(\n <M extends Path<IntlData[Y]>>(\n path: M,\n replaceValues?: IcuArgs<\n Value<IntlData[Y], M>,\n IntlPath | Path<IntlData[Y]>\n >,\n ) => context.getTranslation(key)(path as any, replaceValues as any),\n [key, context],\n )\n\n if (isEmptyObject(context))\n return {\n ...DEFAULT_LANGUAGE,\n changeLanguage: noop,\n t: () => \"\",\n }\n\n if (key) return { ...context, t: translation }\n else return context\n}\n"],"mappings":";;;;;;;;;;;AAmCA,MAAM,mBAA6B;CACjC,KAAA;CACA,QAAQA,iBAAAA;AACV;AAEA,MAAa,UAAU,OAAO,KAAKC,0CAAI;AA0BvC,MAAa,eAAA,GAAcC,MAAAA,cAAAA,CAA2B;CACpD,GAAG;CACH,gBAAA,oBAAA,cAAgB;CAChB,4BAA4B;CAC5B,SAAS;AACX,CAAC;AAoCD,MAAa,gBAAuC,EAClD,UACA,KAAK,WACL,iBAAiBF,iBAAAA,gBACjB,SACA,MAAM,YACN,0BACA,QAAQ,mBACJ;CACJ,MAAM,QAAA,GAAOG,MAAAA,QAAAA,OAAoB;EAC/B,IAAI,CAAC,YAAY,OAAOF;EAExB,KAAA,GAAA,oBAAA,cAAI,cAAA,CAAc,UAAU,GAAG,OAAOA;EAEtC,OAAO;CACT,GAAG,CAAC,UAAU,CAAC;CACf,MAAM,WAAA,GAAUE,MAAAA,QAAAA,OAAc,OAAO,KAAK,IAAI,GAAG,CAAC,IAAI,CAAC;CAEvD,MAAM,qBAAA,GAAoBC,MAAAA,YAAAA,EACvB,aAAsB;EACrB,IAAI,UACG;QAAA,MAAM,OAAO,SAAS,IAAI,IAAI,WAAW,QAAQ,GAAG,OAA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OAAO;AACd"}
@@ -4,6 +4,5 @@ const require_i18n_provider = require("./i18n-provider.cjs");
4
4
  exports.I18nContext = require_i18n_provider.I18nContext;
5
5
  exports.I18nProvider = require_i18n_provider.I18nProvider;
6
6
  exports.LOCALES = require_i18n_provider.LOCALES;
7
- exports.getLanguage = require_i18n_provider.getLanguage;
8
7
  exports.i18nCache = require_i18n_cache.i18nCache;
9
8
  exports.useI18n = require_i18n_provider.useI18n;
@@ -13,12 +13,15 @@ let react_jsx_runtime = require("react/jsx-runtime");
13
13
  /**
14
14
  * The global provider that must be added to make all Yamada UI components work correctly.
15
15
  */
16
- const UIProvider = ({ children, colorMode, colorModeStorageKey, config: config$1 = require_config.config, cookie, dir, intl, locale, rootNode, storage, theme: theme$1 = require_theme_index.theme, themeSchemeStorageKey }) => {
16
+ const UIProvider = ({ children, colorMode, colorModeStorageKey, config: config$1 = require_config.config, cookie, dir, fallbackLocale, formats, intl, intlMessageFormatOptions, locale, rootNode, storage, theme: theme$1 = require_theme_index.theme, themeSchemeStorageKey }) => {
17
17
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_environment_provider.EnvironmentProvider, {
18
18
  value: rootNode,
19
19
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_i18n_provider.I18nProvider, {
20
20
  dir,
21
+ fallbackLocale,
22
+ formats,
21
23
  intl,
24
+ intlMessageFormatOptions,
22
25
  locale,
23
26
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_system_provider.SystemProvider, {
24
27
  config: config$1,
@@ -1 +1 @@
1
- {"version":3,"file":"ui-provider.cjs","names":["defaultConfig","defaultTheme","EnvironmentProvider","I18nProvider","SystemProvider","config","theme","ThemeProvider","ColorModeProvider","LoadingProvider","NoticeProvider"],"sources":["../../../../src/providers/ui-provider/ui-provider.tsx"],"sourcesContent":["import type { FC } from \"react\"\nimport type {\n ColorModeProviderProps,\n EnvironmentProviderProps,\n ThemeConfig,\n ThemeProviderProps,\n UsageTheme,\n} from \"../../core\"\nimport type { DeepMerge } from \"../../utils\"\nimport type { I18nProviderProps } from \"../i18n-provider\"\nimport { LoadingProvider } from \"../../components/loading\"\nimport { NoticeProvider } from \"../../components/notice\"\nimport {\n ColorModeProvider,\n EnvironmentProvider,\n SystemProvider,\n ThemeProvider,\n} from \"../../core\"\nimport { config as defaultConfig, theme as defaultTheme } from \"../../theme\"\nimport { merge } from \"../../utils\"\nimport { I18nProvider } from \"../i18n-provider\"\n\nexport interface UIProviderProps\n extends\n Omit<ThemeProviderProps, \"storageKey\">,\n Pick<ColorModeProviderProps, \"colorMode\">,\n I18nProviderProps {\n /**\n * Key of value saved in storage.\n * By default, it is saved to `local storage`.\n */\n colorModeStorageKey?: string\n /**\n * The root node to use.\n */\n rootNode?: EnvironmentProviderProps[\"value\"]\n /**\n * Key of value saved in storage.\n * By default, it is saved to `local storage`.\n */\n themeSchemeStorageKey?: string\n}\n\n/**\n * The global provider that must be added to make all Yamada UI components work correctly.\n */\nexport const UIProvider: FC<UIProviderProps> = ({\n children,\n colorMode,\n colorModeStorageKey,\n config = defaultConfig,\n cookie,\n dir,\n intl,\n locale,\n rootNode,\n storage,\n theme = defaultTheme,\n themeSchemeStorageKey,\n}) => {\n return (\n <EnvironmentProvider value={rootNode}>\n <I18nProvider dir={dir} intl={intl} locale={locale}>\n <SystemProvider config={config} theme={theme}>\n <ThemeProvider\n config={config}\n cookie={cookie}\n storage={storage}\n storageKey={themeSchemeStorageKey}\n theme={theme}\n >\n <ColorModeProvider\n colorMode={colorMode}\n config={config}\n cookie={cookie}\n storage={storage}\n storageKey={colorModeStorageKey}\n >\n <LoadingProvider {...config.loading}>\n <NoticeProvider {...config.notice}>{children}</NoticeProvider>\n </LoadingProvider>\n </ColorModeProvider>\n </ThemeProvider>\n </SystemProvider>\n </I18nProvider>\n </EnvironmentProvider>\n )\n}\n\ntype DefaultTheme = typeof defaultTheme\n\nexport const extendTheme = <Y extends UsageTheme>(theme: Y) => {\n return merge<DeepMerge<DefaultTheme, Y>>(defaultTheme, theme)\n}\n\nexport const extendConfig = (config: ThemeConfig) => {\n return merge(defaultConfig, config)\n}\n"],"mappings":";;;;;;;;;;;;;;;AA8CA,MAAa,cAAmC,EAC9C,UACA,WACA,qBACA,QAAA,WAASA,eAAAA,QACT,QACA,KACA,MACA,QACA,UACA,SACA,OAAA,UAAQC,oBAAAA,OACR,4BACI;CACJ,OACE,iBAAA,GAAA,kBAAA,IAAA,CAACC,6BAAAA,qBAAD;EAAqB,OAAO;EAC1B,UAAA,iBAAA,GAAA,kBAAA,IAAA,CAACC,sBAAAA,cAAD;GAAmB;GAAW;GAAc;GAC1C,UAAA,iBAAA,GAAA,kBAAA,IAAA,CAACC,wBAAAA,gBAAD;IAAgB,QAAQC;IAAQ,OAAOC;IACrC,UAAA,iBAAA,GAAA,kBAAA,IAAA,CAACC,uBAAAA,eAAD;KACE,QAAQF;KACA;KACC;KACT,YAAY;KACZ,OAAOC;KAEP,UAAA,iBAAA,GAAA,kBAAA,IAAA,CAACE,4BAAAA,mBAAD;MACa;MACX,QAAQH;MACA;MACC;MACT,YAAY;MAEZ,UAAA,iBAAA,GAAA,kBAAA,IAAA,CAACI,yBAAAA,iBAAD;OAAiB,GAAIJ,SAAO;OAC1B,UAAA,iBAAA,GAAA,kBAAA,IAAA,CAACK,wBAAAA,gBAAD;QAAgB,GAAIL,SAAO;QAAS;OAAyB,CAAA;MAC9C,CAAA;KACA,CAAA;IACN,CAAA;GACD,CAAA;EACJ,CAAA;CACK,CAAA;AAEzB;AAIA,MAAa,eAAqC,YAAa;CAC7D,QAAA,GAAA,oBAAA,cAAO,MAAA,CAAkCJ,oBAAAA,OAAcK,OAAK;AAC9D;AAEA,MAAa,gBAAgB,aAAwB;CACnD,QAAA,GAAA,oBAAA,cAAO,MAAA,CAAMN,eAAAA,QAAeK,QAAM;AACpC"}
1
+ {"version":3,"file":"ui-provider.cjs","names":["defaultConfig","defaultTheme","EnvironmentProvider","I18nProvider","SystemProvider","config","theme","ThemeProvider","ColorModeProvider","LoadingProvider","NoticeProvider"],"sources":["../../../../src/providers/ui-provider/ui-provider.tsx"],"sourcesContent":["import type { FC } from \"react\"\nimport type {\n ColorModeProviderProps,\n EnvironmentProviderProps,\n ThemeConfig,\n ThemeProviderProps,\n UsageTheme,\n} from \"../../core\"\nimport type { DeepMerge } from \"../../utils\"\nimport type { I18nProviderProps } from \"../i18n-provider\"\nimport { LoadingProvider } from \"../../components/loading\"\nimport { NoticeProvider } from \"../../components/notice\"\nimport {\n ColorModeProvider,\n EnvironmentProvider,\n SystemProvider,\n ThemeProvider,\n} from \"../../core\"\nimport { config as defaultConfig, theme as defaultTheme } from \"../../theme\"\nimport { merge } from \"../../utils\"\nimport { I18nProvider } from \"../i18n-provider\"\n\nexport interface UIProviderProps\n extends\n Omit<ThemeProviderProps, \"storageKey\">,\n Pick<ColorModeProviderProps, \"colorMode\">,\n I18nProviderProps {\n /**\n * Key of value saved in storage.\n * By default, it is saved to `local storage`.\n */\n colorModeStorageKey?: string\n /**\n * The root node to use.\n */\n rootNode?: EnvironmentProviderProps[\"value\"]\n /**\n * Key of value saved in storage.\n * By default, it is saved to `local storage`.\n */\n themeSchemeStorageKey?: string\n}\n\n/**\n * The global provider that must be added to make all Yamada UI components work correctly.\n */\nexport const UIProvider: FC<UIProviderProps> = ({\n children,\n colorMode,\n colorModeStorageKey,\n config = defaultConfig,\n cookie,\n dir,\n fallbackLocale,\n formats,\n intl,\n intlMessageFormatOptions,\n locale,\n rootNode,\n storage,\n theme = defaultTheme,\n themeSchemeStorageKey,\n}) => {\n return (\n <EnvironmentProvider value={rootNode}>\n <I18nProvider\n dir={dir}\n fallbackLocale={fallbackLocale}\n formats={formats}\n intl={intl}\n intlMessageFormatOptions={intlMessageFormatOptions}\n locale={locale}\n >\n <SystemProvider config={config} theme={theme}>\n <ThemeProvider\n config={config}\n cookie={cookie}\n storage={storage}\n storageKey={themeSchemeStorageKey}\n theme={theme}\n >\n <ColorModeProvider\n colorMode={colorMode}\n config={config}\n cookie={cookie}\n storage={storage}\n storageKey={colorModeStorageKey}\n >\n <LoadingProvider {...config.loading}>\n <NoticeProvider {...config.notice}>{children}</NoticeProvider>\n </LoadingProvider>\n </ColorModeProvider>\n </ThemeProvider>\n </SystemProvider>\n </I18nProvider>\n </EnvironmentProvider>\n )\n}\n\ntype DefaultTheme = typeof defaultTheme\n\nexport const extendTheme = <Y extends UsageTheme>(theme: Y) => {\n return merge<DeepMerge<DefaultTheme, Y>>(defaultTheme, theme)\n}\n\nexport const extendConfig = (config: ThemeConfig) => {\n return merge(defaultConfig, config)\n}\n"],"mappings":";;;;;;;;;;;;;;;AA8CA,MAAa,cAAmC,EAC9C,UACA,WACA,qBACA,QAAA,WAASA,eAAAA,QACT,QACA,KACA,gBACA,SACA,MACA,0BACA,QACA,UACA,SACA,OAAA,UAAQC,oBAAAA,OACR,4BACI;CACJ,OACE,iBAAA,GAAA,kBAAA,IAAA,CAACC,6BAAAA,qBAAD;EAAqB,OAAO;EAC1B,UAAA,iBAAA,GAAA,kBAAA,IAAA,CAACC,sBAAAA,cAAD;GACO;GACW;GACP;GACH;GACoB;GAClB;GAER,UAAA,iBAAA,GAAA,kBAAA,IAAA,CAACC,wBAAAA,gBAAD;IAAgB,QAAQC;IAAQ,OAAOC;IACrC,UAAA,iBAAA,GAAA,kBAAA,IAAA,CAACC,uBAAAA,eAAD;KACE,QAAQF;KACA;KACC;KACT,YAAY;KACZ,OAAOC;KAEP,UAAA,iBAAA,GAAA,kBAAA,IAAA,CAACE,4BAAAA,mBAAD;MACa;MACX,QAAQH;MACA;MACC;MACT,YAAY;MAEZ,UAAA,iBAAA,GAAA,kBAAA,IAAA,CAACI,yBAAAA,iBAAD;OAAiB,GAAIJ,SAAO;OAC1B,UAAA,iBAAA,GAAA,kBAAA,IAAA,CAACK,wBAAAA,gBAAD;QAAgB,GAAIL,SAAO;QAAS;OAAyB,CAAA;MAC9C,CAAA;KACA,CAAA;IACN,CAAA;GACD,CAAA;EACJ,CAAA;CACK,CAAA;AAEzB;AAIA,MAAa,eAAqC,YAAa;CAC7D,QAAA,GAAA,oBAAA,cAAO,MAAA,CAAkCJ,oBAAAA,OAAcK,OAAK;AAC9D;AAEA,MAAa,gBAAgB,aAAwB;CACnD,QAAA,GAAA,oBAAA,cAAO,MAAA,CAAMN,eAAAA,QAAeK,QAAM;AACpC"}
@@ -64,10 +64,9 @@ const usePopover = ({ autoFocus = true, autoUpdate, modal = false, blockScrollOn
64
64
  ]);
65
65
  const onBlur = useCallback((ev) => {
66
66
  const relatedTarget = getEventRelatedTarget(ev);
67
- const popup = relatedTarget?.hasAttribute("data-popup");
67
+ if (relatedTarget?.closest("[data-popup]")) return;
68
68
  if ((0, utils_exports.contains)(triggerRef.current, relatedTarget)) return;
69
69
  if ((0, utils_exports.contains)(contentRef.current, relatedTarget)) return;
70
- if ((0, utils_exports.contains)(contentRef.current, ev.target) && popup) return;
71
70
  if (closeOnBlur) onClose();
72
71
  }, [closeOnBlur, onClose]);
73
72
  useEventListener(getDocument(), "scroll", () => {
@@ -1 +1 @@
1
- {"version":3,"file":"use-popover.js","names":["contains","focusTrap","scrollLock","focusTransfer","ariaAttr","handlerAll","dataAttr"],"sources":["../../../../src/components/popover/use-popover.tsx"],"sourcesContent":["\"use client\"\n\nimport type { FocusEvent, KeyboardEvent, RefObject } from \"react\"\nimport type { Direction, PropGetter } from \"../../core\"\nimport type { UseDisclosureProps } from \"../../hooks/use-disclosure\"\nimport type { UsePopperProps } from \"../../hooks/use-popper\"\nimport type { Dict } from \"../../utils\"\nimport type { UsePopupAnimationProps } from \"./popover\"\nimport { useCallback, useEffect, useId, useRef } from \"react\"\nimport { useEnvironment, useSplitProps } from \"../../core\"\nimport { useDisclosure } from \"../../hooks/use-disclosure\"\nimport { useEventListener } from \"../../hooks/use-event-listener\"\nimport { useFocusOnShow } from \"../../hooks/use-focus\"\nimport { useOutsideClick } from \"../../hooks/use-outside-click\"\nimport { popperProps, usePopper } from \"../../hooks/use-popper\"\nimport {\n ariaAttr,\n assignRef,\n contains,\n dataAttr,\n focusTransfer,\n focusTrap,\n getEventRelatedTarget,\n handlerAll,\n mergeRefs,\n runKeyAction,\n scrollLock,\n setAttribute,\n useSafeLayoutEffect,\n useUnmountEffect,\n} from \"../../utils\"\n\nexport interface UsePopoverProps\n extends Omit<UseDisclosureProps, \"timing\">, UsePopperProps<\"button\"> {\n /**\n * If `true`, focus will be transferred to the first interactive element when the popover opens.\n *\n * @default true\n */\n autoFocus?: boolean\n /**\n * If `true`, scrolling will be disabled on the `body` when the modal opens.\n *\n * @default false\n */\n blockScrollOnMount?: boolean\n /**\n * If `true`, the popover will close when you blur out it by clicking outside or tabbing out.\n *\n * @default true\n */\n closeOnBlur?: boolean\n /**\n * If `true`, the popover will hide on pressing Esc key.\n *\n * @default true\n */\n closeOnEsc?: boolean\n /**\n * If `true`, the popover will hide on scroll.\n *\n * @default false\n */\n closeOnScroll?: boolean\n /**\n * If `true`, the popover will be disabled.\n *\n * @default false\n */\n disabled?: boolean\n /**\n * The `ref` of the element that should receive focus when the popover opens.\n */\n initialFocusRef?: RefObject<HTMLElement | null>\n /**\n * If `true`, the popover will be modal.\n *\n * - scrolling is blocked.\n * - focus is trapped within the popover.\n *\n * @default false\n */\n modal?: boolean\n /**\n * If `true`, the popover will be opened when click on the field.\n *\n * @default true\n */\n openOnClick?: boolean\n /**\n * The placement of the popper relative to its reference.\n *\n * @default 'end'\n */\n placement?: Direction\n /**\n * If `true`, the focus will be transferred to the popover content when the tab key is pressed.\n *\n * @default true\n */\n transferFocus?: boolean\n /**\n * Update the position of the floating element, re-rendering the component if required.\n */\n updateRef?: RefObject<() => void>\n}\n\nexport const usePopover = ({\n autoFocus = true,\n autoUpdate,\n modal = false,\n blockScrollOnMount = modal,\n closeOnBlur = true,\n closeOnEsc = true,\n closeOnScroll,\n defaultOpen,\n disabled,\n elements,\n flip,\n gutter,\n initialFocusRef,\n matchWidth,\n middleware,\n offset,\n open: openProp,\n openOnClick = true,\n placement = \"end\",\n platform,\n preventOverflow,\n strategy,\n transferFocus = true,\n transform,\n updateRef,\n whileElementsMounted,\n onClose: onCloseProp,\n onOpen: onOpenProp,\n}: UsePopoverProps = {}) => {\n const { getDocument } = useEnvironment()\n const headerId = useId()\n const bodyId = useId()\n const contentId = useId()\n const anchorRef = useRef<HTMLElement>(null)\n const triggerRef = useRef<HTMLButtonElement>(null)\n const contentRef = useRef<HTMLElement>(null)\n const openTimeout = useRef<NodeJS.Timeout>(undefined)\n const closeTimeout = useRef<NodeJS.Timeout>(undefined)\n const { open, onClose, onOpen } = useDisclosure({\n defaultOpen,\n open: openProp,\n onClose: onCloseProp,\n onOpen: onOpenProp,\n })\n const { refs, update, getPopperProps } = usePopper<\"button\">({\n autoUpdate,\n elements,\n flip,\n gutter,\n matchWidth,\n middleware,\n offset,\n open,\n placement,\n platform,\n preventOverflow,\n strategy,\n transform,\n whileElementsMounted,\n })\n\n assignRef(updateRef, update)\n\n const onRestoreFocus = useCallback(() => {\n clearTimeout(closeTimeout.current)\n closeTimeout.current = setTimeout(() => {\n triggerRef.current?.focus()\n })\n }, [])\n\n const onKeyDown = useCallback(\n (ev: KeyboardEvent<HTMLElement>) => {\n runKeyAction(ev, {\n Escape: () => {\n if (!closeOnEsc) return\n\n onClose()\n onRestoreFocus()\n },\n })\n },\n [closeOnEsc, onClose, onRestoreFocus],\n )\n\n const onBlur = useCallback(\n (ev: FocusEvent<HTMLDivElement>) => {\n const relatedTarget = getEventRelatedTarget(ev)\n const popup = relatedTarget?.hasAttribute(\"data-popup\")\n\n if (contains(triggerRef.current, relatedTarget)) return\n if (contains(contentRef.current, relatedTarget)) return\n if (contains(contentRef.current, ev.target) && popup) return\n\n if (closeOnBlur) onClose()\n },\n [closeOnBlur, onClose],\n )\n\n useEventListener(getDocument(), \"scroll\", () => {\n if (open && closeOnScroll) onClose()\n })\n\n useFocusOnShow(contentRef, {\n focusTarget: initialFocusRef,\n shouldFocus: autoFocus,\n visible: open,\n })\n\n useOutsideClick({\n ref: [contentRef, triggerRef],\n enabled: open && closeOnBlur,\n handler: onClose,\n })\n\n useSafeLayoutEffect(() => {\n const el = contentRef.current\n const hasHeader = !!getDocument()?.getElementById(headerId)\n const hasBody = !!getDocument()?.getElementById(bodyId)\n\n if (el && hasHeader) setAttribute(el, \"aria-labelledby\", headerId)\n if (el && hasBody) setAttribute(el, \"aria-describedby\", bodyId)\n }, [open, headerId, bodyId])\n\n useEffect(() => {\n if (!open || !modal) return\n\n return focusTrap(contentRef.current)\n }, [open, modal])\n\n useEffect(() => {\n if (!open || !blockScrollOnMount) return\n\n return scrollLock(contentRef.current)\n }, [open, modal, blockScrollOnMount])\n\n useEffect(() => {\n if (!open || modal || !transferFocus) return\n\n return focusTransfer(contentRef.current, triggerRef.current)\n }, [open, modal, transferFocus])\n\n useUnmountEffect(() => {\n clearTimeout(openTimeout.current)\n clearTimeout(closeTimeout.current)\n })\n\n const getTriggerProps: PropGetter<\"button\"> = useCallback(\n ({ ref, ...props } = {}) => ({\n \"aria-controls\": open ? contentId : undefined,\n \"aria-disabled\": ariaAttr(disabled),\n \"aria-expanded\": open,\n \"aria-haspopup\": \"dialog\",\n role: \"button\",\n ...props,\n ref: mergeRefs(ref, triggerRef, (node) => {\n if (anchorRef.current == null) refs.setReference(node)\n }),\n onBlur: handlerAll(props.onBlur, (ev) =>\n !contains(contentRef.current, getEventRelatedTarget(ev)) && closeOnBlur\n ? onClose()\n : void 0,\n ),\n onClick: handlerAll(\n props.onClick,\n !open ? (!disabled && openOnClick ? onOpen : undefined) : onClose,\n ),\n onKeyDown: handlerAll(props.onKeyDown, onKeyDown),\n }),\n [\n closeOnBlur,\n contentId,\n disabled,\n onClose,\n onKeyDown,\n onOpen,\n open,\n openOnClick,\n refs,\n ],\n )\n\n const getAnchorProps: PropGetter = useCallback(\n ({ ref, ...props } = {}) => ({\n ...props,\n ref: mergeRefs(ref, anchorRef, refs.setReference),\n }),\n [refs.setReference],\n )\n\n const getPositionerProps: PropGetter = useCallback(\n (props) => getPopperProps(props),\n [getPopperProps],\n )\n\n const getContentProps: PropGetter = useCallback(\n ({ ref, ...props } = {}) => ({\n id: contentId,\n \"aria-hidden\": !open,\n \"aria-modal\": modal ? \"true\" : undefined,\n \"data-close\": dataAttr(!open),\n \"data-open\": dataAttr(open),\n \"data-popup\": dataAttr(true),\n role: \"dialog\",\n tabIndex: -1,\n ...props,\n ref: mergeRefs(ref, contentRef),\n onBlur: handlerAll(props.onBlur, onBlur),\n onKeyDown: handlerAll(props.onKeyDown, onKeyDown),\n }),\n [contentId, open, modal, onBlur, onKeyDown],\n )\n\n const getHeaderProps: PropGetter = useCallback(\n (props) => ({ id: headerId, ...props }),\n [headerId],\n )\n\n const getBodyProps: PropGetter = useCallback(\n (props) => ({ id: bodyId, ...props }),\n [bodyId],\n )\n\n const getFooterProps: PropGetter = useCallback((props) => ({ ...props }), [])\n\n const getCloseTriggerProps: PropGetter<\"button\"> = useCallback(\n (props = {}) => ({\n ...props,\n onClick: handlerAll(props.onClick, () => {\n onClose()\n onRestoreFocus()\n }),\n }),\n [onClose, onRestoreFocus],\n )\n\n return {\n open,\n getAnchorProps,\n getBodyProps,\n getCloseTriggerProps,\n getContentProps,\n getFooterProps,\n getHeaderProps,\n getPositionerProps,\n getTriggerProps,\n onClose,\n onOpen,\n }\n}\n\nexport type UsePopoverReturn = ReturnType<typeof usePopover>\n\nexport const popoverProps: (\n | keyof UsePopoverProps\n | keyof UsePopupAnimationProps\n)[] = [\n ...popperProps,\n \"autoFocus\",\n \"transferFocus\",\n \"blockScrollOnMount\",\n \"closeOnBlur\",\n \"closeOnEsc\",\n \"closeOnScroll\",\n \"openOnClick\",\n \"disabled\",\n \"initialFocusRef\",\n \"modal\",\n \"updateRef\",\n \"defaultOpen\",\n \"onOpen\",\n \"onClose\",\n \"animationScheme\",\n \"duration\",\n]\n\nexport const usePopoverProps = <\n Y extends Dict = Dict,\n M extends keyof UsePopoverProps | keyof UsePopupAnimationProps =\n | keyof UsePopoverProps\n | keyof UsePopupAnimationProps,\n>(\n props: Y,\n omitKeys?: M[],\n) => {\n return useSplitProps(\n props,\n popoverProps.filter((key) => !omitKeys?.includes(key as M)),\n ) as unknown as [\n keyof UsePopoverProps | keyof UsePopupAnimationProps extends M\n ? UsePopoverProps & UsePopupAnimationProps\n : Omit<UsePopoverProps & UsePopupAnimationProps, M>,\n Omit<\n Y,\n keyof UsePopoverProps | keyof UsePopupAnimationProps extends M\n ? keyof UsePopoverProps | keyof UsePopupAnimationProps\n : Exclude<keyof UsePopoverProps | keyof UsePopupAnimationProps, M>\n >,\n ]\n}\n"],"mappings":";;;;;;;;;;;;;;AA2GA,MAAa,cAAc,EACzB,YAAY,MACZ,YACA,QAAQ,OACR,qBAAqB,OACrB,cAAc,MACd,aAAa,MACb,eACA,aACA,UACA,UACA,MACA,QACA,iBACA,YACA,YACA,QACA,MAAM,UACN,cAAc,MACd,YAAY,OACZ,UACA,iBACA,UACA,gBAAgB,MAChB,WACA,WACA,sBACA,SAAS,aACT,QAAQ,eACW,CAAC,MAAM;CAC1B,MAAM,EAAE,gBAAgB,eAAe;CACvC,MAAM,WAAW,MAAM;CACvB,MAAM,SAAS,MAAM;CACrB,MAAM,YAAY,MAAM;CACxB,MAAM,YAAY,OAAoB,IAAI;CAC1C,MAAM,aAAa,OAA0B,IAAI;CACjD,MAAM,aAAa,OAAoB,IAAI;CAC3C,MAAM,cAAc,OAAuB,KAAA,CAAS;CACpD,MAAM,eAAe,OAAuB,KAAA,CAAS;CACrD,MAAM,EAAE,MAAM,SAAS,WAAW,cAAc;EAC9C;EACA,MAAM;EACN,SAAS;EACT,QAAQ;CACV,CAAC;CACD,MAAM,EAAE,MAAM,QAAQ,mBAAmB,UAAoB;EAC3D;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;CAED,UAAU,WAAW,MAAM;CAE3B,MAAM,iBAAiB,kBAAkB;EACvC,aAAa,aAAa,OAAO;EACjC,aA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ACA;CACA;CACA;CACA;CACA;AACF;AAEA,MAAa,mBAMX,OACA,aACG;CACH,OAAO,cACL,OACA,aAAa,QAAQ,QAAQ,CAAC,UAAU,SAAS,GAAQ,CAAC,CAC5D;AAWF"}
1
+ {"version":3,"file":"use-popover.js","names":["contains","focusTrap","scrollLock","focusTransfer","ariaAttr","handlerAll","dataAttr"],"sources":["../../../../src/components/popover/use-popover.tsx"],"sourcesContent":["\"use client\"\n\nimport type { FocusEvent, KeyboardEvent, RefObject } from \"react\"\nimport type { Direction, PropGetter } from \"../../core\"\nimport type { UseDisclosureProps } from \"../../hooks/use-disclosure\"\nimport type { UsePopperProps } from \"../../hooks/use-popper\"\nimport type { Dict } from \"../../utils\"\nimport type { UsePopupAnimationProps } from \"./popover\"\nimport { useCallback, useEffect, useId, useRef } from \"react\"\nimport { useEnvironment, useSplitProps } from \"../../core\"\nimport { useDisclosure } from \"../../hooks/use-disclosure\"\nimport { useEventListener } from \"../../hooks/use-event-listener\"\nimport { useFocusOnShow } from \"../../hooks/use-focus\"\nimport { useOutsideClick } from \"../../hooks/use-outside-click\"\nimport { popperProps, usePopper } from \"../../hooks/use-popper\"\nimport {\n ariaAttr,\n assignRef,\n contains,\n dataAttr,\n focusTransfer,\n focusTrap,\n getEventRelatedTarget,\n handlerAll,\n mergeRefs,\n runKeyAction,\n scrollLock,\n setAttribute,\n useSafeLayoutEffect,\n useUnmountEffect,\n} from \"../../utils\"\n\nexport interface UsePopoverProps\n extends Omit<UseDisclosureProps, \"timing\">, UsePopperProps<\"button\"> {\n /**\n * If `true`, focus will be transferred to the first interactive element when the popover opens.\n *\n * @default true\n */\n autoFocus?: boolean\n /**\n * If `true`, scrolling will be disabled on the `body` when the modal opens.\n *\n * @default false\n */\n blockScrollOnMount?: boolean\n /**\n * If `true`, the popover will close when you blur out it by clicking outside or tabbing out.\n *\n * @default true\n */\n closeOnBlur?: boolean\n /**\n * If `true`, the popover will hide on pressing Esc key.\n *\n * @default true\n */\n closeOnEsc?: boolean\n /**\n * If `true`, the popover will hide on scroll.\n *\n * @default false\n */\n closeOnScroll?: boolean\n /**\n * If `true`, the popover will be disabled.\n *\n * @default false\n */\n disabled?: boolean\n /**\n * The `ref` of the element that should receive focus when the popover opens.\n */\n initialFocusRef?: RefObject<HTMLElement | null>\n /**\n * If `true`, the popover will be modal.\n *\n * - scrolling is blocked.\n * - focus is trapped within the popover.\n *\n * @default false\n */\n modal?: boolean\n /**\n * If `true`, the popover will be opened when click on the field.\n *\n * @default true\n */\n openOnClick?: boolean\n /**\n * The placement of the popper relative to its reference.\n *\n * @default 'end'\n */\n placement?: Direction\n /**\n * If `true`, the focus will be transferred to the popover content when the tab key is pressed.\n *\n * @default true\n */\n transferFocus?: boolean\n /**\n * Update the position of the floating element, re-rendering the component if required.\n */\n updateRef?: RefObject<() => void>\n}\n\nexport const usePopover = ({\n autoFocus = true,\n autoUpdate,\n modal = false,\n blockScrollOnMount = modal,\n closeOnBlur = true,\n closeOnEsc = true,\n closeOnScroll,\n defaultOpen,\n disabled,\n elements,\n flip,\n gutter,\n initialFocusRef,\n matchWidth,\n middleware,\n offset,\n open: openProp,\n openOnClick = true,\n placement = \"end\",\n platform,\n preventOverflow,\n strategy,\n transferFocus = true,\n transform,\n updateRef,\n whileElementsMounted,\n onClose: onCloseProp,\n onOpen: onOpenProp,\n}: UsePopoverProps = {}) => {\n const { getDocument } = useEnvironment()\n const headerId = useId()\n const bodyId = useId()\n const contentId = useId()\n const anchorRef = useRef<HTMLElement>(null)\n const triggerRef = useRef<HTMLButtonElement>(null)\n const contentRef = useRef<HTMLElement>(null)\n const openTimeout = useRef<NodeJS.Timeout>(undefined)\n const closeTimeout = useRef<NodeJS.Timeout>(undefined)\n const { open, onClose, onOpen } = useDisclosure({\n defaultOpen,\n open: openProp,\n onClose: onCloseProp,\n onOpen: onOpenProp,\n })\n const { refs, update, getPopperProps } = usePopper<\"button\">({\n autoUpdate,\n elements,\n flip,\n gutter,\n matchWidth,\n middleware,\n offset,\n open,\n placement,\n platform,\n preventOverflow,\n strategy,\n transform,\n whileElementsMounted,\n })\n\n assignRef(updateRef, update)\n\n const onRestoreFocus = useCallback(() => {\n clearTimeout(closeTimeout.current)\n closeTimeout.current = setTimeout(() => {\n triggerRef.current?.focus()\n })\n }, [])\n\n const onKeyDown = useCallback(\n (ev: KeyboardEvent<HTMLElement>) => {\n runKeyAction(ev, {\n Escape: () => {\n if (!closeOnEsc) return\n\n onClose()\n onRestoreFocus()\n },\n })\n },\n [closeOnEsc, onClose, onRestoreFocus],\n )\n\n const onBlur = useCallback(\n (ev: FocusEvent<HTMLDivElement>) => {\n const relatedTarget = getEventRelatedTarget(ev)\n const popup = relatedTarget?.closest(\"[data-popup]\")\n\n if (popup) return\n if (contains(triggerRef.current, relatedTarget)) return\n if (contains(contentRef.current, relatedTarget)) return\n\n if (closeOnBlur) onClose()\n },\n [closeOnBlur, onClose],\n )\n\n useEventListener(getDocument(), \"scroll\", () => {\n if (open && closeOnScroll) onClose()\n })\n\n useFocusOnShow(contentRef, {\n focusTarget: initialFocusRef,\n shouldFocus: autoFocus,\n visible: open,\n })\n\n useOutsideClick({\n ref: [contentRef, triggerRef],\n enabled: open && closeOnBlur,\n handler: onClose,\n })\n\n useSafeLayoutEffect(() => {\n const el = contentRef.current\n const hasHeader = !!getDocument()?.getElementById(headerId)\n const hasBody = !!getDocument()?.getElementById(bodyId)\n\n if (el && hasHeader) setAttribute(el, \"aria-labelledby\", headerId)\n if (el && hasBody) setAttribute(el, \"aria-describedby\", bodyId)\n }, [open, headerId, bodyId])\n\n useEffect(() => {\n if (!open || !modal) return\n\n return focusTrap(contentRef.current)\n }, [open, modal])\n\n useEffect(() => {\n if (!open || !blockScrollOnMount) return\n\n return scrollLock(contentRef.current)\n }, [open, modal, blockScrollOnMount])\n\n useEffect(() => {\n if (!open || modal || !transferFocus) return\n\n return focusTransfer(contentRef.current, triggerRef.current)\n }, [open, modal, transferFocus])\n\n useUnmountEffect(() => {\n clearTimeout(openTimeout.current)\n clearTimeout(closeTimeout.current)\n })\n\n const getTriggerProps: PropGetter<\"button\"> = useCallback(\n ({ ref, ...props } = {}) => ({\n \"aria-controls\": open ? contentId : undefined,\n \"aria-disabled\": ariaAttr(disabled),\n \"aria-expanded\": open,\n \"aria-haspopup\": \"dialog\",\n role: \"button\",\n ...props,\n ref: mergeRefs(ref, triggerRef, (node) => {\n if (anchorRef.current == null) refs.setReference(node)\n }),\n onBlur: handlerAll(props.onBlur, (ev) =>\n !contains(contentRef.current, getEventRelatedTarget(ev)) && closeOnBlur\n ? onClose()\n : void 0,\n ),\n onClick: handlerAll(\n props.onClick,\n !open ? (!disabled && openOnClick ? onOpen : undefined) : onClose,\n ),\n onKeyDown: handlerAll(props.onKeyDown, onKeyDown),\n }),\n [\n closeOnBlur,\n contentId,\n disabled,\n onClose,\n onKeyDown,\n onOpen,\n open,\n openOnClick,\n refs,\n ],\n )\n\n const getAnchorProps: PropGetter = useCallback(\n ({ ref, ...props } = {}) => ({\n ...props,\n ref: mergeRefs(ref, anchorRef, refs.setReference),\n }),\n [refs.setReference],\n )\n\n const getPositionerProps: PropGetter = useCallback(\n (props) => getPopperProps(props),\n [getPopperProps],\n )\n\n const getContentProps: PropGetter = useCallback(\n ({ ref, ...props } = {}) => ({\n id: contentId,\n \"aria-hidden\": !open,\n \"aria-modal\": modal ? \"true\" : undefined,\n \"data-close\": dataAttr(!open),\n \"data-open\": dataAttr(open),\n \"data-popup\": dataAttr(true),\n role: \"dialog\",\n tabIndex: -1,\n ...props,\n ref: mergeRefs(ref, contentRef),\n onBlur: handlerAll(props.onBlur, onBlur),\n onKeyDown: handlerAll(props.onKeyDown, onKeyDown),\n }),\n [contentId, open, modal, onBlur, onKeyDown],\n )\n\n const getHeaderProps: PropGetter = useCallback(\n (props) => ({ id: headerId, ...props }),\n [headerId],\n )\n\n const getBodyProps: PropGetter = useCallback(\n (props) => ({ id: bodyId, ...props }),\n [bodyId],\n )\n\n const getFooterProps: PropGetter = useCallback((props) => ({ ...props }), [])\n\n const getCloseTriggerProps: PropGetter<\"button\"> = useCallback(\n (props = {}) => ({\n ...props,\n onClick: handlerAll(props.onClick, () => {\n onClose()\n onRestoreFocus()\n }),\n }),\n [onClose, onRestoreFocus],\n )\n\n return {\n open,\n getAnchorProps,\n getBodyProps,\n getCloseTriggerProps,\n getContentProps,\n getFooterProps,\n getHeaderProps,\n getPositionerProps,\n getTriggerProps,\n onClose,\n onOpen,\n }\n}\n\nexport type UsePopoverReturn = ReturnType<typeof usePopover>\n\nexport const popoverProps: (\n | keyof UsePopoverProps\n | keyof UsePopupAnimationProps\n)[] = [\n ...popperProps,\n \"autoFocus\",\n \"transferFocus\",\n \"blockScrollOnMount\",\n \"closeOnBlur\",\n \"closeOnEsc\",\n \"closeOnScroll\",\n \"openOnClick\",\n \"disabled\",\n \"initialFocusRef\",\n \"modal\",\n \"updateRef\",\n \"defaultOpen\",\n \"onOpen\",\n \"onClose\",\n \"animationScheme\",\n \"duration\",\n]\n\nexport const usePopoverProps = <\n Y extends Dict = Dict,\n M extends keyof UsePopoverProps | keyof UsePopupAnimationProps =\n | keyof UsePopoverProps\n | keyof UsePopupAnimationProps,\n>(\n props: Y,\n omitKeys?: M[],\n) => {\n return useSplitProps(\n props,\n popoverProps.filter((key) => !omitKeys?.includes(key as M)),\n ) as unknown as [\n keyof UsePopoverProps | keyof UsePopupAnimationProps extends M\n ? UsePopoverProps & UsePopupAnimationProps\n : Omit<UsePopoverProps & UsePopupAnimationProps, M>,\n Omit<\n Y,\n keyof UsePopoverProps | keyof UsePopupAnimationProps extends M\n ? keyof UsePopoverProps | keyof UsePopupAnimationProps\n : Exclude<keyof UsePopoverProps | keyof UsePopupAnimationProps, M>\n >,\n ]\n}\n"],"mappings":";;;;;;;;;;;;;;AA2GA,MAAa,cAAc,EACzB,YAAY,MACZ,YACA,QAAQ,OACR,qBAAqB,OACrB,cAAc,MACd,aAAa,MACb,eACA,aACA,UACA,UACA,MACA,QACA,iBACA,YACA,YACA,QACA,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