Skip to content

Commit

Permalink
Remove unsued configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
ZelvaMan committed May 8, 2024
1 parent 86e191a commit db90df1
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 30 deletions.
1 change: 0 additions & 1 deletion src/lib/Branch.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@

<Checkbox
{checkboxes}
{helper}
{recursive}
{node}
{onlyLeafCheckboxes}
Expand Down
6 changes: 2 additions & 4 deletions src/lib/Checkbox.svelte
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
<script lang="ts">
import { createEventDispatcher, hasContext } from 'svelte';
import { createEventDispatcher } from 'svelte';
import { SelectionModes, VisualState, type Node } from './types.js';
import type { TreeHelper } from '$lib/index.js';
import { SelectionProvider, isSelectable } from '$lib/providers/selection-provider.js';
import { isSelectable } from '$lib/providers/selection-provider.js';
export let checkboxes: SelectionModes;
export let helper: TreeHelper;
export let recursive: boolean;
export let node: Node;
export let onlyLeafCheckboxes: boolean;
Expand Down
3 changes: 0 additions & 3 deletions src/lib/TreeView.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,6 @@
$: dragAndDrop && console.warn('Drag and drop is not supported in this version');
$: helper = new TreeHelper({
recursive: recursiveSelection,
recalculateNodePath,
checkboxes: selectionMode,
separator
});
$: selectionProvider = new SelectionProvider(helper, recursiveSelection);
Expand Down
3 changes: 1 addition & 2 deletions src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,5 @@ export const defaultClasses: CustomizableClasses = {
};

export const defaultConfig: HelperConfig = {
separator: '.',
checkboxes: SelectionModes.none
separator: '.'
};
6 changes: 3 additions & 3 deletions src/lib/helpers/tree-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class TreeHelper {
getParentNodePath(nodePath: NodePath): NodePath {
if (nodePath == null) throw new Error('cannot get parent of root');

const separator = this.config.separator ?? '.';
const separator = this.config.separator;
const parentPath = nodePath?.substring(0, nodePath.lastIndexOf(separator));
if (parentPath === '') return null;

Expand All @@ -78,7 +78,7 @@ export class TreeHelper {
}

nodePathIsChild(nodePath: NodePath) {
const separator = this.config.separator ?? '.';
const separator = this.config.separator;

const includesSeparator = nodePath?.includes(separator);
return includesSeparator;
Expand Down Expand Up @@ -143,7 +143,7 @@ export class TreeHelper {
getDepthLevel(nodePath: NodePath) {
if (nodePath == null) return 0;

const separator = this.config.separator ?? '.';
const separator = this.config.separator;
return nodePath.split(separator).length - 1;
}

Expand Down
19 changes: 9 additions & 10 deletions src/lib/menu/ContextMenu.svelte
Original file line number Diff line number Diff line change
@@ -1,33 +1,32 @@
<script>
// @ts-nocheck
<script lang="ts">
import type { Node } from '$lib/types.js';
import Menu from './Menu.svelte';
let pos = { x: 0, y: 0 };
let showMenu = false;
let node = null;
let clickedNode: Node | null = null;
export async function onRightClick(e, n) {
export async function onRightClick(event: MouseEvent, node: Node) {
if (showMenu) {
showMenu = false;
await new Promise((res) => setTimeout(res, 100));
}
node = n;
pos = { x: e.clientX, y: e.clientY };
clickedNode = node;
pos = { x: event.clientX, y: event.clientY };
showMenu = true;
}
function closeMenu() {
showMenu = false;
node = null;
clickedNode = null;
}
</script>

<svelte:window on:click={closeMenu} />
{#if showMenu}
<Menu {...pos} on:click={closeMenu} on:clickoutside={closeMenu}>
<slot {node}>
<b> context menu openned from: {node?.nodePath}</b>
<slot node={clickedNode}>
<b> context menu openned from: {clickedNode?.path}</b>
</slot>
</Menu>
{/if}
3 changes: 0 additions & 3 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,6 @@ export type ExpandedCallback = (node: Node) => Promise<void>;

export type HelperConfig = {
separator: string;
recursive?: boolean;
recalculateNodePath?: boolean;
checkboxes?: SelectionModes;
};

export enum HighlighType {
Expand Down
2 changes: 1 addition & 1 deletion src/test/selection-helper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function getTree(treeHelper: TreeHelper, testSpecifcNodes: any[] = []): Tree {
}

function getHelper(recursive: boolean): { helper: TreeHelper; selection: SelectionProvider } {
const helper = new TreeHelper({ recursive, separator: '.' });
const helper = new TreeHelper({ separator: '.' });
const selection = new SelectionProvider(helper, recursive);
return { helper, selection };
}
Expand Down
6 changes: 3 additions & 3 deletions src/test/tree-helper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ function getTree(testSpecifcNodes: any[] = []) {
return [...testingTree, ...testSpecifcNodes].map((node) => ({ ...node, id: node.path } as Node));
}

function getHelper(recursive: boolean): { helper: TreeHelper } {
const helper = new TreeHelper({ recursive, separator: '.' });
function getHelper(): { helper: TreeHelper } {
const helper = new TreeHelper({ separator: '.' });
return { helper };
}

test('get all children of root', () => {
const { helper } = getHelper(true);
const { helper } = getHelper();
const tree = getTree();

const parentNodePath = null;
Expand Down

0 comments on commit db90df1

Please sign in to comment.