react-restyle-components 0.4.46 → 0.4.47
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/lib/index.js +1 -3
- package/lib/src/core-components/index.js +1 -1
- package/lib/src/core-components/src/components/Accordion/AccordionSection/Accordion.js +1 -15
- package/lib/src/core-components/src/components/Accordion/AccordionSection/AccordionContext.js +1 -6
- package/lib/src/core-components/src/components/Accordion/AccordionSection/AccordionSection.js +1 -39
- package/lib/src/core-components/src/components/Accordion/AccordionSection/Header.js +1 -39
- package/lib/src/core-components/src/components/Accordion/AccordionSection/elements.js +57 -94
- package/lib/src/core-components/src/components/Accordion/AccordionSection/hooks/useCurrentAccordionIndex.js +1 -13
- package/lib/src/core-components/src/components/Accordion/AccordionSection/index.js +1 -3
- package/lib/src/core-components/src/components/Accordion/AccordionSection/types.js +1 -9
- package/lib/src/core-components/src/components/Accordion/Collapsible/Collapsible2.component.js +1 -249
- package/lib/src/core-components/src/components/Action/types.js +1 -8
- package/lib/src/core-components/src/components/AlertBanner/AlertBanner.js +1 -45
- package/lib/src/core-components/src/components/AlertBanner/elements.js +45 -120
- package/lib/src/core-components/src/components/AlertBanner/index.js +1 -2
- package/lib/src/core-components/src/components/AlertBanner/types.js +1 -10
- package/lib/src/core-components/src/components/AutoComplete/auto-complete-filter-group-by-multiple-select-multiple-fields-display/auto-complete-filter-group-by-multiple-select-multiple-fields-display.component.js +1 -451
- package/lib/src/core-components/src/components/AutoComplete/auto-complete-filter-multi-select-multi-fields-display-drag-drop/auto-complete-filter-multi-select-multi-fields-display-drag-drop.component.js +1 -229
- package/lib/src/core-components/src/components/AutoComplete/auto-complete-filter-multi-select-selected-top-display/auto-complete-filter-multi-select-selected-top-display.component.js +1 -174
- package/lib/src/core-components/src/components/AutoComplete/auto-complete-filter-multiple-select-multiple-fields-display/auto-complete-filter-multiple-select-multiple-fields-display.component.js +2 -129
- package/lib/src/core-components/src/components/AutoComplete/auto-complete-filter-single-select/auto-complete-filter-single-select.component.js +1 -55
- package/lib/src/core-components/src/components/AutoComplete/auto-complete-filter-single-select-multiple-fields-display/auto-complete-filter-single-select-multiple-fields-display.component.js +2 -308
- package/lib/src/core-components/src/components/AutoComplete/auto-complete-group-by/auto-complete-group-by.component.js +1 -115
- package/lib/src/core-components/src/components/AutoComplete/autocomplete/autocomplete.js +2 -442
- package/lib/src/core-components/src/components/AutoComplete/index.js +1 -8
- package/lib/src/core-components/src/components/Avatar/Avatar.js +14 -148
- package/lib/src/core-components/src/components/Badge/Badge.js +2 -25
- package/lib/src/core-components/src/components/Badge/InnerBadge/Inline.js +1 -25
- package/lib/src/core-components/src/components/Badge/InnerBadge/InnerBadge.js +1 -25
- package/lib/src/core-components/src/components/Badge/InnerBadge/elements.js +32 -78
- package/lib/src/core-components/src/components/Badge/InnerBadge/index.js +1 -1
- package/lib/src/core-components/src/components/Badge/index.js +1 -1
- package/lib/src/core-components/src/components/Badge/types.js +1 -5
- package/lib/src/core-components/src/components/Breadcrumb/Breadcrumb.js +1 -83
- package/lib/src/core-components/src/components/Breadcrumb/elements.js +94 -166
- package/lib/src/core-components/src/components/Breadcrumb/index.js +1 -3
- package/lib/src/core-components/src/components/Breadcrumb/types.js +1 -3
- package/lib/src/core-components/src/components/Button/button.component.js +1 -18
- package/lib/src/core-components/src/components/Button/buttonGroup/buttonGroup.component.js +1 -4
- package/lib/src/core-components/src/components/Button/index.js +1 -2
- package/lib/src/core-components/src/components/Button/types.js +1 -1
- package/lib/src/core-components/src/components/Chip/Chip.js +1 -64
- package/lib/src/core-components/src/components/Chip/elements.js +48 -148
- package/lib/src/core-components/src/components/Chip/index.js +1 -2
- package/lib/src/core-components/src/components/Chip/types.js +1 -4
- package/lib/src/core-components/src/components/Divider/Divider.js +1 -25
- package/lib/src/core-components/src/components/Divider/elements.js +31 -68
- package/lib/src/core-components/src/components/Divider/index.js +1 -2
- package/lib/src/core-components/src/components/Divider/types.js +1 -4
- package/lib/src/core-components/src/components/DynamicGrid/DynamicGrid.js +1 -147
- package/lib/src/core-components/src/components/DynamicGrid/GridContainer.js +17 -24
- package/lib/src/core-components/src/components/DynamicGrid/elements.js +100 -162
- package/lib/src/core-components/src/components/DynamicGrid/index.js +1 -3
- package/lib/src/core-components/src/components/DynamicGrid/types.js +1 -28
- package/lib/src/core-components/src/components/DynamicGrid/utils.js +1 -193
- package/lib/src/core-components/src/components/FormField/FormField.js +1 -103
- package/lib/src/core-components/src/components/FormField/components/CheckboxGroupInput.js +1 -37
- package/lib/src/core-components/src/components/FormField/components/CheckboxInput.js +1 -8
- package/lib/src/core-components/src/components/FormField/components/CssMultilineInput.js +1 -192
- package/lib/src/core-components/src/components/FormField/components/DatePickerInput.js +1 -99
- package/lib/src/core-components/src/components/FormField/components/DropdownInput.js +1 -70
- package/lib/src/core-components/src/components/FormField/components/OtpInput.js +1 -81
- package/lib/src/core-components/src/components/FormField/components/PasswordInput.js +1 -40
- package/lib/src/core-components/src/components/FormField/components/PinInput.js +1 -75
- package/lib/src/core-components/src/components/FormField/components/RadioInput.js +1 -54
- package/lib/src/core-components/src/components/FormField/components/TextDropdownInput.js +1 -94
- package/lib/src/core-components/src/components/FormField/components/ToggleInput.js +1 -36
- package/lib/src/core-components/src/components/FormField/components/index.js +1 -11
- package/lib/src/core-components/src/components/FormField/css-properties.js +1 -161
- package/lib/src/core-components/src/components/FormField/index.js +1 -2
- package/lib/src/core-components/src/components/Icon/Icon.js +1 -159
- package/lib/src/core-components/src/components/Icon/index.js +1 -2
- package/lib/src/core-components/src/components/Icon/types.js +1 -9
- package/lib/src/core-components/src/components/Loader/loader.component.js +2 -215
- package/lib/src/core-components/src/components/Masonry/Masonry.js +1 -73
- package/lib/src/core-components/src/components/Masonry/elements.js +29 -46
- package/lib/src/core-components/src/components/Masonry/hooks.js +1 -100
- package/lib/src/core-components/src/components/Masonry/index.js +1 -3
- package/lib/src/core-components/src/components/Masonry/types.js +1 -1
- package/lib/src/core-components/src/components/Modal/BasicModal/modal.component.js +1 -116
- package/lib/src/core-components/src/components/Modal/index.js +1 -2
- package/lib/src/core-components/src/components/Modal/modal-confirm/modal-confirm.component.js +1 -147
- package/lib/src/core-components/src/components/Picker/color-picker/color-picker.component.js +1 -12
- package/lib/src/core-components/src/components/Picker/color-picker-modal/color-picker-modal.component.js +1 -40
- package/lib/src/core-components/src/components/Picker/index.js +1 -2
- package/lib/src/core-components/src/components/Selection/index.js +1 -4
- package/lib/src/core-components/src/components/Selection/multi-select/multi-select.component.js +1 -49
- package/lib/src/core-components/src/components/Selection/multi-select-with-field/multi-select-with-field.component.js +1 -58
- package/lib/src/core-components/src/components/Selection/multi-selection-dropdown/multi-selection-dropdown.component.js +1 -43
- package/lib/src/core-components/src/components/Selection/single-select/single-select.component.js +1 -87
- package/lib/src/core-components/src/components/Skeleton/Skeleton.js +1 -51
- package/lib/src/core-components/src/components/Skeleton/elements.js +54 -143
- package/lib/src/core-components/src/components/Skeleton/index.js +1 -2
- package/lib/src/core-components/src/components/Skeleton/types.js +1 -4
- package/lib/src/core-components/src/components/SpeedDial/SpeedDial.js +1 -128
- package/lib/src/core-components/src/components/SpeedDial/elements.js +62 -132
- package/lib/src/core-components/src/components/SpeedDial/index.js +1 -2
- package/lib/src/core-components/src/components/SpeedDial/types.js +1 -3
- package/lib/src/core-components/src/components/Stepper2/stepper.component.js +1 -139
- package/lib/src/core-components/src/components/Switch/Switch.js +1 -26
- package/lib/src/core-components/src/components/Switch/elements.js +34 -103
- package/lib/src/core-components/src/components/Switch/index.js +1 -2
- package/lib/src/core-components/src/components/Switch/types.js +1 -3
- package/lib/src/core-components/src/components/Table/Table.js +1 -1489
- package/lib/src/core-components/src/components/Table/columnReorder.js +36 -332
- package/lib/src/core-components/src/components/Table/columnResize.js +21 -284
- package/lib/src/core-components/src/components/Table/elements.js +173 -277
- package/lib/src/core-components/src/components/Table/filters.js +30 -555
- package/lib/src/core-components/src/components/Table/hooks.js +2 -536
- package/lib/src/core-components/src/components/Table/index.js +1 -6
- package/lib/src/core-components/src/components/Table/types.js +1 -1
- package/lib/src/core-components/src/components/Tabs/tabs.component.js +1 -22
- package/lib/src/core-components/src/components/Tags1/Tags.component.js +1 -118
- package/lib/src/core-components/src/components/Tags1/types.js +1 -20
- package/lib/src/core-components/src/components/Timer1/timer.component.js +1 -76
- package/lib/src/core-components/src/components/Toast/Toast.js +1 -50
- package/lib/src/core-components/src/components/Toast/elements.js +41 -122
- package/lib/src/core-components/src/components/Toast/index.js +1 -2
- package/lib/src/core-components/src/components/Toast/types.js +1 -9
- package/lib/src/core-components/src/components/Tooltip/Tooltip.js +1 -200
- package/lib/src/core-components/src/components/Tooltip/elements.js +55 -117
- package/lib/src/core-components/src/components/Tooltip/index.js +1 -2
- package/lib/src/core-components/src/components/Tooltip/types.js +1 -17
- package/lib/src/core-components/src/components/Tooltip/utils.js +1 -140
- package/lib/src/core-components/src/components/TreeSelect/TreeSelect.js +1 -303
- package/lib/src/core-components/src/components/TreeSelect/elements.js +117 -216
- package/lib/src/core-components/src/components/TreeSelect/hooks.js +1 -252
- package/lib/src/core-components/src/components/TreeSelect/index.js +1 -3
- package/lib/src/core-components/src/components/TreeSelect/types.js +1 -1
- package/lib/src/core-components/src/components/ag-grid/AgGrid.js +1 -1057
- package/lib/src/core-components/src/components/ag-grid/elements.js +396 -790
- package/lib/src/core-components/src/components/ag-grid/hooks.js +4 -1220
- package/lib/src/core-components/src/components/ag-grid/index.js +1 -15
- package/lib/src/core-components/src/components/ag-grid/types.js +1 -6
- package/lib/src/core-components/src/components/index.js +1 -31
- package/lib/src/core-components/src/components/pdf/pdf-images.components.js +1 -7
- package/lib/src/core-components/src/components/pdf/pdf-table.components.js +5 -48
- package/lib/src/core-components/src/components/pdf/pdf-typography.components.js +1 -70
- package/lib/src/core-components/src/components/pdf/pdf-wrapped-view.components.js +1 -50
- package/lib/src/core-components/src/core-components/Avatar.js +4 -33
- package/lib/src/core-components/src/core-components/CoreButton/CoreButton.js +1 -10
- package/lib/src/core-components/src/core-components/CoreButton/elements.js +67 -176
- package/lib/src/core-components/src/core-components/CoreButton/index.js +1 -3
- package/lib/src/core-components/src/core-components/CoreButton/types.js +1 -6
- package/lib/src/core-components/src/core-components/CoreButton/utils.js +1 -12
- package/lib/src/core-components/src/core-components/Divider/Divider.js +4 -19
- package/lib/src/core-components/src/core-components/Divider/index.js +1 -1
- package/lib/src/core-components/src/core-components/SelectionCardStrip/index.js +1 -1
- package/lib/src/core-components/src/core-components/SelectionCardStrip/selectionCardStrip.js +10 -33
- package/lib/src/core-components/src/core-components/StateLayer.js +3 -5
- package/lib/src/core-components/src/core-components/ToggleCore/elements.js +25 -50
- package/lib/src/core-components/src/core-components/ToggleCore/index.js +1 -2
- package/lib/src/core-components/src/core-components/ToggleCore/toggleCore.js +1 -14
- package/lib/src/core-components/src/core-components/atoms/Input/Input.js +1 -22
- package/lib/src/core-components/src/core-components/atoms/Label/Label.js +1 -21
- package/lib/src/core-components/src/core-components/atoms/Textarea/Textarea.js +1 -19
- package/lib/src/core-components/src/core-components/index.js +1 -3
- package/lib/src/core-components/src/helpers/constants.js +1 -11
- package/lib/src/core-components/src/hooks/index.js +1 -1
- package/lib/src/core-components/src/hooks/outside.hook.js +1 -28
- package/lib/src/core-components/src/index.js +1 -12
- package/lib/src/core-components/src/tc.global.css +1 -0
- package/lib/src/core-components/src/utils/abstracts/breakpoints/index.js +1 -28
- package/lib/src/core-components/src/utils/abstracts/colors/index.js +1 -49
- package/lib/src/core-components/src/utils/abstracts/index.js +1 -5
- package/lib/src/core-components/src/utils/abstracts/space/index.js +1 -26
- package/lib/src/core-components/src/utils/abstracts/theme/ThemeBoundary.js +1 -8
- package/lib/src/core-components/src/utils/abstracts/theme/default-themes.js +1 -30
- package/lib/src/core-components/src/utils/abstracts/theme/index.js +1 -3
- package/lib/src/core-components/src/utils/abstracts/theme/theme.js +1 -30
- package/lib/src/core-components/src/utils/abstracts/theme/types.js +1 -1
- package/lib/src/core-components/src/utils/abstracts/theme/useTheme.js +1 -17
- package/lib/src/core-components/src/utils/abstracts/typography/index.js +1 -25
- package/lib/src/core-components/src/utils/context/DefaultsProvider.js +1 -8
- package/lib/src/core-components/src/utils/context/InternalProvider.js +1 -24
- package/lib/src/core-components/src/utils/context/index.js +1 -2
- package/lib/src/core-components/src/utils/designTokens.js +1 -128
- package/lib/src/core-components/src/utils/helpers/attachSubComponents.js +1 -23
- package/lib/src/core-components/src/utils/helpers/flattenChildren.js +1 -11
- package/lib/src/core-components/src/utils/helpers/getChildByType.js +1 -3
- package/lib/src/core-components/src/utils/helpers/index.js +1 -5
- package/lib/src/core-components/src/utils/helpers/isComponentType.js +1 -16
- package/lib/src/core-components/src/utils/helpers/separateChildrenByType.js +1 -12
- package/lib/src/core-components/src/utils/hooks/index.js +1 -18
- package/lib/src/core-components/src/utils/hooks/useClickOutside.js +1 -18
- package/lib/src/core-components/src/utils/hooks/useCombinedRefs.js +1 -17
- package/lib/src/core-components/src/utils/hooks/useDebouncedCallback.js +1 -12
- package/lib/src/core-components/src/utils/hooks/useDebouncedValue.js +1 -20
- package/lib/src/core-components/src/utils/hooks/useDeprecation.js +1 -40
- package/lib/src/core-components/src/utils/hooks/useDeviceDetect.js +1 -10
- package/lib/src/core-components/src/utils/hooks/useDeviceForm.js +1 -24
- package/lib/src/core-components/src/utils/hooks/useDisableBodyScroll.js +1 -16
- package/lib/src/core-components/src/utils/hooks/useHoverState.js +1 -36
- package/lib/src/core-components/src/utils/hooks/useId.js +1 -7
- package/lib/src/core-components/src/utils/hooks/useIsBrowser.js +1 -11
- package/lib/src/core-components/src/utils/hooks/useMediaQuery.js +1 -16
- package/lib/src/core-components/src/utils/hooks/useOverflow.js +1 -22
- package/lib/src/core-components/src/utils/hooks/useSafeLayoutEffect.js +1 -5
- package/lib/src/core-components/src/utils/hooks/useScrollingUp.js +1 -18
- package/lib/src/core-components/src/utils/hooks/useTrapFocus.js +1 -30
- package/lib/src/core-components/src/utils/hooks/useWindowDimensions.js +1 -23
- package/lib/src/core-components/src/utils/index.js +1 -9
- package/lib/src/core-components/src/utils/stories/Wrappers.js +8 -23
- package/lib/src/core-components/src/utils/stories/cleanProps.js +1 -5
- package/lib/src/core-components/src/utils/stories/index.js +1 -4
- package/lib/src/core-components/src/utils/stories/sleep.js +1 -4
- package/lib/src/core-components/src/utils/stories/view-ports.js +1 -50
- package/lib/src/core-components/src/utils/styling/calcWidthOfColumns.js +1 -5
- package/lib/src/core-components/src/utils/styling/createGridContainer.js +6 -12
- package/lib/src/core-components/src/utils/styling/createTransition.js +2 -7
- package/lib/src/core-components/src/utils/styling/forwardProps.js +1 -10
- package/lib/src/core-components/src/utils/styling/index.js +1 -5
- package/lib/src/core-components/src/utils/styling/pxToRem.js +1 -6
- package/lib/src/core-components/src/utils/testing/getComputedStyle.js +1 -3
- package/lib/src/core-components/src/utils/testing/index.js +1 -1
- package/lib/src/core-components/src/utils/utility.util.js +1 -14
- package/lib/src/core-components/tailwind.config.js +1 -233
- package/lib/src/core-hooks/index.js +1 -3
- package/lib/src/core-hooks/src/useClickOutside/useClickOutside.hook.js +1 -46
- package/lib/src/core-hooks/src/useDebounce/useDebounce.hook.js +1 -30
- package/lib/src/core-hooks/src/usePreventEKey/usePreventEKey.hook.js +1 -8
- package/lib/src/core-utils/index.js +1 -7
- package/lib/src/core-utils/src/calculation/calculation.util.js +1 -89
- package/lib/src/core-utils/src/colors/color.util.js +1 -15
- package/lib/src/core-utils/src/convert/numberToWords/numToWords.util.js +1 -145
- package/lib/src/core-utils/src/convert/typography/camelCaseToTitleCase.util.js +1 -5
- package/lib/src/core-utils/src/form-helper/form-helper.util.js +1 -82
- package/lib/src/core-utils/src/index.js +1 -7
- package/lib/src/core-utils/src/utility/utility.util.js +1 -12
- package/lib/src/core-utils/src/uuid/uuid.util.js +1 -8
- package/package.json +1 -1
|
@@ -1,303 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
-
import React, { forwardRef, useState, useRef, useCallback, useEffect, useMemo, } from 'react';
|
|
4
|
-
import { TreeSelectRoot, Selector, Prefix, SearchInput, Placeholder, SelectedValue, Tag, TagLabel, TagClose, MaxTagPlaceholder, Suffix, ArrowIcon, ClearButton, Dropdown, TreeContainer, TreeNode, ExpandIcon, LeafIndent, Checkbox, NodeIcon, NodeTitle, EmptyState, } from './elements';
|
|
5
|
-
import { useExpandedState, useCheckedState, useAsyncLoading, filterTree, findNodeByValue, getFieldValue, getDescendantValues, } from './hooks';
|
|
6
|
-
// Icons
|
|
7
|
-
const ChevronDownIcon = () => (_jsx("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: _jsx("path", { d: "M6 9l6 6 6-6", strokeLinecap: "round", strokeLinejoin: "round" }) }));
|
|
8
|
-
const ChevronRightIcon = () => (_jsx("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: _jsx("path", { d: "M9 6l6 6-6 6", strokeLinecap: "round", strokeLinejoin: "round" }) }));
|
|
9
|
-
const CloseIcon = () => (_jsx("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: _jsx("path", { d: "M18 6L6 18M6 6l12 12", strokeLinecap: "round", strokeLinejoin: "round" }) }));
|
|
10
|
-
const CheckIcon = () => (_jsx("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "3", children: _jsx("path", { d: "M5 12l5 5L20 7", strokeLinecap: "round", strokeLinejoin: "round" }) }));
|
|
11
|
-
const MinusIcon = () => (_jsx("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "3", children: _jsx("path", { d: "M5 12h14", strokeLinecap: "round" }) }));
|
|
12
|
-
const LoadingIcon = () => (_jsxs("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [_jsx("circle", { cx: "12", cy: "12", r: "10", strokeOpacity: "0.25" }), _jsx("path", { d: "M12 2a10 10 0 0 1 10 10", strokeLinecap: "round" })] }));
|
|
13
|
-
const FolderIcon = () => (_jsx("svg", { viewBox: "0 0 24 24", fill: "currentColor", children: _jsx("path", { d: "M2 6a2 2 0 0 1 2-2h5l2 2h9a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V6z" }) }));
|
|
14
|
-
const FileIcon = () => (_jsxs("svg", { viewBox: "0 0 24 24", fill: "currentColor", children: [_jsx("path", { d: "M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8l-6-6z" }), _jsx("path", { d: "M14 2v6h6", fill: "none", stroke: "currentColor", strokeWidth: "1" })] }));
|
|
15
|
-
export const TreeSelect = forwardRef(function TreeSelectComponent(props, ref) {
|
|
16
|
-
const { treeData, value, defaultValue, mode = 'single', placeholder = 'Please select', disabled = false, showSearch = false, filterTreeNode, treeNodeFilterProp = 'title', treeLine = false, showTreeIcon = false, checkable = false, checkStrictly = false, defaultExpandedKeys, expandedKeys: controlledExpandedKeys, defaultExpandAll = false, loadData, allowClear = false, autoClearSearchValue = true, maxTagCount, maxTagPlaceholder, placement = 'bottomLeft', open: controlledOpen, defaultOpen = false, variant = 'outlined', size = 'medium', prefix, suffixIcon, clearIcon, listHeight = 256, popupMatchSelectWidth = true, classNames = {}, styles = {}, className, style, status, fieldNames, dropdownRender, tabIndex = 0, autoFocus = false, onChange, onSelect, onSearch, onDropdownVisibleChange, onTreeExpand, onPopupScroll, onFocus, onBlur, onClear, ...rest } = props;
|
|
17
|
-
// Refs
|
|
18
|
-
const rootRef = useRef(null);
|
|
19
|
-
const inputRef = useRef(null);
|
|
20
|
-
// State
|
|
21
|
-
const [internalOpen, setInternalOpen] = useState(defaultOpen);
|
|
22
|
-
const [searchValue, setSearchValue] = useState('');
|
|
23
|
-
const [focused, setFocused] = useState(false);
|
|
24
|
-
const isOpen = controlledOpen !== undefined ? controlledOpen : internalOpen;
|
|
25
|
-
const isMultiple = mode === 'multiple' || mode === 'checkable';
|
|
26
|
-
const isCheckable = mode === 'checkable' || checkable;
|
|
27
|
-
// Selection state
|
|
28
|
-
const [selectedValues, setSelectedValues] = useState(() => {
|
|
29
|
-
if (value !== undefined) {
|
|
30
|
-
return Array.isArray(value) ? value : value ? [value] : [];
|
|
31
|
-
}
|
|
32
|
-
if (defaultValue !== undefined) {
|
|
33
|
-
return Array.isArray(defaultValue) ? defaultValue : defaultValue ? [defaultValue] : [];
|
|
34
|
-
}
|
|
35
|
-
return [];
|
|
36
|
-
});
|
|
37
|
-
// Update when controlled value changes
|
|
38
|
-
useEffect(() => {
|
|
39
|
-
if (value !== undefined) {
|
|
40
|
-
setSelectedValues(Array.isArray(value) ? value : value ? [value] : []);
|
|
41
|
-
}
|
|
42
|
-
}, [value]);
|
|
43
|
-
// Expanded state
|
|
44
|
-
const { expandedKeys, toggleExpand, setExpanded } = useExpandedState(treeData, defaultExpandedKeys, defaultExpandAll, controlledExpandedKeys, fieldNames);
|
|
45
|
-
// Checked state (for checkable mode)
|
|
46
|
-
const { checkedKeys, halfCheckedKeys, toggleCheck } = useCheckedState(treeData, isCheckable ? selectedValues : undefined, checkStrictly, fieldNames);
|
|
47
|
-
// Async loading
|
|
48
|
-
const { isLoading, setLoading, markLoaded } = useAsyncLoading();
|
|
49
|
-
// Filter tree based on search
|
|
50
|
-
const filteredData = useMemo(() => {
|
|
51
|
-
if (!searchValue)
|
|
52
|
-
return treeData;
|
|
53
|
-
return filterTree(treeData, searchValue, filterTreeNode, treeNodeFilterProp, fieldNames);
|
|
54
|
-
}, [treeData, searchValue, filterTreeNode, treeNodeFilterProp, fieldNames]);
|
|
55
|
-
// Get selected labels
|
|
56
|
-
const selectedLabels = useMemo(() => {
|
|
57
|
-
return selectedValues.map((val) => {
|
|
58
|
-
const node = findNodeByValue(treeData, val, fieldNames);
|
|
59
|
-
return node ? getFieldValue(node, 'label', fieldNames) : val;
|
|
60
|
-
});
|
|
61
|
-
}, [selectedValues, treeData, fieldNames]);
|
|
62
|
-
// Toggle dropdown
|
|
63
|
-
const toggleOpen = useCallback((newOpen) => {
|
|
64
|
-
if (disabled)
|
|
65
|
-
return;
|
|
66
|
-
if (controlledOpen === undefined) {
|
|
67
|
-
setInternalOpen(newOpen);
|
|
68
|
-
}
|
|
69
|
-
onDropdownVisibleChange?.(newOpen);
|
|
70
|
-
}, [disabled, controlledOpen, onDropdownVisibleChange]);
|
|
71
|
-
// Handle click outside
|
|
72
|
-
useEffect(() => {
|
|
73
|
-
const handleClickOutside = (e) => {
|
|
74
|
-
if (rootRef.current && !rootRef.current.contains(e.target)) {
|
|
75
|
-
toggleOpen(false);
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
if (isOpen) {
|
|
79
|
-
document.addEventListener('mousedown', handleClickOutside);
|
|
80
|
-
return () => document.removeEventListener('mousedown', handleClickOutside);
|
|
81
|
-
}
|
|
82
|
-
}, [isOpen, toggleOpen]);
|
|
83
|
-
// Handle selector click
|
|
84
|
-
const handleSelectorClick = useCallback(() => {
|
|
85
|
-
if (!disabled) {
|
|
86
|
-
toggleOpen(!isOpen);
|
|
87
|
-
if (showSearch) {
|
|
88
|
-
inputRef.current?.focus();
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}, [disabled, isOpen, showSearch, toggleOpen]);
|
|
92
|
-
// Handle search
|
|
93
|
-
const handleSearchChange = useCallback((e) => {
|
|
94
|
-
const val = e.target.value;
|
|
95
|
-
setSearchValue(val);
|
|
96
|
-
onSearch?.(val);
|
|
97
|
-
}, [onSearch]);
|
|
98
|
-
// Handle node select
|
|
99
|
-
const handleNodeSelect = useCallback((node) => {
|
|
100
|
-
const nodeValue = getFieldValue(node, 'value', fieldNames);
|
|
101
|
-
const nodeLabel = getFieldValue(node, 'label', fieldNames);
|
|
102
|
-
if (node.disabled)
|
|
103
|
-
return;
|
|
104
|
-
if (isCheckable) {
|
|
105
|
-
toggleCheck(nodeValue, node);
|
|
106
|
-
const newChecked = checkedKeys.has(nodeValue)
|
|
107
|
-
? Array.from(checkedKeys).filter((v) => v !== nodeValue)
|
|
108
|
-
: [...Array.from(checkedKeys), nodeValue];
|
|
109
|
-
if (!checkStrictly) {
|
|
110
|
-
// Handle descendants
|
|
111
|
-
const descendants = getDescendantValues(node, fieldNames);
|
|
112
|
-
const isChecking = !checkedKeys.has(nodeValue);
|
|
113
|
-
descendants.forEach((d) => {
|
|
114
|
-
if (isChecking) {
|
|
115
|
-
if (!newChecked.includes(d))
|
|
116
|
-
newChecked.push(d);
|
|
117
|
-
}
|
|
118
|
-
else {
|
|
119
|
-
const idx = newChecked.indexOf(d);
|
|
120
|
-
if (idx > -1)
|
|
121
|
-
newChecked.splice(idx, 1);
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
setSelectedValues(newChecked);
|
|
126
|
-
onChange?.(newChecked, newChecked.map((v) => {
|
|
127
|
-
const n = findNodeByValue(treeData, v, fieldNames);
|
|
128
|
-
return n ? getFieldValue(n, 'label', fieldNames) : v;
|
|
129
|
-
}), { triggerValue: nodeValue, triggerNode: node });
|
|
130
|
-
}
|
|
131
|
-
else if (isMultiple) {
|
|
132
|
-
const isSelected = selectedValues.includes(nodeValue);
|
|
133
|
-
const newValues = isSelected
|
|
134
|
-
? selectedValues.filter((v) => v !== nodeValue)
|
|
135
|
-
: [...selectedValues, nodeValue];
|
|
136
|
-
setSelectedValues(newValues);
|
|
137
|
-
onSelect?.(nodeValue, node, { selected: !isSelected });
|
|
138
|
-
onChange?.(newValues, newValues.map((v) => {
|
|
139
|
-
const n = findNodeByValue(treeData, v, fieldNames);
|
|
140
|
-
return n ? getFieldValue(n, 'label', fieldNames) : v;
|
|
141
|
-
}), { preValue: selectedValues, triggerValue: nodeValue, triggerNode: node });
|
|
142
|
-
}
|
|
143
|
-
else {
|
|
144
|
-
setSelectedValues([nodeValue]);
|
|
145
|
-
onSelect?.(nodeValue, node, { selected: true });
|
|
146
|
-
onChange?.(nodeValue, nodeLabel, {
|
|
147
|
-
preValue: selectedValues[0],
|
|
148
|
-
triggerValue: nodeValue,
|
|
149
|
-
triggerNode: node,
|
|
150
|
-
});
|
|
151
|
-
toggleOpen(false);
|
|
152
|
-
}
|
|
153
|
-
if (autoClearSearchValue) {
|
|
154
|
-
setSearchValue('');
|
|
155
|
-
}
|
|
156
|
-
}, [
|
|
157
|
-
isCheckable,
|
|
158
|
-
isMultiple,
|
|
159
|
-
selectedValues,
|
|
160
|
-
checkedKeys,
|
|
161
|
-
checkStrictly,
|
|
162
|
-
fieldNames,
|
|
163
|
-
treeData,
|
|
164
|
-
toggleCheck,
|
|
165
|
-
autoClearSearchValue,
|
|
166
|
-
onChange,
|
|
167
|
-
onSelect,
|
|
168
|
-
toggleOpen,
|
|
169
|
-
]);
|
|
170
|
-
// Handle expand toggle
|
|
171
|
-
const handleExpandToggle = useCallback(async (e, node) => {
|
|
172
|
-
e.stopPropagation();
|
|
173
|
-
const nodeValue = getFieldValue(node, 'value', fieldNames);
|
|
174
|
-
const children = getFieldValue(node, 'children', fieldNames);
|
|
175
|
-
// Async loading
|
|
176
|
-
if (loadData &&
|
|
177
|
-
!node.isLeaf &&
|
|
178
|
-
(!children || children.length === 0) &&
|
|
179
|
-
!isLoading(nodeValue)) {
|
|
180
|
-
setLoading(nodeValue, true);
|
|
181
|
-
try {
|
|
182
|
-
await loadData(node);
|
|
183
|
-
markLoaded(nodeValue);
|
|
184
|
-
}
|
|
185
|
-
catch (err) {
|
|
186
|
-
console.error('Failed to load data:', err);
|
|
187
|
-
}
|
|
188
|
-
setLoading(nodeValue, false);
|
|
189
|
-
}
|
|
190
|
-
toggleExpand(nodeValue);
|
|
191
|
-
const newExpanded = expandedKeys.has(nodeValue)
|
|
192
|
-
? Array.from(expandedKeys).filter((k) => k !== nodeValue)
|
|
193
|
-
: [...Array.from(expandedKeys), nodeValue];
|
|
194
|
-
onTreeExpand?.(newExpanded);
|
|
195
|
-
}, [fieldNames, loadData, isLoading, setLoading, markLoaded, toggleExpand, expandedKeys, onTreeExpand]);
|
|
196
|
-
// Handle tag remove
|
|
197
|
-
const handleTagRemove = useCallback((e, val) => {
|
|
198
|
-
e.stopPropagation();
|
|
199
|
-
const newValues = selectedValues.filter((v) => v !== val);
|
|
200
|
-
setSelectedValues(newValues);
|
|
201
|
-
onChange?.(newValues, newValues.map((v) => {
|
|
202
|
-
const n = findNodeByValue(treeData, v, fieldNames);
|
|
203
|
-
return n ? getFieldValue(n, 'label', fieldNames) : v;
|
|
204
|
-
}), { triggerValue: val });
|
|
205
|
-
}, [selectedValues, treeData, fieldNames, onChange]);
|
|
206
|
-
// Handle clear
|
|
207
|
-
const handleClear = useCallback((e) => {
|
|
208
|
-
e.stopPropagation();
|
|
209
|
-
setSelectedValues([]);
|
|
210
|
-
setSearchValue('');
|
|
211
|
-
onChange?.(isMultiple ? [] : '', isMultiple ? [] : '', {});
|
|
212
|
-
onClear?.();
|
|
213
|
-
}, [isMultiple, onChange, onClear]);
|
|
214
|
-
// Handle focus/blur
|
|
215
|
-
const handleFocus = useCallback((e) => {
|
|
216
|
-
setFocused(true);
|
|
217
|
-
onFocus?.(e);
|
|
218
|
-
}, [onFocus]);
|
|
219
|
-
const handleBlur = useCallback((e) => {
|
|
220
|
-
setFocused(false);
|
|
221
|
-
onBlur?.(e);
|
|
222
|
-
}, [onBlur]);
|
|
223
|
-
// Keyboard navigation
|
|
224
|
-
const handleKeyDown = useCallback((e) => {
|
|
225
|
-
switch (e.key) {
|
|
226
|
-
case 'Enter':
|
|
227
|
-
case ' ':
|
|
228
|
-
if (!isOpen) {
|
|
229
|
-
toggleOpen(true);
|
|
230
|
-
}
|
|
231
|
-
break;
|
|
232
|
-
case 'Escape':
|
|
233
|
-
toggleOpen(false);
|
|
234
|
-
break;
|
|
235
|
-
case 'Backspace':
|
|
236
|
-
if (!searchValue && isMultiple && selectedValues.length > 0) {
|
|
237
|
-
const newValues = selectedValues.slice(0, -1);
|
|
238
|
-
setSelectedValues(newValues);
|
|
239
|
-
onChange?.(newValues, newValues.map((v) => {
|
|
240
|
-
const n = findNodeByValue(treeData, v, fieldNames);
|
|
241
|
-
return n ? getFieldValue(n, 'label', fieldNames) : v;
|
|
242
|
-
}), {});
|
|
243
|
-
}
|
|
244
|
-
break;
|
|
245
|
-
}
|
|
246
|
-
}, [isOpen, searchValue, isMultiple, selectedValues, treeData, fieldNames, onChange, toggleOpen]);
|
|
247
|
-
// Auto focus
|
|
248
|
-
useEffect(() => {
|
|
249
|
-
if (autoFocus && inputRef.current) {
|
|
250
|
-
inputRef.current.focus();
|
|
251
|
-
}
|
|
252
|
-
}, [autoFocus]);
|
|
253
|
-
// Render tree node
|
|
254
|
-
const renderTreeNode = (node, level = 0) => {
|
|
255
|
-
const nodeValue = getFieldValue(node, 'value', fieldNames);
|
|
256
|
-
const nodeLabel = getFieldValue(node, 'label', fieldNames);
|
|
257
|
-
const children = getFieldValue(node, 'children', fieldNames);
|
|
258
|
-
const hasChildren = children && children.length > 0;
|
|
259
|
-
const isExpanded = expandedKeys.has(nodeValue);
|
|
260
|
-
const isSelected = selectedValues.includes(nodeValue);
|
|
261
|
-
const isChecked = checkedKeys.has(nodeValue);
|
|
262
|
-
const isHalfChecked = halfCheckedKeys.has(nodeValue);
|
|
263
|
-
const loading = isLoading(nodeValue);
|
|
264
|
-
const isLeaf = node.isLeaf || (!hasChildren && !loadData);
|
|
265
|
-
const showLine = !!treeLine;
|
|
266
|
-
return (_jsxs(React.Fragment, { children: [_jsxs(TreeNode, { "$level": level, "$isLeaf": isLeaf, "$disabled": !!node.disabled, "$selected": isSelected && !isCheckable, "$checked": isChecked, "$indeterminate": isHalfChecked, "$showLine": showLine, "data-disabled": node.disabled, className: classNames.node, style: styles.node, onClick: () => handleNodeSelect(node), role: "treeitem", "aria-selected": isSelected, "aria-expanded": hasChildren ? isExpanded : undefined, "aria-disabled": node.disabled, children: [isLeaf ? (_jsx(LeafIndent, {})) : (_jsx(ExpandIcon, { "$expanded": isExpanded, "$loading": loading, onClick: (e) => handleExpandToggle(e, node), children: loading ? _jsx(LoadingIcon, {}) : _jsx(ChevronRightIcon, {}) })), isCheckable && node.checkable !== false && (_jsxs(Checkbox, { "$checked": isChecked, "$indeterminate": isHalfChecked && !isChecked, "$disabled": !!node.disableCheckbox || !!node.disabled, className: classNames.nodeCheckbox, style: styles.nodeCheckbox, role: "checkbox", "aria-checked": isHalfChecked ? 'mixed' : isChecked, children: [isChecked && _jsx(CheckIcon, {}), isHalfChecked && !isChecked && _jsx(MinusIcon, {})] })), showTreeIcon && (_jsx(NodeIcon, { children: node.icon || (isLeaf ? _jsx(FileIcon, {}) : _jsx(FolderIcon, {})) })), _jsx(NodeTitle, { "$disabled": !!node.disabled, className: classNames.nodeTitle, style: styles.nodeTitle, children: nodeLabel })] }), hasChildren && isExpanded && (_jsx(_Fragment, { children: children.map((child) => renderTreeNode(child, level + 1)) }))] }, node.key || nodeValue));
|
|
267
|
-
};
|
|
268
|
-
// Render selected tags
|
|
269
|
-
const renderTags = () => {
|
|
270
|
-
if (!isMultiple)
|
|
271
|
-
return null;
|
|
272
|
-
let visibleValues = selectedValues;
|
|
273
|
-
let hiddenCount = 0;
|
|
274
|
-
if (maxTagCount !== undefined && maxTagCount !== 'responsive') {
|
|
275
|
-
visibleValues = selectedValues.slice(0, maxTagCount);
|
|
276
|
-
hiddenCount = selectedValues.length - maxTagCount;
|
|
277
|
-
}
|
|
278
|
-
return (_jsxs(_Fragment, { children: [visibleValues.map((val, idx) => {
|
|
279
|
-
const label = selectedLabels[selectedValues.indexOf(val)];
|
|
280
|
-
const node = findNodeByValue(treeData, val, fieldNames);
|
|
281
|
-
return (_jsxs(Tag, { "$size": size, "$disabled": node?.disabled, className: classNames.tag, style: styles.tag, children: [_jsx(TagLabel, { children: label }), !disabled && !node?.disabled && (_jsx(TagClose, { onClick: (e) => handleTagRemove(e, val), children: _jsx(CloseIcon, {}) }))] }, val));
|
|
282
|
-
}), hiddenCount > 0 && (_jsx(MaxTagPlaceholder, { "$size": size, children: typeof maxTagPlaceholder === 'function'
|
|
283
|
-
? maxTagPlaceholder(selectedValues.slice(maxTagCount))
|
|
284
|
-
: maxTagPlaceholder || `+${hiddenCount}` }))] }));
|
|
285
|
-
};
|
|
286
|
-
// Render dropdown content
|
|
287
|
-
const renderDropdown = () => {
|
|
288
|
-
const content = (_jsx(TreeContainer, { "$showLine": !!treeLine, className: classNames.tree, style: styles.tree, role: "tree", onScroll: onPopupScroll, children: filteredData.length === 0 ? (_jsx(EmptyState, { children: "No data" })) : (filteredData.map((node) => renderTreeNode(node))) }));
|
|
289
|
-
return dropdownRender ? dropdownRender(content) : content;
|
|
290
|
-
};
|
|
291
|
-
const hasValue = selectedValues.length > 0;
|
|
292
|
-
return (_jsxs(TreeSelectRoot, { ref: (node) => {
|
|
293
|
-
rootRef.current = node;
|
|
294
|
-
if (typeof ref === 'function') {
|
|
295
|
-
ref(node);
|
|
296
|
-
}
|
|
297
|
-
else if (ref) {
|
|
298
|
-
ref.current = node;
|
|
299
|
-
}
|
|
300
|
-
}, "$size": size, "$variant": variant, "$status": status, "$disabled": disabled, "$focused": focused, "data-disabled": disabled, className: className || classNames.root, style: { ...styles.root, ...style }, onKeyDown: handleKeyDown, tabIndex: disabled ? -1 : tabIndex, role: "combobox", "aria-expanded": isOpen, "aria-haspopup": "tree", "aria-disabled": disabled, "aria-label": rest['aria-label'], "aria-labelledby": rest['aria-labelledby'], children: [_jsxs(Selector, { "$size": size, "$variant": variant, "$status": status, "$multiple": isMultiple, "$hasValue": hasValue, className: classNames.selector, style: styles.selector, onClick: handleSelectorClick, onFocus: handleFocus, onBlur: handleBlur, children: [prefix && (_jsx(Prefix, { "$size": size, className: classNames.prefix, style: styles.prefix, children: prefix })), renderTags(), showSearch ? (_jsx(SearchInput, { ref: inputRef, "$size": size, value: searchValue, onChange: handleSearchChange, placeholder: hasValue && !isMultiple ? '' : placeholder, disabled: disabled, className: classNames.search, style: styles.search, "aria-label": "Search" })) : !isMultiple || !hasValue ? (hasValue && !isMultiple ? (_jsx(SelectedValue, { children: selectedLabels[0] })) : (_jsx(Placeholder, { className: classNames.placeholder, style: styles.placeholder, children: placeholder }))) : null, _jsxs(Suffix, { "$size": size, "$open": isOpen, className: classNames.suffix, style: styles.suffix, children: [allowClear && hasValue && !disabled && (_jsx(ClearButton, { onClick: handleClear, "aria-label": "Clear", children: clearIcon || _jsx(CloseIcon, {}) })), _jsx(ArrowIcon, { "$open": isOpen, children: suffixIcon || _jsx(ChevronDownIcon, {}) })] })] }), isOpen && (_jsx(Dropdown, { "$placement": placement, "$maxHeight": listHeight, "$matchWidth": popupMatchSelectWidth, className: classNames.popup, style: styles.popup, role: "listbox", children: renderDropdown() }))] }));
|
|
301
|
-
});
|
|
302
|
-
TreeSelect.displayName = 'TreeSelect';
|
|
303
|
-
export default TreeSelect;
|
|
1
|
+
"use strict";"use client";import{jsx as a,jsxs as x,Fragment as Le}from"react/jsx-runtime";import sn,{forwardRef as on,useState as O,useRef as we,useCallback as C,useEffect as X,useMemo as ve}from"react";import{TreeSelectRoot as cn,Selector as dn,Prefix as un,SearchInput as hn,Placeholder as fn,SelectedValue as pn,Tag as gn,TagLabel as mn,TagClose as kn,MaxTagPlaceholder as bn,Suffix as xn,ArrowIcon as Cn,ClearButton as yn,Dropdown as $n,TreeContainer as Ln,TreeNode as wn,ExpandIcon as vn,LeafIndent as Nn,Checkbox as Sn,NodeIcon as Vn,NodeTitle as Tn,EmptyState as In}from"./elements";import{useExpandedState as En,useCheckedState as Mn,useAsyncLoading as Bn,filterTree as An,findNodeByValue as S,getFieldValue as p,getDescendantValues as Fn}from"./hooks";const zn=()=>a("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:a("path",{d:"M6 9l6 6 6-6",strokeLinecap:"round",strokeLinejoin:"round"})}),Dn=()=>a("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:a("path",{d:"M9 6l6 6-6 6",strokeLinecap:"round",strokeLinejoin:"round"})}),Ne=()=>a("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:a("path",{d:"M18 6L6 18M6 6l12 12",strokeLinecap:"round",strokeLinejoin:"round"})}),Pn=()=>a("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",children:a("path",{d:"M5 12l5 5L20 7",strokeLinecap:"round",strokeLinejoin:"round"})}),On=()=>a("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",children:a("path",{d:"M5 12h14",strokeLinecap:"round"})}),Rn=()=>x("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[a("circle",{cx:"12",cy:"12",r:"10",strokeOpacity:"0.25"}),a("path",{d:"M12 2a10 10 0 0 1 10 10",strokeLinecap:"round"})]}),Wn=()=>a("svg",{viewBox:"0 0 24 24",fill:"currentColor",children:a("path",{d:"M2 6a2 2 0 0 1 2-2h5l2 2h9a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V6z"})}),jn=()=>x("svg",{viewBox:"0 0 24 24",fill:"currentColor",children:[a("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8l-6-6z"}),a("path",{d:"M14 2v6h6",fill:"none",stroke:"currentColor",strokeWidth:"1"})]});export const TreeSelect=on(function(Se,A){const{treeData:i,value:g,defaultValue:V,mode:R="single",placeholder:Y="Please select",disabled:m=!1,showSearch:W=!1,filterTreeNode:Z,treeNodeFilterProp:ee="title",treeLine:ne=!1,showTreeIcon:Ve=!1,checkable:Te=!1,checkStrictly:j=!1,defaultExpandedKeys:Ie,expandedKeys:Ee,defaultExpandAll:Me=!1,loadData:F,allowClear:Be=!1,autoClearSearchValue:ae=!0,maxTagCount:T,maxTagPlaceholder:K,placement:Ae="bottomLeft",open:z,defaultOpen:Fe=!1,variant:le="outlined",size:$="medium",prefix:te,suffixIcon:ze,clearIcon:De,listHeight:Pe=256,popupMatchSelectWidth:Oe=!0,classNames:d={},styles:u={},className:Re,style:We,status:re,fieldNames:t,dropdownRender:se,tabIndex:je=0,autoFocus:oe=!1,onChange:k,onSelect:H,onSearch:ce,onDropdownVisibleChange:ie,onTreeExpand:de,onPopupScroll:Ke,onFocus:ue,onBlur:he,onClear:fe,...pe}=Se,_=we(null),D=we(null),[He,_e]=O(Fe),[w,q]=O(""),[qe,ge]=O(!1),b=z!==void 0?z:He,h=R==="multiple"||R==="checkable",I=R==="checkable"||Te,[s,L]=O(()=>g!==void 0?Array.isArray(g)?g:g?[g]:[]:V!==void 0?Array.isArray(V)?V:V?[V]:[]:[]);X(()=>{g!==void 0&&L(Array.isArray(g)?g:g?[g]:[])},[g]);const{expandedKeys:E,toggleExpand:me,setExpanded:Hn}=En(i,Ie,Me,Ee,t),{checkedKeys:v,halfCheckedKeys:Ge,toggleCheck:ke}=Mn(i,I?s:void 0,j,t),{isLoading:G,setLoading:J,markLoaded:be}=Bn(),xe=ve(()=>w?An(i,w,Z,ee,t):i,[i,w,Z,ee,t]),Ce=ve(()=>s.map(e=>{const n=S(i,e,t);return n?p(n,"label",t):e}),[s,i,t]),y=C(e=>{m||(z===void 0&&_e(e),ie?.(e))},[m,z,ie]);X(()=>{const e=n=>{_.current&&!_.current.contains(n.target)&&y(!1)};if(b)return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[b,y]);const Je=C(()=>{m||(y(!b),W&&D.current?.focus())},[m,b,W,y]),Qe=C(e=>{const n=e.target.value;q(n),ce?.(n)},[ce]),Ue=C(e=>{const n=p(e,"value",t),l=p(e,"label",t);if(!e.disabled){if(I){ke(n,e);const r=v.has(n)?Array.from(v).filter(o=>o!==n):[...Array.from(v),n];if(!j){const o=Fn(e,t),c=!v.has(n);o.forEach(f=>{if(c)r.includes(f)||r.push(f);else{const B=r.indexOf(f);B>-1&&r.splice(B,1)}})}L(r),k?.(r,r.map(o=>{const c=S(i,o,t);return c?p(c,"label",t):o}),{triggerValue:n,triggerNode:e})}else if(h){const r=s.includes(n),o=r?s.filter(c=>c!==n):[...s,n];L(o),H?.(n,e,{selected:!r}),k?.(o,o.map(c=>{const f=S(i,c,t);return f?p(f,"label",t):c}),{preValue:s,triggerValue:n,triggerNode:e})}else L([n]),H?.(n,e,{selected:!0}),k?.(n,l,{preValue:s[0],triggerValue:n,triggerNode:e}),y(!1);ae&&q("")}},[I,h,s,v,j,t,i,ke,ae,k,H,y]),Xe=C(async(e,n)=>{e.stopPropagation();const l=p(n,"value",t),r=p(n,"children",t);if(F&&!n.isLeaf&&(!r||r.length===0)&&!G(l)){J(l,!0);try{await F(n),be(l)}catch(c){console.error("Failed to load data:",c)}J(l,!1)}me(l);const o=E.has(l)?Array.from(E).filter(c=>c!==l):[...Array.from(E),l];de?.(o)},[t,F,G,J,be,me,E,de]),Ye=C((e,n)=>{e.stopPropagation();const l=s.filter(r=>r!==n);L(l),k?.(l,l.map(r=>{const o=S(i,r,t);return o?p(o,"label",t):r}),{triggerValue:n})},[s,i,t,k]),Ze=C(e=>{e.stopPropagation(),L([]),q(""),k?.(h?[]:"",h?[]:"",{}),fe?.()},[h,k,fe]),en=C(e=>{ge(!0),ue?.(e)},[ue]),nn=C(e=>{ge(!1),he?.(e)},[he]),an=C(e=>{switch(e.key){case"Enter":case" ":b||y(!0);break;case"Escape":y(!1);break;case"Backspace":if(!w&&h&&s.length>0){const n=s.slice(0,-1);L(n),k?.(n,n.map(l=>{const r=S(i,l,t);return r?p(r,"label",t):l}),{})}break}},[b,w,h,s,i,t,k,y]);X(()=>{oe&&D.current&&D.current.focus()},[oe]);const ye=(e,n=0)=>{const l=p(e,"value",t),r=p(e,"label",t),o=p(e,"children",t),c=o&&o.length>0,f=E.has(l),B=s.includes(l),N=v.has(l),P=Ge.has(l),$e=G(l),Q=e.isLeaf||!c&&!F,rn=!!ne;return x(sn.Fragment,{children:[x(wn,{$level:n,$isLeaf:Q,$disabled:!!e.disabled,$selected:B&&!I,$checked:N,$indeterminate:P,$showLine:rn,"data-disabled":e.disabled,className:d.node,style:u.node,onClick:()=>Ue(e),role:"treeitem","aria-selected":B,"aria-expanded":c?f:void 0,"aria-disabled":e.disabled,children:[Q?a(Nn,{}):a(vn,{$expanded:f,$loading:$e,onClick:U=>Xe(U,e),children:$e?a(Rn,{}):a(Dn,{})}),I&&e.checkable!==!1&&x(Sn,{$checked:N,$indeterminate:P&&!N,$disabled:!!e.disableCheckbox||!!e.disabled,className:d.nodeCheckbox,style:u.nodeCheckbox,role:"checkbox","aria-checked":P?"mixed":N,children:[N&&a(Pn,{}),P&&!N&&a(On,{})]}),Ve&&a(Vn,{children:e.icon||(Q?a(jn,{}):a(Wn,{}))}),a(Tn,{$disabled:!!e.disabled,className:d.nodeTitle,style:u.nodeTitle,children:r})]}),c&&f&&a(Le,{children:o.map(U=>ye(U,n+1))})]},e.key||l)},ln=()=>{if(!h)return null;let e=s,n=0;return T!==void 0&&T!=="responsive"&&(e=s.slice(0,T),n=s.length-T),x(Le,{children:[e.map((l,r)=>{const o=Ce[s.indexOf(l)],c=S(i,l,t);return x(gn,{$size:$,$disabled:c?.disabled,className:d.tag,style:u.tag,children:[a(mn,{children:o}),!m&&!c?.disabled&&a(kn,{onClick:f=>Ye(f,l),children:a(Ne,{})})]},l)}),n>0&&a(bn,{$size:$,children:typeof K=="function"?K(s.slice(T)):K||`+${n}`})]})},tn=()=>{const e=a(Ln,{$showLine:!!ne,className:d.tree,style:u.tree,role:"tree",onScroll:Ke,children:xe.length===0?a(In,{children:"No data"}):xe.map(n=>ye(n))});return se?se(e):e},M=s.length>0;return x(cn,{ref:e=>{_.current=e,typeof A=="function"?A(e):A&&(A.current=e)},$size:$,$variant:le,$status:re,$disabled:m,$focused:qe,"data-disabled":m,className:Re||d.root,style:{...u.root,...We},onKeyDown:an,tabIndex:m?-1:je,role:"combobox","aria-expanded":b,"aria-haspopup":"tree","aria-disabled":m,"aria-label":pe["aria-label"],"aria-labelledby":pe["aria-labelledby"],children:[x(dn,{$size:$,$variant:le,$status:re,$multiple:h,$hasValue:M,className:d.selector,style:u.selector,onClick:Je,onFocus:en,onBlur:nn,children:[te&&a(un,{$size:$,className:d.prefix,style:u.prefix,children:te}),ln(),W?a(hn,{ref:D,$size:$,value:w,onChange:Qe,placeholder:M&&!h?"":Y,disabled:m,className:d.search,style:u.search,"aria-label":"Search"}):!h||!M?M&&!h?a(pn,{children:Ce[0]}):a(fn,{className:d.placeholder,style:u.placeholder,children:Y}):null,x(xn,{$size:$,$open:b,className:d.suffix,style:u.suffix,children:[Be&&M&&!m&&a(yn,{onClick:Ze,"aria-label":"Clear",children:De||a(Ne,{})}),a(Cn,{$open:b,children:ze||a(zn,{})})]})]}),b&&a($n,{$placement:Ae,$maxHeight:Pe,$matchWidth:Oe,className:d.popup,style:u.popup,role:"listbox",children:tn()})]})});TreeSelect.displayName="TreeSelect";export default TreeSelect;
|