( files: DownloadFiles['files'], deps: DownloadFiles['deps'], type: 'vanilla' | 'tailwind' | 's2' = 'vanilla', entry: string = 'Example' )
| 2 | import LZString from 'lz-string'; |
| 3 | |
| 4 | export function createCodeSandbox( |
| 5 | files: DownloadFiles['files'], |
| 6 | deps: DownloadFiles['deps'], |
| 7 | type: 'vanilla' | 'tailwind' | 's2' = 'vanilla', |
| 8 | entry: string = 'Example' |
| 9 | ) { |
| 10 | let form = document.createElement('form'); |
| 11 | form.hidden = true; |
| 12 | form.method = 'POST'; |
| 13 | form.action = 'https://codesandbox.io/api/v1/sandboxes/define'; |
| 14 | form.target = '_blank'; |
| 15 | |
| 16 | let input = document.createElement('input'); |
| 17 | input.type = 'hidden'; |
| 18 | input.name = 'query'; |
| 19 | input.value = 'file=src/Example.tsx'; |
| 20 | form.appendChild(input); |
| 21 | |
| 22 | input = document.createElement('input'); |
| 23 | input.type = 'hidden'; |
| 24 | input.name = 'environment'; |
| 25 | input.value = 'server'; |
| 26 | form.appendChild(input); |
| 27 | |
| 28 | input = document.createElement('input'); |
| 29 | input.type = 'hidden'; |
| 30 | input.name = 'parameters'; |
| 31 | |
| 32 | input.value = LZString.compressToBase64( |
| 33 | JSON.stringify({ |
| 34 | files: getCodeSandboxFiles(files, deps, type, entry) |
| 35 | }) |
| 36 | ); |
| 37 | form.appendChild(input); |
| 38 | |
| 39 | document.body.appendChild(form); |
| 40 | form.submit(); |
| 41 | form.remove(); |
| 42 | } |
| 43 | |
| 44 | const devDependencies = { |
| 45 | vanilla: { |
nothing calls this directly
no test coverage detected