@keenmate/svelte-treeview 1.1.0-beta.0 → 1.1.0-beta.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/TreeView.svelte +12 -3
- package/dist/TreeView.svelte.d.ts +4 -1
- package/package.json +1 -1
package/dist/TreeView.svelte
CHANGED
|
@@ -114,7 +114,7 @@ export let dropDisabledCallback = null;
|
|
|
114
114
|
/**
|
|
115
115
|
* If true, keyboard navigation will be enabled. Use arrow keys to navigate and space to select node.
|
|
116
116
|
*/
|
|
117
|
-
export let
|
|
117
|
+
export let allowKeyboardNavigation = false;
|
|
118
118
|
let ctxMenu;
|
|
119
119
|
let expandedIds = [];
|
|
120
120
|
let draggedNode = null;
|
|
@@ -173,6 +173,14 @@ export function focusNode(nodePath) {
|
|
|
173
173
|
const node = helper.findNode(computedTree, nodePath);
|
|
174
174
|
focusedNode = node;
|
|
175
175
|
}
|
|
176
|
+
export function focusFirstNode() {
|
|
177
|
+
const rootChildren = helper.getDirectChildren(computedTree, null);
|
|
178
|
+
if (rootChildren.length === 0) {
|
|
179
|
+
focusedNode = null;
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
focusedNode = rootChildren[0];
|
|
183
|
+
}
|
|
176
184
|
function computeTree(helper, selectionProvider, userProvidedTree, filter, props, expandedIds, value) {
|
|
177
185
|
if (!Array.isArray(userProvidedTree) || !Array.isArray(value)) {
|
|
178
186
|
console.error('value and tree must be arrays!!');
|
|
@@ -314,7 +322,7 @@ function onDragLeave({ detail: { node, event, element } }) {
|
|
|
314
322
|
}
|
|
315
323
|
function onKeyPress(detail) {
|
|
316
324
|
const { event, node: targetNode } = detail;
|
|
317
|
-
if (!
|
|
325
|
+
if (!allowKeyboardNavigation) {
|
|
318
326
|
return;
|
|
319
327
|
}
|
|
320
328
|
const movement = parseMovementDirection(event.key);
|
|
@@ -324,6 +332,7 @@ function onKeyPress(detail) {
|
|
|
324
332
|
if (setExpansion !== null) {
|
|
325
333
|
onExpand({ node: node, changeTo: setExpansion });
|
|
326
334
|
}
|
|
335
|
+
dispatch('focus', node);
|
|
327
336
|
}
|
|
328
337
|
if (event.key === 'Enter' || event.key === ' ') {
|
|
329
338
|
onSelectionChanged({ node: targetNode });
|
|
@@ -356,7 +365,7 @@ function debugLog(...data) {
|
|
|
356
365
|
{highlightedNode}
|
|
357
366
|
{draggedNode}
|
|
358
367
|
{focusedNode}
|
|
359
|
-
{
|
|
368
|
+
{allowKeyboardNavigation}
|
|
360
369
|
on:internal-handleDragStart={onDragStart}
|
|
361
370
|
on:internal-handleDragDrop={onDragDrop}
|
|
362
371
|
on:internal-handleDragOver={onDragOver}
|
|
@@ -81,12 +81,13 @@ declare const __propDef: {
|
|
|
81
81
|
*/ dropDisabledCallback?: DragEnterCallback | null | undefined;
|
|
82
82
|
/**
|
|
83
83
|
* If true, keyboard navigation will be enabled. Use arrow keys to navigate and space to select node.
|
|
84
|
-
*/
|
|
84
|
+
*/ allowKeyboardNavigation?: boolean | undefined;
|
|
85
85
|
changeAllExpansion?: ((changeTo: boolean) => void) | undefined;
|
|
86
86
|
expandToNode?: ((nodePath: string) => void) | undefined;
|
|
87
87
|
setNodeExpansion?: ((nodePath: string, changeTo: boolean) => void) | undefined;
|
|
88
88
|
setExpansions?: ((expansions: NodeId[]) => void) | undefined;
|
|
89
89
|
focusNode?: ((nodePath: string | null) => void) | undefined;
|
|
90
|
+
focusFirstNode?: (() => void) | undefined;
|
|
90
91
|
};
|
|
91
92
|
events: {
|
|
92
93
|
expansion: CustomEvent<any>;
|
|
@@ -97,6 +98,7 @@ declare const __propDef: {
|
|
|
97
98
|
selected: CustomEvent<any>;
|
|
98
99
|
unselected: CustomEvent<any>;
|
|
99
100
|
moved: CustomEvent<any>;
|
|
101
|
+
focus: CustomEvent<any>;
|
|
100
102
|
} & {
|
|
101
103
|
[evt: string]: CustomEvent<any>;
|
|
102
104
|
};
|
|
@@ -119,5 +121,6 @@ export default class TreeView extends SvelteComponent<TreeViewProps, TreeViewEve
|
|
|
119
121
|
get setNodeExpansion(): (nodePath: string, changeTo: boolean) => void;
|
|
120
122
|
get setExpansions(): (expansions: NodeId[]) => void;
|
|
121
123
|
get focusNode(): (nodePath: string | null) => void;
|
|
124
|
+
get focusFirstNode(): () => void;
|
|
122
125
|
}
|
|
123
126
|
export {};
|