@hi-ui/cascader 4.1.2 → 4.1.3

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.
@@ -27,96 +27,84 @@ import { useLocaleContext } from '@hi-ui/core';
27
27
  import { callAllFuncs } from '@hi-ui/func-utils';
28
28
  import { CascaderMenuList } from './CascaderMenuList.js';
29
29
  import Highlighter from '@hi-ui/highlighter';
30
-
31
30
  var _prefix = getPrefixCls('cascader');
32
-
33
31
  var NOOP_ARRAY = [];
34
32
  /**
35
33
  * 级联选择器
36
34
  * Trigger + MenuList + Search
37
35
  */
38
-
39
36
  var Cascader = /*#__PURE__*/forwardRef(function (props, ref) {
40
37
  var _props$prefixCls = props.prefixCls,
41
- prefixCls = _props$prefixCls === void 0 ? _prefix : _props$prefixCls,
42
- className = props.className,
43
- placeholderProp = props.placeholder,
44
- _props$disabled = props.disabled,
45
- disabled = _props$disabled === void 0 ? false : _props$disabled,
46
- _props$clearable = props.clearable,
47
- clearable = _props$clearable === void 0 ? true : _props$clearable,
48
- _props$type = props.type,
49
- type = _props$type === void 0 ? 'tree' : _props$type,
50
- fieldNames = props.fieldNames,
51
- _props$expandTrigger = props.expandTrigger,
52
- expandTrigger = _props$expandTrigger === void 0 ? 'click' : _props$expandTrigger,
53
- displayRenderProp = props.displayRender,
54
- onSelectProp = props.onSelect,
55
- onLoadChildren = props.onLoadChildren,
56
- appearance = props.appearance,
57
- invalid = props.invalid,
58
- filterOption = props.filterOption,
59
- searchableProp = props.searchable,
60
- onSearchProp = props.onSearch,
61
- titleRender = props.render,
62
- overlayClassName = props.overlayClassName,
63
- _props$data = props.data,
64
- data = _props$data === void 0 ? NOOP_ARRAY : _props$data,
65
- _props$flattedSearchR = props.flattedSearchResult,
66
- flattedSearchResult = _props$flattedSearchR === void 0 ? true : _props$flattedSearchR,
67
- visible = props.visible,
68
- _props$size = props.size,
69
- size = _props$size === void 0 ? 'md' : _props$size,
70
- onOpen = props.onOpen,
71
- onClose = props.onClose,
72
- renderExtraFooter = props.renderExtraFooter,
73
- dropdownColumnRender = props.dropdownColumnRender,
74
- rest = __rest(props, ["prefixCls", "className", "placeholder", "disabled", "clearable", "type", "fieldNames", "expandTrigger", "displayRender", "onSelect", "onLoadChildren", "appearance", "invalid", "filterOption", "searchable", "onSearch", "render", "overlayClassName", "data", "flattedSearchResult", "visible", "size", "onOpen", "onClose", "renderExtraFooter", "dropdownColumnRender"]);
75
-
38
+ prefixCls = _props$prefixCls === void 0 ? _prefix : _props$prefixCls,
39
+ className = props.className,
40
+ placeholderProp = props.placeholder,
41
+ _props$disabled = props.disabled,
42
+ disabled = _props$disabled === void 0 ? false : _props$disabled,
43
+ _props$clearable = props.clearable,
44
+ clearable = _props$clearable === void 0 ? true : _props$clearable,
45
+ _props$type = props.type,
46
+ type = _props$type === void 0 ? 'tree' : _props$type,
47
+ fieldNames = props.fieldNames,
48
+ _props$expandTrigger = props.expandTrigger,
49
+ expandTrigger = _props$expandTrigger === void 0 ? 'click' : _props$expandTrigger,
50
+ displayRenderProp = props.displayRender,
51
+ onSelectProp = props.onSelect,
52
+ onLoadChildren = props.onLoadChildren,
53
+ appearance = props.appearance,
54
+ invalid = props.invalid,
55
+ filterOption = props.filterOption,
56
+ searchableProp = props.searchable,
57
+ onSearchProp = props.onSearch,
58
+ titleRender = props.render,
59
+ overlayClassName = props.overlayClassName,
60
+ _props$data = props.data,
61
+ data = _props$data === void 0 ? NOOP_ARRAY : _props$data,
62
+ _props$flattedSearchR = props.flattedSearchResult,
63
+ flattedSearchResult = _props$flattedSearchR === void 0 ? true : _props$flattedSearchR,
64
+ visible = props.visible,
65
+ _props$size = props.size,
66
+ size = _props$size === void 0 ? 'md' : _props$size,
67
+ onOpen = props.onOpen,
68
+ onClose = props.onClose,
69
+ renderExtraFooter = props.renderExtraFooter,
70
+ dropdownColumnRender = props.dropdownColumnRender,
71
+ rest = __rest(props, ["prefixCls", "className", "placeholder", "disabled", "clearable", "type", "fieldNames", "expandTrigger", "displayRender", "onSelect", "onLoadChildren", "appearance", "invalid", "filterOption", "searchable", "onSearch", "render", "overlayClassName", "data", "flattedSearchResult", "visible", "size", "onOpen", "onClose", "renderExtraFooter", "dropdownColumnRender"]);
76
72
  var i18n = useLocaleContext();
77
73
  var placeholder = isUndef(placeholderProp) ? i18n.get('cascader.placeholder') : placeholderProp;
78
-
79
74
  var _useUncontrolledToggl = useUncontrolledToggle({
80
- visible: visible,
81
- disabled: disabled,
82
- onOpen: onOpen,
83
- onClose: onClose
84
- }),
85
- menuVisible = _useUncontrolledToggl[0],
86
- menuVisibleAction = _useUncontrolledToggl[1]; // 搜索时临时选中缓存数据
87
-
88
-
75
+ visible: visible,
76
+ disabled: disabled,
77
+ onOpen: onOpen,
78
+ onClose: onClose
79
+ }),
80
+ menuVisible = _useUncontrolledToggl[0],
81
+ menuVisibleAction = _useUncontrolledToggl[1];
82
+ // 搜索时临时选中缓存数据
89
83
  var _useState = useState(null),
90
- selectedItem = _useState[0],
91
- setSelectedItem = _useState[1];
92
-
84
+ selectedItem = _useState[0],
85
+ setSelectedItem = _useState[1];
93
86
  var onSelect = function onSelect(value, item, itemPaths) {
94
87
  onSelectProp === null || onSelectProp === void 0 ? void 0 : onSelectProp(value, item, itemPaths);
95
- setSelectedItem(item); // 关闭弹窗
96
-
88
+ setSelectedItem(item);
89
+ // 关闭弹窗
97
90
  menuVisibleAction.off();
98
- }; // 拦截 titleRender,自定义高亮展示
99
-
100
-
91
+ };
92
+ // 拦截 titleRender,自定义高亮展示
101
93
  var proxyTitleRender = function proxyTitleRender(node) {
102
94
  // 本地搜索执行默认高亮规则
103
95
  var highlight = !!searchValue && searchMode === 'upMatch';
104
-
105
96
  if (highlight) {
106
97
  return flattedSearchResult ? renderHighlightTitles(searchValue, node, titleRender) : renderHighlightTitle(searchValue, node, titleRender);
107
98
  }
108
-
109
99
  return isFunction(titleRender) ? titleRender(node) : true;
110
100
  };
111
-
112
101
  var _useCache = useCache(data),
113
- cascaderData = _useCache[0],
114
- setCascaderData = _useCache[1];
115
-
102
+ cascaderData = _useCache[0],
103
+ setCascaderData = _useCache[1];
116
104
  var flattedData = useMemo(function () {
117
105
  return flattenTreeData(cascaderData, fieldNames);
118
- }, [cascaderData, fieldNames]); // ************************** 异步搜索 ************************* //
119
-
106
+ }, [cascaderData, fieldNames]);
107
+ // ************************** 异步搜索 ************************* //
120
108
  var customSearchStrategy = useTreeCustomSearch({
121
109
  data: flattedData,
122
110
  filterOption: filterOption
@@ -127,80 +115,70 @@ var Cascader = /*#__PURE__*/forwardRef(function (props, ref) {
127
115
  enabled: searchableProp,
128
116
  exclude: function exclude(node) {
129
117
  return node.disabled;
130
- } // exclude: (option: FlattedCascaderDataItem) => {
118
+ }
119
+ // exclude: (option: FlattedCascaderDataItem) => {
131
120
  // return checkCanLoadChildren(option, onLoadChildren)
132
121
  // },
133
-
134
122
  });
135
123
 
136
124
  var _useSearchMode = useSearchMode({
137
- searchable: searchableProp,
138
- strategies: [customSearchStrategy, upMatchSearchStrategy]
139
- }),
140
- stateInSearch = _useSearchMode.state,
141
- searchable = _useSearchMode.searchable,
142
- searchMode = _useSearchMode.searchMode,
143
- onSearch = _useSearchMode.onSearch,
144
- searchValue = _useSearchMode.keyword;
145
-
125
+ searchable: searchableProp,
126
+ strategies: [customSearchStrategy, upMatchSearchStrategy]
127
+ }),
128
+ stateInSearch = _useSearchMode.state,
129
+ searchable = _useSearchMode.searchable,
130
+ searchMode = _useSearchMode.searchMode,
131
+ onSearch = _useSearchMode.onSearch,
132
+ searchValue = _useSearchMode.keyword;
146
133
  var displayRender = function displayRender(item) {
147
134
  var itemPaths = getTopDownAncestors(item);
148
-
149
135
  if (displayRenderProp) {
150
136
  var eventOption = getItemEventData(item, getItemRequiredProps(item));
151
137
  return displayRenderProp(eventOption, itemPaths.map(function (item) {
152
138
  return getItemEventData(item, getItemRequiredProps(item));
153
139
  }));
154
140
  }
155
-
156
141
  var mergedTitle = itemPaths.reduce(function (acc, item, index, _ref) {
157
142
  var length = _ref.length;
158
143
  acc.push(item.title);
159
-
160
144
  if (length - 1 !== index) {
161
145
  acc.push('/');
162
146
  }
163
-
164
147
  return acc;
165
148
  }, []);
166
149
  return /*#__PURE__*/React.createElement("span", {
167
150
  className: "title__text"
168
151
  }, mergedTitle);
169
152
  };
170
-
171
- var shouldUseSearch = !!searchValue; // 搜索的结果列表也采用 flatted 模式进行展示
172
-
153
+ var shouldUseSearch = !!searchValue;
154
+ // 搜索的结果列表也采用 flatted 模式进行展示
173
155
  var flatted = shouldUseSearch ? flattedSearchResult : type === 'flatted';
174
-
175
156
  var _a = useCascader(Object.assign(Object.assign({}, rest), {
176
- disabled: disabled,
177
- fieldNames: fieldNames,
178
- flatted: flatted,
179
- onSelect: onSelect,
180
- onLoadChildren: onLoadChildren,
181
- data: data,
182
- // @ts-ignore
183
- cascaderData: cascaderData,
184
- setCascaderData: setCascaderData,
185
- flattedData: flattedData
186
- })),
187
- rootProps = _a.rootProps,
188
- context = __rest(_a, ["rootProps"]);
189
-
157
+ disabled: disabled,
158
+ fieldNames: fieldNames,
159
+ flatted: flatted,
160
+ onSelect: onSelect,
161
+ onLoadChildren: onLoadChildren,
162
+ data: data,
163
+ // @ts-ignore
164
+ cascaderData: cascaderData,
165
+ setCascaderData: setCascaderData,
166
+ flattedData: flattedData
167
+ })),
168
+ rootProps = _a.rootProps,
169
+ context = __rest(_a, ["rootProps"]);
190
170
  var value = context.value,
191
- tryChangeValue = context.tryChangeValue,
192
- reset = context.reset,
193
- menuList = context.menuList,
194
- getItemRequiredProps = context.getItemRequiredProps;
171
+ tryChangeValue = context.tryChangeValue,
172
+ reset = context.reset,
173
+ menuList = context.menuList,
174
+ getItemRequiredProps = context.getItemRequiredProps;
195
175
  var showData = useMemo(function () {
196
176
  if (shouldUseSearch) {
197
177
  if (!flattedSearchResult) {
198
178
  return getFilteredMenuList(menuList, stateInSearch.data);
199
179
  }
200
-
201
180
  return isArrayNonEmpty(stateInSearch.data) ? [stateInSearch.data] : [];
202
181
  }
203
-
204
182
  return menuList;
205
183
  }, [shouldUseSearch, flattedSearchResult, stateInSearch.data, menuList]);
206
184
  useEffect(function () {
@@ -208,14 +186,13 @@ var Cascader = /*#__PURE__*/forwardRef(function (props, ref) {
208
186
  if (!menuVisible) {
209
187
  reset();
210
188
  }
211
- }, [menuVisible, reset]); // 下拉菜单不能合并(因为树形数据,不知道是第几级)
212
-
189
+ }, [menuVisible, reset]);
190
+ // 下拉菜单不能合并(因为树形数据,不知道是第几级)
213
191
  var mergedData = useMemo(function () {
214
192
  if (selectedItem) {
215
193
  var nextData = [selectedItem].concat(flattedData);
216
194
  return uniqBy(nextData, 'id');
217
195
  }
218
-
219
196
  return flattedData;
220
197
  }, [selectedItem, flattedData]);
221
198
  var cls = cx(prefixCls, className, prefixCls + "--" + (menuVisible ? 'open' : 'closed'));
@@ -260,11 +237,9 @@ var Cascader = /*#__PURE__*/forwardRef(function (props, ref) {
260
237
  })
261
238
  }), isArrayNonEmpty(showData) ? /*#__PURE__*/React.createElement(CascaderMenuList, null) : null));
262
239
  });
263
-
264
240
  if (__DEV__) {
265
241
  Cascader.displayName = 'Cascader';
266
242
  }
267
-
268
243
  var renderHighlightTitle = function renderHighlightTitle(keyword, option, titleRender) {
269
244
  // 如果 titleRender 返回 `true`,则使用默认 title
270
245
  var title = titleRender ? titleRender(option, keyword) : true;
@@ -274,23 +249,20 @@ var renderHighlightTitle = function renderHighlightTitle(keyword, option, titleR
274
249
  keyword: keyword
275
250
  }, option.title);
276
251
  };
277
-
278
252
  var renderHighlightTitles = function renderHighlightTitles(keyword, option, titleRender) {
279
253
  // 如果 titleRender 返回 `true`,则使用默认 title
280
254
  var title = titleRender ? titleRender(option, keyword) : true;
281
255
  if (title !== true) return title;
282
-
283
256
  if (typeof option.title !== 'string') {
284
257
  console.info('WARNING: The `option.title` should be `string` when searchable is enabled.');
285
258
  return option.title;
286
259
  }
287
-
288
260
  var found = false;
289
261
  return /*#__PURE__*/React.createElement("span", {
290
262
  className: cx("title__text", "title__text--cols")
291
263
  }, getNodeAncestorsWithMe(option).map(function (item) {
292
264
  var title = item.title,
293
- id = item.id;
265
+ id = item.id;
294
266
  var raw = /*#__PURE__*/React.createElement("span", {
295
267
  className: "title__text--col",
296
268
  key: id
@@ -310,5 +282,4 @@ var renderHighlightTitles = function renderHighlightTitles(keyword, option, titl
310
282
  }, keyword), afterStr);
311
283
  }).reverse());
312
284
  };
313
-
314
285
  export { Cascader };
@@ -19,15 +19,13 @@ import { isArrayNonEmpty, isFunction } from '@hi-ui/type-assertion';
19
19
  var menuListPrefix = getPrefixCls('cascader-menu-list');
20
20
  var CascaderMenuList = /*#__PURE__*/forwardRef(function (_a, ref) {
21
21
  var _a$prefixCls = _a.prefixCls,
22
- prefixCls = _a$prefixCls === void 0 ? menuListPrefix : _a$prefixCls,
23
- className = _a.className,
24
- rest = __rest(_a, ["prefixCls", "className"]);
25
-
22
+ prefixCls = _a$prefixCls === void 0 ? menuListPrefix : _a$prefixCls,
23
+ className = _a.className,
24
+ rest = __rest(_a, ["prefixCls", "className"]);
26
25
  var _useCascaderContext = useCascaderContext(),
27
- flatted = _useCascaderContext.flatted,
28
- menuList = _useCascaderContext.menuList,
29
- dropdownColumnRender = _useCascaderContext.dropdownColumnRender;
30
-
26
+ flatted = _useCascaderContext.flatted,
27
+ menuList = _useCascaderContext.menuList,
28
+ dropdownColumnRender = _useCascaderContext.dropdownColumnRender;
31
29
  var cls = cx(prefixCls, className, flatted && prefixCls + "--flatted");
32
30
  return /*#__PURE__*/React.createElement("div", Object.assign({
33
31
  ref: ref,
@@ -42,32 +40,27 @@ var CascaderMenuList = /*#__PURE__*/forwardRef(function (_a, ref) {
42
40
  }) : null;
43
41
  }));
44
42
  });
45
-
46
43
  if (__DEV__) {
47
44
  CascaderMenuList.displayName = 'CascaderMenuList';
48
45
  }
49
-
50
46
  var menuPrefix = getPrefixCls('cascader-menu');
51
-
52
47
  var CascaderMenu = function CascaderMenu(_ref) {
53
48
  var _ref$prefixCls = _ref.prefixCls,
54
- prefixCls = _ref$prefixCls === void 0 ? menuPrefix : _ref$prefixCls,
55
- _ref$role = _ref.role,
56
- role = _ref$role === void 0 ? 'menu' : _ref$role,
57
- className = _ref.className,
58
- style = _ref.style,
59
- menu = _ref.data;
60
-
49
+ prefixCls = _ref$prefixCls === void 0 ? menuPrefix : _ref$prefixCls,
50
+ _ref$role = _ref.role,
51
+ role = _ref$role === void 0 ? 'menu' : _ref$role,
52
+ className = _ref.className,
53
+ style = _ref.style,
54
+ menu = _ref.data;
61
55
  var _useCascaderContext2 = useCascaderContext(),
62
- flatted = _useCascaderContext2.flatted,
63
- disabledContext = _useCascaderContext2.disabled,
64
- expandTrigger = _useCascaderContext2.expandTrigger,
65
- onItemClick = _useCascaderContext2.onItemClick,
66
- onItemHover = _useCascaderContext2.onItemHover,
67
- titleRender = _useCascaderContext2.titleRender,
68
- onLoadChildren = _useCascaderContext2.onLoadChildren,
69
- getItemRequiredProps = _useCascaderContext2.getItemRequiredProps;
70
-
56
+ flatted = _useCascaderContext2.flatted,
57
+ disabledContext = _useCascaderContext2.disabled,
58
+ expandTrigger = _useCascaderContext2.expandTrigger,
59
+ onItemClick = _useCascaderContext2.onItemClick,
60
+ onItemHover = _useCascaderContext2.onItemHover,
61
+ titleRender = _useCascaderContext2.titleRender,
62
+ onLoadChildren = _useCascaderContext2.onLoadChildren,
63
+ getItemRequiredProps = _useCascaderContext2.getItemRequiredProps;
71
64
  var cls = cx(prefixCls, className);
72
65
  return /*#__PURE__*/React.createElement("ul", {
73
66
  className: cls,
@@ -76,8 +69,8 @@ var CascaderMenu = function CascaderMenu(_ref) {
76
69
  }, menu.map(function (option) {
77
70
  var eventOption = getItemEventData(option, getItemRequiredProps(option));
78
71
  var selected = eventOption.selected,
79
- loading = eventOption.loading,
80
- active = eventOption.active;
72
+ loading = eventOption.loading,
73
+ active = eventOption.active;
81
74
  var disabled = disabledContext || option.disabled;
82
75
  var optionCls = cx(prefixCls + "-option", active && prefixCls + "-option--active", loading && prefixCls + "-option--loading", disabled && prefixCls + "-option--disabled", selected && prefixCls + "-option--selected");
83
76
  return /*#__PURE__*/React.createElement("li", {
@@ -92,7 +85,6 @@ var CascaderMenu = function CascaderMenu(_ref) {
92
85
  },
93
86
  onMouseEnter: function onMouseEnter() {
94
87
  if (disabled) return;
95
-
96
88
  if (expandTrigger === 'hover') {
97
89
  onItemHover(eventOption);
98
90
  }
@@ -103,28 +95,22 @@ var CascaderMenu = function CascaderMenu(_ref) {
103
95
  /**
104
96
  * 渲染菜单子项的展开提示图标
105
97
  */
106
-
107
-
108
98
  var renderSuffix = function renderSuffix(prefixCls, item, loading, onLoadChildren) {
109
99
  if (loading) {
110
100
  return /*#__PURE__*/React.createElement("span", {
111
101
  className: cx(prefixCls + "-switcher", prefixCls + "-switcher--loading")
112
102
  }, defaultLoadingIcon);
113
103
  }
114
-
115
104
  var canLoadChildren = checkCanLoadChildren(item, onLoadChildren);
116
-
117
105
  if (canLoadChildren) {
118
106
  return /*#__PURE__*/React.createElement("span", {
119
107
  className: cx(prefixCls + "-switcher", prefixCls + "-switcher--arrow")
120
108
  }, defaultSuffixIcon);
121
109
  }
122
-
123
110
  return /*#__PURE__*/React.createElement("span", {
124
111
  className: cx(prefixCls + "-switcher", prefixCls + "-switcher--noop")
125
112
  }, defaultLeafIcon);
126
113
  };
127
-
128
114
  var renderFlattedTitle = function renderFlattedTitle(option, titleRender) {
129
115
  // 如果 titleRender 返回 `true`,则使用默认 title
130
116
  var title = titleRender ? titleRender(option) : true;
@@ -138,7 +124,6 @@ var renderFlattedTitle = function renderFlattedTitle(option, titleRender) {
138
124
  }, item.title);
139
125
  }));
140
126
  };
141
-
142
127
  var renderDefaultTitle = function renderDefaultTitle(option, titleRender) {
143
128
  // 如果 titleRender 返回 `true`,则使用默认 title
144
129
  var title = titleRender ? titleRender(option) : true;
@@ -147,5 +132,4 @@ var renderDefaultTitle = function renderDefaultTitle(option, titleRender) {
147
132
  className: "title__text"
148
133
  }, option.title);
149
134
  };
150
-
151
135
  export { CascaderMenu, CascaderMenuList };
@@ -10,15 +10,11 @@
10
10
  import { useContext, createContext } from 'react';
11
11
  var cascaderContext = /*#__PURE__*/createContext(null);
12
12
  var CascaderProvider = cascaderContext.Provider;
13
-
14
13
  var useCascaderContext = function useCascaderContext() {
15
14
  var context = useContext(cascaderContext);
16
-
17
15
  if (!context) {
18
16
  throw new Error('The cascaderContext context should using in Cascader.');
19
17
  }
20
-
21
18
  return context;
22
19
  };
23
-
24
20
  export { CascaderProvider, useCascaderContext };
@@ -13,10 +13,9 @@ import { useCallback } from 'react';
13
13
  import { useLatestCallback } from '@hi-ui/use-latest';
14
14
  import { cloneTree, addChildrenById, getTopDownAncestors } from '@hi-ui/tree-utils';
15
15
  import { useCheckState } from '@hi-ui/use-check-state';
16
-
17
16
  var useAsyncSwitch = function useAsyncSwitch(setCascaderData, onExpand, onLoadChildren) {
18
- var onLoadChildrenLatest = useLatestCallback(onLoadChildren); // 加载节点
19
-
17
+ var onLoadChildrenLatest = useLatestCallback(onLoadChildren);
18
+ // 加载节点
20
19
  var loadChildren = useCallback(function (node) {
21
20
  return __awaiter(void 0, void 0, void 0, /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
22
21
  var childrenNodes;
@@ -29,10 +28,8 @@ var useAsyncSwitch = function useAsyncSwitch(setCascaderData, onExpand, onLoadCh
29
28
  var id = _ref.id;
30
29
  return id;
31
30
  }));
32
-
33
31
  case 2:
34
32
  childrenNodes = _context.sent;
35
-
36
33
  if (Array.isArray(childrenNodes)) {
37
34
  setCascaderData(function (prev) {
38
35
  var nextTreeData = cloneTree(prev);
@@ -40,7 +37,6 @@ var useAsyncSwitch = function useAsyncSwitch(setCascaderData, onExpand, onLoadCh
40
37
  return nextTreeData;
41
38
  });
42
39
  }
43
-
44
40
  case 4:
45
41
  case "end":
46
42
  return _context.stop();
@@ -49,18 +45,15 @@ var useAsyncSwitch = function useAsyncSwitch(setCascaderData, onExpand, onLoadCh
49
45
  }, _callee);
50
46
  }));
51
47
  }, [onLoadChildrenLatest, setCascaderData]);
52
-
53
48
  var _useCheckState = useCheckState(),
54
- isLoadingId = _useCheckState.has,
55
- addLoadingIds = _useCheckState.add,
56
- removeLoadingIds = _useCheckState.remove;
57
-
49
+ isLoadingId = _useCheckState.has,
50
+ addLoadingIds = _useCheckState.add,
51
+ removeLoadingIds = _useCheckState.remove;
58
52
  var onExpandLatest = useLatestCallback(onExpand);
59
53
  var onNodeSwitch = useCallback(function (node, onlyExpand) {
60
54
  if (onlyExpand === void 0) {
61
55
  onlyExpand = false;
62
56
  }
63
-
64
57
  return __awaiter(void 0, void 0, void 0, /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
65
58
  var id, children, isLeaf;
66
59
  return _regeneratorRuntime.wrap(function _callee2$(_context2) {
@@ -70,43 +63,34 @@ var useAsyncSwitch = function useAsyncSwitch(setCascaderData, onExpand, onLoadCh
70
63
  // 直接触发选中该节点
71
64
  onExpandLatest(node, onlyExpand);
72
65
  id = node.id, children = node.children, isLeaf = node.isLeaf;
73
-
74
66
  if (!children) {
75
67
  _context2.next = 4;
76
68
  break;
77
69
  }
78
-
79
70
  return _context2.abrupt("return");
80
-
81
71
  case 4:
82
72
  if (!isLeaf) {
83
73
  _context2.next = 6;
84
74
  break;
85
75
  }
86
-
87
76
  return _context2.abrupt("return");
88
-
89
77
  case 6:
90
78
  if (!onLoadChildren) {
91
79
  _context2.next = 17;
92
80
  break;
93
81
  }
94
-
95
82
  addLoadingIds(id);
96
83
  _context2.prev = 8;
97
84
  _context2.next = 11;
98
85
  return loadChildren(node);
99
-
100
86
  case 11:
101
87
  removeLoadingIds(id);
102
88
  _context2.next = 17;
103
89
  break;
104
-
105
90
  case 14:
106
91
  _context2.prev = 14;
107
92
  _context2.t0 = _context2["catch"](8);
108
93
  removeLoadingIds(id);
109
-
110
94
  case 17:
111
95
  case "end":
112
96
  return _context2.stop();
@@ -117,5 +101,4 @@ var useAsyncSwitch = function useAsyncSwitch(setCascaderData, onExpand, onLoadCh
117
101
  }, [loadChildren, onLoadChildren, onExpandLatest, addLoadingIds, removeLoadingIds]);
118
102
  return [isLoadingId, onNodeSwitch];
119
103
  };
120
-
121
104
  export { useAsyncSwitch };
@@ -8,6 +8,7 @@
8
8
  * LICENSE file in the root directory of this source tree.
9
9
  */
10
10
  import { useState, useEffect } from 'react';
11
+
11
12
  /** @LICENSE
12
13
  * @hi-ui/use-cache
13
14
  * https://github.com/XiaoMi/hiui/tree/master/packages/hooks/use-cache#readme
@@ -21,16 +22,13 @@ import { useState, useEffect } from 'react';
21
22
  /**
22
23
  * A hook using for data cache that compatible with the controlled and uncontrolled modes coexist.
23
24
  */
24
-
25
25
  var useCache = function useCache(data) {
26
26
  var _useState = useState(data),
27
- internalData = _useState[0],
28
- setInternalData = _useState[1];
29
-
27
+ internalData = _useState[0],
28
+ setInternalData = _useState[1];
30
29
  useEffect(function () {
31
30
  setInternalData(data);
32
31
  }, [data]);
33
32
  return [internalData, setInternalData];
34
33
  };
35
-
36
34
  export { useCache };
@@ -11,20 +11,17 @@ import { useState, useCallback } from 'react';
11
11
  import { useLatestCallback } from '@hi-ui/use-latest';
12
12
  import { getTopDownAncestors } from '@hi-ui/tree-utils';
13
13
  import { checkCanLoadChildren } from '../utils/index.js';
14
+
14
15
  /**
15
16
  * 用于选中的 hook
16
17
  */
17
-
18
18
  var useSelect = function useSelect(disabled, onSelect, changeOnSelect, onLoadChildren) {
19
19
  var onSelectLatest = useLatestCallback(onSelect);
20
-
21
20
  var _useState = useState(''),
22
- selectedId = _useState[0],
23
- setSelectedId = _useState[1];
24
-
21
+ selectedId = _useState[0],
22
+ setSelectedId = _useState[1];
25
23
  var proxyOnSelect = useCallback(function (selectedId, selectOption) {
26
24
  var optionPaths = getTopDownAncestors(selectOption);
27
-
28
25
  if (changeOnSelect) {
29
26
  // 任意选中
30
27
  onSelectLatest(selectedId, selectOption, optionPaths);
@@ -38,11 +35,9 @@ var useSelect = function useSelect(disabled, onSelect, changeOnSelect, onLoadChi
38
35
  var onItemSelect = useCallback(function (targetItem, onlyExpand) {
39
36
  if (disabled) return;
40
37
  if (targetItem.disabled) return;
41
-
42
38
  if (onlyExpand) {
43
39
  // 仅展开,不做选中处理
44
40
  var canLoadChildren = checkCanLoadChildren(targetItem, onLoadChildren);
45
-
46
41
  if (canLoadChildren) {
47
42
  setSelectedId(targetItem.id);
48
43
  }
@@ -53,5 +48,4 @@ var useSelect = function useSelect(disabled, onSelect, changeOnSelect, onLoadChi
53
48
  }, [disabled, proxyOnSelect, onLoadChildren]);
54
49
  return [selectedId, onItemSelect, setSelectedId];
55
50
  };
56
-
57
51
  export { useSelect };
@@ -9,7 +9,5 @@
9
9
  */
10
10
  import __styleInject__ from 'style-inject';
11
11
  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);}}";
12
-
13
12
  __styleInject__(css_248z);
14
-
15
13
  export { css_248z as default };