Compare commits

..

17 Commits

Author SHA1 Message Date
youxingzhi
d1e12aad85 1.4.5 2020-05-30 22:13:14 +08:00
youxingzhi
d5dd9b88c9 fix: 🐛 #72 2020-05-30 22:12:00 +08:00
youxingzhi
ccb1067713 1.4.4 2020-04-25 19:44:54 +08:00
ayou
d5705f92e8 Merge pull request #68 from laashub/master
update: after blur emit the event for changeName
2020-04-10 11:48:34 +08:00
tristan-tsl
ae494ce25f update: after blur emit the event for changeName 2020-04-06 13:11:15 +08:00
tristan-tsl
c59015fdf7 update: after blur emit the event for changeName 2020-04-06 13:05:32 +08:00
ayou
5f94ebf51b Merge pull request #65 from ParadeTo/feature-code-format
chore: 🤖 add code format tool
2020-01-30 13:36:42 +08:00
youxingzhi
53320cc235 chore: 🤖 change lint-staged conf 2020-01-30 13:34:24 +08:00
youxingzhi
d73b4c1829 chore: 🤖 add code format tool 2020-01-30 12:01:36 +08:00
ayou
15f33d187d Merge pull request #64 from ParadeTo/fix-#62
fix: 🐛 #62
2020-01-30 10:44:55 +08:00
youxingzhi
a67e39ce31 fix: 🐛 #62 2020-01-30 10:43:51 +08:00
youxingzhi
69ffc1da0f 1.4.3 2020-01-07 11:44:57 +08:00
ayou
31c9225441 Merge pull request #56 from ParadeTo/bugfix/style-including
bugfix: extracted css file
2020-01-07 11:44:07 +08:00
ayou
64c56af961 Merge pull request #57 from ParadeTo/feature/plugin-export
feat: plugin export
2020-01-07 11:43:46 +08:00
Binbin Sun
a792ee3910 chore: 🤖 move core-js & vue to devDependencies 2020-01-07 11:38:23 +08:00
Binbin Sun
aa3359155f docs: ✏️ install doc 2020-01-07 11:27:16 +08:00
Binbin Sun
c1270b880b feat: 🎸 export default with the install method 2020-01-07 11:21:17 +08:00
17 changed files with 1496 additions and 159 deletions

29
.eslintrc Normal file
View File

@@ -0,0 +1,29 @@
{
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/essential",
"plugin:prettier/recommended",
"eslint:recommended"
],
"rules": {
"prettier/prettier": "error",
"no-console": "warn"
},
"parserOptions": {
"parser": "babel-eslint"
},
"overrides": [
{
"files": [
"**/__tests__/*.{j,t}s?(x)",
"**/tests/unit/**/*.spec.{j,t}s?(x)"
],
"env": {
"jest": true
}
}
]
}

View File

@@ -1,4 +1,3 @@
hooks:
pre-commit:
- npm run standard
pre-commit: npm run lint-staged
commit-msg: commitlint -E HUSKY_GIT_PARAMS

View File

@@ -1,5 +1,3 @@
module.exports = {
presets: [
'@vue/cli-plugin-babel/preset'
]
presets: ['@vue/cli-plugin-babel/preset']
}

View File

@@ -31,7 +31,12 @@
</template>
<template v-slot:treeNodeIcon="slotProps">
<span class="icon">
{{ (slotProps.model.children && slotProps.model.children.length > 0 && !slotProps.expanded) ? '🌲' : '' }}</span>
{{
slotProps.model.children && slotProps.model.children.length > 0 && !slotProps.expanded
? '🌲'
: ''
}}</span
>
</template>
</vue-tree-list>
<button @click="getNewTree">Get new tree</button>

1338
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
{
"name": "vue-tree-list",
"version": "1.4.2",
"version": "1.4.5",
"description": "A vue component for tree structure. Support adding treenode/leafnode, editing node's name and dragging.",
"author": "ayou",
"scripts": {
@@ -9,14 +9,12 @@
"test:unit": "vue-cli-service test:unit --watch",
"test:coverage": "vue-cli-service test:unit --coverage",
"lint": "vue-cli-service lint",
"lint-staged": "lint-staged",
"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"
},
"dependencies": {},
"devDependencies": {
"@vue/cli-plugin-babel": "^4.1.0",
"@vue/cli-plugin-eslint": "^4.1.0",
@@ -24,38 +22,24 @@
"@vue/cli-service": "^4.1.0",
"@vue/test-utils": "1.0.0-beta.29",
"babel-eslint": "^10.0.3",
"core-js": "^3.4.3",
"eslint": "^5.16.0",
"eslint-config-prettier": "^6.10.0",
"eslint-plugin-prettier": "^3.1.2",
"eslint-plugin-vue": "^5.0.0",
"husky": "^4.2.1",
"jest-serializer-vue": "^2.0.2",
"less": "^3.10.3",
"less-loader": "^5.0.0",
"lint-staged": "^10.0.4",
"prettier": "^1.19.1",
"prettier-eslint-cli": "^5.0.0",
"vue": "^2.6.10",
"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
}
}
"lint-staged": {
"**/*.{js,json,md,vue}": [
"prettier --write"
]
},
"browserslist": [

15
prettier.config.js Normal file
View File

@@ -0,0 +1,15 @@
module.exports = {
printWidth: 100,
tabWidth: 2,
useTabs: false,
semi: false,
singleQuote: true,
jsxSingleQuote: true,
bracketSpacing: true,
jsxBracketSameLine: false,
rangeStart: 0,
rangeEnd: Infinity,
requirePragma: false,
insertPragma: false,
htmlWhitespaceSensitivity: 'css'
}

View File

@@ -7,6 +7,19 @@ A vue component for tree structure. Support adding treenode/leafnode, editing no
[Live Demo](http://paradeto.com/vue-tree-list/)
# install
Install the plugin then you can use the component globally.
```js
import Vue from 'vue'
import VueTreeList from 'vue-tree-list'
Vue.use(VueTreeList)
```
Or just register locally like the example below.
# use
``npm install vue-tree-list``

View File

@@ -27,34 +27,17 @@
@mouseout="mouseOut"
@click.stop="click"
>
<span
class="vtl-caret vtl-is-small"
v-if="model.children && model.children.length > 0"
>
<i
class="vtl-icon"
:class="caretClass"
@click.prevent.stop="toggle"
></i>
<span class="vtl-caret vtl-is-small" v-if="model.children && model.children.length > 0">
<i class="vtl-icon" :class="caretClass" @click.prevent.stop="toggle"></i>
</span>
<span v-if="model.isLeaf">
<slot
name="leafNodeIcon"
:expanded="expanded"
:model="model"
:root="rootNode"
>
<slot name="leafNodeIcon" :expanded="expanded" :model="model" :root="rootNode">
<i class="vtl-icon vtl-menu-icon vtl-icon-file"></i>
</slot>
</span>
<span v-else>
<slot
name="treeNodeIcon"
:expanded="expanded"
:model="model"
:root="rootNode"
>
<slot name="treeNodeIcon" :expanded="expanded" :model="model" :root="rootNode">
<i class="vtl-icon vtl-menu-icon vtl-icon-folder"></i>
</slot>
</span>
@@ -77,12 +60,7 @@
@click.stop.prevent="addChild(false)"
v-if="!model.isLeaf && !model.addTreeNodeDisabled"
>
<slot
name="addTreeNodeIcon"
:expanded="expanded"
:model="model"
:root="rootNode"
>
<slot name="addTreeNodeIcon" :expanded="expanded" :model="model" :root="rootNode">
<i class="vtl-icon vtl-icon-folder-plus-e"></i>
</slot>
</span>
@@ -91,40 +69,17 @@
@click.stop.prevent="addChild(true)"
v-if="!model.isLeaf && !model.addLeafNodeDisabled"
>
<slot
name="addLeafNodeIcon"
:expanded="expanded"
:model="model"
:root="rootNode"
>
<slot name="addLeafNodeIcon" :expanded="expanded" :model="model" :root="rootNode">
<i class="vtl-icon vtl-icon-plus"></i>
</slot>
</span>
<span
title="edit"
@click.stop.prevent="setEditable"
v-if="!model.editNodeDisabled"
>
<slot
name="editNodeIcon"
:expanded="expanded"
:model="model"
:root="rootNode"
>
<span title="edit" @click.stop.prevent="setEditable" v-if="!model.editNodeDisabled">
<slot name="editNodeIcon" :expanded="expanded" :model="model" :root="rootNode">
<i class="vtl-icon vtl-icon-edit"></i>
</slot>
</span>
<span
title="delete"
@click.stop.prevent="delNode"
v-if="!model.delNodeDisabled"
>
<slot
name="delNodeIcon"
:expanded="expanded"
:model="model"
:root="rootNode"
>
<span title="delete" @click.stop.prevent="delNode" v-if="!model.delNodeDisabled">
<slot name="delNodeIcon" :expanded="expanded" :model="model" :root="rootNode">
<i class="vtl-icon vtl-icon-trash"></i>
</slot>
</span>
@@ -185,6 +140,7 @@ import {addHandler, removeHandler} from './tools.js'
let compInOperation = null
export default {
name: 'vue-tree-list',
data: function() {
return {
isHover: false,
@@ -265,7 +221,8 @@ export default {
this.rootNode.$emit('change-name', {
id: this.model.id,
oldName: oldName,
newName: e.target.value
newName: e.target.value,
node: this.model
})
},
@@ -282,8 +239,16 @@ export default {
})
},
setUnEditable() {
setUnEditable(e) {
this.editable = false
var oldName = this.model.name
this.model.changeName(e.target.value)
this.rootNode.$emit('change-name', {
id: this.model.id,
oldName: oldName,
newName: e.target.value,
eventType: 'blur'
})
},
toggle() {
@@ -332,7 +297,8 @@ export default {
},
dragEnter() {
if (!compInOperation) return
if (this.model.isLeaf) return
if (compInOperation.model.id === this.model.id || !compInOperation || this.model.isLeaf)
return
this.isDragEnterNode = true
},
dragLeave() {

View File

@@ -2,7 +2,12 @@
* Created by ayou on 17/7/21.
*/
import VueTreeList from "./VueTreeList";
import { Tree, TreeNode } from "./Tree";
import VueTreeList from './VueTreeList'
import { Tree, TreeNode } from './Tree'
export { Tree, TreeNode, VueTreeList };
VueTreeList.install = Vue => {
Vue.component(VueTreeList.name, VueTreeList)
}
export default VueTreeList
export { Tree, TreeNode, VueTreeList }

View File

@@ -26,7 +26,7 @@ export const removeHandler = function (element, type) {
}
// depth first search
export const traverseTree = (root) => {
export const traverseTree = root => {
var newRoot = {}
for (var k in root) {

View File

@@ -57,7 +57,12 @@ describe('Drag', () => {
$tree3.trigger('dragstart', { dataTransfer: { setData: () => {} } })
$tree1Bottom.trigger('drop')
Vue.nextTick(() => {
expect(wrapper.findAll('.vtl-tree-node').at(2).attributes('id')).toBe('t3')
expect(
wrapper
.findAll('.vtl-tree-node')
.at(2)
.attributes('id')
).toBe('t3')
done()
})
})

View File

@@ -30,22 +30,34 @@ describe('Slot', () => {
propsData: { model: new Tree([]) },
scopedSlots: {
addTreeNodeIcon() {
return <span class="add-tree-node-icon">📂</span>
return <span class='add-tree-node-icon'>📂</span>
},
addLeafNodeIcon() {
return <span class="icon"></span>
return <span class='icon'></span>
},
editNodeIcon() {
return <span class="icon">📃</span>
return <span class='icon'>📃</span>
},
delNodeIcon(slotProps) {
return (slotProps.model.isLeaf || !slotProps.model.children) ? <span class="del-node-icon"></span> : <span />
return slotProps.model.isLeaf || !slotProps.model.children ? (
<span class='del-node-icon'></span>
) : (
<span />
)
},
leafNodeIcon() {
return <span class="icon">🍃</span>
return <span class='icon'>🍃</span>
},
treeNodeIcon(slotProps) {
return <span class="tree-node-icon icon">{ slotProps.model.children && slotProps.model.children.length > 0 && !slotProps.expanded ? '🌲' : '❀' }</span>
return (
<span class='tree-node-icon icon'>
{slotProps.model.children &&
slotProps.model.children.length > 0 &&
!slotProps.expanded
? '🌲'
: '❀'}
</span>
)
}
}
})

View File

@@ -2,4 +2,4 @@ module.exports = {
css: {
extract: false
}
};
}