@laser-ui/components 1.6.1 → 2.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.
- package/CHANGELOG.md +10 -0
- package/accordion/Accordion.d.ts +1 -1
- package/accordion/Accordion.js +13 -25
- package/accordion/types.d.ts +1 -0
- package/affix/Affix.d.ts +2 -2
- package/affix/Affix.js +27 -32
- package/affix/types.d.ts +7 -2
- package/alert/Alert.d.ts +1 -1
- package/alert/Alert.js +12 -21
- package/anchor/Anchor.d.ts +2 -4
- package/anchor/Anchor.js +34 -26
- package/anchor/types.d.ts +1 -0
- package/avatar/Avatar.d.ts +1 -1
- package/avatar/Avatar.js +9 -3
- package/badge/Badge.d.ts +1 -1
- package/badge/Badge.js +22 -41
- package/badge/BadgeText.js +12 -26
- package/badge/internal/BadgeNumber.d.ts +2 -2
- package/badge/internal/BadgeNumber.js +34 -24
- package/base-input/BaseInput.d.ts +1 -2
- package/base-input/BaseInput.js +4 -4
- package/base-input/types.d.ts +1 -0
- package/breadcrumb/Breadcrumb.d.ts +1 -1
- package/button/Button.d.ts +1 -2
- package/button/Button.js +18 -22
- package/button/types.d.ts +1 -0
- package/card/Card.d.ts +1 -1
- package/card/CardAction.d.ts +1 -1
- package/card/CardAction.js +3 -4
- package/card/CardActions.d.ts +1 -1
- package/card/CardActions.js +7 -3
- package/card/CardContent.d.ts +1 -1
- package/card/CardHeader.d.ts +1 -1
- package/card/types.d.ts +5 -1
- package/cascader/Cascader.d.ts +2 -4
- package/cascader/Cascader.js +217 -214
- package/cascader/internal/CascaderPanel.d.ts +2 -2
- package/cascader/internal/CascaderPanel.js +21 -7
- package/cascader/internal/CascaderSearchPanel.d.ts +2 -2
- package/cascader/internal/CascaderSearchPanel.js +15 -6
- package/cascader/types.d.ts +3 -3
- package/checkbox/Checkbox.d.ts +1 -1
- package/checkbox/Checkbox.js +4 -5
- package/checkbox/CheckboxGroup.d.ts +1 -1
- package/checkbox/CheckboxGroup.js +8 -7
- package/checkbox/types.d.ts +14 -4
- package/{internal/circular-progress → circular-progress}/CircularProgress.d.ts +1 -1
- package/{internal/circular-progress → circular-progress}/CircularProgress.js +2 -2
- package/compose/Compose.d.ts +1 -1
- package/compose/ComposeItem.d.ts +1 -1
- package/config-provider/ConfigProvider.d.ts +1 -1
- package/config-provider/ConfigProvider.js +3 -3
- package/date-picker/DatePicker.d.ts +2 -2
- package/date-picker/DatePicker.js +116 -98
- package/date-picker/internal/DatePickerPanel.d.ts +2 -1
- package/date-picker/internal/DatePickerPanel.js +4 -4
- package/date-picker/types.d.ts +3 -3
- package/dialog-service.d.ts +9 -6
- package/dialog-service.js +50 -26
- package/drawer/Drawer.d.ts +1 -1
- package/drawer/Drawer.js +83 -92
- package/drawer/DrawerFooter.d.ts +1 -1
- package/drawer/DrawerFooter.js +12 -9
- package/drawer/DrawerHeader.d.ts +1 -1
- package/drawer/DrawerHeader.js +10 -7
- package/drawer/types.d.ts +9 -2
- package/drawer/vars.d.ts +5 -1
- package/drawer/vars.js +1 -1
- package/dropdown/Dropdown.d.ts +2 -4
- package/dropdown/Dropdown.js +83 -104
- package/dropdown/internal/DropdownGroup.d.ts +1 -1
- package/dropdown/internal/DropdownItem.d.ts +1 -1
- package/dropdown/internal/DropdownSub.d.ts +2 -1
- package/dropdown/internal/DropdownSub.js +26 -49
- package/dropdown/types.d.ts +15 -2
- package/empty/Empty.d.ts +1 -1
- package/fab/Fab.d.ts +1 -1
- package/fab/Fab.js +19 -14
- package/fab/FabBacktop.d.ts +1 -1
- package/fab/FabBacktop.js +24 -31
- package/fab/FabButton.d.ts +1 -1
- package/fab/FabButton.js +37 -10
- package/fab/types.d.ts +6 -2
- package/fab/vars.d.ts +14 -0
- package/fab/vars.js +4 -0
- package/form/Form.d.ts +1 -1
- package/form/Form.js +7 -2
- package/form/FormItem.d.ts +1 -1
- package/form/FormItem.js +35 -24
- package/form/internal/FormError.d.ts +3 -2
- package/form/internal/FormError.js +10 -19
- package/hooks/index.d.ts +0 -2
- package/hooks/index.js +0 -2
- package/hooks/useComponentProps.js +2 -2
- package/hooks/useFocusVisible.d.ts +9 -2
- package/hooks/useFocusVisible.js +5 -11
- package/hooks/useLayout.d.ts +2 -2
- package/hooks/useLayout.js +2 -2
- package/hooks/useNamespace.js +2 -2
- package/hooks/useNestedPopup.d.ts +1 -1
- package/hooks/useScopedProps.js +2 -2
- package/hooks/useStyled.js +2 -2
- package/hooks/useTranslation.js +2 -2
- package/icon/Icon.d.ts +1 -1
- package/icon/Icon.js +7 -4
- package/image/Image.d.ts +1 -1
- package/image/Image.js +6 -2
- package/image/ImageAction.d.ts +1 -1
- package/image/ImageAction.js +3 -4
- package/image/ImageLoader.d.ts +1 -1
- package/image/ImagePreview.d.ts +1 -1
- package/image/ImagePreview.js +94 -109
- package/image/types.d.ts +6 -2
- package/input/Input.d.ts +1 -1
- package/input/Input.js +12 -8
- package/input/InputNumber.js +49 -40
- package/input/types.d.ts +3 -5
- package/internal/lazy-loading/LazyLoading.d.ts +3 -0
- package/internal/lazy-loading/LazyLoading.js +9 -0
- package/internal/lazy-loading/index.d.ts +2 -0
- package/internal/lazy-loading/index.js +1 -0
- package/internal/lazy-loading/types.d.ts +7 -0
- package/internal/popup/Popup.d.ts +1 -1
- package/internal/popup/Popup.js +40 -68
- package/internal/popup/types.d.ts +13 -6
- package/internal/portal/Portal.d.ts +1 -1
- package/internal/portal/Portal.js +12 -6
- package/internal/portal/types.d.ts +3 -2
- package/mask/Mask.d.ts +3 -0
- package/mask/Mask.js +31 -0
- package/menu/Menu.d.ts +2 -4
- package/menu/Menu.js +37 -42
- package/menu/internal/MenuGroup.d.ts +1 -1
- package/menu/internal/MenuItem.d.ts +1 -1
- package/menu/internal/MenuItem.js +14 -10
- package/menu/internal/MenuSub.d.ts +2 -1
- package/menu/internal/MenuSub.js +43 -70
- package/menu/types.d.ts +1 -0
- package/modal/Modal.d.ts +1 -1
- package/modal/Modal.js +77 -80
- package/modal/ModalAlert.d.ts +1 -1
- package/modal/ModalFooter.d.ts +1 -1
- package/modal/ModalFooter.js +12 -9
- package/modal/ModalHeader.d.ts +1 -1
- package/modal/ModalHeader.js +10 -7
- package/modal/types.d.ts +9 -2
- package/modal/vars.d.ts +5 -0
- package/modal/vars.js +2 -0
- package/notification/Notification.d.ts +1 -1
- package/notification/Notification.js +44 -71
- package/notification/types.d.ts +1 -0
- package/package.json +2 -2
- package/pagination/Pagination.d.ts +1 -1
- package/pagination/Pagination.js +9 -6
- package/popover/Popover.d.ts +2 -2
- package/popover/Popover.js +82 -118
- package/popover/PopoverFooter.d.ts +1 -1
- package/popover/PopoverFooter.js +12 -9
- package/popover/PopoverHeader.d.ts +1 -1
- package/popover/PopoverHeader.js +10 -7
- package/popover/types.d.ts +18 -4
- package/popover/vars.d.ts +5 -0
- package/popover/vars.js +2 -0
- package/progress/Progress.d.ts +1 -1
- package/radio/Radio.d.ts +1 -1
- package/radio/Radio.js +18 -13
- package/radio/RadioGroup.d.ts +1 -1
- package/radio/RadioGroup.js +12 -7
- package/radio/types.d.ts +16 -4
- package/radio/vars.d.ts +6 -0
- package/radio/vars.js +2 -0
- package/rating/Rating.d.ts +1 -1
- package/rating/internal/RatingStar.d.ts +1 -1
- package/rating/internal/RatingStar.js +23 -21
- package/root/Root.d.ts +1 -1
- package/root/Root.js +1 -1
- package/select/Select.d.ts +2 -4
- package/select/Select.js +245 -243
- package/select/types.d.ts +3 -3
- package/separator/Separator.d.ts +1 -1
- package/skeleton/Skeleton.d.ts +1 -1
- package/slider/Slider.d.ts +1 -1
- package/slider/Slider.js +54 -34
- package/slider/types.d.ts +2 -3
- package/slides/Slides.d.ts +1 -1
- package/slides/Slides.js +8 -3
- package/spinner/Spinner.d.ts +1 -1
- package/spinner/Spinner.js +27 -29
- package/stepper/Stepper.d.ts +1 -1
- package/stepper/Stepper.js +9 -16
- package/switch/Switch.js +33 -24
- package/switch/types.d.ts +2 -3
- package/table/Table.d.ts +1 -1
- package/table/Table.js +14 -10
- package/table/TableEmpty.d.ts +1 -1
- package/table/TableEmpty.js +9 -3
- package/table/TableExpand.d.ts +1 -1
- package/table/TableFilter.d.ts +1 -1
- package/table/TableFilter.js +1 -1
- package/table/TableTd.d.ts +1 -1
- package/table/TableTh.d.ts +1 -1
- package/table/TableThAction.d.ts +1 -1
- package/table/TableThAction.js +3 -4
- package/table/internal/TableCell.d.ts +1 -1
- package/table/internal/TableCell.js +13 -5
- package/table/types.d.ts +9 -2
- package/tabs/Tabs.d.ts +2 -4
- package/tabs/Tabs.js +41 -25
- package/tabs/types.d.ts +1 -0
- package/tag/Tag.d.ts +1 -1
- package/textarea/Textarea.d.ts +1 -1
- package/textarea/Textarea.js +15 -8
- package/textarea/types.d.ts +1 -0
- package/time-picker/TimePicker.d.ts +2 -2
- package/time-picker/TimePicker.js +89 -75
- package/time-picker/internal/TimePickerPanel.d.ts +2 -1
- package/time-picker/internal/TimePickerPanel.js +22 -7
- package/time-picker/types.d.ts +3 -3
- package/timeline/Timeline.d.ts +1 -1
- package/toast/Toast.d.ts +1 -1
- package/toast/Toast.js +44 -72
- package/toast/types.d.ts +1 -0
- package/tooltip/Tooltip.d.ts +2 -2
- package/tooltip/Tooltip.js +50 -74
- package/tooltip/types.d.ts +10 -2
- package/transfer/Transfer.d.ts +1 -1
- package/transfer/internal/TransferPanel.d.ts +1 -1
- package/transfer/internal/TransferPanel.js +7 -2
- package/{internal/transition → transition}/CollapseTransition.d.ts +1 -1
- package/transition/CollapseTransition.js +65 -0
- package/transition/Transition.d.ts +3 -0
- package/transition/Transition.js +148 -0
- package/transition/types.d.ts +29 -0
- package/tree/Tree.d.ts +1 -1
- package/tree/Tree.js +19 -7
- package/tree/internal/TreePanel.d.ts +2 -2
- package/tree/internal/TreePanel.js +32 -26
- package/tree-select/TreeSelect.d.ts +2 -4
- package/tree-select/TreeSelect.js +216 -213
- package/tree-select/internal/TreeSelectSearchPanel.d.ts +2 -2
- package/tree-select/internal/TreeSelectSearchPanel.js +15 -6
- package/tree-select/types.d.ts +3 -3
- package/types.d.ts +1 -1
- package/upload/Upload.d.ts +1 -3
- package/upload/Upload.js +41 -50
- package/upload/UploadAction.d.ts +1 -1
- package/upload/UploadAction.js +19 -16
- package/upload/UploadButton.d.ts +1 -1
- package/upload/UploadButton.js +16 -12
- package/upload/UploadList.d.ts +1 -1
- package/upload/UploadList.js +52 -47
- package/upload/UploadPicture.d.ts +1 -1
- package/upload/UploadPicture.js +47 -53
- package/upload/UploadPictureList.d.ts +1 -1
- package/upload/UploadPictureList.js +52 -47
- package/upload/UploadPreviewAction.d.ts +1 -1
- package/upload/UploadPreviewAction.js +15 -14
- package/upload/hooks.d.ts +2 -0
- package/upload/types.d.ts +27 -6
- package/upload/vars.d.ts +11 -0
- package/upload/vars.js +3 -0
- package/virtual-scroll/VirtualScroll.d.ts +2 -4
- package/virtual-scroll/VirtualScroll.js +13 -21
- package/virtual-scroll/types.d.ts +2 -1
- package/wave/Wave.d.ts +3 -0
- package/{internal/wave → wave}/Wave.js +6 -6
- package/{internal/wave → wave}/types.d.ts +1 -0
- package/wave/types.js +1 -0
- package/LICENSE +0 -21
- package/hooks/useJSS.d.ts +0 -1
- package/hooks/useJSS.js +0 -15
- package/hooks/useNextTick.d.ts +0 -2
- package/internal/mask/Mask.d.ts +0 -3
- package/internal/mask/Mask.js +0 -36
- package/internal/transition/CollapseTransition.js +0 -101
- package/internal/transition/Transition.d.ts +0 -3
- package/internal/transition/Transition.js +0 -87
- package/internal/transition/types.d.ts +0 -33
- package/internal/wave/Wave.d.ts +0 -3
- /package/{internal/circular-progress → circular-progress}/index.d.ts +0 -0
- /package/{internal/circular-progress → circular-progress}/index.js +0 -0
- /package/{internal/circular-progress → circular-progress}/vars.d.ts +0 -0
- /package/{internal/circular-progress → circular-progress}/vars.js +0 -0
- /package/internal/{mask → lazy-loading}/types.js +0 -0
- /package/{internal/mask → mask}/index.d.ts +0 -0
- /package/{internal/mask → mask}/index.js +0 -0
- /package/{internal/mask → mask}/types.d.ts +0 -0
- /package/{internal/transition → mask}/types.js +0 -0
- /package/{internal/mask → mask}/vars.d.ts +0 -0
- /package/{internal/mask → mask}/vars.js +0 -0
- /package/{internal/transition → transition}/index.d.ts +0 -0
- /package/{internal/transition → transition}/index.js +0 -0
- /package/{internal/wave → transition}/types.js +0 -0
- /package/{hooks/useNextTick.js → upload/hooks.js} +0 -0
- /package/{internal/wave → wave}/index.d.ts +0 -0
- /package/{internal/wave → wave}/index.js +0 -0
- /package/{internal/wave → wave}/vars.d.ts +0 -0
- /package/{internal/wave → wave}/vars.js +0 -0
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
import { __rest } from "tslib";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
-
import { useEventCallback,
|
|
4
|
-
import { findNested } from '@laser-ui/utils';
|
|
3
|
+
import { useEventCallback, useResize } from '@laser-ui/hooks';
|
|
4
|
+
import { findNested, setRef } from '@laser-ui/utils';
|
|
5
5
|
import CancelFilled from '@material-design-icons/svg/filled/cancel.svg?react';
|
|
6
6
|
import CloseOutlined from '@material-design-icons/svg/outlined/close.svg?react';
|
|
7
7
|
import KeyboardArrowDownOutlined from '@material-design-icons/svg/outlined/keyboard_arrow_down.svg?react';
|
|
8
8
|
import SearchOutlined from '@material-design-icons/svg/outlined/search.svg?react';
|
|
9
9
|
import { isNull, isNumber, isUndefined } from 'lodash';
|
|
10
|
-
import {
|
|
10
|
+
import { useId, useImperativeHandle, useMemo, useRef, useState } from 'react';
|
|
11
11
|
import { TreeSelectSearchPanel } from './internal/TreeSelectSearchPanel';
|
|
12
12
|
import { CLASSES } from './vars';
|
|
13
13
|
import { BaseInput } from '../base-input';
|
|
14
|
+
import { CircularProgress } from '../circular-progress';
|
|
14
15
|
import { Dropdown } from '../dropdown';
|
|
15
|
-
import { useComponentProps, useContainerScrolling, useControlled, useDesign, useFocusVisible,
|
|
16
|
+
import { useComponentProps, useContainerScrolling, useControlled, useDesign, useFocusVisible, useLayout, useMaxIndex, useNamespace, useScopedProps, useStyled, useTranslation, } from '../hooks';
|
|
16
17
|
import { Icon } from '../icon';
|
|
17
|
-
import { CircularProgress } from '../internal/circular-progress';
|
|
18
18
|
import { Portal } from '../internal/portal';
|
|
19
|
-
import { Transition } from '../internal/transition';
|
|
20
19
|
import { ROOT_DATA } from '../root/vars';
|
|
21
20
|
import { Tag } from '../tag';
|
|
21
|
+
import { Transition } from '../transition';
|
|
22
22
|
import { TreePanel } from '../tree/internal/TreePanel';
|
|
23
23
|
import { MultipleTreeNode } from '../tree/node/multiple-node';
|
|
24
24
|
import { SingleTreeNode } from '../tree/node/single-node';
|
|
@@ -26,18 +26,15 @@ import { getTreeNodeLabel } from '../tree/utils';
|
|
|
26
26
|
import { TREE_NODE_KEY } from '../tree/vars';
|
|
27
27
|
import { getVerticalSidePosition, isPrintableCharacter, mergeCS } from '../utils';
|
|
28
28
|
import { TTANSITION_DURING_POPUP, WINDOW_SPACE } from '../vars';
|
|
29
|
-
function
|
|
30
|
-
const _a = useComponentProps('TreeSelect', props), { styleOverrides, styleProvider, formControl, list, model, defaultModel, expands: expandsProp, defaultExpands, visible: visibleProp, defaultVisible, placeholder, multiple = false, searchable = false, searchValue: searchValueProp, defaultSearchValue, onlyLeafSelectable = true, showLine = false, clearable: clearableProp = false, loading = false, size: sizeProp, disabled: disabledProp = false, virtual = false, escClosable = true, customItem, customSelected, customSearch,
|
|
29
|
+
export function TreeSelect(props) {
|
|
30
|
+
const _a = useComponentProps('TreeSelect', props), { ref, styleOverrides, styleProvider, formControl, list, model, defaultModel, expands: expandsProp, defaultExpands, visible: visibleProp, defaultVisible, placeholder, multiple = false, searchable = false, searchValue: searchValueProp, defaultSearchValue, onlyLeafSelectable = true, showLine = false, clearable: clearableProp = false, loading = false, size: sizeProp, disabled: disabledProp = false, virtual = false, escClosable = true, customItem, customSelected, customSearch, inputProps, popupRender, onModelChange, onFirstExpand, onExpandsChange, onVisibleChange, onSearch, onClear, afterVisibleChange, onScrollBottom } = _a, restProps = __rest(_a, ["ref", "styleOverrides", "styleProvider", "formControl", "list", "model", "defaultModel", "expands", "defaultExpands", "visible", "defaultVisible", "placeholder", "multiple", "searchable", "searchValue", "defaultSearchValue", "onlyLeafSelectable", "showLine", "clearable", "loading", "size", "disabled", "virtual", "escClosable", "customItem", "customSelected", "customSearch", "inputProps", "popupRender", "onModelChange", "onFirstExpand", "onExpandsChange", "onVisibleChange", "onSearch", "onClear", "afterVisibleChange", "onScrollBottom"]);
|
|
31
31
|
const namespace = useNamespace();
|
|
32
32
|
const styled = useStyled(CLASSES, {
|
|
33
33
|
'tree-select': styleProvider === null || styleProvider === void 0 ? void 0 : styleProvider['tree-select'],
|
|
34
34
|
tree: styleProvider === null || styleProvider === void 0 ? void 0 : styleProvider.tree,
|
|
35
35
|
'tree-select-popup': styleProvider === null || styleProvider === void 0 ? void 0 : styleProvider['tree-select-popup'],
|
|
36
36
|
}, styleOverrides);
|
|
37
|
-
const
|
|
38
|
-
const dataRef = useRef({
|
|
39
|
-
expands: new Set(),
|
|
40
|
-
});
|
|
37
|
+
const expandSaved = useRef(new Set());
|
|
41
38
|
const { t } = useTranslation();
|
|
42
39
|
const uniqueId = useId();
|
|
43
40
|
const listId = `${namespace}-tree-select-list-${uniqueId}`;
|
|
@@ -46,7 +43,6 @@ function TreeSelectFC(props, ref) {
|
|
|
46
43
|
const boxRef = useRef(null);
|
|
47
44
|
const popupRef = useRef(null);
|
|
48
45
|
const inputRef = useRef(null);
|
|
49
|
-
const combineInputRef = useForkRef(inputRef, inputRefProp);
|
|
50
46
|
const focusRef = useRef(null);
|
|
51
47
|
const [nodes, nodesMap] = useMemo(() => {
|
|
52
48
|
const nodes = list.map((item) => multiple
|
|
@@ -149,7 +145,7 @@ function TreeSelectFC(props, ref) {
|
|
|
149
145
|
return searchList;
|
|
150
146
|
})();
|
|
151
147
|
const isEmpty = hasSearch ? searchList.length === 0 : nodes.length === 0;
|
|
152
|
-
const [focusVisible,
|
|
148
|
+
const [focusVisible, focusVisibleProps] = useFocusVisible((code) => code.startsWith('Arrow') || ['Home', 'End', 'Enter', 'Space'].includes(code));
|
|
153
149
|
const [_itemFocusedWithoutSearch, setItemFocusedWithoutSearch] = useState();
|
|
154
150
|
const itemFocusedWithoutSearch = (() => {
|
|
155
151
|
let itemFocused;
|
|
@@ -179,7 +175,6 @@ function TreeSelectFC(props, ref) {
|
|
|
179
175
|
})();
|
|
180
176
|
const maxZIndex = useMaxIndex(visible);
|
|
181
177
|
const zIndex = `calc(var(--${namespace}-zindex-fixed) + ${maxZIndex})`;
|
|
182
|
-
const transformOrigin = useRef();
|
|
183
178
|
const updatePosition = useEventCallback(() => {
|
|
184
179
|
if (visible && boxRef.current && popupRef.current) {
|
|
185
180
|
const boxWidth = boxRef.current.offsetWidth;
|
|
@@ -190,17 +185,11 @@ function TreeSelectFC(props, ref) {
|
|
|
190
185
|
placement: 'bottom-left',
|
|
191
186
|
inWindow: WINDOW_SPACE,
|
|
192
187
|
});
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
top: position.top,
|
|
199
|
-
left: position.left,
|
|
200
|
-
minWidth: Math.min(boxWidth, maxWidth),
|
|
201
|
-
maxWidth,
|
|
202
|
-
});
|
|
203
|
-
popupRef.current.classList.toggle(sheet.classes.position, true);
|
|
188
|
+
popupRef.current.style.setProperty(`--popup-down-transform-origin`, position.transformOrigin);
|
|
189
|
+
popupRef.current.style.top = position.top + 'px';
|
|
190
|
+
popupRef.current.style.left = position.left + 'px';
|
|
191
|
+
popupRef.current.style.minWidth = Math.min(boxWidth, maxWidth) + 'px';
|
|
192
|
+
popupRef.current.style.maxWidth = maxWidth + 'px';
|
|
204
193
|
}
|
|
205
194
|
});
|
|
206
195
|
useContainerScrolling(boxRef, updatePosition, !visible);
|
|
@@ -224,8 +213,8 @@ function TreeSelectFC(props, ref) {
|
|
|
224
213
|
});
|
|
225
214
|
}
|
|
226
215
|
else {
|
|
227
|
-
if (!
|
|
228
|
-
|
|
216
|
+
if (!expandSaved.current.has(node.id)) {
|
|
217
|
+
expandSaved.current.add(node.id);
|
|
229
218
|
onFirstExpand === null || onFirstExpand === void 0 ? void 0 : onFirstExpand(node.id, node.origin);
|
|
230
219
|
}
|
|
231
220
|
changeExpands((draft) => {
|
|
@@ -234,141 +223,9 @@ function TreeSelectFC(props, ref) {
|
|
|
234
223
|
}
|
|
235
224
|
}
|
|
236
225
|
};
|
|
237
|
-
const scrollCallback = useRef();
|
|
226
|
+
const scrollCallback = useRef(() => { });
|
|
238
227
|
const inputable = searchable && visible;
|
|
239
228
|
const clearable = clearableProp && hasSelected && !visible && !loading && !disabled;
|
|
240
|
-
const inputNode = focusVisibleWrapper(createElement(searchable ? BaseInput : 'div', Object.assign(Object.assign(Object.assign(Object.assign({}, mergeCS(styled('tree-select__search'), {
|
|
241
|
-
style: {
|
|
242
|
-
opacity: inputable ? undefined : 0,
|
|
243
|
-
zIndex: inputable ? undefined : -1,
|
|
244
|
-
},
|
|
245
|
-
})), formControl === null || formControl === void 0 ? void 0 : formControl.inputAria), { ref: combineInputRef, tabIndex: disabled ? -1 : 0, role: 'combobox', 'aria-haspopup': 'listbox', 'aria-expanded': visible, 'aria-controls': listId, onBlur: () => {
|
|
246
|
-
changeVisible(false);
|
|
247
|
-
}, onKeyDown: (e) => {
|
|
248
|
-
if (e.code === 'Escape') {
|
|
249
|
-
if (visible && escClosable) {
|
|
250
|
-
e.stopPropagation();
|
|
251
|
-
e.preventDefault();
|
|
252
|
-
changeVisible(false);
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
else {
|
|
256
|
-
const itemFocused = (code) => {
|
|
257
|
-
if (focusRef.current) {
|
|
258
|
-
const item = focusRef.current(code);
|
|
259
|
-
if (item) {
|
|
260
|
-
hasSearch ? setItemFocusedWithSearch(item) : setItemFocusedWithoutSearch(item);
|
|
261
|
-
if (virtual === false && !code.includes('level')) {
|
|
262
|
-
scrollCallback.current = () => {
|
|
263
|
-
const el = document.getElementById(getItemId(hasSearch ? item.value : item.id));
|
|
264
|
-
if (el) {
|
|
265
|
-
focusRef.current(el);
|
|
266
|
-
}
|
|
267
|
-
};
|
|
268
|
-
if (visible) {
|
|
269
|
-
scrollCallback.current();
|
|
270
|
-
scrollCallback.current = undefined;
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
};
|
|
276
|
-
if (visible) {
|
|
277
|
-
switch (e.code) {
|
|
278
|
-
case 'ArrowUp': {
|
|
279
|
-
e.preventDefault();
|
|
280
|
-
itemFocused('prev');
|
|
281
|
-
break;
|
|
282
|
-
}
|
|
283
|
-
case 'ArrowDown': {
|
|
284
|
-
e.preventDefault();
|
|
285
|
-
itemFocused('next');
|
|
286
|
-
break;
|
|
287
|
-
}
|
|
288
|
-
case 'ArrowLeft': {
|
|
289
|
-
if (!hasSearch) {
|
|
290
|
-
e.preventDefault();
|
|
291
|
-
itemFocused('prev-level');
|
|
292
|
-
}
|
|
293
|
-
break;
|
|
294
|
-
}
|
|
295
|
-
case 'ArrowRight': {
|
|
296
|
-
if (!hasSearch) {
|
|
297
|
-
e.preventDefault();
|
|
298
|
-
itemFocused('next-level');
|
|
299
|
-
}
|
|
300
|
-
break;
|
|
301
|
-
}
|
|
302
|
-
case 'Home': {
|
|
303
|
-
e.preventDefault();
|
|
304
|
-
itemFocused('first');
|
|
305
|
-
break;
|
|
306
|
-
}
|
|
307
|
-
case 'End': {
|
|
308
|
-
e.preventDefault();
|
|
309
|
-
itemFocused('last');
|
|
310
|
-
break;
|
|
311
|
-
}
|
|
312
|
-
default: {
|
|
313
|
-
if (e.code === 'Enter' || (e.code === 'Space' && !searchable)) {
|
|
314
|
-
e.preventDefault();
|
|
315
|
-
if (hasSearch) {
|
|
316
|
-
if (itemFocusedWithSearch) {
|
|
317
|
-
changeSelectedByClickWithSearch(itemFocusedWithSearch);
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
else {
|
|
321
|
-
if (itemFocusedWithoutSearch) {
|
|
322
|
-
changeSelectedByClickWithoutSearch(itemFocusedWithoutSearch);
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
break;
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
else if (!(searchable && ['Home', 'End', 'Enter', 'Space'].includes(e.code))) {
|
|
331
|
-
switch (e.code) {
|
|
332
|
-
case 'End':
|
|
333
|
-
case 'ArrowUp': {
|
|
334
|
-
e.preventDefault();
|
|
335
|
-
changeVisible(true);
|
|
336
|
-
itemFocused('last');
|
|
337
|
-
break;
|
|
338
|
-
}
|
|
339
|
-
case 'Home':
|
|
340
|
-
case 'ArrowDown': {
|
|
341
|
-
e.preventDefault();
|
|
342
|
-
changeVisible(true);
|
|
343
|
-
itemFocused('first');
|
|
344
|
-
break;
|
|
345
|
-
}
|
|
346
|
-
case 'Enter':
|
|
347
|
-
case 'Space': {
|
|
348
|
-
e.preventDefault();
|
|
349
|
-
changeVisible(true);
|
|
350
|
-
break;
|
|
351
|
-
}
|
|
352
|
-
default: {
|
|
353
|
-
if (isPrintableCharacter(e.key)) {
|
|
354
|
-
changeVisible(true);
|
|
355
|
-
}
|
|
356
|
-
break;
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
} }), searchable
|
|
362
|
-
? {
|
|
363
|
-
type: 'text',
|
|
364
|
-
value: searchValue,
|
|
365
|
-
autoComplete: 'off',
|
|
366
|
-
disabled,
|
|
367
|
-
onValueChange: (val) => {
|
|
368
|
-
changeSearchValue(val);
|
|
369
|
-
},
|
|
370
|
-
}
|
|
371
|
-
: {})));
|
|
372
229
|
const [selectedNode, suffixNode, selectedLabel] = (() => {
|
|
373
230
|
let selectedNode = null;
|
|
374
231
|
let suffixNode = null;
|
|
@@ -392,7 +249,7 @@ function TreeSelectFC(props, ref) {
|
|
|
392
249
|
draft.splice(draft.findIndex((v) => v === id), 1);
|
|
393
250
|
});
|
|
394
251
|
return false;
|
|
395
|
-
}, children: _jsx(Tag, { tabIndex: -1, size: size, children: selected.size }) }));
|
|
252
|
+
}, children: (dropdownProps) => (_jsx(Tag, Object.assign({}, dropdownProps, { tabIndex: -1, size: size, children: selected.size }))) }));
|
|
396
253
|
selectedNode = selectedNodes.map(({ value, label, node }) => (_jsxs(Tag, { size: size, children: [label, !((node === null || node === void 0 ? void 0 : node.disabled) || disabled) && (_jsx("div", Object.assign({}, styled('tree-select__close'), { role: "button", "aria-label": t('Close'), onClick: (e) => {
|
|
397
254
|
e.stopPropagation();
|
|
398
255
|
const checkeds = node.changeStatus('UNCHECKED', selected);
|
|
@@ -418,7 +275,12 @@ function TreeSelectFC(props, ref) {
|
|
|
418
275
|
}), {
|
|
419
276
|
className: restProps.className,
|
|
420
277
|
style: restProps.style,
|
|
421
|
-
}), designProps, { ref:
|
|
278
|
+
}), designProps, { ref: (instance) => {
|
|
279
|
+
boxRef.current = instance;
|
|
280
|
+
return () => {
|
|
281
|
+
boxRef.current = null;
|
|
282
|
+
};
|
|
283
|
+
}, onMouseDown: (e) => {
|
|
422
284
|
var _a;
|
|
423
285
|
(_a = restProps.onMouseDown) === null || _a === void 0 ? void 0 : _a.call(restProps, e);
|
|
424
286
|
preventBlur(e);
|
|
@@ -431,7 +293,158 @@ function TreeSelectFC(props, ref) {
|
|
|
431
293
|
(_a = restProps.onClick) === null || _a === void 0 ? void 0 : _a.call(restProps, e);
|
|
432
294
|
(_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus({ preventScroll: true });
|
|
433
295
|
changeVisible((draft) => (searchable ? true : !draft));
|
|
434
|
-
}, children: [_jsxs("div", Object.assign({}, styled('tree-select__container'), { title: selectedLabel, children: [
|
|
296
|
+
}, children: [_jsxs("div", Object.assign({}, styled('tree-select__container'), { title: selectedLabel, children: [(() => {
|
|
297
|
+
const nodeProps = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, inputProps), mergeCS(styled('tree-select__search'), {
|
|
298
|
+
style: {
|
|
299
|
+
opacity: inputable ? undefined : 0,
|
|
300
|
+
zIndex: inputable ? undefined : -1,
|
|
301
|
+
},
|
|
302
|
+
})), formControl === null || formControl === void 0 ? void 0 : formControl.inputAria), { ref: (instance) => {
|
|
303
|
+
inputRef.current = instance;
|
|
304
|
+
const ret = setRef(inputProps === null || inputProps === void 0 ? void 0 : inputProps.ref, instance);
|
|
305
|
+
return () => {
|
|
306
|
+
inputRef.current = null;
|
|
307
|
+
ret();
|
|
308
|
+
};
|
|
309
|
+
}, tabIndex: disabled ? -1 : 0, role: 'combobox', 'aria-haspopup': 'listbox', 'aria-expanded': visible, 'aria-controls': listId, onFocus: (e) => {
|
|
310
|
+
var _a;
|
|
311
|
+
(_a = inputProps === null || inputProps === void 0 ? void 0 : inputProps.onFocus) === null || _a === void 0 ? void 0 : _a.call(inputProps, e);
|
|
312
|
+
focusVisibleProps.onFocus(e);
|
|
313
|
+
}, onBlur: (e) => {
|
|
314
|
+
var _a;
|
|
315
|
+
(_a = inputProps === null || inputProps === void 0 ? void 0 : inputProps.onBlur) === null || _a === void 0 ? void 0 : _a.call(inputProps, e);
|
|
316
|
+
focusVisibleProps.onBlur(e);
|
|
317
|
+
changeVisible(false);
|
|
318
|
+
}, onKeyDown: (e) => {
|
|
319
|
+
var _a;
|
|
320
|
+
(_a = inputProps === null || inputProps === void 0 ? void 0 : inputProps.onKeyDown) === null || _a === void 0 ? void 0 : _a.call(inputProps, e);
|
|
321
|
+
focusVisibleProps.onKeyDown(e);
|
|
322
|
+
if (e.code === 'Escape') {
|
|
323
|
+
if (visible && escClosable) {
|
|
324
|
+
e.stopPropagation();
|
|
325
|
+
e.preventDefault();
|
|
326
|
+
changeVisible(false);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
else {
|
|
330
|
+
const itemFocused = (code) => {
|
|
331
|
+
if (focusRef.current) {
|
|
332
|
+
const item = focusRef.current(code);
|
|
333
|
+
if (item) {
|
|
334
|
+
hasSearch ? setItemFocusedWithSearch(item) : setItemFocusedWithoutSearch(item);
|
|
335
|
+
if (virtual === false && !code.includes('level')) {
|
|
336
|
+
scrollCallback.current = () => {
|
|
337
|
+
scrollCallback.current = () => { };
|
|
338
|
+
const el = document.getElementById(getItemId(hasSearch ? item.value : item.id));
|
|
339
|
+
if (el) {
|
|
340
|
+
focusRef.current(el);
|
|
341
|
+
}
|
|
342
|
+
};
|
|
343
|
+
if (visible) {
|
|
344
|
+
scrollCallback.current();
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
};
|
|
350
|
+
if (visible) {
|
|
351
|
+
switch (e.code) {
|
|
352
|
+
case 'ArrowUp': {
|
|
353
|
+
e.preventDefault();
|
|
354
|
+
itemFocused('prev');
|
|
355
|
+
break;
|
|
356
|
+
}
|
|
357
|
+
case 'ArrowDown': {
|
|
358
|
+
e.preventDefault();
|
|
359
|
+
itemFocused('next');
|
|
360
|
+
break;
|
|
361
|
+
}
|
|
362
|
+
case 'ArrowLeft': {
|
|
363
|
+
if (!hasSearch) {
|
|
364
|
+
e.preventDefault();
|
|
365
|
+
itemFocused('prev-level');
|
|
366
|
+
}
|
|
367
|
+
break;
|
|
368
|
+
}
|
|
369
|
+
case 'ArrowRight': {
|
|
370
|
+
if (!hasSearch) {
|
|
371
|
+
e.preventDefault();
|
|
372
|
+
itemFocused('next-level');
|
|
373
|
+
}
|
|
374
|
+
break;
|
|
375
|
+
}
|
|
376
|
+
case 'Home': {
|
|
377
|
+
e.preventDefault();
|
|
378
|
+
itemFocused('first');
|
|
379
|
+
break;
|
|
380
|
+
}
|
|
381
|
+
case 'End': {
|
|
382
|
+
e.preventDefault();
|
|
383
|
+
itemFocused('last');
|
|
384
|
+
break;
|
|
385
|
+
}
|
|
386
|
+
default: {
|
|
387
|
+
if (e.code === 'Enter' || (e.code === 'Space' && !searchable)) {
|
|
388
|
+
e.preventDefault();
|
|
389
|
+
if (hasSearch) {
|
|
390
|
+
if (itemFocusedWithSearch) {
|
|
391
|
+
changeSelectedByClickWithSearch(itemFocusedWithSearch);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
else {
|
|
395
|
+
if (itemFocusedWithoutSearch) {
|
|
396
|
+
changeSelectedByClickWithoutSearch(itemFocusedWithoutSearch);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
break;
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
else if (!(searchable && ['Home', 'End', 'Enter', 'Space'].includes(e.code))) {
|
|
405
|
+
switch (e.code) {
|
|
406
|
+
case 'End':
|
|
407
|
+
case 'ArrowUp': {
|
|
408
|
+
e.preventDefault();
|
|
409
|
+
changeVisible(true);
|
|
410
|
+
itemFocused('last');
|
|
411
|
+
break;
|
|
412
|
+
}
|
|
413
|
+
case 'Home':
|
|
414
|
+
case 'ArrowDown': {
|
|
415
|
+
e.preventDefault();
|
|
416
|
+
changeVisible(true);
|
|
417
|
+
itemFocused('first');
|
|
418
|
+
break;
|
|
419
|
+
}
|
|
420
|
+
case 'Enter':
|
|
421
|
+
case 'Space': {
|
|
422
|
+
e.preventDefault();
|
|
423
|
+
changeVisible(true);
|
|
424
|
+
break;
|
|
425
|
+
}
|
|
426
|
+
default: {
|
|
427
|
+
if (isPrintableCharacter(e.key)) {
|
|
428
|
+
changeVisible(true);
|
|
429
|
+
}
|
|
430
|
+
break;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
} }), searchable
|
|
436
|
+
? {
|
|
437
|
+
type: 'text',
|
|
438
|
+
value: searchValue,
|
|
439
|
+
autoComplete: 'off',
|
|
440
|
+
disabled,
|
|
441
|
+
onValueChange: (val) => {
|
|
442
|
+
changeSearchValue(val);
|
|
443
|
+
},
|
|
444
|
+
}
|
|
445
|
+
: {});
|
|
446
|
+
return searchable ? _jsx(BaseInput, Object.assign({}, nodeProps)) : _jsx("div", Object.assign({}, nodeProps));
|
|
447
|
+
})(), !inputable &&
|
|
435
448
|
(hasSelected ? (_jsx("div", Object.assign({}, styled('tree-select__content'), { children: selectedNode }))) : placeholder ? (_jsx("div", Object.assign({}, styled('tree-select__placeholder-wrapper'), { children: _jsx("div", Object.assign({}, styled('tree-select__placeholder'), { children: placeholder })) }))) : null)] })), multiple && (_jsx("div", Object.assign({}, styled('tree-select__multiple-count'), { onClick: (e) => {
|
|
436
449
|
e.stopPropagation();
|
|
437
450
|
}, children: suffixNode }))), clearable && (_jsx("div", Object.assign({}, styled('tree-select__clear'), { role: "button", "aria-label": t('Clear'), onClick: (e) => {
|
|
@@ -453,56 +466,46 @@ function TreeSelectFC(props, ref) {
|
|
|
453
466
|
document.body.appendChild(el);
|
|
454
467
|
}
|
|
455
468
|
return el;
|
|
456
|
-
}, children: _jsx(Transition, { enter: visible,
|
|
457
|
-
|
|
469
|
+
}, children: _jsx(Transition, { enter: visible, name: `${namespace}-popup-down`, duration: TTANSITION_DURING_POPUP, onSkipEnter: () => {
|
|
470
|
+
updatePosition();
|
|
471
|
+
scrollCallback.current();
|
|
472
|
+
}, onBeforeEnter: () => {
|
|
458
473
|
updatePosition();
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
}, afterEnter: () => {
|
|
474
|
+
scrollCallback.current();
|
|
475
|
+
}, onAfterEnter: () => {
|
|
462
476
|
afterVisibleChange === null || afterVisibleChange === void 0 ? void 0 : afterVisibleChange(true);
|
|
463
|
-
},
|
|
477
|
+
}, onAfterLeave: () => {
|
|
464
478
|
afterVisibleChange === null || afterVisibleChange === void 0 ? void 0 : afterVisibleChange(false);
|
|
465
|
-
}, children: (
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
}, children: (() => {
|
|
498
|
-
const el = (_jsxs("div", Object.assign({}, styled('tree-select-popup__content'), { children: [loading && (_jsx("div", Object.assign({}, styled('tree-select-popup__loading', {
|
|
499
|
-
'tree-select-popup__loading--empty': isEmpty,
|
|
500
|
-
}), { children: _jsx(Icon, { children: _jsx(CircularProgress, {}) }) }))), loading && isEmpty ? null : hasSearch ? (_jsx(TreeSelectSearchPanel, { ref: focusRef, namespace: namespace, styled: styled, id: listId, list: searchList, customItem: customItem, itemId: getItemId, itemFocused: itemFocusedWithSearch, multiple: multiple, onlyLeafSelectable: onlyLeafSelectable, virtual: virtual, focusVisible: focusVisible, onClick: (item) => {
|
|
501
|
-
setItemFocusedWithSearch(item);
|
|
502
|
-
changeSelectedByClickWithSearch(item);
|
|
503
|
-
} })) : (_jsx(TreePanel, { style: { maxHeight: 264, padding: '4px 0' }, ref: focusRef, id: listId, namespace: namespace, styled: styled, list: nodes, itemId: getItemId, itemSelected: !multiple && hasSelected ? nodesMap.get(selected) : undefined, itemFocused: itemFocusedWithoutSearch, expands: expands, customItem: customItem, showLine: showLine, multiple: multiple, onlyLeafSelectable: onlyLeafSelectable, disabled: false, virtual: virtual === false ? undefined : { listSize: 264, listPadding: 4, itemSize: isNumber(virtual) ? virtual : 32 }, focusVisible: focusVisible, onNodeFocus: setItemFocusedWithoutSearch, onNodeExpand: handleExpand, onNodeClick: changeSelectedByClickWithoutSearch, onScrollBottom: onScrollBottom }))] })));
|
|
504
|
-
return popupRender ? popupRender(el) : el;
|
|
505
|
-
})() })));
|
|
506
|
-
} }) })] }));
|
|
479
|
+
}, children: (transitionRef, leaved) => (_jsx("div", Object.assign({}, mergeCS(styled('tree-select-popup'), {
|
|
480
|
+
style: Object.assign({ zIndex }, (leaved ? { display: 'none' } : undefined)),
|
|
481
|
+
}), { ref: (instance) => {
|
|
482
|
+
popupRef.current = instance;
|
|
483
|
+
transitionRef(instance);
|
|
484
|
+
return () => {
|
|
485
|
+
popupRef.current = null;
|
|
486
|
+
transitionRef(null);
|
|
487
|
+
};
|
|
488
|
+
}, onMouseDown: (e) => {
|
|
489
|
+
preventBlur(e);
|
|
490
|
+
}, onMouseUp: (e) => {
|
|
491
|
+
preventBlur(e);
|
|
492
|
+
}, children: (() => {
|
|
493
|
+
const el = (_jsxs("div", Object.assign({}, styled('tree-select-popup__content'), { children: [loading && (_jsx("div", Object.assign({}, styled('tree-select-popup__loading', {
|
|
494
|
+
'tree-select-popup__loading--empty': isEmpty,
|
|
495
|
+
}), { children: _jsx(Icon, { children: _jsx(CircularProgress, {}) }) }))), loading && isEmpty ? null : hasSearch ? (_jsx(TreeSelectSearchPanel, { ref: (instance) => {
|
|
496
|
+
focusRef.current = instance;
|
|
497
|
+
return () => {
|
|
498
|
+
focusRef.current = null;
|
|
499
|
+
};
|
|
500
|
+
}, namespace: namespace, styled: styled, id: listId, list: searchList, customItem: customItem, itemId: getItemId, itemFocused: itemFocusedWithSearch, multiple: multiple, onlyLeafSelectable: onlyLeafSelectable, virtual: virtual, focusVisible: focusVisible, onClick: (item) => {
|
|
501
|
+
setItemFocusedWithSearch(item);
|
|
502
|
+
changeSelectedByClickWithSearch(item);
|
|
503
|
+
} })) : (_jsx(TreePanel, { style: { maxHeight: 264, padding: '4px 0' }, ref: (instance) => {
|
|
504
|
+
focusRef.current = instance;
|
|
505
|
+
return () => {
|
|
506
|
+
focusRef.current = null;
|
|
507
|
+
};
|
|
508
|
+
}, id: listId, namespace: namespace, styled: styled, list: nodes, itemId: getItemId, itemSelected: !multiple && hasSelected ? nodesMap.get(selected) : undefined, itemFocused: itemFocusedWithoutSearch, expands: expands, customItem: customItem, showLine: showLine, multiple: multiple, onlyLeafSelectable: onlyLeafSelectable, disabled: false, virtual: virtual === false ? undefined : { listSize: 264, listPadding: 4, itemSize: isNumber(virtual) ? virtual : 32 }, focusVisible: focusVisible, onNodeFocus: setItemFocusedWithoutSearch, onNodeExpand: handleExpand, onNodeClick: changeSelectedByClickWithoutSearch, onScrollBottom: onScrollBottom }))] })));
|
|
509
|
+
return popupRender ? popupRender(el) : el;
|
|
510
|
+
})() }))) }) })] }));
|
|
507
511
|
}
|
|
508
|
-
export const TreeSelect = forwardRef(TreeSelectFC);
|
|
@@ -4,6 +4,7 @@ import type { Styled } from '../../hooks/useStyled';
|
|
|
4
4
|
import type { TreeItem } from '../../tree/types';
|
|
5
5
|
import type { CLASSES } from '../vars';
|
|
6
6
|
interface TreeSelectSearchPanelProps<V extends React.Key, T extends TreeItem<V>> {
|
|
7
|
+
ref?: React.Ref<(code: any) => TreeSelectSearchPanelItem<V, T> | undefined>;
|
|
7
8
|
namespace: string;
|
|
8
9
|
styled: Styled<typeof CLASSES>;
|
|
9
10
|
id: string;
|
|
@@ -17,6 +18,5 @@ interface TreeSelectSearchPanelProps<V extends React.Key, T extends TreeItem<V>>
|
|
|
17
18
|
focusVisible: boolean;
|
|
18
19
|
onClick: (item: TreeSelectSearchPanelItem<V, T>) => void;
|
|
19
20
|
}
|
|
20
|
-
declare function
|
|
21
|
-
export declare const TreeSelectSearchPanel: <V extends React.Key, T extends TreeItem<V>>(props: TreeSelectSearchPanelProps<V, T> & React.RefAttributes<any>) => ReturnType<typeof TreeSelectSearchPanelFC>;
|
|
21
|
+
export declare function TreeSelectSearchPanel<V extends React.Key, T extends TreeItem<V>>(props: TreeSelectSearchPanelProps<V, T>): React.ReactElement | null;
|
|
22
22
|
export {};
|
|
@@ -3,14 +3,14 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
3
3
|
import { useEventCallback } from '@laser-ui/hooks';
|
|
4
4
|
import { scrollIntoViewIfNeeded } from '@laser-ui/utils';
|
|
5
5
|
import { isNumber, isUndefined } from 'lodash';
|
|
6
|
-
import {
|
|
6
|
+
import { useImperativeHandle, useMemo, useRef } from 'react';
|
|
7
7
|
import { Checkbox } from '../../checkbox';
|
|
8
8
|
import { Empty } from '../../empty';
|
|
9
9
|
import { getTreeNodeLabel } from '../../tree/utils';
|
|
10
10
|
import { TREE_NODE_KEY } from '../../tree/vars';
|
|
11
11
|
import { VirtualScroll } from '../../virtual-scroll';
|
|
12
|
-
function
|
|
13
|
-
const { namespace, styled, id, list, customItem, itemId, itemFocused, multiple, onlyLeafSelectable, virtual, focusVisible, onClick } = props;
|
|
12
|
+
export function TreeSelectSearchPanel(props) {
|
|
13
|
+
const { ref, namespace, styled, id, list, customItem, itemId, itemFocused, multiple, onlyLeafSelectable, virtual, focusVisible, onClick, } = props;
|
|
14
14
|
const listRef = useRef(null);
|
|
15
15
|
const vsRef = useRef(null);
|
|
16
16
|
const handleKeyDown = useEventCallback((code) => {
|
|
@@ -46,7 +46,12 @@ function TreeSelectSearchPanelFC(props, ref) {
|
|
|
46
46
|
itemSize: isNumber(virtual) ? virtual : 32,
|
|
47
47
|
itemFocusable: (item) => item[TREE_NODE_KEY].enabled,
|
|
48
48
|
}), [list, virtual]);
|
|
49
|
-
return (_jsx(VirtualScroll, Object.assign({}, vsProps, { ref:
|
|
49
|
+
return (_jsx(VirtualScroll, Object.assign({}, vsProps, { ref: (instance) => {
|
|
50
|
+
vsRef.current = instance;
|
|
51
|
+
return () => {
|
|
52
|
+
vsRef.current = null;
|
|
53
|
+
};
|
|
54
|
+
}, enable: virtual !== false, listSize: 264, listPadding: 4, itemRender: (item, index, props) => {
|
|
50
55
|
const node = item[TREE_NODE_KEY];
|
|
51
56
|
let inSelected = node.checked;
|
|
52
57
|
if (!onlyLeafSelectable) {
|
|
@@ -68,6 +73,10 @@ function TreeSelectSearchPanelFC(props, ref) {
|
|
|
68
73
|
focusVisible && (itemFocused === null || itemFocused === void 0 ? void 0 : itemFocused.value) === item.value && _jsx("div", { className: `${namespace}-focus-outline` }),
|
|
69
74
|
multiple && (_jsx("div", Object.assign({}, styled('tree__option-checkbox'), { children: _jsx(Checkbox, { model: node.checked, disabled: node.disabled }) }))),
|
|
70
75
|
_jsx("div", Object.assign({}, styled('tree__option-content'), { children: customItem ? customItem(node.origin) : getTreeNodeLabel(node) }))));
|
|
71
|
-
}, itemFocused: itemFocused === null || itemFocused === void 0 ? void 0 : itemFocused.value, placeholder: "li", children: (vsList, onScroll) => (_jsx("ul", Object.assign({}, styled('tree'), { ref:
|
|
76
|
+
}, itemFocused: itemFocused === null || itemFocused === void 0 ? void 0 : itemFocused.value, placeholder: "li", children: (vsList, onScroll) => (_jsx("ul", Object.assign({}, styled('tree'), { ref: (instance) => {
|
|
77
|
+
listRef.current = instance;
|
|
78
|
+
return () => {
|
|
79
|
+
listRef.current = null;
|
|
80
|
+
};
|
|
81
|
+
}, id: id, tabIndex: -1, role: "listbox", "aria-multiselectable": multiple, "aria-activedescendant": isUndefined(itemFocused) ? undefined : itemId(itemFocused.value), onScroll: onScroll, children: list.length === 0 ? _jsx(Empty, { style: { padding: '12px 28px' }, image: Empty.SIMPLE_IMG }) : vsList }))) })));
|
|
72
82
|
}
|
|
73
|
-
export const TreeSelectSearchPanel = forwardRef(TreeSelectSearchPanelFC);
|
package/tree-select/types.d.ts
CHANGED
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
import type { CLASSES } from './vars';
|
|
3
3
|
import type { FormControlProvider } from '../form/types';
|
|
4
4
|
import type { TreeItem } from '../tree/types';
|
|
5
|
-
import type { BaseProps,
|
|
5
|
+
import type { BaseProps, Size } from '../types';
|
|
6
6
|
export {};
|
|
7
7
|
export interface TreeSelectRef {
|
|
8
8
|
updatePosition: () => void;
|
|
9
9
|
}
|
|
10
10
|
export interface TreeSelectProps<V extends React.Key, T extends TreeItem<V>> extends BaseProps<'tree-select' | 'tree' | 'tree-select-popup', typeof CLASSES>, Omit<React.HTMLAttributes<HTMLDivElement>, 'children'> {
|
|
11
|
+
ref?: React.Ref<TreeSelectRef>;
|
|
11
12
|
formControl?: FormControlProvider;
|
|
12
13
|
list: T[];
|
|
13
14
|
model?: V | null | V[];
|
|
@@ -35,8 +36,7 @@ export interface TreeSelectProps<V extends React.Key, T extends TreeItem<V>> ext
|
|
|
35
36
|
filter?: (value: string, item: T) => boolean;
|
|
36
37
|
sort?: (a: T, b: T) => number;
|
|
37
38
|
};
|
|
38
|
-
|
|
39
|
-
inputRender?: CloneHTMLElement;
|
|
39
|
+
inputProps?: React.ComponentPropsWithRef<'input'>;
|
|
40
40
|
popupRender?: (el: React.ReactElement) => React.ReactNode;
|
|
41
41
|
onModelChange?: (value: any, origin: any) => void;
|
|
42
42
|
onFirstExpand?: (value: V, origin: T) => void;
|