Skip to content

Commit

Permalink
decouple tree helpers and selections
Browse files Browse the repository at this point in the history
  • Loading branch information
ZelvaMan committed Apr 9, 2024
1 parent 3155760 commit f4f55a1
Show file tree
Hide file tree
Showing 9 changed files with 325 additions and 293 deletions.
11 changes: 1 addition & 10 deletions src/lib/Branch.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,6 @@
const getNodeId = (node: Node) => `${treeId}-${helper.path(node)}`;
// get children nodes
function getChildren(tree: Tree) {
const directChildren = helper.getDirectChildren(tree, helper.path(branchRootNode));
const orderedChildren = helper.dragDrop.OrderByPriority(directChildren);
return orderedChildren;
}
function setExpansion(node: Node, changeTo: boolean) {
dispatch('internal-expand', { node: node, changeTo });
}
Expand Down Expand Up @@ -135,7 +126,7 @@
class:child-menu={childDepth > 0}
class={childDepth === 0 ? classes.treeClass : ''}
>
{#each getChildren(tree) as node (getNodeId(node))}
{#each helper.getDirectChildren(tree, helper.path(branchRootNode)) as node (getNodeId(node))}
{@const nesthighlighed = highlightNesting(node, highlightedNode, validTarget, canNest)}
{@const insertHighlighted = highlightInsert(node, highlightedNode, validTarget, canNest)}
{@const expanded = isExpanded(node, childDepth, expandTo)}
Expand Down
6 changes: 5 additions & 1 deletion src/lib/Checkbox.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { createEventDispatcher } from 'svelte';
import { SelectionModes, type Node } from './types.js';
import type { TreeHelper } from '$lib/index.js';
import { SelectionProvider } from '$lib/providers/selection-provider.js';
export let checkboxes: SelectionModes;
export let helper: TreeHelper;
Expand All @@ -12,13 +13,16 @@
export let readonly = false;
let indeterminate: boolean;
$: {
if (helper.props.visualState(node) == 'indeterminate') {
indeterminate = true;
} else {
indeterminate = false;
}
}
// TODO pass from root
$: selectionProvider = new SelectionProvider(helper, recursive);
const dispatch = createEventDispatcher();
Expand All @@ -28,7 +32,7 @@
</script>

{#if checkboxes == SelectionModes.perNode || checkboxes == SelectionModes.all}
{#if helper.selection.isSelectable(node, checkboxes)}
{#if selectionProvider.isSelectable(node, checkboxes)}
<!-- select node -->
{#if !recursive || (recursive && !helper.props.hasChildren(node))}
<input
Expand Down
Loading

0 comments on commit f4f55a1

Please sign in to comment.