8000 Fix #1890 - Apply latest patch that was lost (#1891) · shivashankarv/pyscript@6a3e283 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6a3e283

Browse files
Fix pyscript#1890 - Apply latest patch that was lost (pyscript#1891)
1 parent c0d45d3 commit 6a3e283

File tree

5 files changed

+53
-34
lines changed

5 files changed

+53
-34
lines changed

pyscript.core/package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyscript.core/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pyscript/core",
3-
"version": "0.3.8",
3+
"version": "0.3.9",
44
"type": "module",
55
"description": "PyScript",
66
"module": "./index.js",
@@ -66,7 +66,7 @@
6666
"rollup-plugin-postcss": "^4.0.2",
6767
"rollup-plugin-string": "^3.0.0",
6868
"static-handler": "^0.4.3",
69-
"typescript": "^5.3.2",
69+
"typescript": "^5.3.3",
7070
"xterm": "^5.3.0",
7171
"xterm-readline": "^1.1.1"
7272
},

pyscript.core/src/core.css

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,41 @@ mpy-script,
44
mpy-config {
55
display: none;
66
}
7+
8+
/* PyEditor */
9+
.py-editor-box,
10+
.mpy-editor-box {
11+
padding: 0.5rem;
12+
}
13+
.py-editor-input,
14+
.mpy-editor-input {
15+
position: relative;
16+
}
17+
.py-editor-box::before,
18+
.mpy-editor-box::before {
19+
content: attr(data-env);
20+
display: block;
21+
font-size: x-small;
22+
text-align: end;
23+
}
24+
.py-editor-output,
25+
.mpy-editor-output {
26+
white-space: pre;
27+
}
28+
.py-editor-run-button,
29+
.mpy-editor-run-button {
30+
position: absolute;
31+
right: 0.5rem;
32+
bottom: 0.5rem;
33+
opacity: 0;
34+
transition: opacity 0.25s;
35+
z-index: 1;
36+
}
37+
.py-editor-box:hover .py-editor-run-button,
38+
.mpy-editor-box:hover .mpy-editor-run-button,
39+
.py-editor-run-button:focus,
40+
.py-editor-run-button:disabled,
41+
.mpy-editor-run-button:focus,
42+
.mpy-editor-run-button:disabled {
43+
opacity: 1;
44+
}

pyscript.core/src/plugins/py-editor.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,19 @@ async function execute({ currentTarget }) {
4848
xworker.onerror = ({ error }) => {
4949
outDiv.innerHTML += `<span style='color:red'>${
5050
error.message || error
51-
}</span>`;
52-
console.log(error);
51+
}</span>\n`;
52+
console.error(error);
5353
};
5454

5555
const enable = () => {
5656
currentTarget.disabled = false;
5757
};
5858
const { sync } = xworker;
5959
sync.write = (str) => {
60-
outDiv.innerText += str;
60+
outDiv.innerText += `${str}\n`;
6161
};
6262
sync.writeErr = (str) => {
63-
outDiv.innerHTML += `<span style='color:red'>${str}</span>`;
63+
outDiv.innerHTML += `<span style='color:red'>${str}</span>\n`;
6464
};
6565
sync.runAsync(pySrc).then(enable, enable);
6666
});
@@ -88,7 +88,7 @@ const makeEditorDiv = (listener, type) => {
8888
event.stopPropagation();
8989
});
9090

91-
editorDiv.append(editorShadowContainer, runButton);
91+
editorDiv.append(runButton, editorShadowContainer);
9292

9393
return editorDiv;
9494
};
@@ -164,6 +164,7 @@ const init = async (script, type, interpreter) => {
164164
// @see https://github.com/JeffersGlass/mkdocs-pyscript/blob/main/mkdocs_pyscript/js/makeblocks.js
165165
const listener = execute.bind(context);
166166
const [boxDiv, outDiv] = makeBoxDiv(listener, type);
167+
boxDiv.dataset.env = script.hasAttribute("env") ? env : interpreter;
167168

168169
const inputChild = boxDiv.querySelector(`.${type}-editor-input > div`);
169170
const parent = inputChild.attachShadow({ mode: "open" });

pyscript.core/test/py-editor.html

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,6 @@
66
<title>PyTerminal</title>
77
<link rel="stylesheet" href="../dist/core.css">
88
<script type="module" src="../dist/core.js"></script>
9-
<style>
10-
.py-editor-box, .mpy-editor-box {
11-
padding: .5rem;
12-
position: relative;
13-
}
14-
.py-editor-run-button, .mpy-editor-run-button {
15-
position: absolute;
16-
right: .5rem;
17-
top: .5rem;
18-
opacity: 0;
19-
transition: opacity .25s;
20-
}
21-
.py-editor-box:hover .py-editor-run-button,
22-
.mpy-editor-box:hover .mpy-editor-run-button,
23-
.py-editor-run-button:focus,
24-
.py-editor-run-button:disabled,
25-
.mpy-editor-run-button:focus,
26-
.mpy-editor-run-button:disabled {
27-
opacity: 1;
28-
}
29-
</style>
309
</head>
3110
<body>
3211
<script type="py-editor">
@@ -37,6 +16,7 @@
3716
import sys
3817
print(sys.version)
3918
a = 42
19+
print(a)
4020
</script>
4121
<script type="mpy-editor" env="shared">
4222
if not 'a' in globals():

0 commit comments

Comments
 (0)
0