@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,601 @@
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 _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
9
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
10
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
11
+ 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; }
12
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
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); }
14
+ import { NODE_KEY, markNodeData } from "./util";
15
+ import isNil from 'lodash/isNil';
16
+ import { isBoolean, isFunction, isString, isUndefined } from "../../Util";
17
+ export var getChildState = function getChildState(node) {
18
+ var all = true;
19
+ var none = true;
20
+ var allWithoutDisable = true;
21
+ var isEffectivelyChecked = true;
22
+ for (var i = 0, j = node.length; i < j; i++) {
23
+ var n = node[i];
24
+ if (n.checked !== true || n.indeterminate) {
25
+ all = false;
26
+ if (!n.disabled) {
27
+ allWithoutDisable = false;
28
+ }
29
+ }
30
+ if (n.checked !== false || n.indeterminate) {
31
+ none = false;
32
+ }
33
+ if (!n.isEffectivelyChecked) {
34
+ isEffectivelyChecked = false;
35
+ }
36
+ }
37
+ return {
38
+ all: all,
39
+ none: none,
40
+ allWithoutDisable: allWithoutDisable,
41
+ half: !all && !none,
42
+ isEffectivelyChecked: isEffectivelyChecked
43
+ };
44
+ };
45
+ var _reInitChecked = function reInitChecked(node) {
46
+ if (node.childNodes.length === 0 || node.loading) {
47
+ node.isEffectivelyChecked = node.disabled || node.checked;
48
+ return;
49
+ }
50
+ var _getChildState = getChildState(node.childNodes),
51
+ all = _getChildState.all,
52
+ none = _getChildState.none,
53
+ half = _getChildState.half,
54
+ isEffectivelyChecked = _getChildState.isEffectivelyChecked;
55
+ node.isEffectivelyChecked = isEffectivelyChecked;
56
+ if (all) {
57
+ node.checked = true;
58
+ node.indeterminate = false;
59
+ } else if (half) {
60
+ node.checked = false;
61
+ node.indeterminate = true;
62
+ } else if (none) {
63
+ node.checked = false;
64
+ node.indeterminate = false;
65
+ }
66
+ var parent = node.parent;
67
+ if (!parent || parent.level === 0) {
68
+ return;
69
+ }
70
+ if (!node.store.checkStrictly) {
71
+ _reInitChecked(parent);
72
+ }
73
+ };
74
+ var getPropertyFromData = function getPropertyFromData(node, prop) {
75
+ var props = node.store.props;
76
+ var data = node.data || {};
77
+ var config = props[prop];
78
+ if (isFunction(config)) {
79
+ return config(data, node);
80
+ } else if (isString(config)) {
81
+ return data[config];
82
+ } else if (isUndefined(config)) {
83
+ var dataProp = data[prop];
84
+ return isUndefined(dataProp) ? '' : dataProp;
85
+ }
86
+ };
87
+ var setCanFocus = function setCanFocus(childNodes, focus) {
88
+ childNodes.forEach(function (item) {
89
+ item.canFocus = focus;
90
+ setCanFocus(item.childNodes, focus);
91
+ });
92
+ };
93
+ var nodeIdSeed = 0;
94
+ var Node = /*#__PURE__*/function () {
95
+ function Node(options) {
96
+ _classCallCheck(this, Node);
97
+ _defineProperty(this, "id", void 0);
98
+ _defineProperty(this, "text", void 0);
99
+ _defineProperty(this, "checked", void 0);
100
+ _defineProperty(this, "indeterminate", void 0);
101
+ _defineProperty(this, "data", void 0);
102
+ _defineProperty(this, "expanded", void 0);
103
+ _defineProperty(this, "parent", void 0);
104
+ _defineProperty(this, "visible", void 0);
105
+ _defineProperty(this, "isCurrent", void 0);
106
+ _defineProperty(this, "store", void 0);
107
+ _defineProperty(this, "isLeafByUser", undefined);
108
+ _defineProperty(this, "isLeaf", undefined);
109
+ _defineProperty(this, "canFocus", void 0);
110
+ _defineProperty(this, "level", void 0);
111
+ _defineProperty(this, "loaded", void 0);
112
+ _defineProperty(this, "childNodes", void 0);
113
+ _defineProperty(this, "loading", void 0);
114
+ /**
115
+ * Determines whether the current tree node is effectively checked.
116
+ *
117
+ * Rules:
118
+ * 1. A disabled leaf node is always considered checked.
119
+ * 2. A non-disabled leaf node reflects its actual checked state.
120
+ * 3. A non-leaf node is considered checked only when:
121
+ * - All of its child nodes are effectively checked, and
122
+ * - Each child follows the same evaluation rules:
123
+ * - Disabled leaf nodes follow rule #1.
124
+ * - Non-leaf child nodes are recursively evaluated under this rule (#3).
125
+ */
126
+ _defineProperty(this, "isEffectivelyChecked", false);
127
+ this.id = nodeIdSeed++;
128
+ this.text = null;
129
+ this.checked = false;
130
+ this.indeterminate = false;
131
+ this.data = null;
132
+ this.expanded = false;
133
+ this.parent = null;
134
+ this.visible = true;
135
+ this.isCurrent = false;
136
+ this.canFocus = false;
137
+ for (var name in options) {
138
+ if (Object.prototype.hasOwnProperty.call(options, name)) {
139
+ this[name] = options[name];
140
+ }
141
+ }
142
+
143
+ // internal
144
+ this.level = 0;
145
+ this.loaded = false;
146
+ this.childNodes = [];
147
+ this.loading = false;
148
+ if (this.parent) {
149
+ this.level = this.parent.level + 1;
150
+ }
151
+ }
152
+ _createClass(Node, [{
153
+ key: "initialize",
154
+ value: function initialize() {
155
+ var _this$parent;
156
+ var store = this.store;
157
+ if (!store) {
158
+ throw new Error('[Node]store is required!');
159
+ }
160
+ store.registerNode(this);
161
+ var props = store.props;
162
+ if (props && typeof props.isLeaf !== 'undefined') {
163
+ var isLeaf = getPropertyFromData(this, 'isLeaf');
164
+ if (isBoolean(isLeaf)) {
165
+ this.isLeafByUser = isLeaf;
166
+ }
167
+ }
168
+ if (store.lazy !== true && this.data) {
169
+ this.setData(this.data);
170
+ if (store.defaultExpandAll) {
171
+ this.expanded = true;
172
+ this.canFocus = true;
173
+ }
174
+ } else if (this.level > 0 && store.lazy && store.defaultExpandAll && !this.isLeafByUser) {
175
+ this.expand();
176
+ }
177
+ if (!Array.isArray(this.data)) {
178
+ markNodeData(this, this.data);
179
+ }
180
+ if (!this.data) {
181
+ return;
182
+ }
183
+ var defaultExpandedKeys = store.defaultExpandedKeys;
184
+ var key = store.key;
185
+ if (key && !isNil(this.key) && defaultExpandedKeys && defaultExpandedKeys.includes(this.key)) {
186
+ this.expand(null, store.autoExpandParent);
187
+ }
188
+ if (key && store.currentNodeKey !== undefined && this.key === store.currentNodeKey) {
189
+ store.currentNode && (store.currentNode.isCurrent = false);
190
+ store.currentNode = this;
191
+ store.currentNode.isCurrent = true;
192
+ }
193
+ if (store.lazy) {
194
+ store._initDefaultCheckedNode(this);
195
+ }
196
+ this.updateLeafState();
197
+ if (this.level === 1 || ((_this$parent = this.parent) === null || _this$parent === void 0 ? void 0 : _this$parent.expanded) === true) {
198
+ this.canFocus = true;
199
+ }
200
+ }
201
+ }, {
202
+ key: "setData",
203
+ value: function setData(data) {
204
+ if (!Array.isArray(data)) {
205
+ markNodeData(this, data);
206
+ }
207
+ this.data = data;
208
+ this.childNodes = [];
209
+ var children;
210
+ if (this.level === 0 && Array.isArray(this.data)) {
211
+ children = this.data;
212
+ } else {
213
+ children = getPropertyFromData(this, 'children') || [];
214
+ }
215
+ for (var i = 0, j = children.length; i < j; i++) {
216
+ this.insertChild({
217
+ data: children[i]
218
+ });
219
+ }
220
+ }
221
+ }, {
222
+ key: "label",
223
+ get: function get() {
224
+ return getPropertyFromData(this, 'label');
225
+ }
226
+ }, {
227
+ key: "key",
228
+ get: function get() {
229
+ var nodeKey = this.store.key;
230
+ if (this.data) {
231
+ return this.data[nodeKey];
232
+ }
233
+ return null;
234
+ }
235
+ }, {
236
+ key: "disabled",
237
+ get: function get() {
238
+ return getPropertyFromData(this, 'disabled');
239
+ }
240
+ }, {
241
+ key: "nextSibling",
242
+ get: function get() {
243
+ var parent = this.parent;
244
+ if (parent) {
245
+ var index = parent.childNodes.indexOf(this);
246
+ if (index > -1) {
247
+ return parent.childNodes[index + 1];
248
+ }
249
+ }
250
+ return null;
251
+ }
252
+ }, {
253
+ key: "previousSibling",
254
+ get: function get() {
255
+ var parent = this.parent;
256
+ if (parent) {
257
+ var index = parent.childNodes.indexOf(this);
258
+ if (index > -1) {
259
+ return index > 0 ? parent.childNodes[index - 1] : null;
260
+ }
261
+ }
262
+ return null;
263
+ }
264
+ }, {
265
+ key: "contains",
266
+ value: function contains(target) {
267
+ var deep = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
268
+ return (this.childNodes || []).some(function (child) {
269
+ return child === target || deep && child.contains(target);
270
+ });
271
+ }
272
+ }, {
273
+ key: "remove",
274
+ value: function remove() {
275
+ var parent = this.parent;
276
+ if (parent) {
277
+ parent.removeChild(this);
278
+ }
279
+ }
280
+ }, {
281
+ key: "insertChild",
282
+ value: function insertChild(child, index, batch) {
283
+ if (!child) {
284
+ throw new Error('InsertChild error: child is required.');
285
+ }
286
+ if (!(child instanceof Node)) {
287
+ if (!batch) {
288
+ var children = this.getChildren(true);
289
+ if (!(children !== null && children !== void 0 && children.includes(child.data))) {
290
+ if (isUndefined(index) || index < 0) {
291
+ children === null || children === void 0 || children.push(child.data);
292
+ } else {
293
+ children === null || children === void 0 || children.splice(index, 0, child.data);
294
+ }
295
+ }
296
+ }
297
+ Object.assign(child, {
298
+ parent: this,
299
+ store: this.store
300
+ });
301
+ child = new Node(child);
302
+ if (child instanceof Node) {
303
+ child.initialize();
304
+ }
305
+ }
306
+ child.level = this.level + 1;
307
+ if (isUndefined(index) || index < 0) {
308
+ this.childNodes.push(child);
309
+ } else {
310
+ this.childNodes.splice(index, 0, child);
311
+ }
312
+ this.updateLeafState();
313
+ }
314
+ }, {
315
+ key: "insertBefore",
316
+ value: function insertBefore(child, ref) {
317
+ var index;
318
+ if (ref) {
319
+ index = this.childNodes.indexOf(ref);
320
+ }
321
+ this.insertChild(child, index);
322
+ }
323
+ }, {
324
+ key: "insertAfter",
325
+ value: function insertAfter(child, ref) {
326
+ var index;
327
+ if (ref) {
328
+ index = this.childNodes.indexOf(ref);
329
+ if (index !== -1) {
330
+ index += 1;
331
+ }
332
+ }
333
+ this.insertChild(child, index);
334
+ }
335
+ }, {
336
+ key: "removeChild",
337
+ value: function removeChild(child) {
338
+ var children = this.getChildren() || [];
339
+ var dataIndex = children.indexOf(child.data);
340
+ if (dataIndex > -1) {
341
+ children.splice(dataIndex, 1);
342
+ }
343
+ var index = this.childNodes.indexOf(child);
344
+ if (index > -1) {
345
+ this.store && this.store.deregisterNode(child);
346
+ child.parent = null;
347
+ this.childNodes.splice(index, 1);
348
+ }
349
+ this.updateLeafState();
350
+ }
351
+ }, {
352
+ key: "removeChildByData",
353
+ value: function removeChildByData(data) {
354
+ var targetNode = this.childNodes.find(function (child) {
355
+ return child.data === data;
356
+ });
357
+ if (targetNode) {
358
+ this.removeChild(targetNode);
359
+ }
360
+ }
361
+ }, {
362
+ key: "expand",
363
+ value: function expand(callback, expandParent) {
364
+ var _this = this;
365
+ var done = function done() {
366
+ if (expandParent) {
367
+ var parent = _this.parent;
368
+ while (parent && parent.level > 0) {
369
+ parent.expanded = true;
370
+ parent = parent.parent;
371
+ }
372
+ }
373
+ _this.expanded = true;
374
+ if (callback) {
375
+ callback();
376
+ }
377
+ setCanFocus(_this.childNodes, true);
378
+ };
379
+ if (this.shouldLoadData()) {
380
+ this.loadData(function (data) {
381
+ if (Array.isArray(data)) {
382
+ if (_this.checked) {
383
+ _this.setChecked(true, true);
384
+ } else if (!_this.store.checkStrictly) {
385
+ _reInitChecked(_this);
386
+ }
387
+ done();
388
+ }
389
+ });
390
+ } else {
391
+ done();
392
+ }
393
+ }
394
+ }, {
395
+ key: "doCreateChildren",
396
+ value: function doCreateChildren(array) {
397
+ var _this2 = this;
398
+ var defaultProps = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
399
+ array.forEach(function (item) {
400
+ _this2.insertChild(Object.assign({
401
+ data: item
402
+ }, defaultProps), undefined, true);
403
+ });
404
+ }
405
+ }, {
406
+ key: "collapse",
407
+ value: function collapse() {
408
+ this.expanded = false;
409
+ setCanFocus(this.childNodes, false);
410
+ }
411
+ }, {
412
+ key: "shouldLoadData",
413
+ value: function shouldLoadData() {
414
+ return Boolean(this.store.lazy === true && this.store.load && !this.loaded);
415
+ }
416
+ }, {
417
+ key: "updateLeafState",
418
+ value: function updateLeafState() {
419
+ if (this.store.lazy === true && this.loaded !== true && typeof this.isLeafByUser !== 'undefined') {
420
+ this.isLeaf = this.isLeafByUser;
421
+ this.isEffectivelyChecked = this.isLeaf && this.disabled;
422
+ return;
423
+ }
424
+ var childNodes = this.childNodes;
425
+ if (!this.store.lazy || this.store.lazy === true && this.loaded === true) {
426
+ this.isLeaf = !childNodes || childNodes.length === 0;
427
+ this.isEffectivelyChecked = this.isLeaf && this.disabled;
428
+ return;
429
+ }
430
+ this.isLeaf = false;
431
+ }
432
+ }, {
433
+ key: "setChecked",
434
+ value: function setChecked(value, deep, recursion, passValue) {
435
+ var _this3 = this;
436
+ this.indeterminate = value === 'half';
437
+ this.checked = value === true;
438
+ this.isEffectivelyChecked = !this.childNodes.length && (this.disabled || this.checked);
439
+ if (this.store.checkStrictly) {
440
+ return;
441
+ }
442
+ if (!(this.shouldLoadData() && !this.store.checkDescendants)) {
443
+ var handleDescendants = function handleDescendants() {
444
+ if (deep) {
445
+ var childNodes = _this3.childNodes;
446
+ for (var i = 0, j = childNodes.length; i < j; i++) {
447
+ var child = childNodes[i];
448
+ passValue = passValue || value !== false;
449
+ var isCheck = child.disabled && child.isLeaf ? child.checked : passValue;
450
+ child.setChecked(isCheck, deep, true, passValue);
451
+ }
452
+ var _getChildState2 = getChildState(childNodes),
453
+ half = _getChildState2.half,
454
+ all = _getChildState2.all,
455
+ isEffectivelyChecked = _getChildState2.isEffectivelyChecked;
456
+ if (!all) {
457
+ _this3.checked = all;
458
+ _this3.indeterminate = half;
459
+ }
460
+ _this3.isEffectivelyChecked = !_this3.childNodes.length ? _this3.disabled || _this3.checked : isEffectivelyChecked;
461
+ }
462
+ };
463
+ if (this.shouldLoadData()) {
464
+ // Only work on lazy load data.
465
+ this.loadData(function () {
466
+ handleDescendants();
467
+ _reInitChecked(_this3);
468
+ }, {
469
+ checked: value !== false
470
+ });
471
+ return;
472
+ } else {
473
+ handleDescendants();
474
+ }
475
+ }
476
+ var parent = this.parent;
477
+ if (!parent || parent.level === 0) {
478
+ return;
479
+ }
480
+ if (!recursion) {
481
+ _reInitChecked(parent);
482
+ }
483
+ }
484
+ }, {
485
+ key: "getChildren",
486
+ value: function getChildren() {
487
+ var forceInit = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
488
+ // this is data
489
+ if (this.level === 0) {
490
+ return this.data;
491
+ }
492
+ var data = this.data;
493
+ if (!data) {
494
+ return null;
495
+ }
496
+ var props = this.store.props;
497
+ var children = 'children';
498
+ if (props) {
499
+ children = props.children || 'children';
500
+ }
501
+ if (isUndefined(data[children])) {
502
+ data[children] = null;
503
+ }
504
+ if (forceInit && !data[children]) {
505
+ data[children] = [];
506
+ }
507
+ return data[children];
508
+ }
509
+ }, {
510
+ key: "updateChildren",
511
+ value: function updateChildren() {
512
+ var _this4 = this;
513
+ var newData = this.getChildren() || [];
514
+ var oldData = this.childNodes.map(function (node) {
515
+ return node.data;
516
+ });
517
+ var newDataMap = {};
518
+ var newNodes = [];
519
+ newData.forEach(function (item, index) {
520
+ var key = item[NODE_KEY];
521
+ var isNodeExists = !!key && oldData.some(function (data) {
522
+ return (data === null || data === void 0 ? void 0 : data[NODE_KEY]) === key;
523
+ });
524
+ if (isNodeExists) {
525
+ newDataMap[key] = {
526
+ index: index,
527
+ data: item
528
+ };
529
+ } else {
530
+ newNodes.push({
531
+ index: index,
532
+ data: item
533
+ });
534
+ }
535
+ });
536
+ if (!this.store.lazy) {
537
+ oldData.forEach(function (item) {
538
+ if (!newDataMap[item === null || item === void 0 ? void 0 : item[NODE_KEY]]) {
539
+ _this4.removeChildByData(item);
540
+ }
541
+ });
542
+ }
543
+ newNodes.forEach(function (_ref) {
544
+ var index = _ref.index,
545
+ data = _ref.data;
546
+ _this4.insertChild({
547
+ data: data
548
+ }, index);
549
+ });
550
+ this.updateLeafState();
551
+ }
552
+ }, {
553
+ key: "loadData",
554
+ value: function loadData(callback) {
555
+ var _this5 = this;
556
+ var defaultProps = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
557
+ if (this.store.lazy === true && this.store.load && !this.loaded && (!this.loading || Object.keys(defaultProps).length)) {
558
+ this.loading = true;
559
+ var resolve = function resolve(children) {
560
+ _this5.childNodes = [];
561
+ _this5.doCreateChildren(children, defaultProps);
562
+ _this5.loaded = true;
563
+ _this5.loading = false;
564
+ _this5.updateLeafState();
565
+ if (callback) {
566
+ callback.call(_this5, children);
567
+ }
568
+ };
569
+ var reject = function reject() {
570
+ _this5.loading = false;
571
+ _this5.store.forceUpdate();
572
+ };
573
+ this.store.load(this, resolve, reject);
574
+ } else {
575
+ if (callback) {
576
+ callback.call(this);
577
+ }
578
+ }
579
+ }
580
+ }, {
581
+ key: "eachNode",
582
+ value: function eachNode(callback) {
583
+ var arr = [this];
584
+ while (arr.length) {
585
+ var _node = arr.shift();
586
+ arr.unshift.apply(arr, _toConsumableArray(_node.childNodes));
587
+ callback(_node);
588
+ }
589
+ }
590
+ }, {
591
+ key: "reInitChecked",
592
+ value: function reInitChecked() {
593
+ if (this.store.checkStrictly) {
594
+ return;
595
+ }
596
+ _reInitChecked(this);
597
+ }
598
+ }]);
599
+ return Node;
600
+ }();
601
+ export default Node;
@@ -0,0 +1,52 @@
1
+ import { FilterNodeMethodFunction, FilterValue, LoadFunction, TreeData, TreeKey, TreeNodeData, TreeOptionProps, TreeStoreNodesMap, TreeStoreOptions } from '../typings';
2
+ import Node from './node';
3
+ export default class TreeStore {
4
+ currentNode: Node | null;
5
+ currentNodeKey: TreeKey | null;
6
+ nodesMap: TreeStoreNodesMap;
7
+ root: Node;
8
+ data: TreeData;
9
+ lazy: boolean;
10
+ load?: LoadFunction;
11
+ filterNodeMethod?: FilterNodeMethodFunction;
12
+ key: TreeKey;
13
+ defaultCheckedKeys?: TreeKey[];
14
+ checkStrictly: boolean;
15
+ defaultExpandedKeys?: TreeKey[];
16
+ autoExpandParent: boolean;
17
+ defaultExpandAll: boolean;
18
+ checkDescendants: boolean;
19
+ props: TreeOptionProps;
20
+ forceUpdate?: () => void;
21
+ constructor(options: TreeStoreOptions);
22
+ initialize(): void;
23
+ filter(value: FilterValue): void;
24
+ setData(newVal: TreeData): void;
25
+ getNode(data: TreeKey | TreeNodeData | Node): Node;
26
+ insertBefore(data: TreeNodeData, refData: TreeKey | TreeNodeData | Node): void;
27
+ insertAfter(data: TreeNodeData, refData: TreeKey | TreeNodeData | Node): void;
28
+ remove(data: TreeNodeData | Node): void;
29
+ append(data: TreeNodeData, parentData: TreeNodeData | TreeKey | Node): void;
30
+ _initDefaultCheckedNodes(): void;
31
+ _initDefaultCheckedNode(node: Node): void;
32
+ setDefaultCheckedKey(newVal: TreeKey[]): void;
33
+ registerNode(node: Node): void;
34
+ deregisterNode(node: Node): void;
35
+ getCheckedNodes(leafOnly?: boolean, includeHalfChecked?: boolean): TreeNodeData[];
36
+ getCheckedKeys(leafOnly?: boolean): TreeKey[];
37
+ getHalfCheckedNodes(): TreeNodeData[];
38
+ getHalfCheckedKeys(): TreeKey[];
39
+ _getAllNodes(): Node[];
40
+ updateChildren(key: TreeKey, data: TreeData): void;
41
+ _setCheckedKeys(key: TreeKey, leafOnly: boolean, checkedKeys: {
42
+ [key: string]: boolean;
43
+ }): void;
44
+ setCheckedNodes(array: Node[], leafOnly?: boolean): void;
45
+ setCheckedKeys(keys: TreeKey[], leafOnly?: boolean): void;
46
+ setDefaultExpandedKeys(keys: TreeKey[]): void;
47
+ setChecked(data: TreeKey | TreeNodeData, checked: boolean, deep: boolean): void;
48
+ getCurrentNode(): Node;
49
+ setCurrentNode(currentNode: Node): void;
50
+ setUserCurrentNode(node: Node, shouldAutoExpandParent?: boolean): void;
51
+ setCurrentNodeKey(key: TreeKey | null, shouldAutoExpandParent?: boolean): void;
52
+ }