@qsxy/element-plus-react 1.0.1 → 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 (256) 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/Calendar/Calendar.js +12 -3
  8. package/dist/Calendar/Footer.js +4 -2
  9. package/dist/Calendar/QuarterPanel.d.ts +4 -0
  10. package/dist/Calendar/QuarterPanel.js +109 -0
  11. package/dist/Calendar/WeekPanel.js +1 -1
  12. package/dist/Calendar/typings.d.ts +1 -1
  13. package/dist/Card/Card.js +13 -6
  14. package/dist/Card/typings.d.ts +1 -1
  15. package/dist/Cascader/Cascader.js +1 -1
  16. package/dist/Cascader/useCascader.d.ts +0 -14
  17. package/dist/Cascader/useCascader.js +33 -32
  18. package/dist/Checkbox/Checkbox.js +3 -2
  19. package/dist/ConfigProvider/ConfigProvider.js +2 -24
  20. package/dist/ConfigProvider/ConfigProviderContext.js +1 -1
  21. package/dist/ConfigProvider/typings.d.ts +1 -1
  22. package/dist/Container/Main.d.ts +1 -1
  23. package/dist/Container/typings.d.ts +1 -1
  24. package/dist/DatePicker/DatePicker.js +38 -12
  25. package/dist/DatePicker/DateRangePicker.js +27 -9
  26. package/dist/DatePicker/main.js +1 -1
  27. package/dist/DatePicker/typings.d.ts +1 -1
  28. package/dist/DateTimePicker/DateTimePicker.js +2 -2
  29. package/dist/Dialog/Dialog.js +5 -12
  30. package/dist/Input/Input.js +190 -149
  31. package/dist/Input/InputRange.js +1 -1
  32. package/dist/Input/TextArea.js +87 -12
  33. package/dist/Input/typings.d.ts +56 -5
  34. package/dist/Input/useComposition.d.ts +23 -0
  35. package/dist/Input/useComposition.js +63 -0
  36. package/dist/Input/utils.d.ts +7 -0
  37. package/dist/Input/utils.js +95 -0
  38. package/dist/InputNumber/InputNumber.js +351 -141
  39. package/dist/InputNumber/typings.d.ts +16 -2
  40. package/dist/Loading/Loading.js +5 -2
  41. package/dist/Menu/Menu.js +25 -1
  42. package/dist/Menu/MenuItem.js +4 -2
  43. package/dist/Menu/SubMenu.js +2 -2
  44. package/dist/Menu/SubMenuCollapseTransition.js +14 -9
  45. package/dist/Menu/typings.d.ts +2 -1
  46. package/dist/Message/Message.js +51 -23
  47. package/dist/Message/index.js +8 -10
  48. package/dist/Message/typings.d.ts +8 -5
  49. package/dist/MessageBox/MessageBox.js +52 -30
  50. package/dist/MessageBox/index.d.ts +2 -1
  51. package/dist/MessageBox/index.js +4 -2
  52. package/dist/MessageBox/typings.d.ts +3 -0
  53. package/dist/Notification/Notification.js +26 -19
  54. package/dist/Select/Option.js +30 -14
  55. package/dist/Select/SelectContext.d.ts +5 -5
  56. package/dist/Select/SelectContext.js +2 -1
  57. package/dist/Select/SelectCore.d.ts +2 -2
  58. package/dist/Select/SelectCore.js +172 -449
  59. package/dist/Select/SelectDropdown.js +85 -155
  60. package/dist/Select/index.d.ts +1 -1
  61. package/dist/Select/typings.d.ts +52 -22
  62. package/dist/Select/useSelect.d.ts +128 -0
  63. package/dist/Select/useSelect.js +524 -0
  64. package/dist/Space/Space.d.ts +4 -0
  65. package/dist/Space/Space.js +128 -0
  66. package/dist/Space/SpaceItem.d.ts +7 -0
  67. package/dist/Space/SpaceItem.js +14 -0
  68. package/dist/Space/index.d.ts +3 -0
  69. package/dist/Space/index.js +2 -0
  70. package/dist/Space/typings.d.ts +26 -0
  71. package/dist/Space/typings.js +1 -0
  72. package/dist/Space/useSpace.d.ts +7 -0
  73. package/dist/Space/useSpace.js +104 -0
  74. package/dist/Statistic/Statistic.d.ts +4 -0
  75. package/dist/Statistic/Statistic.js +92 -0
  76. package/dist/Statistic/index.d.ts +2 -0
  77. package/dist/Statistic/index.js +1 -0
  78. package/dist/Statistic/typings.d.ts +28 -0
  79. package/dist/Statistic/typings.js +1 -0
  80. package/dist/Switch/Switch.js +2 -2
  81. package/dist/Table/Table.js +3 -0
  82. package/dist/Table/typings.d.ts +2 -0
  83. package/dist/Table/util.js +6 -5
  84. package/dist/Tag/Tag.js +22 -17
  85. package/dist/Tag/typings.d.ts +1 -1
  86. package/dist/Text/Text.d.ts +4 -0
  87. package/dist/Text/Text.js +84 -0
  88. package/dist/Text/index.d.ts +2 -0
  89. package/dist/Text/index.js +1 -0
  90. package/dist/Text/typings.d.ts +15 -0
  91. package/dist/Text/typings.js +1 -0
  92. package/dist/TimePicker/TimePicker.js +2 -2
  93. package/dist/Tree/CollapseTransition.d.ts +7 -0
  94. package/dist/Tree/CollapseTransition.js +60 -0
  95. package/dist/Tree/Tree.d.ts +3 -140
  96. package/dist/Tree/Tree.js +350 -77
  97. package/dist/Tree/TreeContext.d.ts +9 -0
  98. package/dist/Tree/TreeContext.js +14 -0
  99. package/dist/Tree/TreeNode.d.ts +5 -3
  100. package/dist/Tree/TreeNode.js +321 -331
  101. package/dist/Tree/TreeNodeContent.d.ts +9 -0
  102. package/dist/Tree/TreeNodeContent.js +22 -0
  103. package/dist/Tree/index.d.ts +3 -8
  104. package/dist/Tree/index.js +1 -4
  105. package/dist/Tree/model/node.d.ts +62 -0
  106. package/dist/Tree/model/node.js +601 -0
  107. package/dist/Tree/model/tree-store.d.ts +52 -0
  108. package/dist/Tree/model/tree-store.js +510 -0
  109. package/dist/Tree/model/useDragNode.d.ts +30 -0
  110. package/dist/Tree/model/useDragNode.js +293 -0
  111. package/dist/Tree/model/useKeydown.d.ts +0 -0
  112. package/dist/Tree/model/useKeydown.js +104 -0
  113. package/dist/Tree/model/useNodeExpandEventBroadcast.d.ts +15 -0
  114. package/dist/Tree/model/useNodeExpandEventBroadcast.js +54 -0
  115. package/dist/Tree/model/util.d.ts +7 -0
  116. package/dist/Tree/model/util.js +24 -0
  117. package/dist/Tree/typings.d.ts +225 -114
  118. package/dist/TreeSelect/TreeSelect.d.ts +2 -10
  119. package/dist/TreeSelect/TreeSelect.js +90 -566
  120. package/dist/TreeSelect/TreeSelectOption.d.ts +6 -0
  121. package/dist/TreeSelect/TreeSelectOption.js +62 -0
  122. package/dist/TreeSelect/cacheOptions.d.ts +9 -0
  123. package/dist/TreeSelect/cacheOptions.js +22 -0
  124. package/dist/TreeSelect/index.d.ts +0 -1
  125. package/dist/TreeSelect/typings.d.ts +11 -63
  126. package/dist/TreeSelect/useSelect.d.ts +125 -0
  127. package/dist/TreeSelect/useSelect.js +104 -0
  128. package/dist/TreeSelect/useTree.d.ts +130 -0
  129. package/dist/TreeSelect/useTree.js +285 -0
  130. package/dist/TreeSelect/utils.d.ts +10 -0
  131. package/dist/TreeSelect/utils.js +38 -0
  132. package/dist/Upload/UploadContent.js +2 -0
  133. package/dist/Upload/ajax.js +3 -0
  134. package/dist/Upload/typings.d.ts +4 -0
  135. package/dist/Util/aria.d.ts +25 -0
  136. package/dist/Util/aria.js +118 -0
  137. package/dist/Util/base.d.ts +5 -0
  138. package/dist/Util/base.js +140 -1
  139. package/dist/config/Constants.d.ts +3 -0
  140. package/dist/config/Constants.js +8 -0
  141. package/dist/hooks/index.d.ts +1 -0
  142. package/dist/hooks/index.js +1 -0
  143. package/dist/hooks/popperPropsUtils.js +1 -1
  144. package/dist/hooks/treePropsUtils.d.ts +3 -3
  145. package/dist/hooks/treePropsUtils.js +2 -2
  146. package/dist/hooks/useCalcInputWidth.d.ts +8 -0
  147. package/dist/{Tree/useUnmount.js → hooks/useCalcInputWidth.js} +23 -27
  148. package/dist/hooks/useComposition.d.ts +16 -0
  149. package/dist/hooks/useComposition.js +39 -0
  150. package/dist/hooks/useConfigProvider.d.ts +27 -0
  151. package/dist/hooks/useConfigProvider.js +78 -0
  152. package/dist/hooks/useCursor.d.ts +2 -0
  153. package/dist/hooks/useCursor.js +52 -0
  154. package/dist/hooks/useFocusController.d.ts +27 -0
  155. package/dist/hooks/useFocusController.js +72 -0
  156. package/dist/hooks/useResizeObserver.js +6 -6
  157. package/dist/index.css +1 -1
  158. package/dist/index.d.ts +18 -11
  159. package/dist/index.js +11 -5
  160. package/dist/locale/en.d.ts +15 -0
  161. package/dist/locale/en.js +15 -0
  162. package/dist/locale/zhCn.d.ts +15 -0
  163. package/dist/locale/zhCn.js +15 -0
  164. package/package.json +1 -1
  165. package/theme-chalk/alert.scss +115 -0
  166. package/theme-chalk/aside.scss +8 -8
  167. package/theme-chalk/button-group.scss +80 -80
  168. package/theme-chalk/button.scss +304 -304
  169. package/theme-chalk/calendar/date-table.scss +164 -164
  170. package/theme-chalk/calendar/index.scss +1 -0
  171. package/theme-chalk/calendar/quarter-table.scss +78 -0
  172. package/theme-chalk/checkbox.scss +34 -0
  173. package/theme-chalk/color/index.scss +20 -20
  174. package/theme-chalk/common/transition.scss +142 -142
  175. package/theme-chalk/common/var.scss +1 -1
  176. package/theme-chalk/container.scss +14 -14
  177. package/theme-chalk/dark/css-vars.scss +39 -39
  178. package/theme-chalk/dark/var.scss +225 -225
  179. package/theme-chalk/date-picker.scss +12 -12
  180. package/theme-chalk/drawer.scss +1 -0
  181. package/theme-chalk/footer.scss +12 -12
  182. package/theme-chalk/header.scss +12 -12
  183. package/theme-chalk/index.scss +4 -0
  184. package/theme-chalk/input/input-range.scss +2 -1
  185. package/theme-chalk/input/input.scss +298 -437
  186. package/theme-chalk/input/input.scss--bak +578 -0
  187. package/theme-chalk/input-number.bak +172 -0
  188. package/theme-chalk/input-number.scss +192 -172
  189. package/theme-chalk/link.scss +87 -87
  190. package/theme-chalk/main.scss +14 -14
  191. package/theme-chalk/menu.scss +353 -353
  192. package/theme-chalk/message.scss +104 -178
  193. package/theme-chalk/mixins/_button.scss +224 -224
  194. package/theme-chalk/mixins/_col.scss +33 -33
  195. package/theme-chalk/mixins/_var.scss +67 -67
  196. package/theme-chalk/mixins/config.scss +5 -5
  197. package/theme-chalk/mixins/function.scss +99 -99
  198. package/theme-chalk/mixins/mixins.scss +240 -240
  199. package/theme-chalk/mixins/utils.scss +39 -39
  200. package/theme-chalk/notification.bak +156 -0
  201. package/theme-chalk/notification.scss +109 -156
  202. package/theme-chalk/popper.scss +104 -104
  203. package/theme-chalk/radio-button.scss +169 -169
  204. package/theme-chalk/select/index.scss +222 -191
  205. package/theme-chalk/select/index.scss--bak +247 -0
  206. package/theme-chalk/select/option-group.scss +2 -2
  207. package/theme-chalk/select/option.scss +2 -2
  208. package/theme-chalk/select/select-dropdown.scss +2 -2
  209. package/theme-chalk/space.scss +20 -0
  210. package/theme-chalk/statistic.scss +35 -0
  211. package/theme-chalk/switch.scss +300 -300
  212. package/theme-chalk/tag.scss +150 -172
  213. package/theme-chalk/tag.scss--bak +203 -0
  214. package/theme-chalk/text.scss +48 -0
  215. package/theme-chalk/transition.scss +34 -4
  216. package/theme-chalk/tree-select.scss +41 -25
  217. package/theme-chalk/tree.scss +136 -0
  218. package/theme-chalk/var.scss +83 -83
  219. package/dist/Tree/DirectoryTree.d.ts +0 -15
  220. package/dist/Tree/DirectoryTree.js +0 -183
  221. package/dist/Tree/DropIndicator.d.ts +0 -8
  222. package/dist/Tree/DropIndicator.js +0 -34
  223. package/dist/Tree/Indent.d.ts +0 -9
  224. package/dist/Tree/Indent.js +0 -25
  225. package/dist/Tree/MotionTreeNode.d.ts +0 -14
  226. package/dist/Tree/MotionTreeNode.js +0 -125
  227. package/dist/Tree/NodeList.d.ts +0 -50
  228. package/dist/Tree/NodeList.js +0 -301
  229. package/dist/Tree/RCTree.d.ts +0 -248
  230. package/dist/Tree/RCTree.js +0 -1216
  231. package/dist/Tree/contextTypes.d.ts +0 -69
  232. package/dist/Tree/contextTypes.js +0 -9
  233. package/dist/Tree/typings.tsx--bak +0 -245
  234. package/dist/Tree/useUnmount.d.ts +0 -5
  235. package/dist/Tree/util.d.ts +0 -51
  236. package/dist/Tree/util.js +0 -303
  237. package/dist/Tree/utils/conductUtil.d.ts +0 -17
  238. package/dist/Tree/utils/conductUtil.js +0 -209
  239. package/dist/Tree/utils/dictUtil.d.ts +0 -13
  240. package/dist/Tree/utils/dictUtil.js +0 -75
  241. package/dist/Tree/utils/diffUtil.d.ts +0 -7
  242. package/dist/Tree/utils/diffUtil.js +0 -48
  243. package/dist/Tree/utils/dropIndicator.d.ts +0 -11
  244. package/dist/Tree/utils/dropIndicator.js +0 -36
  245. package/dist/Tree/utils/iconUtil.d.ts +0 -5
  246. package/dist/Tree/utils/iconUtil.js +0 -62
  247. package/dist/Tree/utils/keyUtil.d.ts +0 -2
  248. package/dist/Tree/utils/keyUtil.js +0 -3
  249. package/dist/Tree/utils/motion.d.ts +0 -10
  250. package/dist/Tree/utils/motion.js +0 -54
  251. package/dist/Tree/utils/pickAttrs.d.ts +0 -11
  252. package/dist/Tree/utils/pickAttrs.js +0 -51
  253. package/dist/Tree/utils/treeUtil.d.ts +0 -86
  254. package/dist/Tree/utils/treeUtil.js +0 -364
  255. package/dist/TreeSelect/Utils.d.ts +0 -3
  256. 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 {
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Determine if the testing element is visible on screen no matter if its on the viewport or not
3
+ */
4
+ export declare const isVisible: (element: HTMLElement) => boolean;
5
+ export declare const obtainAllFocusableElements: (element: HTMLElement) => HTMLElement[];
6
+ /**
7
+ * @desc Determine if target element is focusable
8
+ * @param element {HTMLElement}
9
+ * @returns {Boolean} true if it is focusable
10
+ */
11
+ export declare const isFocusable: (element: HTMLElement) => boolean;
12
+ /**
13
+ * Trigger an event
14
+ * mouseenter, mouseleave, mouseover, keyup, change, click, etc.
15
+ * @param {HTMLElement} elm
16
+ * @param {String} name
17
+ * @param {*} opts
18
+ */
19
+ export declare const triggerEvent: (elm: HTMLElement, name: string, ...opts: Array<boolean>) => HTMLElement;
20
+ export declare const isLeaf: (el: HTMLElement) => boolean;
21
+ export declare const getSibling: (el: HTMLElement, distance: number, elClass: string) => Element;
22
+ export declare const focusElement: (el?: HTMLElement | {
23
+ focus: () => void;
24
+ } | null, options?: FocusOptions) => void;
25
+ export declare const focusNode: (el: HTMLElement) => void;
@@ -0,0 +1,118 @@
1
+ var FOCUSABLE_ELEMENT_SELECTORS = 'a[href],button:not([disabled]),button:not([hidden]),:not([tabindex="-1"]),input:not([disabled]),input:not([type="hidden"]),select:not([disabled]),textarea:not([disabled])';
2
+ var isHTMLElement = function isHTMLElement(e) {
3
+ if (typeof Element === 'undefined') {
4
+ return false;
5
+ }
6
+ return e instanceof Element;
7
+ };
8
+
9
+ /**
10
+ * Determine if the testing element is visible on screen no matter if its on the viewport or not
11
+ */
12
+ export var isVisible = function isVisible(element) {
13
+ if (process.env.NODE_ENV === 'test') {
14
+ return true;
15
+ }
16
+ var computed = getComputedStyle(element);
17
+ // element.offsetParent won't work on fix positioned
18
+ // WARNING: potential issue here, going to need some expert advices on this issue
19
+ return computed.position === 'fixed' ? false : element.offsetParent !== null;
20
+ };
21
+ export var obtainAllFocusableElements = function obtainAllFocusableElements(element) {
22
+ return Array.from(element.querySelectorAll(FOCUSABLE_ELEMENT_SELECTORS)).filter(function (item) {
23
+ return isFocusable(item) && isVisible(item);
24
+ });
25
+ };
26
+
27
+ /**
28
+ * @desc Determine if target element is focusable
29
+ * @param element {HTMLElement}
30
+ * @returns {Boolean} true if it is focusable
31
+ */
32
+ export var isFocusable = function isFocusable(element) {
33
+ if (element.tabIndex > 0 || element.tabIndex === 0 && element.getAttribute('tabIndex') !== null) {
34
+ return true;
35
+ }
36
+ if (element.tabIndex < 0 || element.hasAttribute('disabled') || element.getAttribute('aria-disabled') === 'true') {
37
+ return false;
38
+ }
39
+ switch (element.nodeName) {
40
+ case 'A':
41
+ {
42
+ // casting current element to Specific HTMLElement in order to be more type precise
43
+ return !!element.href && element.rel !== 'ignore';
44
+ }
45
+ case 'INPUT':
46
+ {
47
+ return !(element.type === 'hidden' || element.type === 'file');
48
+ }
49
+ case 'BUTTON':
50
+ case 'SELECT':
51
+ case 'TEXTAREA':
52
+ {
53
+ return true;
54
+ }
55
+ default:
56
+ {
57
+ return false;
58
+ }
59
+ }
60
+ };
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
68
+ */
69
+ export var triggerEvent = function triggerEvent(elm, name) {
70
+ var eventName;
71
+ if (name.includes('mouse') || name.includes('click')) {
72
+ eventName = 'MouseEvents';
73
+ } else if (name.includes('key')) {
74
+ eventName = 'KeyboardEvent';
75
+ } else {
76
+ eventName = 'HTMLEvents';
77
+ }
78
+ var evt = document.createEvent(eventName);
79
+ for (var _len = arguments.length, opts = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
80
+ opts[_key - 2] = arguments[_key];
81
+ }
82
+ evt.initEvent.apply(evt, [name].concat(opts));
83
+ elm.dispatchEvent(evt);
84
+ return elm;
85
+ };
86
+ export var isLeaf = function isLeaf(el) {
87
+ return !el.getAttribute('aria-owns');
88
+ };
89
+ export var getSibling = function getSibling(el, distance, elClass) {
90
+ var parentNode = el.parentNode;
91
+ if (!parentNode) {
92
+ return null;
93
+ }
94
+ var siblings = parentNode.querySelectorAll(elClass);
95
+ var index = Array.prototype.indexOf.call(siblings, el);
96
+ return siblings[index + distance] || null;
97
+ };
98
+ export var focusElement = function focusElement(el, options) {
99
+ if (!el || !el.focus) {
100
+ return;
101
+ }
102
+ var cleanup = false;
103
+ if (isHTMLElement(el) && !isFocusable(el) && !el.getAttribute('tabindex')) {
104
+ el.setAttribute('tabindex', '-1');
105
+ cleanup = true;
106
+ }
107
+ el.focus(options);
108
+ if (isHTMLElement(el) && cleanup) {
109
+ el.removeAttribute('tabindex');
110
+ }
111
+ };
112
+ export var focusNode = function focusNode(el) {
113
+ if (!el) {
114
+ return;
115
+ }
116
+ focusElement(el);
117
+ !isLeaf(el) && el.click();
118
+ };
@@ -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;