( files: DownloadFiles['files'], deps: DownloadFiles['deps'], type: 'vanilla' | 'tailwind' | 's2' = 'vanilla', entry: string = 'Example' )
| 1 | import type {DownloadFiles} from './CodeBlock'; |
| 2 | |
| 3 | export function createStackBlitz( |
| 4 | files: DownloadFiles['files'], |
| 5 | deps: DownloadFiles['deps'], |
| 6 | type: 'vanilla' | 'tailwind' | 's2' = 'vanilla', |
| 7 | entry: string = 'Example' |
| 8 | ) { |
| 9 | let form = document.createElement('form'); |
| 10 | form.hidden = true; |
| 11 | form.method = 'POST'; |
| 12 | form.action = 'https://stackblitz.com/run?file=src/Example.tsx'; |
| 13 | form.target = '_blank'; |
| 14 | |
| 15 | let input = document.createElement('input'); |
| 16 | input.type = 'hidden'; |
| 17 | input.name = 'project[template]'; |
| 18 | input.value = 'node'; |
| 19 | form.appendChild(input); |
| 20 | |
| 21 | input = document.createElement('input'); |
| 22 | input.type = 'hidden'; |
| 23 | input.name = 'project[title]'; |
| 24 | input.value = 'Project'; |
| 25 | form.appendChild(input); |
| 26 | |
| 27 | input = document.createElement('input'); |
| 28 | input.type = 'hidden'; |
| 29 | input.name = 'project[description]'; |
| 30 | input.value = 'description'; |
| 31 | form.appendChild(input); |
| 32 | |
| 33 | let generatedFiles = getFiles(files, deps, type, entry); |
| 34 | for (let name in generatedFiles) { |
| 35 | input = document.createElement('input'); |
| 36 | input.type = 'hidden'; |
| 37 | input.name = `project[files][${name}]`; |
| 38 | input.value = generatedFiles[name]; |
| 39 | form.appendChild(input); |
| 40 | } |
| 41 | |
| 42 | document.body.appendChild(form); |
| 43 | form.submit(); |
| 44 | form.remove(); |
| 45 | } |
| 46 | |
| 47 | function getFiles( |
| 48 | files: DownloadFiles['files'], |
no test coverage detected