Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commiteaa6711

Browse files
Fix#2360 - Better shared env/setup handling (#2361)
1 parentb528ba6 commiteaa6711

File tree

3 files changed

+69
-46
lines changed

3 files changed

+69
-46
lines changed

‎core/package-lock.json

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

‎core/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name":"@pyscript/core",
3-
"version":"0.6.64",
3+
"version":"0.6.65",
44
"type":"module",
55
"description":"PyScript",
66
"module":"./index.js",
@@ -70,7 +70,7 @@
7070
"@webreflection/utils":"^0.1.1",
7171
"add-promise-listener":"^0.1.3",
7272
"basic-devtools":"^0.1.6",
73-
"polyscript":"^0.18.1",
73+
"polyscript":"^0.18.3",
7474
"sticky-module":"^0.1.1",
7575
"to-json-callback":"^0.1.1",
7676
"type-checked-collections":"^0.1.7"
@@ -81,7 +81,7 @@
8181
"@codemirror/language":"^6.11.2",
8282
"@codemirror/state":"^6.5.2",
8383
"@codemirror/view":"^6.38.0",
84-
"@playwright/test":"^1.53.2",
84+
"@playwright/test":"^1.54.0",
8585
"@rollup/plugin-commonjs":"^28.0.6",
8686
"@rollup/plugin-node-resolve":"^16.0.1",
8787
"@rollup/plugin-terser":"^0.4.4",

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

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const getRelatedScript = (target, type) => {
3838
returneditor?.parentNode?.previousElementSibling;
3939
};
4040

41-
asyncfunctionexecute({ currentTarget}){
41+
asyncfunctionexecute({ currentTarget, script}){
4242
const{ env, pySrc, outDiv}=this;
4343
consthasRunButton=!!currentTarget;
4444

@@ -91,14 +91,13 @@ async function execute({ currentTarget }) {
9191
// creation and destruction of editors on the fly
9292
if(hasRunButton){
9393
for(consttypeofTYPES.keys()){
94-
constscript=getRelatedScript(currentTarget,type);
95-
if(script){
96-
defineProperties(script,{xworker:{value:xworker}});
97-
break;
98-
}
94+
script=getRelatedScript(currentTarget,type);
95+
if(script)break;
9996
}
10097
}
10198

99+
defineProperties(script,{xworker:{value:xworker}});
100+
102101
const{ sync}=xworker;
103102
const{ promise, resolve}=withResolvers();
104103
envs.set(env,promise);
@@ -157,6 +156,20 @@ async function execute({ currentTarget }) {
157156
});
158157
}
159158

159+
constreplaceScript=(script,type)=>{
160+
script.xworker?.terminate();
161+
constclone=script.cloneNode(true);
162+
clone.type=`${type}-editor`;
163+
consteditor=editors.get(script);
164+
if(editor){
165+
constcontent=editor.state.doc.toString();
166+
clone.textContent=content;
167+
editors.delete(script);
168+
script.nextElementSibling.remove();
169+
}
170+
script.replaceWith(clone);
171+
};
172+
160173
constmakeRunButton=(handler,type)=>{
161174
construnButton=document.createElement("button");
162175
runButton.className=`absolute${type}-editor-run-button`;
@@ -169,15 +182,25 @@ const makeRunButton = (handler, type) => {
169182
){
170183
constscript=getRelatedScript(runButton,type);
171184
if(script){
172-
consteditor=editors.get(script);
173-
constcontent=editor.state.doc.toString();
174-
constclone=script.cloneNode(true);
175-
clone.type=`${type}-editor`;
176-
clone.textContent=content;
177-
script.xworker.terminate();
178-
script.nextElementSibling.remove();
179-
script.replaceWith(clone);
180-
editors.delete(script);
185+
constenv=script.getAttribute("env");
186+
// remove the bootstrapped env which could be one or shared
187+
if(env){
188+
for(const[key,value]ofTYPES){
189+
if(key===type){
190+
configs.delete(`${value}-${env}`);
191+
envs.delete(`${value}-${env}`);
192+
break;
193+
}
194+
}
195+
}
196+
// lonley script without setup node should be replaced
197+
if(script.xworker)replaceScript(script,type);
198+
// all scripts sharing the same env should be replaced
199+
else{
200+
constsel=`script[type^="${type}-editor"][env="${env}"]`;
201+
for(constscriptofdocument.querySelectorAll(sel))
202+
replaceScript(script,type);
203+
}
181204
}
182205
return;
183206
}
@@ -365,7 +388,7 @@ const init = async (script, type, interpreter) => {
365388
};
366389

367390
if(isSetup){
368-
awaitcontext.handleEvent({currentTarget:null});
391+
awaitcontext.handleEvent({currentTarget:null, script});
369392
notifyEditor();
370393
return;
371394
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp