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.
@@ -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 p } from "./util.js";
4
- class E {
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, i = function(o) {
25
- const h = o.root ? o.root.childNodes : o.childNodes;
26
- if (h.forEach((r) => {
27
- r.visible = t.call(r, e, r.data, r), i(r);
28
- }), !o.visible && h.length) {
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 = !h.some((n) => n.visible), o.root ? o.root.visible = r === !1 : o.visible = r === !1;
30
+ r = !d.some((h) => h.visible), i.root ? i.root.visible = r === !1 : i.visible = r === !1;
31
31
  }
32
- e && o.visible && !o.isLeaf && !s && o.expand();
32
+ e && i.visible && !i.isLeaf && !s && i.expand();
33
33
  };
34
- i(this);
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) ? p(this.key, e) : 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 i = t[s];
65
- i && i.setChecked(!0, !this.checkStrictly);
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 = [], i = function(o) {
85
- (o.root ? o.root.childNodes : o.childNodes).forEach((r) => {
86
- (r.checked || t && r.indeterminate) && (!e || e && r.isLeaf) && s.push(r.data), i(r);
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 i(this), s;
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((o) => {
97
- o.indeterminate && e.push(o.data), t(o);
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
- _updateChildren(e, t) {
112
- const s = e.childNodes;
113
- for (let i = s.length - 1; i >= 0; i--) {
114
- const o = s[i];
115
- this.remove(o.data);
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, o = t.length; i < o; i++) {
118
- const h = t[i];
119
- this.append(h, e);
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 i = this._getAllNodes().sort((r, n) => n.level - r.level), o = /* @__PURE__ */ Object.create(null), h = Object.keys(s);
135
- i.forEach((r) => r.setChecked(!1, !1));
136
- for (let r = 0, n = i.length; r < n; r++) {
137
- const d = i[r], a = d.data[e].toString();
138
- if (!h.includes(a)) {
139
- d.checked && !o[a] && d.setChecked(!1, !1);
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 = d.parent;
134
+ let c = n.parent;
143
135
  for (; c && c.level > 0; )
144
- o[c.data[e]] = !0, c = c.parent;
145
- if (d.isLeaf || this.checkStrictly) {
146
- d.setChecked(!0, !1);
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 (d.setChecked(!0, !0), t) {
150
- d.setChecked(!1, !1);
141
+ if (n.setChecked(!0, !0), t) {
142
+ n.setChecked(!1, !1);
151
143
  const f = function(k) {
152
- k.childNodes.forEach((l) => {
153
- l.isLeaf || l.setChecked(!1, !1), f(l);
144
+ k.childNodes.forEach((a) => {
145
+ a.isLeaf || a.setChecked(!1, !1), f(a);
154
146
  });
155
147
  };
156
- f(d);
148
+ f(n);
157
149
  }
158
150
  }
159
151
  }
160
152
  setCheckedNodes(e, t = !1) {
161
- const s = this.key, i = {};
162
- e.forEach((o) => {
163
- i[(o || {})[s]] = !0;
164
- }), this._setCheckedKeys(s, t, i);
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, i = {};
169
- e.forEach((o) => {
170
- i[o] = !0;
171
- }), this._setCheckedKeys(s, t, i);
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 i = this.getNode(e);
181
- i && i.setChecked(!!t, s);
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], i = this.nodesMap[s];
192
- this.setCurrentNode(i), t && this.currentNode.level > 1 && this.currentNode.parent.expand(null, !0);
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
- E as default
196
+ M as default
208
197
  };
@@ -1,5 +1,5 @@
1
- import { defineComponent as _, ref as l, computed as U, watch as u, provide as f, getCurrentInstance as V } from "vue";
2
- import { useNamespace as G } from "../../hooks/use-namespace/index.js";
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 J from "./model/tree-store.js";
11
- import { getNodeKey as L, handleCurrentChange as K } from "./model/util.js";
12
- import Q from "./tree-node.vue.js";
13
- import { useNodeExpandEventBroadcast as W } from "./model/useNodeExpandEventBroadcast.js";
14
- import { useDragNodeHandler as X } from "./model/useDragNode.js";
15
- import { useKeydown as Y } from "./model/useKeydown.js";
16
- import { formItemContextKey as Z } from "../form/constants.js";
17
- const Ce = _({
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: Q },
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(n, o) {
102
- const C = G("tree"), t = l(
103
- new J({
104
- key: n.nodeKey,
105
- data: n.data,
106
- lazy: n.lazy,
107
- props: n.props,
108
- load: n.load,
109
- currentNodeKey: n.currentNodeKey,
110
- checkStrictly: n.checkStrictly,
111
- checkDescendants: n.checkDescendants,
112
- defaultCheckedKeys: n.defaultCheckedKeys,
113
- defaultExpandedKeys: n.defaultExpandedKeys,
114
- autoExpandParent: n.autoExpandParent,
115
- defaultExpandAll: n.defaultExpandAll,
116
- filterNodeMethod: n.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
- t.value.initialize();
120
- const c = l(t.value.root), s = l(null), i = l(null), y = l(null), { broadcastExpanded: N } = W(n), { dragState: m } = X({
121
- props: n,
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: t
125
+ store: n
126
126
  });
127
- Y({ el$: i }, t);
128
- const g = U(() => {
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
- () => n.currentNodeKey,
133
+ () => t.currentNodeKey,
134
134
  (e) => {
135
- t.value.setCurrentNodeKey(e);
135
+ n.value.setCurrentNodeKey(e);
136
136
  }
137
137
  ), u(
138
- () => n.defaultCheckedKeys,
138
+ () => t.defaultCheckedKeys,
139
139
  (e) => {
140
- t.value.setDefaultCheckedKey(e);
140
+ n.value.setDefaultCheckedKey(e);
141
141
  }
142
142
  ), u(
143
- () => n.defaultExpandedKeys,
143
+ () => t.defaultExpandedKeys,
144
144
  (e) => {
145
- t.value.setDefaultExpandedKeys(e);
145
+ n.value.setDefaultExpandedKeys(e);
146
146
  }
147
147
  ), u(
148
- () => n.data,
148
+ () => t.data,
149
149
  (e) => {
150
- t.value.setData(e);
150
+ n.value.setData(e);
151
151
  },
152
152
  { deep: !0 }
153
153
  ), u(
154
- () => n.checkStrictly,
154
+ () => t.checkStrictly,
155
155
  (e) => {
156
- t.value.checkStrictly = e;
156
+ n.value.checkStrictly = e;
157
157
  }
158
158
  );
159
- const v = (e) => {
160
- if (!n.filterNodeMethod)
159
+ const k = (e) => {
160
+ if (!t.filterNodeMethod)
161
161
  throw new Error("[Tree] filterNodeMethod is required when filter");
162
- t.value.filter(e);
163
- }, k = (e) => L(n.nodeKey, e.data), E = (e) => {
164
- if (!n.nodeKey)
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 = t.value.getNode(e);
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
- }, p = (e, r) => t.value.getCheckedNodes(e, r), w = (e) => t.value.getCheckedKeys(e), h = () => {
175
- const e = t.value.getCurrentNode();
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 (!n.nodeKey)
178
+ if (!t.nodeKey)
179
179
  throw new Error("[Tree] nodeKey is required in getCurrentKey");
180
180
  const e = h();
181
- return e ? e[n.nodeKey] : null;
181
+ return e ? e[t.nodeKey] : null;
182
182
  }, B = (e, r) => {
183
- if (!n.nodeKey)
183
+ if (!t.nodeKey)
184
184
  throw new Error("[Tree] nodeKey is required in setCheckedNodes");
185
- t.value.setCheckedNodes(e, r);
185
+ n.value.setCheckedNodes(e, r);
186
186
  }, T = (e, r) => {
187
- if (!n.nodeKey)
187
+ if (!t.nodeKey)
188
188
  throw new Error("[Tree] nodeKey is required in setCheckedKeys");
189
- t.value.setCheckedKeys(e, r);
189
+ n.value.setCheckedKeys(e, r);
190
190
  }, b = (e, r, d) => {
191
- t.value.setChecked(e, r, d);
192
- }, S = () => t.value.getHalfCheckedNodes(), A = () => t.value.getHalfCheckedKeys(), D = (e, r = !0) => {
193
- if (!n.nodeKey)
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
- t,
196
+ n,
197
197
  o.emit,
198
- () => t.value.setUserCurrentNode(e, r)
198
+ () => n.value.setUserCurrentNode(e, r)
199
199
  );
200
200
  }, q = (e, r = !0) => {
201
- if (!n.nodeKey)
201
+ if (!t.nodeKey)
202
202
  throw new Error("[Tree] nodeKey is required in setCurrentKey");
203
203
  K(
204
- t,
204
+ n,
205
205
  o.emit,
206
- () => t.value.setCurrentNodeKey(e, r)
206
+ () => n.value.setCurrentNodeKey(e, r)
207
207
  );
208
- }, F = (e) => t.value.getNode(e), H = () => t.value.getRoot(), M = (e) => {
209
- t.value.remove(e);
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
- t.value.append(e, r);
212
- }, R = (e, r) => {
213
- t.value.updateNodeChildren(e, r);
213
+ n.value.insertBefore(e, r);
214
214
  }, z = (e, r) => {
215
- t.value.insertBefore(e, r);
216
- }, O = (e) => {
217
- t.value.updateRootChildren(e);
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.value.insertAfter(e, r);
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
- t.value.updateKeyChildren(e, r);
221
+ n.value.updateChildren(e, r);
226
222
  };
227
223
  return f("RootTree", {
228
224
  ctx: o,
229
- props: n,
230
- store: t,
225
+ props: t,
226
+ store: n,
231
227
  root: c,
232
228
  currentNode: s,
233
- instance: V()
234
- }), f(Z, void 0), {
229
+ instance: _()
230
+ }), f(W, void 0), {
235
231
  ns: C,
236
232
  // ref
237
- store: t,
233
+ store: n,
238
234
  root: c,
239
235
  currentNode: s,
240
- dragState: m,
236
+ dragState: N,
241
237
  el$: i,
242
238
  dropIndicator$: y,
243
239
  // computed
244
240
  isEmpty: g,
245
241
  // methods
246
- filter: v,
247
- getRoot: H,
248
- getNodeKey: k,
242
+ filter: k,
243
+ getNodeKey: v,
249
244
  getNodePath: E,
250
- getCheckedNodes: p,
251
- getCheckedKeys: w,
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: M,
263
- append: P,
264
- update: R,
265
- insertBefore: z,
266
- insertAfter: I,
267
- handleNodeExpand: $,
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
- Ce as default
267
+ he as default
275
268
  };
@@ -1,4 +1,4 @@
1
- const o = "0.0.106";
1
+ const o = "0.0.107";
2
2
  export {
3
3
  o as version
4
4
  };
@@ -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,i=function(o){const n=o.root?o.root.childNodes:o.childNodes;if(n.forEach(r=>{r.visible=t.call(r,e,r.data,r),i(r)}),!o.visible&&n.length){let r=!0;r=!n.some(h=>h.visible),o.root?o.root.visible=r===!1:o.visible=r===!1}e&&o.visible&&!o.isLeaf&&!s&&o.expand()};i(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 i=t[s];i&&i.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=[],i=function(o){(o.root?o.root.childNodes:o.childNodes).forEach(r=>{(r.checked||t&&r.indeterminate)&&(!e||e&&r.isLeaf)&&s.push(r.data),i(r)})};return i(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(o=>{o.indeterminate&&e.push(o.data),t(o)})};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=e.childNodes;for(let i=s.length-1;i>=0;i--){const o=s[i];this.remove(o.data)}for(let i=0,o=t.length;i<o;i++){const n=t[i];this.append(n,e)}}updateRootChildren(e){this._updateChildren(this.root,e)}updateKeyChildren(e,t){const s=this.nodesMap[e];s&&this._updateChildren(s,t)}updateNodeChildren(e,t){const s=t?this.getNode(t):this.root;this._updateChildren(s,e)}_setCheckedKeys(e,t=!1,s){const i=this._getAllNodes().sort((r,h)=>h.level-r.level),o=Object.create(null),n=Object.keys(s);i.forEach(r=>r.setChecked(!1,!1));for(let r=0,h=i.length;r<h;r++){const d=i[r],u=d.data[e].toString();if(!n.includes(u)){d.checked&&!o[u]&&d.setChecked(!1,!1);continue}let c=d.parent;for(;c&&c.level>0;)o[c.data[e]]=!0,c=c.parent;if(d.isLeaf||this.checkStrictly){d.setChecked(!0,!1);continue}if(d.setChecked(!0,!0),t){d.setChecked(!1,!1);const f=function(k){k.childNodes.forEach(l=>{l.isLeaf||l.setChecked(!1,!1),f(l)})};f(d)}}}setCheckedNodes(e,t=!1){const s=this.key,i={};e.forEach(o=>{i[(o||{})[s]]=!0}),this._setCheckedKeys(s,t,i)}setCheckedKeys(e,t=!1){this.defaultCheckedKeys=e;const s=this.key,i={};e.forEach(o=>{i[o]=!0}),this._setCheckedKeys(s,t,i)}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 i=this.getNode(e);i&&i.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],i=this.nodesMap[s];this.setCurrentNode(i),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))}getRoot(){return this.root}}exports.default=y;
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"),j=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 I=require("./model/tree-store.cjs"),s=require("./model/util.cjs"),$=require("./tree-node.vue.cjs"),U=require("./model/useNodeExpandEventBroadcast.cjs"),V=require("./model/useDragNode.cjs"),G=require("./model/useKeydown.cjs"),J=require("../form/constants.cjs"),L=d.defineComponent({name:"VftTree",components:{TreeNode:$.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(n,a){const f=j.useNamespace("tree"),t=d.ref(new I.default({key:n.nodeKey,data:n.data,lazy:n.lazy,props:n.props,load:n.load,currentNodeKey:n.currentNodeKey,checkStrictly:n.checkStrictly,checkDescendants:n.checkDescendants,defaultCheckedKeys:n.defaultCheckedKeys,defaultExpandedKeys:n.defaultExpandedKeys,autoExpandParent:n.autoExpandParent,defaultExpandAll:n.defaultExpandAll,filterNodeMethod:n.filterNodeMethod}));t.value.initialize();const l=d.ref(t.value.root),i=d.ref(null),c=d.ref(null),y=d.ref(null),{broadcastExpanded:K}=U.useNodeExpandEventBroadcast(n),{dragState:C}=V.useDragNodeHandler({props:n,ctx:a,el$:c,dropIndicator$:y,store:t});G.useKeydown({el$:c},t);const N=d.computed(()=>{const{childNodes:e}=l.value;return!e||e.length===0||e.every(({visible:r})=>!r)});d.watch(()=>n.currentNodeKey,e=>{t.value.setCurrentNodeKey(e)}),d.watch(()=>n.defaultCheckedKeys,e=>{t.value.setDefaultCheckedKey(e)}),d.watch(()=>n.defaultExpandedKeys,e=>{t.value.setDefaultExpandedKeys(e)}),d.watch(()=>n.data,e=>{t.value.setData(e)},{deep:!0}),d.watch(()=>n.checkStrictly,e=>{t.value.checkStrictly=e});const g=e=>{if(!n.filterNodeMethod)throw new Error("[Tree] filterNodeMethod is required when filter");t.value.filter(e)},v=e=>s.getNodeKey(n.nodeKey,e.data),k=e=>{if(!n.nodeKey)throw new Error("[Tree] nodeKey is required in getNodePath");const r=t.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)=>t.value.getCheckedNodes(e,r),E=e=>t.value.getCheckedKeys(e),h=()=>{const e=t.value.getCurrentNode();return e?e.data:null},q=()=>{if(!n.nodeKey)throw new Error("[Tree] nodeKey is required in getCurrentKey");const e=h();return e?e[n.nodeKey]:null},m=(e,r)=>{if(!n.nodeKey)throw new Error("[Tree] nodeKey is required in setCheckedNodes");t.value.setCheckedNodes(e,r)},x=(e,r)=>{if(!n.nodeKey)throw new Error("[Tree] nodeKey is required in setCheckedKeys");t.value.setCheckedKeys(e,r)},B=(e,r,o)=>{t.value.setChecked(e,r,o)},b=()=>t.value.getHalfCheckedNodes(),T=()=>t.value.getHalfCheckedKeys(),S=(e,r=!0)=>{if(!n.nodeKey)throw new Error("[Tree] nodeKey is required in setCurrentNode");s.handleCurrentChange(t,a.emit,()=>t.value.setUserCurrentNode(e,r))},p=(e,r=!0)=>{if(!n.nodeKey)throw new Error("[Tree] nodeKey is required in setCurrentKey");s.handleCurrentChange(t,a.emit,()=>t.value.setCurrentNodeKey(e,r))},D=e=>t.value.getNode(e),A=()=>t.value.getRoot(),M=e=>{t.value.remove(e)},P=(e,r)=>{t.value.append(e,r)},F=(e,r)=>{t.value.updateNodeChildren(e,r)},H=(e,r)=>{t.value.insertBefore(e,r)},O=e=>{t.value.updateRootChildren(e)},R=(e,r)=>{t.value.insertAfter(e,r)},z=(e,r,o)=>{K(r),a.emit("node-expand",e,r,o)},_=(e,r)=>{if(!n.nodeKey)throw new Error("[Tree] nodeKey is required in updateKeyChild");t.value.updateKeyChildren(e,r)};return d.provide("RootTree",{ctx:a,props:n,store:t,root:l,currentNode:i,instance:d.getCurrentInstance()}),d.provide(J.formItemContextKey,void 0),{ns:f,store:t,root:l,currentNode:i,dragState:C,el$:c,dropIndicator$:y,isEmpty:N,filter:g,getRoot:A,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:p,getNode:D,remove:M,append:P,update:F,insertBefore:H,insertAfter:R,handleNodeExpand:z,updateRootChildren:O,updateKeyChildren:_}}});exports.default=L;
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;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e="0.0.106";exports.version=e;
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.106",
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.39",
60
+ "@vft/utils": "0.0.40",
61
61
  "@vft/directives": "0.0.21"
62
62
  },
63
63
  "vetur": {