(handler, type)
| 175 | }; |
| 176 | |
| 177 | const 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 | |
| 220 | const makeEditorDiv = (handler, type) => { |
| 221 | const editorDiv = document.createElement("div"); |
no test coverage detected