|
@@ -8,25 +8,32 @@ |
|
@@ -8,25 +8,32 @@ |
8
|
*/
|
8
|
*/
|
9
|
function getTarget(node) {
|
9
|
function getTarget(node) {
|
10
|
if (node === void 0) {
|
10
|
if (node === void 0) {
|
11
|
- node = document.body
|
11
|
+ node = document.body;
|
12
|
}
|
12
|
}
|
13
|
- if (node === true) { return document.body }
|
|
|
14
|
- return node instanceof window.Node ? node : document.querySelector(node)
|
13
|
+ if (node === true) {
|
|
|
14
|
+ return document.body;
|
|
|
15
|
+ }
|
|
|
16
|
+ return node instanceof window.Node ? node : document.querySelector(node);
|
15
|
}
|
17
|
}
|
16
|
|
18
|
|
17
|
const directive = {
|
19
|
const directive = {
|
18
|
inserted(el, { value }, vnode) {
|
20
|
inserted(el, { value }, vnode) {
|
19
|
- if (el.dataset && el.dataset.transfer !== 'true') return false;
|
21
|
+ if (el.dataset && el.dataset.transfer !== 'true') {
|
|
|
22
|
+ return false;
|
|
|
23
|
+ }
|
20
|
el.className = el.className ? el.className + ' v-transfer-dom' : 'v-transfer-dom';
|
24
|
el.className = el.className ? el.className + ' v-transfer-dom' : 'v-transfer-dom';
|
21
|
const parentNode = el.parentNode;
|
25
|
const parentNode = el.parentNode;
|
22
|
- if (!parentNode) return;
|
26
|
+
|
|
|
27
|
+ if (!parentNode) {
|
|
|
28
|
+ return;
|
|
|
29
|
+ }
|
23
|
const home = document.createComment('');
|
30
|
const home = document.createComment('');
|
24
|
let hasMovedOut = false;
|
31
|
let hasMovedOut = false;
|
25
|
|
32
|
|
26
|
if (value !== false) {
|
33
|
if (value !== false) {
|
27
|
parentNode.replaceChild(home, el); // moving out, el is no longer in the document
|
34
|
parentNode.replaceChild(home, el); // moving out, el is no longer in the document
|
28
|
getTarget(value).appendChild(el); // moving into new place
|
35
|
getTarget(value).appendChild(el); // moving into new place
|
29
|
- hasMovedOut = true
|
36
|
+ hasMovedOut = true;
|
30
|
}
|
37
|
}
|
31
|
if (!el.__transferDomData) {
|
38
|
if (!el.__transferDomData) {
|
32
|
el.__transferDomData = {
|
39
|
el.__transferDomData = {
|
|
@@ -34,14 +41,21 @@ const directive = { |
|
@@ -34,14 +41,21 @@ const directive = { |
34
|
home: home,
|
41
|
home: home,
|
35
|
target: getTarget(value),
|
42
|
target: getTarget(value),
|
36
|
hasMovedOut: hasMovedOut
|
43
|
hasMovedOut: hasMovedOut
|
37
|
- }
|
44
|
+ };
|
38
|
}
|
45
|
}
|
39
|
},
|
46
|
},
|
40
|
componentUpdated(el, { value }) {
|
47
|
componentUpdated(el, { value }) {
|
41
|
- if (el.dataset && el.dataset.transfer !== 'true') return false;
|
48
|
+ if (el.dataset && el.dataset.transfer !== 'true') {
|
|
|
49
|
+ return false;
|
|
|
50
|
+ }
|
|
|
51
|
+
|
42
|
// need to make sure children are done updating (vs. `update`)
|
52
|
// need to make sure children are done updating (vs. `update`)
|
43
|
const ref$1 = el.__transferDomData;
|
53
|
const ref$1 = el.__transferDomData;
|
44
|
- if (!ref$1) return;
|
54
|
+
|
|
|
55
|
+ if (!ref$1) {
|
|
|
56
|
+ return;
|
|
|
57
|
+ }
|
|
|
58
|
+
|
45
|
// homes.get(el)
|
59
|
// homes.get(el)
|
46
|
const parentNode = ref$1.parentNode;
|
60
|
const parentNode = ref$1.parentNode;
|
47
|
const home = ref$1.home;
|
61
|
const home = ref$1.home;
|
|
@@ -50,6 +64,7 @@ const directive = { |
|
@@ -50,6 +64,7 @@ const directive = { |
50
|
if (!hasMovedOut && value) {
|
64
|
if (!hasMovedOut && value) {
|
51
|
// remove from document and leave placeholder
|
65
|
// remove from document and leave placeholder
|
52
|
parentNode.replaceChild(home, el);
|
66
|
parentNode.replaceChild(home, el);
|
|
|
67
|
+
|
53
|
// append to target
|
68
|
// append to target
|
54
|
getTarget(value).appendChild(el);
|
69
|
getTarget(value).appendChild(el);
|
55
|
el.__transferDomData = Object.assign({}, el.__transferDomData, { hasMovedOut: true, target: getTarget(value) });
|
70
|
el.__transferDomData = Object.assign({}, el.__transferDomData, { hasMovedOut: true, target: getTarget(value) });
|
|
@@ -63,14 +78,19 @@ const directive = { |
|
@@ -63,14 +78,19 @@ const directive = { |
63
|
}
|
78
|
}
|
64
|
},
|
79
|
},
|
65
|
unbind(el) {
|
80
|
unbind(el) {
|
66
|
- if (el.dataset && el.dataset.transfer !== 'true') return false;
|
81
|
+ if (el.dataset && el.dataset.transfer !== 'true') {
|
|
|
82
|
+ return false;
|
|
|
83
|
+ }
|
67
|
el.className = el.className.replace('v-transfer-dom', '');
|
84
|
el.className = el.className.replace('v-transfer-dom', '');
|
68
|
const ref$1 = el.__transferDomData;
|
85
|
const ref$1 = el.__transferDomData;
|
69
|
- if (!ref$1) return;
|
86
|
+
|
|
|
87
|
+ if (!ref$1) {
|
|
|
88
|
+ return;
|
|
|
89
|
+ }
|
70
|
if (el.__transferDomData.hasMovedOut === true) {
|
90
|
if (el.__transferDomData.hasMovedOut === true) {
|
71
|
- el.__transferDomData.parentNode && el.__transferDomData.parentNode.appendChild(el)
|
91
|
+ el.__transferDomData.parentNode && el.__transferDomData.parentNode.appendChild(el);
|
72
|
}
|
92
|
}
|
73
|
- el.__transferDomData = null
|
93
|
+ el.__transferDomData = null;
|
74
|
}
|
94
|
}
|
75
|
};
|
95
|
};
|
76
|
|
96
|
|