@sheinx/base 3.0.10 → 3.0.11

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.
@@ -1 +1 @@
1
- {"version":3,"file":"cascader.d.ts","sourceRoot":"","sources":["cascader.tsx"],"names":[],"mappings":";AAEA,OAAO,EAML,YAAY,EAIb,MAAM,eAAe,CAAC;AAMvB,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAYhD,QAAA,MAAM,QAAQ,iGA+rBb,CAAC;AACF,eAAe,QAAQ,CAAC"}
1
+ {"version":3,"file":"cascader.d.ts","sourceRoot":"","sources":["cascader.tsx"],"names":[],"mappings":";AAEA,OAAO,EAML,YAAY,EAIb,MAAM,eAAe,CAAC;AAMvB,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAYhD,QAAA,MAAM,QAAQ,iGA8rBb,CAAC;AACF,eAAe,QAAQ,CAAC"}
@@ -330,8 +330,8 @@ var Cascader = function Cascader(props0) {
330
330
  if (!path) return;
331
331
  handlePathChange(id, null, path);
332
332
  };
333
- var handleRemove = function handleRemove(item, key, index) {
334
- var dataKey = _hooks.util.isUnMatchedData(item) ? item.value : datum.getKey(item, key, index);
333
+ var handleRemove = function handleRemove(item, key) {
334
+ var dataKey = key !== null && key !== void 0 ? key : _hooks.util.isUnMatchedData(item) ? item.value : datum.getKey(item);
335
335
  var isDisabled = datum.isDisabled(dataKey);
336
336
  if (isDisabled) return;
337
337
  datum.set(dataKey, 0);
@@ -1 +1 @@
1
- {"version":3,"file":"result.d.ts","sourceRoot":"","sources":["result.tsx"],"names":[],"mappings":";AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAQ5C,QAAA,MAAM,MAAM,uEAkXX,CAAC;AAEF,eAAe,MAAM,CAAC"}
1
+ {"version":3,"file":"result.d.ts","sourceRoot":"","sources":["result.tsx"],"names":[],"mappings":";AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAQ5C,QAAA,MAAM,MAAM,uEA8WX,CAAC;AAEF,eAAe,MAAM,CAAC"}
@@ -29,7 +29,6 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
29
29
  var isObject = _hooks.util.isObject,
30
30
  isEmpty = _hooks.util.isEmpty,
31
31
  isNumber = _hooks.util.isNumber,
32
- getKey = _hooks.util.getKey,
33
32
  isUnMatchedData = _hooks.util.isUnMatchedData,
34
33
  isFunc = _hooks.util.isFunc,
35
34
  isArray = _hooks.util.isArray;
@@ -66,7 +65,7 @@ var Result = function Result(props) {
66
65
  onRemove = props.onRemove,
67
66
  onResultItemClick = props.onResultItemClick,
68
67
  data = props.data;
69
- var value = [null, undefined, ''].includes(valueProp) ? [] : multiple ? valueProp : [valueProp];
68
+ var value = [null, undefined, ''].includes(valueProp) ? [] : Array.isArray(valueProp) ? valueProp : [valueProp];
70
69
  var _useState = (0, _react.useState)(-1),
71
70
  _useState2 = _slicedToArray(_useState, 2),
72
71
  more = _useState2[0],
@@ -142,20 +141,9 @@ var Result = function Result(props) {
142
141
  })
143
142
  }, 'input');
144
143
  };
145
- var renderResultItem = function renderResultItem(item, index, nodes) {
146
- var key;
147
- if (isUnMatchedData(item)) {
148
- if (isFunc(keygen)) {
149
- key = keygen(item.value, index);
150
- if (key === undefined) key = index;
151
- } else {
152
- key = item.value;
153
- }
154
- } else {
155
- key = getKey(keygen, item, index);
156
- }
144
+ var renderResultItem = function renderResultItem(item, index, nodes, v) {
157
145
  var handleClose = function handleClose() {
158
- onRemove === null || onRemove === void 0 || onRemove(item, key, index);
146
+ onRemove === null || onRemove === void 0 || onRemove(item, v);
159
147
  };
160
148
  var isDisabled;
161
149
  if (_hooks.util.isFunc(disabled)) {
@@ -165,7 +153,7 @@ var Result = function Result(props) {
165
153
  }
166
154
  var resultClassName;
167
155
  if (_hooks.util.isFunc(props.resultClassName)) {
168
- resultClassName = props.resultClassName(key);
156
+ resultClassName = props.resultClassName(isUnMatchedData(item) ? item.value : item);
169
157
  } else {
170
158
  resultClassName = props.resultClassName;
171
159
  }
@@ -175,8 +163,9 @@ var Result = function Result(props) {
175
163
  var content = renderResultContent(item, index, nodes);
176
164
  if (!content) return null;
177
165
  if (renderResultContentProp) {
166
+ // cascader 不渲染tag
178
167
  return renderResultContentProp(_objectSpread({
179
- key: key,
168
+ key: index,
180
169
  size: size,
181
170
  disabled: isDisabled,
182
171
  className: (0, _classnames.default)(styles.tag, styles.hideTag, resultClassName),
@@ -202,7 +191,7 @@ var Result = function Result(props) {
202
191
  type: disabled === true ? 'dark' : undefined
203
192
  })), {}, {
204
193
  children: content
205
- }), key);
194
+ }), index);
206
195
  };
207
196
  var renderNbsp = function renderNbsp() {
208
197
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.default.Fragment, {
@@ -233,22 +222,28 @@ var Result = function Result(props) {
233
222
  children: content
234
223
  }, 'single');
235
224
  };
225
+ var getValueArr = function getValueArr(v) {
226
+ return (isArray(v) ? v : [v]).filter(function (v) {
227
+ return v !== undefined && v !== null;
228
+ });
229
+ };
236
230
  var renderMultipleResult = function renderMultipleResult() {
237
231
  if (isEmptyResult()) return renderNbsp();
238
232
  // [TODO] separator 处理逻辑后续交给 hooks 处理,此处临时处理
239
- var nextValue = value;
233
+ var nextValue = getValueArr(value);
240
234
  if (separator && _hooks.util.isString(valueProp)) {
241
235
  nextValue = valueProp.split(separator);
242
236
  }
243
- var values = getDataByValues(nextValue);
244
- var result = values.map(function (v, i) {
245
- if (renderResultContentProp && i !== values.length - 1) {
246
- return [renderResultItem(v, i, values), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
237
+ var datas = getDataByValues(nextValue);
238
+ var result = datas.map(function (d, i) {
239
+ var v = nextValue[i];
240
+ if (renderResultContentProp && i !== datas.length - 1) {
241
+ return [renderResultItem(d, i, datas, v), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
247
242
  className: (0, _classnames.default)(styles.tag, styles.hideTag),
248
243
  children: "/"
249
244
  }, "separator-".concat(i))];
250
245
  }
251
- return renderResultItem(v, i, values);
246
+ return renderResultItem(d, i, datas, v);
252
247
  });
253
248
  return result;
254
249
  };
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react';
2
- import { TreeContextProps, TreeProviderProps } from './tree-context.type';
3
- export declare const TreeContext: React.Context<TreeContextProps<any>>;
2
+ import { TreeProviderProps } from './tree-context.type';
3
+ export declare const TreeContext: React.Context<import("../../../hooks/src/components/use-tree/use-tree.type").TreeDatum<any>>;
4
4
  export declare const Provider: <DataItem>(props: TreeProviderProps<DataItem>) => JSX.Element;
5
- export declare const useTreeContext: () => TreeContextProps<any>;
5
+ export declare const useTreeContext: () => import("../../../hooks/src/components/use-tree/use-tree.type").TreeDatum<any>;
6
6
  //# sourceMappingURL=tree-context.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tree-context.d.ts","sourceRoot":"","sources":["tree-context.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAE1E,eAAO,MAAM,WAAW,sCAA0E,CAAC;AAEnG,eAAO,MAAM,QAAQ,+DAGpB,CAAC;AAEF,eAAO,MAAM,cAAc,6BAAsC,CAAC"}
1
+ {"version":3,"file":"tree-context.d.ts","sourceRoot":"","sources":["tree-context.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAoB,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAE1E,eAAO,MAAM,WAAW,8FAA0E,CAAC;AAEnG,eAAO,MAAM,QAAQ,+DAGpB,CAAC;AAEF,eAAO,MAAM,cAAc,qFAAsC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"tree.d.ts","sourceRoot":"","sources":["tree.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,YAAY,EAAyC,MAAM,eAAe,CAAC;AAEpF,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAMxC,QAAA,MAAM,IAAI,4FA4OT,CAAC;AAEF,eAAe,IAAI,CAAC"}
1
+ {"version":3,"file":"tree.d.ts","sourceRoot":"","sources":["tree.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,YAAY,EAA4B,MAAM,eAAe,CAAC;AAEvE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAMxC,QAAA,MAAM,IAAI,4FA8NT,CAAC;AAEF,eAAe,IAAI,CAAC"}
package/cjs/tree/tree.js CHANGED
@@ -11,7 +11,7 @@ var _hooks = require("@sheinx/hooks");
11
11
  var _treeRoot = _interopRequireDefault(require("./tree-root"));
12
12
  var _treeContext = require("./tree-context");
13
13
  var _jsxRuntime = require("react/jsx-runtime");
14
- var _excluded = ["jssStyle", "line", "childrenKey", "data", "value", "mode", "keygen", "expanded", "expandIcons", "iconClass", "leafClass", "nodeClass", "contentClass", "renderItem", "defaultValue", "dataUpdate", "childrenClass", "defaultExpandAll", "defaultExpanded", "parentClickExpand", "doubleClickExpand", "dragImageSelector", "dragImageStyle", "dragSibling", "unmatch", "dragHoverExpand", "active", "disabled", "inlineNode", "highlight", "className", "onClick", "loader", "getDatum", "onDrop", "onExpand", "onChange", "onDragEnd", "onDragLeave", "onDragOver", "onDragStart", "keepCache"];
14
+ var _excluded = ["jssStyle", "line", "childrenKey", "data", "value", "mode", "keygen", "expanded", "expandIcons", "iconClass", "leafClass", "nodeClass", "contentClass", "renderItem", "defaultValue", "dataUpdate", "childrenClass", "defaultExpandAll", "defaultExpanded", "parentClickExpand", "doubleClickExpand", "dragImageSelector", "dragImageStyle", "dragSibling", "unmatch", "dragHoverExpand", "active", "disabled", "inlineNode", "highlight", "className", "onClick", "loader", "getDatum", "onDrop", "onExpand", "onChange", "onDragEnd", "onDragLeave", "onDragOver", "onDragStart", "datum"];
15
15
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
16
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
17
17
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
@@ -73,9 +73,8 @@ var Tree = function Tree(props) {
73
73
  onDragLeave = props.onDragLeave,
74
74
  onDragOver = props.onDragOver,
75
75
  onDragStart = props.onDragStart,
76
- keepCache = props.keepCache,
76
+ propsDatum = props.datum,
77
77
  rest = _objectWithoutProperties(props, _excluded);
78
- var prevData = (0, _hooks.usePrevious)(data);
79
78
  var _useTree = (0, _hooks.useTree)({
80
79
  mode: mode,
81
80
  value: value,
@@ -92,7 +91,7 @@ var Tree = function Tree(props) {
92
91
  childrenKey: childrenKey,
93
92
  keygen: keygen,
94
93
  onExpand: onExpandProp,
95
- keepCache: keepCache
94
+ datum: propsDatum
96
95
  }),
97
96
  datum = _useTree.datum,
98
97
  expanded = _useTree.expanded,
@@ -193,16 +192,6 @@ var Tree = function Tree(props) {
193
192
  (0, _react.useEffect)(function () {
194
193
  handleUpdateExpanded(expanded);
195
194
  }, [expanded]);
196
- (0, _react.useEffect)(function () {
197
- if (!prevData) return;
198
- if (prevData !== data && dataUpdate) {
199
- datum.setData(data);
200
- }
201
- }, [data]);
202
- (0, _react.useEffect)(function () {
203
- if (!value) return;
204
- datum.setValue(value);
205
- }, [value]);
206
195
  (0, _react.useEffect)(function () {
207
196
  if (getDatum) getDatum(datum);
208
197
  }, []);
@@ -1 +1 @@
1
- {"version":3,"file":"tree-select.d.ts","sourceRoot":"","sources":["tree-select.tsx"],"names":[],"mappings":";AACA,OAAO,EAQL,YAAY,EAEb,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,eAAe,EAAc,MAAM,oBAAoB,CAAC;AAcjE,MAAM,MAAM,mBAAmB,GAAG,YAAY,GAAG,YAAY,EAAE,CAAC;AAIhE,QAAA,MAAM,UAAU,wGA8mBf,CAAC;AAEF,eAAe,UAAU,CAAC"}
1
+ {"version":3,"file":"tree-select.d.ts","sourceRoot":"","sources":["tree-select.tsx"],"names":[],"mappings":";AACA,OAAO,EAQL,YAAY,EAEb,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,eAAe,EAAc,MAAM,oBAAoB,CAAC;AAajE,MAAM,MAAM,mBAAmB,GAAG,YAAY,GAAG,YAAY,EAAE,CAAC;AAIhE,QAAA,MAAM,UAAU,wGA8oBf,CAAC;AAEF,eAAe,UAAU,CAAC"}
@@ -39,7 +39,6 @@ var preventDefault = function preventDefault(e) {
39
39
  var TreeSelect = function TreeSelect(props0) {
40
40
  var _jssStyle$treeSelect;
41
41
  var props = (0, _useWithFormConfig.default)(props0);
42
- var render = (0, _hooks.useRender)();
43
42
  var _useConfig = (0, _config.useConfig)(),
44
43
  locale = _useConfig.locale;
45
44
  var jssStyle = props.jssStyle,
@@ -47,9 +46,11 @@ var TreeSelect = function TreeSelect(props0) {
47
46
  size = props.size,
48
47
  valueProp = props.value,
49
48
  defaultValue = props.defaultValue,
50
- data = props.data,
49
+ _props$data = props.data,
50
+ data = _props$data === void 0 ? [] : _props$data,
51
51
  multiple = props.multiple,
52
- mode = props.mode,
52
+ _props$mode = props.mode,
53
+ mode = _props$mode === void 0 ? 1 : _props$mode,
53
54
  _props$line = props.line,
54
55
  line = _props$line === void 0 ? false : _props$line,
55
56
  innerTitle = props.innerTitle,
@@ -109,9 +110,12 @@ var TreeSelect = function TreeSelect(props0) {
109
110
  width: width
110
111
  }, style);
111
112
  var showInput = _hooks.util.isFunc(props.onAdvancedFilter || onFilterProp);
112
- var datum = (0, _react.useRef)();
113
113
  var blurEvent = (0, _react.useRef)();
114
114
  var inputRef = (0, _react.useRef)();
115
+ var _useRef = (0, _react.useRef)({
116
+ cachedMap: new Map()
117
+ }),
118
+ context = _useRef.current;
115
119
  var _useState = (0, _react.useState)(false),
116
120
  _useState2 = _slicedToArray(_useState, 2),
117
121
  focused = _useState2[0],
@@ -121,7 +125,8 @@ var TreeSelect = function TreeSelect(props0) {
121
125
  onChange: onChangeProp,
122
126
  defaultValue: defaultValue,
123
127
  control: 'value' in props,
124
- filterSameChange: filterSameChange
128
+ filterSameChange: filterSameChange,
129
+ multiple: multiple
125
130
  }),
126
131
  value = _useTreeSelect.value,
127
132
  onChange = _useTreeSelect.onChange;
@@ -152,6 +157,23 @@ var TreeSelect = function TreeSelect(props0) {
152
157
  onFilter = _useFilter.onFilter,
153
158
  onClearCreatedData = _useFilter.onClearCreatedData,
154
159
  setInputText = _useFilter.setInputText;
160
+ var controlExpanded = 'expanded' in props || expanded !== null && expanded !== void 0 && expanded.length ? expanded : undefined;
161
+ var _useTree = (0, _hooks.useTree)({
162
+ mode: mode,
163
+ value: value,
164
+ data: data,
165
+ unmatch: unmatch,
166
+ disabled: disabled,
167
+ childrenKey: childrenKey,
168
+ keygen: keygen,
169
+ onExpand: onExpand,
170
+ expanded: controlExpanded,
171
+ defaultExpanded: defaultExpanded,
172
+ defaultExpandAll: defaultExpandAll,
173
+ isControlled: controlExpanded !== undefined
174
+ }),
175
+ datum = _useTree.datum,
176
+ onExpandTree = _useTree.onExpand;
155
177
  var renderMoreIcon = function renderMoreIcon() {
156
178
  return _icons.default.treeSelect.More;
157
179
  };
@@ -202,10 +224,6 @@ var TreeSelect = function TreeSelect(props0) {
202
224
  jssStyle: props.jssStyle
203
225
  });
204
226
  var rootClass = (0, _classnames.default)(className, isEmpty && styles.wrapperEmpty, styles === null || styles === void 0 ? void 0 : styles.wrapper, open && (styles === null || styles === void 0 ? void 0 : styles.wrapperOpen), disabled === true && (styles === null || styles === void 0 ? void 0 : styles.wrapperDisabled), !!open && (styles === null || styles === void 0 ? void 0 : styles.wrapperFocus), disabled !== true && focused && (styles === null || styles === void 0 ? void 0 : styles.wrapperFocus), innerTitle && (styles === null || styles === void 0 ? void 0 : styles.wrapperInnerTitle), size === 'small' && (styles === null || styles === void 0 ? void 0 : styles.wrapperSmall), size === 'large' && (styles === null || styles === void 0 ? void 0 : styles.wrapperLarge), (!!props.error || props.status === 'error') && (styles === null || styles === void 0 ? void 0 : styles.wrapperError), clearable && (styles === null || styles === void 0 ? void 0 : styles.clearable), !border && (styles === null || styles === void 0 ? void 0 : styles.wrapperNoBorder), !!underline && (styles === null || styles === void 0 ? void 0 : styles.wrapperUnderline), _defineProperty({}, styles === null || styles === void 0 ? void 0 : styles.multiple, multiple));
205
- var bindTreeDatum = function bindTreeDatum(treeDatum) {
206
- datum.current = treeDatum;
207
- render();
208
- };
209
227
  var getRenderItem = function getRenderItem(data, expanded, active, id) {
210
228
  return typeof renderItemProp === 'function' ? renderItemProp(data, expanded, active, id) : data[renderItemProp];
211
229
  };
@@ -261,9 +279,9 @@ var TreeSelect = function TreeSelect(props0) {
261
279
  };
262
280
  var handleClear = function handleClear(e) {
263
281
  e.stopPropagation();
264
- if (!datum.current) return;
265
- datum.current.setValue([]);
266
- onChange(multiple ? [] : '');
282
+ if (!datum) return;
283
+ datum.setValue([]);
284
+ onChange(multiple ? [] : ['']);
267
285
  if (onChangeAddition) {
268
286
  onChangeAddition({
269
287
  data: multiple ? [] : null
@@ -271,9 +289,6 @@ var TreeSelect = function TreeSelect(props0) {
271
289
  }
272
290
  if (open) closePop();
273
291
  };
274
- var handleExpand = function handleExpand(expands) {
275
- onExpand === null || onExpand === void 0 || onExpand(expands);
276
- };
277
292
  var renderClearable = function renderClearable() {
278
293
  if (!multiple !== undefined && !showArrow) return null;
279
294
  var defaultIcon = multiple ? _icons.default.treeSelect.More : _icons.default.treeSelect.DropdownArrow;
@@ -303,37 +318,43 @@ var TreeSelect = function TreeSelect(props0) {
303
318
  children: defaultIcon
304
319
  });
305
320
  };
321
+ var getDataById = (0, _hooks.usePersistFn)(function (id) {
322
+ if (!props.noCache) {
323
+ if (context.cachedMap.has(id)) {
324
+ return context.cachedMap.get(id);
325
+ }
326
+ }
327
+ if (!datum) return undefined;
328
+ var origin = datum === null || datum === void 0 ? void 0 : datum.getDataById(id);
329
+ if (!props.noCache && !(datum !== null && datum !== void 0 && datum.isUnMatched(origin))) {
330
+ context.cachedMap.set(id, origin);
331
+ }
332
+ return origin;
333
+ });
306
334
  var getDataByValues = function getDataByValues(values) {
307
- if (!datum.current || !values) return [];
308
- return datum.current.getDataByValues(values);
335
+ if (!datum || !values) return [];
336
+ return datum.getDataByValues(values);
309
337
  };
310
338
  var getDataByValuesRef = function getDataByValuesRef(values) {
311
- var _datum$current2;
312
339
  if (_hooks.util.isArray(values)) {
313
340
  return values.map(function (id) {
314
- var _datum$current;
315
- return (_datum$current = datum.current) === null || _datum$current === void 0 ? void 0 : _datum$current.getDataById(id);
341
+ return datum === null || datum === void 0 ? void 0 : datum.getDataById(id);
316
342
  });
317
343
  }
318
- return (_datum$current2 = datum.current) === null || _datum$current2 === void 0 ? void 0 : _datum$current2.getDataById(values);
344
+ return datum === null || datum === void 0 ? void 0 : datum.getDataById(values);
319
345
  };
320
346
  var getValue = function getValue() {
321
- if (!datum.current) return;
322
- var nextValue = datum.current.getValue();
347
+ if (!datum) return;
348
+ var nextValue = datum.getValue();
323
349
  if (multiple) return nextValue;
324
- return nextValue.length ? nextValue[0] : '';
325
- };
326
- var getValueArray = function getValueArray(value) {
327
- if (!value) return [];
328
- if (!Array.isArray(value)) return [value];
329
- return value;
350
+ if (nextValue.length === 0) return [];
351
+ return [nextValue[0]];
330
352
  };
331
353
  var getContentClass = function getContentClass(data) {
332
- var _datum$current3, _datum$current4;
333
- if (!datum.current) return '';
334
- var key = datum.current.getKey(data);
335
- var isDisabled = (_datum$current3 = datum.current) === null || _datum$current3 === void 0 ? void 0 : _datum$current3.isDisabled(key);
336
- var isCheck = (_datum$current4 = datum.current) === null || _datum$current4 === void 0 ? void 0 : _datum$current4.getChecked(key);
354
+ if (!datum) return '';
355
+ var key = datum.getKey(data);
356
+ var isDisabled = datum === null || datum === void 0 ? void 0 : datum.isDisabled(key);
357
+ var isCheck = datum === null || datum === void 0 ? void 0 : datum.getChecked(key);
337
358
  if (isDisabled) {
338
359
  return (0, _classnames.default)(styles.optionDisabled);
339
360
  }
@@ -364,46 +385,62 @@ var TreeSelect = function TreeSelect(props0) {
364
385
  onTiledFilter === null || onTiledFilter === void 0 || onTiledFilter(trim ? text.trim() : text);
365
386
  };
366
387
  var handleChange = function handleChange(item, id) {
367
- var _datum$current5;
368
- if (!datum.current) return;
369
- if (disabled === true || (_datum$current5 = datum.current) !== null && _datum$current5 !== void 0 && _datum$current5.isDisabled(id)) return;
370
- var currentData = datum.current.getDataById(id);
388
+ if (disabled === true || datum !== null && datum !== void 0 && datum.isDisabled(id)) return;
389
+ var currentData = datum.getDataById(id);
371
390
  if (!multiple) {
372
- datum.current.setValue([]);
373
- datum.current.set(datum.current.getKey(item), 1);
391
+ datum.setValue([]);
392
+ datum.set(datum.getKey(item), 1);
374
393
  }
375
394
  var nextValue = getValue();
376
395
  if (onChange) {
377
- onChange(nextValue, currentData, id ? (datum.current.getPath(id) || {}).path : undefined);
396
+ onChange(nextValue, currentData, id ? (datum.getPath(id) || {}).path : undefined);
378
397
  }
379
398
  if (typeof onChangeAddition === 'function') {
380
399
  onChangeAddition({
381
400
  data: getDataByValues(nextValue),
382
- checked: multiple ? datum.current.get(id) : undefined,
401
+ checked: multiple ? datum.get(id) : undefined,
383
402
  current: currentData
384
403
  });
385
404
  }
386
405
  };
387
- var handleTreeChange = function handleTreeChange(item, id) {
406
+ var handleTreeClick = function handleTreeClick(item, id) {
388
407
  handleChange(item, id);
389
- if (!multiple) closePop();
408
+ closePop();
390
409
  };
391
- var handleRemove = function handleRemove(item, key, index) {
392
- if (!datum.current) return;
393
- var dataKey = _hooks.util.isUnMatchedData(item) ? item.value : datum.current.getKey(item, key, index);
394
- var isDisabled = datum.current.isDisabled(dataKey);
410
+ var handleTreeChange = function handleTreeChange(_value, id) {
411
+ var item = datum.getDataById(id);
412
+ handleChange(item, id);
413
+ };
414
+ var handleRemove = function handleRemove(item, key) {
415
+ if (!datum) return;
416
+ var dataKey = key !== null && key !== void 0 ? key : _hooks.util.isUnMatchedData(item) ? item.value : datum.getKey(item);
417
+ var isDisabled = datum.isDisabled(dataKey);
395
418
  if (isDisabled) return;
396
- datum.current.set(dataKey, 0);
397
- handleChange(item, datum.current.getKey(item, key, index));
419
+ datum.set(dataKey, 0);
420
+ handleChange(item, dataKey);
398
421
  };
399
422
 
400
423
  // innerTitle 模式
401
424
  var renderInnerTitle = (0, _useInnerTitle.default)({
402
- open: open || !!value,
425
+ open: open || !!(value && value.length),
403
426
  size: size,
404
427
  jssStyle: jssStyle,
405
428
  innerTitle: innerTitle
406
429
  });
430
+ var getResultByValue = (0, _hooks.usePersistFn)(function (arr) {
431
+ var result = (Array.isArray(arr) ? arr : [arr]).map(function (id) {
432
+ return getDataById(id);
433
+ }).filter(function (item) {
434
+ return item !== undefined;
435
+ });
436
+ return result;
437
+ });
438
+ var getResultValue = function getResultValue() {
439
+ if (!multiple && Array.isArray(value)) {
440
+ return value[0];
441
+ }
442
+ return value;
443
+ };
407
444
  var renderResult = function renderResult() {
408
445
  var result = /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
409
446
  className: (0, _classnames.default)(styles === null || styles === void 0 ? void 0 : styles.result),
@@ -411,13 +448,11 @@ var TreeSelect = function TreeSelect(props0) {
411
448
  trim: trim,
412
449
  jssStyle: jssStyle,
413
450
  size: size,
414
- value: value,
415
- data: tiledData,
451
+ value: getResultValue(),
452
+ data: data,
416
453
  focus: open,
417
454
  keygen: keygen,
418
- disabled: disabled
419
- // maxLength={maxLength}
420
- ,
455
+ disabled: disabled,
421
456
  compressed: compressed,
422
457
  compressedBound: compressedBound,
423
458
  compressedClassName: compressedClassName,
@@ -436,7 +471,7 @@ var TreeSelect = function TreeSelect(props0) {
436
471
  onRef: inputRef,
437
472
  checkUnMatched: checkUnMatched,
438
473
  onClearCreatedData: onClearCreatedData,
439
- getDataByValues: getDataByValues,
474
+ getDataByValues: getResultByValue,
440
475
  onRemove: handleRemove,
441
476
  classes: styles,
442
477
  setInputText: setInputText
@@ -492,14 +527,13 @@ var TreeSelect = function TreeSelect(props0) {
492
527
  if (multiple) {
493
528
  treeProps.onChange = handleTreeChange;
494
529
  } else {
495
- treeProps.onClick = handleTreeChange;
530
+ treeProps.onClick = handleTreeClick;
496
531
  treeProps.renderItem = renderActive;
497
532
  treeProps.active = value;
498
533
  }
499
534
  if ('expanded' in props) {
500
535
  treeProps.expanded = expanded;
501
536
  }
502
- var nextValue = getValueArray(value);
503
537
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
504
538
  className: (0, _classnames.default)(styles.tree),
505
539
  style: {
@@ -507,30 +541,28 @@ var TreeSelect = function TreeSelect(props0) {
507
541
  },
508
542
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_tree.default, _objectSpread(_objectSpread({
509
543
  jssStyle: jssStyle,
510
- getDatum: bindTreeDatum,
511
544
  renderItem: renderItem
512
545
  }, treeProps), {}, {
513
- keepCache: !props.noCache,
514
546
  line: line,
515
547
  mode: mode,
516
548
  data: tiledData,
517
549
  keygen: keygen,
518
550
  unmatch: unmatch,
519
- value: nextValue,
551
+ value: value,
520
552
  loader: loader,
521
- expanded: 'expanded' in props || expanded !== null && expanded !== void 0 && expanded.length ? expanded : undefined,
553
+ onExpand: onExpandTree,
554
+ expanded: controlExpanded,
555
+ defaultExpandAll: defaultExpandAll,
522
556
  expandIcons: tiledExpandIcons,
523
557
  disabled: disabled,
524
558
  parentClickExpand: parentClickExpand,
525
- defaultExpanded: defaultExpanded,
526
- defaultExpandAll: defaultExpandAll,
527
559
  contentClass: getContentClass,
528
- onExpand: handleExpand
560
+ datum: datum
529
561
  }))
530
562
  });
531
563
  };
532
564
  (0, _react.useEffect)(function () {
533
- if (getComponentRef && datum.current) {
565
+ if (getComponentRef && datum) {
534
566
  if (_hooks.util.isFunc(getComponentRef)) {
535
567
  getComponentRef({
536
568
  getDataByValues: getDataByValuesRef
@@ -1 +1 @@
1
- {"version":3,"file":"cascader.d.ts","sourceRoot":"","sources":["cascader.tsx"],"names":[],"mappings":";AAEA,OAAO,EAML,YAAY,EAIb,MAAM,eAAe,CAAC;AAMvB,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAYhD,QAAA,MAAM,QAAQ,iGA+rBb,CAAC;AACF,eAAe,QAAQ,CAAC"}
1
+ {"version":3,"file":"cascader.d.ts","sourceRoot":"","sources":["cascader.tsx"],"names":[],"mappings":";AAEA,OAAO,EAML,YAAY,EAIb,MAAM,eAAe,CAAC;AAMvB,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAYhD,QAAA,MAAM,QAAQ,iGA8rBb,CAAC;AACF,eAAe,QAAQ,CAAC"}
@@ -323,8 +323,8 @@ var Cascader = function Cascader(props0) {
323
323
  if (!path) return;
324
324
  handlePathChange(id, null, path);
325
325
  };
326
- var handleRemove = function handleRemove(item, key, index) {
327
- var dataKey = util.isUnMatchedData(item) ? item.value : datum.getKey(item, key, index);
326
+ var handleRemove = function handleRemove(item, key) {
327
+ var dataKey = key !== null && key !== void 0 ? key : util.isUnMatchedData(item) ? item.value : datum.getKey(item);
328
328
  var isDisabled = datum.isDisabled(dataKey);
329
329
  if (isDisabled) return;
330
330
  datum.set(dataKey, 0);
@@ -1 +1 @@
1
- {"version":3,"file":"result.d.ts","sourceRoot":"","sources":["result.tsx"],"names":[],"mappings":";AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAQ5C,QAAA,MAAM,MAAM,uEAkXX,CAAC;AAEF,eAAe,MAAM,CAAC"}
1
+ {"version":3,"file":"result.d.ts","sourceRoot":"","sources":["result.tsx"],"names":[],"mappings":";AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAQ5C,QAAA,MAAM,MAAM,uEA8WX,CAAC;AAEF,eAAe,MAAM,CAAC"}
@@ -21,7 +21,6 @@ import { jsx as _jsx } from "react/jsx-runtime";
21
21
  var isObject = util.isObject,
22
22
  isEmpty = util.isEmpty,
23
23
  isNumber = util.isNumber,
24
- getKey = util.getKey,
25
24
  isUnMatchedData = util.isUnMatchedData,
26
25
  isFunc = util.isFunc,
27
26
  isArray = util.isArray;
@@ -58,7 +57,7 @@ var Result = function Result(props) {
58
57
  onRemove = props.onRemove,
59
58
  onResultItemClick = props.onResultItemClick,
60
59
  data = props.data;
61
- var value = [null, undefined, ''].includes(valueProp) ? [] : multiple ? valueProp : [valueProp];
60
+ var value = [null, undefined, ''].includes(valueProp) ? [] : Array.isArray(valueProp) ? valueProp : [valueProp];
62
61
  var _useState = useState(-1),
63
62
  _useState2 = _slicedToArray(_useState, 2),
64
63
  more = _useState2[0],
@@ -134,20 +133,9 @@ var Result = function Result(props) {
134
133
  })
135
134
  }, 'input');
136
135
  };
137
- var renderResultItem = function renderResultItem(item, index, nodes) {
138
- var key;
139
- if (isUnMatchedData(item)) {
140
- if (isFunc(keygen)) {
141
- key = keygen(item.value, index);
142
- if (key === undefined) key = index;
143
- } else {
144
- key = item.value;
145
- }
146
- } else {
147
- key = getKey(keygen, item, index);
148
- }
136
+ var renderResultItem = function renderResultItem(item, index, nodes, v) {
149
137
  var handleClose = function handleClose() {
150
- onRemove === null || onRemove === void 0 || onRemove(item, key, index);
138
+ onRemove === null || onRemove === void 0 || onRemove(item, v);
151
139
  };
152
140
  var isDisabled;
153
141
  if (util.isFunc(disabled)) {
@@ -157,7 +145,7 @@ var Result = function Result(props) {
157
145
  }
158
146
  var resultClassName;
159
147
  if (util.isFunc(props.resultClassName)) {
160
- resultClassName = props.resultClassName(key);
148
+ resultClassName = props.resultClassName(isUnMatchedData(item) ? item.value : item);
161
149
  } else {
162
150
  resultClassName = props.resultClassName;
163
151
  }
@@ -167,8 +155,9 @@ var Result = function Result(props) {
167
155
  var content = renderResultContent(item, index, nodes);
168
156
  if (!content) return null;
169
157
  if (renderResultContentProp) {
158
+ // cascader 不渲染tag
170
159
  return renderResultContentProp(_objectSpread({
171
- key: key,
160
+ key: index,
172
161
  size: size,
173
162
  disabled: isDisabled,
174
163
  className: classNames(styles.tag, styles.hideTag, resultClassName),
@@ -194,7 +183,7 @@ var Result = function Result(props) {
194
183
  type: disabled === true ? 'dark' : undefined
195
184
  })), {}, {
196
185
  children: content
197
- }), key);
186
+ }), index);
198
187
  };
199
188
  var renderNbsp = function renderNbsp() {
200
189
  return /*#__PURE__*/_jsx(React.Fragment, {
@@ -225,22 +214,28 @@ var Result = function Result(props) {
225
214
  children: content
226
215
  }, 'single');
227
216
  };
217
+ var getValueArr = function getValueArr(v) {
218
+ return (isArray(v) ? v : [v]).filter(function (v) {
219
+ return v !== undefined && v !== null;
220
+ });
221
+ };
228
222
  var renderMultipleResult = function renderMultipleResult() {
229
223
  if (isEmptyResult()) return renderNbsp();
230
224
  // [TODO] separator 处理逻辑后续交给 hooks 处理,此处临时处理
231
- var nextValue = value;
225
+ var nextValue = getValueArr(value);
232
226
  if (separator && util.isString(valueProp)) {
233
227
  nextValue = valueProp.split(separator);
234
228
  }
235
- var values = getDataByValues(nextValue);
236
- var result = values.map(function (v, i) {
237
- if (renderResultContentProp && i !== values.length - 1) {
238
- return [renderResultItem(v, i, values), /*#__PURE__*/_jsx("span", {
229
+ var datas = getDataByValues(nextValue);
230
+ var result = datas.map(function (d, i) {
231
+ var v = nextValue[i];
232
+ if (renderResultContentProp && i !== datas.length - 1) {
233
+ return [renderResultItem(d, i, datas, v), /*#__PURE__*/_jsx("span", {
239
234
  className: classNames(styles.tag, styles.hideTag),
240
235
  children: "/"
241
236
  }, "separator-".concat(i))];
242
237
  }
243
- return renderResultItem(v, i, values);
238
+ return renderResultItem(d, i, datas, v);
244
239
  });
245
240
  return result;
246
241
  };
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react';
2
- import { TreeContextProps, TreeProviderProps } from './tree-context.type';
3
- export declare const TreeContext: React.Context<TreeContextProps<any>>;
2
+ import { TreeProviderProps } from './tree-context.type';
3
+ export declare const TreeContext: React.Context<import("../../../hooks/src/components/use-tree/use-tree.type").TreeDatum<any>>;
4
4
  export declare const Provider: <DataItem>(props: TreeProviderProps<DataItem>) => JSX.Element;
5
- export declare const useTreeContext: () => TreeContextProps<any>;
5
+ export declare const useTreeContext: () => import("../../../hooks/src/components/use-tree/use-tree.type").TreeDatum<any>;
6
6
  //# sourceMappingURL=tree-context.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tree-context.d.ts","sourceRoot":"","sources":["tree-context.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAE1E,eAAO,MAAM,WAAW,sCAA0E,CAAC;AAEnG,eAAO,MAAM,QAAQ,+DAGpB,CAAC;AAEF,eAAO,MAAM,cAAc,6BAAsC,CAAC"}
1
+ {"version":3,"file":"tree-context.d.ts","sourceRoot":"","sources":["tree-context.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAoB,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAE1E,eAAO,MAAM,WAAW,8FAA0E,CAAC;AAEnG,eAAO,MAAM,QAAQ,+DAGpB,CAAC;AAEF,eAAO,MAAM,cAAc,qFAAsC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"tree.d.ts","sourceRoot":"","sources":["tree.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,YAAY,EAAyC,MAAM,eAAe,CAAC;AAEpF,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAMxC,QAAA,MAAM,IAAI,4FA4OT,CAAC;AAEF,eAAe,IAAI,CAAC"}
1
+ {"version":3,"file":"tree.d.ts","sourceRoot":"","sources":["tree.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,YAAY,EAA4B,MAAM,eAAe,CAAC;AAEvE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAMxC,QAAA,MAAM,IAAI,4FA8NT,CAAC;AAEF,eAAe,IAAI,CAAC"}
package/esm/tree/tree.js CHANGED
@@ -1,5 +1,5 @@
1
1
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
- var _excluded = ["jssStyle", "line", "childrenKey", "data", "value", "mode", "keygen", "expanded", "expandIcons", "iconClass", "leafClass", "nodeClass", "contentClass", "renderItem", "defaultValue", "dataUpdate", "childrenClass", "defaultExpandAll", "defaultExpanded", "parentClickExpand", "doubleClickExpand", "dragImageSelector", "dragImageStyle", "dragSibling", "unmatch", "dragHoverExpand", "active", "disabled", "inlineNode", "highlight", "className", "onClick", "loader", "getDatum", "onDrop", "onExpand", "onChange", "onDragEnd", "onDragLeave", "onDragOver", "onDragStart", "keepCache"];
2
+ var _excluded = ["jssStyle", "line", "childrenKey", "data", "value", "mode", "keygen", "expanded", "expandIcons", "iconClass", "leafClass", "nodeClass", "contentClass", "renderItem", "defaultValue", "dataUpdate", "childrenClass", "defaultExpandAll", "defaultExpanded", "parentClickExpand", "doubleClickExpand", "dragImageSelector", "dragImageStyle", "dragSibling", "unmatch", "dragHoverExpand", "active", "disabled", "inlineNode", "highlight", "className", "onClick", "loader", "getDatum", "onDrop", "onExpand", "onChange", "onDragEnd", "onDragLeave", "onDragOver", "onDragStart", "datum"];
3
3
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
4
4
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
5
5
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
@@ -15,7 +15,7 @@ function _objectWithoutProperties(source, excluded) { if (source == null) return
15
15
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
16
16
  import { useEffect } from 'react';
17
17
  import classNames from 'classnames';
18
- import { useTree, util, usePrevious } from '@sheinx/hooks';
18
+ import { useTree, util } from '@sheinx/hooks';
19
19
  import RootTree from "./tree-root";
20
20
  import { Provider } from "./tree-context";
21
21
  import { jsx as _jsx } from "react/jsx-runtime";
@@ -66,9 +66,8 @@ var Tree = function Tree(props) {
66
66
  onDragLeave = props.onDragLeave,
67
67
  onDragOver = props.onDragOver,
68
68
  onDragStart = props.onDragStart,
69
- keepCache = props.keepCache,
69
+ propsDatum = props.datum,
70
70
  rest = _objectWithoutProperties(props, _excluded);
71
- var prevData = usePrevious(data);
72
71
  var _useTree = useTree({
73
72
  mode: mode,
74
73
  value: value,
@@ -85,7 +84,7 @@ var Tree = function Tree(props) {
85
84
  childrenKey: childrenKey,
86
85
  keygen: keygen,
87
86
  onExpand: onExpandProp,
88
- keepCache: keepCache
87
+ datum: propsDatum
89
88
  }),
90
89
  datum = _useTree.datum,
91
90
  expanded = _useTree.expanded,
@@ -186,16 +185,6 @@ var Tree = function Tree(props) {
186
185
  useEffect(function () {
187
186
  handleUpdateExpanded(expanded);
188
187
  }, [expanded]);
189
- useEffect(function () {
190
- if (!prevData) return;
191
- if (prevData !== data && dataUpdate) {
192
- datum.setData(data);
193
- }
194
- }, [data]);
195
- useEffect(function () {
196
- if (!value) return;
197
- datum.setValue(value);
198
- }, [value]);
199
188
  useEffect(function () {
200
189
  if (getDatum) getDatum(datum);
201
190
  }, []);
@@ -1 +1 @@
1
- {"version":3,"file":"tree-select.d.ts","sourceRoot":"","sources":["tree-select.tsx"],"names":[],"mappings":";AACA,OAAO,EAQL,YAAY,EAEb,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,eAAe,EAAc,MAAM,oBAAoB,CAAC;AAcjE,MAAM,MAAM,mBAAmB,GAAG,YAAY,GAAG,YAAY,EAAE,CAAC;AAIhE,QAAA,MAAM,UAAU,wGA8mBf,CAAC;AAEF,eAAe,UAAU,CAAC"}
1
+ {"version":3,"file":"tree-select.d.ts","sourceRoot":"","sources":["tree-select.tsx"],"names":[],"mappings":";AACA,OAAO,EAQL,YAAY,EAEb,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,eAAe,EAAc,MAAM,oBAAoB,CAAC;AAajE,MAAM,MAAM,mBAAmB,GAAG,YAAY,GAAG,YAAY,EAAE,CAAC;AAIhE,QAAA,MAAM,UAAU,wGA8oBf,CAAC;AAEF,eAAe,UAAU,CAAC"}
@@ -11,7 +11,7 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
11
11
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
12
12
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
13
13
  import React, { useRef, useEffect, useState } from 'react';
14
- import { util, usePersistFn, useTiled, usePopup, useTreeSelect, useFilter, useRender } from '@sheinx/hooks';
14
+ import { util, usePersistFn, useTiled, usePopup, useTreeSelect, useFilter, useTree } from '@sheinx/hooks';
15
15
  import classNames from 'classnames';
16
16
  import { AbsoluteList } from "../absolute-list";
17
17
  import useInnerTitle from "../common/use-inner-title";
@@ -32,7 +32,6 @@ var preventDefault = function preventDefault(e) {
32
32
  var TreeSelect = function TreeSelect(props0) {
33
33
  var _jssStyle$treeSelect;
34
34
  var props = useWithFormConfig(props0);
35
- var render = useRender();
36
35
  var _useConfig = useConfig(),
37
36
  locale = _useConfig.locale;
38
37
  var jssStyle = props.jssStyle,
@@ -40,9 +39,11 @@ var TreeSelect = function TreeSelect(props0) {
40
39
  size = props.size,
41
40
  valueProp = props.value,
42
41
  defaultValue = props.defaultValue,
43
- data = props.data,
42
+ _props$data = props.data,
43
+ data = _props$data === void 0 ? [] : _props$data,
44
44
  multiple = props.multiple,
45
- mode = props.mode,
45
+ _props$mode = props.mode,
46
+ mode = _props$mode === void 0 ? 1 : _props$mode,
46
47
  _props$line = props.line,
47
48
  line = _props$line === void 0 ? false : _props$line,
48
49
  innerTitle = props.innerTitle,
@@ -102,9 +103,12 @@ var TreeSelect = function TreeSelect(props0) {
102
103
  width: width
103
104
  }, style);
104
105
  var showInput = util.isFunc(props.onAdvancedFilter || onFilterProp);
105
- var datum = useRef();
106
106
  var blurEvent = useRef();
107
107
  var inputRef = useRef();
108
+ var _useRef = useRef({
109
+ cachedMap: new Map()
110
+ }),
111
+ context = _useRef.current;
108
112
  var _useState = useState(false),
109
113
  _useState2 = _slicedToArray(_useState, 2),
110
114
  focused = _useState2[0],
@@ -114,7 +118,8 @@ var TreeSelect = function TreeSelect(props0) {
114
118
  onChange: onChangeProp,
115
119
  defaultValue: defaultValue,
116
120
  control: 'value' in props,
117
- filterSameChange: filterSameChange
121
+ filterSameChange: filterSameChange,
122
+ multiple: multiple
118
123
  }),
119
124
  value = _useTreeSelect.value,
120
125
  onChange = _useTreeSelect.onChange;
@@ -145,6 +150,23 @@ var TreeSelect = function TreeSelect(props0) {
145
150
  onFilter = _useFilter.onFilter,
146
151
  onClearCreatedData = _useFilter.onClearCreatedData,
147
152
  setInputText = _useFilter.setInputText;
153
+ var controlExpanded = 'expanded' in props || expanded !== null && expanded !== void 0 && expanded.length ? expanded : undefined;
154
+ var _useTree = useTree({
155
+ mode: mode,
156
+ value: value,
157
+ data: data,
158
+ unmatch: unmatch,
159
+ disabled: disabled,
160
+ childrenKey: childrenKey,
161
+ keygen: keygen,
162
+ onExpand: onExpand,
163
+ expanded: controlExpanded,
164
+ defaultExpanded: defaultExpanded,
165
+ defaultExpandAll: defaultExpandAll,
166
+ isControlled: controlExpanded !== undefined
167
+ }),
168
+ datum = _useTree.datum,
169
+ onExpandTree = _useTree.onExpand;
148
170
  var renderMoreIcon = function renderMoreIcon() {
149
171
  return Icons.treeSelect.More;
150
172
  };
@@ -195,10 +217,6 @@ var TreeSelect = function TreeSelect(props0) {
195
217
  jssStyle: props.jssStyle
196
218
  });
197
219
  var rootClass = classNames(className, isEmpty && styles.wrapperEmpty, styles === null || styles === void 0 ? void 0 : styles.wrapper, open && (styles === null || styles === void 0 ? void 0 : styles.wrapperOpen), disabled === true && (styles === null || styles === void 0 ? void 0 : styles.wrapperDisabled), !!open && (styles === null || styles === void 0 ? void 0 : styles.wrapperFocus), disabled !== true && focused && (styles === null || styles === void 0 ? void 0 : styles.wrapperFocus), innerTitle && (styles === null || styles === void 0 ? void 0 : styles.wrapperInnerTitle), size === 'small' && (styles === null || styles === void 0 ? void 0 : styles.wrapperSmall), size === 'large' && (styles === null || styles === void 0 ? void 0 : styles.wrapperLarge), (!!props.error || props.status === 'error') && (styles === null || styles === void 0 ? void 0 : styles.wrapperError), clearable && (styles === null || styles === void 0 ? void 0 : styles.clearable), !border && (styles === null || styles === void 0 ? void 0 : styles.wrapperNoBorder), !!underline && (styles === null || styles === void 0 ? void 0 : styles.wrapperUnderline), _defineProperty({}, styles === null || styles === void 0 ? void 0 : styles.multiple, multiple));
198
- var bindTreeDatum = function bindTreeDatum(treeDatum) {
199
- datum.current = treeDatum;
200
- render();
201
- };
202
220
  var getRenderItem = function getRenderItem(data, expanded, active, id) {
203
221
  return typeof renderItemProp === 'function' ? renderItemProp(data, expanded, active, id) : data[renderItemProp];
204
222
  };
@@ -254,9 +272,9 @@ var TreeSelect = function TreeSelect(props0) {
254
272
  };
255
273
  var handleClear = function handleClear(e) {
256
274
  e.stopPropagation();
257
- if (!datum.current) return;
258
- datum.current.setValue([]);
259
- onChange(multiple ? [] : '');
275
+ if (!datum) return;
276
+ datum.setValue([]);
277
+ onChange(multiple ? [] : ['']);
260
278
  if (onChangeAddition) {
261
279
  onChangeAddition({
262
280
  data: multiple ? [] : null
@@ -264,9 +282,6 @@ var TreeSelect = function TreeSelect(props0) {
264
282
  }
265
283
  if (open) closePop();
266
284
  };
267
- var handleExpand = function handleExpand(expands) {
268
- onExpand === null || onExpand === void 0 || onExpand(expands);
269
- };
270
285
  var renderClearable = function renderClearable() {
271
286
  if (!multiple !== undefined && !showArrow) return null;
272
287
  var defaultIcon = multiple ? Icons.treeSelect.More : Icons.treeSelect.DropdownArrow;
@@ -296,37 +311,43 @@ var TreeSelect = function TreeSelect(props0) {
296
311
  children: defaultIcon
297
312
  });
298
313
  };
314
+ var getDataById = usePersistFn(function (id) {
315
+ if (!props.noCache) {
316
+ if (context.cachedMap.has(id)) {
317
+ return context.cachedMap.get(id);
318
+ }
319
+ }
320
+ if (!datum) return undefined;
321
+ var origin = datum === null || datum === void 0 ? void 0 : datum.getDataById(id);
322
+ if (!props.noCache && !(datum !== null && datum !== void 0 && datum.isUnMatched(origin))) {
323
+ context.cachedMap.set(id, origin);
324
+ }
325
+ return origin;
326
+ });
299
327
  var getDataByValues = function getDataByValues(values) {
300
- if (!datum.current || !values) return [];
301
- return datum.current.getDataByValues(values);
328
+ if (!datum || !values) return [];
329
+ return datum.getDataByValues(values);
302
330
  };
303
331
  var getDataByValuesRef = function getDataByValuesRef(values) {
304
- var _datum$current2;
305
332
  if (util.isArray(values)) {
306
333
  return values.map(function (id) {
307
- var _datum$current;
308
- return (_datum$current = datum.current) === null || _datum$current === void 0 ? void 0 : _datum$current.getDataById(id);
334
+ return datum === null || datum === void 0 ? void 0 : datum.getDataById(id);
309
335
  });
310
336
  }
311
- return (_datum$current2 = datum.current) === null || _datum$current2 === void 0 ? void 0 : _datum$current2.getDataById(values);
337
+ return datum === null || datum === void 0 ? void 0 : datum.getDataById(values);
312
338
  };
313
339
  var getValue = function getValue() {
314
- if (!datum.current) return;
315
- var nextValue = datum.current.getValue();
340
+ if (!datum) return;
341
+ var nextValue = datum.getValue();
316
342
  if (multiple) return nextValue;
317
- return nextValue.length ? nextValue[0] : '';
318
- };
319
- var getValueArray = function getValueArray(value) {
320
- if (!value) return [];
321
- if (!Array.isArray(value)) return [value];
322
- return value;
343
+ if (nextValue.length === 0) return [];
344
+ return [nextValue[0]];
323
345
  };
324
346
  var getContentClass = function getContentClass(data) {
325
- var _datum$current3, _datum$current4;
326
- if (!datum.current) return '';
327
- var key = datum.current.getKey(data);
328
- var isDisabled = (_datum$current3 = datum.current) === null || _datum$current3 === void 0 ? void 0 : _datum$current3.isDisabled(key);
329
- var isCheck = (_datum$current4 = datum.current) === null || _datum$current4 === void 0 ? void 0 : _datum$current4.getChecked(key);
347
+ if (!datum) return '';
348
+ var key = datum.getKey(data);
349
+ var isDisabled = datum === null || datum === void 0 ? void 0 : datum.isDisabled(key);
350
+ var isCheck = datum === null || datum === void 0 ? void 0 : datum.getChecked(key);
330
351
  if (isDisabled) {
331
352
  return classNames(styles.optionDisabled);
332
353
  }
@@ -357,46 +378,62 @@ var TreeSelect = function TreeSelect(props0) {
357
378
  onTiledFilter === null || onTiledFilter === void 0 || onTiledFilter(trim ? text.trim() : text);
358
379
  };
359
380
  var handleChange = function handleChange(item, id) {
360
- var _datum$current5;
361
- if (!datum.current) return;
362
- if (disabled === true || (_datum$current5 = datum.current) !== null && _datum$current5 !== void 0 && _datum$current5.isDisabled(id)) return;
363
- var currentData = datum.current.getDataById(id);
381
+ if (disabled === true || datum !== null && datum !== void 0 && datum.isDisabled(id)) return;
382
+ var currentData = datum.getDataById(id);
364
383
  if (!multiple) {
365
- datum.current.setValue([]);
366
- datum.current.set(datum.current.getKey(item), 1);
384
+ datum.setValue([]);
385
+ datum.set(datum.getKey(item), 1);
367
386
  }
368
387
  var nextValue = getValue();
369
388
  if (onChange) {
370
- onChange(nextValue, currentData, id ? (datum.current.getPath(id) || {}).path : undefined);
389
+ onChange(nextValue, currentData, id ? (datum.getPath(id) || {}).path : undefined);
371
390
  }
372
391
  if (typeof onChangeAddition === 'function') {
373
392
  onChangeAddition({
374
393
  data: getDataByValues(nextValue),
375
- checked: multiple ? datum.current.get(id) : undefined,
394
+ checked: multiple ? datum.get(id) : undefined,
376
395
  current: currentData
377
396
  });
378
397
  }
379
398
  };
380
- var handleTreeChange = function handleTreeChange(item, id) {
399
+ var handleTreeClick = function handleTreeClick(item, id) {
381
400
  handleChange(item, id);
382
- if (!multiple) closePop();
401
+ closePop();
383
402
  };
384
- var handleRemove = function handleRemove(item, key, index) {
385
- if (!datum.current) return;
386
- var dataKey = util.isUnMatchedData(item) ? item.value : datum.current.getKey(item, key, index);
387
- var isDisabled = datum.current.isDisabled(dataKey);
403
+ var handleTreeChange = function handleTreeChange(_value, id) {
404
+ var item = datum.getDataById(id);
405
+ handleChange(item, id);
406
+ };
407
+ var handleRemove = function handleRemove(item, key) {
408
+ if (!datum) return;
409
+ var dataKey = key !== null && key !== void 0 ? key : util.isUnMatchedData(item) ? item.value : datum.getKey(item);
410
+ var isDisabled = datum.isDisabled(dataKey);
388
411
  if (isDisabled) return;
389
- datum.current.set(dataKey, 0);
390
- handleChange(item, datum.current.getKey(item, key, index));
412
+ datum.set(dataKey, 0);
413
+ handleChange(item, dataKey);
391
414
  };
392
415
 
393
416
  // innerTitle 模式
394
417
  var renderInnerTitle = useInnerTitle({
395
- open: open || !!value,
418
+ open: open || !!(value && value.length),
396
419
  size: size,
397
420
  jssStyle: jssStyle,
398
421
  innerTitle: innerTitle
399
422
  });
423
+ var getResultByValue = usePersistFn(function (arr) {
424
+ var result = (Array.isArray(arr) ? arr : [arr]).map(function (id) {
425
+ return getDataById(id);
426
+ }).filter(function (item) {
427
+ return item !== undefined;
428
+ });
429
+ return result;
430
+ });
431
+ var getResultValue = function getResultValue() {
432
+ if (!multiple && Array.isArray(value)) {
433
+ return value[0];
434
+ }
435
+ return value;
436
+ };
400
437
  var renderResult = function renderResult() {
401
438
  var result = /*#__PURE__*/_jsx("div", {
402
439
  className: classNames(styles === null || styles === void 0 ? void 0 : styles.result),
@@ -404,13 +441,11 @@ var TreeSelect = function TreeSelect(props0) {
404
441
  trim: trim,
405
442
  jssStyle: jssStyle,
406
443
  size: size,
407
- value: value,
408
- data: tiledData,
444
+ value: getResultValue(),
445
+ data: data,
409
446
  focus: open,
410
447
  keygen: keygen,
411
- disabled: disabled
412
- // maxLength={maxLength}
413
- ,
448
+ disabled: disabled,
414
449
  compressed: compressed,
415
450
  compressedBound: compressedBound,
416
451
  compressedClassName: compressedClassName,
@@ -429,7 +464,7 @@ var TreeSelect = function TreeSelect(props0) {
429
464
  onRef: inputRef,
430
465
  checkUnMatched: checkUnMatched,
431
466
  onClearCreatedData: onClearCreatedData,
432
- getDataByValues: getDataByValues,
467
+ getDataByValues: getResultByValue,
433
468
  onRemove: handleRemove,
434
469
  classes: styles,
435
470
  setInputText: setInputText
@@ -485,14 +520,13 @@ var TreeSelect = function TreeSelect(props0) {
485
520
  if (multiple) {
486
521
  treeProps.onChange = handleTreeChange;
487
522
  } else {
488
- treeProps.onClick = handleTreeChange;
523
+ treeProps.onClick = handleTreeClick;
489
524
  treeProps.renderItem = renderActive;
490
525
  treeProps.active = value;
491
526
  }
492
527
  if ('expanded' in props) {
493
528
  treeProps.expanded = expanded;
494
529
  }
495
- var nextValue = getValueArray(value);
496
530
  return /*#__PURE__*/_jsx("div", {
497
531
  className: classNames(styles.tree),
498
532
  style: {
@@ -500,30 +534,28 @@ var TreeSelect = function TreeSelect(props0) {
500
534
  },
501
535
  children: /*#__PURE__*/_jsx(Tree, _objectSpread(_objectSpread({
502
536
  jssStyle: jssStyle,
503
- getDatum: bindTreeDatum,
504
537
  renderItem: renderItem
505
538
  }, treeProps), {}, {
506
- keepCache: !props.noCache,
507
539
  line: line,
508
540
  mode: mode,
509
541
  data: tiledData,
510
542
  keygen: keygen,
511
543
  unmatch: unmatch,
512
- value: nextValue,
544
+ value: value,
513
545
  loader: loader,
514
- expanded: 'expanded' in props || expanded !== null && expanded !== void 0 && expanded.length ? expanded : undefined,
546
+ onExpand: onExpandTree,
547
+ expanded: controlExpanded,
548
+ defaultExpandAll: defaultExpandAll,
515
549
  expandIcons: tiledExpandIcons,
516
550
  disabled: disabled,
517
551
  parentClickExpand: parentClickExpand,
518
- defaultExpanded: defaultExpanded,
519
- defaultExpandAll: defaultExpandAll,
520
552
  contentClass: getContentClass,
521
- onExpand: handleExpand
553
+ datum: datum
522
554
  }))
523
555
  });
524
556
  };
525
557
  useEffect(function () {
526
- if (getComponentRef && datum.current) {
558
+ if (getComponentRef && datum) {
527
559
  if (util.isFunc(getComponentRef)) {
528
560
  getComponentRef({
529
561
  getDataByValues: getDataByValuesRef
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sheinx/base",
3
- "version": "3.0.10",
3
+ "version": "3.0.11",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "license": "MIT",
@@ -10,7 +10,7 @@
10
10
  "module": "./esm/index.js",
11
11
  "typings": "./cjs/index.d.ts",
12
12
  "dependencies": {
13
- "@sheinx/hooks": "3.0.10",
13
+ "@sheinx/hooks": "3.0.11",
14
14
  "immer": "^10.0.0",
15
15
  "classnames": "^2.0.0",
16
16
  "@shined/reactive": "^0.1.2"