Skip to content

Provide an xworker to PyEditors #2216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
164 changes: 82 additions & 82 deletions core/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pyscript/core",
"version": "0.6.2",
"version": "0.6.4",
"type": "module",
"description": "PyScript",
"module": "./index.js",
Expand Down Expand Up @@ -80,7 +80,7 @@
"@webreflection/toml-j0.4": "^1.1.3",
"@xterm/addon-fit": "^0.10.0",
"@xterm/addon-web-links": "^0.11.0",
"bun": "^1.1.29",
"bun": "^1.1.30",
"chokidar": "^4.0.1",
"codedent": "^0.1.2",
"codemirror": "^6.0.1",
Expand All @@ -91,7 +91,7 @@
"rollup-plugin-string": "^3.0.0",
"static-handler": "^0.5.3",
"string-width": "^7.2.0",
"typescript": "^5.6.2",
"typescript": "^5.6.3",
"xterm": "^5.3.0",
"xterm-readline": "^1.1.1"
},
Expand Down
13 changes: 13 additions & 0 deletions core/src/plugins/py-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,19 @@ async function execute({ currentTarget }) {

const xworker = XWorker.call(new Hook(null, hooks), srcLink, details);

// expose xworker like in terminal or other workers to allow
// creation and destruction of editors on the fly
if (hasRunButton) {
for (const type of TYPES.keys()) {
const editor = currentTarget.closest(`.${type}-editor-box`);
const script = editor?.parentNode?.previousElementSibling;
if (script) {
defineProperties(script, { xworker: { value: xworker } });
break;
}
}
}

const { sync } = xworker;
const { promise, resolve } = Promise.withResolvers();
envs.set(env, promise);
Expand Down
2 changes: 1 addition & 1 deletion core/tests/manual/py-editor-failure.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>PyTerminal</title>
<title>PyEditor Failure</title>
<link rel="stylesheet" href="../../dist/core.css">
<script type="module" src="../../dist/core.js"></script>
</head>
Expand Down
2 changes: 1 addition & 1 deletion core/tests/manual/py-editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>PyTerminal</title>
<title>PyEditor</title>
<link rel="stylesheet" href="../../dist/core.css">
<script type="module" src="../../dist/core.js"></script>
</head>
Expand Down
2 changes: 1 addition & 1 deletion core/types/core.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,5 @@ declare const exportedHooks: {
};
};
declare const exportedConfig: {};
declare const exportedWhenDefined: (type: string) => Promise<object>;
declare const exportedWhenDefined: any;
export { stdlib, optional, inputFailure, TYPES, relative_url, exportedPyWorker as PyWorker, exportedMPWorker as MPWorker, exportedHooks as hooks, exportedConfig as config, exportedWhenDefined as whenDefined };