one-design-next 0.0.33 → 0.0.34

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.
@@ -20,6 +20,7 @@ export interface TreeSelectProps extends Omit<RcTreeSelectProps, 'treeData'> {
20
20
  showInnerSearch?: boolean;
21
21
  light?: boolean;
22
22
  popupRender?: (menu: React.ReactElement) => React.ReactElement;
23
+ checkStrictly?: boolean;
23
24
  }
24
25
  declare const TreeSelect: React.FC<TreeSelectProps>;
25
26
  export default TreeSelect;
@@ -1,5 +1,4 @@
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 = ["mode", "suffixIcon", "visible", "onVisibleChange", "treeCheckable", "className", "showInnerSearch", "light", "popupRender", "searchValue", "onSearch"];
1
+ var _excluded = ["mode", "suffixIcon", "visible", "onVisibleChange", "treeCheckable", "className", "showInnerSearch", "light", "popupRender", "searchValue", "onSearch", "checkStrictly", "value", "defaultValue", "onChange"];
3
2
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
4
3
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
5
4
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
@@ -14,13 +13,31 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
14
13
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
15
14
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
16
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
+ 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); }
17
17
  import clsx from 'clsx';
18
18
  import RcTreeSelect from 'rc-tree-select';
19
- import React, { useEffect, useRef, useState } from 'react';
19
+ import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
20
20
  import Icon from "../icon";
21
21
  import "../select/style";
22
22
  import useIcons from "../select/useIcons";
23
23
  import "./style";
24
+ function toLabelInValue(val) {
25
+ if (val === undefined || val === null) return undefined;
26
+ var arr = Array.isArray(val) ? val : [val];
27
+ return arr.map(function (v) {
28
+ return _typeof(v) === 'object' && v !== null && 'value' in v ? v : {
29
+ value: v,
30
+ label: v
31
+ };
32
+ });
33
+ }
34
+ function toSimpleValues(val) {
35
+ if (val === undefined || val === null) return [];
36
+ var arr = Array.isArray(val) ? val : [val];
37
+ return arr.map(function (v) {
38
+ return v.value;
39
+ });
40
+ }
24
41
  var TreeSelect = function TreeSelect(_ref) {
25
42
  var mode = _ref.mode,
26
43
  _ref$suffixIcon = _ref.suffixIcon,
@@ -39,8 +56,31 @@ var TreeSelect = function TreeSelect(_ref) {
39
56
  popupRender = _ref.popupRender,
40
57
  searchValueProp = _ref.searchValue,
41
58
  onSearch = _ref.onSearch,
59
+ _ref$checkStrictly = _ref.checkStrictly,
60
+ checkStrictly = _ref$checkStrictly === void 0 ? false : _ref$checkStrictly,
61
+ valueProp = _ref.value,
62
+ defaultValueProp = _ref.defaultValue,
63
+ onChangeProp = _ref.onChange,
42
64
  rest = _objectWithoutProperties(_ref, _excluded);
43
65
  var isMultiple = mode === 'multiple';
66
+ var rcValue = useMemo(function () {
67
+ return checkStrictly ? toLabelInValue(valueProp) : valueProp;
68
+ }, [checkStrictly, valueProp]);
69
+ var rcDefaultValue = useMemo(function () {
70
+ return checkStrictly ? toLabelInValue(defaultValueProp) : defaultValueProp;
71
+ }, [checkStrictly, defaultValueProp]);
72
+ var rcOnChange = useCallback(function () {
73
+ if (!onChangeProp) return;
74
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
75
+ args[_key] = arguments[_key];
76
+ }
77
+ if (checkStrictly) {
78
+ var simpleValues = toSimpleValues(args[0]);
79
+ onChangeProp(simpleValues, args[1], args[2]);
80
+ } else {
81
+ onChangeProp.apply(void 0, args);
82
+ }
83
+ }, [checkStrictly, onChangeProp]);
44
84
  var _useIcons = useIcons(_objectSpread(_objectSpread({}, rest), {}, {
45
85
  multiple: isMultiple,
46
86
  hasFeedback: false,
@@ -102,7 +142,8 @@ var TreeSelect = function TreeSelect(_ref) {
102
142
  treeCheckable: isMultiple ? treeCheckable ? /*#__PURE__*/React.createElement("span", {
103
143
  className: "odn-select-tree-checkbox-inner"
104
144
  }) : treeCheckable : false,
105
- showCheckedStrategy: "SHOW_PARENT",
145
+ treeCheckStrictly: checkStrictly,
146
+ showCheckedStrategy: checkStrictly ? 'SHOW_ALL' : 'SHOW_PARENT',
106
147
  searchValue: searchValue,
107
148
  dropdownRender: function dropdownRender(menu) {
108
149
  var searchNode = showInnerSearch ? /*#__PURE__*/React.createElement("div", {
@@ -133,7 +174,10 @@ var TreeSelect = function TreeSelect(_ref) {
133
174
  var content = /*#__PURE__*/React.createElement(React.Fragment, null, searchNode, menu);
134
175
  return popupRender ? popupRender(content) : content;
135
176
  },
136
- notFoundContent: "\u65E0\u5339\u914D\u7ED3\u679C"
177
+ notFoundContent: "\u65E0\u5339\u914D\u7ED3\u679C",
178
+ value: rcValue,
179
+ defaultValue: rcDefaultValue,
180
+ onChange: rcOnChange
137
181
  }, rest));
138
182
  };
139
183
  TreeSelect.displayName = 'TreeSelect';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "one-design-next",
3
- "version": "0.0.33",
3
+ "version": "0.0.34",
4
4
  "description": "One Design Next from TAD@tencent.com",
5
5
  "packageManager": "pnpm@10.33.0",
6
6
  "module": "dist/index.js",