Skip to content

Commit fc40e97

Browse files
author
KP73410
committed
#180 Is to possible for only parent to call a function?
1 parent 192c2b4 commit fc40e97

17 files changed

+160
-148
lines changed

demo/pages/events.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@
140140
{ name: 'node:dblclick', args: ['Node'] },
141141
{ name: 'node:selected', args: ['Node'] },
142142
{ name: 'node:unselected', args: ['Node'] },
143-
{ name: 'node:checked', args: ['Node'] },
143+
{ name: 'node:checked', args: ['Node', 'Target Node'] },
144144
{ name: 'node:unchecked', args: ['Node'] },
145145
{ name: 'node:expanded', args: ['Node'] },
146146
{ name: 'node:collapsed', args: ['Node'] },
@@ -228,6 +228,7 @@
228228
)
229229

230230
console.log(arguments)
231+
console.log(node.text, newNode ? newNode.text : null)
231232
}
232233
}
233234
}

package.json

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"name": "liquor-tree",
33
"description": "A Vue.js tree component.",
4-
"version": "0.2.68",
4+
"version": "0.2.69",
55
"author": "Kostiantyn <[email protected]>",
66
"library": "LiquorTree",
77
"homepage": "https://amsik.github.io/liquor-tree/",
88
"scripts": {
99
"dev": "cross-env NODE_ENV=development rollup -w -c rollup.config.js",
10-
"build": "cross-env NODE_ENV=production rollup -c rollup.config.js",
10+
"build": "cross-env NODE_ENV=production rollup -c rollup.config.js -- --environment BUILD:production",
1111
"lint": "eslint --fix src test",
1212
"test": "npm run lint && npm run unit",
1313
"unit": "jest",
@@ -26,12 +26,13 @@
2626
"vue-tree",
2727
"treeview"
2828
],
29-
"dependencies": {},
29+
"license": "MIT",
3030
"files": [
3131
"src",
3232
"dist/*.js"
3333
],
3434
"devDependencies": {
35+
"@rollup/plugin-alias": "^2.2.0",
3536
"@storybook/addon-notes": "^3.4.11",
3637
"@storybook/addon-options": "^3.4.11",
3738
"@storybook/vue": "^3.4.11",
@@ -45,19 +46,20 @@
4546
"eslint-plugin-jest": "^21.22.1",
4647
"eslint-plugin-vue-libs": "^2.1.0",
4748
"jest": "^22.4.4",
48-
"rollup": "^0.66.2",
49-
"rollup-plugin-alias": "^1.4.0",
50-
"rollup-plugin-buble": "^0.19.2",
51-
"rollup-plugin-serve": "^0.4.2",
52-
"rollup-plugin-uglify": "^3.0.0",
53-
"rollup-plugin-vue": "^3.0.0",
54-
"vue": "^2.5.17",
55-
"vue-jest": "^2.6.0",
56-
"vue-loader": "^14.2.3",
57-
"vue-template-compiler": "^2.5.17"
49+
"rollup": "^0.66.6",
50+
"rollup-plugin-buble": "^0.19.8",
51+
"rollup-plugin-serve": "^1.0.1",
52+
"rollup-plugin-vue": "^4.6.0",
53+
"rollup-plugin-uglify": "^6.0.3",
54+
"vue": "^2.6.10",
55+
"vue-jest": "^3.0.5",
56+
"vue-loader": "^15.7.2",
57+
"vue-template-compiler": "^2.6.10"
5858
},
5959
"jest": {
60-
"setupFiles": ["./test/setupTests.js"],
60+
"setupFiles": [
61+
"./tests/setupTests.js"
62+
],
6163
"moduleFileExtensions": [
6264
"js",
6365
"vue"

rollup.config.js

Lines changed: 47 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import pkg from './package.json'
22
import vue from 'rollup-plugin-vue'
33
import buble from 'rollup-plugin-buble'
4-
import uglify from 'rollup-plugin-uglify'
5-
import alias from 'rollup-plugin-alias'
4+
import { uglify } from 'rollup-plugin-uglify'
5+
import alias from '@rollup/plugin-alias'
66
import serve from 'rollup-plugin-serve'
77

8-
const path = require('path')
9-
108
const version = pkg.version
119
const banner = `
1210
/*!
@@ -16,50 +14,56 @@ const banner = `
1614
*/
1715
`
1816

19-
const config = {
20-
input: 'src/main.js',
21-
output: [
22-
{
23-
file: pkg.module,
24-
format: 'es',
25-
sourcemap: true,
26-
banner
27-
}, {
28-
file: pkg.main,
29-
format: 'umd',
30-
name: 'LiquorTree',
31-
sourcemap: true,
32-
banner
33-
}
34-
],
35-
cache: false,
36-
plugins: [
37-
alias({
38-
resolve: ['.vue', '.js'],
39-
'@': path.resolve(__dirname, './src')
40-
}),
41-
vue({ css: true }),
42-
buble({ objectAssign: 'Object.assign' })
43-
]
17+
const plugins = [
18+
alias({
19+
resolve: ['.vue', '.js'],
20+
}),
21+
vue({ css: true }),
22+
buble({ objectAssign: 'Object.assign' })
23+
]
24+
25+
const outputES = {
26+
file: pkg.module,
27+
format: 'es',
28+
sourcemap: true,
29+
banner
4430
}
4531

46-
if ('production' == process.env.NODE_ENV) {
47-
config.output.forEach(c => (c.sourcemap = false))
48-
config.plugins.push(uglify({
49-
output: {
50-
comments: function(node, comment) {
51-
var text = comment.value;
52-
var type = comment.type;
53-
if (type == "comment2") {
54-
return /license/i.test(text);
55-
}
56-
}
57-
}
58-
}))
32+
const outputUMD = {
33+
file: pkg.main,
34+
format: 'umd',
35+
name: 'LiquorTree',
36+
sourcemap: true,
37+
banner
5938
}
6039

40+
const config = [
41+
{
42+
input: 'src/main.js',
43+
output: outputES,
44+
cache: false,
45+
plugins
46+
},
47+
{
48+
input: 'src/main.js',
49+
output: outputUMD,
50+
cache: false,
51+
plugins: plugins.concat('production' !== process.env.NODE_ENV ? [] : uglify({
52+
output: {
53+
comments: function(node, comment) {
54+
var text = comment.value;
55+
var type = comment.type;
56+
if (type == "comment2") {
57+
return /license/i.test(text);
58+
}
59+
}
60+
}
61+
}))
62+
},
63+
]
64+
6165
if ('development' == process.env.NODE_ENV) {
62-
config.plugins.push(serve({
66+
config[0].plugins.push(serve({
6367
contentBase: ['dist', 'demo'],
6468
port: 8081,
6569
open: true

src/components/NodeContent.js

Lines changed: 0 additions & 53 deletions
This file was deleted.

src/components/NodeContent.vue

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<script>
2+
const NodeContent = {
3+
name: 'node-content',
4+
props: ['node'],
5+
render (h) {
6+
const node = this.node
7+
const vm = this.node.tree.vm
8+
9+
if (node.isEditing) {
10+
let nodeText = node.text
11+
12+
this.$nextTick(_ => {
13+
this.$refs.editCtrl.focus()
14+
})
15+
16+
return h('input', {
17+
domProps: {
18+
value: node.text,
19+
type: 'text'
20+
},
21+
class: 'tree-input',
22+
on: {
23+
input (e) {
24+
nodeText = e.target.value
25+
},
26+
blur () {
27+
node.stopEditing(nodeText)
28+
},
29+
keyup (e) {
30+
if (e.keyCode === 13) {
31+
node.stopEditing(nodeText)
32+
}
33+
},
34+
mouseup (e) {
35+
e.stopPropagation()
36+
}
37+
},
38+
ref: 'editCtrl'
39+
})
40+
}
41+
42+
if (vm.$scopedSlots.default) {
43+
return vm.$scopedSlots.default({ node: this.node })
44+
}
45+
46+
return h('span', {
47+
domProps: {
48+
innerHTML: node.text
49+
}
50+
})
51+
}
52+
}
53+
54+
export default NodeContent
55+
</script>

src/components/TreeNode.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
</template>
4444

4545
<script>
46-
import NodeContent from '@/components/NodeContent'
46+
import NodeContent from './NodeContent.vue'
4747
4848
const TreeNode = {
4949
name: 'Node',

src/components/TreeRoot.vue

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@
3333
</template>
3434

3535
<script>
36-
import TreeNode from '@/components/TreeNode'
37-
import DraggableNode from '@/components/DraggableNode'
38-
import TreeMixin from '@/mixins/TreeMixin'
39-
import TreeDnd from '@/mixins/DndMixin'
40-
import Tree from '@/lib/Tree'
36+
import TreeNode from './TreeNode.vue'
37+
import DraggableNode from './DraggableNode.vue'
38+
import TreeMixin from '../mixins/TreeMixin.js'
39+
import TreeDnd from '../mixins/DndMixin.js'
40+
import Tree from '../lib/Tree.js'
4141
4242
const defaults = {
4343
direction: 'ltr',
@@ -74,7 +74,7 @@
7474
},
7575
plainList: false,
7676
showChildren: true
77-
}
77+
};
7878
7979
export default {
8080
name: 'Tree',

src/lib/Node.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { recurseDown } from '@/utils/recurse'
2-
import find from '@/utils/find'
3-
import uuidV4 from '@/utils/uuidV4'
4-
import Selection from '@/lib/Selection'
1+
import { recurseDown } from '../utils/recurse'
2+
import find from '../utils/find'
3+
import uuidV4 from '../utils/uuidV4'
4+
import Selection from '../lib/Selection'
55

66
export default class Node {
77
constructor (tree, item) {
@@ -223,6 +223,7 @@ export default class Node {
223223
}
224224

225225
const checkDisabledChildren = this.tree.options.checkDisabledChildren
226+
const targetNode = this
226227

227228
if (this.tree.options.autoCheckChildren) {
228229
this.recurseDown(node => {
@@ -236,7 +237,7 @@ export default class Node {
236237
this.tree.check(node)
237238

238239
node.state('checked', true)
239-
node.$emit('checked')
240+
node.$emit('checked', node.id === targetNode.id ? undefined : targetNode)
240241
}
241242
})
242243

@@ -258,6 +259,8 @@ export default class Node {
258259
return this
259260
}
260261

262+
const targetNode = this
263+
261264
if (this.tree.options.autoCheckChildren) {
262265
this.recurseDown(node => {
263266
node.state('indeterminate', false)
@@ -266,7 +269,7 @@ export default class Node {
266269
this.tree.uncheck(node)
267270

268271
node.state('checked', false)
269-
node.$emit('unchecked')
272+
node.$emit('unchecked', node.id === targetNode.id ? undefined : targetNode)
270273
}
271274
})
272275

0 commit comments

Comments
 (0)