Skip to content

Commit

Permalink
0.0.620
Browse files Browse the repository at this point in the history
  • Loading branch information
bahrus committed Dec 14, 2024
1 parent 395269f commit 80446cb
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 23 deletions.
14 changes: 5 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ The nice thing is this allows us to reuse the same web component base with diffe
This assumes the document imports a js file, for example, that registers a custom element with name "plus-minus-base".


## Example 4b -- Support for inner script tag [TODO]
## Example 4b -- Support for inner script tag

```html
<hello-world place=Earth>
Expand All @@ -336,21 +336,17 @@ This assumes the document imports a js file, for example, that registers a custo
"div": "greeting"
}'
>
<script>
document.currentScript.o = [
(place) => ({
greeting: `Hello, ${place}`
})
]
</script>
<script nomodule>[
({place}) => ({greeting: `Hello, ${place}`})
]</script>
</xtal-element>
</template>
</hello-world>
<hello-world place=Mars></hello-world>
<hello-world place=Venus></hello-world>
```

Another death-blow [against progressive enhancement](https://github.com/WICG/webcomponents/issues/477).

# Real world examples

## Example 1 up-down-counter
Expand Down
14 changes: 6 additions & 8 deletions demo/script/Example4a.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,19 @@
<template shadowrootmode=open>
<div></div>
<xtal-element
prop-defaults='{
"place": ""
}'
prop-info='{
"place": {},
"greeting": {}
}'
xform='{
"div": "greeting"
}'
>
<script>
document.currentScript.o = [
(place) => ({
greeting: `Hello, ${place}`
})
]
</script>
<script nomodule=>[
({place}) => ({greeting: `Hello, ${place}`})
]</script>
</xtal-element>
</template>
</hello-world>
Expand Down
2 changes: 1 addition & 1 deletion imports.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"imports": {
"blow-dry/": "/node_modules/blow-dry/",
"mount-observer/": "/node_modules/mount-observer/",
"trans-render/": "/trans-render/"
"trans-render/": "/node_modules/trans-render/"
}
}
</script>
2 changes: 1 addition & 1 deletion ts-refs
Submodule ts-refs updated from b73514 to 4751b8
9 changes: 7 additions & 2 deletions xtal-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,15 @@ export class XtalElement extends O {
}
}
}
const innerScript = this.querySelector('script');
const innerScript = this.querySelector('script[nomodule]');
let infractions = undefined;
if (innerScript !== null) {
infractions = innerScript.o;
const infractionsText = innerScript.innerHTML;
const infractionsScript = document.createElement('script');
const guid = `a_${crypto.randomUUID()}`;
infractionsScript.innerHTML = `document.currentScript['${guid}'] = ${infractionsText}`;
document.head.appendChild(infractionsScript);
infractions = infractionsScript[guid];
}
const ctr = class extends inheritingClass {
localize = localize;
Expand Down
10 changes: 8 additions & 2 deletions xtal-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,16 @@ export class XtalElement extends O implements Actions{
}

}
const innerScript = this.querySelector('script');
const innerScript = this.querySelector('script[nomodule]');
let infractions: Infractions | undefined = undefined;
if(innerScript !== null){
infractions = (<any>innerScript).o as Infractions;
const infractionsText = innerScript.innerHTML;
const infractionsScript = document.createElement('script');
const guid = `a_${crypto.randomUUID()}`;
infractionsScript.innerHTML = `document.currentScript['${guid}'] = ${infractionsText}`;
document.head.appendChild(infractionsScript);

infractions = (<any>infractionsScript)[guid] as Infractions;
}
const ctr = class extends inheritingClass {
localize = localize;
Expand Down

0 comments on commit 80446cb

Please sign in to comment.