@keenmate/svelte-treeview 3.0.0 → 3.1.1
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/Branch.svelte +14 -20
- package/dist/Branch.svelte.d.ts +68 -2
- package/dist/TreeView.svelte +142 -107
- package/dist/helpers/tree-helper.js +3 -5
- package/dist/tree-styles.scss +151 -0
- package/package.json +4 -1
- package/dist/tree-styles.sass +0 -121
package/dist/Branch.svelte
CHANGED
|
@@ -28,7 +28,7 @@ function selectionChanged(node) {
|
|
|
28
28
|
}
|
|
29
29
|
// drag and drop
|
|
30
30
|
function handleDragStart(e, node) {
|
|
31
|
-
internal_onHandleDragStart?.({ node: node,
|
|
31
|
+
internal_onHandleDragStart?.({ node: node, event: e });
|
|
32
32
|
}
|
|
33
33
|
function handleDragDrop(e, node, el) {
|
|
34
34
|
e.stopImmediatePropagation();
|
|
@@ -172,25 +172,19 @@ function onContextMenu(ev, node) {
|
|
|
172
172
|
{insertionType}
|
|
173
173
|
{focusedNode}
|
|
174
174
|
{allowKeyboardNavigation}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
{@render children?.({node: nodeNested,})}
|
|
189
|
-
<!--<svelte:fragment slot="nest-highlight">-->
|
|
190
|
-
<!-- <slot name="nest-highlight" />-->
|
|
191
|
-
<!--</svelte:fragment>-->
|
|
192
|
-
{/snippet}
|
|
193
|
-
</Branch>
|
|
175
|
+
{children}
|
|
176
|
+
{nestHighlight}
|
|
177
|
+
{onOpenCtxmenu}
|
|
178
|
+
{internal_onExpand}
|
|
179
|
+
{internal_onSelectionChanged}
|
|
180
|
+
{internal_onHandleDragStart}
|
|
181
|
+
{internal_onHandleDragDrop}
|
|
182
|
+
{internal_onHandleDragOver}
|
|
183
|
+
{internal_onHandleDragEnter}
|
|
184
|
+
{internal_onHandleDragEnd}
|
|
185
|
+
{internal_onHandleDragLeave}
|
|
186
|
+
{internal_onKeypress}
|
|
187
|
+
/>
|
|
194
188
|
{/if}
|
|
195
189
|
{#if !expanded && node.hasChildren}
|
|
196
190
|
<ul class:child-menu={childDepth > 0}></ul>
|
package/dist/Branch.svelte.d.ts
CHANGED
|
@@ -1,4 +1,70 @@
|
|
|
1
1
|
import Branch from "./Branch.svelte";
|
|
2
|
-
|
|
3
|
-
type
|
|
2
|
+
import { type CustomizableClasses, InsertionType, type Node, SelectionModes } from "./types.js";
|
|
3
|
+
import type { TreeHelper } from "./helpers/tree-helper.js";
|
|
4
|
+
interface Props {
|
|
5
|
+
tree: Node[];
|
|
6
|
+
treeId: string;
|
|
7
|
+
recursive?: boolean;
|
|
8
|
+
checkboxes?: SelectionModes;
|
|
9
|
+
onlyLeafCheckboxes: boolean;
|
|
10
|
+
hideDisabledCheckboxes: boolean;
|
|
11
|
+
dragAndDrop: boolean;
|
|
12
|
+
verticalLines: boolean;
|
|
13
|
+
readonly: boolean;
|
|
14
|
+
expandTo: number;
|
|
15
|
+
classes: CustomizableClasses;
|
|
16
|
+
helper: TreeHelper;
|
|
17
|
+
childDepth: number;
|
|
18
|
+
branchRootNode: Node | null;
|
|
19
|
+
draggedNode: Node | null;
|
|
20
|
+
highlightedNode: Node | null;
|
|
21
|
+
insertionType: InsertionType;
|
|
22
|
+
focusedNode: Node | null;
|
|
23
|
+
allowKeyboardNavigation: boolean;
|
|
24
|
+
onOpenCtxmenu?: () => void;
|
|
25
|
+
internal_onExpand?: ({ node: any, changeTo: boolean }: {
|
|
26
|
+
node: any;
|
|
27
|
+
changeTo: any;
|
|
28
|
+
}) => void;
|
|
29
|
+
internal_onSelectionChanged?: ({ node: any }: {
|
|
30
|
+
node: any;
|
|
31
|
+
}) => void;
|
|
32
|
+
internal_onHandleDragStart?: ({ node: any, event: any }: {
|
|
33
|
+
node: any;
|
|
34
|
+
event: any;
|
|
35
|
+
}) => void;
|
|
36
|
+
internal_onHandleDragDrop?: ({ node: any, event: any, element: any }: {
|
|
37
|
+
node: any;
|
|
38
|
+
event: any;
|
|
39
|
+
element: any;
|
|
40
|
+
}) => void;
|
|
41
|
+
internal_onHandleDragOver?: ({ node: any, event: any, element: any, nest: any }: {
|
|
42
|
+
node: any;
|
|
43
|
+
event: any;
|
|
44
|
+
element: any;
|
|
45
|
+
nest: any;
|
|
46
|
+
}) => void;
|
|
47
|
+
internal_onHandleDragEnter?: ({ node: any, event: any, element: any }: {
|
|
48
|
+
node: any;
|
|
49
|
+
event: any;
|
|
50
|
+
element: any;
|
|
51
|
+
}) => void;
|
|
52
|
+
internal_onHandleDragEnd?: ({ node: any, event: any }: {
|
|
53
|
+
node: any;
|
|
54
|
+
event: any;
|
|
55
|
+
}) => void;
|
|
56
|
+
internal_onHandleDragLeave?: ({ node: any, event: any, element: any }: {
|
|
57
|
+
node: any;
|
|
58
|
+
event: any;
|
|
59
|
+
element: any;
|
|
60
|
+
}) => void;
|
|
61
|
+
internal_onKeypress?: ({ node: any, event: any }: {
|
|
62
|
+
node: any;
|
|
63
|
+
event: any;
|
|
64
|
+
}) => void;
|
|
65
|
+
children?: import("svelte").Snippet<[any]>;
|
|
66
|
+
nestHighlight?: import("svelte").Snippet;
|
|
67
|
+
}
|
|
68
|
+
declare const Branch: import("svelte").Component<Props, {}, "">;
|
|
69
|
+
type Branch = ReturnType<typeof Branch>;
|
|
4
70
|
export default Branch;
|
package/dist/TreeView.svelte
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
<!-- @migration-task Error while migrating Svelte code: migrating this component would require adding a `$props` rune but there's already a variable named props.
|
|
2
|
-
Rename the variable and try again or migrate by hand. -->
|
|
3
|
-
<!-- @migration-task Error while migrating Svelte code: This migration would change the name of a slot (context-menu to context_menu) making the component unusable -->
|
|
4
|
-
<!-- @migration-task Error while migrating Svelte code: This migration would change the name of a slot (nest-highlight to nest_highlight) making the component unusable -->
|
|
5
|
-
<!-- @migration-task Error while migrating Svelte code: This migration would change the name of a slot (nest-highlight to nest_highlight) making the component unusable -->
|
|
6
|
-
<!-- @migration-task Error while migrating Svelte code: This migration would change the name of a slot (nest-highlight to nest_highlight) making the component unusable -->
|
|
7
1
|
<script lang="ts">import ContextMenu from "./menu/ContextMenu.svelte";
|
|
8
2
|
import { defaultClasses, defaultPropNames } from "./constants.js";
|
|
9
3
|
import { InsertionType, SelectionModes as SelectionModes } from "./types.js";
|
|
@@ -13,13 +7,8 @@ import { SelectionProvider } from "./providers/selection-provider.js";
|
|
|
13
7
|
import { DragDropProvider } from "./providers/drag-drop-provider.js";
|
|
14
8
|
import uniq from "lodash.uniq";
|
|
15
9
|
import { calculateNewFocusedNode, parseMovementDirection } from "./providers/movement-provider.js";
|
|
10
|
+
import { untrack } from "svelte";
|
|
16
11
|
let { treeId, tree, value = [], treeProps = {}, verticalLines = false, readonly = false, separator = ".", recursiveSelection = false, selectionMode = SelectionModes.none, onlyLeafCheckboxes = false, hideDisabledCheckboxes = false, loadChildrenAsync = null, showContextMenu = false, expandTo = 0, expansionThreshold = 0, customClasses = {}, filter = null, logger = null, nodeSorter = null, dragAndDrop = false, dropDisabledCallback = null, allowKeyboardNavigation = false, onFocus = undefined, onFocusLeave = undefined, onExpansion = undefined, onExpanded = undefined, onClosed = undefined, onChange = undefined, onSelection = undefined, onSelected = undefined, onUnselected = undefined, onMoved = undefined, children, nestHighlight, contextMenu } = $props();
|
|
17
|
-
let ctxMenu = $state();
|
|
18
|
-
let expandedPaths = $state([]);
|
|
19
|
-
let draggedNode = $state(null);
|
|
20
|
-
let highlightedNode = $state(null);
|
|
21
|
-
let insertionType = $state(InsertionType.none);
|
|
22
|
-
let focusedNode = $state(null);
|
|
23
12
|
export function changeAllExpansion(changeTo) {
|
|
24
13
|
debugLog("changing expansion of every node to ", changeTo ? "expanded" : "collapsed");
|
|
25
14
|
if (changeTo) {
|
|
@@ -47,10 +36,15 @@ export function setNodeExpansion(nodePath, changeTo) {
|
|
|
47
36
|
console.warn("Cannot expand node with null path");
|
|
48
37
|
return;
|
|
49
38
|
}
|
|
39
|
+
const expandedPathsBefore = $state.snapshot(expandedPaths);
|
|
50
40
|
if (changeTo === null) {
|
|
51
41
|
changeTo = !expandedPaths.includes(nodePath);
|
|
52
42
|
}
|
|
53
43
|
expandedPaths = helper.changeExpansion(nodePath, changeTo, expandedPaths);
|
|
44
|
+
console.log("Setting expansion", {
|
|
45
|
+
expandedPathsBefore: expandedPathsBefore,
|
|
46
|
+
expandedPaths: $state.snapshot(expandedPaths),
|
|
47
|
+
});
|
|
54
48
|
}
|
|
55
49
|
export function setExpansions(expansions) {
|
|
56
50
|
if (!Array.isArray(expansions)) {
|
|
@@ -77,40 +71,76 @@ export function focusFirstNode() {
|
|
|
77
71
|
onFocus?.(focusedNode);
|
|
78
72
|
return focusedNode;
|
|
79
73
|
}
|
|
74
|
+
let ctxMenu = $state();
|
|
75
|
+
let expandedPaths = $state([]);
|
|
76
|
+
let draggedNode = $state(null);
|
|
77
|
+
let highlightedNode = $state(null);
|
|
78
|
+
let insertionType = $state(InsertionType.none);
|
|
79
|
+
let focusedNode = $state(null);
|
|
80
80
|
let computedClasses = $derived({ ...defaultClasses, ...(customClasses ?? {}) });
|
|
81
|
-
$effect(() => {
|
|
82
|
-
dragAndDrop && console.warn("Drag and drop is not supported in this version");
|
|
83
|
-
});
|
|
84
81
|
let helper = $derived(new TreeHelper({
|
|
85
82
|
separator,
|
|
86
83
|
nodeSorter
|
|
87
84
|
}));
|
|
88
85
|
let dragAndDropProvider = $derived(new DragDropProvider(helper));
|
|
89
86
|
let selectionProvider = $derived(new SelectionProvider(helper, recursiveSelection));
|
|
90
|
-
let computedTree = $derived(
|
|
91
|
-
|
|
92
|
-
|
|
87
|
+
let computedTree = $derived((helper,
|
|
88
|
+
selectionProvider,
|
|
89
|
+
tree,
|
|
90
|
+
filter,
|
|
91
|
+
treeProps,
|
|
92
|
+
expandedPaths,
|
|
93
|
+
value, computeTree()));
|
|
94
|
+
$effect(() => {
|
|
95
|
+
dragAndDrop && console.warn("Drag and drop is not supported in this version");
|
|
96
|
+
});
|
|
97
|
+
function computeTree(
|
|
98
|
+
// helper: TreeHelper,
|
|
99
|
+
// selectionProvider: SelectionProvider,
|
|
100
|
+
// userProvidedTree: any[],
|
|
101
|
+
// filter: FilterFunction | null,
|
|
102
|
+
// props: Partial<TreeProps>,
|
|
103
|
+
// expandedPaths: string[],
|
|
104
|
+
// value: NodeId[]
|
|
105
|
+
) {
|
|
106
|
+
if (!Array.isArray(tree) || !Array.isArray(value)) {
|
|
93
107
|
console.error("value and tree must be arrays!!");
|
|
94
108
|
return [];
|
|
95
109
|
}
|
|
96
110
|
const start = Date.now();
|
|
97
|
-
const mappedTree = helper.mapTree(
|
|
98
|
-
const { tree: filteredTree, count: filteredCount } = helper.searchTree(mappedTree, filter);
|
|
111
|
+
const mappedTree = untrack(() => helper.mapTree(tree, { ...defaultPropNames, ...treeProps }));
|
|
112
|
+
const { tree: filteredTree, count: filteredCount } = untrack(() => helper.searchTree(mappedTree, filter));
|
|
113
|
+
console.log("threshold condition", {
|
|
114
|
+
res: (!expandedPaths?.length || filter) && filteredCount <= expansionThreshold,
|
|
115
|
+
expandedPaths: $state.snapshot(expandedPaths),
|
|
116
|
+
filter,
|
|
117
|
+
filteredCount,
|
|
118
|
+
expansionThreshold
|
|
119
|
+
});
|
|
99
120
|
// threshold applies to nodes that match the filter, not all their parents
|
|
100
|
-
if (filteredCount <= expansionThreshold) {
|
|
101
|
-
|
|
121
|
+
if ((!expandedPaths?.length || filter) && filteredCount <= expansionThreshold) {
|
|
122
|
+
untrack(() => {
|
|
123
|
+
expandedPaths = uniq([...expandedPaths, ...filteredTree.map((node) => node.path)]);
|
|
124
|
+
});
|
|
102
125
|
}
|
|
103
|
-
helper.markExpanded(filteredTree, expandedPaths);
|
|
126
|
+
untrack(() => helper.markExpanded(filteredTree, expandedPaths));
|
|
104
127
|
// TODO here we could save last value and only recompute visual state if value changed
|
|
105
128
|
// or use diff to only update affected nodes
|
|
106
|
-
selectionProvider.markSelected(filteredTree, value);
|
|
129
|
+
untrack(() => selectionProvider.markSelected(filteredTree, value));
|
|
107
130
|
const end = Date.now();
|
|
108
|
-
debugLog(`Tree computed in: ${end - start}
|
|
131
|
+
debugLog(`Tree computed in: ${end - start}`);
|
|
109
132
|
return filteredTree;
|
|
110
133
|
}
|
|
111
|
-
function onExpand(
|
|
112
|
-
const { node, changeTo } =
|
|
134
|
+
function onExpand(data) {
|
|
135
|
+
const { node, changeTo } = data;
|
|
136
|
+
console.log("expandedPaths before after expand", {
|
|
137
|
+
after: expandedPaths,
|
|
138
|
+
before: $state.snapshot(expandedPaths)
|
|
139
|
+
});
|
|
113
140
|
expandedPaths = helper.changeExpansion(node.path, changeTo, expandedPaths);
|
|
141
|
+
console.log("expandedPaths before after expand", {
|
|
142
|
+
after: $state.snapshot(expandedPaths),
|
|
143
|
+
});
|
|
114
144
|
debugLog("changed expansion of node '", node.id, "' to ", changeTo);
|
|
115
145
|
//trigger callback if it is present and node has useCallback property set to true
|
|
116
146
|
if (changeTo) {
|
|
@@ -145,8 +175,8 @@ function handleCallback(node) {
|
|
|
145
175
|
// this is now responsibility of user
|
|
146
176
|
loadChildrenAsync(node);
|
|
147
177
|
}
|
|
148
|
-
function onSelectionChanged(
|
|
149
|
-
const { node } =
|
|
178
|
+
function onSelectionChanged(data) {
|
|
179
|
+
const { node } = data;
|
|
150
180
|
const nodePath = node.path;
|
|
151
181
|
const changeTo = !selectionProvider.isNodeSelected(node);
|
|
152
182
|
const newValue = selectionProvider.setSelection(computedTree, nodePath, changeTo, value);
|
|
@@ -163,28 +193,28 @@ function onSelectionChanged(detail) {
|
|
|
163
193
|
onUnselected?.({ node, value: newValue });
|
|
164
194
|
}
|
|
165
195
|
}
|
|
166
|
-
function openContextMenu(
|
|
167
|
-
const {
|
|
196
|
+
function openContextMenu(data) {
|
|
197
|
+
const { event, node } = data;
|
|
168
198
|
if (!showContextMenu) {
|
|
169
199
|
return;
|
|
170
200
|
}
|
|
171
|
-
|
|
172
|
-
ctxMenu.onRightClick(
|
|
201
|
+
event.preventDefault();
|
|
202
|
+
ctxMenu.onRightClick(event, node);
|
|
173
203
|
}
|
|
174
|
-
function onDragStart(
|
|
175
|
-
const { node,
|
|
204
|
+
function onDragStart(data) {
|
|
205
|
+
const { node, event } = data;
|
|
176
206
|
draggedNode = null;
|
|
177
207
|
if (!dragAndDrop || node.dragDisabled) {
|
|
178
208
|
return;
|
|
179
209
|
}
|
|
180
210
|
draggedNode = node;
|
|
181
211
|
}
|
|
182
|
-
function onDragEnd({
|
|
212
|
+
function onDragEnd({ node, event, element }) {
|
|
183
213
|
// fires when you stop dragging element
|
|
184
214
|
draggedNode = null;
|
|
185
215
|
highlightedNode = null;
|
|
186
216
|
}
|
|
187
|
-
function onDragDrop({
|
|
217
|
+
function onDragDrop({ node, event, element }) {
|
|
188
218
|
// here we assume that highlightType is correctly calculated in handleDragOver
|
|
189
219
|
if (!dragAndDrop || draggedNode === null || insertionType === InsertionType.none) {
|
|
190
220
|
event.preventDefault();
|
|
@@ -199,7 +229,7 @@ function onDragDrop({ detail: { node, event, element } }) {
|
|
|
199
229
|
});
|
|
200
230
|
}
|
|
201
231
|
// handle highlighting
|
|
202
|
-
function onDragEnter({
|
|
232
|
+
function onDragEnter({ node, event, element }) {
|
|
203
233
|
highlightedNode = null;
|
|
204
234
|
if (!draggedNode || !dragAndDrop) {
|
|
205
235
|
return;
|
|
@@ -220,7 +250,7 @@ function onDragEnter({ detail: { node, event, element } }) {
|
|
|
220
250
|
highlightedNode = node;
|
|
221
251
|
}
|
|
222
252
|
}
|
|
223
|
-
function onDragOver({
|
|
253
|
+
function onDragOver({ node, event, element, nest }) {
|
|
224
254
|
if (!dragAndDrop || draggedNode === null || node.dropDisabled) {
|
|
225
255
|
return;
|
|
226
256
|
}
|
|
@@ -231,11 +261,11 @@ function onDragOver({ detail: { node, event, element, nest } }) {
|
|
|
231
261
|
event.preventDefault();
|
|
232
262
|
insertionType = insertType;
|
|
233
263
|
}
|
|
234
|
-
function onDragLeave({
|
|
264
|
+
function onDragLeave({ node, event, element }) {
|
|
235
265
|
insertionType = InsertionType.none;
|
|
236
266
|
}
|
|
237
|
-
function onKeyPress(
|
|
238
|
-
const { event, node: targetNode } =
|
|
267
|
+
function onKeyPress(data) {
|
|
268
|
+
const { event, node: targetNode } = data;
|
|
239
269
|
if (!allowKeyboardNavigation) {
|
|
240
270
|
return;
|
|
241
271
|
}
|
|
@@ -269,68 +299,73 @@ function debugLog(...data) {
|
|
|
269
299
|
}
|
|
270
300
|
</script>
|
|
271
301
|
|
|
272
|
-
<
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
{
|
|
308
|
-
|
|
309
|
-
|
|
302
|
+
<div class="treeview-parent">
|
|
303
|
+
<Branch
|
|
304
|
+
branchRootNode={null}
|
|
305
|
+
{treeId}
|
|
306
|
+
checkboxes={selectionMode}
|
|
307
|
+
tree={computedTree}
|
|
308
|
+
recursive={recursiveSelection}
|
|
309
|
+
{onlyLeafCheckboxes}
|
|
310
|
+
{hideDisabledCheckboxes}
|
|
311
|
+
{expandTo}
|
|
312
|
+
{dragAndDrop}
|
|
313
|
+
{readonly}
|
|
314
|
+
{helper}
|
|
315
|
+
classes={computedClasses}
|
|
316
|
+
{verticalLines}
|
|
317
|
+
childDepth={0}
|
|
318
|
+
{insertionType}
|
|
319
|
+
{highlightedNode}
|
|
320
|
+
{draggedNode}
|
|
321
|
+
{focusedNode}
|
|
322
|
+
{allowKeyboardNavigation}
|
|
323
|
+
{children}
|
|
324
|
+
{nestHighlight}
|
|
325
|
+
internal_onHandleDragStart={onDragStart}
|
|
326
|
+
internal_onHandleDragDrop={onDragDrop}
|
|
327
|
+
internal_onHandleDragOver={onDragOver}
|
|
328
|
+
internal_onHandleDragEnter={onDragEnter}
|
|
329
|
+
internal_onHandleDragEnd={onDragEnd}
|
|
330
|
+
internal_onHandleDragLeave={onDragLeave}
|
|
331
|
+
internal_onKeypress={onKeyPress}
|
|
332
|
+
internal_onExpand={onExpand}
|
|
333
|
+
internal_onSelectionChanged={onSelectionChanged}
|
|
334
|
+
onOpenCtxmenu={openContextMenu}
|
|
335
|
+
/>
|
|
336
|
+
<ContextMenu bind:this={ctxMenu}>
|
|
337
|
+
{#snippet children({node})}
|
|
338
|
+
{@render contextMenu?.({node})}
|
|
339
|
+
{/snippet}
|
|
340
|
+
</ContextMenu>
|
|
341
|
+
</div>
|
|
310
342
|
|
|
311
|
-
<style global>:global(.treeview) {
|
|
343
|
+
<style global>:global(.treeview-parent) {
|
|
344
|
+
color: red !important;
|
|
345
|
+
}
|
|
346
|
+
:global(.treeview-parent) :global(.treeview) {
|
|
312
347
|
padding: 0;
|
|
313
348
|
}
|
|
314
|
-
:global(.treeview.show-lines) :global(ul:before) {
|
|
349
|
+
:global(.treeview-parent) :global(.treeview.show-lines) :global(ul:before) {
|
|
315
350
|
border-left: solid black 1px;
|
|
316
351
|
}
|
|
317
|
-
:global(.treeview.show-lines) :global(ul) :global(li:before) {
|
|
352
|
+
:global(.treeview-parent) :global(.treeview.show-lines) :global(ul) :global(li:before) {
|
|
318
353
|
border-top: solid black 1px;
|
|
319
354
|
margin: 0;
|
|
320
355
|
padding: 0;
|
|
321
356
|
list-style: none;
|
|
322
357
|
}
|
|
323
|
-
:global(.treeview) :global(ul), :global(.treeview) :global(li) {
|
|
358
|
+
:global(.treeview-parent) :global(.treeview) :global(ul), :global(.treeview-parent) :global(.treeview) :global(li) {
|
|
324
359
|
margin: 0;
|
|
325
360
|
padding: 0;
|
|
326
361
|
list-style: none;
|
|
327
362
|
}
|
|
328
|
-
:global(.treeview) :global(ul) {
|
|
363
|
+
:global(.treeview-parent) :global(.treeview) :global(ul) {
|
|
329
364
|
margin-left: 0.4em;
|
|
330
365
|
position: relative;
|
|
331
366
|
margin-left: 0.3em;
|
|
332
367
|
}
|
|
333
|
-
:global(.treeview) :global(ul:before) {
|
|
368
|
+
:global(.treeview-parent) :global(.treeview) :global(ul:before) {
|
|
334
369
|
content: "";
|
|
335
370
|
display: block;
|
|
336
371
|
width: 0;
|
|
@@ -339,7 +374,7 @@ function debugLog(...data) {
|
|
|
339
374
|
bottom: 0;
|
|
340
375
|
left: 0;
|
|
341
376
|
}
|
|
342
|
-
:global(.treeview) :global(ul) :global(li:before) {
|
|
377
|
+
:global(.treeview-parent) :global(.treeview) :global(ul) :global(li:before) {
|
|
343
378
|
content: "";
|
|
344
379
|
display: block;
|
|
345
380
|
width: 10px;
|
|
@@ -349,48 +384,48 @@ function debugLog(...data) {
|
|
|
349
384
|
top: 0.8em;
|
|
350
385
|
left: 0;
|
|
351
386
|
}
|
|
352
|
-
:global(.treeview) :global(ul) :global(li:not(.has-children):before) {
|
|
387
|
+
:global(.treeview-parent) :global(.treeview) :global(ul) :global(li:not(.has-children):before) {
|
|
353
388
|
width: 26px;
|
|
354
389
|
}
|
|
355
|
-
:global(.treeview) :global(ul) :global(li:last-child:before) {
|
|
390
|
+
:global(.treeview-parent) :global(.treeview) :global(ul) :global(li:last-child:before) {
|
|
356
391
|
background: #fff;
|
|
357
392
|
height: auto;
|
|
358
393
|
top: 1em;
|
|
359
394
|
bottom: 0;
|
|
360
395
|
}
|
|
361
|
-
:global(.treeview) :global(li) {
|
|
396
|
+
:global(.treeview-parent) :global(.treeview) :global(li) {
|
|
362
397
|
margin: 0;
|
|
363
|
-
padding: 0 0.
|
|
398
|
+
padding: 0 0.8e;
|
|
364
399
|
color: #555;
|
|
365
|
-
font-weight:
|
|
366
|
-
position:
|
|
400
|
+
font-weight: 70;
|
|
401
|
+
position: relat;
|
|
367
402
|
}
|
|
368
|
-
:global(.treeview) :global(.tree-item) {
|
|
403
|
+
:global(.treeview-parent) :global(.treeview) :global(.tree-item) {
|
|
369
404
|
display: flex;
|
|
370
405
|
column-gap: 0.4em;
|
|
371
406
|
align-items: center;
|
|
372
407
|
padding: 4px 0;
|
|
373
408
|
}
|
|
374
|
-
:global(.treeview) :global(.no-arrow) {
|
|
409
|
+
:global(.treeview-parent) :global(.treeview) :global(.no-arrow) {
|
|
375
410
|
padding-left: 0.5rem;
|
|
376
411
|
}
|
|
377
|
-
:global(.treeview) :global(.arrow) {
|
|
412
|
+
:global(.treeview-parent) :global(.treeview) :global(.arrow) {
|
|
378
413
|
cursor: pointer;
|
|
379
414
|
display: inline-block;
|
|
380
415
|
}
|
|
381
|
-
:global(.treeview) :global(.arrowDown) {
|
|
416
|
+
:global(.treeview-parent) :global(.treeview) :global(.arrowDown) {
|
|
382
417
|
transform: rotate(90deg);
|
|
383
418
|
}
|
|
384
|
-
:global(.treeview) :global(.invisible) {
|
|
419
|
+
:global(.treeview-parent) :global(.treeview) :global(.invisible) {
|
|
385
420
|
visibility: hidden;
|
|
386
421
|
}
|
|
387
|
-
:global(.treeview) :global(.inserting-highlighted) {
|
|
422
|
+
:global(.treeview-parent) :global(.treeview) :global(.inserting-highlighted) {
|
|
388
423
|
color: red;
|
|
389
424
|
}
|
|
390
|
-
:global(.treeview) :global(.hover) {
|
|
425
|
+
:global(.treeview-parent) :global(.treeview) :global(.hover) {
|
|
391
426
|
font-weight: bold;
|
|
392
427
|
}
|
|
393
|
-
:global(.treeview) :global(.insert-line) {
|
|
428
|
+
:global(.treeview-parent) :global(.treeview) :global(.insert-line) {
|
|
394
429
|
position: absolute;
|
|
395
430
|
left: 0;
|
|
396
431
|
z-index: 99;
|
|
@@ -402,24 +437,24 @@ function debugLog(...data) {
|
|
|
402
437
|
margin-left: 28px;
|
|
403
438
|
pointer-events: none;
|
|
404
439
|
}
|
|
405
|
-
:global(.treeview) :global(.insert-line-child) {
|
|
440
|
+
:global(.treeview-parent) :global(.treeview) :global(.insert-line-child) {
|
|
406
441
|
margin-left: calc(28px + 5em);
|
|
407
442
|
background-color: red;
|
|
408
443
|
height: 6px;
|
|
409
444
|
}
|
|
410
|
-
:global(.treeview) :global(.insert-line-wrapper) {
|
|
445
|
+
:global(.treeview-parent) :global(.treeview) :global(.insert-line-wrapper) {
|
|
411
446
|
position: relative;
|
|
412
447
|
}
|
|
413
|
-
:global(.treeview) :global(.currently-dragged) {
|
|
448
|
+
:global(.treeview-parent) :global(.treeview) :global(.currently-dragged) {
|
|
414
449
|
color: LightGray;
|
|
415
450
|
}
|
|
416
|
-
:global(.treeview) :global(.pointer-cursor) {
|
|
451
|
+
:global(.treeview-parent) :global(.treeview) :global(.pointer-cursor) {
|
|
417
452
|
cursor: grab;
|
|
418
453
|
}
|
|
419
|
-
:global(.treeview) :global(.expansion-button) {
|
|
454
|
+
:global(.treeview-parent) :global(.treeview) :global(.expansion-button) {
|
|
420
455
|
all: unset;
|
|
421
456
|
}
|
|
422
|
-
:global(.treeview) :global(.fixed-icon) {
|
|
457
|
+
:global(.treeview-parent) :global(.treeview) :global(.fixed-icon) {
|
|
423
458
|
text-align: center;
|
|
424
459
|
width: 1.25em;
|
|
425
460
|
min-width: 1.25em;
|
|
@@ -32,11 +32,9 @@ export class TreeHelper {
|
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
markExpanded(tree, expandedPaths) {
|
|
35
|
-
{
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
});
|
|
39
|
-
}
|
|
35
|
+
tree.forEach((node) => {
|
|
36
|
+
node.expanded = expandedPaths.includes(node.path ?? "");
|
|
37
|
+
});
|
|
40
38
|
}
|
|
41
39
|
//#region basic helpers
|
|
42
40
|
getParentNodePath(nodePath) {
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
$treeview-lines: solid black 1px;
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
.treeview {
|
|
5
|
+
padding: 0;
|
|
6
|
+
//will show lines if you set show-lines to root element
|
|
7
|
+
&.show-lines {
|
|
8
|
+
ul {
|
|
9
|
+
&:before {
|
|
10
|
+
border-left: $treeview-lines;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
li:before {
|
|
14
|
+
border-top: $treeview-lines;
|
|
15
|
+
margin: 0;
|
|
16
|
+
padding: 0;
|
|
17
|
+
list-style: none;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
ul, li {
|
|
23
|
+
margin: 0;
|
|
24
|
+
padding: 0;
|
|
25
|
+
list-style: none;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
ul {
|
|
29
|
+
margin-left: 0.4em;
|
|
30
|
+
position: relative;
|
|
31
|
+
margin-left: .3em;
|
|
32
|
+
|
|
33
|
+
&:before {
|
|
34
|
+
content: "";
|
|
35
|
+
display: block;
|
|
36
|
+
width: 0;
|
|
37
|
+
position: absolute;
|
|
38
|
+
top: 0;
|
|
39
|
+
bottom: 0;
|
|
40
|
+
left: 0;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
li:before {
|
|
44
|
+
content: "";
|
|
45
|
+
display: block;
|
|
46
|
+
width: 10px;
|
|
47
|
+
height: 0;
|
|
48
|
+
margin-top: -1px;
|
|
49
|
+
position: absolute;
|
|
50
|
+
top: 0.8em;
|
|
51
|
+
left: 0;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
li:not(.has-children):before {
|
|
55
|
+
width: 26px;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
li:last-child:before {
|
|
59
|
+
background: #fff;
|
|
60
|
+
height: auto;
|
|
61
|
+
top: 1em;
|
|
62
|
+
bottom: 0;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
li {
|
|
67
|
+
margin: 0;
|
|
68
|
+
padding: 0 0.8e;
|
|
69
|
+
color: #555;
|
|
70
|
+
font-weight: 70;
|
|
71
|
+
position: relat;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.tree-item {
|
|
75
|
+
display: flex;
|
|
76
|
+
column-gap: 0.4em;
|
|
77
|
+
align-items: center;
|
|
78
|
+
padding: 4px 0;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
.no-arrow {
|
|
82
|
+
padding-left: .5rem;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
.arrow {
|
|
86
|
+
cursor: pointer;
|
|
87
|
+
display: inline-block;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
.arrowDown {
|
|
91
|
+
transform: rotate(90deg);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
.invisible {
|
|
95
|
+
visibility: hidden;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.inserting-highlighted {
|
|
99
|
+
color: red;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
.hover {
|
|
103
|
+
font-weight: bold;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
.insert-line {
|
|
107
|
+
position: absolute;
|
|
108
|
+
left: 0;
|
|
109
|
+
z-index: 99;
|
|
110
|
+
height: 2px;
|
|
111
|
+
width: 200px;
|
|
112
|
+
background-color: blue;
|
|
113
|
+
display: block;
|
|
114
|
+
border-radius: 3px;
|
|
115
|
+
margin-left: 28px;
|
|
116
|
+
pointer-events: none;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
//! this is needed to fix flickering issue
|
|
120
|
+
// margin-bottom: -2px
|
|
121
|
+
// margin-top: -2px
|
|
122
|
+
.insert-line-child {
|
|
123
|
+
margin-left: calc(28px + 5em);
|
|
124
|
+
background-color: red;
|
|
125
|
+
height: 6px;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
.insert-line-wrapper {
|
|
129
|
+
position: relative;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
.currently-dragged {
|
|
133
|
+
color: LightGray;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
.pointer-cursor {
|
|
137
|
+
cursor: grab;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
.expansion-button {
|
|
141
|
+
all: unset;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
.fixed-icon {
|
|
145
|
+
text-align: center;
|
|
146
|
+
width: 1.25em;
|
|
147
|
+
// fix deformation on small screens
|
|
148
|
+
min-width: 1.25em;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@keenmate/svelte-treeview",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.1",
|
|
4
4
|
"repository": {
|
|
5
5
|
"url": "https://github.com/keenmate/svelte-treeview"
|
|
6
6
|
},
|
|
@@ -22,6 +22,9 @@
|
|
|
22
22
|
".": {
|
|
23
23
|
"types": "./dist/index.d.ts",
|
|
24
24
|
"svelte": "./dist/index.js"
|
|
25
|
+
},
|
|
26
|
+
"./*": {
|
|
27
|
+
"import": "./dist/*"
|
|
25
28
|
}
|
|
26
29
|
},
|
|
27
30
|
"files": [
|
package/dist/tree-styles.sass
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
$treeview-lines: solid black 1px
|
|
2
|
-
.treeview
|
|
3
|
-
padding: 0
|
|
4
|
-
//will show lines if you set show-lines to root element
|
|
5
|
-
&.show-lines
|
|
6
|
-
ul
|
|
7
|
-
&:before
|
|
8
|
-
border-left: $treeview-lines
|
|
9
|
-
|
|
10
|
-
li:before
|
|
11
|
-
border-top: $treeview-lines
|
|
12
|
-
margin: 0
|
|
13
|
-
padding: 0
|
|
14
|
-
list-style: none
|
|
15
|
-
|
|
16
|
-
ul, li
|
|
17
|
-
margin: 0
|
|
18
|
-
padding: 0
|
|
19
|
-
list-style: none
|
|
20
|
-
|
|
21
|
-
ul
|
|
22
|
-
margin-left: 0.4em
|
|
23
|
-
position: relative
|
|
24
|
-
margin-left: .3em
|
|
25
|
-
|
|
26
|
-
&:before
|
|
27
|
-
content: ""
|
|
28
|
-
display: block
|
|
29
|
-
width: 0
|
|
30
|
-
position: absolute
|
|
31
|
-
top: 0
|
|
32
|
-
bottom: 0
|
|
33
|
-
left: 0
|
|
34
|
-
|
|
35
|
-
li:before
|
|
36
|
-
content: ""
|
|
37
|
-
display: block
|
|
38
|
-
width: 10px
|
|
39
|
-
height: 0
|
|
40
|
-
margin-top: -1px
|
|
41
|
-
position: absolute
|
|
42
|
-
top: 0.8em
|
|
43
|
-
left: 0
|
|
44
|
-
|
|
45
|
-
li:not(.has-children):before
|
|
46
|
-
width: 26px
|
|
47
|
-
|
|
48
|
-
li:last-child:before
|
|
49
|
-
background: #fff
|
|
50
|
-
height: auto
|
|
51
|
-
top: 1em
|
|
52
|
-
bottom: 0
|
|
53
|
-
|
|
54
|
-
li
|
|
55
|
-
margin: 0
|
|
56
|
-
padding: 0 0.8em
|
|
57
|
-
color: #555
|
|
58
|
-
font-weight: 700
|
|
59
|
-
position: relative
|
|
60
|
-
|
|
61
|
-
.tree-item
|
|
62
|
-
display: flex
|
|
63
|
-
column-gap: 0.4em
|
|
64
|
-
align-items: center
|
|
65
|
-
padding: 4px 0
|
|
66
|
-
|
|
67
|
-
.no-arrow
|
|
68
|
-
padding-left: .5rem
|
|
69
|
-
|
|
70
|
-
.arrow
|
|
71
|
-
cursor: pointer
|
|
72
|
-
display: inline-block
|
|
73
|
-
|
|
74
|
-
.arrowDown
|
|
75
|
-
transform: rotate(90deg)
|
|
76
|
-
|
|
77
|
-
.invisible
|
|
78
|
-
visibility: hidden
|
|
79
|
-
|
|
80
|
-
.inserting-highlighted
|
|
81
|
-
color: red
|
|
82
|
-
|
|
83
|
-
.hover
|
|
84
|
-
font-weight: bold
|
|
85
|
-
|
|
86
|
-
.insert-line
|
|
87
|
-
position: absolute
|
|
88
|
-
left: 0
|
|
89
|
-
z-index: 99
|
|
90
|
-
height: 2px
|
|
91
|
-
width: 200px
|
|
92
|
-
background-color: blue
|
|
93
|
-
display: block
|
|
94
|
-
border-radius: 3px
|
|
95
|
-
margin-left: 28px
|
|
96
|
-
pointer-events: none
|
|
97
|
-
//! this is needed to fix flickering issue
|
|
98
|
-
// margin-bottom: -2px
|
|
99
|
-
// margin-top: -2px
|
|
100
|
-
.insert-line-child
|
|
101
|
-
margin-left: calc(28px + 5em)
|
|
102
|
-
background-color: red
|
|
103
|
-
height: 6px
|
|
104
|
-
|
|
105
|
-
.insert-line-wrapper
|
|
106
|
-
position: relative
|
|
107
|
-
|
|
108
|
-
.currently-dragged
|
|
109
|
-
color: LightGray
|
|
110
|
-
|
|
111
|
-
.pointer-cursor
|
|
112
|
-
cursor: grab
|
|
113
|
-
|
|
114
|
-
.expansion-button
|
|
115
|
-
all: unset
|
|
116
|
-
|
|
117
|
-
.fixed-icon
|
|
118
|
-
text-align: center
|
|
119
|
-
width: 1.25em
|
|
120
|
-
// fix deformation on small screens
|
|
121
|
-
min-width: 1.25em
|