@hi-ui/cascader 4.1.2 → 4.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +53 -0
- package/lib/cjs/Cascader.js +87 -140
- package/lib/cjs/CascaderMenuList.js +27 -56
- package/lib/cjs/context.js +0 -6
- package/lib/cjs/hooks/use-async-switch.js +7 -33
- package/lib/cjs/hooks/use-cache/lib/esm/index.js +3 -7
- package/lib/cjs/hooks/use-select.js +3 -14
- package/lib/cjs/icons/index.js +2 -9
- package/lib/cjs/index.js +0 -3
- package/lib/cjs/styles/index.scss.js +0 -3
- package/lib/cjs/use-cascader.js +33 -50
- package/lib/cjs/utils/index.js +1 -21
- package/lib/esm/Cascader.js +84 -113
- package/lib/esm/CascaderMenuList.js +25 -41
- package/lib/esm/context.js +0 -4
- package/lib/esm/hooks/use-async-switch.js +5 -22
- package/lib/esm/hooks/use-cache/lib/esm/index.js +3 -5
- package/lib/esm/hooks/use-select.js +3 -9
- package/lib/esm/styles/index.scss.js +0 -2
- package/lib/esm/use-cascader.js +33 -42
- package/lib/esm/utils/index.js +1 -18
- package/package.json +22 -22
@@ -10,34 +10,24 @@
|
|
10
10
|
'use strict';
|
11
11
|
|
12
12
|
var _typeof = require("@babel/runtime/helpers/typeof");
|
13
|
-
|
14
13
|
Object.defineProperty(exports, '__esModule', {
|
15
14
|
value: true
|
16
15
|
});
|
17
|
-
|
18
16
|
var _regeneratorRuntime = require('@babel/runtime/regenerator');
|
19
|
-
|
20
17
|
var tslib = require('tslib');
|
21
|
-
|
22
18
|
var React = require('react');
|
23
|
-
|
24
19
|
var useLatest = require('@hi-ui/use-latest');
|
25
|
-
|
26
20
|
var treeUtils = require('@hi-ui/tree-utils');
|
27
|
-
|
28
21
|
var useCheckState = require('@hi-ui/use-check-state');
|
29
|
-
|
30
|
-
function _interopDefaultLegacy(e) {
|
22
|
+
function _interopDefaultCompat(e) {
|
31
23
|
return e && _typeof(e) === 'object' && 'default' in e ? e : {
|
32
24
|
'default': e
|
33
25
|
};
|
34
26
|
}
|
35
|
-
|
36
|
-
var _regeneratorRuntime__default = /*#__PURE__*/_interopDefaultLegacy(_regeneratorRuntime);
|
37
|
-
|
27
|
+
var _regeneratorRuntime__default = /*#__PURE__*/_interopDefaultCompat(_regeneratorRuntime);
|
38
28
|
var useAsyncSwitch = function useAsyncSwitch(setCascaderData, onExpand, onLoadChildren) {
|
39
|
-
var onLoadChildrenLatest = useLatest.useLatestCallback(onLoadChildren);
|
40
|
-
|
29
|
+
var onLoadChildrenLatest = useLatest.useLatestCallback(onLoadChildren);
|
30
|
+
// 加载节点
|
41
31
|
var loadChildren = React.useCallback(function (node) {
|
42
32
|
return tslib.__awaiter(void 0, void 0, void 0, /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee() {
|
43
33
|
var childrenNodes;
|
@@ -50,10 +40,8 @@ var useAsyncSwitch = function useAsyncSwitch(setCascaderData, onExpand, onLoadCh
|
|
50
40
|
var id = _ref.id;
|
51
41
|
return id;
|
52
42
|
}));
|
53
|
-
|
54
43
|
case 2:
|
55
44
|
childrenNodes = _context.sent;
|
56
|
-
|
57
45
|
if (Array.isArray(childrenNodes)) {
|
58
46
|
setCascaderData(function (prev) {
|
59
47
|
var nextTreeData = treeUtils.cloneTree(prev);
|
@@ -61,7 +49,6 @@ var useAsyncSwitch = function useAsyncSwitch(setCascaderData, onExpand, onLoadCh
|
|
61
49
|
return nextTreeData;
|
62
50
|
});
|
63
51
|
}
|
64
|
-
|
65
52
|
case 4:
|
66
53
|
case "end":
|
67
54
|
return _context.stop();
|
@@ -70,18 +57,15 @@ var useAsyncSwitch = function useAsyncSwitch(setCascaderData, onExpand, onLoadCh
|
|
70
57
|
}, _callee);
|
71
58
|
}));
|
72
59
|
}, [onLoadChildrenLatest, setCascaderData]);
|
73
|
-
|
74
60
|
var _useCheckState = useCheckState.useCheckState(),
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
61
|
+
isLoadingId = _useCheckState.has,
|
62
|
+
addLoadingIds = _useCheckState.add,
|
63
|
+
removeLoadingIds = _useCheckState.remove;
|
79
64
|
var onExpandLatest = useLatest.useLatestCallback(onExpand);
|
80
65
|
var onNodeSwitch = React.useCallback(function (node, onlyExpand) {
|
81
66
|
if (onlyExpand === void 0) {
|
82
67
|
onlyExpand = false;
|
83
68
|
}
|
84
|
-
|
85
69
|
return tslib.__awaiter(void 0, void 0, void 0, /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee2() {
|
86
70
|
var id, children, isLeaf;
|
87
71
|
return _regeneratorRuntime__default["default"].wrap(function _callee2$(_context2) {
|
@@ -91,43 +75,34 @@ var useAsyncSwitch = function useAsyncSwitch(setCascaderData, onExpand, onLoadCh
|
|
91
75
|
// 直接触发选中该节点
|
92
76
|
onExpandLatest(node, onlyExpand);
|
93
77
|
id = node.id, children = node.children, isLeaf = node.isLeaf;
|
94
|
-
|
95
78
|
if (!children) {
|
96
79
|
_context2.next = 4;
|
97
80
|
break;
|
98
81
|
}
|
99
|
-
|
100
82
|
return _context2.abrupt("return");
|
101
|
-
|
102
83
|
case 4:
|
103
84
|
if (!isLeaf) {
|
104
85
|
_context2.next = 6;
|
105
86
|
break;
|
106
87
|
}
|
107
|
-
|
108
88
|
return _context2.abrupt("return");
|
109
|
-
|
110
89
|
case 6:
|
111
90
|
if (!onLoadChildren) {
|
112
91
|
_context2.next = 17;
|
113
92
|
break;
|
114
93
|
}
|
115
|
-
|
116
94
|
addLoadingIds(id);
|
117
95
|
_context2.prev = 8;
|
118
96
|
_context2.next = 11;
|
119
97
|
return loadChildren(node);
|
120
|
-
|
121
98
|
case 11:
|
122
99
|
removeLoadingIds(id);
|
123
100
|
_context2.next = 17;
|
124
101
|
break;
|
125
|
-
|
126
102
|
case 14:
|
127
103
|
_context2.prev = 14;
|
128
104
|
_context2.t0 = _context2["catch"](8);
|
129
105
|
removeLoadingIds(id);
|
130
|
-
|
131
106
|
case 17:
|
132
107
|
case "end":
|
133
108
|
return _context2.stop();
|
@@ -138,5 +113,4 @@ var useAsyncSwitch = function useAsyncSwitch(setCascaderData, onExpand, onLoadCh
|
|
138
113
|
}, [loadChildren, onLoadChildren, onExpandLatest, addLoadingIds, removeLoadingIds]);
|
139
114
|
return [isLoadingId, onNodeSwitch];
|
140
115
|
};
|
141
|
-
|
142
116
|
exports.useAsyncSwitch = useAsyncSwitch;
|
@@ -12,8 +12,8 @@
|
|
12
12
|
Object.defineProperty(exports, '__esModule', {
|
13
13
|
value: true
|
14
14
|
});
|
15
|
-
|
16
15
|
var React = require('react');
|
16
|
+
|
17
17
|
/** @LICENSE
|
18
18
|
* @hi-ui/use-cache
|
19
19
|
* https://github.com/XiaoMi/hiui/tree/master/packages/hooks/use-cache#readme
|
@@ -27,17 +27,13 @@ var React = require('react');
|
|
27
27
|
/**
|
28
28
|
* A hook using for data cache that compatible with the controlled and uncontrolled modes coexist.
|
29
29
|
*/
|
30
|
-
|
31
|
-
|
32
30
|
var useCache = function useCache(data) {
|
33
31
|
var _useState = React.useState(data),
|
34
|
-
|
35
|
-
|
36
|
-
|
32
|
+
internalData = _useState[0],
|
33
|
+
setInternalData = _useState[1];
|
37
34
|
React.useEffect(function () {
|
38
35
|
setInternalData(data);
|
39
36
|
}, [data]);
|
40
37
|
return [internalData, setInternalData];
|
41
38
|
};
|
42
|
-
|
43
39
|
exports.useCache = useCache;
|
@@ -12,29 +12,21 @@
|
|
12
12
|
Object.defineProperty(exports, '__esModule', {
|
13
13
|
value: true
|
14
14
|
});
|
15
|
-
|
16
15
|
var React = require('react');
|
17
|
-
|
18
16
|
var useLatest = require('@hi-ui/use-latest');
|
19
|
-
|
20
17
|
var treeUtils = require('@hi-ui/tree-utils');
|
21
|
-
|
22
18
|
var index = require('../utils/index.js');
|
19
|
+
|
23
20
|
/**
|
24
21
|
* 用于选中的 hook
|
25
22
|
*/
|
26
|
-
|
27
|
-
|
28
23
|
var useSelect = function useSelect(disabled, onSelect, changeOnSelect, onLoadChildren) {
|
29
24
|
var onSelectLatest = useLatest.useLatestCallback(onSelect);
|
30
|
-
|
31
25
|
var _useState = React.useState(''),
|
32
|
-
|
33
|
-
|
34
|
-
|
26
|
+
selectedId = _useState[0],
|
27
|
+
setSelectedId = _useState[1];
|
35
28
|
var proxyOnSelect = React.useCallback(function (selectedId, selectOption) {
|
36
29
|
var optionPaths = treeUtils.getTopDownAncestors(selectOption);
|
37
|
-
|
38
30
|
if (changeOnSelect) {
|
39
31
|
// 任意选中
|
40
32
|
onSelectLatest(selectedId, selectOption, optionPaths);
|
@@ -48,11 +40,9 @@ var useSelect = function useSelect(disabled, onSelect, changeOnSelect, onLoadChi
|
|
48
40
|
var onItemSelect = React.useCallback(function (targetItem, onlyExpand) {
|
49
41
|
if (disabled) return;
|
50
42
|
if (targetItem.disabled) return;
|
51
|
-
|
52
43
|
if (onlyExpand) {
|
53
44
|
// 仅展开,不做选中处理
|
54
45
|
var canLoadChildren = index.checkCanLoadChildren(targetItem, onLoadChildren);
|
55
|
-
|
56
46
|
if (canLoadChildren) {
|
57
47
|
setSelectedId(targetItem.id);
|
58
48
|
}
|
@@ -63,5 +53,4 @@ var useSelect = function useSelect(disabled, onSelect, changeOnSelect, onLoadChi
|
|
63
53
|
}, [disabled, proxyOnSelect, onLoadChildren]);
|
64
54
|
return [selectedId, onItemSelect, setSelectedId];
|
65
55
|
};
|
66
|
-
|
67
56
|
exports.useSelect = useSelect;
|
package/lib/cjs/icons/index.js
CHANGED
@@ -10,25 +10,18 @@
|
|
10
10
|
'use strict';
|
11
11
|
|
12
12
|
var _typeof = require("@babel/runtime/helpers/typeof");
|
13
|
-
|
14
13
|
Object.defineProperty(exports, '__esModule', {
|
15
14
|
value: true
|
16
15
|
});
|
17
|
-
|
18
16
|
var React = require('react');
|
19
|
-
|
20
17
|
var icons = require('@hi-ui/icons');
|
21
|
-
|
22
18
|
var spinner = require('@hi-ui/spinner');
|
23
|
-
|
24
|
-
function _interopDefaultLegacy(e) {
|
19
|
+
function _interopDefaultCompat(e) {
|
25
20
|
return e && _typeof(e) === 'object' && 'default' in e ? e : {
|
26
21
|
'default': e
|
27
22
|
};
|
28
23
|
}
|
29
|
-
|
30
|
-
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
31
|
-
|
24
|
+
var React__default = /*#__PURE__*/_interopDefaultCompat(React);
|
32
25
|
var defaultSuffixIcon = /*#__PURE__*/React__default["default"].createElement(icons.DownOutlined, null);
|
33
26
|
var defaultLeafIcon = /*#__PURE__*/React__default["default"].createElement("span", {
|
34
27
|
style: {
|
package/lib/cjs/index.js
CHANGED
@@ -13,9 +13,6 @@ Object.defineProperty(exports, '__esModule', {
|
|
13
13
|
value: true
|
14
14
|
});
|
15
15
|
var css_248z = "@charset \"UTF-8\";.hi-v4-cascader__popper .hi-v4-picker__body {padding-left: 0;padding-right: 0;overflow-y: hidden;}.hi-v4-cascader__popper .hi-v4-picker__loading, .hi-v4-cascader__popper .hi-v4-picker__empty {padding: var(--hi-v4-spacing-5, 10px) var(--hi-v4-spacing-8, 16px);}.hi-v4-cascader-panel {white-space: nowrap;-webkit-box-sizing: border-box;box-sizing: border-box;font-size: var(--hi-v4-text-size-md, 0.875rem);color: var(--hi-v4-color-gray-700, #1f2733);}.hi-v4-cascader-search {-webkit-box-sizing: border-box;box-sizing: border-box;padding: 0 10px 10px;position: relative;}.hi-v4-cascader-search .hi-v4-input__prefix {font-size: 16px;padding-left: 0;}.hi-v4-cascader-search__empty {display: inline-block;margin-top: 20px;font-size: 14px;font-weight: 400;color: #999;line-height: 20px;}.hi-v4-cascader-menu-list {display: -webkit-box;display: -ms-flexbox;display: flex;-webkit-box-sizing: border-box;box-sizing: border-box;overflow-x: auto;}.hi-v4-cascader-menu-list--flatted .hi-v4-cascader-menu {-ms-flex-preferred-size: 100%;flex-basis: 100%;}.hi-v4-cascader-menu {-webkit-box-sizing: border-box;box-sizing: border-box;margin: 0;padding: 0;border: none;outline: none;font-size: var(--hi-v4-text-size-md, 0.875rem);vertical-align: middle;list-style: none;width: auto;box-sizing: border-box;-ms-flex-negative: 0;flex-shrink: 0;display: inline-block;min-width: 140px;max-height: 260px;overflow: auto;padding: 0 var(--hi-v4-spacing-4, 8px);border-right: var(--hi-v4-border-size-normal, 1px solid) var(--hi-v4-color-gray-200, #ebedf0);}.hi-v4-cascader-menu:last-of-type {border: none;}.hi-v4-cascader-menu-item {width: 100%;position: relative;cursor: pointer;display: -webkit-box;display: -ms-flexbox;display: flex;}.hi-v4-cascader-menu-option {padding: var(--hi-v4-spacing-1, 2px) var(--hi-v4-spacing-3, 6px);-webkit-box-sizing: border-box;box-sizing: border-box;height: var(--hi-v4-height-8, 32px);width: 100%;display: -webkit-box;display: -ms-flexbox;display: flex;-webkit-box-align: center;-ms-flex-align: center;align-items: center;position: relative;-webkit-box-pack: justify;-ms-flex-pack: justify;justify-content: space-between;border-radius: var(--hi-v4-border-radius-md, 4px);}.hi-v4-cascader-menu-option:hover {background-color: var(--hi-v4-color-gray-100, #f2f4f7);}.hi-v4-cascader-menu-option.hi-v4-cascader-menu-option--selected {background-color: var(--hi-v4-color-primary-50, var(--hi-v4-color-brandblue-50, #e2f3fe));color: var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa));}.hi-v4-cascader-menu-option.hi-v4-cascader-menu-option--selected .hi-v4-cascader-menu-switcher {color: var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa));}.hi-v4-cascader-menu-option--focused {background-color: var(--hi-v4-color-primary-50, var(--hi-v4-color-brandblue-50, #e2f3fe));}.hi-v4-cascader-menu-option--checked {font-weight: 700;}.hi-v4-cascader-menu-option.hi-v4-cascader-menu-option--disabled {cursor: not-allowed;color: var(--hi-v4-color-gray-500, #929aa6);background: transparent;}.hi-v4-cascader-menu-option.hi-v4-cascader-menu-option--disabled .hi-v4-cascader-menu-switcher {color: var(--hi-v4-color-gray-400, #b5bcc7);}.hi-v4-cascader-menu .title__text {-webkit-box-flex: 1;-ms-flex: 1 1;flex: 1 1;}.hi-v4-cascader-menu .title__text--cols {display: block;width: 100%;-webkit-box-sizing: border-box;box-sizing: border-box;margin: 0;padding: 0;border: none;outline: none;font-size: var(--hi-v4-text-size-md, 0.875rem);vertical-align: middle;list-style: none;}.hi-v4-cascader-menu .title__text--col {display: inline-block;}.hi-v4-cascader-menu .title__text--col::after {content: \" / \";}.hi-v4-cascader-menu .title__text--col:last-child::after {content: none;}.hi-v4-cascader-menu .title__text--matched {color: var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa));}.hi-v4-cascader-menu-switcher {-ms-flex-negative: 0;flex-shrink: 0;font-size: 16px;color: var(--hi-v4-color-gray-500, #929aa6);}.hi-v4-cascader-menu-switcher--loading {color: var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa));}.hi-v4-cascader-menu-switcher--arrow {-webkit-transform: rotate(-90deg);transform: rotate(-90deg);}.hi-v4-cascader__icon--loading {display: inline-block;width: 1em;height: 1em;stroke: none;cursor: default;fill: currentColor;}.hi-v4-cascader__icon--loading svg {-webkit-animation-name: hi-rotate;animation-name: hi-rotate;-webkit-animation-duration: 2s;animation-duration: 2s;-webkit-animation-iteration-count: infinite;animation-iteration-count: infinite;}@-webkit-keyframes rotate {to {-webkit-transform: rotate(360deg);transform: rotate(360deg);}}@keyframes rotate {to {-webkit-transform: rotate(360deg);transform: rotate(360deg);}}";
|
16
|
-
|
17
16
|
var __styleInject__ = require('style-inject')["default"];
|
18
|
-
|
19
17
|
__styleInject__(css_248z);
|
20
|
-
|
21
18
|
exports["default"] = css_248z;
|
package/lib/cjs/use-cascader.js
CHANGED
@@ -12,85 +12,69 @@
|
|
12
12
|
Object.defineProperty(exports, '__esModule', {
|
13
13
|
value: true
|
14
14
|
});
|
15
|
-
|
16
15
|
var tslib = require('tslib');
|
17
|
-
|
18
16
|
var React = require('react');
|
19
|
-
|
20
17
|
var useUncontrolledState = require('@hi-ui/use-uncontrolled-state');
|
21
|
-
|
22
18
|
var index = require('./hooks/use-cache/lib/esm/index.js');
|
23
|
-
|
24
19
|
var index$1 = require('./utils/index.js');
|
25
|
-
|
26
20
|
var useSelect = require('./hooks/use-select.js');
|
27
|
-
|
28
21
|
var useAsyncSwitch = require('./hooks/use-async-switch.js');
|
29
|
-
|
30
22
|
var NOOP_ARRAY = [];
|
31
23
|
var NOOP_VALUE = [];
|
32
|
-
|
33
24
|
var useCascader = function useCascader(_a) {
|
34
25
|
var _a$defaultValue = _a.defaultValue,
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
26
|
+
defaultValue = _a$defaultValue === void 0 ? NOOP_VALUE : _a$defaultValue,
|
27
|
+
valueProp = _a.value,
|
28
|
+
onChangeProp = _a.onChange,
|
29
|
+
_a$data = _a.data,
|
30
|
+
data = _a$data === void 0 ? NOOP_ARRAY : _a$data,
|
31
|
+
_a$disabled = _a.disabled,
|
32
|
+
disabled = _a$disabled === void 0 ? false : _a$disabled,
|
33
|
+
_a$changeOnSelect = _a.changeOnSelect,
|
34
|
+
changeOnSelect = _a$changeOnSelect === void 0 ? false : _a$changeOnSelect,
|
35
|
+
_a$flatted = _a.flatted,
|
36
|
+
flatted = _a$flatted === void 0 ? false : _a$flatted,
|
37
|
+
onSelectProp = _a.onSelect,
|
38
|
+
onLoadChildren = _a.onLoadChildren,
|
39
|
+
cascaderDataProp = _a.cascaderData,
|
40
|
+
setCascaderDataProp = _a.setCascaderData,
|
41
|
+
flattedDataProp = _a.flattedData,
|
42
|
+
fieldNames = _a.fieldNames,
|
43
|
+
rest = tslib.__rest(_a, ["defaultValue", "value", "onChange", "data", "disabled", "changeOnSelect", "flatted", "onSelect", "onLoadChildren", "cascaderData", "setCascaderData", "flattedData", "fieldNames"]);
|
54
44
|
var _useCache = index.useCache(data),
|
55
|
-
|
56
|
-
|
57
|
-
|
45
|
+
cacheData = _useCache[0],
|
46
|
+
setCacheData = _useCache[1];
|
58
47
|
var cascaderData = cascaderDataProp !== null && cascaderDataProp !== void 0 ? cascaderDataProp : cacheData;
|
59
48
|
var setCascaderData = setCascaderDataProp !== null && setCascaderDataProp !== void 0 ? setCascaderDataProp : setCacheData;
|
60
49
|
var flattedData = React.useMemo(function () {
|
61
50
|
return flattedDataProp !== null && flattedDataProp !== void 0 ? flattedDataProp : index$1.flattenTreeData(cascaderData, fieldNames);
|
62
51
|
}, [cascaderData, flattedDataProp, fieldNames]);
|
63
|
-
|
64
52
|
var _useUncontrolledState = useUncontrolledState.useUncontrolledState(defaultValue, valueProp, onChangeProp),
|
65
|
-
|
66
|
-
|
67
|
-
|
53
|
+
value = _useUncontrolledState[0],
|
54
|
+
tryChangeValue = _useUncontrolledState[1];
|
68
55
|
var onSelect = function onSelect(value, item, itemPaths) {
|
69
56
|
tryChangeValue(itemPaths.map(function (_ref) {
|
70
57
|
var id = _ref.id;
|
71
58
|
return id;
|
72
59
|
}));
|
73
60
|
onSelectProp === null || onSelectProp === void 0 ? void 0 : onSelectProp(value, item, itemPaths);
|
74
|
-
};
|
75
|
-
|
76
|
-
|
61
|
+
};
|
62
|
+
// 单击选中某项
|
77
63
|
var _useSelect = useSelect.useSelect(disabled, onSelect, changeOnSelect, onLoadChildren),
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
64
|
+
selectedId = _useSelect[0],
|
65
|
+
onOptionSelect = _useSelect[1],
|
66
|
+
setSelectedId = _useSelect[2];
|
67
|
+
// 选中 id 路径
|
83
68
|
var selectedIds = React.useMemo(function () {
|
84
69
|
return index$1.getActiveNodePaths(flattedData, selectedId).map(function (_ref2) {
|
85
70
|
var id = _ref2.id;
|
86
71
|
return id;
|
87
72
|
});
|
88
|
-
}, [flattedData, selectedId]);
|
89
|
-
|
73
|
+
}, [flattedData, selectedId]);
|
74
|
+
// 存在异步加载数据的情况时,单击选中时需要控制异步加载状态
|
90
75
|
var _useAsyncSwitch = useAsyncSwitch.useAsyncSwitch(setCascaderData, onOptionSelect, onLoadChildren),
|
91
|
-
|
92
|
-
|
93
|
-
|
76
|
+
isLoadingId = _useAsyncSwitch[0],
|
77
|
+
onItemExpand = _useAsyncSwitch[1];
|
94
78
|
var onItemHover = React.useCallback(function (option) {
|
95
79
|
// hover模式,仅展开节点,不触发 change
|
96
80
|
onItemExpand(option, true);
|
@@ -103,7 +87,7 @@ var useCascader = function useCascader(_a) {
|
|
103
87
|
}, [flatted, flattedData, selectedId, isCanLoadChildren]);
|
104
88
|
var getItemRequiredProps = React.useCallback(function (_ref3) {
|
105
89
|
var id = _ref3.id,
|
106
|
-
|
90
|
+
depth = _ref3.depth;
|
107
91
|
return {
|
108
92
|
active: value[depth] === id,
|
109
93
|
selected: flatted ? selectedId === id : selectedIds[depth] === id,
|
@@ -131,5 +115,4 @@ var useCascader = function useCascader(_a) {
|
|
131
115
|
menuList: menuList
|
132
116
|
};
|
133
117
|
};
|
134
|
-
|
135
118
|
exports.useCascader = useCascader;
|
package/lib/cjs/utils/index.js
CHANGED
@@ -12,15 +12,12 @@
|
|
12
12
|
Object.defineProperty(exports, '__esModule', {
|
13
13
|
value: true
|
14
14
|
});
|
15
|
-
|
16
15
|
var treeUtils = require('@hi-ui/tree-utils');
|
17
|
-
|
18
16
|
var typeAssertion = require('@hi-ui/type-assertion');
|
17
|
+
|
19
18
|
/**
|
20
19
|
* 扁平化树数据结构,基于前序遍历
|
21
20
|
*/
|
22
|
-
|
23
|
-
|
24
21
|
var flattenTreeData = function flattenTreeData(treeData, fieldNames) {
|
25
22
|
/**
|
26
23
|
* 转换对象
|
@@ -29,10 +26,8 @@ var flattenTreeData = function flattenTreeData(treeData, fieldNames) {
|
|
29
26
|
if (fieldNames) {
|
30
27
|
return node[fieldNames[key] || key];
|
31
28
|
}
|
32
|
-
|
33
29
|
return node[key];
|
34
30
|
};
|
35
|
-
|
36
31
|
return treeUtils.baseFlattenTree({
|
37
32
|
tree: treeData,
|
38
33
|
childrenFieldName: function childrenFieldName(node) {
|
@@ -40,7 +35,6 @@ var flattenTreeData = function flattenTreeData(treeData, fieldNames) {
|
|
40
35
|
},
|
41
36
|
transform: function transform(node) {
|
42
37
|
var _a, _b;
|
43
|
-
|
44
38
|
var flattedNode = node;
|
45
39
|
var raw = node.raw;
|
46
40
|
flattedNode.id = getKeyFields(raw, 'id');
|
@@ -54,8 +48,6 @@ var flattenTreeData = function flattenTreeData(treeData, fieldNames) {
|
|
54
48
|
/**
|
55
49
|
* 获取选中节点的节点路径,包含选中节点
|
56
50
|
*/
|
57
|
-
|
58
|
-
|
59
51
|
var getActiveNodePaths = function getActiveNodePaths(flattedData, selectedId) {
|
60
52
|
if (flattedData.length === 0) return [];
|
61
53
|
var selectedOption = flattedData.find(function (_ref) {
|
@@ -68,8 +60,6 @@ var getActiveNodePaths = function getActiveNodePaths(flattedData, selectedId) {
|
|
68
60
|
/**
|
69
61
|
* 获取自顶向下的兄弟节点列表菜单
|
70
62
|
*/
|
71
|
-
|
72
|
-
|
73
63
|
var getActiveMenus = function getActiveMenus(flattedData, selectedId) {
|
74
64
|
if (flattedData.length === 0) return [];
|
75
65
|
var root = flattedData[0].parent;
|
@@ -80,48 +70,39 @@ var getActiveMenus = function getActiveMenus(flattedData, selectedId) {
|
|
80
70
|
return selectedId === id;
|
81
71
|
});
|
82
72
|
if (!selectedOption) return menu;
|
83
|
-
|
84
73
|
if (selectedOption.children) {
|
85
74
|
menu = [selectedOption.children];
|
86
75
|
} else {
|
87
76
|
menu = [];
|
88
77
|
}
|
89
|
-
|
90
78
|
while (selectedOption.parent) {
|
91
79
|
menu.push(selectedOption.parent.children);
|
92
80
|
selectedOption = selectedOption.parent;
|
93
81
|
}
|
94
|
-
|
95
82
|
return menu.reverse();
|
96
83
|
};
|
97
|
-
|
98
84
|
var getFlattedMenus = function getFlattedMenus(data, filter) {
|
99
85
|
return [data.filter(function (item) {
|
100
86
|
return !filter(item);
|
101
87
|
})];
|
102
88
|
};
|
103
|
-
|
104
89
|
var checkCanLoadChildren = function checkCanLoadChildren(node, onLoadChildren) {
|
105
90
|
var hasChildren = typeAssertion.isArrayNonEmpty(node.children);
|
106
91
|
return hasChildren || onLoadChildren && !node.isLeaf && !node.children;
|
107
92
|
};
|
108
|
-
|
109
93
|
function getItemEventData(node, requiredProps) {
|
110
94
|
return Object.assign(Object.assign({}, node), requiredProps);
|
111
95
|
}
|
112
|
-
|
113
96
|
var getFilteredMenuList = function getFilteredMenuList(menuList, searchedData) {
|
114
97
|
var result = [];
|
115
98
|
searchedData.forEach(function (item) {
|
116
99
|
while (item && item.depth >= 0) {
|
117
100
|
var depth = item.depth;
|
118
101
|
var depthResult = result[depth];
|
119
|
-
|
120
102
|
if (!depthResult) {
|
121
103
|
depthResult = new Map();
|
122
104
|
result[depth] = depthResult;
|
123
105
|
}
|
124
|
-
|
125
106
|
depthResult.set(item.id, item);
|
126
107
|
item = item.parent;
|
127
108
|
}
|
@@ -137,7 +118,6 @@ var getFilteredMenuList = function getFilteredMenuList(menuList, searchedData) {
|
|
137
118
|
});
|
138
119
|
});
|
139
120
|
};
|
140
|
-
|
141
121
|
exports.checkCanLoadChildren = checkCanLoadChildren;
|
142
122
|
exports.flattenTreeData = flattenTreeData;
|
143
123
|
exports.getActiveMenus = getActiveMenus;
|