@yamada-ui/react 2.3.5-dev-20261126022425 → 2.3.5-dev-20261126060138

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/dist/cjs/components/carousel/use-carousel.cjs +1 -1
  2. package/dist/cjs/components/carousel/use-carousel.cjs.map +1 -1
  3. package/dist/cjs/components/chart/chart.cjs +29 -9
  4. package/dist/cjs/components/chart/chart.cjs.map +1 -1
  5. package/dist/cjs/components/chart/polar-chart.cjs +3 -3
  6. package/dist/cjs/components/chart/polar-chart.cjs.map +1 -1
  7. package/dist/cjs/components/dropzone/use-dropzone.cjs +1 -1
  8. package/dist/cjs/components/dropzone/use-dropzone.cjs.map +1 -1
  9. package/dist/cjs/components/file-input/use-file-input.cjs +1 -2
  10. package/dist/cjs/components/file-input/use-file-input.cjs.map +1 -1
  11. package/dist/cjs/components/infinite-scroll-area/use-infinite-scroll.cjs +4 -2
  12. package/dist/cjs/components/infinite-scroll-area/use-infinite-scroll.cjs.map +1 -1
  13. package/dist/cjs/components/loading/loading-provider.cjs +13 -23
  14. package/dist/cjs/components/loading/loading-provider.cjs.map +1 -1
  15. package/dist/cjs/components/marquee/use-marquee.cjs +1 -1
  16. package/dist/cjs/components/marquee/use-marquee.cjs.map +1 -1
  17. package/dist/cjs/components/menu/use-menu.cjs +7 -1
  18. package/dist/cjs/components/menu/use-menu.cjs.map +1 -1
  19. package/dist/cjs/components/native-popover/use-native-popover.cjs +1 -1
  20. package/dist/cjs/components/native-popover/use-native-popover.cjs.map +1 -1
  21. package/dist/cjs/components/notice/notice-provider.cjs +23 -23
  22. package/dist/cjs/components/notice/notice-provider.cjs.map +1 -1
  23. package/dist/cjs/components/notice/notice.cjs +4 -3
  24. package/dist/cjs/components/notice/notice.cjs.map +1 -1
  25. package/dist/cjs/components/popover/use-popover.cjs +1 -1
  26. package/dist/cjs/components/popover/use-popover.cjs.map +1 -1
  27. package/dist/cjs/components/sidebar/use-sidebar.cjs +2 -2
  28. package/dist/cjs/components/sidebar/use-sidebar.cjs.map +1 -1
  29. package/dist/cjs/components/textarea/use-textarea.cjs +1 -2
  30. package/dist/cjs/components/textarea/use-textarea.cjs.map +1 -1
  31. package/dist/cjs/components/tree/use-tree.cjs +24 -35
  32. package/dist/cjs/components/tree/use-tree.cjs.map +1 -1
  33. package/dist/esm/components/carousel/use-carousel.js +3 -3
  34. package/dist/esm/components/carousel/use-carousel.js.map +1 -1
  35. package/dist/esm/components/chart/chart.js +30 -10
  36. package/dist/esm/components/chart/chart.js.map +1 -1
  37. package/dist/esm/components/chart/polar-chart.js +3 -3
  38. package/dist/esm/components/chart/polar-chart.js.map +1 -1
  39. package/dist/esm/components/dropzone/use-dropzone.js +3 -3
  40. package/dist/esm/components/dropzone/use-dropzone.js.map +1 -1
  41. package/dist/esm/components/file-input/use-file-input.js +2 -3
  42. package/dist/esm/components/file-input/use-file-input.js.map +1 -1
  43. package/dist/esm/components/infinite-scroll-area/use-infinite-scroll.js +6 -4
  44. package/dist/esm/components/infinite-scroll-area/use-infinite-scroll.js.map +1 -1
  45. package/dist/esm/components/loading/loading-provider.js +14 -24
  46. package/dist/esm/components/loading/loading-provider.js.map +1 -1
  47. package/dist/esm/components/marquee/use-marquee.js +3 -3
  48. package/dist/esm/components/marquee/use-marquee.js.map +1 -1
  49. package/dist/esm/components/menu/use-menu.js +9 -3
  50. package/dist/esm/components/menu/use-menu.js.map +1 -1
  51. package/dist/esm/components/native-popover/use-native-popover.js +3 -3
  52. package/dist/esm/components/native-popover/use-native-popover.js.map +1 -1
  53. package/dist/esm/components/notice/notice-provider.js +24 -24
  54. package/dist/esm/components/notice/notice-provider.js.map +1 -1
  55. package/dist/esm/components/notice/notice.js +5 -4
  56. package/dist/esm/components/notice/notice.js.map +1 -1
  57. package/dist/esm/components/popover/use-popover.js +3 -3
  58. package/dist/esm/components/popover/use-popover.js.map +1 -1
  59. package/dist/esm/components/sidebar/use-sidebar.js +4 -4
  60. package/dist/esm/components/sidebar/use-sidebar.js.map +1 -1
  61. package/dist/esm/components/textarea/use-textarea.js +2 -3
  62. package/dist/esm/components/textarea/use-textarea.js.map +1 -1
  63. package/dist/esm/components/tree/use-tree.js +25 -36
  64. package/dist/esm/components/tree/use-tree.js.map +1 -1
  65. package/dist/types/components/accordion/accordion.style.d.ts +1 -1
  66. package/dist/types/components/autocomplete/autocomplete.style.d.ts +1 -1
  67. package/dist/types/components/avatar/avatar.d.ts +3 -3
  68. package/dist/types/components/avatar/avatar.style.d.ts +1 -1
  69. package/dist/types/components/breadcrumb/breadcrumb.style.d.ts +1 -1
  70. package/dist/types/components/bubble/bubble.style.d.ts +1 -1
  71. package/dist/types/components/calendar/calendar.style.d.ts +2 -2
  72. package/dist/types/components/carousel/carousel.style.d.ts +2 -2
  73. package/dist/types/components/chart/cartesian-chart.style.d.ts +1 -1
  74. package/dist/types/components/chart/chart.d.ts +3 -2
  75. package/dist/types/components/chart/polar-chart.style.d.ts +1 -1
  76. package/dist/types/components/color-picker/color-picker.style.d.ts +1 -1
  77. package/dist/types/components/color-selector/color-selector.style.d.ts +2 -2
  78. package/dist/types/components/data-list/data-list.style.d.ts +1 -1
  79. package/dist/types/components/editable/editable.d.ts +1 -1
  80. package/dist/types/components/editable/editable.style.d.ts +1 -1
  81. package/dist/types/components/flip/flip.d.ts +1 -1
  82. package/dist/types/components/flip/flip.style.d.ts +1 -1
  83. package/dist/types/components/list/list.style.d.ts +2 -2
  84. package/dist/types/components/marquee/marquee.style.d.ts +1 -1
  85. package/dist/types/components/menu/menu.style.d.ts +2 -2
  86. package/dist/types/components/native-accordion/native-accordion.style.d.ts +2 -2
  87. package/dist/types/components/notice/notice.style.d.ts +1 -1
  88. package/dist/types/components/number-input/number-input.style.d.ts +1 -1
  89. package/dist/types/components/pagination/pagination.style.d.ts +1 -1
  90. package/dist/types/components/rating/rating.style.d.ts +2 -2
  91. package/dist/types/components/reorder/reorder.style.d.ts +1 -1
  92. package/dist/types/components/resizable/resizable.style.d.ts +2 -2
  93. package/dist/types/components/segmented-control/segmented-control.style.d.ts +2 -2
  94. package/dist/types/components/select/select.style.d.ts +1 -1
  95. package/dist/types/components/steps/steps.style.d.ts +1 -1
  96. package/dist/types/components/timeline/timeline.d.ts +1 -1
  97. package/dist/types/components/timeline/timeline.style.d.ts +1 -1
  98. package/dist/types/components/tree/tree.style.d.ts +1 -1
  99. package/dist/types/providers/i18n-provider/i18n-provider.d.ts +1 -1
  100. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"loading-provider.js","names":["isNumber"],"sources":["../../../../src/components/loading/loading-provider.tsx"],"sourcesContent":["\"use client\"\n\nimport type { FC, PropsWithChildren, ReactNode, RefObject } from \"react\"\nimport type { LoadingConfig, LoadingScheme, ThemeConfig } from \"../../core\"\nimport { AnimatePresence } from \"motion/react\"\nimport { createContext, createRef, use, useMemo, useRef, useState } from \"react\"\nimport { RemoveScroll } from \"react-remove-scroll\"\nimport { assignRef, isNumber, useUpdateEffect } from \"../../utils\"\nimport { Portal } from \"../portal\"\nimport { Background } from \"./background\"\nimport { Page } from \"./page\"\nimport { Screen } from \"./screen\"\n\ninterface LoadingMethods {\n /**\n * Function to finish loading.\n */\n finish: () => void\n /**\n * Function to forcefully update the loading state.\n *\n * Please be careful, as it will forcefully overwrite the state of the loading component.\n */\n force: (state: Partial<LoadingState>) => void\n /**\n * Function to start loading.\n *\n * If you specify a `message` etc. as an argument, the loading will change accordingly.\n */\n start: (options?: LoadingOptions) => void\n /**\n * Function to update loading.\n *\n * If you specify a `message` etc. as an argument, the loading will change accordingly.\n */\n update: (options: LoadingOptions) => void\n}\n\nexport interface LoadingOptions {\n duration?: null | number\n loadingScheme?: LoadingScheme\n message?: ReactNode\n}\n\ninterface LoadingState {\n duration: null | number\n loadingCount: number\n loadingScheme: LoadingScheme\n message: ReactNode | undefined\n}\n\ninterface LoadingContext {\n /**\n * The background loading methods.\n */\n background: LoadingMethods\n /**\n * The page loading methods.\n */\n page: LoadingMethods\n /**\n * The screen loading methods.\n */\n screen: LoadingMethods\n}\n\nconst LoadingContext = createContext({} as LoadingContext)\n\nconst createController = () => ({\n finish: createRef<LoadingMethods[\"finish\"]>(),\n force: createRef<LoadingMethods[\"force\"]>(),\n start: createRef<LoadingMethods[\"start\"]>(),\n update: createRef<LoadingMethods[\"update\"]>(),\n})\n\ntype Controller = ReturnType<typeof createController>\n\nconst createMethods = (refs: RefObject<Controller>): LoadingMethods => ({\n finish: () => refs.current.finish.current?.(),\n force: (state) => refs.current.force.current?.(state),\n start: (props) => refs.current.start.current?.(props),\n update: (props) => refs.current.update.current?.(props),\n})\n\nconst incrementCount = (prev: number) => prev + 1\nconst decrementCount = (prev: number) => (prev === 0 ? prev : prev - 1)\n\nexport interface LoadingProviderProps extends PropsWithChildren<\n ThemeConfig[\"loading\"]\n> {}\n\nexport const LoadingProvider: FC<LoadingProviderProps> = ({\n background: backgroundConfig,\n children,\n page: pageConfig,\n screen: screenConfig,\n}) => {\n const screen = useRef(createController())\n const page = useRef(createController())\n const background = useRef(createController())\n\n const value = useMemo(\n () => ({\n background: createMethods(background),\n page: createMethods(page),\n screen: createMethods(screen),\n }),\n [],\n )\n\n return (\n <LoadingContext value={value}>\n {children}\n\n <Controller ref={screen} {...screenConfig} component={Screen} />\n\n <Controller ref={page} {...pageConfig} component={Page} />\n\n <Controller\n ref={background}\n {...backgroundConfig}\n blockScrollOnMount={backgroundConfig?.blockScrollOnMount ?? false}\n component={Background}\n />\n </LoadingContext>\n )\n}\n\nexport interface LoadingSharedProps {\n duration: null | number\n loadingScheme: LoadingScheme\n message: ReactNode | undefined\n onFinish: () => void\n initial?: boolean | string\n}\n\ninterface ControllerProps extends LoadingConfig {\n component: FC<LoadingSharedProps>\n ref: RefObject<Controller>\n}\n\nconst Controller: FC<ControllerProps> = ({\n ref,\n allowPinchZoom = false,\n blockScrollOnMount = true,\n component: Component,\n duration: durationProp = null,\n loadingCount: loadingCountProp = 0,\n loadingScheme: loadingSchemeProp = \"oval\",\n}) => {\n const loading = useRef<boolean>(false)\n const [{ duration, loadingCount, loadingScheme, message }, setState] =\n useState<LoadingState>({\n duration: durationProp,\n loadingCount: loadingCountProp,\n loadingScheme: loadingSchemeProp,\n message: undefined,\n })\n\n const { finish, force, start, update } = useMemo<LoadingMethods>(\n () => ({\n finish: () => {\n loading.current = false\n\n setState(({ loadingCount }) => ({\n duration: durationProp,\n loadingCount: decrementCount(loadingCount),\n loadingScheme: loadingSchemeProp,\n message: undefined,\n }))\n },\n\n force: ({\n duration = durationProp,\n loadingCount = 0,\n loadingScheme = loadingSchemeProp,\n message,\n }) => {\n loading.current = !!loadingCount\n\n setState({\n duration,\n loadingCount,\n loadingScheme,\n message,\n })\n },\n\n start: ({\n duration = durationProp,\n loadingScheme = loadingSchemeProp,\n message,\n } = {}) => {\n loading.current = true\n\n setState(({ loadingCount }) => ({\n duration,\n loadingCount: incrementCount(loadingCount),\n loadingScheme,\n message,\n }))\n },\n\n update: (next) => setState((prev) => ({ ...prev, ...next })),\n }),\n [durationProp, loadingSchemeProp],\n )\n\n assignRef(ref.current.start, start)\n assignRef(ref.current.finish, finish)\n assignRef(ref.current.update, update)\n assignRef(ref.current.force, force)\n\n const props: LoadingSharedProps = {\n duration,\n initial: loadingCountProp > 0 ? false : \"initial\",\n loadingScheme,\n message,\n onFinish: finish,\n }\n\n useUpdateEffect(() => {\n if (loadingCountProp > 0 || isNumber(durationProp))\n setState({\n duration: durationProp,\n loadingCount: loadingCountProp,\n loadingScheme: loadingSchemeProp,\n message: undefined,\n })\n }, [loadingCountProp, durationProp, loadingSchemeProp])\n\n return (\n <AnimatePresence initial={false}>\n {loadingCount ? (\n <Portal>\n <RemoveScroll\n allowPinchZoom={allowPinchZoom}\n enabled={blockScrollOnMount}\n forwardProps\n >\n <Component {...props} />\n </RemoveScroll>\n </Portal>\n ) : null}\n </AnimatePresence>\n )\n}\n\n/**\n * `useLoading` is a custom hook for controlling the loading of the application.\n *\n * @see https://yamada-ui.com/docs/hooks/use-loading\n */\nexport const useLoading = (): LoadingContext => {\n const { background, page, screen } = use(LoadingContext)\n\n const context = useMemo(\n () => ({ background, page, screen }),\n [background, page, screen],\n )\n\n return context\n}\n"],"mappings":";;;;;;;;;;;;;AAkEA,MAAM,iBAAiB,cAAc,CAAC,CAAmB;AAEzD,MAAM,0BAA0B;CAC9B,QAAQ,UAAoC;CAC5C,OAAO,UAAmC;CAC1C,OAAO,UAAmC;CAC1C,QAAQ,UAAoC;AAC9C;AAIA,MAAM,iBAAiB,UAAiD;CACtE,cAAc,KAAK,QAAQ,OAAO,UAAU;CAC5C,QAAQ,UAAU,KAAK,QAAQ,MAAM,UAAU,KAAK;CACpD,QAAQ,UAAU,KAAK,QAAQ,MAAM,UAAU,KAAK;CACpD,SAAS,UAAU,KAAK,QAAQ,OAAO,UAAU,KAAK;AACxD;AAEA,MAAM,kBAAkB,SAAiB,OAAO;AAChD,MAAM,kBAAkB,SAAkB,SAAS,IAAI,OAAO,OAAO;AAMrE,MAAa,mBAA6C,EACxD,YAAY,kBACZ,UACA,MAAM,YACN,QAAQ,mBACJ;CACJ,MAAM,SAAS,OAAO,iBAAiB,CAAC;CACxC,MAAM,OAAO,OAAO,iBAAiB,CAAC;CACtC,MAAM,aAAa,OAAO,iBAAiB,CAAC;CAE5C,MAAM,QAAQ,eACL;EACL,YAAY,cAAc,UAAU;EACpC,MAAM,cAAc,IAAI;EACxB,QAAQ,cAAc,MAAM;CAC9B,IACA,CAAC,CACH;CAEA,OACE,qBAAC,gBAAD;EAAuB;EAAvB,UAAA;GACG;GAED,oBAAC,YAAD;IAAY,KAAK;IAAQ,GAAI;IAAc,WAAW;GAAS,CAAA;GAE/D,oBAAC,YAAD;IAAY,KAAK;IAAM,GAAI;IAAY,WAAW;GAAO,CAAA;GAEzD,oBAAC,YAAD;IACE,KAAK;IACL,GAAI;IACJ,oBAAoB,kBAAkB,sBAAsB;IAC5D,WAAW;GACZ,CAAA;EACa;;AAEpB;AAeA,MAAM,cA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,KAAA;EACX,CAAC;CACL,GAAG;EAAC;EAAkB;EAAc;CAAiB,CAAC;CAEtD,OACE,oBAAC,iBAAD;EAAiB,SAAS;EACvB,UAAA,eACC,oBAAC,QAAD,EAAA,UACE,oBAAC,cAAD;GACkB;GAChB,SAAS;GACT,cAAA;GAEA,UAAA,oBAAC,WAAD,EAAW,GAAI,MAAQ,CAAA;EACX,CAAA,EACR,CAAA,IACN;CACW,CAAA;AAErB;;;;;;AAOA,MAAa,mBAAmC;CAC9C,MAAM,EAAE,YAAY,MAAM,WAAW,IAAI,cAAc;CAOvD,OALgB,eACP;EAAE;EAAY;EAAM;CAAO,IAClC;EAAC;EAAY;EAAM;CAAM,CAGd;AACf"}
1
+ {"version":3,"file":"loading-provider.js","names":["isNumber"],"sources":["../../../../src/components/loading/loading-provider.tsx"],"sourcesContent":["\"use client\"\n\nimport type { FC, PropsWithChildren, ReactNode, RefObject } from \"react\"\nimport type { LoadingConfig, LoadingScheme, ThemeConfig } from \"../../core\"\nimport { AnimatePresence } from \"motion/react\"\nimport {\n createContext,\n use,\n useImperativeHandle,\n useMemo,\n useRef,\n useState,\n} from \"react\"\nimport { RemoveScroll } from \"react-remove-scroll\"\nimport { isNumber, useUpdateEffect } from \"../../utils\"\nimport { Portal } from \"../portal\"\nimport { Background } from \"./background\"\nimport { Page } from \"./page\"\nimport { Screen } from \"./screen\"\n\ninterface LoadingMethods {\n /**\n * Function to finish loading.\n */\n finish: () => void\n /**\n * Function to forcefully update the loading state.\n *\n * Please be careful, as it will forcefully overwrite the state of the loading component.\n */\n force: (state: Partial<LoadingState>) => void\n /**\n * Function to start loading.\n *\n * If you specify a `message` etc. as an argument, the loading will change accordingly.\n */\n start: (options?: LoadingOptions) => void\n /**\n * Function to update loading.\n *\n * If you specify a `message` etc. as an argument, the loading will change accordingly.\n */\n update: (options: LoadingOptions) => void\n}\n\nexport interface LoadingOptions {\n duration?: null | number\n loadingScheme?: LoadingScheme\n message?: ReactNode\n}\n\ninterface LoadingState {\n duration: null | number\n loadingCount: number\n loadingScheme: LoadingScheme\n message: ReactNode | undefined\n}\n\ninterface LoadingContext {\n /**\n * The background loading methods.\n */\n background: LoadingMethods\n /**\n * The page loading methods.\n */\n page: LoadingMethods\n /**\n * The screen loading methods.\n */\n screen: LoadingMethods\n}\n\nconst LoadingContext = createContext({} as LoadingContext)\n\nconst createMethods = (\n ref: RefObject<LoadingMethods | null>,\n): LoadingMethods => ({\n finish: () => ref.current?.finish(),\n force: (state) => ref.current?.force(state),\n start: (props) => ref.current?.start(props),\n update: (props) => ref.current?.update(props),\n})\n\nconst incrementCount = (prev: number) => prev + 1\nconst decrementCount = (prev: number) => (prev === 0 ? prev : prev - 1)\n\nexport interface LoadingProviderProps extends PropsWithChildren<\n ThemeConfig[\"loading\"]\n> {}\n\nexport const LoadingProvider: FC<LoadingProviderProps> = ({\n background: backgroundConfig,\n children,\n page: pageConfig,\n screen: screenConfig,\n}) => {\n const screen = useRef<LoadingMethods>(null)\n const page = useRef<LoadingMethods>(null)\n const background = useRef<LoadingMethods>(null)\n\n const value = useMemo(\n () => ({\n background: createMethods(background),\n page: createMethods(page),\n screen: createMethods(screen),\n }),\n [],\n )\n\n return (\n <LoadingContext value={value}>\n <Controller ref={screen} {...screenConfig} component={Screen} />\n\n <Controller ref={page} {...pageConfig} component={Page} />\n\n <Controller\n ref={background}\n {...backgroundConfig}\n blockScrollOnMount={backgroundConfig?.blockScrollOnMount ?? false}\n component={Background}\n />\n\n {children}\n </LoadingContext>\n )\n}\n\nexport interface LoadingSharedProps {\n duration: null | number\n loadingScheme: LoadingScheme\n message: ReactNode | undefined\n onFinish: () => void\n initial?: boolean | string\n}\n\ninterface ControllerProps extends LoadingConfig {\n component: FC<LoadingSharedProps>\n ref: RefObject<LoadingMethods | null>\n}\n\nconst Controller: FC<ControllerProps> = ({\n ref,\n allowPinchZoom = false,\n blockScrollOnMount = true,\n component: Component,\n duration: durationProp = null,\n loadingCount: loadingCountProp = 0,\n loadingScheme: loadingSchemeProp = \"oval\",\n}) => {\n const loading = useRef<boolean>(false)\n const [{ duration, loadingCount, loadingScheme, message }, setState] =\n useState<LoadingState>({\n duration: durationProp,\n loadingCount: loadingCountProp,\n loadingScheme: loadingSchemeProp,\n message: undefined,\n })\n\n const methods = useMemo<LoadingMethods>(\n () => ({\n finish: () => {\n loading.current = false\n\n setState(({ loadingCount }) => ({\n duration: durationProp,\n loadingCount: decrementCount(loadingCount),\n loadingScheme: loadingSchemeProp,\n message: undefined,\n }))\n },\n\n force: ({\n duration = durationProp,\n loadingCount = 0,\n loadingScheme = loadingSchemeProp,\n message,\n }) => {\n loading.current = !!loadingCount\n\n setState({\n duration,\n loadingCount,\n loadingScheme,\n message,\n })\n },\n\n start: ({\n duration = durationProp,\n loadingScheme = loadingSchemeProp,\n message,\n } = {}) => {\n loading.current = true\n\n setState(({ loadingCount }) => ({\n duration,\n loadingCount: incrementCount(loadingCount),\n loadingScheme,\n message,\n }))\n },\n\n update: (next) => setState((prev) => ({ ...prev, ...next })),\n }),\n [durationProp, loadingSchemeProp],\n )\n\n useImperativeHandle(ref, () => methods, [methods])\n\n const props: LoadingSharedProps = {\n duration,\n initial: loadingCountProp > 0 ? false : \"initial\",\n loadingScheme,\n message,\n onFinish: methods.finish,\n }\n\n useUpdateEffect(() => {\n if (loadingCountProp > 0 || isNumber(durationProp))\n setState({\n duration: durationProp,\n loadingCount: loadingCountProp,\n loadingScheme: loadingSchemeProp,\n message: undefined,\n })\n }, [loadingCountProp, durationProp, loadingSchemeProp])\n\n return (\n <AnimatePresence initial={false}>\n {loadingCount ? (\n <Portal>\n <RemoveScroll\n allowPinchZoom={allowPinchZoom}\n enabled={blockScrollOnMount}\n forwardProps\n >\n <Component {...props} />\n </RemoveScroll>\n </Portal>\n ) : null}\n </AnimatePresence>\n )\n}\n\n/**\n * `useLoading` is a custom hook for controlling the loading of the application.\n *\n * @see https://yamada-ui.com/docs/hooks/use-loading\n */\nexport const useLoading = (): LoadingContext => {\n const { background, page, screen } = use(LoadingContext)\n\n const context = useMemo(\n () => ({ background, page, screen }),\n [background, page, screen],\n )\n\n return context\n}\n"],"mappings":";;;;;;;;;;;;AAyEA,MAAM,iBAAiB,cAAc,CAAC,CAAmB;AAEzD,MAAM,iBACJ,SACoB;CACpB,cAAc,IAAI,SAAS,OAAO;CAClC,QAAQ,UAAU,IAAI,SAAS,MAAM,KAAK;CAC1C,QAAQ,UAAU,IAAI,SAAS,MAAM,KAAK;CAC1C,SAAS,UAAU,IAAI,SAAS,OAAO,KAAK;AAC9C;AAEA,MAAM,kBAAkB,SAAiB,OAAO;AAChD,MAAM,kBAAkB,SAAkB,SAAS,IAAI,OAAO,OAAO;AAMrE,MAAa,mBAA6C,EACxD,YAAY,kBACZ,UACA,MAAM,YACN,QAAQ,mBACJ;CACJ,MAAM,SAAS,OAAuB,IAAI;CAC1C,MAAM,OAAO,OAAuB,IAAI;CACxC,MAAM,aAAa,OAAuB,IAAI;CAE9C,MAAM,QAAQ,eACL;EACL,YAAY,cAAc,UAAU;EACpC,MAAM,cAAc,IAAI;EACxB,QAAQ,cAAc,MAAM;CAC9B,IACA,CAAC,CACH;CAEA,OACE,qBAAC,gBAAD;EAAuB;EAAvB,UAAA;GACE,oBAAC,YAAD;IAAY,KAAK;IAAQ,GAAI;IAAc,WAAW;GAAS,CAAA;GAE/D,oBAAC,YAAD;IAAY,KAAK;IAAM,GAAI;IAAY,WAAW;GAAO,CAAA;GAEzD,oBAAC,YAAD;IACE,KAAK;IACL,GAAI;IACJ,oBAAoB,kBAAkB,sBAAsB;IAC5D,WAAW;GACZ,CAAA;GAEA;EACa;;AAEpB;AAeA,MAAM,cAAmC,EACvC,KACA,iBAAiB,OACjB,qBAAqB,MACrB,WAAW,WACX,UAAU,eAAe,MACzB,cAAc,mBAAmB,GACjC,eAAe,oBAAoB,aAC/B;CACJ,MAAM,UAAU,OAAgB,KAAK;CACrC,MAAM,CAAC,EAAE,UAAU,cAAc,eAAe,WAAW,YACzD,SAAuB;EACrB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AW,IAAI,cAAc;CAOvD,OALgB,eACP;EAAE;EAAY;EAAM;CAAO,IAClC;EAAC;EAAY;EAAM;CAAM,CAGd;AACf"}
@@ -1,11 +1,11 @@
1
1
  "use client";
2
2
  import { createContext as createContext$1 } from "../../utils/context.js";
3
- import { assignRef, mergeRefs, useCallbackRef } from "../../utils/ref.js";
3
+ import { mergeRefs, useCallbackRef } from "../../utils/ref.js";
4
4
  import { mergeProps } from "../../core/components/props.js";
5
5
  import { useControllableState } from "../../hooks/use-controllable-state/index.js";
6
6
  import { useI18n } from "../../providers/i18n-provider/i18n-provider.js";
7
7
  import { utils_exports } from "../../utils/index.js";
8
- import { useCallback, useEffect, useMemo, useRef, useState } from "react";
8
+ import { useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from "react";
9
9
  // src/components/marquee/use-marquee.ts
10
10
  const [MarqueeContext, useMarqueeContext] = createContext$1({ name: "MarqueeContext" });
11
11
  function useMarquee({ controlRef, defaultPaused = false, delay = 0, dir: dirProp, direction = "start", duration: durationProp, loopCount = 0, orientation = "horizontal", paused: pausedProp, pauseOnFocus = false, pauseOnHover = false, reverse = false, speed = 50, onComplete: onCompleteProp, onLoopComplete: onLoopCompleteProp, onPauseChange, ...rest } = {}) {
@@ -57,7 +57,7 @@ function useMarquee({ controlRef, defaultPaused = false, delay = 0, dir: dirProp
57
57
  resume,
58
58
  togglePause
59
59
  ]);
60
- assignRef(controlRef, control);
60
+ useImperativeHandle(controlRef, () => control, [control]);
61
61
  useEffect(() => {
62
62
  const root = rootRef.current;
63
63
  const content = contentRef.current;
@@ -1 +1 @@
1
- {"version":3,"file":"use-marquee.js","names":["createContext","dataAttr"],"sources":["../../../../src/components/marquee/use-marquee.ts"],"sourcesContent":["\"use client\"\n\nimport type {\n AnimationEvent,\n FocusEvent,\n KeyboardEvent,\n RefObject,\n} from \"react\"\nimport type {\n HTMLProps,\n Orientation,\n PropGetter,\n SimpleDirection,\n} from \"../../core\"\nimport { useCallback, useEffect, useMemo, useRef, useState } from \"react\"\nimport { mergeProps } from \"../../core\"\nimport { useControllableState } from \"../../hooks/use-controllable-state\"\nimport { useI18n } from \"../../providers/i18n-provider\"\nimport {\n assignRef,\n createContext,\n dataAttr,\n mergeRefs,\n useCallbackRef,\n} from \"../../utils\"\n\nexport interface MarqueeControl {\n /**\n * Whether the marquee is paused.\n */\n paused: boolean\n /**\n * Pauses the marquee.\n */\n pause: () => void\n /**\n * Restarts the animation, including its delay and loop count.\n */\n restart: () => void\n /**\n * Resumes the marquee.\n */\n resume: () => void\n /**\n * Toggles the pause state.\n */\n togglePause: () => void\n}\n\nexport interface UseMarqueeProps extends HTMLProps {\n /**\n * Ref of the marquee controls.\n */\n controlRef?: RefObject<MarqueeControl | null>\n /**\n * Whether the marquee is initially paused.\n *\n * @default false\n */\n defaultPaused?: boolean\n /**\n * The delay before the animation starts, in seconds.\n *\n * @default 0\n */\n delay?: number\n /**\n * The direction the content scrolls towards.\n *\n * @default 'start'\n */\n direction?: SimpleDirection\n /**\n * The duration of one loop in seconds. Overrides `speed`.\n */\n duration?: number\n /**\n * The number of animation loops. Set to `0` for infinite loops.\n *\n * @default 0\n */\n loopCount?: number\n /**\n * The orientation of the marquee.\n *\n * @default 'horizontal'\n */\n orientation?: Orientation\n /**\n * If `true`, the animation is paused.\n *\n * @default false\n */\n paused?: boolean\n /**\n * If `true`, the animation pauses while an item is focused.\n *\n * @default false\n */\n pauseOnFocus?: boolean\n /**\n * If `true`, the animation pauses on hover.\n *\n * @default false\n */\n pauseOnHover?: boolean\n /**\n * If `true`, the scrolling direction is reversed.\n *\n * @default false\n */\n reverse?: boolean\n /**\n * The scrolling speed in pixels per second.\n *\n * @default 50\n */\n speed?: number\n /**\n * The callback invoked when all finite loops finish.\n */\n onComplete?: () => void\n /**\n * The callback invoked after each animation iteration, except the final one.\n */\n onLoopComplete?: () => void\n /**\n * The callback invoked when the persistent pause state changes.\n */\n onPauseChange?: (paused: boolean) => void\n}\n\ninterface MarqueeContext extends Pick<\n UseMarqueeReturn,\n \"copies\" | \"getContentProps\" | \"getEdgeProps\" | \"getGroupProps\"\n> {}\n\nconst [MarqueeContext, useMarqueeContext] = createContext<MarqueeContext>({\n name: \"MarqueeContext\",\n})\n\nexport { MarqueeContext, useMarqueeContext }\n\nexport function useMarquee({\n controlRef,\n defaultPaused = false,\n delay = 0,\n dir: dirProp,\n direction = \"start\",\n duration: durationProp,\n loopCount = 0,\n orientation = \"horizontal\",\n paused: pausedProp,\n pauseOnFocus = false,\n pauseOnHover = false,\n reverse = false,\n speed = 50,\n onComplete: onCompleteProp,\n onLoopComplete: onLoopCompleteProp,\n onPauseChange,\n ...rest\n}: UseMarqueeProps = {}) {\n const { dir: defaultDir } = useI18n()\n const dir = dirProp ?? defaultDir\n const vertical = orientation === \"vertical\"\n const rootRef = useRef<HTMLDivElement>(null)\n const contentRef = useRef<HTMLDivElement>(null)\n const trackRef = useRef<HTMLDivElement>(null)\n const [hovered, setHovered] = useState(false)\n const [focused, setFocused] = useState(false)\n const [completed, setCompleted] = useState(false)\n const [paused, setPaused] = useControllableState({\n defaultValue: defaultPaused,\n value: pausedProp,\n onChange: onPauseChange,\n })\n const onComplete = useCallbackRef(onCompleteProp)\n const onLoopComplete = useCallbackRef(onLoopCompleteProp)\n const [size, setSize] = useState({ content: 0, root: 0 })\n const duration = durationProp ?? (speed > 0 ? size.content / speed : 0)\n const ready = size.content > 0 && Number.isFinite(duration) && duration > 0\n const copies = Math.max(\n 1,\n size.content > 0 ? Math.ceil(size.root / size.content) : 1,\n )\n const iterations = Number.isFinite(loopCount) && loopCount > 0 ? loopCount : 0\n const animationDirection =\n (direction === \"end\") !== reverse ? \"reverse\" : \"normal\"\n const interactionPaused =\n (pauseOnHover && hovered) || (pauseOnFocus && focused)\n const animationPaused = paused || interactionPaused || completed || !ready\n\n const pause = useCallback(() => setPaused(true), [setPaused])\n const resume = useCallback(() => setPaused(false), [setPaused])\n const togglePause = useCallback(() => setPaused((prev) => !prev), [setPaused])\n const restart = useCallback(() => {\n trackRef.current?.getAnimations().forEach((animation) => {\n animation.currentTime = 0\n })\n setCompleted(false)\n }, [])\n const control = useMemo<MarqueeControl>(\n () => ({ pause, paused: animationPaused, restart, resume, togglePause }),\n [animationPaused, pause, restart, resume, togglePause],\n )\n\n assignRef(controlRef, control)\n\n useEffect(() => {\n const root = rootRef.current\n const content = contentRef.current\n\n if (!root || !content) return\n\n const observer = new ResizeObserver((entries) => {\n entries.forEach(({ target, borderBoxSize }) => {\n const box = borderBoxSize[0]\n\n if (!box) return\n\n const key = target === root ? \"root\" : \"content\"\n const value = vertical ? box.blockSize : box.inlineSize\n\n setSize((prev) =>\n prev[key] === value ? prev : { ...prev, [key]: value },\n )\n })\n })\n\n observer.observe(root, { box: \"border-box\" })\n observer.observe(content, { box: \"border-box\" })\n\n return () => observer.disconnect()\n }, [vertical])\n\n const getRootProps: PropGetter = useCallback(\n (props = {}) =>\n mergeProps(\n {\n style: {\n \"--delay\": `${Number.isFinite(delay) ? delay : 0}s`,\n \"--direction\": animationDirection,\n \"--distance\": `${size.content}px`,\n \"--duration\": `${ready ? duration : 0}s`,\n \"--loop-count\": iterations || \"infinite\",\n },\n \"aria-keyshortcuts\": \"Space\",\n \"aria-live\": \"off\",\n \"aria-roledescription\": \"marquee\",\n role: \"region\",\n tabIndex: 0,\n },\n rest,\n props,\n {\n ref: rootRef,\n \"data-complete\": dataAttr(completed),\n \"data-end\": dataAttr(direction === \"end\"),\n \"data-orientation\": orientation,\n \"data-pause-on-focus\": dataAttr(pauseOnFocus),\n \"data-pause-on-hover\": dataAttr(pauseOnHover),\n \"data-paused\": dataAttr(animationPaused),\n \"data-start\": dataAttr(direction === \"start\"),\n dir,\n onBlurCapture: (ev: FocusEvent<HTMLDivElement>) => {\n if (ev.currentTarget.contains(ev.relatedTarget)) return\n\n setFocused(false)\n\n if (!pauseOnFocus) return\n\n ev.currentTarget.scrollLeft = 0\n ev.currentTarget.scrollTop = 0\n },\n onFocusCapture: () => setFocused(true),\n onKeyDown: (ev: KeyboardEvent<HTMLDivElement>) => {\n if (\n ev.target !== ev.currentTarget ||\n ev.key !== \" \" ||\n ev.altKey ||\n ev.ctrlKey ||\n ev.metaKey ||\n ev.repeat\n )\n return\n\n ev.preventDefault()\n togglePause()\n },\n onMouseEnter: () => setHovered(true),\n onMouseLeave: () => setHovered(false),\n },\n )(),\n [\n rest,\n direction,\n orientation,\n pauseOnFocus,\n pauseOnHover,\n animationPaused,\n completed,\n ready,\n dir,\n duration,\n animationDirection,\n delay,\n iterations,\n size.content,\n togglePause,\n ],\n )\n\n const getContentProps: PropGetter = useCallback(\n (props = {}) =>\n mergeProps(props, {\n ref: trackRef,\n \"data-marquee-content\": \"\",\n \"data-orientation\": orientation,\n \"data-ready\": dataAttr(ready),\n onAnimationEnd: (ev: AnimationEvent<HTMLDivElement>) => {\n if (ev.target !== ev.currentTarget || !iterations) return\n\n setCompleted(true)\n onComplete()\n },\n onAnimationIteration: (ev: AnimationEvent<HTMLDivElement>) => {\n if (ev.target === ev.currentTarget) onLoopComplete()\n },\n })(),\n [orientation, ready, iterations, onComplete, onLoopComplete],\n )\n\n const getEdgeProps: PropGetter<\"div\", { direction?: SimpleDirection }> =\n useCallback(\n ({ direction = \"start\", ...props } = {}) =>\n mergeProps(props, {\n \"aria-hidden\": true,\n \"data-end\": dataAttr(direction === \"end\"),\n \"data-orientation\": orientation,\n \"data-start\": dataAttr(direction === \"start\"),\n dir,\n inert: true,\n })(),\n [dir, orientation],\n )\n\n const getGroupProps: PropGetter<\"div\", { index?: number }> = useCallback(\n ({ id, ref, index = 0, ...props } = {}) =>\n mergeProps({ style: { \"--index\": index } }, props, {\n id: index ? undefined : id,\n ref: index ? undefined : mergeRefs(ref, contentRef),\n \"aria-hidden\": index ? true : undefined,\n \"data-clone\": dataAttr(!!index),\n \"data-orientation\": orientation,\n inert: index ? true : undefined,\n })(),\n [orientation],\n )\n\n return {\n control,\n copies,\n getContentProps,\n getEdgeProps,\n getGroupProps,\n getRootProps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uC;IACtD,IAAI,GAAG,WAAW,GAAG,iBAAiB,CAAC,YAAY;IAEnD,aAAa,IAAI;IACjB,WAAW;GACb;GACA,uBAAuB,OAAuC;IAC5D,IAAI,GAAG,WAAW,GAAG,eAAe,eAAe;GACrD;EACF,CAAC,CAAC,CAAC,GACL;GAAC;GAAa;GAAO;GAAY;GAAY;EAAc,CAiC7C;EACd,cA9BA,aACG,EAAE,YAAY,SAAS,GAAG,UAAU,CAAC,MACpC,WAAW,OAAO;GAChB,eAAe;GACf,aAAA,GAAYA,cAAAA,SAAAA,CAAS,cAAc,KAAK;GACxC,oBAAoB;GACpB,eAAA,GAAcA,cAAAA,SAAAA,CAAS,cAAc,OAAO;GAC5C;GACA,OAAO;EACT,CAAC,CAAC,CAAC,GACL,CAAC,KAAK,WAAW,CAoBR;EACX,eAlB2D,aAC1D,EAAE,IAAI,KAAK,QAAQ,GAAG,GAAG,UAAU,CAAC,MACnC,WAAW,EAAE,OAAO,EAAE,WAAW,MAAM,EAAE,GAAG,OAAO;GACjD,IAAI,QAAQ,KAAA,IAAY;GACxB,KAAK,QAAQ,KAAA,IAAY,UAAU,KAAK,UAAU;GAClD,eAAe,QAAQ,OAAO,KAAA;GAC9B,eAAA,GAAcA,cAAAA,SAAAA,CAAS,CAAC,CAAC,KAAK;GAC9B,oBAAoB;GACpB,OAAO,QAAQ,OAAO,KAAA;EACxB,CAAC,CAAC,CAAC,GACL,CAAC,WAAW,CAQA;EACZ;CACF;AACF"}
1
+ {"version":3,"file":"use-marquee.js","names":["createContext","dataAttr"],"sources":["../../../../src/components/marquee/use-marquee.ts"],"sourcesContent":["\"use client\"\n\nimport type {\n AnimationEvent,\n FocusEvent,\n KeyboardEvent,\n RefObject,\n} from \"react\"\nimport type {\n HTMLProps,\n Orientation,\n PropGetter,\n SimpleDirection,\n} from \"../../core\"\nimport {\n useCallback,\n useEffect,\n useImperativeHandle,\n useMemo,\n useRef,\n useState,\n} from \"react\"\nimport { mergeProps } from \"../../core\"\nimport { useControllableState } from \"../../hooks/use-controllable-state\"\nimport { useI18n } from \"../../providers/i18n-provider\"\nimport { createContext, dataAttr, mergeRefs, useCallbackRef } from \"../../utils\"\n\nexport interface MarqueeControl {\n /**\n * Whether the marquee is paused.\n */\n paused: boolean\n /**\n * Pauses the marquee.\n */\n pause: () => void\n /**\n * Restarts the animation, including its delay and loop count.\n */\n restart: () => void\n /**\n * Resumes the marquee.\n */\n resume: () => void\n /**\n * Toggles the pause state.\n */\n togglePause: () => void\n}\n\nexport interface UseMarqueeProps extends HTMLProps {\n /**\n * Ref of the marquee controls.\n */\n controlRef?: RefObject<MarqueeControl | null>\n /**\n * Whether the marquee is initially paused.\n *\n * @default false\n */\n defaultPaused?: boolean\n /**\n * The delay before the animation starts, in seconds.\n *\n * @default 0\n */\n delay?: number\n /**\n * The direction the content scrolls towards.\n *\n * @default 'start'\n */\n direction?: SimpleDirection\n /**\n * The duration of one loop in seconds. Overrides `speed`.\n */\n duration?: number\n /**\n * The number of animation loops. Set to `0` for infinite loops.\n *\n * @default 0\n */\n loopCount?: number\n /**\n * The orientation of the marquee.\n *\n * @default 'horizontal'\n */\n orientation?: Orientation\n /**\n * If `true`, the animation is paused.\n *\n * @default false\n */\n paused?: boolean\n /**\n * If `true`, the animation pauses while an item is focused.\n *\n * @default false\n */\n pauseOnFocus?: boolean\n /**\n * If `true`, the animation pauses on hover.\n *\n * @default false\n */\n pauseOnHover?: boolean\n /**\n * If `true`, the scrolling direction is reversed.\n *\n * @default false\n */\n reverse?: boolean\n /**\n * The scrolling speed in pixels per second.\n *\n * @default 50\n */\n speed?: number\n /**\n * The callback invoked when all finite loops finish.\n */\n onComplete?: () => void\n /**\n * The callback invoked after each animation iteration, except the final one.\n */\n onLoopComplete?: () => void\n /**\n * The callback invoked when the persistent pause state changes.\n */\n onPauseChange?: (paused: boolean) => void\n}\n\ninterface MarqueeContext extends Pick<\n UseMarqueeReturn,\n \"copies\" | \"getContentProps\" | \"getEdgeProps\" | \"getGroupProps\"\n> {}\n\nconst [MarqueeContext, useMarqueeContext] = createContext<MarqueeContext>({\n name: \"MarqueeContext\",\n})\n\nexport { MarqueeContext, useMarqueeContext }\n\nexport function useMarquee({\n controlRef,\n defaultPaused = false,\n delay = 0,\n dir: dirProp,\n direction = \"start\",\n duration: durationProp,\n loopCount = 0,\n orientation = \"horizontal\",\n paused: pausedProp,\n pauseOnFocus = false,\n pauseOnHover = false,\n reverse = false,\n speed = 50,\n onComplete: onCompleteProp,\n onLoopComplete: onLoopCompleteProp,\n onPauseChange,\n ...rest\n}: UseMarqueeProps = {}) {\n const { dir: defaultDir } = useI18n()\n const dir = dirProp ?? defaultDir\n const vertical = orientation === \"vertical\"\n const rootRef = useRef<HTMLDivElement>(null)\n const contentRef = useRef<HTMLDivElement>(null)\n const trackRef = useRef<HTMLDivElement>(null)\n const [hovered, setHovered] = useState(false)\n const [focused, setFocused] = useState(false)\n const [completed, setCompleted] = useState(false)\n const [paused, setPaused] = useControllableState({\n defaultValue: defaultPaused,\n value: pausedProp,\n onChange: onPauseChange,\n })\n const onComplete = useCallbackRef(onCompleteProp)\n const onLoopComplete = useCallbackRef(onLoopCompleteProp)\n const [size, setSize] = useState({ content: 0, root: 0 })\n const duration = durationProp ?? (speed > 0 ? size.content / speed : 0)\n const ready = size.content > 0 && Number.isFinite(duration) && duration > 0\n const copies = Math.max(\n 1,\n size.content > 0 ? Math.ceil(size.root / size.content) : 1,\n )\n const iterations = Number.isFinite(loopCount) && loopCount > 0 ? loopCount : 0\n const animationDirection =\n (direction === \"end\") !== reverse ? \"reverse\" : \"normal\"\n const interactionPaused =\n (pauseOnHover && hovered) || (pauseOnFocus && focused)\n const animationPaused = paused || interactionPaused || completed || !ready\n\n const pause = useCallback(() => setPaused(true), [setPaused])\n const resume = useCallback(() => setPaused(false), [setPaused])\n const togglePause = useCallback(() => setPaused((prev) => !prev), [setPaused])\n const restart = useCallback(() => {\n trackRef.current?.getAnimations().forEach((animation) => {\n animation.currentTime = 0\n })\n setCompleted(false)\n }, [])\n const control = useMemo<MarqueeControl>(\n () => ({ pause, paused: animationPaused, restart, resume, togglePause }),\n [animationPaused, pause, restart, resume, togglePause],\n )\n\n useImperativeHandle(controlRef, () => control, [control])\n\n useEffect(() => {\n const root = rootRef.current\n const content = contentRef.current\n\n if (!root || !content) return\n\n const observer = new ResizeObserver((entries) => {\n entries.forEach(({ target, borderBoxSize }) => {\n const box = borderBoxSize[0]\n\n if (!box) return\n\n const key = target === root ? \"root\" : \"content\"\n const value = vertical ? box.blockSize : box.inlineSize\n\n setSize((prev) =>\n prev[key] === value ? prev : { ...prev, [key]: value },\n )\n })\n })\n\n observer.observe(root, { box: \"border-box\" })\n observer.observe(content, { box: \"border-box\" })\n\n return () => observer.disconnect()\n }, [vertical])\n\n const getRootProps: PropGetter = useCallback(\n (props = {}) =>\n mergeProps(\n {\n style: {\n \"--delay\": `${Number.isFinite(delay) ? delay : 0}s`,\n \"--direction\": animationDirection,\n \"--distance\": `${size.content}px`,\n \"--duration\": `${ready ? duration : 0}s`,\n \"--loop-count\": iterations || \"infinite\",\n },\n \"aria-keyshortcuts\": \"Space\",\n \"aria-live\": \"off\",\n \"aria-roledescription\": \"marquee\",\n role: \"region\",\n tabIndex: 0,\n },\n rest,\n props,\n {\n ref: rootRef,\n \"data-complete\": dataAttr(completed),\n \"data-end\": dataAttr(direction === \"end\"),\n \"data-orientation\": orientation,\n \"data-pause-on-focus\": dataAttr(pauseOnFocus),\n \"data-pause-on-hover\": dataAttr(pauseOnHover),\n \"data-paused\": dataAttr(animationPaused),\n \"data-start\": dataAttr(direction === \"start\"),\n dir,\n onBlurCapture: (ev: FocusEvent<HTMLDivElement>) => {\n if (ev.currentTarget.contains(ev.relatedTarget)) return\n\n setFocused(false)\n\n if (!pauseOnFocus) return\n\n ev.currentTarget.scrollLeft = 0\n ev.currentTarget.scrollTop = 0\n },\n onFocusCapture: () => setFocused(true),\n onKeyDown: (ev: KeyboardEvent<HTMLDivElement>) => {\n if (\n ev.target !== ev.currentTarget ||\n ev.key !== \" \" ||\n ev.altKey ||\n ev.ctrlKey ||\n ev.metaKey ||\n ev.repeat\n )\n return\n\n ev.preventDefault()\n togglePause()\n },\n onMouseEnter: () => setHovered(true),\n onMouseLeave: () => setHovered(false),\n },\n )(),\n [\n rest,\n direction,\n orientation,\n pauseOnFocus,\n pauseOnHover,\n animationPaused,\n completed,\n ready,\n dir,\n duration,\n animationDirection,\n delay,\n iterations,\n size.content,\n togglePause,\n ],\n )\n\n const getContentProps: PropGetter = useCallback(\n (props = {}) =>\n mergeProps(props, {\n ref: trackRef,\n \"data-marquee-content\": \"\",\n \"data-orientation\": orientation,\n \"data-ready\": dataAttr(ready),\n onAnimationEnd: (ev: AnimationEvent<HTMLDivElement>) => {\n if (ev.target !== ev.currentTarget || !iterations) return\n\n setCompleted(true)\n onComplete()\n },\n onAnimationIteration: (ev: AnimationEvent<HTMLDivElement>) => {\n if (ev.target === ev.currentTarget) onLoopComplete()\n },\n })(),\n [orientation, ready, iterations, onComplete, onLoopComplete],\n )\n\n const getEdgeProps: PropGetter<\"div\", { direction?: SimpleDirection }> =\n useCallback(\n ({ direction = \"start\", ...props } = {}) =>\n mergeProps(props, {\n \"aria-hidden\": true,\n \"data-end\": dataAttr(direction === \"end\"),\n \"data-orientation\": orientation,\n \"data-start\": dataAttr(direction === \"start\"),\n dir,\n inert: true,\n })(),\n [dir, orientation],\n )\n\n const getGroupProps: PropGetter<\"div\", { index?: number }> = useCallback(\n ({ id, ref, index = 0, ...props } = {}) =>\n mergeProps({ style: { \"--index\": index } }, props, {\n id: index ? undefined : id,\n ref: index ? undefined : mergeRefs(ref, contentRef),\n \"aria-hidden\": index ? true : undefined,\n \"data-clone\": dataAttr(!!index),\n \"data-orientation\": orientation,\n inert: index ? true : undefined,\n })(),\n [orientation],\n )\n\n return {\n control,\n copies,\n getContentProps,\n getEdgeProps,\n getGroupProps,\n getRootProps,\n }\n}\n\nexport type UseMarqueeReturn = ReturnType<typeof useMarquee>\n"],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G,iBAAiB,CAAC,YAAY;IAEnD,aAAa,IAAI;IACjB,WAAW;GACb;GACA,uBAAuB,OAAuC;IAC5D,IAAI,GAAG,WAAW,GAAG,eAAe,eAAe;GACrD;EACF,CAAC,CAAC,CAAC,GACL;GAAC;GAAa;GAAO;GAAY;GAAY;EAAc,CAiC7C;EACd,cA9BA,aACG,EAAE,YAAY,SAAS,GAAG,UAAU,CAAC,MACpC,WAAW,OAAO;GAChB,eAAe;GACf,aAAA,GAAYA,cAAAA,SAAAA,CAAS,cAAc,KAAK;GACxC,oBAAoB;GACpB,eAAA,GAAcA,cAAAA,SAAAA,CAAS,cAAc,OAAO;GAC5C;GACA,OAAO;EACT,CAAC,CAAC,CAAC,GACL,CAAC,KAAK,WAAW,CAoBR;EACX,eAlB2D,aAC1D,EAAE,IAAI,KAAK,QAAQ,GAAG,GAAG,UAAU,CAAC,MACnC,WAAW,EAAE,OAAO,EAAE,WAAW,MAAM,EAAE,GAAG,OAAO;GACjD,IAAI,QAAQ,KAAA,IAAY;GACxB,KAAK,QAAQ,KAAA,IAAY,UAAU,KAAK,UAAU;GAClD,eAAe,QAAQ,OAAO,KAAA;GAC9B,eAAA,GAAcA,cAAAA,SAAAA,CAAS,CAAC,CAAC,KAAK;GAC9B,oBAAoB;GACpB,OAAO,QAAQ,OAAO,KAAA;EACxB,CAAC,CAAC,CAAC,GACL,CAAC,WAAW,CAQA;EACZ;CACF;AACF"}
@@ -1,8 +1,8 @@
1
1
  "use client";
2
2
  import { createContext as createContext$1 } from "../../utils/context.js";
3
3
  import { runKeyAction } from "../../utils/dom.js";
4
- import { useUpdateEffect } from "../../utils/effect.js";
5
- import { assignRef, mergeRefs } from "../../utils/ref.js";
4
+ import { useSafeLayoutEffect, useUpdateEffect } from "../../utils/effect.js";
5
+ import { mergeRefs } from "../../utils/ref.js";
6
6
  import { mergeProps } from "../../core/components/props.js";
7
7
  import { useControllableState } from "../../hooks/use-controllable-state/index.js";
8
8
  import { createDescendants } from "../../hooks/use-descendants/index.js";
@@ -275,7 +275,13 @@ const useSubMenu = ({ descendants, disabled = false, open, subMenuDirection = "e
275
275
  subMenuDirection,
276
276
  onOpen
277
277
  ]);
278
- assignRef(onCloseRef, onClose);
278
+ useSafeLayoutEffect(() => {
279
+ if (!onCloseRef) return;
280
+ onCloseRef.current = onClose;
281
+ return () => {
282
+ if (onCloseRef.current === onClose) onCloseRef.current = utils_exports.noop;
283
+ };
284
+ }, [onCloseRef, onClose]);
279
285
  return {
280
286
  mainCloseOnSelect,
281
287
  subMenu,
@@ -1 +1 @@
1
- {"version":3,"file":"use-menu.js","names":["createContext","noop","ariaAttr","dataAttr","handlerAll","isTruthyDataAttr","isString","isArray"],"sources":["../../../../src/components/menu/use-menu.ts"],"sourcesContent":["\"use client\"\n\nimport type { KeyboardEvent, MouseEvent, RefObject } from \"react\"\nimport type { HTMLProps, PropGetter } from \"../../core\"\nimport type { Descendant, Descendants } from \"../../hooks/use-descendants\"\nimport type { UseDisclosureProps } from \"../../hooks/use-disclosure\"\nimport { useCallback, useId, useRef } from \"react\"\nimport { mergeProps } from \"../../core\"\nimport { useControllableState } from \"../../hooks/use-controllable-state\"\nimport { createDescendants } from \"../../hooks/use-descendants\"\nimport { useDisclosure } from \"../../hooks/use-disclosure\"\nimport {\n ariaAttr,\n assignRef,\n createContext,\n dataAttr,\n handlerAll,\n isArray,\n isString,\n isTruthyDataAttr,\n mergeRefs,\n noop,\n runKeyAction,\n useUpdateEffect,\n} from \"../../utils\"\n\ntype SubMenuDirection = \"end\" | \"start\"\n\ninterface MenuDescendantProps {\n id: string\n}\ntype MenuDescendant = Descendant<HTMLDivElement, MenuDescendantProps>\n\nconst {\n DescendantsContext: MenuDescendantsContext,\n useDescendant: useMenuDescendant,\n useDescendantRegister: useMenuDescendantRegister,\n useDescendants: useMenuDescendants,\n} = createDescendants<HTMLDivElement, MenuDescendantProps>()\n\nexport { MenuDescendantsContext, useMenuDescendant, useMenuDescendants }\n\ninterface MenuContext extends Pick<\n UseMenuReturn,\n | \"disabled\"\n | \"onActiveDescendant\"\n | \"onClose\"\n | \"onCloseSubMenu\"\n | \"onOpen\"\n | \"onSelect\"\n | \"subMenu\"\n | \"subMenuDirection\"\n> {}\n\nconst [MenuContext, useMenuContext] = createContext<MenuContext>({\n name: \"MenuContext\",\n})\n\ninterface MenuGroupContext extends Pick<UseMenuGroupReturn, \"getLabelProps\"> {}\n\nconst [MenuGroupContext, useMenuGroupContext] = createContext<MenuGroupContext>(\n {\n name: \"MenuGroupContext\",\n },\n)\n\ninterface MainMenuContext {\n descendants: Descendants<HTMLDivElement, MenuDescendantProps>\n onActiveDescendant: (descendant?: MenuDescendant) => void\n onCloseRef: RefObject<() => void>\n onSelect: (value?: string, closeOnSelect?: boolean) => void\n closeOnSelect?: boolean\n}\n\nconst [MainMenuContext, useMainMenuContext] = createContext<MainMenuContext>({\n name: \"MainMenuContext\",\n strict: false,\n})\n\ninterface MenuOptionGroupContext {\n type: \"checkbox\" | \"radio\"\n value: string | string[]\n onChange?: (value: string) => void\n}\n\nconst [MenuOptionGroupContext, useMenuOptionGroupContext] =\n createContext<MenuOptionGroupContext>({\n name: \"MenuOptionGroupContext\",\n })\n\nexport {\n MainMenuContext,\n MenuContext,\n MenuGroupContext,\n MenuOptionGroupContext,\n useMainMenuContext,\n useMenuContext,\n useMenuGroupContext,\n useMenuOptionGroupContext,\n}\n\nexport interface UseMenuProps extends Omit<UseDisclosureProps, \"timing\"> {\n /**\n * If `true`, the menu item will be closed when selected.\n *\n * @default true\n */\n closeOnSelect?: boolean\n /**\n * If `true`, the menu will be disabled.\n *\n * @default false\n */\n disabled?: boolean\n /**\n * The direction of the sub menu.\n *\n * @default 'end'\n */\n subMenuDirection?: SubMenuDirection\n /**\n * Callback invoked when a menu item is selected.\n */\n onSelect?: (value?: string) => void\n}\n\nexport const useMenu = ({\n closeOnSelect,\n defaultOpen,\n disabled = false,\n open: openProp,\n subMenuDirection = \"end\",\n onClose: onCloseProp,\n onOpen: onOpenProp,\n onSelect: onSelectProp,\n}: UseMenuProps = {}) => {\n const triggerId = useId()\n const contentId = useId()\n const descendants = useMenuDescendants()\n const updateRef = useRef<() => void>(noop)\n const onCloseRef = useRef<() => void>(noop)\n const contentRef = useRef<HTMLDivElement>(null)\n const { open, onClose, onOpen } = useDisclosure({\n defaultOpen,\n open: openProp,\n onClose: onCloseProp,\n onOpen: onOpenProp,\n })\n const onCloseSubMenu = useCallback(() => onCloseRef.current(), [])\n const onActiveDescendant = useCallback(\n (\n descendant?: MenuDescendant,\n options: FocusOptions = { preventScroll: true },\n ) => {\n if (!contentRef.current || !descendant || disabled) return\n\n contentRef.current.setAttribute(\"aria-activedescendant\", descendant.id)\n\n descendants.active(descendant, options)\n },\n [descendants, disabled],\n )\n const { mainCloseOnSelect, subMenu, getSubMenuProps, onMainSelect } =\n useSubMenu({\n descendants,\n disabled,\n open,\n subMenuDirection,\n onActiveDescendant,\n onClose,\n onOpen,\n })\n\n closeOnSelect ??= mainCloseOnSelect ?? true\n\n const onSelect = useCallback(\n (value?: string, closeOnSelectProp = closeOnSelect) => {\n if (disabled) return\n\n onSelectProp?.(value)\n onMainSelect?.(value, closeOnSelectProp)\n\n if (!closeOnSelectProp) return\n\n onClose()\n },\n [closeOnSelect, disabled, onClose, onMainSelect, onSelectProp],\n )\n\n const onClick = useCallback(\n (ev: MouseEvent<HTMLDivElement>) => {\n if (disabled) return\n\n ev.preventDefault()\n\n if (!open) onOpen()\n else onClose()\n },\n [disabled, onClose, onOpen, open],\n )\n\n const onContextMenu = useCallback(\n (ev: MouseEvent<HTMLDivElement>) => {\n if (disabled) return\n\n ev.preventDefault()\n onOpen()\n updateRef.current()\n },\n [disabled, onOpen],\n )\n\n const onKeyDown = useCallback(\n (ev: KeyboardEvent<HTMLDivElement>) => {\n if (disabled) return\n\n runKeyAction(ev, {\n ArrowDown: () => {\n onOpen()\n\n setTimeout(() => {\n const descendant = descendants.enabledFirstValue()\n\n onActiveDescendant(descendant)\n })\n },\n ArrowUp: () => {\n onOpen()\n\n setTimeout(() => {\n const descendant = descendants.enabledLastValue()\n\n onActiveDescendant(descendant)\n })\n },\n Enter: () => {\n onOpen()\n\n setTimeout(() => {\n const descendant = descendants.enabledFirstValue()\n\n onActiveDescendant(descendant)\n })\n },\n Space: () => {\n onOpen()\n\n setTimeout(() => {\n const descendant = descendants.enabledFirstValue()\n\n onActiveDescendant(descendant)\n })\n },\n })\n },\n [descendants, disabled, onActiveDescendant, onOpen],\n )\n\n const getTriggerProps: PropGetter = useCallback(\n (props = {}) => ({\n ...getSubMenuProps({\n id: triggerId,\n \"aria-controls\": open ? contentId : undefined,\n \"aria-disabled\": ariaAttr(disabled),\n \"aria-expanded\": open,\n \"aria-haspopup\": \"menu\",\n \"data-trigger\": dataAttr(true),\n role: \"button\",\n tabIndex: disabled ? -1 : 0,\n ...props,\n onClick: handlerAll(props.onClick, onClick),\n onKeyDown: handlerAll(props.onKeyDown, onKeyDown),\n }),\n }),\n [contentId, disabled, getSubMenuProps, onClick, onKeyDown, open, triggerId],\n )\n\n const getContextTriggerProps: PropGetter = useCallback(\n (props = {}) => ({\n id: triggerId,\n \"aria-controls\": open ? contentId : undefined,\n \"aria-disabled\": ariaAttr(disabled),\n \"aria-expanded\": open,\n \"aria-haspopup\": \"menu\",\n \"data-trigger\": dataAttr(true),\n role: \"application\",\n ...props,\n onContextMenu: handlerAll(props.onContextMenu, onContextMenu),\n }),\n [contentId, disabled, onContextMenu, open, triggerId],\n )\n\n const getContentProps: PropGetter = useCallback(\n (props = {}) =>\n mergeProps(\n {\n id: contentId,\n ref: contentRef,\n \"aria-labelledby\": triggerId,\n role: \"menu\",\n },\n props,\n )(),\n [contentId, triggerId],\n )\n\n const getSeparatorProps: PropGetter = useCallback(\n (props) => ({ role: \"separator\", ...props }),\n [],\n )\n\n return {\n closeOnSelect,\n descendants,\n disabled,\n open,\n subMenu,\n subMenuDirection,\n updateRef,\n getContentProps,\n getContextTriggerProps,\n getSeparatorProps,\n getTriggerProps,\n onActiveDescendant,\n onClose,\n onCloseRef,\n onCloseSubMenu,\n onOpen,\n onSelect,\n }\n}\n\nexport type UseMenuReturn = ReturnType<typeof useMenu>\n\nexport interface UseSubMenuProps extends Omit<\n Required<UseDisclosureProps>,\n \"defaultOpen\" | \"timing\"\n> {\n descendants: Descendants<HTMLDivElement, MenuDescendantProps>\n onActiveDescendant: (descendant?: MenuDescendant) => void\n disabled?: boolean\n subMenuDirection?: SubMenuDirection\n}\n\nexport const useSubMenu = ({\n descendants,\n disabled = false,\n open,\n subMenuDirection = \"end\",\n onActiveDescendant,\n onClose,\n onOpen,\n}: UseSubMenuProps) => {\n const uuid = useId()\n const {\n closeOnSelect: mainCloseOnSelect,\n descendants: mainDescendants,\n onActiveDescendant: onActiveMainDescendant,\n onCloseRef,\n onSelect: onMainSelect,\n } = useMainMenuContext() ?? {}\n const subMenu = !!mainDescendants && !!onActiveMainDescendant\n const createRegister = useMenuDescendantRegister(mainDescendants)\n const triggerRef = useRef<HTMLDivElement>(null)\n\n const dataDisabled = useCallback((node?: HTMLDivElement | null) => {\n node ??= triggerRef.current\n\n if (!node) return false\n\n const dataDisabled = isTruthyDataAttr(node.getAttribute(\"data-disabled\"))\n\n return dataDisabled\n }, [])\n\n const ariaDisabled = useCallback((node?: HTMLDivElement | null) => {\n node ??= triggerRef.current\n\n if (!node) return false\n\n const ariaDisabled = isTruthyDataAttr(node.getAttribute(\"aria-disabled\"))\n\n return ariaDisabled\n }, [])\n\n const onClick = useCallback(\n (ev: MouseEvent<HTMLDivElement>) => {\n if (!subMenu) return\n\n ev.defaultPrevented = disabled || dataDisabled() || ariaDisabled()\n },\n [ariaDisabled, dataDisabled, disabled, subMenu],\n )\n\n const onMouseEnter = useCallback(() => {\n if (!subMenu || disabled || dataDisabled() || ariaDisabled()) return\n\n onOpen()\n }, [ariaDisabled, dataDisabled, disabled, onOpen, subMenu])\n\n const onMouseMove = useCallback(\n (ev: MouseEvent<HTMLDivElement>) => {\n if (!subMenu || disabled || dataDisabled() || ariaDisabled()) return\n\n const descendant = descendants.value(triggerRef.current)\n\n onActiveMainDescendant(descendant)\n\n ev.defaultPrevented = true\n },\n [\n ariaDisabled,\n dataDisabled,\n descendants,\n disabled,\n onActiveMainDescendant,\n subMenu,\n ],\n )\n\n const onKeyDown = useCallback(\n (ev: KeyboardEvent<HTMLDivElement>) => {\n if (!subMenu || disabled) return\n\n const currentDescendant = open ? descendants : mainDescendants\n const onActiveCurrentDescendant = open\n ? onActiveDescendant\n : onActiveMainDescendant\n\n runKeyAction(ev, {\n ArrowDown: () => {\n const descendant = currentDescendant.enabledNextValue(\n triggerRef.current,\n )\n\n onActiveCurrentDescendant(descendant)\n\n ev.defaultPrevented = true\n },\n ArrowUp: () => {\n const descendant = currentDescendant.enabledPrevValue(\n triggerRef.current,\n )\n\n onActiveCurrentDescendant(descendant)\n\n ev.defaultPrevented = true\n },\n End: () => {\n const descendant = currentDescendant.enabledLastValue()\n\n onActiveCurrentDescendant(descendant)\n\n ev.defaultPrevented = true\n },\n Home: () => {\n const descendant = currentDescendant.enabledFirstValue()\n\n onActiveCurrentDescendant(descendant)\n\n ev.defaultPrevented = true\n },\n [subMenuDirection === \"end\" ? \"ArrowRight\" : \"ArrowLeft\"]: () => {\n onOpen()\n\n setTimeout(() => {\n const descendant = descendants.enabledFirstValue()\n\n onActiveDescendant(descendant)\n })\n\n ev.defaultPrevented = true\n },\n })\n },\n [\n subMenu,\n disabled,\n open,\n descendants,\n mainDescendants,\n onActiveDescendant,\n onActiveMainDescendant,\n subMenuDirection,\n onOpen,\n ],\n )\n\n assignRef(onCloseRef, onClose)\n\n const getSubMenuProps: PropGetter = useCallback(\n ({ id = uuid, ...props } = {}) =>\n mergeProps(\n {\n ref: mergeRefs(\n triggerRef,\n createRegister({\n id,\n disabled: (node) =>\n disabled || dataDisabled(node) || ariaDisabled(node),\n }),\n ),\n role: subMenu ? \"menuitem\" : \"button\",\n },\n props,\n { onClick, onKeyDown, onMouseEnter, onMouseMove },\n )(),\n [\n uuid,\n subMenu,\n createRegister,\n onClick,\n onKeyDown,\n onMouseEnter,\n onMouseMove,\n disabled,\n dataDisabled,\n ariaDisabled,\n ],\n )\n\n return { mainCloseOnSelect, subMenu, getSubMenuProps, onMainSelect }\n}\n\nexport type UseSubMenuReturn = ReturnType<typeof useSubMenu>\n\nexport interface UseMenuGroupProps extends HTMLProps {}\n\nexport const useMenuGroup = ({ ...rest }: UseMenuGroupProps) => {\n const labelId = useId()\n\n const getGroupProps: PropGetter = useCallback(\n (props = {}) =>\n mergeProps(\n {\n \"aria-labelledby\": labelId,\n role: \"group\",\n },\n rest,\n props,\n )(),\n [labelId, rest],\n )\n\n const getLabelProps: PropGetter<\"span\"> = useCallback(\n (props) => ({ id: labelId, role: \"presentation\", ...props }),\n [labelId],\n )\n\n return { getGroupProps, getLabelProps }\n}\n\nexport type UseMenuGroupReturn = ReturnType<typeof useMenuGroup>\n\nexport interface UseMenuItemProps extends Omit<HTMLProps, \"onSelect\"> {\n /**\n * If `true`, the menu item will be closed when selected.\n */\n closeOnSelect?: boolean\n /**\n * If `true`, the menu item will be disabled.\n *\n * @default false\n */\n disabled?: boolean\n /**\n * The value of the menu item.\n */\n value?: string\n /**\n * Callback invoked when the menu item is selected.\n */\n onSelect?: (value?: string) => void\n}\n\nexport const useMenuItem = ({\n id,\n \"aria-disabled\": ariaDisabled,\n \"data-disabled\": dataDisabled,\n \"data-trigger\": dataTrigger,\n closeOnSelect,\n disabled = false,\n value,\n onSelect: onSelectProp,\n ...rest\n}: UseMenuItemProps) => {\n const trigger = isTruthyDataAttr(dataTrigger)\n const {\n disabled: rootDisabled,\n subMenu,\n subMenuDirection,\n onActiveDescendant,\n onClose,\n onCloseSubMenu,\n onSelect: onRootSelect,\n } = useMenuContext()\n const uuid = useId()\n const itemRef = useRef<HTMLDivElement>(null)\n const subMenuTrigger = subMenu && trigger\n\n id ??= uuid\n\n const { descendants, register } = useMenuDescendant({\n id,\n disabled: disabled || subMenuTrigger,\n })\n\n const onSelect = useCallback(\n (value?: string) => {\n if (disabled || rootDisabled) return\n\n onSelectProp?.(value)\n onRootSelect(value, closeOnSelect)\n },\n [closeOnSelect, disabled, onRootSelect, onSelectProp, rootDisabled],\n )\n\n const onActive = useCallback(() => {\n if (disabled) return\n\n const descendant = descendants.value(itemRef.current)\n\n onActiveDescendant(descendant)\n }, [descendants, disabled, onActiveDescendant])\n\n const onKeyDown = useCallback(\n (ev: KeyboardEvent<HTMLDivElement>) => {\n runKeyAction(ev, {\n ArrowDown: () => {\n const descendant = descendants.enabledNextValue(itemRef.current)\n\n onActiveDescendant(descendant)\n },\n ArrowUp: () => {\n const descendant = descendants.enabledPrevValue(itemRef.current)\n\n onActiveDescendant(descendant)\n },\n End: () => {\n const descendant = descendants.enabledLastValue()\n\n onActiveDescendant(descendant)\n },\n Enter: () => onSelect(value),\n Home: () => {\n const descendant = descendants.enabledFirstValue()\n\n onActiveDescendant(descendant)\n },\n Space: () => onSelect(value),\n [subMenuDirection === \"end\" ? \"ArrowLeft\" : \"ArrowRight\"]: () => {\n if (!subMenu) return\n\n onClose()\n\n const descendant = descendants.firstValue()\n\n descendant?.node.focus()\n },\n })\n },\n [\n descendants,\n onActiveDescendant,\n onClose,\n onSelect,\n subMenu,\n subMenuDirection,\n value,\n ],\n )\n\n const getItemProps: PropGetter = useCallback(\n (props = {}) =>\n mergeProps(\n {\n id,\n ref: mergeRefs(itemRef, register),\n \"aria-disabled\": ariaDisabled ?? ariaAttr(disabled),\n \"data-disabled\": dataDisabled ?? dataAttr(disabled),\n role: \"menuitem\",\n tabIndex: -1,\n },\n rest,\n props,\n {\n onClick: () => onSelect(value),\n onFocus: onActive,\n onKeyDown: onKeyDown,\n onMouseMove: () => {\n onCloseSubMenu()\n onActive()\n },\n },\n )(),\n [\n id,\n ariaDisabled,\n disabled,\n dataDisabled,\n rest,\n register,\n onActive,\n onKeyDown,\n onSelect,\n value,\n onCloseSubMenu,\n ],\n )\n\n return {\n subMenuTrigger,\n getItemProps,\n }\n}\n\nexport type UseMenuItemReturn = ReturnType<typeof useMenuItem>\n\nexport type MenuOptionGroupType = \"checkbox\" | \"radio\"\nexport type MenuOptionGroupValue<Y extends MenuOptionGroupType> =\n Y extends \"checkbox\" ? string[] : string\n\nexport interface UseMenuOptionGroupProps<\n Y extends MenuOptionGroupType = \"checkbox\",\n M extends MenuOptionGroupValue<Y> = MenuOptionGroupValue<Y>,\n> {\n /**\n * The initial value of the menu item group.\n */\n defaultValue?: M\n /**\n * The type of the menu option group.\n */\n type?: Y\n /**\n * The value of the menu item group.\n */\n value?: M\n /**\n * The callback fired when any children checkbox is checked or unchecked.\n */\n onChange?: (value: M) => void\n}\n\nexport const useMenuOptionGroup = <\n Y extends \"checkbox\" | \"radio\" = \"checkbox\",\n M extends (Y extends \"checkbox\" ? string[] : string) = Y extends \"checkbox\"\n ? string[]\n : string,\n>({\n type = \"checkbox\" as Y,\n defaultValue = (type === \"checkbox\" ? [] : \"\") as M,\n value: valueProp,\n onChange: onChangeProp,\n}: UseMenuOptionGroupProps<Y, M>) => {\n const [value, setValue] = useControllableState({\n defaultValue,\n value: valueProp,\n onChange: onChangeProp,\n })\n const radio = type === \"radio\"\n\n const onChange = useCallback(\n (selectedValue: string) => {\n setValue((prev) => {\n if (radio && isString(prev)) return selectedValue as M\n else if (!radio && isArray(prev))\n return (\n prev.includes(selectedValue)\n ? prev.filter((value) => value !== selectedValue)\n : prev.concat(selectedValue)\n ) as M\n else return prev\n })\n },\n [radio, setValue],\n )\n\n useUpdateEffect(() => {\n setValue(valueProp!)\n }, [valueProp])\n\n return {\n type,\n value,\n onChange,\n }\n}\n\nexport type UseMenuOptionGroupReturn = ReturnType<typeof useMenuOptionGroup>\n\nexport interface UseMenuOptionItemProps extends UseMenuItemProps {\n /**\n * The value of the menu option item.\n */\n value: string\n}\n\nexport const useMenuOptionItem = ({\n disabled,\n value,\n ...rest\n}: UseMenuOptionItemProps) => {\n const { type, value: selectedValue, onChange } = useMenuOptionGroupContext()\n const { getItemProps } = useMenuItem({ disabled, value, ...rest })\n const radio = type === \"radio\" && isString(selectedValue)\n const checkbox = type === \"checkbox\" && isArray(selectedValue)\n const selected = radio\n ? value === selectedValue\n : checkbox\n ? selectedValue.includes(value)\n : false\n\n const getIndicatorProps: PropGetter = useCallback(\n ({ style, ...props } = {}) => ({\n style: { opacity: selected ? 1 : 0, ...style },\n ...props,\n }),\n [selected],\n )\n\n const getOptionItemProps: PropGetter = useCallback(\n (props = {}) =>\n getItemProps({\n role: radio ? \"menuitemradio\" : \"menuitemcheckbox\",\n ...props,\n onClick: handlerAll(props.onClick, () =>\n !disabled ? onChange?.(value) : noop,\n ),\n }),\n [disabled, getItemProps, onChange, radio, value],\n )\n\n return {\n type,\n selected,\n getIndicatorProps,\n getOptionItemProps,\n }\n}\n\nexport type UseMenuOptionItemReturn = ReturnType<typeof useMenuOptionItem>\n"],"mappings":";;;;;;;;;;;;AAiCA,MAAM,EACJ,oBAAoB,wBACpB,eAAe,mBACf,uBAAuB,2BACvB,gBAAgB,uBACd,kBAAuD;AAgB3D,MAAM,CAAC,aAAa,kBAAkBA,gBAA2B,EAC/D,MAAM,cACR,CAAC;AAID,MAAM,CAAC,kBAAkB,uBAAuBA,gBAC9C,EACE,MAAM,mBACR,CACF;AAUA,MAAM,CAAC,iBAAiB,sBAAsBA,gBAA+B;CAC3E,MAAM;CACN,QAAQ;AACV,CAAC;AAQD,MAAM,CAAC,wBAAwB,6BAC7BA,gBAAsC,EACpC,MAAM,yBACR,CAAC;AAsCH,MAAa,WAAW,EACtB,eACA,aACA,WAAW,OACX,MAAM,UACN,mBAAmB,OACnB,SAAS,aACT,QAAQ,YACR,UAAU,iBACM,CAAC,MAAM;CACvB,MAAM,YAAY,MAAM;CACxB,MAAM,YAAY,MAAM;CACxB,MAAM,cAAc,mBAAmB;CACvC,MAAM,YAAY,OAAmBC,cAAAA,IAAI;CACzC,MAAM,aAAa,OAAmBA,cAAAA,IAAI;CAC1C,MAAM,aAAa,OAAuB,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cAAAA,SAAAA,CAAS,IAAI,GAAG,OAAO;QAC/B,IAAI,CAAC,UAAA,GAASC,cAAAA,QAAAA,CAAQ,IAAI,GAC7B,OACE,KAAK,SAAS,aAAa,IACvB,KAAK,QAAQ,UAAU,UAAU,aAAa,IAC9C,KAAK,OAAO,aAAa;QAE5B,OAAO;EACd,CAAC;CACH,GACA,CAAC,OAAO,QAAQ,CAClB;CAEA,sBAAsB;EACpB,SAAS,SAAU;CACrB,GAAG,CAAC,SAAS,CAAC;CAEd,OAAO;EACL;EACA;EACA;CACF;AACF;AAWA,MAAa,qBAAqB,EAChC,UACA,OACA,GAAG,WACyB;CAC5B,MAAM,EAAE,MAAM,OAAO,eAAe,aAAa,0BAA0B;CAC3E,MAAM,EAAE,iBAAiB,YAAY;EAAE;EAAU;EAAO,GAAG;CAAK,CAAC;CACjE,MAAM,QAAQ,SAAS,YAAA,GAAWD,cAAAA,SAAAA,CAAS,aAAa;CACxD,MAAM,WAAW,SAAS,eAAA,GAAcC,cAAAA,QAAAA,CAAQ,aAAa;CAC7D,MAAM,WAAW,QACb,UAAU,gBACV,WACE,cAAc,SAAS,KAAK,IAC5B;CAsBN,OAAO;EACL;EACA;EACA,mBAvBoC,aACnC,EAAE,OAAO,GAAG,UAAU,CAAC,OAAO;GAC7B,OAAO;IAAE,SAAS,WAAW,IAAI;IAAG,GAAG;GAAM;GAC7C,GAAG;EACL,IACA,CAAC,QAAQ,CAkBO;EAChB,oBAhBqC,aACpC,QAAQ,CAAC,MACR,aAAa;GACX,MAAM,QAAQ,kBAAkB;GAChC,GAAG;GACH,UAAA,GAASH,cAAAA,WAAAA,CAAW,MAAM,eACxB,CAAC,WAAW,WAAW,KAAK,IAAIH,cAAAA,IAClC;EACF,CAAC,GACH;GAAC;GAAU;GAAc;GAAU;GAAO;EAAK,CAO9B;CACnB;AACF"}
1
+ {"version":3,"file":"use-menu.js","names":["createContext","noop","ariaAttr","dataAttr","handlerAll","isTruthyDataAttr","isString","isArray"],"sources":["../../../../src/components/menu/use-menu.ts"],"sourcesContent":["\"use client\"\n\nimport type { KeyboardEvent, MouseEvent, RefObject } from \"react\"\nimport type { HTMLProps, PropGetter } from \"../../core\"\nimport type { Descendant, Descendants } from \"../../hooks/use-descendants\"\nimport type { UseDisclosureProps } from \"../../hooks/use-disclosure\"\nimport { useCallback, useId, useRef } from \"react\"\nimport { mergeProps } from \"../../core\"\nimport { useControllableState } from \"../../hooks/use-controllable-state\"\nimport { createDescendants } from \"../../hooks/use-descendants\"\nimport { useDisclosure } from \"../../hooks/use-disclosure\"\nimport {\n ariaAttr,\n createContext,\n dataAttr,\n handlerAll,\n isArray,\n isString,\n isTruthyDataAttr,\n mergeRefs,\n noop,\n runKeyAction,\n useSafeLayoutEffect,\n useUpdateEffect,\n} from \"../../utils\"\n\ntype SubMenuDirection = \"end\" | \"start\"\n\ninterface MenuDescendantProps {\n id: string\n}\ntype MenuDescendant = Descendant<HTMLDivElement, MenuDescendantProps>\n\nconst {\n DescendantsContext: MenuDescendantsContext,\n useDescendant: useMenuDescendant,\n useDescendantRegister: useMenuDescendantRegister,\n useDescendants: useMenuDescendants,\n} = createDescendants<HTMLDivElement, MenuDescendantProps>()\n\nexport { MenuDescendantsContext, useMenuDescendant, useMenuDescendants }\n\ninterface MenuContext extends Pick<\n UseMenuReturn,\n | \"disabled\"\n | \"onActiveDescendant\"\n | \"onClose\"\n | \"onCloseSubMenu\"\n | \"onOpen\"\n | \"onSelect\"\n | \"subMenu\"\n | \"subMenuDirection\"\n> {}\n\nconst [MenuContext, useMenuContext] = createContext<MenuContext>({\n name: \"MenuContext\",\n})\n\ninterface MenuGroupContext extends Pick<UseMenuGroupReturn, \"getLabelProps\"> {}\n\nconst [MenuGroupContext, useMenuGroupContext] = createContext<MenuGroupContext>(\n {\n name: \"MenuGroupContext\",\n },\n)\n\ninterface MainMenuContext {\n descendants: Descendants<HTMLDivElement, MenuDescendantProps>\n onActiveDescendant: (descendant?: MenuDescendant) => void\n onCloseRef: RefObject<() => void>\n onSelect: (value?: string, closeOnSelect?: boolean) => void\n closeOnSelect?: boolean\n}\n\nconst [MainMenuContext, useMainMenuContext] = createContext<MainMenuContext>({\n name: \"MainMenuContext\",\n strict: false,\n})\n\ninterface MenuOptionGroupContext {\n type: \"checkbox\" | \"radio\"\n value: string | string[]\n onChange?: (value: string) => void\n}\n\nconst [MenuOptionGroupContext, useMenuOptionGroupContext] =\n createContext<MenuOptionGroupContext>({\n name: \"MenuOptionGroupContext\",\n })\n\nexport {\n MainMenuContext,\n MenuContext,\n MenuGroupContext,\n MenuOptionGroupContext,\n useMainMenuContext,\n useMenuContext,\n useMenuGroupContext,\n useMenuOptionGroupContext,\n}\n\nexport interface UseMenuProps extends Omit<UseDisclosureProps, \"timing\"> {\n /**\n * If `true`, the menu item will be closed when selected.\n *\n * @default true\n */\n closeOnSelect?: boolean\n /**\n * If `true`, the menu will be disabled.\n *\n * @default false\n */\n disabled?: boolean\n /**\n * The direction of the sub menu.\n *\n * @default 'end'\n */\n subMenuDirection?: SubMenuDirection\n /**\n * Callback invoked when a menu item is selected.\n */\n onSelect?: (value?: string) => void\n}\n\nexport const useMenu = ({\n closeOnSelect,\n defaultOpen,\n disabled = false,\n open: openProp,\n subMenuDirection = \"end\",\n onClose: onCloseProp,\n onOpen: onOpenProp,\n onSelect: onSelectProp,\n}: UseMenuProps = {}) => {\n const triggerId = useId()\n const contentId = useId()\n const descendants = useMenuDescendants()\n const updateRef = useRef<() => void>(noop)\n const onCloseRef = useRef<() => void>(noop)\n const contentRef = useRef<HTMLDivElement>(null)\n const { open, onClose, onOpen } = useDisclosure({\n defaultOpen,\n open: openProp,\n onClose: onCloseProp,\n onOpen: onOpenProp,\n })\n const onCloseSubMenu = useCallback(() => onCloseRef.current(), [])\n const onActiveDescendant = useCallback(\n (\n descendant?: MenuDescendant,\n options: FocusOptions = { preventScroll: true },\n ) => {\n if (!contentRef.current || !descendant || disabled) return\n\n contentRef.current.setAttribute(\"aria-activedescendant\", descendant.id)\n\n descendants.active(descendant, options)\n },\n [descendants, disabled],\n )\n const { mainCloseOnSelect, subMenu, getSubMenuProps, onMainSelect } =\n useSubMenu({\n descendants,\n disabled,\n open,\n subMenuDirection,\n onActiveDescendant,\n onClose,\n onOpen,\n })\n\n closeOnSelect ??= mainCloseOnSelect ?? true\n\n const onSelect = useCallback(\n (value?: string, closeOnSelectProp = closeOnSelect) => {\n if (disabled) return\n\n onSelectProp?.(value)\n onMainSelect?.(value, closeOnSelectProp)\n\n if (!closeOnSelectProp) return\n\n onClose()\n },\n [closeOnSelect, disabled, onClose, onMainSelect, onSelectProp],\n )\n\n const onClick = useCallback(\n (ev: MouseEvent<HTMLDivElement>) => {\n if (disabled) return\n\n ev.preventDefault()\n\n if (!open) onOpen()\n else onClose()\n },\n [disabled, onClose, onOpen, open],\n )\n\n const onContextMenu = useCallback(\n (ev: MouseEvent<HTMLDivElement>) => {\n if (disabled) return\n\n ev.preventDefault()\n onOpen()\n updateRef.current()\n },\n [disabled, onOpen],\n )\n\n const onKeyDown = useCallback(\n (ev: KeyboardEvent<HTMLDivElement>) => {\n if (disabled) return\n\n runKeyAction(ev, {\n ArrowDown: () => {\n onOpen()\n\n setTimeout(() => {\n const descendant = descendants.enabledFirstValue()\n\n onActiveDescendant(descendant)\n })\n },\n ArrowUp: () => {\n onOpen()\n\n setTimeout(() => {\n const descendant = descendants.enabledLastValue()\n\n onActiveDescendant(descendant)\n })\n },\n Enter: () => {\n onOpen()\n\n setTimeout(() => {\n const descendant = descendants.enabledFirstValue()\n\n onActiveDescendant(descendant)\n })\n },\n Space: () => {\n onOpen()\n\n setTimeout(() => {\n const descendant = descendants.enabledFirstValue()\n\n onActiveDescendant(descendant)\n })\n },\n })\n },\n [descendants, disabled, onActiveDescendant, onOpen],\n )\n\n const getTriggerProps: PropGetter = useCallback(\n (props = {}) => ({\n ...getSubMenuProps({\n id: triggerId,\n \"aria-controls\": open ? contentId : undefined,\n \"aria-disabled\": ariaAttr(disabled),\n \"aria-expanded\": open,\n \"aria-haspopup\": \"menu\",\n \"data-trigger\": dataAttr(true),\n role: \"button\",\n tabIndex: disabled ? -1 : 0,\n ...props,\n onClick: handlerAll(props.onClick, onClick),\n onKeyDown: handlerAll(props.onKeyDown, onKeyDown),\n }),\n }),\n [contentId, disabled, getSubMenuProps, onClick, onKeyDown, open, triggerId],\n )\n\n const getContextTriggerProps: PropGetter = useCallback(\n (props = {}) => ({\n id: triggerId,\n \"aria-controls\": open ? contentId : undefined,\n \"aria-disabled\": ariaAttr(disabled),\n \"aria-expanded\": open,\n \"aria-haspopup\": \"menu\",\n \"data-trigger\": dataAttr(true),\n role: \"application\",\n ...props,\n onContextMenu: handlerAll(props.onContextMenu, onContextMenu),\n }),\n [contentId, disabled, onContextMenu, open, triggerId],\n )\n\n const getContentProps: PropGetter = useCallback(\n (props = {}) =>\n mergeProps(\n {\n id: contentId,\n ref: contentRef,\n \"aria-labelledby\": triggerId,\n role: \"menu\",\n },\n props,\n )(),\n [contentId, triggerId],\n )\n\n const getSeparatorProps: PropGetter = useCallback(\n (props) => ({ role: \"separator\", ...props }),\n [],\n )\n\n return {\n closeOnSelect,\n descendants,\n disabled,\n open,\n subMenu,\n subMenuDirection,\n updateRef,\n getContentProps,\n getContextTriggerProps,\n getSeparatorProps,\n getTriggerProps,\n onActiveDescendant,\n onClose,\n onCloseRef,\n onCloseSubMenu,\n onOpen,\n onSelect,\n }\n}\n\nexport type UseMenuReturn = ReturnType<typeof useMenu>\n\nexport interface UseSubMenuProps extends Omit<\n Required<UseDisclosureProps>,\n \"defaultOpen\" | \"timing\"\n> {\n descendants: Descendants<HTMLDivElement, MenuDescendantProps>\n onActiveDescendant: (descendant?: MenuDescendant) => void\n disabled?: boolean\n subMenuDirection?: SubMenuDirection\n}\n\nexport const useSubMenu = ({\n descendants,\n disabled = false,\n open,\n subMenuDirection = \"end\",\n onActiveDescendant,\n onClose,\n onOpen,\n}: UseSubMenuProps) => {\n const uuid = useId()\n const {\n closeOnSelect: mainCloseOnSelect,\n descendants: mainDescendants,\n onActiveDescendant: onActiveMainDescendant,\n onCloseRef,\n onSelect: onMainSelect,\n } = useMainMenuContext() ?? {}\n const subMenu = !!mainDescendants && !!onActiveMainDescendant\n const createRegister = useMenuDescendantRegister(mainDescendants)\n const triggerRef = useRef<HTMLDivElement>(null)\n\n const dataDisabled = useCallback((node?: HTMLDivElement | null) => {\n node ??= triggerRef.current\n\n if (!node) return false\n\n const dataDisabled = isTruthyDataAttr(node.getAttribute(\"data-disabled\"))\n\n return dataDisabled\n }, [])\n\n const ariaDisabled = useCallback((node?: HTMLDivElement | null) => {\n node ??= triggerRef.current\n\n if (!node) return false\n\n const ariaDisabled = isTruthyDataAttr(node.getAttribute(\"aria-disabled\"))\n\n return ariaDisabled\n }, [])\n\n const onClick = useCallback(\n (ev: MouseEvent<HTMLDivElement>) => {\n if (!subMenu) return\n\n ev.defaultPrevented = disabled || dataDisabled() || ariaDisabled()\n },\n [ariaDisabled, dataDisabled, disabled, subMenu],\n )\n\n const onMouseEnter = useCallback(() => {\n if (!subMenu || disabled || dataDisabled() || ariaDisabled()) return\n\n onOpen()\n }, [ariaDisabled, dataDisabled, disabled, onOpen, subMenu])\n\n const onMouseMove = useCallback(\n (ev: MouseEvent<HTMLDivElement>) => {\n if (!subMenu || disabled || dataDisabled() || ariaDisabled()) return\n\n const descendant = descendants.value(triggerRef.current)\n\n onActiveMainDescendant(descendant)\n\n ev.defaultPrevented = true\n },\n [\n ariaDisabled,\n dataDisabled,\n descendants,\n disabled,\n onActiveMainDescendant,\n subMenu,\n ],\n )\n\n const onKeyDown = useCallback(\n (ev: KeyboardEvent<HTMLDivElement>) => {\n if (!subMenu || disabled) return\n\n const currentDescendant = open ? descendants : mainDescendants\n const onActiveCurrentDescendant = open\n ? onActiveDescendant\n : onActiveMainDescendant\n\n runKeyAction(ev, {\n ArrowDown: () => {\n const descendant = currentDescendant.enabledNextValue(\n triggerRef.current,\n )\n\n onActiveCurrentDescendant(descendant)\n\n ev.defaultPrevented = true\n },\n ArrowUp: () => {\n const descendant = currentDescendant.enabledPrevValue(\n triggerRef.current,\n )\n\n onActiveCurrentDescendant(descendant)\n\n ev.defaultPrevented = true\n },\n End: () => {\n const descendant = currentDescendant.enabledLastValue()\n\n onActiveCurrentDescendant(descendant)\n\n ev.defaultPrevented = true\n },\n Home: () => {\n const descendant = currentDescendant.enabledFirstValue()\n\n onActiveCurrentDescendant(descendant)\n\n ev.defaultPrevented = true\n },\n [subMenuDirection === \"end\" ? \"ArrowRight\" : \"ArrowLeft\"]: () => {\n onOpen()\n\n setTimeout(() => {\n const descendant = descendants.enabledFirstValue()\n\n onActiveDescendant(descendant)\n })\n\n ev.defaultPrevented = true\n },\n })\n },\n [\n subMenu,\n disabled,\n open,\n descendants,\n mainDescendants,\n onActiveDescendant,\n onActiveMainDescendant,\n subMenuDirection,\n onOpen,\n ],\n )\n\n useSafeLayoutEffect(() => {\n if (!onCloseRef) return\n\n onCloseRef.current = onClose\n\n return () => {\n if (onCloseRef.current === onClose) onCloseRef.current = noop\n }\n }, [onCloseRef, onClose])\n\n const getSubMenuProps: PropGetter = useCallback(\n ({ id = uuid, ...props } = {}) =>\n mergeProps(\n {\n ref: mergeRefs(\n triggerRef,\n createRegister({\n id,\n disabled: (node) =>\n disabled || dataDisabled(node) || ariaDisabled(node),\n }),\n ),\n role: subMenu ? \"menuitem\" : \"button\",\n },\n props,\n { onClick, onKeyDown, onMouseEnter, onMouseMove },\n )(),\n [\n uuid,\n subMenu,\n createRegister,\n onClick,\n onKeyDown,\n onMouseEnter,\n onMouseMove,\n disabled,\n dataDisabled,\n ariaDisabled,\n ],\n )\n\n return { mainCloseOnSelect, subMenu, getSubMenuProps, onMainSelect }\n}\n\nexport type UseSubMenuReturn = ReturnType<typeof useSubMenu>\n\nexport interface UseMenuGroupProps extends HTMLProps {}\n\nexport const useMenuGroup = ({ ...rest }: UseMenuGroupProps) => {\n const labelId = useId()\n\n const getGroupProps: PropGetter = useCallback(\n (props = {}) =>\n mergeProps(\n {\n \"aria-labelledby\": labelId,\n role: \"group\",\n },\n rest,\n props,\n )(),\n [labelId, rest],\n )\n\n const getLabelProps: PropGetter<\"span\"> = useCallback(\n (props) => ({ id: labelId, role: \"presentation\", ...props }),\n [labelId],\n )\n\n return { getGroupProps, getLabelProps }\n}\n\nexport type UseMenuGroupReturn = ReturnType<typeof useMenuGroup>\n\nexport interface UseMenuItemProps extends Omit<HTMLProps, \"onSelect\"> {\n /**\n * If `true`, the menu item will be closed when selected.\n */\n closeOnSelect?: boolean\n /**\n * If `true`, the menu item will be disabled.\n *\n * @default false\n */\n disabled?: boolean\n /**\n * The value of the menu item.\n */\n value?: string\n /**\n * Callback invoked when the menu item is selected.\n */\n onSelect?: (value?: string) => void\n}\n\nexport const useMenuItem = ({\n id,\n \"aria-disabled\": ariaDisabled,\n \"data-disabled\": dataDisabled,\n \"data-trigger\": dataTrigger,\n closeOnSelect,\n disabled = false,\n value,\n onSelect: onSelectProp,\n ...rest\n}: UseMenuItemProps) => {\n const trigger = isTruthyDataAttr(dataTrigger)\n const {\n disabled: rootDisabled,\n subMenu,\n subMenuDirection,\n onActiveDescendant,\n onClose,\n onCloseSubMenu,\n onSelect: onRootSelect,\n } = useMenuContext()\n const uuid = useId()\n const itemRef = useRef<HTMLDivElement>(null)\n const subMenuTrigger = subMenu && trigger\n\n id ??= uuid\n\n const { descendants, register } = useMenuDescendant({\n id,\n disabled: disabled || subMenuTrigger,\n })\n\n const onSelect = useCallback(\n (value?: string) => {\n if (disabled || rootDisabled) return\n\n onSelectProp?.(value)\n onRootSelect(value, closeOnSelect)\n },\n [closeOnSelect, disabled, onRootSelect, onSelectProp, rootDisabled],\n )\n\n const onActive = useCallback(() => {\n if (disabled) return\n\n const descendant = descendants.value(itemRef.current)\n\n onActiveDescendant(descendant)\n }, [descendants, disabled, onActiveDescendant])\n\n const onKeyDown = useCallback(\n (ev: KeyboardEvent<HTMLDivElement>) => {\n runKeyAction(ev, {\n ArrowDown: () => {\n const descendant = descendants.enabledNextValue(itemRef.current)\n\n onActiveDescendant(descendant)\n },\n ArrowUp: () => {\n const descendant = descendants.enabledPrevValue(itemRef.current)\n\n onActiveDescendant(descendant)\n },\n End: () => {\n const descendant = descendants.enabledLastValue()\n\n onActiveDescendant(descendant)\n },\n Enter: () => onSelect(value),\n Home: () => {\n const descendant = descendants.enabledFirstValue()\n\n onActiveDescendant(descendant)\n },\n Space: () => onSelect(value),\n [subMenuDirection === \"end\" ? \"ArrowLeft\" : \"ArrowRight\"]: () => {\n if (!subMenu) return\n\n onClose()\n\n const descendant = descendants.firstValue()\n\n descendant?.node.focus()\n },\n })\n },\n [\n descendants,\n onActiveDescendant,\n onClose,\n onSelect,\n subMenu,\n subMenuDirection,\n value,\n ],\n )\n\n const getItemProps: PropGetter = useCallback(\n (props = {}) =>\n mergeProps(\n {\n id,\n ref: mergeRefs(itemRef, register),\n \"aria-disabled\": ariaDisabled ?? ariaAttr(disabled),\n \"data-disabled\": dataDisabled ?? dataAttr(disabled),\n role: \"menuitem\",\n tabIndex: -1,\n },\n rest,\n props,\n {\n onClick: () => onSelect(value),\n onFocus: onActive,\n onKeyDown: onKeyDown,\n onMouseMove: () => {\n onCloseSubMenu()\n onActive()\n },\n },\n )(),\n [\n id,\n ariaDisabled,\n disabled,\n dataDisabled,\n rest,\n register,\n onActive,\n onKeyDown,\n onSelect,\n value,\n onCloseSubMenu,\n ],\n )\n\n return {\n subMenuTrigger,\n getItemProps,\n }\n}\n\nexport type UseMenuItemReturn = ReturnType<typeof useMenuItem>\n\nexport type MenuOptionGroupType = \"checkbox\" | \"radio\"\nexport type MenuOptionGroupValue<Y extends MenuOptionGroupType> =\n Y extends \"checkbox\" ? string[] : string\n\nexport interface UseMenuOptionGroupProps<\n Y extends MenuOptionGroupType = \"checkbox\",\n M extends MenuOptionGroupValue<Y> = MenuOptionGroupValue<Y>,\n> {\n /**\n * The initial value of the menu item group.\n */\n defaultValue?: M\n /**\n * The type of the menu option group.\n */\n type?: Y\n /**\n * The value of the menu item group.\n */\n value?: M\n /**\n * The callback fired when any children checkbox is checked or unchecked.\n */\n onChange?: (value: M) => void\n}\n\nexport const useMenuOptionGroup = <\n Y extends \"checkbox\" | \"radio\" = \"checkbox\",\n M extends (Y extends \"checkbox\" ? string[] : string) = Y extends \"checkbox\"\n ? string[]\n : string,\n>({\n type = \"checkbox\" as Y,\n defaultValue = (type === \"checkbox\" ? [] : \"\") as M,\n value: valueProp,\n onChange: onChangeProp,\n}: UseMenuOptionGroupProps<Y, M>) => {\n const [value, setValue] = useControllableState({\n defaultValue,\n value: valueProp,\n onChange: onChangeProp,\n })\n const radio = type === \"radio\"\n\n const onChange = useCallback(\n (selectedValue: string) => {\n setValue((prev) => {\n if (radio && isString(prev)) return selectedValue as M\n else if (!radio && isArray(prev))\n return (\n prev.includes(selectedValue)\n ? prev.filter((value) => value !== selectedValue)\n : prev.concat(selectedValue)\n ) as M\n else return prev\n })\n },\n [radio, setValue],\n )\n\n useUpdateEffect(() => {\n setValue(valueProp!)\n }, [valueProp])\n\n return {\n type,\n value,\n onChange,\n }\n}\n\nexport type UseMenuOptionGroupReturn = ReturnType<typeof useMenuOptionGroup>\n\nexport interface UseMenuOptionItemProps extends UseMenuItemProps {\n /**\n * The value of the menu option item.\n */\n value: string\n}\n\nexport const useMenuOptionItem = ({\n disabled,\n value,\n ...rest\n}: UseMenuOptionItemProps) => {\n const { type, value: selectedValue, onChange } = useMenuOptionGroupContext()\n const { getItemProps } = useMenuItem({ disabled, value, ...rest })\n const radio = type === \"radio\" && isString(selectedValue)\n const checkbox = type === \"checkbox\" && isArray(selectedValue)\n const selected = radio\n ? value === selectedValue\n : checkbox\n ? selectedValue.includes(value)\n : false\n\n const getIndicatorProps: PropGetter = useCallback(\n ({ style, ...props } = {}) => ({\n style: { opacity: selected ? 1 : 0, ...style },\n ...props,\n }),\n [selected],\n )\n\n const getOptionItemProps: PropGetter = useCallback(\n (props = {}) =>\n getItemProps({\n role: radio ? \"menuitemradio\" : \"menuitemcheckbox\",\n ...props,\n onClick: handlerAll(props.onClick, () =>\n !disabled ? onChange?.(value) : noop,\n ),\n }),\n [disabled, getItemProps, onChange, radio, value],\n )\n\n return {\n type,\n selected,\n getIndicatorProps,\n getOptionItemProps,\n }\n}\n\nexport type UseMenuOptionItemReturn = ReturnType<typeof useMenuOptionItem>\n"],"mappings":";;;;;;;;;;;;AAiCA,MAAM,EACJ,oBAAoB,wBACpB,eAAe,mBACf,uBAAuB,2BACvB,gBAAgB,uBACd,kBAAuD;AAgB3D,MAAM,CAAC,aAAa,kBAAkBA,gBAA2B,EAC/D,MAAM,cACR,CAAC;AAID,MAAM,CAAC,kBAAkB,uBAAuBA,gBAC9C,EACE,MAAM,mBACR,CACF;AAUA,MAAM,CAAC,iBAAiB,sBAAsBA,gBAA+B;CAC3E,MAAM;CACN,QAAQ;AACV,CAAC;AAQD,MAAM,CAAC,wBAAwB,6BAC7BA,gBAAsC,EACpC,MAAM,yBACR,CAAC;AAsCH,MAAa,WAAW,EACtB,eACA,aACA,WAAW,OACX,MAAM,UACN,mBAAmB,OACnB,SAAS,aACT,QAAQ,YACR,UAAU,iBACM,CAAC,MAAM;CACvB,MAAM,YAAY,MAAM;CACxB,MAAM,YAAY,MAAM;CACxB,MAAM,cAAc,mBAAmB;CACvC,MAAM,YAAY,OAAmBC,cAAAA,IAAI;CACzC,MAAM,aAAa,OAAmBA,cAAAA,IAAI;CAC1C,MAAM,aAAa,OAAuB,IAAI;CAC9C,MAAM,EAAE,MAAM,SAAS,WAAW,cAAc;EAC9C;EACA,MAAM;EACN,SAAS;EACT,QAAQ;CACV,CAAC;CACD,MAAM,iBAAiB,kBAAkB,WAAW,QAAQ,GAAG,CAAC,CAAC;CACjE,MAAM,qBAAqB,aAEvB,YACA,UAAwB,EAAE,eAAe,KAAK,MAC3C;EACH,IAAI,CAAC,WAAW,WAAW,CAAC,cAAc,UAAU;EAEpD,WAAW,QAAQ,aAAa,yBAAyB,WAAW,EAAE;EAEtE,Y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;QAE5B,OAAO;EACd,CAAC;CACH,GACA,CAAC,OAAO,QAAQ,CAClB;CAEA,sBAAsB;EACpB,SAAS,SAAU;CACrB,GAAG,CAAC,SAAS,CAAC;CAEd,OAAO;EACL;EACA;EACA;CACF;AACF;AAWA,MAAa,qBAAqB,EAChC,UACA,OACA,GAAG,WACyB;CAC5B,MAAM,EAAE,MAAM,OAAO,eAAe,aAAa,0BAA0B;CAC3E,MAAM,EAAE,iBAAiB,YAAY;EAAE;EAAU;EAAO,GAAG;CAAK,CAAC;CACjE,MAAM,QAAQ,SAAS,YAAA,GAAWD,cAAAA,SAAAA,CAAS,aAAa;CACxD,MAAM,WAAW,SAAS,eAAA,GAAcC,cAAAA,QAAAA,CAAQ,aAAa;CAC7D,MAAM,WAAW,QACb,UAAU,gBACV,WACE,cAAc,SAAS,KAAK,IAC5B;CAsBN,OAAO;EACL;EACA;EACA,mBAvBoC,aACnC,EAAE,OAAO,GAAG,UAAU,CAAC,OAAO;GAC7B,OAAO;IAAE,SAAS,WAAW,IAAI;IAAG,GAAG;GAAM;GAC7C,GAAG;EACL,IACA,CAAC,QAAQ,CAkBO;EAChB,oBAhBqC,aACpC,QAAQ,CAAC,MACR,aAAa;GACX,MAAM,QAAQ,kBAAkB;GAChC,GAAG;GACH,UAAA,GAASH,cAAAA,WAAAA,CAAW,MAAM,eACxB,CAAC,WAAW,WAAW,KAAK,IAAIH,cAAAA,IAClC;EACF,CAAC,GACH;GAAC;GAAU;GAAc;GAAU;GAAO;EAAK,CAO9B;CACnB;AACF"}
@@ -1,10 +1,10 @@
1
1
  "use client";
2
- import { assignRef, mergeRefs } from "../../utils/ref.js";
2
+ import { mergeRefs } from "../../utils/ref.js";
3
3
  import { mergeProps } from "../../core/components/props.js";
4
4
  import { useEnvironment } from "../../core/system/environment-provider.js";
5
5
  import { usePopper } from "../../hooks/use-popper/index.js";
6
6
  import { utils_exports } from "../../utils/index.js";
7
- import { useCallback, useId, useRef } from "react";
7
+ import { useCallback, useId, useImperativeHandle, useRef } from "react";
8
8
  // src/components/native-popover/use-native-popover.tsx
9
9
  const useNativePopover = ({ autoUpdate, disabled = false, elements, flip, gutter, matchWidth, middleware, offset, placement = "end", platform, popover = "auto", popoverTarget, popoverTargetAction = "toggle", preventOverflow, strategy, transform, updateRef, whileElementsMounted } = {}) => {
10
10
  const { getDocument } = useEnvironment();
@@ -30,7 +30,7 @@ const useNativePopover = ({ autoUpdate, disabled = false, elements, flip, gutter
30
30
  transform,
31
31
  whileElementsMounted
32
32
  });
33
- assignRef(updateRef, update);
33
+ useImperativeHandle(updateRef, () => update, [update]);
34
34
  const onClick = useCallback((ev) => {
35
35
  if (!disabled) return;
36
36
  ev.preventDefault();
@@ -1 +1 @@
1
- {"version":3,"file":"use-native-popover.js","names":["ariaAttr","handlerAll","dataAttr"],"sources":["../../../../src/components/native-popover/use-native-popover.tsx"],"sourcesContent":["\"use client\"\n\nimport type { MouseEvent, RefObject } from \"react\"\nimport type { PropGetter } from \"../../core\"\nimport type { UsePopperProps } from \"../../hooks/use-popper\"\nimport { useCallback, useId, useRef } from \"react\"\nimport { mergeProps, useEnvironment } from \"../../core\"\nimport { usePopper } from \"../../hooks/use-popper\"\nimport {\n ariaAttr,\n assignRef,\n dataAttr,\n handlerAll,\n mergeRefs,\n} from \"../../utils\"\n\nexport interface UseNativePopoverProps extends UsePopperProps<\"button\"> {\n /**\n * If `true`, the popover will be disabled.\n *\n * @default false\n */\n disabled?: boolean\n /**\n * The placement of the popper relative to its reference.\n *\n * @default 'end'\n */\n placement?: UsePopperProps[\"placement\"]\n /**\n * The mode of the popover.\n *\n * @default 'auto'\n */\n popover?: \"\" | \"auto\" | \"hint\" | \"manual\" | true\n /**\n * The target element ID for the popover trigger.\n * If not provided, a generated ID will be used.\n */\n popoverTarget?: string\n /**\n * The action for the popover target.\n *\n * @default 'toggle'\n */\n popoverTargetAction?: \"hide\" | \"show\" | \"toggle\"\n /**\n * Update the position of the floating element, re-rendering the component if required.\n */\n updateRef?: RefObject<() => void>\n}\n\nexport const useNativePopover = ({\n autoUpdate,\n disabled = false,\n elements,\n flip,\n gutter,\n matchWidth,\n middleware,\n offset,\n placement = \"end\",\n platform,\n popover = \"auto\",\n popoverTarget,\n popoverTargetAction = \"toggle\",\n preventOverflow,\n strategy,\n transform,\n updateRef,\n whileElementsMounted,\n}: UseNativePopoverProps = {}) => {\n const { getDocument } = useEnvironment()\n const headerId = useId()\n const bodyId = useId()\n const generatedContentId = useId()\n const contentId = popoverTarget ?? generatedContentId\n const anchorRef = useRef<HTMLElement>(null)\n const triggerRef = useRef<HTMLButtonElement>(null)\n const contentRef = useRef<HTMLDivElement>(null)\n const { refs, update, getPopperProps } = usePopper<\"button\">({\n autoUpdate,\n elements,\n flip,\n gutter,\n matchWidth,\n middleware,\n offset,\n placement,\n platform,\n preventOverflow,\n strategy,\n transform,\n whileElementsMounted,\n })\n\n assignRef(updateRef, update)\n\n const onClick = useCallback(\n (ev: MouseEvent<HTMLButtonElement>) => {\n if (!disabled) return\n\n ev.preventDefault()\n ev.stopPropagation()\n },\n [disabled],\n )\n\n const getTriggerProps: PropGetter<\"button\"> = useCallback(\n ({ ref, ...props } = {}) => {\n return {\n type: \"button\",\n \"aria-controls\": contentId,\n \"aria-disabled\": ariaAttr(disabled),\n \"aria-haspopup\": \"dialog\",\n popoverTarget: contentId,\n popoverTargetAction,\n role: \"button\",\n ...props,\n ref: mergeRefs(ref, triggerRef, (node) => {\n if (anchorRef.current == null) refs.setReference(node)\n }),\n onClick: handlerAll(props.onClick, onClick),\n }\n },\n [contentId, disabled, onClick, popoverTargetAction, refs],\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 (props = {}) => {\n const hasHeader = !!getDocument()?.getElementById(headerId)\n const hasBody = !!getDocument()?.getElementById(bodyId)\n\n return mergeProps(\n {\n id: contentId,\n ref: contentRef,\n \"aria-describedby\": hasBody ? bodyId : undefined,\n \"aria-labelledby\": hasHeader ? headerId : undefined,\n \"data-popup\": dataAttr(true),\n popover: popover === true ? \"\" : popover,\n role: \"dialog\",\n tabIndex: -1,\n },\n props,\n )()\n },\n [getDocument, headerId, bodyId, contentId, popover],\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 return {\n popoverTarget: contentId,\n popoverTargetAction: \"hide\",\n ...props,\n }\n },\n [contentId],\n )\n\n return {\n getAnchorProps,\n getBodyProps,\n getCloseTriggerProps,\n getContentProps,\n getFooterProps,\n getHeaderProps,\n getPositionerProps,\n getTriggerProps,\n }\n}\n\nexport type UseNativePopoverReturn = ReturnType<typeof useNativePopover>\n"],"mappings":";;;;;;;;AAoDA,MAAa,oBAAoB,EAC/B,YACA,WAAW,OACX,UACA,MACA,QACA,YACA,YACA,QACA,YAAY,OACZ,UACA,UAAU,QACV,eACA,sBAAsB,UACtB,iBACA,UACA,WACA,WACA,yBACyB,CAAC,MAAM;CAChC,MAAM,EAAE,gBAAgB,eAAe;CACvC,MAAM,WAAW,MAAM;CACvB,MAAM,SAAS,MAAM;CACrB,MAAM,qBAAqB,MAAM;CACjC,MAAM,YAAY,iBAAiB;CACnC,MAAM,YAAY,OAAoB,IAAI;CAC1C,MAAM,aAAa,OAA0B,IAAI;CACjD,MAAM,aAAa,OAAuB,IAAI;CAC9C,MAAM,EAAE,MAAM,QAAQ,mBAAmB,UAAoB;EAC3D;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA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AAW;CAAO,CACpD;CAEA,MAAM,iBAA6B,aAChC,WAAW;EAAE,IAAI;EAAU,GAAG;CAAM,IACrC,CAAC,QAAQ,CACX;CAEA,MAAM,eAA2B,aAC9B,WAAW;EAAE,IAAI;EAAQ,GAAG;CAAM,IACnC,CAAC,MAAM,CACT;CAEA,MAAM,iBAA6B,aAAa,WAAW,EAAE,GAAG,MAAM,IAAI,CAAC,CAAC;CAa5E,OAAO;EACL;EACA;EACA,sBAdiD,aAChD,QAAQ,CAAC,MAAM;GACd,OAAO;IACL,eAAe;IACf,qBAAqB;IACrB,GAAG;GACL;EACF,GACA,CAAC,SAAS,CAMS;EACnB;EACA;EACA;EACA;EACA;CACF;AACF"}
1
+ {"version":3,"file":"use-native-popover.js","names":["ariaAttr","handlerAll","dataAttr"],"sources":["../../../../src/components/native-popover/use-native-popover.tsx"],"sourcesContent":["\"use client\"\n\nimport type { MouseEvent, RefObject } from \"react\"\nimport type { PropGetter } from \"../../core\"\nimport type { UsePopperProps } from \"../../hooks/use-popper\"\nimport { useCallback, useId, useImperativeHandle, useRef } from \"react\"\nimport { mergeProps, useEnvironment } from \"../../core\"\nimport { usePopper } from \"../../hooks/use-popper\"\nimport { ariaAttr, dataAttr, handlerAll, mergeRefs } from \"../../utils\"\n\nexport interface UseNativePopoverProps extends UsePopperProps<\"button\"> {\n /**\n * If `true`, the popover will be disabled.\n *\n * @default false\n */\n disabled?: boolean\n /**\n * The placement of the popper relative to its reference.\n *\n * @default 'end'\n */\n placement?: UsePopperProps[\"placement\"]\n /**\n * The mode of the popover.\n *\n * @default 'auto'\n */\n popover?: \"\" | \"auto\" | \"hint\" | \"manual\" | true\n /**\n * The target element ID for the popover trigger.\n * If not provided, a generated ID will be used.\n */\n popoverTarget?: string\n /**\n * The action for the popover target.\n *\n * @default 'toggle'\n */\n popoverTargetAction?: \"hide\" | \"show\" | \"toggle\"\n /**\n * Update the position of the floating element, re-rendering the component if required.\n */\n updateRef?: RefObject<() => void>\n}\n\nexport const useNativePopover = ({\n autoUpdate,\n disabled = false,\n elements,\n flip,\n gutter,\n matchWidth,\n middleware,\n offset,\n placement = \"end\",\n platform,\n popover = \"auto\",\n popoverTarget,\n popoverTargetAction = \"toggle\",\n preventOverflow,\n strategy,\n transform,\n updateRef,\n whileElementsMounted,\n}: UseNativePopoverProps = {}) => {\n const { getDocument } = useEnvironment()\n const headerId = useId()\n const bodyId = useId()\n const generatedContentId = useId()\n const contentId = popoverTarget ?? generatedContentId\n const anchorRef = useRef<HTMLElement>(null)\n const triggerRef = useRef<HTMLButtonElement>(null)\n const contentRef = useRef<HTMLDivElement>(null)\n const { refs, update, getPopperProps } = usePopper<\"button\">({\n autoUpdate,\n elements,\n flip,\n gutter,\n matchWidth,\n middleware,\n offset,\n placement,\n platform,\n preventOverflow,\n strategy,\n transform,\n whileElementsMounted,\n })\n\n useImperativeHandle(updateRef, () => update, [update])\n\n const onClick = useCallback(\n (ev: MouseEvent<HTMLButtonElement>) => {\n if (!disabled) return\n\n ev.preventDefault()\n ev.stopPropagation()\n },\n [disabled],\n )\n\n const getTriggerProps: PropGetter<\"button\"> = useCallback(\n ({ ref, ...props } = {}) => {\n return {\n type: \"button\",\n \"aria-controls\": contentId,\n \"aria-disabled\": ariaAttr(disabled),\n \"aria-haspopup\": \"dialog\",\n popoverTarget: contentId,\n popoverTargetAction,\n role: \"button\",\n ...props,\n ref: mergeRefs(ref, triggerRef, (node) => {\n if (anchorRef.current == null) refs.setReference(node)\n }),\n onClick: handlerAll(props.onClick, onClick),\n }\n },\n [contentId, disabled, onClick, popoverTargetAction, refs],\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 (props = {}) => {\n const hasHeader = !!getDocument()?.getElementById(headerId)\n const hasBody = !!getDocument()?.getElementById(bodyId)\n\n return mergeProps(\n {\n id: contentId,\n ref: contentRef,\n \"aria-describedby\": hasBody ? bodyId : undefined,\n \"aria-labelledby\": hasHeader ? headerId : undefined,\n \"data-popup\": dataAttr(true),\n popover: popover === true ? \"\" : popover,\n role: \"dialog\",\n tabIndex: -1,\n },\n props,\n )()\n },\n [getDocument, headerId, bodyId, contentId, popover],\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 return {\n popoverTarget: contentId,\n popoverTargetAction: \"hide\",\n ...props,\n }\n },\n [contentId],\n )\n\n return {\n getAnchorProps,\n getBodyProps,\n getCloseTriggerProps,\n getContentProps,\n getFooterProps,\n getHeaderProps,\n getPositionerProps,\n getTriggerProps,\n }\n}\n\nexport type UseNativePopoverReturn = ReturnType<typeof useNativePopover>\n"],"mappings":";;;;;;;;AA8CA,MAAa,oBAAoB,EAC/B,YACA,WAAW,OACX,UACA,MACA,QACA,YACA,YACA,QACA,YAAY,OACZ,UACA,UAAU,QACV,eACA,sBAAsB,UACtB,iBACA,UACA,WACA,WACA,yBACyB,CAAC,MAAM;CAChC,MAAM,EAAE,gBAAgB,eAAe;CACvC,MAAM,WAAW,MAAM;CACvB,MAAM,SAAS,MAAM;CACrB,MAAM,qBAAqB,MAAM;CACjC,MAAM,YAAY,iBAAiB;CACnC,MAAM,YAAY,OAAoB,IAAI;CAC1C,MAAM,aAAa,OAA0B,IAAI;CACjD,MAAM,aAAa,OAAuB,IAAI;CAC9C,MAAM,EAAE,MAAM,QAAQ,mBAAmB,UAAoB;EAC3D;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CAAC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AU;EAAQ;EAAW;CAAO,CACpD;CAEA,MAAM,iBAA6B,aAChC,WAAW;EAAE,IAAI;EAAU,GAAG;CAAM,IACrC,CAAC,QAAQ,CACX;CAEA,MAAM,eAA2B,aAC9B,WAAW;EAAE,IAAI;EAAQ,GAAG;CAAM,IACnC,CAAC,MAAM,CACT;CAEA,MAAM,iBAA6B,aAAa,WAAW,EAAE,GAAG,MAAM,IAAI,CAAC,CAAC;CAa5E,OAAO;EACL;EACA;EACA,sBAdiD,aAChD,QAAQ,CAAC,MAAM;GACd,OAAO;IACL,eAAe;IACf,qBAAqB;IACrB,GAAG;GACL;EACF,GACA,CAAC,SAAS,CAMS;EACnB;EACA;EACA;EACA;EACA;CACF;AACF"}
@@ -1,49 +1,49 @@
1
1
  "use client";
2
2
  import { Portal } from "../portal/portal.js";
3
3
  import { NoticeRoot, PLACEMENT_MAP } from "./notice.js";
4
- import { createContext, createRef, use, useId, useMemo, useRef } from "react";
4
+ import { createContext, createRef, use, useId, useMemo, useState } from "react";
5
5
  import { jsx, jsxs } from "react/jsx-runtime";
6
6
  // src/components/notice/notice-provider.tsx
7
7
  const NoticeContext = createContext({});
8
- const createController = () => ({
9
- getLimit: createRef(),
10
- updateLimit: createRef()
11
- });
12
8
  const createMethods = (id, refs, defaultLimit) => ({
13
9
  getId: (placement) => {
14
10
  return `${id}-${placement}`;
15
11
  },
16
12
  getLimit: (placement) => {
17
- const method = refs[placement]?.current.getLimit.current;
18
- return method?.(placement) ?? defaultLimit;
13
+ return refs.get(placement)?.current?.getLimit(placement) ?? defaultLimit;
19
14
  },
20
15
  updateLimit: (state) => {
21
16
  const { placement } = state;
22
- const method = refs[placement]?.current.updateLimit.current;
23
- method?.(state);
17
+ refs.get(placement)?.current?.updateLimit(state);
24
18
  }
25
19
  });
26
20
  const NoticeProvider = ({ children, containerRef, expand = false, limit = 3 }) => {
27
- const placementMap = useRef({});
21
+ const [placementMap] = useState(() => {
22
+ const placements = Object.keys(PLACEMENT_MAP);
23
+ return new Map(placements.map((placement) => [placement, createRef()]));
24
+ });
28
25
  const id = useId();
29
- const value = useMemo(() => ({ ...createMethods(id, placementMap.current, limit) }), [id, limit]);
30
- const components = useMemo(() => {
31
- return Object.keys(PLACEMENT_MAP).map((placement) => {
32
- if (!placementMap.current[placement]) placementMap.current[placement] = { current: createController() };
33
- return /* @__PURE__ */ jsx(NoticeRoot, {
34
- ref: placementMap.current[placement],
35
- expand,
36
- limit,
37
- placement
38
- }, placement);
39
- });
40
- }, [limit, expand]);
26
+ const value = useMemo(() => createMethods(id, placementMap, limit), [
27
+ id,
28
+ limit,
29
+ placementMap
30
+ ]);
31
+ const components = useMemo(() => Array.from(placementMap, ([placement, ref]) => /* @__PURE__ */ jsx(NoticeRoot, {
32
+ ref,
33
+ expand,
34
+ limit,
35
+ placement
36
+ }, placement)), [
37
+ limit,
38
+ expand,
39
+ placementMap
40
+ ]);
41
41
  return /* @__PURE__ */ jsxs(NoticeContext, {
42
42
  value,
43
- children: [children, /* @__PURE__ */ jsx(Portal, {
43
+ children: [/* @__PURE__ */ jsx(Portal, {
44
44
  containerRef,
45
45
  children: components
46
- })]
46
+ }), children]
47
47
  });
48
48
  };
49
49
  const useNoticeContext = () => {
@@ -1 +1 @@
1
- {"version":3,"file":"notice-provider.js","names":[],"sources":["../../../../src/components/notice/notice-provider.tsx"],"sourcesContent":["\"use client\"\n\nimport type { FC, RefObject } from \"react\"\nimport type {\n HTMLStyledProps,\n NoticeConfig,\n NoticePlacement,\n ThemeProps,\n} from \"../../core\"\nimport type { NoticeStyle } from \"./notice.style\"\nimport { createContext, createRef, use, useId, useMemo, useRef } from \"react\"\nimport { Portal } from \"../portal\"\nimport { NoticeRoot, PLACEMENT_MAP } from \"./notice\"\n\nexport interface NoticeProviderProps\n extends HTMLStyledProps, NoticeConfig, ThemeProps<NoticeStyle> {\n /**\n * Container ref for the portal.\n */\n containerRef?: RefObject<HTMLElement>\n}\n\ninterface NoticeState {\n limit: number\n placement: NoticePlacement\n}\n\nexport interface NoticeMethods {\n getId: (placement: NoticePlacement) => string\n getLimit: (placement: NoticePlacement) => number\n updateLimit: (state: NoticeState) => void\n}\n\ninterface NoticeContext extends NoticeMethods {}\n\nconst NoticeContext = createContext({} as NoticeContext)\n\nexport type Controller = ReturnType<typeof createController>\n\nconst createController = () => ({\n getLimit: createRef<NoticeMethods[\"getLimit\"]>(),\n updateLimit: createRef<NoticeMethods[\"updateLimit\"]>(),\n})\n\nconst createMethods = (\n id: string,\n refs: {\n [K in NoticePlacement]?: RefObject<Controller>\n },\n defaultLimit: number,\n): NoticeMethods => ({\n getId: (placement) => {\n return `${id}-${placement}`\n },\n getLimit: (placement) => {\n const method = refs[placement]?.current.getLimit.current\n\n return method?.(placement) ?? defaultLimit\n },\n updateLimit: (state) => {\n const { placement } = state\n const method = refs[placement]?.current.updateLimit.current\n\n method?.(state)\n },\n})\n\nexport const NoticeProvider: FC<NoticeProviderProps> = ({\n children,\n containerRef,\n expand = false,\n limit = 3,\n}) => {\n const placementMap = useRef<{\n [K in NoticePlacement]?: RefObject<Controller>\n }>({})\n const id = useId()\n\n const value = useMemo(\n () => ({ ...createMethods(id, placementMap.current, limit) }),\n [id, limit],\n )\n\n const components = useMemo(() => {\n return (Object.keys(PLACEMENT_MAP) as NoticePlacement[]).map(\n (placement) => {\n if (!placementMap.current[placement])\n placementMap.current[placement] = { current: createController() }\n\n return (\n <NoticeRoot\n key={placement}\n ref={placementMap.current[placement]}\n expand={expand}\n limit={limit}\n placement={placement}\n />\n )\n },\n )\n }, [limit, expand])\n\n return (\n <NoticeContext value={value}>\n {children}\n <Portal containerRef={containerRef}>{components}</Portal>\n </NoticeContext>\n )\n}\n\nexport const useNoticeContext = (): NoticeContext => {\n const context = use(NoticeContext)\n\n return context\n}\n"],"mappings":";;;;;;AAmCA,MAAM,gBAAgB,cAAc,CAAC,CAAkB;AAIvD,MAAM,0BAA0B;CAC9B,UAAU,UAAqC;CAC/C,aAAa,UAAwC;AACvD;AAEA,MAAM,iBACJ,IACA,MAGA,kBACmB;CACnB,QAAQ,cAAc;EACpB,OAAO,GAAG,GAAG,GAAG;CAClB;CACA,WAAW,cAAc;EACvB,MAAM,SAAS,KAAK,UAAU,EAAE,QAAQ,SAAS;EAEjD,OAAO,SAAS,SAAS,KAAK;CAChC;CACA,cAAc,UAAU;EACtB,MAAM,EAAE,cAAc;EACtB,MAAM,SAAS,KAAK,UAAU,EAAE,QAAQ,YAAY;EAEpD,SAAS,KAAK;CAChB;AACF;AAEA,MAAa,kBAA2C,EACtD,UACA,cACA,SAAS,OACT,QAAQ,QACJ;CACJ,MAAM,eAAe,OAElB,CAAC,CAAC;CACL,MAAM,KAAK,MAAM;CAEjB,MAAM,QAAQ,eACL,EAAE,GAAG,cAAc,IAAI,aAAa,SAAS,KAAK,EAAE,IAC3D,CAAC,IAAI,KAAK,CACZ;CAEA,MAAM,aAAa,cAAc;EAC/B,OAAQ,OAAO,KAAK,aAAa,CAAC,CAAuB,KACtD,cAAc;GACb,IAAI,CAAC,aAAa,QAAQ,YACxB,aAAa,QAAQ,aAAa,EAAE,SAAS,iBAAiB,EAAE;GAElE,OACE,oBAAC,YAAD;IAEE,KAAK,aAAa,QAAQ;IAClB;IACD;IACI;GACZ,GALM,SAKN;EAEL,CACF;CACF,GAAG,CAAC,OAAO,MAAM,CAAC;CAElB,OACE,qBAAC,eAAD;EAAsB;EAAtB,UAAA,CACG,UACD,oBAAC,QAAD;GAAsB;GAAe,UAAA;EAAmB,CAAA,CAC3C;;AAEnB;AAEA,MAAa,yBAAwC;CAGnD,OAFgB,IAAI,aAEP;AACf"}
1
+ {"version":3,"file":"notice-provider.js","names":[],"sources":["../../../../src/components/notice/notice-provider.tsx"],"sourcesContent":["\"use client\"\n\nimport type { FC, RefObject } from \"react\"\nimport type {\n HTMLStyledProps,\n NoticeConfig,\n NoticePlacement,\n ThemeProps,\n} from \"../../core\"\nimport type { NoticeStyle } from \"./notice.style\"\nimport { createContext, createRef, use, useId, useMemo, useState } from \"react\"\nimport { Portal } from \"../portal\"\nimport { NoticeRoot, PLACEMENT_MAP } from \"./notice\"\n\nexport interface NoticeProviderProps\n extends HTMLStyledProps, NoticeConfig, ThemeProps<NoticeStyle> {\n /**\n * Container ref for the portal.\n */\n containerRef?: RefObject<HTMLElement>\n}\n\ninterface NoticeState {\n limit: number\n placement: NoticePlacement\n}\n\nexport interface NoticeMethods {\n getId: (placement: NoticePlacement) => string\n getLimit: (placement: NoticePlacement) => number\n updateLimit: (state: NoticeState) => void\n}\n\ninterface NoticeContext extends NoticeMethods {}\n\nconst NoticeContext = createContext({} as NoticeContext)\n\nexport type Controller = Pick<NoticeMethods, \"getLimit\" | \"updateLimit\">\n\nconst createMethods = (\n id: string,\n refs: Map<NoticePlacement, RefObject<Controller | null>>,\n defaultLimit: number,\n): NoticeMethods => ({\n getId: (placement) => {\n return `${id}-${placement}`\n },\n getLimit: (placement) => {\n return refs.get(placement)?.current?.getLimit(placement) ?? defaultLimit\n },\n updateLimit: (state) => {\n const { placement } = state\n refs.get(placement)?.current?.updateLimit(state)\n },\n})\n\nexport const NoticeProvider: FC<NoticeProviderProps> = ({\n children,\n containerRef,\n expand = false,\n limit = 3,\n}) => {\n const [placementMap] = useState(() => {\n const placements = Object.keys(PLACEMENT_MAP) as NoticePlacement[]\n\n return new Map(\n placements.map((placement) => [placement, createRef<Controller>()]),\n )\n })\n const id = useId()\n\n const value = useMemo(\n () => createMethods(id, placementMap, limit),\n [id, limit, placementMap],\n )\n\n const components = useMemo(\n () =>\n Array.from(placementMap, ([placement, ref]) => (\n <NoticeRoot\n key={placement}\n ref={ref}\n expand={expand}\n limit={limit}\n placement={placement}\n />\n )),\n [limit, expand, placementMap],\n )\n\n return (\n <NoticeContext value={value}>\n <Portal containerRef={containerRef}>{components}</Portal>\n {children}\n </NoticeContext>\n )\n}\n\nexport const useNoticeContext = (): NoticeContext => {\n const context = use(NoticeContext)\n\n return context\n}\n"],"mappings":";;;;;;AAmCA,MAAM,gBAAgB,cAAc,CAAC,CAAkB;AAIvD,MAAM,iBACJ,IACA,MACA,kBACmB;CACnB,QAAQ,cAAc;EACpB,OAAO,GAAG,GAAG,GAAG;CAClB;CACA,WAAW,cAAc;EACvB,OAAO,KAAK,IAAI,SAAS,CAAC,EAAE,SAAS,SAAS,SAAS,KAAK;CAC9D;CACA,cAAc,UAAU;EACtB,MAAM,EAAE,cAAc;EACtB,KAAK,IAAI,SAAS,CAAC,EAAE,SAAS,YAAY,KAAK;CACjD;AACF;AAEA,MAAa,kBAA2C,EACtD,UACA,cACA,SAAS,OACT,QAAQ,QACJ;CACJ,MAAM,CAAC,gBAAgB,eAAe;EACpC,MAAM,aAAa,OAAO,KAAK,aAAa;EAE5C,OAAO,IAAI,IACT,WAAW,KAAK,cAAc,CAAC,WAAW,UAAsB,CAAC,CAAC,CACpE;CACF,CAAC;CACD,MAAM,KAAK,MAAM;CAEjB,MAAM,QAAQ,cACN,cAAc,IAAI,cAAc,KAAK,GAC3C;EAAC;EAAI;EAAO;CAAY,CAC1B;CAEA,MAAM,aAAa,cAEf,MAAM,KAAK,eAAe,CAAC,WAAW,SACpC,oBAAC,YAAD;EAEO;EACG;EACD;EACI;CACZ,GALM,SAKN,CACF,GACH;EAAC;EAAO;EAAQ;CAAY,CAC9B;CAEA,OACE,qBAAC,eAAD;EAAsB;EAAtB,UAAA,CACE,oBAAC,QAAD;GAAsB;GAAe,UAAA;EAAmB,CAAA,GACvD,QACY;;AAEnB;AAEA,MAAa,yBAAwC;CAGnD,OAFgB,IAAI,aAEP;AACf"}
@@ -1,5 +1,4 @@
1
1
  "use client";
2
- import { assignRef } from "../../utils/ref.js";
3
2
  import { createSlotComponent } from "../../core/components/create-component.js";
4
3
  import { styled } from "../../core/system/factory.js";
5
4
  import { utils_exports } from "../../utils/index.js";
@@ -7,7 +6,7 @@ import { AlertDescription, AlertIcon, AlertLoading, AlertRoot, AlertTitle } from
7
6
  import { CloseButton } from "../close-button/close-button.js";
8
7
  import { useNoticeContext } from "./notice-provider.js";
9
8
  import { noticeStyle } from "./notice.style.js";
10
- import { useCallback, useMemo, useState } from "react";
9
+ import { useCallback, useImperativeHandle, useMemo, useState } from "react";
11
10
  import { jsx, jsxs } from "react/jsx-runtime";
12
11
  import { Toaster, toast } from "sonner";
13
12
  // src/components/notice/notice.tsx
@@ -37,8 +36,10 @@ const NoticeRoot = withProvider(({ ref, expand, limit, placement, ...rest }) =>
37
36
  const updateLimit = useCallback(({ limit, placement: target }) => {
38
37
  if (target === placement) setUpdatedLimit(limit);
39
38
  }, [placement]);
40
- assignRef(ref.current.updateLimit, updateLimit);
41
- assignRef(ref.current.getLimit, getLimit);
39
+ useImperativeHandle(ref, () => ({
40
+ getLimit,
41
+ updateLimit
42
+ }), [getLimit, updateLimit]);
42
43
  return /* @__PURE__ */ jsx(styled.div, {
43
44
  ...rest,
44
45
  children: /* @__PURE__ */ jsx(Toaster, {
@@ -1 +1 @@
1
- {"version":3,"file":"notice.js","names":["Alert.Root","handlerAll","noop","Alert.Loading","Alert.Icon","dataAttr","Alert.Title","Alert.Description"],"sources":["../../../../src/components/notice/notice.tsx"],"sourcesContent":["\"use client\"\n\nimport type { RefObject } from \"react\"\nimport type { ToasterProps } from \"sonner\"\nimport type {\n HTMLStyledProps,\n NoticeCloseStrategy,\n NoticeConfig,\n NoticePlacement,\n} from \"../../core\"\nimport type { CloseButtonProps } from \"../close-button\"\nimport type { Controller, NoticeMethods } from \"./notice-provider\"\nimport type { NoticeStyle } from \"./notice.style\"\nimport type { UseNoticeOptions } from \"./use-notice\"\nimport { useCallback, useMemo, useState } from \"react\"\nimport { toast, Toaster } from \"sonner\"\nimport { createSlotComponent, styled } from \"../../core\"\nimport { assignRef, dataAttr, handlerAll, noop } from \"../../utils\"\nimport { Alert } from \"../alert\"\nimport { CloseButton } from \"../close-button\"\nimport { useNoticeContext } from \"./notice-provider\"\nimport { noticeStyle } from \"./notice.style\"\n\ntype ToasterPosition = Required<ToasterProps>[\"position\"]\n\nexport const PLACEMENT_MAP: {\n [key in NoticePlacement]: ToasterPosition\n} = {\n end: \"bottom-center\",\n \"end-center\": \"bottom-center\",\n \"end-end\": \"bottom-right\",\n \"end-start\": \"bottom-left\",\n start: \"top-center\",\n \"start-center\": \"top-center\",\n \"start-end\": \"top-right\",\n \"start-start\": \"top-left\",\n}\n\nexport interface NoticeRootProps extends Pick<\n Required<NoticeConfig>,\n \"expand\" | \"limit\" | \"placement\"\n> {\n ref: RefObject<Controller>\n}\n\nconst {\n PropsContext: NoticePropsContext,\n usePropsContext: useNoticePropsContext,\n withContext,\n withProvider,\n} = createSlotComponent<NoticeRootProps, NoticeStyle>(\"notice\", noticeStyle)\n\nexport { NoticePropsContext, useNoticePropsContext }\n\nexport const NoticeRoot = withProvider<\"fragment\", NoticeRootProps>(\n ({ ref, expand, limit, placement, ...rest }) => {\n const { getId } = useNoticeContext()\n const position = useMemo(() => PLACEMENT_MAP[placement], [placement])\n const [updatedLimit, setUpdatedLimit] = useState(limit)\n\n const getLimit = useCallback<NoticeMethods[\"getLimit\"]>(\n (target) => {\n if (target === placement && updatedLimit !== limit) return updatedLimit\n else return limit\n },\n [placement, limit, updatedLimit],\n )\n\n const updateLimit = useCallback<NoticeMethods[\"updateLimit\"]>(\n ({ limit, placement: target }) => {\n if (target === placement) setUpdatedLimit(limit)\n },\n [placement],\n )\n\n assignRef(ref.current.updateLimit, updateLimit)\n assignRef(ref.current.getLimit, getLimit)\n\n return (\n <styled.div {...rest}>\n <Toaster\n id={getId(placement)}\n containerAriaLabel=\"\"\n expand={expand}\n gap={16}\n hotkey={[\"\"]}\n mobileOffset=\"var(--mobile-offset)\"\n offset=\"var(--offset)\"\n position={position}\n visibleToasts={updatedLimit}\n />\n </styled.div>\n )\n },\n \"root\",\n)()\n\nexport interface NoticeItemProps\n extends UseNoticeOptions, Omit<HTMLStyledProps, \"id\" | \"title\"> {\n closeStrategies?: NoticeCloseStrategy[]\n}\n\nexport const NoticeItem = withContext<\"div\", NoticeItemProps>(\n ({\n id,\n variant = \"plain\",\n closable,\n closeStrategies = [\"click\", \"drag\"],\n description,\n loadingScheme,\n status,\n title,\n withIcon = true,\n closeButtonProps,\n contentProps,\n descriptionProps,\n iconProps,\n loadingProps,\n titleProps,\n onClick,\n ...rest\n }) => {\n const onClose = useCallback(() => toast.dismiss(id), [id])\n\n return (\n <Alert.Root\n variant={variant}\n status={status}\n {...rest}\n onClick={handlerAll(\n onClick,\n closable && closeStrategies.includes(\"click\") ? onClose : noop,\n )}\n >\n {withIcon ? (\n loadingScheme ? (\n <Alert.Loading loadingScheme={loadingScheme} {...loadingProps} />\n ) : (\n <Alert.Icon {...iconProps} />\n )\n ) : null}\n\n <NoticeContent\n data-close-button={dataAttr(\n closable && closeStrategies.includes(\"button\"),\n )}\n {...contentProps}\n >\n {title ? (\n <Alert.Title me=\"0\" {...titleProps}>\n {title}\n </Alert.Title>\n ) : null}\n {description ? (\n <Alert.Description lineClamp={2} {...descriptionProps}>\n {description}\n </Alert.Description>\n ) : null}\n </NoticeContent>\n\n {closable && closeStrategies.includes(\"button\") ? (\n <NoticeCloseButton\n data-variant={variant}\n {...closeButtonProps}\n onClick={handlerAll(closeButtonProps?.onClick, onClose)}\n />\n ) : null}\n </Alert.Root>\n )\n },\n \"item\",\n)()\n\nexport interface NoticeContentProps extends HTMLStyledProps {}\n\nexport const NoticeContent = withContext<\"div\", NoticeContentProps>(\n \"div\",\n \"content\",\n)()\n\nexport interface NoticeCloseButtonProps extends CloseButtonProps {}\n\nexport const NoticeCloseButton = withContext<\"button\", NoticeCloseButtonProps>(\n CloseButton,\n \"closeButton\",\n)()\n"],"mappings":";;;;;;;;;;;;;AAyBA,MAAa,gBAET;CACF,KAAK;CACL,cAAc;CACd,WAAW;CACX,aAAa;CACb,OAAO;CACP,gBAAgB;CAChB,aAAa;CACb,eAAe;AACjB;AASA,MAAM,EACJ,cAAc,oBACd,iBAAiB,uBACjB,aACA,iBACE,oBAAkD,UAAU,WAAW;AAI3E,MAAa,aAAa,cACvB,EAAE,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D;IACE,sBAAA,GAAmBC,cAAAA,SAAAA,CACjB,YAAY,gBAAgB,SAAS,QAAQ,CAC/C;IACA,GAAI;IAJN,UAAA,CAMG,QACC,oBAACC,YAAD;KAAa,IAAG;KAAI,GAAI;KACrB,UAAA;IACU,CAAA,IACX,MACH,cACC,oBAACC,kBAAD;KAAmB,WAAW;KAAG,GAAI;KAClC,UAAA;IACgB,CAAA,IACjB,IACS;;GAEd,YAAY,gBAAgB,SAAS,QAAQ,IAC5C,oBAAC,mBAAD;IACE,gBAAc;IACd,GAAI;IACJ,UAAA,GAASN,cAAAA,WAAAA,CAAW,kBAAkB,SAAS,OAAO;GACvD,CAAA,IACC;EACM;;AAEhB,GACA,MACF,CAAC,CAAC;AAIF,MAAa,gBAAgB,YAC3B,OACA,SACF,CAAC,CAAC;AAIF,MAAa,oBAAoB,YAC/B,aACA,aACF,CAAC,CAAC"}
1
+ {"version":3,"file":"notice.js","names":["Alert.Root","handlerAll","noop","Alert.Loading","Alert.Icon","dataAttr","Alert.Title","Alert.Description"],"sources":["../../../../src/components/notice/notice.tsx"],"sourcesContent":["\"use client\"\n\nimport type { RefObject } from \"react\"\nimport type { ToasterProps } from \"sonner\"\nimport type {\n HTMLStyledProps,\n NoticeCloseStrategy,\n NoticeConfig,\n NoticePlacement,\n} from \"../../core\"\nimport type { CloseButtonProps } from \"../close-button\"\nimport type { Controller, NoticeMethods } from \"./notice-provider\"\nimport type { NoticeStyle } from \"./notice.style\"\nimport type { UseNoticeOptions } from \"./use-notice\"\nimport { useCallback, useImperativeHandle, useMemo, useState } from \"react\"\nimport { toast, Toaster } from \"sonner\"\nimport { createSlotComponent, styled } from \"../../core\"\nimport { dataAttr, handlerAll, noop } from \"../../utils\"\nimport { Alert } from \"../alert\"\nimport { CloseButton } from \"../close-button\"\nimport { useNoticeContext } from \"./notice-provider\"\nimport { noticeStyle } from \"./notice.style\"\n\ntype ToasterPosition = Required<ToasterProps>[\"position\"]\n\nexport const PLACEMENT_MAP: {\n [key in NoticePlacement]: ToasterPosition\n} = {\n end: \"bottom-center\",\n \"end-center\": \"bottom-center\",\n \"end-end\": \"bottom-right\",\n \"end-start\": \"bottom-left\",\n start: \"top-center\",\n \"start-center\": \"top-center\",\n \"start-end\": \"top-right\",\n \"start-start\": \"top-left\",\n}\n\nexport interface NoticeRootProps extends Pick<\n Required<NoticeConfig>,\n \"expand\" | \"limit\" | \"placement\"\n> {\n ref: RefObject<Controller | null>\n}\n\nconst {\n PropsContext: NoticePropsContext,\n usePropsContext: useNoticePropsContext,\n withContext,\n withProvider,\n} = createSlotComponent<NoticeRootProps, NoticeStyle>(\"notice\", noticeStyle)\n\nexport { NoticePropsContext, useNoticePropsContext }\n\nexport const NoticeRoot = withProvider<\"fragment\", NoticeRootProps>(\n ({ ref, expand, limit, placement, ...rest }) => {\n const { getId } = useNoticeContext()\n const position = useMemo(() => PLACEMENT_MAP[placement], [placement])\n const [updatedLimit, setUpdatedLimit] = useState(limit)\n\n const getLimit = useCallback<NoticeMethods[\"getLimit\"]>(\n (target) => {\n if (target === placement && updatedLimit !== limit) return updatedLimit\n else return limit\n },\n [placement, limit, updatedLimit],\n )\n\n const updateLimit = useCallback<NoticeMethods[\"updateLimit\"]>(\n ({ limit, placement: target }) => {\n if (target === placement) setUpdatedLimit(limit)\n },\n [placement],\n )\n\n useImperativeHandle(ref, () => ({ getLimit, updateLimit }), [\n getLimit,\n updateLimit,\n ])\n\n return (\n <styled.div {...rest}>\n <Toaster\n id={getId(placement)}\n containerAriaLabel=\"\"\n expand={expand}\n gap={16}\n hotkey={[\"\"]}\n mobileOffset=\"var(--mobile-offset)\"\n offset=\"var(--offset)\"\n position={position}\n visibleToasts={updatedLimit}\n />\n </styled.div>\n )\n },\n \"root\",\n)()\n\nexport interface NoticeItemProps\n extends UseNoticeOptions, Omit<HTMLStyledProps, \"id\" | \"title\"> {\n closeStrategies?: NoticeCloseStrategy[]\n}\n\nexport const NoticeItem = withContext<\"div\", NoticeItemProps>(\n ({\n id,\n variant = \"plain\",\n closable,\n closeStrategies = [\"click\", \"drag\"],\n description,\n loadingScheme,\n status,\n title,\n withIcon = true,\n closeButtonProps,\n contentProps,\n descriptionProps,\n iconProps,\n loadingProps,\n titleProps,\n onClick,\n ...rest\n }) => {\n const onClose = useCallback(() => toast.dismiss(id), [id])\n\n return (\n <Alert.Root\n variant={variant}\n status={status}\n {...rest}\n onClick={handlerAll(\n onClick,\n closable && closeStrategies.includes(\"click\") ? onClose : noop,\n )}\n >\n {withIcon ? (\n loadingScheme ? (\n <Alert.Loading loadingScheme={loadingScheme} {...loadingProps} />\n ) : (\n <Alert.Icon {...iconProps} />\n )\n ) : null}\n\n <NoticeContent\n data-close-button={dataAttr(\n closable && closeStrategies.includes(\"button\"),\n )}\n {...contentProps}\n >\n {title ? (\n <Alert.Title me=\"0\" {...titleProps}>\n {title}\n </Alert.Title>\n ) : null}\n {description ? (\n <Alert.Description lineClamp={2} {...descriptionProps}>\n {description}\n </Alert.Description>\n ) : null}\n </NoticeContent>\n\n {closable && closeStrategies.includes(\"button\") ? (\n <NoticeCloseButton\n data-variant={variant}\n {...closeButtonProps}\n onClick={handlerAll(closeButtonProps?.onClick, onClose)}\n />\n ) : null}\n </Alert.Root>\n )\n },\n \"item\",\n)()\n\nexport interface NoticeContentProps extends HTMLStyledProps {}\n\nexport const NoticeContent = withContext<\"div\", NoticeContentProps>(\n \"div\",\n \"content\",\n)()\n\nexport interface NoticeCloseButtonProps extends CloseButtonProps {}\n\nexport const NoticeCloseButton = withContext<\"button\", NoticeCloseButtonProps>(\n CloseButton,\n \"closeButton\",\n)()\n"],"mappings":";;;;;;;;;;;;AAyBA,MAAa,gBAET;CACF,KAAK;CACL,cAAc;CACd,WAAW;CACX,aAAa;CACb,OAAO;CACP,gBAAgB;CAChB,aAAa;CACb,eAAe;AACjB;AASA,MAAM,EACJ,cAAc,oBACd,iBAAiB,uBACjB,aACA,iBACE,oBAAkD,UAAU,WAAW;AAI3E,MAAa,aAAa,cACvB,EAAE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AAA,GAAmBC,cAAAA,SAAAA,CACjB,YAAY,gBAAgB,SAAS,QAAQ,CAC/C;IACA,GAAI;IAJN,UAAA,CAMG,QACC,oBAACC,YAAD;KAAa,IAAG;KAAI,GAAI;KACrB,UAAA;IACU,CAAA,IACX,MACH,cACC,oBAACC,kBAAD;KAAmB,WAAW;KAAG,GAAI;KAClC,UAAA;IACgB,CAAA,IACjB,IACS;;GAEd,YAAY,gBAAgB,SAAS,QAAQ,IAC5C,oBAAC,mBAAD;IACE,gBAAc;IACd,GAAI;IACJ,UAAA,GAASN,cAAAA,WAAAA,CAAW,kBAAkB,SAAS,OAAO;GACvD,CAAA,IACC;EACM;;AAEhB,GACA,MACF,CAAC,CAAC;AAIF,MAAa,gBAAgB,YAC3B,OACA,SACF,CAAC,CAAC;AAIF,MAAa,oBAAoB,YAC/B,aACA,aACF,CAAC,CAAC"}
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import { getEventRelatedTarget, runKeyAction } from "../../utils/dom.js";
3
3
  import { useSafeLayoutEffect, useUnmountEffect } from "../../utils/effect.js";
4
- import { assignRef, mergeRefs } from "../../utils/ref.js";
4
+ import { mergeRefs } from "../../utils/ref.js";
5
5
  import { useEnvironment } from "../../core/system/environment-provider.js";
6
6
  import { useSplitProps } from "../../core/components/props.js";
7
7
  import { useDisclosure } from "../../hooks/use-disclosure/use-disclosure.js";
@@ -10,7 +10,7 @@ import { useFocusOnShow } from "../../hooks/use-focus/index.js";
10
10
  import { useOutsideClick } from "../../hooks/use-outside-click/index.js";
11
11
  import { popperProps, usePopper } from "../../hooks/use-popper/index.js";
12
12
  import { utils_exports } from "../../utils/index.js";
13
- import { useCallback, useEffect, useId, useRef } from "react";
13
+ import { useCallback, useEffect, useId, useImperativeHandle, useRef } from "react";
14
14
  // src/components/popover/use-popover.tsx
15
15
  const usePopover = ({ autoFocus = true, autoUpdate, modal = false, blockScrollOnMount = modal, closeOnBlur = true, closeOnEsc = true, closeOnScroll, defaultOpen, disabled, elements, flip, gutter, initialFocusRef, matchWidth, middleware, offset, open: openProp, openOnClick = true, placement = "end", platform, preventOverflow, strategy, transferFocus = true, transform, updateRef, whileElementsMounted, onClose: onCloseProp, onOpen: onOpenProp } = {}) => {
16
16
  const { getDocument } = useEnvironment();
@@ -44,7 +44,7 @@ const usePopover = ({ autoFocus = true, autoUpdate, modal = false, blockScrollOn
44
44
  transform,
45
45
  whileElementsMounted
46
46
  });
47
- assignRef(updateRef, update);
47
+ useImperativeHandle(updateRef, () => update, [update]);
48
48
  const onRestoreFocus = useCallback(() => {
49
49
  clearTimeout(closeTimeout.current);
50
50
  closeTimeout.current = setTimeout(() => {