diff --git a/pyscriptjs/src/components/base.ts b/pyscriptjs/src/components/base.ts index e76ab6deebf..877745d721f 100644 --- a/pyscriptjs/src/components/base.ts +++ b/pyscriptjs/src/components/base.ts @@ -45,9 +45,7 @@ export class BaseEvalElement extends HTMLElement { this.shadow = this.attachShadow({ mode: 'open'}); this.wrapper = document.createElement('slot'); this.shadow.appendChild(this.wrapper); - if (!this.id) - this.id = this.constructor.name+"-"+guidGenerator() - } + } addToOutput(s: string) { this.outputElement.innerHTML += "
"+s+"
"; @@ -58,6 +56,11 @@ export class BaseEvalElement extends HTMLElement { } + checkId(){ + if (!this.id) + this.id = this.constructor.name+"-"+guidGenerator(); + } + getSourceFromElement(): string{ return ""; } @@ -165,6 +168,8 @@ export class BaseEvalElement extends HTMLElement { } // end eval } + + function createWidget(name: string, code: string, klass: string){ class CustomWidget extends HTMLElement{ diff --git a/pyscriptjs/src/components/pyrepl.ts b/pyscriptjs/src/components/pyrepl.ts index 2f9cd61e3b4..621d224a0b3 100644 --- a/pyscriptjs/src/components/pyrepl.ts +++ b/pyscriptjs/src/components/pyrepl.ts @@ -59,26 +59,27 @@ export class PyRepl extends BaseEvalElement { connectedCallback() { - this.code = this.innerHTML; - this.innerHTML = ''; - - let extensions = [ - basicSetup, - languageConf.of(python()), - keymap.of([ - ...defaultKeymap, - { key: "Ctrl-Enter", run: createCmdHandler(this) }, - { key: "Shift-Enter", run: createCmdHandler(this) } - ]), - - // Event listener function that is called every time an user types something on this editor - // EditorView.updateListener.of((v:ViewUpdate) => { - // if (v.docChanged) { - // console.log(v.changes); - - // } - // }) - ]; + this.checkId() + this.code = this.innerHTML; + this.innerHTML = ''; + + let extensions = [ + basicSetup, + languageConf.of(python()), + keymap.of([ + ...defaultKeymap, + { key: "Ctrl-Enter", run: createCmdHandler(this) }, + { key: "Shift-Enter", run: createCmdHandler(this) } + ]), + + // Event listener function that is called every time an user types something on this editor + // EditorView.updateListener.of((v:ViewUpdate) => { + // if (v.docChanged) { + // console.log(v.changes); + + // } + // }) + ]; if (!this.hasAttribute('theme')) { this.theme = this.getAttribute('theme'); diff --git a/pyscriptjs/src/components/pyscript.ts b/pyscriptjs/src/components/pyscript.ts index 672c7223864..8b7aacc8f92 100644 --- a/pyscriptjs/src/components/pyscript.ts +++ b/pyscriptjs/src/components/pyscript.ts @@ -98,6 +98,7 @@ export class PyScript extends BaseEvalElement { } connectedCallback() { + this.checkId() this.code = this.innerHTML; this.innerHTML = ''; let startState = EditorState.create({