@opentiny/vue-renderless 3.21.1 → 3.22.0
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/amount/index.js +4 -4
- package/anchor/index.js +1 -1
- package/async-flowchart/index.js +1 -1
- package/autocomplete/index.js +1 -1
- package/autocomplete/vue.js +3 -3
- package/base-select/index.js +19 -19
- package/base-select/vue.js +2 -2
- package/calendar/index.js +2 -2
- package/calendar-bar/index.js +2 -2
- package/calendar-bar/vue.js +1 -1
- package/calendar-view/index.js +66 -22
- package/calendar-view/vue.js +2 -3
- package/card/index.js +1 -1
- package/card-template/index.js +1 -1
- package/carousel/index.js +4 -4
- package/carousel/vue.js +1 -1
- package/cascader/index.js +21 -11
- package/cascader/vue.js +6 -5
- package/cascader-menu/vue.js +2 -2
- package/cascader-mobile/index.js +1 -1
- package/cascader-panel/index.js +4 -4
- package/cascader-panel/node.js +3 -4
- package/cascader-panel/vue.js +1 -1
- package/cascader-select/column-index.js +2 -2
- package/cascader-view/index.js +1 -1
- package/chart-bar/index.js +1 -1
- package/chart-candle/index.js +1 -1
- package/chart-core/deps/utils.js +6 -6
- package/chart-core/index.js +1 -1
- package/chart-funnel/index.js +1 -1
- package/chart-gauge/index.js +1 -1
- package/chart-line/index.js +1 -1
- package/chart-map/index.js +1 -1
- package/chart-pie/index.js +1 -1
- package/chart-radar/index.js +1 -1
- package/chart-sankey/index.js +1 -1
- package/chart-scatter/index.js +1 -1
- package/chart-waterfall/index.js +1 -1
- package/chart-wordcloud/index.js +1 -1
- package/checkbox/index.js +1 -1
- package/collapse-item/vue.js +1 -1
- package/column-list-item/index.js +1 -1
- package/common/deps/dom.js +20 -196
- package/common/deps/infinite-scroll.js +4 -43
- package/common/deps/popup-manager.js +1 -200
- package/container/index.js +2 -2
- package/crop/index.js +3 -3
- package/currency/index.js +2 -2
- package/date-panel/index.js +75 -25
- package/date-panel/vue.js +53 -21
- package/date-picker/vue.js +1 -1
- package/date-picker-mobile/index.js +1 -1
- package/date-range/index.js +71 -37
- package/date-range/vue.js +27 -23
- package/date-table/index.js +8 -5
- package/date-table/vue.js +1 -1
- package/dialog-box/index.js +3 -3
- package/dialog-box/vue.js +1 -1
- package/dialog-select/vue.js +7 -4
- package/drawer/index.js +2 -2
- package/drop-times/index.js +1 -1
- package/dropdown/index.js +11 -3
- package/dropdown/vue.js +2 -2
- package/dropdown-item/index.js +1 -1
- package/dropdown-item/mf.js +1 -1
- package/dropdown-menu/index.js +1 -1
- package/espace/vue.js +2 -2
- package/fall-menu/index.js +3 -3
- package/file-upload/index.js +16 -13
- package/file-upload/vue.js +2 -2
- package/filter/vue.js +1 -1
- package/filter-panel/vue.js +1 -2
- package/floating-button/index.js +1 -1
- package/flowchart/index.js +3 -3
- package/flowchart/vue.js +1 -1
- package/fluent-editor/index.js +5 -7
- package/fluent-editor/options.js +2 -2
- package/form/index.js +20 -2
- package/form-item/index.js +6 -6
- package/fullscreen/index.js +1 -1
- package/fullscreen/vue.js +1 -1
- package/grid/plugins/export.js +2 -2
- package/grid/plugins/exportExcel.js +3 -3
- package/grid/plugins/resize.js +2 -2
- package/grid/static/base/helperEqualCompare.js +1 -1
- package/grid/static/base/isPlainObject.js +1 -1
- package/grid/utils/common.js +2 -2
- package/grid/utils/dom.js +16 -8
- package/grid/utils/event.js +4 -4
- package/hrapprover/index.js +1 -1
- package/image/index.js +3 -3
- package/image-viewer/index.js +4 -6
- package/input/index.js +2 -2
- package/input/vue.js +1 -1
- package/ip-address/index.js +17 -21
- package/ip-address/vue.js +1 -1
- package/link-menu/index.js +1 -1
- package/link-menu/vue.js +1 -1
- package/load-list/index.js +1 -1
- package/load-list/vue.js +4 -4
- package/loading/index.js +2 -2
- package/menu/vue.js +1 -1
- package/milestone/index.js +6 -45
- package/modal/index.js +5 -5
- package/month-range/index.js +45 -5
- package/month-range/vue.js +19 -15
- package/month-table/index.js +5 -5
- package/month-table/vue.js +1 -1
- package/nav-menu/index.js +7 -7
- package/notify/index.js +3 -3
- package/numeric/index.js +5 -5
- package/option/index.js +1 -1
- package/option/vue.js +2 -1
- package/package.json +4 -3
- package/pager/index.js +28 -16
- package/pager/vue.js +27 -16
- package/panel/index.js +1 -1
- package/picker/index.js +11 -11
- package/picker/vue.js +2 -2
- package/picker-column/index.js +1 -1
- package/pop-upload/vue.js +1 -1
- package/popconfirm/vue.js +1 -1
- package/popeditor/index.js +6 -6
- package/popeditor/vue.js +2 -2
- package/popover/index.js +3 -3
- package/popover/vue.js +1 -1
- package/popup/index.js +3 -3
- package/pull-refresh/index.js +1 -1
- package/pull-refresh-mobile-first/index.js +1 -1
- package/pull-refresh-mobile-first/vue.js +4 -4
- package/quarter-panel/index.js +2 -2
- package/quarter-panel/vue.js +1 -1
- package/radio-group/index.js +1 -1
- package/rate/index.js +1 -1
- package/rate/vue.js +1 -1
- package/recycle-scroller/index.js +2 -2
- package/recycle-scroller/vue.js +1 -1
- package/rich-text/index.js +1 -1
- package/rich-text/table-module.js +2 -2
- package/river/river.js +1 -1
- package/river/vue.js +1 -1
- package/scrollbar/vue-bar.js +1 -1
- package/scrollbar/vue.js +1 -1
- package/search/index.js +3 -3
- package/select/index.js +26 -22
- package/select/vue.js +8 -7
- package/select-dropdown/vue.js +5 -5
- package/selected-box/index.js +1 -1
- package/signature/index.js +1 -1
- package/signature/vue.js +2 -2
- package/skeleton/index.js +1 -1
- package/slider/index.js +4 -4
- package/slider-button-group/slide-button.js +2 -2
- package/split/index.js +2 -2
- package/split/vue.js +1 -1
- package/statistic/index.js +1 -1
- package/steps/index.js +2 -3
- package/steps/slide-bar.js +2 -2
- package/sticky/vue.js +4 -4
- package/tab-bar/index.js +2 -2
- package/tab-item-mf/vue.js +1 -1
- package/tab-nav/index.js +4 -4
- package/tabbar/index.js +1 -1
- package/tabbar/vue.js +1 -1
- package/tabbar-item/index.js +1 -1
- package/tabs-mf/index.js +5 -5
- package/tabs-mf/vue-bar.js +1 -1
- package/tabs-mf/vue-swipe.js +1 -1
- package/tabs-mf/vue.js +2 -2
- package/tabs-mf/wheel.js +3 -3
- package/tag-group/vue.js +2 -2
- package/tall-storage/index.js +1 -1
- package/tall-storage/vue.js +1 -1
- package/time/index.js +1 -1
- package/time/vue.js +1 -1
- package/time-line/index.js +1 -1
- package/time-line-new/index.js +1 -1
- package/time-panel/index.js +2 -2
- package/time-panel/vue.js +1 -1
- package/time-range/index.js +1 -1
- package/time-range/vue.js +1 -1
- package/time-spinner/index.js +4 -4
- package/time-spinner/vue.js +1 -1
- package/timeline-item/index.js +1 -1
- package/toggle-menu/index.js +1 -1
- package/tooltip/index.js +2 -2
- package/tooltip/vue.js +2 -2
- package/top-box/index.js +3 -3
- package/transfer/index.js +1 -1
- package/transfer-panel/index.js +1 -1
- package/tree/index.js +9 -9
- package/tree/vue.js +2 -2
- package/tree-node/index.js +1 -1
- package/tree-node/vue.js +1 -1
- package/tree-select/index.js +1 -1
- package/types/async-flowchart.type.d.ts +2 -14
- package/types/breadcrumb-item.type.d.ts +5 -1
- package/types/breadcrumb.type.d.ts +5 -1
- package/types/button-group.type.d.ts +5 -1
- package/types/button.type.d.ts +1 -1
- package/types/cascader.type.d.ts +6 -1
- package/types/date-table.type.d.ts +1 -120
- package/types/dropdown.type.d.ts +1 -1
- package/types/label.type.d.ts +1 -53
- package/types/loading.type.d.ts +12 -0
- package/types/numeric.type.d.ts +3 -22
- package/types/pager.type.d.ts +12 -7
- package/types/popconfirm.type.d.ts +2 -0
- package/types/steps.type.d.ts +1 -0
- package/types/tag-group.type.d.ts +2 -14
- package/types/tag.type.d.ts +4 -4
- package/types/tooltip.type.d.ts +3 -13
- package/types/user-head.type.d.ts +0 -4
- package/upload/index.js +1 -1
- package/upload-list/index.js +1 -1
- package/upload-list/vue.js +4 -4
- package/user/index.js +7 -7
- package/user/vue.js +15 -2
- package/user-contact/vue.js +2 -2
- package/virtual-scroll-box/index.js +2 -2
- package/wizard/index.js +3 -3
- package/year-range/index.js +61 -11
- package/year-range/vue.js +33 -20
- package/year-table/index.js +7 -5
- package/avatar/index.js +0 -30
- package/avatar/vue.js +0 -22
- package/common/array.js +0 -115
- package/common/bigInt.js +0 -315
- package/common/browser.js +0 -81
- package/common/calendar/calendar.js +0 -97
- package/common/dataset/index.js +0 -99
- package/common/date.js +0 -354
- package/common/decimal.js +0 -155
- package/common/deps/ResizeObserver.js +0 -456
- package/common/deps/after-leave.js +0 -27
- package/common/deps/clickoutside.js +0 -75
- package/common/deps/date-util.js +0 -255
- package/common/deps/date.js +0 -286
- package/common/deps/debounce.js +0 -8
- package/common/deps/eSpaceCtrl.js +0 -304
- package/common/deps/fastdom/async.js +0 -41
- package/common/deps/fastdom/index.js +0 -9
- package/common/deps/fastdom/sandbox.js +0 -53
- package/common/deps/fastdom/singleton.js +0 -88
- package/common/deps/fullscreen/apis.js +0 -143
- package/common/deps/fullscreen/screenfull.js +0 -165
- package/common/deps/memorize.js +0 -124
- package/common/deps/observe-visibility.js +0 -106
- package/common/deps/popper.js +0 -613
- package/common/deps/repeat-click.js +0 -29
- package/common/deps/resize-event.js +0 -39
- package/common/deps/scroll-into-view.js +0 -29
- package/common/deps/scrollbar-width.js +0 -33
- package/common/deps/throttle.js +0 -45
- package/common/deps/touch-emulator.js +0 -103
- package/common/deps/touch.js +0 -37
- package/common/deps/tree-model/node.js +0 -475
- package/common/deps/tree-model/tree-store.js +0 -312
- package/common/deps/tree-model/util.js +0 -24
- package/common/deps/upload-ajax.js +0 -81
- package/common/deps/useEventListener.js +0 -54
- package/common/deps/useInstanceSlots.js +0 -22
- package/common/deps/useRect.js +0 -25
- package/common/deps/useRelation.js +0 -89
- package/common/deps/useTouch.js +0 -68
- package/common/deps/useUserAgent.js +0 -16
- package/common/deps/useWindowSize.js +0 -23
- package/common/deps/vue-emitter.js +0 -34
- package/common/deps/vue-popper.js +0 -177
- package/common/deps/vue-popup.js +0 -138
- package/common/event.js +0 -46
- package/common/form/const.js +0 -10
- package/common/function.js +0 -28
- package/common/global.js +0 -11
- package/common/index.js +0 -259
- package/common/object.js +0 -227
- package/common/prop-util.js +0 -43
- package/common/runtime.js +0 -79
- package/common/string.js +0 -417
- package/common/type.js +0 -66
- package/common/validate/index.js +0 -10
- package/common/validate/messages.js +0 -65
- package/common/validate/rules/enum.js +0 -12
- package/common/validate/rules/index.js +0 -18
- package/common/validate/rules/pattern.js +0 -20
- package/common/validate/rules/range.js +0 -52
- package/common/validate/rules/required.js +0 -11
- package/common/validate/rules/type.js +0 -100
- package/common/validate/rules/whitespace.js +0 -10
- package/common/validate/schema.js +0 -290
- package/common/validate/util.js +0 -211
- package/common/validate/validations/array.js +0 -22
- package/common/validate/validations/date.js +0 -31
- package/common/validate/validations/enum.js +0 -22
- package/common/validate/validations/float.js +0 -22
- package/common/validate/validations/index.js +0 -46
- package/common/validate/validations/integer.js +0 -22
- package/common/validate/validations/method.js +0 -21
- package/common/validate/validations/number.js +0 -25
- package/common/validate/validations/pattern.js +0 -21
- package/common/validate/validations/required.js +0 -11
- package/common/validate/validations/string.js +0 -33
- package/common/validate/validations/type.js +0 -29
- package/index-bar/index.js +0 -66
- package/index-bar/vue.js +0 -73
- package/index-bar-anchor/vue.js +0 -16
- package/label/index.js +0 -56
- package/label/vue.js +0 -26
- package/list/index.js +0 -13
- package/list/vue.js +0 -17
- package/mask/index.js +0 -13
- package/mask/vue.js +0 -18
- package/mini-picker/index.js +0 -165
- package/mini-picker/vue.js +0 -122
- package/multi-select/index.js +0 -394
- package/multi-select/vue.js +0 -113
- package/multi-select-item/index.js +0 -23
- package/multi-select-item/vue.js +0 -31
- package/toast/index.js +0 -7
- package/toast/vue.js +0 -19
- package/types/toast.type.d.ts +0 -63
- package/wheel/index.js +0 -165
- package/wheel/vue.js +0 -79
|
@@ -1,475 +0,0 @@
|
|
|
1
|
-
import "../../../chunk-G2ADBYYC.js";
|
|
2
|
-
import { merge } from "../../object";
|
|
3
|
-
import { markNodeData, NODE_KEY } from "./util";
|
|
4
|
-
import { indexOf } from "../../array";
|
|
5
|
-
import { hasOwn, typeOf } from "../../type";
|
|
6
|
-
const defaultChildrenKey = "children";
|
|
7
|
-
const defaultIsLeafKey = "isLeaf";
|
|
8
|
-
const getPropertyFromData = (node, prop) => {
|
|
9
|
-
const props = node.store.props;
|
|
10
|
-
const dataData = node.data || {};
|
|
11
|
-
const config = props[prop];
|
|
12
|
-
if (typeOf(config) === "string") {
|
|
13
|
-
return dataData[config];
|
|
14
|
-
} else if (typeOf(config) === "function") {
|
|
15
|
-
return config(dataData, node);
|
|
16
|
-
} else if (typeof config === "undefined") {
|
|
17
|
-
const dataProp = dataData[prop];
|
|
18
|
-
return dataProp === void 0 ? "" : dataProp;
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
const getChildState = (node) => {
|
|
22
|
-
let all = true;
|
|
23
|
-
let none = true;
|
|
24
|
-
let allWithoutDisable = true;
|
|
25
|
-
for (let i = 0, len = node.length; i < len; i++) {
|
|
26
|
-
const { checked, disabled, indeterminate } = node[i];
|
|
27
|
-
if (checked !== true || indeterminate) {
|
|
28
|
-
all = false;
|
|
29
|
-
if (!disabled) {
|
|
30
|
-
allWithoutDisable = false;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
if (checked !== false || indeterminate) {
|
|
34
|
-
none = false;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
const half = !all && !none;
|
|
38
|
-
return { all, none, allWithoutDisable, half };
|
|
39
|
-
};
|
|
40
|
-
const reInitChecked = (node) => {
|
|
41
|
-
const childNodes = node.childNodes;
|
|
42
|
-
if (childNodes.length === 0) {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
const { all, none, half } = getChildState(childNodes);
|
|
46
|
-
if (all) {
|
|
47
|
-
Object.assign(node, { checked: true, indeterminate: false });
|
|
48
|
-
} else if (half) {
|
|
49
|
-
Object.assign(node, { checked: false, indeterminate: true });
|
|
50
|
-
} else if (none) {
|
|
51
|
-
Object.assign(node, { checked: false, indeterminate: false });
|
|
52
|
-
}
|
|
53
|
-
const parent = node.parent;
|
|
54
|
-
if (!parent || parent.level === 0) {
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
!node.store.checkStrictly && reInitChecked(parent);
|
|
58
|
-
};
|
|
59
|
-
let nodeIdSeed = 0;
|
|
60
|
-
class Node {
|
|
61
|
-
constructor(options) {
|
|
62
|
-
this.init(options);
|
|
63
|
-
const store = this.store;
|
|
64
|
-
if (!store) {
|
|
65
|
-
throw new Error("[TINY-Tree][Node]store is required!");
|
|
66
|
-
}
|
|
67
|
-
store.registerNode(this);
|
|
68
|
-
const props = store.props;
|
|
69
|
-
if (props && typeof props.isLeaf !== "undefined") {
|
|
70
|
-
const isLeaf = getPropertyFromData(this, defaultIsLeafKey);
|
|
71
|
-
if (typeof isLeaf === "boolean") {
|
|
72
|
-
this.isLeafByUser = isLeaf;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
this.initExpandState();
|
|
76
|
-
if (!Array.isArray(this.data)) {
|
|
77
|
-
markNodeData(this, this.data);
|
|
78
|
-
}
|
|
79
|
-
if (!this.data) {
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
this.expandByDefaultKeys();
|
|
83
|
-
const { key, lazy, currentNodeKey } = store;
|
|
84
|
-
if (key && currentNodeKey !== void 0 && this.key === currentNodeKey) {
|
|
85
|
-
store.currentNode = this;
|
|
86
|
-
store.currentNode.isCurrent = true;
|
|
87
|
-
}
|
|
88
|
-
lazy && store._initDefaultCheckedNode(this);
|
|
89
|
-
this.updateLeafState();
|
|
90
|
-
}
|
|
91
|
-
initExpandState() {
|
|
92
|
-
const { store, data, level } = this;
|
|
93
|
-
if (store.lazy !== true && data) {
|
|
94
|
-
this.setData(data);
|
|
95
|
-
if (store.defaultExpandAll) {
|
|
96
|
-
this.expanded = true;
|
|
97
|
-
this.updateMethod(this, "expanded");
|
|
98
|
-
}
|
|
99
|
-
} else if (level > 0 && store.lazy && store.defaultExpandAll) {
|
|
100
|
-
this.expand();
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
init(options) {
|
|
104
|
-
var _a, _b;
|
|
105
|
-
this.id = nodeIdSeed++;
|
|
106
|
-
this.checked = false;
|
|
107
|
-
this.indeterminate = false;
|
|
108
|
-
this.expanded = false;
|
|
109
|
-
this.visible = true;
|
|
110
|
-
this.isCurrent = false;
|
|
111
|
-
this.text = null;
|
|
112
|
-
this.data = null;
|
|
113
|
-
this.parent = null;
|
|
114
|
-
this.updateMethod = () => {
|
|
115
|
-
};
|
|
116
|
-
Object.keys(options).forEach((key) => {
|
|
117
|
-
if (hasOwn.call(options, key)) {
|
|
118
|
-
this[key] = options[key];
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
const isLeafKey = ((_b = (_a = this.store) == null ? void 0 : _a.props) == null ? void 0 : _b.isLeaf) || defaultIsLeafKey;
|
|
122
|
-
this.isLeaf = !!(this.data && this.data[isLeafKey]);
|
|
123
|
-
this.loaded = this.isLeaf;
|
|
124
|
-
this.loading = false;
|
|
125
|
-
this.childNodes = [];
|
|
126
|
-
this.level = this.parent ? this.parent.level + 1 : 0;
|
|
127
|
-
}
|
|
128
|
-
expandByDefaultKeys() {
|
|
129
|
-
const { defaultExpandedKeys, key, autoExpandParent } = this.store;
|
|
130
|
-
if (key && defaultExpandedKeys && ~defaultExpandedKeys.indexOf(this.key)) {
|
|
131
|
-
this.expand(null, autoExpandParent);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
setData(data) {
|
|
135
|
-
if (!Array.isArray(data)) {
|
|
136
|
-
markNodeData(this, data);
|
|
137
|
-
}
|
|
138
|
-
this.data = data;
|
|
139
|
-
this.childNodes = [];
|
|
140
|
-
let children;
|
|
141
|
-
if (this.level === 0 && Array.isArray(this.data)) {
|
|
142
|
-
children = this.data;
|
|
143
|
-
} else {
|
|
144
|
-
children = getPropertyFromData(this, defaultChildrenKey) || [];
|
|
145
|
-
}
|
|
146
|
-
for (let i = 0, len = children.length; i < len; i++) {
|
|
147
|
-
const data2 = children[i];
|
|
148
|
-
this.insertChild({ data: data2 });
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
get key() {
|
|
152
|
-
const { store, data } = this;
|
|
153
|
-
const nodeKey = store.key;
|
|
154
|
-
if (data) {
|
|
155
|
-
return data[nodeKey];
|
|
156
|
-
}
|
|
157
|
-
return null;
|
|
158
|
-
}
|
|
159
|
-
get label() {
|
|
160
|
-
return getPropertyFromData(this, "label");
|
|
161
|
-
}
|
|
162
|
-
get disabled() {
|
|
163
|
-
return getPropertyFromData(this, "disabled");
|
|
164
|
-
}
|
|
165
|
-
get nextSibling() {
|
|
166
|
-
const parent = this.parent;
|
|
167
|
-
if (parent) {
|
|
168
|
-
const childNodes = parent.childNodes;
|
|
169
|
-
const index = childNodes.indexOf(this);
|
|
170
|
-
if (~index) {
|
|
171
|
-
return childNodes[index + 1];
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
return null;
|
|
175
|
-
}
|
|
176
|
-
get previousSibling() {
|
|
177
|
-
const parent = this.parent;
|
|
178
|
-
if (parent) {
|
|
179
|
-
const childNodes = parent.childNodes;
|
|
180
|
-
const index = childNodes.indexOf(this);
|
|
181
|
-
if (~index) {
|
|
182
|
-
return index > 0 ? childNodes[index - 1] : null;
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
return null;
|
|
186
|
-
}
|
|
187
|
-
remove() {
|
|
188
|
-
const parent = this.parent;
|
|
189
|
-
parent && parent.removeChild(this);
|
|
190
|
-
}
|
|
191
|
-
contains(target, deep = true) {
|
|
192
|
-
const walkTree = (parent) => {
|
|
193
|
-
const children = parent.childNodes || [];
|
|
194
|
-
let isContain = false;
|
|
195
|
-
for (let i = 0, len = children.length; i < len; i++) {
|
|
196
|
-
const child = children[i];
|
|
197
|
-
if (child === target || deep && walkTree(child)) {
|
|
198
|
-
isContain = true;
|
|
199
|
-
break;
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
return isContain;
|
|
203
|
-
};
|
|
204
|
-
return walkTree(this);
|
|
205
|
-
}
|
|
206
|
-
insertChild(child, index, batch) {
|
|
207
|
-
if (!child) {
|
|
208
|
-
throw new Error("[TINY-Tree] insertChild error: child is required.");
|
|
209
|
-
}
|
|
210
|
-
const insertNode = ({ arr, index: index2, item }) => {
|
|
211
|
-
if (typeof index2 === "undefined" || index2 < 0) {
|
|
212
|
-
arr.push(item);
|
|
213
|
-
} else {
|
|
214
|
-
arr.splice(index2, 0, item);
|
|
215
|
-
}
|
|
216
|
-
};
|
|
217
|
-
if (!(child instanceof Node)) {
|
|
218
|
-
if (!batch) {
|
|
219
|
-
const children = this.getChildren(true) || [];
|
|
220
|
-
if (!~children.indexOf(child.data)) {
|
|
221
|
-
insertNode({ arr: children, index, item: child.data });
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
merge(child, { parent: this, store: this.store });
|
|
225
|
-
child = new Node(child);
|
|
226
|
-
}
|
|
227
|
-
child.level = this.level + 1;
|
|
228
|
-
insertNode({ arr: this.childNodes, index, item: child });
|
|
229
|
-
this.updateLeafState();
|
|
230
|
-
return child;
|
|
231
|
-
}
|
|
232
|
-
insertBefore(child, beforeNode) {
|
|
233
|
-
let index;
|
|
234
|
-
if (beforeNode) {
|
|
235
|
-
index = this.childNodes.indexOf(beforeNode);
|
|
236
|
-
}
|
|
237
|
-
this.insertChild(child, index);
|
|
238
|
-
}
|
|
239
|
-
insertAfter(child, afterNode) {
|
|
240
|
-
let index;
|
|
241
|
-
if (afterNode) {
|
|
242
|
-
index = this.childNodes.indexOf(afterNode);
|
|
243
|
-
if (~index) {
|
|
244
|
-
index += 1;
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
this.insertChild(child, index);
|
|
248
|
-
}
|
|
249
|
-
removeChild(child) {
|
|
250
|
-
const children = this.getChildren() || [];
|
|
251
|
-
let index = children.indexOf(child.data);
|
|
252
|
-
if (~index) {
|
|
253
|
-
children.splice(index, 1);
|
|
254
|
-
}
|
|
255
|
-
index = this.childNodes.indexOf(child);
|
|
256
|
-
if (~index) {
|
|
257
|
-
this.store && this.store.deregisterNode(child);
|
|
258
|
-
child.parent = null;
|
|
259
|
-
this.childNodes.splice(index, 1);
|
|
260
|
-
}
|
|
261
|
-
this.updateLeafState();
|
|
262
|
-
}
|
|
263
|
-
removeChildByData(data) {
|
|
264
|
-
let removeNode = null;
|
|
265
|
-
for (let i = 0, len = this.childNodes.length; i < len; i++) {
|
|
266
|
-
const child = this.childNodes[i];
|
|
267
|
-
if (child.data === data) {
|
|
268
|
-
removeNode = child;
|
|
269
|
-
break;
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
removeNode && this.removeChild(removeNode);
|
|
273
|
-
}
|
|
274
|
-
expand(callback, expandParent) {
|
|
275
|
-
const expandNodes = () => {
|
|
276
|
-
if (expandParent) {
|
|
277
|
-
let parentNode = this.parent;
|
|
278
|
-
while (parentNode.level > 0) {
|
|
279
|
-
parentNode.expanded = true;
|
|
280
|
-
parentNode.updateMethod(parentNode, "expanded");
|
|
281
|
-
parentNode = parentNode.parent;
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
this.expanded = true;
|
|
285
|
-
this.updateMethod(this, "expanded");
|
|
286
|
-
callback && callback();
|
|
287
|
-
};
|
|
288
|
-
if (this.shouldLoadData()) {
|
|
289
|
-
this.loadData((data) => {
|
|
290
|
-
if (Array.isArray(data)) {
|
|
291
|
-
if (this.checked) {
|
|
292
|
-
this.setChecked(true, true);
|
|
293
|
-
} else if (!this.store.checkStrictly) {
|
|
294
|
-
reInitChecked(this);
|
|
295
|
-
}
|
|
296
|
-
expandNodes();
|
|
297
|
-
}
|
|
298
|
-
});
|
|
299
|
-
} else {
|
|
300
|
-
expandNodes();
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
doCreateChildren(array, defaultProps = {}) {
|
|
304
|
-
array.forEach((data) => {
|
|
305
|
-
this.insertChild(merge({ data }, defaultProps), void 0, true);
|
|
306
|
-
});
|
|
307
|
-
}
|
|
308
|
-
collapse() {
|
|
309
|
-
this.expanded = false;
|
|
310
|
-
this.updateMethod(this, "expanded");
|
|
311
|
-
}
|
|
312
|
-
shouldLoadData() {
|
|
313
|
-
return this.store.lazy === true && this.store.load && !this.loaded;
|
|
314
|
-
}
|
|
315
|
-
updateLeafState() {
|
|
316
|
-
const { store, loaded, isLeafByUser } = this;
|
|
317
|
-
const lazy = store.lazy;
|
|
318
|
-
if (lazy === true && loaded !== true && typeof isLeafByUser !== "undefined") {
|
|
319
|
-
this.isLeaf = isLeafByUser;
|
|
320
|
-
return;
|
|
321
|
-
}
|
|
322
|
-
const childs = this.childNodes;
|
|
323
|
-
if (!lazy || lazy === true && loaded === true) {
|
|
324
|
-
this.isLeaf = !childs || childs.length === 0;
|
|
325
|
-
return;
|
|
326
|
-
}
|
|
327
|
-
this.isLeaf = false;
|
|
328
|
-
}
|
|
329
|
-
getChildren(forceInit = false) {
|
|
330
|
-
const { level, data } = this;
|
|
331
|
-
if (level === 0) {
|
|
332
|
-
return data;
|
|
333
|
-
}
|
|
334
|
-
if (!data) {
|
|
335
|
-
return null;
|
|
336
|
-
}
|
|
337
|
-
const props = this.store.props;
|
|
338
|
-
let childrenKey = defaultChildrenKey;
|
|
339
|
-
if (props) {
|
|
340
|
-
childrenKey = props.children || defaultChildrenKey;
|
|
341
|
-
}
|
|
342
|
-
if (data[childrenKey] === void 0) {
|
|
343
|
-
data[childrenKey] = null;
|
|
344
|
-
}
|
|
345
|
-
if (forceInit && !data[childrenKey]) {
|
|
346
|
-
data[childrenKey] = [];
|
|
347
|
-
}
|
|
348
|
-
return data[childrenKey];
|
|
349
|
-
}
|
|
350
|
-
setChecked(value, isDeepChecked, recursion, passValue, checkEasily) {
|
|
351
|
-
this.checked = value === true;
|
|
352
|
-
this.indeterminate = value === "half";
|
|
353
|
-
const { checkStrictly, checkDescendants } = this.store;
|
|
354
|
-
if (checkStrictly && !checkEasily) {
|
|
355
|
-
return;
|
|
356
|
-
}
|
|
357
|
-
let ret = this.setCheckedInner({
|
|
358
|
-
checkDescendants,
|
|
359
|
-
value,
|
|
360
|
-
isDeepChecked,
|
|
361
|
-
passValue,
|
|
362
|
-
checkEasily
|
|
363
|
-
});
|
|
364
|
-
let returnFlag = ret.returnFlag;
|
|
365
|
-
passValue = ret.passValue;
|
|
366
|
-
value = ret.value;
|
|
367
|
-
if (returnFlag || checkStrictly && checkEasily) {
|
|
368
|
-
return;
|
|
369
|
-
}
|
|
370
|
-
const parentNode = this.parent;
|
|
371
|
-
if (!parentNode || parentNode.level === 0) {
|
|
372
|
-
return;
|
|
373
|
-
}
|
|
374
|
-
if (!recursion) {
|
|
375
|
-
reInitChecked(parentNode);
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
setCheckedInner({ checkDescendants, value, isDeepChecked, passValue, checkEasily }) {
|
|
379
|
-
let returnFlag = false;
|
|
380
|
-
if (this.shouldLoadData() && !checkDescendants) {
|
|
381
|
-
return { value, passValue, returnFlag };
|
|
382
|
-
}
|
|
383
|
-
const { all, allWithoutDisable } = getChildState(this.childNodes);
|
|
384
|
-
if (!this.isLeaf && !all && allWithoutDisable && !checkEasily) {
|
|
385
|
-
this.checked = false;
|
|
386
|
-
value = false;
|
|
387
|
-
}
|
|
388
|
-
const batchSetChecked = () => {
|
|
389
|
-
if (isDeepChecked) {
|
|
390
|
-
const childNodes = this.childNodes;
|
|
391
|
-
for (let i = 0, len = childNodes.length; i < len; i++) {
|
|
392
|
-
const childNode = childNodes[i];
|
|
393
|
-
passValue = passValue || value !== false;
|
|
394
|
-
const isCheck = childNode.disabled ? childNode.checked : passValue;
|
|
395
|
-
childNode.setChecked(isCheck, isDeepChecked, true, passValue, checkEasily);
|
|
396
|
-
}
|
|
397
|
-
const { half, all: all2 } = getChildState(childNodes);
|
|
398
|
-
if (!all2 && !checkEasily) {
|
|
399
|
-
this.checked = all2;
|
|
400
|
-
this.indeterminate = half;
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
};
|
|
404
|
-
if (this.shouldLoadData()) {
|
|
405
|
-
const afterLoad = () => {
|
|
406
|
-
batchSetChecked();
|
|
407
|
-
reInitChecked(this);
|
|
408
|
-
};
|
|
409
|
-
this.loadData(afterLoad, { checked: value !== false });
|
|
410
|
-
returnFlag = true;
|
|
411
|
-
} else {
|
|
412
|
-
batchSetChecked();
|
|
413
|
-
}
|
|
414
|
-
return { value, passValue, returnFlag };
|
|
415
|
-
}
|
|
416
|
-
updateChildren() {
|
|
417
|
-
const children = this.getChildren() || [];
|
|
418
|
-
const oldChildren = this.childNodes.map((child) => child.data);
|
|
419
|
-
const newChildrenMap = {};
|
|
420
|
-
const newChildren = [];
|
|
421
|
-
children.forEach((item, index) => {
|
|
422
|
-
const key = item[NODE_KEY];
|
|
423
|
-
const isNodeExists = !!key && indexOf(oldChildren, key, (item2, data) => item2[NODE_KEY] === data) >= 0;
|
|
424
|
-
if (isNodeExists) {
|
|
425
|
-
newChildrenMap[key] = { index, data: item };
|
|
426
|
-
} else {
|
|
427
|
-
newChildren.push({ index, data: item });
|
|
428
|
-
}
|
|
429
|
-
});
|
|
430
|
-
if (!this.store.lazy) {
|
|
431
|
-
oldChildren.forEach((item) => {
|
|
432
|
-
if (!newChildrenMap[item[NODE_KEY]]) {
|
|
433
|
-
this.removeChildByData(item);
|
|
434
|
-
}
|
|
435
|
-
});
|
|
436
|
-
}
|
|
437
|
-
newChildren.forEach(({ data, index }) => {
|
|
438
|
-
this.insertChild({ data }, index);
|
|
439
|
-
});
|
|
440
|
-
this.updateLeafState();
|
|
441
|
-
}
|
|
442
|
-
loadData(callback, defaultProps = {}) {
|
|
443
|
-
const { lazy, load } = this.store;
|
|
444
|
-
if (lazy === true && load && !this.loaded && (!this.loading || Object.keys(defaultProps).length)) {
|
|
445
|
-
this.loading = true;
|
|
446
|
-
this.store.load(this, (children) => {
|
|
447
|
-
this.loading = false;
|
|
448
|
-
this.loaded = true;
|
|
449
|
-
this.childNodes = [];
|
|
450
|
-
this.doCreateChildren(children, defaultProps);
|
|
451
|
-
this.updateLeafState();
|
|
452
|
-
callback && callback.call(this, children);
|
|
453
|
-
typeof this.store.afterLoad === "function" && this.store.afterLoad({ data: children });
|
|
454
|
-
});
|
|
455
|
-
} else {
|
|
456
|
-
callback && callback.call(this);
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
getPathData(key) {
|
|
460
|
-
const nodes = [key ? this.data[key] : this.data];
|
|
461
|
-
let parentNode = this.parent;
|
|
462
|
-
while (parentNode && parentNode.parent) {
|
|
463
|
-
nodes.unshift(key ? parentNode.data[key] : parentNode.data);
|
|
464
|
-
parentNode = parentNode.parent;
|
|
465
|
-
}
|
|
466
|
-
return nodes;
|
|
467
|
-
}
|
|
468
|
-
getPathText(key, separator = ",") {
|
|
469
|
-
return (this.getPathData(key) || []).join(separator);
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
|
-
export {
|
|
473
|
-
Node as default,
|
|
474
|
-
getChildState
|
|
475
|
-
};
|