@yamada-ui/react 2.2.0-next-20260409094221 → 2.2.0

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 (247) hide show
  1. package/dist/cjs/components/action-bar/use-action-bar.cjs +2 -1
  2. package/dist/cjs/components/action-bar/use-action-bar.cjs.map +1 -1
  3. package/dist/cjs/components/editable/use-editable.cjs +8 -4
  4. package/dist/cjs/components/editable/use-editable.cjs.map +1 -1
  5. package/dist/cjs/components/modal/modal.cjs +3 -1
  6. package/dist/cjs/components/modal/modal.cjs.map +1 -1
  7. package/dist/cjs/components/modal/use-modal.cjs +4 -2
  8. package/dist/cjs/components/modal/use-modal.cjs.map +1 -1
  9. package/dist/cjs/components/sidebar/sidebar.cjs +5 -3
  10. package/dist/cjs/components/sidebar/sidebar.cjs.map +1 -1
  11. package/dist/cjs/components/sidebar/use-sidebar.cjs +8 -3
  12. package/dist/cjs/components/sidebar/use-sidebar.cjs.map +1 -1
  13. package/dist/cjs/components/tree/tree.cjs +3 -2
  14. package/dist/cjs/components/tree/tree.cjs.map +1 -1
  15. package/dist/cjs/components/tree/tree.style.cjs +4 -1
  16. package/dist/cjs/components/tree/tree.style.cjs.map +1 -1
  17. package/dist/cjs/components/tree/use-tree.cjs +20 -6
  18. package/dist/cjs/components/tree/use-tree.cjs.map +1 -1
  19. package/dist/esm/components/action-bar/use-action-bar.js +2 -1
  20. package/dist/esm/components/action-bar/use-action-bar.js.map +1 -1
  21. package/dist/esm/components/editable/use-editable.js +8 -4
  22. package/dist/esm/components/editable/use-editable.js.map +1 -1
  23. package/dist/esm/components/modal/modal.js +3 -1
  24. package/dist/esm/components/modal/modal.js.map +1 -1
  25. package/dist/esm/components/modal/use-modal.js +4 -2
  26. package/dist/esm/components/modal/use-modal.js.map +1 -1
  27. package/dist/esm/components/sidebar/sidebar.js +5 -3
  28. package/dist/esm/components/sidebar/sidebar.js.map +1 -1
  29. package/dist/esm/components/sidebar/use-sidebar.js +9 -4
  30. package/dist/esm/components/sidebar/use-sidebar.js.map +1 -1
  31. package/dist/esm/components/tree/tree.js +3 -2
  32. package/dist/esm/components/tree/tree.js.map +1 -1
  33. package/dist/esm/components/tree/tree.style.js +4 -1
  34. package/dist/esm/components/tree/tree.style.js.map +1 -1
  35. package/dist/esm/components/tree/use-tree.js +21 -7
  36. package/dist/esm/components/tree/use-tree.js.map +1 -1
  37. package/dist/types/components/accordion/accordion.d.ts +2 -2
  38. package/dist/types/components/accordion/use-accordion.d.ts +11 -11
  39. package/dist/types/components/action-bar/action-bar.d.ts +2 -2
  40. package/dist/types/components/airy/airy.d.ts +2 -2
  41. package/dist/types/components/alert/alert.d.ts +2 -2
  42. package/dist/types/components/alert/alert.style.d.ts +1 -1
  43. package/dist/types/components/alpha-slider/alpha-slider.d.ts +2 -2
  44. package/dist/types/components/aspect-ratio/aspect-ratio.d.ts +2 -2
  45. package/dist/types/components/autocomplete/autocomplete.d.ts +2 -2
  46. package/dist/types/components/autocomplete/autocomplete.style.d.ts +1 -1
  47. package/dist/types/components/autocomplete/use-autocomplete.d.ts +5 -5
  48. package/dist/types/components/avatar/avatar.d.ts +5 -5
  49. package/dist/types/components/avatar/avatar.style.d.ts +1 -1
  50. package/dist/types/components/avatar/use-avatar-group.d.ts +2 -2
  51. package/dist/types/components/badge/badge.d.ts +2 -2
  52. package/dist/types/components/bleed/bleed.d.ts +2 -2
  53. package/dist/types/components/blockquote/blockquote.d.ts +2 -2
  54. package/dist/types/components/breadcrumb/breadcrumb.d.ts +2 -2
  55. package/dist/types/components/breadcrumb/use-breadcrumb.d.ts +2 -2
  56. package/dist/types/components/button/button.d.ts +2 -2
  57. package/dist/types/components/button/icon-button.d.ts +2 -2
  58. package/dist/types/components/calendar/calendar.d.ts +2 -2
  59. package/dist/types/components/calendar/calendar.style.d.ts +2 -2
  60. package/dist/types/components/calendar/use-calendar.d.ts +8 -8
  61. package/dist/types/components/card/card.d.ts +2 -2
  62. package/dist/types/components/carousel/carousel.d.ts +2 -2
  63. package/dist/types/components/carousel/carousel.style.d.ts +2 -2
  64. package/dist/types/components/carousel/use-carousel.d.ts +3 -3
  65. package/dist/types/components/center/center.d.ts +2 -2
  66. package/dist/types/components/chart/chart.d.ts +5 -5
  67. package/dist/types/components/chart/pie-chart.d.ts +2 -2
  68. package/dist/types/components/chart/radar-chart.d.ts +2 -2
  69. package/dist/types/components/chart/radial-chart.d.ts +2 -2
  70. package/dist/types/components/chart/use-chart.d.ts +2 -2
  71. package/dist/types/components/checkbox/checkbox.d.ts +4 -4
  72. package/dist/types/components/checkbox/use-checkbox-group.d.ts +2 -2
  73. package/dist/types/components/checkbox-card/checkbox-card.d.ts +5 -5
  74. package/dist/types/components/checkbox-card/checkbox-card.style.d.ts +1 -1
  75. package/dist/types/components/circle-progress/circle-progress.d.ts +2 -2
  76. package/dist/types/components/close-button/close-button.d.ts +2 -2
  77. package/dist/types/components/code/code.d.ts +2 -2
  78. package/dist/types/components/collapse/collapse.d.ts +2 -2
  79. package/dist/types/components/color-picker/color-picker.d.ts +2 -2
  80. package/dist/types/components/color-picker/color-picker.style.d.ts +1 -1
  81. package/dist/types/components/color-picker/use-color-picker.d.ts +2 -2
  82. package/dist/types/components/color-selector/color-selector.d.ts +2 -2
  83. package/dist/types/components/color-selector/color-selector.style.d.ts +2 -2
  84. package/dist/types/components/color-selector/use-color-selector.d.ts +3 -3
  85. package/dist/types/components/color-swatch/color-swatch.d.ts +2 -2
  86. package/dist/types/components/container/container.d.ts +2 -2
  87. package/dist/types/components/data-list/data-list.d.ts +2 -2
  88. package/dist/types/components/date-picker/date-picker.d.ts +2 -2
  89. package/dist/types/components/date-picker/use-date-picker.d.ts +4 -4
  90. package/dist/types/components/drawer/drawer.d.ts +2 -2
  91. package/dist/types/components/drawer/drawer.style.d.ts +2 -2
  92. package/dist/types/components/dropzone/dropzone.d.ts +5 -5
  93. package/dist/types/components/dropzone/dropzone.style.d.ts +1 -1
  94. package/dist/types/components/editable/editable.d.ts +4 -4
  95. package/dist/types/components/editable/use-editable.d.ts +2 -2
  96. package/dist/types/components/em/em.d.ts +2 -2
  97. package/dist/types/components/empty-state/empty-state.d.ts +2 -2
  98. package/dist/types/components/empty-state/empty-state.style.d.ts +2 -2
  99. package/dist/types/components/fade/fade.d.ts +2 -2
  100. package/dist/types/components/field/field.d.ts +3 -3
  101. package/dist/types/components/field/field.style.d.ts +2 -2
  102. package/dist/types/components/field/use-field-props.d.ts +4 -4
  103. package/dist/types/components/fieldset/fieldset.d.ts +3 -3
  104. package/dist/types/components/fieldset/fieldset.style.d.ts +1 -1
  105. package/dist/types/components/file-button/file-button.d.ts +2 -2
  106. package/dist/types/components/file-button/use-file-button.d.ts +18 -18
  107. package/dist/types/components/file-input/file-input.d.ts +2 -2
  108. package/dist/types/components/file-input/file-input.style.d.ts +1 -1
  109. package/dist/types/components/file-input/use-file-input.d.ts +17 -17
  110. package/dist/types/components/flex/flex.d.ts +2 -2
  111. package/dist/types/components/flip/flip.d.ts +4 -4
  112. package/dist/types/components/float/float.d.ts +2 -2
  113. package/dist/types/components/form/form.d.ts +3 -3
  114. package/dist/types/components/format/format-byte.d.ts +4 -4
  115. package/dist/types/components/format/format-date-time.d.ts +4 -4
  116. package/dist/types/components/format/format-number.d.ts +2 -2
  117. package/dist/types/components/grid/grid-item.d.ts +2 -2
  118. package/dist/types/components/grid/grid.d.ts +2 -2
  119. package/dist/types/components/group/group.d.ts +2 -2
  120. package/dist/types/components/group/use-group.d.ts +2 -2
  121. package/dist/types/components/heading/heading.d.ts +2 -2
  122. package/dist/types/components/hue-slider/hue-slider.d.ts +3 -3
  123. package/dist/types/components/icon/icon.d.ts +5 -5
  124. package/dist/types/components/image/image.d.ts +2 -2
  125. package/dist/types/components/indicator/indicator.d.ts +4 -4
  126. package/dist/types/components/infinite-scroll-area/infinite-scroll-area.d.ts +2 -2
  127. package/dist/types/components/input/input-addon.d.ts +2 -2
  128. package/dist/types/components/input/input-element.d.ts +2 -2
  129. package/dist/types/components/input/input.d.ts +2 -2
  130. package/dist/types/components/kbd/kbd.d.ts +2 -2
  131. package/dist/types/components/link/link.d.ts +2 -2
  132. package/dist/types/components/link-box/link-box.d.ts +2 -2
  133. package/dist/types/components/list/list.d.ts +2 -2
  134. package/dist/types/components/loading/loading-provider.d.ts +2 -2
  135. package/dist/types/components/loading/loading.d.ts +3 -3
  136. package/dist/types/components/mark/mark.d.ts +2 -2
  137. package/dist/types/components/menu/menu.d.ts +2 -2
  138. package/dist/types/components/menu/menu.style.d.ts +2 -2
  139. package/dist/types/components/menu/use-menu.d.ts +11 -11
  140. package/dist/types/components/modal/modal.d.ts +2 -2
  141. package/dist/types/components/modal/modal.style.d.ts +2 -2
  142. package/dist/types/components/native-accordion/native-accordion.d.ts +2 -2
  143. package/dist/types/components/native-accordion/use-native-accordion.d.ts +2 -2
  144. package/dist/types/components/native-popover/native-popover.d.ts +2 -2
  145. package/dist/types/components/native-select/native-select.d.ts +2 -2
  146. package/dist/types/components/native-table/native-table.d.ts +4 -4
  147. package/dist/types/components/notice/notice.style.d.ts +1 -1
  148. package/dist/types/components/number-input/number-input.d.ts +2 -2
  149. package/dist/types/components/pagination/pagination.d.ts +2 -2
  150. package/dist/types/components/pagination/use-pagination.d.ts +2 -2
  151. package/dist/types/components/password-input/password-input.d.ts +2 -2
  152. package/dist/types/components/password-input/strength-meter.d.ts +2 -2
  153. package/dist/types/components/password-input/use-password-input.d.ts +2 -2
  154. package/dist/types/components/pin-input/pin-input.d.ts +2 -2
  155. package/dist/types/components/pin-input/use-pin-input.d.ts +7 -7
  156. package/dist/types/components/popover/popover.d.ts +2 -2
  157. package/dist/types/components/progress/progress.d.ts +2 -2
  158. package/dist/types/components/progress/use-progress.d.ts +706 -706
  159. package/dist/types/components/qr-code/qr-code.d.ts +2 -2
  160. package/dist/types/components/radio/radio.d.ts +4 -4
  161. package/dist/types/components/radio/use-radio-group.d.ts +2 -2
  162. package/dist/types/components/radio-card/radio-card.d.ts +5 -5
  163. package/dist/types/components/radio-card/radio-card.style.d.ts +1 -1
  164. package/dist/types/components/rating/use-rating.d.ts +7 -7
  165. package/dist/types/components/reorder/reorder.d.ts +2 -2
  166. package/dist/types/components/reorder/reorder.style.d.ts +1 -1
  167. package/dist/types/components/reorder/use-reorder.d.ts +3 -3
  168. package/dist/types/components/resizable/resizable.d.ts +2 -2
  169. package/dist/types/components/resizable/resizable.style.d.ts +2 -2
  170. package/dist/types/components/resizable/use-resizable.d.ts +2 -2
  171. package/dist/types/components/ripple/ripple.d.ts +2 -2
  172. package/dist/types/components/ripple/use-ripple.d.ts +2 -2
  173. package/dist/types/components/rotate/rotate.d.ts +2 -2
  174. package/dist/types/components/saturation-slider/saturation-slider.d.ts +2 -2
  175. package/dist/types/components/saturation-slider/use-saturation-slider.d.ts +2 -2
  176. package/dist/types/components/scroll-area/scroll-area.d.ts +2 -2
  177. package/dist/types/components/segmented-control/segmented-control.d.ts +2 -2
  178. package/dist/types/components/segmented-control/segmented-control.style.d.ts +2 -2
  179. package/dist/types/components/segmented-control/use-segmented-control.d.ts +9 -9
  180. package/dist/types/components/select/select.d.ts +2 -2
  181. package/dist/types/components/select/select.style.d.ts +1 -1
  182. package/dist/types/components/select/use-select.d.ts +4 -4
  183. package/dist/types/components/separator/separator.d.ts +2 -2
  184. package/dist/types/components/sidebar/sidebar.d.ts +2 -2
  185. package/dist/types/components/sidebar/use-sidebar.d.ts +9 -9
  186. package/dist/types/components/simple-grid/simple-grid.d.ts +2 -2
  187. package/dist/types/components/skeleton/skeleton.d.ts +2 -2
  188. package/dist/types/components/slide/slide.d.ts +2 -2
  189. package/dist/types/components/slide-fade/slide-fade.d.ts +2 -2
  190. package/dist/types/components/slider/slider.d.ts +2 -2
  191. package/dist/types/components/slider/use-slider.d.ts +2 -2
  192. package/dist/types/components/stack/h-stack.d.ts +2 -2
  193. package/dist/types/components/stack/stack.d.ts +2 -2
  194. package/dist/types/components/stack/v-stack.d.ts +2 -2
  195. package/dist/types/components/stack/z-stack.d.ts +2 -2
  196. package/dist/types/components/stat/stat.d.ts +2 -2
  197. package/dist/types/components/stat/stat.style.d.ts +2 -2
  198. package/dist/types/components/status/status.d.ts +2 -2
  199. package/dist/types/components/steps/steps.d.ts +2 -2
  200. package/dist/types/components/steps/steps.style.d.ts +1 -1
  201. package/dist/types/components/steps/use-steps.d.ts +10 -10
  202. package/dist/types/components/switch/switch.d.ts +2 -2
  203. package/dist/types/components/table/table.d.ts +2 -2
  204. package/dist/types/components/tabs/tabs.d.ts +2 -2
  205. package/dist/types/components/tabs/tabs.style.d.ts +1 -1
  206. package/dist/types/components/tabs/use-tabs.d.ts +16 -16
  207. package/dist/types/components/tag/tag.d.ts +2 -2
  208. package/dist/types/components/tag/tag.style.d.ts +1 -1
  209. package/dist/types/components/text/text.d.ts +2 -2
  210. package/dist/types/components/textarea/textarea.d.ts +2 -2
  211. package/dist/types/components/textarea/use-autosize.d.ts +2 -2
  212. package/dist/types/components/timeline/timeline.d.ts +5 -5
  213. package/dist/types/components/timeline/timeline.style.d.ts +1 -1
  214. package/dist/types/components/toggle/toggle.d.ts +5 -5
  215. package/dist/types/components/toggle/use-toggle-group.d.ts +2 -2
  216. package/dist/types/components/toggle/use-toggle.d.ts +2 -2
  217. package/dist/types/components/tooltip/tooltip.d.ts +2 -2
  218. package/dist/types/components/tree/tree.d.ts +3 -3
  219. package/dist/types/components/tree/tree.style.d.ts +1 -1
  220. package/dist/types/components/tree/use-tree.d.ts +190 -184
  221. package/dist/types/components/visually-hidden/visually-hidden.d.ts +2 -2
  222. package/dist/types/components/wrap/wrap.d.ts +2 -2
  223. package/dist/types/core/components/create-component.d.ts +7 -8
  224. package/dist/types/core/components/use-component-style.d.ts +0 -1
  225. package/dist/types/core/components/utils.d.ts +0 -1
  226. package/dist/types/core/constant.d.ts +0 -1
  227. package/dist/types/core/css/calc.d.ts +0 -1
  228. package/dist/types/core/css/config.d.ts +0 -1
  229. package/dist/types/core/css/css.d.ts +0 -1
  230. package/dist/types/core/css/index.types.d.ts +0 -1
  231. package/dist/types/core/css/styles.d.ts +0 -1
  232. package/dist/types/core/css/token.d.ts +0 -1
  233. package/dist/types/core/css/use-css.d.ts +0 -1
  234. package/dist/types/core/css/utils.d.ts +0 -1
  235. package/dist/types/core/generated-theme-tokens.types.d.ts +0 -1
  236. package/dist/types/core/index.d.ts +0 -1
  237. package/dist/types/core/system/color-mode-provider.d.ts +2 -2
  238. package/dist/types/core/system/storage-script.d.ts +3 -3
  239. package/dist/types/core/system/styled.d.ts +2 -2
  240. package/dist/types/core/system/system-provider.d.ts +2 -2
  241. package/dist/types/core/system/var.d.ts +0 -1
  242. package/dist/types/hooks/use-breakpoint/use-breakpoint-state.d.ts +2 -2
  243. package/dist/types/hooks/use-clickable/index.d.ts +2 -2
  244. package/dist/types/providers/i18n-provider/i18n-provider.d.ts +3 -3
  245. package/dist/types/providers/ui-provider/ui-provider.d.ts +2 -2
  246. package/dist/types/utils/children.d.ts +2 -2
  247. package/package.json +1 -1
@@ -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 useUpdateEffect,\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}\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(({ value }) =>\n match(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 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 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 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().then(() => {\n onOpen()\n onExpandedChange(value)\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, 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 value,\n ],\n )\n\n const onItemClick = useCallback(\n (ev: MouseEvent<HTMLLIElement>) => {\n if (disabled || !value) return\n\n if (group && !groupLoading)\n if (!ev.ctrlKey && !ev.metaKey && !ev.shiftKey) onGroupToggle()\n\n ev.stopPropagation()\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 useUpdateEffect(() => {\n if (defaultExpanded) {\n if (async && !initialAsyncRef.current) {\n initialAsyncRef.current = true\n\n onGroupChildren().then(() => {\n onOpen()\n })\n } else {\n onOpen()\n }\n } else {\n onClose()\n }\n }, [defaultExpanded])\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 indeterminate,\n tabIndex: -1,\n ...props,\n onChange: handlerAll(props.onChange, onCheckboxChange),\n }),\n [checkboxId, labelId, selected, checked, indeterminate, onCheckboxChange],\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,yB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GAAO,GAC1C,CAAC,QAAQ,CACV;EAqBC;EACA;EACA;EACD"}
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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W,UAAU;EAClD,GACD;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACD,CACF;CAED,MAAMC,4CACH,QAAQ,EAAE,KAAK,aAAa;EAAE,iBAAiB;EAAW,GAAG;EAAO,CAAC,EACtE,CAAC,cAAc,UAAU,CAC1B;CAED,MAAMC,4CACH,WAAW;EACV,iEAA0B,SAAS;EACnC,iBAAiB;EACjB,eAAe;EACf,iEAA0B,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"}
@@ -24,8 +24,9 @@ const useActionBar = ({ closeOnEsc = true, defaultOpen, open: openProp, onClose:
24
24
  const { t } = useI18n("actionBar");
25
25
  const onKeyDown = useCallback((ev) => {
26
26
  if (ev.key !== "Escape") return;
27
+ if (!closeOnEsc) return;
27
28
  ev.stopPropagation();
28
- if (closeOnEsc) onClose();
29
+ onClose();
29
30
  }, [closeOnEsc, onClose]);
30
31
  useEventListener(getDocument(), "keydown", onKeyDown);
31
32
  const getRootProps = useCallback((props = {}) => ({
@@ -1 +1 @@
1
- {"version":3,"file":"use-action-bar.js","names":["getRootProps: PropGetter","getOpenTriggerProps: PropGetter<\"button\">"],"sources":["../../../../src/components/action-bar/use-action-bar.ts"],"sourcesContent":["\"use client\"\n\nimport type { HTMLProps, PropGetter } from \"../../core\"\nimport { useCallback } from \"react\"\nimport { useEnvironment } from \"../../core\"\nimport {\n useDisclosure,\n type UseDisclosureProps,\n} from \"../../hooks/use-disclosure\"\nimport { useEventListener } from \"../../hooks/use-event-listener\"\nimport { useI18n } from \"../../providers/i18n-provider\"\nimport { handlerAll, useIds } from \"../../utils\"\n\nexport interface UseActionBarProps\n extends HTMLProps, Omit<UseDisclosureProps, \"timing\"> {\n /**\n * If `true`, the action bar will close when the `Esc` key is pressed.\n *\n * @default true\n */\n closeOnEsc?: boolean\n}\n\nexport const useActionBar = ({\n closeOnEsc = true,\n defaultOpen,\n open: openProp,\n onClose: onCloseProp,\n onOpen: onOpenProp,\n ...rest\n}: UseActionBarProps = {}) => {\n const { getDocument } = useEnvironment()\n const { open, onClose, onOpen } = useDisclosure({\n defaultOpen,\n open: openProp,\n onClose: onCloseProp,\n onOpen: onOpenProp,\n })\n const [contentId] = useIds()\n const { t } = useI18n(\"actionBar\")\n\n const onKeyDown = useCallback(\n (ev: KeyboardEvent) => {\n if (ev.key !== \"Escape\") return\n\n ev.stopPropagation()\n\n if (closeOnEsc) onClose()\n },\n [closeOnEsc, onClose],\n )\n\n useEventListener(getDocument(), \"keydown\", onKeyDown)\n\n const getRootProps: PropGetter = useCallback(\n (props = {}) => ({ ...rest, ...props }),\n [rest],\n )\n\n const getOpenTriggerProps: PropGetter<\"button\"> = useCallback(\n (props = {}) => ({\n \"aria-controls\": open ? contentId : undefined,\n \"aria-expanded\": open,\n \"aria-haspopup\": \"dialog\",\n \"aria-label\": t(\"Open action bar\"),\n ...props,\n onClick: handlerAll(props.onClick, onOpen),\n }),\n [contentId, onOpen, open, t],\n )\n\n const getCloseTriggerProps: PropGetter<\"button\"> = useCallback(\n (props = {}) => ({\n \"aria-label\": t(\"Close action bar\"),\n ...props,\n onClick: handlerAll(props.onClick, onClose),\n }),\n [onClose, t],\n )\n\n const getContentProps: PropGetter<\"section\"> = useCallback(\n (props = {}) => ({\n id: contentId,\n role: \"dialog\",\n ...props,\n }),\n [contentId],\n )\n\n return {\n open,\n getCloseTriggerProps,\n getContentProps,\n getOpenTriggerProps,\n getRootProps,\n onClose,\n onOpen,\n }\n}\n\nexport type UseActionBarReturn = ReturnType<typeof useActionBar>\n"],"mappings":";;;;;;;;;;;;;;AAuBA,MAAa,gBAAgB,EAC3B,aAAa,MACb,aACA,MAAM,UACN,SAAS,aACT,QAAQ,YACR,GAAG,SACkB,EAAE,KAAK;CAC5B,MAAM,EAAE,gBAAgB,gBAAgB;CACxC,MAAM,EAAE,MAAM,SAAS,WAAW,cAAc;EAC9C;EACA,MAAM;EACN,SAAS;EACT,QAAQ;EACT,CAAC;CACF,MAAM,CAAC,aAAa,QAAQ;CAC5B,MAAM,EAAE,MAAM,QAAQ,YAAY;CAElC,MAAM,YAAY,aACf,OAAsB;AACrB,MAAI,GAAG,QAAQ,SAAU;AAEzB,KAAG,iBAAiB;AAEpB,MAAI,WAAY,UAAS;IAE3B,CAAC,YAAY,QAAQ,CACtB;AAED,kBAAiB,aAAa,EAAE,WAAW,UAAU;CAErD,MAAMA,eAA2B,aAC9B,QAAQ,EAAE,MAAM;EAAE,GAAG;EAAM,GAAG;EAAO,GACtC,CAAC,KAAK,CACP;CAED,MAAMC,sBAA4C,aAC/C,QAAQ,EAAE,MAAM;EACf,iBAAiB,OAAO,YAAY;EACpC,iBAAiB;EACjB,iBAAiB;EACjB,cAAc,EAAE,kBAAkB;EAClC,GAAG;EACH,uCAAoB,MAAM,SAAS,OAAO;EAC3C,GACD;EAAC;EAAW;EAAQ;EAAM;EAAE,CAC7B;AAoBD,QAAO;EACL;EACA,sBApBiD,aAChD,QAAQ,EAAE,MAAM;GACf,cAAc,EAAE,mBAAmB;GACnC,GAAG;GACH,uCAAoB,MAAM,SAAS,QAAQ;GAC5C,GACD,CAAC,SAAS,EAAE,CACb;EAcC,iBAZ6C,aAC5C,QAAQ,EAAE,MAAM;GACf,IAAI;GACJ,MAAM;GACN,GAAG;GACJ,GACD,CAAC,UAAU,CACZ;EAMC;EACA;EACA;EACA;EACD"}
1
+ {"version":3,"file":"use-action-bar.js","names":["getRootProps: PropGetter","getOpenTriggerProps: PropGetter<\"button\">"],"sources":["../../../../src/components/action-bar/use-action-bar.ts"],"sourcesContent":["\"use client\"\n\nimport type { HTMLProps, PropGetter } from \"../../core\"\nimport { useCallback } from \"react\"\nimport { useEnvironment } from \"../../core\"\nimport {\n useDisclosure,\n type UseDisclosureProps,\n} from \"../../hooks/use-disclosure\"\nimport { useEventListener } from \"../../hooks/use-event-listener\"\nimport { useI18n } from \"../../providers/i18n-provider\"\nimport { handlerAll, useIds } from \"../../utils\"\n\nexport interface UseActionBarProps\n extends HTMLProps, Omit<UseDisclosureProps, \"timing\"> {\n /**\n * If `true`, the action bar will close when the `Esc` key is pressed.\n *\n * @default true\n */\n closeOnEsc?: boolean\n}\n\nexport const useActionBar = ({\n closeOnEsc = true,\n defaultOpen,\n open: openProp,\n onClose: onCloseProp,\n onOpen: onOpenProp,\n ...rest\n}: UseActionBarProps = {}) => {\n const { getDocument } = useEnvironment()\n const { open, onClose, onOpen } = useDisclosure({\n defaultOpen,\n open: openProp,\n onClose: onCloseProp,\n onOpen: onOpenProp,\n })\n const [contentId] = useIds()\n const { t } = useI18n(\"actionBar\")\n\n const onKeyDown = useCallback(\n (ev: KeyboardEvent) => {\n if (ev.key !== \"Escape\") return\n\n if (!closeOnEsc) return\n\n ev.stopPropagation()\n onClose()\n },\n [closeOnEsc, onClose],\n )\n\n useEventListener(getDocument(), \"keydown\", onKeyDown)\n\n const getRootProps: PropGetter = useCallback(\n (props = {}) => ({ ...rest, ...props }),\n [rest],\n )\n\n const getOpenTriggerProps: PropGetter<\"button\"> = useCallback(\n (props = {}) => ({\n \"aria-controls\": open ? contentId : undefined,\n \"aria-expanded\": open,\n \"aria-haspopup\": \"dialog\",\n \"aria-label\": t(\"Open action bar\"),\n ...props,\n onClick: handlerAll(props.onClick, onOpen),\n }),\n [contentId, onOpen, open, t],\n )\n\n const getCloseTriggerProps: PropGetter<\"button\"> = useCallback(\n (props = {}) => ({\n \"aria-label\": t(\"Close action bar\"),\n ...props,\n onClick: handlerAll(props.onClick, onClose),\n }),\n [onClose, t],\n )\n\n const getContentProps: PropGetter<\"section\"> = useCallback(\n (props = {}) => ({\n id: contentId,\n role: \"dialog\",\n ...props,\n }),\n [contentId],\n )\n\n return {\n open,\n getCloseTriggerProps,\n getContentProps,\n getOpenTriggerProps,\n getRootProps,\n onClose,\n onOpen,\n }\n}\n\nexport type UseActionBarReturn = ReturnType<typeof useActionBar>\n"],"mappings":";;;;;;;;;;;;;;AAuBA,MAAa,gBAAgB,EAC3B,aAAa,MACb,aACA,MAAM,UACN,SAAS,aACT,QAAQ,YACR,GAAG,SACkB,EAAE,KAAK;CAC5B,MAAM,EAAE,gBAAgB,gBAAgB;CACxC,MAAM,EAAE,MAAM,SAAS,WAAW,cAAc;EAC9C;EACA,MAAM;EACN,SAAS;EACT,QAAQ;EACT,CAAC;CACF,MAAM,CAAC,aAAa,QAAQ;CAC5B,MAAM,EAAE,MAAM,QAAQ,YAAY;CAElC,MAAM,YAAY,aACf,OAAsB;AACrB,MAAI,GAAG,QAAQ,SAAU;AAEzB,MAAI,CAAC,WAAY;AAEjB,KAAG,iBAAiB;AACpB,WAAS;IAEX,CAAC,YAAY,QAAQ,CACtB;AAED,kBAAiB,aAAa,EAAE,WAAW,UAAU;CAErD,MAAMA,eAA2B,aAC9B,QAAQ,EAAE,MAAM;EAAE,GAAG;EAAM,GAAG;EAAO,GACtC,CAAC,KAAK,CACP;CAED,MAAMC,sBAA4C,aAC/C,QAAQ,EAAE,MAAM;EACf,iBAAiB,OAAO,YAAY;EACpC,iBAAiB;EACjB,iBAAiB;EACjB,cAAc,EAAE,kBAAkB;EAClC,GAAG;EACH,uCAAoB,MAAM,SAAS,OAAO;EAC3C,GACD;EAAC;EAAW;EAAQ;EAAM;EAAE,CAC7B;AAoBD,QAAO;EACL;EACA,sBApBiD,aAChD,QAAQ,EAAE,MAAM;GACf,cAAc,EAAE,mBAAmB;GACnC,GAAG;GACH,uCAAoB,MAAM,SAAS,QAAQ;GAC5C,GACD,CAAC,SAAS,EAAE,CACb;EAcC,iBAZ6C,aAC5C,QAAQ,EAAE,MAAM;GACf,IAAI;GACJ,MAAM;GACN,GAAG;GACJ,GACD,CAAC,UAAU,CACZ;EAMC;EACA;EACA;EACA;EACD"}
@@ -50,11 +50,15 @@ const useEditable = (props = {}) => {
50
50
  }, [onSubmitProp, value]);
51
51
  const onKeyDown = useCallback((ev) => {
52
52
  if (ev.key !== "Escape" && ev.key !== "Enter") return;
53
- ev.preventDefault();
54
- if (ev.key === "Escape") onCancel();
55
- else {
53
+ if (ev.key === "Escape") {
54
+ ev.preventDefault();
55
+ onCancel();
56
+ } else {
56
57
  const { metaKey, shiftKey } = ev;
57
- if (!shiftKey && !metaKey) onSubmit();
58
+ if (!shiftKey && !metaKey) {
59
+ ev.preventDefault();
60
+ onSubmit();
61
+ }
58
62
  }
59
63
  }, [onCancel, onSubmit]);
60
64
  const onKeyDownWithoutSubmit = useCallback((ev) => {
@@ -1 +1 @@
1
- {"version":3,"file":"use-editable.js","names":["createContext","getRootProps: PropGetter","props","getPreviewProps: PropGetter<\"span\">","getInputProps: PropGetter<\"input\">","getTextareaProps: PropGetter<\"textarea\">","getControlProps: PropGetter","getEditProps: PropGetter<\"button\">","getSubmitProps: PropGetter<\"button\">"],"sources":["../../../../src/components/editable/use-editable.ts"],"sourcesContent":["\"use client\"\n\nimport type { ChangeEvent, FocusEvent, KeyboardEvent } from \"react\"\nimport type { PropGetter } from \"../../core\"\nimport type { FieldProps } from \"../field\"\nimport { useCallback, useEffect, useRef, useState } from \"react\"\nimport { useControllableState } from \"../../hooks/use-controllable-state\"\nimport { useFocusOnPointerDown } from \"../../hooks/use-focus\"\nimport {\n contains,\n createContext,\n handlerAll,\n mergeRefs,\n useCallbackRef,\n useSafeLayoutEffect,\n useUpdateEffect,\n} from \"../../utils\"\nimport { useFieldProps } from \"../field\"\n\ninterface EditableContext extends Omit<\n UseEditableReturn,\n \"getRootProps\" | \"onCancel\" | \"onEdit\" | \"onSubmit\" | \"value\"\n> {}\n\nconst [EditableContext, useEditableContext] = createContext<EditableContext>({\n name: \"EditableContext\",\n})\n\nexport { EditableContext, useEditableContext }\n\nexport interface UseEditableProps extends FieldProps {\n /**\n * The initial value of the Editable in both edit & preview mode.\n */\n defaultValue?: string\n /**\n * The placeholder text when the value is empty.\n */\n placeholder?: string\n /**\n * If `true`, the read only view, has a `tabIndex` set to `0`\n * so it can receive focus via the keyboard or click.\n *\n * @default true\n */\n previewFocusable?: boolean\n /**\n * If `true`, the input's text will be highlighted on focus.\n *\n * @default true\n */\n selectAllOnFocus?: boolean\n /**\n * If `true`, the Editable will start with edit mode by default.\n */\n startWithEditView?: boolean\n /**\n * If `true`, it'll update the value onBlur and turn off the edit mode.\n *\n * @default true\n */\n submitOnBlur?: boolean\n /**\n * The value of the Editable in both edit & preview mode.\n */\n value?: string\n /**\n * Callback invoked when user cancels input with the `Esc` key.\n * It provides the last confirmed value as argument.\n */\n onCancel?: (preValue: string) => void\n /**\n * A callback invoked when user changes input.\n */\n onChange?: (value: string) => void\n /**\n * A callback invoked once the user enters edit mode.\n */\n onEdit?: () => void\n /**\n * A callback invoked when user confirms value with `enter` key or by blurring input.\n */\n onSubmit?: (value: string) => void\n}\n\nexport const useEditable = (props: UseEditableProps = {}) => {\n const {\n props: {\n id,\n defaultValue,\n disabled,\n placeholder,\n previewFocusable = true,\n readOnly,\n required,\n selectAllOnFocus = true,\n startWithEditView,\n submitOnBlur = true,\n value: valueProp,\n onCancel: onCancelProp,\n onChange: onChangeProp,\n onEdit: onEditProp,\n onSubmit: onSubmitProp,\n ...rest\n },\n ariaProps,\n dataProps,\n eventProps,\n } = useFieldProps(props)\n const onEditRef = useCallbackRef(onEditProp)\n const [editing, setEditing] = useState<boolean>(\n !!startWithEditView && !disabled,\n )\n const [value, setValue] = useControllableState({\n defaultValue: defaultValue || \"\",\n value: valueProp,\n onChange: onChangeProp,\n })\n const interactive = !editing && !disabled\n const emptyValue = value.length === 0\n const [prevValue, setPrevValue] = useState(value)\n const inputRef = useRef<HTMLInputElement | HTMLTextAreaElement>(null)\n const previewRef = useRef<HTMLElement>(null)\n const editRef = useRef<HTMLButtonElement>(null)\n const cancelRef = useRef<HTMLButtonElement>(null)\n const submitRef = useRef<HTMLButtonElement>(null)\n\n const onChange = useCallback(\n (ev: ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) =>\n setValue(ev.currentTarget.value),\n [setValue],\n )\n\n const onUpdatePrevValue = useCallback(() => setPrevValue(value), [value])\n\n const onEdit = useCallback(() => {\n if (interactive) setEditing(true)\n }, [interactive])\n\n const onCancel = useCallback(() => {\n setEditing(false)\n setValue(prevValue)\n onCancelProp?.(prevValue)\n }, [prevValue, onCancelProp, setValue])\n\n const onSubmit = useCallback(() => {\n setEditing(false)\n setPrevValue(value)\n onSubmitProp?.(value)\n }, [onSubmitProp, value])\n\n const onKeyDown = useCallback(\n (ev: KeyboardEvent) => {\n if (ev.key !== \"Escape\" && ev.key !== \"Enter\") return\n\n ev.preventDefault()\n\n if (ev.key === \"Escape\") {\n onCancel()\n } else {\n const { metaKey, shiftKey } = ev\n\n if (!shiftKey && !metaKey) onSubmit()\n }\n },\n [onCancel, onSubmit],\n )\n\n const onKeyDownWithoutSubmit = useCallback(\n (ev: KeyboardEvent) => {\n if (ev.key !== \"Escape\") return\n\n ev.preventDefault()\n onCancel()\n },\n [onCancel],\n )\n\n const onBlur = useCallback(\n (ev: FocusEvent) => {\n if (!editing) return\n\n const ownerDocument = ev.currentTarget.ownerDocument\n const relatedTarget = (ev.relatedTarget ??\n ownerDocument.activeElement) as HTMLElement\n const targetIsCancel = contains(cancelRef.current, relatedTarget)\n const targetIsSubmit = contains(submitRef.current, relatedTarget)\n const validBlur = !targetIsCancel && !targetIsSubmit\n\n if (!validBlur) return\n\n if (submitOnBlur) {\n onSubmit()\n } else {\n onCancel()\n }\n },\n [editing, submitOnBlur, onSubmit, onCancel],\n )\n\n useFocusOnPointerDown({\n ref: inputRef,\n elements: [cancelRef, submitRef],\n enabled: editing,\n })\n\n useSafeLayoutEffect(() => {\n if (!editing) return\n\n inputRef.current?.focus()\n\n if (selectAllOnFocus) inputRef.current?.select()\n }, [])\n\n useUpdateEffect(() => {\n if (!editing) {\n editRef.current?.focus()\n\n return\n }\n\n inputRef.current?.focus()\n\n if (selectAllOnFocus) inputRef.current?.select()\n\n onEditRef()\n }, [editing, onEditRef, selectAllOnFocus])\n\n useEffect(() => {\n if (editing) return\n\n const el = inputRef.current\n const activeEl = el?.ownerDocument.activeElement\n\n if (activeEl === el) el?.blur()\n }, [editing])\n\n const getRootProps: PropGetter = useCallback(\n (props) => ({\n ...rest,\n ...dataProps,\n ...props,\n }),\n [rest, dataProps],\n )\n\n const getPreviewProps: PropGetter<\"span\"> = useCallback(\n ({ ref, ...props } = {}) => ({\n ...dataProps,\n ...props,\n ref: mergeRefs(previewRef, ref),\n children: emptyValue ? placeholder : value,\n hidden: editing,\n tabIndex: interactive && previewFocusable ? 0 : undefined,\n onFocus: handlerAll(props.onFocus, onEdit, onUpdatePrevValue),\n }),\n [\n dataProps,\n editing,\n interactive,\n previewFocusable,\n emptyValue,\n onEdit,\n onUpdatePrevValue,\n placeholder,\n value,\n ],\n )\n\n const getInputProps: PropGetter<\"input\"> = useCallback(\n ({ ref, ...props } = {}) => ({\n ...dataProps,\n ...ariaProps,\n ...props,\n id,\n ref: mergeRefs(inputRef, ref),\n disabled,\n hidden: !editing,\n placeholder,\n readOnly,\n required,\n value,\n onBlur: handlerAll(eventProps.onBlur, props.onBlur, onBlur),\n onChange: handlerAll(props.onChange, onChange),\n onFocus: handlerAll(eventProps.onFocus, props.onFocus, onUpdatePrevValue),\n onKeyDown: handlerAll(props.onKeyDown, onKeyDown),\n }),\n [\n dataProps,\n ariaProps,\n id,\n disabled,\n editing,\n placeholder,\n readOnly,\n required,\n value,\n eventProps.onBlur,\n eventProps.onFocus,\n onBlur,\n onChange,\n onUpdatePrevValue,\n onKeyDown,\n ],\n )\n\n const getTextareaProps: PropGetter<\"textarea\"> = useCallback(\n ({ ref, ...props } = {}) => ({\n ...dataProps,\n ...ariaProps,\n ...props,\n id,\n ref: mergeRefs(inputRef, ref),\n disabled,\n hidden: !editing,\n placeholder,\n readOnly,\n required,\n value,\n onBlur: handlerAll(eventProps.onBlur, props.onBlur, onBlur),\n onChange: handlerAll(props.onChange, onChange),\n onFocus: handlerAll(eventProps.onFocus, props.onFocus, onUpdatePrevValue),\n onKeyDown: handlerAll(props.onKeyDown, onKeyDownWithoutSubmit),\n }),\n [\n dataProps,\n ariaProps,\n id,\n disabled,\n editing,\n placeholder,\n readOnly,\n required,\n value,\n eventProps.onBlur,\n eventProps.onFocus,\n onBlur,\n onChange,\n onUpdatePrevValue,\n onKeyDownWithoutSubmit,\n ],\n )\n\n const getControlProps: PropGetter = useCallback(\n (props) => ({\n ...dataProps,\n role: \"group\",\n ...props,\n }),\n [dataProps],\n )\n\n const getEditProps: PropGetter<\"button\"> = useCallback(\n ({ ref, ...props } = {}) => ({\n ...dataProps,\n ...props,\n ref: mergeRefs(editRef, ref),\n disabled,\n hidden: editing,\n onClick: handlerAll(props.onClick, onEdit),\n }),\n [dataProps, disabled, editing, onEdit],\n )\n\n const getSubmitProps: PropGetter<\"button\"> = useCallback(\n ({ ref, ...props } = {}) => ({\n ...dataProps,\n ...props,\n ref: mergeRefs(submitRef, ref),\n disabled,\n hidden: !editing,\n onClick: handlerAll(props.onClick, onSubmit),\n }),\n [dataProps, disabled, editing, onSubmit],\n )\n\n const getCancelProps: PropGetter<\"button\"> = useCallback(\n ({ ref, ...props } = {}) => ({\n ...dataProps,\n ...props,\n ref: mergeRefs(cancelRef, ref),\n disabled,\n hidden: !editing,\n onClick: handlerAll(props.onClick, onCancel),\n }),\n [dataProps, disabled, editing, onCancel],\n )\n\n return {\n editing,\n value,\n getCancelProps,\n getControlProps,\n getEditProps,\n getInputProps,\n getPreviewProps,\n getRootProps,\n getSubmitProps,\n getTextareaProps,\n onCancel,\n onEdit,\n onSubmit,\n }\n}\n\nexport type UseEditableReturn = ReturnType<typeof useEditable>\n"],"mappings":";;;;;;;;;;;;;AAwBA,MAAM,CAAC,iBAAiB,sBAAsBA,gBAA+B,EAC3E,MAAM,mBACP,CAAC;AA2DF,MAAa,eAAe,QAA0B,EAAE,KAAK;CAC3D,MAAM,EACJ,OAAO,EACL,IACA,cACA,UACA,aACA,mBAAmB,MACnB,UACA,UACA,mBAAmB,MACnB,mBACA,eAAe,MACf,OAAO,WACP,UAAU,cACV,UAAU,cACV,QAAQ,YACR,UAAU,cACV,GAAG,QAEL,WACA,WACA,eACE,cAAc,MAAM;CACxB,MAAM,YAAY,eAAe,WAAW;CAC5C,MAAM,CAAC,SAAS,cAAc,SAC5B,CAAC,CAAC,qBAAqB,CAAC,SACzB;CACD,MAAM,CAAC,OAAO,YAAY,qBAAqB;EAC7C,cAAc,gBAAgB;EAC9B,OAAO;EACP,UAAU;EACX,CAAC;CACF,MAAM,cAAc,CAAC,WAAW,CAAC;CACjC,MAAM,aAAa,MAAM,WAAW;CACpC,MAAM,CAAC,WAAW,gBAAgB,SAAS,MAAM;CACjD,MAAM,WAAW,OAA+C,KAAK;CACrE,MAAM,aAAa,OAAoB,KAAK;CAC5C,MAAM,UAAU,OAA0B,KAAK;CAC/C,MAAM,YAAY,OAA0B,KAAK;CACjD,MAAM,YAAY,OAA0B,KAAK;CAEjD,MAAM,WAAW,aACd,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AW;GAAU;GAAS;GAAS,CACzC;EAMC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACD"}
1
+ {"version":3,"file":"use-editable.js","names":["createContext","getRootProps: PropGetter","props","getPreviewProps: PropGetter<\"span\">","getInputProps: PropGetter<\"input\">","getTextareaProps: PropGetter<\"textarea\">","getControlProps: PropGetter","getEditProps: PropGetter<\"button\">","getSubmitProps: PropGetter<\"button\">"],"sources":["../../../../src/components/editable/use-editable.ts"],"sourcesContent":["\"use client\"\n\nimport type { ChangeEvent, FocusEvent, KeyboardEvent } from \"react\"\nimport type { PropGetter } from \"../../core\"\nimport type { FieldProps } from \"../field\"\nimport { useCallback, useEffect, useRef, useState } from \"react\"\nimport { useControllableState } from \"../../hooks/use-controllable-state\"\nimport { useFocusOnPointerDown } from \"../../hooks/use-focus\"\nimport {\n contains,\n createContext,\n handlerAll,\n mergeRefs,\n useCallbackRef,\n useSafeLayoutEffect,\n useUpdateEffect,\n} from \"../../utils\"\nimport { useFieldProps } from \"../field\"\n\ninterface EditableContext extends Omit<\n UseEditableReturn,\n \"getRootProps\" | \"onCancel\" | \"onEdit\" | \"onSubmit\" | \"value\"\n> {}\n\nconst [EditableContext, useEditableContext] = createContext<EditableContext>({\n name: \"EditableContext\",\n})\n\nexport { EditableContext, useEditableContext }\n\nexport interface UseEditableProps extends FieldProps {\n /**\n * The initial value of the Editable in both edit & preview mode.\n */\n defaultValue?: string\n /**\n * The placeholder text when the value is empty.\n */\n placeholder?: string\n /**\n * If `true`, the read only view, has a `tabIndex` set to `0`\n * so it can receive focus via the keyboard or click.\n *\n * @default true\n */\n previewFocusable?: boolean\n /**\n * If `true`, the input's text will be highlighted on focus.\n *\n * @default true\n */\n selectAllOnFocus?: boolean\n /**\n * If `true`, the Editable will start with edit mode by default.\n */\n startWithEditView?: boolean\n /**\n * If `true`, it'll update the value onBlur and turn off the edit mode.\n *\n * @default true\n */\n submitOnBlur?: boolean\n /**\n * The value of the Editable in both edit & preview mode.\n */\n value?: string\n /**\n * Callback invoked when user cancels input with the `Esc` key.\n * It provides the last confirmed value as argument.\n */\n onCancel?: (preValue: string) => void\n /**\n * A callback invoked when user changes input.\n */\n onChange?: (value: string) => void\n /**\n * A callback invoked once the user enters edit mode.\n */\n onEdit?: () => void\n /**\n * A callback invoked when user confirms value with `enter` key or by blurring input.\n */\n onSubmit?: (value: string) => void\n}\n\nexport const useEditable = (props: UseEditableProps = {}) => {\n const {\n props: {\n id,\n defaultValue,\n disabled,\n placeholder,\n previewFocusable = true,\n readOnly,\n required,\n selectAllOnFocus = true,\n startWithEditView,\n submitOnBlur = true,\n value: valueProp,\n onCancel: onCancelProp,\n onChange: onChangeProp,\n onEdit: onEditProp,\n onSubmit: onSubmitProp,\n ...rest\n },\n ariaProps,\n dataProps,\n eventProps,\n } = useFieldProps(props)\n const onEditRef = useCallbackRef(onEditProp)\n const [editing, setEditing] = useState<boolean>(\n !!startWithEditView && !disabled,\n )\n const [value, setValue] = useControllableState({\n defaultValue: defaultValue || \"\",\n value: valueProp,\n onChange: onChangeProp,\n })\n const interactive = !editing && !disabled\n const emptyValue = value.length === 0\n const [prevValue, setPrevValue] = useState(value)\n const inputRef = useRef<HTMLInputElement | HTMLTextAreaElement>(null)\n const previewRef = useRef<HTMLElement>(null)\n const editRef = useRef<HTMLButtonElement>(null)\n const cancelRef = useRef<HTMLButtonElement>(null)\n const submitRef = useRef<HTMLButtonElement>(null)\n\n const onChange = useCallback(\n (ev: ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) =>\n setValue(ev.currentTarget.value),\n [setValue],\n )\n\n const onUpdatePrevValue = useCallback(() => setPrevValue(value), [value])\n\n const onEdit = useCallback(() => {\n if (interactive) setEditing(true)\n }, [interactive])\n\n const onCancel = useCallback(() => {\n setEditing(false)\n setValue(prevValue)\n onCancelProp?.(prevValue)\n }, [prevValue, onCancelProp, setValue])\n\n const onSubmit = useCallback(() => {\n setEditing(false)\n setPrevValue(value)\n onSubmitProp?.(value)\n }, [onSubmitProp, value])\n\n const onKeyDown = useCallback(\n (ev: KeyboardEvent) => {\n if (ev.key !== \"Escape\" && ev.key !== \"Enter\") return\n\n if (ev.key === \"Escape\") {\n ev.preventDefault()\n onCancel()\n } else {\n const { metaKey, shiftKey } = ev\n\n if (!shiftKey && !metaKey) {\n ev.preventDefault()\n onSubmit()\n }\n }\n },\n [onCancel, onSubmit],\n )\n\n const onKeyDownWithoutSubmit = useCallback(\n (ev: KeyboardEvent) => {\n if (ev.key !== \"Escape\") return\n\n ev.preventDefault()\n onCancel()\n },\n [onCancel],\n )\n\n const onBlur = useCallback(\n (ev: FocusEvent) => {\n if (!editing) return\n\n const ownerDocument = ev.currentTarget.ownerDocument\n const relatedTarget = (ev.relatedTarget ??\n ownerDocument.activeElement) as HTMLElement\n const targetIsCancel = contains(cancelRef.current, relatedTarget)\n const targetIsSubmit = contains(submitRef.current, relatedTarget)\n const validBlur = !targetIsCancel && !targetIsSubmit\n\n if (!validBlur) return\n\n if (submitOnBlur) {\n onSubmit()\n } else {\n onCancel()\n }\n },\n [editing, submitOnBlur, onSubmit, onCancel],\n )\n\n useFocusOnPointerDown({\n ref: inputRef,\n elements: [cancelRef, submitRef],\n enabled: editing,\n })\n\n useSafeLayoutEffect(() => {\n if (!editing) return\n\n inputRef.current?.focus()\n\n if (selectAllOnFocus) inputRef.current?.select()\n }, [])\n\n useUpdateEffect(() => {\n if (!editing) {\n editRef.current?.focus()\n\n return\n }\n\n inputRef.current?.focus()\n\n if (selectAllOnFocus) inputRef.current?.select()\n\n onEditRef()\n }, [editing, onEditRef, selectAllOnFocus])\n\n useEffect(() => {\n if (editing) return\n\n const el = inputRef.current\n const activeEl = el?.ownerDocument.activeElement\n\n if (activeEl === el) el?.blur()\n }, [editing])\n\n const getRootProps: PropGetter = useCallback(\n (props) => ({\n ...rest,\n ...dataProps,\n ...props,\n }),\n [rest, dataProps],\n )\n\n const getPreviewProps: PropGetter<\"span\"> = useCallback(\n ({ ref, ...props } = {}) => ({\n ...dataProps,\n ...props,\n ref: mergeRefs(previewRef, ref),\n children: emptyValue ? placeholder : value,\n hidden: editing,\n tabIndex: interactive && previewFocusable ? 0 : undefined,\n onFocus: handlerAll(props.onFocus, onEdit, onUpdatePrevValue),\n }),\n [\n dataProps,\n editing,\n interactive,\n previewFocusable,\n emptyValue,\n onEdit,\n onUpdatePrevValue,\n placeholder,\n value,\n ],\n )\n\n const getInputProps: PropGetter<\"input\"> = useCallback(\n ({ ref, ...props } = {}) => ({\n ...dataProps,\n ...ariaProps,\n ...props,\n id,\n ref: mergeRefs(inputRef, ref),\n disabled,\n hidden: !editing,\n placeholder,\n readOnly,\n required,\n value,\n onBlur: handlerAll(eventProps.onBlur, props.onBlur, onBlur),\n onChange: handlerAll(props.onChange, onChange),\n onFocus: handlerAll(eventProps.onFocus, props.onFocus, onUpdatePrevValue),\n onKeyDown: handlerAll(props.onKeyDown, onKeyDown),\n }),\n [\n dataProps,\n ariaProps,\n id,\n disabled,\n editing,\n placeholder,\n readOnly,\n required,\n value,\n eventProps.onBlur,\n eventProps.onFocus,\n onBlur,\n onChange,\n onUpdatePrevValue,\n onKeyDown,\n ],\n )\n\n const getTextareaProps: PropGetter<\"textarea\"> = useCallback(\n ({ ref, ...props } = {}) => ({\n ...dataProps,\n ...ariaProps,\n ...props,\n id,\n ref: mergeRefs(inputRef, ref),\n disabled,\n hidden: !editing,\n placeholder,\n readOnly,\n required,\n value,\n onBlur: handlerAll(eventProps.onBlur, props.onBlur, onBlur),\n onChange: handlerAll(props.onChange, onChange),\n onFocus: handlerAll(eventProps.onFocus, props.onFocus, onUpdatePrevValue),\n onKeyDown: handlerAll(props.onKeyDown, onKeyDownWithoutSubmit),\n }),\n [\n dataProps,\n ariaProps,\n id,\n disabled,\n editing,\n placeholder,\n readOnly,\n required,\n value,\n eventProps.onBlur,\n eventProps.onFocus,\n onBlur,\n onChange,\n onUpdatePrevValue,\n onKeyDownWithoutSubmit,\n ],\n )\n\n const getControlProps: PropGetter = useCallback(\n (props) => ({\n ...dataProps,\n role: \"group\",\n ...props,\n }),\n [dataProps],\n )\n\n const getEditProps: PropGetter<\"button\"> = useCallback(\n ({ ref, ...props } = {}) => ({\n ...dataProps,\n ...props,\n ref: mergeRefs(editRef, ref),\n disabled,\n hidden: editing,\n onClick: handlerAll(props.onClick, onEdit),\n }),\n [dataProps, disabled, editing, onEdit],\n )\n\n const getSubmitProps: PropGetter<\"button\"> = useCallback(\n ({ ref, ...props } = {}) => ({\n ...dataProps,\n ...props,\n ref: mergeRefs(submitRef, ref),\n disabled,\n hidden: !editing,\n onClick: handlerAll(props.onClick, onSubmit),\n }),\n [dataProps, disabled, editing, onSubmit],\n )\n\n const getCancelProps: PropGetter<\"button\"> = useCallback(\n ({ ref, ...props } = {}) => ({\n ...dataProps,\n ...props,\n ref: mergeRefs(cancelRef, ref),\n disabled,\n hidden: !editing,\n onClick: handlerAll(props.onClick, onCancel),\n }),\n [dataProps, disabled, editing, onCancel],\n )\n\n return {\n editing,\n value,\n getCancelProps,\n getControlProps,\n getEditProps,\n getInputProps,\n getPreviewProps,\n getRootProps,\n getSubmitProps,\n getTextareaProps,\n onCancel,\n onEdit,\n onSubmit,\n }\n}\n\nexport type UseEditableReturn = ReturnType<typeof useEditable>\n"],"mappings":";;;;;;;;;;;;;AAwBA,MAAM,CAAC,iBAAiB,sBAAsBA,gBAA+B,EAC3E,MAAM,mBACP,CAAC;AA2DF,MAAa,eAAe,QAA0B,EAAE,KAAK;CAC3D,MAAM,EACJ,OAAO,EACL,IACA,cACA,UACA,aACA,mBAAmB,MACnB,UACA,UACA,mBAAmB,MACnB,mBACA,eAAe,MACf,OAAO,WACP,UAAU,cACV,UAAU,cACV,QAAQ,YACR,UAAU,cACV,GAAG,QAEL,WACA,WACA,eACE,cAAc,MAAM;CACxB,MAAM,YAAY,eAAe,WAAW;CAC5C,MAAM,CAAC,SAAS,cAAc,SAC5B,CAAC,CAAC,qBAAqB,CAAC,SACzB;CACD,MAAM,CAAC,OAAO,Y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AAGN,YAAU,EAAE,MAAM;EAC3B,GAAG;EACH,GAAGA;EACH,KAAK,UAAU,WAAW,IAAI;EAC9B;EACA,QAAQ,CAAC;EACT,uCAAoBA,QAAM,SAAS,SAAS;EAC7C,GACD;EAAC;EAAW;EAAU;EAAS;EAAS,CACzC;AAcD,QAAO;EACL;EACA;EACA,gBAf2C,aAC1C,EAAE,KAAK,GAAGA,YAAU,EAAE,MAAM;GAC3B,GAAG;GACH,GAAGA;GACH,KAAK,UAAU,WAAW,IAAI;GAC9B;GACA,QAAQ,CAAC;GACT,uCAAoBA,QAAM,SAAS,SAAS;GAC7C,GACD;GAAC;GAAW;GAAU;GAAS;GAAS,CACzC;EAMC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACD"}
@@ -7,6 +7,7 @@ import { createSlotComponent } from "../../core/components/create-component.js";
7
7
  import "../../core/index.js";
8
8
  import { motion as motion$1 } from "../motion/factory.js";
9
9
  import "../motion/index.js";
10
+ import { useValue } from "../../hooks/use-value/index.js";
10
11
  import { Portal } from "../portal/portal.js";
11
12
  import "../portal/index.js";
12
13
  import { usePopupAnimationProps } from "../popover/popover.js";
@@ -112,7 +113,8 @@ const ModalCloseButton = withContext(CloseButton, "closeButton")(void 0, (props)
112
113
  return { ...getCloseButtonProps(props) };
113
114
  });
114
115
  const ModalOverlay = withContext((props) => {
115
- const { animationScheme, duration, getOverlayProps } = useComponentContext();
116
+ const { animationScheme, duration: durationProp, getOverlayProps } = useComponentContext();
117
+ const duration = useValue(durationProp);
116
118
  return /* @__PURE__ */ jsx(motion$1.div, {
117
119
  custom: { duration },
118
120
  ...animationScheme !== "none" ? {
@@ -1 +1 @@
1
- {"version":3,"file":"modal.js","names":["motion","ShorthandModalContent: FC<ShorthandModalContentProps>"],"sources":["../../../../src/components/modal/modal.tsx"],"sourcesContent":["\"use client\"\n\nimport type { FC, PropsWithChildren, ReactNode } from \"react\"\nimport type { HTMLProps, HTMLStyledProps, ThemeProps } from \"../../core\"\nimport type { ButtonProps } from \"../button\"\nimport type { CloseButtonProps } from \"../close-button\"\nimport type { FocusLockProps } from \"../focus-lock\"\nimport type { HTMLMotionProps, HTMLMotionPropsWithoutAs } from \"../motion\"\nimport type { UsePopupAnimationProps } from \"../popover\"\nimport type { PortalProps } from \"../portal\"\nimport type { ModalStyle } from \"./modal.style\"\nimport type { UseModalProps, UseModalReturn } from \"./use-modal\"\nimport { AnimatePresence } from \"motion/react\"\nimport { useMemo } from \"react\"\nimport { RemoveScroll } from \"react-remove-scroll\"\nimport { createSlotComponent, styled } from \"../../core\"\nimport { cast, isArray, useSplitChildren, wrapOrPassProps } from \"../../utils\"\nimport { Button } from \"../button\"\nimport { CloseButton } from \"../close-button\"\nimport { fadeVariants } from \"../fade\"\nimport { FocusLock } from \"../focus-lock\"\nimport { motion } from \"../motion\"\nimport { usePopupAnimationProps } from \"../popover\"\nimport { Portal } from \"../portal\"\nimport { modalStyle } from \"./modal.style\"\nimport { useModal } from \"./use-modal\"\n\ninterface ComponentContext\n extends\n Omit<UseModalReturn, \"getRootProps\">,\n UsePopupAnimationProps,\n Pick<ModalRootProps, \"withCloseButton\"> {}\n\nexport interface ModalRootProps\n extends\n ThemeProps<ModalStyle>,\n Omit<UseModalProps, \"title\">,\n Pick<\n FocusLockProps,\n | \"autoFocus\"\n | \"finalFocusRef\"\n | \"initialFocusRef\"\n | \"lockFocusAcrossFrames\"\n | \"restoreFocus\"\n >,\n UsePopupAnimationProps,\n ShorthandModalContentProps {\n /**\n * Handle zoom or pinch gestures on iOS devices when scroll locking is enabled.\n *\n * @default false.\n */\n allowPinchZoom?: boolean\n /**\n * If `true`, scrolling will be disabled on the `body` when the modal opens.\n *\n * @default true\n */\n blockScrollOnMount?: boolean\n /**\n * The modal trigger to use.\n */\n trigger?: ReactNode\n /**\n * If `true`, display the modal close button.\n *\n * @default true\n */\n withCloseButton?: boolean\n /**\n * If `true`, display the modal overlay.\n *\n * @default true\n */\n withOverlay?: boolean\n /**\n * Props to be forwarded to the portal component.\n */\n portalProps?: Omit<PortalProps, \"children\">\n /**\n * Callback function to run side effects after the modal has closed.\n */\n onCloseComplete?: () => void\n}\n\nconst {\n ComponentContext,\n PropsContext: ModalPropsContext,\n useComponentContext,\n usePropsContext: useModalPropsContext,\n withContext,\n withProvider,\n} = createSlotComponent<ModalRootProps, ModalStyle, ComponentContext>(\n \"modal\",\n modalStyle,\n)\n\nexport { ModalPropsContext, useModalPropsContext }\n\n/**\n * `Modal` is a component that is displayed over the main content to focus the user's attention solely on the information.\n *\n * @see https://yamada-ui.com/docs/components/modal\n */\nexport const ModalRoot = withProvider<\"div\", ModalRootProps>(\n ({\n allowPinchZoom = false,\n animationScheme = \"scale\",\n autoFocus,\n blockScrollOnMount = true,\n body,\n cancel,\n children,\n duration,\n finalFocusRef,\n footer,\n header,\n initialFocusRef,\n lockFocusAcrossFrames = true,\n middle,\n restoreFocus,\n success,\n title,\n trigger,\n withCloseButton = true,\n withOverlay = true,\n portalProps,\n onCancel,\n onCloseComplete,\n onMiddle,\n onSuccess,\n ...props\n }) => {\n const [omittedChildren, openTrigger, customOverlay] = useSplitChildren(\n children,\n ModalOpenTrigger,\n ModalOverlay,\n )\n const hasChildren = isArray(omittedChildren) && !!omittedChildren.length\n const { open, getRootProps, ...rest } = useModal(props)\n const customOpenTrigger = trigger ? (\n <ModalOpenTrigger>{trigger}</ModalOpenTrigger>\n ) : null\n const context = useMemo(\n () => ({\n animationScheme,\n duration,\n open,\n withCloseButton,\n ...rest,\n }),\n [animationScheme, duration, open, withCloseButton, rest],\n )\n\n return (\n <ComponentContext value={context}>\n {openTrigger ?? customOpenTrigger}\n\n <AnimatePresence onExitComplete={onCloseComplete}>\n {open ? (\n <Portal {...portalProps}>\n <FocusLock\n autoFocus={autoFocus}\n finalFocusRef={finalFocusRef}\n initialFocusRef={initialFocusRef}\n lockFocusAcrossFrames={lockFocusAcrossFrames}\n restoreFocus={restoreFocus}\n >\n <RemoveScroll\n allowPinchZoom={allowPinchZoom}\n enabled={blockScrollOnMount}\n forwardProps\n >\n <styled.div {...getRootProps()}>\n {customOverlay ?? (withOverlay ? <ModalOverlay /> : null)}\n\n {hasChildren ? (\n omittedChildren\n ) : (\n <ShorthandModalContent\n body={body}\n cancel={cancel}\n footer={footer}\n header={header}\n middle={middle}\n success={success}\n title={title}\n onCancel={onCancel}\n onMiddle={onMiddle}\n onSuccess={onSuccess}\n />\n )}\n </styled.div>\n </RemoveScroll>\n </FocusLock>\n </Portal>\n ) : null}\n </AnimatePresence>\n </ComponentContext>\n )\n },\n \"root\",\n)()\n\nexport interface ModalOpenTriggerProps extends HTMLStyledProps<\"button\"> {}\n\nexport const ModalOpenTrigger = withContext<\"button\", ModalOpenTriggerProps>(\n \"button\",\n { name: \"OpenTrigger\", slot: [\"trigger\", \"open\"] },\n)(undefined, (props) => {\n const { getOpenTriggerProps } = useComponentContext()\n\n return { asChild: true, ...getOpenTriggerProps(props) }\n})\n\nexport interface ModalCloseTriggerProps extends HTMLStyledProps<\"button\"> {}\n\nexport const ModalCloseTrigger = withContext<\"button\", ModalCloseTriggerProps>(\n \"button\",\n { name: \"CloseTrigger\", slot: [\"trigger\", \"close\"] },\n)(undefined, (props) => {\n const { getCloseTriggerProps } = useComponentContext()\n\n return { asChild: true, ...getCloseTriggerProps(props) }\n})\n\nexport interface ModalCloseButtonProps extends CloseButtonProps {}\n\nexport const ModalCloseButton = withContext<\"button\", ModalCloseButtonProps>(\n CloseButton,\n \"closeButton\",\n)(undefined, (props) => {\n const { getCloseButtonProps } = useComponentContext()\n\n return { ...getCloseButtonProps(props) }\n})\n\nexport interface ModalOverlayProps extends HTMLMotionProps {}\n\nexport const ModalOverlay = withContext<\"div\", ModalOverlayProps>((props) => {\n const { animationScheme, duration, getOverlayProps } = useComponentContext()\n\n return (\n <motion.div\n custom={{ duration }}\n {...(animationScheme !== \"none\"\n ? {\n animate: \"enter\",\n exit: \"exit\",\n initial: \"exit\",\n variants: fadeVariants,\n }\n : {})}\n {...cast<HTMLMotionProps>(getOverlayProps(cast<HTMLProps>(props)))}\n />\n )\n}, \"overlay\")()\n\nexport interface ModalContentProps\n extends Omit<HTMLMotionProps<\"section\">, \"children\">, PropsWithChildren {}\n\nexport const ModalContent = withContext<\"section\", ModalContentProps>(\n ({ children, ...rest }) => {\n const { animationScheme, duration, withCloseButton, getContentProps } =\n useComponentContext()\n const [omittedChildren, customCloseButton] = useSplitChildren(\n children,\n ModalCloseButton,\n )\n const popupAnimationProps = usePopupAnimationProps({\n animationScheme,\n duration,\n })\n\n return (\n <motion.section\n {...popupAnimationProps}\n {...cast<HTMLMotionPropsWithoutAs<\"section\">>(\n getContentProps(cast<HTMLProps<\"section\">>(rest)),\n )}\n >\n {customCloseButton ?? (withCloseButton ? <ModalCloseButton /> : null)}\n\n {omittedChildren}\n </motion.section>\n )\n },\n \"content\",\n)()\n\ninterface ShorthandModalContentProps {\n /**\n * The modal body to use.\n */\n body?: ModalBodyProps | ReactNode\n /**\n * The modal cancel button to use.\n */\n cancel?: ButtonProps | ReactNode\n /**\n * The modal footer to use.\n */\n footer?: ModalFooterProps | ReactNode\n /**\n * The modal header to use.\n */\n header?: ModalHeaderProps | ReactNode\n /**\n * The modal middle button to use.\n */\n middle?: ButtonProps | ReactNode\n /**\n * The modal success button to use.\n */\n success?: ButtonProps | ReactNode\n /**\n * The modal title to use.\n */\n title?: ModalTitleProps | ReactNode\n /**\n * The callback invoked when cancel button clicked.\n */\n onCancel?: (onClose: () => void) => void\n /**\n * The callback invoked when middle button clicked.\n */\n onMiddle?: (onClose: () => void) => void\n /**\n * The callback invoked when success button clicked.\n */\n onSuccess?: (onClose: () => void) => void\n}\n\nexport const ShorthandModalContent: FC<ShorthandModalContentProps> = ({\n body,\n cancel,\n footer,\n header,\n middle,\n success,\n title,\n onCancel,\n onMiddle,\n onSuccess,\n}) => {\n const { onClose } = useComponentContext()\n const customHeader = wrapOrPassProps(ModalHeader, header)\n const customTitle = wrapOrPassProps(ModalTitle, title)\n const customBody = wrapOrPassProps(ModalBody, body)\n const customFooter = wrapOrPassProps(ModalFooter, footer)\n const customCancel = wrapOrPassProps(Button, cancel, {\n colorScheme: \"mono\",\n variant: \"ghost\",\n onClick: () => (onCancel ? onCancel(onClose) : onClose()),\n })\n const customMiddle = wrapOrPassProps(Button, middle, {\n colorScheme: \"secondary\",\n onClick: () => (onMiddle ? onMiddle(onClose) : onClose()),\n })\n const customSuccess = wrapOrPassProps(Button, success, {\n colorScheme: \"primary\",\n onClick: () => (onSuccess ? onSuccess(onClose) : onClose()),\n })\n\n return (\n <ModalContent>\n {customHeader ??\n (customTitle ? <ModalHeader>{customTitle}</ModalHeader> : null)}\n {customBody}\n {customFooter ??\n (customCancel || customMiddle || customSuccess ? (\n <ModalFooter>\n {customCancel}\n {customMiddle}\n {customSuccess}\n </ModalFooter>\n ) : null)}\n </ModalContent>\n )\n}\n\nexport interface ModalHeaderProps extends HTMLStyledProps<\"header\"> {}\n\nexport const ModalHeader = withContext<\"header\", ModalHeaderProps>(\n \"header\",\n \"header\",\n)(undefined, (props) => {\n const { getHeaderProps } = useComponentContext()\n\n return { ...getHeaderProps(props) }\n})\n\nexport interface ModalTitleProps extends HTMLStyledProps<\"h2\"> {}\n\nexport const ModalTitle = withContext<\"h2\", ModalTitleProps>(\"h2\", \"title\")(\n undefined,\n (props) => {\n const { getTitleProps } = useComponentContext()\n\n return { ...getTitleProps(props) }\n },\n)\n\nexport interface ModalBodyProps extends HTMLStyledProps {}\n\nexport const ModalBody = withContext<\"div\", ModalBodyProps>(\"div\", \"body\")(\n undefined,\n (props) => {\n const { getBodyProps } = useComponentContext()\n\n return { ...getBodyProps(props) }\n },\n)\n\nexport interface ModalFooterProps extends HTMLStyledProps<\"footer\"> {}\n\nexport const ModalFooter = withContext<\"footer\", ModalFooterProps>(\n \"footer\",\n \"footer\",\n)(undefined, (props) => {\n const { getFooterProps } = useComponentContext()\n\n return { ...getFooterProps(props) }\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;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Aa,OAAO;CACzD,MAAM,eAAe,gBAAgB,QAAQ,QAAQ;EACnD,aAAa;EACb,SAAS;EACT,eAAgB,WAAW,SAAS,QAAQ,GAAG,SAAS;EACzD,CAAC;CACF,MAAM,eAAe,gBAAgB,QAAQ,QAAQ;EACnD,aAAa;EACb,eAAgB,WAAW,SAAS,QAAQ,GAAG,SAAS;EACzD,CAAC;CACF,MAAM,gBAAgB,gBAAgB,QAAQ,SAAS;EACrD,aAAa;EACb,eAAgB,YAAY,UAAU,QAAQ,GAAG,SAAS;EAC3D,CAAC;AAEF,QACE,qBAAC;EACE,iBACE,cAAc,oBAAC,yBAAa,cAA0B,GAAG;EAC3D;EACA,iBACE,gBAAgB,gBAAgB,gBAC/B,qBAAC;GACE;GACA;GACA;MACW,GACZ;KACO;;AAMnB,MAAa,cAAc,YACzB,UACA,SACD,CAAC,SAAY,UAAU;CACtB,MAAM,EAAE,mBAAmB,qBAAqB;AAEhD,QAAO,EAAE,GAAG,eAAe,MAAM,EAAE;EACnC;AAIF,MAAa,aAAa,YAAmC,MAAM,QAAQ,CACzE,SACC,UAAU;CACT,MAAM,EAAE,kBAAkB,qBAAqB;AAE/C,QAAO,EAAE,GAAG,cAAc,MAAM,EAAE;EAErC;AAID,MAAa,YAAY,YAAmC,OAAO,OAAO,CACxE,SACC,UAAU;CACT,MAAM,EAAE,iBAAiB,qBAAqB;AAE9C,QAAO,EAAE,GAAG,aAAa,MAAM,EAAE;EAEpC;AAID,MAAa,cAAc,YACzB,UACA,SACD,CAAC,SAAY,UAAU;CACtB,MAAM,EAAE,mBAAmB,qBAAqB;AAEhD,QAAO,EAAE,GAAG,eAAe,MAAM,EAAE;EACnC"}
1
+ {"version":3,"file":"modal.js","names":["motion","ShorthandModalContent: FC<ShorthandModalContentProps>"],"sources":["../../../../src/components/modal/modal.tsx"],"sourcesContent":["\"use client\"\n\nimport type { FC, PropsWithChildren, ReactNode } from \"react\"\nimport type { HTMLProps, HTMLStyledProps, ThemeProps } from \"../../core\"\nimport type { ButtonProps } from \"../button\"\nimport type { CloseButtonProps } from \"../close-button\"\nimport type { FocusLockProps } from \"../focus-lock\"\nimport type { HTMLMotionProps, HTMLMotionPropsWithoutAs } from \"../motion\"\nimport type { UsePopupAnimationProps } from \"../popover\"\nimport type { PortalProps } from \"../portal\"\nimport type { ModalStyle } from \"./modal.style\"\nimport type { UseModalProps, UseModalReturn } from \"./use-modal\"\nimport { AnimatePresence } from \"motion/react\"\nimport { useMemo } from \"react\"\nimport { RemoveScroll } from \"react-remove-scroll\"\nimport { createSlotComponent, styled } from \"../../core\"\nimport { useValue } from \"../../hooks/use-value\"\nimport { cast, isArray, useSplitChildren, wrapOrPassProps } from \"../../utils\"\nimport { Button } from \"../button\"\nimport { CloseButton } from \"../close-button\"\nimport { fadeVariants } from \"../fade\"\nimport { FocusLock } from \"../focus-lock\"\nimport { motion } from \"../motion\"\nimport { usePopupAnimationProps } from \"../popover\"\nimport { Portal } from \"../portal\"\nimport { modalStyle } from \"./modal.style\"\nimport { useModal } from \"./use-modal\"\n\ninterface ComponentContext\n extends\n Omit<UseModalReturn, \"getRootProps\">,\n UsePopupAnimationProps,\n Pick<ModalRootProps, \"withCloseButton\"> {}\n\nexport interface ModalRootProps\n extends\n ThemeProps<ModalStyle>,\n Omit<UseModalProps, \"title\">,\n Pick<\n FocusLockProps,\n | \"autoFocus\"\n | \"finalFocusRef\"\n | \"initialFocusRef\"\n | \"lockFocusAcrossFrames\"\n | \"restoreFocus\"\n >,\n UsePopupAnimationProps,\n ShorthandModalContentProps {\n /**\n * Handle zoom or pinch gestures on iOS devices when scroll locking is enabled.\n *\n * @default false.\n */\n allowPinchZoom?: boolean\n /**\n * If `true`, scrolling will be disabled on the `body` when the modal opens.\n *\n * @default true\n */\n blockScrollOnMount?: boolean\n /**\n * The modal trigger to use.\n */\n trigger?: ReactNode\n /**\n * If `true`, display the modal close button.\n *\n * @default true\n */\n withCloseButton?: boolean\n /**\n * If `true`, display the modal overlay.\n *\n * @default true\n */\n withOverlay?: boolean\n /**\n * Props to be forwarded to the portal component.\n */\n portalProps?: Omit<PortalProps, \"children\">\n /**\n * Callback function to run side effects after the modal has closed.\n */\n onCloseComplete?: () => void\n}\n\nconst {\n ComponentContext,\n PropsContext: ModalPropsContext,\n useComponentContext,\n usePropsContext: useModalPropsContext,\n withContext,\n withProvider,\n} = createSlotComponent<ModalRootProps, ModalStyle, ComponentContext>(\n \"modal\",\n modalStyle,\n)\n\nexport { ModalPropsContext, useModalPropsContext }\n\n/**\n * `Modal` is a component that is displayed over the main content to focus the user's attention solely on the information.\n *\n * @see https://yamada-ui.com/docs/components/modal\n */\nexport const ModalRoot = withProvider<\"div\", ModalRootProps>(\n ({\n allowPinchZoom = false,\n animationScheme = \"scale\",\n autoFocus,\n blockScrollOnMount = true,\n body,\n cancel,\n children,\n duration,\n finalFocusRef,\n footer,\n header,\n initialFocusRef,\n lockFocusAcrossFrames = true,\n middle,\n restoreFocus,\n success,\n title,\n trigger,\n withCloseButton = true,\n withOverlay = true,\n portalProps,\n onCancel,\n onCloseComplete,\n onMiddle,\n onSuccess,\n ...props\n }) => {\n const [omittedChildren, openTrigger, customOverlay] = useSplitChildren(\n children,\n ModalOpenTrigger,\n ModalOverlay,\n )\n const hasChildren = isArray(omittedChildren) && !!omittedChildren.length\n const { open, getRootProps, ...rest } = useModal(props)\n const customOpenTrigger = trigger ? (\n <ModalOpenTrigger>{trigger}</ModalOpenTrigger>\n ) : null\n const context = useMemo(\n () => ({\n animationScheme,\n duration,\n open,\n withCloseButton,\n ...rest,\n }),\n [animationScheme, duration, open, withCloseButton, rest],\n )\n\n return (\n <ComponentContext value={context}>\n {openTrigger ?? customOpenTrigger}\n\n <AnimatePresence onExitComplete={onCloseComplete}>\n {open ? (\n <Portal {...portalProps}>\n <FocusLock\n autoFocus={autoFocus}\n finalFocusRef={finalFocusRef}\n initialFocusRef={initialFocusRef}\n lockFocusAcrossFrames={lockFocusAcrossFrames}\n restoreFocus={restoreFocus}\n >\n <RemoveScroll\n allowPinchZoom={allowPinchZoom}\n enabled={blockScrollOnMount}\n forwardProps\n >\n <styled.div {...getRootProps()}>\n {customOverlay ?? (withOverlay ? <ModalOverlay /> : null)}\n\n {hasChildren ? (\n omittedChildren\n ) : (\n <ShorthandModalContent\n body={body}\n cancel={cancel}\n footer={footer}\n header={header}\n middle={middle}\n success={success}\n title={title}\n onCancel={onCancel}\n onMiddle={onMiddle}\n onSuccess={onSuccess}\n />\n )}\n </styled.div>\n </RemoveScroll>\n </FocusLock>\n </Portal>\n ) : null}\n </AnimatePresence>\n </ComponentContext>\n )\n },\n \"root\",\n)()\n\nexport interface ModalOpenTriggerProps extends HTMLStyledProps<\"button\"> {}\n\nexport const ModalOpenTrigger = withContext<\"button\", ModalOpenTriggerProps>(\n \"button\",\n { name: \"OpenTrigger\", slot: [\"trigger\", \"open\"] },\n)(undefined, (props) => {\n const { getOpenTriggerProps } = useComponentContext()\n\n return { asChild: true, ...getOpenTriggerProps(props) }\n})\n\nexport interface ModalCloseTriggerProps extends HTMLStyledProps<\"button\"> {}\n\nexport const ModalCloseTrigger = withContext<\"button\", ModalCloseTriggerProps>(\n \"button\",\n { name: \"CloseTrigger\", slot: [\"trigger\", \"close\"] },\n)(undefined, (props) => {\n const { getCloseTriggerProps } = useComponentContext()\n\n return { asChild: true, ...getCloseTriggerProps(props) }\n})\n\nexport interface ModalCloseButtonProps extends CloseButtonProps {}\n\nexport const ModalCloseButton = withContext<\"button\", ModalCloseButtonProps>(\n CloseButton,\n \"closeButton\",\n)(undefined, (props) => {\n const { getCloseButtonProps } = useComponentContext()\n\n return { ...getCloseButtonProps(props) }\n})\n\nexport interface ModalOverlayProps extends HTMLMotionProps {}\n\nexport const ModalOverlay = withContext<\"div\", ModalOverlayProps>((props) => {\n const {\n animationScheme,\n duration: durationProp,\n getOverlayProps,\n } = useComponentContext()\n const duration = useValue(durationProp)\n\n return (\n <motion.div\n custom={{ duration }}\n {...(animationScheme !== \"none\"\n ? {\n animate: \"enter\",\n exit: \"exit\",\n initial: \"exit\",\n variants: fadeVariants,\n }\n : {})}\n {...cast<HTMLMotionProps>(getOverlayProps(cast<HTMLProps>(props)))}\n />\n )\n}, \"overlay\")()\n\nexport interface ModalContentProps\n extends Omit<HTMLMotionProps<\"section\">, \"children\">, PropsWithChildren {}\n\nexport const ModalContent = withContext<\"section\", ModalContentProps>(\n ({ children, ...rest }) => {\n const { animationScheme, duration, withCloseButton, getContentProps } =\n useComponentContext()\n const [omittedChildren, customCloseButton] = useSplitChildren(\n children,\n ModalCloseButton,\n )\n const popupAnimationProps = usePopupAnimationProps({\n animationScheme,\n duration,\n })\n\n return (\n <motion.section\n {...popupAnimationProps}\n {...cast<HTMLMotionPropsWithoutAs<\"section\">>(\n getContentProps(cast<HTMLProps<\"section\">>(rest)),\n )}\n >\n {customCloseButton ?? (withCloseButton ? <ModalCloseButton /> : null)}\n\n {omittedChildren}\n </motion.section>\n )\n },\n \"content\",\n)()\n\ninterface ShorthandModalContentProps {\n /**\n * The modal body to use.\n */\n body?: ModalBodyProps | ReactNode\n /**\n * The modal cancel button to use.\n */\n cancel?: ButtonProps | ReactNode\n /**\n * The modal footer to use.\n */\n footer?: ModalFooterProps | ReactNode\n /**\n * The modal header to use.\n */\n header?: ModalHeaderProps | ReactNode\n /**\n * The modal middle button to use.\n */\n middle?: ButtonProps | ReactNode\n /**\n * The modal success button to use.\n */\n success?: ButtonProps | ReactNode\n /**\n * The modal title to use.\n */\n title?: ModalTitleProps | ReactNode\n /**\n * The callback invoked when cancel button clicked.\n */\n onCancel?: (onClose: () => void) => void\n /**\n * The callback invoked when middle button clicked.\n */\n onMiddle?: (onClose: () => void) => void\n /**\n * The callback invoked when success button clicked.\n */\n onSuccess?: (onClose: () => void) => void\n}\n\nexport const ShorthandModalContent: FC<ShorthandModalContentProps> = ({\n body,\n cancel,\n footer,\n header,\n middle,\n success,\n title,\n onCancel,\n onMiddle,\n onSuccess,\n}) => {\n const { onClose } = useComponentContext()\n const customHeader = wrapOrPassProps(ModalHeader, header)\n const customTitle = wrapOrPassProps(ModalTitle, title)\n const customBody = wrapOrPassProps(ModalBody, body)\n const customFooter = wrapOrPassProps(ModalFooter, footer)\n const customCancel = wrapOrPassProps(Button, cancel, {\n colorScheme: \"mono\",\n variant: \"ghost\",\n onClick: () => (onCancel ? onCancel(onClose) : onClose()),\n })\n const customMiddle = wrapOrPassProps(Button, middle, {\n colorScheme: \"secondary\",\n onClick: () => (onMiddle ? onMiddle(onClose) : onClose()),\n })\n const customSuccess = wrapOrPassProps(Button, success, {\n colorScheme: \"primary\",\n onClick: () => (onSuccess ? onSuccess(onClose) : onClose()),\n })\n\n return (\n <ModalContent>\n {customHeader ??\n (customTitle ? <ModalHeader>{customTitle}</ModalHeader> : null)}\n {customBody}\n {customFooter ??\n (customCancel || customMiddle || customSuccess ? (\n <ModalFooter>\n {customCancel}\n {customMiddle}\n {customSuccess}\n </ModalFooter>\n ) : null)}\n </ModalContent>\n )\n}\n\nexport interface ModalHeaderProps extends HTMLStyledProps<\"header\"> {}\n\nexport const ModalHeader = withContext<\"header\", ModalHeaderProps>(\n \"header\",\n \"header\",\n)(undefined, (props) => {\n const { getHeaderProps } = useComponentContext()\n\n return { ...getHeaderProps(props) }\n})\n\nexport interface ModalTitleProps extends HTMLStyledProps<\"h2\"> {}\n\nexport const ModalTitle = withContext<\"h2\", ModalTitleProps>(\"h2\", \"title\")(\n undefined,\n (props) => {\n const { getTitleProps } = useComponentContext()\n\n return { ...getTitleProps(props) }\n },\n)\n\nexport interface ModalBodyProps extends HTMLStyledProps {}\n\nexport const ModalBody = withContext<\"div\", ModalBodyProps>(\"div\", \"body\")(\n undefined,\n (props) => {\n const { getBodyProps } = useComponentContext()\n\n return { ...getBodyProps(props) }\n },\n)\n\nexport interface ModalFooterProps extends HTMLStyledProps<\"footer\"> {}\n\nexport const ModalFooter = withContext<\"footer\", ModalFooterProps>(\n \"footer\",\n \"footer\",\n)(undefined, (props) => {\n const { getFooterProps } = useComponentContext()\n\n return { ...getFooterProps(props) }\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsFA,MAAM,EACJ,kBACA,cAAc,mBACd,qBACA,iBAAiB,sBACjB,aACA,iBACE,oBACF,SACA,WACD;;;;;;AASD,MAAa,YAAY,cACtB,EACC,iBAAiB,OACjB,kBAAkB,SAClB,WACA,qBAAqB,MACrB,MACA,QACA,UACA,UACA,eACA,QACA,QACA,iBACA,wBAAwB,MACxB,QACA,cACA,SACA,OACA,SACA,kBAAkB,MAClB,cAAc,MACd,aACA,UACA,iBACA,UACA,WACA,GAAG,YACC;CACJ,MAAM,CAAC,iBAAiB,aAAa,iBAAiB,iBACpD,UACA,kBACA,aACD;CACD,MAAM,yCAAsB,gBAAgB,IAAI,CAAC,CAAC,gBAAgB;CAClE,MAAM,EAAE,MAAM,cAAc,GAAG,SAAS,SAAS,MAAM;CACvD,MAAM,oBAAoB,UACxB,oBAAC,8BAAkB,UAA2B,GAC5C;AAYJ,QACE,qBAAC;EAAiB,OAZJ,eACP;GACL;GACA;GACA;GACA;GACA,GAAG;GACJ,GACD;GAAC;GAAiB;GAAU;GAAM;GAAiB;GAAK,CACzD;aAII,eAAe,mBAEhB,oBAAC;GAAgB,gBAAgB;aAC9B,OACC,oBAAC;IAAO,GAAI;cACV,oBAAC;KACY;KACI;KACE;KACM;KACT;eAEd,oBAAC;MACiB;MAChB,SAAS;MACT;gBAEA,qBAAC,OAAO;OAAI,GAAI,cAAc;kBAC3B,kBAAkB,cAAc,oBAAC,iBAAe,GAAG,OAEnD,cACC,kBAEA,oBAAC;QACO;QACE;QACA;QACA;QACA;QACC;QACF;QACG;QACA;QACC;SACX;QAEO;OACA;MACL;KACL,GACP;IACY;GACD;GAGvB,OACD,EAAE;AAIH,MAAa,mBAAmB,YAC9B,UACA;CAAE,MAAM;CAAe,MAAM,CAAC,WAAW,OAAO;CAAE,CACnD,CAAC,SAAY,UAAU;CACtB,MAAM,EAAE,wBAAwB,qBAAqB;A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AM,cAAc,gBAAgB,YAAY,MAAM;CACtD,MAAM,aAAa,gBAAgB,WAAW,KAAK;CACnD,MAAM,eAAe,gBAAgB,aAAa,OAAO;CACzD,MAAM,eAAe,gBAAgB,QAAQ,QAAQ;EACnD,aAAa;EACb,SAAS;EACT,eAAgB,WAAW,SAAS,QAAQ,GAAG,SAAS;EACzD,CAAC;CACF,MAAM,eAAe,gBAAgB,QAAQ,QAAQ;EACnD,aAAa;EACb,eAAgB,WAAW,SAAS,QAAQ,GAAG,SAAS;EACzD,CAAC;CACF,MAAM,gBAAgB,gBAAgB,QAAQ,SAAS;EACrD,aAAa;EACb,eAAgB,YAAY,UAAU,QAAQ,GAAG,SAAS;EAC3D,CAAC;AAEF,QACE,qBAAC;EACE,iBACE,cAAc,oBAAC,yBAAa,cAA0B,GAAG;EAC3D;EACA,iBACE,gBAAgB,gBAAgB,gBAC/B,qBAAC;GACE;GACA;GACA;MACW,GACZ;KACO;;AAMnB,MAAa,cAAc,YACzB,UACA,SACD,CAAC,SAAY,UAAU;CACtB,MAAM,EAAE,mBAAmB,qBAAqB;AAEhD,QAAO,EAAE,GAAG,eAAe,MAAM,EAAE;EACnC;AAIF,MAAa,aAAa,YAAmC,MAAM,QAAQ,CACzE,SACC,UAAU;CACT,MAAM,EAAE,kBAAkB,qBAAqB;AAE/C,QAAO,EAAE,GAAG,cAAc,MAAM,EAAE;EAErC;AAID,MAAa,YAAY,YAAmC,OAAO,OAAO,CACxE,SACC,UAAU;CACT,MAAM,EAAE,iBAAiB,qBAAqB;AAE9C,QAAO,EAAE,GAAG,aAAa,MAAM,EAAE;EAEpC;AAID,MAAa,cAAc,YACzB,UACA,SACD,CAAC,SAAY,UAAU;CACtB,MAAM,EAAE,mBAAmB,qBAAqB;AAEhD,QAAO,EAAE,GAAG,eAAe,MAAM,EAAE;EACnC"}
@@ -18,8 +18,10 @@ const useModal = ({ closeOnEsc = true, closeOnOverlay = true, defaultOpen, open:
18
18
  const { t } = useI18n("modal");
19
19
  const onKeyDown = useCallback((ev) => {
20
20
  if (ev.key !== "Escape") return;
21
- ev.stopPropagation();
22
- if (closeOnEsc) onClose();
21
+ if (closeOnEsc) {
22
+ ev.stopPropagation();
23
+ onClose();
24
+ }
23
25
  onEsc?.();
24
26
  }, [
25
27
  closeOnEsc,
@@ -1 +1 @@
1
- {"version":3,"file":"use-modal.js","names":["getRootProps: PropGetter","getOverlayProps: PropGetter","getOpenTriggerProps: PropGetter<\"button\">","getCloseTriggerProps: PropGetter<\"button\">","getCloseButtonProps: PropGetter<\"button\">","getContentProps: PropGetter<\"section\">","getHeaderProps: PropGetter<\"header\">","getTitleProps: PropGetter<\"h2\">"],"sources":["../../../../src/components/modal/use-modal.ts"],"sourcesContent":["import type { KeyboardEvent } from \"react\"\nimport type { HTMLProps, PropGetter } from \"../../core\"\nimport type { UseDisclosureProps } from \"../../hooks/use-disclosure\"\nimport { useCallback } from \"react\"\nimport { useDisclosure } from \"../../hooks/use-disclosure\"\nimport { useI18n } from \"../../providers/i18n-provider\"\nimport { cx, handlerAll, useIds } from \"../../utils\"\n\nexport interface UseModalProps\n extends HTMLProps, Omit<UseDisclosureProps, \"timing\"> {\n /**\n * If `true`, the modal will close when the `Esc` key is pressed.\n *\n * @default true\n */\n closeOnEsc?: boolean\n /**\n * If `true`, the modal will close when the overlay is clicked.\n *\n * @default true\n */\n closeOnOverlay?: boolean\n /**\n * Callback invoked when the escape key is pressed and focus is within modal.\n */\n onEsc?: () => void\n}\n\nexport const useModal = ({\n closeOnEsc = true,\n closeOnOverlay = true,\n defaultOpen,\n open: openProp,\n onClose: onCloseProp,\n onEsc,\n onOpen: onOpenProp,\n ...rest\n}: UseModalProps = {}) => {\n const { open, onClose, onOpen } = useDisclosure({\n defaultOpen,\n open: openProp,\n onClose: onCloseProp,\n onOpen: onOpenProp,\n })\n const [contentId, titleId, bodyId] = useIds()\n const { t } = useI18n(\"modal\")\n\n const onKeyDown = useCallback(\n (ev: KeyboardEvent) => {\n if (ev.key !== \"Escape\") return\n\n ev.stopPropagation()\n\n if (closeOnEsc) onClose()\n\n onEsc?.()\n },\n [closeOnEsc, onClose, onEsc],\n )\n\n const getRootProps: PropGetter = useCallback(\n (props) => ({\n ...rest,\n ...props,\n }),\n [rest],\n )\n\n const getOverlayProps: PropGetter = useCallback(\n (props = {}) => ({\n \"aria-hidden\": \"true\",\n ...props,\n onClick: handlerAll(props.onClick, (ev) => {\n ev.stopPropagation()\n\n if (closeOnOverlay) onClose()\n }),\n }),\n [closeOnOverlay, onClose],\n )\n\n const getOpenTriggerProps: PropGetter<\"button\"> = useCallback(\n (props = {}) => ({\n \"aria-controls\": open ? contentId : undefined,\n \"aria-expanded\": open,\n \"aria-haspopup\": \"dialog\",\n \"aria-label\": t(\"Open modal\"),\n ...props,\n onClick: handlerAll(props.onClick, onOpen),\n }),\n [contentId, onOpen, open, t],\n )\n\n const getCloseTriggerProps: PropGetter<\"button\"> = useCallback(\n (props = {}) => ({\n \"aria-label\": t(\"Close modal\"),\n ...props,\n onClick: handlerAll(props.onClick, onClose),\n }),\n [onClose, t],\n )\n\n const getCloseButtonProps: PropGetter<\"button\"> = useCallback(\n (props = {}) => ({\n \"aria-label\": t(\"Close modal\"),\n ...props,\n onClick: handlerAll(props.onClick, onClose),\n }),\n [onClose, t],\n )\n\n const getContentProps: PropGetter<\"section\"> = useCallback(\n ({\n \"aria-describedby\": ariaDescribedby,\n \"aria-labelledby\": ariaLabelledby,\n ...props\n } = {}) => ({\n id: contentId,\n \"aria-describedby\": cx(ariaDescribedby, bodyId),\n \"aria-labelledby\": cx(ariaLabelledby, titleId),\n \"aria-modal\": \"true\",\n role: \"dialog\",\n ...props,\n onKeyDown: handlerAll(props.onKeyDown, onKeyDown),\n }),\n [bodyId, contentId, onKeyDown, titleId],\n )\n\n const getHeaderProps: PropGetter<\"header\"> = useCallback(\n (props) => ({\n ...props,\n }),\n [],\n )\n\n const getTitleProps: PropGetter<\"h2\"> = useCallback(\n (props) => ({\n id: titleId,\n ...props,\n }),\n [titleId],\n )\n\n const getBodyProps: PropGetter = useCallback(\n (props) => ({\n id: bodyId,\n ...props,\n }),\n [bodyId],\n )\n\n const getFooterProps: PropGetter<\"footer\"> = useCallback(\n (props) => ({\n ...props,\n }),\n [],\n )\n\n return {\n open,\n getBodyProps,\n getCloseButtonProps,\n getCloseTriggerProps,\n getContentProps,\n getFooterProps,\n getHeaderProps,\n getOpenTriggerProps,\n getOverlayProps,\n getRootProps,\n getTitleProps,\n onClose,\n onOpen,\n }\n}\n\nexport type UseModalReturn = ReturnType<typeof useModal>\n"],"mappings":";;;;;;;;;AA4BA,MAAa,YAAY,EACvB,aAAa,MACb,iBAAiB,MACjB,aACA,MAAM,UACN,SAAS,aACT,OACA,QAAQ,YACR,GAAG,SACc,EAAE,KAAK;CACxB,MAAM,EAAE,MAAM,SAAS,WAAW,cAAc;EAC9C;EACA,MAAM;EACN,SAAS;EACT,QAAQ;EACT,CAAC;CACF,MAAM,CAAC,WAAW,SAAS,UAAU,QAAQ;CAC7C,MAAM,EAAE,MAAM,QAAQ,QAAQ;CAE9B,MAAM,YAAY,aACf,OAAsB;AACrB,MAAI,GAAG,QAAQ,SAAU;AAEzB,KAAG,iBAAiB;AAEpB,MAAI,WAAY,UAAS;AAEzB,WAAS;IAEX;EAAC;EAAY;EAAS;EAAM,CAC7B;CAED,MAAMA,eAA2B,aAC9B,WAAW;EACV,GAAG;EACH,GAAG;EACJ,GACD,CAAC,KAAK,CACP;CAED,MAAMC,kBAA8B,aACjC,QAAQ,EAAE,MAAM;EACf,eAAe;EACf,GAAG;EACH,uCAAoB,MAAM,UAAU,OAAO;AACzC,MAAG,iBAAiB;AAEpB,OAAI,eAAgB,UAAS;IAC7B;EACH,GACD,CAAC,gBAAgB,QAAQ,CAC1B;CAED,MAAMC,sBAA4C,aAC/C,QAAQ,EAAE,MAAM;EACf,iBAAiB,OAAO,YAAY;EACpC,iBAAiB;EACjB,iBAAiB;EACjB,cAAc,EAAE,aAAa;EAC7B,GAAG;EACH,uCAAoB,MAAM,SAAS,OAAO;EAC3C,GACD;EAAC;EAAW;EAAQ;EAAM;EAAE,CAC7B;CAED,MAAMC,uBAA6C,aAChD,QAAQ,EAAE,MAAM;EACf,cAAc,EAAE,cAAc;EAC9B,GAAG;EACH,uCAAoB,MAAM,SAAS,QAAQ;EAC5C,GACD,CAAC,SAAS,EAAE,CACb;CAED,MAAMC,sBAA4C,aAC/C,QAAQ,EAAE,MAAM;EACf,cAAc,EAAE,cAAc;EAC9B,GAAG;EACH,uCAAoB,MAAM,SAAS,QAAQ;EAC5C,GACD,CAAC,SAAS,EAAE,CACb;CAED,MAAMC,kBAAyC,aAC5C,EACC,oBAAoB,iBACpB,mBAAmB,gBACnB,GAAG,UACD,EAAE,MAAM;EACV,IAAI;EACJ,0CAAuB,iBAAiB,OAAO;EAC/C,yCAAsB,gBAAgB,QAAQ;EAC9C,cAAc;EACd,MAAM;EACN,GAAG;EACH,yCAAsB,MAAM,WAAW,UAAU;EAClD,GACD;EAAC;EAAQ;EAAW;EAAW;EAAQ,CACxC;CAED,MAAMC,iBAAuC,aAC1C,WAAW,EACV,GAAG,OACJ,GACD,EAAE,CACH;CAED,MAAMC,gBAAkC,aACrC,WAAW;EACV,IAAI;EACJ,GAAG;EACJ,GACD,CAAC,QAAQ,CACV;AAiBD,QAAO;EACL;EACA,cAjB+B,aAC9B,WAAW;GACV,IAAI;GACJ,GAAG;GACJ,GACD,CAAC,OAAO,CACT;EAYC;EACA;EACA;EACA,gBAb2C,aAC1C,WAAW,EACV,GAAG,OACJ,GACD,EAAE,CACH;EASC;EACA;EACA;EACA;EACA;EACA;EACA;EACD"}
1
+ {"version":3,"file":"use-modal.js","names":["getRootProps: PropGetter","getOverlayProps: PropGetter","getOpenTriggerProps: PropGetter<\"button\">","getCloseTriggerProps: PropGetter<\"button\">","getCloseButtonProps: PropGetter<\"button\">","getContentProps: PropGetter<\"section\">","getHeaderProps: PropGetter<\"header\">","getTitleProps: PropGetter<\"h2\">"],"sources":["../../../../src/components/modal/use-modal.ts"],"sourcesContent":["import type { KeyboardEvent } from \"react\"\nimport type { HTMLProps, PropGetter } from \"../../core\"\nimport type { UseDisclosureProps } from \"../../hooks/use-disclosure\"\nimport { useCallback } from \"react\"\nimport { useDisclosure } from \"../../hooks/use-disclosure\"\nimport { useI18n } from \"../../providers/i18n-provider\"\nimport { cx, handlerAll, useIds } from \"../../utils\"\n\nexport interface UseModalProps\n extends HTMLProps, Omit<UseDisclosureProps, \"timing\"> {\n /**\n * If `true`, the modal will close when the `Esc` key is pressed.\n *\n * @default true\n */\n closeOnEsc?: boolean\n /**\n * If `true`, the modal will close when the overlay is clicked.\n *\n * @default true\n */\n closeOnOverlay?: boolean\n /**\n * Callback invoked when the escape key is pressed and focus is within modal.\n */\n onEsc?: () => void\n}\n\nexport const useModal = ({\n closeOnEsc = true,\n closeOnOverlay = true,\n defaultOpen,\n open: openProp,\n onClose: onCloseProp,\n onEsc,\n onOpen: onOpenProp,\n ...rest\n}: UseModalProps = {}) => {\n const { open, onClose, onOpen } = useDisclosure({\n defaultOpen,\n open: openProp,\n onClose: onCloseProp,\n onOpen: onOpenProp,\n })\n const [contentId, titleId, bodyId] = useIds()\n const { t } = useI18n(\"modal\")\n\n const onKeyDown = useCallback(\n (ev: KeyboardEvent) => {\n if (ev.key !== \"Escape\") return\n\n if (closeOnEsc) {\n ev.stopPropagation()\n onClose()\n }\n\n onEsc?.()\n },\n [closeOnEsc, onClose, onEsc],\n )\n\n const getRootProps: PropGetter = useCallback(\n (props) => ({\n ...rest,\n ...props,\n }),\n [rest],\n )\n\n const getOverlayProps: PropGetter = useCallback(\n (props = {}) => ({\n \"aria-hidden\": \"true\",\n ...props,\n onClick: handlerAll(props.onClick, (ev) => {\n ev.stopPropagation()\n\n if (closeOnOverlay) onClose()\n }),\n }),\n [closeOnOverlay, onClose],\n )\n\n const getOpenTriggerProps: PropGetter<\"button\"> = useCallback(\n (props = {}) => ({\n \"aria-controls\": open ? contentId : undefined,\n \"aria-expanded\": open,\n \"aria-haspopup\": \"dialog\",\n \"aria-label\": t(\"Open modal\"),\n ...props,\n onClick: handlerAll(props.onClick, onOpen),\n }),\n [contentId, onOpen, open, t],\n )\n\n const getCloseTriggerProps: PropGetter<\"button\"> = useCallback(\n (props = {}) => ({\n \"aria-label\": t(\"Close modal\"),\n ...props,\n onClick: handlerAll(props.onClick, onClose),\n }),\n [onClose, t],\n )\n\n const getCloseButtonProps: PropGetter<\"button\"> = useCallback(\n (props = {}) => ({\n \"aria-label\": t(\"Close modal\"),\n ...props,\n onClick: handlerAll(props.onClick, onClose),\n }),\n [onClose, t],\n )\n\n const getContentProps: PropGetter<\"section\"> = useCallback(\n ({\n \"aria-describedby\": ariaDescribedby,\n \"aria-labelledby\": ariaLabelledby,\n ...props\n } = {}) => ({\n id: contentId,\n \"aria-describedby\": cx(ariaDescribedby, bodyId),\n \"aria-labelledby\": cx(ariaLabelledby, titleId),\n \"aria-modal\": \"true\",\n role: \"dialog\",\n ...props,\n onKeyDown: handlerAll(props.onKeyDown, onKeyDown),\n }),\n [bodyId, contentId, onKeyDown, titleId],\n )\n\n const getHeaderProps: PropGetter<\"header\"> = useCallback(\n (props) => ({\n ...props,\n }),\n [],\n )\n\n const getTitleProps: PropGetter<\"h2\"> = useCallback(\n (props) => ({\n id: titleId,\n ...props,\n }),\n [titleId],\n )\n\n const getBodyProps: PropGetter = useCallback(\n (props) => ({\n id: bodyId,\n ...props,\n }),\n [bodyId],\n )\n\n const getFooterProps: PropGetter<\"footer\"> = useCallback(\n (props) => ({\n ...props,\n }),\n [],\n )\n\n return {\n open,\n getBodyProps,\n getCloseButtonProps,\n getCloseTriggerProps,\n getContentProps,\n getFooterProps,\n getHeaderProps,\n getOpenTriggerProps,\n getOverlayProps,\n getRootProps,\n getTitleProps,\n onClose,\n onOpen,\n }\n}\n\nexport type UseModalReturn = ReturnType<typeof useModal>\n"],"mappings":";;;;;;;;;AA4BA,MAAa,YAAY,EACvB,aAAa,MACb,iBAAi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C,EACC,oBAAoB,iBACpB,mBAAmB,gBACnB,GAAG,UACD,EAAE,MAAM;EACV,IAAI;EACJ,0CAAuB,iBAAiB,OAAO;EAC/C,yCAAsB,gBAAgB,QAAQ;EAC9C,cAAc;EACd,MAAM;EACN,GAAG;EACH,yCAAsB,MAAM,WAAW,UAAU;EAClD,GACD;EAAC;EAAQ;EAAW;EAAW;EAAQ,CACxC;CAED,MAAMC,iBAAuC,aAC1C,WAAW,EACV,GAAG,OACJ,GACD,EAAE,CACH;CAED,MAAMC,gBAAkC,aACrC,WAAW;EACV,IAAI;EACJ,GAAG;EACJ,GACD,CAAC,QAAQ,CACV;AAiBD,QAAO;EACL;EACA,cAjB+B,aAC9B,WAAW;GACV,IAAI;GACJ,GAAG;GACJ,GACD,CAAC,OAAO,CACT;EAYC;EACA;EACA;EACA,gBAb2C,aAC1C,WAAW,EACV,GAAG,OACJ,GACD,EAAE,CACH;EASC;EACA;EACA;EACA;EACA;EACA;EACA;EACD"}
@@ -316,10 +316,12 @@ const SidebarMenuButton = withContext("button", ["menu", "button"])(void 0, (pro
316
316
  const { mode } = useComponentContext();
317
317
  const { menuProps } = useSidePanelComponentContext();
318
318
  const offcanvas = mode === "offcanvas";
319
+ const { disabled, ...rest } = mergeProps(menuProps, props)();
319
320
  return {
320
321
  "data-menu": "",
321
- ...mergeProps(menuProps, props)(),
322
- tabIndex: !offcanvas || open ? 0 : -1
322
+ disabled,
323
+ ...rest,
324
+ tabIndex: (!offcanvas || open) && !disabled ? 0 : -1
323
325
  };
324
326
  });
325
327
  const SidebarItem = withContext(({ animated: animatedProp, asyncChildren: asyncChildrenProp, children: childrenProp, endElement, indicator: indicatorProp, items, label, loadingScheme, render, startElement, contentProps, endElementProps, indicatorProps, labelProps, linkProps, startElementProps, tooltipProps, triggerProps, ...rest }) => {
@@ -353,7 +355,7 @@ const SidebarItem = withContext(({ animated: animatedProp, asyncChildren: asyncC
353
355
  children: computedChildren
354
356
  });
355
357
  const animated = animatedProp ?? componentContext.animated ?? true;
356
- const tabIndex = offcanvas ? open && expanded ? 0 : -1 : expanded ? 0 : -1;
358
+ const tabIndex = offcanvas ? open && expanded && !disabled ? 0 : -1 : expanded && !disabled ? 0 : -1;
357
359
  const callbackProps = useMemo(() => ({
358
360
  disabled,
359
361
  expanded: groupOpen