@box/blueprint-web 19.5.0 → 20.0.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 (208) hide show
  1. package/THIRD_PARTY_LICENSES +119 -0
  2. package/dist/lib-esm/accordion/accordion.js +14 -6
  3. package/dist/lib-esm/accordion/accordion.module.js +1 -1
  4. package/dist/lib-esm/accordion/types.d.ts +1 -1
  5. package/dist/lib-esm/blueprint-configuration-context/consts.d.ts +1 -1
  6. package/dist/lib-esm/blueprint-configuration-context/consts.js +1 -1
  7. package/dist/lib-esm/checkbox/checkbox-item.js +3 -3
  8. package/dist/lib-esm/checkbox/types.d.ts +1 -1
  9. package/dist/lib-esm/collapsible/collapsible-section.js +5 -5
  10. package/dist/lib-esm/collapsible/types.d.ts +1 -1
  11. package/dist/lib-esm/combobox-group/combobox-group-combobox.js +1 -1
  12. package/dist/lib-esm/components.css +400 -280
  13. package/dist/lib-esm/date-picker/date-picker.js +8 -7
  14. package/dist/lib-esm/guided-tooltip/guided-tooltip.js +7 -7
  15. package/dist/lib-esm/guided-tooltip/types.d.ts +1 -1
  16. package/dist/lib-esm/index.css +400 -280
  17. package/dist/lib-esm/modal/alert-modal.types.d.ts +1 -1
  18. package/dist/lib-esm/modal/modal-close.js +2 -2
  19. package/dist/lib-esm/modal/modal-content.d.ts +1 -1
  20. package/dist/lib-esm/modal/modal-content.js +4 -4
  21. package/dist/lib-esm/modal/modal-description.js +2 -2
  22. package/dist/lib-esm/modal/modal-title.js +2 -2
  23. package/dist/lib-esm/modal/modal-trigger.js +2 -2
  24. package/dist/lib-esm/modal/modal.d.ts +1 -1
  25. package/dist/lib-esm/modal/modal.js +1 -1
  26. package/dist/lib-esm/modal/types.d.ts +1 -1
  27. package/dist/lib-esm/navigation-menu/index.d.ts +4 -2
  28. package/dist/lib-esm/navigation-menu/navigation-menu-item.d.ts +1 -1
  29. package/dist/lib-esm/navigation-menu/navigation-menu-trigger.d.ts +3 -1
  30. package/dist/lib-esm/primitives/chips/chip.d.ts +1 -1
  31. package/dist/lib-esm/primitives/chips/chip.js +2 -2
  32. package/dist/lib-esm/primitives/chips/chips-group.js +2 -2
  33. package/dist/lib-esm/primitives/chips/filter-chip/filter-chip-button.d.ts +1 -1
  34. package/dist/lib-esm/primitives/chips/filter-chip/filter-chip.d.ts +1 -1
  35. package/dist/lib-esm/primitives/chips/filter-chip/filter-combo-chip.d.ts +2 -2
  36. package/dist/lib-esm/primitives/chips/filter-chip/filter-trigger-chip.d.ts +1 -1
  37. package/dist/lib-esm/primitives/chips/filter-chip/index.d.ts +5 -5
  38. package/dist/lib-esm/primitives/chips/types.d.ts +1 -1
  39. package/dist/lib-esm/primitives/context-menu/context-menu-item.d.ts +2 -2
  40. package/dist/lib-esm/primitives/context-menu/context-menu-item.js +2 -2
  41. package/dist/lib-esm/primitives/context-menu/context-menu-menu-content.d.ts +1 -1
  42. package/dist/lib-esm/primitives/context-menu/context-menu-menu-content.js +5 -5
  43. package/dist/lib-esm/primitives/context-menu/context-menu-menu-header.js +3 -10
  44. package/dist/lib-esm/primitives/context-menu/context-menu-menu-root.d.ts +1 -1
  45. package/dist/lib-esm/primitives/context-menu/context-menu-menu-root.js +1 -1
  46. package/dist/lib-esm/primitives/context-menu/context-menu-menu-trigger.d.ts +1 -1
  47. package/dist/lib-esm/primitives/context-menu/context-menu-menu-trigger.js +1 -1
  48. package/dist/lib-esm/primitives/context-menu/context-menu-sub-menu-content.d.ts +1 -1
  49. package/dist/lib-esm/primitives/context-menu/context-menu-sub-menu-content.js +5 -5
  50. package/dist/lib-esm/primitives/context-menu/context-menu-sub-menu-root.d.ts +1 -1
  51. package/dist/lib-esm/primitives/context-menu/context-menu-sub-menu-root.js +1 -1
  52. package/dist/lib-esm/primitives/context-menu/context-menu-sub-menu-trigger.d.ts +2 -2
  53. package/dist/lib-esm/primitives/context-menu/context-menu-sub-menu-trigger.js +1 -1
  54. package/dist/lib-esm/primitives/context-menu/index.d.ts +3 -3
  55. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-checkbox-item.d.ts +2 -2
  56. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-checkbox-item.js +3 -3
  57. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-content.d.ts +1 -1
  58. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-content.js +5 -5
  59. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-group.d.ts +4 -2
  60. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-group.js +2 -2
  61. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-item.d.ts +2 -2
  62. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-item.js +2 -2
  63. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-radio-group.d.ts +2 -2
  64. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-radio-group.js +2 -2
  65. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-radio-select-item.d.ts +2 -2
  66. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-radio-select-item.js +3 -3
  67. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-root.d.ts +1 -1
  68. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-root.js +2 -2
  69. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-sub-header.d.ts +4 -2
  70. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-sub-header.js +2 -2
  71. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-sub-menu-content.d.ts +1 -1
  72. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-sub-menu-content.js +5 -5
  73. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-sub-menu-root.d.ts +1 -1
  74. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-sub-menu-root.js +2 -2
  75. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-sub-menu-trigger.d.ts +2 -2
  76. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-sub-menu-trigger.js +2 -2
  77. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-trigger.d.ts +4 -2
  78. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-trigger.js +2 -2
  79. package/dist/lib-esm/primitives/dropdown-menu/index.d.ts +14 -8
  80. package/dist/lib-esm/primitives/notification/hooks/use-notification-layer.d.ts +15 -0
  81. package/dist/lib-esm/primitives/notification/hooks/use-notification-layer.js +49 -0
  82. package/dist/lib-esm/primitives/notification/notification-provider.js +2 -2
  83. package/dist/lib-esm/primitives/notification/notification.viewport-animated.js +12 -8
  84. package/dist/lib-esm/primitives/notification/notification.viewport.js +5 -1
  85. package/dist/lib-esm/primitives/notification/private-notification-element-animated.js +44 -6
  86. package/dist/lib-esm/primitives/notification/private-notification-element.js +34 -4
  87. package/dist/lib-esm/primitives/popover/index.d.ts +11 -5
  88. package/dist/lib-esm/primitives/popover/popover-anchor.d.ts +4 -2
  89. package/dist/lib-esm/primitives/popover/popover-anchor.js +2 -2
  90. package/dist/lib-esm/primitives/popover/popover-close.d.ts +4 -2
  91. package/dist/lib-esm/primitives/popover/popover-close.js +2 -2
  92. package/dist/lib-esm/primitives/popover/popover-content-container.d.ts +1 -1
  93. package/dist/lib-esm/primitives/popover/popover-content-container.js +3 -3
  94. package/dist/lib-esm/primitives/popover/popover-footer.d.ts +1 -1
  95. package/dist/lib-esm/primitives/popover/popover-main-content.d.ts +1 -1
  96. package/dist/lib-esm/primitives/popover/popover-root.d.ts +1 -1
  97. package/dist/lib-esm/primitives/popover/popover-root.js +2 -2
  98. package/dist/lib-esm/primitives/popover/popover-trigger.d.ts +4 -2
  99. package/dist/lib-esm/primitives/popover/popover-trigger.js +2 -2
  100. package/dist/lib-esm/radio-group/index.d.ts +1 -1
  101. package/dist/lib-esm/radio-group/radio-group.d.ts +1 -1
  102. package/dist/lib-esm/radio-group/radio-group.js +2 -2
  103. package/dist/lib-esm/radio-group/radio-item.js +3 -3
  104. package/dist/lib-esm/radio-group/types.d.ts +1 -1
  105. package/dist/lib-esm/select/select.js +12 -12
  106. package/dist/lib-esm/select/types.d.ts +1 -1
  107. package/dist/lib-esm/select/utils/use-select-exit-animation.d.ts +3 -3
  108. package/dist/lib-esm/select/utils/use-select-exit-animation.js +3 -3
  109. package/dist/lib-esm/side-panel/side-panel-close.js +2 -2
  110. package/dist/lib-esm/side-panel/side-panel-content.js +3 -3
  111. package/dist/lib-esm/side-panel/side-panel-header.js +2 -2
  112. package/dist/lib-esm/side-panel/side-panel-overlay.js +3 -3
  113. package/dist/lib-esm/side-panel/side-panel-trigger.js +2 -2
  114. package/dist/lib-esm/side-panel/side-panel.js +1 -1
  115. package/dist/lib-esm/side-panel/types.d.ts +1 -1
  116. package/dist/lib-esm/small-list-item/small-list.js +8 -0
  117. package/dist/lib-esm/switch/switch-item.js +3 -3
  118. package/dist/lib-esm/switch/types.d.ts +1 -1
  119. package/dist/lib-esm/toolbar/index.d.ts +2 -2
  120. package/dist/lib-esm/toolbar/toolbar-button.js +2 -2
  121. package/dist/lib-esm/toolbar/toolbar-input.js +2 -2
  122. package/dist/lib-esm/toolbar/toolbar-link.js +2 -2
  123. package/dist/lib-esm/toolbar/toolbar-root.js +3 -3
  124. package/dist/lib-esm/toolbar/toolbar-separator.d.ts +1 -1
  125. package/dist/lib-esm/toolbar/toolbar-separator.js +2 -2
  126. package/dist/lib-esm/toolbar/toolbar-text-toggle-item.js +2 -2
  127. package/dist/lib-esm/toolbar/toolbar-toggle-group.d.ts +1 -2
  128. package/dist/lib-esm/toolbar/toolbar-toggle-group.js +2 -2
  129. package/dist/lib-esm/toolbar/toolbar-toggle-item.js +2 -2
  130. package/dist/lib-esm/toolbar/types.d.ts +1 -1
  131. package/dist/lib-esm/tooltip/tooltip.d.ts +1 -1
  132. package/dist/lib-esm/tooltip/tooltip.js +6 -6
  133. package/dist/lib-esm/tooltip/types.d.ts +1 -1
  134. package/dist/lib-esm/util-components/base-grid-list-item/base-grid-list-item.module.js +1 -1
  135. package/dist/lib-esm/utils/TooltipWrapper.d.ts +1 -1
  136. package/dist/lib-esm/utils/radix-compat/accordion.d.ts +45 -0
  137. package/dist/lib-esm/utils/radix-compat/accordion.js +299 -0
  138. package/dist/lib-esm/utils/radix-compat/allow-auto-focus.d.ts +9 -0
  139. package/dist/lib-esm/utils/radix-compat/allow-auto-focus.js +16 -0
  140. package/dist/lib-esm/utils/radix-compat/bubble-input.d.ts +14 -0
  141. package/dist/lib-esm/utils/radix-compat/bubble-input.js +70 -0
  142. package/dist/lib-esm/utils/radix-compat/button-controls.d.ts +9 -0
  143. package/dist/lib-esm/utils/radix-compat/button-controls.js +6 -0
  144. package/dist/lib-esm/utils/radix-compat/checkbox.d.ts +18 -0
  145. package/dist/lib-esm/utils/radix-compat/checkbox.js +131 -0
  146. package/dist/lib-esm/utils/radix-compat/collapsible.d.ts +33 -0
  147. package/dist/lib-esm/utils/radix-compat/collapsible.js +133 -0
  148. package/dist/lib-esm/utils/radix-compat/collection.d.ts +21 -0
  149. package/dist/lib-esm/utils/radix-compat/collection.js +82 -0
  150. package/dist/lib-esm/utils/radix-compat/compose-refs.d.ts +8 -0
  151. package/dist/lib-esm/utils/radix-compat/compose-refs.js +44 -0
  152. package/dist/lib-esm/utils/radix-compat/content-size.d.ts +15 -0
  153. package/dist/lib-esm/utils/radix-compat/content-size.js +61 -0
  154. package/dist/lib-esm/utils/radix-compat/context-menu.d.ts +56 -0
  155. package/dist/lib-esm/utils/radix-compat/context-menu.js +191 -0
  156. package/dist/lib-esm/utils/radix-compat/dialog.d.ts +50 -0
  157. package/dist/lib-esm/utils/radix-compat/dialog.js +367 -0
  158. package/dist/lib-esm/utils/radix-compat/dismiss-marker.d.ts +5 -0
  159. package/dist/lib-esm/utils/radix-compat/dismiss-marker.js +12 -0
  160. package/dist/lib-esm/utils/radix-compat/dismissable.d.ts +34 -0
  161. package/dist/lib-esm/utils/radix-compat/dismissable.js +205 -0
  162. package/dist/lib-esm/utils/radix-compat/dropdown-menu.d.ts +57 -0
  163. package/dist/lib-esm/utils/radix-compat/dropdown-menu.js +187 -0
  164. package/dist/lib-esm/utils/radix-compat/focus-scope-component.d.ts +16 -0
  165. package/dist/lib-esm/utils/radix-compat/focus-scope-component.js +41 -0
  166. package/dist/lib-esm/utils/radix-compat/focus-scope.d.ts +37 -0
  167. package/dist/lib-esm/utils/radix-compat/focus-scope.js +288 -0
  168. package/dist/lib-esm/utils/radix-compat/hide-others.d.ts +6 -0
  169. package/dist/lib-esm/utils/radix-compat/hide-others.js +18 -0
  170. package/dist/lib-esm/utils/radix-compat/index.d.ts +14 -0
  171. package/dist/lib-esm/utils/radix-compat/layers.d.ts +25 -0
  172. package/dist/lib-esm/utils/radix-compat/layers.js +61 -0
  173. package/dist/lib-esm/utils/radix-compat/menu.d.ts +98 -0
  174. package/dist/lib-esm/utils/radix-compat/menu.js +1041 -0
  175. package/dist/lib-esm/utils/radix-compat/popover.d.ts +44 -0
  176. package/dist/lib-esm/utils/radix-compat/popover.js +386 -0
  177. package/dist/lib-esm/utils/radix-compat/popper.d.ts +60 -0
  178. package/dist/lib-esm/utils/radix-compat/popper.js +416 -0
  179. package/dist/lib-esm/utils/radix-compat/portal.d.ts +11 -0
  180. package/dist/lib-esm/utils/radix-compat/portal.js +20 -0
  181. package/dist/lib-esm/utils/radix-compat/presence.d.ts +20 -0
  182. package/dist/lib-esm/utils/radix-compat/presence.js +110 -0
  183. package/dist/lib-esm/utils/radix-compat/radio-group.d.ts +27 -0
  184. package/dist/lib-esm/utils/radix-compat/radio-group.js +189 -0
  185. package/dist/lib-esm/utils/radix-compat/roving-focus.d.ts +35 -0
  186. package/dist/lib-esm/utils/radix-compat/roving-focus.js +237 -0
  187. package/dist/lib-esm/utils/radix-compat/select.d.ts +82 -0
  188. package/dist/lib-esm/utils/radix-compat/select.js +901 -0
  189. package/dist/lib-esm/utils/radix-compat/slot.d.ts +31 -0
  190. package/dist/lib-esm/utils/radix-compat/slot.js +119 -0
  191. package/dist/lib-esm/utils/radix-compat/store-options.d.ts +8 -0
  192. package/dist/lib-esm/utils/radix-compat/store-options.js +10 -0
  193. package/dist/lib-esm/utils/radix-compat/switch.d.ts +16 -0
  194. package/dist/lib-esm/utils/radix-compat/switch.js +97 -0
  195. package/dist/lib-esm/utils/radix-compat/toggle-group.d.ts +41 -0
  196. package/dist/lib-esm/utils/radix-compat/toggle-group.js +195 -0
  197. package/dist/lib-esm/utils/radix-compat/toolbar.d.ts +32 -0
  198. package/dist/lib-esm/utils/radix-compat/toolbar.js +136 -0
  199. package/dist/lib-esm/utils/radix-compat/tooltip.d.ts +59 -0
  200. package/dist/lib-esm/utils/radix-compat/tooltip.js +636 -0
  201. package/dist/lib-esm/utils/radix-compat/typeahead.d.ts +22 -0
  202. package/dist/lib-esm/utils/radix-compat/typeahead.js +64 -0
  203. package/dist/lib-esm/utils/radix-compat/types.d.ts +53 -0
  204. package/dist/lib-esm/utils/radix-compat/viewport-height.d.ts +5 -0
  205. package/dist/lib-esm/utils/radix-compat/viewport-height.js +28 -0
  206. package/dist/lib-esm/utils/radix-compat/visually-hidden.d.ts +2 -0
  207. package/dist/lib-esm/utils/radix-compat/visually-hidden.js +24 -0
  208. package/package.json +8 -19
@@ -0,0 +1,187 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+ import { forwardRef, useRef, useContext, createContext, useId, useCallback, useMemo } from 'react';
3
+ import { composeEventHandlers } from '../composeEventHandlers.js';
4
+ import { useControllableState } from '../useControllableState.js';
5
+ import { useComposedRefs } from './compose-refs.js';
6
+ import * as menu from './menu.js';
7
+ import { Anchor, Content as Content$1, SubContent as SubContent$1, Root as Root$1, Sub as Sub$1 } from './menu.js';
8
+ import { getPopperCssVariables } from './popper.js';
9
+ import { Slot } from './slot.js';
10
+
11
+ const contentCssVariables = getPopperCssVariables('dropdown-menu');
12
+ const DropdownMenuContext = /*#__PURE__*/createContext(null);
13
+ function useDropdownMenuContext(consumerName) {
14
+ const context = useContext(DropdownMenuContext);
15
+ if (!context) {
16
+ throw new Error(`\`${consumerName}\` must be used within \`DropdownMenu\``);
17
+ }
18
+ return context;
19
+ }
20
+ /** Dropdown menu with the Radix API, DOM and keyboard model; its content is an Ariakit popover with `role="menu"`. */
21
+ const Root = props => {
22
+ const {
23
+ children,
24
+ dir,
25
+ open: openProp,
26
+ defaultOpen,
27
+ onOpenChange,
28
+ modal = true
29
+ } = props;
30
+ const triggerRef = useRef(null);
31
+ const triggerId = useId();
32
+ const contentId = useId();
33
+ const [open = false, setOpen] = useControllableState({
34
+ prop: openProp,
35
+ defaultProp: defaultOpen,
36
+ onChange: onOpenChange
37
+ });
38
+ const onOpenToggle = useCallback(() => setOpen(prevOpen => !prevOpen), [setOpen]);
39
+ const onOpenChangeCallback = useCallback(nextOpen => setOpen(nextOpen), [setOpen]);
40
+ const value = useMemo(() => ({
41
+ triggerId,
42
+ triggerRef,
43
+ contentId,
44
+ open,
45
+ onOpenChange: onOpenChangeCallback,
46
+ onOpenToggle,
47
+ modal
48
+ }), [triggerId, contentId, open, onOpenChangeCallback, onOpenToggle, modal]);
49
+ return jsx(DropdownMenuContext.Provider, {
50
+ value: value,
51
+ children: jsx(Root$1, {
52
+ dir: dir,
53
+ modal: modal,
54
+ onOpenChange: onOpenChangeCallback,
55
+ open: open,
56
+ children: children
57
+ })
58
+ });
59
+ };
60
+ Root.displayName = 'DropdownMenu';
61
+ const Trigger = /*#__PURE__*/forwardRef((props, forwardedRef) => {
62
+ const {
63
+ disabled = false,
64
+ asChild,
65
+ ...triggerProps
66
+ } = props;
67
+ const context = useDropdownMenuContext('DropdownMenuTrigger');
68
+ const composedRefs = useComposedRefs(forwardedRef, context.triggerRef);
69
+ const Comp = asChild ? Slot : 'button';
70
+ return jsx(Anchor, {
71
+ asChild: true,
72
+ children: jsx(Comp, {
73
+ "aria-controls": context.open ? context.contentId : undefined,
74
+ "aria-expanded": context.open,
75
+ "aria-haspopup": "menu",
76
+ "data-disabled": disabled ? '' : undefined,
77
+ "data-state": context.open ? 'open' : 'closed',
78
+ disabled: disabled,
79
+ id: context.triggerId,
80
+ type: "button",
81
+ ...triggerProps,
82
+ ref: composedRefs,
83
+ onKeyDown: composeEventHandlers(props.onKeyDown, event => {
84
+ if (disabled) {
85
+ return;
86
+ }
87
+ if (['Enter', ' '].includes(event.key)) {
88
+ context.onOpenToggle();
89
+ }
90
+ if (event.key === 'ArrowDown') {
91
+ context.onOpenChange(true);
92
+ }
93
+ // Prevent the key press from scrolling the window or reaching the first focused item.
94
+ if (['Enter', ' ', 'ArrowDown'].includes(event.key)) {
95
+ event.preventDefault();
96
+ }
97
+ }),
98
+ onPointerDown: composeEventHandlers(props.onPointerDown, event => {
99
+ // Only the primary button opens the menu, and not with Ctrl (macOS right click).
100
+ if (!disabled && event.button === 0 && event.ctrlKey === false) {
101
+ context.onOpenToggle();
102
+ // The trigger doesn't take focus when opening, so the content gets it without competition.
103
+ if (!context.open) {
104
+ event.preventDefault();
105
+ }
106
+ }
107
+ })
108
+ })
109
+ });
110
+ });
111
+ Trigger.displayName = 'DropdownMenuTrigger';
112
+ const {
113
+ Portal
114
+ } = menu;
115
+ const Content = /*#__PURE__*/forwardRef((props, forwardedRef) => {
116
+ const context = useDropdownMenuContext('DropdownMenuContent');
117
+ const hasInteractedOutsideRef = useRef(false);
118
+ return jsx(Content$1, {
119
+ "aria-labelledby": context.triggerId,
120
+ id: context.contentId,
121
+ ...props,
122
+ ref: forwardedRef,
123
+ onCloseAutoFocus: composeEventHandlers(props.onCloseAutoFocus, event => {
124
+ if (!hasInteractedOutsideRef.current) {
125
+ context.triggerRef.current?.focus();
126
+ }
127
+ hasInteractedOutsideRef.current = false;
128
+ // Always prevent auto focus because we either focus manually or want user agent focus.
129
+ event.preventDefault();
130
+ }),
131
+ onInteractOutside: composeEventHandlers(props.onInteractOutside, event => {
132
+ const {
133
+ originalEvent
134
+ } = event.detail;
135
+ const ctrlLeftClick = originalEvent.button === 0 && originalEvent.ctrlKey === true;
136
+ const isRightClick = originalEvent.button === 2 || ctrlLeftClick;
137
+ if (!context.modal || isRightClick) {
138
+ hasInteractedOutsideRef.current = true;
139
+ }
140
+ }),
141
+ style: {
142
+ ...props.style,
143
+ ...contentCssVariables
144
+ }
145
+ });
146
+ });
147
+ Content.displayName = 'DropdownMenuContent';
148
+ const {
149
+ Group,
150
+ Label,
151
+ Item,
152
+ CheckboxItem,
153
+ RadioGroup,
154
+ RadioItem,
155
+ ItemIndicator,
156
+ SubTrigger
157
+ } = menu;
158
+ const Sub = props => {
159
+ const {
160
+ children,
161
+ open: openProp,
162
+ onOpenChange,
163
+ defaultOpen
164
+ } = props;
165
+ const [open = false, setOpen] = useControllableState({
166
+ prop: openProp,
167
+ defaultProp: defaultOpen,
168
+ onChange: onOpenChange
169
+ });
170
+ return jsx(Sub$1, {
171
+ onOpenChange: setOpen,
172
+ open: open,
173
+ children: children
174
+ });
175
+ };
176
+ Sub.displayName = 'DropdownMenuSub';
177
+ const SubContent = /*#__PURE__*/forwardRef((props, forwardedRef) => jsx(SubContent$1, {
178
+ ...props,
179
+ ref: forwardedRef,
180
+ style: {
181
+ ...props.style,
182
+ ...contentCssVariables
183
+ }
184
+ }));
185
+ SubContent.displayName = 'DropdownMenuSubContent';
186
+
187
+ export { CheckboxItem, Content, Group, Item, ItemIndicator, Label, Portal, RadioGroup, RadioItem, Root, Sub, SubContent, SubTrigger, Trigger };
@@ -0,0 +1,16 @@
1
+ import { type PrimitiveProps } from './types';
2
+ export interface FocusScopeComponentProps extends PrimitiveProps<'div'> {
3
+ /** When `true`, tabbing from the last item focuses the first one, and Shift+Tab from the first focuses the last. */
4
+ loop?: boolean;
5
+ /** When `true`, Tab and Shift+Tab can't leave the scope. */
6
+ trapped?: boolean;
7
+ /** Called when auto-focusing on mount. Can be prevented. */
8
+ onMountAutoFocus?: (event: Event) => void;
9
+ /** Called when auto-focusing on unmount. Can be prevented. */
10
+ onUnmountAutoFocus?: (event: Event) => void;
11
+ }
12
+ /**
13
+ * The Radix `FocusScope` component: a focusable `div` (or its only child with `asChild`) that manages focus
14
+ * inside it. Nested scopes pause the outer ones.
15
+ */
16
+ export declare const FocusScope: import("react").ForwardRefExoticComponent<FocusScopeComponentProps & import("react").RefAttributes<HTMLDivElement>>;
@@ -0,0 +1,41 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+ import { forwardRef, useState } from 'react';
3
+ import { composeEventHandlers } from '../composeEventHandlers.js';
4
+ import { useComposedRefs } from './compose-refs.js';
5
+ import { useFocusScope } from './focus-scope.js';
6
+ import { Slot } from './slot.js';
7
+
8
+ /**
9
+ * The Radix `FocusScope` component: a focusable `div` (or its only child with `asChild`) that manages focus
10
+ * inside it. Nested scopes pause the outer ones.
11
+ */
12
+ const FocusScope = /*#__PURE__*/forwardRef((props, forwardedRef) => {
13
+ const {
14
+ loop = false,
15
+ trapped = false,
16
+ onMountAutoFocus,
17
+ onUnmountAutoFocus,
18
+ asChild,
19
+ onKeyDown,
20
+ ...scopeProps
21
+ } = props;
22
+ const [container, setContainer] = useState(null);
23
+ const composedRefs = useComposedRefs(forwardedRef, setContainer);
24
+ const focusScope = useFocusScope({
25
+ container,
26
+ loop,
27
+ trapped,
28
+ onMountAutoFocus,
29
+ onUnmountAutoFocus
30
+ });
31
+ const Comp = asChild ? Slot : 'div';
32
+ return jsx(Comp, {
33
+ tabIndex: -1,
34
+ ...scopeProps,
35
+ ref: composedRefs,
36
+ onKeyDown: composeEventHandlers(onKeyDown, focusScope.onKeyDown)
37
+ });
38
+ });
39
+ FocusScope.displayName = 'FocusScope';
40
+
41
+ export { FocusScope };
@@ -0,0 +1,37 @@
1
+ import { type KeyboardEvent as ReactKeyboardEvent } from 'react';
2
+ export declare function focusElement(element?: HTMLElement | null, { select }?: {
3
+ select?: boolean | undefined;
4
+ }): void;
5
+ /**
6
+ * Focuses the first candidate that actually receives focus.
7
+ */
8
+ export declare function focusFirst(candidates: HTMLElement[], { select }?: {
9
+ select?: boolean | undefined;
10
+ }): void;
11
+ /**
12
+ * Elements inside `container` that the browser considers tabbable, in DOM order.
13
+ */
14
+ export declare function getTabbableCandidates(container: HTMLElement): HTMLElement[];
15
+ export declare function getTabbableEdges(container: HTMLElement): readonly [HTMLElement | undefined, HTMLElement | undefined];
16
+ export declare function removeLinks(items: HTMLElement[]): HTMLElement[];
17
+ export interface UseFocusScopeOptions {
18
+ /** The element focus is scoped to. Pass `null` while it isn't mounted. */
19
+ container: HTMLElement | null;
20
+ /** When `true`, tabbing from the last item focuses the first one, and Shift+Tab from the first focuses the last. */
21
+ loop?: boolean;
22
+ /** When `true`, Tab and Shift+Tab can't leave the container. */
23
+ trapped?: boolean;
24
+ /** Called when auto-focusing on mount. Call `event.preventDefault()` to prevent it. */
25
+ onMountAutoFocus?: (event: Event) => void;
26
+ /** Called when auto-focusing on unmount. Call `event.preventDefault()` to prevent it. */
27
+ onUnmountAutoFocus?: (event: Event) => void;
28
+ /** Picks the element to focus on mount. Defaults to the first tabbable element that isn't a link. */
29
+ getMountAutoFocusCandidates?: (container: HTMLElement) => HTMLElement[];
30
+ }
31
+ /**
32
+ * Focus management of the Radix `FocusScope`: initial focus, focus restore and Tab looping/trapping.
33
+ * Nested scopes pause the outer ones, so only the innermost scope handles Tab.
34
+ */
35
+ export declare function useFocusScope({ container, loop, trapped, onMountAutoFocus: onMountAutoFocusProp, onUnmountAutoFocus: onUnmountAutoFocusProp, getMountAutoFocusCandidates, }: UseFocusScopeOptions): {
36
+ onKeyDown: (event: ReactKeyboardEvent<HTMLElement>) => void;
37
+ };
@@ -0,0 +1,288 @@
1
+ import { useRef, useEffect, useCallback } from 'react';
2
+ import { useCallbackRef } from '../useCallbackRef.js';
3
+ import { isInsidePersistentElement } from './layers.js';
4
+
5
+ const AUTOFOCUS_ON_MOUNT = 'focusScope.autoFocusOnMount';
6
+ const AUTOFOCUS_ON_UNMOUNT = 'focusScope.autoFocusOnUnmount';
7
+ const EVENT_OPTIONS = {
8
+ bubbles: false,
9
+ cancelable: true
10
+ };
11
+ function arrayRemove(array, item) {
12
+ const updatedArray = [...array];
13
+ const index = updatedArray.indexOf(item);
14
+ if (index !== -1) {
15
+ updatedArray.splice(index, 1);
16
+ }
17
+ return updatedArray;
18
+ }
19
+ function createFocusScopesStack() {
20
+ let stack = [];
21
+ return {
22
+ add(focusScope) {
23
+ const activeFocusScope = stack[0];
24
+ if (focusScope !== activeFocusScope) {
25
+ activeFocusScope?.pause();
26
+ }
27
+ stack = arrayRemove(stack, focusScope);
28
+ stack.unshift(focusScope);
29
+ },
30
+ remove(focusScope) {
31
+ stack = arrayRemove(stack, focusScope);
32
+ stack[0]?.resume();
33
+ }
34
+ };
35
+ }
36
+ const focusScopesStack = createFocusScopesStack();
37
+ function isSelectableInput(element) {
38
+ return element instanceof HTMLInputElement && 'select' in element;
39
+ }
40
+ function focusElement(element, {
41
+ select = false
42
+ } = {}) {
43
+ if (element && element.focus) {
44
+ const previouslyFocusedElement = document.activeElement;
45
+ element.focus({
46
+ preventScroll: true
47
+ });
48
+ if (element !== previouslyFocusedElement && isSelectableInput(element) && select) {
49
+ element.select();
50
+ }
51
+ }
52
+ }
53
+ /**
54
+ * Focuses the first candidate that actually receives focus.
55
+ */
56
+ function focusFirst(candidates, {
57
+ select = false
58
+ } = {}) {
59
+ const previouslyFocusedElement = document.activeElement;
60
+ for (const candidate of candidates) {
61
+ focusElement(candidate, {
62
+ select
63
+ });
64
+ if (document.activeElement !== previouslyFocusedElement) {
65
+ return;
66
+ }
67
+ }
68
+ }
69
+ /**
70
+ * Elements inside `container` that the browser considers tabbable, in DOM order.
71
+ */
72
+ function getTabbableCandidates(container) {
73
+ const nodes = [];
74
+ const walker = document.createTreeWalker(container, NodeFilter.SHOW_ELEMENT, {
75
+ acceptNode: node => {
76
+ const element = node;
77
+ const isHiddenInput = element.tagName === 'INPUT' && element.type === 'hidden';
78
+ if (element.disabled || element.hidden || isHiddenInput) {
79
+ return NodeFilter.FILTER_SKIP;
80
+ }
81
+ return element.tabIndex >= 0 ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
82
+ }
83
+ });
84
+ while (walker.nextNode()) {
85
+ nodes.push(walker.currentNode);
86
+ }
87
+ return nodes;
88
+ }
89
+ function isHidden(node, upTo) {
90
+ if (getComputedStyle(node).visibility === 'hidden') {
91
+ return true;
92
+ }
93
+ let current = node;
94
+ while (current) {
95
+ if (current === upTo) {
96
+ return false;
97
+ }
98
+ if (getComputedStyle(current).display === 'none') {
99
+ return true;
100
+ }
101
+ current = current.parentElement;
102
+ }
103
+ return false;
104
+ }
105
+ function findVisible(elements, container) {
106
+ return elements.find(element => !isHidden(element, container));
107
+ }
108
+ function getTabbableEdges(container) {
109
+ const candidates = getTabbableCandidates(container);
110
+ const first = findVisible(candidates, container);
111
+ const last = findVisible(candidates.reverse(), container);
112
+ return [first, last];
113
+ }
114
+ function removeLinks(items) {
115
+ return items.filter(item => item.tagName !== 'A');
116
+ }
117
+ /**
118
+ * Focus management of the Radix `FocusScope`: initial focus, focus restore and Tab looping/trapping.
119
+ * Nested scopes pause the outer ones, so only the innermost scope handles Tab.
120
+ */
121
+ function useFocusScope({
122
+ container,
123
+ loop = false,
124
+ trapped = false,
125
+ onMountAutoFocus: onMountAutoFocusProp,
126
+ onUnmountAutoFocus: onUnmountAutoFocusProp,
127
+ getMountAutoFocusCandidates
128
+ }) {
129
+ const onMountAutoFocus = useCallbackRef(onMountAutoFocusProp);
130
+ const onUnmountAutoFocus = useCallbackRef(onUnmountAutoFocusProp);
131
+ const getCandidates = useCallbackRef(getMountAutoFocusCandidates ?? (node => removeLinks(getTabbableCandidates(node))));
132
+ const focusScope = useRef({
133
+ paused: false,
134
+ pause() {
135
+ this.paused = true;
136
+ },
137
+ resume() {
138
+ this.paused = false;
139
+ }
140
+ }).current;
141
+ const lastFocusedElementRef = useRef(null);
142
+ useEffect(() => {
143
+ if (!trapped || !container) {
144
+ return undefined;
145
+ }
146
+ // Listening on the document (bubble phase) like Radix: when focusing an element moves focus again, the
147
+ // outer element is recorded last.
148
+ const handleFocusIn = event => {
149
+ if (focusScope.paused) {
150
+ return;
151
+ }
152
+ const target = event.target;
153
+ if (container.contains(target)) {
154
+ lastFocusedElementRef.current = target;
155
+ } else if (!isInsidePersistentElement(target)) {
156
+ focusElement(lastFocusedElementRef.current, {
157
+ select: true
158
+ });
159
+ }
160
+ };
161
+ const handleFocusOut = event => {
162
+ if (focusScope.paused) {
163
+ return;
164
+ }
165
+ const relatedTarget = event.relatedTarget;
166
+ // A `null` related target means the window lost focus, or the focused element was removed.
167
+ if (relatedTarget === null) {
168
+ return;
169
+ }
170
+ if (!container.contains(relatedTarget) && !isInsidePersistentElement(relatedTarget)) {
171
+ focusElement(lastFocusedElementRef.current, {
172
+ select: true
173
+ });
174
+ }
175
+ };
176
+ // When the focused element gets removed from the DOM, browsers move focus to the body.
177
+ const handleMutations = mutations => {
178
+ if (document.activeElement !== document.body) {
179
+ return;
180
+ }
181
+ if (mutations.some(mutation => mutation.removedNodes.length > 0)) {
182
+ focusElement(container);
183
+ }
184
+ };
185
+ document.addEventListener('focusin', handleFocusIn);
186
+ document.addEventListener('focusout', handleFocusOut);
187
+ const mutationObserver = new MutationObserver(handleMutations);
188
+ mutationObserver.observe(container, {
189
+ childList: true,
190
+ subtree: true
191
+ });
192
+ return () => {
193
+ document.removeEventListener('focusin', handleFocusIn);
194
+ document.removeEventListener('focusout', handleFocusOut);
195
+ mutationObserver.disconnect();
196
+ };
197
+ }, [trapped, container, focusScope]);
198
+ useEffect(() => {
199
+ if (!container) {
200
+ return undefined;
201
+ }
202
+ focusScopesStack.add(focusScope);
203
+ const previouslyFocusedElement = document.activeElement;
204
+ const hasFocusedCandidate = container.contains(previouslyFocusedElement);
205
+ if (!hasFocusedCandidate) {
206
+ const mountEvent = new CustomEvent(AUTOFOCUS_ON_MOUNT, EVENT_OPTIONS);
207
+ container.addEventListener(AUTOFOCUS_ON_MOUNT, onMountAutoFocus);
208
+ container.dispatchEvent(mountEvent);
209
+ if (!mountEvent.defaultPrevented) {
210
+ focusFirst(getCandidates(container), {
211
+ select: true
212
+ });
213
+ if (document.activeElement === previouslyFocusedElement) {
214
+ focusElement(container);
215
+ }
216
+ }
217
+ }
218
+ return () => {
219
+ container.removeEventListener(AUTOFOCUS_ON_MOUNT, onMountAutoFocus);
220
+ // Focusing during unmount is delayed until the element is gone.
221
+ setTimeout(() => {
222
+ const unmountEvent = new CustomEvent(AUTOFOCUS_ON_UNMOUNT, EVENT_OPTIONS);
223
+ container.addEventListener(AUTOFOCUS_ON_UNMOUNT, onUnmountAutoFocus);
224
+ container.dispatchEvent(unmountEvent);
225
+ if (!unmountEvent.defaultPrevented) {
226
+ focusElement(previouslyFocusedElement ?? document.body, {
227
+ select: true
228
+ });
229
+ }
230
+ container.removeEventListener(AUTOFOCUS_ON_UNMOUNT, onUnmountAutoFocus);
231
+ focusScopesStack.remove(focusScope);
232
+ }, 0);
233
+ };
234
+ }, [container, onMountAutoFocus, onUnmountAutoFocus, getCandidates, focusScope]);
235
+ const onKeyDown = useCallback(event => {
236
+ if (!loop && !trapped) {
237
+ return;
238
+ }
239
+ if (focusScope.paused) {
240
+ return;
241
+ }
242
+ const isTabKey = event.key === 'Tab' && !event.altKey && !event.ctrlKey && !event.metaKey;
243
+ const focusedElement = document.activeElement;
244
+ if (isTabKey && focusedElement) {
245
+ const scopeContainer = event.currentTarget;
246
+ const [first, last] = getTabbableEdges(scopeContainer);
247
+ const hasTabbableElementsInside = first && last;
248
+ if (!hasTabbableElementsInside) {
249
+ if (focusedElement === scopeContainer) {
250
+ event.preventDefault();
251
+ }
252
+ } else if (!event.shiftKey && focusedElement === last) {
253
+ event.preventDefault();
254
+ if (loop) {
255
+ focusElement(first, {
256
+ select: true
257
+ });
258
+ }
259
+ } else if (event.shiftKey && focusedElement === first) {
260
+ event.preventDefault();
261
+ if (loop) {
262
+ focusElement(last, {
263
+ select: true
264
+ });
265
+ }
266
+ }
267
+ }
268
+ // Inert elements outside a modal can't take focus, so a Tab that heads outside doesn't move it. Radix
269
+ // brought focus back to the last focused element in that case, so it's done here too.
270
+ if (isTabKey && trapped && focusedElement && !event.defaultPrevented) {
271
+ const {
272
+ nativeEvent
273
+ } = event;
274
+ window.setTimeout(() => {
275
+ if (!nativeEvent.defaultPrevented && document.activeElement === focusedElement) {
276
+ focusElement(lastFocusedElementRef.current, {
277
+ select: true
278
+ });
279
+ }
280
+ });
281
+ }
282
+ }, [loop, trapped, focusScope]);
283
+ return {
284
+ onKeyDown
285
+ };
286
+ }
287
+
288
+ export { focusElement, focusFirst, getTabbableCandidates, getTabbableEdges, removeLinks, useFocusScope };
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Hides everything but the content of a modal overlay with `aria-hidden` while it is mounted, like Radix did.
3
+ * Ariakit makes the rest of the page inert as well, but tools that read the accessibility tree, like Testing
4
+ * Library queries, only leave out `aria-hidden` content.
5
+ */
6
+ export declare function useHideOthers(content: HTMLElement | null, enabled: boolean): void;
@@ -0,0 +1,18 @@
1
+ import { hideOthers } from 'aria-hidden';
2
+ import { useEffect } from 'react';
3
+
4
+ /**
5
+ * Hides everything but the content of a modal overlay with `aria-hidden` while it is mounted, like Radix did.
6
+ * Ariakit makes the rest of the page inert as well, but tools that read the accessibility tree, like Testing
7
+ * Library queries, only leave out `aria-hidden` content.
8
+ */
9
+ function useHideOthers(content, enabled) {
10
+ useEffect(() => {
11
+ if (!enabled || !content) {
12
+ return undefined;
13
+ }
14
+ return hideOthers(content);
15
+ }, [content, enabled]);
16
+ }
17
+
18
+ export { useHideOthers };
@@ -0,0 +1,14 @@
1
+ export { BubbleInput, isFormControl } from './bubble-input';
2
+ export { createCollection } from './collection';
3
+ export { composeRefs, useComposedRefs } from './compose-refs';
4
+ export { useCollapsibleContentSize } from './content-size';
5
+ export { preventRightClickDismiss, useDismissable } from './dismissable';
6
+ export { focusElement, focusFirst, getTabbableCandidates, getTabbableEdges, removeLinks, useFocusScope, type UseFocusScopeOptions, } from './focus-scope';
7
+ export { getPersistentElements, isInsidePersistentElement, useLayer, usePersistentElement } from './layers';
8
+ export { getPopperCssVariables, POPPER_WRAPPER_ATTRIBUTE, PopperArrow, PopperArrowProvider, usePopper, type PopperAnchor, type PopperArrowProps, } from './popper';
9
+ export { Portal, type PortalComponentProps } from './portal';
10
+ export { Presence, usePresence } from './presence';
11
+ export { RovingFocusGroup, RovingFocusGroupItem, wrapArray, type RovingFocusGroupItemProps, type RovingFocusGroupProps, } from './roving-focus';
12
+ export { getElementRef, mergeSlotProps, Slot, type SlotProps } from './slot';
13
+ export { findNextItem, getNextMatch, isTypeaheadKey, useTypeaheadSearch } from './typeahead';
14
+ export type { Align, Direction, DismissableLayerProps, FocusOutsideEvent, FocusScopeProps, Orientation, PointerDownOutsideEvent, PopperContentProps, PortalProps, PrimitiveProps, Side, } from './types';
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Blueprint layers (overlays and notifications) in the order they opened.
3
+ *
4
+ * Overlays use Ariakit while notifications use Radix Toast. Radix arbitrated Escape between all its layers
5
+ * with a single stack, which this registry keeps for the two libraries: only the most recently opened layer
6
+ * reacts to a document level Escape key press. Like in Radix, a layer that blocks outside pointer events (a modal
7
+ * one) also keeps the layers below it from reacting to pointer downs outside of them.
8
+ */
9
+ export type LayerKind = 'overlay' | 'notification';
10
+ /**
11
+ * Registers a layer while `enabled`, and tells which layers opened after it.
12
+ */
13
+ export declare function useLayer(kind: LayerKind, enabled: boolean, blocksOutsidePointerEvents?: boolean): {
14
+ /** Whether a layer of the given kind opened after this one. */
15
+ hasLayerAbove: (otherKind: LayerKind) => boolean;
16
+ /** Whether a layer that blocks outside pointer events opened after this one. */
17
+ hasBlockingLayerAbove: () => boolean;
18
+ };
19
+ /**
20
+ * Registers an element that must stay interactive while a modal overlay is open, like the notification viewport.
21
+ * Pointer and focus interactions inside it also don't dismiss open overlays.
22
+ */
23
+ export declare function usePersistentElement(element: HTMLElement | null): void;
24
+ export declare function getPersistentElements(): HTMLElement[];
25
+ export declare function isInsidePersistentElement(target: EventTarget | null): boolean;