vft 0.0.106 → 0.0.107
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/es/components/tree/model/tree-store.js +58 -69
- package/es/components/tree/tree.vue2.js +92 -99
- package/es/package.json.js +1 -1
- package/lib/components/tree/model/tree-store.cjs +1 -1
- package/lib/components/tree/tree.vue2.cjs +1 -1
- package/lib/package.json.cjs +1 -1
- package/package.json +2 -2
- package/web-types.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { hasOwn as u, isObject as C } from "@vft/utils";
|
|
2
2
|
import N from "./node.js";
|
|
3
|
-
import { getNodeKey as
|
|
4
|
-
class
|
|
3
|
+
import { getNodeKey as y } from "./util.js";
|
|
4
|
+
class M {
|
|
5
5
|
constructor(e) {
|
|
6
6
|
this.currentNode = null, this.currentNodeKey = null;
|
|
7
7
|
for (const t in e)
|
|
@@ -21,17 +21,17 @@ class E {
|
|
|
21
21
|
this._initDefaultCheckedNodes();
|
|
22
22
|
}
|
|
23
23
|
filter(e) {
|
|
24
|
-
const t = this.filterNodeMethod, s = this.lazy,
|
|
25
|
-
const
|
|
26
|
-
if (
|
|
27
|
-
r.visible = t.call(r, e, r.data, r),
|
|
28
|
-
}), !
|
|
24
|
+
const t = this.filterNodeMethod, s = this.lazy, o = function(i) {
|
|
25
|
+
const d = i.root ? i.root.childNodes : i.childNodes;
|
|
26
|
+
if (d.forEach((r) => {
|
|
27
|
+
r.visible = t.call(r, e, r.data, r), o(r);
|
|
28
|
+
}), !i.visible && d.length) {
|
|
29
29
|
let r = !0;
|
|
30
|
-
r = !
|
|
30
|
+
r = !d.some((h) => h.visible), i.root ? i.root.visible = r === !1 : i.visible = r === !1;
|
|
31
31
|
}
|
|
32
|
-
e &&
|
|
32
|
+
e && i.visible && !i.isLeaf && !s && i.expand();
|
|
33
33
|
};
|
|
34
|
-
|
|
34
|
+
o(this);
|
|
35
35
|
}
|
|
36
36
|
setData(e) {
|
|
37
37
|
e !== this.root.data ? (this.root.setData(e), this._initDefaultCheckedNodes()) : this.root.updateChildren();
|
|
@@ -39,7 +39,7 @@ class E {
|
|
|
39
39
|
getNode(e) {
|
|
40
40
|
if (e instanceof N)
|
|
41
41
|
return e;
|
|
42
|
-
const t = C(e) ?
|
|
42
|
+
const t = C(e) ? y(this.key, e) : e;
|
|
43
43
|
return this.nodesMap[t] || null;
|
|
44
44
|
}
|
|
45
45
|
insertBefore(e, t) {
|
|
@@ -61,8 +61,8 @@ class E {
|
|
|
61
61
|
_initDefaultCheckedNodes() {
|
|
62
62
|
const e = this.defaultCheckedKeys || [], t = this.nodesMap;
|
|
63
63
|
e.forEach((s) => {
|
|
64
|
-
const
|
|
65
|
-
|
|
64
|
+
const o = t[s];
|
|
65
|
+
o && o.setChecked(!0, !this.checkStrictly);
|
|
66
66
|
});
|
|
67
67
|
}
|
|
68
68
|
_initDefaultCheckedNode(e) {
|
|
@@ -81,20 +81,20 @@ class E {
|
|
|
81
81
|
}), delete this.nodesMap[e.key]);
|
|
82
82
|
}
|
|
83
83
|
getCheckedNodes(e = !1, t = !1) {
|
|
84
|
-
const s = [],
|
|
85
|
-
(
|
|
86
|
-
(r.checked || t && r.indeterminate) && (!e || e && r.isLeaf) && s.push(r.data),
|
|
84
|
+
const s = [], o = function(i) {
|
|
85
|
+
(i.root ? i.root.childNodes : i.childNodes).forEach((r) => {
|
|
86
|
+
(r.checked || t && r.indeterminate) && (!e || e && r.isLeaf) && s.push(r.data), o(r);
|
|
87
87
|
});
|
|
88
88
|
};
|
|
89
|
-
return
|
|
89
|
+
return o(this), s;
|
|
90
90
|
}
|
|
91
91
|
getCheckedKeys(e = !1) {
|
|
92
92
|
return this.getCheckedNodes(e).map((t) => (t || {})[this.key]);
|
|
93
93
|
}
|
|
94
94
|
getHalfCheckedNodes() {
|
|
95
95
|
const e = [], t = function(s) {
|
|
96
|
-
(s.root ? s.root.childNodes : s.childNodes).forEach((
|
|
97
|
-
|
|
96
|
+
(s.root ? s.root.childNodes : s.childNodes).forEach((i) => {
|
|
97
|
+
i.indeterminate && e.push(i.data), t(i);
|
|
98
98
|
});
|
|
99
99
|
};
|
|
100
100
|
return t(this), e;
|
|
@@ -108,67 +108,59 @@ class E {
|
|
|
108
108
|
u(t, s) && e.push(t[s]);
|
|
109
109
|
return e;
|
|
110
110
|
}
|
|
111
|
-
|
|
112
|
-
const s = e
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
111
|
+
updateChildren(e, t) {
|
|
112
|
+
const s = this.nodesMap[e];
|
|
113
|
+
if (!s)
|
|
114
|
+
return;
|
|
115
|
+
const o = s.childNodes;
|
|
116
|
+
for (let i = o.length - 1; i >= 0; i--) {
|
|
117
|
+
const d = o[i];
|
|
118
|
+
this.remove(d.data);
|
|
116
119
|
}
|
|
117
|
-
for (let i = 0,
|
|
118
|
-
const
|
|
119
|
-
this.append(
|
|
120
|
+
for (let i = 0, d = t.length; i < d; i++) {
|
|
121
|
+
const r = t[i];
|
|
122
|
+
this.append(r, s.data);
|
|
120
123
|
}
|
|
121
124
|
}
|
|
122
|
-
updateRootChildren(e) {
|
|
123
|
-
this._updateChildren(this.root, e);
|
|
124
|
-
}
|
|
125
|
-
updateKeyChildren(e, t) {
|
|
126
|
-
const s = this.nodesMap[e];
|
|
127
|
-
s && this._updateChildren(s, t);
|
|
128
|
-
}
|
|
129
|
-
updateNodeChildren(e, t) {
|
|
130
|
-
const s = t ? this.getNode(t) : this.root;
|
|
131
|
-
this._updateChildren(s, e);
|
|
132
|
-
}
|
|
133
125
|
_setCheckedKeys(e, t = !1, s) {
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
for (let r = 0,
|
|
137
|
-
const
|
|
138
|
-
if (!
|
|
139
|
-
|
|
126
|
+
const o = this._getAllNodes().sort((r, h) => h.level - r.level), i = /* @__PURE__ */ Object.create(null), d = Object.keys(s);
|
|
127
|
+
o.forEach((r) => r.setChecked(!1, !1));
|
|
128
|
+
for (let r = 0, h = o.length; r < h; r++) {
|
|
129
|
+
const n = o[r], l = n.data[e].toString();
|
|
130
|
+
if (!d.includes(l)) {
|
|
131
|
+
n.checked && !i[l] && n.setChecked(!1, !1);
|
|
140
132
|
continue;
|
|
141
133
|
}
|
|
142
|
-
let c =
|
|
134
|
+
let c = n.parent;
|
|
143
135
|
for (; c && c.level > 0; )
|
|
144
|
-
|
|
145
|
-
if (
|
|
146
|
-
|
|
136
|
+
i[c.data[e]] = !0, c = c.parent;
|
|
137
|
+
if (n.isLeaf || this.checkStrictly) {
|
|
138
|
+
n.setChecked(!0, !1);
|
|
147
139
|
continue;
|
|
148
140
|
}
|
|
149
|
-
if (
|
|
150
|
-
|
|
141
|
+
if (n.setChecked(!0, !0), t) {
|
|
142
|
+
n.setChecked(!1, !1);
|
|
151
143
|
const f = function(k) {
|
|
152
|
-
k.childNodes.forEach((
|
|
153
|
-
|
|
144
|
+
k.childNodes.forEach((a) => {
|
|
145
|
+
a.isLeaf || a.setChecked(!1, !1), f(a);
|
|
154
146
|
});
|
|
155
147
|
};
|
|
156
|
-
f(
|
|
148
|
+
f(n);
|
|
157
149
|
}
|
|
158
150
|
}
|
|
159
151
|
}
|
|
160
152
|
setCheckedNodes(e, t = !1) {
|
|
161
|
-
const s = this.key,
|
|
162
|
-
e.forEach((
|
|
163
|
-
|
|
164
|
-
}), this._setCheckedKeys(s, t,
|
|
153
|
+
const s = this.key, o = {};
|
|
154
|
+
e.forEach((i) => {
|
|
155
|
+
o[(i || {})[s]] = !0;
|
|
156
|
+
}), this._setCheckedKeys(s, t, o);
|
|
165
157
|
}
|
|
166
158
|
setCheckedKeys(e, t = !1) {
|
|
167
159
|
this.defaultCheckedKeys = e;
|
|
168
|
-
const s = this.key,
|
|
169
|
-
e.forEach((
|
|
170
|
-
i
|
|
171
|
-
}), this._setCheckedKeys(s, t,
|
|
160
|
+
const s = this.key, o = {};
|
|
161
|
+
e.forEach((i) => {
|
|
162
|
+
o[i] = !0;
|
|
163
|
+
}), this._setCheckedKeys(s, t, o);
|
|
172
164
|
}
|
|
173
165
|
setDefaultExpandedKeys(e) {
|
|
174
166
|
e = e || [], this.defaultExpandedKeys = e, e.forEach((t) => {
|
|
@@ -177,8 +169,8 @@ class E {
|
|
|
177
169
|
});
|
|
178
170
|
}
|
|
179
171
|
setChecked(e, t, s) {
|
|
180
|
-
const
|
|
181
|
-
|
|
172
|
+
const o = this.getNode(e);
|
|
173
|
+
o && o.setChecked(!!t, s);
|
|
182
174
|
}
|
|
183
175
|
getCurrentNode() {
|
|
184
176
|
return this.currentNode;
|
|
@@ -188,8 +180,8 @@ class E {
|
|
|
188
180
|
t && (t.isCurrent = !1), this.currentNode = e, this.currentNode.isCurrent = !0;
|
|
189
181
|
}
|
|
190
182
|
setUserCurrentNode(e, t = !0) {
|
|
191
|
-
const s = e[this.key],
|
|
192
|
-
this.setCurrentNode(
|
|
183
|
+
const s = e[this.key], o = this.nodesMap[s];
|
|
184
|
+
this.setCurrentNode(o), t && this.currentNode.level > 1 && this.currentNode.parent.expand(null, !0);
|
|
193
185
|
}
|
|
194
186
|
setCurrentNodeKey(e, t = !0) {
|
|
195
187
|
if (e == null) {
|
|
@@ -199,10 +191,7 @@ class E {
|
|
|
199
191
|
const s = this.getNode(e);
|
|
200
192
|
s && (this.setCurrentNode(s), t && this.currentNode.level > 1 && this.currentNode.parent.expand(null, !0));
|
|
201
193
|
}
|
|
202
|
-
getRoot() {
|
|
203
|
-
return this.root;
|
|
204
|
-
}
|
|
205
194
|
}
|
|
206
195
|
export {
|
|
207
|
-
|
|
196
|
+
M as default
|
|
208
197
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { defineComponent as
|
|
2
|
-
import { useNamespace as
|
|
1
|
+
import { defineComponent as $, ref as l, computed as j, watch as u, provide as f, getCurrentInstance as _ } from "vue";
|
|
2
|
+
import { useNamespace as R } from "../../hooks/use-namespace/index.js";
|
|
3
3
|
import "@popperjs/core";
|
|
4
4
|
import "lodash";
|
|
5
5
|
import "../../hooks/use-z-index/index.js";
|
|
@@ -7,16 +7,16 @@ import "@vueuse/core";
|
|
|
7
7
|
import "@vft/utils";
|
|
8
8
|
import "../../utils/ns-cover.js";
|
|
9
9
|
import "../form/index.js";
|
|
10
|
-
import
|
|
11
|
-
import { getNodeKey as
|
|
12
|
-
import
|
|
13
|
-
import { useNodeExpandEventBroadcast as
|
|
14
|
-
import { useDragNodeHandler as
|
|
15
|
-
import { useKeydown as
|
|
16
|
-
import { formItemContextKey as
|
|
17
|
-
const
|
|
10
|
+
import U from "./model/tree-store.js";
|
|
11
|
+
import { getNodeKey as V, handleCurrentChange as K } from "./model/util.js";
|
|
12
|
+
import G from "./tree-node.vue.js";
|
|
13
|
+
import { useNodeExpandEventBroadcast as J } from "./model/useNodeExpandEventBroadcast.js";
|
|
14
|
+
import { useDragNodeHandler as L } from "./model/useDragNode.js";
|
|
15
|
+
import { useKeydown as Q } from "./model/useKeydown.js";
|
|
16
|
+
import { formItemContextKey as W } from "../form/constants.js";
|
|
17
|
+
const he = $({
|
|
18
18
|
name: "VftTree",
|
|
19
|
-
components: { TreeNode:
|
|
19
|
+
components: { TreeNode: G },
|
|
20
20
|
props: {
|
|
21
21
|
data: {
|
|
22
22
|
type: Array,
|
|
@@ -98,72 +98,72 @@ const Ce = _({
|
|
|
98
98
|
"node-drag-enter",
|
|
99
99
|
"node-drag-over"
|
|
100
100
|
],
|
|
101
|
-
setup(
|
|
102
|
-
const C =
|
|
103
|
-
new
|
|
104
|
-
key:
|
|
105
|
-
data:
|
|
106
|
-
lazy:
|
|
107
|
-
props:
|
|
108
|
-
load:
|
|
109
|
-
currentNodeKey:
|
|
110
|
-
checkStrictly:
|
|
111
|
-
checkDescendants:
|
|
112
|
-
defaultCheckedKeys:
|
|
113
|
-
defaultExpandedKeys:
|
|
114
|
-
autoExpandParent:
|
|
115
|
-
defaultExpandAll:
|
|
116
|
-
filterNodeMethod:
|
|
101
|
+
setup(t, o) {
|
|
102
|
+
const C = R("tree"), n = l(
|
|
103
|
+
new U({
|
|
104
|
+
key: t.nodeKey,
|
|
105
|
+
data: t.data,
|
|
106
|
+
lazy: t.lazy,
|
|
107
|
+
props: t.props,
|
|
108
|
+
load: t.load,
|
|
109
|
+
currentNodeKey: t.currentNodeKey,
|
|
110
|
+
checkStrictly: t.checkStrictly,
|
|
111
|
+
checkDescendants: t.checkDescendants,
|
|
112
|
+
defaultCheckedKeys: t.defaultCheckedKeys,
|
|
113
|
+
defaultExpandedKeys: t.defaultExpandedKeys,
|
|
114
|
+
autoExpandParent: t.autoExpandParent,
|
|
115
|
+
defaultExpandAll: t.defaultExpandAll,
|
|
116
|
+
filterNodeMethod: t.filterNodeMethod
|
|
117
117
|
})
|
|
118
118
|
);
|
|
119
|
-
|
|
120
|
-
const c = l(
|
|
121
|
-
props:
|
|
119
|
+
n.value.initialize();
|
|
120
|
+
const c = l(n.value.root), s = l(null), i = l(null), y = l(null), { broadcastExpanded: m } = J(t), { dragState: N } = L({
|
|
121
|
+
props: t,
|
|
122
122
|
ctx: o,
|
|
123
123
|
el$: i,
|
|
124
124
|
dropIndicator$: y,
|
|
125
|
-
store:
|
|
125
|
+
store: n
|
|
126
126
|
});
|
|
127
|
-
|
|
128
|
-
const g =
|
|
127
|
+
Q({ el$: i }, n);
|
|
128
|
+
const g = j(() => {
|
|
129
129
|
const { childNodes: e } = c.value;
|
|
130
130
|
return !e || e.length === 0 || e.every(({ visible: r }) => !r);
|
|
131
131
|
});
|
|
132
132
|
u(
|
|
133
|
-
() =>
|
|
133
|
+
() => t.currentNodeKey,
|
|
134
134
|
(e) => {
|
|
135
|
-
|
|
135
|
+
n.value.setCurrentNodeKey(e);
|
|
136
136
|
}
|
|
137
137
|
), u(
|
|
138
|
-
() =>
|
|
138
|
+
() => t.defaultCheckedKeys,
|
|
139
139
|
(e) => {
|
|
140
|
-
|
|
140
|
+
n.value.setDefaultCheckedKey(e);
|
|
141
141
|
}
|
|
142
142
|
), u(
|
|
143
|
-
() =>
|
|
143
|
+
() => t.defaultExpandedKeys,
|
|
144
144
|
(e) => {
|
|
145
|
-
|
|
145
|
+
n.value.setDefaultExpandedKeys(e);
|
|
146
146
|
}
|
|
147
147
|
), u(
|
|
148
|
-
() =>
|
|
148
|
+
() => t.data,
|
|
149
149
|
(e) => {
|
|
150
|
-
|
|
150
|
+
n.value.setData(e);
|
|
151
151
|
},
|
|
152
152
|
{ deep: !0 }
|
|
153
153
|
), u(
|
|
154
|
-
() =>
|
|
154
|
+
() => t.checkStrictly,
|
|
155
155
|
(e) => {
|
|
156
|
-
|
|
156
|
+
n.value.checkStrictly = e;
|
|
157
157
|
}
|
|
158
158
|
);
|
|
159
|
-
const
|
|
160
|
-
if (!
|
|
159
|
+
const k = (e) => {
|
|
160
|
+
if (!t.filterNodeMethod)
|
|
161
161
|
throw new Error("[Tree] filterNodeMethod is required when filter");
|
|
162
|
-
|
|
163
|
-
},
|
|
164
|
-
if (!
|
|
162
|
+
n.value.filter(e);
|
|
163
|
+
}, v = (e) => V(t.nodeKey, e.data), E = (e) => {
|
|
164
|
+
if (!t.nodeKey)
|
|
165
165
|
throw new Error("[Tree] nodeKey is required in getNodePath");
|
|
166
|
-
const r =
|
|
166
|
+
const r = n.value.getNode(e);
|
|
167
167
|
if (!r)
|
|
168
168
|
return [];
|
|
169
169
|
const d = [r.data];
|
|
@@ -171,84 +171,79 @@ const Ce = _({
|
|
|
171
171
|
for (; a && a !== c.value; )
|
|
172
172
|
d.push(a.data), a = a.parent;
|
|
173
173
|
return d.reverse();
|
|
174
|
-
},
|
|
175
|
-
const e =
|
|
174
|
+
}, w = (e, r) => n.value.getCheckedNodes(e, r), p = (e) => n.value.getCheckedKeys(e), h = () => {
|
|
175
|
+
const e = n.value.getCurrentNode();
|
|
176
176
|
return e ? e.data : null;
|
|
177
177
|
}, x = () => {
|
|
178
|
-
if (!
|
|
178
|
+
if (!t.nodeKey)
|
|
179
179
|
throw new Error("[Tree] nodeKey is required in getCurrentKey");
|
|
180
180
|
const e = h();
|
|
181
|
-
return e ? e[
|
|
181
|
+
return e ? e[t.nodeKey] : null;
|
|
182
182
|
}, B = (e, r) => {
|
|
183
|
-
if (!
|
|
183
|
+
if (!t.nodeKey)
|
|
184
184
|
throw new Error("[Tree] nodeKey is required in setCheckedNodes");
|
|
185
|
-
|
|
185
|
+
n.value.setCheckedNodes(e, r);
|
|
186
186
|
}, T = (e, r) => {
|
|
187
|
-
if (!
|
|
187
|
+
if (!t.nodeKey)
|
|
188
188
|
throw new Error("[Tree] nodeKey is required in setCheckedKeys");
|
|
189
|
-
|
|
189
|
+
n.value.setCheckedKeys(e, r);
|
|
190
190
|
}, b = (e, r, d) => {
|
|
191
|
-
|
|
192
|
-
}, S = () =>
|
|
193
|
-
if (!
|
|
191
|
+
n.value.setChecked(e, r, d);
|
|
192
|
+
}, S = () => n.value.getHalfCheckedNodes(), A = () => n.value.getHalfCheckedKeys(), D = (e, r = !0) => {
|
|
193
|
+
if (!t.nodeKey)
|
|
194
194
|
throw new Error("[Tree] nodeKey is required in setCurrentNode");
|
|
195
195
|
K(
|
|
196
|
-
|
|
196
|
+
n,
|
|
197
197
|
o.emit,
|
|
198
|
-
() =>
|
|
198
|
+
() => n.value.setUserCurrentNode(e, r)
|
|
199
199
|
);
|
|
200
200
|
}, q = (e, r = !0) => {
|
|
201
|
-
if (!
|
|
201
|
+
if (!t.nodeKey)
|
|
202
202
|
throw new Error("[Tree] nodeKey is required in setCurrentKey");
|
|
203
203
|
K(
|
|
204
|
-
|
|
204
|
+
n,
|
|
205
205
|
o.emit,
|
|
206
|
-
() =>
|
|
206
|
+
() => n.value.setCurrentNodeKey(e, r)
|
|
207
207
|
);
|
|
208
|
-
}, F = (e) =>
|
|
209
|
-
|
|
208
|
+
}, F = (e) => n.value.getNode(e), H = (e) => {
|
|
209
|
+
n.value.remove(e);
|
|
210
|
+
}, M = (e, r) => {
|
|
211
|
+
n.value.append(e, r);
|
|
210
212
|
}, P = (e, r) => {
|
|
211
|
-
|
|
212
|
-
}, R = (e, r) => {
|
|
213
|
-
t.value.updateNodeChildren(e, r);
|
|
213
|
+
n.value.insertBefore(e, r);
|
|
214
214
|
}, z = (e, r) => {
|
|
215
|
-
|
|
216
|
-
}, O = (e) => {
|
|
217
|
-
|
|
215
|
+
n.value.insertAfter(e, r);
|
|
216
|
+
}, O = (e, r, d) => {
|
|
217
|
+
m(r), o.emit("node-expand", e, r, d);
|
|
218
218
|
}, I = (e, r) => {
|
|
219
|
-
t.
|
|
220
|
-
}, $ = (e, r, d) => {
|
|
221
|
-
N(r), o.emit("node-expand", e, r, d);
|
|
222
|
-
}, j = (e, r) => {
|
|
223
|
-
if (!n.nodeKey)
|
|
219
|
+
if (!t.nodeKey)
|
|
224
220
|
throw new Error("[Tree] nodeKey is required in updateKeyChild");
|
|
225
|
-
|
|
221
|
+
n.value.updateChildren(e, r);
|
|
226
222
|
};
|
|
227
223
|
return f("RootTree", {
|
|
228
224
|
ctx: o,
|
|
229
|
-
props:
|
|
230
|
-
store:
|
|
225
|
+
props: t,
|
|
226
|
+
store: n,
|
|
231
227
|
root: c,
|
|
232
228
|
currentNode: s,
|
|
233
|
-
instance:
|
|
234
|
-
}), f(
|
|
229
|
+
instance: _()
|
|
230
|
+
}), f(W, void 0), {
|
|
235
231
|
ns: C,
|
|
236
232
|
// ref
|
|
237
|
-
store:
|
|
233
|
+
store: n,
|
|
238
234
|
root: c,
|
|
239
235
|
currentNode: s,
|
|
240
|
-
dragState:
|
|
236
|
+
dragState: N,
|
|
241
237
|
el$: i,
|
|
242
238
|
dropIndicator$: y,
|
|
243
239
|
// computed
|
|
244
240
|
isEmpty: g,
|
|
245
241
|
// methods
|
|
246
|
-
filter:
|
|
247
|
-
|
|
248
|
-
getNodeKey: k,
|
|
242
|
+
filter: k,
|
|
243
|
+
getNodeKey: v,
|
|
249
244
|
getNodePath: E,
|
|
250
|
-
getCheckedNodes:
|
|
251
|
-
getCheckedKeys:
|
|
245
|
+
getCheckedNodes: w,
|
|
246
|
+
getCheckedKeys: p,
|
|
252
247
|
getCurrentNode: h,
|
|
253
248
|
getCurrentKey: x,
|
|
254
249
|
setCheckedNodes: B,
|
|
@@ -259,17 +254,15 @@ const Ce = _({
|
|
|
259
254
|
setCurrentNode: D,
|
|
260
255
|
setCurrentKey: q,
|
|
261
256
|
getNode: F,
|
|
262
|
-
remove:
|
|
263
|
-
append:
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
updateRootChildren: O,
|
|
269
|
-
updateKeyChildren: j
|
|
257
|
+
remove: H,
|
|
258
|
+
append: M,
|
|
259
|
+
insertBefore: P,
|
|
260
|
+
insertAfter: z,
|
|
261
|
+
handleNodeExpand: O,
|
|
262
|
+
updateKeyChildren: I
|
|
270
263
|
};
|
|
271
264
|
}
|
|
272
265
|
});
|
|
273
266
|
export {
|
|
274
|
-
|
|
267
|
+
he as default
|
|
275
268
|
};
|
package/es/package.json.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const a=require("@vft/utils"),N=require("./node.cjs"),C=require("./util.cjs");class y{constructor(e){this.currentNode=null,this.currentNodeKey=null;for(const t in e)a.hasOwn(e,t)&&(this[t]=e[t]);this.nodesMap={}}initialize(){if(this.root=new N.default({data:this.data,store:this}),this.root.initialize(),this.lazy&&this.load){const e=this.load;e(this.root,t=>{this.root.doCreateChildren(t),this._initDefaultCheckedNodes()})}else this._initDefaultCheckedNodes()}filter(e){const t=this.filterNodeMethod,s=this.lazy,
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const a=require("@vft/utils"),N=require("./node.cjs"),C=require("./util.cjs");class y{constructor(e){this.currentNode=null,this.currentNodeKey=null;for(const t in e)a.hasOwn(e,t)&&(this[t]=e[t]);this.nodesMap={}}initialize(){if(this.root=new N.default({data:this.data,store:this}),this.root.initialize(),this.lazy&&this.load){const e=this.load;e(this.root,t=>{this.root.doCreateChildren(t),this._initDefaultCheckedNodes()})}else this._initDefaultCheckedNodes()}filter(e){const t=this.filterNodeMethod,s=this.lazy,o=function(i){const d=i.root?i.root.childNodes:i.childNodes;if(d.forEach(r=>{r.visible=t.call(r,e,r.data,r),o(r)}),!i.visible&&d.length){let r=!0;r=!d.some(c=>c.visible),i.root?i.root.visible=r===!1:i.visible=r===!1}e&&i.visible&&!i.isLeaf&&!s&&i.expand()};o(this)}setData(e){e!==this.root.data?(this.root.setData(e),this._initDefaultCheckedNodes()):this.root.updateChildren()}getNode(e){if(e instanceof N.default)return e;const t=a.isObject(e)?C.getNodeKey(this.key,e):e;return this.nodesMap[t]||null}insertBefore(e,t){const s=this.getNode(t);s.parent.insertBefore({data:e},s)}insertAfter(e,t){const s=this.getNode(t);s.parent.insertAfter({data:e},s)}remove(e){const t=this.getNode(e);t&&t.parent&&(t===this.currentNode&&(this.currentNode=null),t.parent.removeChild(t))}append(e,t){const s=t?this.getNode(t):this.root;s&&s.insertChild({data:e})}_initDefaultCheckedNodes(){const e=this.defaultCheckedKeys||[],t=this.nodesMap;e.forEach(s=>{const o=t[s];o&&o.setChecked(!0,!this.checkStrictly)})}_initDefaultCheckedNode(e){(this.defaultCheckedKeys||[]).includes(e.key)&&e.setChecked(!0,!this.checkStrictly)}setDefaultCheckedKey(e){e!==this.defaultCheckedKeys&&(this.defaultCheckedKeys=e,this._initDefaultCheckedNodes())}registerNode(e){const t=this.key;!e||!e.data||(t?e.key!==void 0&&(this.nodesMap[e.key]=e):this.nodesMap[e.id]=e)}deregisterNode(e){!this.key||!e||!e.data||(e.childNodes.forEach(s=>{this.deregisterNode(s)}),delete this.nodesMap[e.key])}getCheckedNodes(e=!1,t=!1){const s=[],o=function(i){(i.root?i.root.childNodes:i.childNodes).forEach(r=>{(r.checked||t&&r.indeterminate)&&(!e||e&&r.isLeaf)&&s.push(r.data),o(r)})};return o(this),s}getCheckedKeys(e=!1){return this.getCheckedNodes(e).map(t=>(t||{})[this.key])}getHalfCheckedNodes(){const e=[],t=function(s){(s.root?s.root.childNodes:s.childNodes).forEach(i=>{i.indeterminate&&e.push(i.data),t(i)})};return t(this),e}getHalfCheckedKeys(){return this.getHalfCheckedNodes().map(e=>(e||{})[this.key])}_getAllNodes(){const e=[],t=this.nodesMap;for(const s in t)a.hasOwn(t,s)&&e.push(t[s]);return e}updateChildren(e,t){const s=this.nodesMap[e];if(!s)return;const o=s.childNodes;for(let i=o.length-1;i>=0;i--){const d=o[i];this.remove(d.data)}for(let i=0,d=t.length;i<d;i++){const r=t[i];this.append(r,s.data)}}_setCheckedKeys(e,t=!1,s){const o=this._getAllNodes().sort((r,c)=>c.level-r.level),i=Object.create(null),d=Object.keys(s);o.forEach(r=>r.setChecked(!1,!1));for(let r=0,c=o.length;r<c;r++){const n=o[r],f=n.data[e].toString();if(!d.includes(f)){n.checked&&!i[f]&&n.setChecked(!1,!1);continue}let h=n.parent;for(;h&&h.level>0;)i[h.data[e]]=!0,h=h.parent;if(n.isLeaf||this.checkStrictly){n.setChecked(!0,!1);continue}if(n.setChecked(!0,!0),t){n.setChecked(!1,!1);const u=function(k){k.childNodes.forEach(l=>{l.isLeaf||l.setChecked(!1,!1),u(l)})};u(n)}}}setCheckedNodes(e,t=!1){const s=this.key,o={};e.forEach(i=>{o[(i||{})[s]]=!0}),this._setCheckedKeys(s,t,o)}setCheckedKeys(e,t=!1){this.defaultCheckedKeys=e;const s=this.key,o={};e.forEach(i=>{o[i]=!0}),this._setCheckedKeys(s,t,o)}setDefaultExpandedKeys(e){e=e||[],this.defaultExpandedKeys=e,e.forEach(t=>{const s=this.getNode(t);s&&s.expand(null,this.autoExpandParent)})}setChecked(e,t,s){const o=this.getNode(e);o&&o.setChecked(!!t,s)}getCurrentNode(){return this.currentNode}setCurrentNode(e){const t=this.currentNode;t&&(t.isCurrent=!1),this.currentNode=e,this.currentNode.isCurrent=!0}setUserCurrentNode(e,t=!0){const s=e[this.key],o=this.nodesMap[s];this.setCurrentNode(o),t&&this.currentNode.level>1&&this.currentNode.parent.expand(null,!0)}setCurrentNodeKey(e,t=!0){if(e==null){this.currentNode&&(this.currentNode.isCurrent=!1),this.currentNode=null;return}const s=this.getNode(e);s&&(this.setCurrentNode(s),t&&this.currentNode.level>1&&this.currentNode.parent.expand(null,!0))}}exports.default=y;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const d=require("vue"),
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const d=require("vue"),z=require("../../hooks/use-namespace/index.cjs");require("@popperjs/core");require("lodash");require("../../hooks/use-z-index/index.cjs");require("@vueuse/core");require("@vft/utils");require("../../utils/ns-cover.cjs");require("../form/index.cjs");const _=require("./model/tree-store.cjs"),s=require("./model/util.cjs"),j=require("./tree-node.vue.cjs"),I=require("./model/useNodeExpandEventBroadcast.cjs"),$=require("./model/useDragNode.cjs"),R=require("./model/useKeydown.cjs"),U=require("../form/constants.cjs"),V=d.defineComponent({name:"VftTree",components:{TreeNode:j.default},props:{data:{type:Array,default:()=>[]},emptyText:{type:String},renderAfterExpand:{type:Boolean,default:!0},nodeKey:String,checkStrictly:Boolean,defaultExpandAll:Boolean,expandOnClickNode:{type:Boolean,default:!0},checkOnClickNode:Boolean,checkDescendants:{type:Boolean,default:!1},autoExpandParent:{type:Boolean,default:!0},defaultCheckedKeys:Array,defaultExpandedKeys:Array,currentNodeKey:[String,Number],renderContent:Function,showCheckbox:{type:Boolean,default:!1},draggable:{type:Boolean,default:!1},allowDrag:Function,allowDrop:Function,props:{type:Object,default:()=>({children:"children",label:"label",disabled:"disabled"})},lazy:{type:Boolean,default:!1},highlightCurrent:Boolean,load:Function,filterNodeMethod:Function,accordion:Boolean,indent:{type:Number,default:18},icon:{type:Object}},emits:["check-change","current-change","node-click","node-contextmenu","node-collapse","node-expand","check","node-drag-start","node-drag-end","node-drop","node-drag-leave","node-drag-enter","node-drag-over"],setup(t,a){const f=z.useNamespace("tree"),n=d.ref(new _.default({key:t.nodeKey,data:t.data,lazy:t.lazy,props:t.props,load:t.load,currentNodeKey:t.currentNodeKey,checkStrictly:t.checkStrictly,checkDescendants:t.checkDescendants,defaultCheckedKeys:t.defaultCheckedKeys,defaultExpandedKeys:t.defaultExpandedKeys,autoExpandParent:t.autoExpandParent,defaultExpandAll:t.defaultExpandAll,filterNodeMethod:t.filterNodeMethod}));n.value.initialize();const l=d.ref(n.value.root),i=d.ref(null),c=d.ref(null),y=d.ref(null),{broadcastExpanded:K}=I.useNodeExpandEventBroadcast(t),{dragState:C}=$.useDragNodeHandler({props:t,ctx:a,el$:c,dropIndicator$:y,store:n});R.useKeydown({el$:c},n);const N=d.computed(()=>{const{childNodes:e}=l.value;return!e||e.length===0||e.every(({visible:r})=>!r)});d.watch(()=>t.currentNodeKey,e=>{n.value.setCurrentNodeKey(e)}),d.watch(()=>t.defaultCheckedKeys,e=>{n.value.setDefaultCheckedKey(e)}),d.watch(()=>t.defaultExpandedKeys,e=>{n.value.setDefaultExpandedKeys(e)}),d.watch(()=>t.data,e=>{n.value.setData(e)},{deep:!0}),d.watch(()=>t.checkStrictly,e=>{n.value.checkStrictly=e});const g=e=>{if(!t.filterNodeMethod)throw new Error("[Tree] filterNodeMethod is required when filter");n.value.filter(e)},v=e=>s.getNodeKey(t.nodeKey,e.data),k=e=>{if(!t.nodeKey)throw new Error("[Tree] nodeKey is required in getNodePath");const r=n.value.getNode(e);if(!r)return[];const o=[r.data];let u=r.parent;for(;u&&u!==l.value;)o.push(u.data),u=u.parent;return o.reverse()},w=(e,r)=>n.value.getCheckedNodes(e,r),E=e=>n.value.getCheckedKeys(e),h=()=>{const e=n.value.getCurrentNode();return e?e.data:null},q=()=>{if(!t.nodeKey)throw new Error("[Tree] nodeKey is required in getCurrentKey");const e=h();return e?e[t.nodeKey]:null},m=(e,r)=>{if(!t.nodeKey)throw new Error("[Tree] nodeKey is required in setCheckedNodes");n.value.setCheckedNodes(e,r)},x=(e,r)=>{if(!t.nodeKey)throw new Error("[Tree] nodeKey is required in setCheckedKeys");n.value.setCheckedKeys(e,r)},B=(e,r,o)=>{n.value.setChecked(e,r,o)},b=()=>n.value.getHalfCheckedNodes(),T=()=>n.value.getHalfCheckedKeys(),S=(e,r=!0)=>{if(!t.nodeKey)throw new Error("[Tree] nodeKey is required in setCurrentNode");s.handleCurrentChange(n,a.emit,()=>n.value.setUserCurrentNode(e,r))},D=(e,r=!0)=>{if(!t.nodeKey)throw new Error("[Tree] nodeKey is required in setCurrentKey");s.handleCurrentChange(n,a.emit,()=>n.value.setCurrentNodeKey(e,r))},A=e=>n.value.getNode(e),M=e=>{n.value.remove(e)},p=(e,r)=>{n.value.append(e,r)},P=(e,r)=>{n.value.insertBefore(e,r)},F=(e,r)=>{n.value.insertAfter(e,r)},H=(e,r,o)=>{K(r),a.emit("node-expand",e,r,o)},O=(e,r)=>{if(!t.nodeKey)throw new Error("[Tree] nodeKey is required in updateKeyChild");n.value.updateChildren(e,r)};return d.provide("RootTree",{ctx:a,props:t,store:n,root:l,currentNode:i,instance:d.getCurrentInstance()}),d.provide(U.formItemContextKey,void 0),{ns:f,store:n,root:l,currentNode:i,dragState:C,el$:c,dropIndicator$:y,isEmpty:N,filter:g,getNodeKey:v,getNodePath:k,getCheckedNodes:w,getCheckedKeys:E,getCurrentNode:h,getCurrentKey:q,setCheckedNodes:m,setCheckedKeys:x,setChecked:B,getHalfCheckedNodes:b,getHalfCheckedKeys:T,setCurrentNode:S,setCurrentKey:D,getNode:A,remove:M,append:p,insertBefore:P,insertAfter:F,handleNodeExpand:H,updateKeyChildren:O}}});exports.default=V;
|
package/lib/package.json.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e="0.0.
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e="0.0.107";exports.version=e;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vft",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.107",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "lib/index.cjs",
|
|
6
6
|
"module": "es/index.js",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"@vft/router": "0.0.25",
|
|
58
58
|
"@vft/store": "0.0.25",
|
|
59
59
|
"@vft/use": "0.0.28",
|
|
60
|
-
"@vft/utils": "0.0.
|
|
60
|
+
"@vft/utils": "0.0.40",
|
|
61
61
|
"@vft/directives": "0.0.21"
|
|
62
62
|
},
|
|
63
63
|
"vetur": {
|