• Stars
    star
    146
  • Rank 252,769 (Top 5 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created almost 8 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A reactjs and vuejs tree component.

tree-component

Dependency Status devDependency Status Build Status: Windows Github CI npm version Downloads type-coverage

A reactjs and vuejs tree component.

features

  • vuejs component
  • reactjs component
  • open and close
  • select and deselect
  • disabled
  • loading
  • highlighted
  • checkbox
  • custom icon or no icon
  • drag and drop
  • no dots
  • large and small
  • default and dark theme
  • contextmenu(vuejs and reactjs only)
  • node id
  • custom node(vuejs and reactjs only)
  • drag and drop between different tree
  • composition model(reactjs children and vuejs slot)

link css

<link rel="stylesheet" href="./node_modules/tree-component/dist/tree.min.css" />

vuejs component

gzip size

npm i tree-vue-component

import { Node, Tree } from "tree-vue-component";

app.component('node', Node)
app.component('tree', Tree)

or

<script src="./node_modules/vue/dist/vue.min.js"></script>
<script src="./node_modules/tree-vue-component/dist/tree-vue-component.min.js"></script>
<tree :data="data"
    @toggle="toggle($event)"
    @change="change($event)">
</tree>

the online demo: https://plantain-00.github.io/tree-component/packages/vue/demo

reactjs component

gzip size

npm i tree-react-component

import { Tree } from "tree-react-component";

or

<script src="./node_modules/react/umd/react.production.min.js"></script>
<script src="./node_modules/react-dom/umd/react-dom.production.min.js"></script>
<script src="./node_modules/tree-react-component/dist/tree-react-component.min.js"></script>
<Tree data={data}
    toggle={this.toggle}
    change={this.change}>
</Tree>

the online demo: https://plantain-00.github.io/tree-component/packages/react/demo

properties and events of the component

name type description
data TreeData[] the data of the tree
checkbox boolean? show checkbox for node
draggable boolean? whether the node is draggable
nodots boolean? the tree will have no dots
size string? can also be "large", "small"
theme string? can be "default"(the default theme), "dark"
dropAllowed (dropData: common.DropData) => boolean optional, a function to show whether the drop action is allowed
zindex number? z-index of contextmenu
preid string? the node id prefix, eg: if preid = "test_", then a node's id can be test_1-2-3
toggle (eventData: EventData) => void triggered when opening or closing a node
change (eventData: EventData) => void triggered when selecting or deselecting a node
drop (dropData: DropData) => void triggered when drag a node, then drop it
dragTarget DragTargetData drag target, used when drag and drop between different tree
changeDragTarget (dragTarget: DragTargetData) => void triggered when drag target changed

tree data structure

type TreeData<T = any> = {
    text?: string;
    value?: T; // anything attached to the node
    icon?: string | false; // the icon class string, or no icon if is false
    state: TreeNodeState;
    children?: TreeData<T>[];
    contextmenu?: string | Function; // the contextmenu component, props: (data: ContextMenuData<T>)
    component?: string | Function; // the node component, props: (data: TreeData<T>)
};

type TreeNodeState = {
    opened: boolean; // whether the node show its children
    selected: boolean;
    disabled: boolean; // disabled node can not be selected and deselected
    loading: boolean; // show the loading icon, usually used when loading child nodes
    highlighted: boolean;
    openable: boolean; // can open or close even no children
    dropPosition: DropPosition;
    dropAllowed: boolean; // whether the drop action is allowed
};

const enum DropPosition {
    empty,
    up,
    inside,
    down,
}
// For javascript users, the enum type can not imported from the package,
// it is just number(0,1,2,3 in order), so you can use this instead:
const DropPosition = {
    empty: 0,
    up: 1,
    inside: 2,
    down: 3
}

event data structure

type EventData<T = any> = {
    data: TreeData<T>; // the data of the node that triggered the event
    path: number[]; // the index array of path from root to the node that triggered the event
};

drop data structure

type DropData<T = any> = {
    sourceData: TreeData<T>;
    sourcePath: number[];
    sourceRoot: TreeData<T>[];
    targetData: TreeData<T>;
    targetPath: number[];
};

contextmenu data structure

type ContextMenuData<T = any> = {
    data: TreeData<T>;
    path: number[];
    root: TreeData<T>[];
    parent?: any;
};

drag target data structure

type DragTargetData<T = any> = {
  root: TreeData<T>[];
  target: HTMLElement;
} | null

changelogs

# v5
// vue 2
import 'tree-vue-component'

# v6
// vue 3
import { Node, Tree } from "tree-vue-component"

app.component('node', Node)
app.component('tree', Tree)
# v4
npm i tree-component

# v5
npm i tree-vue-component
npm i tree-react-component
npm i tree-angular-component
// v4
import "tree-component/vue";
import { Tree } from "tree-component/react";
import { TreeModule } from "tree-component/angular";

// v5
import "tree-vue-component";
import { Tree } from "tree-react-component";
import { TreeModule } from "tree-angular-component";
// v4
<link rel="stylesheet" href="./node_modules/tree-component/tree.min.css" />

// v5
<link rel="stylesheet" href="./node_modules/tree-component/dist/tree.min.css" />
// v3 angular AOT:
import { TreeModule } from "tree-component/angular";

// v4 angular AOT:
import { TreeModule } from "tree-component/aot/angular";
// v3
import "tree-component/vue";
import { TreeComponent, NodeComponent } from "tree-component/angular";
import { Tree } from "tree-component/react";

// v2
import "tree-component/dist/vue";
import { TreeComponent, NodeComponent } from "tree-component/dist/angular";
import { Tree } from "tree-component/dist/react";
// v2:
<link rel="stylesheet" href="./node_modules/tree-component/tree.min.css" />

// v1:
<link rel="stylesheet" href="./node_modules/jstree/dist/themes/default/style.min.css" />

More Repositories

1

type-coverage

A CLI tool to check type coverage for typescript code
TypeScript
1,232
star
2

schema-based-json-editor

A reactjs and vuejs component of schema based json editor.
TypeScript
168
star
3

types-as-schema

Genetate json schema, protobuf file, graphQL schema and reasonml/ocaml/rust types from typescript types.
TypeScript
40
star
4

ws-tool

A Develop Tool to Test WebSocket, Socket.IO, Stomp, Bayeux, HTTP, TCP, UDP, WebRTC, DNS API.
TypeScript
25
star
5

js-excel-template

A js excel template used in browser or nodejs environment.
TypeScript
24
star
6

select2-component

A vuejs and reactjs select component.
TypeScript
23
star
7

tour-component

A vuejs and reactjs tour component.
TypeScript
22
star
8

ws-heartbeat

Server-side and client-side heartbeat library for ws and browser-side Websocket.
TypeScript
18
star
9

blogs

something to share
JavaScript
16
star
10

file-uploader-component

A reactjs and vuejs component of file uploader.
TypeScript
12
star
11

ws-benchmark

A CLI tool for websocket, like apache bench for http.
TypeScript
12
star
12

relative-time-component

A auto-updated vuejs and reactjs relative time component.
TypeScript
10
star
13

package-dependency-graph

A CLI tool to generate a dependency graph of packages in a monorepo by graphviz or dagre.
TypeScript
10
star
14

ExcelFile.net

A Excel File operator based on NPOI.
C#
8
star
15

expression-engine

An expression tokenizer, parser and evaluator.
TypeScript
8
star
16

ts-csinterface

Adobe extensions CSInterface v7.0 library implementation in typescript (identical to original).
TypeScript
7
star
17

js-split-file

A library to split big file to small binary data for nodejs and browsers.
TypeScript
7
star
18

Bootstrap.Pagination

a Bootstrap pagination and pager for asp.net MVC and Webform
C#
7
star
19

rev-static

Static asset revisioning by appending content hash to filenames, then changing the names in html files.
TypeScript
7
star
20

no-unused-export

A CLI tool to check whether exported things in a module is used by other modules for Typescript.
TypeScript
7
star
21

deploy-robot

a test and deploy robot.
TypeScript
7
star
22

template-editor-demo

A poster template edit and generation design document and demo.
TypeScript
6
star
23

composable-editor-canvas

A composable editor canvas library.
TypeScript
6
star
24

clean-scripts

A CLI tool to make scripts in package.json clean.
TypeScript
4
star
25

rpc-on-ws

A lightweight RPC library on websocket connection.
TypeScript
4
star
26

code-count

A CLI tool to count code lines and characters.
TypeScript
4
star
27

monitor-a-list-from-redis

A simple tool to watch some realtime data from a redis source
TypeScript
3
star
28

weighted-picker

A library to pick a random item from weighted array.
TypeScript
3
star
29

grid-js-component

A reactjs and vuejs grid component.
TypeScript
3
star
30

optimize-yarn-lock

A CLI to optimize yarn.lock
TypeScript
3
star
31

simple-doc

A Server-less and Build-less markdown document application.
TypeScript
3
star
32

ps-extendscript-types

Photoshop extendscript typescript types.
TypeScript
3
star
33

markdown_to_pdf

A CLI tool to convert a markdown to a pdf file.
TypeScript
2
star
34

news-fetcher-client

The client side of a cross-platform tool to get and sync news.
TypeScript
2
star
35

protocol-first-design-demo

TypeScript
2
star
36

code-structure

A CLI tool to generate code structure for javascript or typescript source code.
TypeScript
2
star
37

prune-node-modules

A CLI tool to prune node_modules.
TypeScript
2
star
38

stringify2stream

A js library to stringify json to stream to avoid out-of-memory of JSON.stringify.
TypeScript
2
star
39

dns-protocol

A Library to encode and parse data for DNS protocol.
TypeScript
2
star
40

js-project-initializer

A tool to initialize a js project.
TypeScript
2
star
41

vscode-type-coverage

VSCode plugin for type-coverage. deprecated.
TypeScript
2
star
42

copy-tool

A tool to copy text or file from one place, and get it from another place
TypeScript
2
star
43

json-field-size

A CLI tool to calculate size of all fields in a json, for memory analysis.
TypeScript
1
star
44

ease-in-out

An ease-in-out no-css animation library.
TypeScript
1
star
45

image2base64-cli

A CLI tool to convert image file to base64 string.
TypeScript
1
star
46

Despise

a library to generate fake data for test, such as name, email, phone, number and so on.
C#
1
star
47

pagination-js-component

A vuejs and reactjs pagination component.
TypeScript
1
star
48

protocol-based-web-framework

A protocol and code generation based web framework.
TypeScript
1
star
49

DbHelper.Obsolete.Oracle

a oracle access helper.
C#
1
star
50

watch-then-execute

A CLI tool to execute script after source file changes.
TypeScript
1
star
51

git-commits-to-changelog

A CLI to generate changelog from git commits.
TypeScript
1
star
52

router-demo

Multiple-application SPA and SSR demo
TypeScript
1
star
53

Form.Recover

a library to recover form data from json(obsolete)
C#
1
star
54

queued-jobs

A library to handle jobs in a smooth way with help of queue for nodejs and browser
TypeScript
1
star
55

tab-container-component

A vuejs and reactjs tab container component.
TypeScript
1
star
56

badge-svg

A library to generate badge svg
TypeScript
1
star
57

reconnection

A javascript library for browser or nodejs client reconnection.
TypeScript
1
star
58

prerender-js

[Obsolete]A CLI tool to prerender a page and save html element by id to a file.
TypeScript
1
star