@skygraph/core 0.0.0-placeholder.0 → 0.4.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/LICENSE +21 -0
- package/dist/calendar.cjs +404 -0
- package/dist/calendar.cjs.map +1 -0
- package/dist/calendar.d.cts +209 -0
- package/dist/calendar.d.ts +209 -0
- package/dist/calendar.js +12 -0
- package/dist/calendar.js.map +1 -0
- package/dist/chunk-5CCD5Q4B.js +36 -0
- package/dist/chunk-5CCD5Q4B.js.map +1 -0
- package/dist/chunk-AB3RLBLW.js +357 -0
- package/dist/chunk-AB3RLBLW.js.map +1 -0
- package/dist/chunk-GEMALROQ.js +258 -0
- package/dist/chunk-GEMALROQ.js.map +1 -0
- package/dist/chunk-IY6LJU3L.js +256 -0
- package/dist/chunk-IY6LJU3L.js.map +1 -0
- package/dist/chunk-KMGRNPLG.js +453 -0
- package/dist/chunk-KMGRNPLG.js.map +1 -0
- package/dist/chunk-KP75DEA4.js +1012 -0
- package/dist/chunk-KP75DEA4.js.map +1 -0
- package/dist/chunk-Y7FTBBYX.js +397 -0
- package/dist/chunk-Y7FTBBYX.js.map +1 -0
- package/dist/chunk-ZWB7JGAJ.js +488 -0
- package/dist/chunk-ZWB7JGAJ.js.map +1 -0
- package/dist/form.cjs +498 -0
- package/dist/form.cjs.map +1 -0
- package/dist/form.d.cts +130 -0
- package/dist/form.d.ts +130 -0
- package/dist/form.js +8 -0
- package/dist/form.js.map +1 -0
- package/dist/graph.cjs +1065 -0
- package/dist/graph.cjs.map +1 -0
- package/dist/graph.d.cts +542 -0
- package/dist/graph.d.ts +542 -0
- package/dist/graph.js +24 -0
- package/dist/graph.js.map +1 -0
- package/dist/index.cjs +3656 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +144 -0
- package/dist/index.d.ts +144 -0
- package/dist/index.js +467 -0
- package/dist/index.js.map +1 -0
- package/dist/runtime-internal.cjs +339 -0
- package/dist/runtime-internal.cjs.map +1 -0
- package/dist/runtime-internal.d.cts +130 -0
- package/dist/runtime-internal.d.ts +130 -0
- package/dist/runtime-internal.js +67 -0
- package/dist/runtime-internal.js.map +1 -0
- package/dist/table.cjs +537 -0
- package/dist/table.cjs.map +1 -0
- package/dist/table.d.cts +215 -0
- package/dist/table.d.ts +215 -0
- package/dist/table.js +16 -0
- package/dist/table.js.map +1 -0
- package/dist/tree.cjs +442 -0
- package/dist/tree.cjs.map +1 -0
- package/dist/tree.d.cts +76 -0
- package/dist/tree.d.ts +76 -0
- package/dist/tree.js +8 -0
- package/dist/tree.js.map +1 -0
- package/dist/types-B-rKQJ4R.d.cts +35 -0
- package/dist/types-B-rKQJ4R.d.ts +35 -0
- package/dist/virtual.cjs +283 -0
- package/dist/virtual.cjs.map +1 -0
- package/dist/virtual.d.cts +96 -0
- package/dist/virtual.d.ts +96 -0
- package/dist/virtual.js +9 -0
- package/dist/virtual.js.map +1 -0
- package/package.json +98 -18
- package/README.md +0 -12
- package/index.js +0 -3
package/dist/tree.cjs
ADDED
|
@@ -0,0 +1,442 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/engines/tree/index.ts
|
|
21
|
+
var tree_exports = {};
|
|
22
|
+
__export(tree_exports, {
|
|
23
|
+
createTree: () => createTree
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(tree_exports);
|
|
26
|
+
|
|
27
|
+
// src/engines/namespaces.ts
|
|
28
|
+
var reserved = /* @__PURE__ */ new Map();
|
|
29
|
+
function reservePrefix(engine, prefix) {
|
|
30
|
+
if (!prefix.startsWith("$") || !prefix.endsWith(".")) {
|
|
31
|
+
throw new Error(
|
|
32
|
+
`[skygraph] engine "${engine}" tried to reserve invalid prefix "${prefix}". Engine prefixes must start with "$" and end with ".".`
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
const existing = reserved.get(prefix);
|
|
36
|
+
if (existing !== void 0 && existing !== engine) {
|
|
37
|
+
throw new Error(
|
|
38
|
+
`[skygraph] prefix "${prefix}" is already owned by engine "${existing}", cannot reserve it for "${engine}". Pick a different prefix or update the registry.`
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
reserved.set(prefix, engine);
|
|
42
|
+
return prefix;
|
|
43
|
+
}
|
|
44
|
+
var FORM_META_PREFIX = reservePrefix("form", "$meta.");
|
|
45
|
+
var TABLE_PREFIX = reservePrefix("table", "$table.");
|
|
46
|
+
var TREE_PREFIX = reservePrefix("tree", "$tree.");
|
|
47
|
+
var GRAPH_PREFIX = reservePrefix("graph", "$graph.");
|
|
48
|
+
var CALENDAR_PREFIX = reservePrefix("calendar", "$calendar.");
|
|
49
|
+
|
|
50
|
+
// src/engines/tree/TreeEngine.ts
|
|
51
|
+
var treeCounter = 0;
|
|
52
|
+
function createTree(core, options) {
|
|
53
|
+
const treeId = `tr${treeCounter++}`;
|
|
54
|
+
const fn = {
|
|
55
|
+
key: options?.fieldNames?.key ?? "key",
|
|
56
|
+
title: options?.fieldNames?.title ?? "title",
|
|
57
|
+
children: options?.fieldNames?.children ?? "children"
|
|
58
|
+
};
|
|
59
|
+
const checkStrictly = options?.checkStrictly ?? false;
|
|
60
|
+
let nodes = [];
|
|
61
|
+
let nodeMap = /* @__PURE__ */ new Map();
|
|
62
|
+
let expandedKeys = new Set(options?.defaultExpandedKeys ?? []);
|
|
63
|
+
let checkedKeys = new Set(options?.defaultCheckedKeys ?? []);
|
|
64
|
+
let halfCheckedKeys = /* @__PURE__ */ new Set();
|
|
65
|
+
let selectedKeys = new Set(options?.defaultSelectedKeys ?? []);
|
|
66
|
+
let loadedKeys = /* @__PURE__ */ new Set();
|
|
67
|
+
let loadingKeys = /* @__PURE__ */ new Set();
|
|
68
|
+
let filteredKeys = null;
|
|
69
|
+
function getKey(node) {
|
|
70
|
+
return node[fn.key];
|
|
71
|
+
}
|
|
72
|
+
function getChildren(node) {
|
|
73
|
+
return node[fn.children];
|
|
74
|
+
}
|
|
75
|
+
function buildMap(data) {
|
|
76
|
+
nodeMap = /* @__PURE__ */ new Map();
|
|
77
|
+
function walk(list, parentKey, depth) {
|
|
78
|
+
for (const n of list) {
|
|
79
|
+
const k = getKey(n);
|
|
80
|
+
const children = getChildren(n);
|
|
81
|
+
const childKeys = [];
|
|
82
|
+
const isLeaf = n.isLeaf === true || (!children || children.length === 0);
|
|
83
|
+
if (children && children.length > 0) {
|
|
84
|
+
for (const ch of children) childKeys.push(getKey(ch));
|
|
85
|
+
}
|
|
86
|
+
nodeMap.set(k, { node: n, key: k, depth, parentKey, childKeys, isLeaf });
|
|
87
|
+
if (children && children.length > 0) {
|
|
88
|
+
walk(children, k, depth + 1);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
walk(data, null, 0);
|
|
93
|
+
}
|
|
94
|
+
function getAllDescendantKeys(key) {
|
|
95
|
+
const result = [];
|
|
96
|
+
const internal = nodeMap.get(key);
|
|
97
|
+
if (!internal) return result;
|
|
98
|
+
for (const ck of internal.childKeys) {
|
|
99
|
+
result.push(ck);
|
|
100
|
+
result.push(...getAllDescendantKeys(ck));
|
|
101
|
+
}
|
|
102
|
+
return result;
|
|
103
|
+
}
|
|
104
|
+
function getAllAncestorKeys(key) {
|
|
105
|
+
const result = [];
|
|
106
|
+
let current = nodeMap.get(key);
|
|
107
|
+
while (current && current.parentKey !== null) {
|
|
108
|
+
result.push(current.parentKey);
|
|
109
|
+
current = nodeMap.get(current.parentKey);
|
|
110
|
+
}
|
|
111
|
+
return result;
|
|
112
|
+
}
|
|
113
|
+
function recomputeHalfChecked() {
|
|
114
|
+
if (checkStrictly) {
|
|
115
|
+
halfCheckedKeys = /* @__PURE__ */ new Set();
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
const half = /* @__PURE__ */ new Set();
|
|
119
|
+
for (const [key, internal] of nodeMap) {
|
|
120
|
+
if (internal.childKeys.length === 0) continue;
|
|
121
|
+
if (checkedKeys.has(key)) continue;
|
|
122
|
+
const allDescendants = getAllDescendantKeys(key);
|
|
123
|
+
const someChecked = allDescendants.some((dk) => checkedKeys.has(dk));
|
|
124
|
+
if (someChecked) half.add(key);
|
|
125
|
+
}
|
|
126
|
+
halfCheckedKeys = half;
|
|
127
|
+
}
|
|
128
|
+
function cascadeCheck(key, checked) {
|
|
129
|
+
if (checkStrictly) {
|
|
130
|
+
if (checked) checkedKeys.add(key);
|
|
131
|
+
else checkedKeys.delete(key);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
const internal = nodeMap.get(key);
|
|
135
|
+
if (!internal) return;
|
|
136
|
+
if (checked) {
|
|
137
|
+
checkedKeys.add(key);
|
|
138
|
+
const descendants = getAllDescendantKeys(key);
|
|
139
|
+
for (const dk of descendants) {
|
|
140
|
+
const dn = nodeMap.get(dk);
|
|
141
|
+
if (dn && !dn.node.disabled && !dn.node.disableCheckbox) {
|
|
142
|
+
checkedKeys.add(dk);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
} else {
|
|
146
|
+
checkedKeys.delete(key);
|
|
147
|
+
const descendants = getAllDescendantKeys(key);
|
|
148
|
+
for (const dk of descendants) {
|
|
149
|
+
checkedKeys.delete(dk);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
const ancestors = getAllAncestorKeys(key);
|
|
153
|
+
for (const ak of ancestors) {
|
|
154
|
+
const an = nodeMap.get(ak);
|
|
155
|
+
if (!an) continue;
|
|
156
|
+
const allChildren = getAllDescendantKeys(ak);
|
|
157
|
+
const enabledChildren = allChildren.filter((ck) => {
|
|
158
|
+
const cn = nodeMap.get(ck);
|
|
159
|
+
return cn && !cn.node.disabled && !cn.node.disableCheckbox;
|
|
160
|
+
});
|
|
161
|
+
const allChecked = enabledChildren.length > 0 && enabledChildren.every((ck) => checkedKeys.has(ck));
|
|
162
|
+
if (allChecked) {
|
|
163
|
+
checkedKeys.add(ak);
|
|
164
|
+
} else {
|
|
165
|
+
checkedKeys.delete(ak);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
recomputeHalfChecked();
|
|
169
|
+
}
|
|
170
|
+
function removeFromTree(data, targetKey) {
|
|
171
|
+
let removed = null;
|
|
172
|
+
const remaining = data.filter((n) => {
|
|
173
|
+
if (getKey(n) === targetKey) {
|
|
174
|
+
removed = n;
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
return true;
|
|
178
|
+
});
|
|
179
|
+
if (!removed) {
|
|
180
|
+
for (const n of remaining) {
|
|
181
|
+
const children = getChildren(n);
|
|
182
|
+
if (children && children.length > 0) {
|
|
183
|
+
const result = removeFromTree(children, targetKey);
|
|
184
|
+
if (result.removed) {
|
|
185
|
+
;
|
|
186
|
+
n[fn.children] = result.remaining;
|
|
187
|
+
return { remaining, removed: result.removed };
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return { remaining, removed };
|
|
193
|
+
}
|
|
194
|
+
function insertIntoTree(data, targetKey, node, position) {
|
|
195
|
+
if (position === 0) {
|
|
196
|
+
return data.map((n) => {
|
|
197
|
+
if (getKey(n) === targetKey) {
|
|
198
|
+
const children2 = getChildren(n) ?? [];
|
|
199
|
+
n[fn.children] = [...children2, node];
|
|
200
|
+
return n;
|
|
201
|
+
}
|
|
202
|
+
const children = getChildren(n);
|
|
203
|
+
if (children && children.length > 0) {
|
|
204
|
+
;
|
|
205
|
+
n[fn.children] = insertIntoTree(children, targetKey, node, position);
|
|
206
|
+
}
|
|
207
|
+
return n;
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
const result = [];
|
|
211
|
+
for (const n of data) {
|
|
212
|
+
if (getKey(n) === targetKey) {
|
|
213
|
+
if (position === -1) {
|
|
214
|
+
result.push(node, n);
|
|
215
|
+
} else {
|
|
216
|
+
result.push(n, node);
|
|
217
|
+
}
|
|
218
|
+
} else {
|
|
219
|
+
const children = getChildren(n);
|
|
220
|
+
if (children && children.length > 0) {
|
|
221
|
+
;
|
|
222
|
+
n[fn.children] = insertIntoTree(children, targetKey, node, position);
|
|
223
|
+
}
|
|
224
|
+
result.push(n);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return result;
|
|
228
|
+
}
|
|
229
|
+
function publishState() {
|
|
230
|
+
const path = (k) => `${TREE_PREFIX}${treeId}.${k}`;
|
|
231
|
+
core.batch(() => {
|
|
232
|
+
core.set(path("expandedKeys"), [...expandedKeys]);
|
|
233
|
+
core.set(path("checkedKeys"), [...checkedKeys]);
|
|
234
|
+
core.set(path("halfCheckedKeys"), [...halfCheckedKeys]);
|
|
235
|
+
core.set(path("selectedKeys"), [...selectedKeys]);
|
|
236
|
+
core.set(path("loadedKeys"), [...loadedKeys]);
|
|
237
|
+
core.set(path("loadingKeys"), [...loadingKeys]);
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
function initDefaults() {
|
|
241
|
+
if (options?.defaultExpandAll) {
|
|
242
|
+
for (const [key, internal] of nodeMap) {
|
|
243
|
+
if (!internal.isLeaf) expandedKeys.add(key);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
if (options?.defaultCheckedKeys && !checkStrictly) {
|
|
247
|
+
for (const key of options.defaultCheckedKeys) {
|
|
248
|
+
cascadeCheck(key, true);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
recomputeHalfChecked();
|
|
252
|
+
publishState();
|
|
253
|
+
}
|
|
254
|
+
const engine = {
|
|
255
|
+
setData(data) {
|
|
256
|
+
nodes = data;
|
|
257
|
+
buildMap(data);
|
|
258
|
+
initDefaults();
|
|
259
|
+
},
|
|
260
|
+
getData() {
|
|
261
|
+
return nodes;
|
|
262
|
+
},
|
|
263
|
+
// Expand
|
|
264
|
+
expand(key) {
|
|
265
|
+
expandedKeys.add(key);
|
|
266
|
+
publishState();
|
|
267
|
+
},
|
|
268
|
+
collapse(key) {
|
|
269
|
+
expandedKeys.delete(key);
|
|
270
|
+
publishState();
|
|
271
|
+
},
|
|
272
|
+
toggleExpand(key) {
|
|
273
|
+
if (expandedKeys.has(key)) expandedKeys.delete(key);
|
|
274
|
+
else expandedKeys.add(key);
|
|
275
|
+
publishState();
|
|
276
|
+
},
|
|
277
|
+
setExpandedKeys(keys) {
|
|
278
|
+
expandedKeys = new Set(keys);
|
|
279
|
+
publishState();
|
|
280
|
+
},
|
|
281
|
+
expandAll() {
|
|
282
|
+
for (const [key, internal] of nodeMap) {
|
|
283
|
+
if (!internal.isLeaf) expandedKeys.add(key);
|
|
284
|
+
}
|
|
285
|
+
publishState();
|
|
286
|
+
},
|
|
287
|
+
collapseAll() {
|
|
288
|
+
expandedKeys = /* @__PURE__ */ new Set();
|
|
289
|
+
publishState();
|
|
290
|
+
},
|
|
291
|
+
// Check
|
|
292
|
+
check(key) {
|
|
293
|
+
cascadeCheck(key, true);
|
|
294
|
+
publishState();
|
|
295
|
+
},
|
|
296
|
+
uncheck(key) {
|
|
297
|
+
cascadeCheck(key, false);
|
|
298
|
+
publishState();
|
|
299
|
+
},
|
|
300
|
+
toggleCheck(key) {
|
|
301
|
+
const checked = !checkedKeys.has(key);
|
|
302
|
+
cascadeCheck(key, checked);
|
|
303
|
+
publishState();
|
|
304
|
+
},
|
|
305
|
+
setCheckedKeys(keys) {
|
|
306
|
+
checkedKeys = new Set(keys);
|
|
307
|
+
recomputeHalfChecked();
|
|
308
|
+
publishState();
|
|
309
|
+
},
|
|
310
|
+
// Select
|
|
311
|
+
select(key, multiple) {
|
|
312
|
+
if (multiple) {
|
|
313
|
+
if (selectedKeys.has(key)) selectedKeys.delete(key);
|
|
314
|
+
else selectedKeys.add(key);
|
|
315
|
+
} else {
|
|
316
|
+
selectedKeys = /* @__PURE__ */ new Set([key]);
|
|
317
|
+
}
|
|
318
|
+
publishState();
|
|
319
|
+
},
|
|
320
|
+
deselect(key) {
|
|
321
|
+
selectedKeys.delete(key);
|
|
322
|
+
publishState();
|
|
323
|
+
},
|
|
324
|
+
setSelectedKeys(keys) {
|
|
325
|
+
selectedKeys = new Set(keys);
|
|
326
|
+
publishState();
|
|
327
|
+
},
|
|
328
|
+
// Async loading
|
|
329
|
+
markLoading(key) {
|
|
330
|
+
loadingKeys.add(key);
|
|
331
|
+
publishState();
|
|
332
|
+
},
|
|
333
|
+
markLoaded(key) {
|
|
334
|
+
loadingKeys.delete(key);
|
|
335
|
+
loadedKeys.add(key);
|
|
336
|
+
publishState();
|
|
337
|
+
},
|
|
338
|
+
addChildren(parentKey, children) {
|
|
339
|
+
const internal = nodeMap.get(parentKey);
|
|
340
|
+
if (!internal) return;
|
|
341
|
+
internal.node[fn.children] = children;
|
|
342
|
+
buildMap(nodes);
|
|
343
|
+
publishState();
|
|
344
|
+
},
|
|
345
|
+
// Drag & drop
|
|
346
|
+
moveNode(dragKey, dropKey, position) {
|
|
347
|
+
if (dragKey === dropKey) return null;
|
|
348
|
+
const ancestors = getAllAncestorKeys(dropKey);
|
|
349
|
+
if (ancestors.includes(dragKey)) return null;
|
|
350
|
+
const { remaining, removed } = removeFromTree(nodes, dragKey);
|
|
351
|
+
if (!removed) return null;
|
|
352
|
+
nodes = insertIntoTree(remaining, dropKey, removed, position);
|
|
353
|
+
buildMap(nodes);
|
|
354
|
+
publishState();
|
|
355
|
+
return nodes;
|
|
356
|
+
},
|
|
357
|
+
// Filter
|
|
358
|
+
filterNodes(predicate) {
|
|
359
|
+
if (!predicate) {
|
|
360
|
+
filteredKeys = null;
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
const matched = /* @__PURE__ */ new Set();
|
|
364
|
+
for (const [key, internal] of nodeMap) {
|
|
365
|
+
if (predicate(internal.node)) {
|
|
366
|
+
matched.add(key);
|
|
367
|
+
const ancestors = getAllAncestorKeys(key);
|
|
368
|
+
for (const ak of ancestors) matched.add(ak);
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
filteredKeys = matched;
|
|
372
|
+
},
|
|
373
|
+
getFilteredKeys() {
|
|
374
|
+
return filteredKeys ? [...filteredKeys] : null;
|
|
375
|
+
},
|
|
376
|
+
// Query
|
|
377
|
+
getNode(key) {
|
|
378
|
+
return nodeMap.get(key)?.node;
|
|
379
|
+
},
|
|
380
|
+
getParentKey(key) {
|
|
381
|
+
return nodeMap.get(key)?.parentKey ?? null;
|
|
382
|
+
},
|
|
383
|
+
getChildKeys(key) {
|
|
384
|
+
return nodeMap.get(key)?.childKeys ?? [];
|
|
385
|
+
},
|
|
386
|
+
getAllKeys() {
|
|
387
|
+
return [...nodeMap.keys()];
|
|
388
|
+
},
|
|
389
|
+
getLeafKeys() {
|
|
390
|
+
const result = [];
|
|
391
|
+
for (const [key, internal] of nodeMap) {
|
|
392
|
+
if (internal.isLeaf) result.push(key);
|
|
393
|
+
}
|
|
394
|
+
return result;
|
|
395
|
+
},
|
|
396
|
+
getState() {
|
|
397
|
+
return {
|
|
398
|
+
expandedKeys: [...expandedKeys],
|
|
399
|
+
checkedKeys: [...checkedKeys],
|
|
400
|
+
halfCheckedKeys: [...halfCheckedKeys],
|
|
401
|
+
selectedKeys: [...selectedKeys],
|
|
402
|
+
loadedKeys: [...loadedKeys],
|
|
403
|
+
loadingKeys: [...loadingKeys]
|
|
404
|
+
};
|
|
405
|
+
},
|
|
406
|
+
getFlatNodes() {
|
|
407
|
+
const result = [];
|
|
408
|
+
function walk(list, parentKey, depth) {
|
|
409
|
+
for (const n of list) {
|
|
410
|
+
const k = getKey(n);
|
|
411
|
+
if (filteredKeys && !filteredKeys.has(k)) continue;
|
|
412
|
+
const children = getChildren(n);
|
|
413
|
+
const isLeaf = n.isLeaf === true || (!children || children.length === 0);
|
|
414
|
+
result.push({ node: n, key: k, depth, isLeaf, parentKey });
|
|
415
|
+
if (!isLeaf && expandedKeys.has(k) && children && children.length > 0) {
|
|
416
|
+
walk(children, k, depth + 1);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
walk(nodes, null, 0);
|
|
421
|
+
return result;
|
|
422
|
+
},
|
|
423
|
+
reset() {
|
|
424
|
+
nodes = [];
|
|
425
|
+
nodeMap = /* @__PURE__ */ new Map();
|
|
426
|
+
expandedKeys = /* @__PURE__ */ new Set();
|
|
427
|
+
checkedKeys = /* @__PURE__ */ new Set();
|
|
428
|
+
halfCheckedKeys = /* @__PURE__ */ new Set();
|
|
429
|
+
selectedKeys = /* @__PURE__ */ new Set();
|
|
430
|
+
loadedKeys = /* @__PURE__ */ new Set();
|
|
431
|
+
loadingKeys = /* @__PURE__ */ new Set();
|
|
432
|
+
filteredKeys = null;
|
|
433
|
+
publishState();
|
|
434
|
+
}
|
|
435
|
+
};
|
|
436
|
+
return engine;
|
|
437
|
+
}
|
|
438
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
439
|
+
0 && (module.exports = {
|
|
440
|
+
createTree
|
|
441
|
+
});
|
|
442
|
+
//# sourceMappingURL=tree.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/engines/tree/index.ts","../src/engines/namespaces.ts","../src/engines/tree/TreeEngine.ts"],"sourcesContent":["export { createTree } from './TreeEngine'\nexport type {\n TreeEngine,\n TreeState,\n TreeEngineOptions,\n TreeKey,\n TreeNodeData,\n TreeFieldNames,\n} from './types'\n","/**\n * Engine path namespace registry\n *\n * Every engine that stores state in the Core store under a `$`-prefixed\n * namespace MUST register its prefix here. This prevents two engines from\n * silently colliding on the same root path (e.g. two engines both writing\n * under `$meta.`).\n *\n * Rules:\n * 1. Prefixes MUST start with `$` and end with `.`.\n * 2. Prefixes MUST be unique across all engines.\n * 3. An engine MUST use `reservedPrefix(name)` at module load so\n * collisions surface at import time during dev/test.\n * 4. User data MUST NOT live under `$` prefixes — reserve them for engines.\n */\n\nconst reserved = new Map<string, string>()\n\n/**\n * Reserve (or look up) a prefix for an engine. Throws synchronously if the\n * same prefix is already owned by a different engine.\n */\nexport function reservePrefix(engine: string, prefix: string): string {\n if (!prefix.startsWith('$') || !prefix.endsWith('.')) {\n throw new Error(\n `[skygraph] engine \"${engine}\" tried to reserve invalid prefix \"${prefix}\". ` +\n `Engine prefixes must start with \"$\" and end with \".\".`,\n )\n }\n\n const existing = reserved.get(prefix)\n if (existing !== undefined && existing !== engine) {\n throw new Error(\n `[skygraph] prefix \"${prefix}\" is already owned by engine \"${existing}\", ` +\n `cannot reserve it for \"${engine}\". ` +\n `Pick a different prefix or update the registry.`,\n )\n }\n\n reserved.set(prefix, engine)\n return prefix\n}\n\n/** Snapshot of registered engine prefixes (debug / introspection). */\nexport function listReservedPrefixes(): ReadonlyMap<string, string> {\n return new Map(reserved)\n}\n\n/** Test-only helper. DO NOT call from engine code. */\nexport function __resetPrefixes(): void {\n reserved.clear()\n}\n\n// ── Canonical in-tree reservations ─────────────────────────────────────────\n//\n// Listed here so they are reserved even if the engine module is not loaded.\n// New engines must add their entry here and reference it from their\n// implementation via `reservePrefix(...)`.\n\nexport const FORM_META_PREFIX = reservePrefix('form', '$meta.')\nexport const TABLE_PREFIX = reservePrefix('table', '$table.')\nexport const TREE_PREFIX = reservePrefix('tree', '$tree.')\nexport const GRAPH_PREFIX = reservePrefix('graph', '$graph.')\nexport const CALENDAR_PREFIX = reservePrefix('calendar', '$calendar.')\n","import type { Core } from '../../types'\nimport type {\n TreeKey,\n TreeNodeData,\n TreeFieldNames,\n TreeEngine,\n TreeEngineOptions,\n TreeState,\n} from './types'\n\nimport { TREE_PREFIX } from '../namespaces'\n\nlet treeCounter = 0\n\ninterface InternalNode {\n node: TreeNodeData\n key: TreeKey\n depth: number\n parentKey: TreeKey | null\n childKeys: TreeKey[]\n isLeaf: boolean\n}\n\nexport function createTree(core: Core, options?: TreeEngineOptions): TreeEngine {\n const treeId = `tr${treeCounter++}`\n const fn: Required<TreeFieldNames> = {\n key: options?.fieldNames?.key ?? 'key',\n title: options?.fieldNames?.title ?? 'title',\n children: options?.fieldNames?.children ?? 'children',\n }\n const checkStrictly = options?.checkStrictly ?? false\n\n let nodes: TreeNodeData[] = []\n let nodeMap = new Map<TreeKey, InternalNode>()\n\n let expandedKeys = new Set<TreeKey>(options?.defaultExpandedKeys ?? [])\n let checkedKeys = new Set<TreeKey>(options?.defaultCheckedKeys ?? [])\n let halfCheckedKeys = new Set<TreeKey>()\n let selectedKeys = new Set<TreeKey>(options?.defaultSelectedKeys ?? [])\n let loadedKeys = new Set<TreeKey>()\n let loadingKeys = new Set<TreeKey>()\n let filteredKeys: Set<TreeKey> | null = null\n\n function getKey(node: TreeNodeData): TreeKey {\n return (node as Record<string, unknown>)[fn.key] as TreeKey\n }\n\n function getChildren(node: TreeNodeData): TreeNodeData[] | undefined {\n return (node as Record<string, unknown>)[fn.children] as TreeNodeData[] | undefined\n }\n\n function buildMap(data: TreeNodeData[]): void {\n nodeMap = new Map()\n function walk(list: TreeNodeData[], parentKey: TreeKey | null, depth: number) {\n for (const n of list) {\n const k = getKey(n)\n const children = getChildren(n)\n const childKeys: TreeKey[] = []\n const isLeaf = n.isLeaf === true || (!children || children.length === 0)\n\n if (children && children.length > 0) {\n for (const ch of children) childKeys.push(getKey(ch))\n }\n\n nodeMap.set(k, { node: n, key: k, depth, parentKey, childKeys, isLeaf })\n\n if (children && children.length > 0) {\n walk(children, k, depth + 1)\n }\n }\n }\n walk(data, null, 0)\n }\n\n function getAllDescendantKeys(key: TreeKey): TreeKey[] {\n const result: TreeKey[] = []\n const internal = nodeMap.get(key)\n if (!internal) return result\n for (const ck of internal.childKeys) {\n result.push(ck)\n result.push(...getAllDescendantKeys(ck))\n }\n return result\n }\n\n function getAllAncestorKeys(key: TreeKey): TreeKey[] {\n const result: TreeKey[] = []\n let current = nodeMap.get(key)\n while (current && current.parentKey !== null) {\n result.push(current.parentKey)\n current = nodeMap.get(current.parentKey)\n }\n return result\n }\n\n function recomputeHalfChecked(): void {\n if (checkStrictly) {\n halfCheckedKeys = new Set()\n return\n }\n const half = new Set<TreeKey>()\n for (const [key, internal] of nodeMap) {\n if (internal.childKeys.length === 0) continue\n if (checkedKeys.has(key)) continue\n const allDescendants = getAllDescendantKeys(key)\n const someChecked = allDescendants.some((dk) => checkedKeys.has(dk))\n if (someChecked) half.add(key)\n }\n halfCheckedKeys = half\n }\n\n function cascadeCheck(key: TreeKey, checked: boolean): void {\n if (checkStrictly) {\n if (checked) checkedKeys.add(key)\n else checkedKeys.delete(key)\n return\n }\n\n const internal = nodeMap.get(key)\n if (!internal) return\n\n if (checked) {\n checkedKeys.add(key)\n const descendants = getAllDescendantKeys(key)\n for (const dk of descendants) {\n const dn = nodeMap.get(dk)\n if (dn && !dn.node.disabled && !dn.node.disableCheckbox) {\n checkedKeys.add(dk)\n }\n }\n } else {\n checkedKeys.delete(key)\n const descendants = getAllDescendantKeys(key)\n for (const dk of descendants) {\n checkedKeys.delete(dk)\n }\n }\n\n // Propagate up\n const ancestors = getAllAncestorKeys(key)\n for (const ak of ancestors) {\n const an = nodeMap.get(ak)\n if (!an) continue\n const allChildren = getAllDescendantKeys(ak)\n const enabledChildren = allChildren.filter((ck) => {\n const cn = nodeMap.get(ck)\n return cn && !cn.node.disabled && !cn.node.disableCheckbox\n })\n const allChecked = enabledChildren.length > 0 && enabledChildren.every((ck) => checkedKeys.has(ck))\n if (allChecked) {\n checkedKeys.add(ak)\n } else {\n checkedKeys.delete(ak)\n }\n }\n\n recomputeHalfChecked()\n }\n\n function removeFromTree(data: TreeNodeData[], targetKey: TreeKey): { remaining: TreeNodeData[]; removed: TreeNodeData | null } {\n let removed: TreeNodeData | null = null\n const remaining = data.filter((n) => {\n if (getKey(n) === targetKey) {\n removed = n\n return false\n }\n return true\n })\n if (!removed) {\n for (const n of remaining) {\n const children = getChildren(n)\n if (children && children.length > 0) {\n const result = removeFromTree(children, targetKey)\n if (result.removed) {\n ;(n as Record<string, unknown>)[fn.children] = result.remaining\n return { remaining, removed: result.removed }\n }\n }\n }\n }\n return { remaining, removed }\n }\n\n function insertIntoTree(\n data: TreeNodeData[],\n targetKey: TreeKey,\n node: TreeNodeData,\n position: -1 | 0 | 1,\n ): TreeNodeData[] {\n if (position === 0) {\n return data.map((n) => {\n if (getKey(n) === targetKey) {\n const children = getChildren(n) ?? []\n ;(n as Record<string, unknown>)[fn.children] = [...children, node]\n return n\n }\n const children = getChildren(n)\n if (children && children.length > 0) {\n ;(n as Record<string, unknown>)[fn.children] = insertIntoTree(children, targetKey, node, position)\n }\n return n\n })\n }\n\n const result: TreeNodeData[] = []\n for (const n of data) {\n if (getKey(n) === targetKey) {\n if (position === -1) {\n result.push(node, n)\n } else {\n result.push(n, node)\n }\n } else {\n const children = getChildren(n)\n if (children && children.length > 0) {\n ;(n as Record<string, unknown>)[fn.children] = insertIntoTree(children, targetKey, node, position)\n }\n result.push(n)\n }\n }\n return result\n }\n\n function publishState(): void {\n const path = (k: string) => `${TREE_PREFIX}${treeId}.${k}`\n core.batch(() => {\n core.set(path('expandedKeys'), [...expandedKeys])\n core.set(path('checkedKeys'), [...checkedKeys])\n core.set(path('halfCheckedKeys'), [...halfCheckedKeys])\n core.set(path('selectedKeys'), [...selectedKeys])\n core.set(path('loadedKeys'), [...loadedKeys])\n core.set(path('loadingKeys'), [...loadingKeys])\n })\n }\n\n function initDefaults(): void {\n if (options?.defaultExpandAll) {\n for (const [key, internal] of nodeMap) {\n if (!internal.isLeaf) expandedKeys.add(key)\n }\n }\n\n if (options?.defaultCheckedKeys && !checkStrictly) {\n for (const key of options.defaultCheckedKeys) {\n cascadeCheck(key, true)\n }\n }\n\n recomputeHalfChecked()\n publishState()\n }\n\n const engine: TreeEngine = {\n setData(data: TreeNodeData[]): void {\n nodes = data\n buildMap(data)\n initDefaults()\n },\n\n getData(): TreeNodeData[] {\n return nodes\n },\n\n // Expand\n expand(key: TreeKey): void {\n expandedKeys.add(key)\n publishState()\n },\n\n collapse(key: TreeKey): void {\n expandedKeys.delete(key)\n publishState()\n },\n\n toggleExpand(key: TreeKey): void {\n if (expandedKeys.has(key)) expandedKeys.delete(key)\n else expandedKeys.add(key)\n publishState()\n },\n\n setExpandedKeys(keys: TreeKey[]): void {\n expandedKeys = new Set(keys)\n publishState()\n },\n\n expandAll(): void {\n for (const [key, internal] of nodeMap) {\n if (!internal.isLeaf) expandedKeys.add(key)\n }\n publishState()\n },\n\n collapseAll(): void {\n expandedKeys = new Set()\n publishState()\n },\n\n // Check\n check(key: TreeKey): void {\n cascadeCheck(key, true)\n publishState()\n },\n\n uncheck(key: TreeKey): void {\n cascadeCheck(key, false)\n publishState()\n },\n\n toggleCheck(key: TreeKey): void {\n const checked = !checkedKeys.has(key)\n cascadeCheck(key, checked)\n publishState()\n },\n\n setCheckedKeys(keys: TreeKey[]): void {\n checkedKeys = new Set(keys)\n recomputeHalfChecked()\n publishState()\n },\n\n // Select\n select(key: TreeKey, multiple?: boolean): void {\n if (multiple) {\n if (selectedKeys.has(key)) selectedKeys.delete(key)\n else selectedKeys.add(key)\n } else {\n selectedKeys = new Set([key])\n }\n publishState()\n },\n\n deselect(key: TreeKey): void {\n selectedKeys.delete(key)\n publishState()\n },\n\n setSelectedKeys(keys: TreeKey[]): void {\n selectedKeys = new Set(keys)\n publishState()\n },\n\n // Async loading\n markLoading(key: TreeKey): void {\n loadingKeys.add(key)\n publishState()\n },\n\n markLoaded(key: TreeKey): void {\n loadingKeys.delete(key)\n loadedKeys.add(key)\n publishState()\n },\n\n addChildren(parentKey: TreeKey, children: TreeNodeData[]): void {\n const internal = nodeMap.get(parentKey)\n if (!internal) return\n ;(internal.node as Record<string, unknown>)[fn.children] = children\n buildMap(nodes)\n publishState()\n },\n\n // Drag & drop\n moveNode(dragKey: TreeKey, dropKey: TreeKey, position: -1 | 0 | 1): TreeNodeData[] | null {\n if (dragKey === dropKey) return null\n const ancestors = getAllAncestorKeys(dropKey)\n if (ancestors.includes(dragKey)) return null\n\n const { remaining, removed } = removeFromTree(nodes, dragKey)\n if (!removed) return null\n\n nodes = insertIntoTree(remaining, dropKey, removed, position)\n buildMap(nodes)\n publishState()\n return nodes\n },\n\n // Filter\n filterNodes(predicate: ((node: TreeNodeData) => boolean) | null): void {\n if (!predicate) {\n filteredKeys = null\n return\n }\n const matched = new Set<TreeKey>()\n for (const [key, internal] of nodeMap) {\n if (predicate(internal.node)) {\n matched.add(key)\n const ancestors = getAllAncestorKeys(key)\n for (const ak of ancestors) matched.add(ak)\n }\n }\n filteredKeys = matched\n },\n\n getFilteredKeys(): TreeKey[] | null {\n return filteredKeys ? [...filteredKeys] : null\n },\n\n // Query\n getNode(key: TreeKey): TreeNodeData | undefined {\n return nodeMap.get(key)?.node\n },\n\n getParentKey(key: TreeKey): TreeKey | null {\n return nodeMap.get(key)?.parentKey ?? null\n },\n\n getChildKeys(key: TreeKey): TreeKey[] {\n return nodeMap.get(key)?.childKeys ?? []\n },\n\n getAllKeys(): TreeKey[] {\n return [...nodeMap.keys()]\n },\n\n getLeafKeys(): TreeKey[] {\n const result: TreeKey[] = []\n for (const [key, internal] of nodeMap) {\n if (internal.isLeaf) result.push(key)\n }\n return result\n },\n\n getState(): TreeState {\n return {\n expandedKeys: [...expandedKeys],\n checkedKeys: [...checkedKeys],\n halfCheckedKeys: [...halfCheckedKeys],\n selectedKeys: [...selectedKeys],\n loadedKeys: [...loadedKeys],\n loadingKeys: [...loadingKeys],\n }\n },\n\n getFlatNodes() {\n const result: Array<{ node: TreeNodeData; key: TreeKey; depth: number; isLeaf: boolean; parentKey: TreeKey | null }> = []\n\n function walk(list: TreeNodeData[], parentKey: TreeKey | null, depth: number) {\n for (const n of list) {\n const k = getKey(n)\n if (filteredKeys && !filteredKeys.has(k)) continue\n\n const children = getChildren(n)\n const isLeaf = n.isLeaf === true || (!children || children.length === 0)\n\n result.push({ node: n, key: k, depth, isLeaf, parentKey })\n\n if (!isLeaf && expandedKeys.has(k) && children && children.length > 0) {\n walk(children, k, depth + 1)\n }\n }\n }\n\n walk(nodes, null, 0)\n return result\n },\n\n reset(): void {\n nodes = []\n nodeMap = new Map()\n expandedKeys = new Set()\n checkedKeys = new Set()\n halfCheckedKeys = new Set()\n selectedKeys = new Set()\n loadedKeys = new Set()\n loadingKeys = new Set()\n filteredKeys = null\n publishState()\n },\n }\n\n return engine\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACgBA,IAAM,WAAW,oBAAI,IAAoB;AAMlC,SAAS,cAAc,QAAgB,QAAwB;AACpE,MAAI,CAAC,OAAO,WAAW,GAAG,KAAK,CAAC,OAAO,SAAS,GAAG,GAAG;AACpD,UAAM,IAAI;AAAA,MACR,sBAAsB,MAAM,sCAAsC,MAAM;AAAA,IAE1E;AAAA,EACF;AAEA,QAAM,WAAW,SAAS,IAAI,MAAM;AACpC,MAAI,aAAa,UAAa,aAAa,QAAQ;AACjD,UAAM,IAAI;AAAA,MACR,sBAAsB,MAAM,iCAAiC,QAAQ,6BACzC,MAAM;AAAA,IAEpC;AAAA,EACF;AAEA,WAAS,IAAI,QAAQ,MAAM;AAC3B,SAAO;AACT;AAkBO,IAAM,mBAAmB,cAAc,QAAQ,QAAQ;AACvD,IAAM,eAAe,cAAc,SAAS,SAAS;AACrD,IAAM,cAAc,cAAc,QAAQ,QAAQ;A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AC1B,qBAAe,oBAAI,IAAI;AACvB,mBAAa,oBAAI,IAAI;AACrB,oBAAc,oBAAI,IAAI;AACtB,qBAAe;AACf,mBAAa;AAAA,IACf;AAAA,EACF;AAEA,SAAO;AACT;","names":["children"]}
|
package/dist/tree.d.cts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { C as Core } from './types-B-rKQJ4R.cjs';
|
|
2
|
+
|
|
3
|
+
type TreeKey = string | number;
|
|
4
|
+
interface TreeNodeData {
|
|
5
|
+
key: TreeKey;
|
|
6
|
+
title?: string;
|
|
7
|
+
children?: TreeNodeData[];
|
|
8
|
+
isLeaf?: boolean;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
disableCheckbox?: boolean;
|
|
11
|
+
selectable?: boolean;
|
|
12
|
+
checkable?: boolean;
|
|
13
|
+
[field: string]: unknown;
|
|
14
|
+
}
|
|
15
|
+
interface TreeFieldNames {
|
|
16
|
+
key?: string;
|
|
17
|
+
title?: string;
|
|
18
|
+
children?: string;
|
|
19
|
+
}
|
|
20
|
+
interface TreeState {
|
|
21
|
+
expandedKeys: TreeKey[];
|
|
22
|
+
checkedKeys: TreeKey[];
|
|
23
|
+
halfCheckedKeys: TreeKey[];
|
|
24
|
+
selectedKeys: TreeKey[];
|
|
25
|
+
loadedKeys: TreeKey[];
|
|
26
|
+
loadingKeys: TreeKey[];
|
|
27
|
+
}
|
|
28
|
+
interface TreeEngineOptions {
|
|
29
|
+
fieldNames?: TreeFieldNames;
|
|
30
|
+
checkStrictly?: boolean;
|
|
31
|
+
defaultExpandAll?: boolean;
|
|
32
|
+
defaultExpandedKeys?: TreeKey[];
|
|
33
|
+
defaultCheckedKeys?: TreeKey[];
|
|
34
|
+
defaultSelectedKeys?: TreeKey[];
|
|
35
|
+
}
|
|
36
|
+
interface TreeEngine {
|
|
37
|
+
setData(nodes: TreeNodeData[]): void;
|
|
38
|
+
getData(): TreeNodeData[];
|
|
39
|
+
expand(key: TreeKey): void;
|
|
40
|
+
collapse(key: TreeKey): void;
|
|
41
|
+
toggleExpand(key: TreeKey): void;
|
|
42
|
+
setExpandedKeys(keys: TreeKey[]): void;
|
|
43
|
+
expandAll(): void;
|
|
44
|
+
collapseAll(): void;
|
|
45
|
+
check(key: TreeKey): void;
|
|
46
|
+
uncheck(key: TreeKey): void;
|
|
47
|
+
toggleCheck(key: TreeKey): void;
|
|
48
|
+
setCheckedKeys(keys: TreeKey[]): void;
|
|
49
|
+
select(key: TreeKey, multiple?: boolean): void;
|
|
50
|
+
deselect(key: TreeKey): void;
|
|
51
|
+
setSelectedKeys(keys: TreeKey[]): void;
|
|
52
|
+
markLoading(key: TreeKey): void;
|
|
53
|
+
markLoaded(key: TreeKey): void;
|
|
54
|
+
addChildren(parentKey: TreeKey, children: TreeNodeData[]): void;
|
|
55
|
+
moveNode(dragKey: TreeKey, dropKey: TreeKey, position: -1 | 0 | 1): TreeNodeData[] | null;
|
|
56
|
+
filterNodes(predicate: ((node: TreeNodeData) => boolean) | null): void;
|
|
57
|
+
getFilteredKeys(): TreeKey[] | null;
|
|
58
|
+
getNode(key: TreeKey): TreeNodeData | undefined;
|
|
59
|
+
getParentKey(key: TreeKey): TreeKey | null;
|
|
60
|
+
getChildKeys(key: TreeKey): TreeKey[];
|
|
61
|
+
getAllKeys(): TreeKey[];
|
|
62
|
+
getLeafKeys(): TreeKey[];
|
|
63
|
+
getState(): TreeState;
|
|
64
|
+
getFlatNodes(): Array<{
|
|
65
|
+
node: TreeNodeData;
|
|
66
|
+
key: TreeKey;
|
|
67
|
+
depth: number;
|
|
68
|
+
isLeaf: boolean;
|
|
69
|
+
parentKey: TreeKey | null;
|
|
70
|
+
}>;
|
|
71
|
+
reset(): void;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
declare function createTree(core: Core, options?: TreeEngineOptions): TreeEngine;
|
|
75
|
+
|
|
76
|
+
export { type TreeEngine, type TreeEngineOptions, type TreeFieldNames, type TreeKey, type TreeNodeData, type TreeState, createTree };
|
package/dist/tree.d.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { C as Core } from './types-B-rKQJ4R.js';
|
|
2
|
+
|
|
3
|
+
type TreeKey = string | number;
|
|
4
|
+
interface TreeNodeData {
|
|
5
|
+
key: TreeKey;
|
|
6
|
+
title?: string;
|
|
7
|
+
children?: TreeNodeData[];
|
|
8
|
+
isLeaf?: boolean;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
disableCheckbox?: boolean;
|
|
11
|
+
selectable?: boolean;
|
|
12
|
+
checkable?: boolean;
|
|
13
|
+
[field: string]: unknown;
|
|
14
|
+
}
|
|
15
|
+
interface TreeFieldNames {
|
|
16
|
+
key?: string;
|
|
17
|
+
title?: string;
|
|
18
|
+
children?: string;
|
|
19
|
+
}
|
|
20
|
+
interface TreeState {
|
|
21
|
+
expandedKeys: TreeKey[];
|
|
22
|
+
checkedKeys: TreeKey[];
|
|
23
|
+
halfCheckedKeys: TreeKey[];
|
|
24
|
+
selectedKeys: TreeKey[];
|
|
25
|
+
loadedKeys: TreeKey[];
|
|
26
|
+
loadingKeys: TreeKey[];
|
|
27
|
+
}
|
|
28
|
+
interface TreeEngineOptions {
|
|
29
|
+
fieldNames?: TreeFieldNames;
|
|
30
|
+
checkStrictly?: boolean;
|
|
31
|
+
defaultExpandAll?: boolean;
|
|
32
|
+
defaultExpandedKeys?: TreeKey[];
|
|
33
|
+
defaultCheckedKeys?: TreeKey[];
|
|
34
|
+
defaultSelectedKeys?: TreeKey[];
|
|
35
|
+
}
|
|
36
|
+
interface TreeEngine {
|
|
37
|
+
setData(nodes: TreeNodeData[]): void;
|
|
38
|
+
getData(): TreeNodeData[];
|
|
39
|
+
expand(key: TreeKey): void;
|
|
40
|
+
collapse(key: TreeKey): void;
|
|
41
|
+
toggleExpand(key: TreeKey): void;
|
|
42
|
+
setExpandedKeys(keys: TreeKey[]): void;
|
|
43
|
+
expandAll(): void;
|
|
44
|
+
collapseAll(): void;
|
|
45
|
+
check(key: TreeKey): void;
|
|
46
|
+
uncheck(key: TreeKey): void;
|
|
47
|
+
toggleCheck(key: TreeKey): void;
|
|
48
|
+
setCheckedKeys(keys: TreeKey[]): void;
|
|
49
|
+
select(key: TreeKey, multiple?: boolean): void;
|
|
50
|
+
deselect(key: TreeKey): void;
|
|
51
|
+
setSelectedKeys(keys: TreeKey[]): void;
|
|
52
|
+
markLoading(key: TreeKey): void;
|
|
53
|
+
markLoaded(key: TreeKey): void;
|
|
54
|
+
addChildren(parentKey: TreeKey, children: TreeNodeData[]): void;
|
|
55
|
+
moveNode(dragKey: TreeKey, dropKey: TreeKey, position: -1 | 0 | 1): TreeNodeData[] | null;
|
|
56
|
+
filterNodes(predicate: ((node: TreeNodeData) => boolean) | null): void;
|
|
57
|
+
getFilteredKeys(): TreeKey[] | null;
|
|
58
|
+
getNode(key: TreeKey): TreeNodeData | undefined;
|
|
59
|
+
getParentKey(key: TreeKey): TreeKey | null;
|
|
60
|
+
getChildKeys(key: TreeKey): TreeKey[];
|
|
61
|
+
getAllKeys(): TreeKey[];
|
|
62
|
+
getLeafKeys(): TreeKey[];
|
|
63
|
+
getState(): TreeState;
|
|
64
|
+
getFlatNodes(): Array<{
|
|
65
|
+
node: TreeNodeData;
|
|
66
|
+
key: TreeKey;
|
|
67
|
+
depth: number;
|
|
68
|
+
isLeaf: boolean;
|
|
69
|
+
parentKey: TreeKey | null;
|
|
70
|
+
}>;
|
|
71
|
+
reset(): void;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
declare function createTree(core: Core, options?: TreeEngineOptions): TreeEngine;
|
|
75
|
+
|
|
76
|
+
export { type TreeEngine, type TreeEngineOptions, type TreeFieldNames, type TreeKey, type TreeNodeData, type TreeState, createTree };
|
package/dist/tree.js
ADDED
package/dist/tree.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|