()
| 107 | }); |
| 108 | |
| 109 | export const addStackblitz = () => { |
| 110 | const iframe = queryElement(getArticle(), ':scope iframe'); |
| 111 | const iframeParent = iframe?.parentElement; |
| 112 | if (iframe == null || iframeParent == null) { |
| 113 | return; |
| 114 | } |
| 115 | const form = iframeParent.insertBefore( |
| 116 | createElement('form', null, { |
| 117 | action: 'https://stackblitz.com/run', |
| 118 | method: 'post', |
| 119 | target: '_blank', |
| 120 | }), |
| 121 | iframe, |
| 122 | ) as HTMLFormElement; |
| 123 | iframeParent.insertBefore( |
| 124 | createElement('a', null, {id: 'sbEdit'}, 'Open this demo in StackBlitz'), |
| 125 | iframe, |
| 126 | ).onclick = () => { |
| 127 | if (form.childNodes.length == 0) { |
| 128 | fetch('stackblitz.json') |
| 129 | .then((response) => response.json()) |
| 130 | .then((project: ExecutableProject) => { |
| 131 | addHiddenInput(form, '[title]', project.title); |
| 132 | addHiddenInput(form, '[description]', project.description); |
| 133 | addHiddenInput(form, '[template]', project.template); |
| 134 | Object.entries(project.files).forEach(([filePath, contents]) => |
| 135 | addHiddenInput(form, `[files][${filePath}]`, contents), |
| 136 | ); |
| 137 | if (project.settings != null) { |
| 138 | addHiddenInput( |
| 139 | form, |
| 140 | '[settings]', |
| 141 | JSON.stringify(project.settings), |
| 142 | ); |
| 143 | } |
| 144 | if (project.dependencies != null) { |
| 145 | addHiddenInput( |
| 146 | form, |
| 147 | '[dependencies]', |
| 148 | JSON.stringify(project.dependencies), |
| 149 | ); |
| 150 | } |
| 151 | const action = new URL(form.action); |
| 152 | Object.entries(project.options ?? {}).forEach(([option, value]) => |
| 153 | action.searchParams.set(option, value), |
| 154 | ); |
| 155 | form.action = action.toString(); |
| 156 | form.submit(); |
| 157 | }); |
| 158 | } else { |
| 159 | form.submit(); |
| 160 | } |
| 161 | }; |
| 162 | }; |
| 163 | |
| 164 | const updateNav = ( |
| 165 | { |
no test coverage detected
searching dependent graphs…