@hi-ui/check-cascader 4.0.0-beta.26 → 4.0.0-beta.29

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.
@@ -29,29 +29,21 @@ var useUncontrolledState = require('@hi-ui/use-uncontrolled-state');
29
29
 
30
30
  var icons = require('@hi-ui/icons');
31
31
 
32
- var useSearch = require('./hooks/use-search.js');
33
-
34
- require('@hi-ui/use-check');
35
-
36
- var useCache = require('./hooks/use-cache.js');
37
-
38
- require('@babel/runtime/regenerator');
39
-
40
- var useLatest = require('@hi-ui/use-latest');
41
-
42
- var treeUtils = require('@hi-ui/tree-utils');
32
+ var index = require('./hooks/use-cache/lib/esm/index.js');
43
33
 
44
34
  var picker = require('@hi-ui/picker');
45
35
 
46
36
  var tagInput = require('@hi-ui/tag-input');
47
37
 
48
- var arrayUtils = require('@hi-ui/array-utils');
49
-
50
38
  var CheckCascaderMenus = require('./CheckCascaderMenus.js');
51
39
 
52
40
  var useSearchMode = require('@hi-ui/use-search-mode');
53
41
 
54
- var index = require('./utils/index.js');
42
+ var index$1 = require('./utils/index.js');
43
+
44
+ var treeUtils = require('@hi-ui/tree-utils');
45
+
46
+ var useLatest = require('@hi-ui/use-latest');
55
47
 
56
48
  var typeAssertion = require('@hi-ui/type-assertion');
57
49
 
@@ -103,9 +95,10 @@ var CheckCascader = /*#__PURE__*/React.forwardRef(function (_a, ref) {
103
95
  overlayClassName = _a.overlayClassName,
104
96
  _a$type = _a.type,
105
97
  type = _a$type === void 0 ? 'tree' : _a$type,
98
+ checkedMode = _a.checkedMode,
106
99
  onOpen = _a.onOpen,
107
100
  onClose = _a.onClose,
108
- rest = tslib.__rest(_a, ["prefixCls", "className", "defaultValue", "value", "onChange", "data", "placeholder", "clearable", "onSelect", "expandTrigger", "disabled", "emptyContent", "changeOnSelect", "render", "displayRender", "checkCascaded", "searchPlaceholder", "onLoadChildren", "wrap", "appearance", "invalid", "filterOption", "searchable", "onSearch", "overlayClassName", "type", "onOpen", "onClose"]);
101
+ rest = tslib.__rest(_a, ["prefixCls", "className", "defaultValue", "value", "onChange", "data", "placeholder", "clearable", "onSelect", "expandTrigger", "disabled", "emptyContent", "changeOnSelect", "render", "displayRender", "checkCascaded", "searchPlaceholder", "onLoadChildren", "appearance", "invalid", "filterOption", "searchable", "onSearch", "overlayClassName", "type", "checkedMode", "onOpen", "onClose"]);
109
102
 
110
103
  var i18n = localeContext.useLocaleContext();
111
104
  var placeholder = typeAssertion.isUndef(placeholderProp) ? i18n.get('checkCascader.placeholder') : placeholderProp;
@@ -119,12 +112,12 @@ var CheckCascader = /*#__PURE__*/React.forwardRef(function (_a, ref) {
119
112
  menuVisible = _useUncontrolledToggl[0],
120
113
  menuVisibleAction = _useUncontrolledToggl[1];
121
114
 
122
- var _useCache = useCache.useCache(data),
115
+ var _useCache = index.useCache(data),
123
116
  cascaderData = _useCache[0],
124
117
  setCascaderData = _useCache[1];
125
118
 
126
119
  var flattedData = React.useMemo(function () {
127
- return index.flattenTreeData(cascaderData);
120
+ return index$1.flattenTreeData(cascaderData);
128
121
  }, [cascaderData]);
129
122
 
130
123
  var _useUncontrolledState = useUncontrolledState.useUncontrolledState(defaultValue, valueProp, onChange),
@@ -138,6 +131,7 @@ var CheckCascader = /*#__PURE__*/React.forwardRef(function (_a, ref) {
138
131
 
139
132
  var proxyOnChange = useLatest.useLatestCallback(function (value, item, shouldChecked) {
140
133
  var flattedItems = flattedData;
134
+ console.log(item);
141
135
  var itemsPaths = value.map(function (lastId) {
142
136
  var item = flattedItems.find(function (item) {
143
137
  return item.id === lastId;
@@ -156,20 +150,10 @@ var CheckCascader = /*#__PURE__*/React.forwardRef(function (_a, ref) {
156
150
  });
157
151
 
158
152
  return idPaths || [lastId];
159
- }); // const itemsPaths = flattedItems
160
- // .filter((item) => value.includes(item.id))
161
- // .map((item) => getTopDownAncestors(item).map(({ id }) => id))
162
- // TODO: 找到所有 id 的祖先节点路径
163
-
164
- tryChangeValue(itemsPaths); // 包括所有全选的数据,包括全选
165
-
166
- if (shouldChecked) {
167
- // TODO:as useCheckList
168
- setSelectedItems(function (prev) {
169
- return [].concat(prev, [item]);
170
- });
171
- }
172
- }); // ************************** 异步搜索 ************************* //
153
+ });
154
+ tryChangeValue(itemsPaths);
155
+ }); // ************************** 搜索 ************************* //
156
+ // 无法做异步搜索,因为下拉菜单不能合并(因为树形数据,不知道是第几级)
173
157
 
174
158
  var customSearchStrategy = useSearchMode.useTreeCustomSearch({
175
159
  data: flattedData,
@@ -216,7 +200,7 @@ var CheckCascader = /*#__PURE__*/React.forwardRef(function (_a, ref) {
216
200
  }, title);
217
201
  if (typeof title !== 'string') return raw;
218
202
  if (found) return raw;
219
- var index = useSearch.matchStrategy(title, searchValue);
203
+ var index = useSearchMode.matchStrategy(title, searchValue);
220
204
  if (index === -1) return raw;
221
205
  found = true;
222
206
  var resultLength = searchValue.length;
@@ -231,22 +215,12 @@ var CheckCascader = /*#__PURE__*/React.forwardRef(function (_a, ref) {
231
215
  }, resultStr), afterStr);
232
216
  }).reverse()) : true;
233
217
  return ret;
234
- }, [titleRender, searchValue, searchMode]); // 搜索时临时选中缓存数据
235
-
236
- var _useState = React.useState([]),
237
- selectedItems = _useState[0],
238
- setSelectedItems = _useState[1];
239
-
218
+ }, [titleRender, searchValue, searchMode]);
240
219
  var shouldUseSearch = !!searchValue;
241
220
  var selectProps = {
242
221
  data: shouldUseSearch ? stateInSearch.data : flattedData,
243
222
  titleRender: proxyTitleRender
244
- }; // 下拉菜单不能合并(因为树形数据,不知道是第几级)
245
-
246
- var mergedData = React.useMemo(function () {
247
- var nextData = selectedItems.concat(flattedData);
248
- return arrayUtils.uniqBy(nextData, 'id');
249
- }, [selectedItems, flattedData]);
223
+ };
250
224
  var cls = classname.cx(prefixCls, className, prefixCls + "--" + (menuVisible ? 'open' : 'closed'));
251
225
  return /*#__PURE__*/React__default["default"].createElement(picker.Picker, Object.assign({
252
226
  ref: ref,
@@ -277,7 +251,7 @@ var CheckCascader = /*#__PURE__*/React.forwardRef(function (_a, ref) {
277
251
  value: value,
278
252
  // @ts-ignore
279
253
  onChange: proxyOnChange,
280
- data: mergedData,
254
+ data: flattedData,
281
255
  invalid: invalid
282
256
  })
283
257
  }), typeAssertion.isArrayNonEmpty(selectProps.data) ? /*#__PURE__*/React__default["default"].createElement(CheckCascaderMenus.CheckCascaderMenus, {
@@ -295,7 +269,8 @@ var CheckCascader = /*#__PURE__*/React.forwardRef(function (_a, ref) {
295
269
  // @ts-ignore
296
270
  flattedData: selectProps.data,
297
271
  data: cascaderData,
298
- onChangeData: setCascaderData
272
+ onChangeData: setCascaderData,
273
+ checkedMode: checkedMode
299
274
  }) : null);
300
275
  });
301
276
 
@@ -27,6 +27,8 @@ var context = require('./context.js');
27
27
 
28
28
  var index = require('./utils/index.js');
29
29
 
30
+ var treeUtils = require('@hi-ui/tree-utils');
31
+
30
32
  function _interopDefaultLegacy(e) {
31
33
  return e && _typeof(e) === 'object' && 'default' in e ? e : {
32
34
  'default': e
@@ -73,7 +75,7 @@ var CheckCascaderMenu = function CheckCascaderMenu(_ref) {
73
75
 
74
76
  return flatted ? /*#__PURE__*/React__default["default"].createElement("span", {
75
77
  className: classname.cx("title__text", "title__text--cols")
76
- }, index.getNodeAncestors(option).reverse().map(function (item, index) {
78
+ }, treeUtils.getNodeAncestorsWithMe(option).reverse().map(function (item, index) {
77
79
  return /*#__PURE__*/React__default["default"].createElement("span", {
78
80
  className: "title__text--col",
79
81
  key: item.id
@@ -77,7 +77,13 @@ var CheckCascaderMenus = /*#__PURE__*/React.forwardRef(function (_a, ref) {
77
77
  onChange = _a.onChange,
78
78
  titleRender = _a.titleRender,
79
79
  flatted = _a.flatted,
80
- rest = tslib.__rest(_a, ["prefixCls", "role", "className", "children", "data", "flattedData", "onChangeData", "value", "defaultValue", "disabled", "expandTrigger", "changeOnSelect", "checkCascaded", "onLoadChildren", "onChange", "onSelect", "titleRender", "flatted"]);
80
+ _a$checkedMode = _a.checkedMode,
81
+ checkedMode = _a$checkedMode === void 0 ? 'ALL' : _a$checkedMode,
82
+ rest = tslib.__rest(_a, ["prefixCls", "role", "className", "children", "data", "flattedData", "onChangeData", "value", "defaultValue", "disabled", "expandTrigger", "changeOnSelect", "checkCascaded", "onLoadChildren", "onChange", "onSelect", "titleRender", "flatted", "checkedMode"]);
83
+
84
+ if (checkCascaded === false) {
85
+ checkedMode = 'SEPARATE';
86
+ }
81
87
 
82
88
  var _useSelect = useSelect.useSelect(disabled),
83
89
  selectedId = _useSelect[0],
@@ -89,17 +95,10 @@ var CheckCascaderMenus = /*#__PURE__*/React.forwardRef(function (_a, ref) {
89
95
  isLoadingId = _useAsyncSwitch[0],
90
96
  onItemExpand = _useAsyncSwitch[1];
91
97
 
92
- var _useCheck = useCheck.useCheck(checkCascaded, disabled, flattedData, defaultValue, valueProp, function (_ref, target, shouldChecked) {
93
- var checkedIds = _ref.checkedIds,
94
- semiCheckedIds = _ref.semiCheckedIds; // @ts-ignore
95
-
96
- onChange === null || onChange === void 0 ? void 0 : onChange(checkedIds, {
97
- trigger: 'checkbox',
98
- target: target,
99
- shouldChecked: shouldChecked,
100
- semiCheckedIds: semiCheckedIds // checkedItems: fFindNodesByIds(flattedData, checkedIds),
98
+ var _useCheck = useCheck.useCheck(checkedMode, disabled, flattedData, defaultValue, valueProp, function (_ref, target, shouldChecked) {
99
+ var checkedIds = _ref.checkedIds; // @ts-ignore
101
100
 
102
- });
101
+ onChange === null || onChange === void 0 ? void 0 : onChange(checkedIds, target, shouldChecked);
103
102
  }),
104
103
  onOptionCheck = _useCheck[0],
105
104
  isCheckedId = _useCheck[1],
@@ -112,8 +111,8 @@ var CheckCascaderMenus = /*#__PURE__*/React.forwardRef(function (_a, ref) {
112
111
  selected: flatted ? selectedId === id : selectedIds[depth] === id,
113
112
  checked: isCheckedId(id),
114
113
  loading: isLoadingId(id),
115
- semiChecked: isSemiCheckedId(id),
116
- focused: false
114
+ semiChecked: isSemiCheckedId(id) // focused: false,
115
+
117
116
  };
118
117
  });
119
118
  var providedValue = React.useMemo(function () {
@@ -14,11 +14,18 @@ Object.defineProperty(exports, '__esModule', {
14
14
  });
15
15
 
16
16
  var React = require('react');
17
- /**
18
- * 一个缓存数据的 hook
17
+ /** @LICENSE
18
+ * @hi-ui/use-cache
19
+ * https://github.com/XiaoMi/hiui/tree/master/packages/hooks/use-cache#readme
19
20
  *
20
- * @param data
21
- * @returns
21
+ * Copyright (c) HIUI <mi-hiui@xiaomi.com>.
22
+ *
23
+ * This source code is licensed under the MIT license found in the
24
+ * LICENSE file in the root directory of this source tree.
25
+ */
26
+
27
+ /**
28
+ * A hook using for data cache that compatible with the controlled and uncontrolled modes coexist.
22
29
  */
23
30
 
24
31
 
@@ -13,31 +13,38 @@ Object.defineProperty(exports, '__esModule', {
13
13
  value: true
14
14
  });
15
15
 
16
+ var useUncontrolledState = require('@hi-ui/use-uncontrolled-state');
17
+
16
18
  var useCheck$1 = require('@hi-ui/use-check');
17
19
 
18
- var useUncontrolledState = require('@hi-ui/use-uncontrolled-state');
20
+ var index = require('../utils/index.js');
19
21
 
20
22
  var NOOP_ARRAY = [];
21
23
 
22
- var useCheck = function useCheck(cascaded, disabled, flattedData, defaultCheckedIds, checkedIdsProp, onCheck) {
24
+ var useCheck = function useCheck(checkedMode, disabled, flattedData, defaultCheckedIds, checkedIdsProp, onCheck) {
23
25
  if (defaultCheckedIds === void 0) {
24
26
  defaultCheckedIds = NOOP_ARRAY;
25
27
  }
26
28
 
27
29
  var _useUncontrolledState = useUncontrolledState.useUncontrolledState(defaultCheckedIds, checkedIdsProp, function (checkedIds, checkedNode, shouldChecked, semiCheckedIds) {
30
+ // 出口数据处理
31
+ var processedIds = index.processCheckedIds(checkedMode, checkedIds, flattedData, allowCheck);
28
32
  onCheck === null || onCheck === void 0 ? void 0 : onCheck({
29
- checkedIds: checkedIds,
33
+ checkedIds: processedIds,
30
34
  semiCheckedIds: semiCheckedIds
31
35
  }, checkedNode, shouldChecked);
32
36
  }),
33
37
  checkedIds = _useUncontrolledState[0],
34
- trySetCheckedIds = _useUncontrolledState[1];
38
+ trySetCheckedIds = _useUncontrolledState[1]; // 入口数据处理
39
+
35
40
 
41
+ var parsedCheckedIds = index.parseCheckDataDirty(checkedMode, checkedIds, flattedData, allowCheck);
42
+ var cascaded = checkedMode !== 'SEPARATE';
36
43
  return useCheck$1.useCascadeCheck({
37
44
  cascaded: cascaded,
38
45
  disabled: disabled,
39
46
  flattedData: flattedData,
40
- checkedIds: checkedIds,
47
+ checkedIds: parsedCheckedIds,
41
48
  onCheck: trySetCheckedIds,
42
49
  allowCheck: allowCheck
43
50
  });
@@ -12,6 +12,10 @@
12
12
  Object.defineProperty(exports, '__esModule', {
13
13
  value: true
14
14
  });
15
+
16
+ var treeUtils = require('@hi-ui/tree-utils');
17
+
18
+ var typeAssertion = require('@hi-ui/type-assertion');
15
19
  /**
16
20
  * 扁平化树数据结构,基于前序遍历
17
21
  *
@@ -19,74 +23,38 @@ Object.defineProperty(exports, '__esModule', {
19
23
  * @returns
20
24
  */
21
25
 
22
- var flattenTreeData = function flattenTreeData(treeData) {
23
- var flattedTreeData = [];
24
-
25
- var dig = function dig(node, depth, parent) {
26
- var id = node.id,
27
- title = node.title,
28
- children = node.children,
29
- _node$checkable = node.checkable,
30
- checkable = _node$checkable === void 0 ? true : _node$checkable,
31
- _node$isLeaf = node.isLeaf,
32
- isLeaf = _node$isLeaf === void 0 ? false : _node$isLeaf,
33
- _node$disabled = node.disabled,
34
- disabled = _node$disabled === void 0 ? false : _node$disabled,
35
- _node$disabledCheckbo = node.disabledCheckbox,
36
- disabledCheckbox = _node$disabledCheckbo === void 0 ? false : _node$disabledCheckbo;
37
- var flattedNode = {
38
- id: id,
39
- title: title,
40
- depth: depth,
41
- parent: parent,
42
- raw: node,
43
- isLeaf: isLeaf,
44
- disabled: disabled,
45
- disabledCheckbox: disabledCheckbox,
46
- checkable: checkable
47
- };
48
- flattedTreeData.push(flattedNode);
49
-
50
- if (children) {
51
- var childDepth = depth + 1;
52
- flattedNode.children = children.map(function (child) {
53
- return dig(child, childDepth, flattedNode);
54
- });
55
- }
56
-
57
- return flattedNode;
58
- }; // @ts-ignore
59
26
 
27
+ var flattenTreeData = function flattenTreeData(treeData, fieldNames) {
28
+ /**
29
+ * 转换对象
30
+ */
31
+ var getKeyFields = function getKeyFields(node, key) {
32
+ if (fieldNames) {
33
+ return node[fieldNames[key] || key];
34
+ }
60
35
 
61
- var treeRoot = getTreeRoot(); // @ts-ignore
62
-
63
- treeRoot.children = treeData.map(function (node) {
64
- return dig(node, 0, treeRoot);
65
- });
66
- return flattedTreeData;
67
- };
68
-
69
- var getTreeRoot = function getTreeRoot() {
70
- return {
71
- depth: -1
36
+ return node[key];
72
37
  };
73
- };
74
- /**
75
- * 获取祖先节点,包括自己
76
- * @param node
77
- * @returns
78
- */
79
-
80
38
 
81
- var getNodeAncestors = function getNodeAncestors(node) {
82
- var ancestors = [];
83
-
84
- while (node.parent) {
85
- ancestors.push(node);
86
- node = node.parent;
87
- }
39
+ return treeUtils.baseFlattenTree({
40
+ tree: treeData,
41
+ childrenFieldName: function childrenFieldName(node) {
42
+ return getKeyFields(node, 'children');
43
+ },
44
+ transform: function transform(node) {
45
+ var _a, _b, _c, _d;
88
46
 
89
- return ancestors;
47
+ var flattedNode = node;
48
+ var raw = node.raw;
49
+ flattedNode.id = getKeyFields(raw, 'id');
50
+ flattedNode.title = getKeyFields(raw, 'title');
51
+ flattedNode.disabled = (_a = getKeyFields(raw, 'disabled')) !== null && _a !== void 0 ? _a : false;
52
+ flattedNode.isLeaf = (_b = getKeyFields(raw, 'isLeaf')) !== null && _b !== void 0 ? _b : false;
53
+ flattedNode.checkable = (_c = getKeyFields(raw, 'checkable')) !== null && _c !== void 0 ? _c : true;
54
+ flattedNode.disabledCheckbox = (_d = getKeyFields(raw, 'disabledCheckbox')) !== null && _d !== void 0 ? _d : false;
55
+ return flattedNode;
56
+ }
57
+ });
90
58
  };
91
59
 
92
60
  var getActiveMenus = function getActiveMenus(data, selectedIds) {
@@ -128,19 +96,162 @@ var getActiveMenuIds = function getActiveMenuIds(data, selectedIds) {
128
96
  return selectedIds === id;
129
97
  });
130
98
  if (!selectedOption) return [];
131
- return getNodeAncestors(selectedOption).map(function (_ref4) {
99
+ return treeUtils.getTopDownAncestors(selectedOption).map(function (_ref4) {
132
100
  var id = _ref4.id;
133
101
  return id;
134
- }).reverse();
102
+ });
135
103
  };
136
104
 
137
105
  function getCascaderItemEventData(node, requiredProps) {
138
106
  return Object.assign(Object.assign({}, node), requiredProps);
139
107
  }
108
+ /**
109
+ * 处理选中的回显数据
110
+ *
111
+ * @param checkedIds 当前所有被选中的节点 ID 集合
112
+ * @param nodeEntries 所有数据的Map 集合
113
+ * @param type 数据回显方式
114
+ */
115
+
116
+
117
+ var processCheckedIds = function processCheckedIds(type, checkedIds, flattenData, allowCheck) {
118
+ var keySet = new Set(checkedIds);
119
+
120
+ switch (type) {
121
+ case 'CHILD':
122
+ return checkedIds.filter(function (id) {
123
+ var node = treeUtils.fFindNodeById(flattenData, id);
124
+
125
+ if (node) {
126
+ var children = node.children;
127
+
128
+ if (typeAssertion.isArrayNonEmpty(children)) {
129
+ if (children.filter(allowCheck).every(function (node) {
130
+ return keySet.has(node.id);
131
+ })) {
132
+ return false;
133
+ }
134
+ }
135
+ } // 没有孩子节点,保留
136
+
137
+
138
+ return true;
139
+ });
140
+
141
+ case 'PARENT':
142
+ return checkedIds.filter(function (id) {
143
+ var node = treeUtils.fFindNodeById(flattenData, id);
144
+
145
+ if (node) {
146
+ // 向上递归遍历是否被勾选
147
+ var ancestors = treeUtils.getNodeAncestors(node);
148
+ console.log(ancestors);
149
+
150
+ if (ancestors.some(function (parent) {
151
+ return keySet.has(parent.id);
152
+ })) {
153
+ return false;
154
+ }
155
+ }
156
+
157
+ return true;
158
+ });
159
+ }
160
+
161
+ return checkedIds;
162
+ };
163
+ /**
164
+ * 根据传入的 checkedIds 解析全选/半选数据
165
+ */
166
+
167
+
168
+ var parseCheckDataDirty = function parseCheckDataDirty(type, checkedIds, flattenData, allowCheck) {
169
+ switch (type) {
170
+ case 'CHILD':
171
+ case 'PARENT':
172
+ return dirtyCheck(checkedIds, flattenData, allowCheck);
173
+ }
174
+
175
+ return checkedIds;
176
+ };
177
+
178
+ function dirtyCheck(checkedIds, flattenData, allowCheck) {
179
+ var nodeEntities = flattenData.reduce(function (prev, cur) {
180
+ prev[cur.id] = cur;
181
+ return prev;
182
+ }, {});
183
+ var checkedIdsSet = new Set(checkedIds.filter(function (id) {
184
+ return !!nodeEntities[id];
185
+ }));
186
+ var depthEntities = new Map();
187
+ var maxDepth = 0; // Convert entities by depth for calculation
188
+
189
+ Object.keys(nodeEntities).forEach(function (id) {
190
+ var entity = nodeEntities[id];
191
+ var depth = entity.depth;
192
+ var depthSet = depthEntities.get(depth);
193
+
194
+ if (!depthSet) {
195
+ depthSet = new Set();
196
+ depthEntities.set(depth, depthSet);
197
+ }
198
+
199
+ depthSet.add(entity);
200
+ maxDepth = Math.max(maxDepth, depth);
201
+ });
202
+ return fillCheck(checkedIdsSet, depthEntities, nodeEntities, maxDepth, allowCheck);
203
+ }
204
+ /**
205
+ * 对 checkedIds 级联遗漏选项 id 填充
206
+ *
207
+ * 1. 把所有嵌套孩子节点 allowCheck 的都标记为 checked
208
+ * 2. 祖先节点从下至上维护 checked 状态
209
+ */
210
+
211
+
212
+ function fillCheck(checkedIds, depthEntities, nodeEntities, maxDepth, allowCheck) {
213
+ var checkedIdsSet = new Set(checkedIds);
214
+ checkedIdsSet.forEach(function (id) {
215
+ var checkedNode = nodeEntities[id];
216
+ var nestedChildren = treeUtils.findNestedChildren(checkedNode, allowCheck);
217
+ nestedChildren.forEach(function (child) {
218
+ checkedIdsSet.add(child.id);
219
+ });
220
+ }); // 缓存中间结果,优化查询
221
+
222
+ var visitedIds = new Map();
223
+
224
+ for (var depth = maxDepth - 1; depth >= 0; --depth) {
225
+ var entities = depthEntities.get(depth);
226
+ entities === null || entities === void 0 ? void 0 : entities.forEach(function (entity) {
227
+ var id = entity.id,
228
+ children = entity.children;
229
+ if (visitedIds.has(id)) return;
230
+
231
+ if (typeAssertion.isArrayNonEmpty(children)) {
232
+ var shouldChecked = !children.some(function (child) {
233
+ if (visitedIds.has(child.id)) {
234
+ return !visitedIds.get(child.id);
235
+ }
236
+
237
+ return !checkedIdsSet.has(child.id);
238
+ });
239
+ visitedIds.set(id, shouldChecked);
240
+
241
+ if (shouldChecked && allowCheck(entity)) {
242
+ checkedIdsSet.add(id);
243
+ }
244
+ }
245
+ });
246
+ }
247
+
248
+ return Array.from(checkedIdsSet);
249
+ }
140
250
 
141
251
  exports.flattenTreeData = flattenTreeData;
142
252
  exports.getActiveMenuIds = getActiveMenuIds;
143
253
  exports.getActiveMenus = getActiveMenus;
144
254
  exports.getCascaderItemEventData = getCascaderItemEventData;
145
255
  exports.getFlattedMenus = getFlattedMenus;
146
- exports.getNodeAncestors = getNodeAncestors;
256
+ exports.parseCheckDataDirty = parseCheckDataDirty;
257
+ exports.processCheckedIds = processCheckedIds;
@@ -8,24 +8,20 @@
8
8
  * LICENSE file in the root directory of this source tree.
9
9
  */
10
10
  import { __rest } from 'tslib';
11
- import React, { forwardRef, useMemo, useCallback, useState } from 'react';
11
+ import React, { forwardRef, useMemo, useCallback } from 'react';
12
12
  import { getPrefixCls, cx } from '@hi-ui/classname';
13
13
  import { __DEV__ } from '@hi-ui/env';
14
14
  import { useUncontrolledToggle } from '@hi-ui/use-toggle';
15
15
  import { useUncontrolledState } from '@hi-ui/use-uncontrolled-state';
16
16
  import { UpOutlined, DownOutlined } from '@hi-ui/icons';
17
- import { matchStrategy } from './hooks/use-search.js';
18
- import '@hi-ui/use-check';
19
- import { useCache } from './hooks/use-cache.js';
20
- import '@babel/runtime/regenerator';
21
- import { useLatestCallback } from '@hi-ui/use-latest';
22
- import { getTopDownAncestors, getNodeAncestorsWithMe } from '@hi-ui/tree-utils';
17
+ import { useCache } from './hooks/use-cache/lib/esm/index.js';
23
18
  import { Picker } from '@hi-ui/picker';
24
19
  import { TagInputMock } from '@hi-ui/tag-input';
25
- import { uniqBy } from '@hi-ui/array-utils';
26
20
  import { CheckCascaderMenus } from './CheckCascaderMenus.js';
27
- import { useTreeCustomSearch, useTreeUpMatchSearch, useSearchMode } from '@hi-ui/use-search-mode';
21
+ import { useTreeCustomSearch, useTreeUpMatchSearch, useSearchMode, matchStrategy } from '@hi-ui/use-search-mode';
28
22
  import { flattenTreeData } from './utils/index.js';
23
+ import { getTopDownAncestors, getNodeAncestorsWithMe } from '@hi-ui/tree-utils';
24
+ import { useLatestCallback } from '@hi-ui/use-latest';
29
25
  import { isUndef, isArrayNonEmpty } from '@hi-ui/type-assertion';
30
26
  import { useLocaleContext } from '@hi-ui/locale-context';
31
27
  import { callAllFuncs } from '@hi-ui/func-utils';
@@ -66,9 +62,10 @@ var CheckCascader = /*#__PURE__*/forwardRef(function (_a, ref) {
66
62
  overlayClassName = _a.overlayClassName,
67
63
  _a$type = _a.type,
68
64
  type = _a$type === void 0 ? 'tree' : _a$type,
65
+ checkedMode = _a.checkedMode,
69
66
  onOpen = _a.onOpen,
70
67
  onClose = _a.onClose,
71
- rest = __rest(_a, ["prefixCls", "className", "defaultValue", "value", "onChange", "data", "placeholder", "clearable", "onSelect", "expandTrigger", "disabled", "emptyContent", "changeOnSelect", "render", "displayRender", "checkCascaded", "searchPlaceholder", "onLoadChildren", "wrap", "appearance", "invalid", "filterOption", "searchable", "onSearch", "overlayClassName", "type", "onOpen", "onClose"]);
68
+ rest = __rest(_a, ["prefixCls", "className", "defaultValue", "value", "onChange", "data", "placeholder", "clearable", "onSelect", "expandTrigger", "disabled", "emptyContent", "changeOnSelect", "render", "displayRender", "checkCascaded", "searchPlaceholder", "onLoadChildren", "appearance", "invalid", "filterOption", "searchable", "onSearch", "overlayClassName", "type", "checkedMode", "onOpen", "onClose"]);
72
69
 
73
70
  var i18n = useLocaleContext();
74
71
  var placeholder = isUndef(placeholderProp) ? i18n.get('checkCascader.placeholder') : placeholderProp;
@@ -101,6 +98,7 @@ var CheckCascader = /*#__PURE__*/forwardRef(function (_a, ref) {
101
98
 
102
99
  var proxyOnChange = useLatestCallback(function (value, item, shouldChecked) {
103
100
  var flattedItems = flattedData;
101
+ console.log(item);
104
102
  var itemsPaths = value.map(function (lastId) {
105
103
  var item = flattedItems.find(function (item) {
106
104
  return item.id === lastId;
@@ -119,20 +117,10 @@ var CheckCascader = /*#__PURE__*/forwardRef(function (_a, ref) {
119
117
  });
120
118
 
121
119
  return idPaths || [lastId];
122
- }); // const itemsPaths = flattedItems
123
- // .filter((item) => value.includes(item.id))
124
- // .map((item) => getTopDownAncestors(item).map(({ id }) => id))
125
- // TODO: 找到所有 id 的祖先节点路径
126
-
127
- tryChangeValue(itemsPaths); // 包括所有全选的数据,包括全选
128
-
129
- if (shouldChecked) {
130
- // TODO:as useCheckList
131
- setSelectedItems(function (prev) {
132
- return [].concat(prev, [item]);
133
- });
134
- }
135
- }); // ************************** 异步搜索 ************************* //
120
+ });
121
+ tryChangeValue(itemsPaths);
122
+ }); // ************************** 搜索 ************************* //
123
+ // 无法做异步搜索,因为下拉菜单不能合并(因为树形数据,不知道是第几级)
136
124
 
137
125
  var customSearchStrategy = useTreeCustomSearch({
138
126
  data: flattedData,
@@ -194,22 +182,12 @@ var CheckCascader = /*#__PURE__*/forwardRef(function (_a, ref) {
194
182
  }, resultStr), afterStr);
195
183
  }).reverse()) : true;
196
184
  return ret;
197
- }, [titleRender, searchValue, searchMode]); // 搜索时临时选中缓存数据
198
-
199
- var _useState = useState([]),
200
- selectedItems = _useState[0],
201
- setSelectedItems = _useState[1];
202
-
185
+ }, [titleRender, searchValue, searchMode]);
203
186
  var shouldUseSearch = !!searchValue;
204
187
  var selectProps = {
205
188
  data: shouldUseSearch ? stateInSearch.data : flattedData,
206
189
  titleRender: proxyTitleRender
207
- }; // 下拉菜单不能合并(因为树形数据,不知道是第几级)
208
-
209
- var mergedData = useMemo(function () {
210
- var nextData = selectedItems.concat(flattedData);
211
- return uniqBy(nextData, 'id');
212
- }, [selectedItems, flattedData]);
190
+ };
213
191
  var cls = cx(prefixCls, className, prefixCls + "--" + (menuVisible ? 'open' : 'closed'));
214
192
  return /*#__PURE__*/React.createElement(Picker, Object.assign({
215
193
  ref: ref,
@@ -240,7 +218,7 @@ var CheckCascader = /*#__PURE__*/forwardRef(function (_a, ref) {
240
218
  value: value,
241
219
  // @ts-ignore
242
220
  onChange: proxyOnChange,
243
- data: mergedData,
221
+ data: flattedData,
244
222
  invalid: invalid
245
223
  })
246
224
  }), isArrayNonEmpty(selectProps.data) ? /*#__PURE__*/React.createElement(CheckCascaderMenus, {
@@ -258,7 +236,8 @@ var CheckCascader = /*#__PURE__*/forwardRef(function (_a, ref) {
258
236
  // @ts-ignore
259
237
  flattedData: selectProps.data,
260
238
  data: cascaderData,
261
- onChangeData: setCascaderData
239
+ onChangeData: setCascaderData,
240
+ checkedMode: checkedMode
262
241
  }) : null);
263
242
  });
264
243