mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-22 19:53:00 -05:00
[FIX] output management cleanups (#464)
* return on \n before empty div is appended * use appendOutput with out.write * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: Mariano Weber <info@uiremotely.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
@@ -152,7 +152,7 @@ export class BaseEvalElement extends HTMLElement {
|
||||
Element = pyodide.globals.get('Element');
|
||||
}
|
||||
const out = Element(this.outputElement.id);
|
||||
out.write.callKwargs(output, { append: true });
|
||||
out.write.callKwargs(output, { append: this.appendOutput });
|
||||
|
||||
this.outputElement.hidden = false;
|
||||
this.outputElement.style.display = 'block';
|
||||
@@ -179,7 +179,7 @@ export class BaseEvalElement extends HTMLElement {
|
||||
const out = Element(this.errorElement.id);
|
||||
|
||||
addClasses(this.errorElement, ['bg-red-200', 'p-2']);
|
||||
out.write.callKwargs(err, { append: true });
|
||||
out.write.callKwargs(err, { append: this.appendOutput });
|
||||
|
||||
this.errorElement.children[this.errorElement.children.length - 1].setAttribute('error', '');
|
||||
this.errorElement.hidden = false;
|
||||
|
||||
@@ -153,6 +153,10 @@ class Element:
|
||||
|
||||
out_element_id = self.id
|
||||
|
||||
html, mime_type = format_mime(value)
|
||||
if html == "\n":
|
||||
return
|
||||
|
||||
if append:
|
||||
child = document.createElement("div")
|
||||
exec_id = self.element.childElementCount + 1
|
||||
@@ -161,13 +165,10 @@ class Element:
|
||||
|
||||
out_element = document.querySelector(f"#{out_element_id}")
|
||||
|
||||
html, mime_type = format_mime(value)
|
||||
if mime_type in ("application/javascript", "text/html"):
|
||||
script_element = document.createRange().createContextualFragment(html)
|
||||
out_element.appendChild(script_element)
|
||||
else:
|
||||
if html == "\n":
|
||||
return
|
||||
out_element.innerHTML = html
|
||||
|
||||
def clear(self):
|
||||
|
||||
Reference in New Issue
Block a user