@pyscript/core 0.2.9 → 0.2.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core.js +3 -3
- package/dist/core.js.map +1 -1
- package/dist/{error-q53fTtv2.js → error-0_IesYFM.js} +2 -2
- package/dist/{error-q53fTtv2.js.map → error-0_IesYFM.js.map} +1 -1
- package/docs/README.md +1 -1
- package/package.json +2 -1
- package/src/core.js +26 -12
- package/src/exceptions.js +4 -2
- package/src/fetch.js +1 -1
- package/types/core.d.ts +4 -16
@@ -1,2 +1,2 @@
|
|
1
|
-
import{hooks as e}from"./core.js";function r(e){const r=document.createElement("div");r.className="py-error",r.textContent=e,r.style.cssText="\n border: 1px solid red;\n background: #ffdddd;\n color: black;\n font-family: courier, monospace;\n white-space: pre;\n overflow-x: auto;\n padding: 8px;\n margin-top: 8px;\n ",document.body.append(r)}e.onInterpreterReady.add((function n
|
2
|
-
//# sourceMappingURL=error-
|
1
|
+
import{hooks as e}from"./core.js";function r(e){const r=document.createElement("div");r.className="py-error",r.textContent=e,r.style.cssText="\n border: 1px solid red;\n background: #ffdddd;\n color: black;\n font-family: courier, monospace;\n white-space: pre;\n overflow-x: auto;\n padding: 8px;\n margin-top: 8px;\n ",document.body.append(r)}e.onInterpreterReady.add((function o(n){e.onInterpreterReady.delete(o);const{stderr:t}=n.io;n.io.stderr=(e,...o)=>(r(e.message||e),t(e,...o)),addEventListener("error",(({message:e})=>{e.startsWith("Uncaught PythonError")&&r(e)}))}));export{r as notify};
|
2
|
+
//# sourceMappingURL=error-0_IesYFM.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"error-
|
1
|
+
{"version":3,"file":"error-0_IesYFM.js","sources":["../src/plugins/error.js"],"sourcesContent":["// PyScript Error Plugin\nimport { hooks } from \"../core.js\";\n\nhooks.onInterpreterReady.add(function override(pyScript) {\n // be sure this override happens only once\n hooks.onInterpreterReady.delete(override);\n\n // trap generic `stderr` to propagate to it regardless\n const { stderr } = pyScript.io;\n\n // override it with our own logic\n pyScript.io.stderr = (error, ...rest) => {\n notify(error.message || error);\n // let other plugins or stderr hook, if any, do the rest\n return stderr(error, ...rest);\n };\n\n // be sure uncaught Python errors are also visible\n addEventListener(\"error\", ({ message }) => {\n if (message.startsWith(\"Uncaught PythonError\")) notify(message);\n });\n});\n\n// Error hook utilities\n\n// Custom function to show notifications\n\n/**\n * Add a banner to the top of the page, notifying the user of an error\n * @param {string} message\n */\nexport function notify(message) {\n const div = document.createElement(\"div\");\n div.className = \"py-error\";\n div.textContent = message;\n div.style.cssText = `\n border: 1px solid red;\n background: #ffdddd;\n color: black;\n font-family: courier, monospace;\n white-space: pre;\n overflow-x: auto;\n padding: 8px;\n margin-top: 8px;\n `;\n document.body.append(div);\n}\n"],"names":["notify","message","div","document","createElement","className","textContent","style","cssText","body","append","hooks","onInterpreterReady","add","override","pyScript","delete","stderr","io","error","rest","addEventListener","startsWith"],"mappings":"kCA+BO,SAASA,EAAOC,GACnB,MAAMC,EAAMC,SAASC,cAAc,OACnCF,EAAIG,UAAY,WAChBH,EAAII,YAAcL,EAClBC,EAAIK,MAAMC,QAAU,6MAUpBL,SAASM,KAAKC,OAAOR,EACzB,CA3CAS,EAAMC,mBAAmBC,KAAI,SAASC,EAASC,GAE3CJ,EAAMC,mBAAmBI,OAAOF,GAGhC,MAAMG,OAAEA,GAAWF,EAASG,GAG5BH,EAASG,GAAGD,OAAS,CAACE,KAAUC,KAC5BpB,EAAOmB,EAAMlB,SAAWkB,GAEjBF,EAAOE,KAAUC,IAI5BC,iBAAiB,SAAS,EAAGpB,cACrBA,EAAQqB,WAAW,yBAAyBtB,EAAOC,EAAQ,GAEvE"}
|
package/docs/README.md
CHANGED
@@ -159,7 +159,7 @@ The commonly shared utilities are:
|
|
159
159
|
* **display** in both main and worker, refers to the good old `display` utility except:
|
160
160
|
* in the *main* it automatically uses the current script `target` to display content
|
161
161
|
* in the *worker* it still needs to know *where* to display content using the `target="dom-id"` named argument, as workers don't get a default target attached
|
162
|
-
* in both main and worker, the `append=
|
162
|
+
* in both main and worker, the `append=False` is the *default* behavior, which is a breaking change compared to classic PyScript, but because there is no `Element` with its `write(content)` utility, which would have used that `append=False` behind the scene, we've decided that `false` as append default is more desired, specially after porting most examples in *PyScript Next*, where `append=True` is the exception, not the norm.
|
163
163
|
|
164
164
|
#### Extra main-only features
|
165
165
|
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@pyscript/core",
|
3
|
-
"version": "0.2.
|
3
|
+
"version": "0.2.10",
|
4
4
|
"type": "module",
|
5
5
|
"description": "PyScript",
|
6
6
|
"module": "./index.js",
|
@@ -34,6 +34,7 @@
|
|
34
34
|
"@ungap/with-resolvers": "^0.1.0",
|
35
35
|
"basic-devtools": "^0.1.6",
|
36
36
|
"polyscript": "^0.4.20",
|
37
|
+
"sticky-module": "^0.1.0",
|
37
38
|
"type-checked-collections": "^0.1.7"
|
38
39
|
},
|
39
40
|
"devDependencies": {
|
package/src/core.js
CHANGED
@@ -1,20 +1,20 @@
|
|
1
1
|
/*! (c) PyScript Development Team */
|
2
2
|
|
3
|
+
import stickyModule from "sticky-module";
|
3
4
|
import "@ungap/with-resolvers";
|
4
5
|
|
5
|
-
// These imports can hook more than usual and help debugging possible polyscript issues
|
6
6
|
import {
|
7
7
|
INVALID_CONTENT,
|
8
|
-
|
8
|
+
Hook,
|
9
9
|
XWorker,
|
10
|
-
|
11
|
-
import { queryTarget } from "../node_modules/polyscript/esm/script-handler.js";
|
12
|
-
import {
|
10
|
+
assign,
|
13
11
|
dedent,
|
12
|
+
define,
|
13
|
+
defineProperty,
|
14
14
|
dispatch,
|
15
|
+
queryTarget,
|
15
16
|
unescape,
|
16
|
-
} from "
|
17
|
-
import { Hook } from "../node_modules/polyscript/esm/worker/hooks.js";
|
17
|
+
} from "polyscript/exports";
|
18
18
|
|
19
19
|
import "./all-done.js";
|
20
20
|
import TYPES from "./types.js";
|
@@ -25,8 +25,6 @@ import stdlib from "./stdlib.js";
|
|
25
25
|
import { ErrorCode } from "./exceptions.js";
|
26
26
|
import { robustFetch as fetch, getText } from "./fetch.js";
|
27
27
|
|
28
|
-
const { assign, defineProperty } = Object;
|
29
|
-
|
30
28
|
// allows lazy element features on code evaluation
|
31
29
|
let currentElement;
|
32
30
|
|
@@ -86,10 +84,26 @@ const workerHooks = {
|
|
86
84
|
[...hooks.codeAfterRunWorkerAsync].map(dedent).join("\n"),
|
87
85
|
};
|
88
86
|
|
89
|
-
|
90
|
-
|
87
|
+
// avoid multiple initialization of the same library
|
88
|
+
const [
|
89
|
+
{
|
90
|
+
PyWorker: exportedPyWorker,
|
91
|
+
hooks: exportedHooks,
|
92
|
+
config: exportedConfig,
|
93
|
+
},
|
94
|
+
alreadyLive,
|
95
|
+
] = stickyModule("@pyscript/core", { PyWorker, hooks, config: {} });
|
96
|
+
|
97
|
+
export {
|
98
|
+
exportedPyWorker as PyWorker,
|
99
|
+
exportedHooks as hooks,
|
100
|
+
exportedConfig as config,
|
101
|
+
};
|
91
102
|
|
92
103
|
for (const [TYPE, interpreter] of TYPES) {
|
104
|
+
// avoid any dance if the module already landed
|
105
|
+
if (alreadyLive) break;
|
106
|
+
|
93
107
|
const dispatchDone = (element, isAsync, result) => {
|
94
108
|
if (isAsync) result.then(() => dispatch(element, TYPE, "done"));
|
95
109
|
else dispatch(element, TYPE, "done");
|
@@ -290,7 +304,7 @@ for (const [TYPE, interpreter] of TYPES) {
|
|
290
304
|
* @param {{config?: string | object, async?: boolean}} [options] optional configuration for the worker.
|
291
305
|
* @returns {Worker & {sync: ProxyHandler<object>}}
|
292
306
|
*/
|
293
|
-
|
307
|
+
function PyWorker(file, options) {
|
294
308
|
// this propagates pyscript worker hooks without needing a pyscript
|
295
309
|
// bootstrap + it passes arguments and enforces `pyodide`
|
296
310
|
// as the interpreter to use in the worker, as all hooks assume that
|
package/src/exceptions.js
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
import { assign } from "polyscript/exports";
|
2
|
+
|
1
3
|
const CLOSEBUTTON =
|
2
4
|
"<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='currentColor' width='12px'><path d='M.293.293a1 1 0 011.414 0L8 6.586 14.293.293a1 1 0 111.414 1.414L9.414 8l6.293 6.293a1 1 0 01-1.414 1.414L8 9.414l-6.293 6.293a1 1 0 01-1.414-1.414L6.586 8 .293 1.707a1 1 0 010-1.414z'/></svg>";
|
3
5
|
|
@@ -87,13 +89,13 @@ export function _createAlertBanner(
|
|
87
89
|
}
|
88
90
|
|
89
91
|
const content = messageType === "html" ? "innerHTML" : "textContent";
|
90
|
-
const banner =
|
92
|
+
const banner = assign(document.createElement("div"), {
|
91
93
|
className: `alert-banner py-${level}`,
|
92
94
|
[content]: message,
|
93
95
|
});
|
94
96
|
|
95
97
|
if (level === "warning") {
|
96
|
-
const closeButton =
|
98
|
+
const closeButton = assign(document.createElement("button"), {
|
97
99
|
id: "alert-close-button",
|
98
100
|
innerHTML: CLOSEBUTTON,
|
99
101
|
});
|
package/src/fetch.js
CHANGED
package/types/core.d.ts
CHANGED
@@ -1,16 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
* @returns {Worker & {sync: ProxyHandler<object>}}
|
6
|
-
*/
|
7
|
-
export function PyWorker(file: string, options?: {
|
8
|
-
config?: string | object;
|
9
|
-
async?: boolean;
|
10
|
-
}): Worker & {
|
11
|
-
sync: ProxyHandler<object>;
|
12
|
-
};
|
13
|
-
import sync from "./sync.js";
|
14
|
-
declare const exportedConfig: {};
|
15
|
-
import hooks from "./hooks.js";
|
16
|
-
export { exportedConfig as config, hooks };
|
1
|
+
declare const exportedPyWorker: any;
|
2
|
+
declare const exportedHooks: any;
|
3
|
+
declare const exportedConfig: any;
|
4
|
+
export { exportedPyWorker as PyWorker, exportedHooks as hooks, exportedConfig as config };
|