@keenmate/svelte-treeview 1.1.0-beta.1 → 1.1.0-beta.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.
@@ -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) {
@@ -333,9 +332,19 @@ function onKeyPress(detail) {
333
332
  onExpand({ node: node, changeTo: setExpansion });
334
333
  }
335
334
  dispatch('focus', node);
335
+ return;
336
336
  }
337
337
  if (event.key === 'Enter' || event.key === ' ') {
338
338
  onSelectionChanged({ node: targetNode });
339
+ return;
340
+ }
341
+ if (event.key === 'Escape') {
342
+ focusedNode = null;
343
+ if (document.activeElement instanceof HTMLElement) {
344
+ document.activeElement.blur();
345
+ }
346
+ dispatch('focus-leave');
347
+ return;
339
348
  }
340
349
  }
341
350
  function debugLog(...data) {
@@ -99,6 +99,7 @@ declare const __propDef: {
99
99
  unselected: CustomEvent<any>;
100
100
  moved: CustomEvent<any>;
101
101
  focus: CustomEvent<any>;
102
+ 'focus-leave': CustomEvent<any>;
102
103
  } & {
103
104
  [evt: string]: CustomEvent<any>;
104
105
  };
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.2",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "vite build && npm run package",