@chaoswise/ui 2.2.9 → 2.3.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 (50) hide show
  1. package/lib/AbreastLayout/index.js +5 -1
  2. package/lib/BasicLayout/Sider.js +8 -3
  3. package/lib/BasicLayout/index.js +10 -2
  4. package/lib/CWCascader/Cascader/index.js +207 -0
  5. package/lib/CWCascader/index.js +5 -0
  6. package/lib/CWCascader/index.less +9 -0
  7. package/lib/CWCascader/rc-cascader/Cascader.js +329 -0
  8. package/lib/CWCascader/rc-cascader/OptionList/Checkbox.js +22 -0
  9. package/lib/CWCascader/rc-cascader/OptionList/Column.js +209 -0
  10. package/lib/CWCascader/rc-cascader/OptionList/index.js +215 -0
  11. package/lib/CWCascader/rc-cascader/OptionList/useActive.js +33 -0
  12. package/lib/CWCascader/rc-cascader/OptionList/useKeyboard.js +177 -0
  13. package/lib/CWCascader/rc-cascader/context.js +3 -0
  14. package/lib/CWCascader/rc-cascader/hooks/useDisplayValues.js +56 -0
  15. package/lib/CWCascader/rc-cascader/hooks/useEntities.js +48 -0
  16. package/lib/CWCascader/rc-cascader/hooks/useMissingValues.js +19 -0
  17. package/lib/CWCascader/rc-cascader/hooks/useRefFunc.js +13 -0
  18. package/lib/CWCascader/rc-cascader/hooks/useSearchConfig.js +30 -0
  19. package/lib/CWCascader/rc-cascader/hooks/useSearchOptions.js +74 -0
  20. package/lib/CWCascader/rc-cascader/index.js +2 -0
  21. package/lib/CWCascader/rc-cascader/utils/commonUtil.js +54 -0
  22. package/lib/CWCascader/rc-cascader/utils/treeUtil.js +37 -0
  23. package/lib/CWCascader/rc-cascader/utils/warningPropsUtil.js +30 -0
  24. package/lib/CWRangePicker/index.js +6 -1
  25. package/lib/CWSelect/index.js +9 -1
  26. package/lib/CWSelect/index.less +10 -0
  27. package/lib/Cascader/index.js +0 -8
  28. package/lib/Cascader/index.less +5 -0
  29. package/lib/Cascaders/Cascader/index.js +208 -0
  30. package/lib/Cascaders/index.js +17 -0
  31. package/lib/Cascaders/index.less +1 -0
  32. package/lib/Cascaders/rc-cascader/Cascader.js +326 -0
  33. package/lib/Cascaders/rc-cascader/OptionList/Checkbox.js +22 -0
  34. package/lib/Cascaders/rc-cascader/OptionList/Column.js +203 -0
  35. package/lib/Cascaders/rc-cascader/OptionList/index.js +213 -0
  36. package/lib/Cascaders/rc-cascader/OptionList/useActive.js +33 -0
  37. package/lib/Cascaders/rc-cascader/OptionList/useKeyboard.js +171 -0
  38. package/lib/Cascaders/rc-cascader/context.js +3 -0
  39. package/lib/Cascaders/rc-cascader/hooks/useDisplayValues.js +56 -0
  40. package/lib/Cascaders/rc-cascader/hooks/useEntities.js +34 -0
  41. package/lib/Cascaders/rc-cascader/hooks/useMissingValues.js +19 -0
  42. package/lib/Cascaders/rc-cascader/hooks/useRefFunc.js +13 -0
  43. package/lib/Cascaders/rc-cascader/hooks/useSearchConfig.js +25 -0
  44. package/lib/Cascaders/rc-cascader/hooks/useSearchOptions.js +72 -0
  45. package/lib/Cascaders/rc-cascader/index.js +2 -0
  46. package/lib/Cascaders/rc-cascader/utils/commonUtil.js +54 -0
  47. package/lib/Cascaders/rc-cascader/utils/treeUtil.js +37 -0
  48. package/lib/Cascaders/rc-cascader/utils/warningPropsUtil.js +30 -0
  49. package/lib/CitySelect/index.js +2 -2
  50. package/package.json +3 -3
@@ -0,0 +1,203 @@
1
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
+ import "@chaoswise/ui/lib/Input/index.less";
3
+ import _Input from "@chaoswise/ui/lib/Input";
4
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
6
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
7
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
8
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
9
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
10
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
11
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
12
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
13
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
14
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
15
+ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
16
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
17
+ // @ts-nocheck
18
+ import * as React from "react";
19
+ import classNames from "classnames";
20
+ import { isLeaf, toPathKey } from "../utils/commonUtil";
21
+ import CascaderContext from "../context";
22
+ import Checkbox from "./Checkbox";
23
+ import { SEARCH_MARK } from "../hooks/useSearchOptions";
24
+ export var FIX_LABEL = "__cascader_fix_label__";
25
+ export default function Column(_ref) {
26
+ var prefixCls = _ref.prefixCls,
27
+ multiple = _ref.multiple,
28
+ options = _ref.options,
29
+ activeValue = _ref.activeValue,
30
+ prevValuePath = _ref.prevValuePath,
31
+ onToggleOpen = _ref.onToggleOpen,
32
+ onSelect = _ref.onSelect,
33
+ onActive = _ref.onActive,
34
+ checkedSet = _ref.checkedSet,
35
+ halfCheckedSet = _ref.halfCheckedSet,
36
+ loadingKeys = _ref.loadingKeys,
37
+ isSelectable = _ref.isSelectable;
38
+ var menuPrefixCls = "".concat(prefixCls, "-menu");
39
+ var menuItemPrefixCls = "".concat(prefixCls, "-menu-item");
40
+ var _React$useContext = React.useContext(CascaderContext),
41
+ fieldNames = _React$useContext.fieldNames,
42
+ changeOnSelect = _React$useContext.changeOnSelect,
43
+ expandTrigger = _React$useContext.expandTrigger,
44
+ expandIcon = _React$useContext.expandIcon,
45
+ loadingIcon = _React$useContext.loadingIcon,
46
+ dropdownMenuColumnStyle = _React$useContext.dropdownMenuColumnStyle,
47
+ _React$useContext$onS = _React$useContext.onScroll,
48
+ _onScroll = _React$useContext$onS === void 0 ? function () {} : _React$useContext$onS,
49
+ _React$useContext$onS2 = _React$useContext.onSrollBottom,
50
+ onSrollBottom = _React$useContext$onS2 === void 0 ? function () {} : _React$useContext$onS2,
51
+ _React$useContext$onI = _React$useContext.onInputChange,
52
+ onInputChange = _React$useContext$onI === void 0 ? function () {} : _React$useContext$onI;
53
+ var hoverOpen = expandTrigger === "hover";
54
+ var _React$useState = React.useState(""),
55
+ _React$useState2 = _slicedToArray(_React$useState, 2),
56
+ inputValue = _React$useState2[0],
57
+ setInputValue = _React$useState2[1];
58
+ // ============================ Option ============================
59
+ var optionInfoList = React.useMemo(function () {
60
+ return options.map(function (option) {
61
+ var _a;
62
+ var disabled = option.disabled;
63
+ var searchOptions = option[SEARCH_MARK];
64
+ var label = (_a = option[FIX_LABEL]) !== null && _a !== void 0 ? _a : option[fieldNames.label];
65
+ var value = option[fieldNames.value];
66
+ var isMergedLeaf = isLeaf(option, fieldNames);
67
+ // Get real value of option. Search option is different way.
68
+ var fullPath = searchOptions ? searchOptions.map(function (opt) {
69
+ return opt[fieldNames.value];
70
+ }) : [].concat(_toConsumableArray(prevValuePath), [value]);
71
+ var fullPathKey = toPathKey(fullPath);
72
+ var isLoading = loadingKeys.includes(fullPathKey);
73
+ // >>>>> checked
74
+ var checked = checkedSet.has(fullPathKey);
75
+ // >>>>> halfChecked
76
+ var halfChecked = halfCheckedSet.has(fullPathKey);
77
+ return {
78
+ disabled: disabled,
79
+ label: label,
80
+ value: value,
81
+ isLeaf: isMergedLeaf,
82
+ isLoading: isLoading,
83
+ checked: checked,
84
+ halfChecked: halfChecked,
85
+ option: option,
86
+ fullPath: fullPath,
87
+ fullPathKey: fullPathKey
88
+ };
89
+ });
90
+ }, [options, checkedSet, fieldNames, halfCheckedSet, loadingKeys, prevValuePath]);
91
+ var scrollColumnId = prevValuePath.length ? prevValuePath[prevValuePath.length - 1] : undefined;
92
+ var onChange = function onChange(e) {
93
+ setInputValue(e.target.value);
94
+ onInputChange(e, scrollColumnId);
95
+ };
96
+ // ============================ Render ============================
97
+ return /*#__PURE__*/React.createElement("div", {
98
+ style: {
99
+ display: "flex",
100
+ flexDirection: "column",
101
+ flex: 1
102
+ }
103
+ }, /*#__PURE__*/React.createElement(_Input, {
104
+ style: {
105
+ width: "100%"
106
+ },
107
+ value: inputValue,
108
+ onChange: onChange
109
+ }), /*#__PURE__*/React.createElement("ul", {
110
+ className: menuPrefixCls,
111
+ role: "menu",
112
+ style: {
113
+ flex: 1
114
+ },
115
+ onScroll: function onScroll(e) {
116
+ // scrollColumnId,一级为undefind,非一级为上一次的value
117
+ _onScroll(e, scrollColumnId);
118
+ function isScrollBottom() {
119
+ var element = e.target;
120
+ return element.scrollHeight - element.scrollTop <= element.clientHeight;
121
+ }
122
+ if (isScrollBottom()) {
123
+ onSrollBottom(e, scrollColumnId);
124
+ }
125
+ }
126
+ }, optionInfoList.map(function (_ref2) {
127
+ var _classNames;
128
+ var disabled = _ref2.disabled,
129
+ label = _ref2.label,
130
+ value = _ref2.value,
131
+ isMergedLeaf = _ref2.isLeaf,
132
+ isLoading = _ref2.isLoading,
133
+ checked = _ref2.checked,
134
+ halfChecked = _ref2.halfChecked,
135
+ option = _ref2.option,
136
+ fullPath = _ref2.fullPath,
137
+ fullPathKey = _ref2.fullPathKey;
138
+ // >>>>> Open
139
+ var triggerOpenPath = function triggerOpenPath() {
140
+ if (!disabled && (!hoverOpen || !isMergedLeaf)) {
141
+ onActive(fullPath);
142
+ }
143
+ };
144
+ // >>>>> Selection
145
+ var triggerSelect = function triggerSelect() {
146
+ if (isSelectable(option)) {
147
+ onSelect(fullPath, isMergedLeaf);
148
+ }
149
+ };
150
+ // >>>>> Title
151
+ var title;
152
+ if (typeof option.title === "string") {
153
+ title = option.title;
154
+ } else if (typeof label === "string") {
155
+ title = label;
156
+ }
157
+ // >>>>> Render
158
+ return /*#__PURE__*/React.createElement("li", {
159
+ key: fullPathKey,
160
+ className: classNames(menuItemPrefixCls, (_classNames = {}, _defineProperty(_classNames, "".concat(menuItemPrefixCls, "-expand"), !isMergedLeaf), _defineProperty(_classNames, "".concat(menuItemPrefixCls, "-active"), activeValue === value), _defineProperty(_classNames, "".concat(menuItemPrefixCls, "-disabled"), disabled), _defineProperty(_classNames, "".concat(menuItemPrefixCls, "-loading"), isLoading), _classNames)),
161
+ style: dropdownMenuColumnStyle,
162
+ role: "menuitemcheckbox",
163
+ title: title,
164
+ "aria-checked": checked,
165
+ "data-path-key": fullPathKey,
166
+ onClick: function onClick() {
167
+ triggerOpenPath();
168
+ if (!multiple || isMergedLeaf) {
169
+ triggerSelect();
170
+ }
171
+ },
172
+ onDoubleClick: function onDoubleClick() {
173
+ if (changeOnSelect) {
174
+ onToggleOpen(false);
175
+ }
176
+ },
177
+ onMouseEnter: function onMouseEnter() {
178
+ if (hoverOpen) {
179
+ triggerOpenPath();
180
+ }
181
+ },
182
+ onMouseDown: function onMouseDown(e) {
183
+ // Prevent selector from blurring
184
+ // e.preventDefault();
185
+ }
186
+ }, multiple && /*#__PURE__*/React.createElement(Checkbox, {
187
+ prefixCls: "".concat(prefixCls, "-checkbox"),
188
+ checked: checked,
189
+ halfChecked: halfChecked,
190
+ disabled: disabled,
191
+ onClick: function onClick(e) {
192
+ e.stopPropagation();
193
+ triggerSelect();
194
+ }
195
+ }), /*#__PURE__*/React.createElement("div", {
196
+ className: "".concat(menuItemPrefixCls, "-content")
197
+ }, label), !isLoading && expandIcon && !isMergedLeaf && /*#__PURE__*/React.createElement("div", {
198
+ className: "".concat(menuItemPrefixCls, "-expand-icon")
199
+ }, expandIcon), isLoading && loadingIcon && /*#__PURE__*/React.createElement("div", {
200
+ className: "".concat(menuItemPrefixCls, "-loading-icon")
201
+ }, loadingIcon));
202
+ })));
203
+ }
@@ -0,0 +1,213 @@
1
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
3
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
4
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
5
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
6
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
7
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
8
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
9
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
10
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
11
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
12
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
13
+ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
14
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
15
+ // @ts-nocheck
16
+ /* eslint-disable default-case */
17
+ import classNames from 'classnames';
18
+ import { useBaseProps } from 'rc-cascader/node_modules/rc-select';
19
+ import * as React from 'react';
20
+ import CascaderContext from '../context';
21
+ import { getFullPathKeys, isLeaf, scrollIntoParentView, toPathKey, toPathKeys, toPathValueStr } from '../utils/commonUtil';
22
+ import { toPathOptions } from '../utils/treeUtil';
23
+ import Column, { FIX_LABEL } from './Column';
24
+ import useActive from './useActive';
25
+ import useKeyboard from './useKeyboard';
26
+ var RefOptionList = /*#__PURE__*/React.forwardRef(function (props, ref) {
27
+ var _ref3, _classNames;
28
+ var _a, _b;
29
+ var _useBaseProps = useBaseProps(),
30
+ prefixCls = _useBaseProps.prefixCls,
31
+ multiple = _useBaseProps.multiple,
32
+ searchValue = _useBaseProps.searchValue,
33
+ toggleOpen = _useBaseProps.toggleOpen,
34
+ notFoundContent = _useBaseProps.notFoundContent,
35
+ direction = _useBaseProps.direction;
36
+ var containerRef = React.useRef();
37
+ var rtl = direction === 'rtl';
38
+ var _React$useContext = React.useContext(CascaderContext),
39
+ options = _React$useContext.options,
40
+ values = _React$useContext.values,
41
+ halfValues = _React$useContext.halfValues,
42
+ fieldNames = _React$useContext.fieldNames,
43
+ changeOnSelect = _React$useContext.changeOnSelect,
44
+ onSelect = _React$useContext.onSelect,
45
+ searchOptions = _React$useContext.searchOptions,
46
+ dropdownPrefixCls = _React$useContext.dropdownPrefixCls,
47
+ loadData = _React$useContext.loadData,
48
+ expandTrigger = _React$useContext.expandTrigger;
49
+ var mergedPrefixCls = dropdownPrefixCls || prefixCls;
50
+ // ========================= loadData =========================
51
+ var _React$useState = React.useState([]),
52
+ _React$useState2 = _slicedToArray(_React$useState, 2),
53
+ loadingKeys = _React$useState2[0],
54
+ setLoadingKeys = _React$useState2[1];
55
+ var internalLoadData = function internalLoadData(valueCells) {
56
+ // Do not load when search
57
+ if (!loadData || searchValue) {
58
+ return;
59
+ }
60
+ var optionList = toPathOptions(valueCells, options, fieldNames);
61
+ var rawOptions = optionList.map(function (_ref) {
62
+ var option = _ref.option;
63
+ return option;
64
+ });
65
+ var lastOption = rawOptions[rawOptions.length - 1];
66
+ if (lastOption && !isLeaf(lastOption, fieldNames)) {
67
+ var pathKey = toPathKey(valueCells);
68
+ setLoadingKeys(function (keys) {
69
+ return [].concat(_toConsumableArray(keys), [pathKey]);
70
+ });
71
+ loadData(rawOptions);
72
+ }
73
+ };
74
+ // zombieJ: This is bad. We should make this same as `rc-tree` to use Promise instead.
75
+ React.useEffect(function () {
76
+ if (loadingKeys.length) {
77
+ loadingKeys.forEach(function (loadingKey) {
78
+ var valueStrCells = toPathValueStr(loadingKey);
79
+ var optionList = toPathOptions(valueStrCells, options, fieldNames, true).map(function (_ref2) {
80
+ var option = _ref2.option;
81
+ return option;
82
+ });
83
+ var lastOption = optionList[optionList.length - 1];
84
+ if (!lastOption || lastOption[fieldNames.children] || isLeaf(lastOption, fieldNames)) {
85
+ setLoadingKeys(function (keys) {
86
+ return keys.filter(function (key) {
87
+ return key !== loadingKey;
88
+ });
89
+ });
90
+ }
91
+ });
92
+ }
93
+ }, [options, loadingKeys, fieldNames]);
94
+ // ========================== Values ==========================
95
+ var checkedSet = React.useMemo(function () {
96
+ return new Set(toPathKeys(values));
97
+ }, [values]);
98
+ var halfCheckedSet = React.useMemo(function () {
99
+ return new Set(toPathKeys(halfValues));
100
+ }, [halfValues]);
101
+ // ====================== Accessibility =======================
102
+ var _useActive = useActive(),
103
+ _useActive2 = _slicedToArray(_useActive, 2),
104
+ activeValueCells = _useActive2[0],
105
+ setActiveValueCells = _useActive2[1];
106
+ // =========================== Path ===========================
107
+ var onPathOpen = function onPathOpen(nextValueCells) {
108
+ setActiveValueCells(nextValueCells);
109
+ // Trigger loadData
110
+ internalLoadData(nextValueCells);
111
+ };
112
+ var isSelectable = function isSelectable(option) {
113
+ var disabled = option.disabled;
114
+ var isMergedLeaf = isLeaf(option, fieldNames);
115
+ return !disabled && (isMergedLeaf || changeOnSelect || multiple);
116
+ };
117
+ var onPathSelect = function onPathSelect(valuePath, leaf) {
118
+ var fromKeyboard = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
119
+ onSelect(valuePath);
120
+ if (!multiple && (leaf || changeOnSelect && (expandTrigger === 'hover' || fromKeyboard))) {
121
+ toggleOpen(false);
122
+ }
123
+ };
124
+ // ========================== Option ==========================
125
+ var mergedOptions = React.useMemo(function () {
126
+ if (searchValue) {
127
+ return searchOptions;
128
+ }
129
+ return options;
130
+ }, [searchValue, searchOptions, options]);
131
+ // ========================== Column ==========================
132
+ var optionColumns = React.useMemo(function () {
133
+ var optionList = [{
134
+ options: mergedOptions
135
+ }];
136
+ var currentList = mergedOptions;
137
+ var fullPathKeys = getFullPathKeys(currentList, fieldNames);
138
+ var _loop = function _loop() {
139
+ var activeValueCell = activeValueCells[i];
140
+ var currentOption = currentList.find(function (option, index) {
141
+ return (fullPathKeys[index] ? toPathKey(fullPathKeys[index]) : option[fieldNames.value]) === activeValueCell;
142
+ });
143
+ var subOptions = currentOption === null || currentOption === void 0 ? void 0 : currentOption[fieldNames.children];
144
+ if (!(subOptions === null || subOptions === void 0 ? void 0 : subOptions.length)) {
145
+ return "break";
146
+ }
147
+ currentList = subOptions;
148
+ optionList.push({
149
+ options: subOptions
150
+ });
151
+ };
152
+ for (var i = 0; i < activeValueCells.length; i += 1) {
153
+ var _ret = _loop();
154
+ if (_ret === "break") break;
155
+ }
156
+ return optionList;
157
+ }, [mergedOptions, activeValueCells, fieldNames]);
158
+ // ========================= Keyboard =========================
159
+ var onKeyboardSelect = function onKeyboardSelect(selectValueCells, option) {
160
+ if (isSelectable(option)) {
161
+ onPathSelect(selectValueCells, isLeaf(option, fieldNames), true);
162
+ }
163
+ };
164
+ useKeyboard(ref, mergedOptions, fieldNames, activeValueCells, onPathOpen, onKeyboardSelect);
165
+ // >>>>> Active Scroll
166
+ React.useEffect(function () {
167
+ var _a;
168
+ for (var i = 0; i < activeValueCells.length; i += 1) {
169
+ var cellPath = activeValueCells.slice(0, i + 1);
170
+ var cellKeyPath = toPathKey(cellPath);
171
+ var ele = (_a = containerRef.current) === null || _a === void 0 ? void 0 : _a.querySelector("li[data-path-key=\"".concat(cellKeyPath.replace(/\\{0,2}"/g, '\\"'), "\"]"));
172
+ if (ele) {
173
+ scrollIntoParentView(ele);
174
+ }
175
+ }
176
+ }, [activeValueCells]);
177
+ // ========================== Render ==========================
178
+ // >>>>> Empty
179
+ var isEmpty = !((_b = (_a = optionColumns[0]) === null || _a === void 0 ? void 0 : _a.options) === null || _b === void 0 ? void 0 : _b.length);
180
+ var emptyList = [(_ref3 = {}, _defineProperty(_ref3, fieldNames.value, '__EMPTY__'), _defineProperty(_ref3, FIX_LABEL, notFoundContent), _defineProperty(_ref3, "disabled", true), _ref3)];
181
+ var columnProps = Object.assign(Object.assign({}, props), {
182
+ multiple: !isEmpty && multiple,
183
+ onSelect: onPathSelect,
184
+ onActive: onPathOpen,
185
+ onToggleOpen: toggleOpen,
186
+ checkedSet: checkedSet,
187
+ halfCheckedSet: halfCheckedSet,
188
+ loadingKeys: loadingKeys,
189
+ isSelectable: isSelectable
190
+ });
191
+ // >>>>> Columns
192
+ var mergedOptionColumns = isEmpty ? [{
193
+ options: emptyList
194
+ }] : optionColumns;
195
+ var columnNodes = mergedOptionColumns.map(function (col, index) {
196
+ var prevValuePath = activeValueCells.slice(0, index);
197
+ var activeValue = activeValueCells[index];
198
+ return /*#__PURE__*/React.createElement(Column, Object.assign({
199
+ key: index
200
+ }, columnProps, {
201
+ prefixCls: mergedPrefixCls,
202
+ options: col.options,
203
+ prevValuePath: prevValuePath,
204
+ activeValue: activeValue
205
+ }));
206
+ });
207
+ // >>>>> Render
208
+ return /*#__PURE__*/React.createElement("div", {
209
+ className: classNames("".concat(mergedPrefixCls, "-menus"), (_classNames = {}, _defineProperty(_classNames, "".concat(mergedPrefixCls, "-menu-empty"), isEmpty), _defineProperty(_classNames, "".concat(mergedPrefixCls, "-rtl"), rtl), _classNames)),
210
+ ref: containerRef
211
+ }, columnNodes);
212
+ });
213
+ export default RefOptionList;
@@ -0,0 +1,33 @@
1
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
5
+ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
6
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
+ import * as React from 'react';
8
+ import CascaderContext from '../context';
9
+ import { useBaseProps } from 'rc-cascader/node_modules/rc-select';
10
+ /**
11
+ * Control the active open options path.
12
+ */
13
+ export default (function () {
14
+ var _useBaseProps = useBaseProps(),
15
+ multiple = _useBaseProps.multiple,
16
+ open = _useBaseProps.open;
17
+ var _React$useContext = React.useContext(CascaderContext),
18
+ values = _React$useContext.values;
19
+ // Record current dropdown active options
20
+ // This also control the open status
21
+ var _React$useState = React.useState([]),
22
+ _React$useState2 = _slicedToArray(_React$useState, 2),
23
+ activeValueCells = _React$useState2[0],
24
+ setActiveValueCells = _React$useState2[1];
25
+ React.useEffect(function () {
26
+ if (open && !multiple) {
27
+ var firstValueCells = values[0];
28
+ setActiveValueCells(firstValueCells || []);
29
+ }
30
+ }, /* eslint-disable react-hooks/exhaustive-deps */
31
+ [open]);
32
+ return [activeValueCells, setActiveValueCells];
33
+ });
@@ -0,0 +1,171 @@
1
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
2
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
4
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
5
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
6
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
7
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
8
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
9
+ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
10
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
11
+ import { useBaseProps } from 'rc-cascader/node_modules/rc-select';
12
+ import * as React from 'react';
13
+ import { getFullPathKeys, toPathKey } from '../utils/commonUtil';
14
+ export default (function (ref, options, fieldNames, activeValueCells, setActiveValueCells, onKeyBoardSelect) {
15
+ var _useBaseProps = useBaseProps(),
16
+ direction = _useBaseProps.direction,
17
+ searchValue = _useBaseProps.searchValue,
18
+ toggleOpen = _useBaseProps.toggleOpen,
19
+ open = _useBaseProps.open;
20
+ var rtl = direction === 'rtl';
21
+ var _React$useMemo = React.useMemo(function () {
22
+ var activeIndex = -1;
23
+ var currentOptions = options;
24
+ var mergedActiveIndexes = [];
25
+ var mergedActiveValueCells = [];
26
+ var len = activeValueCells.length;
27
+ var pathKeys = getFullPathKeys(options, fieldNames);
28
+ // Fill validate active value cells and index
29
+ var _loop = function _loop(i) {
30
+ // Mark the active index for current options
31
+ var nextActiveIndex = currentOptions.findIndex(function (option, index) {
32
+ return (pathKeys[index] ? toPathKey(pathKeys[index]) : option[fieldNames.value]) === activeValueCells[i];
33
+ });
34
+ if (nextActiveIndex === -1) {
35
+ return "break";
36
+ }
37
+ activeIndex = nextActiveIndex;
38
+ mergedActiveIndexes.push(activeIndex);
39
+ mergedActiveValueCells.push(activeValueCells[i]);
40
+ currentOptions = currentOptions[activeIndex][fieldNames.children];
41
+ };
42
+ for (var i = 0; i < len && currentOptions; i += 1) {
43
+ var _ret = _loop(i);
44
+ if (_ret === "break") break;
45
+ }
46
+ // Fill last active options
47
+ var activeOptions = options;
48
+ for (var _i2 = 0; _i2 < mergedActiveIndexes.length - 1; _i2 += 1) {
49
+ activeOptions = activeOptions[mergedActiveIndexes[_i2]][fieldNames.children];
50
+ }
51
+ return [mergedActiveValueCells, activeIndex, activeOptions, pathKeys];
52
+ }, [activeValueCells, fieldNames, options]),
53
+ _React$useMemo2 = _slicedToArray(_React$useMemo, 4),
54
+ validActiveValueCells = _React$useMemo2[0],
55
+ lastActiveIndex = _React$useMemo2[1],
56
+ lastActiveOptions = _React$useMemo2[2],
57
+ fullPathKeys = _React$useMemo2[3];
58
+ // Update active value cells and scroll to target element
59
+ var internalSetActiveValueCells = function internalSetActiveValueCells(next) {
60
+ setActiveValueCells(next);
61
+ };
62
+ // Same options offset
63
+ var offsetActiveOption = function offsetActiveOption(offset) {
64
+ var len = lastActiveOptions.length;
65
+ var currentIndex = lastActiveIndex;
66
+ if (currentIndex === -1 && offset < 0) {
67
+ currentIndex = len;
68
+ }
69
+ for (var i = 0; i < len; i += 1) {
70
+ currentIndex = (currentIndex + offset + len) % len;
71
+ var option = lastActiveOptions[currentIndex];
72
+ if (option && !option.disabled) {
73
+ var nextActiveCells = validActiveValueCells.slice(0, -1).concat(fullPathKeys[currentIndex] ? toPathKey(fullPathKeys[currentIndex]) : option[fieldNames.value]);
74
+ internalSetActiveValueCells(nextActiveCells);
75
+ return;
76
+ }
77
+ }
78
+ };
79
+ // Different options offset
80
+ var prevColumn = function prevColumn() {
81
+ if (validActiveValueCells.length > 1) {
82
+ var nextActiveCells = validActiveValueCells.slice(0, -1);
83
+ internalSetActiveValueCells(nextActiveCells);
84
+ } else {
85
+ toggleOpen(false);
86
+ }
87
+ };
88
+ var nextColumn = function nextColumn() {
89
+ var _a;
90
+ var nextOptions = ((_a = lastActiveOptions[lastActiveIndex]) === null || _a === void 0 ? void 0 : _a[fieldNames.children]) || [];
91
+ var nextOption = nextOptions.find(function (option) {
92
+ return !option.disabled;
93
+ });
94
+ if (nextOption) {
95
+ var nextActiveCells = [].concat(_toConsumableArray(validActiveValueCells), [nextOption[fieldNames.value]]);
96
+ internalSetActiveValueCells(nextActiveCells);
97
+ }
98
+ };
99
+ React.useImperativeHandle(ref, function () {
100
+ return {
101
+ // scrollTo: treeRef.current?.scrollTo,
102
+ onKeyDown: function onKeyDown(event) {
103
+ var which = event.which;
104
+ // switch (which) {
105
+ // // >>> Arrow keys
106
+ // case KeyCode.UP:
107
+ // case KeyCode.DOWN: {
108
+ // let offset = 0;
109
+ // if (which === KeyCode.UP) {
110
+ // offset = -1;
111
+ // } else if (which === KeyCode.DOWN) {
112
+ // offset = 1;
113
+ // }
114
+ // if (offset !== 0) {
115
+ // offsetActiveOption(offset);
116
+ // }
117
+ // break;
118
+ // }
119
+ // case KeyCode.LEFT: {
120
+ // if (rtl) {
121
+ // nextColumn();
122
+ // } else {
123
+ // prevColumn();
124
+ // }
125
+ // break;
126
+ // }
127
+ // case KeyCode.RIGHT: {
128
+ // if (rtl) {
129
+ // prevColumn();
130
+ // } else {
131
+ // nextColumn();
132
+ // }
133
+ // break;
134
+ // }
135
+ // case KeyCode.BACKSPACE: {
136
+ // if (!searchValue && !showColumnSearch) {
137
+ // prevColumn();
138
+ // }
139
+ // break;
140
+ // }
141
+ // // >>> Select
142
+ // case KeyCode.ENTER: {
143
+ // if (validActiveValueCells.length) {
144
+ // const option = lastActiveOptions[lastActiveIndex];
145
+ // // Search option should revert back of origin options
146
+ // const originOptions: DefaultOptionType[] = option?.[SEARCH_MARK] || [];
147
+ // if (originOptions.length) {
148
+ // onKeyBoardSelect(
149
+ // originOptions.map(opt => opt[fieldNames.value]),
150
+ // originOptions[originOptions.length - 1],
151
+ // );
152
+ // } else {
153
+ // onKeyBoardSelect(validActiveValueCells, lastActiveOptions[lastActiveIndex]);
154
+ // }
155
+ // }
156
+ // break;
157
+ // }
158
+ // // >>> Close
159
+ // case KeyCode.ESC: {
160
+ // toggleOpen(false);
161
+ // if (open) {
162
+ // event.stopPropagation();
163
+ // }
164
+ // }
165
+ // }
166
+ },
167
+
168
+ onKeyUp: function onKeyUp() {}
169
+ };
170
+ });
171
+ });
@@ -0,0 +1,3 @@
1
+ import * as React from 'react';
2
+ var CascaderContext = /*#__PURE__*/React.createContext(null);
3
+ export default CascaderContext;