@rc-component/cascader 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/LICENSE.md +9 -0
  2. package/README.md +300 -0
  3. package/assets/index.less +3 -0
  4. package/assets/list.less +106 -0
  5. package/assets/panel.less +7 -0
  6. package/assets/select.less +3 -0
  7. package/es/Cascader.d.ts +88 -0
  8. package/es/Cascader.js +230 -0
  9. package/es/OptionList/CacheContent.d.ts +7 -0
  10. package/es/OptionList/CacheContent.js +8 -0
  11. package/es/OptionList/Checkbox.d.ts +10 -0
  12. package/es/OptionList/Checkbox.js +24 -0
  13. package/es/OptionList/Column.d.ts +21 -0
  14. package/es/OptionList/Column.js +175 -0
  15. package/es/OptionList/List.d.ts +6 -0
  16. package/es/OptionList/List.js +216 -0
  17. package/es/OptionList/index.d.ts +4 -0
  18. package/es/OptionList/index.js +13 -0
  19. package/es/OptionList/useActive.d.ts +6 -0
  20. package/es/OptionList/useActive.js +26 -0
  21. package/es/OptionList/useKeyboard.d.ts +10 -0
  22. package/es/OptionList/useKeyboard.js +165 -0
  23. package/es/Panel.d.ts +5 -0
  24. package/es/Panel.js +116 -0
  25. package/es/context.d.ts +21 -0
  26. package/es/context.js +3 -0
  27. package/es/hooks/useDisplayValues.d.ts +10 -0
  28. package/es/hooks/useDisplayValues.js +44 -0
  29. package/es/hooks/useEntities.d.ts +10 -0
  30. package/es/hooks/useEntities.js +35 -0
  31. package/es/hooks/useMissingValues.d.ts +3 -0
  32. package/es/hooks/useMissingValues.js +17 -0
  33. package/es/hooks/useOptions.d.ts +9 -0
  34. package/es/hooks/useOptions.js +20 -0
  35. package/es/hooks/useSearchConfig.d.ts +2 -0
  36. package/es/hooks/useSearchConfig.js +27 -0
  37. package/es/hooks/useSearchOptions.d.ts +4 -0
  38. package/es/hooks/useSearchOptions.js +63 -0
  39. package/es/hooks/useSelect.d.ts +4 -0
  40. package/es/hooks/useSelect.js +49 -0
  41. package/es/hooks/useValues.d.ts +9 -0
  42. package/es/hooks/useValues.js +21 -0
  43. package/es/index.d.ts +5 -0
  44. package/es/index.js +4 -0
  45. package/es/utils/commonUtil.d.ts +18 -0
  46. package/es/utils/commonUtil.js +69 -0
  47. package/es/utils/treeUtil.d.ts +9 -0
  48. package/es/utils/treeUtil.js +35 -0
  49. package/es/utils/warningPropsUtil.d.ts +4 -0
  50. package/es/utils/warningPropsUtil.js +29 -0
  51. package/lib/Cascader.d.ts +88 -0
  52. package/lib/Cascader.js +239 -0
  53. package/lib/OptionList/CacheContent.d.ts +7 -0
  54. package/lib/OptionList/CacheContent.js +16 -0
  55. package/lib/OptionList/Checkbox.d.ts +10 -0
  56. package/lib/OptionList/Checkbox.js +33 -0
  57. package/lib/OptionList/Column.d.ts +21 -0
  58. package/lib/OptionList/Column.js +185 -0
  59. package/lib/OptionList/List.d.ts +6 -0
  60. package/lib/OptionList/List.js +224 -0
  61. package/lib/OptionList/index.d.ts +4 -0
  62. package/lib/OptionList/index.js +22 -0
  63. package/lib/OptionList/useActive.d.ts +6 -0
  64. package/lib/OptionList/useActive.js +34 -0
  65. package/lib/OptionList/useKeyboard.d.ts +10 -0
  66. package/lib/OptionList/useKeyboard.js +175 -0
  67. package/lib/Panel.d.ts +5 -0
  68. package/lib/Panel.js +125 -0
  69. package/lib/context.d.ts +21 -0
  70. package/lib/context.js +11 -0
  71. package/lib/hooks/useDisplayValues.d.ts +10 -0
  72. package/lib/hooks/useDisplayValues.js +53 -0
  73. package/lib/hooks/useEntities.d.ts +10 -0
  74. package/lib/hooks/useEntities.js +44 -0
  75. package/lib/hooks/useMissingValues.d.ts +3 -0
  76. package/lib/hooks/useMissingValues.js +25 -0
  77. package/lib/hooks/useOptions.d.ts +9 -0
  78. package/lib/hooks/useOptions.js +29 -0
  79. package/lib/hooks/useSearchConfig.d.ts +2 -0
  80. package/lib/hooks/useSearchConfig.js +36 -0
  81. package/lib/hooks/useSearchOptions.d.ts +4 -0
  82. package/lib/hooks/useSearchOptions.js +71 -0
  83. package/lib/hooks/useSelect.d.ts +4 -0
  84. package/lib/hooks/useSelect.js +55 -0
  85. package/lib/hooks/useValues.d.ts +9 -0
  86. package/lib/hooks/useValues.js +29 -0
  87. package/lib/index.d.ts +5 -0
  88. package/lib/index.js +16 -0
  89. package/lib/utils/commonUtil.d.ts +18 -0
  90. package/lib/utils/commonUtil.js +83 -0
  91. package/lib/utils/treeUtil.d.ts +9 -0
  92. package/lib/utils/treeUtil.js +42 -0
  93. package/lib/utils/warningPropsUtil.d.ts +4 -0
  94. package/lib/utils/warningPropsUtil.js +37 -0
  95. package/package.json +88 -0
@@ -0,0 +1,239 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _select = require("@rc-component/select");
8
+ var _useId = _interopRequireDefault(require("@rc-component/select/lib/hooks/useId"));
9
+ var _useEvent = _interopRequireDefault(require("@rc-component/util/lib/hooks/useEvent"));
10
+ var _useMergedState = _interopRequireDefault(require("@rc-component/util/lib/hooks/useMergedState"));
11
+ var React = _interopRequireWildcard(require("react"));
12
+ var _context = _interopRequireDefault(require("./context"));
13
+ var _useDisplayValues = _interopRequireDefault(require("./hooks/useDisplayValues"));
14
+ var _useMissingValues = _interopRequireDefault(require("./hooks/useMissingValues"));
15
+ var _useOptions = _interopRequireDefault(require("./hooks/useOptions"));
16
+ var _useSearchConfig = _interopRequireDefault(require("./hooks/useSearchConfig"));
17
+ var _useSearchOptions = _interopRequireDefault(require("./hooks/useSearchOptions"));
18
+ var _useSelect = _interopRequireDefault(require("./hooks/useSelect"));
19
+ var _useValues = _interopRequireDefault(require("./hooks/useValues"));
20
+ var _OptionList = _interopRequireDefault(require("./OptionList"));
21
+ var _Panel = _interopRequireDefault(require("./Panel"));
22
+ var _commonUtil = require("./utils/commonUtil");
23
+ var _treeUtil = require("./utils/treeUtil");
24
+ var _warningPropsUtil = _interopRequireWildcard(require("./utils/warningPropsUtil"));
25
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
26
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
27
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
28
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
29
+ const Cascader = /*#__PURE__*/React.forwardRef((props, ref) => {
30
+ const {
31
+ // MISC
32
+ id,
33
+ prefixCls = 'rc-cascader',
34
+ fieldNames,
35
+ // Value
36
+ defaultValue,
37
+ value,
38
+ changeOnSelect,
39
+ onChange,
40
+ displayRender,
41
+ checkable,
42
+ // Search
43
+ autoClearSearchValue = true,
44
+ searchValue,
45
+ onSearch,
46
+ showSearch,
47
+ // Trigger
48
+ expandTrigger,
49
+ // Options
50
+ options,
51
+ dropdownPrefixCls,
52
+ loadData,
53
+ // Open
54
+ popupVisible,
55
+ open,
56
+ popupClassName,
57
+ dropdownMenuColumnStyle,
58
+ popupStyle: customPopupStyle,
59
+ popupPlacement,
60
+ placement,
61
+ onPopupVisibleChange,
62
+ // Icon
63
+ expandIcon = '>',
64
+ loadingIcon,
65
+ // Children
66
+ children,
67
+ popupMatchSelectWidth = false,
68
+ showCheckedStrategy = _commonUtil.SHOW_PARENT,
69
+ optionRender,
70
+ ...restProps
71
+ } = props;
72
+ const mergedId = (0, _useId.default)(id);
73
+ const multiple = !!checkable;
74
+
75
+ // =========================== Values ===========================
76
+ const [rawValues, setRawValues] = (0, _useMergedState.default)(defaultValue, {
77
+ value,
78
+ postState: _commonUtil.toRawValues
79
+ });
80
+
81
+ // ========================= FieldNames =========================
82
+ const mergedFieldNames = React.useMemo(() => (0, _commonUtil.fillFieldNames)(fieldNames), /* eslint-disable react-hooks/exhaustive-deps */
83
+ [JSON.stringify(fieldNames)]
84
+ /* eslint-enable react-hooks/exhaustive-deps */);
85
+
86
+ // =========================== Option ===========================
87
+ const [mergedOptions, getPathKeyEntities, getValueByKeyPath] = (0, _useOptions.default)(mergedFieldNames, options);
88
+
89
+ // =========================== Search ===========================
90
+ const [mergedSearchValue, setSearchValue] = (0, _useMergedState.default)('', {
91
+ value: searchValue,
92
+ postState: search => search || ''
93
+ });
94
+ const onInternalSearch = (searchText, info) => {
95
+ setSearchValue(searchText);
96
+ if (info.source !== 'blur' && onSearch) {
97
+ onSearch(searchText);
98
+ }
99
+ };
100
+ const [mergedShowSearch, searchConfig] = (0, _useSearchConfig.default)(showSearch);
101
+ const searchOptions = (0, _useSearchOptions.default)(mergedSearchValue, mergedOptions, mergedFieldNames, dropdownPrefixCls || prefixCls, searchConfig, changeOnSelect || multiple);
102
+
103
+ // =========================== Values ===========================
104
+ const getMissingValues = (0, _useMissingValues.default)(mergedOptions, mergedFieldNames);
105
+
106
+ // Fill `rawValues` with checked conduction values
107
+ const [checkedValues, halfCheckedValues, missingCheckedValues] = (0, _useValues.default)(multiple, rawValues, getPathKeyEntities, getValueByKeyPath, getMissingValues);
108
+ const deDuplicatedValues = React.useMemo(() => {
109
+ const checkedKeys = (0, _commonUtil.toPathKeys)(checkedValues);
110
+ const deduplicateKeys = (0, _treeUtil.formatStrategyValues)(checkedKeys, getPathKeyEntities, showCheckedStrategy);
111
+ return [...missingCheckedValues, ...getValueByKeyPath(deduplicateKeys)];
112
+ }, [checkedValues, getPathKeyEntities, getValueByKeyPath, missingCheckedValues, showCheckedStrategy]);
113
+ const displayValues = (0, _useDisplayValues.default)(deDuplicatedValues, mergedOptions, mergedFieldNames, multiple, displayRender);
114
+
115
+ // =========================== Change ===========================
116
+ const triggerChange = (0, _useEvent.default)(nextValues => {
117
+ setRawValues(nextValues);
118
+
119
+ // Save perf if no need trigger event
120
+ if (onChange) {
121
+ const nextRawValues = (0, _commonUtil.toRawValues)(nextValues);
122
+ const valueOptions = nextRawValues.map(valueCells => (0, _treeUtil.toPathOptions)(valueCells, mergedOptions, mergedFieldNames).map(valueOpt => valueOpt.option));
123
+ const triggerValues = multiple ? nextRawValues : nextRawValues[0];
124
+ const triggerOptions = multiple ? valueOptions : valueOptions[0];
125
+ onChange(triggerValues, triggerOptions);
126
+ }
127
+ });
128
+
129
+ // =========================== Select ===========================
130
+ const handleSelection = (0, _useSelect.default)(multiple, triggerChange, checkedValues, halfCheckedValues, missingCheckedValues, getPathKeyEntities, getValueByKeyPath, showCheckedStrategy);
131
+ const onInternalSelect = (0, _useEvent.default)(valuePath => {
132
+ if (!multiple || autoClearSearchValue) {
133
+ setSearchValue('');
134
+ }
135
+ handleSelection(valuePath);
136
+ });
137
+
138
+ // Display Value change logic
139
+ const onDisplayValuesChange = (_, info) => {
140
+ if (info.type === 'clear') {
141
+ triggerChange([]);
142
+ return;
143
+ }
144
+
145
+ // Cascader do not support `add` type. Only support `remove`
146
+ const {
147
+ valueCells
148
+ } = info.values[0];
149
+ onInternalSelect(valueCells);
150
+ };
151
+
152
+ // ============================ Open ============================
153
+ const mergedOpen = open !== undefined ? open : popupVisible;
154
+ const mergedPlacement = placement || popupPlacement;
155
+ const onInternalPopupVisibleChange = nextVisible => {
156
+ onPopupVisibleChange?.(nextVisible);
157
+ };
158
+
159
+ // ========================== Warning ===========================
160
+ if (process.env.NODE_ENV !== 'production') {
161
+ (0, _warningPropsUtil.default)(props);
162
+ (0, _warningPropsUtil.warningNullOptions)(mergedOptions, mergedFieldNames);
163
+ }
164
+
165
+ // ========================== Context ===========================
166
+ const cascaderContext = React.useMemo(() => ({
167
+ options: mergedOptions,
168
+ fieldNames: mergedFieldNames,
169
+ values: checkedValues,
170
+ halfValues: halfCheckedValues,
171
+ changeOnSelect,
172
+ onSelect: onInternalSelect,
173
+ checkable,
174
+ searchOptions,
175
+ dropdownPrefixCls,
176
+ loadData,
177
+ expandTrigger,
178
+ expandIcon,
179
+ loadingIcon,
180
+ dropdownMenuColumnStyle,
181
+ optionRender
182
+ }), [mergedOptions, mergedFieldNames, checkedValues, halfCheckedValues, changeOnSelect, onInternalSelect, checkable, searchOptions, dropdownPrefixCls, loadData, expandTrigger, expandIcon, loadingIcon, dropdownMenuColumnStyle, optionRender]);
183
+
184
+ // ==============================================================
185
+ // == Render ==
186
+ // ==============================================================
187
+ const emptyOptions = !(mergedSearchValue ? searchOptions : mergedOptions).length;
188
+ const popupStyle =
189
+ // Search to match width
190
+ mergedSearchValue && searchConfig.matchInputWidth ||
191
+ // Empty keep the width
192
+ emptyOptions ? {} : {
193
+ minWidth: 'auto'
194
+ };
195
+ return /*#__PURE__*/React.createElement(_context.default.Provider, {
196
+ value: cascaderContext
197
+ }, /*#__PURE__*/React.createElement(_select.BaseSelect, _extends({}, restProps, {
198
+ // MISC
199
+ ref: ref,
200
+ id: mergedId,
201
+ prefixCls: prefixCls,
202
+ autoClearSearchValue: autoClearSearchValue,
203
+ popupMatchSelectWidth: popupMatchSelectWidth,
204
+ popupStyle: {
205
+ ...popupStyle,
206
+ ...customPopupStyle
207
+ }
208
+ // Value
209
+ ,
210
+ displayValues: displayValues,
211
+ onDisplayValuesChange: onDisplayValuesChange,
212
+ mode: multiple ? 'multiple' : undefined
213
+ // Search
214
+ ,
215
+ searchValue: mergedSearchValue,
216
+ onSearch: onInternalSearch,
217
+ showSearch: mergedShowSearch
218
+ // Options
219
+ ,
220
+ OptionList: _OptionList.default,
221
+ emptyOptions: emptyOptions
222
+ // Open
223
+ ,
224
+ open: mergedOpen,
225
+ popupClassName: popupClassName,
226
+ placement: mergedPlacement,
227
+ onPopupVisibleChange: onInternalPopupVisibleChange
228
+ // Children
229
+ ,
230
+ getRawInputElement: () => children
231
+ })));
232
+ });
233
+ if (process.env.NODE_ENV !== 'production') {
234
+ Cascader.displayName = 'Cascader';
235
+ }
236
+ Cascader.SHOW_PARENT = _commonUtil.SHOW_PARENT;
237
+ Cascader.SHOW_CHILD = _commonUtil.SHOW_CHILD;
238
+ Cascader.Panel = _Panel.default;
239
+ var _default = exports.default = Cascader;
@@ -0,0 +1,7 @@
1
+ import * as React from 'react';
2
+ export interface CacheContentProps {
3
+ children?: React.ReactNode;
4
+ open?: boolean;
5
+ }
6
+ declare const CacheContent: React.MemoExoticComponent<({ children }: CacheContentProps) => React.ReactElement<any, string | React.JSXElementConstructor<any>>>;
7
+ export default CacheContent;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var React = _interopRequireWildcard(require("react"));
8
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
9
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
10
+ const CacheContent = /*#__PURE__*/React.memo(({
11
+ children
12
+ }) => children, (_, next) => !next.open);
13
+ if (process.env.NODE_ENV !== 'production') {
14
+ CacheContent.displayName = 'CacheContent';
15
+ }
16
+ var _default = exports.default = CacheContent;
@@ -0,0 +1,10 @@
1
+ import * as React from 'react';
2
+ export interface CheckboxProps {
3
+ prefixCls: string;
4
+ checked?: boolean;
5
+ halfChecked?: boolean;
6
+ disabled?: boolean;
7
+ onClick?: React.MouseEventHandler;
8
+ disableCheckbox?: boolean;
9
+ }
10
+ export default function Checkbox({ prefixCls, checked, halfChecked, disabled, onClick, disableCheckbox, }: CheckboxProps): React.JSX.Element;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = Checkbox;
7
+ var React = _interopRequireWildcard(require("react"));
8
+ var _classnames = _interopRequireDefault(require("classnames"));
9
+ var _context = _interopRequireDefault(require("../context"));
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
12
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
13
+ function Checkbox({
14
+ prefixCls,
15
+ checked,
16
+ halfChecked,
17
+ disabled,
18
+ onClick,
19
+ disableCheckbox
20
+ }) {
21
+ const {
22
+ checkable
23
+ } = React.useContext(_context.default);
24
+ const customCheckbox = typeof checkable !== 'boolean' ? checkable : null;
25
+ return /*#__PURE__*/React.createElement("span", {
26
+ className: (0, _classnames.default)(`${prefixCls}`, {
27
+ [`${prefixCls}-checked`]: checked,
28
+ [`${prefixCls}-indeterminate`]: !checked && halfChecked,
29
+ [`${prefixCls}-disabled`]: disabled || disableCheckbox
30
+ }),
31
+ onClick: onClick
32
+ }, customCheckbox);
33
+ }
@@ -0,0 +1,21 @@
1
+ import * as React from 'react';
2
+ import type { DefaultOptionType, SingleValueType } from '../Cascader';
3
+ export declare const FIX_LABEL = "__cascader_fix_label__";
4
+ export interface ColumnProps<OptionType extends DefaultOptionType = DefaultOptionType> {
5
+ prefixCls: string;
6
+ multiple?: boolean;
7
+ options: OptionType[];
8
+ /** Current Column opened item key */
9
+ activeValue?: React.Key;
10
+ /** The value path before current column */
11
+ prevValuePath: React.Key[];
12
+ onToggleOpen: (open: boolean) => void;
13
+ onSelect: (valuePath: SingleValueType, leaf: boolean) => void;
14
+ onActive: (valuePath: SingleValueType) => void;
15
+ checkedSet: Set<React.Key>;
16
+ halfCheckedSet: Set<React.Key>;
17
+ loadingKeys: React.Key[];
18
+ isSelectable: (option: DefaultOptionType) => boolean;
19
+ disabled?: boolean;
20
+ }
21
+ export default function Column<OptionType extends DefaultOptionType = DefaultOptionType>({ prefixCls, multiple, options, activeValue, prevValuePath, onToggleOpen, onSelect, onActive, checkedSet, halfCheckedSet, loadingKeys, isSelectable, disabled: propsDisabled, }: ColumnProps<OptionType>): React.JSX.Element;
@@ -0,0 +1,185 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.FIX_LABEL = void 0;
7
+ exports.default = Column;
8
+ var _classnames = _interopRequireDefault(require("classnames"));
9
+ var React = _interopRequireWildcard(require("react"));
10
+ var _context = _interopRequireDefault(require("../context"));
11
+ var _useSearchOptions = require("../hooks/useSearchOptions");
12
+ var _commonUtil = require("../utils/commonUtil");
13
+ var _Checkbox = _interopRequireDefault(require("./Checkbox"));
14
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
15
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
16
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
+ const FIX_LABEL = exports.FIX_LABEL = '__cascader_fix_label__';
18
+ function Column({
19
+ prefixCls,
20
+ multiple,
21
+ options,
22
+ activeValue,
23
+ prevValuePath,
24
+ onToggleOpen,
25
+ onSelect,
26
+ onActive,
27
+ checkedSet,
28
+ halfCheckedSet,
29
+ loadingKeys,
30
+ isSelectable,
31
+ disabled: propsDisabled
32
+ }) {
33
+ const menuPrefixCls = `${prefixCls}-menu`;
34
+ const menuItemPrefixCls = `${prefixCls}-menu-item`;
35
+ const {
36
+ fieldNames,
37
+ changeOnSelect,
38
+ expandTrigger,
39
+ expandIcon,
40
+ loadingIcon,
41
+ dropdownMenuColumnStyle,
42
+ optionRender
43
+ } = React.useContext(_context.default);
44
+ const hoverOpen = expandTrigger === 'hover';
45
+ const isOptionDisabled = disabled => propsDisabled || disabled;
46
+
47
+ // ============================ Option ============================
48
+ const optionInfoList = React.useMemo(() => options.map(option => {
49
+ const {
50
+ disabled,
51
+ disableCheckbox
52
+ } = option;
53
+ const searchOptions = option[_useSearchOptions.SEARCH_MARK];
54
+ const label = option[FIX_LABEL] ?? option[fieldNames.label];
55
+ const value = option[fieldNames.value];
56
+ const isMergedLeaf = (0, _commonUtil.isLeaf)(option, fieldNames);
57
+
58
+ // Get real value of option. Search option is different way.
59
+ const fullPath = searchOptions ? searchOptions.map(opt => opt[fieldNames.value]) : [...prevValuePath, value];
60
+ const fullPathKey = (0, _commonUtil.toPathKey)(fullPath);
61
+ const isLoading = loadingKeys.includes(fullPathKey);
62
+
63
+ // >>>>> checked
64
+ const checked = checkedSet.has(fullPathKey);
65
+
66
+ // >>>>> halfChecked
67
+ const halfChecked = halfCheckedSet.has(fullPathKey);
68
+ return {
69
+ disabled,
70
+ label,
71
+ value,
72
+ isLeaf: isMergedLeaf,
73
+ isLoading,
74
+ checked,
75
+ halfChecked,
76
+ option,
77
+ disableCheckbox,
78
+ fullPath,
79
+ fullPathKey
80
+ };
81
+ }), [options, checkedSet, fieldNames, halfCheckedSet, loadingKeys, prevValuePath]);
82
+
83
+ // ============================ Render ============================
84
+ return /*#__PURE__*/React.createElement("ul", {
85
+ className: menuPrefixCls,
86
+ role: "menu"
87
+ }, optionInfoList.map(({
88
+ disabled,
89
+ label,
90
+ value,
91
+ isLeaf: isMergedLeaf,
92
+ isLoading,
93
+ checked,
94
+ halfChecked,
95
+ option,
96
+ fullPath,
97
+ fullPathKey,
98
+ disableCheckbox
99
+ }) => {
100
+ // >>>>> Open
101
+ const triggerOpenPath = () => {
102
+ if (isOptionDisabled(disabled)) {
103
+ return;
104
+ }
105
+ const nextValueCells = [...fullPath];
106
+ if (hoverOpen && isMergedLeaf) {
107
+ nextValueCells.pop();
108
+ }
109
+ onActive(nextValueCells);
110
+ };
111
+
112
+ // >>>>> Selection
113
+ const triggerSelect = () => {
114
+ if (isSelectable(option) && !isOptionDisabled(disabled)) {
115
+ onSelect(fullPath, isMergedLeaf);
116
+ }
117
+ };
118
+
119
+ // >>>>> Title
120
+ let title;
121
+ if (typeof option.title === 'string') {
122
+ title = option.title;
123
+ } else if (typeof label === 'string') {
124
+ title = label;
125
+ }
126
+
127
+ // >>>>> Render
128
+ return /*#__PURE__*/React.createElement("li", {
129
+ key: fullPathKey,
130
+ className: (0, _classnames.default)(menuItemPrefixCls, {
131
+ [`${menuItemPrefixCls}-expand`]: !isMergedLeaf,
132
+ [`${menuItemPrefixCls}-active`]: activeValue === value || activeValue === fullPathKey,
133
+ [`${menuItemPrefixCls}-disabled`]: isOptionDisabled(disabled),
134
+ [`${menuItemPrefixCls}-loading`]: isLoading
135
+ }),
136
+ style: dropdownMenuColumnStyle,
137
+ role: "menuitemcheckbox",
138
+ title: title,
139
+ "aria-checked": checked,
140
+ "data-path-key": fullPathKey,
141
+ onClick: () => {
142
+ triggerOpenPath();
143
+ if (disableCheckbox) {
144
+ return;
145
+ }
146
+ if (!multiple || isMergedLeaf) {
147
+ triggerSelect();
148
+ }
149
+ },
150
+ onDoubleClick: () => {
151
+ if (changeOnSelect) {
152
+ onToggleOpen(false);
153
+ }
154
+ },
155
+ onMouseEnter: () => {
156
+ if (hoverOpen) {
157
+ triggerOpenPath();
158
+ }
159
+ },
160
+ onMouseDown: e => {
161
+ // Prevent selector from blurring
162
+ e.preventDefault();
163
+ }
164
+ }, multiple && /*#__PURE__*/React.createElement(_Checkbox.default, {
165
+ prefixCls: `${prefixCls}-checkbox`,
166
+ checked: checked,
167
+ halfChecked: halfChecked,
168
+ disabled: isOptionDisabled(disabled) || disableCheckbox,
169
+ disableCheckbox: disableCheckbox,
170
+ onClick: e => {
171
+ if (disableCheckbox) {
172
+ return;
173
+ }
174
+ e.stopPropagation();
175
+ triggerSelect();
176
+ }
177
+ }), /*#__PURE__*/React.createElement("div", {
178
+ className: `${menuItemPrefixCls}-content`
179
+ }, optionRender ? optionRender(option) : label), !isLoading && expandIcon && !isMergedLeaf && /*#__PURE__*/React.createElement("div", {
180
+ className: `${menuItemPrefixCls}-expand-icon`
181
+ }, expandIcon), isLoading && loadingIcon && /*#__PURE__*/React.createElement("div", {
182
+ className: `${menuItemPrefixCls}-loading-icon`
183
+ }, loadingIcon));
184
+ }));
185
+ }
@@ -0,0 +1,6 @@
1
+ import type { useBaseProps } from '@rc-component/select';
2
+ import type { RefOptionListProps } from '@rc-component/select/lib/OptionList';
3
+ import * as React from 'react';
4
+ export type RawOptionListProps = Pick<ReturnType<typeof useBaseProps>, 'prefixCls' | 'multiple' | 'searchValue' | 'toggleOpen' | 'notFoundContent' | 'direction' | 'open' | 'disabled'>;
5
+ declare const RawOptionList: React.ForwardRefExoticComponent<RawOptionListProps & React.RefAttributes<RefOptionListProps>>;
6
+ export default RawOptionList;