iov-design 2.15.59 → 2.15.61
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.
- package/README.md +148 -148
- package/lib/alert.js +24 -105
- package/lib/aside.js +24 -34
- package/lib/autocomplete.js +36 -240
- package/lib/avatar.js +21 -20
- package/lib/backtop.js +27 -52
- package/lib/badge.js +30 -58
- package/lib/breadcrumb-item.js +24 -53
- package/lib/breadcrumb.js +24 -37
- package/lib/button-group.js +24 -29
- package/lib/button.js +38 -60
- package/lib/calendar.js +29 -146
- package/lib/card.js +24 -51
- package/lib/carousel-item.js +30 -68
- package/lib/carousel.js +27 -159
- package/lib/cascader-panel.js +41 -64
- package/lib/cascader.js +37 -470
- package/lib/checkbox-button.js +28 -164
- package/lib/checkbox-group.js +24 -37
- package/lib/checkbox.js +35 -189
- package/lib/col.js +1 -0
- package/lib/collapse-item.js +27 -125
- package/lib/collapse.js +24 -37
- package/lib/color-picker.js +104 -424
- package/lib/container.js +24 -34
- package/lib/date-picker.js +126 -1981
- package/lib/descriptions-item.js +1 -0
- package/lib/descriptions.js +1 -0
- package/lib/dialog.js +24 -137
- package/lib/divider.js +29 -64
- package/lib/drawer.js +24 -139
- package/lib/dropdown-item.js +27 -45
- package/lib/dropdown-menu.js +24 -51
- package/lib/dropdown.js +21 -20
- package/lib/empty.js +24 -61
- package/lib/footer.js +24 -34
- package/lib/form-item.js +42 -128
- package/lib/form.js +27 -40
- package/lib/header.js +24 -34
- package/lib/icon.js +24 -29
- package/lib/image.js +36 -220
- package/lib/index.js +1 -1
- package/lib/infinite-scroll.js +1 -0
- package/lib/input-number.js +30 -163
- package/lib/input.js +42 -274
- package/lib/iov-design.common.js +1638 -11132
- package/lib/link.js +33 -55
- package/lib/loading.js +24 -77
- package/lib/locale/format.js +10 -10
- package/lib/main.js +24 -29
- package/lib/menu-item-group.js +24 -40
- package/lib/menu-item.js +27 -83
- package/lib/menu.js +21 -20
- package/lib/message-box.js +24 -321
- package/lib/message.js +30 -82
- package/lib/mixins/migrating.js +20 -20
- package/lib/notification.js +24 -109
- package/lib/option-group.js +24 -50
- package/lib/option.js +27 -76
- package/lib/page-header.js +24 -56
- package/lib/pagination.js +24 -97
- package/lib/popconfirm.js +24 -97
- package/lib/popover.js +24 -89
- package/lib/progress.js +30 -133
- package/lib/radio-button.js +29 -111
- package/lib/radio-group.js +24 -39
- package/lib/radio.js +36 -152
- package/lib/rate.js +24 -94
- package/lib/result.js +72 -187
- package/lib/row.js +1 -0
- package/lib/scrollbar.js +1 -0
- package/lib/select.js +48 -637
- package/lib/skeleton-item.js +36 -68
- package/lib/skeleton.js +28 -70
- package/lib/slider.js +36 -267
- package/lib/spinner.js +24 -51
- package/lib/statistic.js +24 -76
- package/lib/step.js +29 -118
- package/lib/steps.js +27 -40
- package/lib/submenu.js +21 -20
- package/lib/switch.js +24 -130
- package/lib/tab-pane.js +24 -52
- package/lib/table-column.js +1 -0
- package/lib/table.js +93 -633
- package/lib/tabs.js +34 -49
- package/lib/tag.js +22 -21
- package/lib/theme-chalk/base.css +1 -1
- package/lib/theme-chalk/button.css +1 -1
- package/lib/theme-chalk/calendar.css +1 -1
- package/lib/theme-chalk/cascader-panel.css +1 -1
- package/lib/theme-chalk/cascader.css +1 -1
- package/lib/theme-chalk/dropdown.css +1 -1
- package/lib/theme-chalk/index.css +1 -1
- package/lib/theme-chalk/iovfont.css +1 -1
- package/lib/theme-chalk/link.css +1 -1
- package/lib/theme-chalk/message-box.css +1 -1
- package/lib/theme-chalk/pagination.css +1 -1
- package/lib/theme-chalk/radio.css +1 -1
- package/lib/theme-chalk/select.css +1 -1
- package/lib/theme-chalk/table-column.css +1 -1
- package/lib/theme-chalk/table.css +1 -1
- package/lib/theme-chalk/tabs.css +1 -1
- package/lib/theme-chalk/tag.css +1 -1
- package/lib/theme-chalk/transfer.css +1 -1
- package/lib/time-picker.js +58 -820
- package/lib/time-select.js +42 -303
- package/lib/timeline-item.js +29 -75
- package/lib/timeline.js +21 -20
- package/lib/tooltip.js +1 -0
- package/lib/transfer.js +36 -299
- package/lib/tree.js +54 -243
- package/lib/upload.js +86 -654
- package/lib/utils/clickoutside.js +7 -7
- package/lib/utils/vue-popper.js +7 -7
- package/package.json +154 -154
- package/packages/autocomplete/src/autocomplete-suggestions.vue +76 -76
- package/packages/autocomplete/src/autocomplete.vue +285 -285
- package/packages/button/src/button.vue +90 -90
- package/packages/calendar/src/date-table.vue +200 -200
- package/packages/calendar/src/main.vue +280 -280
- package/packages/carousel/src/item.vue +138 -138
- package/packages/carousel/src/main.vue +315 -315
- package/packages/cascader/src/cascader.vue +776 -776
- package/packages/cascader-panel/src/cascader-menu.vue +138 -138
- package/packages/cascader-panel/src/cascader-node.vue +246 -246
- package/packages/cascader-panel/src/cascader-panel.vue +391 -391
- package/packages/cascader-panel/src/node.js +166 -166
- package/packages/cascader-panel/src/store.js +58 -58
- package/packages/checkbox/src/checkbox-button.vue +199 -199
- package/packages/checkbox/src/checkbox-group.vue +49 -49
- package/packages/checkbox/src/checkbox.vue +225 -225
- package/packages/collapse/src/collapse-item.vue +114 -114
- package/packages/color-picker/src/components/picker-dropdown.vue +121 -121
- package/packages/color-picker/src/main.vue +188 -188
- package/packages/date-picker/src/basic/date-table.vue +441 -441
- package/packages/date-picker/src/basic/month-table.vue +269 -269
- package/packages/date-picker/src/basic/time-spinner.vue +304 -304
- package/packages/date-picker/src/basic/year-table.vue +111 -111
- package/packages/date-picker/src/panel/date-range.vue +680 -680
- package/packages/date-picker/src/panel/date.vue +609 -609
- package/packages/date-picker/src/panel/month-range.vue +289 -289
- package/packages/date-picker/src/panel/time-range.vue +248 -248
- package/packages/date-picker/src/panel/time-select.vue +178 -178
- package/packages/date-picker/src/panel/time.vue +186 -186
- package/packages/date-picker/src/picker.vue +967 -967
- package/packages/descriptions/src/index.js +180 -180
- package/packages/dialog/src/component.vue +262 -262
- package/packages/drawer/src/main.vue +205 -205
- package/packages/dropdown/src/dropdown-item.vue +37 -37
- package/packages/dropdown/src/dropdown-menu.vue +63 -63
- package/packages/dropdown/src/dropdown.vue +293 -293
- package/packages/empty/src/index.vue +70 -70
- package/packages/form/src/form-item.vue +324 -324
- package/packages/form/src/form.vue +182 -182
- package/packages/image/src/image-viewer.vue +330 -330
- package/packages/image/src/main.vue +249 -249
- package/packages/infinite-scroll/src/main.js +150 -150
- package/packages/input/src/input.vue +477 -477
- package/packages/input-number/src/input-number.vue +283 -283
- package/packages/link/src/main.vue +2 -0
- package/packages/loading/src/directive.js +133 -133
- package/packages/loading/src/index.js +106 -106
- package/packages/menu/src/menu-item.vue +112 -112
- package/packages/menu/src/menu.vue +325 -325
- package/packages/menu/src/submenu.vue +349 -349
- package/packages/message/src/main.js +91 -91
- package/packages/message-box/src/main.js +216 -216
- package/packages/message-box/src/main.vue +333 -333
- package/packages/notification/src/main.js +94 -94
- package/packages/page-header/src/main.vue +30 -30
- package/packages/pagination/src/pagination.js +390 -390
- package/packages/popconfirm/src/main.vue +104 -104
- package/packages/popover/src/main.vue +239 -239
- package/packages/radio/src/radio-button.vue +115 -115
- package/packages/radio/src/radio-group.vue +115 -115
- package/packages/radio/src/radio.vue +148 -148
- package/packages/rate/src/main.vue +348 -348
- package/packages/scrollbar/src/bar.js +92 -92
- package/packages/scrollbar/src/main.js +130 -130
- package/packages/select/src/option-group.vue +60 -60
- package/packages/select/src/option.vue +171 -171
- package/packages/select/src/select-dropdown.vue +74 -74
- package/packages/select/src/select.vue +979 -979
- package/packages/slider/src/button.vue +238 -238
- package/packages/slider/src/main.vue +427 -427
- package/packages/statistic/src/main.vue +204 -204
- package/packages/steps/src/steps.vue +68 -68
- package/packages/switch/src/component.vue +182 -182
- package/packages/table/src/config.js +153 -153
- package/packages/table/src/filter-panel.vue +194 -194
- package/packages/table/src/store/current.js +76 -76
- package/packages/table/src/store/helper.js +41 -41
- package/packages/table/src/store/index.js +147 -147
- package/packages/table/src/store/watcher.js +502 -502
- package/packages/table/src/table-body.js +469 -469
- package/packages/table/src/table-column.js +328 -328
- package/packages/table/src/table-header.js +571 -571
- package/packages/table/src/table-layout.js +249 -249
- package/packages/table/src/table-row.js +101 -101
- package/packages/table/src/table.vue +740 -740
- package/packages/table/src/util.js +273 -273
- package/packages/tabs/src/tab-bar.vue +57 -57
- package/packages/tabs/src/tab-nav.vue +294 -294
- package/packages/tabs/src/tabs.vue +201 -201
- package/packages/tag/src/tag.vue +1 -1
- package/packages/theme-chalk/src/button.scss +416 -416
- package/packages/theme-chalk/src/cascader.scss +252 -252
- package/packages/theme-chalk/src/checkbox.scss +419 -419
- package/packages/theme-chalk/src/common/var.scss +795 -816
- package/packages/theme-chalk/src/form.scss +201 -201
- package/packages/theme-chalk/src/input.scss +591 -591
- package/packages/theme-chalk/src/iovfont.scss +803 -784
- package/packages/theme-chalk/src/link.scss +36 -19
- package/packages/theme-chalk/src/message-box.scss +207 -207
- package/packages/theme-chalk/src/mixins/_button.scss +136 -136
- package/packages/theme-chalk/src/mixins/mixins.scss +190 -190
- package/packages/theme-chalk/src/radio-button.scss +115 -115
- package/packages/theme-chalk/src/radio.scss +1 -0
- package/packages/theme-chalk/src/select.scss +270 -270
- package/packages/theme-chalk/src/table.scss +1 -2
- package/packages/theme-chalk/src/tabs.scss +755 -750
- package/packages/theme-chalk/src/tag.scss +4 -4
- package/packages/theme-chalk/src/upload.scss +568 -568
- package/packages/tooltip/src/main.js +242 -242
- package/packages/transfer/src/main.vue +231 -231
- package/packages/transfer/src/transfer-panel.vue +251 -251
- package/packages/tree/src/model/node.js +484 -484
- package/packages/tree/src/tree-node.vue +279 -279
- package/packages/tree/src/tree.vue +496 -496
- package/packages/upload/src/index.vue +420 -420
- package/packages/upload/src/upload-file.vue +98 -98
- package/packages/upload/src/upload-list.vue +115 -115
- package/packages/upload/src/upload-picture.vue +98 -98
- package/packages/upload/src/upload.vue +231 -231
- package/packages/upload/src/utils.js +31 -31
- package/src/directives/repeat-click.js +26 -26
- package/src/index.js +259 -259
- package/src/locale/format.js +46 -46
- package/src/locale/index.js +48 -48
- package/src/locale/lang/lo-LA.js +126 -126
- package/src/mixins/locale.js +9 -9
- package/src/mixins/migrating.js +54 -54
- package/src/transitions/collapse-transition.js +77 -77
- package/src/utils/clickoutside.js +76 -76
- package/src/utils/date-util.js +282 -282
- package/src/utils/popup/index.js +218 -218
- package/src/utils/popup/popup-manager.js +194 -194
- package/src/utils/util.js +245 -245
- package/src/utils/vdom.js +5 -5
- package/src/utils/vue-popper.js +198 -198
|
@@ -1,484 +1,484 @@
|
|
|
1
|
-
import objectAssign from 'iov-design/src/utils/merge';
|
|
2
|
-
import { markNodeData, NODE_KEY } from './util';
|
|
3
|
-
import { arrayFindIndex } from 'iov-design/src/utils/util';
|
|
4
|
-
|
|
5
|
-
export const getChildState = node => {
|
|
6
|
-
let all = true;
|
|
7
|
-
let none = true;
|
|
8
|
-
let allWithoutDisable = true;
|
|
9
|
-
for (let i = 0, j = node.length; i < j; i++) {
|
|
10
|
-
const n = node[i];
|
|
11
|
-
if (n.checked !== true || n.indeterminate) {
|
|
12
|
-
all = false;
|
|
13
|
-
if (!n.disabled) {
|
|
14
|
-
allWithoutDisable = false;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
if (n.checked !== false || n.indeterminate) {
|
|
18
|
-
none = false;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return { all, none, allWithoutDisable, half: !all && !none };
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const reInitChecked = function(node) {
|
|
26
|
-
if (node.childNodes.length === 0 || node.loading) return;
|
|
27
|
-
|
|
28
|
-
const {all, none, half} = getChildState(node.childNodes);
|
|
29
|
-
if (all) {
|
|
30
|
-
node.checked = true;
|
|
31
|
-
node.indeterminate = false;
|
|
32
|
-
} else if (half) {
|
|
33
|
-
node.checked = false;
|
|
34
|
-
node.indeterminate = true;
|
|
35
|
-
} else if (none) {
|
|
36
|
-
node.checked = false;
|
|
37
|
-
node.indeterminate = false;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const parent = node.parent;
|
|
41
|
-
if (!parent || parent.level === 0) return;
|
|
42
|
-
|
|
43
|
-
if (!node.store.checkStrictly) {
|
|
44
|
-
reInitChecked(parent);
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const getPropertyFromData = function(node, prop) {
|
|
49
|
-
const props = node.store.props;
|
|
50
|
-
const data = node.data || {};
|
|
51
|
-
const config = props[prop];
|
|
52
|
-
|
|
53
|
-
if (typeof config === 'function') {
|
|
54
|
-
return config(data, node);
|
|
55
|
-
} else if (typeof config === 'string') {
|
|
56
|
-
return data[config];
|
|
57
|
-
} else if (typeof config === 'undefined') {
|
|
58
|
-
const dataProp = data[prop];
|
|
59
|
-
return dataProp === undefined ? '' : dataProp;
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
let nodeIdSeed = 0;
|
|
64
|
-
|
|
65
|
-
export default class Node {
|
|
66
|
-
constructor(options) {
|
|
67
|
-
this.id = nodeIdSeed++;
|
|
68
|
-
this.text = null;
|
|
69
|
-
this.checked = false;
|
|
70
|
-
this.indeterminate = false;
|
|
71
|
-
this.data = null;
|
|
72
|
-
this.expanded = false;
|
|
73
|
-
this.parent = null;
|
|
74
|
-
this.visible = true;
|
|
75
|
-
this.isCurrent = false;
|
|
76
|
-
|
|
77
|
-
for (let name in options) {
|
|
78
|
-
if (options.hasOwnProperty(name)) {
|
|
79
|
-
this[name] = options[name];
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// internal
|
|
84
|
-
this.level = 0;
|
|
85
|
-
this.loaded = false;
|
|
86
|
-
this.childNodes = [];
|
|
87
|
-
this.loading = false;
|
|
88
|
-
|
|
89
|
-
if (this.parent) {
|
|
90
|
-
this.level = this.parent.level + 1;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const store = this.store;
|
|
94
|
-
if (!store) {
|
|
95
|
-
throw new Error('[Node]store is required!');
|
|
96
|
-
}
|
|
97
|
-
store.registerNode(this);
|
|
98
|
-
|
|
99
|
-
const props = store.props;
|
|
100
|
-
if (props && typeof props.isLeaf !== 'undefined') {
|
|
101
|
-
const isLeaf = getPropertyFromData(this, 'isLeaf');
|
|
102
|
-
if (typeof isLeaf === 'boolean') {
|
|
103
|
-
this.isLeafByUser = isLeaf;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
if (store.lazy !== true && this.data) {
|
|
108
|
-
this.setData(this.data);
|
|
109
|
-
|
|
110
|
-
if (store.defaultExpandAll) {
|
|
111
|
-
this.expanded = true;
|
|
112
|
-
}
|
|
113
|
-
} else if (this.level > 0 && store.lazy && store.defaultExpandAll) {
|
|
114
|
-
this.expand();
|
|
115
|
-
}
|
|
116
|
-
if (!Array.isArray(this.data)) {
|
|
117
|
-
markNodeData(this, this.data);
|
|
118
|
-
}
|
|
119
|
-
if (!this.data) return;
|
|
120
|
-
const defaultExpandedKeys = store.defaultExpandedKeys;
|
|
121
|
-
const key = store.key;
|
|
122
|
-
if (key && defaultExpandedKeys && defaultExpandedKeys.indexOf(this.key) !== -1) {
|
|
123
|
-
this.expand(null, store.autoExpandParent);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
if (key && store.currentNodeKey !== undefined && this.key === store.currentNodeKey) {
|
|
127
|
-
store.currentNode = this;
|
|
128
|
-
store.currentNode.isCurrent = true;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
if (store.lazy) {
|
|
132
|
-
store._initDefaultCheckedNode(this);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
this.updateLeafState();
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
setData(data) {
|
|
139
|
-
if (!Array.isArray(data)) {
|
|
140
|
-
markNodeData(this, data);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
this.data = data;
|
|
144
|
-
this.childNodes = [];
|
|
145
|
-
|
|
146
|
-
let children;
|
|
147
|
-
if (this.level === 0 && this.data instanceof Array) {
|
|
148
|
-
children = this.data;
|
|
149
|
-
} else {
|
|
150
|
-
children = getPropertyFromData(this, 'children') || [];
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
for (let i = 0, j = children.length; i < j; i++) {
|
|
154
|
-
this.insertChild({ data: children[i] });
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
get label() {
|
|
159
|
-
return getPropertyFromData(this, 'label');
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
get key() {
|
|
163
|
-
const nodeKey = this.store.key;
|
|
164
|
-
if (this.data) return this.data[nodeKey];
|
|
165
|
-
return null;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
get disabled() {
|
|
169
|
-
return getPropertyFromData(this, 'disabled');
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
get nextSibling() {
|
|
173
|
-
const parent = this.parent;
|
|
174
|
-
if (parent) {
|
|
175
|
-
const index = parent.childNodes.indexOf(this);
|
|
176
|
-
if (index > -1) {
|
|
177
|
-
return parent.childNodes[index + 1];
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
return null;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
get previousSibling() {
|
|
184
|
-
const parent = this.parent;
|
|
185
|
-
if (parent) {
|
|
186
|
-
const index = parent.childNodes.indexOf(this);
|
|
187
|
-
if (index > -1) {
|
|
188
|
-
return index > 0 ? parent.childNodes[index - 1] : null;
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
return null;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
contains(target, deep = true) {
|
|
195
|
-
const walk = function(parent) {
|
|
196
|
-
const children = parent.childNodes || [];
|
|
197
|
-
let result = false;
|
|
198
|
-
for (let i = 0, j = children.length; i < j; i++) {
|
|
199
|
-
const child = children[i];
|
|
200
|
-
if (child === target || (deep && walk(child))) {
|
|
201
|
-
result = true;
|
|
202
|
-
break;
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
return result;
|
|
206
|
-
};
|
|
207
|
-
|
|
208
|
-
return walk(this);
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
remove() {
|
|
212
|
-
const parent = this.parent;
|
|
213
|
-
if (parent) {
|
|
214
|
-
parent.removeChild(this);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
insertChild(child, index, batch) {
|
|
219
|
-
if (!child) throw new Error('insertChild error: child is required.');
|
|
220
|
-
|
|
221
|
-
if (!(child instanceof Node)) {
|
|
222
|
-
if (!batch) {
|
|
223
|
-
const children = this.getChildren(true) || [];
|
|
224
|
-
if (children.indexOf(child.data) === -1) {
|
|
225
|
-
if (typeof index === 'undefined' || index < 0) {
|
|
226
|
-
children.push(child.data);
|
|
227
|
-
} else {
|
|
228
|
-
children.splice(index, 0, child.data);
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
objectAssign(child, {
|
|
233
|
-
parent: this,
|
|
234
|
-
store: this.store
|
|
235
|
-
});
|
|
236
|
-
child = new Node(child);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
child.level = this.level + 1;
|
|
240
|
-
|
|
241
|
-
if (typeof index === 'undefined' || index < 0) {
|
|
242
|
-
this.childNodes.push(child);
|
|
243
|
-
} else {
|
|
244
|
-
this.childNodes.splice(index, 0, child);
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
this.updateLeafState();
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
insertBefore(child, ref) {
|
|
251
|
-
let index;
|
|
252
|
-
if (ref) {
|
|
253
|
-
index = this.childNodes.indexOf(ref);
|
|
254
|
-
}
|
|
255
|
-
this.insertChild(child, index);
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
insertAfter(child, ref) {
|
|
259
|
-
let index;
|
|
260
|
-
if (ref) {
|
|
261
|
-
index = this.childNodes.indexOf(ref);
|
|
262
|
-
if (index !== -1) index += 1;
|
|
263
|
-
}
|
|
264
|
-
this.insertChild(child, index);
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
removeChild(child) {
|
|
268
|
-
const children = this.getChildren() || [];
|
|
269
|
-
const dataIndex = children.indexOf(child.data);
|
|
270
|
-
if (dataIndex > -1) {
|
|
271
|
-
children.splice(dataIndex, 1);
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
const index = this.childNodes.indexOf(child);
|
|
275
|
-
|
|
276
|
-
if (index > -1) {
|
|
277
|
-
this.store && this.store.deregisterNode(child);
|
|
278
|
-
child.parent = null;
|
|
279
|
-
this.childNodes.splice(index, 1);
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
this.updateLeafState();
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
removeChildByData(data) {
|
|
286
|
-
let targetNode = null;
|
|
287
|
-
|
|
288
|
-
for (let i = 0; i < this.childNodes.length; i++) {
|
|
289
|
-
if (this.childNodes[i].data === data) {
|
|
290
|
-
targetNode = this.childNodes[i];
|
|
291
|
-
break;
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
if (targetNode) {
|
|
296
|
-
this.removeChild(targetNode);
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
expand(callback, expandParent) {
|
|
301
|
-
const done = () => {
|
|
302
|
-
if (expandParent) {
|
|
303
|
-
let parent = this.parent;
|
|
304
|
-
while (parent.level > 0) {
|
|
305
|
-
parent.expanded = true;
|
|
306
|
-
parent = parent.parent;
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
this.expanded = true;
|
|
310
|
-
if (callback) callback();
|
|
311
|
-
};
|
|
312
|
-
|
|
313
|
-
if (this.shouldLoadData()) {
|
|
314
|
-
this.loadData((data) => {
|
|
315
|
-
if (data instanceof Array) {
|
|
316
|
-
if (this.checked) {
|
|
317
|
-
this.setChecked(true, true);
|
|
318
|
-
} else if (!this.store.checkStrictly) {
|
|
319
|
-
reInitChecked(this);
|
|
320
|
-
}
|
|
321
|
-
done();
|
|
322
|
-
}
|
|
323
|
-
});
|
|
324
|
-
} else {
|
|
325
|
-
done();
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
doCreateChildren(array, defaultProps = {}) {
|
|
330
|
-
array.forEach((item) => {
|
|
331
|
-
this.insertChild(objectAssign({ data: item }, defaultProps), undefined, true);
|
|
332
|
-
});
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
collapse() {
|
|
336
|
-
this.expanded = false;
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
shouldLoadData() {
|
|
340
|
-
return this.store.lazy === true && this.store.load && !this.loaded;
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
updateLeafState() {
|
|
344
|
-
if (this.store.lazy === true && this.loaded !== true && typeof this.isLeafByUser !== 'undefined') {
|
|
345
|
-
this.isLeaf = this.isLeafByUser;
|
|
346
|
-
return;
|
|
347
|
-
}
|
|
348
|
-
const childNodes = this.childNodes;
|
|
349
|
-
if (!this.store.lazy || (this.store.lazy === true && this.loaded === true)) {
|
|
350
|
-
this.isLeaf = !childNodes || childNodes.length === 0;
|
|
351
|
-
return;
|
|
352
|
-
}
|
|
353
|
-
this.isLeaf = false;
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
setChecked(value, deep, recursion, passValue) {
|
|
357
|
-
this.indeterminate = value === 'half';
|
|
358
|
-
this.checked = value === true;
|
|
359
|
-
|
|
360
|
-
if (this.store.checkStrictly) return;
|
|
361
|
-
|
|
362
|
-
if (!(this.shouldLoadData() && !this.store.checkDescendants)) {
|
|
363
|
-
let { all, allWithoutDisable } = getChildState(this.childNodes);
|
|
364
|
-
|
|
365
|
-
if (!this.isLeaf && (!all && allWithoutDisable)) {
|
|
366
|
-
this.checked = false;
|
|
367
|
-
value = false;
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
const handleDescendants = () => {
|
|
371
|
-
if (deep) {
|
|
372
|
-
const childNodes = this.childNodes;
|
|
373
|
-
for (let i = 0, j = childNodes.length; i < j; i++) {
|
|
374
|
-
const child = childNodes[i];
|
|
375
|
-
passValue = passValue || value !== false;
|
|
376
|
-
const isCheck = child.disabled ? child.checked : passValue;
|
|
377
|
-
child.setChecked(isCheck, deep, true, passValue);
|
|
378
|
-
}
|
|
379
|
-
const { half, all } = getChildState(childNodes);
|
|
380
|
-
if (!all) {
|
|
381
|
-
this.checked = all;
|
|
382
|
-
this.indeterminate = half;
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
};
|
|
386
|
-
|
|
387
|
-
if (this.shouldLoadData()) {
|
|
388
|
-
// Only work on lazy load data.
|
|
389
|
-
this.loadData(() => {
|
|
390
|
-
handleDescendants();
|
|
391
|
-
reInitChecked(this);
|
|
392
|
-
}, {
|
|
393
|
-
checked: value !== false
|
|
394
|
-
});
|
|
395
|
-
return;
|
|
396
|
-
} else {
|
|
397
|
-
handleDescendants();
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
const parent = this.parent;
|
|
402
|
-
if (!parent || parent.level === 0) return;
|
|
403
|
-
|
|
404
|
-
if (!recursion) {
|
|
405
|
-
reInitChecked(parent);
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
getChildren(forceInit = false) { // this is data
|
|
410
|
-
if (this.level === 0) return this.data;
|
|
411
|
-
const data = this.data;
|
|
412
|
-
if (!data) return null;
|
|
413
|
-
|
|
414
|
-
const props = this.store.props;
|
|
415
|
-
let children = 'children';
|
|
416
|
-
if (props) {
|
|
417
|
-
children = props.children || 'children';
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
if (data[children] === undefined) {
|
|
421
|
-
data[children] = null;
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
if (forceInit && !data[children]) {
|
|
425
|
-
data[children] = [];
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
return data[children];
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
updateChildren() {
|
|
432
|
-
const newData = this.getChildren() || [];
|
|
433
|
-
const oldData = this.childNodes.map((node) => node.data);
|
|
434
|
-
|
|
435
|
-
const newDataMap = {};
|
|
436
|
-
const newNodes = [];
|
|
437
|
-
|
|
438
|
-
newData.forEach((item, index) => {
|
|
439
|
-
const key = item[NODE_KEY];
|
|
440
|
-
const isNodeExists = !!key && arrayFindIndex(oldData, data => data[NODE_KEY] === key) >= 0;
|
|
441
|
-
if (isNodeExists) {
|
|
442
|
-
newDataMap[key] = { index, data: item };
|
|
443
|
-
} else {
|
|
444
|
-
newNodes.push({ index, data: item });
|
|
445
|
-
}
|
|
446
|
-
});
|
|
447
|
-
|
|
448
|
-
if (!this.store.lazy) {
|
|
449
|
-
oldData.forEach((item) => {
|
|
450
|
-
if (!newDataMap[item[NODE_KEY]]) this.removeChildByData(item);
|
|
451
|
-
});
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
newNodes.forEach(({ index, data }) => {
|
|
455
|
-
this.insertChild({ data }, index);
|
|
456
|
-
});
|
|
457
|
-
|
|
458
|
-
this.updateLeafState();
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
loadData(callback, defaultProps = {}) {
|
|
462
|
-
if (this.store.lazy === true && this.store.load && !this.loaded && (!this.loading || Object.keys(defaultProps).length)) {
|
|
463
|
-
this.loading = true;
|
|
464
|
-
|
|
465
|
-
const resolve = (children) => {
|
|
466
|
-
this.childNodes = [];
|
|
467
|
-
|
|
468
|
-
this.doCreateChildren(children, defaultProps);
|
|
469
|
-
this.loaded = true;
|
|
470
|
-
this.loading = false;
|
|
471
|
-
this.updateLeafState();
|
|
472
|
-
if (callback) {
|
|
473
|
-
callback.call(this, children);
|
|
474
|
-
}
|
|
475
|
-
};
|
|
476
|
-
|
|
477
|
-
this.store.load(this, resolve);
|
|
478
|
-
} else {
|
|
479
|
-
if (callback) {
|
|
480
|
-
callback.call(this);
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
}
|
|
1
|
+
import objectAssign from 'iov-design/src/utils/merge';
|
|
2
|
+
import { markNodeData, NODE_KEY } from './util';
|
|
3
|
+
import { arrayFindIndex } from 'iov-design/src/utils/util';
|
|
4
|
+
|
|
5
|
+
export const getChildState = node => {
|
|
6
|
+
let all = true;
|
|
7
|
+
let none = true;
|
|
8
|
+
let allWithoutDisable = true;
|
|
9
|
+
for (let i = 0, j = node.length; i < j; i++) {
|
|
10
|
+
const n = node[i];
|
|
11
|
+
if (n.checked !== true || n.indeterminate) {
|
|
12
|
+
all = false;
|
|
13
|
+
if (!n.disabled) {
|
|
14
|
+
allWithoutDisable = false;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
if (n.checked !== false || n.indeterminate) {
|
|
18
|
+
none = false;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return { all, none, allWithoutDisable, half: !all && !none };
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const reInitChecked = function(node) {
|
|
26
|
+
if (node.childNodes.length === 0 || node.loading) return;
|
|
27
|
+
|
|
28
|
+
const {all, none, half} = getChildState(node.childNodes);
|
|
29
|
+
if (all) {
|
|
30
|
+
node.checked = true;
|
|
31
|
+
node.indeterminate = false;
|
|
32
|
+
} else if (half) {
|
|
33
|
+
node.checked = false;
|
|
34
|
+
node.indeterminate = true;
|
|
35
|
+
} else if (none) {
|
|
36
|
+
node.checked = false;
|
|
37
|
+
node.indeterminate = false;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const parent = node.parent;
|
|
41
|
+
if (!parent || parent.level === 0) return;
|
|
42
|
+
|
|
43
|
+
if (!node.store.checkStrictly) {
|
|
44
|
+
reInitChecked(parent);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const getPropertyFromData = function(node, prop) {
|
|
49
|
+
const props = node.store.props;
|
|
50
|
+
const data = node.data || {};
|
|
51
|
+
const config = props[prop];
|
|
52
|
+
|
|
53
|
+
if (typeof config === 'function') {
|
|
54
|
+
return config(data, node);
|
|
55
|
+
} else if (typeof config === 'string') {
|
|
56
|
+
return data[config];
|
|
57
|
+
} else if (typeof config === 'undefined') {
|
|
58
|
+
const dataProp = data[prop];
|
|
59
|
+
return dataProp === undefined ? '' : dataProp;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
let nodeIdSeed = 0;
|
|
64
|
+
|
|
65
|
+
export default class Node {
|
|
66
|
+
constructor(options) {
|
|
67
|
+
this.id = nodeIdSeed++;
|
|
68
|
+
this.text = null;
|
|
69
|
+
this.checked = false;
|
|
70
|
+
this.indeterminate = false;
|
|
71
|
+
this.data = null;
|
|
72
|
+
this.expanded = false;
|
|
73
|
+
this.parent = null;
|
|
74
|
+
this.visible = true;
|
|
75
|
+
this.isCurrent = false;
|
|
76
|
+
|
|
77
|
+
for (let name in options) {
|
|
78
|
+
if (options.hasOwnProperty(name)) {
|
|
79
|
+
this[name] = options[name];
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// internal
|
|
84
|
+
this.level = 0;
|
|
85
|
+
this.loaded = false;
|
|
86
|
+
this.childNodes = [];
|
|
87
|
+
this.loading = false;
|
|
88
|
+
|
|
89
|
+
if (this.parent) {
|
|
90
|
+
this.level = this.parent.level + 1;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const store = this.store;
|
|
94
|
+
if (!store) {
|
|
95
|
+
throw new Error('[Node]store is required!');
|
|
96
|
+
}
|
|
97
|
+
store.registerNode(this);
|
|
98
|
+
|
|
99
|
+
const props = store.props;
|
|
100
|
+
if (props && typeof props.isLeaf !== 'undefined') {
|
|
101
|
+
const isLeaf = getPropertyFromData(this, 'isLeaf');
|
|
102
|
+
if (typeof isLeaf === 'boolean') {
|
|
103
|
+
this.isLeafByUser = isLeaf;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (store.lazy !== true && this.data) {
|
|
108
|
+
this.setData(this.data);
|
|
109
|
+
|
|
110
|
+
if (store.defaultExpandAll) {
|
|
111
|
+
this.expanded = true;
|
|
112
|
+
}
|
|
113
|
+
} else if (this.level > 0 && store.lazy && store.defaultExpandAll) {
|
|
114
|
+
this.expand();
|
|
115
|
+
}
|
|
116
|
+
if (!Array.isArray(this.data)) {
|
|
117
|
+
markNodeData(this, this.data);
|
|
118
|
+
}
|
|
119
|
+
if (!this.data) return;
|
|
120
|
+
const defaultExpandedKeys = store.defaultExpandedKeys;
|
|
121
|
+
const key = store.key;
|
|
122
|
+
if (key && defaultExpandedKeys && defaultExpandedKeys.indexOf(this.key) !== -1) {
|
|
123
|
+
this.expand(null, store.autoExpandParent);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (key && store.currentNodeKey !== undefined && this.key === store.currentNodeKey) {
|
|
127
|
+
store.currentNode = this;
|
|
128
|
+
store.currentNode.isCurrent = true;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (store.lazy) {
|
|
132
|
+
store._initDefaultCheckedNode(this);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
this.updateLeafState();
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
setData(data) {
|
|
139
|
+
if (!Array.isArray(data)) {
|
|
140
|
+
markNodeData(this, data);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
this.data = data;
|
|
144
|
+
this.childNodes = [];
|
|
145
|
+
|
|
146
|
+
let children;
|
|
147
|
+
if (this.level === 0 && this.data instanceof Array) {
|
|
148
|
+
children = this.data;
|
|
149
|
+
} else {
|
|
150
|
+
children = getPropertyFromData(this, 'children') || [];
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
for (let i = 0, j = children.length; i < j; i++) {
|
|
154
|
+
this.insertChild({ data: children[i] });
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
get label() {
|
|
159
|
+
return getPropertyFromData(this, 'label');
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
get key() {
|
|
163
|
+
const nodeKey = this.store.key;
|
|
164
|
+
if (this.data) return this.data[nodeKey];
|
|
165
|
+
return null;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
get disabled() {
|
|
169
|
+
return getPropertyFromData(this, 'disabled');
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
get nextSibling() {
|
|
173
|
+
const parent = this.parent;
|
|
174
|
+
if (parent) {
|
|
175
|
+
const index = parent.childNodes.indexOf(this);
|
|
176
|
+
if (index > -1) {
|
|
177
|
+
return parent.childNodes[index + 1];
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
get previousSibling() {
|
|
184
|
+
const parent = this.parent;
|
|
185
|
+
if (parent) {
|
|
186
|
+
const index = parent.childNodes.indexOf(this);
|
|
187
|
+
if (index > -1) {
|
|
188
|
+
return index > 0 ? parent.childNodes[index - 1] : null;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return null;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
contains(target, deep = true) {
|
|
195
|
+
const walk = function(parent) {
|
|
196
|
+
const children = parent.childNodes || [];
|
|
197
|
+
let result = false;
|
|
198
|
+
for (let i = 0, j = children.length; i < j; i++) {
|
|
199
|
+
const child = children[i];
|
|
200
|
+
if (child === target || (deep && walk(child))) {
|
|
201
|
+
result = true;
|
|
202
|
+
break;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return result;
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
return walk(this);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
remove() {
|
|
212
|
+
const parent = this.parent;
|
|
213
|
+
if (parent) {
|
|
214
|
+
parent.removeChild(this);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
insertChild(child, index, batch) {
|
|
219
|
+
if (!child) throw new Error('insertChild error: child is required.');
|
|
220
|
+
|
|
221
|
+
if (!(child instanceof Node)) {
|
|
222
|
+
if (!batch) {
|
|
223
|
+
const children = this.getChildren(true) || [];
|
|
224
|
+
if (children.indexOf(child.data) === -1) {
|
|
225
|
+
if (typeof index === 'undefined' || index < 0) {
|
|
226
|
+
children.push(child.data);
|
|
227
|
+
} else {
|
|
228
|
+
children.splice(index, 0, child.data);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
objectAssign(child, {
|
|
233
|
+
parent: this,
|
|
234
|
+
store: this.store
|
|
235
|
+
});
|
|
236
|
+
child = new Node(child);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
child.level = this.level + 1;
|
|
240
|
+
|
|
241
|
+
if (typeof index === 'undefined' || index < 0) {
|
|
242
|
+
this.childNodes.push(child);
|
|
243
|
+
} else {
|
|
244
|
+
this.childNodes.splice(index, 0, child);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
this.updateLeafState();
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
insertBefore(child, ref) {
|
|
251
|
+
let index;
|
|
252
|
+
if (ref) {
|
|
253
|
+
index = this.childNodes.indexOf(ref);
|
|
254
|
+
}
|
|
255
|
+
this.insertChild(child, index);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
insertAfter(child, ref) {
|
|
259
|
+
let index;
|
|
260
|
+
if (ref) {
|
|
261
|
+
index = this.childNodes.indexOf(ref);
|
|
262
|
+
if (index !== -1) index += 1;
|
|
263
|
+
}
|
|
264
|
+
this.insertChild(child, index);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
removeChild(child) {
|
|
268
|
+
const children = this.getChildren() || [];
|
|
269
|
+
const dataIndex = children.indexOf(child.data);
|
|
270
|
+
if (dataIndex > -1) {
|
|
271
|
+
children.splice(dataIndex, 1);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
const index = this.childNodes.indexOf(child);
|
|
275
|
+
|
|
276
|
+
if (index > -1) {
|
|
277
|
+
this.store && this.store.deregisterNode(child);
|
|
278
|
+
child.parent = null;
|
|
279
|
+
this.childNodes.splice(index, 1);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
this.updateLeafState();
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
removeChildByData(data) {
|
|
286
|
+
let targetNode = null;
|
|
287
|
+
|
|
288
|
+
for (let i = 0; i < this.childNodes.length; i++) {
|
|
289
|
+
if (this.childNodes[i].data === data) {
|
|
290
|
+
targetNode = this.childNodes[i];
|
|
291
|
+
break;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
if (targetNode) {
|
|
296
|
+
this.removeChild(targetNode);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
expand(callback, expandParent) {
|
|
301
|
+
const done = () => {
|
|
302
|
+
if (expandParent) {
|
|
303
|
+
let parent = this.parent;
|
|
304
|
+
while (parent.level > 0) {
|
|
305
|
+
parent.expanded = true;
|
|
306
|
+
parent = parent.parent;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
this.expanded = true;
|
|
310
|
+
if (callback) callback();
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
if (this.shouldLoadData()) {
|
|
314
|
+
this.loadData((data) => {
|
|
315
|
+
if (data instanceof Array) {
|
|
316
|
+
if (this.checked) {
|
|
317
|
+
this.setChecked(true, true);
|
|
318
|
+
} else if (!this.store.checkStrictly) {
|
|
319
|
+
reInitChecked(this);
|
|
320
|
+
}
|
|
321
|
+
done();
|
|
322
|
+
}
|
|
323
|
+
});
|
|
324
|
+
} else {
|
|
325
|
+
done();
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
doCreateChildren(array, defaultProps = {}) {
|
|
330
|
+
array.forEach((item) => {
|
|
331
|
+
this.insertChild(objectAssign({ data: item }, defaultProps), undefined, true);
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
collapse() {
|
|
336
|
+
this.expanded = false;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
shouldLoadData() {
|
|
340
|
+
return this.store.lazy === true && this.store.load && !this.loaded;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
updateLeafState() {
|
|
344
|
+
if (this.store.lazy === true && this.loaded !== true && typeof this.isLeafByUser !== 'undefined') {
|
|
345
|
+
this.isLeaf = this.isLeafByUser;
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
const childNodes = this.childNodes;
|
|
349
|
+
if (!this.store.lazy || (this.store.lazy === true && this.loaded === true)) {
|
|
350
|
+
this.isLeaf = !childNodes || childNodes.length === 0;
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
this.isLeaf = false;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
setChecked(value, deep, recursion, passValue) {
|
|
357
|
+
this.indeterminate = value === 'half';
|
|
358
|
+
this.checked = value === true;
|
|
359
|
+
|
|
360
|
+
if (this.store.checkStrictly) return;
|
|
361
|
+
|
|
362
|
+
if (!(this.shouldLoadData() && !this.store.checkDescendants)) {
|
|
363
|
+
let { all, allWithoutDisable } = getChildState(this.childNodes);
|
|
364
|
+
|
|
365
|
+
if (!this.isLeaf && (!all && allWithoutDisable)) {
|
|
366
|
+
this.checked = false;
|
|
367
|
+
value = false;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
const handleDescendants = () => {
|
|
371
|
+
if (deep) {
|
|
372
|
+
const childNodes = this.childNodes;
|
|
373
|
+
for (let i = 0, j = childNodes.length; i < j; i++) {
|
|
374
|
+
const child = childNodes[i];
|
|
375
|
+
passValue = passValue || value !== false;
|
|
376
|
+
const isCheck = child.disabled ? child.checked : passValue;
|
|
377
|
+
child.setChecked(isCheck, deep, true, passValue);
|
|
378
|
+
}
|
|
379
|
+
const { half, all } = getChildState(childNodes);
|
|
380
|
+
if (!all) {
|
|
381
|
+
this.checked = all;
|
|
382
|
+
this.indeterminate = half;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
|
|
387
|
+
if (this.shouldLoadData()) {
|
|
388
|
+
// Only work on lazy load data.
|
|
389
|
+
this.loadData(() => {
|
|
390
|
+
handleDescendants();
|
|
391
|
+
reInitChecked(this);
|
|
392
|
+
}, {
|
|
393
|
+
checked: value !== false
|
|
394
|
+
});
|
|
395
|
+
return;
|
|
396
|
+
} else {
|
|
397
|
+
handleDescendants();
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
const parent = this.parent;
|
|
402
|
+
if (!parent || parent.level === 0) return;
|
|
403
|
+
|
|
404
|
+
if (!recursion) {
|
|
405
|
+
reInitChecked(parent);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
getChildren(forceInit = false) { // this is data
|
|
410
|
+
if (this.level === 0) return this.data;
|
|
411
|
+
const data = this.data;
|
|
412
|
+
if (!data) return null;
|
|
413
|
+
|
|
414
|
+
const props = this.store.props;
|
|
415
|
+
let children = 'children';
|
|
416
|
+
if (props) {
|
|
417
|
+
children = props.children || 'children';
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
if (data[children] === undefined) {
|
|
421
|
+
data[children] = null;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
if (forceInit && !data[children]) {
|
|
425
|
+
data[children] = [];
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
return data[children];
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
updateChildren() {
|
|
432
|
+
const newData = this.getChildren() || [];
|
|
433
|
+
const oldData = this.childNodes.map((node) => node.data);
|
|
434
|
+
|
|
435
|
+
const newDataMap = {};
|
|
436
|
+
const newNodes = [];
|
|
437
|
+
|
|
438
|
+
newData.forEach((item, index) => {
|
|
439
|
+
const key = item[NODE_KEY];
|
|
440
|
+
const isNodeExists = !!key && arrayFindIndex(oldData, data => data[NODE_KEY] === key) >= 0;
|
|
441
|
+
if (isNodeExists) {
|
|
442
|
+
newDataMap[key] = { index, data: item };
|
|
443
|
+
} else {
|
|
444
|
+
newNodes.push({ index, data: item });
|
|
445
|
+
}
|
|
446
|
+
});
|
|
447
|
+
|
|
448
|
+
if (!this.store.lazy) {
|
|
449
|
+
oldData.forEach((item) => {
|
|
450
|
+
if (!newDataMap[item[NODE_KEY]]) this.removeChildByData(item);
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
newNodes.forEach(({ index, data }) => {
|
|
455
|
+
this.insertChild({ data }, index);
|
|
456
|
+
});
|
|
457
|
+
|
|
458
|
+
this.updateLeafState();
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
loadData(callback, defaultProps = {}) {
|
|
462
|
+
if (this.store.lazy === true && this.store.load && !this.loaded && (!this.loading || Object.keys(defaultProps).length)) {
|
|
463
|
+
this.loading = true;
|
|
464
|
+
|
|
465
|
+
const resolve = (children) => {
|
|
466
|
+
this.childNodes = [];
|
|
467
|
+
|
|
468
|
+
this.doCreateChildren(children, defaultProps);
|
|
469
|
+
this.loaded = true;
|
|
470
|
+
this.loading = false;
|
|
471
|
+
this.updateLeafState();
|
|
472
|
+
if (callback) {
|
|
473
|
+
callback.call(this, children);
|
|
474
|
+
}
|
|
475
|
+
};
|
|
476
|
+
|
|
477
|
+
this.store.load(this, resolve);
|
|
478
|
+
} else {
|
|
479
|
+
if (callback) {
|
|
480
|
+
callback.call(this);
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
}
|