@keenmate/svelte-treeview 1.1.1 → 1.1.2
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/README.md +1 -1
- package/dist/Branch.svelte +2 -2
- package/dist/TreeView.svelte +14 -14
- package/dist/TreeView.svelte.d.ts +7 -7
- package/dist/constants.js +1 -1
- package/dist/providers/drag-drop-provider.d.ts +1 -1
- package/dist/providers/drag-drop-provider.js +1 -1
- package/dist/providers/movement-provider.js +1 -1
- package/dist/providers/selection-provider.js +3 -3
- package/dist/types.d.ts +3 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -68,7 +68,7 @@ For more examples see `src/routes/`
|
|
|
68
68
|
| hideDisabledCheckboxes | bool | false | hides checkboxes instead of disabling, see [Selection](#selection) |
|
|
69
69
|
| loadChildrenAsync | ExpandedCallback | null | function that is called when node is expanded, see [Async loading](#async-loading) |
|
|
70
70
|
| showContextMenu | bool | false | On right click dispaly context menu defined in `context-menu` slot, see [Context menu](#context-menu) |
|
|
71
|
-
|
|
|
71
|
+
| expansionThreshold | number | 0 | Expand all nodes when there is less than number provided |
|
|
72
72
|
| customClasses | Partial<CustomizableClasses> | {} | changes classes used on same elements, see [Custom classes](#custom-classes) |
|
|
73
73
|
| filter | (node: Node) => boolean or null | null | function that is used for fitlering. It is called on every node |
|
|
74
74
|
| dragAndDrop | bool | false | enables drag and drop, see [Drag and drop](#drag-and-drop) |
|
package/dist/Branch.svelte
CHANGED
|
@@ -105,7 +105,7 @@ function getHighlighMode(node, highlightedNode, insertionType) {
|
|
|
105
105
|
>
|
|
106
106
|
{#if effectiveHighlight == InsertionType.insertAbove}
|
|
107
107
|
<div class="insert-line-wrapper">
|
|
108
|
-
<div class="insert-line {classes.
|
|
108
|
+
<div class="insert-line {classes.insertLineClass}" />
|
|
109
109
|
</div>
|
|
110
110
|
{/if}
|
|
111
111
|
|
|
@@ -204,7 +204,7 @@ function getHighlighMode(node, highlightedNode, insertionType) {
|
|
|
204
204
|
<!-- Show line if insering -->
|
|
205
205
|
{#if effectiveHighlight === InsertionType.insertBelow}
|
|
206
206
|
<div class="insert-line-wrapper">
|
|
207
|
-
<div class="insert-line {classes.
|
|
207
|
+
<div class="insert-line {classes.insertLineClass}" />
|
|
208
208
|
</div>
|
|
209
209
|
{/if}
|
|
210
210
|
</li>
|
package/dist/TreeView.svelte
CHANGED
|
@@ -50,8 +50,8 @@ export let recursiveSelection = false;
|
|
|
50
50
|
*/
|
|
51
51
|
export let selectionMode = SelectionModes.none;
|
|
52
52
|
/**
|
|
53
|
-
* By default, in recursive mode, non-leaf checkboxes will select/
|
|
54
|
-
* If you set this to true, this
|
|
53
|
+
* By default, in recursive mode, non-leaf checkboxes will select/deselect all its children
|
|
54
|
+
* If you set this to true, this behavior will be disabled and only leaf nodes will be selectable
|
|
55
55
|
*/
|
|
56
56
|
export let onlyLeafCheckboxes = false; //bool
|
|
57
57
|
/**
|
|
@@ -59,7 +59,7 @@ export let onlyLeafCheckboxes = false; //bool
|
|
|
59
59
|
*/
|
|
60
60
|
export let hideDisabledCheckboxes = false; //bool
|
|
61
61
|
/**
|
|
62
|
-
* Function that will be
|
|
62
|
+
* Function that will be caged when node is expanded and useCallback is set to true
|
|
63
63
|
* It should return array of nodes that will be added to tree
|
|
64
64
|
* If it throws error, node will be collapsed,
|
|
65
65
|
* but user will be able to open it again and callback will be called
|
|
@@ -72,18 +72,18 @@ export let loadChildrenAsync = null;
|
|
|
72
72
|
export let showContextMenu = false;
|
|
73
73
|
// TODO stopped working in new version
|
|
74
74
|
/**
|
|
75
|
-
*
|
|
75
|
+
* Automatically expand nodes to this level,
|
|
76
76
|
* any user made expansion will override this.
|
|
77
77
|
*/
|
|
78
78
|
export let expandTo = 0;
|
|
79
79
|
/**
|
|
80
|
-
*
|
|
80
|
+
* Threshold for automatic expansion. If tree has less or equal nodes than this value,
|
|
81
81
|
* all nodes will be expanded. Default is 0, which means no automatic expansion
|
|
82
82
|
*/
|
|
83
|
-
export let
|
|
83
|
+
export let expansionThreshold = 0;
|
|
84
84
|
/**
|
|
85
85
|
* Classes used in tree. You can override default classes with this prop.
|
|
86
|
-
* It is recommended to use default classes and add
|
|
86
|
+
* It is recommended to use default classes and add additional styles in your css
|
|
87
87
|
*/
|
|
88
88
|
export let customClasses = {};
|
|
89
89
|
/**
|
|
@@ -100,7 +100,7 @@ export let filter = null;
|
|
|
100
100
|
*/
|
|
101
101
|
export let logger = null;
|
|
102
102
|
/*
|
|
103
|
-
* Drag and drop mode allows all nodes, that
|
|
103
|
+
* Drag and drop mode allows all nodes, that don't have dragDisabled property set to true
|
|
104
104
|
* to be dragged and dropped. By default you can only insert at same level node you are dropping on,
|
|
105
105
|
* but you can allow nesting by setting nestAllowed to true on node. If you want to disable insertion,
|
|
106
106
|
* set dropDisabled to true on node. if both is disabled, you wont be able to drop on node.
|
|
@@ -131,7 +131,7 @@ $: selectionProvider = new SelectionProvider(helper, recursiveSelection);
|
|
|
131
131
|
$: computedTree = computeTree(helper, selectionProvider, tree, filter, props, expandedIds, value);
|
|
132
132
|
$: debugLog('computedTree', computedTree);
|
|
133
133
|
export function changeAllExpansion(changeTo) {
|
|
134
|
-
debugLog('
|
|
134
|
+
debugLog('changing expansion of every node to ', changeTo ? 'expanded' : 'collapsed');
|
|
135
135
|
if (changeTo) {
|
|
136
136
|
expandedIds = computedTree.map((node) => node.id);
|
|
137
137
|
}
|
|
@@ -190,7 +190,7 @@ function computeTree(helper, selectionProvider, userProvidedTree, filter, props,
|
|
|
190
190
|
const mappedTree = helper.mapTree(userProvidedTree, { ...defaultPropNames, ...props });
|
|
191
191
|
const { tree: filteredTree, count: filteredCount } = helper.searchTree(mappedTree, filter);
|
|
192
192
|
// treshold applies to nodes that match the filter, not all their parents
|
|
193
|
-
if (filteredCount <=
|
|
193
|
+
if (filteredCount <= expansionThreshold) {
|
|
194
194
|
expandedIds = uniq([...expandedIds, ...filteredTree.map((node) => node.id)]);
|
|
195
195
|
}
|
|
196
196
|
helper.markExpanded(filteredTree, expandedIds);
|
|
@@ -229,7 +229,7 @@ function handleCallback(node) {
|
|
|
229
229
|
return;
|
|
230
230
|
}
|
|
231
231
|
debugLog('calling callback for node', node);
|
|
232
|
-
// TODO mark node as loaded and
|
|
232
|
+
// TODO mark node as loaded and don't call callback again
|
|
233
233
|
// this is now responsibility of user
|
|
234
234
|
loadChildrenAsync(node);
|
|
235
235
|
}
|
|
@@ -238,7 +238,7 @@ function onSelectionChanged(detail) {
|
|
|
238
238
|
const nodePath = node.path;
|
|
239
239
|
const changeTo = !selectionProvider.isNodeSelected(node);
|
|
240
240
|
const newValue = selectionProvider.setSelection(computedTree, nodePath, changeTo, value);
|
|
241
|
-
debugLog("changing selection of node '", nodePath, "' to ", changeTo, '
|
|
241
|
+
debugLog("changing selection of node '", nodePath, "' to ", changeTo, ' returning value ', newValue);
|
|
242
242
|
dispatch('change', newValue);
|
|
243
243
|
dispatch('selection', {
|
|
244
244
|
node: node,
|
|
@@ -272,7 +272,7 @@ function onDragEnd({ detail: { node, event, element } }) {
|
|
|
272
272
|
highlightedNode = null;
|
|
273
273
|
}
|
|
274
274
|
function onDragDrop({ detail: { node, event, element } }) {
|
|
275
|
-
// here we
|
|
275
|
+
// here we assume that highlightType is correctly calculated in handleDragOver
|
|
276
276
|
if (!dragAndDrop || draggedNode === null || insertionType === InsertionType.none) {
|
|
277
277
|
event.preventDefault();
|
|
278
278
|
return;
|
|
@@ -285,7 +285,7 @@ function onDragDrop({ detail: { node, event, element } }) {
|
|
|
285
285
|
insertType: insertionType
|
|
286
286
|
});
|
|
287
287
|
}
|
|
288
|
-
// handle
|
|
288
|
+
// handle highlighting
|
|
289
289
|
function onDragEnter({ detail: { node, event, element } }) {
|
|
290
290
|
highlightedNode = null;
|
|
291
291
|
if (!draggedNode || !dragAndDrop) {
|
|
@@ -35,14 +35,14 @@ declare const __propDef: {
|
|
|
35
35
|
* TODO find better name
|
|
36
36
|
*/ selectionMode?: SelectionModes | undefined;
|
|
37
37
|
/**
|
|
38
|
-
* By default, in recursive mode, non-leaf checkboxes will select/
|
|
39
|
-
* If you set this to true, this
|
|
38
|
+
* By default, in recursive mode, non-leaf checkboxes will select/deselect all its children
|
|
39
|
+
* If you set this to true, this behavior will be disabled and only leaf nodes will be selectable
|
|
40
40
|
*/ onlyLeafCheckboxes?: boolean | undefined;
|
|
41
41
|
/**
|
|
42
42
|
* Instead of showing disabled checkboxes, show blank space
|
|
43
43
|
*/ hideDisabledCheckboxes?: boolean | undefined;
|
|
44
44
|
/**
|
|
45
|
-
* Function that will be
|
|
45
|
+
* Function that will be caged when node is expanded and useCallback is set to true
|
|
46
46
|
* It should return array of nodes that will be added to tree
|
|
47
47
|
* If it throws error, node will be collapsed,
|
|
48
48
|
* but user will be able to open it again and callback will be called
|
|
@@ -52,16 +52,16 @@ declare const __propDef: {
|
|
|
52
52
|
* Its defined in slot context-menu
|
|
53
53
|
*/ showContextMenu?: boolean | undefined;
|
|
54
54
|
/**
|
|
55
|
-
*
|
|
55
|
+
* Automatically expand nodes to this level,
|
|
56
56
|
* any user made expansion will override this.
|
|
57
57
|
*/ expandTo?: number | undefined;
|
|
58
58
|
/**
|
|
59
|
-
*
|
|
59
|
+
* Threshold for automatic expansion. If tree has less or equal nodes than this value,
|
|
60
60
|
* all nodes will be expanded. Default is 0, which means no automatic expansion
|
|
61
|
-
*/
|
|
61
|
+
*/ expansionThreshold?: number | undefined;
|
|
62
62
|
/**
|
|
63
63
|
* Classes used in tree. You can override default classes with this prop.
|
|
64
|
-
* It is recommended to use default classes and add
|
|
64
|
+
* It is recommended to use default classes and add additional styles in your css
|
|
65
65
|
*/ customClasses?: Partial<CustomizableClasses> | undefined;
|
|
66
66
|
/**
|
|
67
67
|
* Function used to filter what nodes should be shown.
|
package/dist/constants.js
CHANGED
|
@@ -16,7 +16,7 @@ export const defaultClasses = {
|
|
|
16
16
|
nodeClass: '',
|
|
17
17
|
expandIcon: 'far fa-fw fa-plus-square',
|
|
18
18
|
collapseIcon: 'far fa-fw fa-minus-square',
|
|
19
|
-
|
|
19
|
+
insertLineClass: '',
|
|
20
20
|
nestIcon: 'fas fa-level-down-alt'
|
|
21
21
|
};
|
|
22
22
|
export const defaultConfig = {
|
|
@@ -3,7 +3,7 @@ import { type Node, InsertionType } from '../types.js';
|
|
|
3
3
|
export declare class DragDropProvider {
|
|
4
4
|
helper: TreeHelper;
|
|
5
5
|
constructor(treeHelper: TreeHelper);
|
|
6
|
-
getInsertionPosition(
|
|
6
|
+
getInsertionPosition(draggedNode: Node, draggedOverNode: Node, e: DragEvent, element: HTMLElement, nest: boolean): InsertionType;
|
|
7
7
|
getRelativePosition(element: Element, e: DragEvent): InsertionType;
|
|
8
8
|
isDropAllowed(draggedNode: Node, targeNode: Node): boolean;
|
|
9
9
|
}
|
|
@@ -4,7 +4,7 @@ export class DragDropProvider {
|
|
|
4
4
|
constructor(treeHelper) {
|
|
5
5
|
this.helper = treeHelper;
|
|
6
6
|
}
|
|
7
|
-
getInsertionPosition(
|
|
7
|
+
getInsertionPosition(draggedNode, draggedOverNode, e, element, nest) {
|
|
8
8
|
if (nest && draggedOverNode.nestAllowed) {
|
|
9
9
|
return InsertionType.nest;
|
|
10
10
|
}
|
|
@@ -65,7 +65,7 @@ export function calculateNewFocusedNode(helper, tree, targetNode, movementDirect
|
|
|
65
65
|
return wrapReturn(targetNode);
|
|
66
66
|
}
|
|
67
67
|
const parentNode = helper.findNode(tree, parentNodePath);
|
|
68
|
-
//
|
|
68
|
+
// assertion
|
|
69
69
|
if (!parentNode) {
|
|
70
70
|
console.warn('Parent node not found, this should never happen');
|
|
71
71
|
return wrapReturn(targetNode);
|
|
@@ -113,7 +113,7 @@ export class SelectionProvider {
|
|
|
113
113
|
directChildrenStates.push(result.state);
|
|
114
114
|
}
|
|
115
115
|
});
|
|
116
|
-
// if
|
|
116
|
+
// if it doesn't have any children, mark it as selected but ignore it in upstream calculations
|
|
117
117
|
const ignore = directChildrenStates.length === 0;
|
|
118
118
|
return { ignore, state: this.computeVisualState(directChildrenStates) };
|
|
119
119
|
}
|
|
@@ -122,7 +122,7 @@ export class SelectionProvider {
|
|
|
122
122
|
tree.forEach((node) => {
|
|
123
123
|
// match itself and all children
|
|
124
124
|
if (node.path?.startsWith(parentNodePath ? parentNodePath + this.helper.config.separator : '')) {
|
|
125
|
-
//
|
|
125
|
+
//don't change if not selectable
|
|
126
126
|
if (!isSelectable(node, SelectionModes.all)) {
|
|
127
127
|
return;
|
|
128
128
|
}
|
|
@@ -148,6 +148,6 @@ export function isSelectable(node, showCheckboxes) {
|
|
|
148
148
|
if (showCheckboxes === SelectionModes.perNode) {
|
|
149
149
|
return node.checkbox === true;
|
|
150
150
|
}
|
|
151
|
-
//
|
|
151
|
+
//don't show at all
|
|
152
152
|
return false;
|
|
153
153
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -55,11 +55,11 @@ export type CustomizableClasses = {
|
|
|
55
55
|
collapseIcon: string;
|
|
56
56
|
nestIcon: string;
|
|
57
57
|
expandClass: string;
|
|
58
|
-
|
|
58
|
+
insertLineClass: string;
|
|
59
59
|
currentlyDraggedClass: string;
|
|
60
60
|
};
|
|
61
|
-
export type DragEnterCallback = (
|
|
62
|
-
export type BeforeMovedCallback = (
|
|
61
|
+
export type DragEnterCallback = (draggedNode: Node, targetNode: Node) => Promise<boolean>;
|
|
62
|
+
export type BeforeMovedCallback = (draggedNode: Node, oldParent: Node, newParent: Node, insertionType: string) => boolean;
|
|
63
63
|
export type ExpandedCallback = (node: Node) => Promise<void>;
|
|
64
64
|
export type HelperConfig = {
|
|
65
65
|
separator: string;
|