mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-20 02:37:41 -05:00
Restore output attribute of py-script tags, add py-script exec lifecycle hooks (#1063)
* Add beforePyScriptExec, afterPyScriptExec lifecycle hooks * Add stdiodirector plugin for `output`, `stderr` attributes of py-script tag * Add docs on `output` and `stderr` attributes of py-script tag * Tests * Removed output deprecation warning for `output` attribute * Add createSingularWarning(), with createDeprecationWarning as alias
This commit is contained in:
@@ -1,24 +1,21 @@
|
||||
import { htmlDecode, ensureUniqueId, showWarning, createDeprecationWarning } from '../utils';
|
||||
import { htmlDecode, ensureUniqueId, createDeprecationWarning } from '../utils';
|
||||
import type { Runtime } from '../runtime';
|
||||
import { getLogger } from '../logger';
|
||||
import { pyExec } from '../pyexec';
|
||||
import { _createAlertBanner } from '../exceptions';
|
||||
import { robustFetch } from '../fetch';
|
||||
import { PyScriptApp } from '../main';
|
||||
import { Stdio } from '../stdio';
|
||||
|
||||
const logger = getLogger('py-script');
|
||||
|
||||
export function make_PyScript(runtime: Runtime) {
|
||||
export function make_PyScript(runtime: Runtime, app: PyScriptApp) {
|
||||
class PyScript extends HTMLElement {
|
||||
srcCode: string;
|
||||
srcCode: string
|
||||
stdout_manager: Stdio | null
|
||||
stderr_manager: Stdio | null
|
||||
|
||||
async connectedCallback() {
|
||||
if (this.hasAttribute('output')) {
|
||||
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);
|
||||
}
|
||||
ensureUniqueId(this);
|
||||
// Save innerHTML information in srcCode so we can access it later
|
||||
// once we clean innerHTML (which is required since we don't want
|
||||
@@ -26,7 +23,9 @@ export function make_PyScript(runtime: Runtime) {
|
||||
this.srcCode = this.innerHTML;
|
||||
const pySrc = await this.getPySrc();
|
||||
this.innerHTML = '';
|
||||
pyExec(runtime, pySrc, this);
|
||||
app.plugins.beforePyScriptExec(runtime, pySrc, this);
|
||||
const result = pyExec(runtime, pySrc, this);
|
||||
app.plugins.afterPyScriptExec(runtime, pySrc, this, result);
|
||||
}
|
||||
|
||||
async getPySrc(): Promise<string> {
|
||||
|
||||
Reference in New Issue
Block a user