@keenmate/svelte-treeview 3.0.0 → 3.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/Branch.svelte +14 -20
- package/dist/Branch.svelte.d.ts +68 -2
- package/dist/TreeView.svelte +101 -97
- 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";
|
|
@@ -14,12 +8,6 @@ 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";
|
|
16
10
|
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
11
|
export function changeAllExpansion(changeTo) {
|
|
24
12
|
debugLog("changing expansion of every node to ", changeTo ? "expanded" : "collapsed");
|
|
25
13
|
if (changeTo) {
|
|
@@ -47,10 +35,15 @@ export function setNodeExpansion(nodePath, changeTo) {
|
|
|
47
35
|
console.warn("Cannot expand node with null path");
|
|
48
36
|
return;
|
|
49
37
|
}
|
|
38
|
+
const expandedPathsBefore = $state.snapshot(expandedPaths);
|
|
50
39
|
if (changeTo === null) {
|
|
51
40
|
changeTo = !expandedPaths.includes(nodePath);
|
|
52
41
|
}
|
|
53
42
|
expandedPaths = helper.changeExpansion(nodePath, changeTo, expandedPaths);
|
|
43
|
+
console.log("Setting expansion", {
|
|
44
|
+
expandedPathsBefore: expandedPathsBefore,
|
|
45
|
+
expandedPaths: $state.snapshot(expandedPaths),
|
|
46
|
+
});
|
|
54
47
|
}
|
|
55
48
|
export function setExpansions(expansions) {
|
|
56
49
|
if (!Array.isArray(expansions)) {
|
|
@@ -77,10 +70,13 @@ export function focusFirstNode() {
|
|
|
77
70
|
onFocus?.(focusedNode);
|
|
78
71
|
return focusedNode;
|
|
79
72
|
}
|
|
73
|
+
let ctxMenu = $state();
|
|
74
|
+
let expandedPaths = $state([]);
|
|
75
|
+
let draggedNode = $state(null);
|
|
76
|
+
let highlightedNode = $state(null);
|
|
77
|
+
let insertionType = $state(InsertionType.none);
|
|
78
|
+
let focusedNode = $state(null);
|
|
80
79
|
let computedClasses = $derived({ ...defaultClasses, ...(customClasses ?? {}) });
|
|
81
|
-
$effect(() => {
|
|
82
|
-
dragAndDrop && console.warn("Drag and drop is not supported in this version");
|
|
83
|
-
});
|
|
84
80
|
let helper = $derived(new TreeHelper({
|
|
85
81
|
separator,
|
|
86
82
|
nodeSorter
|
|
@@ -88,6 +84,9 @@ let helper = $derived(new TreeHelper({
|
|
|
88
84
|
let dragAndDropProvider = $derived(new DragDropProvider(helper));
|
|
89
85
|
let selectionProvider = $derived(new SelectionProvider(helper, recursiveSelection));
|
|
90
86
|
let computedTree = $derived(computeTree(helper, selectionProvider, tree, filter, treeProps, expandedPaths, value));
|
|
87
|
+
$effect(() => {
|
|
88
|
+
dragAndDrop && console.warn("Drag and drop is not supported in this version");
|
|
89
|
+
});
|
|
91
90
|
function computeTree(helper, selectionProvider, userProvidedTree, filter, props, expandedPaths, value) {
|
|
92
91
|
if (!Array.isArray(userProvidedTree) || !Array.isArray(value)) {
|
|
93
92
|
console.error("value and tree must be arrays!!");
|
|
@@ -108,8 +107,8 @@ function computeTree(helper, selectionProvider, userProvidedTree, filter, props,
|
|
|
108
107
|
debugLog(`Tree computed in: ${end - start}`, computeTree);
|
|
109
108
|
return filteredTree;
|
|
110
109
|
}
|
|
111
|
-
function onExpand(
|
|
112
|
-
const { node, changeTo } =
|
|
110
|
+
function onExpand(data) {
|
|
111
|
+
const { node, changeTo } = data;
|
|
113
112
|
expandedPaths = helper.changeExpansion(node.path, changeTo, expandedPaths);
|
|
114
113
|
debugLog("changed expansion of node '", node.id, "' to ", changeTo);
|
|
115
114
|
//trigger callback if it is present and node has useCallback property set to true
|
|
@@ -145,8 +144,8 @@ function handleCallback(node) {
|
|
|
145
144
|
// this is now responsibility of user
|
|
146
145
|
loadChildrenAsync(node);
|
|
147
146
|
}
|
|
148
|
-
function onSelectionChanged(
|
|
149
|
-
const { node } =
|
|
147
|
+
function onSelectionChanged(data) {
|
|
148
|
+
const { node } = data;
|
|
150
149
|
const nodePath = node.path;
|
|
151
150
|
const changeTo = !selectionProvider.isNodeSelected(node);
|
|
152
151
|
const newValue = selectionProvider.setSelection(computedTree, nodePath, changeTo, value);
|
|
@@ -163,28 +162,28 @@ function onSelectionChanged(detail) {
|
|
|
163
162
|
onUnselected?.({ node, value: newValue });
|
|
164
163
|
}
|
|
165
164
|
}
|
|
166
|
-
function openContextMenu(
|
|
167
|
-
const {
|
|
165
|
+
function openContextMenu(data) {
|
|
166
|
+
const { event, node } = data;
|
|
168
167
|
if (!showContextMenu) {
|
|
169
168
|
return;
|
|
170
169
|
}
|
|
171
|
-
|
|
172
|
-
ctxMenu.onRightClick(
|
|
170
|
+
event.preventDefault();
|
|
171
|
+
ctxMenu.onRightClick(event, node);
|
|
173
172
|
}
|
|
174
|
-
function onDragStart(
|
|
175
|
-
const { node,
|
|
173
|
+
function onDragStart(data) {
|
|
174
|
+
const { node, event } = data;
|
|
176
175
|
draggedNode = null;
|
|
177
176
|
if (!dragAndDrop || node.dragDisabled) {
|
|
178
177
|
return;
|
|
179
178
|
}
|
|
180
179
|
draggedNode = node;
|
|
181
180
|
}
|
|
182
|
-
function onDragEnd({
|
|
181
|
+
function onDragEnd({ node, event, element }) {
|
|
183
182
|
// fires when you stop dragging element
|
|
184
183
|
draggedNode = null;
|
|
185
184
|
highlightedNode = null;
|
|
186
185
|
}
|
|
187
|
-
function onDragDrop({
|
|
186
|
+
function onDragDrop({ node, event, element }) {
|
|
188
187
|
// here we assume that highlightType is correctly calculated in handleDragOver
|
|
189
188
|
if (!dragAndDrop || draggedNode === null || insertionType === InsertionType.none) {
|
|
190
189
|
event.preventDefault();
|
|
@@ -199,7 +198,7 @@ function onDragDrop({ detail: { node, event, element } }) {
|
|
|
199
198
|
});
|
|
200
199
|
}
|
|
201
200
|
// handle highlighting
|
|
202
|
-
function onDragEnter({
|
|
201
|
+
function onDragEnter({ node, event, element }) {
|
|
203
202
|
highlightedNode = null;
|
|
204
203
|
if (!draggedNode || !dragAndDrop) {
|
|
205
204
|
return;
|
|
@@ -220,7 +219,7 @@ function onDragEnter({ detail: { node, event, element } }) {
|
|
|
220
219
|
highlightedNode = node;
|
|
221
220
|
}
|
|
222
221
|
}
|
|
223
|
-
function onDragOver({
|
|
222
|
+
function onDragOver({ node, event, element, nest }) {
|
|
224
223
|
if (!dragAndDrop || draggedNode === null || node.dropDisabled) {
|
|
225
224
|
return;
|
|
226
225
|
}
|
|
@@ -231,11 +230,11 @@ function onDragOver({ detail: { node, event, element, nest } }) {
|
|
|
231
230
|
event.preventDefault();
|
|
232
231
|
insertionType = insertType;
|
|
233
232
|
}
|
|
234
|
-
function onDragLeave({
|
|
233
|
+
function onDragLeave({ node, event, element }) {
|
|
235
234
|
insertionType = InsertionType.none;
|
|
236
235
|
}
|
|
237
|
-
function onKeyPress(
|
|
238
|
-
const { event, node: targetNode } =
|
|
236
|
+
function onKeyPress(data) {
|
|
237
|
+
const { event, node: targetNode } = data;
|
|
239
238
|
if (!allowKeyboardNavigation) {
|
|
240
239
|
return;
|
|
241
240
|
}
|
|
@@ -269,68 +268,73 @@ function debugLog(...data) {
|
|
|
269
268
|
}
|
|
270
269
|
</script>
|
|
271
270
|
|
|
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
|
-
|
|
271
|
+
<div class="treeview-parent">
|
|
272
|
+
<Branch
|
|
273
|
+
branchRootNode={null}
|
|
274
|
+
{treeId}
|
|
275
|
+
checkboxes={selectionMode}
|
|
276
|
+
tree={computedTree}
|
|
277
|
+
recursive={recursiveSelection}
|
|
278
|
+
{onlyLeafCheckboxes}
|
|
279
|
+
{hideDisabledCheckboxes}
|
|
280
|
+
{expandTo}
|
|
281
|
+
{dragAndDrop}
|
|
282
|
+
{readonly}
|
|
283
|
+
{helper}
|
|
284
|
+
classes={computedClasses}
|
|
285
|
+
{verticalLines}
|
|
286
|
+
childDepth={0}
|
|
287
|
+
{insertionType}
|
|
288
|
+
{highlightedNode}
|
|
289
|
+
{draggedNode}
|
|
290
|
+
{focusedNode}
|
|
291
|
+
{allowKeyboardNavigation}
|
|
292
|
+
{children}
|
|
293
|
+
{nestHighlight}
|
|
294
|
+
internal_onHandleDragStart={onDragStart}
|
|
295
|
+
internal_onHandleDragDrop={onDragDrop}
|
|
296
|
+
internal_onHandleDragOver={onDragOver}
|
|
297
|
+
internal_onHandleDragEnter={onDragEnter}
|
|
298
|
+
internal_onHandleDragEnd={onDragEnd}
|
|
299
|
+
internal_onHandleDragLeave={onDragLeave}
|
|
300
|
+
internal_onKeypress={onKeyPress}
|
|
301
|
+
internal_onExpand={onExpand}
|
|
302
|
+
internal_onSelectionChanged={onSelectionChanged}
|
|
303
|
+
onOpenCtxmenu={openContextMenu}
|
|
304
|
+
/>
|
|
305
|
+
<ContextMenu bind:this={ctxMenu}>
|
|
306
|
+
{#snippet children({node})}
|
|
307
|
+
{@render contextMenu?.({node})}
|
|
308
|
+
{/snippet}
|
|
309
|
+
</ContextMenu>
|
|
310
|
+
</div>
|
|
310
311
|
|
|
311
|
-
<style global>:global(.treeview) {
|
|
312
|
+
<style global>:global(.treeview-parent) {
|
|
313
|
+
color: red !important;
|
|
314
|
+
}
|
|
315
|
+
:global(.treeview-parent) :global(.treeview) {
|
|
312
316
|
padding: 0;
|
|
313
317
|
}
|
|
314
|
-
:global(.treeview.show-lines) :global(ul:before) {
|
|
318
|
+
:global(.treeview-parent) :global(.treeview.show-lines) :global(ul:before) {
|
|
315
319
|
border-left: solid black 1px;
|
|
316
320
|
}
|
|
317
|
-
:global(.treeview.show-lines) :global(ul) :global(li:before) {
|
|
321
|
+
:global(.treeview-parent) :global(.treeview.show-lines) :global(ul) :global(li:before) {
|
|
318
322
|
border-top: solid black 1px;
|
|
319
323
|
margin: 0;
|
|
320
324
|
padding: 0;
|
|
321
325
|
list-style: none;
|
|
322
326
|
}
|
|
323
|
-
:global(.treeview) :global(ul), :global(.treeview) :global(li) {
|
|
327
|
+
:global(.treeview-parent) :global(.treeview) :global(ul), :global(.treeview-parent) :global(.treeview) :global(li) {
|
|
324
328
|
margin: 0;
|
|
325
329
|
padding: 0;
|
|
326
330
|
list-style: none;
|
|
327
331
|
}
|
|
328
|
-
:global(.treeview) :global(ul) {
|
|
332
|
+
:global(.treeview-parent) :global(.treeview) :global(ul) {
|
|
329
333
|
margin-left: 0.4em;
|
|
330
334
|
position: relative;
|
|
331
335
|
margin-left: 0.3em;
|
|
332
336
|
}
|
|
333
|
-
:global(.treeview) :global(ul:before) {
|
|
337
|
+
:global(.treeview-parent) :global(.treeview) :global(ul:before) {
|
|
334
338
|
content: "";
|
|
335
339
|
display: block;
|
|
336
340
|
width: 0;
|
|
@@ -339,7 +343,7 @@ function debugLog(...data) {
|
|
|
339
343
|
bottom: 0;
|
|
340
344
|
left: 0;
|
|
341
345
|
}
|
|
342
|
-
:global(.treeview) :global(ul) :global(li:before) {
|
|
346
|
+
:global(.treeview-parent) :global(.treeview) :global(ul) :global(li:before) {
|
|
343
347
|
content: "";
|
|
344
348
|
display: block;
|
|
345
349
|
width: 10px;
|
|
@@ -349,48 +353,48 @@ function debugLog(...data) {
|
|
|
349
353
|
top: 0.8em;
|
|
350
354
|
left: 0;
|
|
351
355
|
}
|
|
352
|
-
:global(.treeview) :global(ul) :global(li:not(.has-children):before) {
|
|
356
|
+
:global(.treeview-parent) :global(.treeview) :global(ul) :global(li:not(.has-children):before) {
|
|
353
357
|
width: 26px;
|
|
354
358
|
}
|
|
355
|
-
:global(.treeview) :global(ul) :global(li:last-child:before) {
|
|
359
|
+
:global(.treeview-parent) :global(.treeview) :global(ul) :global(li:last-child:before) {
|
|
356
360
|
background: #fff;
|
|
357
361
|
height: auto;
|
|
358
362
|
top: 1em;
|
|
359
363
|
bottom: 0;
|
|
360
364
|
}
|
|
361
|
-
:global(.treeview) :global(li) {
|
|
365
|
+
:global(.treeview-parent) :global(.treeview) :global(li) {
|
|
362
366
|
margin: 0;
|
|
363
|
-
padding: 0 0.
|
|
367
|
+
padding: 0 0.8e;
|
|
364
368
|
color: #555;
|
|
365
|
-
font-weight:
|
|
366
|
-
position:
|
|
369
|
+
font-weight: 70;
|
|
370
|
+
position: relat;
|
|
367
371
|
}
|
|
368
|
-
:global(.treeview) :global(.tree-item) {
|
|
372
|
+
:global(.treeview-parent) :global(.treeview) :global(.tree-item) {
|
|
369
373
|
display: flex;
|
|
370
374
|
column-gap: 0.4em;
|
|
371
375
|
align-items: center;
|
|
372
376
|
padding: 4px 0;
|
|
373
377
|
}
|
|
374
|
-
:global(.treeview) :global(.no-arrow) {
|
|
378
|
+
:global(.treeview-parent) :global(.treeview) :global(.no-arrow) {
|
|
375
379
|
padding-left: 0.5rem;
|
|
376
380
|
}
|
|
377
|
-
:global(.treeview) :global(.arrow) {
|
|
381
|
+
:global(.treeview-parent) :global(.treeview) :global(.arrow) {
|
|
378
382
|
cursor: pointer;
|
|
379
383
|
display: inline-block;
|
|
380
384
|
}
|
|
381
|
-
:global(.treeview) :global(.arrowDown) {
|
|
385
|
+
:global(.treeview-parent) :global(.treeview) :global(.arrowDown) {
|
|
382
386
|
transform: rotate(90deg);
|
|
383
387
|
}
|
|
384
|
-
:global(.treeview) :global(.invisible) {
|
|
388
|
+
:global(.treeview-parent) :global(.treeview) :global(.invisible) {
|
|
385
389
|
visibility: hidden;
|
|
386
390
|
}
|
|
387
|
-
:global(.treeview) :global(.inserting-highlighted) {
|
|
391
|
+
:global(.treeview-parent) :global(.treeview) :global(.inserting-highlighted) {
|
|
388
392
|
color: red;
|
|
389
393
|
}
|
|
390
|
-
:global(.treeview) :global(.hover) {
|
|
394
|
+
:global(.treeview-parent) :global(.treeview) :global(.hover) {
|
|
391
395
|
font-weight: bold;
|
|
392
396
|
}
|
|
393
|
-
:global(.treeview) :global(.insert-line) {
|
|
397
|
+
:global(.treeview-parent) :global(.treeview) :global(.insert-line) {
|
|
394
398
|
position: absolute;
|
|
395
399
|
left: 0;
|
|
396
400
|
z-index: 99;
|
|
@@ -402,24 +406,24 @@ function debugLog(...data) {
|
|
|
402
406
|
margin-left: 28px;
|
|
403
407
|
pointer-events: none;
|
|
404
408
|
}
|
|
405
|
-
:global(.treeview) :global(.insert-line-child) {
|
|
409
|
+
:global(.treeview-parent) :global(.treeview) :global(.insert-line-child) {
|
|
406
410
|
margin-left: calc(28px + 5em);
|
|
407
411
|
background-color: red;
|
|
408
412
|
height: 6px;
|
|
409
413
|
}
|
|
410
|
-
:global(.treeview) :global(.insert-line-wrapper) {
|
|
414
|
+
:global(.treeview-parent) :global(.treeview) :global(.insert-line-wrapper) {
|
|
411
415
|
position: relative;
|
|
412
416
|
}
|
|
413
|
-
:global(.treeview) :global(.currently-dragged) {
|
|
417
|
+
:global(.treeview-parent) :global(.treeview) :global(.currently-dragged) {
|
|
414
418
|
color: LightGray;
|
|
415
419
|
}
|
|
416
|
-
:global(.treeview) :global(.pointer-cursor) {
|
|
420
|
+
:global(.treeview-parent) :global(.treeview) :global(.pointer-cursor) {
|
|
417
421
|
cursor: grab;
|
|
418
422
|
}
|
|
419
|
-
:global(.treeview) :global(.expansion-button) {
|
|
423
|
+
:global(.treeview-parent) :global(.treeview) :global(.expansion-button) {
|
|
420
424
|
all: unset;
|
|
421
425
|
}
|
|
422
|
-
:global(.treeview) :global(.fixed-icon) {
|
|
426
|
+
:global(.treeview-parent) :global(.treeview) :global(.fixed-icon) {
|
|
423
427
|
text-align: center;
|
|
424
428
|
width: 1.25em;
|
|
425
429
|
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.0",
|
|
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
|