mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-20 02:37:41 -05:00
pys-onClick shouldn't prevent splashscreen from closing (#1069)
This commit is contained in:
@@ -9,16 +9,15 @@ const logger = getLogger('py-script');
|
||||
|
||||
export function make_PyScript(runtime: Runtime) {
|
||||
class PyScript extends HTMLElement {
|
||||
srcCode: string
|
||||
srcCode: string;
|
||||
|
||||
async connectedCallback() {
|
||||
if (this.hasAttribute('output')) {
|
||||
const deprecationMessage = (
|
||||
const deprecationMessage =
|
||||
"The 'output' attribute is deprecated and ignored. You should use " +
|
||||
"'display()' to output the content to a specific element. " +
|
||||
'For example display(myElement, target="divID").'
|
||||
)
|
||||
showWarning(deprecationMessage)
|
||||
'For example display(myElement, target="divID").';
|
||||
showWarning(deprecationMessage);
|
||||
}
|
||||
ensureUniqueId(this);
|
||||
// Save innerHTML information in srcCode so we can access it later
|
||||
@@ -36,10 +35,10 @@ export function make_PyScript(runtime: Runtime) {
|
||||
try {
|
||||
const response = await robustFetch(url);
|
||||
return await response.text();
|
||||
} catch(e) {
|
||||
} catch (e) {
|
||||
_createAlertBanner(e.message);
|
||||
this.innerHTML = '';
|
||||
throw e
|
||||
throw e;
|
||||
}
|
||||
} else {
|
||||
return htmlDecode(this.srcCode);
|
||||
@@ -173,7 +172,15 @@ function createElementsWithEventListeners(runtime: Runtime, pyAttribute: string)
|
||||
from pyodide.ffi import create_proxy
|
||||
Element("${el.id}").element.addEventListener("${event}", create_proxy(${handlerCode}))
|
||||
`;
|
||||
runtime.run(source);
|
||||
|
||||
// We meed to run the source code in a try/catch block, because
|
||||
// the source code may contain a syntax error, which will cause
|
||||
// the splashscreen to not be removed.
|
||||
try {
|
||||
runtime.run(source);
|
||||
} catch (e) {
|
||||
logger.error((e as Error).message);
|
||||
}
|
||||
} else {
|
||||
el.addEventListener(event, () => {
|
||||
runtime.run(handlerCode);
|
||||
|
||||
Reference in New Issue
Block a user