Skip to content

Commit 20ed0dd

Browse files
committed
feat: support options
1 parent eb48eb3 commit 20ed0dd

2 files changed

Lines changed: 19 additions & 5 deletions

File tree

public/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ Open editor at first.
5252
}
5353
},
5454
"entry": "/index.html",
55+
"options": {
56+
"showLineNumbers": true,
57+
"showInlineErrors": true,
58+
"wrapContent": false,
59+
"editorHeight": 550,
60+
"editorWidthPercentage": 60
61+
},
5562
"honkitSettings": {
5663
"isOpen": true,
5764
"hideExitButton": true

src/sandpack.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@ import React from "react";
33
import { createRoot } from "react-dom/client";
44
import { parseCommentAsSandboxOptions } from "./parse-comment-as-sandbox-options";
55
import { t } from "./localize";
6-
import { Dependencies, SandpackBundlerFile } from "@codesandbox/sandpack-client/dist/types/types";
6+
import type { SandboxInfo } from "@codesandbox/sandpack-client";
77

88
// Based: SandboxInfo
99
export type SandboxOptions = {
1010
files: Record<
1111
string,
12-
SandpackBundlerFile & {
12+
{
13+
code: string;
14+
readOnly?: boolean;
15+
} & {
1316
// prepend code snippet
1417
prependCode?: string;
1518
// load the path and fill code with it
@@ -19,13 +22,14 @@ export type SandboxOptions = {
1922
appendCode?: string;
2023
}
2124
>;
22-
dependencies?: Dependencies;
23-
devDependencies?: Dependencies;
25+
dependencies?: SandboxInfo["dependencies"];
26+
devDependencies?: SandboxInfo["devDependencies"];
2427
entry?: string;
2528
/**
2629
* What template we use, if not defined we infer the template from the dependencies or files.
2730
*/
2831
template?: string;
32+
options?: Record<string, any>; // Refer SandpackInternalProps
2933
honkitSettings?: {
3034
isOpen: boolean; // false by default
3135
hideExitButton: boolean; // false by default
@@ -109,6 +113,8 @@ export const attachToElement = (element: HTMLElement | ChildNode, options: Sandb
109113
environment: "parcel"
110114
};
111115
const entry = options.entry;
116+
const sandpackOptions = options.options;
117+
console.log({ sandpackOptions });
112118
const template = (options.template ?? "vanilla") as SandpackPredefinedTemplate;
113119
currentRoot.render(
114120
<Sandpack
@@ -117,7 +123,8 @@ export const attachToElement = (element: HTMLElement | ChildNode, options: Sandb
117123
options={{
118124
startRoute: entry,
119125
skipEval: false,
120-
autorun: true
126+
autorun: true,
127+
...sandpackOptions
121128
}}
122129
template={template}
123130
/>

0 commit comments

Comments
 (0)