@splicetree/adapter-vue 0.2.0 → 1.0.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.
Files changed (2) hide show
  1. package/dist/index.js +19 -7
  2. package/package.json +5 -6
package/dist/index.js CHANGED
@@ -88,7 +88,7 @@ function buildTree(data, keyField, parentField, expandedKeys = /* @__PURE__ */ n
88
88
  childrenCache
89
89
  };
90
90
  }
91
- function initDefaultExpansion(map, expanded, def, lvl) {
91
+ function initDefaultExpansion(map, expanded, def, lvl, autoExpandParent) {
92
92
  const expandAll = () => {
93
93
  for (const id of map.keys()) expanded.add(id);
94
94
  };
@@ -100,7 +100,18 @@ function initDefaultExpansion(map, expanded, def, lvl) {
100
100
  return;
101
101
  }
102
102
  if (Array.isArray(def)) {
103
- for (const id of def) expanded.add(id);
103
+ for (const id of def) {
104
+ expanded.add(id);
105
+ if (autoExpandParent) {
106
+ let cur = map.get(id);
107
+ while (cur) {
108
+ const p = cur.getParent();
109
+ if (!p) break;
110
+ expanded.add(p.id);
111
+ cur = p;
112
+ }
113
+ }
114
+ }
104
115
  if (lvl === "deepest") {
105
116
  expandAll();
106
117
  return;
@@ -315,10 +326,11 @@ function moveNode(ctx, id, newParentId, beforeId) {
315
326
  */
316
327
  function createSpliceTree(data, options = {}) {
317
328
  const cfg = options.configuration ?? {};
318
- const keyField = cfg.keyField ?? options.keyField ?? "id";
319
- const parentField = cfg.parentField ?? options.parentField ?? "parent";
320
- const defaultExpanded = cfg.defaultExpanded ?? options.defaultExpanded;
321
- const defaultExpandedLevel = cfg.defaultExpandedLevel ?? options.defaultExpandedLevel;
329
+ const keyField = cfg.keyField ?? "id";
330
+ const parentField = cfg.parentField ?? "parent";
331
+ const defaultExpanded = cfg.defaultExpanded;
332
+ const defaultExpandedLevel = cfg.defaultExpandedLevel;
333
+ const autoExpandParent = cfg.autoExpandParent;
322
334
  const events = createEmitter();
323
335
  const expandedKeys = createReactive(/* @__PURE__ */ new Set(), (payload) => {
324
336
  events.emit({
@@ -327,7 +339,7 @@ function createSpliceTree(data, options = {}) {
327
339
  });
328
340
  });
329
341
  let { roots, map, parentCache, childrenCache } = buildTree(data, keyField, parentField, expandedKeys);
330
- initDefaultExpansion(map, expandedKeys, defaultExpanded, defaultExpandedLevel);
342
+ initDefaultExpansion(map, expandedKeys, defaultExpanded, defaultExpandedLevel, autoExpandParent);
331
343
  const emitVisibility = () => {
332
344
  events.emit({
333
345
  name: "visibility",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@splicetree/adapter-vue",
3
3
  "type": "module",
4
- "version": "0.2.0",
4
+ "version": "1.0.0",
5
5
  "author": {
6
6
  "email": "michael.cocova@gmail.com",
7
7
  "name": "Michael Cocova"
@@ -25,13 +25,12 @@
25
25
  "peerDependencies": {
26
26
  "vue": "^3.0.0"
27
27
  },
28
- "dependencies": {
29
- "unplugin-vue": "^7.1.0",
30
- "vue-tsc": "^3.1.5"
31
- },
28
+ "dependencies": {},
32
29
  "devDependencies": {
30
+ "unplugin-vue": "^7.1.0",
33
31
  "vue": "^3.0.0",
34
- "@splicetree/core": "0.2.0"
32
+ "vue-tsc": "^3.1.5",
33
+ "@splicetree/core": "1.0.0"
35
34
  },
36
35
  "publishConfig": {
37
36
  "access": "public"