All Projects → geekhybrid → tree-vue

geekhybrid / tree-vue

Licence: MIT license
A lightweight library for handling hierarchical content. With full customizations of items rendering.

Programming Languages

typescript
32286 projects
Vue
7211 projects
javascript
184084 projects - #8 most used programming language
HTML
75241 projects
CSS
56736 projects

Projects that are alternatives of or similar to tree-vue

React Sortable Tree
Drag-and-drop sortable component for nested data and hierarchies
Stars: ✭ 4,348 (+17292%)
Mutual labels:  tree, hierarchical-data
treetime
TreeTime is a data organisation, management and analysis tool. A tree is a hierarchical structure that arranges information in units and sub-units. TreeTime uses linked trees (one data item can be part of different distinct trees) to store and organise any general purpose data.
Stars: ✭ 26 (+4%)
Mutual labels:  tree, hierarchical-data
stefano-tree
Framework agnostic Nested Set (MPTT) implementation for PHP
Stars: ✭ 24 (-4%)
Mutual labels:  tree, hierarchical-data
radixdb
Static Radix Tree (Patricia trie) implementation in C
Stars: ✭ 34 (+36%)
Mutual labels:  tree
markdown-explorer
Easily explore, view and edit markdown documentation of a file tree
Stars: ✭ 58 (+132%)
Mutual labels:  tree
tbcnn
Efficient tree-based convolutional neural networks in TensorFlow
Stars: ✭ 121 (+384%)
Mutual labels:  tree
nested-set
Nested Set is an Go implementation of the Nested set model for Gorm.
Stars: ✭ 44 (+76%)
Mutual labels:  tree
react-binary-tree
Binary Tree Traversal Visualisation
Stars: ✭ 25 (+0%)
Mutual labels:  tree
Graph-Theory
The Repository is All about the Graph Algorithms. I am Still Working On it. I am trying to Note down all the variations of Popular graph Algorithms. I am also keeping the solution to the problems of Different Online Judges according to the topic. I hope you can find it useful.
Stars: ✭ 16 (-36%)
Mutual labels:  tree
gradle-dependencies-viewer
A simple web UI to analyze dependencies for your project based on the text data generated from "gradle dependencies" command.
Stars: ✭ 70 (+180%)
Mutual labels:  tree
leaflet-layer-tree-plugin
No description or website provided.
Stars: ✭ 31 (+24%)
Mutual labels:  tree
silicate
A general form for complex data
Stars: ✭ 46 (+84%)
Mutual labels:  hierarchical-data
regexp-graph
No description or website provided.
Stars: ✭ 22 (-12%)
Mutual labels:  tree
tree-tree
No description or website provided.
Stars: ✭ 15 (-40%)
Mutual labels:  tree
ofxLSystem
3D turtle graphics interpretation of L-Systems
Stars: ✭ 39 (+56%)
Mutual labels:  tree
kdtree-rs
K-dimensional tree in Rust for fast geospatial indexing and lookup
Stars: ✭ 137 (+448%)
Mutual labels:  tree
extraction
Tree Extraction for JavaScript Object Graphs
Stars: ✭ 70 (+180%)
Mutual labels:  tree
dslib
🌿 A library of "connected" data structures
Stars: ✭ 122 (+388%)
Mutual labels:  tree
qverse
Traverse any data with DPML commands.
Stars: ✭ 25 (+0%)
Mutual labels:  tree
Algorithms
Data Structures & Algorithms. Includes solutions for Cracking the Coding Interview 6th Edition
Stars: ✭ 89 (+256%)
Mutual labels:  tree

Tree-Vue

A light-weight library for management of hierachical content. Most solutions I found did not offer the depth of flexibility I needed with the tree. I decided to solve my problem and also give back to the Vue community. Feel free to log issues, I will jump on them at the slightest opportunity. 😊

How to install.

npm: npm i v-tree-vue

Vue 3 Project: https://github.com/geekhybrid/vue3-tree-vue

Vue 3 npm package: npm i vue3-tree-vue

Features

  1. ✔️ Hierachical rendering of content.
  2. ✔️ Subscribing to items checked event (based on type)
  3. ✔️ Moving Items between folders (drag-and-drop)
  4. ✔️ Customising Item Rendering based on item type
  5. ✔️ Rendering selectable items like checkboxes or plain content
  6. ✔️ Double clicking to rename item

Features in Development

  1. Programmatically toggle item visibility based on the type property.
  2. Sorting items alphametically or grouping based on types
  3. Disabling and Enabling Item(s)
  4. Programmatically determining what item can be dragged into another item.
  5. -Custom Context Menu depending on item type.

image

Basic Component Rendering

<template>
    <tree-view :treeViewItems="treeViewNodes" />
</template>
<script lang='ts'>
import { Vue, Component} from 'vue-property-decorator';

import { TreeViewItem, ItemTypes } from '@/businessLogic/contracts/types';

@Component
export default class App extends Vue {
  treeViewNodes: TreeViewItem[] = []
}

Item Schema

export interface TreeViewItem {
    children?: TreeViewItem[]
    type: string
    checkedStatus?: CheckedState,
    name: string,
    id: string,
    parentId?: string
}

How to use Advance

Custom Icon Based on Item Type.

You can customise item based on their type property.

<template>
  <tree-view :treeViewItems="treeViewNodes">
      <template v-slot:icon="treeViewItem">
          <img src="@/assets/folder.svg" alt="folder" v-if="treeViewItem.type === 'folder'" >
          <img src="@/assets/word.png" alt="vue-logo" v-else-if="treeViewItem.type === '.doc'" height="22" width="22">
          <img src="@/assets/excel.png" alt="vue-logo" v-else-if="treeViewItem.type === '.excel'" height="22" width="22">
      </template>
  </tree-view>
</template>

Advanced Customisation

The library provides a way to further customise the tree view by listening to the v-on:created event from the tree-view component. The payload surplied provides robust set of options for configuring the tree.

Schema of CreatedEvent Payload

    export interface TreeViewCreatedEventPayload {
        itemCustomisations: ItemTypeCustomisations;
        eventManager: EventManager
        ...
    }

Schema for ItemTypeCustomisations

export interface ItemTypeCustomisations {
    isDropValid(droppedNode: TreeViewItem, dropHost: TreeViewItem): boolean;
    makeItemsCheckable(types: string[]): void;
    registerItemRenamedHandler(type: string, callback: (renamedItem: TreeViewItem) => Promise<TreeViewItem>): void;
    registerDragAndDropValidator(canItemMoveCallBack: (movingItem: TreeViewItem, destinationItem: TreeViewItem) => boolean): void;
    disableDragAndDrop(): void;
    
    getCustomisation(type: string): Customisations;
    getRenameHandler(type: string): (item: TreeViewItem) => Promise<TreeViewItem>;

    registerItemDeletedHandler(type: string, callback: (item: TreeViewItem) => Promise<boolean>): void;
    registerItemMovedHandler(callBack: (movedItem: TreeViewItem) => Promise<TreeViewItem>): void;
    
    registerAnyItemDeleted(callback: (item: TreeViewItem) => Promise<boolean>): void;
    registerAnyItemRenamed(callback: (item: TreeViewItem) => Promise<TreeViewItem>): void;
    registerAnyItemDragAndDrop(): void;
}

Example

<template>
  <tree-view :treeViewItems="treeViewNodes" @created="customiseTreeView" />
</template>
<script lang='ts'>
import { Vue, Component} from 'vue-property-decorator';

import { TreeViewCreatedEventPayload, TreeViewItem } from '@/businessLogic/contracts/types';

@Component
export default class App extends Vue {
  
  // This method is called when the tree view is created (on Created hook). And allows you to customise the tree-view items using the payload passed into the function.

  customiseTreeView(treeCreatedEvent: TreeViewCreatedEventPayload) {
    const customisations = treeCreatedEvent.itemCustomisations;
    
    // `Tree-vue` supports 2-major types of tree items. Checkable items or plain items.
    customisations.makeItemsCheckable([".doc", ".excel", "media" ]);
  }

  treeViewNodes: TreeViewItem[] = [] // Populate tree items here.
  ];
}
</script>

Output

image

Listening to Items Checked

To carter for advanced cases where children of the hierachical tree may be of different types. And you want to perform some further actions whenever something happens to them. You can subscribe for checked events of item types you may be interested in. And perform further actions.

Use case

E.g A school has departments, and you want to check some departments and delete them.

Solution

You can attach callbacks that notify you when departments have been checked on the tree.

How to Use

<template>    
    <!-- Examples of how to subscribe for events -->
    <tree-view :treeViewItems="schools" @created="customiseSchools" />
</template>
<script lang='ts'>
import { Vue, Component} from 'vue-property-decorator';

import { TreeViewCreatedEventPayload } from '@/businessLogic/contracts/types';

@Component
export default class App extends Vue {
  customiseSchools(treeCreatedEvent: TreeViewCreatedEventPayload) {
    const customisations = treeCreatedEvent.itemCustomisations;
    const eventManager = treeCreatedEvent.eventManager;

    eventManager.subscribeToItemChecked("department", (items) => console.log(items));
    customisations.makeItemsCheckable(["department"]);
  }
  schools: TreeViewItem[] = [
    {
      id: '1',
      type: 'school',
      name: 'Vue School',
      children: [
        {
          id: '2',
          type: 'department',
          name: 'Typescript Department',
          parentId: '1'
        },
        {
          id: '3',
          type: 'department',
          name: 'Open Source Department',
          parentId: '1'
        }
      ]
    }
  ]
}

Properties

Property Default Description
treeViewItems Empty array An array of TreeViewItem.
hideGuideLines false Determines the visibility of the guidelines
selectionMode Multiple Single or Multiple. This determines how many items can be simultaneously selected/checked in the tree.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].