Skip to content

Commit 59f14b1

Browse files
author
Ives van Hoorne
committed
Update docs
1 parent 3f0adfe commit 59f14b1

File tree

6 files changed

+88
-11
lines changed

6 files changed

+88
-11
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
CodeSandbox. An online code editor tailored for web application development.
2-
Copyright (C) 2017 Ives van Hoorne
2+
Copyright (C) 2018 Ives van Hoorne
33

44
This program is free software: you can redistribute it and/or modify
55
it under the terms of the GNU General Public License as published by

packages/react-sandpack/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "0.0.0",
44
"description": "",
55
"keywords": [],
6+
"license": "SEE LICENSE.MD IN ROOT",
67
"main": "dist/react-sandpack.umd.js",
78
"module": "dist/react-sandpack.es5.js",
89
"typings": "dist/types/react-sandpack.d.ts",

packages/sandpack/README.md

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Online code playgrounds are getting more popular: they provide an easy way to pl
88

99
CodeSandbox came along, and still had a pretty basic bundler. However, as CodeSandbox got more popular its bundler got more advanced. Nowadays the bundler is used for all kinds of bigger web projects, and it would be a shame if others couldn't use the functionality.
1010

11-
This library acts as an interface with the bundler of CodeSandbox. It allows you to run any code on a web page, from Vue projects to React projects to Parcel projects. With everything that CodeSandbox supports as well.
11+
This library acts as an interface with the bundler of CodeSandbox. It allows you to run any code on a web page, from Vue projects to React projects to Parcel projects. With everything that CodeSandbox supports client side as well.
1212

1313
## So what can this bundler do?
1414

@@ -132,3 +132,59 @@ const App = () => (
132132
```
133133

134134
The above code will render a File Explorer, a working code editor and a preview with browser navigation. For more info about `react-sandpack` you can go here: https://github.com/CompuIves/codesandbox-client/tree/master/packages/react-sandpack.
135+
136+
### SandboxInfo Argument
137+
138+
The second argument in the constructor of `Manager` is all sandbox info. It has this structure:
139+
140+
```ts
141+
{
142+
/**
143+
* Files, keys are paths.
144+
**/
145+
files: {
146+
[path: string]: {
147+
code: string
148+
}
149+
},
150+
/**
151+
* Dependencies, supports npm and GitHub dependencies
152+
**/
153+
dependencies?: {
154+
[dependencyName: string]: string
155+
},
156+
/**
157+
* Default file to evaluate
158+
**/
159+
entry?: string,
160+
/**
161+
* The sandbox template to use, this is inferred from the files and package.json if not specified
162+
**/
163+
template?: string
164+
}
165+
```
166+
167+
### Options Argument
168+
169+
```ts
170+
The third argument in the constructor of `Manager` is extra options. It has this structure:
171+
172+
{
173+
/**
174+
* Location of the bundler. Defaults to `sandpack-${version}.codesandbox.io`
175+
*/
176+
bundlerURL?: string;
177+
/**
178+
* Width of iframe.
179+
*/
180+
width?: string;
181+
/**
182+
* Height of iframe.
183+
*/
184+
height?: string;
185+
/**
186+
* If we should skip the third step: evaluation.
187+
*/
188+
skipEval?: boolean;
189+
}
190+
```

packages/sandpack/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"main": "dist/sandpack.umd.js",
77
"module": "dist/sandpack.es5.js",
88
"typings": "dist/types/sandpack.d.ts",
9+
"license": "SEE LICENSE.MD IN ROOT",
910
"files": [
1011
"dist"
1112
],
@@ -73,7 +74,8 @@
7374
"mapCoverage": true
7475
},
7576
"dependencies": {
76-
"codesandbox-api": "^0.0.14"
77+
"codesandbox-api": "^0.0.14",
78+
"codesandbox-import-utils": "^1.2.2"
7779
},
7880
"devDependencies": {
7981
"@types/jest": "^22.0.0",

packages/sandpack/src/manager/index.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,25 @@
22
import { dispatch, listen, registerFrame } from 'codesandbox-api';
33
import generatePackageJSON from '../utils/generate-package-json';
44

5+
import { getTemplate } from 'codesandbox-import-utils/lib/create-sandbox/templates';
6+
57
const version = require('../../package.json').version;
68

79
export interface IManagerOptions {
810
/**
9-
* Location of the bundler
11+
* Location of the bundler.
1012
*/
1113
bundlerURL?: string;
14+
/**
15+
* Width of iframe.
16+
*/
1217
width?: string;
13-
height?: string;
1418
/**
15-
* What template we use, if not defined we infer the template from the dependencies or files.
19+
* Height of iframe.
1620
*/
17-
template?: string;
21+
height?: string;
1822
/**
19-
* If we should skip evaluation.
23+
* If we should skip the third step: evaluation.
2024
*/
2125
skipEval?: boolean;
2226
}
@@ -40,12 +44,17 @@ export interface IDependencies {
4044
[depName: string]: string;
4145
}
4246

43-
export type ISandboxInfo = {
47+
export interface ISandboxInfo {
4448
files: IFiles;
4549
dependencies?: IDependencies;
4650
entry?: string;
51+
/**
52+
* What template we use, if not defined we infer the template from the dependencies or files.
53+
*
54+
* @type {string}
55+
*/
4756
template?: string;
48-
};
57+
}
4958

5059
const BUNDLER_URL = `https://sandpack-${version}.codesandbox.io`;
5160

@@ -120,13 +129,15 @@ export default class PreviewManager {
120129
{}
121130
);
122131

132+
const packageJSON = JSON.parse(files['/package.json'].code);
133+
123134
dispatch({
124135
type: 'compile',
125136
codesandbox: true,
126137
version: 3,
127138
modules,
128139
externalResources: [],
129-
template: this.options.template || 'create-react-app',
140+
template: this.sandboxInfo.template || getTemplate(packageJSON, files),
130141
showOpenInCodeSandbox: true,
131142
skipEval: this.skipEval,
132143
});

yarn.lock

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3879,6 +3879,13 @@ codesandbox-import-utils@^1.1.21:
38793879
istextorbinary "^2.2.1"
38803880
lz-string "^1.4.4"
38813881

3882+
codesandbox-import-utils@^1.2.2:
3883+
version "1.2.2"
3884+
resolved "https://registry.yarnpkg.com/codesandbox-import-utils/-/codesandbox-import-utils-1.2.2.tgz#de08fbae99d3ef68be49497ceb88ec463e8eb869"
3885+
dependencies:
3886+
istextorbinary "^2.2.1"
3887+
lz-string "^1.4.4"
3888+
38823889
collapse-white-space@^1.0.0, collapse-white-space@^1.0.2:
38833890
version "1.0.3"
38843891
resolved "https://registry.yarnpkg.com/collapse-white-space/-/collapse-white-space-1.0.3.tgz#4b906f670e5a963a87b76b0e1689643341b6023c"

0 commit comments

Comments
 (0)