|
1 | 1 | import { Sandpack, SandpackPredefinedTemplate, SandpackSetup } from "@codesandbox/sandpack-react"; |
2 | 2 | import React from "react"; |
3 | 3 | import { createRoot } from "react-dom/client"; |
4 | | -import { parseComment, SandboxInfo } from "./parse-comment"; |
| 4 | +import { parseComment } from "./parse-comment"; |
5 | 5 | import { t } from "./localize"; |
| 6 | +import { Dependencies, SandpackBundlerFile } from "@codesandbox/sandpack-client/dist/types/types"; |
6 | 7 |
|
7 | | -export const attachToElement = (element: HTMLElement, options: SandboxInfo, isOpen: boolean = false) => { |
| 8 | +// Based: SandboxInfo |
| 9 | +export type SandboxOptions = { |
| 10 | + files: Record< |
| 11 | + string, |
| 12 | + SandpackBundlerFile & { |
| 13 | + // prepend code snippet |
| 14 | + prependCode?: string; |
| 15 | + // load the path and fill code with it |
| 16 | + // this path is based on the markdown file path |
| 17 | + path?: string; |
| 18 | + // append code snippet |
| 19 | + appendCode?: string; |
| 20 | + } |
| 21 | + >; |
| 22 | + dependencies?: Dependencies; |
| 23 | + devDependencies?: Dependencies; |
| 24 | + entry?: string; |
| 25 | + /** |
| 26 | + * What template we use, if not defined we infer the template from the dependencies or files. |
| 27 | + */ |
| 28 | + template?: string; |
| 29 | +}; |
| 30 | + |
| 31 | +export const attachToElement = (element: HTMLElement, options: SandboxOptions, isOpen: boolean = false) => { |
8 | 32 | let currentRoot: ReturnType<typeof createRoot> | null; |
9 | 33 | let containerElement: HTMLDivElement | null = null; |
10 | 34 | const insert = (node: HTMLElement) => { |
@@ -174,7 +198,7 @@ window.gitbook.events.bind("page.change", function () { |
174 | 198 | updateCodeBlocs(); |
175 | 199 | }); |
176 | 200 |
|
177 | | -function replaceCodeWithConsole(codeBlock: Element, options: SandboxInfo) { |
| 201 | +function replaceCodeWithConsole(codeBlock: Element, options: SandboxOptions) { |
178 | 202 | const codes = codeBlock.getElementsByTagName("code"); |
179 | 203 | if (!codes || codes.length === 0) { |
180 | 204 | return; |
|
0 commit comments