mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-19 18:27:29 -05:00
[next] allow document.createElement(py-script) (#1662)
This commit is contained in:
committed by
GitHub
parent
74cd7c840a
commit
4cc9647dc6
File diff suppressed because one or more lines are too long
@@ -13,7 +13,7 @@ import { Hook } from "../node_modules/polyscript/esm/worker/hooks.js";
|
||||
|
||||
import { robustFetch as fetch } from "./fetch.js";
|
||||
|
||||
const { defineProperty } = Object;
|
||||
const { assign, defineProperty } = Object;
|
||||
|
||||
const getText = (body) => body.text();
|
||||
|
||||
@@ -231,10 +231,17 @@ define("py", {
|
||||
|
||||
class PyScriptElement extends HTMLElement {
|
||||
constructor() {
|
||||
if (!super().id) this.id = getID();
|
||||
this._pyodide = Promise.withResolvers();
|
||||
this.srcCode = "";
|
||||
this.executed = false;
|
||||
assign(super(), {
|
||||
_pyodide: Promise.withResolvers(),
|
||||
srcCode: "",
|
||||
executed: false,
|
||||
});
|
||||
}
|
||||
get id() {
|
||||
return super.id || (super.id = getID());
|
||||
}
|
||||
set id(value) {
|
||||
super.id = value;
|
||||
}
|
||||
async connectedCallback() {
|
||||
if (!this.executed) {
|
||||
|
||||
36
pyscript.core/test/create-element.html
Normal file
36
pyscript.core/test/create-element.html
Normal file
@@ -0,0 +1,36 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<style>py-script{display:none}</style>
|
||||
<script type="module" src="../core.js"></script>
|
||||
<script type="module">
|
||||
customElements.whenDefined('py-script').then(PyScript => {
|
||||
const textContent = `
|
||||
from pyscript import display
|
||||
|
||||
display("Hello World")
|
||||
`;
|
||||
|
||||
document.body.append(
|
||||
// test <script type="py">
|
||||
Object.assign(
|
||||
document.createElement('script'),
|
||||
{ type: "py", textContent }
|
||||
),
|
||||
|
||||
// test <py-script>
|
||||
Object.assign(
|
||||
document.createElement('py-script'),
|
||||
{ textContent }
|
||||
),
|
||||
|
||||
// test PyScript class
|
||||
Object.assign(
|
||||
new PyScript(),
|
||||
{ textContent }
|
||||
)
|
||||
);
|
||||
});
|
||||
</script>
|
||||
</head>
|
||||
</html>
|
||||
Reference in New Issue
Block a user