Compare commits
57 Commits
1.0.6
...
add-licens
Author | SHA1 | Date | |
---|---|---|---|
![]() |
fab494cedf | ||
![]() |
ad6ad1b255 | ||
![]() |
9ded7fe914 | ||
![]() |
b07e14b9ff | ||
![]() |
fa2b7cb9dd | ||
![]() |
7b70e8dbf2 | ||
![]() |
b9402076ec | ||
![]() |
669e84fdc5 | ||
![]() |
146b61e70d | ||
![]() |
b3e238208b | ||
![]() |
4b8bbcbfde | ||
![]() |
0723294c7b | ||
![]() |
22988f0c81 | ||
![]() |
c46c570c30 | ||
![]() |
cfe90c7f81 | ||
![]() |
7e0184f7f5 | ||
![]() |
a78ff3f904 | ||
![]() |
cf41282fcf | ||
![]() |
6154cfd1ad | ||
![]() |
51167862c9 | ||
![]() |
e38102ed71 | ||
![]() |
d605642199 | ||
![]() |
62335d9eac | ||
![]() |
625dadcb44 | ||
![]() |
87b8a30bfb | ||
![]() |
2164d032ca | ||
![]() |
538678d916 | ||
![]() |
dd3d61ddf7 | ||
![]() |
e7757b97a7 | ||
![]() |
76e67c583c | ||
![]() |
106708217f | ||
![]() |
165d2dfb5d | ||
![]() |
8f0a5d7737 | ||
![]() |
a3b03a9579 | ||
![]() |
136b33971c | ||
![]() |
3dd6e31028 | ||
![]() |
cde7836539 | ||
![]() |
a8284583da | ||
![]() |
8cb42cd952 | ||
![]() |
5ab8775ace | ||
![]() |
3fec41a890 | ||
![]() |
867ef2a7fa | ||
![]() |
2b2b1419ad | ||
![]() |
47a4e2df8d | ||
![]() |
ec49d0e226 | ||
![]() |
52a63af52f | ||
![]() |
b10803df64 | ||
![]() |
7d35504b40 | ||
![]() |
b2eba3e3c9 | ||
![]() |
d6826e1a24 | ||
![]() |
a815fc658b | ||
![]() |
572b045314 | ||
![]() |
7bc8a7a17f | ||
![]() |
c3019872c5 | ||
![]() |
162c911f3b | ||
![]() |
a7b717334c | ||
![]() |
f6de5a2be8 |
10
.babelrc
10
.babelrc
@@ -1,10 +0,0 @@
|
|||||||
{
|
|
||||||
"presets": ["es2015", "stage-2"],
|
|
||||||
"plugins": ["transform-runtime"],
|
|
||||||
"comments": false,
|
|
||||||
"env": {
|
|
||||||
"test": {
|
|
||||||
"plugins": [ "istanbul" ]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
2
.commitlintrc.yml
Normal file
2
.commitlintrc.yml
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
extends:
|
||||||
|
- "@commitlint/config-conventional"
|
15
.github/workflows/test.yml
vendored
Normal file
15
.github/workflows/test.yml
vendored
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
name: Test
|
||||||
|
|
||||||
|
on: [pull_request, push]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v1
|
||||||
|
- name: npm install, lint and test
|
||||||
|
run: |
|
||||||
|
npm install
|
||||||
|
npm run lint
|
||||||
|
npm run test:unit
|
21
.gitignore
vendored
21
.gitignore
vendored
@@ -1,4 +1,21 @@
|
|||||||
|
.DS_Store
|
||||||
node_modules
|
node_modules
|
||||||
npm-debug.log
|
/dist
|
||||||
|
|
||||||
|
# local env files
|
||||||
|
.env.local
|
||||||
|
.env.*.local
|
||||||
|
|
||||||
|
# Log files
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
|
||||||
|
# Editor directories and files
|
||||||
.idea
|
.idea
|
||||||
coverage
|
.vscode
|
||||||
|
*.suo
|
||||||
|
*.ntvs*
|
||||||
|
*.njsproj
|
||||||
|
*.sln
|
||||||
|
*.sw?
|
||||||
|
4
.huskyrc.yml
Normal file
4
.huskyrc.yml
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
hooks:
|
||||||
|
pre-commit:
|
||||||
|
- npm run standard
|
||||||
|
commit-msg: commitlint -E HUSKY_GIT_PARAMS
|
21
LICENSE
Normal file
21
LICENSE
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2019 ayou
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
5
babel.config.js
Normal file
5
babel.config.js
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
module.exports = {
|
||||||
|
presets: [
|
||||||
|
'@vue/cli-plugin-babel/preset'
|
||||||
|
]
|
||||||
|
}
|
@@ -1,39 +0,0 @@
|
|||||||
var webpack = require('webpack');
|
|
||||||
var path = require('path');
|
|
||||||
|
|
||||||
var projectRoot = path.resolve(__dirname, '../')
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
module: {
|
|
||||||
loaders: [
|
|
||||||
{
|
|
||||||
test: /\.vue$/,
|
|
||||||
loader: 'vue'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
test: /\.js$/,
|
|
||||||
loader: 'babel',
|
|
||||||
include: [path.join(projectRoot, 'src'), path.join(projectRoot, 'dev')],
|
|
||||||
exclude: /node_modules/
|
|
||||||
},
|
|
||||||
{
|
|
||||||
test: /\.(woff2?|eot|ttf|otf|svg)(\?.*)?$/,
|
|
||||||
loader: 'url-loader',
|
|
||||||
query: {
|
|
||||||
limit: 10000,
|
|
||||||
name: 'fonts/[name].[hash:7].[ext]'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
vue: {
|
|
||||||
loaders: {
|
|
||||||
less: 'vue-style!css!less'
|
|
||||||
},
|
|
||||||
postcss: [
|
|
||||||
require('autoprefixer')({
|
|
||||||
browsers: ['iOS >= 7', 'Android >= 4.1']
|
|
||||||
})
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,16 +0,0 @@
|
|||||||
var webpack = require('webpack')
|
|
||||||
var merge = require('webpack-merge')
|
|
||||||
var baseConfig = require('./webpack.base.conf')
|
|
||||||
var path = require('path')
|
|
||||||
|
|
||||||
var projectRoot = path.resolve(__dirname, '../')
|
|
||||||
|
|
||||||
module.exports = merge(baseConfig, {
|
|
||||||
entry: './src/index.js',
|
|
||||||
output: {
|
|
||||||
path: path.resolve(projectRoot, 'dist'),
|
|
||||||
filename: 'vue-tree-list.min.js',
|
|
||||||
library: 'VueTreeList',
|
|
||||||
libraryTarget: 'umd'
|
|
||||||
}
|
|
||||||
})
|
|
@@ -1,28 +0,0 @@
|
|||||||
var webpack = require('webpack')
|
|
||||||
var merge = require('webpack-merge')
|
|
||||||
var HtmlWebpackPlugin = require('html-webpack-plugin')
|
|
||||||
var baseConfig = require('./webpack.base.conf')
|
|
||||||
var path = require('path')
|
|
||||||
|
|
||||||
var projectRoot = path.resolve(__dirname, '../')
|
|
||||||
|
|
||||||
module.exports = merge(baseConfig, {
|
|
||||||
entry: './dev/index.js',
|
|
||||||
devServer: {
|
|
||||||
historyApiFallback: true,
|
|
||||||
noInfo: true,
|
|
||||||
overlay: true,
|
|
||||||
open: true,
|
|
||||||
hot: true,
|
|
||||||
inline: true
|
|
||||||
},
|
|
||||||
devtool: '#eval-source-map',
|
|
||||||
plugins: [
|
|
||||||
new HtmlWebpackPlugin({
|
|
||||||
template: './dev/index.html',
|
|
||||||
filename: 'index.html',
|
|
||||||
inject: true
|
|
||||||
}),
|
|
||||||
new webpack.HotModuleReplacementPlugin()
|
|
||||||
]
|
|
||||||
})
|
|
84
dev/App.vue
84
dev/App.vue
@@ -1,7 +1,25 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<button @click="addNode">Add Node</button>
|
<button @click="addNode">Add Node</button>
|
||||||
<vue-tree-list @click="onClick" :model="data" default-tree-node-name="new node" default-leaf-node-name="new leaf"></vue-tree-list>
|
<vue-tree-list
|
||||||
|
@click="onClick"
|
||||||
|
@change-name="onChangeName"
|
||||||
|
@delete-node="onDel"
|
||||||
|
@add-node="onAddNode"
|
||||||
|
@drop="drop"
|
||||||
|
@drop-before="dropBefore"
|
||||||
|
@drop-after="dropAfter"
|
||||||
|
:model="data"
|
||||||
|
default-tree-node-name="new node"
|
||||||
|
default-leaf-node-name="new leaf"
|
||||||
|
v-bind:default-expanded="false">
|
||||||
|
<span class="icon" slot="addTreeNodeIcon">📂</span>
|
||||||
|
<span class="icon" slot="addLeafNodeIcon">+</span>
|
||||||
|
<span class="icon" slot="editNodeIcon">📃</span>
|
||||||
|
<span class="icon" slot="delNodeIcon">✂️</span>
|
||||||
|
<span class="icon" slot="leafNodeIcon">🍃</span>
|
||||||
|
<span class="icon" slot="treeNodeIcon">🌲</span>
|
||||||
|
</vue-tree-list>
|
||||||
<button @click="getNewTree">Get new tree</button>
|
<button @click="getNewTree">Get new tree</button>
|
||||||
<pre>
|
<pre>
|
||||||
{{newTree}}
|
{{newTree}}
|
||||||
@@ -23,6 +41,10 @@
|
|||||||
id: 1,
|
id: 1,
|
||||||
pid: 0,
|
pid: 0,
|
||||||
dragDisabled: true,
|
dragDisabled: true,
|
||||||
|
addTreeNodeDisabled: true,
|
||||||
|
addLeafNodeDisabled: true,
|
||||||
|
editNodeDisabled: true,
|
||||||
|
delNodeDisabled: true,
|
||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
name: 'Node 1-2',
|
name: 'Node 1-2',
|
||||||
@@ -36,7 +58,7 @@
|
|||||||
name: 'Node 2',
|
name: 'Node 2',
|
||||||
id: 3,
|
id: 3,
|
||||||
pid: 0,
|
pid: 0,
|
||||||
dragDisabled: true
|
disabled: true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Node 3',
|
name: 'Node 3',
|
||||||
@@ -47,13 +69,42 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
addNode: function () {
|
onDel (node) {
|
||||||
|
console.log(node)
|
||||||
|
node.remove()
|
||||||
|
},
|
||||||
|
|
||||||
|
onChangeName (params) {
|
||||||
|
console.log(params)
|
||||||
|
},
|
||||||
|
|
||||||
|
onAddNode (params) {
|
||||||
|
console.log(params)
|
||||||
|
},
|
||||||
|
|
||||||
|
onClick (params) {
|
||||||
|
console.log(params)
|
||||||
|
},
|
||||||
|
|
||||||
|
drop: function ({node, src, target}) {
|
||||||
|
console.log('drop', node, src, target)
|
||||||
|
},
|
||||||
|
|
||||||
|
dropBefore: function ({node, src, target}) {
|
||||||
|
console.log('drop-before', node, src, target)
|
||||||
|
},
|
||||||
|
|
||||||
|
dropAfter: function ({node, src, target}) {
|
||||||
|
console.log('drop-after', node, src, target)
|
||||||
|
},
|
||||||
|
|
||||||
|
addNode () {
|
||||||
var node = new TreeNode({ name: 'new node', isLeaf: false })
|
var node = new TreeNode({ name: 'new node', isLeaf: false })
|
||||||
if (!this.data.children) this.data.children = []
|
if (!this.data.children) this.data.children = []
|
||||||
this.data.addChildren(node)
|
this.data.addChildren(node)
|
||||||
},
|
},
|
||||||
|
|
||||||
getNewTree: function () {
|
getNewTree () {
|
||||||
var vm = this
|
var vm = this
|
||||||
function _dfs (oldNode) {
|
function _dfs (oldNode) {
|
||||||
var newNode = {}
|
var newNode = {}
|
||||||
@@ -74,11 +125,28 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
vm.newTree = _dfs(vm.data)
|
vm.newTree = _dfs(vm.data)
|
||||||
},
|
|
||||||
|
|
||||||
onClick(model) {
|
|
||||||
console.log(model)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
<style lang="less" rel="stylesheet/less">
|
||||||
|
.vtl {
|
||||||
|
.vtl-drag-disabled {
|
||||||
|
background-color: #d0cfcf;
|
||||||
|
&:hover {
|
||||||
|
background-color: #d0cfcf;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.vtl-disabled {
|
||||||
|
background-color: #d0cfcf;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<style lang="less" rel="stylesheet/less" scoped>
|
||||||
|
.icon {
|
||||||
|
&:hover {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
@@ -1,11 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta name="viewport" content="with=device-width,initial-scale=1.0,
|
|
||||||
maximum-scale=1.0,minimum-scale=1.0,uses-scalable=no">
|
|
||||||
<title>vue-date-range</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div id="app"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
1071
dist/vue-tree-list.min.js
vendored
1071
dist/vue-tree-list.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -59,6 +59,27 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.vtl .vtl-drag-disabled, .vtl .vtl-drag-disabled:hover {
|
||||||
|
background-color: #dbd7d7;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.vtl .vtl-drag-disabled::after, .vtl .vtl-disabled::after {
|
||||||
|
content: 'drag disabled';
|
||||||
|
position: absolute;
|
||||||
|
right: 10px;
|
||||||
|
font-size: 12px;
|
||||||
|
font-style: italic;
|
||||||
|
}
|
||||||
|
|
||||||
|
.vtl .vtl-disabled, .vtl .vtl-disabled:hover {
|
||||||
|
background-color: red;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.vtl .vtl-disabled::after {
|
||||||
|
content: 'disabled';
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
@@ -141,7 +162,7 @@
|
|||||||
name: 'Node 2',
|
name: 'Node 2',
|
||||||
id: 3,
|
id: 3,
|
||||||
pid: 0,
|
pid: 0,
|
||||||
dragDisabled: true
|
disabled: true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Node 3',
|
name: 'Node 3',
|
||||||
|
4
jest.config.js
Normal file
4
jest.config.js
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
module.exports = {
|
||||||
|
preset: "@vue/cli-plugin-unit-jest",
|
||||||
|
snapshotSerializers: ["jest-serializer-vue"]
|
||||||
|
};
|
13806
package-lock.json
generated
Normal file
13806
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
115
package.json
115
package.json
@@ -1,58 +1,77 @@
|
|||||||
{
|
{
|
||||||
"name": "vue-tree-list",
|
"name": "vue-tree-list",
|
||||||
"version": "1.0.6",
|
"version": "1.4.1",
|
||||||
"description": "A vue component for tree structure. Support adding treenode/leafnode, editing node's name and dragging.",
|
"description": "A vue component for tree structure. Support adding treenode/leafnode, editing node's name and dragging.",
|
||||||
"main": "dist/vue-tree-list.min.js",
|
|
||||||
"scripts": {
|
|
||||||
"test": "karma start --single-run",
|
|
||||||
"unit": "karma start --watch",
|
|
||||||
"coveralls": "npm run test -- --report lcovonly && cat ./coverage/lcov.info | coveralls",
|
|
||||||
"build": "webpack --config build/webpack.build.conf.js",
|
|
||||||
"dev": "webpack-dev-server --config build/webpack.dev.conf.js"
|
|
||||||
},
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "git+https://github.com/ParadeTo/vue-tree-list.git"
|
|
||||||
},
|
|
||||||
"keywords": [
|
|
||||||
"vue",
|
|
||||||
"tree"
|
|
||||||
],
|
|
||||||
"author": "ayou",
|
"author": "ayou",
|
||||||
"license": "ISC",
|
"scripts": {
|
||||||
|
"serve": "vue-cli-service serve dev",
|
||||||
|
"build": "vue-cli-service build --target lib src/index.js",
|
||||||
|
"test:unit": "vue-cli-service test:unit",
|
||||||
|
"lint": "vue-cli-service lint",
|
||||||
|
"commit": "npx git-cz",
|
||||||
|
"prepublish": "npm run build"
|
||||||
|
},
|
||||||
|
"main": "dist/vue-tree-list.umd.min.js",
|
||||||
|
"dependencies": {
|
||||||
|
"core-js": "^3.4.3",
|
||||||
|
"vue": "^2.6.10"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@vue/cli-plugin-babel": "^4.1.0",
|
||||||
|
"@vue/cli-plugin-eslint": "^4.1.0",
|
||||||
|
"@vue/cli-plugin-unit-jest": "^4.1.1",
|
||||||
|
"@vue/cli-service": "^4.1.0",
|
||||||
|
"@vue/test-utils": "1.0.0-beta.29",
|
||||||
|
"babel-eslint": "^10.0.3",
|
||||||
|
"eslint": "^5.16.0",
|
||||||
|
"eslint-plugin-vue": "^5.0.0",
|
||||||
|
"jest-serializer-vue": "^2.0.2",
|
||||||
|
"less": "^3.10.3",
|
||||||
|
"less-loader": "^5.0.0",
|
||||||
|
"vue-template-compiler": "^2.6.10"
|
||||||
|
},
|
||||||
|
"eslintConfig": {
|
||||||
|
"root": true,
|
||||||
|
"env": {
|
||||||
|
"node": true
|
||||||
|
},
|
||||||
|
"extends": [
|
||||||
|
"plugin:vue/essential",
|
||||||
|
"eslint:recommended"
|
||||||
|
],
|
||||||
|
"rules": {
|
||||||
|
"no-console": "warn"
|
||||||
|
},
|
||||||
|
"parserOptions": {
|
||||||
|
"parser": "babel-eslint"
|
||||||
|
},
|
||||||
|
"overrides": [
|
||||||
|
{
|
||||||
|
"files": [
|
||||||
|
"**/__tests__/*.{j,t}s?(x)",
|
||||||
|
"**/tests/unit/**/*.spec.{j,t}s?(x)"
|
||||||
|
],
|
||||||
|
"env": {
|
||||||
|
"jest": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"browserslist": [
|
||||||
|
"> 1%",
|
||||||
|
"last 2 versions"
|
||||||
|
],
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/ParadeTo/vue-tree-list/issues"
|
"url": "https://github.com/ParadeTo/vue-tree-list/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/ParadeTo/vue-tree-list#readme",
|
"homepage": "https://github.com/ParadeTo/vue-tree-list#readme",
|
||||||
"devDependencies": {
|
"keywords": [
|
||||||
"autoprefixer": "^6.4.0",
|
"vue",
|
||||||
"babel-core": "^6.0.0",
|
"tree"
|
||||||
"babel-eslint": "^7.0.0",
|
],
|
||||||
"babel-loader": "^6.0.0",
|
"license": "ISC",
|
||||||
"babel-plugin-istanbul": "^3.0.0",
|
"repository": {
|
||||||
"babel-plugin-transform-runtime": "^6.0.0",
|
"type": "git",
|
||||||
"babel-preset-es2015": "^6.0.0",
|
"url": "git+https://github.com/ParadeTo/vue-tree-list.git"
|
||||||
"babel-preset-stage-2": "^6.0.0",
|
|
||||||
"babel-register": "^6.0.0",
|
|
||||||
"chai": "^3.5.0",
|
|
||||||
"cross-env": "^5.0.1",
|
|
||||||
"css-loader": "^0.26.2",
|
|
||||||
"file-loader": "^0.10.1",
|
|
||||||
"isparta": "^4.0.0",
|
|
||||||
"isparta-loader": "^2.0.0",
|
|
||||||
"less": "^2.7.2",
|
|
||||||
"less-loader": "^2.2.3",
|
|
||||||
"sinon": "^2.3.5",
|
|
||||||
"sinon-chai": "^2.11.0",
|
|
||||||
"sourcemap": "^0.1.0",
|
|
||||||
"url-loader": "^0.5.7",
|
|
||||||
"vue": "^2.3.4",
|
|
||||||
"vue-loader": "^11.1.3",
|
|
||||||
"vue-style-loader": "^2.0.3",
|
|
||||||
"vue-template-compiler": "^2.2.0",
|
|
||||||
"webpack": "^1.13.2",
|
|
||||||
"webpack-dev-server": "1.14.0",
|
|
||||||
"webpack-merge": "^0.14.1",
|
|
||||||
"html-webpack-plugin": "^2.8.1"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
17
public/index.html
Normal file
17
public/index.html
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
|
<meta name="viewport" content="width=device-width,initial-scale=1.0">
|
||||||
|
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
|
||||||
|
<title>vue-tree-list</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<noscript>
|
||||||
|
<strong>We're sorry but vue-tree-list doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
|
||||||
|
</noscript>
|
||||||
|
<div id="app"></div>
|
||||||
|
<!-- built files will be auto injected -->
|
||||||
|
</body>
|
||||||
|
</html>
|
164
readme.md
164
readme.md
@@ -8,16 +8,36 @@ A vue component for tree structure. Support adding treenode/leafnode, editing no
|
|||||||
# use
|
# use
|
||||||
``npm install vue-tree-list``
|
``npm install vue-tree-list``
|
||||||
|
|
||||||
```javascript
|
```html
|
||||||
<button @click="addNode">Add Node</button>
|
<template>
|
||||||
<vue-tree-list @click="onClick" :model="data" default-tree-node-name="new node" default-leaf-node-name="new leaf"></vue-tree-list>
|
<div>
|
||||||
<button @click="getNewTree">Get new tree</button>
|
<button @click="addNode">Add Node</button>
|
||||||
<pre>
|
<vue-tree-list
|
||||||
|
@click="onClick"
|
||||||
|
@change-name="onChangeName"
|
||||||
|
@delete-node="onDel"
|
||||||
|
@add-node="onAddNode"
|
||||||
|
:model="data"
|
||||||
|
default-tree-node-name="new node"
|
||||||
|
default-leaf-node-name="new leaf"
|
||||||
|
v-bind:default-expanded="false">
|
||||||
|
<span class="icon" slot="addTreeNodeIcon">📂</span>
|
||||||
|
<span class="icon" slot="addLeafNodeIcon">+</span>
|
||||||
|
<span class="icon" slot="editNodeIcon">📃</span>
|
||||||
|
<span class="icon" slot="delNodeIcon">✂️</span>
|
||||||
|
<span class="icon" slot="leafNodeIcon">🍃</span>
|
||||||
|
<span class="icon" slot="treeNodeIcon">🌲</span>
|
||||||
|
</vue-tree-list>
|
||||||
|
<button @click="getNewTree">Get new tree</button>
|
||||||
|
<pre>
|
||||||
{{newTree}}
|
{{newTree}}
|
||||||
</pre>
|
</pre>
|
||||||
...
|
</div>
|
||||||
import { VueTreeList, Tree, TreeNode } from '../src'
|
</template>
|
||||||
export default {
|
|
||||||
|
<script>
|
||||||
|
import { VueTreeList, Tree, TreeNode } from 'vue-tree-list'
|
||||||
|
export default {
|
||||||
components: {
|
components: {
|
||||||
VueTreeList
|
VueTreeList
|
||||||
},
|
},
|
||||||
@@ -30,6 +50,10 @@ export default {
|
|||||||
id: 1,
|
id: 1,
|
||||||
pid: 0,
|
pid: 0,
|
||||||
dragDisabled: true,
|
dragDisabled: true,
|
||||||
|
addTreeNodeDisabled: true,
|
||||||
|
addLeafNodeDisabled: true,
|
||||||
|
editNodeDisabled: true,
|
||||||
|
delNodeDisabled: true,
|
||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
name: 'Node 1-2',
|
name: 'Node 1-2',
|
||||||
@@ -43,7 +67,7 @@ export default {
|
|||||||
name: 'Node 2',
|
name: 'Node 2',
|
||||||
id: 3,
|
id: 3,
|
||||||
pid: 0,
|
pid: 0,
|
||||||
dragDisabled: true
|
disabled: true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Node 3',
|
name: 'Node 3',
|
||||||
@@ -54,13 +78,30 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
addNode: function () {
|
onDel (node) {
|
||||||
|
console.log(node)
|
||||||
|
node.remove()
|
||||||
|
},
|
||||||
|
|
||||||
|
onChangeName (params) {
|
||||||
|
console.log(params)
|
||||||
|
},
|
||||||
|
|
||||||
|
onAddNode (params) {
|
||||||
|
console.log(params)
|
||||||
|
},
|
||||||
|
|
||||||
|
onClick (params) {
|
||||||
|
console.log(params)
|
||||||
|
},
|
||||||
|
|
||||||
|
addNode () {
|
||||||
var node = new TreeNode({ name: 'new node', isLeaf: false })
|
var node = new TreeNode({ name: 'new node', isLeaf: false })
|
||||||
if (!this.data.children) this.data.children = []
|
if (!this.data.children) this.data.children = []
|
||||||
this.data.addChildren(node)
|
this.data.addChildren(node)
|
||||||
},
|
},
|
||||||
|
|
||||||
getNewTree: function () {
|
getNewTree () {
|
||||||
var vm = this
|
var vm = this
|
||||||
function _dfs (oldNode) {
|
function _dfs (oldNode) {
|
||||||
var newNode = {}
|
var newNode = {}
|
||||||
@@ -83,43 +124,86 @@ export default {
|
|||||||
vm.newTree = _dfs(vm.data)
|
vm.newTree = _dfs(vm.data)
|
||||||
},
|
},
|
||||||
|
|
||||||
onClick(model) {
|
|
||||||
console.log(model)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
</script>
|
||||||
|
|
||||||
|
<style lang="less" rel="stylesheet/less">
|
||||||
|
.vtl {
|
||||||
|
.vtl-drag-disabled {
|
||||||
|
background-color: #d0cfcf;
|
||||||
|
&:hover {
|
||||||
|
background-color: #d0cfcf;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.vtl-disabled {
|
||||||
|
background-color: #d0cfcf;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<style lang="less" rel="stylesheet/less" scoped>
|
||||||
|
.icon {
|
||||||
|
&:hover {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
# props
|
# props
|
||||||
**default-tree-node-name**
|
## props of vue-tree-list
|
||||||
|
| name | type | default | description |
|
||||||
|
|:-----:|:-------:|:------------:|:----:|
|
||||||
|
model | TreeNode | - | You can use `const head = new Tree([])` to generate a tree with the head of `TreeNode` type
|
||||||
|
default-tree-node-name | string | New node node | Default name for new treenode
|
||||||
|
default-leaf-node-name | string | New leaf node | Default name for new leafnode
|
||||||
|
default-expanded | boolean | true | Tree is expanded or not
|
||||||
|
|
||||||
Default name for new treenode.
|
|
||||||
|
|
||||||
**default-leaf-node-name**
|
## props of TreeNode
|
||||||
|
### attributes
|
||||||
|
| name | type | default | description |
|
||||||
|
|:-----:|:-------:|:------------:|:----:|
|
||||||
|
id | string, number | current timestamp | The node's id
|
||||||
|
isLeaf | boolean | false | The node is leaf or not
|
||||||
|
dragDisabled | boolean | false | Forbid dragging tree node
|
||||||
|
addTreeNodeDisabled | boolean | false | Show `addTreeNode` button or not
|
||||||
|
addLeafNodeDisabled | boolean | false | Show `addLeafNode` button or not
|
||||||
|
editNodeDisabled | boolean | false | Show `editNode` button or not
|
||||||
|
delNodeDisabled | boolean | false | Show `delNode` button or not
|
||||||
|
children | array | null | The children of node
|
||||||
|
|
||||||
Default name for new leafnode.
|
### methods
|
||||||
|
| name | params | description |
|
||||||
|
|:-----:|:-------:|:----:|
|
||||||
|
changeName | name | Change node's name
|
||||||
|
addChildren | children: object, array | Add children to node
|
||||||
|
remove | - | Remove node from the tree
|
||||||
|
moveInto | target: TreeNode | Move node into another node
|
||||||
|
insertBefore | target: TreeNode | Move node before another node
|
||||||
|
insertAfter | target: TreeNode | Move node after another node
|
||||||
|
|
||||||
# events
|
# events
|
||||||
**click**
|
| name | params | description |
|
||||||
|
|:-----:|:-------:|:----:|
|
||||||
|
click | TreeNode | Trigger when clicking a tree node
|
||||||
|
change-name | {'id', 'oldName', 'newName'} | Trigger after changing a node's name
|
||||||
|
delete-node | TreeNode | Trigger when clicking `delNode` button. You can call `remove` of `TreeNode` to remove the node.
|
||||||
|
add-node | TreeNode | Trigger after adding a new node
|
||||||
|
drop | {node, src, target} | Trigger after dropping a node into another. node: the draggable node, src: the draggable node's parent, target: the node that draggable node will drop into
|
||||||
|
drop-before | {node, src, target} | Trigger after dropping a node before another. node: the draggable node, src: the draggable node's parent, target: the node that draggable node will drop before
|
||||||
|
drop-after | {node, src, target} | Trigger after dropping a node after another. node: the draggable node, src: the draggable node's parent, target: the node that draggable node will drop after
|
||||||
|
|
||||||
```javascript
|
# customize operation icons
|
||||||
<vue-tree-list @click="onClick" ...
|
The component has default icons for `addTreeNodeIcon`, `addLeafNodeIcon`, `editNodeIcon`, `delNodeIcon`, `leafNodeIcon`, `treeNodeIcon` button, but you can also customize them:
|
||||||
...
|
|
||||||
onClick(model) {
|
```html
|
||||||
console.log(model)
|
<span class="icon" slot="addTreeNodeIcon">📂</span>
|
||||||
}
|
<span class="icon" slot="addLeafNodeIcon">+</span>
|
||||||
...
|
<span class="icon" slot="editNodeIcon">📃</span>
|
||||||
|
<span class="icon" slot="delNodeIcon">✂️</span>
|
||||||
|
<span class="icon" slot="leafNodeIcon">🍃</span>
|
||||||
|
<span class="icon" slot="treeNodeIcon">🌲</span>
|
||||||
```
|
```
|
||||||
|
|
||||||
# Forbid dragging
|
|
||||||
Use `dragDisabled` to forbid dragging:
|
|
||||||
```javascript
|
|
||||||
data: new Tree([
|
|
||||||
{
|
|
||||||
name: 'Node 1',
|
|
||||||
id: 1,
|
|
||||||
pid: 0,
|
|
||||||
dragDisabled: true,
|
|
||||||
...
|
|
||||||
```
|
|
||||||
|
|
||||||
|
57
src/Tree.js
57
src/Tree.js
@@ -1,8 +1,3 @@
|
|||||||
// used to record treenode's change
|
|
||||||
// let Record = {}
|
|
||||||
// treenode's id
|
|
||||||
let nodeId = 1
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tree data struct
|
* Tree data struct
|
||||||
* Created by ayou on 2017/7/20.
|
* Created by ayou on 2017/7/20.
|
||||||
@@ -11,13 +6,12 @@ let nodeId = 1
|
|||||||
* isLeaf: treenode is leaf node or not
|
* isLeaf: treenode is leaf node or not
|
||||||
* id: id
|
* id: id
|
||||||
* dragDisabled: decide if it can be dragged
|
* dragDisabled: decide if it can be dragged
|
||||||
|
* disabled: desabled all operation
|
||||||
*/
|
*/
|
||||||
const TreeNode = function (data) {
|
const TreeNode = function (data) {
|
||||||
const { id, isLeaf } = data
|
const { id, isLeaf } = data
|
||||||
// this.name = name
|
this.id = (typeof id === 'undefined') ? new Date().valueOf() : id
|
||||||
this.id = (typeof id === 'undefined') ? ('new' + nodeId++) : id
|
|
||||||
this.parent = null
|
this.parent = null
|
||||||
// this.pid = null
|
|
||||||
this.children = null
|
this.children = null
|
||||||
this.isLeaf = !!isLeaf
|
this.isLeaf = !!isLeaf
|
||||||
|
|
||||||
@@ -29,25 +23,11 @@ const TreeNode = function (data) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TreeNode.prototype.updateRecordProperty = function () {
|
|
||||||
// if (!Record[this.id]) {
|
|
||||||
// Record[this.id] = {}
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// Record[this.id].name = this.name
|
|
||||||
// Record[this.id].id = this.id
|
|
||||||
// Record[this.id].pid = this.pid
|
|
||||||
// Record[this.id].isLeaf = this.isLeaf
|
|
||||||
// }
|
|
||||||
|
|
||||||
TreeNode.prototype.changeName = function (name) {
|
TreeNode.prototype.changeName = function (name) {
|
||||||
this.name = name
|
this.name = name
|
||||||
|
|
||||||
// this.updateRecordProperty()
|
|
||||||
// Record[this.id].modify = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TreeNode.prototype.addChildren = function (children, isNew) {
|
TreeNode.prototype.addChildren = function (children) {
|
||||||
if (!this.children) {
|
if (!this.children) {
|
||||||
this.children = []
|
this.children = []
|
||||||
}
|
}
|
||||||
@@ -57,11 +37,6 @@ TreeNode.prototype.addChildren = function (children, isNew) {
|
|||||||
const child = children[i]
|
const child = children[i]
|
||||||
child.parent = this
|
child.parent = this
|
||||||
child.pid = this.id
|
child.pid = this.id
|
||||||
|
|
||||||
// if (isNew) {
|
|
||||||
// child.updateRecordProperty()
|
|
||||||
// Record[child.id].add = true
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
this.children.concat(children)
|
this.children.concat(children)
|
||||||
} else {
|
} else {
|
||||||
@@ -69,11 +44,6 @@ TreeNode.prototype.addChildren = function (children, isNew) {
|
|||||||
child.parent = this
|
child.parent = this
|
||||||
child.pid = this.id
|
child.pid = this.id
|
||||||
this.children.push(child)
|
this.children.push(child)
|
||||||
|
|
||||||
// if (isNew) {
|
|
||||||
// child.updateRecordProperty()
|
|
||||||
// Record[child.id].add = true
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,9 +52,6 @@ TreeNode.prototype.remove = function () {
|
|||||||
const parent = this.parent
|
const parent = this.parent
|
||||||
const index = parent.findChildIndex(this)
|
const index = parent.findChildIndex(this)
|
||||||
parent.children.splice(index, 1)
|
parent.children.splice(index, 1)
|
||||||
|
|
||||||
// this.updateRecordProperty()
|
|
||||||
// Record[this.id].remove = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove child
|
// remove child
|
||||||
@@ -130,11 +97,6 @@ TreeNode.prototype.moveInto = function (target) {
|
|||||||
target.children = []
|
target.children = []
|
||||||
}
|
}
|
||||||
target.children.unshift(this)
|
target.children.unshift(this)
|
||||||
|
|
||||||
// this.updateRecordProperty()
|
|
||||||
// Record[this.id].targetId = target.id
|
|
||||||
// Record[this.id].move = true
|
|
||||||
// Record[this.id].moveType = 'inside'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TreeNode.prototype.findChildIndex = function (child) {
|
TreeNode.prototype.findChildIndex = function (child) {
|
||||||
@@ -169,11 +131,6 @@ TreeNode.prototype.insertBefore = function (target) {
|
|||||||
|
|
||||||
const pos = target.parent.findChildIndex(target)
|
const pos = target.parent.findChildIndex(target)
|
||||||
target.parent.children.splice(pos, 0, this)
|
target.parent.children.splice(pos, 0, this)
|
||||||
|
|
||||||
// this.updateRecordProperty()
|
|
||||||
// Record[this.id].targetId = target.id
|
|
||||||
// Record[this.id].move = true
|
|
||||||
// Record[this.id].moveType = 'before'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TreeNode.prototype.insertAfter = function (target) {
|
TreeNode.prototype.insertAfter = function (target) {
|
||||||
@@ -181,14 +138,9 @@ TreeNode.prototype.insertAfter = function (target) {
|
|||||||
|
|
||||||
const pos = target.parent.findChildIndex(target)
|
const pos = target.parent.findChildIndex(target)
|
||||||
target.parent.children.splice(pos + 1, 0, this)
|
target.parent.children.splice(pos + 1, 0, this)
|
||||||
|
|
||||||
// this.updateRecordProperty()
|
|
||||||
// Record[this.id].targetId = target.id
|
|
||||||
// Record[this.id].move = true
|
|
||||||
// Record[this.id].moveType = 'after'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function Tree(data) {
|
function Tree (data) {
|
||||||
this.root = new TreeNode({ name: 'root', isLeaf: false, id: 0 })
|
this.root = new TreeNode({ name: 'root', isLeaf: false, id: 0 })
|
||||||
this.initNode(this.root, data)
|
this.initNode(this.root, data)
|
||||||
return this.root
|
return this.root
|
||||||
@@ -208,4 +160,3 @@ Tree.prototype.initNode = function (node, data) {
|
|||||||
|
|
||||||
exports.Tree = Tree
|
exports.Tree = Tree
|
||||||
exports.TreeNode = TreeNode
|
exports.TreeNode = TreeNode
|
||||||
// exports.Record = Record
|
|
||||||
|
@@ -1,12 +1,12 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div class='vtl'>
|
||||||
<div v-if="model.name !== 'root'">
|
<div v-if="model.name !== 'root'">
|
||||||
<div class="border up" :class="{'active': isDragEnterUp}"
|
<div class="vtl-border vtl-up" :class="{'vtl-active': isDragEnterUp}"
|
||||||
@drop="dropUp"
|
@drop="dropBefore"
|
||||||
@dragenter="dragEnterUp"
|
@dragenter="dragEnterUp"
|
||||||
@dragover='dragOverUp'
|
@dragover='dragOverUp'
|
||||||
@dragleave="dragLeaveUp"></div>
|
@dragleave="dragLeaveUp"></div>
|
||||||
<div class='tree-node' :id='model.id' :class="{'active': isDragEnterNode}"
|
<div :id='model.id' :class="treeNodeClass"
|
||||||
:draggable="!model.dragDisabled"
|
:draggable="!model.dragDisabled"
|
||||||
@dragstart='dragStart'
|
@dragstart='dragStart'
|
||||||
@dragover='dragOver'
|
@dragover='dragOver'
|
||||||
@@ -17,74 +17,81 @@
|
|||||||
@mouseover='mouseOver'
|
@mouseover='mouseOver'
|
||||||
@mouseout='mouseOut'
|
@mouseout='mouseOut'
|
||||||
@click.stop='click'>
|
@click.stop='click'>
|
||||||
<span class="caret icon is-small" v-if="model.children && model.children.length > 0">
|
<span class="vtl-caret vtl-is-small" v-if="model.children && model.children.length > 0">
|
||||||
<i class="vue-tree-icon" :class="caretClass" @click.prevent.stop="toggle"></i>
|
<i class="vtl-icon" :class="caretClass" @click.prevent.stop="toggle"></i>
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
<span v-if="model.isLeaf">
|
<span v-if="model.isLeaf">
|
||||||
<slot name="leafNodeIcon">
|
<slot name="leafNodeIcon">
|
||||||
<i class="vue-tree-icon item-icon icon-file"></i>
|
<i class="vtl-icon vtl-menu-icon vtl-icon-file"></i>
|
||||||
</slot>
|
</slot>
|
||||||
</span>
|
</span>
|
||||||
<span v-else>
|
<span v-else>
|
||||||
<slot name="treeNodeIcon">
|
<slot name="treeNodeIcon">
|
||||||
<i class="vue-tree-icon item-icon icon-folder"></i>
|
<i class="vtl-icon vtl-menu-icon vtl-icon-folder"></i>
|
||||||
</slot>
|
</slot>
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
<div class="node-content" v-if="!editable">
|
<div class="vtl-node-content" v-if="!editable">
|
||||||
{{model.name}}
|
{{model.name}}
|
||||||
</div>
|
</div>
|
||||||
<input v-else class="vue-tree-input" type="text" ref="nodeInput" :value="model.name" @input="updateName" @blur="setUnEditable">
|
<input v-else class="vtl-input" type="text" ref="nodeInput" :value="model.name" @input="updateName" @blur="setUnEditable">
|
||||||
<div class="operation" v-show="isHover">
|
<div class="vtl-operation" v-show="isHover">
|
||||||
<span title="add tree node" @click.stop.prevent="addChild(false)" v-if="!model.isLeaf">
|
<span title="add tree node" @click.stop.prevent="addChild(false)" v-if="!model.isLeaf && !model.addTreeNodeDisabled">
|
||||||
<slot name="addTreeNode">
|
<slot name="addTreeNodeIcon">
|
||||||
<i class="vue-tree-icon icon-folder-plus-e"></i>
|
<i class="vtl-icon vtl-icon-folder-plus-e"></i>
|
||||||
</slot>
|
</slot>
|
||||||
</span>
|
</span>
|
||||||
<span title="add tree node" @click.stop.prevent="addChild(true)" v-if="!model.isLeaf">
|
<span title="add leaf node" @click.stop.prevent="addChild(true)" v-if="!model.isLeaf && !model.addLeafNodeDisabled">
|
||||||
<slot name="addLeafNode">
|
<slot name="addLeafNodeIcon">
|
||||||
<i class="vue-tree-icon icon-plus"></i>
|
<i class="vtl-icon vtl-icon-plus"></i>
|
||||||
</slot>
|
</slot>
|
||||||
</span>
|
</span>
|
||||||
<span title="edit" @click.stop.prevent="setEditable">
|
<span title="edit" @click.stop.prevent="setEditable" v-if="!model.editNodeDisabled">
|
||||||
<slot name="edit">
|
<slot name="editNodeIcon">
|
||||||
<i class="vue-tree-icon icon-edit"></i>
|
<i class="vtl-icon vtl-icon-edit"></i>
|
||||||
</slot>
|
</slot>
|
||||||
</span>
|
</span>
|
||||||
<span title="delete" @click.stop.prevent="delNode">
|
<span title="delete" @click.stop.prevent="delNode" v-if="!model.delNodeDisabled">
|
||||||
<slot name="edit">
|
<slot name="delNodeIcon">
|
||||||
<i class="vue-tree-icon icon-trash"></i>
|
<i class="vtl-icon vtl-icon-trash"></i>
|
||||||
</slot>
|
</slot>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-if="model.children && model.children.length > 0 && expanded"
|
<div v-if="model.children && model.children.length > 0 && expanded"
|
||||||
class="border bottom"
|
class="vtl-border vtl-bottom"
|
||||||
:class="{'active': isDragEnterBottom}"
|
:class="{'vtl-active': isDragEnterBottom}"
|
||||||
@drop="dropBottom"
|
@drop="dropAfter"
|
||||||
@dragenter="dragEnterBottom"
|
@dragenter="dragEnterBottom"
|
||||||
@dragover='dragOverBottom'
|
@dragover='dragOverBottom'
|
||||||
@dragleave="dragLeaveBottom"></div>
|
@dragleave="dragLeaveBottom"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div :class="{'tree-margin': model.name !== 'root'}" v-show="expanded" v-if="isFolder">
|
<div :class="{'vtl-tree-margin': model.name !== 'root'}" v-show="model.name === 'root' || expanded" v-if="isFolder">
|
||||||
<item v-for="model in model.children"
|
<item v-for="model in model.children"
|
||||||
:default-tree-node-name="defaultTreeNodeName"
|
:default-tree-node-name="defaultTreeNodeName"
|
||||||
:default-leaf-node-name="defaultLeafNodeName"
|
:default-leaf-node-name="defaultLeafNodeName"
|
||||||
|
v-bind:default-expanded="defaultExpanded"
|
||||||
:model="model"
|
:model="model"
|
||||||
:key='model.id'>
|
:key='model.id'>
|
||||||
|
<slot name="addTreeNodeIcon" slot="addTreeNodeIcon" />
|
||||||
|
<slot name="addLeafNodeIcon" slot="addLeafNodeIcon" />
|
||||||
|
<slot name="editNodeIcon" slot="editNodeIcon" />
|
||||||
|
<slot name="delNodeIcon" slot="delNodeIcon" />
|
||||||
|
<slot name="leafNodeIcon" slot="leafNodeIcon" />
|
||||||
|
<slot name="treeNodeIcon" slot="treeNodeIcon" />
|
||||||
</item>
|
</item>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { Tree, TreeNode } from './Tree.js'
|
import { TreeNode } from './Tree.js'
|
||||||
import { addHandler, removeHandler } from './tools.js'
|
import { addHandler, removeHandler } from './tools.js'
|
||||||
|
|
||||||
let fromComp = null
|
let compInOperation = null
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data: function () {
|
data: function () {
|
||||||
@@ -94,7 +101,7 @@
|
|||||||
isDragEnterUp: false,
|
isDragEnterUp: false,
|
||||||
isDragEnterBottom: false,
|
isDragEnterBottom: false,
|
||||||
isDragEnterNode: false,
|
isDragEnterNode: false,
|
||||||
expanded: true
|
expanded: this.defaultExpanded
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
@@ -108,21 +115,45 @@
|
|||||||
defaultTreeNodeName: {
|
defaultTreeNodeName: {
|
||||||
type: String,
|
type: String,
|
||||||
default: 'New tree node'
|
default: 'New tree node'
|
||||||
|
},
|
||||||
|
defaultExpanded: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
itemIconClass () {
|
itemIconClass () {
|
||||||
return this.model.isLeaf ? 'icon-file' : 'icon-folder'
|
return this.model.isLeaf ? 'vtl-icon-file' : 'vtl-icon-folder'
|
||||||
},
|
},
|
||||||
|
|
||||||
caretClass () {
|
caretClass () {
|
||||||
return this.expanded ? 'icon-caret-down' : 'icon-caret-right'
|
return this.expanded ? 'vtl-icon-caret-down' : 'vtl-icon-caret-right'
|
||||||
},
|
},
|
||||||
|
|
||||||
isFolder() {
|
isFolder () {
|
||||||
return this.model.children &&
|
return this.model.children &&
|
||||||
this.model.children.length
|
this.model.children.length
|
||||||
|
},
|
||||||
|
|
||||||
|
treeNodeClass () {
|
||||||
|
const {
|
||||||
|
model: {
|
||||||
|
dragDisabled,
|
||||||
|
disabled
|
||||||
|
},
|
||||||
|
isDragEnterNode
|
||||||
|
} = this
|
||||||
|
|
||||||
|
return {
|
||||||
|
'vtl-tree-node': true,
|
||||||
|
'vtl-active': isDragEnterNode,
|
||||||
|
'vtl-drag-disabled': dragDisabled,
|
||||||
|
'vtl-disabled': disabled
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
beforeCreate () {
|
||||||
|
this.$options.components.item = require('./VueTreeList').default
|
||||||
},
|
},
|
||||||
mounted () {
|
mounted () {
|
||||||
const vm = this
|
const vm = this
|
||||||
@@ -138,21 +169,23 @@
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
updateName (e) {
|
updateName (e) {
|
||||||
|
var oldName = this.model.name;
|
||||||
this.model.changeName(e.target.value)
|
this.model.changeName(e.target.value)
|
||||||
|
var node = this.getRootNode();
|
||||||
|
node.$emit('change-name', {'id': this.model.id, 'oldName': oldName, 'newName': e.target.value})
|
||||||
},
|
},
|
||||||
|
|
||||||
delNode () {
|
delNode () {
|
||||||
const vm = this
|
var node = this.getRootNode()
|
||||||
if (window.confirm('Are you sure?')) {
|
node.$emit('delete-node', this.model)
|
||||||
vm.model.remove()
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
setEditable () {
|
setEditable () {
|
||||||
this.editable = true
|
this.editable = true
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
this.$refs.nodeInput.focus()
|
const $input = this.$refs.nodeInput
|
||||||
// fireFocusEvent(this.$refs.nodeInput)
|
$input.focus()
|
||||||
|
$input.setSelectionRange(0, $input.value.length)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -166,21 +199,18 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
mouseOver(e) {
|
mouseOver() {
|
||||||
|
if (this.model.disabled) return
|
||||||
this.isHover = true
|
this.isHover = true
|
||||||
},
|
},
|
||||||
|
|
||||||
mouseOut(e) {
|
mouseOut() {
|
||||||
this.isHover = false
|
this.isHover = false
|
||||||
},
|
},
|
||||||
|
|
||||||
click() {
|
click() {
|
||||||
var node = this.$parent
|
var node = this.getRootNode()
|
||||||
var clickModel = this.model
|
node.$emit('click', this.model);
|
||||||
while (node._props.model.name !== 'root') {
|
|
||||||
node = node.$parent
|
|
||||||
}
|
|
||||||
node.$emit('click', clickModel)
|
|
||||||
},
|
},
|
||||||
|
|
||||||
addChild(isLeaf) {
|
addChild(isLeaf) {
|
||||||
@@ -188,11 +218,13 @@
|
|||||||
this.expanded = true
|
this.expanded = true
|
||||||
var node = new TreeNode({ name, isLeaf })
|
var node = new TreeNode({ name, isLeaf })
|
||||||
this.model.addChildren(node, true)
|
this.model.addChildren(node, true)
|
||||||
|
var root = this.getRootNode();
|
||||||
|
root.$emit('add-node', node)
|
||||||
},
|
},
|
||||||
|
|
||||||
dragStart(e) {
|
dragStart(e) {
|
||||||
if (!this.model.dragDisabled) {
|
if (!(this.model.dragDisabled || this.model.disabled)) {
|
||||||
fromComp = this
|
compInOperation = this
|
||||||
// for firefox
|
// for firefox
|
||||||
e.dataTransfer.setData("data","data");
|
e.dataTransfer.setData("data","data");
|
||||||
e.dataTransfer.effectAllowed = 'move'
|
e.dataTransfer.effectAllowed = 'move'
|
||||||
@@ -200,29 +232,32 @@
|
|||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
},
|
},
|
||||||
dragEnd(e) {
|
dragEnd() {
|
||||||
fromComp = null
|
compInOperation = null
|
||||||
},
|
},
|
||||||
dragOver(e) {
|
dragOver(e) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
return true
|
return true
|
||||||
},
|
},
|
||||||
dragEnter(e) {
|
dragEnter() {
|
||||||
if (!fromComp) return
|
if (!compInOperation) return
|
||||||
if (this.model.isLeaf) return
|
if (this.model.isLeaf) return
|
||||||
this.isDragEnterNode = true
|
this.isDragEnterNode = true
|
||||||
},
|
},
|
||||||
dragLeave(e) {
|
dragLeave() {
|
||||||
this.isDragEnterNode = false
|
this.isDragEnterNode = false
|
||||||
},
|
},
|
||||||
drop(e) {
|
drop() {
|
||||||
if (!fromComp) return
|
if (!compInOperation) return
|
||||||
fromComp.model.moveInto(this.model)
|
const oldParent = compInOperation.model.parent;
|
||||||
|
compInOperation.model.moveInto(this.model)
|
||||||
this.isDragEnterNode = false
|
this.isDragEnterNode = false
|
||||||
|
var node = this.getRootNode();
|
||||||
|
node.$emit('drop', {target: this.model, node: compInOperation.model, src: oldParent})
|
||||||
},
|
},
|
||||||
|
|
||||||
dragEnterUp () {
|
dragEnterUp () {
|
||||||
if (!fromComp) return
|
if (!compInOperation) return
|
||||||
this.isDragEnterUp = true
|
this.isDragEnterUp = true
|
||||||
},
|
},
|
||||||
dragOverUp (e) {
|
dragOverUp (e) {
|
||||||
@@ -230,17 +265,20 @@
|
|||||||
return true
|
return true
|
||||||
},
|
},
|
||||||
dragLeaveUp () {
|
dragLeaveUp () {
|
||||||
if (!fromComp) return
|
if (!compInOperation) return
|
||||||
this.isDragEnterUp = false
|
this.isDragEnterUp = false
|
||||||
},
|
},
|
||||||
dropUp () {
|
dropBefore () {
|
||||||
if (!fromComp) return
|
if (!compInOperation) return
|
||||||
fromComp.model.insertBefore(this.model)
|
const oldParent = compInOperation.model.parent;
|
||||||
|
compInOperation.model.insertBefore(this.model)
|
||||||
this.isDragEnterUp = false
|
this.isDragEnterUp = false
|
||||||
|
var node = this.getRootNode();
|
||||||
|
node.$emit('drop-before', {target: this.model, node: compInOperation.model, src: oldParent})
|
||||||
},
|
},
|
||||||
|
|
||||||
dragEnterBottom () {
|
dragEnterBottom () {
|
||||||
if (!fromComp) return
|
if (!compInOperation) return
|
||||||
this.isDragEnterBottom = true
|
this.isDragEnterBottom = true
|
||||||
},
|
},
|
||||||
dragOverBottom (e) {
|
dragOverBottom (e) {
|
||||||
@@ -248,22 +286,29 @@
|
|||||||
return true
|
return true
|
||||||
},
|
},
|
||||||
dragLeaveBottom () {
|
dragLeaveBottom () {
|
||||||
if (!fromComp) return
|
if (!compInOperation) return
|
||||||
this.isDragEnterBottom = false
|
this.isDragEnterBottom = false
|
||||||
},
|
},
|
||||||
dropBottom () {
|
dropAfter () {
|
||||||
if (!fromComp) return
|
if (!compInOperation) return
|
||||||
fromComp.model.insertAfter(this.model)
|
const oldParent = compInOperation.model.parent;
|
||||||
|
compInOperation.model.insertAfter(this.model)
|
||||||
this.isDragEnterBottom = false
|
this.isDragEnterBottom = false
|
||||||
|
var node = this.getRootNode();
|
||||||
|
node.$emit('drop-after', {target: this.model, node: compInOperation.model, src: oldParent})
|
||||||
|
},
|
||||||
|
getRootNode() {
|
||||||
|
var node = this.$parent
|
||||||
|
while (node._props.model.name !== 'root') {
|
||||||
|
node = node.$parent
|
||||||
|
}
|
||||||
|
return node;
|
||||||
}
|
}
|
||||||
},
|
|
||||||
beforeCreate () {
|
|
||||||
this.$options.components.item = require('./VueTreeList.vue')
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="less" rel="stylesheet/less" scoped>
|
<style lang="less" rel="stylesheet/less">
|
||||||
@font-face {
|
@font-face {
|
||||||
font-family: 'icomoon';
|
font-family: 'icomoon';
|
||||||
src: url('fonts/icomoon.eot?ui1hbx');
|
src: url('fonts/icomoon.eot?ui1hbx');
|
||||||
@@ -275,7 +320,7 @@
|
|||||||
font-style: normal;
|
font-style: normal;
|
||||||
}
|
}
|
||||||
|
|
||||||
.vue-tree-icon {
|
.vtl-icon {
|
||||||
/* use !important to prevent issues with browser extensions that change fonts */
|
/* use !important to prevent issues with browser extensions that change fonts */
|
||||||
font-family: 'icomoon' !important;
|
font-family: 'icomoon' !important;
|
||||||
speak: none;
|
speak: none;
|
||||||
@@ -288,7 +333,7 @@
|
|||||||
/* Better Font Rendering =========== */
|
/* Better Font Rendering =========== */
|
||||||
-webkit-font-smoothing: antialiased;
|
-webkit-font-smoothing: antialiased;
|
||||||
-moz-osx-font-smoothing: grayscale;
|
-moz-osx-font-smoothing: grayscale;
|
||||||
&.item-icon {
|
&.vtl-menu-icon {
|
||||||
margin-right: 4px;
|
margin-right: 4px;
|
||||||
&:hover {
|
&:hover {
|
||||||
color: inherit;
|
color: inherit;
|
||||||
@@ -299,52 +344,52 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.icon-file:before {
|
.vtl-icon-file:before {
|
||||||
content: "\e906";
|
content: "\e906";
|
||||||
}
|
}
|
||||||
.icon-folder:before {
|
.vtl-icon-folder:before {
|
||||||
content: "\e907";
|
content: "\e907";
|
||||||
}
|
}
|
||||||
.icon-caret-down:before {
|
.vtl-icon-caret-down:before {
|
||||||
content: "\e900";
|
|
||||||
}
|
|
||||||
.icon-caret-right:before {
|
|
||||||
content: "\e901";
|
content: "\e901";
|
||||||
}
|
}
|
||||||
.icon-edit:before {
|
.vtl-icon-caret-right:before {
|
||||||
|
content: "\e900";
|
||||||
|
}
|
||||||
|
.vtl-icon-edit:before {
|
||||||
content: "\e902";
|
content: "\e902";
|
||||||
}
|
}
|
||||||
.icon-folder-plus-e:before {
|
.vtl-icon-folder-plus-e:before {
|
||||||
content: "\e903";
|
content: "\e903";
|
||||||
}
|
}
|
||||||
.icon-plus:before {
|
.vtl-icon-plus:before {
|
||||||
content: "\e904";
|
content: "\e904";
|
||||||
}
|
}
|
||||||
.icon-trash:before {
|
.vtl-icon-trash:before {
|
||||||
content: "\e905";
|
content: "\e905";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
.border {
|
.vtl-border {
|
||||||
height: 5px;
|
height: 5px;
|
||||||
&.up {
|
&.vtl-up {
|
||||||
margin-top: -5px;
|
margin-top: -5px;
|
||||||
background-color: transparent;
|
background-color: transparent;
|
||||||
}
|
}
|
||||||
&.bottom {
|
&.vtl-bottom {
|
||||||
background-color: transparent;
|
background-color: transparent;
|
||||||
}
|
}
|
||||||
&.active {
|
&.vtl-active {
|
||||||
border-bottom: 3px dashed blue;
|
border-bottom: 3px dashed blue;
|
||||||
/*background-color: blue;*/
|
/*background-color: blue;*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.tree-node {
|
.vtl-tree-node {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
padding: 5px 0 5px 1rem;
|
padding: 5px 0 5px 1rem;
|
||||||
.input {
|
.vtl-input {
|
||||||
border: none;
|
border: none;
|
||||||
max-width: 150px;
|
max-width: 150px;
|
||||||
border-bottom: 1px solid blue;
|
border-bottom: 1px solid blue;
|
||||||
@@ -352,23 +397,23 @@
|
|||||||
&:hover {
|
&:hover {
|
||||||
background-color: #f0f0f0;
|
background-color: #f0f0f0;
|
||||||
}
|
}
|
||||||
&.active {
|
&.vtl-active {
|
||||||
outline: 2px dashed pink;
|
outline: 2px dashed pink;
|
||||||
}
|
}
|
||||||
.caret {
|
.vtl-caret {
|
||||||
margin-left: -1rem;
|
margin-left: -1rem;
|
||||||
}
|
}
|
||||||
.operation {
|
.vtl-operation {
|
||||||
margin-left: 2rem;
|
margin-left: 2rem;
|
||||||
letter-spacing: 1px;
|
letter-spacing: 1px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
.item {
|
.vtl-item {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
.tree-margin {
|
.vtl-tree-margin {
|
||||||
margin-left: 2em;
|
margin-left: 2em;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
@@ -1,7 +1,8 @@
|
|||||||
/**
|
/**
|
||||||
* Created by ayou on 17/7/21.
|
* Created by ayou on 17/7/21.
|
||||||
*/
|
*/
|
||||||
exports.VueTreeList = require('./VueTreeList.vue')
|
|
||||||
exports.TreeNode = require('./Tree.js').TreeNode
|
import VueTreeList from "./VueTreeList";
|
||||||
exports.Tree = require('./Tree.js').Tree
|
import { Tree, TreeNode } from "./Tree";
|
||||||
// exports.Record = require('./Tree.js').Record
|
|
||||||
|
export { Tree, TreeNode, VueTreeList };
|
||||||
|
14
src/tools.js
14
src/tools.js
@@ -4,24 +4,24 @@
|
|||||||
|
|
||||||
var handlerCache
|
var handlerCache
|
||||||
|
|
||||||
exports.addHandler = function(element, type, handler) {
|
exports.addHandler = function (element, type, handler) {
|
||||||
handlerCache = handler
|
handlerCache = handler
|
||||||
if (element.addEventListener) {
|
if (element.addEventListener) {
|
||||||
element.addEventListener(type, handler, false);
|
element.addEventListener(type, handler, false)
|
||||||
} else if (element.attachEvent) {
|
} else if (element.attachEvent) {
|
||||||
element.attachEvent("on" + type, handler);
|
element.attachEvent('on' + type, handler)
|
||||||
} else {
|
} else {
|
||||||
element["on" + type] = handler;
|
element['on' + type] = handler
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.removeHandler = function (element, type) {
|
exports.removeHandler = function (element, type) {
|
||||||
if (element.removeEventListener) {
|
if (element.removeEventListener) {
|
||||||
element.removeEventListener(type, handlerCache, false);
|
element.removeEventListener(type, handlerCache, false)
|
||||||
} else if (element.detachEvent) {
|
} else if (element.detachEvent) {
|
||||||
element.detachEvent("on" + type, handlerCache);
|
element.detachEvent('on' + type, handlerCache)
|
||||||
} else {
|
} else {
|
||||||
element["on" + type] = null;
|
element['on' + type] = null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
72
tests/unit/__snapshots__/example.spec.js.snap
Normal file
72
tests/unit/__snapshots__/example.spec.js.snap
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`VueTreeList renders correctly 1`] = `
|
||||||
|
<div class="vtl">
|
||||||
|
<!---->
|
||||||
|
<div class="">
|
||||||
|
<div class="vtl">
|
||||||
|
<div>
|
||||||
|
<div class="vtl-border vtl-up"></div>
|
||||||
|
<div id="1" draggable="false" class="vtl-tree-node vtl-drag-disabled"><span class="vtl-caret vtl-is-small"><i class="vtl-icon vtl-icon-caret-right"></i></span> <span><i class="vtl-icon vtl-menu-icon vtl-icon-folder"></i></span>
|
||||||
|
<div class="vtl-node-content">
|
||||||
|
Node 1
|
||||||
|
</div>
|
||||||
|
<div class="vtl-operation" style="display: none;">
|
||||||
|
<!---->
|
||||||
|
<!---->
|
||||||
|
<!---->
|
||||||
|
<!---->
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<!---->
|
||||||
|
</div>
|
||||||
|
<div class="vtl-tree-margin" style="display: none;">
|
||||||
|
<div class="vtl">
|
||||||
|
<div>
|
||||||
|
<div class="vtl-border vtl-up"></div>
|
||||||
|
<div id="2" draggable="true" class="vtl-tree-node">
|
||||||
|
<!----> <span><i class="vtl-icon vtl-menu-icon vtl-icon-file"></i></span>
|
||||||
|
<div class="vtl-node-content">
|
||||||
|
Node 1-2
|
||||||
|
</div>
|
||||||
|
<div class="vtl-operation" style="display: none;">
|
||||||
|
<!---->
|
||||||
|
<!----> <span title="edit"><i class="vtl-icon vtl-icon-edit"></i></span> <span title="delete"><i class="vtl-icon vtl-icon-trash"></i></span></div>
|
||||||
|
</div>
|
||||||
|
<!---->
|
||||||
|
</div>
|
||||||
|
<!---->
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="vtl">
|
||||||
|
<div>
|
||||||
|
<div class="vtl-border vtl-up"></div>
|
||||||
|
<div id="3" draggable="true" class="vtl-tree-node vtl-disabled">
|
||||||
|
<!----> <span><i class="vtl-icon vtl-menu-icon vtl-icon-folder"></i></span>
|
||||||
|
<div class="vtl-node-content">
|
||||||
|
Node 2
|
||||||
|
</div>
|
||||||
|
<div class="vtl-operation" style="display: none;"><span title="add tree node"><i class="vtl-icon vtl-icon-folder-plus-e"></i></span> <span title="add leaf node"><i class="vtl-icon vtl-icon-plus"></i></span> <span title="edit"><i class="vtl-icon vtl-icon-edit"></i></span> <span title="delete"><i class="vtl-icon vtl-icon-trash"></i></span></div>
|
||||||
|
</div>
|
||||||
|
<!---->
|
||||||
|
</div>
|
||||||
|
<!---->
|
||||||
|
</div>
|
||||||
|
<div class="vtl">
|
||||||
|
<div>
|
||||||
|
<div class="vtl-border vtl-up"></div>
|
||||||
|
<div id="4" draggable="true" class="vtl-tree-node">
|
||||||
|
<!----> <span><i class="vtl-icon vtl-menu-icon vtl-icon-folder"></i></span>
|
||||||
|
<div class="vtl-node-content">
|
||||||
|
Node 3
|
||||||
|
</div>
|
||||||
|
<div class="vtl-operation" style="display: none;"><span title="add tree node"><i class="vtl-icon vtl-icon-folder-plus-e"></i></span> <span title="add leaf node"><i class="vtl-icon vtl-icon-plus"></i></span> <span title="edit"><i class="vtl-icon vtl-icon-edit"></i></span> <span title="delete"><i class="vtl-icon vtl-icon-trash"></i></span></div>
|
||||||
|
</div>
|
||||||
|
<!---->
|
||||||
|
</div>
|
||||||
|
<!---->
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
49
tests/unit/example.spec.js
Normal file
49
tests/unit/example.spec.js
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
import { mount } from "@vue/test-utils";
|
||||||
|
import { Tree, VueTreeList } from "@/index";
|
||||||
|
|
||||||
|
describe("VueTreeList", () => {
|
||||||
|
it("renders correctly", () => {
|
||||||
|
const tree = new Tree([
|
||||||
|
{
|
||||||
|
name: "Node 1",
|
||||||
|
id: 1,
|
||||||
|
pid: 0,
|
||||||
|
dragDisabled: true,
|
||||||
|
addTreeNodeDisabled: true,
|
||||||
|
addLeafNodeDisabled: true,
|
||||||
|
editNodeDisabled: true,
|
||||||
|
delNodeDisabled: true,
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
name: "Node 1-2",
|
||||||
|
id: 2,
|
||||||
|
isLeaf: true,
|
||||||
|
pid: 1
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Node 2",
|
||||||
|
id: 3,
|
||||||
|
pid: 0,
|
||||||
|
disabled: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Node 3",
|
||||||
|
id: 4,
|
||||||
|
pid: 0
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
|
||||||
|
const wrapper = mount(VueTreeList, {
|
||||||
|
propsData: {
|
||||||
|
model: tree,
|
||||||
|
defaultTreeNodeName: "new node",
|
||||||
|
defaultLeafNodeName: "new leaf",
|
||||||
|
defaultExpanded: false
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(wrapper).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
});
|
Reference in New Issue
Block a user