You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm sharing a workaround that works with both this wrapper and vue-custom-element, here.
Just set var myRootElementSelector = 'body > #root'; to the relevant place for you.
You can add this to your index.html, or remove the script tags and put it in your code.
<script>varextractVueComponentFromVueMountPoint=(c)=>{if(c.constructor.name==='Vue'){returnc.$children[0];}returnc;};vargetVueInstance=(el)=>el.__vue__;varisWebComponent=(el)=>!!el.vueComponent;varisVueCustomElement=(el)=>!!el.__vue_custom_element__;varwalk=(treeNode)=>{vartraverse=(elements)=>{elements.forEach((el)=>{if(isVueCustomElement(el)||isWebComponent(el)){// we found a custom element,// this _could_ be the best way to "ignore" the custom element layer.el.__vue__=isWebComponent(el) ?
el.vueComponent : el.__vue_custom_element__.$children[0].$children[0];// shouldn't be necessary// getVueInstance(el).$options.name =// "Custom Element: " +// el.tagName.toLowerCase().replace(/^[A-z]/, a => a.toUpperCase());}if(getVueInstance(el)){// we found a vue component, extract it,// create a new tree node level,// and finally keep searching from itvarchildTreeNode={ref: extractVueComponentFromVueMountPoint(getVueInstance(el),),tagName: el.tagName.toLowerCase(),children: [],};treeNode.children.push(childTreeNode);walk(childTreeNode);}elseif(el.children&&el.children.length>0){// keep looking downwards for vue componentstraverse(el.children);}});};if(treeNode.ref.$el.children){traverse(treeNode.ref.$el.children);}};varrepair=(treeNode)=>{// now we "restore" the $children reference across the components// so that Vue Devtools can find them properly. This is hacky as hell. :-)treeNode.children.forEach((childTreeNode)=>{if(!treeNode.ref.$children.includes(childTreeNode.ref)){treeNode.ref.$children.push(childTreeNode.ref);}// keep traversing downwardsrepair(childTreeNode);});};// initiates everything. can be run multiple times.varglueThePage=(rootSelector,forceVueDevtoolsRefresh=false)=>{varroot=extractVueComponentFromVueMountPoint(document.querySelector(rootSelector).__vue__,);vartree={ref: extractVueComponentFromVueMountPoint(root),tagName: root.$el.tagName.toLowerCase(),children: [],};// find all the vue components, put in the "tree" variablewalk(tree);// put up links between the vue components, across vue mount points.repair(tree);lethookIsAvailable=!!window.__VUE_DEVTOOLS_GLOBAL_HOOK__;letvueDevtoolsIsOnComponentsTab=hookIsAvailable&&window.__VUE_DEVTOOLS_GLOBAL_HOOK__.currentTab==='components';if(vueDevtoolsIsOnComponentsTab||forceVueDevtoolsRefresh){if(hookIsAvailable){window.__VUE_DEVTOOLS_GLOBAL_HOOK__.emit('flush');}else{thrownewError('Cannot force a refresh in Vue Devtools as it does not seem to be available.',);}}};// this is the root element of where your first Vue mount point is// for storybook, it should be 'body > #root'varmyRootElementSelector='body > #root';// lets us adapt to changes, and makes sure we don't do scanning unnecessarily early.window.addEventListener('DOMContentLoaded',()=>{// check if the root element is already availableif(document.querySelector(myRootElementSelector)&&document.querySelector(myRootElementSelector).__vue__){glueThePage(myRootElementSelector);}setInterval(()=>{glueThePage(myRootElementSelector)},500);// listen for future changesvarsubscriber=newMutationObserver((mutations,observer)=>{mutations.forEach((mutation)=>mutation.addedNodes.forEach((node)=>{letisRootElement=document.querySelector(myRootElementSelector)===node;letisVueInstance=!!node.__vue__;letisCustomElement=isWebComponent(node)||isVueCustomElement(node);if(isRootElement||isVueInstance||isCustomElement){glueThePage(myRootElementSelector);}}),);}).observe(document.body,{childList: true,subtree: true});},false,);</script>
The text was updated successfully, but these errors were encountered:
Vue Devtools doesn't work with this tool.
I'm sharing a workaround that works with both this wrapper and vue-custom-element, here.
var myRootElementSelector = 'body > #root';
to the relevant place for you.The text was updated successfully, but these errors were encountered: