@splicetree/core 0.3.0 → 1.1.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/dist/index.d.ts +1 -0
- package/dist/index.js +15 -3
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -92,7 +92,7 @@ function buildTree(data, keyField, parentField, expandedKeys = /* @__PURE__ */ n
|
|
|
92
92
|
|
|
93
93
|
//#endregion
|
|
94
94
|
//#region src/utils/expand.ts
|
|
95
|
-
function initDefaultExpansion(map, expanded, def, lvl) {
|
|
95
|
+
function initDefaultExpansion(map, expanded, def, lvl, autoExpandParent) {
|
|
96
96
|
const expandAll = () => {
|
|
97
97
|
for (const id of map.keys()) expanded.add(id);
|
|
98
98
|
};
|
|
@@ -104,7 +104,18 @@ function initDefaultExpansion(map, expanded, def, lvl) {
|
|
|
104
104
|
return;
|
|
105
105
|
}
|
|
106
106
|
if (Array.isArray(def)) {
|
|
107
|
-
for (const id of def)
|
|
107
|
+
for (const id of def) {
|
|
108
|
+
expanded.add(id);
|
|
109
|
+
if (autoExpandParent) {
|
|
110
|
+
let cur = map.get(id);
|
|
111
|
+
while (cur) {
|
|
112
|
+
const p = cur.getParent();
|
|
113
|
+
if (!p) break;
|
|
114
|
+
expanded.add(p.id);
|
|
115
|
+
cur = p;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
108
119
|
if (lvl === "deepest") {
|
|
109
120
|
expandAll();
|
|
110
121
|
return;
|
|
@@ -332,6 +343,7 @@ function createSpliceTree(data, options = {}) {
|
|
|
332
343
|
const parentField = cfg.parentField ?? "parent";
|
|
333
344
|
const defaultExpanded = cfg.defaultExpanded;
|
|
334
345
|
const defaultExpandedLevel = cfg.defaultExpandedLevel;
|
|
346
|
+
const autoExpandParent = cfg.autoExpandParent;
|
|
335
347
|
const events = createEmitter();
|
|
336
348
|
const expandedKeys = createReactive(/* @__PURE__ */ new Set(), (payload) => {
|
|
337
349
|
events.emit({
|
|
@@ -340,7 +352,7 @@ function createSpliceTree(data, options = {}) {
|
|
|
340
352
|
});
|
|
341
353
|
});
|
|
342
354
|
let { roots, map, parentCache, childrenCache } = buildTree(data, keyField, parentField, expandedKeys);
|
|
343
|
-
initDefaultExpansion(map, expandedKeys, defaultExpanded, defaultExpandedLevel);
|
|
355
|
+
initDefaultExpansion(map, expandedKeys, defaultExpanded, defaultExpandedLevel, autoExpandParent);
|
|
344
356
|
const emitVisibility = () => {
|
|
345
357
|
events.emit({
|
|
346
358
|
name: "visibility",
|