MCPcopy Index your code
hub / github.com/pyscript/pyscript / makeRunButton

Function makeRunButton

core/src/plugins/py-editor.js:177–218  ·  view source on GitHub ↗
(handler, type)

Source from the content-addressed store, hash-verified

175};
176
177const makeRunButton = (handler, type) => {
178 const runButton = document.createElement("button");
179 runButton.className = `absolute ${type}-editor-run-button`;
180 runButton.innerHTML = RUN_BUTTON;
181 runButton.setAttribute("aria-label", "Python Script Run Button");
182 runButton.addEventListener("click", async (event) => {
183 const script = getRelatedScript(runButton, type);
184 if (
185 runButton.classList.contains("running") &&
186 confirm("Stop evaluating this code?")
187 ) {
188 if (script) {
189 const env = script.getAttribute("env");
190 // remove the bootstrapped env which could be one or shared
191 if (env) {
192 for (const [key, value] of TYPES) {
193 if (key === type) {
194 configs.delete(`${value}-${env}`);
195 envs.delete(`${value}-${env}`);
196 break;
197 }
198 }
199 }
200 // lonley script without setup node should be replaced
201 if (script.xworker) replaceScript(script, type);
202 // all scripts sharing the same env should be replaced
203 else {
204 const sel = `script[type^="${type}-editor"][env="${env}"]`;
205 for (const script of document.querySelectorAll(sel))
206 replaceScript(script, type);
207 }
208 }
209 return;
210 }
211 runButton.blur();
212 await handler.handleEvent(
213 event,
214 script?.getAttribute("onbeforerun") || "",
215 );
216 });
217 return runButton;
218};
219
220const makeEditorDiv = (handler, type) => {
221 const editorDiv = document.createElement("div");

Callers 1

makeEditorDivFunction · 0.85

Calls 4

getRelatedScriptFunction · 0.85
replaceScriptFunction · 0.85
deleteMethod · 0.45
blurMethod · 0.45

Tested by

no test coverage detected