Skip to content

Commit 6bf67da

Browse files
committed
Merge remote-tracking branch 'upstream/master'
# Conflicts: # README.md # dist/halower-tree.min.css # dist/v2-tree.js # dist/v2-tree.js.map # src/components/tree.vue
2 parents 70df4bb + e323d89 commit 6bf67da

11 files changed

+177
-26
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
node_modules/
33
npm-debug.log
44
yarn-error.log
5+
package-lock.json
6+
demo/package.lock.json
57

68
# Editor directories and files
79
.idea
10+
.vscode
811
*.suo
912
*.ntvs*
1013
*.njsproj

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
### Node Property
1111
| Parameters | Description | Type | Optional values | Default value |
1212
|---------- |-------- |---------- |---------- |---------- |
13-
|id | node index | String | Y | title field |
13+
|id | when this property is empty, the title property will be used as the key | String | Y | -|
1414
|title | node name | String | N | -|
1515
|children | child nodes | Array[object] | Y | -|
1616
|expanded | node Expansion | Boolean | Y | false |
@@ -19,7 +19,7 @@
1919
|selected | whether the node is selected | Boolean | Y | false |
2020
|checked | whether the node check box is selected | Boolean | Y | false |
2121
|nocheck | specifies that a node does not render check box when multiple checkboxes are open | Boolean | Y | false |
22-
|loading | open Load Effect | Boolean | Y | false |
22+
|loading | open load effect | Boolean | Y | false |
2323
|chkDisabled | disable the function of a check box for a node | Boolean | Y | false |
2424

2525
### Tree Property
@@ -39,7 +39,7 @@
3939
| getSelectedNodes | returns an array of currently selected nodes | - |
4040
| getCheckedNodes | returns the array of nodes selected by the current check box | - |
4141
| getNodes |the options objects such as {selected:true}, if empty, use {} | options|
42-
| searchNodes | filter:function/string (If it is a function, it will eventually return a Boolean type) |node|
42+
| searchNodes | filter:function/string (if it is a function, it will eventually return a Boolean type) |node|
4343

4444
### events
4545
| Event name | Description | Parameters |

README_CN.md

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
### Node 属性
1313
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
1414
|---------- |-------- |---------- |---------- |---------- |
15+
|id     | 当这个属性为空,title属性将作为key | String | Y ||
1516
|title     | 节点名称 | String | N ||
1617
|expanded | 节点是否展开 | Boolean | Y | false |
1718
|checked | 节点复选框是否选中 | Boolean | Y | false |

dist/halower-tree.min.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/v2-tree.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/v2-tree.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "vue-tree-halower",
33
"description": "This tree component is based on the Vue.js 2.0",
4-
"version": "1.2.9",
4+
"version": "1.3.1",
55
"author": "halower ([email protected])",
66
"license": "MIT",
77
"private": false,

src/components/collapse-transition.js

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
'use strict'
2+
3+
exports.__esModule = true
4+
5+
var _dom = require('./dom')
6+
7+
function _classCallCheck (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function') } }
8+
9+
var Transition = (function () {
10+
function Transition () {
11+
_classCallCheck(this, Transition)
12+
}
13+
14+
Transition.prototype.beforeEnter = function beforeEnter (el) {
15+
(0, _dom.addClass)(el, 'collapse-transition')
16+
if (!el.dataset) el.dataset = {}
17+
18+
el.dataset.oldPaddingTop = el.style.paddingTop
19+
el.dataset.oldPaddingBottom = el.style.paddingBottom
20+
21+
el.style.height = '0'
22+
el.style.paddingTop = 0
23+
el.style.paddingBottom = 0
24+
}
25+
26+
Transition.prototype.enter = function enter (el) {
27+
el.dataset.oldOverflow = el.style.overflow
28+
if (el.scrollHeight !== 0) {
29+
el.style.height = el.scrollHeight + 'px'
30+
el.style.paddingTop = el.dataset.oldPaddingTop
31+
el.style.paddingBottom = el.dataset.oldPaddingBottom
32+
} else {
33+
el.style.height = ''
34+
el.style.paddingTop = el.dataset.oldPaddingTop
35+
el.style.paddingBottom = el.dataset.oldPaddingBottom
36+
}
37+
38+
el.style.overflow = 'hidden'
39+
}
40+
41+
Transition.prototype.afterEnter = function afterEnter (el) {
42+
// for safari: remove class then reset height is necessary
43+
(0, _dom.removeClass)(el, 'collapse-transition')
44+
el.style.height = ''
45+
el.style.overflow = el.dataset.oldOverflow
46+
}
47+
48+
Transition.prototype.beforeLeave = function beforeLeave (el) {
49+
if (!el.dataset) el.dataset = {}
50+
el.dataset.oldPaddingTop = el.style.paddingTop
51+
el.dataset.oldPaddingBottom = el.style.paddingBottom
52+
el.dataset.oldOverflow = el.style.overflow
53+
54+
el.style.height = el.scrollHeight + 'px'
55+
el.style.overflow = 'hidden'
56+
}
57+
58+
Transition.prototype.leave = function leave (el) {
59+
if (el.scrollHeight !== 0) {
60+
// for safari: add class after set height, or it will jump to zero height suddenly, weired
61+
(0, _dom.addClass)(el, 'collapse-transition')
62+
el.style.height = 0
63+
el.style.paddingTop = 0
64+
el.style.paddingBottom = 0
65+
}
66+
}
67+
68+
Transition.prototype.afterLeave = function afterLeave (el) {
69+
(0, _dom.removeClass)(el, 'collapse-transition')
70+
el.style.height = ''
71+
el.style.overflow = el.dataset.oldOverflow
72+
el.style.paddingTop = el.dataset.oldPaddingTop
73+
el.style.paddingBottom = el.dataset.oldPaddingBottom
74+
}
75+
76+
return Transition
77+
}())
78+
79+
exports.default = {
80+
name: 'ElCollapseTransition',
81+
functional: true,
82+
render: function render (h, _ref) {
83+
var children = _ref.children
84+
85+
var data = {
86+
on: new Transition()
87+
}
88+
89+
return h('transition', data, children)
90+
}
91+
}

src/components/dom.js

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
2+
const trim = function (string) {
3+
return (string || '').replace(/^[\s\uFEFF]+|[\s\uFEFF]+$/g, '')
4+
}
5+
6+
export function hasClass (el, cls) {
7+
if (!el || !cls) return false
8+
if (cls.indexOf(' ') !== -1) throw new Error('className should not contain space.')
9+
if (el.classList) {
10+
return el.classList.contains(cls)
11+
} else {
12+
return (' ' + el.className + ' ').indexOf(' ' + cls + ' ') > -1
13+
}
14+
};
15+
16+
export function addClass (el, cls) {
17+
if (!el) return
18+
let curClass = el.className
19+
let classes = (cls || '').split(' ')
20+
21+
for (let i = 0, j = classes.length; i < j; i++) {
22+
let clsName = classes[i]
23+
if (!clsName) continue
24+
25+
if (el.classList) {
26+
el.classList.add(clsName)
27+
} else {
28+
if (!hasClass(el, clsName)) {
29+
curClass += ' ' + clsName
30+
}
31+
}
32+
}
33+
if (!el.classList) {
34+
el.className = curClass
35+
}
36+
};
37+
38+
export function removeClass (el, cls) {
39+
if (!el || !cls) return
40+
let classes = cls.split(' ')
41+
let curClass = ' ' + el.className + ' '
42+
43+
for (let i = 0, j = classes.length; i < j; i++) {
44+
let clsName = classes[i]
45+
if (!clsName) continue
46+
47+
if (el.classList) {
48+
el.classList.remove(clsName)
49+
} else {
50+
if (hasClass(el, clsName)) {
51+
curClass = curClass.replace(' ' + clsName + ' ', ' ')
52+
}
53+
}
54+
}
55+
if (!el.classList) {
56+
el.className = trim(curClass)
57+
}
58+
};

src/components/render.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ export default {
88
render (h, ctx) {
99
let titleClass = ctx.props.node.selected ? 'node-title node-selected' : 'node-title'
1010
if (ctx.props.node.searched) titleClass += ' node-searched'
11-
return ctx.props.tpl ? ctx.props.tpl(ctx.props.node, ctx) : <span title={ctx.props.node.title} domPropsInnerHTML={ctx.props.node.title} class={titleClass} onClick={() => ctx.parent.nodeSelected(ctx.props.node)}></span>
11+
return ctx.props.tpl ? ctx.props.tpl(ctx.props.node, ctx) : <span domPropsInnerHTML={ctx.props.node.title} class={titleClass} onClick={() => ctx.parent.nodeSelected(ctx.props.node)}></span>
1212
}
1313
}

src/components/tree.vue

+16-18
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,17 @@
1111
<Render :node="item" :tpl ='tpl'/>
1212
{{item.level}}
1313
</div>
14-
<transition name="fade">
14+
<collapse-transition>
1515
<tree v-if="!isLeaf(item)" @node-expanded.once='nodeExpanded' @node-click='nodeClick' @drag-node-end='dragNodeEnd' :dragAfterExpanded="dragAfterExpanded" :draggable="draggable" v-show="item.expanded" :tpl ="tpl" :data="item.children" :halfcheck='halfcheck' :scoped='scoped' :parent ='item' :multiple="multiple"></tree>
16-
</transition>
16+
</collapse-transition>
1717
</li>
1818
</ul>
1919
</template>
2020
<script>
2121
import mixins from './mixins'
2222
import Render from './render'
2323
import Loading from './loading'
24+
import CollapseTransition from './collapse-transition'
2425
export default {
2526
name: 'Tree',
2627
mixins: [mixins],
@@ -55,7 +56,7 @@ export default {
5556
},
5657
tpl: Function
5758
},
58-
components: { Render, Loading },
59+
components: {Render, Loading, CollapseTransition},
5960
watch: {
6061
data () {
6162
this.initHandle()
@@ -201,20 +202,18 @@ export default {
201202
* @param newnode new node
202203
*/
203204
addNode (parent, newNode) {
204-
this.$set(parent, 'expanded', true)
205205
let addnode = null
206+
this.$set(parent, 'expanded', true)
206207
if (typeof newNode === 'undefined') {
207208
throw new ReferenceError('newNode is required but undefined')
208209
}
209210
if (typeof newNode === 'string') {
210-
addnode = {
211-
id: (Math.random().toString(36)+'00000000000000000').slice(2, 7), // Generate random id of 5 characters
212-
title: newNode
213-
}
214-
} else {
215-
if (newNode && !newNode.hasOwnProperty('title')) {
216-
throw new ReferenceError('the property (title) is missed')
217-
}
211+
addnode = { title: newNode }
212+
}
213+
if (typeof newNode === 'object' && !newNode.hasOwnProperty('title')) {
214+
throw new ReferenceError('the title property is missed')
215+
}
216+
if (typeof newNode === 'object' && newNode.hasOwnProperty('title')) {
218217
addnode = newNode
219218
}
220219
if (this.isLeaf(parent)) {
@@ -348,6 +347,10 @@ export default {
348347
}
349348
</script>
350349
<style scoped>
350+
.collapse-transition {
351+
transition: 0.3s height ease-in-out, 0.3s padding-top ease-in-out, 0.3s padding-bottom ease-in-out;
352+
}
353+
351354
.halo-tree li span:hover {
352355
background-color: #dddddde3
353356
}
@@ -545,15 +548,10 @@ export default {
545548
transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;
546549
}
547550
.halo-tree .node-title {
548-
display: inline-block;
551+
padding: 3px 3px;
549552
border-radius: 3px;
550553
cursor: pointer;
551554
margin: 0 2px;
552-
max-width: calc(100% - 30px);
553-
text-overflow: ellipsis;
554-
white-space: nowrap;
555-
overflow:hidden;
556-
vertical-align: bottom;
557555
}
558556
.halo-tree .node-selected {
559557
border: 1px solid #DDDDDD;

0 commit comments

Comments
 (0)