@yamada-ui/react 2.2.1-dev-20260428160818 → 2.2.1-dev-20260428170353

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 (205) hide show
  1. package/dist/cjs/components/carousel/use-carousel.cjs.map +1 -1
  2. package/dist/cjs/components/tree/use-tree.cjs +5 -5
  3. package/dist/cjs/components/tree/use-tree.cjs.map +1 -1
  4. package/dist/esm/components/carousel/use-carousel.js.map +1 -1
  5. package/dist/esm/components/tree/use-tree.js +5 -5
  6. package/dist/esm/components/tree/use-tree.js.map +1 -1
  7. package/dist/types/components/accordion/accordion.d.ts +2 -2
  8. package/dist/types/components/accordion/accordion.style.d.ts +1 -1
  9. package/dist/types/components/accordion/use-accordion.d.ts +11 -11
  10. package/dist/types/components/action-bar/action-bar.d.ts +2 -2
  11. package/dist/types/components/airy/airy.d.ts +2 -2
  12. package/dist/types/components/alert/alert.d.ts +2 -2
  13. package/dist/types/components/alpha-slider/alpha-slider.d.ts +2 -2
  14. package/dist/types/components/aspect-ratio/aspect-ratio.d.ts +2 -2
  15. package/dist/types/components/autocomplete/autocomplete.d.ts +2 -2
  16. package/dist/types/components/autocomplete/autocomplete.style.d.ts +1 -1
  17. package/dist/types/components/autocomplete/use-autocomplete.d.ts +5 -5
  18. package/dist/types/components/avatar/avatar.d.ts +5 -5
  19. package/dist/types/components/avatar/use-avatar-group.d.ts +2 -2
  20. package/dist/types/components/badge/badge.d.ts +2 -2
  21. package/dist/types/components/bleed/bleed.d.ts +2 -2
  22. package/dist/types/components/blockquote/blockquote.d.ts +2 -2
  23. package/dist/types/components/breadcrumb/breadcrumb.d.ts +2 -2
  24. package/dist/types/components/breadcrumb/breadcrumb.style.d.ts +1 -1
  25. package/dist/types/components/breadcrumb/use-breadcrumb.d.ts +2 -2
  26. package/dist/types/components/button/button.d.ts +2 -2
  27. package/dist/types/components/button/icon-button.d.ts +2 -2
  28. package/dist/types/components/calendar/calendar.d.ts +2 -2
  29. package/dist/types/components/calendar/calendar.style.d.ts +2 -2
  30. package/dist/types/components/calendar/use-calendar.d.ts +8 -8
  31. package/dist/types/components/card/card.d.ts +2 -2
  32. package/dist/types/components/carousel/carousel.d.ts +2 -2
  33. package/dist/types/components/carousel/carousel.style.d.ts +2 -2
  34. package/dist/types/components/carousel/use-carousel.d.ts +3 -3
  35. package/dist/types/components/center/center.d.ts +2 -2
  36. package/dist/types/components/chart/area-chart.d.ts +2 -2
  37. package/dist/types/components/chart/bar-chart.d.ts +2 -2
  38. package/dist/types/components/chart/chart.d.ts +5 -5
  39. package/dist/types/components/chart/composed-chart.d.ts +2 -2
  40. package/dist/types/components/chart/line-chart.d.ts +2 -2
  41. package/dist/types/components/chart/pie-chart.d.ts +2 -2
  42. package/dist/types/components/chart/radar-chart.d.ts +2 -2
  43. package/dist/types/components/chart/use-chart.d.ts +2 -2
  44. package/dist/types/components/checkbox/checkbox.d.ts +4 -4
  45. package/dist/types/components/checkbox/use-checkbox-group.d.ts +2 -2
  46. package/dist/types/components/checkbox-card/checkbox-card.d.ts +4 -4
  47. package/dist/types/components/circle-progress/circle-progress.d.ts +2 -2
  48. package/dist/types/components/close-button/close-button.d.ts +2 -2
  49. package/dist/types/components/code/code.d.ts +2 -2
  50. package/dist/types/components/collapse/collapse.d.ts +2 -2
  51. package/dist/types/components/color-picker/color-picker.d.ts +2 -2
  52. package/dist/types/components/color-picker/color-picker.style.d.ts +1 -1
  53. package/dist/types/components/color-picker/use-color-picker.d.ts +2 -2
  54. package/dist/types/components/color-selector/color-selector.d.ts +2 -2
  55. package/dist/types/components/color-selector/use-color-selector.d.ts +3 -3
  56. package/dist/types/components/color-swatch/color-swatch.d.ts +2 -2
  57. package/dist/types/components/container/container.d.ts +2 -2
  58. package/dist/types/components/data-list/data-list.d.ts +2 -2
  59. package/dist/types/components/data-list/data-list.style.d.ts +1 -1
  60. package/dist/types/components/date-picker/date-picker.d.ts +2 -2
  61. package/dist/types/components/date-picker/use-date-picker.d.ts +4 -4
  62. package/dist/types/components/drawer/drawer.d.ts +2 -2
  63. package/dist/types/components/dropzone/dropzone.d.ts +4 -4
  64. package/dist/types/components/editable/editable.d.ts +4 -4
  65. package/dist/types/components/editable/use-editable.d.ts +2 -2
  66. package/dist/types/components/em/em.d.ts +2 -2
  67. package/dist/types/components/empty-state/empty-state.d.ts +2 -2
  68. package/dist/types/components/fade/fade.d.ts +2 -2
  69. package/dist/types/components/field/field.d.ts +3 -3
  70. package/dist/types/components/field/use-field-props.d.ts +3 -3
  71. package/dist/types/components/fieldset/fieldset.d.ts +3 -3
  72. package/dist/types/components/file-button/file-button.d.ts +2 -2
  73. package/dist/types/components/file-button/use-file-button.d.ts +18 -18
  74. package/dist/types/components/file-input/file-input.d.ts +2 -2
  75. package/dist/types/components/file-input/use-file-input.d.ts +15 -15
  76. package/dist/types/components/flex/flex.d.ts +2 -2
  77. package/dist/types/components/flip/flip.d.ts +4 -4
  78. package/dist/types/components/flip/flip.style.d.ts +1 -1
  79. package/dist/types/components/float/float.d.ts +2 -2
  80. package/dist/types/components/form/form.d.ts +3 -3
  81. package/dist/types/components/format/format-byte.d.ts +4 -4
  82. package/dist/types/components/format/format-date-time.d.ts +4 -4
  83. package/dist/types/components/format/format-number.d.ts +2 -2
  84. package/dist/types/components/grid/grid-item.d.ts +2 -2
  85. package/dist/types/components/grid/grid.d.ts +2 -2
  86. package/dist/types/components/group/group.d.ts +2 -2
  87. package/dist/types/components/group/use-group.d.ts +2 -2
  88. package/dist/types/components/heading/heading.d.ts +2 -2
  89. package/dist/types/components/hue-slider/hue-slider.d.ts +3 -3
  90. package/dist/types/components/icon/icon.d.ts +5 -5
  91. package/dist/types/components/image/image.d.ts +2 -2
  92. package/dist/types/components/indicator/indicator.d.ts +4 -4
  93. package/dist/types/components/infinite-scroll-area/infinite-scroll-area.d.ts +2 -2
  94. package/dist/types/components/input/input-addon.d.ts +2 -2
  95. package/dist/types/components/input/input-element.d.ts +2 -2
  96. package/dist/types/components/input/input.d.ts +2 -2
  97. package/dist/types/components/kbd/kbd.d.ts +2 -2
  98. package/dist/types/components/link/link.d.ts +2 -2
  99. package/dist/types/components/link-box/link-box.d.ts +2 -2
  100. package/dist/types/components/list/list.d.ts +2 -2
  101. package/dist/types/components/list/list.style.d.ts +2 -2
  102. package/dist/types/components/loading/loading-provider.d.ts +2 -2
  103. package/dist/types/components/loading/loading.d.ts +3 -3
  104. package/dist/types/components/mark/mark.d.ts +2 -2
  105. package/dist/types/components/menu/menu.d.ts +2 -2
  106. package/dist/types/components/menu/use-menu.d.ts +11 -11
  107. package/dist/types/components/modal/modal.d.ts +2 -2
  108. package/dist/types/components/native-accordion/native-accordion.d.ts +2 -2
  109. package/dist/types/components/native-accordion/native-accordion.style.d.ts +2 -2
  110. package/dist/types/components/native-accordion/use-native-accordion.d.ts +2 -2
  111. package/dist/types/components/native-popover/native-popover.d.ts +2 -2
  112. package/dist/types/components/native-select/native-select.d.ts +2 -2
  113. package/dist/types/components/native-table/native-table.d.ts +4 -4
  114. package/dist/types/components/notice/notice.style.d.ts +1 -1
  115. package/dist/types/components/number-input/number-input.d.ts +2 -2
  116. package/dist/types/components/number-input/number-input.style.d.ts +1 -1
  117. package/dist/types/components/pagination/pagination.d.ts +2 -2
  118. package/dist/types/components/pagination/pagination.style.d.ts +1 -1
  119. package/dist/types/components/pagination/use-pagination.d.ts +2 -2
  120. package/dist/types/components/password-input/password-input.d.ts +2 -2
  121. package/dist/types/components/password-input/strength-meter.d.ts +2 -2
  122. package/dist/types/components/password-input/use-password-input.d.ts +2 -2
  123. package/dist/types/components/pin-input/pin-input.d.ts +2 -2
  124. package/dist/types/components/pin-input/use-pin-input.d.ts +7 -7
  125. package/dist/types/components/popover/popover.d.ts +2 -2
  126. package/dist/types/components/progress/progress.d.ts +4 -4
  127. package/dist/types/components/progress/use-progress.d.ts +706 -706
  128. package/dist/types/components/qr-code/qr-code.d.ts +2 -2
  129. package/dist/types/components/radio/radio.d.ts +4 -4
  130. package/dist/types/components/radio/use-radio-group.d.ts +2 -2
  131. package/dist/types/components/radio-card/radio-card.d.ts +4 -4
  132. package/dist/types/components/rating/rating.style.d.ts +2 -2
  133. package/dist/types/components/rating/use-rating.d.ts +7 -7
  134. package/dist/types/components/reorder/reorder.d.ts +2 -2
  135. package/dist/types/components/reorder/reorder.style.d.ts +1 -1
  136. package/dist/types/components/reorder/use-reorder.d.ts +3 -3
  137. package/dist/types/components/resizable/resizable.d.ts +2 -2
  138. package/dist/types/components/resizable/resizable.style.d.ts +2 -2
  139. package/dist/types/components/resizable/use-resizable.d.ts +2 -2
  140. package/dist/types/components/ripple/ripple.d.ts +2 -2
  141. package/dist/types/components/ripple/use-ripple.d.ts +2 -2
  142. package/dist/types/components/rotate/rotate.d.ts +2 -2
  143. package/dist/types/components/saturation-slider/saturation-slider.d.ts +2 -2
  144. package/dist/types/components/saturation-slider/use-saturation-slider.d.ts +2 -2
  145. package/dist/types/components/scroll-area/scroll-area.d.ts +2 -2
  146. package/dist/types/components/segmented-control/segmented-control.d.ts +2 -2
  147. package/dist/types/components/segmented-control/segmented-control.style.d.ts +2 -2
  148. package/dist/types/components/segmented-control/use-segmented-control.d.ts +9 -9
  149. package/dist/types/components/select/select.d.ts +2 -2
  150. package/dist/types/components/select/select.style.d.ts +1 -1
  151. package/dist/types/components/select/use-select.d.ts +4 -4
  152. package/dist/types/components/separator/separator.d.ts +2 -2
  153. package/dist/types/components/sidebar/sidebar.d.ts +2 -2
  154. package/dist/types/components/sidebar/use-sidebar.d.ts +9 -9
  155. package/dist/types/components/simple-grid/simple-grid.d.ts +2 -2
  156. package/dist/types/components/skeleton/skeleton.d.ts +2 -2
  157. package/dist/types/components/slide/slide.d.ts +2 -2
  158. package/dist/types/components/slide-fade/slide-fade.d.ts +2 -2
  159. package/dist/types/components/slider/slider.d.ts +2 -2
  160. package/dist/types/components/slider/use-slider.d.ts +2 -2
  161. package/dist/types/components/stack/h-stack.d.ts +2 -2
  162. package/dist/types/components/stack/stack.d.ts +2 -2
  163. package/dist/types/components/stack/v-stack.d.ts +2 -2
  164. package/dist/types/components/stack/z-stack.d.ts +2 -2
  165. package/dist/types/components/stat/stat.d.ts +2 -2
  166. package/dist/types/components/status/status.d.ts +2 -2
  167. package/dist/types/components/steps/steps.d.ts +2 -2
  168. package/dist/types/components/steps/steps.style.d.ts +1 -1
  169. package/dist/types/components/steps/use-steps.d.ts +10 -10
  170. package/dist/types/components/switch/switch.d.ts +2 -2
  171. package/dist/types/components/table/table.d.ts +2 -2
  172. package/dist/types/components/tabs/tabs.d.ts +2 -2
  173. package/dist/types/components/tabs/use-tabs.d.ts +16 -16
  174. package/dist/types/components/tag/tag.d.ts +2 -2
  175. package/dist/types/components/tag/tag.style.d.ts +1 -1
  176. package/dist/types/components/text/text.d.ts +2 -2
  177. package/dist/types/components/textarea/textarea.d.ts +2 -2
  178. package/dist/types/components/textarea/use-autosize.d.ts +2 -2
  179. package/dist/types/components/timeline/timeline.d.ts +5 -5
  180. package/dist/types/components/timeline/timeline.style.d.ts +1 -1
  181. package/dist/types/components/toggle/toggle.d.ts +5 -5
  182. package/dist/types/components/toggle/use-toggle-group.d.ts +2 -2
  183. package/dist/types/components/toggle/use-toggle.d.ts +2 -2
  184. package/dist/types/components/tooltip/tooltip.d.ts +2 -2
  185. package/dist/types/components/tree/tree.d.ts +2 -2
  186. package/dist/types/components/tree/tree.style.d.ts +1 -1
  187. package/dist/types/components/tree/use-tree.d.ts +182 -182
  188. package/dist/types/components/visually-hidden/visually-hidden.d.ts +2 -2
  189. package/dist/types/components/wrap/wrap.d.ts +2 -2
  190. package/dist/types/core/components/create-component.d.ts +7 -7
  191. package/dist/types/core/system/color-mode-provider.d.ts +2 -2
  192. package/dist/types/core/system/storage-script.d.ts +3 -3
  193. package/dist/types/core/system/styled.d.ts +2 -2
  194. package/dist/types/core/system/system-provider.d.ts +2 -2
  195. package/dist/types/hooks/use-breakpoint/use-breakpoint-state.d.ts +2 -2
  196. package/dist/types/hooks/use-counter/index.d.ts +2 -2
  197. package/dist/types/hooks/use-descendants/index.d.ts +2 -2
  198. package/dist/types/hooks/use-field-sizing/index.d.ts +2 -2
  199. package/dist/types/hooks/use-hover/index.d.ts +2 -2
  200. package/dist/types/hooks/use-popper/index.d.ts +2 -2
  201. package/dist/types/hooks/use-resize-observer/index.d.ts +3 -3
  202. package/dist/types/providers/i18n-provider/i18n-provider.d.ts +3 -3
  203. package/dist/types/providers/ui-provider/ui-provider.d.ts +2 -2
  204. package/dist/types/utils/children.d.ts +2 -2
  205. package/package.json +2 -2
@@ -1 +1 @@
1
- {"version":3,"file":"use-carousel.cjs","names":["createContext","useI18n","useControllableState","useIds","useBoolean","snapCount","total","index","getRootProps: PropGetter<\"section\">","mergeProps","getListProps: PropGetter","mergeRefs","getItemProps: RequiredPropGetter<\"div\", { index: number }>","indexProp","getPrevTriggerProps: PropGetter<\"button\">","getNextTriggerProps: PropGetter<\"button\">","getIndicatorsProps: PropGetter"],"sources":["../../../../src/components/carousel/use-carousel.ts"],"sourcesContent":["\"use client\"\n\nimport type {\n EmblaCarouselType,\n EmblaOptionsType,\n EmblaPluginType,\n} from \"embla-carousel\"\nimport type { KeyboardEvent, RefObject } from \"react\"\nimport type {\n HTMLProps,\n Orientation,\n PropGetter,\n RequiredPropGetter,\n} from \"../../core\"\nimport useEmblaCarousel from \"embla-carousel-react\"\nimport { useCallback, useEffect, useRef, useState } from \"react\"\nimport { mergeProps } from \"../../core\"\nimport { useBoolean } from \"../../hooks/use-boolean\"\nimport { useControllableState } from \"../../hooks/use-controllable-state\"\nimport { useI18n } from \"../../providers/i18n-provider\"\nimport {\n assignRef,\n createContext,\n dataAttr,\n handlerAll,\n isFunction,\n mergeRefs,\n runKeyAction,\n useIds,\n useUpdateEffect,\n} from \"../../utils\"\n\ntype EmblaOptions = Required<EmblaOptionsType>\nexport type CarouselAlign = EmblaOptions[\"align\"]\nexport type CarouselContainScroll = EmblaOptions[\"containScroll\"]\nexport type CarouselInViewThreshold = EmblaOptions[\"inViewThreshold\"]\nexport type CarouselWatchDrag = EmblaOptions[\"watchDrag\"]\nexport type CarouselWatchResize = EmblaOptions[\"watchResize\"]\nexport type CarouselWatchSlides = EmblaOptions[\"watchSlides\"]\nexport type CarouselControl = EmblaCarouselType\nexport type CarouselPlugin = EmblaPluginType\n\nexport interface CarouselContext extends Omit<\n UseCarouselReturn,\n \"getRootProps\"\n> {}\n\nconst [CarouselContext, useCarouselContext] = createContext<CarouselContext>({\n name: \"CarouselContext\",\n})\n\nexport { CarouselContext, useCarouselContext }\n\nexport interface UseCarouselProps extends Omit<\n HTMLProps<\"section\">,\n \"onChange\"\n> {\n /**\n * The alignment of the carousel.\n *\n * @default 'center'\n */\n align?: CarouselAlign\n /**\n * If `true`, the carousel will be autoplay.\n *\n * @default false\n */\n autoplay?: boolean\n /**\n * Clear leading and trailing empty space that causes excessive scrolling.\n * Use trimSnaps to only use snap points that trigger scrolling or keepSnaps to keep them.\n *\n * @default false\n */\n containScroll?: CarouselContainScroll\n /**\n * Ref of the resizable item callback.\n */\n controlRef?: RefObject<CarouselControl | null>\n /**\n * The initial index of the carousel slide.\n *\n * @default 0\n */\n defaultIndex?: number\n /**\n * The number for the autoplay interval of the carousel.\n *\n * @default 4000\n */\n delay?: number\n /**\n * If `true`, momentum scrolling will be enabled.\n *\n * @default false\n */\n dragFree?: boolean\n /**\n * If `true`, carousel can be scrolled with mouse and touch interactions.\n *\n * @default true\n */\n draggable?: boolean\n /**\n * Set scroll duration when triggered by any of the API methods.\n * Higher numbers enables slower scrolling.\n * Drag interactions are not affected because duration is then determined by the drag force.\n *\n * @default 25\n */\n duration?: number\n /**\n * The index of the carousel slide.\n */\n index?: number\n /**\n * Choose a fraction representing the percentage portion of a slide that needs to be visible in order to be considered in view.\n *\n * @default 0\n */\n inViewThreshold?: CarouselInViewThreshold\n /**\n * If `true`, infinite looping.\n * Automatically falls back to false if slide content isn't enough to loop.\n *\n * @default true\n */\n loop?: boolean\n /**\n * The orientation of the carousel.\n *\n * @default 'horizontal'\n */\n orientation?: Orientation\n /**\n * Embla plugins to use.\n */\n plugins?: CarouselPlugin[]\n /**\n * If `true`, allow the carousel to skip scroll snaps if it's dragged vigorously.\n * Note that this option will be ignored if the dragFree option is set to true.\n *\n * @default false\n */\n skipSnaps?: boolean\n /**\n * The number of slides that should be scrolled with next or previous buttons.\n *\n * @default 1\n */\n slidesToScroll?: number\n /**\n * If `true`, autoplay will pause when the mouse entries over.\n *\n * @default true\n */\n stopMouseEnterAutoplay?: boolean\n /**\n * Enables for scrolling the carousel with mouse and touch interactions.\n * Set this to `false` to disable drag events or pass a custom callback to add your own drag logic.\n *\n * @default true\n */\n watchDrag?: CarouselWatchDrag\n /**\n * Embla automatically watches the container and slides for size changes and runs `reInit` when any size has changed.\n * Set this to `false` to disable this behaviour or pass a custom callback to add your own resize logic.\n *\n * @default true\n */\n watchResize?: CarouselWatchResize\n /**\n * Embla automatically watches the container for added and/or removed slides and runs `reInit` if needed.\n * Set this to `false` to disable this behaviour or pass a custom callback to add your own slides changed logic.\n *\n * @default true\n */\n watchSlides?: CarouselWatchSlides\n /**\n * The callback invoked when carousel slide selected.\n */\n onChange?: (index: number) => void\n /**\n * A callback that return the current scroll amount when the carousel is scrolled.\n */\n onScrollProgress?: (progress: number) => void\n}\n\nexport const useCarousel = ({\n id,\n align = \"center\",\n autoplay = false,\n containScroll = false,\n controlRef,\n defaultIndex = 0,\n delay = 4000,\n dragFree = false,\n draggable = true,\n duration = 25,\n index: indexProp,\n inViewThreshold = 0,\n loop = true,\n orientation = \"horizontal\",\n plugins = [],\n skipSnaps = false,\n slidesToScroll = 1,\n stopMouseEnterAutoplay = true,\n watchDrag = draggable,\n watchResize: watchResizeProp = true,\n watchSlides = true,\n onChange,\n onScrollProgress,\n ...rest\n}: UseCarouselProps = {}) => {\n const { t } = useI18n(\"carousel\")\n const [index, setIndex] = useControllableState({\n defaultValue: defaultIndex,\n value: indexProp,\n onChange,\n })\n const [rootId, listId] = useIds()\n const [hover, { off: onMouseLeave, on: onMouseEnter }] = useBoolean()\n const timeoutId = useRef<NodeJS.Timeout | null>(null)\n const indicatorMapRef = useRef<Map<number, HTMLButtonElement | null>>(\n new Map(),\n )\n const listRef = useRef<HTMLDivElement>(null)\n const horizontal = orientation === \"horizontal\"\n const axis = horizontal ? \"x\" : \"y\"\n const [snapCount, setSnapCount] = useState(0)\n const [total, setTotal] = useState(0)\n const watchResize = useCallback<Extract<CarouselWatchResize, Function>>(\n (methods, entries) => {\n const result = isFunction(watchResizeProp)\n ? watchResizeProp(methods, entries)\n : true\n const snapCount = methods.scrollSnapList().length\n const total = methods.slideNodes().length\n\n setSnapCount(snapCount)\n setTotal(total)\n\n return result\n },\n [watchResizeProp],\n )\n const [carouselRef, carousel] = useEmblaCarousel(\n {\n align,\n axis,\n container: listRef.current,\n containScroll,\n dragFree,\n duration,\n inViewThreshold,\n loop,\n skipSnaps,\n slidesToScroll,\n startIndex: defaultIndex,\n watchDrag,\n watchResize,\n watchSlides,\n },\n plugins,\n )\n\n id ??= rootId\n\n const onInit = useCallback((methods: CarouselControl) => {\n const snapCount = methods.scrollSnapList().length\n const total = methods.slideNodes().length\n\n setSnapCount(snapCount)\n setTotal(total)\n }, [])\n\n const onScroll = useCallback(() => {\n if (!carousel) return\n\n const progress = Math.round(\n Math.max(0, Math.min(1, carousel.scrollProgress())) * 100,\n )\n\n onScrollProgress?.(progress)\n }, [carousel, onScrollProgress])\n\n const onSelect = useCallback(() => {\n if (!carousel) return\n\n const index = carousel.selectedScrollSnap()\n\n setIndex(index)\n }, [carousel, setIndex])\n\n const onFocusIndicator = useCallback(\n (index: number) => {\n const el = indicatorMapRef.current.get(index)\n\n el?.focus()\n carousel?.scrollTo(index)\n },\n [carousel],\n )\n\n const onKeyDown = useCallback(\n (index: number) => (ev: KeyboardEvent<HTMLButtonElement>) => {\n const lastIndex = snapCount - 1\n\n runKeyAction(ev, {\n ArrowDown: () => {\n if (horizontal) return\n\n index = index === lastIndex ? 0 : index + 1\n\n onFocusIndicator(index)\n },\n ArrowLeft: () => {\n if (!horizontal) return\n\n index = index === 0 ? lastIndex : index - 1\n\n onFocusIndicator(index)\n },\n ArrowRight: () => {\n if (!horizontal) return\n\n index = index === lastIndex ? 0 : index + 1\n\n onFocusIndicator(index)\n },\n ArrowUp: () => {\n if (horizontal) return\n\n index = index === 0 ? lastIndex : index - 1\n\n onFocusIndicator(index)\n },\n End: () => {\n onFocusIndicator(lastIndex)\n },\n Home: () => {\n onFocusIndicator(0)\n },\n })\n },\n [snapCount, horizontal, onFocusIndicator],\n )\n\n assignRef(controlRef, carousel)\n\n useEffect(() => {\n if (carousel) {\n carousel.on(\"reInit\", onInit)\n carousel.on(\"select\", onSelect)\n carousel.on(\"scroll\", onScroll)\n\n onScroll()\n\n return () => {\n carousel.off(\"reInit\", onInit)\n carousel.off(\"select\", onSelect)\n carousel.off(\"scroll\", onScroll)\n }\n }\n }, [carousel, onInit, onScroll, onSelect])\n\n useEffect(() => {\n const stop = hover && stopMouseEnterAutoplay\n const last = !carousel?.canScrollNext()\n\n if (carousel && autoplay && !stop && !last) {\n timeoutId.current = setInterval(() => {\n carousel.scrollNext()\n }, delay)\n } else {\n if (timeoutId.current) clearInterval(timeoutId.current)\n\n timeoutId.current = null\n }\n\n return () => {\n if (timeoutId.current) clearInterval(timeoutId.current)\n }\n }, [autoplay, carousel, delay, hover, stopMouseEnterAutoplay])\n\n useUpdateEffect(() => {\n if (!carousel) return\n\n if (indexProp === undefined) return\n\n carousel.scrollTo(indexProp)\n }, [indexProp])\n\n useUpdateEffect(() => {\n if (!carousel) return\n\n carousel.reInit()\n }, [\n carousel,\n total,\n align,\n axis,\n containScroll,\n dragFree,\n duration,\n inViewThreshold,\n loop,\n skipSnaps,\n slidesToScroll,\n ])\n\n const getRootProps: PropGetter<\"section\"> = useCallback(\n ({ ref, ...props } = {}) =>\n mergeProps(\n {\n id,\n \"aria-roledescription\": \"carousel\",\n \"data-orientation\": orientation,\n },\n rest,\n {\n ref,\n onMouseEnter,\n onMouseLeave,\n },\n props,\n )(),\n [id, onMouseEnter, onMouseLeave, rest, orientation],\n )\n\n const getListProps: PropGetter = useCallback(\n ({ ref, ...props } = {}) => ({\n id: listId,\n \"aria-live\": autoplay ? \"off\" : \"polite\",\n \"data-orientation\": orientation,\n ...props,\n ref: mergeRefs(ref, listRef, carouselRef),\n }),\n [autoplay, listId, orientation, carouselRef],\n )\n\n const getItemProps: RequiredPropGetter<\"div\", { index: number }> =\n useCallback(\n ({ index: indexProp, ...props }) => {\n const page = indexProp + 1\n const selected = index === indexProp\n\n return {\n id: `${listId}-${indexProp}`,\n \"aria-label\": t(\"{page} of {total}\", { page, total }),\n \"aria-roledescription\": \"slide\",\n \"data-index\": indexProp.toString(),\n \"data-orientation\": orientation,\n \"data-selected\": dataAttr(selected),\n role: \"tabpanel\",\n ...props,\n }\n },\n [index, listId, total, orientation, t],\n )\n\n const getPrevTriggerProps: PropGetter<\"button\"> = useCallback(\n (props = {}) => ({\n \"aria-controls\": listId,\n \"aria-label\": t(\"Go to previous slide\"),\n \"data-orientation\": orientation,\n disabled: !carousel?.canScrollPrev(),\n ...props,\n onClick: handlerAll(props.onClick, () => carousel?.scrollPrev()),\n }),\n [carousel, listId, orientation, t],\n )\n\n const getNextTriggerProps: PropGetter<\"button\"> = useCallback(\n (props = {}) => ({\n \"aria-controls\": listId,\n \"aria-label\": t(\"Go to next slide\"),\n \"data-orientation\": orientation,\n disabled: !carousel?.canScrollNext(),\n ...props,\n onClick: handlerAll(props.onClick, () => carousel?.scrollNext()),\n }),\n [carousel, listId, orientation, t],\n )\n\n const getIndicatorsProps: PropGetter = useCallback(\n (props = {}) => ({\n \"aria-label\": t(\"Slides\"),\n \"aria-orientation\": orientation,\n role: \"tablist\",\n ...props,\n }),\n [orientation, t],\n )\n\n const getIndicatorProps: RequiredPropGetter<\"button\", { index: number }> =\n useCallback(\n ({ ref, index: indexProp, ...props }) => {\n const page = indexProp + 1\n const selected = index === indexProp\n\n return {\n type: \"button\" as const,\n \"aria-controls\": `${listId}-${indexProp}`,\n \"aria-label\": t(\"Go to {page} slide\", { page }),\n \"aria-selected\": selected,\n \"data-index\": indexProp.toString(),\n \"data-orientation\": orientation,\n \"data-selected\": dataAttr(selected),\n role: \"tab\",\n tabIndex: selected ? 0 : -1,\n ...props,\n ref: mergeRefs(ref, (node) => {\n indicatorMapRef.current.set(indexProp, node)\n }),\n onClick: handlerAll(props.onClick, () =>\n carousel?.scrollTo(indexProp),\n ),\n onKeyDown: handlerAll(props.onKeyDown, onKeyDown(indexProp)),\n }\n },\n [index, listId, t, orientation, onKeyDown, carousel],\n )\n\n return {\n carousel,\n index,\n setIndex,\n snapCount,\n total,\n getIndicatorProps,\n getIndicatorsProps,\n getItemProps,\n getListProps,\n getNextTriggerProps,\n getPrevTriggerProps,\n getRootProps,\n }\n}\n\nexport type UseCarouselReturn = ReturnType<typeof useCarousel>\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA+CA,MAAM,CAAC,iBAAiB,sBAAsBA,8BAA+B,EAC3E,MAAM,mBACP,CAAC;AA4IF,MAAa,eAAe,EAC1B,IACA,QAAQ,UACR,WAAW,OACX,gBAAgB,OAChB,YACA,eAAe,GACf,QAAQ,KACR,WAAW,OACX,YAAY,MACZ,WAAW,IACX,OAAO,WACP,kBAAkB,GAClB,OAAO,MACP,cAAc,cACd,UAAU,EAAE,EACZ,YAAY,OACZ,iBAAiB,GACjB,yBAAyB,MACzB,YAAY,WACZ,aAAa,kBAAkB,MAC/B,cAAc,MACd,UACA,kBACA,GAAG,SACiB,EAAE,KAAK;CAC3B,MAAM,EAAE,MAAMC,8BAAQ,WAAW;CACjC,MAAM,CAAC,OAAO,YAAYC,gEAAqB;EAC7C,cAAc;EACd,OAAO;EACP;EACD,CAAC;CACF,MAAM,CAAC,QAAQ,UAAUC,oBAAQ;CACjC,MAAM,CAAC,OAAO,EAAE,KAAK,cAAc,IAAI,kBAAkBC,4CAAY;CACrE,MAAM,8BAA0C,KAAK;CACrD,MAA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ACf,iBAAiB;EACjB,cAAc,EAAE,mBAAmB;EACnC,oBAAoB;EACpB,UAAU,CAAC,UAAU,eAAe;EACpC,GAAG;EACH,2DAAoB,MAAM,eAAe,UAAU,YAAY,CAAC;EACjE,GACD;EAAC;EAAU;EAAQ;EAAa;EAAE,CACnC;CAED,MAAMC,6CACH,QAAQ,EAAE,MAAM;EACf,cAAc,EAAE,SAAS;EACzB,oBAAoB;EACpB,MAAM;EACN,GAAG;EACJ,GACD,CAAC,aAAa,EAAE,CACjB;AA+BD,QAAO;EACL;EACA;EACA;EACA;EACA;EACA,2CAjCG,EAAE,KAAK,OAAOH,aAAW,GAAG,YAAY;GACvC,MAAM,OAAOA,cAAY;GACzB,MAAM,WAAW,UAAUA;AAE3B,UAAO;IACL,MAAM;IACN,iBAAiB,GAAG,OAAO,GAAGA;IAC9B,cAAc,EAAE,sBAAsB,EAAE,MAAM,CAAC;IAC/C,iBAAiB;IACjB,cAAcA,YAAU,UAAU;IAClC,oBAAoB;IACpB,iEAA0B,SAAS;IACnC,MAAM;IACN,UAAU,WAAW,IAAI;IACzB,GAAG;IACH,KAAKF,sBAAU,MAAM,SAAS;AAC5B,qBAAgB,QAAQ,IAAIE,aAAW,KAAK;MAC5C;IACF,2DAAoB,MAAM,eACxB,UAAU,SAASA,YAAU,CAC9B;IACD,6DAAsB,MAAM,WAAW,UAAUA,YAAU,CAAC;IAC7D;KAEH;GAAC;GAAO;GAAQ;GAAG;GAAa;GAAW;GAAS,CACrD;EASD;EACA;EACA;EACA;EACA;EACA;EACD"}
1
+ {"version":3,"file":"use-carousel.cjs","names":["createContext","useI18n","useControllableState","useIds","useBoolean","snapCount","total","index","getRootProps: PropGetter<\"section\">","mergeProps","getListProps: PropGetter","mergeRefs","getItemProps: RequiredPropGetter<\"div\", { index: number }>","indexProp","getPrevTriggerProps: PropGetter<\"button\">","getNextTriggerProps: PropGetter<\"button\">","getIndicatorsProps: PropGetter"],"sources":["../../../../src/components/carousel/use-carousel.ts"],"sourcesContent":["\"use client\"\n\nimport type {\n EmblaCarouselType,\n EmblaOptionsType,\n EmblaPluginType,\n} from \"embla-carousel\"\nimport type { KeyboardEvent, RefObject } from \"react\"\nimport useEmblaCarousel from \"embla-carousel-react\"\nimport { useCallback, useEffect, useRef, useState } from \"react\"\nimport {\n type HTMLProps,\n mergeProps,\n type Orientation,\n type PropGetter,\n type RequiredPropGetter,\n} from \"../../core\"\nimport { useBoolean } from \"../../hooks/use-boolean\"\nimport { useControllableState } from \"../../hooks/use-controllable-state\"\nimport { useI18n } from \"../../providers/i18n-provider\"\nimport {\n assignRef,\n createContext,\n dataAttr,\n handlerAll,\n isFunction,\n mergeRefs,\n runKeyAction,\n useIds,\n useUpdateEffect,\n} from \"../../utils\"\n\ntype EmblaOptions = Required<EmblaOptionsType>\nexport type CarouselAlign = EmblaOptions[\"align\"]\nexport type CarouselContainScroll = EmblaOptions[\"containScroll\"]\nexport type CarouselInViewThreshold = EmblaOptions[\"inViewThreshold\"]\nexport type CarouselWatchDrag = EmblaOptions[\"watchDrag\"]\nexport type CarouselWatchResize = EmblaOptions[\"watchResize\"]\nexport type CarouselWatchSlides = EmblaOptions[\"watchSlides\"]\nexport type CarouselControl = EmblaCarouselType\nexport type CarouselPlugin = EmblaPluginType\n\nexport interface CarouselContext extends Omit<\n UseCarouselReturn,\n \"getRootProps\"\n> {}\n\nconst [CarouselContext, useCarouselContext] = createContext<CarouselContext>({\n name: \"CarouselContext\",\n})\n\nexport { CarouselContext, useCarouselContext }\n\nexport interface UseCarouselProps extends Omit<\n HTMLProps<\"section\">,\n \"onChange\"\n> {\n /**\n * The alignment of the carousel.\n *\n * @default 'center'\n */\n align?: CarouselAlign\n /**\n * If `true`, the carousel will be autoplay.\n *\n * @default false\n */\n autoplay?: boolean\n /**\n * Clear leading and trailing empty space that causes excessive scrolling.\n * Use trimSnaps to only use snap points that trigger scrolling or keepSnaps to keep them.\n *\n * @default false\n */\n containScroll?: CarouselContainScroll\n /**\n * Ref of the resizable item callback.\n */\n controlRef?: RefObject<CarouselControl | null>\n /**\n * The initial index of the carousel slide.\n *\n * @default 0\n */\n defaultIndex?: number\n /**\n * The number for the autoplay interval of the carousel.\n *\n * @default 4000\n */\n delay?: number\n /**\n * If `true`, momentum scrolling will be enabled.\n *\n * @default false\n */\n dragFree?: boolean\n /**\n * If `true`, carousel can be scrolled with mouse and touch interactions.\n *\n * @default true\n */\n draggable?: boolean\n /**\n * Set scroll duration when triggered by any of the API methods.\n * Higher numbers enables slower scrolling.\n * Drag interactions are not affected because duration is then determined by the drag force.\n *\n * @default 25\n */\n duration?: number\n /**\n * The index of the carousel slide.\n */\n index?: number\n /**\n * Choose a fraction representing the percentage portion of a slide that needs to be visible in order to be considered in view.\n *\n * @default 0\n */\n inViewThreshold?: CarouselInViewThreshold\n /**\n * If `true`, infinite looping.\n * Automatically falls back to false if slide content isn't enough to loop.\n *\n * @default true\n */\n loop?: boolean\n /**\n * The orientation of the carousel.\n *\n * @default 'horizontal'\n */\n orientation?: Orientation\n /**\n * Embla plugins to use.\n */\n plugins?: CarouselPlugin[]\n /**\n * If `true`, allow the carousel to skip scroll snaps if it's dragged vigorously.\n * Note that this option will be ignored if the dragFree option is set to true.\n *\n * @default false\n */\n skipSnaps?: boolean\n /**\n * The number of slides that should be scrolled with next or previous buttons.\n *\n * @default 1\n */\n slidesToScroll?: number\n /**\n * If `true`, autoplay will pause when the mouse entries over.\n *\n * @default true\n */\n stopMouseEnterAutoplay?: boolean\n /**\n * Enables for scrolling the carousel with mouse and touch interactions.\n * Set this to `false` to disable drag events or pass a custom callback to add your own drag logic.\n *\n * @default true\n */\n watchDrag?: CarouselWatchDrag\n /**\n * Embla automatically watches the container and slides for size changes and runs `reInit` when any size has changed.\n * Set this to `false` to disable this behaviour or pass a custom callback to add your own resize logic.\n *\n * @default true\n */\n watchResize?: CarouselWatchResize\n /**\n * Embla automatically watches the container for added and/or removed slides and runs `reInit` if needed.\n * Set this to `false` to disable this behaviour or pass a custom callback to add your own slides changed logic.\n *\n * @default true\n */\n watchSlides?: CarouselWatchSlides\n /**\n * The callback invoked when carousel slide selected.\n */\n onChange?: (index: number) => void\n /**\n * A callback that return the current scroll amount when the carousel is scrolled.\n */\n onScrollProgress?: (progress: number) => void\n}\n\nexport const useCarousel = ({\n id,\n align = \"center\",\n autoplay = false,\n containScroll = false,\n controlRef,\n defaultIndex = 0,\n delay = 4000,\n dragFree = false,\n draggable = true,\n duration = 25,\n index: indexProp,\n inViewThreshold = 0,\n loop = true,\n orientation = \"horizontal\",\n plugins = [],\n skipSnaps = false,\n slidesToScroll = 1,\n stopMouseEnterAutoplay = true,\n watchDrag = draggable,\n watchResize: watchResizeProp = true,\n watchSlides = true,\n onChange,\n onScrollProgress,\n ...rest\n}: UseCarouselProps = {}) => {\n const { t } = useI18n(\"carousel\")\n const [index, setIndex] = useControllableState({\n defaultValue: defaultIndex,\n value: indexProp,\n onChange,\n })\n const [rootId, listId] = useIds()\n const [hover, { off: onMouseLeave, on: onMouseEnter }] = useBoolean()\n const timeoutId = useRef<NodeJS.Timeout | null>(null)\n const indicatorMapRef = useRef<Map<number, HTMLButtonElement | null>>(\n new Map(),\n )\n const listRef = useRef<HTMLDivElement>(null)\n const horizontal = orientation === \"horizontal\"\n const axis = horizontal ? \"x\" : \"y\"\n const [snapCount, setSnapCount] = useState(0)\n const [total, setTotal] = useState(0)\n const watchResize = useCallback<Extract<CarouselWatchResize, Function>>(\n (methods, entries) => {\n const result = isFunction(watchResizeProp)\n ? watchResizeProp(methods, entries)\n : true\n const snapCount = methods.scrollSnapList().length\n const total = methods.slideNodes().length\n\n setSnapCount(snapCount)\n setTotal(total)\n\n return result\n },\n [watchResizeProp],\n )\n const [carouselRef, carousel] = useEmblaCarousel(\n {\n align,\n axis,\n container: listRef.current,\n containScroll,\n dragFree,\n duration,\n inViewThreshold,\n loop,\n skipSnaps,\n slidesToScroll,\n startIndex: defaultIndex,\n watchDrag,\n watchResize,\n watchSlides,\n },\n plugins,\n )\n\n id ??= rootId\n\n const onInit = useCallback((methods: CarouselControl) => {\n const snapCount = methods.scrollSnapList().length\n const total = methods.slideNodes().length\n\n setSnapCount(snapCount)\n setTotal(total)\n }, [])\n\n const onScroll = useCallback(() => {\n if (!carousel) return\n\n const progress = Math.round(\n Math.max(0, Math.min(1, carousel.scrollProgress())) * 100,\n )\n\n onScrollProgress?.(progress)\n }, [carousel, onScrollProgress])\n\n const onSelect = useCallback(() => {\n if (!carousel) return\n\n const index = carousel.selectedScrollSnap()\n\n setIndex(index)\n }, [carousel, setIndex])\n\n const onFocusIndicator = useCallback(\n (index: number) => {\n const el = indicatorMapRef.current.get(index)\n\n el?.focus()\n carousel?.scrollTo(index)\n },\n [carousel],\n )\n\n const onKeyDown = useCallback(\n (index: number) => (ev: KeyboardEvent<HTMLButtonElement>) => {\n const lastIndex = snapCount - 1\n\n runKeyAction(ev, {\n ArrowDown: () => {\n if (horizontal) return\n\n index = index === lastIndex ? 0 : index + 1\n\n onFocusIndicator(index)\n },\n ArrowLeft: () => {\n if (!horizontal) return\n\n index = index === 0 ? lastIndex : index - 1\n\n onFocusIndicator(index)\n },\n ArrowRight: () => {\n if (!horizontal) return\n\n index = index === lastIndex ? 0 : index + 1\n\n onFocusIndicator(index)\n },\n ArrowUp: () => {\n if (horizontal) return\n\n index = index === 0 ? lastIndex : index - 1\n\n onFocusIndicator(index)\n },\n End: () => {\n onFocusIndicator(lastIndex)\n },\n Home: () => {\n onFocusIndicator(0)\n },\n })\n },\n [snapCount, horizontal, onFocusIndicator],\n )\n\n assignRef(controlRef, carousel)\n\n useEffect(() => {\n if (carousel) {\n carousel.on(\"reInit\", onInit)\n carousel.on(\"select\", onSelect)\n carousel.on(\"scroll\", onScroll)\n\n onScroll()\n\n return () => {\n carousel.off(\"reInit\", onInit)\n carousel.off(\"select\", onSelect)\n carousel.off(\"scroll\", onScroll)\n }\n }\n }, [carousel, onInit, onScroll, onSelect])\n\n useEffect(() => {\n const stop = hover && stopMouseEnterAutoplay\n const last = !carousel?.canScrollNext()\n\n if (carousel && autoplay && !stop && !last) {\n timeoutId.current = setInterval(() => {\n carousel.scrollNext()\n }, delay)\n } else {\n if (timeoutId.current) clearInterval(timeoutId.current)\n\n timeoutId.current = null\n }\n\n return () => {\n if (timeoutId.current) clearInterval(timeoutId.current)\n }\n }, [autoplay, carousel, delay, hover, stopMouseEnterAutoplay])\n\n useUpdateEffect(() => {\n if (!carousel) return\n\n if (indexProp === undefined) return\n\n carousel.scrollTo(indexProp)\n }, [indexProp])\n\n useUpdateEffect(() => {\n if (!carousel) return\n\n carousel.reInit()\n }, [\n carousel,\n total,\n align,\n axis,\n containScroll,\n dragFree,\n duration,\n inViewThreshold,\n loop,\n skipSnaps,\n slidesToScroll,\n ])\n\n const getRootProps: PropGetter<\"section\"> = useCallback(\n ({ ref, ...props } = {}) =>\n mergeProps(\n {\n id,\n \"aria-roledescription\": \"carousel\",\n \"data-orientation\": orientation,\n },\n rest,\n {\n ref,\n onMouseEnter,\n onMouseLeave,\n },\n props,\n )(),\n [id, onMouseEnter, onMouseLeave, rest, orientation],\n )\n\n const getListProps: PropGetter = useCallback(\n ({ ref, ...props } = {}) => ({\n id: listId,\n \"aria-live\": autoplay ? \"off\" : \"polite\",\n \"data-orientation\": orientation,\n ...props,\n ref: mergeRefs(ref, listRef, carouselRef),\n }),\n [autoplay, listId, orientation, carouselRef],\n )\n\n const getItemProps: RequiredPropGetter<\"div\", { index: number }> =\n useCallback(\n ({ index: indexProp, ...props }) => {\n const page = indexProp + 1\n const selected = index === indexProp\n\n return {\n id: `${listId}-${indexProp}`,\n \"aria-label\": t(\"{page} of {total}\", { page, total }),\n \"aria-roledescription\": \"slide\",\n \"data-index\": indexProp.toString(),\n \"data-orientation\": orientation,\n \"data-selected\": dataAttr(selected),\n role: \"tabpanel\",\n ...props,\n }\n },\n [index, listId, total, orientation, t],\n )\n\n const getPrevTriggerProps: PropGetter<\"button\"> = useCallback(\n (props = {}) => ({\n \"aria-controls\": listId,\n \"aria-label\": t(\"Go to previous slide\"),\n \"data-orientation\": orientation,\n disabled: !carousel?.canScrollPrev(),\n ...props,\n onClick: handlerAll(props.onClick, () => carousel?.scrollPrev()),\n }),\n [carousel, listId, orientation, t],\n )\n\n const getNextTriggerProps: PropGetter<\"button\"> = useCallback(\n (props = {}) => ({\n \"aria-controls\": listId,\n \"aria-label\": t(\"Go to next slide\"),\n \"data-orientation\": orientation,\n disabled: !carousel?.canScrollNext(),\n ...props,\n onClick: handlerAll(props.onClick, () => carousel?.scrollNext()),\n }),\n [carousel, listId, orientation, t],\n )\n\n const getIndicatorsProps: PropGetter = useCallback(\n (props = {}) => ({\n \"aria-label\": t(\"Slides\"),\n \"aria-orientation\": orientation,\n role: \"tablist\",\n ...props,\n }),\n [orientation, t],\n )\n\n const getIndicatorProps: RequiredPropGetter<\"button\", { index: number }> =\n useCallback(\n ({ ref, index: indexProp, ...props }) => {\n const page = indexProp + 1\n const selected = index === indexProp\n\n return {\n type: \"button\" as const,\n \"aria-controls\": `${listId}-${indexProp}`,\n \"aria-label\": t(\"Go to {page} slide\", { page }),\n \"aria-selected\": selected,\n \"data-index\": indexProp.toString(),\n \"data-orientation\": orientation,\n \"data-selected\": dataAttr(selected),\n role: \"tab\",\n tabIndex: selected ? 0 : -1,\n ...props,\n ref: mergeRefs(ref, (node) => {\n indicatorMapRef.current.set(indexProp, node)\n }),\n onClick: handlerAll(props.onClick, () =>\n carousel?.scrollTo(indexProp),\n ),\n onKeyDown: handlerAll(props.onKeyDown, onKeyDown(indexProp)),\n }\n },\n [index, listId, t, orientation, onKeyDown, carousel],\n )\n\n return {\n carousel,\n index,\n setIndex,\n snapCount,\n total,\n getIndicatorProps,\n getIndicatorsProps,\n getItemProps,\n getListProps,\n getNextTriggerProps,\n getPrevTriggerProps,\n getRootProps,\n }\n}\n\nexport type UseCarouselReturn = ReturnType<typeof useCarousel>\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA+CA,MAAM,CAAC,iBAAiB,sBAAsBA,8BAA+B,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AAS;IACnC,MAAM;IACN,UAAU,WAAW,IAAI;IACzB,GAAG;IACH,KAAKF,sBAAU,MAAM,SAAS;AAC5B,qBAAgB,QAAQ,IAAIE,aAAW,KAAK;MAC5C;IACF,2DAAoB,MAAM,eACxB,UAAU,SAASA,YAAU,CAC9B;IACD,6DAAsB,MAAM,WAAW,UAAUA,YAAU,CAAC;IAC7D;KAEH;GAAC;GAAO;GAAQ;GAAG;GAAa;GAAW;GAAS,CACrD;EASD;EACA;EACA;EACA;EACA;EACA;EACD"}
@@ -6,6 +6,8 @@ const require_dom = require('../../utils/dom.cjs');
6
6
  const require_effect = require('../../utils/effect.cjs');
7
7
  const require_ref = require('../../utils/ref.cjs');
8
8
  const require_utils_index = require('../../utils/index.cjs');
9
+ const require_props = require('../../core/components/props.cjs');
10
+ require('../../core/index.cjs');
9
11
  const require_hooks_use_controllable_state_index = require('../../hooks/use-controllable-state/index.cjs');
10
12
  const require_hooks_use_descendants_index = require('../../hooks/use-descendants/index.cjs');
11
13
  const require_use_disclosure = require('../../hooks/use-disclosure/use-disclosure.cjs');
@@ -101,13 +103,11 @@ const useTree = ({ checkable = false, checkedValue: checkedValueProp, children,
101
103
  expandedValue,
102
104
  multiple,
103
105
  selectedValue,
104
- getRootProps: (0, react.useCallback)((props) => ({
106
+ getRootProps: (0, react.useCallback)((props) => require_props.mergeProps({
105
107
  "aria-multiselectable": (0, require_utils_index.utils_exports.ariaAttr)(multiple || checkable),
106
108
  children,
107
- role: "tree",
108
- ...rest,
109
- ...props
110
- }), [
109
+ role: "tree"
110
+ }, rest, props)(), [
111
111
  multiple,
112
112
  checkable,
113
113
  rest,
@@ -1 +1 @@
1
- {"version":3,"file":"use-tree.cjs","names":["createDescendants","createContext","useControllableState","descendant","value","useIds","Children","level: number","value: string","useDisclosure","branchOpen: boolean[]","useAsyncCallback","selectedValue","parentTarget: string[]","children","indeterminate","getItemProps: PropGetter<\"li\">","mergeRefs","getGroupItemProps: PropGetter<\"li\">","getIndicatorProps: PropGetter<\"svg\">"],"sources":["../../../../src/components/tree/use-tree.ts"],"sourcesContent":["\"use client\"\n\nimport type {\n ChangeEvent,\n KeyboardEvent,\n MouseEvent,\n ReactNode,\n RefObject,\n SetStateAction,\n} from \"react\"\nimport type { HTMLProps, PropGetter } from \"../../core\"\nimport type { Descendant, Descendants } from \"../../hooks/use-descendants\"\nimport type { UseDisclosureProps } from \"../../hooks/use-disclosure\"\nimport type { UseCheckboxProps } from \"../checkbox\"\nimport { Children, useCallback, useRef, useState } from \"react\"\nimport { useAsyncCallback } from \"../../hooks/use-async-callback\"\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 cx,\n dataAttr,\n filterEmpty,\n handlerAll,\n isArray,\n isInputElement,\n isUndefined,\n match,\n mergeRefs,\n runKeyAction,\n setAttribute,\n useIds,\n useSafeLayoutEffect,\n} from \"../../utils\"\n\nexport interface TreeControl {\n collapse: () => void\n expand: () => void\n}\n\ninterface TreeDescendantProps {\n expanded: boolean\n group: boolean\n id: string\n value: string\n query?: string\n}\n\nconst {\n DescendantsContext: TreeDescendantsContext,\n useDescendant: useTreeDescendant,\n useDescendants: useTreeDescendants,\n} = createDescendants<HTMLElement, TreeDescendantProps>()\n\nexport { TreeDescendantsContext, useTreeDescendant, useTreeDescendants }\n\ninterface TreeContext extends Omit<\n UseTreeReturn,\n \"descendants\" | \"getRootProps\"\n> {}\n\nconst [TreeContext, useTreeContext] = createContext<TreeContext>({\n name: \"TreeContext\",\n})\n\nexport { TreeContext, useTreeContext }\n\ninterface TreeItemContext extends Pick<\n UseTreeItemReturn,\n | \"branchOpen\"\n | \"groupOpen\"\n | \"level\"\n | \"onGroupClose\"\n | \"onGroupOpen\"\n | \"onGroupToggle\"\n | \"value\"\n> {}\n\nconst [TreeItemContext, useTreeItemContext] = createContext<TreeItemContext>({\n name: \"TreeItemContext\",\n strict: false,\n})\n\nexport { TreeItemContext, useTreeItemContext }\n\nexport interface UseTreeProps<\n Multiple extends boolean = false,\n> extends HTMLProps<\"ul\"> {\n /**\n * If `true`, the tree will allow checkable items.\n *\n * @default false\n */\n checkable?: boolean\n /**\n * The checked value of the tree.\n */\n checkedValue?: string[]\n /**\n * Ref of the tree callbacks.\n */\n controlRef?: RefObject<null | TreeControl>\n /**\n * The initial checked value of the tree.\n */\n defaultCheckedValue?: string[]\n /**\n * The initial expanded value of the tree.\n */\n defaultExpandedValue?: string[]\n /**\n * The initial selected value of the tree.\n */\n defaultSelectedValue?: Multiple extends true ? string[] : string\n /**\n * The expanded value of the tree.\n */\n expandedValue?: string[]\n /**\n * If `true`, the tree will allow multiple selection.\n *\n * @default false\n */\n multiple?: Multiple\n /**\n * The selected value of the tree.\n */\n selectedValue?: Multiple extends true ? string[] : string\n /**\n * The callback invoked when checked value changes.\n */\n onCheckedChange?: (value: string[]) => void\n /**\n * The callback invoked when expanded value changes.\n */\n onExpandedChange?: (value: string[]) => void\n /**\n * The callback invoked when selected value changes.\n */\n onSelectedChange?: (value: Multiple extends true ? string[] : string) => void\n}\n\nexport const useTree = <Multiple extends boolean = false>({\n checkable = false,\n checkedValue: checkedValueProp,\n children,\n controlRef,\n defaultCheckedValue = [],\n defaultExpandedValue = [],\n defaultSelectedValue,\n expandedValue: expandedValueProp,\n multiple,\n selectedValue: selectedValueProp,\n onCheckedChange: onCheckedChangeProp,\n onExpandedChange: onExpandedChangeProp,\n onSelectedChange: onSelectedChangeProp,\n ...rest\n}: UseTreeProps<Multiple> = {}) => {\n type MaybeSelectedValue = Multiple extends true ? string[] : string\n\n const [selectedValue, setSelectedValue] = useControllableState({\n defaultValue:\n defaultSelectedValue ?? ((multiple ? [] : \"\") as MaybeSelectedValue),\n value: selectedValueProp,\n onChange: onSelectedChangeProp,\n })\n const [checkedValue, onCheckedChange] = useControllableState({\n defaultValue: defaultCheckedValue,\n value: checkedValueProp,\n onChange: onCheckedChangeProp,\n })\n const [expandedValue, setExpandedValue] = useControllableState({\n defaultValue: defaultExpandedValue,\n value: expandedValueProp,\n onChange: onExpandedChangeProp,\n })\n const descendants = useTreeDescendants()\n const activeDescendant = useRef<Descendant<\n HTMLElement,\n TreeDescendantProps\n > | null>(null)\n const searchRef = useRef<{ value: string; omitValue?: string }>({\n omitValue: undefined,\n value: \"\",\n })\n const timeoutRef = useRef<any>(null)\n\n const onExpandAll = useCallback(() => {\n const values = descendants.enabledValues()\n const group = values.filter(({ group }) => group)\n const value = group.map(({ value }) => value)\n\n setExpandedValue(value)\n }, [descendants, setExpandedValue])\n\n const onCollapseAll = useCallback(() => {\n setExpandedValue([])\n }, [setExpandedValue])\n\n const onActiveDescendant = useCallback(\n (\n descendant?: Descendant<HTMLElement, TreeDescendantProps>,\n shouldFocus = true,\n ) => {\n if (!descendant) return\n\n descendants.values().forEach(({ node }) => {\n node.tabIndex = -1\n })\n\n activeDescendant.current = descendant\n descendant.node.tabIndex = 0\n\n if (shouldFocus) descendant.node.focus()\n },\n [descendants],\n )\n\n const onSearch = useCallback(\n (value: string, omitValue: string) => {\n clearTimeout(timeoutRef.current)\n\n searchRef.current.value += value\n\n if (!searchRef.current.omitValue) searchRef.current.omitValue = omitValue\n\n timeoutRef.current = setTimeout(() => {\n searchRef.current = { omitValue: undefined, value: \"\" }\n }, 400)\n\n const values = descendants\n .enabledValues({ expanded: true })\n .filter(\n (descendant) =>\n !isUndefined(descendant.value) &&\n descendant.value !== searchRef.current.omitValue,\n )\n const descendant = values.find(({ query, value }) =>\n match(query ?? value, searchRef.current.value, \"startsWith\"),\n )\n\n if (descendant) onActiveDescendant(descendant)\n },\n [descendants, onActiveDescendant],\n )\n\n const onSelectedChange = useCallback(\n (value: SetStateAction<string | string[]>) => {\n setSelectedValue(value as SetStateAction<MaybeSelectedValue>)\n },\n [setSelectedValue],\n )\n\n const onExpandedChange = useCallback(\n (value: string) => {\n setExpandedValue((prev) => {\n if (prev.includes(value)) {\n return prev.filter((prevValue) => prevValue !== value)\n } else {\n return [...prev, value]\n }\n })\n },\n [setExpandedValue],\n )\n\n useSafeLayoutEffect(() => {\n const value = isArray(selectedValue) ? selectedValue.at(0) : selectedValue\n const expandedDescendants = descendants.enabledValues({ expanded: true })\n\n if (value) {\n const descendant = expandedDescendants.find(\n (descendant) => value === descendant.value,\n )\n\n if (descendant) {\n onActiveDescendant(descendant, false)\n } else {\n onActiveDescendant(expandedDescendants.at(0), false)\n }\n } else {\n onActiveDescendant(expandedDescendants.at(0), false)\n }\n }, [children])\n\n assignRef(controlRef, { collapse: onCollapseAll, expand: onExpandAll })\n\n const getRootProps: PropGetter<\"ul\"> = useCallback(\n (props) => ({\n \"aria-multiselectable\": ariaAttr(multiple || checkable),\n children,\n role: \"tree\",\n ...rest,\n ...props,\n }),\n [multiple, checkable, rest, children],\n )\n\n return {\n activeDescendant,\n checkable,\n checkedValue,\n descendants,\n expandedValue,\n multiple,\n selectedValue,\n getRootProps,\n onActiveDescendant,\n onCheckedChange,\n onCollapseAll,\n onExpandAll,\n onExpandedChange,\n onSearch,\n onSelectedChange,\n }\n}\n\nexport type UseTreeReturn = ReturnType<typeof useTree>\n\nconst getRootDescendant =\n (descendants: Descendants<HTMLElement, TreeDescendantProps>) =>\n (value: string) => {\n const segments = value.split(\"/\")\n\n if (segments.length <= 1) return\n\n const rootValue = segments.at(0)\n\n return descendants.enabledValues().find(({ value }) => value === rootValue)\n }\n\nconst getParentDescendant =\n (descendants: Descendants<HTMLElement, TreeDescendantProps>) =>\n (value: string) => {\n const segments = value.split(\"/\")\n\n if (segments.length <= 1) return\n\n const parentValue = segments.slice(0, -1).join(\"/\")\n\n return descendants\n .enabledValues()\n .find(({ value }) => value === parentValue)\n }\n\nconst getChildDescendants =\n (descendants: Descendants<HTMLElement, TreeDescendantProps>) =>\n (value: string) => {\n const children = descendants\n .enabledValues()\n .filter((descendant) => descendant.value.startsWith(value + \"/\"))\n const values = children\n .map(({ value }) => value)\n .filter((value) => !isUndefined(value))\n\n return { children, values }\n }\n\nconst getParentValues = (value: string) => {\n const segments = value.split(\"/\")\n\n return segments\n .reduce<string[]>((prev, current) => {\n const prevValue = prev.at(-1)\n return prevValue ? [...prev, [prevValue, current].join(\"/\")] : [current]\n }, [])\n .toReversed()\n}\n\nconst getCheckbox = (node?: HTMLElement) => {\n const el = node?.querySelector(\"input[type='checkbox']\")\n\n return isInputElement(el) ? el : null\n}\n\nconst getAllChecked = (\n descendants: Descendant<HTMLElement, TreeDescendantProps>[],\n trulyValues?: string[],\n falsyValues?: string[],\n) => {\n const checked = descendants.map(({ node, value }) => {\n if (value && trulyValues?.includes(value)) return true\n if (value && falsyValues?.includes(value)) return false\n\n const checkbox = getCheckbox(node)\n\n return !!checkbox?.checked\n })\n\n const allChecked = !!checked.length && checked.every(Boolean)\n const indeterminate = checked.some(Boolean) && !allChecked\n\n return { allChecked, checked, indeterminate }\n}\n\nconst getRangeValues =\n (descendants: Descendants<HTMLElement, TreeDescendantProps>) =>\n (start: string, end: string) => {\n const values = descendants.enabledValues()\n const [startIndex, endIndex] = [\n values.findIndex((descendant) => descendant.value === start),\n values.findIndex((descendant) => descendant.value === end),\n ].sort((a, b) => a - b)\n\n return values\n .slice(startIndex, endIndex! + 1)\n .map(({ value }) => value)\n .filter((value) => !isUndefined(value))\n .sort((a, b) => {\n if (a === start && b !== start) return -1\n if (a !== start && b === start) return 1\n\n return 0\n })\n }\n\nexport interface UseTreeItemProps\n extends HTMLProps<\"div\">, Omit<UseDisclosureProps, \"timing\"> {\n /**\n * If `true`, the tree item will be disabled.\n *\n * @default false\n */\n disabled?: boolean\n /**\n * The query to search for in the tree item.\n */\n query?: string\n /**\n * The value of the item.\n */\n value?: string\n /**\n * If provided, the tree item will be rendered as an async tree item.\n */\n asyncChildren?: () => Promise<ReactNode>\n}\n\nexport const useTreeItem = ({\n asyncChildren,\n children: childrenProp,\n defaultOpen,\n disabled = false,\n open: openProp,\n query,\n value: valueProp,\n onClose: onCloseProp,\n onOpen: onOpenProp,\n ...rest\n}: UseTreeItemProps = {}) => {\n const context = useTreeItemContext()\n const {\n activeDescendant,\n checkable,\n checkedValue,\n expandedValue,\n multiple,\n selectedValue,\n onActiveDescendant,\n onCheckedChange,\n onCollapseAll,\n onExpandAll,\n onExpandedChange,\n onSearch,\n onSelectedChange,\n } = useTreeContext()\n const [children, setChildren] = useState<ReactNode>(childrenProp)\n const [indeterminate, setIndeterminate] = useState(false)\n const [itemId, labelId, checkboxId] = useIds()\n const initialAsyncRef = useRef(false)\n const async = !!asyncChildren\n const group = async || Children.count(children) > 0\n const level: number = (context?.level ?? 0) + 1\n const value: string = filterEmpty([context?.value, valueProp]).join(\"/\")\n const nested = !!context?.value\n const selected = isArray(selectedValue)\n ? !!value && selectedValue.includes(value)\n : !!value && selectedValue === value\n const checked = !!value && checkedValue.includes(value)\n const defaultExpanded = !!value && expandedValue.includes(value)\n const {\n open: groupOpen,\n onClose,\n onOpen,\n } = useDisclosure({\n defaultOpen: defaultOpen ?? defaultExpanded,\n open: openProp,\n onClose: onCloseProp,\n onOpen: onOpenProp,\n })\n const branchOpen: boolean[] = nested\n ? [...context.branchOpen, groupOpen]\n : [groupOpen]\n const { descendants, register } = useTreeDescendant({\n id: itemId!,\n disabled,\n expanded: branchOpen.slice(0, -1).every(Boolean),\n group,\n query,\n value,\n })\n\n const [groupLoading, onGroupChildren] = useAsyncCallback(async () => {\n const children = await asyncChildren?.()\n\n setChildren(children)\n }, [asyncChildren])\n\n const onSelect = useCallback(\n (\n ev: (\n | Partial<KeyboardEvent<HTMLElement>>\n | Partial<MouseEvent<HTMLElement>>\n ) & { value?: string } = {},\n ) => {\n const selectedValue = ev.value ?? value\n\n if (disabled || !selectedValue) return\n\n if (multiple) {\n onSelectedChange((prev) => {\n if (!isArray(prev)) return prev\n\n if (ev.ctrlKey || ev.metaKey) {\n if (prev.includes(selectedValue)) {\n return prev.filter((prevValue) => prevValue !== selectedValue)\n } else {\n return [...prev, selectedValue]\n }\n } else if (ev.shiftKey && prev[0]) {\n if (prev[0] === selectedValue) return prev\n\n return getRangeValues(descendants)(prev[0], selectedValue)\n } else {\n return [selectedValue]\n }\n })\n } else {\n onSelectedChange(selectedValue)\n }\n },\n [descendants, disabled, multiple, onSelectedChange, value],\n )\n\n const onGroupOpen = useCallback(() => {\n if (disabled || !value) return\n\n if (async && !initialAsyncRef.current) {\n initialAsyncRef.current = true\n\n onGroupChildren()\n .then(() => {\n onOpen()\n onExpandedChange(value)\n })\n .catch(() => {\n initialAsyncRef.current = false\n })\n } else {\n onOpen()\n onExpandedChange(value)\n }\n }, [disabled, async, onGroupChildren, onOpen, onExpandedChange, value])\n\n const onGroupClose = useCallback(() => {\n if (disabled || !value) return\n\n onClose()\n onExpandedChange(value)\n }, [disabled, onClose, onExpandedChange, value])\n\n const onGroupToggle = useCallback(() => {\n if (groupOpen) {\n onGroupClose()\n } else {\n onGroupOpen()\n }\n }, [groupOpen, onGroupClose, onGroupOpen])\n\n const onKeyDown = useCallback(\n (ev: KeyboardEvent<HTMLElement>) => {\n if (disabled || !value) return\n\n runKeyAction(ev, {\n a: () => {\n if (!multiple || !(ev.ctrlKey || ev.metaKey)) return\n\n const values = descendants\n .enabledValues()\n .map(({ value }) => value)\n .filter((value) => !isUndefined(value))\n\n onSelectedChange(values)\n },\n ArrowDown: () => {\n if ((ev.ctrlKey || ev.metaKey) && ev.shiftKey) {\n onExpandAll()\n } else {\n const descendant = descendants.enabledNextValue(\n activeDescendant.current,\n false,\n { expanded: true },\n )\n\n onActiveDescendant(descendant)\n\n if (descendant && ev.shiftKey && multiple)\n onSelect({ ctrlKey: true, value: descendant.value })\n }\n },\n ArrowLeft: () => {\n if (group && groupOpen) {\n onGroupClose()\n } else if (nested) {\n const descendant = getParentDescendant(descendants)(value)\n\n onActiveDescendant(descendant)\n }\n },\n ArrowRight: () => {\n if (!group) return\n\n if (groupOpen) {\n const descendant = descendants.enabledNextValue(\n activeDescendant.current,\n false,\n { expanded: true },\n )\n\n onActiveDescendant(descendant)\n } else {\n if (!groupLoading) onGroupOpen()\n }\n },\n ArrowUp: () => {\n if ((ev.ctrlKey || ev.metaKey) && ev.shiftKey) {\n onCollapseAll()\n\n if (!nested) return\n\n const descendant = getRootDescendant(descendants)(value)\n\n onActiveDescendant(descendant)\n } else {\n const descendant = descendants.enabledPrevValue(\n activeDescendant.current,\n false,\n { expanded: true },\n )\n\n onActiveDescendant(descendant)\n\n if (descendant && ev.shiftKey && multiple)\n onSelect({ ctrlKey: true, value: descendant.value })\n }\n },\n End: () => {\n const descendant = descendants\n .enabledValues({ expanded: true })\n .at(-1)\n\n onActiveDescendant(descendant)\n },\n Enter: () => {\n if (group) onGroupToggle()\n\n onSelect(ev)\n },\n Home: () => {\n const descendant = descendants.enabledValues({ expanded: true }).at(0)\n\n onActiveDescendant(descendant)\n },\n Space: () => {\n if (group) onGroupToggle()\n\n onSelect(ev)\n },\n })\n\n if (ev.key.length !== 1) return\n if (ev.ctrlKey || ev.metaKey || ev.altKey) return\n\n ev.preventDefault()\n\n onSearch(ev.key, query ?? value)\n },\n [\n activeDescendant,\n descendants,\n disabled,\n group,\n groupLoading,\n groupOpen,\n multiple,\n nested,\n onActiveDescendant,\n onCollapseAll,\n onExpandAll,\n onGroupClose,\n onGroupOpen,\n onGroupToggle,\n onSearch,\n onSelect,\n onSelectedChange,\n query,\n value,\n ],\n )\n\n const onItemClick = useCallback(\n (ev: MouseEvent<HTMLLIElement>) => {\n ev.stopPropagation()\n\n if (disabled || !value) return\n\n if (group && !groupLoading)\n if (!ev.ctrlKey && !ev.metaKey && !ev.shiftKey) onGroupToggle()\n\n onSelect(ev)\n },\n [disabled, group, groupLoading, onGroupToggle, onSelect, value],\n )\n\n const onCheckboxChange = useCallback(\n (ev: ChangeEvent<HTMLInputElement>) => {\n if (disabled || !value) return\n\n ev.stopPropagation()\n\n if (group) setIndeterminate(false)\n\n onCheckedChange((prev) => {\n const target = [value]\n\n if (group) {\n const { values } = getChildDescendants(descendants)(value)\n\n target.push(...values)\n }\n\n if (nested) {\n const parentValues = getParentValues(context.value)\n const parentTarget: string[] = []\n\n parentValues.forEach((parentValue) => {\n const { children } = getChildDescendants(descendants)(parentValue)\n const { allChecked } = getAllChecked(\n children,\n [...parentTarget, ...(ev.target.checked ? target : [])],\n !ev.target.checked ? target : [],\n )\n\n if (allChecked) parentTarget.push(parentValue)\n })\n\n if (!ev.target.checked) parentTarget.push(...parentValues)\n\n target.push(...parentTarget)\n }\n\n if (ev.target.checked) {\n return [...new Set([...prev, ...target])]\n } else {\n return prev.filter((prevValue) => !target.includes(prevValue))\n }\n })\n },\n [disabled, group, onCheckedChange, value, nested, descendants, context],\n )\n\n useSafeLayoutEffect(() => {\n if (defaultExpanded) {\n if (async && !initialAsyncRef.current) {\n initialAsyncRef.current = true\n\n onGroupChildren()\n .then(() => {\n onOpen()\n })\n .catch(() => {\n initialAsyncRef.current = false\n })\n } else {\n onOpen()\n }\n } else {\n onClose()\n }\n }, [async, defaultExpanded, onClose, onGroupChildren, onOpen])\n\n useSafeLayoutEffect(() => {\n if (!group || !checkable) return\n\n const { children } = getChildDescendants(descendants)(value)\n const { indeterminate } = getAllChecked(children)\n\n setIndeterminate(indeterminate)\n }, [checkedValue])\n\n useSafeLayoutEffect(() => {\n if (!checkable) return\n\n const { node } = getParentDescendant(descendants)(value) ?? {}\n const checkbox = getCheckbox(node)\n\n if (!checkbox) return\n\n const cleanup = setAttribute(checkbox, \"aria-controls\", checkboxId)\n\n return cleanup\n }, [checkable, descendants])\n\n const getItemProps: PropGetter<\"li\"> = useCallback(\n ({ ref, \"aria-labelledby\": ariaLabelledby, ...props } = {}) => ({\n id: itemId,\n ref: mergeRefs(ref, register),\n \"aria-disabled\": ariaAttr(disabled),\n \"aria-labelledby\": cx(ariaLabelledby, labelId),\n \"aria-level\": level,\n \"aria-selected\": ariaAttr(selected),\n \"data-disabled\": dataAttr(disabled),\n role: \"treeitem\",\n tabIndex: -1,\n ...props,\n onClick: handlerAll(props.onClick, onItemClick),\n onKeyDown: handlerAll(props.onKeyDown, onKeyDown),\n }),\n [\n itemId,\n register,\n disabled,\n labelId,\n level,\n selected,\n onItemClick,\n onKeyDown,\n ],\n )\n\n const getGroupItemProps: PropGetter<\"li\"> = useCallback(\n (props = {}) => getItemProps({ \"aria-expanded\": groupOpen, ...props }),\n [getItemProps, groupOpen],\n )\n\n const getIndicatorProps: PropGetter<\"svg\"> = useCallback(\n (props) => ({\n \"aria-disabled\": ariaAttr(disabled),\n \"aria-expanded\": groupOpen,\n \"aria-hidden\": true,\n \"data-disabled\": dataAttr(disabled),\n \"data-loading\": dataAttr(groupLoading),\n \"data-selected\": dataAttr(selected),\n role: \"presentation\",\n ...props,\n }),\n [disabled, groupOpen, selected, groupLoading],\n )\n\n const getCheckboxProps: PropGetter<UseCheckboxProps> = useCallback(\n ({ \"aria-labelledby\": ariaLabelledby, ...props } = {}) => ({\n id: checkboxId,\n \"aria-labelledby\": cx(ariaLabelledby, labelId),\n \"data-selected\": dataAttr(selected),\n checked,\n disabled,\n indeterminate,\n tabIndex: -1,\n ...props,\n onChange: handlerAll(props.onChange, onCheckboxChange),\n }),\n [\n checkboxId,\n labelId,\n selected,\n checked,\n disabled,\n indeterminate,\n onCheckboxChange,\n ],\n )\n\n const getGroupProps: PropGetter<\"ul\"> = useCallback(\n ({ \"aria-labelledby\": ariaLabelledby, ...props } = {}) => ({\n \"aria-busy\": ariaAttr(groupLoading),\n \"aria-labelledby\": cx(ariaLabelledby, labelId),\n \"data-disabled\": dataAttr(disabled),\n role: \"group\",\n ...props,\n }),\n [labelId, disabled, groupLoading],\n )\n\n const getLabelProps: PropGetter<\"span\"> = useCallback(\n (props = {}) => ({ id: labelId, ...props }),\n [labelId],\n )\n\n return {\n branchOpen,\n checked,\n children,\n disabled,\n group,\n groupLoading,\n groupOpen,\n indeterminate,\n level,\n props: rest,\n selected,\n value,\n getCheckboxProps,\n getGroupItemProps,\n getGroupProps,\n getIndicatorProps,\n getItemProps,\n getLabelProps,\n onGroupClose,\n onGroupOpen,\n onGroupToggle,\n }\n}\n\nexport type UseTreeItemReturn = ReturnType<typeof useTreeItem>\n"],"mappings":";;;;;;;;;;;;;;;;AAmDA,MAAM,EACJ,oBAAoB,wBACpB,eAAe,mBACf,gBAAgB,uBACdA,uDAAqD;AASzD,MAAM,CAAC,aAAa,kBAAkBC,8BAA2B,EAC/D,MAAM,eACP,CAAC;AAeF,MAAM,CAAC,iBAAiB,sBAAsBA,8BAA+B;CAC3E,MAAM;CACN,QAAQ;CACT,CAAC;AA6DF,MAAa,WAA6C,EACxD,YAAY,OACZ,cAAc,kBACd,UACA,YACA,sBAAsB,EAAE,EACxB,uBAAuB,EAAE,EACzB,sBACA,eAAe,mBACf,UACA,eAAe,mBACf,iBAAiB,qBACjB,kBAAkB,sBAClB,kBAAkB,sBAClB,GAAG,SACuB,EAAE,KAAK;CAGjC,MAAM,CAAC,eAAe,oBAAoBC,gEAAqB;EAC7D,cACE,yBAA0B,WAAW,EAAE,GAAG;EAC5C,OAAO;EACP,UAAU;EACX,CAAC;CACF,MAAM,CAAC,cAAc,mBAAmBA,gEAAqB;EAC3D,cAAc;EACd,OAAO;EACP,UAAU;EACX,CAAC;CACF,MAAM,CAAC,eAAe,oBAAoBA,gEAAqB;EAC7D,cAAc;EACd,OAAO;EACP,UAAU;EACX,CAAC;CACF,MAAM,cAAc,oBAAoB;CACxC,MAAM,qCAGI,KAAK;CACf,MAAM,8BAA0D;EAC9D,WAAW;EACX,OAAO;EACR,CAAC;CACF,MAAM,+BAAyB,KAAK;CAEpC,MAAM,2CAAgC;AAKpC,mBAJe,YAAY,eAAe,CACrB,QAAQ,EAAE,YAAY,MAAM,CAC7B,KAAK,EAAE,YAAY,MAAM,CAEtB;IACtB,CAAC,aAAa,iBAAiB,CAAC;CAEnC,MAAM,6CAAkC;AACtC,mBAAiB,EAAE,CAAC;IACnB,CAAC,iBAAiB,CAAC;CAEtB,MAAM,6CAEF,YACA,cAAc,SACX;AACH,MAAI,C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B,SAAS;EACnC,gEAAyB,aAAa;EACtC,iEAA0B,SAAS;EACnC,MAAM;EACN,GAAG;EACJ,GACD;EAAC;EAAU;EAAW;EAAU;EAAa,CAC9C;AAyCD,QAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,OAAO;EACP;EACA;EACA,0CAnDC,EAAE,mBAAmB,gBAAgB,GAAG,UAAU,EAAE,MAAM;GACzD,IAAI;GACJ,6DAAsB,gBAAgB,QAAQ;GAC9C,iEAA0B,SAAS;GACnC;GACA;GACA;GACA,UAAU;GACV,GAAG;GACH,4DAAqB,MAAM,UAAU,iBAAiB;GACvD,GACD;GACE;GACA;GACA;GACA;GACA;GACA;GACA;GACD,CACF;EAgCC;EACA,uCA9BC,EAAE,mBAAmB,gBAAgB,GAAG,UAAU,EAAE,MAAM;GACzD,6DAAsB,aAAa;GACnC,6DAAsB,gBAAgB,QAAQ;GAC9C,iEAA0B,SAAS;GACnC,MAAM;GACN,GAAG;GACJ,GACD;GAAC;GAAS;GAAU;GAAa,CAClC;EAuBC;EACA;EACA,uCAtBC,QAAQ,EAAE,MAAM;GAAE,IAAI;GAAS,GAAG;GAAO,GAC1C,CAAC,QAAQ,CACV;EAqBC;EACA;EACA;EACD"}
1
+ {"version":3,"file":"use-tree.cjs","names":["createDescendants","createContext","useControllableState","descendant","value","mergeProps","useIds","Children","level: number","value: string","useDisclosure","branchOpen: boolean[]","useAsyncCallback","selectedValue","parentTarget: string[]","children","indeterminate","getItemProps: PropGetter<\"li\">","mergeRefs","getGroupItemProps: PropGetter<\"li\">","getIndicatorProps: PropGetter<\"svg\">"],"sources":["../../../../src/components/tree/use-tree.ts"],"sourcesContent":["\"use client\"\n\nimport type {\n ChangeEvent,\n KeyboardEvent,\n MouseEvent,\n ReactNode,\n RefObject,\n SetStateAction,\n} from \"react\"\nimport type { HTMLProps, PropGetter } from \"../../core\"\nimport type { Descendant, Descendants } from \"../../hooks/use-descendants\"\nimport type { UseDisclosureProps } from \"../../hooks/use-disclosure\"\nimport type { UseCheckboxProps } from \"../checkbox\"\nimport { Children, useCallback, useRef, useState } from \"react\"\nimport { mergeProps } from \"../../core\"\nimport { useAsyncCallback } from \"../../hooks/use-async-callback\"\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 cx,\n dataAttr,\n filterEmpty,\n handlerAll,\n isArray,\n isInputElement,\n isUndefined,\n match,\n mergeRefs,\n runKeyAction,\n setAttribute,\n useIds,\n useSafeLayoutEffect,\n} from \"../../utils\"\n\nexport interface TreeControl {\n collapse: () => void\n expand: () => void\n}\n\ninterface TreeDescendantProps {\n expanded: boolean\n group: boolean\n id: string\n value: string\n query?: string\n}\n\nconst {\n DescendantsContext: TreeDescendantsContext,\n useDescendant: useTreeDescendant,\n useDescendants: useTreeDescendants,\n} = createDescendants<HTMLElement, TreeDescendantProps>()\n\nexport { TreeDescendantsContext, useTreeDescendant, useTreeDescendants }\n\ninterface TreeContext extends Omit<\n UseTreeReturn,\n \"descendants\" | \"getRootProps\"\n> {}\n\nconst [TreeContext, useTreeContext] = createContext<TreeContext>({\n name: \"TreeContext\",\n})\n\nexport { TreeContext, useTreeContext }\n\ninterface TreeItemContext extends Pick<\n UseTreeItemReturn,\n | \"branchOpen\"\n | \"groupOpen\"\n | \"level\"\n | \"onGroupClose\"\n | \"onGroupOpen\"\n | \"onGroupToggle\"\n | \"value\"\n> {}\n\nconst [TreeItemContext, useTreeItemContext] = createContext<TreeItemContext>({\n name: \"TreeItemContext\",\n strict: false,\n})\n\nexport { TreeItemContext, useTreeItemContext }\n\nexport interface UseTreeProps<\n Multiple extends boolean = false,\n> extends HTMLProps<\"ul\"> {\n /**\n * If `true`, the tree will allow checkable items.\n *\n * @default false\n */\n checkable?: boolean\n /**\n * The checked value of the tree.\n */\n checkedValue?: string[]\n /**\n * Ref of the tree callbacks.\n */\n controlRef?: RefObject<null | TreeControl>\n /**\n * The initial checked value of the tree.\n */\n defaultCheckedValue?: string[]\n /**\n * The initial expanded value of the tree.\n */\n defaultExpandedValue?: string[]\n /**\n * The initial selected value of the tree.\n */\n defaultSelectedValue?: Multiple extends true ? string[] : string\n /**\n * The expanded value of the tree.\n */\n expandedValue?: string[]\n /**\n * If `true`, the tree will allow multiple selection.\n *\n * @default false\n */\n multiple?: Multiple\n /**\n * The selected value of the tree.\n */\n selectedValue?: Multiple extends true ? string[] : string\n /**\n * The callback invoked when checked value changes.\n */\n onCheckedChange?: (value: string[]) => void\n /**\n * The callback invoked when expanded value changes.\n */\n onExpandedChange?: (value: string[]) => void\n /**\n * The callback invoked when selected value changes.\n */\n onSelectedChange?: (value: Multiple extends true ? string[] : string) => void\n}\n\nexport const useTree = <Multiple extends boolean = false>({\n checkable = false,\n checkedValue: checkedValueProp,\n children,\n controlRef,\n defaultCheckedValue = [],\n defaultExpandedValue = [],\n defaultSelectedValue,\n expandedValue: expandedValueProp,\n multiple,\n selectedValue: selectedValueProp,\n onCheckedChange: onCheckedChangeProp,\n onExpandedChange: onExpandedChangeProp,\n onSelectedChange: onSelectedChangeProp,\n ...rest\n}: UseTreeProps<Multiple> = {}) => {\n type MaybeSelectedValue = Multiple extends true ? string[] : string\n\n const [selectedValue, setSelectedValue] = useControllableState({\n defaultValue:\n defaultSelectedValue ?? ((multiple ? [] : \"\") as MaybeSelectedValue),\n value: selectedValueProp,\n onChange: onSelectedChangeProp,\n })\n const [checkedValue, onCheckedChange] = useControllableState({\n defaultValue: defaultCheckedValue,\n value: checkedValueProp,\n onChange: onCheckedChangeProp,\n })\n const [expandedValue, setExpandedValue] = useControllableState({\n defaultValue: defaultExpandedValue,\n value: expandedValueProp,\n onChange: onExpandedChangeProp,\n })\n const descendants = useTreeDescendants()\n const activeDescendant = useRef<Descendant<\n HTMLElement,\n TreeDescendantProps\n > | null>(null)\n const searchRef = useRef<{ value: string; omitValue?: string }>({\n omitValue: undefined,\n value: \"\",\n })\n const timeoutRef = useRef<any>(null)\n\n const onExpandAll = useCallback(() => {\n const values = descendants.enabledValues()\n const group = values.filter(({ group }) => group)\n const value = group.map(({ value }) => value)\n\n setExpandedValue(value)\n }, [descendants, setExpandedValue])\n\n const onCollapseAll = useCallback(() => {\n setExpandedValue([])\n }, [setExpandedValue])\n\n const onActiveDescendant = useCallback(\n (\n descendant?: Descendant<HTMLElement, TreeDescendantProps>,\n shouldFocus = true,\n ) => {\n if (!descendant) return\n\n descendants.values().forEach(({ node }) => {\n node.tabIndex = -1\n })\n\n activeDescendant.current = descendant\n descendant.node.tabIndex = 0\n\n if (shouldFocus) descendant.node.focus()\n },\n [descendants],\n )\n\n const onSearch = useCallback(\n (value: string, omitValue: string) => {\n clearTimeout(timeoutRef.current)\n\n searchRef.current.value += value\n\n if (!searchRef.current.omitValue) searchRef.current.omitValue = omitValue\n\n timeoutRef.current = setTimeout(() => {\n searchRef.current = { omitValue: undefined, value: \"\" }\n }, 400)\n\n const values = descendants\n .enabledValues({ expanded: true })\n .filter(\n (descendant) =>\n !isUndefined(descendant.value) &&\n descendant.value !== searchRef.current.omitValue,\n )\n const descendant = values.find(({ query, value }) =>\n match(query ?? value, searchRef.current.value, \"startsWith\"),\n )\n\n if (descendant) onActiveDescendant(descendant)\n },\n [descendants, onActiveDescendant],\n )\n\n const onSelectedChange = useCallback(\n (value: SetStateAction<string | string[]>) => {\n setSelectedValue(value as SetStateAction<MaybeSelectedValue>)\n },\n [setSelectedValue],\n )\n\n const onExpandedChange = useCallback(\n (value: string) => {\n setExpandedValue((prev) => {\n if (prev.includes(value)) {\n return prev.filter((prevValue) => prevValue !== value)\n } else {\n return [...prev, value]\n }\n })\n },\n [setExpandedValue],\n )\n\n useSafeLayoutEffect(() => {\n const value = isArray(selectedValue) ? selectedValue.at(0) : selectedValue\n const expandedDescendants = descendants.enabledValues({ expanded: true })\n\n if (value) {\n const descendant = expandedDescendants.find(\n (descendant) => value === descendant.value,\n )\n\n if (descendant) {\n onActiveDescendant(descendant, false)\n } else {\n onActiveDescendant(expandedDescendants.at(0), false)\n }\n } else {\n onActiveDescendant(expandedDescendants.at(0), false)\n }\n }, [children])\n\n assignRef(controlRef, { collapse: onCollapseAll, expand: onExpandAll })\n\n const getRootProps: PropGetter<\"ul\"> = useCallback(\n (props) =>\n mergeProps(\n {\n \"aria-multiselectable\": ariaAttr(multiple || checkable),\n children,\n role: \"tree\",\n },\n rest,\n props,\n )(),\n [multiple, checkable, rest, children],\n )\n\n return {\n activeDescendant,\n checkable,\n checkedValue,\n descendants,\n expandedValue,\n multiple,\n selectedValue,\n getRootProps,\n onActiveDescendant,\n onCheckedChange,\n onCollapseAll,\n onExpandAll,\n onExpandedChange,\n onSearch,\n onSelectedChange,\n }\n}\n\nexport type UseTreeReturn = ReturnType<typeof useTree>\n\nconst getRootDescendant =\n (descendants: Descendants<HTMLElement, TreeDescendantProps>) =>\n (value: string) => {\n const segments = value.split(\"/\")\n\n if (segments.length <= 1) return\n\n const rootValue = segments.at(0)\n\n return descendants.enabledValues().find(({ value }) => value === rootValue)\n }\n\nconst getParentDescendant =\n (descendants: Descendants<HTMLElement, TreeDescendantProps>) =>\n (value: string) => {\n const segments = value.split(\"/\")\n\n if (segments.length <= 1) return\n\n const parentValue = segments.slice(0, -1).join(\"/\")\n\n return descendants\n .enabledValues()\n .find(({ value }) => value === parentValue)\n }\n\nconst getChildDescendants =\n (descendants: Descendants<HTMLElement, TreeDescendantProps>) =>\n (value: string) => {\n const children = descendants\n .enabledValues()\n .filter((descendant) => descendant.value.startsWith(value + \"/\"))\n const values = children\n .map(({ value }) => value)\n .filter((value) => !isUndefined(value))\n\n return { children, values }\n }\n\nconst getParentValues = (value: string) => {\n const segments = value.split(\"/\")\n\n return segments\n .reduce<string[]>((prev, current) => {\n const prevValue = prev.at(-1)\n return prevValue ? [...prev, [prevValue, current].join(\"/\")] : [current]\n }, [])\n .toReversed()\n}\n\nconst getCheckbox = (node?: HTMLElement) => {\n const el = node?.querySelector(\"input[type='checkbox']\")\n\n return isInputElement(el) ? el : null\n}\n\nconst getAllChecked = (\n descendants: Descendant<HTMLElement, TreeDescendantProps>[],\n trulyValues?: string[],\n falsyValues?: string[],\n) => {\n const checked = descendants.map(({ node, value }) => {\n if (value && trulyValues?.includes(value)) return true\n if (value && falsyValues?.includes(value)) return false\n\n const checkbox = getCheckbox(node)\n\n return !!checkbox?.checked\n })\n\n const allChecked = !!checked.length && checked.every(Boolean)\n const indeterminate = checked.some(Boolean) && !allChecked\n\n return { allChecked, checked, indeterminate }\n}\n\nconst getRangeValues =\n (descendants: Descendants<HTMLElement, TreeDescendantProps>) =>\n (start: string, end: string) => {\n const values = descendants.enabledValues()\n const [startIndex, endIndex] = [\n values.findIndex((descendant) => descendant.value === start),\n values.findIndex((descendant) => descendant.value === end),\n ].sort((a, b) => a - b)\n\n return values\n .slice(startIndex, endIndex! + 1)\n .map(({ value }) => value)\n .filter((value) => !isUndefined(value))\n .sort((a, b) => {\n if (a === start && b !== start) return -1\n if (a !== start && b === start) return 1\n\n return 0\n })\n }\n\nexport interface UseTreeItemProps\n extends HTMLProps<\"div\">, Omit<UseDisclosureProps, \"timing\"> {\n /**\n * If `true`, the tree item will be disabled.\n *\n * @default false\n */\n disabled?: boolean\n /**\n * The query to search for in the tree item.\n */\n query?: string\n /**\n * The value of the item.\n */\n value?: string\n /**\n * If provided, the tree item will be rendered as an async tree item.\n */\n asyncChildren?: () => Promise<ReactNode>\n}\n\nexport const useTreeItem = ({\n asyncChildren,\n children: childrenProp,\n defaultOpen,\n disabled = false,\n open: openProp,\n query,\n value: valueProp,\n onClose: onCloseProp,\n onOpen: onOpenProp,\n ...rest\n}: UseTreeItemProps = {}) => {\n const context = useTreeItemContext()\n const {\n activeDescendant,\n checkable,\n checkedValue,\n expandedValue,\n multiple,\n selectedValue,\n onActiveDescendant,\n onCheckedChange,\n onCollapseAll,\n onExpandAll,\n onExpandedChange,\n onSearch,\n onSelectedChange,\n } = useTreeContext()\n const [children, setChildren] = useState<ReactNode>(childrenProp)\n const [indeterminate, setIndeterminate] = useState(false)\n const [itemId, labelId, checkboxId] = useIds()\n const initialAsyncRef = useRef(false)\n const async = !!asyncChildren\n const group = async || Children.count(children) > 0\n const level: number = (context?.level ?? 0) + 1\n const value: string = filterEmpty([context?.value, valueProp]).join(\"/\")\n const nested = !!context?.value\n const selected = isArray(selectedValue)\n ? !!value && selectedValue.includes(value)\n : !!value && selectedValue === value\n const checked = !!value && checkedValue.includes(value)\n const defaultExpanded = !!value && expandedValue.includes(value)\n const {\n open: groupOpen,\n onClose,\n onOpen,\n } = useDisclosure({\n defaultOpen: defaultOpen ?? defaultExpanded,\n open: openProp,\n onClose: onCloseProp,\n onOpen: onOpenProp,\n })\n const branchOpen: boolean[] = nested\n ? [...context.branchOpen, groupOpen]\n : [groupOpen]\n const { descendants, register } = useTreeDescendant({\n id: itemId!,\n disabled,\n expanded: branchOpen.slice(0, -1).every(Boolean),\n group,\n query,\n value,\n })\n\n const [groupLoading, onGroupChildren] = useAsyncCallback(async () => {\n const children = await asyncChildren?.()\n\n setChildren(children)\n }, [asyncChildren])\n\n const onSelect = useCallback(\n (\n ev: (\n | Partial<KeyboardEvent<HTMLElement>>\n | Partial<MouseEvent<HTMLElement>>\n ) & { value?: string } = {},\n ) => {\n const selectedValue = ev.value ?? value\n\n if (disabled || !selectedValue) return\n\n if (multiple) {\n onSelectedChange((prev) => {\n if (!isArray(prev)) return prev\n\n if (ev.ctrlKey || ev.metaKey) {\n if (prev.includes(selectedValue)) {\n return prev.filter((prevValue) => prevValue !== selectedValue)\n } else {\n return [...prev, selectedValue]\n }\n } else if (ev.shiftKey && prev[0]) {\n if (prev[0] === selectedValue) return prev\n\n return getRangeValues(descendants)(prev[0], selectedValue)\n } else {\n return [selectedValue]\n }\n })\n } else {\n onSelectedChange(selectedValue)\n }\n },\n [descendants, disabled, multiple, onSelectedChange, value],\n )\n\n const onGroupOpen = useCallback(() => {\n if (disabled || !value) return\n\n if (async && !initialAsyncRef.current) {\n initialAsyncRef.current = true\n\n onGroupChildren()\n .then(() => {\n onOpen()\n onExpandedChange(value)\n })\n .catch(() => {\n initialAsyncRef.current = false\n })\n } else {\n onOpen()\n onExpandedChange(value)\n }\n }, [disabled, async, onGroupChildren, onOpen, onExpandedChange, value])\n\n const onGroupClose = useCallback(() => {\n if (disabled || !value) return\n\n onClose()\n onExpandedChange(value)\n }, [disabled, onClose, onExpandedChange, value])\n\n const onGroupToggle = useCallback(() => {\n if (groupOpen) {\n onGroupClose()\n } else {\n onGroupOpen()\n }\n }, [groupOpen, onGroupClose, onGroupOpen])\n\n const onKeyDown = useCallback(\n (ev: KeyboardEvent<HTMLElement>) => {\n if (disabled || !value) return\n\n runKeyAction(ev, {\n a: () => {\n if (!multiple || !(ev.ctrlKey || ev.metaKey)) return\n\n const values = descendants\n .enabledValues()\n .map(({ value }) => value)\n .filter((value) => !isUndefined(value))\n\n onSelectedChange(values)\n },\n ArrowDown: () => {\n if ((ev.ctrlKey || ev.metaKey) && ev.shiftKey) {\n onExpandAll()\n } else {\n const descendant = descendants.enabledNextValue(\n activeDescendant.current,\n false,\n { expanded: true },\n )\n\n onActiveDescendant(descendant)\n\n if (descendant && ev.shiftKey && multiple)\n onSelect({ ctrlKey: true, value: descendant.value })\n }\n },\n ArrowLeft: () => {\n if (group && groupOpen) {\n onGroupClose()\n } else if (nested) {\n const descendant = getParentDescendant(descendants)(value)\n\n onActiveDescendant(descendant)\n }\n },\n ArrowRight: () => {\n if (!group) return\n\n if (groupOpen) {\n const descendant = descendants.enabledNextValue(\n activeDescendant.current,\n false,\n { expanded: true },\n )\n\n onActiveDescendant(descendant)\n } else {\n if (!groupLoading) onGroupOpen()\n }\n },\n ArrowUp: () => {\n if ((ev.ctrlKey || ev.metaKey) && ev.shiftKey) {\n onCollapseAll()\n\n if (!nested) return\n\n const descendant = getRootDescendant(descendants)(value)\n\n onActiveDescendant(descendant)\n } else {\n const descendant = descendants.enabledPrevValue(\n activeDescendant.current,\n false,\n { expanded: true },\n )\n\n onActiveDescendant(descendant)\n\n if (descendant && ev.shiftKey && multiple)\n onSelect({ ctrlKey: true, value: descendant.value })\n }\n },\n End: () => {\n const descendant = descendants\n .enabledValues({ expanded: true })\n .at(-1)\n\n onActiveDescendant(descendant)\n },\n Enter: () => {\n if (group) onGroupToggle()\n\n onSelect(ev)\n },\n Home: () => {\n const descendant = descendants.enabledValues({ expanded: true }).at(0)\n\n onActiveDescendant(descendant)\n },\n Space: () => {\n if (group) onGroupToggle()\n\n onSelect(ev)\n },\n })\n\n if (ev.key.length !== 1) return\n if (ev.ctrlKey || ev.metaKey || ev.altKey) return\n\n ev.preventDefault()\n\n onSearch(ev.key, query ?? value)\n },\n [\n activeDescendant,\n descendants,\n disabled,\n group,\n groupLoading,\n groupOpen,\n multiple,\n nested,\n onActiveDescendant,\n onCollapseAll,\n onExpandAll,\n onGroupClose,\n onGroupOpen,\n onGroupToggle,\n onSearch,\n onSelect,\n onSelectedChange,\n query,\n value,\n ],\n )\n\n const onItemClick = useCallback(\n (ev: MouseEvent<HTMLLIElement>) => {\n ev.stopPropagation()\n\n if (disabled || !value) return\n\n if (group && !groupLoading)\n if (!ev.ctrlKey && !ev.metaKey && !ev.shiftKey) onGroupToggle()\n\n onSelect(ev)\n },\n [disabled, group, groupLoading, onGroupToggle, onSelect, value],\n )\n\n const onCheckboxChange = useCallback(\n (ev: ChangeEvent<HTMLInputElement>) => {\n if (disabled || !value) return\n\n ev.stopPropagation()\n\n if (group) setIndeterminate(false)\n\n onCheckedChange((prev) => {\n const target = [value]\n\n if (group) {\n const { values } = getChildDescendants(descendants)(value)\n\n target.push(...values)\n }\n\n if (nested) {\n const parentValues = getParentValues(context.value)\n const parentTarget: string[] = []\n\n parentValues.forEach((parentValue) => {\n const { children } = getChildDescendants(descendants)(parentValue)\n const { allChecked } = getAllChecked(\n children,\n [...parentTarget, ...(ev.target.checked ? target : [])],\n !ev.target.checked ? target : [],\n )\n\n if (allChecked) parentTarget.push(parentValue)\n })\n\n if (!ev.target.checked) parentTarget.push(...parentValues)\n\n target.push(...parentTarget)\n }\n\n if (ev.target.checked) {\n return [...new Set([...prev, ...target])]\n } else {\n return prev.filter((prevValue) => !target.includes(prevValue))\n }\n })\n },\n [disabled, group, onCheckedChange, value, nested, descendants, context],\n )\n\n useSafeLayoutEffect(() => {\n if (defaultExpanded) {\n if (async && !initialAsyncRef.current) {\n initialAsyncRef.current = true\n\n onGroupChildren()\n .then(() => {\n onOpen()\n })\n .catch(() => {\n initialAsyncRef.current = false\n })\n } else {\n onOpen()\n }\n } else {\n onClose()\n }\n }, [async, defaultExpanded, onClose, onGroupChildren, onOpen])\n\n useSafeLayoutEffect(() => {\n if (!group || !checkable) return\n\n const { children } = getChildDescendants(descendants)(value)\n const { indeterminate } = getAllChecked(children)\n\n setIndeterminate(indeterminate)\n }, [checkedValue])\n\n useSafeLayoutEffect(() => {\n if (!checkable) return\n\n const { node } = getParentDescendant(descendants)(value) ?? {}\n const checkbox = getCheckbox(node)\n\n if (!checkbox) return\n\n const cleanup = setAttribute(checkbox, \"aria-controls\", checkboxId)\n\n return cleanup\n }, [checkable, descendants])\n\n const getItemProps: PropGetter<\"li\"> = useCallback(\n ({ ref, \"aria-labelledby\": ariaLabelledby, ...props } = {}) => ({\n id: itemId,\n ref: mergeRefs(ref, register),\n \"aria-disabled\": ariaAttr(disabled),\n \"aria-labelledby\": cx(ariaLabelledby, labelId),\n \"aria-level\": level,\n \"aria-selected\": ariaAttr(selected),\n \"data-disabled\": dataAttr(disabled),\n role: \"treeitem\",\n tabIndex: -1,\n ...props,\n onClick: handlerAll(props.onClick, onItemClick),\n onKeyDown: handlerAll(props.onKeyDown, onKeyDown),\n }),\n [\n itemId,\n register,\n disabled,\n labelId,\n level,\n selected,\n onItemClick,\n onKeyDown,\n ],\n )\n\n const getGroupItemProps: PropGetter<\"li\"> = useCallback(\n (props = {}) => getItemProps({ \"aria-expanded\": groupOpen, ...props }),\n [getItemProps, groupOpen],\n )\n\n const getIndicatorProps: PropGetter<\"svg\"> = useCallback(\n (props) => ({\n \"aria-disabled\": ariaAttr(disabled),\n \"aria-expanded\": groupOpen,\n \"aria-hidden\": true,\n \"data-disabled\": dataAttr(disabled),\n \"data-loading\": dataAttr(groupLoading),\n \"data-selected\": dataAttr(selected),\n role: \"presentation\",\n ...props,\n }),\n [disabled, groupOpen, selected, groupLoading],\n )\n\n const getCheckboxProps: PropGetter<UseCheckboxProps> = useCallback(\n ({ \"aria-labelledby\": ariaLabelledby, ...props } = {}) => ({\n id: checkboxId,\n \"aria-labelledby\": cx(ariaLabelledby, labelId),\n \"data-selected\": dataAttr(selected),\n checked,\n disabled,\n indeterminate,\n tabIndex: -1,\n ...props,\n onChange: handlerAll(props.onChange, onCheckboxChange),\n }),\n [\n checkboxId,\n labelId,\n selected,\n checked,\n disabled,\n indeterminate,\n onCheckboxChange,\n ],\n )\n\n const getGroupProps: PropGetter<\"ul\"> = useCallback(\n ({ \"aria-labelledby\": ariaLabelledby, ...props } = {}) => ({\n \"aria-busy\": ariaAttr(groupLoading),\n \"aria-labelledby\": cx(ariaLabelledby, labelId),\n \"data-disabled\": dataAttr(disabled),\n role: \"group\",\n ...props,\n }),\n [labelId, disabled, groupLoading],\n )\n\n const getLabelProps: PropGetter<\"span\"> = useCallback(\n (props = {}) => ({ id: labelId, ...props }),\n [labelId],\n )\n\n return {\n branchOpen,\n checked,\n children,\n disabled,\n group,\n groupLoading,\n groupOpen,\n indeterminate,\n level,\n props: rest,\n selected,\n value,\n getCheckboxProps,\n getGroupItemProps,\n getGroupProps,\n getIndicatorProps,\n getItemProps,\n getLabelProps,\n onGroupClose,\n onGroupOpen,\n onGroupToggle,\n }\n}\n\nexport type UseTreeItemReturn = ReturnType<typeof useTreeItem>\n"],"mappings":";;;;;;;;;;;;;;;;;;AAoDA,MAAM,EACJ,oBAAoB,wBACpB,eAAe,mBACf,gBAAgB,uBACdA,uDAAqD;AASzD,MAAM,CAAC,aAAa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CAnDC,EAAE,mBAAmB,gBAAgB,GAAG,UAAU,EAAE,MAAM;GACzD,IAAI;GACJ,6DAAsB,gBAAgB,QAAQ;GAC9C,iEAA0B,SAAS;GACnC;GACA;GACA;GACA,UAAU;GACV,GAAG;GACH,4DAAqB,MAAM,UAAU,iBAAiB;GACvD,GACD;GACE;GACA;GACA;GACA;GACA;GACA;GACA;GACD,CACF;EAgCC;EACA,uCA9BC,EAAE,mBAAmB,gBAAgB,GAAG,UAAU,EAAE,MAAM;GACzD,6DAAsB,aAAa;GACnC,6DAAsB,gBAAgB,QAAQ;GAC9C,iEAA0B,SAAS;GACnC,MAAM;GACN,GAAG;GACJ,GACD;GAAC;GAAS;GAAU;GAAa,CAClC;EAuBC;EACA;EACA,uCAtBC,QAAQ,EAAE,MAAM;GAAE,IAAI;GAAS,GAAG;GAAO,GAC1C,CAAC,QAAQ,CACV;EAqBC;EACA;EACA;EACD"}
@@ -1 +1 @@
1
- {"version":3,"file":"use-carousel.js","names":["createContext","snapCount","total","index","getRootProps: PropGetter<\"section\">","getListProps: PropGetter","getItemProps: RequiredPropGetter<\"div\", { index: number }>","indexProp","getPrevTriggerProps: PropGetter<\"button\">","getNextTriggerProps: PropGetter<\"button\">","getIndicatorsProps: PropGetter"],"sources":["../../../../src/components/carousel/use-carousel.ts"],"sourcesContent":["\"use client\"\n\nimport type {\n EmblaCarouselType,\n EmblaOptionsType,\n EmblaPluginType,\n} from \"embla-carousel\"\nimport type { KeyboardEvent, RefObject } from \"react\"\nimport type {\n HTMLProps,\n Orientation,\n PropGetter,\n RequiredPropGetter,\n} from \"../../core\"\nimport useEmblaCarousel from \"embla-carousel-react\"\nimport { useCallback, useEffect, useRef, useState } from \"react\"\nimport { mergeProps } from \"../../core\"\nimport { useBoolean } from \"../../hooks/use-boolean\"\nimport { useControllableState } from \"../../hooks/use-controllable-state\"\nimport { useI18n } from \"../../providers/i18n-provider\"\nimport {\n assignRef,\n createContext,\n dataAttr,\n handlerAll,\n isFunction,\n mergeRefs,\n runKeyAction,\n useIds,\n useUpdateEffect,\n} from \"../../utils\"\n\ntype EmblaOptions = Required<EmblaOptionsType>\nexport type CarouselAlign = EmblaOptions[\"align\"]\nexport type CarouselContainScroll = EmblaOptions[\"containScroll\"]\nexport type CarouselInViewThreshold = EmblaOptions[\"inViewThreshold\"]\nexport type CarouselWatchDrag = EmblaOptions[\"watchDrag\"]\nexport type CarouselWatchResize = EmblaOptions[\"watchResize\"]\nexport type CarouselWatchSlides = EmblaOptions[\"watchSlides\"]\nexport type CarouselControl = EmblaCarouselType\nexport type CarouselPlugin = EmblaPluginType\n\nexport interface CarouselContext extends Omit<\n UseCarouselReturn,\n \"getRootProps\"\n> {}\n\nconst [CarouselContext, useCarouselContext] = createContext<CarouselContext>({\n name: \"CarouselContext\",\n})\n\nexport { CarouselContext, useCarouselContext }\n\nexport interface UseCarouselProps extends Omit<\n HTMLProps<\"section\">,\n \"onChange\"\n> {\n /**\n * The alignment of the carousel.\n *\n * @default 'center'\n */\n align?: CarouselAlign\n /**\n * If `true`, the carousel will be autoplay.\n *\n * @default false\n */\n autoplay?: boolean\n /**\n * Clear leading and trailing empty space that causes excessive scrolling.\n * Use trimSnaps to only use snap points that trigger scrolling or keepSnaps to keep them.\n *\n * @default false\n */\n containScroll?: CarouselContainScroll\n /**\n * Ref of the resizable item callback.\n */\n controlRef?: RefObject<CarouselControl | null>\n /**\n * The initial index of the carousel slide.\n *\n * @default 0\n */\n defaultIndex?: number\n /**\n * The number for the autoplay interval of the carousel.\n *\n * @default 4000\n */\n delay?: number\n /**\n * If `true`, momentum scrolling will be enabled.\n *\n * @default false\n */\n dragFree?: boolean\n /**\n * If `true`, carousel can be scrolled with mouse and touch interactions.\n *\n * @default true\n */\n draggable?: boolean\n /**\n * Set scroll duration when triggered by any of the API methods.\n * Higher numbers enables slower scrolling.\n * Drag interactions are not affected because duration is then determined by the drag force.\n *\n * @default 25\n */\n duration?: number\n /**\n * The index of the carousel slide.\n */\n index?: number\n /**\n * Choose a fraction representing the percentage portion of a slide that needs to be visible in order to be considered in view.\n *\n * @default 0\n */\n inViewThreshold?: CarouselInViewThreshold\n /**\n * If `true`, infinite looping.\n * Automatically falls back to false if slide content isn't enough to loop.\n *\n * @default true\n */\n loop?: boolean\n /**\n * The orientation of the carousel.\n *\n * @default 'horizontal'\n */\n orientation?: Orientation\n /**\n * Embla plugins to use.\n */\n plugins?: CarouselPlugin[]\n /**\n * If `true`, allow the carousel to skip scroll snaps if it's dragged vigorously.\n * Note that this option will be ignored if the dragFree option is set to true.\n *\n * @default false\n */\n skipSnaps?: boolean\n /**\n * The number of slides that should be scrolled with next or previous buttons.\n *\n * @default 1\n */\n slidesToScroll?: number\n /**\n * If `true`, autoplay will pause when the mouse entries over.\n *\n * @default true\n */\n stopMouseEnterAutoplay?: boolean\n /**\n * Enables for scrolling the carousel with mouse and touch interactions.\n * Set this to `false` to disable drag events or pass a custom callback to add your own drag logic.\n *\n * @default true\n */\n watchDrag?: CarouselWatchDrag\n /**\n * Embla automatically watches the container and slides for size changes and runs `reInit` when any size has changed.\n * Set this to `false` to disable this behaviour or pass a custom callback to add your own resize logic.\n *\n * @default true\n */\n watchResize?: CarouselWatchResize\n /**\n * Embla automatically watches the container for added and/or removed slides and runs `reInit` if needed.\n * Set this to `false` to disable this behaviour or pass a custom callback to add your own slides changed logic.\n *\n * @default true\n */\n watchSlides?: CarouselWatchSlides\n /**\n * The callback invoked when carousel slide selected.\n */\n onChange?: (index: number) => void\n /**\n * A callback that return the current scroll amount when the carousel is scrolled.\n */\n onScrollProgress?: (progress: number) => void\n}\n\nexport const useCarousel = ({\n id,\n align = \"center\",\n autoplay = false,\n containScroll = false,\n controlRef,\n defaultIndex = 0,\n delay = 4000,\n dragFree = false,\n draggable = true,\n duration = 25,\n index: indexProp,\n inViewThreshold = 0,\n loop = true,\n orientation = \"horizontal\",\n plugins = [],\n skipSnaps = false,\n slidesToScroll = 1,\n stopMouseEnterAutoplay = true,\n watchDrag = draggable,\n watchResize: watchResizeProp = true,\n watchSlides = true,\n onChange,\n onScrollProgress,\n ...rest\n}: UseCarouselProps = {}) => {\n const { t } = useI18n(\"carousel\")\n const [index, setIndex] = useControllableState({\n defaultValue: defaultIndex,\n value: indexProp,\n onChange,\n })\n const [rootId, listId] = useIds()\n const [hover, { off: onMouseLeave, on: onMouseEnter }] = useBoolean()\n const timeoutId = useRef<NodeJS.Timeout | null>(null)\n const indicatorMapRef = useRef<Map<number, HTMLButtonElement | null>>(\n new Map(),\n )\n const listRef = useRef<HTMLDivElement>(null)\n const horizontal = orientation === \"horizontal\"\n const axis = horizontal ? \"x\" : \"y\"\n const [snapCount, setSnapCount] = useState(0)\n const [total, setTotal] = useState(0)\n const watchResize = useCallback<Extract<CarouselWatchResize, Function>>(\n (methods, entries) => {\n const result = isFunction(watchResizeProp)\n ? watchResizeProp(methods, entries)\n : true\n const snapCount = methods.scrollSnapList().length\n const total = methods.slideNodes().length\n\n setSnapCount(snapCount)\n setTotal(total)\n\n return result\n },\n [watchResizeProp],\n )\n const [carouselRef, carousel] = useEmblaCarousel(\n {\n align,\n axis,\n container: listRef.current,\n containScroll,\n dragFree,\n duration,\n inViewThreshold,\n loop,\n skipSnaps,\n slidesToScroll,\n startIndex: defaultIndex,\n watchDrag,\n watchResize,\n watchSlides,\n },\n plugins,\n )\n\n id ??= rootId\n\n const onInit = useCallback((methods: CarouselControl) => {\n const snapCount = methods.scrollSnapList().length\n const total = methods.slideNodes().length\n\n setSnapCount(snapCount)\n setTotal(total)\n }, [])\n\n const onScroll = useCallback(() => {\n if (!carousel) return\n\n const progress = Math.round(\n Math.max(0, Math.min(1, carousel.scrollProgress())) * 100,\n )\n\n onScrollProgress?.(progress)\n }, [carousel, onScrollProgress])\n\n const onSelect = useCallback(() => {\n if (!carousel) return\n\n const index = carousel.selectedScrollSnap()\n\n setIndex(index)\n }, [carousel, setIndex])\n\n const onFocusIndicator = useCallback(\n (index: number) => {\n const el = indicatorMapRef.current.get(index)\n\n el?.focus()\n carousel?.scrollTo(index)\n },\n [carousel],\n )\n\n const onKeyDown = useCallback(\n (index: number) => (ev: KeyboardEvent<HTMLButtonElement>) => {\n const lastIndex = snapCount - 1\n\n runKeyAction(ev, {\n ArrowDown: () => {\n if (horizontal) return\n\n index = index === lastIndex ? 0 : index + 1\n\n onFocusIndicator(index)\n },\n ArrowLeft: () => {\n if (!horizontal) return\n\n index = index === 0 ? lastIndex : index - 1\n\n onFocusIndicator(index)\n },\n ArrowRight: () => {\n if (!horizontal) return\n\n index = index === lastIndex ? 0 : index + 1\n\n onFocusIndicator(index)\n },\n ArrowUp: () => {\n if (horizontal) return\n\n index = index === 0 ? lastIndex : index - 1\n\n onFocusIndicator(index)\n },\n End: () => {\n onFocusIndicator(lastIndex)\n },\n Home: () => {\n onFocusIndicator(0)\n },\n })\n },\n [snapCount, horizontal, onFocusIndicator],\n )\n\n assignRef(controlRef, carousel)\n\n useEffect(() => {\n if (carousel) {\n carousel.on(\"reInit\", onInit)\n carousel.on(\"select\", onSelect)\n carousel.on(\"scroll\", onScroll)\n\n onScroll()\n\n return () => {\n carousel.off(\"reInit\", onInit)\n carousel.off(\"select\", onSelect)\n carousel.off(\"scroll\", onScroll)\n }\n }\n }, [carousel, onInit, onScroll, onSelect])\n\n useEffect(() => {\n const stop = hover && stopMouseEnterAutoplay\n const last = !carousel?.canScrollNext()\n\n if (carousel && autoplay && !stop && !last) {\n timeoutId.current = setInterval(() => {\n carousel.scrollNext()\n }, delay)\n } else {\n if (timeoutId.current) clearInterval(timeoutId.current)\n\n timeoutId.current = null\n }\n\n return () => {\n if (timeoutId.current) clearInterval(timeoutId.current)\n }\n }, [autoplay, carousel, delay, hover, stopMouseEnterAutoplay])\n\n useUpdateEffect(() => {\n if (!carousel) return\n\n if (indexProp === undefined) return\n\n carousel.scrollTo(indexProp)\n }, [indexProp])\n\n useUpdateEffect(() => {\n if (!carousel) return\n\n carousel.reInit()\n }, [\n carousel,\n total,\n align,\n axis,\n containScroll,\n dragFree,\n duration,\n inViewThreshold,\n loop,\n skipSnaps,\n slidesToScroll,\n ])\n\n const getRootProps: PropGetter<\"section\"> = useCallback(\n ({ ref, ...props } = {}) =>\n mergeProps(\n {\n id,\n \"aria-roledescription\": \"carousel\",\n \"data-orientation\": orientation,\n },\n rest,\n {\n ref,\n onMouseEnter,\n onMouseLeave,\n },\n props,\n )(),\n [id, onMouseEnter, onMouseLeave, rest, orientation],\n )\n\n const getListProps: PropGetter = useCallback(\n ({ ref, ...props } = {}) => ({\n id: listId,\n \"aria-live\": autoplay ? \"off\" : \"polite\",\n \"data-orientation\": orientation,\n ...props,\n ref: mergeRefs(ref, listRef, carouselRef),\n }),\n [autoplay, listId, orientation, carouselRef],\n )\n\n const getItemProps: RequiredPropGetter<\"div\", { index: number }> =\n useCallback(\n ({ index: indexProp, ...props }) => {\n const page = indexProp + 1\n const selected = index === indexProp\n\n return {\n id: `${listId}-${indexProp}`,\n \"aria-label\": t(\"{page} of {total}\", { page, total }),\n \"aria-roledescription\": \"slide\",\n \"data-index\": indexProp.toString(),\n \"data-orientation\": orientation,\n \"data-selected\": dataAttr(selected),\n role: \"tabpanel\",\n ...props,\n }\n },\n [index, listId, total, orientation, t],\n )\n\n const getPrevTriggerProps: PropGetter<\"button\"> = useCallback(\n (props = {}) => ({\n \"aria-controls\": listId,\n \"aria-label\": t(\"Go to previous slide\"),\n \"data-orientation\": orientation,\n disabled: !carousel?.canScrollPrev(),\n ...props,\n onClick: handlerAll(props.onClick, () => carousel?.scrollPrev()),\n }),\n [carousel, listId, orientation, t],\n )\n\n const getNextTriggerProps: PropGetter<\"button\"> = useCallback(\n (props = {}) => ({\n \"aria-controls\": listId,\n \"aria-label\": t(\"Go to next slide\"),\n \"data-orientation\": orientation,\n disabled: !carousel?.canScrollNext(),\n ...props,\n onClick: handlerAll(props.onClick, () => carousel?.scrollNext()),\n }),\n [carousel, listId, orientation, t],\n )\n\n const getIndicatorsProps: PropGetter = useCallback(\n (props = {}) => ({\n \"aria-label\": t(\"Slides\"),\n \"aria-orientation\": orientation,\n role: \"tablist\",\n ...props,\n }),\n [orientation, t],\n )\n\n const getIndicatorProps: RequiredPropGetter<\"button\", { index: number }> =\n useCallback(\n ({ ref, index: indexProp, ...props }) => {\n const page = indexProp + 1\n const selected = index === indexProp\n\n return {\n type: \"button\" as const,\n \"aria-controls\": `${listId}-${indexProp}`,\n \"aria-label\": t(\"Go to {page} slide\", { page }),\n \"aria-selected\": selected,\n \"data-index\": indexProp.toString(),\n \"data-orientation\": orientation,\n \"data-selected\": dataAttr(selected),\n role: \"tab\",\n tabIndex: selected ? 0 : -1,\n ...props,\n ref: mergeRefs(ref, (node) => {\n indicatorMapRef.current.set(indexProp, node)\n }),\n onClick: handlerAll(props.onClick, () =>\n carousel?.scrollTo(indexProp),\n ),\n onKeyDown: handlerAll(props.onKeyDown, onKeyDown(indexProp)),\n }\n },\n [index, listId, t, orientation, onKeyDown, carousel],\n )\n\n return {\n carousel,\n index,\n setIndex,\n snapCount,\n total,\n getIndicatorProps,\n getIndicatorsProps,\n getItemProps,\n getListProps,\n getNextTriggerProps,\n getPrevTriggerProps,\n getRootProps,\n }\n}\n\nexport type UseCarouselReturn = ReturnType<typeof useCarousel>\n"],"mappings":";;;;;;;;;;;;;;;;;AA+CA,MAAM,CAAC,iBAAiB,sBAAsBA,gBAA+B,EAC3E,MAAM,mBACP,CAAC;AA4IF,MAAa,eAAe,EAC1B,IACA,QAAQ,UACR,WAAW,OACX,gBAAgB,OAChB,YACA,eAAe,GACf,QAAQ,KACR,WAAW,OACX,YAAY,MACZ,WAAW,IACX,OAAO,WACP,kBAAkB,GAClB,OAAO,MACP,cAAc,cACd,UAAU,EAAE,EACZ,YAAY,OACZ,iBAAiB,GACjB,yBAAyB,MACzB,YAAY,WACZ,aAAa,kBAAkB,MAC/B,cAAc,MACd,UACA,kBACA,GAAG,SACiB,EAAE,KAAK;CAC3B,MAAM,EAAE,MAAM,QAAQ,WAAW;CACjC,MAAM,CAAC,OAAO,YAAY,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EACA;EACA;EACA;EACD"}
1
+ {"version":3,"file":"use-carousel.js","names":["createContext","snapCount","total","index","getRootProps: PropGetter<\"section\">","getListProps: PropGetter","getItemProps: RequiredPropGetter<\"div\", { index: number }>","indexProp","getPrevTriggerProps: PropGetter<\"button\">","getNextTriggerProps: PropGetter<\"button\">","getIndicatorsProps: PropGetter"],"sources":["../../../../src/components/carousel/use-carousel.ts"],"sourcesContent":["\"use client\"\n\nimport type {\n EmblaCarouselType,\n EmblaOptionsType,\n EmblaPluginType,\n} from \"embla-carousel\"\nimport type { KeyboardEvent, RefObject } from \"react\"\nimport useEmblaCarousel from \"embla-carousel-react\"\nimport { useCallback, useEffect, useRef, useState } from \"react\"\nimport {\n type HTMLProps,\n mergeProps,\n type Orientation,\n type PropGetter,\n type RequiredPropGetter,\n} from \"../../core\"\nimport { useBoolean } from \"../../hooks/use-boolean\"\nimport { useControllableState } from \"../../hooks/use-controllable-state\"\nimport { useI18n } from \"../../providers/i18n-provider\"\nimport {\n assignRef,\n createContext,\n dataAttr,\n handlerAll,\n isFunction,\n mergeRefs,\n runKeyAction,\n useIds,\n useUpdateEffect,\n} from \"../../utils\"\n\ntype EmblaOptions = Required<EmblaOptionsType>\nexport type CarouselAlign = EmblaOptions[\"align\"]\nexport type CarouselContainScroll = EmblaOptions[\"containScroll\"]\nexport type CarouselInViewThreshold = EmblaOptions[\"inViewThreshold\"]\nexport type CarouselWatchDrag = EmblaOptions[\"watchDrag\"]\nexport type CarouselWatchResize = EmblaOptions[\"watchResize\"]\nexport type CarouselWatchSlides = EmblaOptions[\"watchSlides\"]\nexport type CarouselControl = EmblaCarouselType\nexport type CarouselPlugin = EmblaPluginType\n\nexport interface CarouselContext extends Omit<\n UseCarouselReturn,\n \"getRootProps\"\n> {}\n\nconst [CarouselContext, useCarouselContext] = createContext<CarouselContext>({\n name: \"CarouselContext\",\n})\n\nexport { CarouselContext, useCarouselContext }\n\nexport interface UseCarouselProps extends Omit<\n HTMLProps<\"section\">,\n \"onChange\"\n> {\n /**\n * The alignment of the carousel.\n *\n * @default 'center'\n */\n align?: CarouselAlign\n /**\n * If `true`, the carousel will be autoplay.\n *\n * @default false\n */\n autoplay?: boolean\n /**\n * Clear leading and trailing empty space that causes excessive scrolling.\n * Use trimSnaps to only use snap points that trigger scrolling or keepSnaps to keep them.\n *\n * @default false\n */\n containScroll?: CarouselContainScroll\n /**\n * Ref of the resizable item callback.\n */\n controlRef?: RefObject<CarouselControl | null>\n /**\n * The initial index of the carousel slide.\n *\n * @default 0\n */\n defaultIndex?: number\n /**\n * The number for the autoplay interval of the carousel.\n *\n * @default 4000\n */\n delay?: number\n /**\n * If `true`, momentum scrolling will be enabled.\n *\n * @default false\n */\n dragFree?: boolean\n /**\n * If `true`, carousel can be scrolled with mouse and touch interactions.\n *\n * @default true\n */\n draggable?: boolean\n /**\n * Set scroll duration when triggered by any of the API methods.\n * Higher numbers enables slower scrolling.\n * Drag interactions are not affected because duration is then determined by the drag force.\n *\n * @default 25\n */\n duration?: number\n /**\n * The index of the carousel slide.\n */\n index?: number\n /**\n * Choose a fraction representing the percentage portion of a slide that needs to be visible in order to be considered in view.\n *\n * @default 0\n */\n inViewThreshold?: CarouselInViewThreshold\n /**\n * If `true`, infinite looping.\n * Automatically falls back to false if slide content isn't enough to loop.\n *\n * @default true\n */\n loop?: boolean\n /**\n * The orientation of the carousel.\n *\n * @default 'horizontal'\n */\n orientation?: Orientation\n /**\n * Embla plugins to use.\n */\n plugins?: CarouselPlugin[]\n /**\n * If `true`, allow the carousel to skip scroll snaps if it's dragged vigorously.\n * Note that this option will be ignored if the dragFree option is set to true.\n *\n * @default false\n */\n skipSnaps?: boolean\n /**\n * The number of slides that should be scrolled with next or previous buttons.\n *\n * @default 1\n */\n slidesToScroll?: number\n /**\n * If `true`, autoplay will pause when the mouse entries over.\n *\n * @default true\n */\n stopMouseEnterAutoplay?: boolean\n /**\n * Enables for scrolling the carousel with mouse and touch interactions.\n * Set this to `false` to disable drag events or pass a custom callback to add your own drag logic.\n *\n * @default true\n */\n watchDrag?: CarouselWatchDrag\n /**\n * Embla automatically watches the container and slides for size changes and runs `reInit` when any size has changed.\n * Set this to `false` to disable this behaviour or pass a custom callback to add your own resize logic.\n *\n * @default true\n */\n watchResize?: CarouselWatchResize\n /**\n * Embla automatically watches the container for added and/or removed slides and runs `reInit` if needed.\n * Set this to `false` to disable this behaviour or pass a custom callback to add your own slides changed logic.\n *\n * @default true\n */\n watchSlides?: CarouselWatchSlides\n /**\n * The callback invoked when carousel slide selected.\n */\n onChange?: (index: number) => void\n /**\n * A callback that return the current scroll amount when the carousel is scrolled.\n */\n onScrollProgress?: (progress: number) => void\n}\n\nexport const useCarousel = ({\n id,\n align = \"center\",\n autoplay = false,\n containScroll = false,\n controlRef,\n defaultIndex = 0,\n delay = 4000,\n dragFree = false,\n draggable = true,\n duration = 25,\n index: indexProp,\n inViewThreshold = 0,\n loop = true,\n orientation = \"horizontal\",\n plugins = [],\n skipSnaps = false,\n slidesToScroll = 1,\n stopMouseEnterAutoplay = true,\n watchDrag = draggable,\n watchResize: watchResizeProp = true,\n watchSlides = true,\n onChange,\n onScrollProgress,\n ...rest\n}: UseCarouselProps = {}) => {\n const { t } = useI18n(\"carousel\")\n const [index, setIndex] = useControllableState({\n defaultValue: defaultIndex,\n value: indexProp,\n onChange,\n })\n const [rootId, listId] = useIds()\n const [hover, { off: onMouseLeave, on: onMouseEnter }] = useBoolean()\n const timeoutId = useRef<NodeJS.Timeout | null>(null)\n const indicatorMapRef = useRef<Map<number, HTMLButtonElement | null>>(\n new Map(),\n )\n const listRef = useRef<HTMLDivElement>(null)\n const horizontal = orientation === \"horizontal\"\n const axis = horizontal ? \"x\" : \"y\"\n const [snapCount, setSnapCount] = useState(0)\n const [total, setTotal] = useState(0)\n const watchResize = useCallback<Extract<CarouselWatchResize, Function>>(\n (methods, entries) => {\n const result = isFunction(watchResizeProp)\n ? watchResizeProp(methods, entries)\n : true\n const snapCount = methods.scrollSnapList().length\n const total = methods.slideNodes().length\n\n setSnapCount(snapCount)\n setTotal(total)\n\n return result\n },\n [watchResizeProp],\n )\n const [carouselRef, carousel] = useEmblaCarousel(\n {\n align,\n axis,\n container: listRef.current,\n containScroll,\n dragFree,\n duration,\n inViewThreshold,\n loop,\n skipSnaps,\n slidesToScroll,\n startIndex: defaultIndex,\n watchDrag,\n watchResize,\n watchSlides,\n },\n plugins,\n )\n\n id ??= rootId\n\n const onInit = useCallback((methods: CarouselControl) => {\n const snapCount = methods.scrollSnapList().length\n const total = methods.slideNodes().length\n\n setSnapCount(snapCount)\n setTotal(total)\n }, [])\n\n const onScroll = useCallback(() => {\n if (!carousel) return\n\n const progress = Math.round(\n Math.max(0, Math.min(1, carousel.scrollProgress())) * 100,\n )\n\n onScrollProgress?.(progress)\n }, [carousel, onScrollProgress])\n\n const onSelect = useCallback(() => {\n if (!carousel) return\n\n const index = carousel.selectedScrollSnap()\n\n setIndex(index)\n }, [carousel, setIndex])\n\n const onFocusIndicator = useCallback(\n (index: number) => {\n const el = indicatorMapRef.current.get(index)\n\n el?.focus()\n carousel?.scrollTo(index)\n },\n [carousel],\n )\n\n const onKeyDown = useCallback(\n (index: number) => (ev: KeyboardEvent<HTMLButtonElement>) => {\n const lastIndex = snapCount - 1\n\n runKeyAction(ev, {\n ArrowDown: () => {\n if (horizontal) return\n\n index = index === lastIndex ? 0 : index + 1\n\n onFocusIndicator(index)\n },\n ArrowLeft: () => {\n if (!horizontal) return\n\n index = index === 0 ? lastIndex : index - 1\n\n onFocusIndicator(index)\n },\n ArrowRight: () => {\n if (!horizontal) return\n\n index = index === lastIndex ? 0 : index + 1\n\n onFocusIndicator(index)\n },\n ArrowUp: () => {\n if (horizontal) return\n\n index = index === 0 ? lastIndex : index - 1\n\n onFocusIndicator(index)\n },\n End: () => {\n onFocusIndicator(lastIndex)\n },\n Home: () => {\n onFocusIndicator(0)\n },\n })\n },\n [snapCount, horizontal, onFocusIndicator],\n )\n\n assignRef(controlRef, carousel)\n\n useEffect(() => {\n if (carousel) {\n carousel.on(\"reInit\", onInit)\n carousel.on(\"select\", onSelect)\n carousel.on(\"scroll\", onScroll)\n\n onScroll()\n\n return () => {\n carousel.off(\"reInit\", onInit)\n carousel.off(\"select\", onSelect)\n carousel.off(\"scroll\", onScroll)\n }\n }\n }, [carousel, onInit, onScroll, onSelect])\n\n useEffect(() => {\n const stop = hover && stopMouseEnterAutoplay\n const last = !carousel?.canScrollNext()\n\n if (carousel && autoplay && !stop && !last) {\n timeoutId.current = setInterval(() => {\n carousel.scrollNext()\n }, delay)\n } else {\n if (timeoutId.current) clearInterval(timeoutId.current)\n\n timeoutId.current = null\n }\n\n return () => {\n if (timeoutId.current) clearInterval(timeoutId.current)\n }\n }, [autoplay, carousel, delay, hover, stopMouseEnterAutoplay])\n\n useUpdateEffect(() => {\n if (!carousel) return\n\n if (indexProp === undefined) return\n\n carousel.scrollTo(indexProp)\n }, [indexProp])\n\n useUpdateEffect(() => {\n if (!carousel) return\n\n carousel.reInit()\n }, [\n carousel,\n total,\n align,\n axis,\n containScroll,\n dragFree,\n duration,\n inViewThreshold,\n loop,\n skipSnaps,\n slidesToScroll,\n ])\n\n const getRootProps: PropGetter<\"section\"> = useCallback(\n ({ ref, ...props } = {}) =>\n mergeProps(\n {\n id,\n \"aria-roledescription\": \"carousel\",\n \"data-orientation\": orientation,\n },\n rest,\n {\n ref,\n onMouseEnter,\n onMouseLeave,\n },\n props,\n )(),\n [id, onMouseEnter, onMouseLeave, rest, orientation],\n )\n\n const getListProps: PropGetter = useCallback(\n ({ ref, ...props } = {}) => ({\n id: listId,\n \"aria-live\": autoplay ? \"off\" : \"polite\",\n \"data-orientation\": orientation,\n ...props,\n ref: mergeRefs(ref, listRef, carouselRef),\n }),\n [autoplay, listId, orientation, carouselRef],\n )\n\n const getItemProps: RequiredPropGetter<\"div\", { index: number }> =\n useCallback(\n ({ index: indexProp, ...props }) => {\n const page = indexProp + 1\n const selected = index === indexProp\n\n return {\n id: `${listId}-${indexProp}`,\n \"aria-label\": t(\"{page} of {total}\", { page, total }),\n \"aria-roledescription\": \"slide\",\n \"data-index\": indexProp.toString(),\n \"data-orientation\": orientation,\n \"data-selected\": dataAttr(selected),\n role: \"tabpanel\",\n ...props,\n }\n },\n [index, listId, total, orientation, t],\n )\n\n const getPrevTriggerProps: PropGetter<\"button\"> = useCallback(\n (props = {}) => ({\n \"aria-controls\": listId,\n \"aria-label\": t(\"Go to previous slide\"),\n \"data-orientation\": orientation,\n disabled: !carousel?.canScrollPrev(),\n ...props,\n onClick: handlerAll(props.onClick, () => carousel?.scrollPrev()),\n }),\n [carousel, listId, orientation, t],\n )\n\n const getNextTriggerProps: PropGetter<\"button\"> = useCallback(\n (props = {}) => ({\n \"aria-controls\": listId,\n \"aria-label\": t(\"Go to next slide\"),\n \"data-orientation\": orientation,\n disabled: !carousel?.canScrollNext(),\n ...props,\n onClick: handlerAll(props.onClick, () => carousel?.scrollNext()),\n }),\n [carousel, listId, orientation, t],\n )\n\n const getIndicatorsProps: PropGetter = useCallback(\n (props = {}) => ({\n \"aria-label\": t(\"Slides\"),\n \"aria-orientation\": orientation,\n role: \"tablist\",\n ...props,\n }),\n [orientation, t],\n )\n\n const getIndicatorProps: RequiredPropGetter<\"button\", { index: number }> =\n useCallback(\n ({ ref, index: indexProp, ...props }) => {\n const page = indexProp + 1\n const selected = index === indexProp\n\n return {\n type: \"button\" as const,\n \"aria-controls\": `${listId}-${indexProp}`,\n \"aria-label\": t(\"Go to {page} slide\", { page }),\n \"aria-selected\": selected,\n \"data-index\": indexProp.toString(),\n \"data-orientation\": orientation,\n \"data-selected\": dataAttr(selected),\n role: \"tab\",\n tabIndex: selected ? 0 : -1,\n ...props,\n ref: mergeRefs(ref, (node) => {\n indicatorMapRef.current.set(indexProp, node)\n }),\n onClick: handlerAll(props.onClick, () =>\n carousel?.scrollTo(indexProp),\n ),\n onKeyDown: handlerAll(props.onKeyDown, onKeyDown(indexProp)),\n }\n },\n [index, listId, t, orientation, onKeyDown, carousel],\n )\n\n return {\n carousel,\n index,\n setIndex,\n snapCount,\n total,\n getIndicatorProps,\n getIndicatorsProps,\n getItemProps,\n getListProps,\n getNextTriggerProps,\n getPrevTriggerProps,\n getRootProps,\n }\n}\n\nexport type UseCarouselReturn = ReturnType<typeof useCarousel>\n"],"mappings":";;;;;;;;;;;;;;;;;AA+CA,MAAM,CAAC,iBAAiB,sBAAsBA,gBAA+B,EAC3E,MAAM,mBACP,CAAC;AA4IF,MAAa,eAAe,EAC1B,IACA,QAAQ,UACR,WAAW,OACX,gBAAgB,OAChB,YACA,eAAe,GACf,QAAQ,KACR,WAAW,OACX,YAAY,MACZ,WAAW,IACX,OAAO,WACP,kBAAkB,GAClB,OAAO,MACP,cAAc,cACd,UAAU,EAAE,EACZ,YAAY,OACZ,iBAAiB,GACjB,yBAAyB,MACzB,YAAY,WACZ,aAAa,kBAAkB,MAC/B,cAAc,MACd,UACA,kBACA,GAAG,SACiB,EAAE,KAAK;CAC3B,MAAM,EAAE,MAAM,QAAQ,WAAW;CACjC,MAAM,CAAC,OAAO,YAAY,qBAAqB;EAC7C,cAAc;EACd,OAAO;EACP;EACD,CAAC;CACF,MAAM,CAAC,QAAQ,UAAU,QAAQ;CACjC,MAAM,CAAC,OAAO,EAAE,KAAK,cAAc,IAAI,kBAAkB,YAAY;CACrE,MAAM,YAAY,OAA8B,KAAK;CACrD,MAAM,kBAAkB,uBACtB,IAAI,KAAK,CACV;CACD,MAAM,UAAU,OAAuB,KAAK;CAC5C,MAAM,aAAa,gBAAgB;CACnC,MAAM,OAAO,aAAa,MAAM;CAChC,MAAM,CAAC,WAAW,gBAAgB,SAAS,EAAE;CAC7C,MAAM,CAAC,OAAO,YAAY,SAAS,EAAE;CACrC,MAAM,cAAc,aACjB,SAAS,YAAY;EACpB,MAAM,uCAAoB,gBAAgB,GACtC,gBAAgB,SAAS,QAAQ,GACjC;EACJ,MAAMC,cAAY,QAAQ,gBAAgB,CAAC;EAC3C,MAAMC,UAAQ,QAAQ,YAA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,GAAG;EACJ,GACD,CAAC,aAAa,EAAE,CACjB;AA+BD,QAAO;EACL;EACA;EACA;EACA;EACA;EACA,mBAlCA,aACG,EAAE,KAAK,OAAOH,aAAW,GAAG,YAAY;GACvC,MAAM,OAAOA,cAAY;GACzB,MAAM,WAAW,UAAUA;AAE3B,UAAO;IACL,MAAM;IACN,iBAAiB,GAAG,OAAO,GAAGA;IAC9B,cAAc,EAAE,sBAAsB,EAAE,MAAM,CAAC;IAC/C,iBAAiB;IACjB,cAAcA,YAAU,UAAU;IAClC,oBAAoB;IACpB,6CAA0B,SAAS;IACnC,MAAM;IACN,UAAU,WAAW,IAAI;IACzB,GAAG;IACH,KAAK,UAAU,MAAM,SAAS;AAC5B,qBAAgB,QAAQ,IAAIA,aAAW,KAAK;MAC5C;IACF,uCAAoB,MAAM,eACxB,UAAU,SAASA,YAAU,CAC9B;IACD,yCAAsB,MAAM,WAAW,UAAUA,YAAU,CAAC;IAC7D;KAEH;GAAC;GAAO;GAAQ;GAAG;GAAa;GAAW;GAAS,CACrD;EASD;EACA;EACA;EACA;EACA;EACA;EACD"}
@@ -5,6 +5,8 @@ import { runKeyAction, useIds } from "../../utils/dom.js";
5
5
  import { useSafeLayoutEffect } from "../../utils/effect.js";
6
6
  import { assignRef, mergeRefs } from "../../utils/ref.js";
7
7
  import { utils_exports } from "../../utils/index.js";
8
+ import { mergeProps } from "../../core/components/props.js";
9
+ import "../../core/index.js";
8
10
  import { useControllableState } from "../../hooks/use-controllable-state/index.js";
9
11
  import { createDescendants } from "../../hooks/use-descendants/index.js";
10
12
  import { useDisclosure } from "../../hooks/use-disclosure/use-disclosure.js";
@@ -100,13 +102,11 @@ const useTree = ({ checkable = false, checkedValue: checkedValueProp, children,
100
102
  expandedValue,
101
103
  multiple,
102
104
  selectedValue,
103
- getRootProps: useCallback((props) => ({
105
+ getRootProps: useCallback((props) => mergeProps({
104
106
  "aria-multiselectable": (0, utils_exports.ariaAttr)(multiple || checkable),
105
107
  children,
106
- role: "tree",
107
- ...rest,
108
- ...props
109
- }), [
108
+ role: "tree"
109
+ }, rest, props)(), [
110
110
  multiple,
111
111
  checkable,
112
112
  rest,