@qsxy/element-plus-react 1.0.2 → 1.0.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.
Files changed (216) hide show
  1. package/dist/Alert/Alert.d.ts +7 -0
  2. package/dist/Alert/Alert.js +98 -0
  3. package/dist/Alert/index.d.ts +2 -0
  4. package/dist/Alert/index.js +1 -0
  5. package/dist/Alert/typings.d.ts +45 -0
  6. package/dist/Alert/typings.js +1 -0
  7. package/dist/Card/Card.js +5 -3
  8. package/dist/Cascader/useCascader.d.ts +0 -14
  9. package/dist/Cascader/useCascader.js +33 -32
  10. package/dist/Checkbox/Checkbox.js +3 -2
  11. package/dist/ConfigProvider/ConfigProvider.js +2 -24
  12. package/dist/ConfigProvider/ConfigProviderContext.js +1 -1
  13. package/dist/ConfigProvider/typings.d.ts +1 -1
  14. package/dist/Container/Main.d.ts +1 -1
  15. package/dist/Container/typings.d.ts +1 -1
  16. package/dist/Dialog/Dialog.js +5 -12
  17. package/dist/Input/Input.js +68 -43
  18. package/dist/Input/TextArea.js +1 -1
  19. package/dist/Input/typings.d.ts +42 -1
  20. package/dist/Input/utils.d.ts +1 -0
  21. package/dist/Input/utils.js +5 -1
  22. package/dist/InputNumber/InputNumber.js +351 -141
  23. package/dist/InputNumber/typings.d.ts +15 -1
  24. package/dist/Loading/Loading.js +5 -2
  25. package/dist/Menu/Menu.js +25 -1
  26. package/dist/Menu/MenuItem.js +4 -2
  27. package/dist/Menu/SubMenu.js +2 -2
  28. package/dist/Menu/SubMenuCollapseTransition.js +14 -9
  29. package/dist/Menu/typings.d.ts +2 -1
  30. package/dist/Message/Message.js +51 -23
  31. package/dist/Message/index.js +8 -10
  32. package/dist/Message/typings.d.ts +8 -5
  33. package/dist/MessageBox/MessageBox.js +52 -30
  34. package/dist/MessageBox/index.d.ts +2 -1
  35. package/dist/MessageBox/index.js +4 -2
  36. package/dist/MessageBox/typings.d.ts +3 -0
  37. package/dist/Notification/Notification.js +26 -19
  38. package/dist/Select/SelectContext.d.ts +2 -1
  39. package/dist/Select/SelectContext.js +2 -1
  40. package/dist/Select/SelectCore.js +13 -7
  41. package/dist/Select/SelectDropdown.js +23 -15
  42. package/dist/Select/index.d.ts +1 -1
  43. package/dist/Select/typings.d.ts +13 -9
  44. package/dist/Select/useSelect.d.ts +13 -10
  45. package/dist/Select/useSelect.js +34 -26
  46. package/dist/Space/Space.d.ts +4 -0
  47. package/dist/Space/Space.js +128 -0
  48. package/dist/Space/SpaceItem.d.ts +7 -0
  49. package/dist/Space/SpaceItem.js +14 -0
  50. package/dist/Space/index.d.ts +3 -0
  51. package/dist/Space/index.js +2 -0
  52. package/dist/Space/typings.d.ts +26 -0
  53. package/dist/Space/typings.js +1 -0
  54. package/dist/Space/useSpace.d.ts +7 -0
  55. package/dist/Space/useSpace.js +104 -0
  56. package/dist/Statistic/Statistic.d.ts +4 -0
  57. package/dist/Statistic/Statistic.js +92 -0
  58. package/dist/Statistic/index.d.ts +2 -0
  59. package/dist/Statistic/index.js +1 -0
  60. package/dist/Statistic/typings.d.ts +28 -0
  61. package/dist/Statistic/typings.js +1 -0
  62. package/dist/Switch/Switch.js +2 -2
  63. package/dist/Table/Table.js +3 -0
  64. package/dist/Table/typings.d.ts +2 -0
  65. package/dist/Tag/typings.d.ts +1 -1
  66. package/dist/Text/Text.d.ts +4 -0
  67. package/dist/Text/Text.js +84 -0
  68. package/dist/Text/index.d.ts +2 -0
  69. package/dist/Text/index.js +1 -0
  70. package/dist/Text/typings.d.ts +15 -0
  71. package/dist/Text/typings.js +1 -0
  72. package/dist/Tree/CollapseTransition.d.ts +7 -0
  73. package/dist/Tree/CollapseTransition.js +60 -0
  74. package/dist/Tree/Tree.d.ts +3 -140
  75. package/dist/Tree/Tree.js +350 -77
  76. package/dist/Tree/TreeContext.d.ts +9 -0
  77. package/dist/Tree/TreeContext.js +14 -0
  78. package/dist/Tree/TreeNode.d.ts +5 -3
  79. package/dist/Tree/TreeNode.js +321 -331
  80. package/dist/Tree/TreeNodeContent.d.ts +9 -0
  81. package/dist/Tree/TreeNodeContent.js +22 -0
  82. package/dist/Tree/index.d.ts +3 -8
  83. package/dist/Tree/index.js +1 -4
  84. package/dist/Tree/model/node.d.ts +62 -0
  85. package/dist/Tree/model/node.js +601 -0
  86. package/dist/Tree/model/tree-store.d.ts +52 -0
  87. package/dist/Tree/model/tree-store.js +510 -0
  88. package/dist/Tree/model/useDragNode.d.ts +30 -0
  89. package/dist/Tree/model/useDragNode.js +293 -0
  90. package/dist/Tree/model/useKeydown.d.ts +0 -0
  91. package/dist/Tree/model/useKeydown.js +104 -0
  92. package/dist/Tree/model/useNodeExpandEventBroadcast.d.ts +15 -0
  93. package/dist/Tree/model/useNodeExpandEventBroadcast.js +54 -0
  94. package/dist/Tree/model/util.d.ts +7 -0
  95. package/dist/Tree/model/util.js +24 -0
  96. package/dist/Tree/typings.d.ts +225 -114
  97. package/dist/TreeSelect/TreeSelect.d.ts +2 -10
  98. package/dist/TreeSelect/TreeSelect.js +90 -566
  99. package/dist/TreeSelect/TreeSelectOption.d.ts +6 -0
  100. package/dist/TreeSelect/TreeSelectOption.js +62 -0
  101. package/dist/TreeSelect/cacheOptions.d.ts +9 -0
  102. package/dist/TreeSelect/cacheOptions.js +22 -0
  103. package/dist/TreeSelect/index.d.ts +0 -1
  104. package/dist/TreeSelect/typings.d.ts +11 -63
  105. package/dist/TreeSelect/useSelect.d.ts +125 -0
  106. package/dist/TreeSelect/useSelect.js +104 -0
  107. package/dist/TreeSelect/useTree.d.ts +130 -0
  108. package/dist/TreeSelect/useTree.js +285 -0
  109. package/dist/TreeSelect/utils.d.ts +10 -0
  110. package/dist/TreeSelect/utils.js +38 -0
  111. package/dist/Upload/UploadContent.js +2 -0
  112. package/dist/Upload/ajax.js +3 -0
  113. package/dist/Upload/typings.d.ts +4 -0
  114. package/dist/Util/aria.js +12 -12
  115. package/dist/Util/base.d.ts +5 -0
  116. package/dist/Util/base.js +140 -1
  117. package/dist/config/Constants.d.ts +3 -0
  118. package/dist/config/Constants.js +8 -0
  119. package/dist/hooks/index.d.ts +1 -0
  120. package/dist/hooks/index.js +1 -0
  121. package/dist/hooks/popperPropsUtils.js +1 -1
  122. package/dist/hooks/treePropsUtils.d.ts +3 -3
  123. package/dist/hooks/treePropsUtils.js +2 -2
  124. package/dist/hooks/useConfigProvider.d.ts +27 -0
  125. package/dist/hooks/useConfigProvider.js +78 -0
  126. package/dist/hooks/useResizeObserver.js +6 -6
  127. package/dist/index.css +1 -1
  128. package/dist/index.d.ts +18 -11
  129. package/dist/index.js +11 -5
  130. package/package.json +1 -1
  131. package/theme-chalk/alert.scss +115 -0
  132. package/theme-chalk/aside.scss +8 -8
  133. package/theme-chalk/button-group.scss +80 -80
  134. package/theme-chalk/button.scss +304 -304
  135. package/theme-chalk/calendar/date-table.scss +164 -164
  136. package/theme-chalk/checkbox.scss +34 -0
  137. package/theme-chalk/color/index.scss +20 -20
  138. package/theme-chalk/common/transition.scss +142 -142
  139. package/theme-chalk/container.scss +14 -14
  140. package/theme-chalk/dark/css-vars.scss +39 -39
  141. package/theme-chalk/dark/var.scss +225 -225
  142. package/theme-chalk/date-picker.scss +12 -12
  143. package/theme-chalk/drawer.scss +1 -0
  144. package/theme-chalk/footer.scss +12 -12
  145. package/theme-chalk/header.scss +12 -12
  146. package/theme-chalk/index.scss +4 -0
  147. package/theme-chalk/input/input-range.scss +2 -1
  148. package/theme-chalk/input/input.scss +439 -424
  149. package/theme-chalk/input-number.bak +172 -0
  150. package/theme-chalk/input-number.scss +192 -172
  151. package/theme-chalk/link.scss +87 -87
  152. package/theme-chalk/main.scss +14 -14
  153. package/theme-chalk/menu.scss +353 -353
  154. package/theme-chalk/message.scss +104 -178
  155. package/theme-chalk/mixins/_button.scss +224 -224
  156. package/theme-chalk/mixins/_col.scss +33 -33
  157. package/theme-chalk/mixins/_var.scss +67 -67
  158. package/theme-chalk/mixins/config.scss +5 -5
  159. package/theme-chalk/mixins/function.scss +99 -99
  160. package/theme-chalk/mixins/mixins.scss +240 -240
  161. package/theme-chalk/mixins/utils.scss +39 -39
  162. package/theme-chalk/notification.bak +156 -0
  163. package/theme-chalk/notification.scss +109 -156
  164. package/theme-chalk/popper.scss +104 -104
  165. package/theme-chalk/radio-button.scss +169 -169
  166. package/theme-chalk/select/index.scss +278 -272
  167. package/theme-chalk/space.scss +20 -0
  168. package/theme-chalk/statistic.scss +35 -0
  169. package/theme-chalk/switch.scss +300 -300
  170. package/theme-chalk/tag.scss +181 -181
  171. package/theme-chalk/text.scss +48 -0
  172. package/theme-chalk/transition.scss +34 -4
  173. package/theme-chalk/tree-select.scss +41 -25
  174. package/theme-chalk/tree.scss +136 -0
  175. package/theme-chalk/var.scss +83 -83
  176. package/dist/Input/Input.1.d.ts +0 -16
  177. package/dist/Input/Input.1.js +0 -376
  178. package/dist/Tree/DirectoryTree.d.ts +0 -15
  179. package/dist/Tree/DirectoryTree.js +0 -183
  180. package/dist/Tree/DropIndicator.d.ts +0 -8
  181. package/dist/Tree/DropIndicator.js +0 -34
  182. package/dist/Tree/Indent.d.ts +0 -9
  183. package/dist/Tree/Indent.js +0 -25
  184. package/dist/Tree/MotionTreeNode.d.ts +0 -14
  185. package/dist/Tree/MotionTreeNode.js +0 -125
  186. package/dist/Tree/NodeList.d.ts +0 -50
  187. package/dist/Tree/NodeList.js +0 -301
  188. package/dist/Tree/RCTree.d.ts +0 -248
  189. package/dist/Tree/RCTree.js +0 -1216
  190. package/dist/Tree/contextTypes.d.ts +0 -69
  191. package/dist/Tree/contextTypes.js +0 -9
  192. package/dist/Tree/typings.tsx--bak +0 -245
  193. package/dist/Tree/useUnmount.d.ts +0 -5
  194. package/dist/Tree/useUnmount.js +0 -34
  195. package/dist/Tree/util.d.ts +0 -51
  196. package/dist/Tree/util.js +0 -303
  197. package/dist/Tree/utils/conductUtil.d.ts +0 -17
  198. package/dist/Tree/utils/conductUtil.js +0 -209
  199. package/dist/Tree/utils/dictUtil.d.ts +0 -13
  200. package/dist/Tree/utils/dictUtil.js +0 -75
  201. package/dist/Tree/utils/diffUtil.d.ts +0 -7
  202. package/dist/Tree/utils/diffUtil.js +0 -48
  203. package/dist/Tree/utils/dropIndicator.d.ts +0 -11
  204. package/dist/Tree/utils/dropIndicator.js +0 -36
  205. package/dist/Tree/utils/iconUtil.d.ts +0 -5
  206. package/dist/Tree/utils/iconUtil.js +0 -62
  207. package/dist/Tree/utils/keyUtil.d.ts +0 -2
  208. package/dist/Tree/utils/keyUtil.js +0 -3
  209. package/dist/Tree/utils/motion.d.ts +0 -10
  210. package/dist/Tree/utils/motion.js +0 -54
  211. package/dist/Tree/utils/pickAttrs.d.ts +0 -11
  212. package/dist/Tree/utils/pickAttrs.js +0 -51
  213. package/dist/Tree/utils/treeUtil.d.ts +0 -86
  214. package/dist/Tree/utils/treeUtil.js +0 -364
  215. package/dist/TreeSelect/Utils.d.ts +0 -3
  216. package/dist/TreeSelect/Utils.js +0 -20
@@ -0,0 +1,285 @@
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
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
3
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
5
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
6
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
7
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
8
+ 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; }
9
+ 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; }
10
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
11
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
12
+ 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); }
13
+ import isEqual from 'lodash/isEqual';
14
+ import isNil from 'lodash/isNil';
15
+ import pick from 'lodash/pick';
16
+ import React, { useCallback, useEffect, useMemo, useRef } from 'react';
17
+ import { escapeStringRegexp, isEmpty, isFunction, nextTick } from "../Util";
18
+ import { treeAllProps } from "../hooks/treePropsUtils";
19
+ import TreeSelectOption from "./TreeSelectOption";
20
+ import { isValidArray, isValidValue, toValidArray, treeEach, treeFind } from "./utils"; // 假设工具函数已存在
21
+
22
+ var useTree = function useTree(props, _ref) {
23
+ var selectRef = _ref.selectRef,
24
+ treeRef = _ref.treeRef,
25
+ key = _ref.key,
26
+ value = _ref.value,
27
+ setValue = _ref.setValue;
28
+ var isEffect = useRef(true);
29
+
30
+ // 监听 value 变化并同步树的选中状态
31
+ useEffect(function () {
32
+ if (props.showCheckbox && treeRef.current) {
33
+ var treeInstance = treeRef.current;
34
+ var currentKeys = treeInstance.getCheckedKeys();
35
+ if (!isEqual(currentKeys, toValidArray(value))) {
36
+ treeInstance.setCheckedKeys(toValidArray(value));
37
+ }
38
+ }
39
+ }, [value]);
40
+
41
+ // 计算 propsMap
42
+ var propsMap = useMemo(function () {
43
+ return _objectSpread({
44
+ value: key,
45
+ label: 'label',
46
+ children: 'children',
47
+ disabled: 'disabled',
48
+ isLeaf: 'isLeaf'
49
+ }, props.props);
50
+ }, [key, props.props]);
51
+
52
+ // 获取节点属性值
53
+ var getNodeValByProp = useCallback(function (prop, data) {
54
+ var propVal = propsMap[prop];
55
+ if (isFunction(propVal)) {
56
+ var _treeRef$current;
57
+ // @ts-ignore
58
+ return propVal(data, (_treeRef$current = treeRef.current) === null || _treeRef$current === void 0 ? void 0 : _treeRef$current.getNode(getNodeValByProp('value', data)));
59
+ }
60
+ return data[propVal];
61
+ }, [propsMap, treeRef]);
62
+
63
+ // 默认展开父节点的 Key
64
+ var defaultExpandedParentKeys = useMemo(function () {
65
+ return toValidArray(value).map(function (val) {
66
+ return treeFind(props.data || [], function (data) {
67
+ return getNodeValByProp('value', data) === val;
68
+ }, function (data) {
69
+ return getNodeValByProp('children', data);
70
+ }, function (data, index, array, parent) {
71
+ return parent && getNodeValByProp('value', parent);
72
+ });
73
+ }).filter(isValidValue);
74
+ }, [value, props.data, getNodeValByProp]);
75
+
76
+ // 缓存选项
77
+ var cacheOptions = useMemo(function () {
78
+ // if (!props.renderAfterExpand && !props.lazy) {
79
+ // return [];
80
+ // }
81
+
82
+ var options = [];
83
+ treeEach([].concat(_toConsumableArray(props.data || []), _toConsumableArray(props.cacheData || [])), function (node) {
84
+ var val = getNodeValByProp('value', node);
85
+ options.push({
86
+ value: val,
87
+ currentLabel: getNodeValByProp('label', node),
88
+ label: getNodeValByProp('label', node),
89
+ isDisabled: getNodeValByProp('disabled', node)
90
+ });
91
+ }, function (data) {
92
+ return getNodeValByProp('children', data);
93
+ });
94
+ return options;
95
+ }, [props.data, props.cacheData, getNodeValByProp]);
96
+ useEffect(function () {
97
+ if (isEffect.current) {
98
+ if (!props.multiple) {
99
+ var optionData = cacheOptions.find(function (item) {
100
+ return item.value === value;
101
+ });
102
+ if (optionData) {
103
+ if (treeRef.current.getNode(value)) {
104
+ var _treeRef$current2;
105
+ (_treeRef$current2 = treeRef.current) === null || _treeRef$current2 === void 0 || _treeRef$current2.setCurrentNode(treeRef.current.getNode(value));
106
+ }
107
+ }
108
+ }
109
+ } else {
110
+ isEffect.current = true;
111
+ }
112
+ }, [value]);
113
+
114
+ // 获取子节点选中的 Key
115
+ var getChildCheckedKeys = useCallback(function () {
116
+ var _treeRef$current3;
117
+ return (_treeRef$current3 = treeRef.current) === null || _treeRef$current3 === void 0 ? void 0 : _treeRef$current3.getCheckedKeys().filter(function (item) {
118
+ var _treeRef$current4;
119
+ var node = (_treeRef$current4 = treeRef.current) === null || _treeRef$current4 === void 0 ? void 0 : _treeRef$current4.getNode(item);
120
+ return !isNil(node) && isEmpty(node.childNodes);
121
+ });
122
+ }, [treeRef]);
123
+ var expandOnClickNode = useMemo(function () {
124
+ return !props.checkStrictly && props.expandOnClickNode;
125
+ }, [props.checkStrictly, props.expandOnClickNode]);
126
+ var defaultExpandedKeys = useMemo(function () {
127
+ return props.defaultExpandedKeys ? [].concat(_toConsumableArray(props.defaultExpandedKeys), _toConsumableArray(defaultExpandedParentKeys)) : defaultExpandedParentKeys;
128
+ }, [props.defaultExpandedKeys, defaultExpandedParentKeys]);
129
+
130
+ // 渲染内容
131
+ var renderContent = useCallback(function (_ref2) {
132
+ var node = _ref2.node,
133
+ data = _ref2.data,
134
+ store = _ref2.store;
135
+ return /*#__PURE__*/React.createElement(TreeSelectOption, {
136
+ value: getNodeValByProp('value', data),
137
+ label: getNodeValByProp('label', data),
138
+ disabled: getNodeValByProp('disabled', data),
139
+ visible: node.visible
140
+ }, props.renderContent ? props.renderContent({
141
+ node: node,
142
+ data: data,
143
+ store: store
144
+ }) : props.children);
145
+ }, [getNodeValByProp, props]);
146
+
147
+ // 过滤节点方法
148
+ var filterNodeMethod = useCallback(function (val, data, node) {
149
+ if (props.filterNodeMethod) {
150
+ return props.filterNodeMethod(val, data, node);
151
+ }
152
+ if (!val) {
153
+ return true;
154
+ }
155
+ var regexp = new RegExp(escapeStringRegexp(val), 'i');
156
+ return regexp.test(getNodeValByProp('label', data) || '');
157
+ }, [props, getNodeValByProp]);
158
+
159
+ // 节点点击事件
160
+ var onNodeClick = useCallback(function (data, node, treeNodeRef, e) {
161
+ var _props$onNodeClick;
162
+ (_props$onNodeClick = props.onNodeClick) === null || _props$onNodeClick === void 0 || _props$onNodeClick.call(props, data, node, treeNodeRef, e);
163
+ if (props.showCheckbox && props.checkOnClickNode) {
164
+ return;
165
+ }
166
+ if (!props.showCheckbox && (props.checkStrictly || node.isLeaf)) {
167
+ if (!getNodeValByProp('disabled', data)) {
168
+ var _selectRef$current;
169
+ var val = (_selectRef$current = selectRef.current) === null || _selectRef$current === void 0 ? void 0 : _selectRef$current.onChoose(getNodeValByProp('value', data), data, e);
170
+ isEffect.current = false;
171
+ setValue(val);
172
+ }
173
+ } else if (props.expandOnClickNode) {
174
+ // treeNodeRef.current.handleExpandIconClick();
175
+ }
176
+ }, [props, getNodeValByProp, selectRef, setValue]);
177
+
178
+ // 节点勾选事件
179
+ var onCheck = useCallback(function (data, params) {
180
+ var _treeRef$current5;
181
+ if (!props.showCheckbox) {
182
+ return;
183
+ }
184
+ var controlledValue = null;
185
+ var dataValue = getNodeValByProp('value', data);
186
+ var dataMap = {};
187
+ treeEach([(_treeRef$current5 = treeRef.current) === null || _treeRef$current5 === void 0 ? void 0 : _treeRef$current5.store.root], function (node) {
188
+ return dataMap[node.key] = node;
189
+ }, function (node) {
190
+ return node.childNodes;
191
+ });
192
+ var uncachedCheckedKeys = params.checkedKeys;
193
+ var cachedKeys = props.multiple ? toValidArray(value).filter(function (item) {
194
+ return !(item in dataMap) && !uncachedCheckedKeys.includes(item);
195
+ }) : [];
196
+ var newCheckedKeys = cachedKeys.concat(uncachedCheckedKeys);
197
+ if (props.checkStrictly) {
198
+ var _selectRef$current2;
199
+ var res = null;
200
+ if (props.multiple) {
201
+ res = newCheckedKeys;
202
+ } else {
203
+ res = newCheckedKeys.includes(dataValue) ? dataValue : undefined;
204
+ }
205
+ isEffect.current = false;
206
+ var val = (_selectRef$current2 = selectRef.current) === null || _selectRef$current2 === void 0 ? void 0 : _selectRef$current2.onChoose(dataValue, cacheOptions.find(function (cache) {
207
+ return cache.value === dataValue;
208
+ }));
209
+ controlledValue = val;
210
+ } else {
211
+ if (props.multiple) {
212
+ var _selectRef$current3;
213
+ // const childKeys = getChildCheckedKeys();
214
+ isEffect.current = false;
215
+ var _val = (_selectRef$current3 = selectRef.current) === null || _selectRef$current3 === void 0 ? void 0 : _selectRef$current3.onChoose(dataValue, cacheOptions.find(function (cache) {
216
+ return cache.value === dataValue;
217
+ }));
218
+ controlledValue = _val;
219
+ } else {
220
+ var _selectRef$current4;
221
+ var firstLeaf = treeFind([data], function (item) {
222
+ return !isValidArray(getNodeValByProp('children', item)) && !getNodeValByProp('disabled', item);
223
+ }, function (item) {
224
+ return getNodeValByProp('children', item);
225
+ });
226
+ var firstLeafKey = firstLeaf ? getNodeValByProp('value', firstLeaf) : undefined;
227
+ var hasCheckedChild = isValidValue(value) && !!treeFind([data], function (item) {
228
+ return getNodeValByProp('value', item) === value;
229
+ }, function (item) {
230
+ return getNodeValByProp('children', item);
231
+ });
232
+ (_selectRef$current4 = selectRef.current) === null || _selectRef$current4 === void 0 || _selectRef$current4.onChoose(firstLeafKey === value || hasCheckedChild ? undefined : firstLeafKey, firstLeaf);
233
+ controlledValue = firstLeafKey === value || hasCheckedChild ? undefined : firstLeafKey;
234
+ }
235
+ }
236
+ setValue(controlledValue);
237
+ nextTick(function () {
238
+ var _props$onCheck;
239
+ var _checkedKeys = toValidArray(controlledValue);
240
+ treeRef.current.setCheckedKeys(_checkedKeys);
241
+ (_props$onCheck = props.onCheck) === null || _props$onCheck === void 0 || _props$onCheck.call(props, data, {
242
+ checkedKeys: treeRef.current.getCheckedKeys(),
243
+ checkedNodes: treeRef.current.getCheckedNodes(),
244
+ halfCheckedKeys: treeRef.current.getHalfCheckedKeys(),
245
+ halfCheckedNodes: treeRef.current.getHalfCheckedNodes()
246
+ });
247
+ });
248
+ // selectRef.current?.focus();
249
+ }, [props, getNodeValByProp, treeRef, value, setValue, selectRef, cacheOptions]);
250
+
251
+ // 节点展开事件
252
+ var onNodeExpand = useCallback(function (data, node, treeNodeRef) {
253
+ var _props$onNodeExpand;
254
+ (_props$onNodeExpand = props.onNodeExpand) === null || _props$onNodeExpand === void 0 || _props$onNodeExpand.call(props, data, node, treeNodeRef);
255
+ nextTick(function () {
256
+ if (!props.checkStrictly && props.lazy && props.multiple && node.checked) {
257
+ var _treeRef$current6, _treeRef$current7, _props$onChange;
258
+ var dataMap = {};
259
+ var uncachedCheckedKeys = (_treeRef$current6 = treeRef.current) === null || _treeRef$current6 === void 0 ? void 0 : _treeRef$current6.getCheckedKeys();
260
+ treeEach([(_treeRef$current7 = treeRef.current) === null || _treeRef$current7 === void 0 ? void 0 : _treeRef$current7.store.root], function (item) {
261
+ return dataMap[item.key] = item;
262
+ }, function (item) {
263
+ return item.childNodes;
264
+ });
265
+ var cachedKeys = toValidArray(value).filter(function (item) {
266
+ return !(item in dataMap) && !uncachedCheckedKeys.includes(item);
267
+ });
268
+ var childKeys = getChildCheckedKeys();
269
+ (_props$onChange = props.onChange) === null || _props$onChange === void 0 || _props$onChange.call(props, cachedKeys.concat(childKeys));
270
+ }
271
+ });
272
+ }, [props, treeRef, value, getChildCheckedKeys]);
273
+ return _objectSpread(_objectSpread({}, pick(props, treeAllProps)), {}, {
274
+ nodeKey: key,
275
+ expandOnClickNode: expandOnClickNode,
276
+ defaultExpandedKeys: defaultExpandedKeys,
277
+ renderContent: renderContent,
278
+ filterNodeMethod: filterNodeMethod,
279
+ onNodeClick: onNodeClick,
280
+ onCheck: onCheck,
281
+ onNodeExpand: onNodeExpand,
282
+ cacheOptions: cacheOptions
283
+ });
284
+ };
285
+ export default useTree;
@@ -0,0 +1,10 @@
1
+ import { TreeNodeData } from '../Tree/typings';
2
+ export declare function isValidValue(val: any): any;
3
+ export declare function isValidArray(val: any): number;
4
+ export declare function toValidArray(val: any): any[];
5
+ type TreeCallback<T extends TreeNodeData, R> = (data: T, index: number, array: T[], parent?: T) => R;
6
+ type TreeFindCallback<T extends TreeNodeData> = TreeCallback<T, boolean>;
7
+ export declare function treeFind<T extends TreeNodeData>(treeData: T[], findCallback: TreeFindCallback<T>, getChildren: (data: T) => T[]): T | undefined;
8
+ export declare function treeFind<T extends TreeNodeData, R>(treeData: T[], findCallback: TreeFindCallback<T>, getChildren: (data: T) => T[], resultCallback?: TreeCallback<T, R>, parent?: T): R | undefined;
9
+ export declare function treeEach<T extends TreeNodeData>(treeData: T[], callback: TreeCallback<T, void>, getChildren: (data: T) => T[], parent?: T): void;
10
+ export {};
@@ -0,0 +1,38 @@
1
+ export function isValidValue(val) {
2
+ return val || val === 0;
3
+ }
4
+ export function isValidArray(val) {
5
+ return Array.isArray(val) && val.length;
6
+ }
7
+ export function toValidArray(val) {
8
+ if (Array.isArray(val)) {
9
+ return val;
10
+ }
11
+ return isValidValue(val) ? [val] : [];
12
+ }
13
+ export function treeFind(treeData, findCallback, getChildren, resultCallback, parent) {
14
+ for (var i = 0; i < treeData.length; i++) {
15
+ var _data = treeData[i];
16
+ if (findCallback(_data, i, treeData, parent)) {
17
+ return resultCallback ? resultCallback(_data, i, treeData, parent) : _data;
18
+ } else {
19
+ var children = getChildren(_data);
20
+ if (isValidArray(children)) {
21
+ var find = treeFind(children, findCallback, getChildren, resultCallback, _data);
22
+ if (find) {
23
+ return find;
24
+ }
25
+ }
26
+ }
27
+ }
28
+ }
29
+ export function treeEach(treeData, callback, getChildren, parent) {
30
+ for (var i = 0; i < treeData.length; i++) {
31
+ var _data2 = treeData[i];
32
+ callback(_data2, i, treeData, parent);
33
+ var children = getChildren(_data2);
34
+ if (isValidArray(children)) {
35
+ treeEach(children, callback, getChildren, _data2);
36
+ }
37
+ }
38
+ }
@@ -32,6 +32,7 @@ var UploadContent = /*#__PURE__*/forwardRef(function (props, ref) {
32
32
  data = props.data,
33
33
  method = props.method,
34
34
  withCredentials = props.withCredentials,
35
+ errorStatus = props.errorStatus,
35
36
  filename = props.name,
36
37
  action = props.action,
37
38
  _onProgress = props.onProgress,
@@ -56,6 +57,7 @@ var UploadContent = /*#__PURE__*/forwardRef(function (props, ref) {
56
57
  var options = {
57
58
  headers: headers || {},
58
59
  withCredentials: withCredentials,
60
+ errorStatus: errorStatus,
59
61
  file: rawFile,
60
62
  data: data,
61
63
  method: method,
@@ -59,6 +59,9 @@ export var ajaxUpload = function ajaxUpload(option) {
59
59
  option.onError(getError(action, option, xhr));
60
60
  });
61
61
  xhr.addEventListener('load', function () {
62
+ if (option.errorStatus && option.errorStatus(xhr)) {
63
+ return option.onError(getError(action, option, xhr));
64
+ }
62
65
  if (xhr.status < 200 || xhr.status >= 300) {
63
66
  return option.onError(getError(action, option, xhr));
64
67
  }
@@ -17,6 +17,8 @@ export interface UploadBaseProps {
17
17
  drag?: boolean;
18
18
  /** 支持发送 cookie 凭证信息 */
19
19
  withCredentials?: boolean;
20
+ /** 自定义上传请求的错误判断 */
21
+ errorStatus?: (xhr: XMLHttpRequest) => boolean;
20
22
  /** 是否显示已上传文件列表 */
21
23
  showFileList?: boolean;
22
24
  /** 接受上传的文件类型 */
@@ -113,6 +115,8 @@ export interface UploadRequestOptions {
113
115
  onError: (evt: UploadAjaxError) => void;
114
116
  onProgress: (evt: UploadProgressEvent) => void;
115
117
  onSuccess: (response: any) => void;
118
+ /** 自定义上传请求的错误判断 */
119
+ errorStatus?: (xhr: XMLHttpRequest) => boolean;
116
120
  withCredentials: boolean;
117
121
  }
118
122
  export interface UploadProgressEvent extends ProgressEvent {
package/dist/Util/aria.js CHANGED
@@ -6,8 +6,8 @@ var isHTMLElement = function isHTMLElement(e) {
6
6
  return e instanceof Element;
7
7
  };
8
8
 
9
- /**
10
- * Determine if the testing element is visible on screen no matter if its on the viewport or not
9
+ /**
10
+ * Determine if the testing element is visible on screen no matter if its on the viewport or not
11
11
  */
12
12
  export var isVisible = function isVisible(element) {
13
13
  if (process.env.NODE_ENV === 'test') {
@@ -24,10 +24,10 @@ export var obtainAllFocusableElements = function obtainAllFocusableElements(elem
24
24
  });
25
25
  };
26
26
 
27
- /**
28
- * @desc Determine if target element is focusable
29
- * @param element {HTMLElement}
30
- * @returns {Boolean} true if it is focusable
27
+ /**
28
+ * @desc Determine if target element is focusable
29
+ * @param element {HTMLElement}
30
+ * @returns {Boolean} true if it is focusable
31
31
  */
32
32
  export var isFocusable = function isFocusable(element) {
33
33
  if (element.tabIndex > 0 || element.tabIndex === 0 && element.getAttribute('tabIndex') !== null) {
@@ -59,12 +59,12 @@ export var isFocusable = function isFocusable(element) {
59
59
  }
60
60
  };
61
61
 
62
- /**
63
- * Trigger an event
64
- * mouseenter, mouseleave, mouseover, keyup, change, click, etc.
65
- * @param {HTMLElement} elm
66
- * @param {String} name
67
- * @param {*} opts
62
+ /**
63
+ * Trigger an event
64
+ * mouseenter, mouseleave, mouseover, keyup, change, click, etc.
65
+ * @param {HTMLElement} elm
66
+ * @param {String} name
67
+ * @param {*} opts
68
68
  */
69
69
  export var triggerEvent = function triggerEvent(elm, name) {
70
70
  var eventName;
@@ -36,6 +36,11 @@ export declare const isUndefined: (val: any) => val is undefined;
36
36
  export declare const isBoolean: (val: any) => val is boolean;
37
37
  export declare const isNumber: (val: any) => val is number;
38
38
  export declare const isString: (val: any) => boolean;
39
+ export declare const isFunction: (val: any) => boolean;
40
+ export declare const isPropAbsent: (prop: unknown) => prop is null;
39
41
  export declare const isStringNumber: (val: string) => boolean;
40
42
  export declare function addUnit(value?: string | number, defaultUnit?: string): string;
41
43
  export declare function mergeDefaultProps<T>(defaultProps: Partial<T>, target: T): T;
44
+ export declare let isUsingMicroTask: boolean;
45
+ export declare function nextTick(cb?: Function, ctx?: Object): Promise<unknown>;
46
+ export declare const escapeStringRegexp: (string?: string) => string;
package/dist/Util/base.js CHANGED
@@ -5,6 +5,8 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
5
5
  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); }
6
6
  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); }
7
7
  import is_empty from 'lodash/isEmpty';
8
+ import isNil from 'lodash/isNil';
9
+ import noop from 'lodash/noop';
8
10
 
9
11
  /**
10
12
  * 判断对象是否为空
@@ -130,6 +132,12 @@ export var isNumber = function isNumber(val) {
130
132
  export var isString = function isString(val) {
131
133
  return typeof val === 'string';
132
134
  };
135
+ export var isFunction = function isFunction(val) {
136
+ return typeof val === 'function';
137
+ };
138
+ export var isPropAbsent = function isPropAbsent(prop) {
139
+ return isNil(prop);
140
+ };
133
141
  export var isStringNumber = function isStringNumber(val) {
134
142
  if (!isString(val)) {
135
143
  return false;
@@ -165,4 +173,135 @@ export function mergeDefaultProps() {
165
173
  }
166
174
  }
167
175
  return props;
168
- }
176
+ }
177
+ var isIOS = /iPhone|iPad|iPod/i.test(navigator.userAgent);
178
+ function isNative(Ctor) {
179
+ return typeof Ctor === 'function' && /native code/.test(Ctor.toString());
180
+ }
181
+ // 上面三行与核心代码关系不大,了解即可
182
+ // noop 表示一个无操作空函数,用作函数默认值,防止传入 undefined 导致报错
183
+ // handleError 错误处理函数
184
+ // isIE, isIOS, isNative 环境判断函数,
185
+ // isNative 判断某个属性或方法是否原生支持,如果不支持或通过第三方实现支持都会返回 false
186
+
187
+ export var isUsingMicroTask = false; // 标记 nextTick 最终是否以微任务执行
188
+
189
+ var callbacks = []; // 存放调用 nextTick 时传入的回调函数
190
+ var pending = false; // 标记是否已经向任务队列中添加了一个任务,如果已经添加了就不能再添加了
191
+ // 当向任务队列中添加了任务时,将 pending 置为 true,当任务被执行时将 pending 置为 false
192
+ //
193
+
194
+ // 声明 nextTick 函数,接收一个回调函数和一个执行上下文作为参数
195
+ // 回调的 this 自动绑定到调用它的实例上
196
+ export function nextTick(cb, ctx) {
197
+ var _resolve;
198
+ // 将传入的回调函数存放到数组中,后面会遍历执行其中的回调
199
+ callbacks.push(function () {
200
+ if (cb) {
201
+ // 对传入的回调进行 try catch 错误捕获
202
+ try {
203
+ cb.call(ctx);
204
+ } catch (e) {
205
+ // 进行统一的错误处理
206
+ // handleError(e, ctx, 'nextTick');
207
+ }
208
+ } else if (_resolve) {
209
+ _resolve(ctx);
210
+ }
211
+ });
212
+
213
+ // 如果当前没有在 pending 的回调,
214
+ // 就执行 timeFunc 函数选择当前环境优先支持的异步方法
215
+ if (!pending) {
216
+ pending = true;
217
+ timerFunc();
218
+ }
219
+
220
+ // 如果没有传入回调,并且当前环境支持 promise,就返回一个 promise
221
+ // 在返回的这个 promise.then 中 DOM 已经更新好了,
222
+ if (!cb && typeof Promise !== 'undefined') {
223
+ return new Promise(function (resolve) {
224
+ _resolve = resolve;
225
+ });
226
+ }
227
+ }
228
+
229
+ // 判断当前环境优先支持的异步方法,优先选择微任务
230
+ // 优先级:Promise---> MutationObserver---> setImmediate---> setTimeout
231
+ // setTimeout 可能产生一个 4ms 的延迟,而 setImmediate 会在主线程执行完后立刻执行
232
+ // setImmediate 在 IE10 和 node 中支持
233
+
234
+ // 当在同一轮事件循环中多次调用 nextTick 时 ,timerFunc 只会执行一次
235
+
236
+ var timerFunc;
237
+ // 判断当前环境是否原生支持 promise
238
+ if (typeof Promise !== 'undefined' && isNative(Promise)) {
239
+ // 支持 promise
240
+ var p = Promise.resolve();
241
+ timerFunc = function timerFunc() {
242
+ // 用 promise.then 把 flushCallbacks 函数包裹成一个异步微任务
243
+ p.then(flushCallbacks);
244
+ if (isIOS) {
245
+ setTimeout(noop);
246
+ }
247
+ // 这里的 setTimeout 是用来强制刷新微任务队列的
248
+ // 因为在 ios 下 promise.then 后面没有宏任务的话,微任务队列不会刷新
249
+ };
250
+ // 标记当前 nextTick 使用的微任务
251
+ isUsingMicroTask = true;
252
+
253
+ // 如果不支持 promise,就判断是否支持 MutationObserver
254
+ // 不是IE环境,并且原生支持 MutationObserver,那也是一个微任务
255
+ } else if (typeof MutationObserver !== 'undefined' && (isNative(MutationObserver) || MutationObserver.toString() === '[object MutationObserverConstructor]')) {
256
+ var counter = 1;
257
+ // new 一个 MutationObserver 类
258
+ var observer = new MutationObserver(flushCallbacks);
259
+ // 创建一个文本节点
260
+ var textNode = document.createTextNode(String(counter));
261
+ // 监听这个文本节点,当数据发生变化就执行 flushCallbacks
262
+ observer.observe(textNode, {
263
+ characterData: true
264
+ });
265
+ timerFunc = function timerFunc() {
266
+ counter = (counter + 1) % 2;
267
+ textNode.data = String(counter); // 数据更新
268
+ };
269
+ isUsingMicroTask = true; // 标记当前 nextTick 使用的微任务
270
+
271
+ // 判断当前环境是否原生支持 setImmediate
272
+ } else if (typeof setImmediate !== 'undefined' && isNative(setImmediate)) {
273
+ timerFunc = function timerFunc() {
274
+ setImmediate(flushCallbacks);
275
+ };
276
+ } else {
277
+ // 以上三种都不支持就选择 setTimeout
278
+ timerFunc = function timerFunc() {
279
+ setTimeout(flushCallbacks, 0);
280
+ };
281
+ }
282
+
283
+ // 如果多次调用 nextTick,会依次执行上面的方法,将 nextTick 的回调放在 callbacks 数组中
284
+ // 最后通过 flushCallbacks 函数遍历 callbacks 数组的拷贝并执行其中的回调
285
+ function flushCallbacks() {
286
+ pending = false;
287
+ var copies = callbacks.slice(0); // 拷贝一份 callbacks
288
+ callbacks.length = 0; // 清空 callbacks
289
+ for (var i = 0; i < copies.length; i++) {
290
+ // 遍历执行传入的回调
291
+ copies[i]();
292
+ }
293
+ }
294
+
295
+ // 为什么要拷贝一份 callbacks
296
+
297
+ // 用 callbacks.slice(0) 将 callbacks 拷贝出来一份,
298
+ // 是因为考虑到在 nextTick 回调中可能还会调用 nextTick 的情况,
299
+ // 如果在 nextTick 回调中又调用了一次 nextTick,则又会向 callbacks 中添加回调,
300
+ // 而 nextTick 回调中的 nextTick 应该放在下一轮执行,
301
+ // 否则就可能出现一直循环的情况,
302
+ // 所以需要将 callbacks 复制一份出来然后清空,再遍历备份列表执行回调
303
+
304
+ export var escapeStringRegexp = function escapeStringRegexp() {
305
+ var string = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
306
+ return string.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&').replace(/-/g, '\\x2d');
307
+ };
@@ -1,9 +1,12 @@
1
+ import { IconName } from '../Icon';
1
2
  export declare const TypeMap: {
3
+ primary: string;
2
4
  success: string;
3
5
  info: string;
4
6
  warning: string;
5
7
  error: string;
6
8
  };
9
+ export declare const TypeComponentsMap: Record<string, IconName>;
7
10
  export declare const EVENT_CODE: {
8
11
  tab: string;
9
12
  enter: string;
@@ -1,9 +1,17 @@
1
1
  export var TypeMap = {
2
+ primary: 'primary',
2
3
  success: 'success',
3
4
  info: 'info',
4
5
  warning: 'warning',
5
6
  error: 'error'
6
7
  };
8
+ export var TypeComponentsMap = {
9
+ primary: 'info-circle',
10
+ success: 'circle-check',
11
+ info: 'info-circle',
12
+ warning: 'circle-exclamation',
13
+ error: 'circle-xmark'
14
+ };
7
15
  export var EVENT_CODE = {
8
16
  tab: 'Tab',
9
17
  enter: 'Enter',
@@ -9,5 +9,6 @@ export { default as prefix } from './prefix';
9
9
  export { partitionTreePropsUtils } from './treePropsUtils';
10
10
  export { default as useChildrenInstance } from './useChildrenInstance';
11
11
  export * from './useCommonProps';
12
+ export { useConfigProvider } from './useConfigProvider';
12
13
  export { useForceUpdate } from './useForceUpdate';
13
14
  export { default as useUpdateEffect } from './useUpdateEffect';
@@ -11,5 +11,6 @@ export { default as prefix } from "./prefix";
11
11
  export { partitionTreePropsUtils } from "./treePropsUtils";
12
12
  export { default as useChildrenInstance } from "./useChildrenInstance";
13
13
  export * from "./useCommonProps";
14
+ export { useConfigProvider } from "./useConfigProvider";
14
15
  export { useForceUpdate } from "./useForceUpdate";
15
16
  export { default as useUpdateEffect } from "./useUpdateEffect";
@@ -1,7 +1,7 @@
1
1
  import forEach from 'lodash/forEach';
2
2
  import includes from 'lodash/includes';
3
3
  // @ts-ignore
4
- export var popperAllProps = ['popperInstRef', 'offset', 'placement', 'arrowOffset', 'showArrow', 'popperClass', 'popperStyle', 'name', 'display', 'unmountOnExit', 'transitionAppear', 'duration', 'gpuAcceleration', 'strategy', 'appendToBody', 'appendTo', 'popperOptions', 'fallbackPlacements'];
4
+ export var popperAllProps = ['popperInstRef', 'offset', 'placement', 'arrowOffset', 'showArrow', 'popperClass', 'popperStyle', 'name', 'display', 'unmountOnExit', 'transitionAppear', 'duration', 'gpuAcceleration', 'strategy', 'appendToBody', 'appendTo', 'popperOptions', 'fallbackPlacements', 'effect'];
5
5
 
6
6
  /**
7
7
  * Returns an array of objects consisting of: props of html input element and rest.