Skip to content

Commit

Permalink
feat: support Sandpack pane configuration
Browse files Browse the repository at this point in the history
Fixes #25

Squashed commit of the following:

commit 59ea6a7d78718a02b10e536b72cf4ef81bbcca39
Author: Petyo Ivanov <underlog@gmail.com>
Date:   Sun Jul 23 08:11:07 2023 +0300

    fix: hide console by default

commit a203c13
Author: David Peter <david@type-driven.com>
Date:   Sat Jul 22 20:15:34 2023 +0200

    fix: remove unecessary `readonly` option

commit e00f62a
Author: David Peter <david@type-driven.com>
Date:   Sat Jul 22 19:44:30 2023 +0200

    draft: make panes configurable in SandpackEditor
  • Loading branch information
petyosi committed Jul 23, 2023
1 parent 24bb110 commit a93d5d3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/system/Sandpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ export interface SandpackConfig {
* The list of sandpack presets that can be used.
*/
presets: Array<SandpackPreset>

/**
* The list of sandpack panes to be displayed.
*/
panes?: {
/** the console pane, off by defult */
console?: boolean
/** the preview pane, on by defult */
preview?: boolean
/** the tests pane, on by defult */
tests?: boolean
}
}

const defaultSnippetContent = `
Expand Down
18 changes: 16 additions & 2 deletions src/ui/NodeDecorators/SandpackEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { SandpackCodeEditor, SandpackLayout, SandpackPreview, SandpackProvider, useSandpack } from '@codesandbox/sandpack-react'
import {
SandpackCodeEditor,
SandpackConsole,
SandpackLayout,
SandpackPreview,
SandpackProvider,
SandpackTests,
useSandpack
} from '@codesandbox/sandpack-react'
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext'
import React from 'react'
import { useEmitterValues, usePublisher } from '../../system/EditorSystemComponent'
Expand Down Expand Up @@ -65,7 +73,13 @@ export const SandpackEditor = ({ nodeKey, code, meta, onChange, focusEmitter }:
>
<SandpackLayout>
<SandpackCodeEditor showLineNumbers showInlineErrors ref={codeMirrorRef} />
<SandpackPreview />

{/*show console and tests if explicitly set */}
{config.panes?.console ? <SandpackConsole /> : null}
{config.panes?.tests ? <SandpackTests /> : null}

{/*show preview by default */}
{config.panes?.preview === false ? null : <SandpackPreview />}
</SandpackLayout>
<CodeUpdateEmitter onChange={wrappedOnChange} snippetFileName={preset.snippetFileName} />
</SandpackProvider>
Expand Down

0 comments on commit a93d5d3

Please sign in to comment.