MCPcopy Create free account
hub / github.com/adobe/react-spectrum / createCodeSandbox

Function createCodeSandbox

packages/dev/s2-docs/src/CodeSandbox.tsx:4–42  ·  view source on GitHub ↗
(
  files: DownloadFiles['files'],
  deps: DownloadFiles['deps'],
  type: 'vanilla' | 'tailwind' | 's2' = 'vanilla',
  entry: string = 'Example'
)

Source from the content-addressed store, hash-verified

2import LZString from 'lz-string';
3
4export 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
44const devDependencies = {
45 vanilla: {

Callers

nothing calls this directly

Calls 4

getCodeSandboxFilesFunction · 0.85
createElementMethod · 0.80
appendChildMethod · 0.80
removeMethod · 0.65

Tested by

no test coverage detected