Skip to content

Commit 568f5d5

Browse files
committed
1.1.3 using random treeId instead of vm._uid
1 parent c28e43d commit 568f5d5

File tree

7 files changed

+51
-23
lines changed

7 files changed

+51
-23
lines changed

dist/he-tree-vue.cjs.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* he-tree-vue v1.1.2
2+
* he-tree-vue v1.1.3
33
* (c) phphe <phphe@outlook.com> (https://github.com/phphe)
44
* Homepage: https://he-tree-vue.phphe.com
55
* Released under the MIT License.
@@ -117,7 +117,7 @@ const template = function template(h) {
117117
return h("div", {
118118
"class": `he-tree ${this.treeClass}`,
119119
"attrs": {
120-
"data-tree-id": this._uid
120+
"data-tree-id": this.treeId
121121
}
122122
}, [this.blockHeader && this.blockHeader(), childrenListTpl(this.rootNode.children, this.rootNode, []), this.blockFooter && this.blockFooter()]);
123123
};
@@ -145,7 +145,8 @@ const Tree = {
145145
data() {
146146
return {
147147
trees,
148-
treeClass: ''
148+
treeClass: '',
149+
treeId: hp.strRand()
149150
};
150151
},
151152

@@ -225,9 +226,9 @@ const Tree = {
225226
immediate: true
226227
}); //
227228

228-
this.$set(this.trees, this._uid, this);
229+
this.$set(this.trees, this.treeId, this);
229230
this.$once('hook:beforeDestroy', () => {
230-
this.$delete(this.trees, this._uid);
231+
this.$delete(this.trees, this.treeId);
231232
});
232233
},
233234

dist/he-tree-vue.esm.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*!
2-
* he-tree-vue v1.1.2
2+
* he-tree-vue v1.1.3
33
* (c) phphe <phphe@outlook.com> (https://github.com/phphe)
44
* Homepage: https://he-tree-vue.phphe.com
55
* Released under the MIT License.
66
*/
77
import _defineProperty from '@babel/runtime/helpers/defineProperty';
8-
import { TreeData, findParent, hasClass, getOffset, getBoundingClientRect, elementsFromPoint, isDescendantOf, attachCache, insertAfter, removeEl, waitTime, binarySearch, findNodeList, appendTo, insertBefore, prependTo, createElementFromHTML, addClass, iterateAll, resolveValueOrGettter, arrayWithoutEnd, arrayLast } from 'helper-js';
8+
import { TreeData, strRand, findParent, hasClass, getOffset, getBoundingClientRect, elementsFromPoint, isDescendantOf, attachCache, insertAfter, removeEl, waitTime, binarySearch, findNodeList, appendTo, insertBefore, prependTo, createElementFromHTML, addClass, iterateAll, resolveValueOrGettter, arrayWithoutEnd, arrayLast } from 'helper-js';
99
import { updatablePropsEvenUnbound, hookHelper } from 'vue-functions';
1010
import __vue_normalize__ from 'vue-runtime-helpers/dist/normalize-component.mjs';
1111
import Vue from 'vue';
@@ -111,7 +111,7 @@ var template = function template(h) {
111111
return h("div", {
112112
"class": "he-tree ".concat(this.treeClass),
113113
"attrs": {
114-
"data-tree-id": this._uid
114+
"data-tree-id": this.treeId
115115
}
116116
}, [this.blockHeader && this.blockHeader(), childrenListTpl(this.rootNode.children, this.rootNode, []), this.blockFooter && this.blockFooter()]);
117117
};
@@ -139,7 +139,8 @@ var Tree = {
139139
data() {
140140
return {
141141
trees,
142-
treeClass: ''
142+
treeClass: '',
143+
treeId: strRand()
143144
};
144145
},
145146

@@ -219,9 +220,9 @@ var Tree = {
219220
immediate: true
220221
}); //
221222

222-
this.$set(this.trees, this._uid, this);
223+
this.$set(this.trees, this.treeId, this);
223224
this.$once('hook:beforeDestroy', () => {
224-
this.$delete(this.trees, this._uid);
225+
this.$delete(this.trees, this.treeId);
225226
});
226227
},
227228

dist/he-tree-vue.js

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* he-tree-vue v1.1.2
2+
* he-tree-vue v1.1.3
33
* (c) phphe <phphe@outlook.com> (https://github.com/phphe)
44
* Homepage: https://he-tree-vue.phphe.com
55
* Released under the MIT License.
@@ -949,6 +949,29 @@
949949
}
950950

951951

952+
function numRand(min, max) {
953+
if (arguments.length === 1) {
954+
max = min;
955+
min = 0;
956+
}
957+
958+
return Math.floor(Math.random() * (max - min + 1) + min);
959+
}
960+
961+
function strRand() {
962+
var len = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 8;
963+
var prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
964+
var r = '';
965+
var seeds = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
966+
967+
for (var i = 0; i < len; i++) {
968+
r += seeds[numRand(seeds.length - 1)];
969+
}
970+
971+
return prefix + r;
972+
}
973+
974+
952975
function arrayRemove(arr, v) {
953976
var index;
954977
var count = 0;
@@ -2261,7 +2284,7 @@
22612284
return h("div", {
22622285
"class": "he-tree ".concat(this.treeClass),
22632286
"attrs": {
2264-
"data-tree-id": this._uid
2287+
"data-tree-id": this.treeId
22652288
}
22662289
}, [this.blockHeader && this.blockHeader(), childrenListTpl(this.rootNode.children, this.rootNode, []), this.blockFooter && this.blockFooter()]);
22672290
};
@@ -2290,7 +2313,8 @@
22902313
data: function data() {
22912314
return {
22922315
trees: trees,
2293-
treeClass: ''
2316+
treeClass: '',
2317+
treeId: strRand()
22942318
};
22952319
},
22962320
// computed: {},
@@ -2358,9 +2382,9 @@
23582382
immediate: true
23592383
}); //
23602384

2361-
this.$set(this.trees, this._uid, this);
2385+
this.$set(this.trees, this.treeId, this);
23622386
this.$once('hook:beforeDestroy', function () {
2363-
_this2.$delete(_this2.trees, _this2._uid);
2387+
_this2.$delete(_this2.trees, _this2.treeId);
23642388
});
23652389
},
23662390
// mounted() {},

dist/he-tree-vue.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "he-tree-vue",
3-
"version": "1.1.2",
3+
"version": "1.1.3",
44
"description": "A draggable sortable nested vue tree component.",
55
"main": "dist/he-tree-vue.cjs.js",
66
"module": "dist/he-tree-vue.esm.js",

src/components/Tree.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const template = function (h) {
5252
{nodes.map(branchTpl)}
5353
</div>
5454
}
55-
return <div class={`he-tree ${this.treeClass}`} data-tree-id={this._uid}>
55+
return <div class={`he-tree ${this.treeClass}`} data-tree-id={this.treeId}>
5656
{this.blockHeader && this.blockHeader()}
5757
{childrenListTpl(this.rootNode.children, this.rootNode, [])}
5858
{this.blockFooter && this.blockFooter()}
@@ -78,6 +78,7 @@ const Tree = {
7878
return {
7979
trees,
8080
treeClass: '',
81+
treeId: hp.strRand(),
8182
}
8283
},
8384
// computed: {},
@@ -134,9 +135,9 @@ const Tree = {
134135
this.$watch('rootNode', updateRootNode, {immediate: true})
135136
this.$watch('treeData', updateRootNode, {immediate: true})
136137
//
137-
this.$set(this.trees, this._uid, this)
138+
this.$set(this.trees, this.treeId, this)
138139
this.$once('hook:beforeDestroy', () => {
139-
this.$delete(this.trees, this._uid)
140+
this.$delete(this.trees, this.treeId)
140141
})
141142
},
142143
// mounted() {},

types/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export class Tree extends Vue{
4848
// data
4949
trees: Trees
5050
treeClass: string
51+
treeId: string
5152
// methods
5253
iteratePath(path: Path, opt?: iteratePathOptions): IterableIterator<[Path, Node]>
5354
getTreeVmByTreeEl(treeEl: HTMLElement): Vue

0 commit comments

Comments
 (0)