@qualtrics/ui-react 2.74.0 → 2.76.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.
- package/CHANGELOG.md +18 -0
- package/dist/__node_modules/@radix-ui/primitive/dist/index.js +54 -0
- package/dist/__node_modules/@radix-ui/react-arrow/dist/index.js +28 -0
- package/dist/__node_modules/@radix-ui/react-collection/dist/index.js +605 -0
- package/dist/__node_modules/@radix-ui/react-compose-refs/dist/index.js +45 -0
- package/dist/__node_modules/@radix-ui/react-context/dist/index.js +108 -0
- package/dist/__node_modules/@radix-ui/react-direction/dist/index.js +21 -0
- package/dist/__node_modules/@radix-ui/react-dismissable-layer/dist/index.js +223 -0
- package/dist/__node_modules/@radix-ui/react-dropdown-menu/dist/index.js +350 -0
- package/dist/__node_modules/@radix-ui/react-focus-guards/dist/index.js +35 -0
- package/dist/__node_modules/@radix-ui/react-focus-scope/dist/index.js +248 -0
- package/dist/__node_modules/@radix-ui/react-id/dist/index.js +15 -0
- package/dist/__node_modules/@radix-ui/react-menu/dist/index.js +911 -0
- package/dist/__node_modules/@radix-ui/react-popper/dist/index.js +325 -0
- package/dist/__node_modules/@radix-ui/react-portal/dist/index.js +25 -0
- package/dist/__node_modules/@radix-ui/react-presence/dist/index.js +141 -0
- package/dist/__node_modules/@radix-ui/react-primitive/dist/index.js +34 -0
- package/dist/__node_modules/@radix-ui/react-roving-focus/dist/index.js +216 -0
- package/dist/__node_modules/@radix-ui/react-slot/dist/index.js +127 -0
- package/dist/__node_modules/@radix-ui/react-use-callback-ref/dist/index.js +18 -0
- package/dist/__node_modules/@radix-ui/react-use-controllable-state/dist/index.js +141 -0
- package/dist/__node_modules/@radix-ui/react-use-effect-event/dist/index.js +32 -0
- package/dist/__node_modules/@radix-ui/react-use-escape-keydown/dist/index.js +23 -0
- package/dist/__node_modules/@radix-ui/react-use-layout-effect/dist/index.js +6 -0
- package/dist/__node_modules/@radix-ui/react-use-size/dist/index.js +48 -0
- package/dist/__node_modules/aria-hidden/dist/es2015/index.js +169 -0
- package/dist/__node_modules/detect-node-es/esm/node.js +4 -0
- package/dist/__node_modules/get-nonce/dist/es2015/index.js +15 -0
- package/dist/__node_modules/react-remove-scroll/dist/es2015/Combination.js +9 -0
- package/dist/__node_modules/react-remove-scroll/dist/es2015/SideEffect.js +169 -0
- package/dist/__node_modules/react-remove-scroll/dist/es2015/UI.js +39 -0
- package/dist/__node_modules/react-remove-scroll/dist/es2015/aggresiveCapture.js +21 -0
- package/dist/__node_modules/react-remove-scroll/dist/es2015/handleScroll.js +110 -0
- package/dist/__node_modules/react-remove-scroll/dist/es2015/index.js +1 -0
- package/dist/__node_modules/react-remove-scroll/dist/es2015/medium.js +6 -0
- package/dist/__node_modules/react-remove-scroll/dist/es2015/sidecar.js +8 -0
- package/dist/__node_modules/react-remove-scroll-bar/dist/es2015/component.js +57 -0
- package/dist/__node_modules/react-remove-scroll-bar/dist/es2015/constants.js +10 -0
- package/dist/__node_modules/react-remove-scroll-bar/dist/es2015/index.js +3 -0
- package/dist/__node_modules/react-remove-scroll-bar/dist/es2015/utils.js +31 -0
- package/dist/__node_modules/react-style-singleton/dist/es2015/component.js +19 -0
- package/dist/__node_modules/react-style-singleton/dist/es2015/hook.js +25 -0
- package/dist/__node_modules/react-style-singleton/dist/es2015/index.js +3 -0
- package/dist/__node_modules/react-style-singleton/dist/es2015/singleton.js +51 -0
- package/dist/__node_modules/tslib/tslib.es6.js +403 -0
- package/dist/__node_modules/use-callback-ref/dist/es2015/assignRef.js +24 -0
- package/dist/__node_modules/use-callback-ref/dist/es2015/createRef.js +25 -0
- package/dist/__node_modules/use-callback-ref/dist/es2015/index.js +8 -0
- package/dist/__node_modules/use-callback-ref/dist/es2015/mergeRef.js +21 -0
- package/dist/__node_modules/use-callback-ref/dist/es2015/refToCallback.js +50 -0
- package/dist/__node_modules/use-callback-ref/dist/es2015/transformRef.js +17 -0
- package/dist/__node_modules/use-callback-ref/dist/es2015/useMergeRef.js +48 -0
- package/dist/__node_modules/use-callback-ref/dist/es2015/useRef.js +42 -0
- package/dist/__node_modules/use-callback-ref/dist/es2015/useTransformRef.js +21 -0
- package/dist/__node_modules/use-sidecar/dist/es2015/config.js +8 -0
- package/dist/__node_modules/use-sidecar/dist/es2015/env.js +8 -0
- package/dist/__node_modules/use-sidecar/dist/es2015/exports.js +21 -0
- package/dist/__node_modules/use-sidecar/dist/es2015/hoc.js +18 -0
- package/dist/__node_modules/use-sidecar/dist/es2015/hook.js +44 -0
- package/dist/__node_modules/use-sidecar/dist/es2015/index.js +6 -0
- package/dist/__node_modules/use-sidecar/dist/es2015/medium.js +81 -0
- package/dist/__node_modules/use-sidecar/dist/es2015/renderProp.js +38 -0
- package/dist/__shared/cjs/{index-be619849.js → index-87207072.js} +422 -371
- package/dist/__shared/cjs/{index-97d7b02b.js → index-b569963c.js} +3 -3
- package/dist/components/Accordion/Accordion2.js +3 -3
- package/dist/components/BreakpointSwitch/BreakpointSwitch.js +3 -2
- package/dist/components/Button/Button.js +3 -3
- package/dist/components/ButtonGroup/ButtonGroup.js +3 -2
- package/dist/components/ButtonGroup/ButtonGroup2.js +3 -3
- package/dist/components/Checkbox/Checkbox2.js +3 -3
- package/dist/components/ColorPicker/ColorPicker.js +7 -8
- package/dist/components/ColorPicker/ColorPicker2.js +3 -3
- package/dist/components/Combobox/Combobox.js +9 -8
- package/dist/components/Combobox/Combobox2.js +3 -3
- package/dist/components/Combobox/ComboboxList.js +5 -6
- package/dist/components/ConfigPane/ConfigPane2.js +3 -3
- package/dist/components/Divider/Divider2.js +3 -3
- package/dist/components/Dropdown/Dropdown.js +1 -1
- package/dist/components/Dropdown/Dropdown2.js +3 -3
- package/dist/components/Dropdown/DropdownButton.js +10 -9
- package/dist/components/Dropdown/DropdownList.js +6 -7
- package/dist/components/FilePicker/FilePicker2.js +3 -3
- package/dist/components/FormField/Caption.js +3 -3
- package/dist/components/FormField/FormField2.js +3 -3
- package/dist/components/FullScreenTakeover/FullScreenTakeover2.js +3 -3
- package/dist/components/IconButton/IconButton2.js +3 -3
- package/dist/components/InlineInput/InlineInput2.js +3 -3
- package/dist/components/Input/Input2.js +3 -3
- package/dist/components/InputGroup/InputGroup2.js +3 -3
- package/dist/components/Label/Label2.js +3 -3
- package/dist/components/Link/Link2.js +3 -3
- package/dist/components/LoadingSpinner/LoadingSpinner2.js +3 -3
- package/dist/components/LogicEditor/ConditionSet.js +2 -2
- package/dist/components/LogicEditor/LogicEditor2.js +3 -3
- package/dist/components/Modal/Modal.js +4 -2
- package/dist/components/Modal/Modal2.js +3 -3
- package/dist/components/NewMenu/BaseMenu.js +31 -25
- package/dist/components/NewMenu/Menu/Menu.js +1 -0
- package/dist/components/NewMenu/NewMenu.js +3 -3
- package/dist/components/NewMenu/SelectMenu/SelectMenu.js +3 -1
- package/dist/components/NewMenu/parts/ArrowNav/ArrowNav.js +10 -4
- package/dist/components/NewMenu/parts/MenuItem.js +1 -1
- package/dist/components/NumberStepper/NumberStepper2.js +3 -3
- package/dist/components/PageLayout/PageLayout.js +3 -3
- package/dist/components/Pagination/Pagination2.js +3 -3
- package/dist/components/Popover/Popover.js +8 -14
- package/dist/components/Popover/Popover2.js +3 -3
- package/dist/components/QuickSearch/QuickSearch2.js +3 -3
- package/dist/components/Radio/Radio2.js +3 -3
- package/dist/components/SearchInput/SearchInput2.js +3 -3
- package/dist/components/SidebarNav/SidebarNav2.js +3 -3
- package/dist/components/Slider/Slider2.js +3 -3
- package/dist/components/Switch/Switch2.js +3 -3
- package/dist/components/Table/Table2.js +3 -3
- package/dist/components/Tabs/TabList.js +3 -2
- package/dist/components/Tabs/TabPanels.js +2 -1
- package/dist/components/Tabs/Tabs2.js +3 -3
- package/dist/components/Tooltip/Tooltip.js +6 -12
- package/dist/components/Tooltip/Tooltip2.js +3 -3
- package/dist/components/deprecated_ColorPicker/ColorPicker.js +5 -6
- package/dist/components/deprecated_ColorPicker/ColorPicker2.js +3 -3
- package/dist/components/deprecated_NumberStepper/NumberStepper2.js +3 -3
- package/dist/components/deprecated_Tabs/Tabs.js +3 -3
- package/dist/components/deprecated_Tabs/Tabs2.js +3 -3
- package/dist/components/deprecated_Toolbar/Toolbar2.js +3 -3
- package/dist/design-tokens/less/typography.js +3 -3
- package/dist/hooks/useOverlay/useOverlay2.js +3 -3
- package/dist/hooks/usePrevious/usePrevious.js +1 -1
- package/dist/hooks/useScreenReaderAnnouncement/useScreenReaderAnnouncement.js +2 -2
- package/dist/hooks/useScreenReaderAnnouncement/useScreenReaderAnnouncement2.js +3 -3
- package/dist/icons/Icon.js +3 -3
- package/dist/icons/index.js +1 -1
- package/dist/index.d.ts +18 -17
- package/dist/index.es.js +1 -1
- package/dist/index.js +4 -5
- package/dist/next/AdvancedTable/AdvancedTable.js +2 -0
- package/dist/next/AdvancedTable/AdvancedTable2.js +3 -3
- package/dist/next/AdvancedTable/AdvancedTablePagination.js +3 -1
- package/dist/next/CollapsibleSearchInput/CollapsibleSearchInput2.js +3 -3
- package/dist/next/Combobox/Combobox2.js +3 -3
- package/dist/next/Combobox/ComboboxFlyout.js +6 -6
- package/dist/next/Combobox/ComboboxGroup.js +1 -1
- package/dist/next/Combobox/hooks/useComboboxFocusSequence/useComboboxFocusSequence.js +1 -1
- package/dist/next/Combobox/hooks/useComboboxLoadingState/useComboboxLoadingState.js +1 -1
- package/dist/next/Drawer/Drawer2.js +3 -3
- package/dist/next/FilterAnchor/FilterAnchor2.js +3 -3
- package/dist/next/Form/FormFields/InputField.js +3 -3
- package/dist/next/Indicator/Indicator2.js +3 -3
- package/dist/next/Input/Input2.js +3 -3
- package/dist/next/LoadingSpinner/LoadingSpinner2.js +3 -3
- package/dist/next/Menu/Hooks/usePaneSearch.js +1 -1
- package/dist/next/Menu/Menu.js +2 -2
- package/dist/next/Menu/Menu2.js +3 -3
- package/dist/next/Menu/MenuButton.js +1 -1
- package/dist/next/Menu/MenuItem.js +2 -2
- package/dist/next/Menu/MenuPane.js +4 -3
- package/dist/next/Menu/SubMenu.js +8 -6
- package/dist/next/PhoneNumberInput/PhoneNumberInput.js +90 -41
- package/dist/next/PhoneNumberInput/PhoneNumberInput2.js +3 -3
- package/dist/next/Select/Select2.js +3 -3
- package/dist/next/SplitButton/SplitButton2.js +3 -3
- package/dist/next/TimePicker/TimeDropdown.js +5 -6
- package/dist/next/TimePicker/TimeInput.js +104 -37
- package/dist/next/TimePicker/TimePicker2.js +3 -3
- package/dist/next/ToggleButton/styles.js +3 -3
- package/dist/next/index.d.ts +27 -20
- package/dist/next/index.js +5605 -325
- package/dist/utils/Flyout/Flyout2.js +3 -3
- package/dist/utils/GridChildrenWrapper/GridChildrenWrapper.js +2 -1
- package/dist/utils/Popper/Popper.js +162 -114
- package/dist/utils/Portal/Portal.js +3 -2
- package/dist/utils/Text/Text.js +3 -2
- package/dist/utils/filterChildren/filterChildren.js +3 -2
- package/dist/utils/index.js +1 -0
- package/icons/package.json +3 -4
- package/next/package.json +4 -5
- package/package.json +17 -18
- package/dist/__shared/cjs/index-55082bc8.js +0 -13425
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { composeEventHandlers } from '../../primitive/dist/index.js';
|
|
3
|
+
import { createCollection } from '../../react-collection/dist/index.js';
|
|
4
|
+
import { useComposedRefs } from '../../react-compose-refs/dist/index.js';
|
|
5
|
+
import { createContextScope } from '../../react-context/dist/index.js';
|
|
6
|
+
import { useId } from '../../react-id/dist/index.js';
|
|
7
|
+
import { Primitive } from '../../react-primitive/dist/index.js';
|
|
8
|
+
import { useCallbackRef } from '../../react-use-callback-ref/dist/index.js';
|
|
9
|
+
import { useControllableState } from '../../react-use-controllable-state/dist/index.js';
|
|
10
|
+
import { useDirection } from '../../react-direction/dist/index.js';
|
|
11
|
+
|
|
12
|
+
"use client";
|
|
13
|
+
var ENTRY_FOCUS = "rovingFocusGroup.onEntryFocus";
|
|
14
|
+
var EVENT_OPTIONS = {
|
|
15
|
+
bubbles: false,
|
|
16
|
+
cancelable: true
|
|
17
|
+
};
|
|
18
|
+
var GROUP_NAME = "RovingFocusGroup";
|
|
19
|
+
var [Collection, useCollection, createCollectionScope] = createCollection(GROUP_NAME);
|
|
20
|
+
var [createRovingFocusGroupContext, createRovingFocusGroupScope] = createContextScope(GROUP_NAME, [createCollectionScope]);
|
|
21
|
+
var [RovingFocusProvider, useRovingFocusContext] = createRovingFocusGroupContext(GROUP_NAME);
|
|
22
|
+
var RovingFocusGroup = /*#__PURE__*/React.forwardRef((props, forwardedRef) => {
|
|
23
|
+
return /* @__PURE__ */React.createElement(Collection.Provider, {
|
|
24
|
+
scope: props.__scopeRovingFocusGroup,
|
|
25
|
+
children: /* @__PURE__ */React.createElement(Collection.Slot, {
|
|
26
|
+
scope: props.__scopeRovingFocusGroup,
|
|
27
|
+
children: /* @__PURE__ */React.createElement(RovingFocusGroupImpl, {
|
|
28
|
+
...props,
|
|
29
|
+
ref: forwardedRef
|
|
30
|
+
})
|
|
31
|
+
})
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
RovingFocusGroup.displayName = GROUP_NAME;
|
|
35
|
+
var RovingFocusGroupImpl = /*#__PURE__*/React.forwardRef((props, forwardedRef) => {
|
|
36
|
+
const {
|
|
37
|
+
__scopeRovingFocusGroup,
|
|
38
|
+
orientation,
|
|
39
|
+
loop = false,
|
|
40
|
+
dir,
|
|
41
|
+
currentTabStopId: currentTabStopIdProp,
|
|
42
|
+
defaultCurrentTabStopId,
|
|
43
|
+
onCurrentTabStopIdChange,
|
|
44
|
+
onEntryFocus,
|
|
45
|
+
preventScrollOnEntryFocus = false,
|
|
46
|
+
...groupProps
|
|
47
|
+
} = props;
|
|
48
|
+
const ref = React.useRef(null);
|
|
49
|
+
const composedRefs = useComposedRefs(forwardedRef, ref);
|
|
50
|
+
const direction = useDirection(dir);
|
|
51
|
+
const [currentTabStopId, setCurrentTabStopId] = useControllableState({
|
|
52
|
+
prop: currentTabStopIdProp,
|
|
53
|
+
defaultProp: defaultCurrentTabStopId !== null && defaultCurrentTabStopId !== void 0 ? defaultCurrentTabStopId : null,
|
|
54
|
+
onChange: onCurrentTabStopIdChange,
|
|
55
|
+
caller: GROUP_NAME
|
|
56
|
+
});
|
|
57
|
+
const [isTabbingBackOut, setIsTabbingBackOut] = React.useState(false);
|
|
58
|
+
const handleEntryFocus = useCallbackRef(onEntryFocus);
|
|
59
|
+
const getItems = useCollection(__scopeRovingFocusGroup);
|
|
60
|
+
const isClickFocusRef = React.useRef(false);
|
|
61
|
+
const [focusableItemsCount, setFocusableItemsCount] = React.useState(0);
|
|
62
|
+
React.useEffect(() => {
|
|
63
|
+
const node = ref.current;
|
|
64
|
+
if (node) {
|
|
65
|
+
node.addEventListener(ENTRY_FOCUS, handleEntryFocus);
|
|
66
|
+
return () => node.removeEventListener(ENTRY_FOCUS, handleEntryFocus);
|
|
67
|
+
}
|
|
68
|
+
}, [handleEntryFocus]);
|
|
69
|
+
return /* @__PURE__ */React.createElement(RovingFocusProvider, {
|
|
70
|
+
scope: __scopeRovingFocusGroup,
|
|
71
|
+
orientation,
|
|
72
|
+
dir: direction,
|
|
73
|
+
loop,
|
|
74
|
+
currentTabStopId,
|
|
75
|
+
onItemFocus: React.useCallback(tabStopId => setCurrentTabStopId(tabStopId), [setCurrentTabStopId]),
|
|
76
|
+
onItemShiftTab: React.useCallback(() => setIsTabbingBackOut(true), []),
|
|
77
|
+
onFocusableItemAdd: React.useCallback(() => setFocusableItemsCount(prevCount => prevCount + 1), []),
|
|
78
|
+
onFocusableItemRemove: React.useCallback(() => setFocusableItemsCount(prevCount => prevCount - 1), []),
|
|
79
|
+
children: /* @__PURE__ */React.createElement(Primitive.div, {
|
|
80
|
+
tabIndex: isTabbingBackOut || focusableItemsCount === 0 ? -1 : 0,
|
|
81
|
+
"data-orientation": orientation,
|
|
82
|
+
...groupProps,
|
|
83
|
+
ref: composedRefs,
|
|
84
|
+
style: {
|
|
85
|
+
outline: "none",
|
|
86
|
+
...props.style
|
|
87
|
+
},
|
|
88
|
+
onMouseDown: composeEventHandlers(props.onMouseDown, () => {
|
|
89
|
+
isClickFocusRef.current = true;
|
|
90
|
+
}),
|
|
91
|
+
onFocus: composeEventHandlers(props.onFocus, event => {
|
|
92
|
+
const isKeyboardFocus = !isClickFocusRef.current;
|
|
93
|
+
if (event.target === event.currentTarget && isKeyboardFocus && !isTabbingBackOut) {
|
|
94
|
+
const entryFocusEvent = new CustomEvent(ENTRY_FOCUS, EVENT_OPTIONS);
|
|
95
|
+
event.currentTarget.dispatchEvent(entryFocusEvent);
|
|
96
|
+
if (!entryFocusEvent.defaultPrevented) {
|
|
97
|
+
const items = getItems().filter(item => item.focusable);
|
|
98
|
+
const activeItem = items.find(item => item.active);
|
|
99
|
+
const currentItem = items.find(item => item.id === currentTabStopId);
|
|
100
|
+
const candidateItems = [activeItem, currentItem, ...items].filter(Boolean);
|
|
101
|
+
const candidateNodes = candidateItems.map(item => item.ref.current);
|
|
102
|
+
focusFirst(candidateNodes, preventScrollOnEntryFocus);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
isClickFocusRef.current = false;
|
|
106
|
+
}),
|
|
107
|
+
onBlur: composeEventHandlers(props.onBlur, () => setIsTabbingBackOut(false))
|
|
108
|
+
})
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
var ITEM_NAME = "RovingFocusGroupItem";
|
|
112
|
+
var RovingFocusGroupItem = /*#__PURE__*/React.forwardRef((props, forwardedRef) => {
|
|
113
|
+
const {
|
|
114
|
+
__scopeRovingFocusGroup,
|
|
115
|
+
focusable = true,
|
|
116
|
+
active = false,
|
|
117
|
+
tabStopId,
|
|
118
|
+
children,
|
|
119
|
+
...itemProps
|
|
120
|
+
} = props;
|
|
121
|
+
const autoId = useId();
|
|
122
|
+
const id = tabStopId || autoId;
|
|
123
|
+
const context = useRovingFocusContext(ITEM_NAME, __scopeRovingFocusGroup);
|
|
124
|
+
const isCurrentTabStop = context.currentTabStopId === id;
|
|
125
|
+
const getItems = useCollection(__scopeRovingFocusGroup);
|
|
126
|
+
const {
|
|
127
|
+
onFocusableItemAdd,
|
|
128
|
+
onFocusableItemRemove,
|
|
129
|
+
currentTabStopId
|
|
130
|
+
} = context;
|
|
131
|
+
React.useEffect(() => {
|
|
132
|
+
if (focusable) {
|
|
133
|
+
onFocusableItemAdd();
|
|
134
|
+
return () => onFocusableItemRemove();
|
|
135
|
+
}
|
|
136
|
+
}, [focusable, onFocusableItemAdd, onFocusableItemRemove]);
|
|
137
|
+
return /* @__PURE__ */React.createElement(Collection.ItemSlot, {
|
|
138
|
+
scope: __scopeRovingFocusGroup,
|
|
139
|
+
id,
|
|
140
|
+
focusable,
|
|
141
|
+
active,
|
|
142
|
+
children: /* @__PURE__ */React.createElement(Primitive.span, {
|
|
143
|
+
tabIndex: isCurrentTabStop ? 0 : -1,
|
|
144
|
+
"data-orientation": context.orientation,
|
|
145
|
+
...itemProps,
|
|
146
|
+
ref: forwardedRef,
|
|
147
|
+
onMouseDown: composeEventHandlers(props.onMouseDown, event => {
|
|
148
|
+
if (!focusable) event.preventDefault();else context.onItemFocus(id);
|
|
149
|
+
}),
|
|
150
|
+
onFocus: composeEventHandlers(props.onFocus, () => context.onItemFocus(id)),
|
|
151
|
+
onKeyDown: composeEventHandlers(props.onKeyDown, event => {
|
|
152
|
+
if (event.key === "Tab" && event.shiftKey) {
|
|
153
|
+
context.onItemShiftTab();
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
if (event.target !== event.currentTarget) return;
|
|
157
|
+
const focusIntent = getFocusIntent(event, context.orientation, context.dir);
|
|
158
|
+
if (focusIntent !== void 0) {
|
|
159
|
+
if (event.metaKey || event.ctrlKey || event.altKey || event.shiftKey) return;
|
|
160
|
+
event.preventDefault();
|
|
161
|
+
const items = getItems().filter(item => item.focusable);
|
|
162
|
+
let candidateNodes = items.map(item => item.ref.current);
|
|
163
|
+
if (focusIntent === "last") candidateNodes.reverse();else if (focusIntent === "prev" || focusIntent === "next") {
|
|
164
|
+
if (focusIntent === "prev") candidateNodes.reverse();
|
|
165
|
+
const currentIndex = candidateNodes.indexOf(event.currentTarget);
|
|
166
|
+
candidateNodes = context.loop ? wrapArray(candidateNodes, currentIndex + 1) : candidateNodes.slice(currentIndex + 1);
|
|
167
|
+
}
|
|
168
|
+
setTimeout(() => focusFirst(candidateNodes));
|
|
169
|
+
}
|
|
170
|
+
}),
|
|
171
|
+
children: typeof children === "function" ? children({
|
|
172
|
+
isCurrentTabStop,
|
|
173
|
+
hasTabStop: currentTabStopId != null
|
|
174
|
+
}) : children
|
|
175
|
+
})
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
RovingFocusGroupItem.displayName = ITEM_NAME;
|
|
179
|
+
var MAP_KEY_TO_FOCUS_INTENT = {
|
|
180
|
+
ArrowLeft: "prev",
|
|
181
|
+
ArrowUp: "prev",
|
|
182
|
+
ArrowRight: "next",
|
|
183
|
+
ArrowDown: "next",
|
|
184
|
+
PageUp: "first",
|
|
185
|
+
Home: "first",
|
|
186
|
+
PageDown: "last",
|
|
187
|
+
End: "last"
|
|
188
|
+
};
|
|
189
|
+
function getDirectionAwareKey(key, dir) {
|
|
190
|
+
if (dir !== "rtl") return key;
|
|
191
|
+
return key === "ArrowLeft" ? "ArrowRight" : key === "ArrowRight" ? "ArrowLeft" : key;
|
|
192
|
+
}
|
|
193
|
+
function getFocusIntent(event, orientation, dir) {
|
|
194
|
+
const key = getDirectionAwareKey(event.key, dir);
|
|
195
|
+
if (orientation === "vertical" && ["ArrowLeft", "ArrowRight"].includes(key)) return void 0;
|
|
196
|
+
if (orientation === "horizontal" && ["ArrowUp", "ArrowDown"].includes(key)) return void 0;
|
|
197
|
+
return MAP_KEY_TO_FOCUS_INTENT[key];
|
|
198
|
+
}
|
|
199
|
+
function focusFirst(candidates) {
|
|
200
|
+
let preventScroll = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
201
|
+
const PREVIOUSLY_FOCUSED_ELEMENT = document.activeElement;
|
|
202
|
+
for (const candidate of candidates) {
|
|
203
|
+
if (candidate === PREVIOUSLY_FOCUSED_ELEMENT) return;
|
|
204
|
+
candidate.focus({
|
|
205
|
+
preventScroll
|
|
206
|
+
});
|
|
207
|
+
if (document.activeElement !== PREVIOUSLY_FOCUSED_ELEMENT) return;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
function wrapArray(array, startIndex) {
|
|
211
|
+
return array.map((_, index) => array[(startIndex + index) % array.length]);
|
|
212
|
+
}
|
|
213
|
+
var Root = RovingFocusGroup;
|
|
214
|
+
var Item = RovingFocusGroupItem;
|
|
215
|
+
|
|
216
|
+
export { Item, Root, RovingFocusGroup, RovingFocusGroupItem, createRovingFocusGroupScope };
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { composeRefs } from '../../react-compose-refs/dist/index.js';
|
|
3
|
+
|
|
4
|
+
// src/slot.tsx
|
|
5
|
+
// @__NO_SIDE_EFFECTS__
|
|
6
|
+
function createSlot(ownerName) {
|
|
7
|
+
const SlotClone = /* @__PURE__ */createSlotClone(ownerName);
|
|
8
|
+
const Slot2 = /*#__PURE__*/React.forwardRef((props, forwardedRef) => {
|
|
9
|
+
const {
|
|
10
|
+
children,
|
|
11
|
+
...slotProps
|
|
12
|
+
} = props;
|
|
13
|
+
const childrenArray = React.Children.toArray(children);
|
|
14
|
+
const slottable = childrenArray.find(isSlottable);
|
|
15
|
+
if (slottable) {
|
|
16
|
+
const newElement = slottable.props.children;
|
|
17
|
+
const newChildren = childrenArray.map(child => {
|
|
18
|
+
if (child === slottable) {
|
|
19
|
+
if (React.Children.count(newElement) > 1) return React.Children.only(null);
|
|
20
|
+
return /*#__PURE__*/React.isValidElement(newElement) ? newElement.props.children : null;
|
|
21
|
+
} else {
|
|
22
|
+
return child;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
return /* @__PURE__ */React.createElement(SlotClone, {
|
|
26
|
+
...slotProps,
|
|
27
|
+
ref: forwardedRef,
|
|
28
|
+
children: /*#__PURE__*/React.isValidElement(newElement) ? /*#__PURE__*/React.cloneElement(newElement, void 0, newChildren) : null
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
return /* @__PURE__ */React.createElement(SlotClone, {
|
|
32
|
+
...slotProps,
|
|
33
|
+
ref: forwardedRef,
|
|
34
|
+
children
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
Slot2.displayName = "".concat(ownerName, ".Slot");
|
|
38
|
+
return Slot2;
|
|
39
|
+
}
|
|
40
|
+
var Slot = /* @__PURE__ */createSlot("Slot");
|
|
41
|
+
// @__NO_SIDE_EFFECTS__
|
|
42
|
+
function createSlotClone(ownerName) {
|
|
43
|
+
const SlotClone = /*#__PURE__*/React.forwardRef((props, forwardedRef) => {
|
|
44
|
+
const {
|
|
45
|
+
children,
|
|
46
|
+
...slotProps
|
|
47
|
+
} = props;
|
|
48
|
+
if (/*#__PURE__*/React.isValidElement(children)) {
|
|
49
|
+
const childrenRef = getElementRef(children);
|
|
50
|
+
const props2 = mergeProps(slotProps, children.props);
|
|
51
|
+
if (children.type !== React.Fragment) {
|
|
52
|
+
props2.ref = forwardedRef ? composeRefs(forwardedRef, childrenRef) : childrenRef;
|
|
53
|
+
}
|
|
54
|
+
return /*#__PURE__*/React.cloneElement(children, props2);
|
|
55
|
+
}
|
|
56
|
+
return React.Children.count(children) > 1 ? React.Children.only(null) : null;
|
|
57
|
+
});
|
|
58
|
+
SlotClone.displayName = "".concat(ownerName, ".SlotClone");
|
|
59
|
+
return SlotClone;
|
|
60
|
+
}
|
|
61
|
+
var SLOTTABLE_IDENTIFIER = Symbol("radix.slottable");
|
|
62
|
+
// @__NO_SIDE_EFFECTS__
|
|
63
|
+
function createSlottable(ownerName) {
|
|
64
|
+
const Slottable2 = _ref => {
|
|
65
|
+
let {
|
|
66
|
+
children
|
|
67
|
+
} = _ref;
|
|
68
|
+
return /* @__PURE__ */React.createElement(React.Fragment, {
|
|
69
|
+
children
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
Slottable2.displayName = "".concat(ownerName, ".Slottable");
|
|
73
|
+
Slottable2.__radixId = SLOTTABLE_IDENTIFIER;
|
|
74
|
+
return Slottable2;
|
|
75
|
+
}
|
|
76
|
+
var Slottable = /* @__PURE__ */createSlottable("Slottable");
|
|
77
|
+
function isSlottable(child) {
|
|
78
|
+
return /*#__PURE__*/React.isValidElement(child) && typeof child.type === "function" && "__radixId" in child.type && child.type.__radixId === SLOTTABLE_IDENTIFIER;
|
|
79
|
+
}
|
|
80
|
+
function mergeProps(slotProps, childProps) {
|
|
81
|
+
const overrideProps = {
|
|
82
|
+
...childProps
|
|
83
|
+
};
|
|
84
|
+
for (const propName in childProps) {
|
|
85
|
+
const slotPropValue = slotProps[propName];
|
|
86
|
+
const childPropValue = childProps[propName];
|
|
87
|
+
const isHandler = /^on[A-Z]/.test(propName);
|
|
88
|
+
if (isHandler) {
|
|
89
|
+
if (slotPropValue && childPropValue) {
|
|
90
|
+
overrideProps[propName] = function () {
|
|
91
|
+
const result = childPropValue(...arguments);
|
|
92
|
+
slotPropValue(...arguments);
|
|
93
|
+
return result;
|
|
94
|
+
};
|
|
95
|
+
} else if (slotPropValue) {
|
|
96
|
+
overrideProps[propName] = slotPropValue;
|
|
97
|
+
}
|
|
98
|
+
} else if (propName === "style") {
|
|
99
|
+
overrideProps[propName] = {
|
|
100
|
+
...slotPropValue,
|
|
101
|
+
...childPropValue
|
|
102
|
+
};
|
|
103
|
+
} else if (propName === "className") {
|
|
104
|
+
overrideProps[propName] = [slotPropValue, childPropValue].filter(Boolean).join(" ");
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
...slotProps,
|
|
109
|
+
...overrideProps
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
function getElementRef(element) {
|
|
113
|
+
var _Object$getOwnPropert, _Object$getOwnPropert2;
|
|
114
|
+
let getter = (_Object$getOwnPropert = Object.getOwnPropertyDescriptor(element.props, "ref")) === null || _Object$getOwnPropert === void 0 ? void 0 : _Object$getOwnPropert.get;
|
|
115
|
+
let mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
|
|
116
|
+
if (mayWarn) {
|
|
117
|
+
return element.ref;
|
|
118
|
+
}
|
|
119
|
+
getter = (_Object$getOwnPropert2 = Object.getOwnPropertyDescriptor(element, "ref")) === null || _Object$getOwnPropert2 === void 0 ? void 0 : _Object$getOwnPropert2.get;
|
|
120
|
+
mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
|
|
121
|
+
if (mayWarn) {
|
|
122
|
+
return element.props.ref;
|
|
123
|
+
}
|
|
124
|
+
return element.props.ref || element.ref;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export { Slot as Root, Slot, Slottable, createSlot, createSlottable };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
// packages/react/use-callback-ref/src/use-callback-ref.tsx
|
|
4
|
+
function useCallbackRef(callback) {
|
|
5
|
+
const callbackRef = React.useRef(callback);
|
|
6
|
+
React.useEffect(() => {
|
|
7
|
+
callbackRef.current = callback;
|
|
8
|
+
});
|
|
9
|
+
return React.useMemo(() => function () {
|
|
10
|
+
var _callbackRef$current;
|
|
11
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
12
|
+
args[_key] = arguments[_key];
|
|
13
|
+
}
|
|
14
|
+
return (_callbackRef$current = callbackRef.current) === null || _callbackRef$current === void 0 ? void 0 : _callbackRef$current.call(callbackRef, ...args);
|
|
15
|
+
}, []);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { useCallbackRef };
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { useLayoutEffect as useLayoutEffect2 } from '../../react-use-layout-effect/dist/index.js';
|
|
3
|
+
import { useEffectEvent } from '../../react-use-effect-event/dist/index.js';
|
|
4
|
+
|
|
5
|
+
// src/use-controllable-state.tsx
|
|
6
|
+
var useInsertionEffect = React[" useInsertionEffect ".trim().toString()] || useLayoutEffect2;
|
|
7
|
+
function useControllableState(_ref) {
|
|
8
|
+
let {
|
|
9
|
+
prop,
|
|
10
|
+
defaultProp,
|
|
11
|
+
onChange = () => {},
|
|
12
|
+
caller
|
|
13
|
+
} = _ref;
|
|
14
|
+
const [uncontrolledProp, setUncontrolledProp, onChangeRef] = useUncontrolledState({
|
|
15
|
+
defaultProp,
|
|
16
|
+
onChange
|
|
17
|
+
});
|
|
18
|
+
const isControlled = prop !== void 0;
|
|
19
|
+
const value = isControlled ? prop : uncontrolledProp;
|
|
20
|
+
if (true) {
|
|
21
|
+
const isControlledRef = React.useRef(prop !== void 0);
|
|
22
|
+
React.useEffect(() => {
|
|
23
|
+
const wasControlled = isControlledRef.current;
|
|
24
|
+
if (wasControlled !== isControlled) {
|
|
25
|
+
const from = wasControlled ? "controlled" : "uncontrolled";
|
|
26
|
+
const to = isControlled ? "controlled" : "uncontrolled";
|
|
27
|
+
console.warn("".concat(caller, " is changing from ").concat(from, " to ").concat(to, ". Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component."));
|
|
28
|
+
}
|
|
29
|
+
isControlledRef.current = isControlled;
|
|
30
|
+
}, [isControlled, caller]);
|
|
31
|
+
}
|
|
32
|
+
const setValue = React.useCallback(nextValue => {
|
|
33
|
+
if (isControlled) {
|
|
34
|
+
const value2 = isFunction(nextValue) ? nextValue(prop) : nextValue;
|
|
35
|
+
if (value2 !== prop) {
|
|
36
|
+
var _onChangeRef$current;
|
|
37
|
+
(_onChangeRef$current = onChangeRef.current) === null || _onChangeRef$current === void 0 || _onChangeRef$current.call(onChangeRef, value2);
|
|
38
|
+
}
|
|
39
|
+
} else {
|
|
40
|
+
setUncontrolledProp(nextValue);
|
|
41
|
+
}
|
|
42
|
+
}, [isControlled, prop, setUncontrolledProp, onChangeRef]);
|
|
43
|
+
return [value, setValue];
|
|
44
|
+
}
|
|
45
|
+
function useUncontrolledState(_ref2) {
|
|
46
|
+
let {
|
|
47
|
+
defaultProp,
|
|
48
|
+
onChange
|
|
49
|
+
} = _ref2;
|
|
50
|
+
const [value, setValue] = React.useState(defaultProp);
|
|
51
|
+
const prevValueRef = React.useRef(value);
|
|
52
|
+
const onChangeRef = React.useRef(onChange);
|
|
53
|
+
useInsertionEffect(() => {
|
|
54
|
+
onChangeRef.current = onChange;
|
|
55
|
+
}, [onChange]);
|
|
56
|
+
React.useEffect(() => {
|
|
57
|
+
if (prevValueRef.current !== value) {
|
|
58
|
+
var _onChangeRef$current2;
|
|
59
|
+
(_onChangeRef$current2 = onChangeRef.current) === null || _onChangeRef$current2 === void 0 || _onChangeRef$current2.call(onChangeRef, value);
|
|
60
|
+
prevValueRef.current = value;
|
|
61
|
+
}
|
|
62
|
+
}, [value, prevValueRef]);
|
|
63
|
+
return [value, setValue, onChangeRef];
|
|
64
|
+
}
|
|
65
|
+
function isFunction(value) {
|
|
66
|
+
return typeof value === "function";
|
|
67
|
+
}
|
|
68
|
+
var SYNC_STATE = Symbol("RADIX:SYNC_STATE");
|
|
69
|
+
function useControllableStateReducer(reducer, userArgs, initialArg, init) {
|
|
70
|
+
const {
|
|
71
|
+
prop: controlledState,
|
|
72
|
+
defaultProp,
|
|
73
|
+
onChange: onChangeProp,
|
|
74
|
+
caller
|
|
75
|
+
} = userArgs;
|
|
76
|
+
const isControlled = controlledState !== void 0;
|
|
77
|
+
const onChange = useEffectEvent(onChangeProp);
|
|
78
|
+
if (true) {
|
|
79
|
+
const isControlledRef = React.useRef(controlledState !== void 0);
|
|
80
|
+
React.useEffect(() => {
|
|
81
|
+
const wasControlled = isControlledRef.current;
|
|
82
|
+
if (wasControlled !== isControlled) {
|
|
83
|
+
const from = wasControlled ? "controlled" : "uncontrolled";
|
|
84
|
+
const to = isControlled ? "controlled" : "uncontrolled";
|
|
85
|
+
console.warn("".concat(caller, " is changing from ").concat(from, " to ").concat(to, ". Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component."));
|
|
86
|
+
}
|
|
87
|
+
isControlledRef.current = isControlled;
|
|
88
|
+
}, [isControlled, caller]);
|
|
89
|
+
}
|
|
90
|
+
const args = [{
|
|
91
|
+
...initialArg,
|
|
92
|
+
state: defaultProp
|
|
93
|
+
}];
|
|
94
|
+
if (init) {
|
|
95
|
+
args.push(init);
|
|
96
|
+
}
|
|
97
|
+
const [internalState, dispatch] = React.useReducer((state2, action) => {
|
|
98
|
+
if (action.type === SYNC_STATE) {
|
|
99
|
+
return {
|
|
100
|
+
...state2,
|
|
101
|
+
state: action.state
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
const next = reducer(state2, action);
|
|
105
|
+
if (isControlled && !Object.is(next.state, state2.state)) {
|
|
106
|
+
onChange(next.state);
|
|
107
|
+
}
|
|
108
|
+
return next;
|
|
109
|
+
}, ...args);
|
|
110
|
+
const uncontrolledState = internalState.state;
|
|
111
|
+
const prevValueRef = React.useRef(uncontrolledState);
|
|
112
|
+
React.useEffect(() => {
|
|
113
|
+
if (prevValueRef.current !== uncontrolledState) {
|
|
114
|
+
prevValueRef.current = uncontrolledState;
|
|
115
|
+
if (!isControlled) {
|
|
116
|
+
onChange(uncontrolledState);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}, [onChange, uncontrolledState, prevValueRef, isControlled]);
|
|
120
|
+
const state = React.useMemo(() => {
|
|
121
|
+
const isControlled2 = controlledState !== void 0;
|
|
122
|
+
if (isControlled2) {
|
|
123
|
+
return {
|
|
124
|
+
...internalState,
|
|
125
|
+
state: controlledState
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
return internalState;
|
|
129
|
+
}, [internalState, controlledState]);
|
|
130
|
+
React.useEffect(() => {
|
|
131
|
+
if (isControlled && !Object.is(controlledState, internalState.state)) {
|
|
132
|
+
dispatch({
|
|
133
|
+
type: SYNC_STATE,
|
|
134
|
+
state: controlledState
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
}, [controlledState, internalState.state, isControlled]);
|
|
138
|
+
return [state, dispatch];
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export { useControllableState, useControllableStateReducer };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { useLayoutEffect as useLayoutEffect2 } from '../../react-use-layout-effect/dist/index.js';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
|
|
4
|
+
// src/use-effect-event.tsx
|
|
5
|
+
var useReactEffectEvent = React[" useEffectEvent ".trim().toString()];
|
|
6
|
+
var useReactInsertionEffect = React[" useInsertionEffect ".trim().toString()];
|
|
7
|
+
function useEffectEvent(callback) {
|
|
8
|
+
if (typeof useReactEffectEvent === "function") {
|
|
9
|
+
return useReactEffectEvent(callback);
|
|
10
|
+
}
|
|
11
|
+
const ref = React.useRef(() => {
|
|
12
|
+
throw new Error("Cannot call an event handler while rendering.");
|
|
13
|
+
});
|
|
14
|
+
if (typeof useReactInsertionEffect === "function") {
|
|
15
|
+
useReactInsertionEffect(() => {
|
|
16
|
+
ref.current = callback;
|
|
17
|
+
});
|
|
18
|
+
} else {
|
|
19
|
+
useLayoutEffect2(() => {
|
|
20
|
+
ref.current = callback;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
return React.useMemo(() => function () {
|
|
24
|
+
var _ref$current;
|
|
25
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
26
|
+
args[_key] = arguments[_key];
|
|
27
|
+
}
|
|
28
|
+
return (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.call(ref, ...args);
|
|
29
|
+
}, []);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export { useEffectEvent };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { useCallbackRef } from '../../react-use-callback-ref/dist/index.js';
|
|
3
|
+
|
|
4
|
+
// packages/react/use-escape-keydown/src/use-escape-keydown.tsx
|
|
5
|
+
function useEscapeKeydown(onEscapeKeyDownProp) {
|
|
6
|
+
let ownerDocument = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : globalThis === null || globalThis === void 0 ? void 0 : globalThis.document;
|
|
7
|
+
const onEscapeKeyDown = useCallbackRef(onEscapeKeyDownProp);
|
|
8
|
+
React.useEffect(() => {
|
|
9
|
+
const handleKeyDown = event => {
|
|
10
|
+
if (event.key === "Escape") {
|
|
11
|
+
onEscapeKeyDown(event);
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
ownerDocument.addEventListener("keydown", handleKeyDown, {
|
|
15
|
+
capture: true
|
|
16
|
+
});
|
|
17
|
+
return () => ownerDocument.removeEventListener("keydown", handleKeyDown, {
|
|
18
|
+
capture: true
|
|
19
|
+
});
|
|
20
|
+
}, [onEscapeKeyDown, ownerDocument]);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { useEscapeKeydown };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
// packages/react/use-layout-effect/src/use-layout-effect.tsx
|
|
4
|
+
var useLayoutEffect2 = globalThis !== null && globalThis !== void 0 && globalThis.document ? React.useLayoutEffect : () => {};
|
|
5
|
+
|
|
6
|
+
export { useLayoutEffect2 as useLayoutEffect };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { useLayoutEffect as useLayoutEffect2 } from '../../react-use-layout-effect/dist/index.js';
|
|
3
|
+
|
|
4
|
+
// packages/react/use-size/src/use-size.tsx
|
|
5
|
+
function useSize(element) {
|
|
6
|
+
const [size, setSize] = React.useState(void 0);
|
|
7
|
+
useLayoutEffect2(() => {
|
|
8
|
+
if (element) {
|
|
9
|
+
setSize({
|
|
10
|
+
width: element.offsetWidth,
|
|
11
|
+
height: element.offsetHeight
|
|
12
|
+
});
|
|
13
|
+
const resizeObserver = new ResizeObserver(entries => {
|
|
14
|
+
if (!Array.isArray(entries)) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if (!entries.length) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const entry = entries[0];
|
|
21
|
+
let width;
|
|
22
|
+
let height;
|
|
23
|
+
if ("borderBoxSize" in entry) {
|
|
24
|
+
const borderSizeEntry = entry["borderBoxSize"];
|
|
25
|
+
const borderSize = Array.isArray(borderSizeEntry) ? borderSizeEntry[0] : borderSizeEntry;
|
|
26
|
+
width = borderSize["inlineSize"];
|
|
27
|
+
height = borderSize["blockSize"];
|
|
28
|
+
} else {
|
|
29
|
+
width = element.offsetWidth;
|
|
30
|
+
height = element.offsetHeight;
|
|
31
|
+
}
|
|
32
|
+
setSize({
|
|
33
|
+
width,
|
|
34
|
+
height
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
resizeObserver.observe(element, {
|
|
38
|
+
box: "border-box"
|
|
39
|
+
});
|
|
40
|
+
return () => resizeObserver.unobserve(element);
|
|
41
|
+
} else {
|
|
42
|
+
setSize(void 0);
|
|
43
|
+
}
|
|
44
|
+
}, [element]);
|
|
45
|
+
return size;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export { useSize };
|