2.0.0 • Published 9 months ago

@keenmate/svelte-treeview v2.0.0

Weekly downloads
-
License
-
Repository
github
Last release
9 months ago

Svelte Treeview

The most elaborate treeview for svelte on earth (or even in our galaxy).

Features

  • load new nodes when expanding
  • choose what object properties to use to get necessary information (id, path, ...)
  • enable checkboxes on whole tree or just per node
  • recursive seletion mode, where leafes can be selected
  • build-in support for search
  • drag and drop functionality controlable per node
  • context menu
  • keyboard navigation

Instalation

install the package @keenmate/svelte-treeview using your favourite package manager.

!warning Font awesome is required for expand/collapse icons. If you wish to not use FA, you need to change all icons in classes properties

Minimal usage

Tree and treeId are only mandatory attributes. Tree has to be list of nodes. Only mandatory property of node is nodePath. You can specify which keys to use for what properties by setting props.

<script lang="ts">
 import { TreeView } from '$lib/index.js';

 let tree = [
  { nodePath: 'animals', title: 'Animals', hasChildren: true },
    //...
  { nodePath: 'animals.insects.butterflies', title: 'Butterflies' }
 ];
</script>

<TreeView {tree} treeId="my-tree" let:node>
 {node.title}
</TreeView>

For more examples see src/routes/

!note Both id and path is required for tree to work. By default tree uses nodePath property for both. So if you change propery fro path, you need to also change id property. You can change both using props attribute.

Properties

NameTypeDefaultDescription
treeIdstringvalue used to generate ids of nodes
treearray of nodesrepresents tree strucuture
valuearray of selected nodeIds[]
verticalLinesboolfalseshow vertical guide lines
readonlyboolfalsedont allow selection and drag and drop
separatorstring"."
recursiveSelectionboolfalsechanges behavior of selection, see Selection
selectionModeSelectionModesnonechanges selection mode, see Selection
onlyLeafCheckboxesboolfalsehides non leaf checkboxed, see Selection
hideDisabledCheckboxesboolfalsehides checkboxes instead of disabling, see Selection
loadChildrenAsyncExpandedCallbacknullfunction that is called when node is expanded, see Async loading
showContextMenuboolfalseOn right click dispaly context menu defined in context-menu slot, see Context menu
expansionThresholdnumber0Expand all nodes when there is less than number provided
customClassesPartial{}changes classes used on same elements, see Custom classes
filter(node: Node) => boolean or nullnullfunction that is used for fitlering. It is called on every node
dragAndDropboolfalseenables drag and drop, see Drag and drop
dropDisabledCallback(draggendNode: Node, targetNode: Node) => Promise or nullnullfunction called when draging over new node, see Drag and drop
useKeyboardNavigationboolfalseenables keyboard navigation , see Keyboard navigation
logger((...data: any[]) => void) or nullnullfunction that acts as logger for tree, mostly used for debugging

Selection

Async loading

Context menu

Custom classes

Drag and drop

!NOTE
In memory drag and drop is not yet supported. Tree just dispatches moved event with dragged node(node), target node (target) and insertion type (insertType). In future, this package will export function, that will allow you to easily compute new tree on frontend.

Keyboard navigation

Enable keyboard navigation by setting useKeyboardNavigation to true.

Use arrows to navigata tree. First you need to focus some node, you can use focusNode to do that. Use Enter or Space to select checkbox.

2.0.0

9 months ago

1.2.12

9 months ago

1.1.1

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago

1.2.8

12 months ago

1.2.7

12 months ago

1.1.7

12 months ago

1.1.6

12 months ago

1.1.5

12 months ago

1.1.4

12 months ago

1.1.3

12 months ago

1.1.2

12 months ago

1.0.0-beta.3

1 year ago

1.0.0-beta.4

1 year ago

1.0.0-beta.5

1 year ago

1.1.0-beta.2

1 year ago

1.1.0-beta.1

1 year ago

1.1.0-beta.0

1 year ago

1.0.0-beta.6

1 year ago

1.0.0-beta.7

1 year ago

1.2.9

12 months ago

1.1.0-beta.3

1 year ago

1.2.10

12 months ago

1.2.11

12 months ago

1.0.0-beta.2

1 year ago

1.0.0-beta.1

1 year ago

1.0.0-beta.0

1 year ago

0.3.6

1 year ago

0.3.5

1 year ago

0.3.2

1 year ago

0.3.1

1 year ago

0.3.4

1 year ago

0.3.3

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago

0.1.0

1 year ago