@ringcentral/spring-ui 1.11.2 → 1.13.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/Accordion.js +90 -34
- package/AccordionHeader.js +72 -20
- package/Alert.js +120 -28
- package/Animation.js +2 -45
- package/Announcement.js +46 -35
- package/Autocomplete.js +1011 -580
- package/Avatar.js +134 -73
- package/AvatarGroup.js +50 -7
- package/Backdrop.js +45 -7
- package/Badge.js +77 -15
- package/Block.js +34 -12
- package/BlockHeader.js +55 -11
- package/BottomNavigation.js +181 -65
- package/BottomNavigationItem.js +93 -30
- package/Button.js +160 -24
- package/CallButton.js +53 -31
- package/Checkbox.js +88 -26
- package/Chip.js +126 -26
- package/CircularProgressIndicator.js +80 -8
- package/ClickAwayListener.js +4 -1
- package/ComponentsProps.js +1 -0
- package/DatePicker.js +611 -190
- package/DateUtilsContext.js +43 -25
- package/Dialer.js +576 -250
- package/Dialog.js +100 -45
- package/Divider.js +43 -7
- package/DragHandle.js +32 -6
- package/Drawer.js +117 -19
- package/Dropdown.js +154 -74
- package/EmptyState.js +63 -11
- package/FabButton.js +51 -17
- package/FocusTrap.js +109 -12
- package/FormField.js +106 -8
- package/FormLabel.js +81 -7
- package/Icon.js +1 -8
- package/IconButton.js +142 -26
- package/IconButtonGroup.js +35 -12
- package/InlineEditable.js +98 -44
- package/LinearProgressIndicator.js +73 -24
- package/Link.js +40 -11
- package/List.js +54 -9
- package/ListItem.js +152 -23
- package/ListItemText.js +44 -16
- package/ListNavigation.js +272 -20
- package/Menu.js +139 -23
- package/MenuActions.js +37 -12
- package/MenuDivider.js +34 -8
- package/MenuFooter.js +36 -12
- package/MenuHeader.js +54 -15
- package/MenuItem.js +402 -33
- package/MenuItemText.js +51 -8
- package/MenuList.js +87 -34
- package/Modal.js +345 -16
- package/NestedMenuContext.js +183 -11
- package/Option.js +32 -34
- package/Overlap.js +54 -7
- package/PageHeader.js +62 -24
- package/PickerTextField.js +156 -33
- package/Popover.js +262 -21
- package/Popper.js +130 -77
- package/PopperPaper.js +54 -8
- package/Portal.js +6 -1
- package/Radio.js +65 -21
- package/RadioGroup.js +56 -17
- package/Rating.js +223 -87
- package/Select.js +387 -41
- package/SingleFilter.js +148 -77
- package/Skeleton.js +68 -17
- package/Slider.js +168 -69
- package/Snackbar.js +122 -59
- package/SortableList.js +32 -12
- package/SortableListDndContext.js +69 -22
- package/SortableListItem.js +92 -47
- package/SortableVirtualizedList.js +52 -28
- package/SplitButton.js +124 -86
- package/Squircle.js +4 -7
- package/StatusIndicator.js +51 -9
- package/Step.js +63 -38
- package/StepButton.js +51 -23
- package/StepConnector.js +48 -8
- package/StepContent.js +68 -25
- package/StepIcon.js +90 -9
- package/StepLabel.js +90 -14
- package/Stepper.js +65 -23
- package/SubMenu.js +203 -99
- package/SwipeableDrawer.js +439 -194
- package/Switch.js +70 -23
- package/Tab.js +120 -57
- package/TabContext.js +59 -15
- package/TabPanel.js +40 -13
- package/Table.js +60 -17
- package/TableBody.js +42 -12
- package/TableCell.js +84 -50
- package/TableContainer.js +32 -10
- package/TableFooter.js +38 -10
- package/TableHead.js +49 -15
- package/TablePagination.js +153 -77
- package/TableRow.js +60 -21
- package/Tabs.js +593 -268
- package/Tag.js +51 -16
- package/Text.js +68 -37
- package/TextField.js +209 -29
- package/Textarea.js +51 -40
- package/TimePicker.js +490 -230
- package/Tooltip.js +48 -23
- package/Tray.js +237 -13
- package/TrayMenu.js +62 -41
- package/VirtualizedList.js +208 -109
- package/VirtualizedMenu.js +359 -29
- package/VisuallyHidden.js +29 -6
- package/chunks/1250.js +98 -0
- package/chunks/1294.js +126 -0
- package/chunks/2956.js +18 -0
- package/chunks/4476.js +460 -0
- package/chunks/4491.js +10 -0
- package/chunks/4535.js +364 -0
- package/chunks/5047.js +3 -0
- package/chunks/6335.js +24 -0
- package/chunks/7279.js +10 -0
- package/chunks/8011.js +8 -0
- package/chunks/8307.js +56 -0
- package/chunks/8467.js +8 -0
- package/chunks/8809.js +8 -0
- package/chunks/{RadioGroup.context.js → 9551.js} +12 -6
- package/chunks/987.js +8 -0
- package/index.css +2624 -2416
- package/index.js +245 -193
- package/internal/utils/index.d.ts +1 -0
- package/internal/utils/setRef.d.ts +2 -0
- package/package.json +8 -8
- package/src/Alert/Alert.type.d.ts +2 -1
- package/src/Animation/components/Fade/Fade.d.ts +4 -2
- package/src/Animation/components/Grow/Grow.d.ts +4 -2
- package/src/Animation/components/ShowHideEye/ShowHideEye.d.ts +1 -1
- package/src/Animation/components/SlideIn/SlideIn.d.ts +4 -2
- package/src/Animation/components/SlideIn/getSlideIn.d.ts +1 -1
- package/src/Animation/hooks/useMotionSafeTransition/useMotionSafeTransition.d.ts +2 -0
- package/src/Autocomplete/SuggestionList/SuggestionList.d.ts +1 -1
- package/src/Autocomplete/useAutocomplete.d.ts +18 -18
- package/src/Autocomplete/useAutocompleteTag.d.ts +18 -18
- package/src/Badge/Badge.d.ts +2 -1
- package/src/Button/Button.classes.d.ts +1 -1
- package/src/ComponentsProps.d.ts +111 -110
- package/src/DatePicker/DatePickerDataAttributes.d.ts +11 -0
- package/src/DatePicker/utils/DatePickerAriaLabelUtils.d.ts +2 -1
- package/src/DatePicker/utils/DatePickerUtils.d.ts +1 -1
- package/src/Dialer/DialDelete/DialDelete.d.ts +2 -2
- package/src/Dialer/DialPad/DialPad.d.ts +2 -2
- package/src/Dialer/Dialer.d.ts +4 -2
- package/src/Dropdown/Dropdown.type.d.ts +2 -2
- package/src/InlineEditable/InlineEditable.type.d.ts +2 -1
- package/src/ListNavigation/useListNavigation.d.ts +3 -3
- package/src/MenuActions/MenuActions.d.ts +2 -2
- package/src/MenuItem/MenuItem.type.d.ts +1 -0
- package/src/MenuItem/useMenuItem.d.ts +1 -1
- package/src/MenuItem/useVirtualizedMenuItem.d.ts +1 -1
- package/src/MenuList/MenuList.type.d.ts +1 -1
- package/src/MenuList/MenuListContext.d.ts +2 -3
- package/src/Modal/Modal.type.d.ts +1 -0
- package/src/NestedMenuContext/MenuOverlayGroupContext.d.ts +2 -2
- package/src/Popover/Popover.classes.d.ts +1 -1
- package/src/Popover/Popover.internal.d.ts +8 -0
- package/src/Popover/Popover.type.d.ts +1 -0
- package/src/Popper/Popper.type.d.ts +10 -7
- package/src/Rating/utils.d.ts +3 -2
- package/src/Select/Select.type.d.ts +7 -5
- package/src/Slider/Slider.d.ts +2 -2
- package/src/Slider/SliderThumb.d.ts +2 -1
- package/src/Squircle/Squircle.d.ts +1 -1
- package/src/StatusIndicator/StatusIndicator.d.ts +2 -1
- package/src/SubMenu/PopperMenu.type.d.ts +4 -1
- package/src/Table/Table.type.d.ts +3 -0
- package/src/Table/TableContext.d.ts +3 -0
- package/src/Table/TableRowContext.d.ts +7 -0
- package/src/Table/index.d.ts +1 -0
- package/src/TableCell/TableCell.classes.d.ts +1 -1
- package/src/TableFooter/TableFooter.classes.d.ts +1 -1
- package/src/TableFooter/TableFooter.type.d.ts +1 -0
- package/src/TableHead/TableHead.classes.d.ts +1 -1
- package/src/TableHead/TableHead.type.d.ts +1 -0
- package/src/TableRow/TableRow.type.d.ts +2 -0
- package/chunks/AccordionContext.js +0 -6
- package/chunks/Alert.js +0 -48
- package/chunks/AvatarGroup.js +0 -22
- package/chunks/Backdrop.js +0 -18
- package/chunks/Badge.js +0 -32
- package/chunks/BottomNavigationItem.js +0 -36
- package/chunks/Button.js +0 -88
- package/chunks/Chip.js +0 -73
- package/chunks/CircularProgressIndicator.js +0 -36
- package/chunks/Divider.js +0 -19
- package/chunks/DragHandle.js +0 -11
- package/chunks/Drawer.js +0 -32
- package/chunks/ExpandCollapseCaret.js +0 -24
- package/chunks/FormLabel.js +0 -27
- package/chunks/Icon.js +0 -25
- package/chunks/IconButtonLabel.js +0 -68
- package/chunks/List.js +0 -22
- package/chunks/ListItem.js +0 -83
- package/chunks/Menu.js +0 -61
- package/chunks/MenuDivider.js +0 -14
- package/chunks/MenuItemText.js +0 -17
- package/chunks/MenuList.js +0 -46
- package/chunks/Modal.js +0 -212
- package/chunks/Overlap.js +0 -25
- package/chunks/PickerTextField.js +0 -85
- package/chunks/Popover.js +0 -53
- package/chunks/PopperPaper.js +0 -15
- package/chunks/Select.js +0 -220
- package/chunks/ShowHideEye.js +0 -56
- package/chunks/SlideIn.js +0 -19
- package/chunks/SortableArrow.js +0 -73
- package/chunks/Squircle.js +0 -31
- package/chunks/StatusIndicator.js +0 -20
- package/chunks/StepConnector.js +0 -21
- package/chunks/StepIcon.js +0 -43
- package/chunks/StepLabel.js +0 -29
- package/chunks/StepperContext.js +0 -9
- package/chunks/TableContext.js +0 -6
- package/chunks/Tablelvl2Context.js +0 -6
- package/chunks/TabsContext.js +0 -6
- package/chunks/TextField.js +0 -110
- package/chunks/Tooltip.js +0 -217
- package/chunks/VirtualizedMenu.js +0 -164
- package/chunks/VisuallyHidden.js +0 -12
- package/chunks/getFade.js +0 -27
- package/chunks/getGrow.js +0 -70
- package/chunks/getSlideIn.js +0 -30
- package/chunks/hasContent.js +0 -3
- package/chunks/useAnimationFrame.js +0 -15
- package/chunks/useFocusTrapStack.js +0 -36
- package/chunks/useHelperTextId.js +0 -22
- package/chunks/useListNavigation.js +0 -199
- package/chunks/useMenuItemSelect.js +0 -273
- package/chunks/useMotionSafeTransition.js +0 -9
- package/chunks/useNestedMenuItem.js +0 -27
- package/chunks/useNestedParentMenu.js +0 -113
- package/chunks/usePrefersReducedMotion.js +0 -36
- package/chunks/useTooltipForceHide.js +0 -27
- package/chunks/useTrayNavigate.js +0 -150
- package/chunks/withTooltip.js +0 -15
package/VirtualizedList.js
CHANGED
|
@@ -1,85 +1,139 @@
|
|
|
1
|
-
import { createContext,
|
|
2
|
-
import { jsx } from
|
|
3
|
-
import {
|
|
4
|
-
import { useThemeProps } from
|
|
5
|
-
import { Virtuoso } from
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { createContext, forwardRef, isValidElement, useContext, useEffect, useImperativeHandle, useRef, useState } from "react";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { logInDev, useEventCallback, useForkRef, useVirtuosoExternalWindow } from "@ringcentral/spring-base";
|
|
4
|
+
import { useThemeProps } from "@ringcentral/spring-theme";
|
|
5
|
+
import { Virtuoso } from "react-virtuoso";
|
|
6
|
+
import { List as List_List } from "./List.js";
|
|
7
|
+
import { useAnimationFrame } from "./chunks/6335.js";
|
|
8
|
+
|
|
9
|
+
|
|
10
10
|
|
|
11
11
|
const VirtualizedItemPropsContext = createContext(null);
|
|
12
|
-
const useVirtualizedItemPropsContext = ()
|
|
12
|
+
const useVirtualizedItemPropsContext = ()=>useContext(VirtualizedItemPropsContext);
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
13
25
|
|
|
14
|
-
|
|
26
|
+
|
|
27
|
+
const DATA_ITEM_INDEX_ATTR = 'data-item-index';
|
|
28
|
+
const VirtuosoList = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
15
29
|
const { children: childrenProp, context, style, ...rest } = props;
|
|
16
|
-
const { searchAndFocusItemHandler, isScrolling, ListProps, listActions, listRef, itemContentRenderer, data, keepInvisibleItems, computeItemKey
|
|
30
|
+
const { searchAndFocusItemHandler, isScrolling, ListProps, listActions, listRef, itemContentRenderer, data, keepInvisibleItems, computeItemKey } = context;
|
|
17
31
|
const handleListRef = useForkRef(listRef, ref);
|
|
18
32
|
let rangeStart = null;
|
|
19
33
|
let rangeEnd = null;
|
|
20
34
|
let children = childrenProp;
|
|
21
35
|
if (keepInvisibleItems && computeItemKey && Array.isArray(childrenProp)) {
|
|
22
36
|
const firstChild = childrenProp[0];
|
|
23
|
-
if (firstChild && isValidElement(firstChild)) {
|
|
24
|
-
const index = Number(firstChild.props
|
|
37
|
+
if (firstChild && /*#__PURE__*/ isValidElement(firstChild)) {
|
|
38
|
+
const index = Number(firstChild.props[DATA_ITEM_INDEX_ATTR]);
|
|
25
39
|
rangeStart = Number.isNaN(index) ? null : index;
|
|
26
40
|
}
|
|
27
41
|
const lastChild = childrenProp.at(-1);
|
|
28
|
-
if (lastChild && isValidElement(lastChild)) {
|
|
29
|
-
const index = Number(lastChild.props
|
|
42
|
+
if (lastChild && /*#__PURE__*/ isValidElement(lastChild)) {
|
|
43
|
+
const index = Number(lastChild.props[DATA_ITEM_INDEX_ATTR]);
|
|
30
44
|
rangeEnd = Number.isNaN(index) ? null : index;
|
|
31
45
|
}
|
|
32
46
|
children = [
|
|
33
|
-
...
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
47
|
+
...rangeStart !== null ? keepInvisibleItems// oxlint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
48
|
+
.filter((itemIndex)=>itemIndex < rangeStart).map((itemIndex)=>{
|
|
49
|
+
const itemData = data ? data[itemIndex] : itemIndex;
|
|
50
|
+
return /*#__PURE__*/ jsx(InnerItem, {
|
|
51
|
+
"data-sticky-index": itemIndex,
|
|
52
|
+
style: {
|
|
53
|
+
left: 0,
|
|
54
|
+
top: 0,
|
|
55
|
+
position: 'absolute'
|
|
56
|
+
},
|
|
57
|
+
children: itemContentRenderer(itemIndex, itemData, context)
|
|
58
|
+
}, computeItemKey(itemIndex, itemData, context));
|
|
59
|
+
}) : [],
|
|
45
60
|
...childrenProp,
|
|
46
|
-
...
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
61
|
+
...rangeEnd !== null ? keepInvisibleItems// oxlint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
62
|
+
.filter((itemIndex)=>itemIndex > rangeEnd).map((itemIndex)=>{
|
|
63
|
+
const itemData = data ? data[itemIndex] : itemIndex;
|
|
64
|
+
return /*#__PURE__*/ jsx(InnerItem, {
|
|
65
|
+
"data-sticky-index": itemIndex,
|
|
66
|
+
style: {
|
|
67
|
+
left: 0,
|
|
68
|
+
bottom: 0,
|
|
69
|
+
position: 'absolute'
|
|
70
|
+
},
|
|
71
|
+
children: itemContentRenderer(itemIndex, itemData, context)
|
|
72
|
+
}, computeItemKey(itemIndex, itemData, context));
|
|
73
|
+
}) : []
|
|
58
74
|
];
|
|
59
75
|
}
|
|
60
|
-
return
|
|
76
|
+
return /*#__PURE__*/ jsx(List_List, {
|
|
77
|
+
...ListProps,
|
|
78
|
+
...rest,
|
|
79
|
+
actions: listActions,
|
|
80
|
+
style: {
|
|
61
81
|
...ListProps?.style,
|
|
62
82
|
...style,
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
83
|
+
// optimize list scrolling
|
|
84
|
+
...isScrolling ? {
|
|
85
|
+
pointerEvents: 'none'
|
|
86
|
+
} : undefined,
|
|
87
|
+
// for prop `keepInvisibleItems`
|
|
88
|
+
position: 'relative'
|
|
89
|
+
},
|
|
90
|
+
preventContainerScroll: false,
|
|
91
|
+
ref: handleListRef,
|
|
92
|
+
searchAndFocusItemHandler: searchAndFocusItemHandler,
|
|
93
|
+
children: children
|
|
94
|
+
});
|
|
66
95
|
});
|
|
67
|
-
const Scroller = forwardRef((props, ref)
|
|
96
|
+
const Scroller = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
68
97
|
const { children, context, ...rest } = props;
|
|
69
98
|
const handleRef = useForkRef(ref, context?.scrollerRef);
|
|
70
|
-
return
|
|
99
|
+
return /*#__PURE__*/ jsx("div", {
|
|
100
|
+
...rest,
|
|
101
|
+
ref: handleRef,
|
|
102
|
+
tabIndex: undefined,
|
|
103
|
+
children: children
|
|
104
|
+
});
|
|
71
105
|
});
|
|
72
|
-
const InnerItem = (props)
|
|
106
|
+
const InnerItem = (props)=>{
|
|
73
107
|
const { children, ...rest } = props;
|
|
74
|
-
return
|
|
108
|
+
return /*#__PURE__*/ jsx(VirtualizedItemPropsContext.Provider, {
|
|
109
|
+
value: rest,
|
|
110
|
+
children: children
|
|
111
|
+
});
|
|
75
112
|
};
|
|
76
113
|
const Item = InnerItem;
|
|
77
|
-
const VirtuosoComponents = {
|
|
114
|
+
const VirtuosoComponents = {
|
|
115
|
+
Item: Item,
|
|
116
|
+
Scroller: Scroller,
|
|
117
|
+
List: VirtuosoList
|
|
118
|
+
};
|
|
119
|
+
|
|
78
120
|
|
|
79
|
-
|
|
80
|
-
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
const VirtualizedList = /*#__PURE__*/ forwardRef((inProps, ref)=>{
|
|
128
|
+
const props = useThemeProps({
|
|
129
|
+
props: inProps,
|
|
130
|
+
name: 'VirtualizedList'
|
|
131
|
+
});
|
|
81
132
|
const { children, totalCount, data, isScrolling: handleScroll, rangeChanged: handleRangeChanged, virtuosoActions, actions, ListProps, isItemDisabled, infinite = false, isReady = true, context, components, keepInvisibleItems, computeItemKey, firstFocusIndex = 0, ...rest } = props;
|
|
82
|
-
const listRangeRef = useRef({
|
|
133
|
+
const listRangeRef = useRef({
|
|
134
|
+
startIndex: -1,
|
|
135
|
+
endIndex: -1
|
|
136
|
+
});
|
|
83
137
|
const [isScrolling, setIsScrolling] = useState(false);
|
|
84
138
|
const listRef = useRef(null);
|
|
85
139
|
const virtuosoRef = useRef(null);
|
|
@@ -88,51 +142,60 @@ const VirtualizedList = forwardRef((inProps, ref) => {
|
|
|
88
142
|
const itemRenderedPromiseRef = useRef(null);
|
|
89
143
|
const { requestAnimationFrame } = useAnimationFrame();
|
|
90
144
|
const externalWindowProps = useVirtuosoExternalWindow();
|
|
91
|
-
const isItemRendered = (index)
|
|
145
|
+
const isItemRendered = (index)=>{
|
|
92
146
|
const { startIndex, endIndex } = listRangeRef.current;
|
|
93
147
|
return index <= endIndex && index >= startIndex;
|
|
94
148
|
};
|
|
95
|
-
const focusItemByIndex = (index)
|
|
96
|
-
|
|
97
|
-
|
|
149
|
+
const focusItemByIndex = (index)=>{
|
|
150
|
+
/**
|
|
151
|
+
* If the component isn't ready, we need to defer the focus action until the component is ready.
|
|
152
|
+
* This is necessary if a parent component is waiting for some height calculation of the list to
|
|
153
|
+
* be performed before it actually renders the list. If we didn't do this the component would not
|
|
154
|
+
* know where to scroll to/would scroll to an incorrect position as it has not yet fully rendered.
|
|
155
|
+
*/ if (!isReady) {
|
|
156
|
+
new Promise((resolve)=>{
|
|
98
157
|
initialFocusItemByIndexPromiseRef.current = resolve;
|
|
99
|
-
}).then(()
|
|
100
|
-
|
|
158
|
+
}).then(()=>{
|
|
159
|
+
// Wrap in rAF to ensure height has truly settled before focusing
|
|
160
|
+
requestAnimationFrame(()=>focusByIndexAction(index));
|
|
101
161
|
});
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const focusTarget = () => {
|
|
162
|
+
} else {
|
|
163
|
+
const focusTarget = ()=>{
|
|
105
164
|
const targetItem = listRef.current?.querySelector(`[data-item-index="${index}"]`);
|
|
106
165
|
if (process.env.NODE_ENV !== 'production' && !targetItem) {
|
|
107
166
|
logInDev({
|
|
108
167
|
scope: 'VirtualizedList',
|
|
109
168
|
level: 'warn',
|
|
110
|
-
message: `Can't find the target item with index \`${index}\`. Please ensure \`getSelectedIndex\` can find the index in your data array
|
|
169
|
+
message: `Can't find the target item with index \`${index}\`. Please ensure \`getSelectedIndex\` can find the index in your data array.`
|
|
111
170
|
});
|
|
112
171
|
}
|
|
113
172
|
targetItem?.focus();
|
|
114
173
|
};
|
|
115
174
|
if (!isItemRendered(index)) {
|
|
116
|
-
new Promise((resolve)
|
|
117
|
-
itemRenderedPromiseRef.current = {
|
|
118
|
-
|
|
175
|
+
new Promise((resolve)=>{
|
|
176
|
+
itemRenderedPromiseRef.current = {
|
|
177
|
+
resolve,
|
|
178
|
+
itemIndex: index
|
|
179
|
+
};
|
|
180
|
+
}).then(()=>{
|
|
119
181
|
focusTarget();
|
|
120
182
|
});
|
|
121
|
-
virtuosoRef.current?.scrollToIndex({
|
|
122
|
-
|
|
123
|
-
|
|
183
|
+
virtuosoRef.current?.scrollToIndex({
|
|
184
|
+
index,
|
|
185
|
+
align: 'center'
|
|
186
|
+
});
|
|
187
|
+
} else {
|
|
124
188
|
focusTarget();
|
|
125
189
|
}
|
|
126
190
|
}
|
|
127
191
|
};
|
|
128
|
-
const isDisabled = (index)
|
|
129
|
-
if (!isItemDisabled)
|
|
130
|
-
return false;
|
|
192
|
+
const isDisabled = (index)=>{
|
|
193
|
+
if (!isItemDisabled) return false;
|
|
131
194
|
return isItemDisabled(index);
|
|
132
195
|
};
|
|
133
|
-
const searchAndFocusItemHandler = (searchElementOption)
|
|
196
|
+
const searchAndFocusItemHandler = (searchElementOption)=>{
|
|
134
197
|
const firstItemIndex = 0;
|
|
135
|
-
const lastItemIndex = (()
|
|
198
|
+
const lastItemIndex = (()=>{
|
|
136
199
|
if (data) {
|
|
137
200
|
return data.length - 1;
|
|
138
201
|
}
|
|
@@ -144,17 +207,17 @@ const VirtualizedList = forwardRef((inProps, ref) => {
|
|
|
144
207
|
if (searchElementOption === 'first') {
|
|
145
208
|
startIndex = firstFocusIndex;
|
|
146
209
|
direction = 'down';
|
|
147
|
-
}
|
|
148
|
-
else {
|
|
210
|
+
} else {
|
|
149
211
|
startIndex = lastItemIndex;
|
|
150
212
|
direction = 'up';
|
|
151
213
|
}
|
|
152
214
|
if (!isDisabled(startIndex)) {
|
|
153
215
|
focusItemByIndex(startIndex);
|
|
154
|
-
return {
|
|
216
|
+
return {
|
|
217
|
+
focused: true
|
|
218
|
+
};
|
|
155
219
|
}
|
|
156
|
-
}
|
|
157
|
-
else {
|
|
220
|
+
} else {
|
|
158
221
|
startIndex = Number(searchElementOption.baseElement.dataset['itemIndex']);
|
|
159
222
|
direction = searchElementOption.direction;
|
|
160
223
|
}
|
|
@@ -163,69 +226,75 @@ const VirtualizedList = forwardRef((inProps, ref) => {
|
|
|
163
226
|
if (direction === 'up') {
|
|
164
227
|
do {
|
|
165
228
|
if (pointer - 1 < firstItemIndex) {
|
|
229
|
+
// disabled focus loop when infinite is true
|
|
166
230
|
if (infinite) {
|
|
167
231
|
pointer = startIndex;
|
|
168
|
-
}
|
|
169
|
-
else {
|
|
232
|
+
} else {
|
|
170
233
|
pointer = lastItemIndex;
|
|
171
234
|
}
|
|
172
235
|
isAfterBaseElement = false;
|
|
173
|
-
}
|
|
174
|
-
else {
|
|
236
|
+
} else {
|
|
175
237
|
pointer--;
|
|
176
238
|
}
|
|
177
239
|
if (!isDisabled(pointer)) {
|
|
178
240
|
break;
|
|
179
241
|
}
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
else {
|
|
242
|
+
}while (pointer !== startIndex);
|
|
243
|
+
} else {
|
|
183
244
|
do {
|
|
184
245
|
if (pointer + 1 > lastItemIndex) {
|
|
246
|
+
// disabled focus loop when infinite is true
|
|
185
247
|
if (infinite) {
|
|
186
248
|
pointer = startIndex;
|
|
187
|
-
}
|
|
188
|
-
else {
|
|
249
|
+
} else {
|
|
189
250
|
pointer = firstItemIndex;
|
|
190
251
|
}
|
|
191
252
|
isAfterBaseElement = false;
|
|
192
|
-
}
|
|
193
|
-
else {
|
|
253
|
+
} else {
|
|
194
254
|
pointer++;
|
|
195
255
|
}
|
|
196
256
|
if (!isDisabled(pointer)) {
|
|
197
257
|
break;
|
|
198
258
|
}
|
|
199
|
-
}
|
|
259
|
+
}while (pointer !== startIndex);
|
|
200
260
|
}
|
|
201
261
|
if (isDisabled(pointer)) {
|
|
202
|
-
return {
|
|
262
|
+
return {
|
|
263
|
+
focused: false
|
|
264
|
+
};
|
|
203
265
|
}
|
|
204
266
|
focusItemByIndex(pointer);
|
|
205
|
-
return typeof searchElementOption === 'string'
|
|
206
|
-
|
|
207
|
-
|
|
267
|
+
return typeof searchElementOption === 'string' ? {
|
|
268
|
+
focused: true
|
|
269
|
+
} : {
|
|
270
|
+
focused: true,
|
|
271
|
+
isAfterBaseElement
|
|
272
|
+
};
|
|
208
273
|
};
|
|
209
274
|
const listActions = useRef(null);
|
|
210
|
-
const focusByIndexAction = useEventCallback((i)
|
|
275
|
+
const focusByIndexAction = useEventCallback((i)=>{
|
|
211
276
|
if (isDisabled(i)) {
|
|
212
277
|
listActions.current?.focus();
|
|
213
|
-
}
|
|
214
|
-
else {
|
|
278
|
+
} else {
|
|
215
279
|
focusItemByIndex(i);
|
|
216
280
|
}
|
|
217
281
|
});
|
|
218
|
-
useImperativeHandle(actions, ()
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
282
|
+
useImperativeHandle(actions, ()=>({
|
|
283
|
+
focus: ()=>{
|
|
284
|
+
listActions.current?.focus();
|
|
285
|
+
},
|
|
286
|
+
focusByIndex: focusByIndexAction
|
|
287
|
+
}), [
|
|
288
|
+
focusByIndexAction
|
|
289
|
+
]);
|
|
290
|
+
useEffect(()=>{
|
|
291
|
+
// Execute the initial focus item by index promise when the list is ready
|
|
225
292
|
if (isReady) {
|
|
226
293
|
initialFocusItemByIndexPromiseRef.current?.();
|
|
227
294
|
}
|
|
228
|
-
}, [
|
|
295
|
+
}, [
|
|
296
|
+
isReady
|
|
297
|
+
]);
|
|
229
298
|
const virtuosoContext = {
|
|
230
299
|
listRef,
|
|
231
300
|
scrollerRef: ref,
|
|
@@ -236,9 +305,29 @@ const VirtualizedList = forwardRef((inProps, ref) => {
|
|
|
236
305
|
data,
|
|
237
306
|
keepInvisibleItems,
|
|
238
307
|
itemContentRenderer: children,
|
|
239
|
-
computeItemKey: computeItemKey
|
|
308
|
+
computeItemKey: computeItemKey
|
|
240
309
|
};
|
|
241
|
-
return
|
|
310
|
+
return /*#__PURE__*/ jsx(Virtuoso, {
|
|
311
|
+
className: "sui-virtualized-list",
|
|
312
|
+
...externalWindowProps,
|
|
313
|
+
ref: handleVirtuosoRef,
|
|
314
|
+
// pre-render, make scroll smooth when move focus
|
|
315
|
+
increaseViewportBy: 200,
|
|
316
|
+
...computeItemKey ? {
|
|
317
|
+
computeItemKey
|
|
318
|
+
} : undefined,
|
|
319
|
+
...rest,
|
|
320
|
+
context: {
|
|
321
|
+
...context,
|
|
322
|
+
...virtuosoContext
|
|
323
|
+
},
|
|
324
|
+
components: {
|
|
325
|
+
...VirtuosoComponents,
|
|
326
|
+
...components
|
|
327
|
+
},
|
|
328
|
+
totalCount: totalCount,
|
|
329
|
+
data: data,
|
|
330
|
+
rangeChanged: (range)=>{
|
|
242
331
|
listRangeRef.current = range;
|
|
243
332
|
const itemRenderedPromise = itemRenderedPromiseRef.current;
|
|
244
333
|
if (itemRenderedPromise) {
|
|
@@ -249,11 +338,21 @@ const VirtualizedList = forwardRef((inProps, ref) => {
|
|
|
249
338
|
}
|
|
250
339
|
}
|
|
251
340
|
handleRangeChanged?.(range);
|
|
252
|
-
},
|
|
341
|
+
},
|
|
342
|
+
isScrolling: (isScrolling)=>{
|
|
253
343
|
setIsScrolling(isScrolling);
|
|
254
344
|
handleScroll?.(isScrolling);
|
|
255
|
-
},
|
|
345
|
+
},
|
|
346
|
+
itemContent: children
|
|
347
|
+
});
|
|
256
348
|
});
|
|
257
349
|
VirtualizedList.displayName = 'SuiVirtualizedList';
|
|
258
350
|
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
|
|
259
358
|
export { VirtualizedItemPropsContext, VirtualizedList, VirtuosoComponents, useVirtualizedItemPropsContext };
|