@keenmate/svelte-treeview 1.1.0-beta.1 → 1.1.0-beta.3

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.
@@ -21,7 +21,7 @@ export let draggedNode;
21
21
  export let highlightedNode;
22
22
  export let insertionType;
23
23
  export let focusedNode;
24
- export let useKeyboardNavigation;
24
+ export let allowKeyboardNavigation;
25
25
  let liElements = {};
26
26
  const getNodeId = (node) => `${treeId}-${node.path}`;
27
27
  $: directChildren = helper.getDirectChildren(tree, branchRootNode?.path ?? null);
@@ -101,7 +101,7 @@ function getHighlighMode(node, highlightedNode, insertionType) {
101
101
  on:dragleave|stopPropagation={(e) => handleDragLeave(e, node, liElements[getNodeId(node)])}
102
102
  bind:this={liElements[getNodeId(node)]}
103
103
  on:keydown={(e) => handleKeyPress(e, node)}
104
- tabindex={useKeyboardNavigation ? 1 : -1}
104
+ tabindex={allowKeyboardNavigation ? 1 : -1}
105
105
  >
106
106
  {#if effectiveHighlight == InsertionType.insertAbove}
107
107
  <div class="insert-line-wrapper">
@@ -179,7 +179,7 @@ function getHighlighMode(node, highlightedNode, insertionType) {
179
179
  {highlightedNode}
180
180
  {insertionType}
181
181
  {focusedNode}
182
- {useKeyboardNavigation}
182
+ {allowKeyboardNavigation}
183
183
  on:open-ctxmenu
184
184
  on:internal-expand
185
185
  on:internal-selectionChanged
@@ -21,7 +21,7 @@ declare const __propDef: {
21
21
  highlightedNode: Node | null;
22
22
  insertionType: InsertionType;
23
23
  focusedNode: Node | null;
24
- useKeyboardNavigation: boolean;
24
+ allowKeyboardNavigation: boolean;
25
25
  };
26
26
  events: {
27
27
  'open-ctxmenu': CustomEvent<any>;
@@ -147,7 +147,6 @@ export function expandToNode(nodePath) {
147
147
  }
148
148
  const parents = helper.getParents(computedTree, targetNode);
149
149
  debugLog("expanding to node '" + nodePath + "'" + ' parents', parents);
150
- console.log('parents', parents);
151
150
  expandedIds = uniq([...expandedIds, ...parents.map((node) => node.id)]);
152
151
  }
153
152
  export function setNodeExpansion(nodePath, changeTo) {
@@ -177,9 +176,11 @@ export function focusFirstNode() {
177
176
  const rootChildren = helper.getDirectChildren(computedTree, null);
178
177
  if (rootChildren.length === 0) {
179
178
  focusedNode = null;
180
- return;
179
+ return null;
181
180
  }
182
181
  focusedNode = rootChildren[0];
182
+ dispatch('focus', focusedNode);
183
+ return focusedNode;
183
184
  }
184
185
  function computeTree(helper, selectionProvider, userProvidedTree, filter, props, expandedIds, value) {
185
186
  if (!Array.isArray(userProvidedTree) || !Array.isArray(value)) {
@@ -333,9 +334,19 @@ function onKeyPress(detail) {
333
334
  onExpand({ node: node, changeTo: setExpansion });
334
335
  }
335
336
  dispatch('focus', node);
337
+ return;
336
338
  }
337
339
  if (event.key === 'Enter' || event.key === ' ') {
338
340
  onSelectionChanged({ node: targetNode });
341
+ return;
342
+ }
343
+ if (event.key === 'Escape') {
344
+ focusedNode = null;
345
+ if (document.activeElement instanceof HTMLElement) {
346
+ document.activeElement.blur();
347
+ }
348
+ dispatch('focus-leave');
349
+ return;
339
350
  }
340
351
  }
341
352
  function debugLog(...data) {
@@ -1,5 +1,5 @@
1
1
  import { SvelteComponent } from "svelte";
2
- import { SelectionModes as SelectionModes, type Props, type CustomizableClasses, type DragEnterCallback, type ExpandedCallback, type NodeId, type ProvidedTree, type FilterFunction } from './types.js';
2
+ import { SelectionModes as SelectionModes, type Node, type Props, type CustomizableClasses, type DragEnterCallback, type ExpandedCallback, type NodeId, type ProvidedTree, type FilterFunction } from './types.js';
3
3
  declare const __propDef: {
4
4
  props: {
5
5
  treeId: string;
@@ -87,9 +87,10 @@ declare const __propDef: {
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
+ focusFirstNode?: (() => Node | null) | undefined;
91
91
  };
92
92
  events: {
93
+ focus: CustomEvent<any>;
93
94
  expansion: CustomEvent<any>;
94
95
  expanded: CustomEvent<any>;
95
96
  closed: CustomEvent<any>;
@@ -98,7 +99,7 @@ declare const __propDef: {
98
99
  selected: CustomEvent<any>;
99
100
  unselected: CustomEvent<any>;
100
101
  moved: CustomEvent<any>;
101
- focus: CustomEvent<any>;
102
+ 'focus-leave': CustomEvent<any>;
102
103
  } & {
103
104
  [evt: string]: CustomEvent<any>;
104
105
  };
@@ -121,6 +122,6 @@ export default class TreeView extends SvelteComponent<TreeViewProps, TreeViewEve
121
122
  get setNodeExpansion(): (nodePath: string, changeTo: boolean) => void;
122
123
  get setExpansions(): (expansions: NodeId[]) => void;
123
124
  get focusNode(): (nodePath: string | null) => void;
124
- get focusFirstNode(): () => void;
125
+ get focusFirstNode(): () => Node | null;
125
126
  }
126
127
  export {};
package/dist/constants.js CHANGED
@@ -22,4 +22,12 @@ export const defaultClasses = {
22
22
  export const defaultConfig = {
23
23
  separator: '.'
24
24
  };
25
- export const capturedKeys = ['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight', 'Enter', ' '];
25
+ export const capturedKeys = [
26
+ 'ArrowUp',
27
+ 'ArrowDown',
28
+ 'ArrowLeft',
29
+ 'ArrowRight',
30
+ 'Enter',
31
+ ' ',
32
+ 'Escape'
33
+ ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@keenmate/svelte-treeview",
3
- "version": "1.1.0-beta.1",
3
+ "version": "1.1.0-beta.3",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "vite build && npm run package",