browser-runtime-vue 0.0.8 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/index.js +14 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "browser-runtime-vue",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.10",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Vue 3 SFC compiler and reactive renderer adapter for browser-module-runtime.",
|
|
6
6
|
"exports": {
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"README.md"
|
|
16
16
|
],
|
|
17
17
|
"peerDependencies": {
|
|
18
|
-
"browser-module-runtime": "0.0.
|
|
18
|
+
"browser-module-runtime": "0.0.10",
|
|
19
19
|
"vue": "^3.5.0"
|
|
20
20
|
},
|
|
21
21
|
"peerDependenciesMeta": {
|
package/src/index.js
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
|
|
2
|
+
/** Clone authored DOM into Vue VNodes (a native component default slot). */
|
|
3
|
+
function vueChild(node,h){
|
|
4
|
+
if(node.nodeType===3)return node.nodeValue;
|
|
5
|
+
if(node.nodeType!==1)return null;
|
|
6
|
+
const attrs={};for(const attr of node.attributes)attrs[attr.name]=attr.value;
|
|
7
|
+
const kids=[...node.childNodes].map(n=>vueChild(n,h)).filter(x=>x!==null);
|
|
8
|
+
return h(node.localName,attrs,kids);
|
|
9
|
+
}
|
|
1
10
|
function snapshotProps(next){
|
|
2
11
|
if(next===null||typeof next!=="object"||Array.isArray(next)||
|
|
3
12
|
(Object.getPrototypeOf(next)!==Object.prototype&&Object.getPrototypeOf(next)!==null))
|
|
@@ -29,14 +38,17 @@ export function vue({compiler,renderer,version='3.5.18',provider='esm.sh',script
|
|
|
29
38
|
}],
|
|
30
39
|
renderers:[{
|
|
31
40
|
name:'vue',types:['vue'],
|
|
32
|
-
async mount({component,target,props}){
|
|
41
|
+
async mount({component,target,props,children}){
|
|
33
42
|
vueRuntime ||= await (ownerRuntime ? ownerRuntime.import('vue') : import('vue'));
|
|
34
43
|
if(typeof vueRuntime.createApp!=='function'||typeof vueRuntime.h!=='function'||typeof vueRuntime.reactive!=='function')
|
|
35
44
|
throw new TypeError('Vue renderer requires createApp(), h(), and reactive().');
|
|
36
45
|
// Parent wrapper keeps the component mounted when props change.
|
|
37
46
|
// Spreading state inside render tracks every property and allows additions/removals.
|
|
38
47
|
const state=vueRuntime.reactive(snapshotProps(props));
|
|
39
|
-
const
|
|
48
|
+
const slots=children?.count ? {
|
|
49
|
+
default:()=>children.nodes().map(n=>vueChild(n,vueRuntime.h)).filter(x=>x!==null)
|
|
50
|
+
} : undefined;
|
|
51
|
+
const wrapper={name:'BrowserRuntimeVueHost',render(){return vueRuntime.h(component,{...state},slots);}};
|
|
40
52
|
const app=vueRuntime.createApp(wrapper);
|
|
41
53
|
app.mount(target);
|
|
42
54
|
let disposed=false;
|