...
|
...
|
@@ -8,25 +8,32 @@ |
|
|
*/
|
|
|
function getTarget(node) {
|
|
|
if (node === void 0) {
|
|
|
node = document.body
|
|
|
node = document.body;
|
|
|
}
|
|
|
if (node === true) { return document.body }
|
|
|
return node instanceof window.Node ? node : document.querySelector(node)
|
|
|
if (node === true) {
|
|
|
return document.body;
|
|
|
}
|
|
|
return node instanceof window.Node ? node : document.querySelector(node);
|
|
|
}
|
|
|
|
|
|
const directive = {
|
|
|
inserted(el, { value }, vnode) {
|
|
|
if (el.dataset && el.dataset.transfer !== 'true') return false;
|
|
|
if (el.dataset && el.dataset.transfer !== 'true') {
|
|
|
return false;
|
|
|
}
|
|
|
el.className = el.className ? el.className + ' v-transfer-dom' : 'v-transfer-dom';
|
|
|
const parentNode = el.parentNode;
|
|
|
if (!parentNode) return;
|
|
|
|
|
|
if (!parentNode) {
|
|
|
return;
|
|
|
}
|
|
|
const home = document.createComment('');
|
|
|
let hasMovedOut = false;
|
|
|
|
|
|
if (value !== false) {
|
|
|
parentNode.replaceChild(home, el); // moving out, el is no longer in the document
|
|
|
getTarget(value).appendChild(el); // moving into new place
|
|
|
hasMovedOut = true
|
|
|
hasMovedOut = true;
|
|
|
}
|
|
|
if (!el.__transferDomData) {
|
|
|
el.__transferDomData = {
|
...
|
...
|
@@ -34,14 +41,21 @@ const directive = { |
|
|
home: home,
|
|
|
target: getTarget(value),
|
|
|
hasMovedOut: hasMovedOut
|
|
|
}
|
|
|
};
|
|
|
}
|
|
|
},
|
|
|
componentUpdated(el, { value }) {
|
|
|
if (el.dataset && el.dataset.transfer !== 'true') return false;
|
|
|
if (el.dataset && el.dataset.transfer !== 'true') {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
// need to make sure children are done updating (vs. `update`)
|
|
|
const ref$1 = el.__transferDomData;
|
|
|
if (!ref$1) return;
|
|
|
|
|
|
if (!ref$1) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
// homes.get(el)
|
|
|
const parentNode = ref$1.parentNode;
|
|
|
const home = ref$1.home;
|
...
|
...
|
@@ -50,6 +64,7 @@ const directive = { |
|
|
if (!hasMovedOut && value) {
|
|
|
// remove from document and leave placeholder
|
|
|
parentNode.replaceChild(home, el);
|
|
|
|
|
|
// append to target
|
|
|
getTarget(value).appendChild(el);
|
|
|
el.__transferDomData = Object.assign({}, el.__transferDomData, { hasMovedOut: true, target: getTarget(value) });
|
...
|
...
|
@@ -63,14 +78,19 @@ const directive = { |
|
|
}
|
|
|
},
|
|
|
unbind(el) {
|
|
|
if (el.dataset && el.dataset.transfer !== 'true') return false;
|
|
|
if (el.dataset && el.dataset.transfer !== 'true') {
|
|
|
return false;
|
|
|
}
|
|
|
el.className = el.className.replace('v-transfer-dom', '');
|
|
|
const ref$1 = el.__transferDomData;
|
|
|
if (!ref$1) return;
|
|
|
|
|
|
if (!ref$1) {
|
|
|
return;
|
|
|
}
|
|
|
if (el.__transferDomData.hasMovedOut === true) {
|
|
|
el.__transferDomData.parentNode && el.__transferDomData.parentNode.appendChild(el)
|
|
|
el.__transferDomData.parentNode && el.__transferDomData.parentNode.appendChild(el);
|
|
|
}
|
|
|
el.__transferDomData = null
|
|
|
el.__transferDomData = null;
|
|
|
}
|
|
|
};
|
|
|
|
...
|
...
|
|