{"id":13660895,"url":"https://github.com/plantain-00/tree-component","last_synced_at":"2025-04-07T08:27:03.822Z","repository":{"id":17066178,"uuid":"79797503","full_name":"plantain-00/tree-component","owner":"plantain-00","description":"A reactjs and vuejs tree component.","archived":false,"fork":false,"pushed_at":"2022-05-24T11:54:25.000Z","size":17978,"stargazers_count":146,"open_issues_count":8,"forks_count":32,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-04-25T12:21:12.097Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/plantain-00.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-01-23T11:15:35.000Z","updated_at":"2023-08-13T07:31:25.000Z","dependencies_parsed_at":"2022-07-15T20:30:38.837Z","dependency_job_id":null,"html_url":"https://github.com/plantain-00/tree-component","commit_stats":null,"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plantain-00%2Ftree-component","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plantain-00%2Ftree-component/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plantain-00%2Ftree-component/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plantain-00%2Ftree-component/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/plantain-00","download_url":"https://codeload.github.com/plantain-00/tree-component/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247617662,"owners_count":20967649,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T05:01:27.089Z","updated_at":"2025-04-07T08:27:03.789Z","avatar_url":"https://github.com/plantain-00.png","language":"TypeScript","readme":"# tree-component\n\n[![Dependency Status](https://david-dm.org/plantain-00/tree-component.svg)](https://david-dm.org/plantain-00/tree-component)\n[![devDependency Status](https://david-dm.org/plantain-00/tree-component/dev-status.svg)](https://david-dm.org/plantain-00/tree-component#info=devDependencies)\n[![Build Status: Windows](https://ci.appveyor.com/api/projects/status/github/plantain-00/tree-component?branch=master\u0026svg=true)](https://ci.appveyor.com/project/plantain-00/tree-component/branch/master)\n![Github CI](https://github.com/plantain-00/tree-component/workflows/Github%20CI/badge.svg)\n[![npm version](https://badge.fury.io/js/tree-component.svg)](https://badge.fury.io/js/tree-component)\n[![Downloads](https://img.shields.io/npm/dm/tree-component.svg)](https://www.npmjs.com/package/tree-component)\n[![type-coverage](https://img.shields.io/badge/dynamic/json.svg?label=type-coverage\u0026prefix=%E2%89%A5\u0026suffix=%\u0026query=$.typeCoverage.atLeast\u0026uri=https%3A%2F%2Fraw.githubusercontent.com%2Fplantain-00%2Ftree-component%2Fmaster%2Fpackage.json)](https://github.com/plantain-00/tree-component)\n\nA reactjs and vuejs tree component.\n\n## features\n\n+ vuejs component\n+ reactjs component\n+ open and close\n+ select and deselect\n+ disabled\n+ loading\n+ highlighted\n+ checkbox\n+ custom icon or no icon\n+ drag and drop\n+ no dots\n+ large and small\n+ default and dark theme\n+ contextmenu(vuejs and reactjs only)\n+ node id\n+ custom node(vuejs and reactjs only)\n+ drag and drop between different tree\n+ composition model(reactjs children and vuejs slot)\n\n## link css\n\n```html\n\u003clink rel=\"stylesheet\" href=\"./node_modules/tree-component/dist/tree.min.css\" /\u003e\n```\n\n## vuejs component\n\n[![gzip size](https://img.badgesize.io/https://unpkg.com/tree-vue-component?compression=gzip)](https://unpkg.com/tree-vue-component)\n\n`npm i tree-vue-component`\n\n```ts\nimport { Node, Tree } from \"tree-vue-component\";\n\napp.component('node', Node)\napp.component('tree', Tree)\n```\n\nor\n\n```html\n\u003cscript src=\"./node_modules/vue/dist/vue.min.js\"\u003e\u003c/script\u003e\n\u003cscript src=\"./node_modules/tree-vue-component/dist/tree-vue-component.min.js\"\u003e\u003c/script\u003e\n```\n\n```html\n\u003ctree :data=\"data\"\n    @toggle=\"toggle($event)\"\n    @change=\"change($event)\"\u003e\n\u003c/tree\u003e\n```\n\nthe online demo: \u003chttps://plantain-00.github.io/tree-component/packages/vue/demo\u003e\n\n## reactjs component\n\n[![gzip size](https://img.badgesize.io/https://unpkg.com/tree-react-component?compression=gzip)](https://unpkg.com/tree-react-component)\n\n`npm i tree-react-component`\n\n```ts\nimport { Tree } from \"tree-react-component\";\n```\n\nor\n\n```html\n\u003cscript src=\"./node_modules/react/umd/react.production.min.js\"\u003e\u003c/script\u003e\n\u003cscript src=\"./node_modules/react-dom/umd/react-dom.production.min.js\"\u003e\u003c/script\u003e\n\u003cscript src=\"./node_modules/tree-react-component/dist/tree-react-component.min.js\"\u003e\u003c/script\u003e\n```\n\n```html\n\u003cTree data={data}\n    toggle={this.toggle}\n    change={this.change}\u003e\n\u003c/Tree\u003e\n```\n\nthe online demo: \u003chttps://plantain-00.github.io/tree-component/packages/react/demo\u003e\n\n## properties and events of the component\n\nname | type | description\n--- | --- | ---\ndata | [TreeData](#tree-data-structure)[] | the data of the tree\ncheckbox | boolean? | show checkbox for node\ndraggable | boolean? | whether the node is draggable\nnodots | boolean? | the tree will have no dots\nsize | string? | can also be \"large\", \"small\"\ntheme | string? | can be \"default\"(the default theme), \"dark\"\ndropAllowed | (dropData: common.DropData) =\u003e boolean | optional, a function to show whether the drop action is allowed\nzindex | number? | z-index of contextmenu\npreid | string? | the node id prefix, eg: if `preid = \"test_\"`, then a node's id can be `test_1-2-3`\ntoggle | (eventData: [EventData](#event-data-structure)) =\u003e void | triggered when opening or closing a node\nchange | (eventData: [EventData](#event-data-structure)) =\u003e void | triggered when selecting or deselecting a node\ndrop | (dropData: [DropData](#drop-data-structure)) =\u003e void | triggered when drag a node, then drop it\ndragTarget | [DragTargetData](#drag-target-data-structure) | drag target, used when drag and drop between different tree\nchangeDragTarget | (dragTarget: [DragTargetData](#drag-target-data-structure)) =\u003e void | triggered when drag target changed\n\n## tree data structure\n\n```ts\ntype TreeData\u003cT = any\u003e = {\n    text?: string;\n    value?: T; // anything attached to the node\n    icon?: string | false; // the icon class string, or no icon if is false\n    state: TreeNodeState;\n    children?: TreeData\u003cT\u003e[];\n    contextmenu?: string | Function; // the contextmenu component, props: (data: ContextMenuData\u003cT\u003e)\n    component?: string | Function; // the node component, props: (data: TreeData\u003cT\u003e)\n};\n\ntype TreeNodeState = {\n    opened: boolean; // whether the node show its children\n    selected: boolean;\n    disabled: boolean; // disabled node can not be selected and deselected\n    loading: boolean; // show the loading icon, usually used when loading child nodes\n    highlighted: boolean;\n    openable: boolean; // can open or close even no children\n    dropPosition: DropPosition;\n    dropAllowed: boolean; // whether the drop action is allowed\n};\n\nconst enum DropPosition {\n    empty,\n    up,\n    inside,\n    down,\n}\n// For javascript users, the enum type can not imported from the package,\n// it is just number(0,1,2,3 in order), so you can use this instead:\nconst DropPosition = {\n    empty: 0,\n    up: 1,\n    inside: 2,\n    down: 3\n}\n```\n\n## event data structure\n\n```ts\ntype EventData\u003cT = any\u003e = {\n    data: TreeData\u003cT\u003e; // the data of the node that triggered the event\n    path: number[]; // the index array of path from root to the node that triggered the event\n};\n```\n\n## drop data structure\n\n```ts\ntype DropData\u003cT = any\u003e = {\n    sourceData: TreeData\u003cT\u003e;\n    sourcePath: number[];\n    sourceRoot: TreeData\u003cT\u003e[];\n    targetData: TreeData\u003cT\u003e;\n    targetPath: number[];\n};\n```\n\n## contextmenu data structure\n\n```ts\ntype ContextMenuData\u003cT = any\u003e = {\n    data: TreeData\u003cT\u003e;\n    path: number[];\n    root: TreeData\u003cT\u003e[];\n    parent?: any;\n};\n```\n\n## drag target data structure\n\n```ts\ntype DragTargetData\u003cT = any\u003e = {\n  root: TreeData\u003cT\u003e[];\n  target: HTMLElement;\n} | null\n```\n\n## changelogs\n\n```ts\n# v5\n// vue 2\nimport 'tree-vue-component'\n\n# v6\n// vue 3\nimport { Node, Tree } from \"tree-vue-component\"\n\napp.component('node', Node)\napp.component('tree', Tree)\n```\n\n```bash\n# v4\nnpm i tree-component\n\n# v5\nnpm i tree-vue-component\nnpm i tree-react-component\nnpm i tree-angular-component\n```\n\n```ts\n// v4\nimport \"tree-component/vue\";\nimport { Tree } from \"tree-component/react\";\nimport { TreeModule } from \"tree-component/angular\";\n\n// v5\nimport \"tree-vue-component\";\nimport { Tree } from \"tree-react-component\";\nimport { TreeModule } from \"tree-angular-component\";\n```\n\n```html\n// v4\n\u003clink rel=\"stylesheet\" href=\"./node_modules/tree-component/tree.min.css\" /\u003e\n\n// v5\n\u003clink rel=\"stylesheet\" href=\"./node_modules/tree-component/dist/tree.min.css\" /\u003e\n```\n\n```ts\n// v3 angular AOT:\nimport { TreeModule } from \"tree-component/angular\";\n\n// v4 angular AOT:\nimport { TreeModule } from \"tree-component/aot/angular\";\n```\n\n```ts\n// v3\nimport \"tree-component/vue\";\nimport { TreeComponent, NodeComponent } from \"tree-component/angular\";\nimport { Tree } from \"tree-component/react\";\n\n// v2\nimport \"tree-component/dist/vue\";\nimport { TreeComponent, NodeComponent } from \"tree-component/dist/angular\";\nimport { Tree } from \"tree-component/dist/react\";\n```\n\n```html\n// v2:\n\u003clink rel=\"stylesheet\" href=\"./node_modules/tree-component/tree.min.css\" /\u003e\n\n// v1:\n\u003clink rel=\"stylesheet\" href=\"./node_modules/jstree/dist/themes/default/style.min.css\" /\u003e\n```\n","funding_links":[],"categories":["TypeScript","UI组件","Components \u0026 Libraries","UI Components","UI Components [🔝](#readme)"],"sub_categories":["树","UI Components","Tree"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplantain-00%2Ftree-component","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fplantain-00%2Ftree-component","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplantain-00%2Ftree-component/lists"}