Compare commits

..

10 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
16 changed files with 1474 additions and 156 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: hooks:
pre-commit: pre-commit: npm run lint-staged
- npm run standard
commit-msg: commitlint -E HUSKY_GIT_PARAMS commit-msg: commitlint -E HUSKY_GIT_PARAMS

View File

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

View File

@@ -31,7 +31,12 @@
</template> </template>
<template v-slot:treeNodeIcon="slotProps"> <template v-slot:treeNodeIcon="slotProps">
<span class="icon"> <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> </template>
</vue-tree-list> </vue-tree-list>
<button @click="getNewTree">Get new tree</button> <button @click="getNewTree">Get new tree</button>

1332
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
{ {
"name": "vue-tree-list", "name": "vue-tree-list",
"version": "1.4.3", "version": "1.4.5",
"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.",
"author": "ayou", "author": "ayou",
"scripts": { "scripts": {
@@ -9,6 +9,7 @@
"test:unit": "vue-cli-service test:unit --watch", "test:unit": "vue-cli-service test:unit --watch",
"test:coverage": "vue-cli-service test:unit --coverage", "test:coverage": "vue-cli-service test:unit --coverage",
"lint": "vue-cli-service lint", "lint": "vue-cli-service lint",
"lint-staged": "lint-staged",
"commit": "npx git-cz", "commit": "npx git-cz",
"prepublish": "npm run build" "prepublish": "npm run build"
}, },
@@ -23,38 +24,22 @@
"babel-eslint": "^10.0.3", "babel-eslint": "^10.0.3",
"core-js": "^3.4.3", "core-js": "^3.4.3",
"eslint": "^5.16.0", "eslint": "^5.16.0",
"eslint-config-prettier": "^6.10.0",
"eslint-plugin-prettier": "^3.1.2",
"eslint-plugin-vue": "^5.0.0", "eslint-plugin-vue": "^5.0.0",
"husky": "^4.2.1",
"jest-serializer-vue": "^2.0.2", "jest-serializer-vue": "^2.0.2",
"less": "^3.10.3", "less": "^3.10.3",
"less-loader": "^5.0.0", "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": "^2.6.10",
"vue-template-compiler": "^2.6.10" "vue-template-compiler": "^2.6.10"
}, },
"eslintConfig": { "lint-staged": {
"root": true, "**/*.{js,json,md,vue}": [
"env": { "prettier --write"
"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": [ "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

@@ -27,34 +27,17 @@
@mouseout="mouseOut" @mouseout="mouseOut"
@click.stop="click" @click.stop="click"
> >
<span <span class="vtl-caret vtl-is-small" v-if="model.children && model.children.length > 0">
class="vtl-caret vtl-is-small" <i class="vtl-icon" :class="caretClass" @click.prevent.stop="toggle"></i>
v-if="model.children && model.children.length > 0"
>
<i
class="vtl-icon"
:class="caretClass"
@click.prevent.stop="toggle"
></i>
</span> </span>
<span v-if="model.isLeaf"> <span v-if="model.isLeaf">
<slot <slot name="leafNodeIcon" :expanded="expanded" :model="model" :root="rootNode">
name="leafNodeIcon"
:expanded="expanded"
:model="model"
:root="rootNode"
>
<i class="vtl-icon vtl-menu-icon vtl-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 <slot name="treeNodeIcon" :expanded="expanded" :model="model" :root="rootNode">
name="treeNodeIcon"
:expanded="expanded"
:model="model"
:root="rootNode"
>
<i class="vtl-icon vtl-menu-icon vtl-icon-folder"></i> <i class="vtl-icon vtl-menu-icon vtl-icon-folder"></i>
</slot> </slot>
</span> </span>
@@ -77,12 +60,7 @@
@click.stop.prevent="addChild(false)" @click.stop.prevent="addChild(false)"
v-if="!model.isLeaf && !model.addTreeNodeDisabled" v-if="!model.isLeaf && !model.addTreeNodeDisabled"
> >
<slot <slot name="addTreeNodeIcon" :expanded="expanded" :model="model" :root="rootNode">
name="addTreeNodeIcon"
:expanded="expanded"
:model="model"
:root="rootNode"
>
<i class="vtl-icon vtl-icon-folder-plus-e"></i> <i class="vtl-icon vtl-icon-folder-plus-e"></i>
</slot> </slot>
</span> </span>
@@ -91,40 +69,17 @@
@click.stop.prevent="addChild(true)" @click.stop.prevent="addChild(true)"
v-if="!model.isLeaf && !model.addLeafNodeDisabled" v-if="!model.isLeaf && !model.addLeafNodeDisabled"
> >
<slot <slot name="addLeafNodeIcon" :expanded="expanded" :model="model" :root="rootNode">
name="addLeafNodeIcon"
:expanded="expanded"
:model="model"
:root="rootNode"
>
<i class="vtl-icon vtl-icon-plus"></i> <i class="vtl-icon vtl-icon-plus"></i>
</slot> </slot>
</span> </span>
<span <span title="edit" @click.stop.prevent="setEditable" v-if="!model.editNodeDisabled">
title="edit" <slot name="editNodeIcon" :expanded="expanded" :model="model" :root="rootNode">
@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> <i class="vtl-icon vtl-icon-edit"></i>
</slot> </slot>
</span> </span>
<span <span title="delete" @click.stop.prevent="delNode" v-if="!model.delNodeDisabled">
title="delete" <slot name="delNodeIcon" :expanded="expanded" :model="model" :root="rootNode">
@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> <i class="vtl-icon vtl-icon-trash"></i>
</slot> </slot>
</span> </span>
@@ -266,7 +221,8 @@ export default {
this.rootNode.$emit('change-name', { this.rootNode.$emit('change-name', {
id: this.model.id, id: this.model.id,
oldName: oldName, oldName: oldName,
newName: e.target.value newName: e.target.value,
node: this.model
}) })
}, },
@@ -283,8 +239,16 @@ export default {
}) })
}, },
setUnEditable() { setUnEditable(e) {
this.editable = false 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() { toggle() {
@@ -332,7 +296,9 @@ export default {
return true return true
}, },
dragEnter() { dragEnter() {
if (compInOperation.model.id === this.model.id || !compInOperation || this.model.isLeaf) return if (!compInOperation) return
if (compInOperation.model.id === this.model.id || !compInOperation || this.model.isLeaf)
return
this.isDragEnterNode = true this.isDragEnterNode = true
}, },
dragLeave() { dragLeave() {

View File

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

View File

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

View File

@@ -57,7 +57,12 @@ describe('Drag', () => {
$tree3.trigger('dragstart', { dataTransfer: { setData: () => {} } }) $tree3.trigger('dragstart', { dataTransfer: { setData: () => {} } })
$tree1Bottom.trigger('drop') $tree1Bottom.trigger('drop')
Vue.nextTick(() => { 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() done()
}) })
}) })

View File

@@ -30,22 +30,34 @@ describe('Slot', () => {
propsData: { model: new Tree([]) }, propsData: { model: new Tree([]) },
scopedSlots: { scopedSlots: {
addTreeNodeIcon() { addTreeNodeIcon() {
return <span class="add-tree-node-icon">📂</span> return <span class='add-tree-node-icon'>📂</span>
}, },
addLeafNodeIcon() { addLeafNodeIcon() {
return <span class="icon"></span> return <span class='icon'></span>
}, },
editNodeIcon() { editNodeIcon() {
return <span class="icon">📃</span> return <span class='icon'>📃</span>
}, },
delNodeIcon(slotProps) { 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() { leafNodeIcon() {
return <span class="icon">🍃</span> return <span class='icon'>🍃</span>
}, },
treeNodeIcon(slotProps) { 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: { css: {
extract: false extract: false
} }
}; }