browser-runtime-octane 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/README.md +1 -1
- package/package.json +2 -2
- package/src/index.js +23 -3
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@ Octane compiler and renderer plugin for [`browser-module-runtime`](https://www.n
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
7
7
|
```sh
|
|
8
|
-
npm install browser-module-runtime@0.0.
|
|
8
|
+
npm install browser-module-runtime@0.0.10 browser-runtime-octane@0.0.10 octane@0.2.3
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
## Usage
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "browser-runtime-octane",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.10",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"node": ">=20"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
|
-
"browser-module-runtime": "0.0.
|
|
25
|
+
"browser-module-runtime": "0.0.10",
|
|
26
26
|
"octane": "*"
|
|
27
27
|
},
|
|
28
28
|
"description": "Octane JSX, TSX, and TSRX compiler and renderer adapter for browser-module-runtime.",
|
package/src/index.js
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
|
|
2
|
+
/** Translate captured HTML into Octane element descriptors; never inject raw DOM
|
|
3
|
+
* nodes into the Octane renderer (they are not Octane child values). */
|
|
4
|
+
function octaneChild(node,createElement){
|
|
5
|
+
if(node.nodeType===3)return node.nodeValue;
|
|
6
|
+
if(node.nodeType!==1)return null;
|
|
7
|
+
const props={};
|
|
8
|
+
for(const attr of node.attributes)props[attr.name]=attr.value;
|
|
9
|
+
const childNodes=[...node.childNodes].map(n=>octaneChild(n,createElement)).filter(x=>x!==null);
|
|
10
|
+
return createElement(node.localName,props,...childNodes);
|
|
11
|
+
}
|
|
1
12
|
function snapshotProps(next){
|
|
2
13
|
if(next===null||typeof next!=="object"||Array.isArray(next)||
|
|
3
14
|
(Object.getPrototypeOf(next)!==Object.prototype&&Object.getPrototypeOf(next)!==null))
|
|
@@ -29,15 +40,24 @@ export function octane({compiler,renderer,version='unverified',provider='esm.sh'
|
|
|
29
40
|
}],
|
|
30
41
|
renderers:[{
|
|
31
42
|
name:'octane',types:['octane'],
|
|
32
|
-
async mount({component,target,props}) {
|
|
43
|
+
async mount({component,target,props,children}) {
|
|
33
44
|
octaneRenderer ||= await (ownerRuntime ? ownerRuntime.import('octane') : import('octane'));
|
|
45
|
+
const createElement=octaneRenderer.createElement;
|
|
46
|
+
if(children?.count&&typeof createElement!=='function')
|
|
47
|
+
throw new TypeError('Octane children projection requires createElement() from octane');
|
|
48
|
+
const content=children?.nodes().map(n=>octaneChild(n,createElement)).filter(x=>x!==null);
|
|
49
|
+
const withChildren=next=>{
|
|
50
|
+
const result=snapshotProps(next);
|
|
51
|
+
if(content?.length&&!Object.hasOwn(result,'children'))result.children=content.length===1?content[0]:content;
|
|
52
|
+
return result;
|
|
53
|
+
};
|
|
34
54
|
const root=octaneRenderer.createRoot(target);
|
|
35
|
-
root.render(component,
|
|
55
|
+
root.render(component,withChildren(props));
|
|
36
56
|
let closed=false;
|
|
37
57
|
return {
|
|
38
58
|
updateProps(next){
|
|
39
59
|
if(closed)throw new Error('Octane mount has been disposed');
|
|
40
|
-
return root.render(component,
|
|
60
|
+
return root.render(component,withChildren(next));
|
|
41
61
|
},
|
|
42
62
|
dispose(){if(!closed){closed=true;return root.unmount();}}
|
|
43
63
|
};
|