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