@keenmate/svelte-treeview 1.2.12 → 3.0.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.
@@ -1,50 +1,50 @@
1
- <!-- component from https://svelte.dev/repl/3a33725c3adb4f57b46b597f9dade0c1?version=3.25.0 -->
2
-
3
- <script>
4
- // @ts-nocheck
5
-
6
- import { onMount, setContext, createEventDispatcher } from 'svelte';
7
- import { fade } from 'svelte/transition';
8
- import { key } from './menu.js';
9
-
10
- export let x;
11
- export let y;
12
-
13
- // whenever x and y is changed, restrict box to be within bounds
14
- $: (() => {
15
- if (!menuEl) return;
16
-
17
- const rect = menuEl.getBoundingClientRect();
18
- x = Math.min(window.innerWidth - rect.width, x);
19
- if (y > window.innerHeight - rect.height) y -= rect.height;
20
- })(x, y);
21
-
22
- const dispatch = createEventDispatcher();
23
-
24
- setContext(key, {
25
- dispatchClick: () => dispatch('click')
26
- });
27
-
28
- let menuEl;
29
- function onPageClick(e) {
30
- if (e.target === menuEl || menuEl.contains(e.target)) return;
31
- dispatch('clickoutside');
32
- }
33
- </script>
34
-
35
- <svelte:body on:click={onPageClick} />
36
-
37
- <div transition:fade={{ duration: 100 }} bind:this={menuEl} style="top: {y}px; left: {x}px;">
38
- <slot />
39
- </div>
40
-
41
- <style>
42
- div {
43
- position: fixed;
44
- display: grid;
45
- border: 1px solid #0003;
46
- box-shadow: 2px 2px 5px 0px #0002;
47
- background: white;
48
- z-index: 999;
49
- }
50
- </style>
1
+ <!-- component from https://svelte.dev/repl/3a33725c3adb4f57b46b597f9dade0c1?version=3.25.0 -->
2
+
3
+ <script lang="ts">import { run } from 'svelte/legacy';
4
+ // @ts-nocheck
5
+ import { createEventDispatcher, setContext } from "svelte";
6
+ import { fade } from "svelte/transition";
7
+ import { key } from "./menu.js";
8
+ let { x = $bindable(), y = $bindable(), children } = $props();
9
+ const dispatch = createEventDispatcher();
10
+ setContext(key, {
11
+ dispatchClick: () => dispatch("click")
12
+ });
13
+ let menuEl = $state();
14
+ function onPageClick(e) {
15
+ if (e.target === menuEl || menuEl.contains(e.target)) {
16
+ return;
17
+ }
18
+ dispatch("clickoutside");
19
+ }
20
+ // whenever x and y is changed, restrict box to be within bounds
21
+ run(() => {
22
+ (() => {
23
+ if (!menuEl) {
24
+ return;
25
+ }
26
+ const rect = menuEl.getBoundingClientRect();
27
+ x = Math.min(window.innerWidth - rect.width, x);
28
+ if (y > window.innerHeight - rect.height) {
29
+ y -= rect.height;
30
+ }
31
+ })(x, y);
32
+ });
33
+ </script>
34
+
35
+ <svelte:body onclick={onPageClick} />
36
+
37
+ <div transition:fade={{ duration: 100 }} bind:this={menuEl} style="top: {y}px; left: {x}px;">
38
+ {@render children?.()}
39
+ </div>
40
+
41
+ <style>
42
+ div {
43
+ position: fixed;
44
+ display: grid;
45
+ border: 1px solid #0003;
46
+ box-shadow: 2px 2px 5px 0px #0002;
47
+ background: white;
48
+ z-index: 999;
49
+ }
50
+ </style>
@@ -1,35 +1,25 @@
1
- /** @typedef {typeof __propDef.props} MenuProps */
2
- /** @typedef {typeof __propDef.events} MenuEvents */
3
- /** @typedef {typeof __propDef.slots} MenuSlots */
4
- export default class Menu extends SvelteComponent<{
5
- x: any;
6
- y: any;
1
+ interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
2
+ new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
3
+ $$bindings?: Bindings;
4
+ } & Exports;
5
+ (internal: unknown, props: Props & {
6
+ $$events?: Events;
7
+ $$slots?: Slots;
8
+ }): Exports & {
9
+ $set?: any;
10
+ $on?: any;
11
+ };
12
+ z_$$bindings?: Bindings;
13
+ }
14
+ declare const Menu: $$__sveltets_2_IsomorphicComponent<{
15
+ x?: any;
16
+ y?: any;
17
+ children: any;
7
18
  }, {
8
19
  click: CustomEvent<any>;
9
20
  clickoutside: CustomEvent<any>;
10
21
  } & {
11
22
  [evt: string]: CustomEvent<any>;
12
- }, {
13
- default: {};
14
- }> {
15
- }
16
- export type MenuProps = typeof __propDef.props;
17
- export type MenuEvents = typeof __propDef.events;
18
- export type MenuSlots = typeof __propDef.slots;
19
- import { SvelteComponent } from "svelte";
20
- declare const __propDef: {
21
- props: {
22
- x: any;
23
- y: any;
24
- };
25
- events: {
26
- click: CustomEvent<any>;
27
- clickoutside: CustomEvent<any>;
28
- } & {
29
- [evt: string]: CustomEvent<any>;
30
- };
31
- slots: {
32
- default: {};
33
- };
34
- };
35
- export {};
23
+ }, {}, {}, "x" | "y">;
24
+ type Menu = InstanceType<typeof Menu>;
25
+ export default Menu;
@@ -1,10 +1,10 @@
1
- <style>
2
- hr {
3
- border-top: 1px solid #0003;
4
- width: 100%;
5
- margin: 2px 0;
6
- }
7
- </style>
8
-
9
-
10
- <hr />
1
+ <style>
2
+ hr {
3
+ border-top: 1px solid #0003;
4
+ width: 100%;
5
+ margin: 2px 0;
6
+ }
7
+ </style>
8
+
9
+
10
+ <hr />
@@ -1,23 +1,26 @@
1
- /** @typedef {typeof __propDef.props} MenuDividerProps */
2
- /** @typedef {typeof __propDef.events} MenuDividerEvents */
3
- /** @typedef {typeof __propDef.slots} MenuDividerSlots */
4
- export default class MenuDivider extends SvelteComponent<{
1
+ export default MenuDivider;
2
+ type MenuDivider = SvelteComponent<{
5
3
  [x: string]: never;
6
4
  }, {
7
5
  [evt: string]: CustomEvent<any>;
8
- }, {}> {
9
- }
10
- export type MenuDividerProps = typeof __propDef.props;
11
- export type MenuDividerEvents = typeof __propDef.events;
12
- export type MenuDividerSlots = typeof __propDef.slots;
13
- import { SvelteComponent } from "svelte";
14
- declare const __propDef: {
15
- props: {
16
- [x: string]: never;
17
- };
18
- events: {
19
- [evt: string]: CustomEvent<any>;
20
- };
21
- slots: {};
6
+ }, {}> & {
7
+ $$bindings?: string | undefined;
22
8
  };
23
- export {};
9
+ declare const MenuDivider: $$__sveltets_2_IsomorphicComponent<{
10
+ [x: string]: never;
11
+ }, {
12
+ [evt: string]: CustomEvent<any>;
13
+ }, {}, {}, string>;
14
+ interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
15
+ new (options: import("svelte").ComponentConstructorOptions<Props>): import("svelte").SvelteComponent<Props, Events, Slots> & {
16
+ $$bindings?: Bindings;
17
+ } & Exports;
18
+ (internal: unknown, props: {
19
+ $$events?: Events;
20
+ $$slots?: Slots;
21
+ }): Exports & {
22
+ $set?: any;
23
+ $on?: any;
24
+ };
25
+ z_$$bindings?: Bindings;
26
+ }
@@ -1,49 +1,45 @@
1
- <script>
2
- // @ts-nocheck
3
-
4
- import { onMount, getContext } from 'svelte';
5
- import { key } from './menu.js';
6
-
7
- export let isDisabled = false;
8
- export let text = '';
9
-
10
- import { createEventDispatcher } from 'svelte';
11
- const dispatch = createEventDispatcher();
12
-
13
- const { dispatchClick } = getContext(key);
14
-
15
- const handleClick = (e) => {
16
- if (isDisabled) return;
17
-
18
- dispatch('click');
19
- dispatchClick();
20
- };
21
- </script>
22
-
23
- <div class:disabled={isDisabled} on:click={handleClick} on:keydown={handleClick} role="button" tabindex="">
24
- {#if text}
25
- {text}
26
- {:else}
27
- <slot />
28
- {/if}
29
- </div>
30
-
31
- <style>
32
- div {
33
- padding: 4px 15px;
34
- cursor: default;
35
- font-size: 14px;
36
- display: flex;
37
- align-items: center;
38
- grid-gap: 5px;
39
- }
40
- div:hover {
41
- background: #0002;
42
- }
43
- div.disabled {
44
- color: #0006;
45
- }
46
- div.disabled:hover {
47
- background: white;
48
- }
49
- </style>
1
+ <script lang="ts">// @ts-nocheck
2
+ import { createEventDispatcher, getContext } from "svelte";
3
+ import { key } from "./menu.js";
4
+ let { isDisabled = false, text = "", children } = $props();
5
+ const dispatch = createEventDispatcher();
6
+ const { dispatchClick } = getContext(key);
7
+ const handleClick = (e) => {
8
+ if (isDisabled) {
9
+ return;
10
+ }
11
+ dispatch("click");
12
+ dispatchClick();
13
+ };
14
+ </script>
15
+
16
+ <div class:disabled={isDisabled} onclick={handleClick} onkeydown={handleClick} role="button" tabindex="">
17
+ {#if text}
18
+ {text}
19
+ {:else}
20
+ {@render children?.()}
21
+ {/if}
22
+ </div>
23
+
24
+ <style>
25
+ div {
26
+ padding: 4px 15px;
27
+ cursor: default;
28
+ font-size: 14px;
29
+ display: flex;
30
+ align-items: center;
31
+ grid-gap: 5px;
32
+ }
33
+
34
+ div:hover {
35
+ background: #0002;
36
+ }
37
+
38
+ div.disabled {
39
+ color: #0006;
40
+ }
41
+
42
+ div.disabled:hover {
43
+ background: white;
44
+ }
45
+ </style>
@@ -1,33 +1,25 @@
1
- /** @typedef {typeof __propDef.props} MenuOptionProps */
2
- /** @typedef {typeof __propDef.events} MenuOptionEvents */
3
- /** @typedef {typeof __propDef.slots} MenuOptionSlots */
4
- export default class MenuOption extends SvelteComponent<{
5
- isDisabled?: boolean | undefined;
6
- text?: string | undefined;
7
- }, {
1
+ interface Props {
2
+ isDisabled?: boolean;
3
+ text?: string;
4
+ children?: import('svelte').Snippet;
5
+ }
6
+ interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
7
+ new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
8
+ $$bindings?: Bindings;
9
+ } & Exports;
10
+ (internal: unknown, props: Props & {
11
+ $$events?: Events;
12
+ $$slots?: Slots;
13
+ }): Exports & {
14
+ $set?: any;
15
+ $on?: any;
16
+ };
17
+ z_$$bindings?: Bindings;
18
+ }
19
+ declare const MenuOption: $$__sveltets_2_IsomorphicComponent<Props, {
8
20
  click: CustomEvent<any>;
9
21
  } & {
10
22
  [evt: string]: CustomEvent<any>;
11
- }, {
12
- default: {};
13
- }> {
14
- }
15
- export type MenuOptionProps = typeof __propDef.props;
16
- export type MenuOptionEvents = typeof __propDef.events;
17
- export type MenuOptionSlots = typeof __propDef.slots;
18
- import { SvelteComponent } from "svelte";
19
- declare const __propDef: {
20
- props: {
21
- isDisabled?: boolean | undefined;
22
- text?: string | undefined;
23
- };
24
- events: {
25
- click: CustomEvent<any>;
26
- } & {
27
- [evt: string]: CustomEvent<any>;
28
- };
29
- slots: {
30
- default: {};
31
- };
32
- };
33
- export {};
23
+ }, {}, {}, "">;
24
+ type MenuOption = InstanceType<typeof MenuOption>;
25
+ export default MenuOption;
package/dist/menu/menu.js CHANGED
@@ -1,3 +1,3 @@
1
- const key = {};
2
-
3
- export { key };
1
+ const key = {}
2
+
3
+ export {key}
@@ -1,5 +1,5 @@
1
- import type { TreeHelper } from '../helpers/tree-helper.js';
2
- import { type Node, InsertionType } from '../types.js';
1
+ import type { TreeHelper } from "../helpers/tree-helper.js";
2
+ import { InsertionType, type Node } from "../types.js";
3
3
  export declare class DragDropProvider {
4
4
  helper: TreeHelper;
5
5
  constructor(treeHelper: TreeHelper);
@@ -1,4 +1,4 @@
1
- import { InsertionType } from '../types.js';
1
+ import { InsertionType } from "../types.js";
2
2
  export class DragDropProvider {
3
3
  helper;
4
4
  constructor(treeHelper) {
@@ -1,5 +1,5 @@
1
- import type { TreeHelper } from '../helpers/tree-helper.js';
2
- import { KeyboardMovement as MovementDirection, type Node } from '../types.js';
1
+ import type { TreeHelper } from "../helpers/tree-helper.js";
2
+ import { KeyboardMovement as MovementDirection, type Node } from "../types.js";
3
3
  export declare function calculateNewFocusedNode(helper: TreeHelper, tree: Node[], targetNode: Node, movementDirection: MovementDirection): {
4
4
  node: Node;
5
5
  setExpansion: boolean | null;
@@ -1,4 +1,4 @@
1
- import { KeyboardMovement as MovementDirection } from '../types.js';
1
+ import { KeyboardMovement as MovementDirection } from "../types.js";
2
2
  export function calculateNewFocusedNode(helper, tree, targetNode, movementDirection) {
3
3
  // TODO this could use some refactoring
4
4
  const parentNodePath = helper.getParentNodePath(targetNode.path);
@@ -66,7 +66,7 @@ export function calculateNewFocusedNode(helper, tree, targetNode, movementDirect
66
66
  const parentNode = helper.findNode(tree, parentNodePath);
67
67
  // assertion
68
68
  if (!parentNode) {
69
- console.warn('Parent node not found, this should never happen');
69
+ console.warn("Parent node not found, this should never happen");
70
70
  return wrapReturn(targetNode);
71
71
  }
72
72
  return wrapReturn(parentNode);
@@ -75,13 +75,13 @@ export function calculateNewFocusedNode(helper, tree, targetNode, movementDirect
75
75
  }
76
76
  export function parseMovementDirection(key) {
77
77
  switch (key) {
78
- case 'ArrowRight':
78
+ case "ArrowRight":
79
79
  return MovementDirection.Right;
80
- case 'ArrowLeft':
80
+ case "ArrowLeft":
81
81
  return MovementDirection.Left;
82
- case 'ArrowDown':
82
+ case "ArrowDown":
83
83
  return MovementDirection.Down;
84
- case 'ArrowUp':
84
+ case "ArrowUp":
85
85
  return MovementDirection.Up;
86
86
  default:
87
87
  return null;
@@ -95,7 +95,8 @@ function getRelativeSibling(helper, tree, node, relativeIndex) {
95
95
  const parentDirectChildren = helper.getDirectChildren(tree, parentNodePath);
96
96
  const nodeIndex = parentDirectChildren.findIndex((x) => x.path === node.path);
97
97
  const siblingIndex = nodeIndex + relativeIndex;
98
- if (siblingIndex < 0 || siblingIndex >= parentDirectChildren.length)
98
+ if (siblingIndex < 0 || siblingIndex >= parentDirectChildren.length) {
99
99
  return null;
100
+ }
100
101
  return parentDirectChildren[siblingIndex];
101
102
  }
@@ -1,5 +1,5 @@
1
- import type { TreeHelper } from '../helpers/tree-helper.js';
2
- import { SelectionModes, type Tree, type TreeVisualStates, type Node, type NodeId } from '../types.js';
1
+ import type { TreeHelper } from "../helpers/tree-helper.js";
2
+ import { type Node, type NodeId, SelectionModes, type Tree, type TreeVisualStates } from "../types.js";
3
3
  export declare class SelectionProvider {
4
4
  helper: TreeHelper;
5
5
  recursiveMode: boolean;
@@ -1,4 +1,4 @@
1
- import { SelectionModes, VisualState } from '../types.js';
1
+ import { SelectionModes, VisualState } from "../types.js";
2
2
  export class SelectionProvider {
3
3
  helper;
4
4
  recursiveMode;
@@ -9,13 +9,13 @@ export class SelectionProvider {
9
9
  markSelected(tree, selectedNodeIds) {
10
10
  const visualStates = this.computeVisualStates(tree, selectedNodeIds);
11
11
  tree.forEach((node) => {
12
- if (selectedNodeIds.includes(node.id ?? '')) {
12
+ if (selectedNodeIds.includes(node.id ?? "")) {
13
13
  node.selected = true;
14
14
  node.visualState = VisualState.selected;
15
15
  return;
16
16
  }
17
17
  node.selected = false;
18
- const visualState = visualStates[node.id ?? ''];
18
+ const visualState = visualStates[node.id ?? ""];
19
19
  if (!visualState) {
20
20
  node.visualState = VisualState.notSelected;
21
21
  }
@@ -27,8 +27,9 @@ export class SelectionProvider {
27
27
  }
28
28
  isSelected(nodeId, visualStates, selectedNodeIds) {
29
29
  const selected = selectedNodeIds.includes(nodeId);
30
- if (selected)
30
+ if (selected) {
31
31
  return true;
32
+ }
32
33
  const visualState = visualStates[nodeId];
33
34
  return visualState === VisualState.selected;
34
35
  }
@@ -47,10 +48,10 @@ export class SelectionProvider {
47
48
  else {
48
49
  if (!node) {
49
50
  // throw new Error('Node not found ' + nodePath);
50
- console.warn('Node %s doesnt exits', nodePath);
51
+ console.warn("Node %s doesnt exits", nodePath);
51
52
  return oldSelection;
52
53
  }
53
- const nodeId = node.id ?? '';
54
+ const nodeId = node.id ?? "";
54
55
  // prevent double selection
55
56
  const filteredSelection = oldSelection.filter((x) => x !== nodeId);
56
57
  if (changeTo === false) {
@@ -68,14 +69,15 @@ export class SelectionProvider {
68
69
  rootELements.forEach((node) => {
69
70
  if (node.hasChildren == true) {
70
71
  const result = this.computeVisualStateRecursively(tree, node, selectedNodeIds, visualStates);
71
- visualStates[node.id ?? ''] = result.state;
72
+ visualStates[node.id ?? ""] = result.state;
72
73
  }
73
74
  });
74
75
  return visualStates;
75
76
  }
76
77
  computeVisualState(directChildrenVisualStates) {
77
- if (!directChildrenVisualStates || directChildrenVisualStates?.length == 0)
78
+ if (!directChildrenVisualStates || directChildrenVisualStates?.length == 0) {
78
79
  return VisualState.selected;
80
+ }
79
81
  //if every child is selected or vs=true return true
80
82
  if (directChildrenVisualStates.every((state) => state === VisualState.selected)) {
81
83
  return VisualState.selected;
@@ -101,14 +103,14 @@ export class SelectionProvider {
101
103
  // using recustion compute from leaft nodes to root
102
104
  directChildren.forEach((child) => {
103
105
  if (!child.hasChildren) {
104
- const childState = selectedNodeIds.includes(child.id ?? '')
106
+ const childState = selectedNodeIds.includes(child.id ?? "")
105
107
  ? VisualState.selected
106
108
  : VisualState.notSelected;
107
109
  directChildrenStates.push(childState);
108
110
  return;
109
111
  }
110
112
  const result = this.computeVisualStateRecursively(tree, child, selectedNodeIds, visualStates);
111
- visualStates[child.id ?? ''] = result.state;
113
+ visualStates[child.id ?? ""] = result.state;
112
114
  if (!result.ignore) {
113
115
  directChildrenStates.push(result.state);
114
116
  }
@@ -121,7 +123,7 @@ export class SelectionProvider {
121
123
  let newSelection = [...oldSelection];
122
124
  tree.forEach((node) => {
123
125
  // match itself and all children
124
- if (node.path?.startsWith(parentNodePath ? parentNodePath + this.helper.config.separator : '')) {
126
+ if (node.path?.startsWith(parentNodePath ? parentNodePath + this.helper.config.separator : "")) {
125
127
  //don't change if not selectable
126
128
  if (!isSelectable(node, SelectionModes.all)) {
127
129
  return;
@@ -131,9 +133,9 @@ export class SelectionProvider {
131
133
  return;
132
134
  }
133
135
  // prevent double selection
134
- newSelection = newSelection.filter((x) => x !== (node.id ?? ''));
136
+ newSelection = newSelection.filter((x) => x !== (node.id ?? ""));
135
137
  if (changeTo === true) {
136
- newSelection.push(node.id ?? '');
138
+ newSelection.push(node.id ?? "");
137
139
  }
138
140
  }
139
141
  });