-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Sandpack: upgrade dependencies and adds ReactDevtools #4161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 19 commits
059d8c7
c5ebd61
2d4e27b
5202a8f
50498f5
c53ec60
b5adb42
3679b10
1301a9d
1425f2c
5666721
77b5860
29d034e
b7f3766
8fbcaac
5a522d1
15f8c71
877b8b2
c29fa17
5b40436
bfe9ad9
a91d10e
a965508
2a1cf07
32ba5ff
0686663
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
*/ | ||
|
||
import * as React from 'react'; | ||
|
||
export const IconInspect = React.memo<JSX.IntrinsicElements['svg']>( | ||
function IconInspect({className, ...rest}) { | ||
return ( | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
className={className} | ||
viewBox="0 0 203 203" | ||
width=".9em" | ||
height=".9em" | ||
fill="currentColor" | ||
{...rest}> | ||
<path d="M136.159 63.8778L156.979 63.8778V25.2093C156.979 22.4484 155.883 19.8005 153.93 17.8482C151.978 15.8959 149.33 14.7991 146.569 14.7991L11.2354 14.7991C8.47459 14.7991 5.82622 15.8959 3.87429 17.8482C1.92237 19.8005 0.826178 22.4484 0.826178 25.2093L0.826172 160.543C0.826172 163.304 1.92236 165.952 3.87428 167.904C5.82622 169.856 8.47458 170.953 11.2354 170.953H47.3955V150.132H21.6462L21.6462 35.6195L136.159 35.6195V63.8778Z" /> | ||
<path d="M60.1716 70.2329C57.7899 69.3855 55.4922 71.6832 56.3396 74.0649L89.241 166.542C89.9797 168.619 92.6303 169.216 94.1887 167.658L112 139.5L157.93 184C159.102 185.172 161.001 185.172 162.173 184L170.312 175.861C171.484 174.689 171.484 172.789 170.312 171.618L124.382 127.118L153.765 108.082C155.323 106.524 154.725 103.873 152.649 103.134L60.1716 70.2329Z" /> | ||
</svg> | ||
); | ||
} | ||
); | ||
|
||
IconInspect.displayName = 'IconInspect'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,7 +42,6 @@ const colors = [ | |
|
||
export function APIAnatomy({children}: APIAnatomyProps) { | ||
const [activeStep, setActiveStep] = React.useState<number | null>(null); | ||
const ref = React.useRef<HTMLDivElement>(); | ||
|
||
const {steps, code} = React.Children.toArray(children).reduce( | ||
(acc: AnatomyContent, child) => { | ||
|
@@ -60,11 +59,7 @@ export function APIAnatomy({children}: APIAnatomyProps) { | |
break; | ||
case 'pre': | ||
acc.code = ( | ||
<CodeBlock | ||
ref={ref} | ||
{...child.props.children.props} | ||
noMargin={true} | ||
/> | ||
<CodeBlock {...child.props.children.props} noMargin={true} /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed |
||
); | ||
break; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
* Copyright (c) Facebook, Inc. and its affiliates. | ||
*/ | ||
|
||
import * as React from 'react'; | ||
import cn from 'classnames'; | ||
import { | ||
ClasserProvider, | ||
|
@@ -21,22 +20,19 @@ interface InlineHiglight { | |
endColumn: number; | ||
} | ||
|
||
const CodeBlock = React.forwardRef(function CodeBlock( | ||
{ | ||
children, | ||
className = 'language-js', | ||
metastring, | ||
noMargin, | ||
noMarkers, | ||
}: { | ||
children: string; | ||
className?: string; | ||
metastring: string; | ||
noMargin?: boolean; | ||
noMarkers?: boolean; | ||
}, | ||
ref?: React.Ref<HTMLDivElement> | ||
) { | ||
const CodeBlock = function CodeBlock({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only removed |
||
children, | ||
className = 'language-js', | ||
metastring, | ||
noMargin, | ||
noMarkers, | ||
}: { | ||
children: string; | ||
className?: string; | ||
metastring: string; | ||
noMargin?: boolean; | ||
noMarkers?: boolean; | ||
}) { | ||
const getDecoratedLineInfo = () => { | ||
if (!metastring) { | ||
return []; | ||
|
@@ -95,7 +91,6 @@ const CodeBlock = React.forwardRef(function CodeBlock( | |
'sp-cm': styles.codeViewer, | ||
}}> | ||
<SandpackCodeViewer | ||
ref={ref} | ||
showLineNumbers={false} | ||
decorators={decorators} | ||
/> | ||
|
@@ -104,7 +99,7 @@ const CodeBlock = React.forwardRef(function CodeBlock( | |
</SandpackProvider> | ||
</div> | ||
); | ||
}); | ||
}; | ||
|
||
export default CodeBlock; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
*/ | ||
|
||
import * as React from 'react'; | ||
import {IconInspect} from '../../Icon/IconInspect'; | ||
export interface ResetButtonProps { | ||
onClick: () => void; | ||
} | ||
|
||
export const DevToolsButton: React.FC<ResetButtonProps> = ({onClick}) => { | ||
return ( | ||
<button | ||
className="text-sm text-primary dark:text-primary-dark inline-flex items-center hover:text-link duration-100 ease-in transition mx-1" | ||
onClick={onClick} | ||
title="Open React devtools" | ||
type="button"> | ||
<IconInspect | ||
className="inline mb-0.5 ml-1 mr-0.5 relative" | ||
style={{top: 2}} | ||
/> | ||
<span className="hidden md:block">Inspect</span> | ||
</button> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,22 +3,29 @@ | |
*/ | ||
|
||
import * as React from 'react'; | ||
import {FileTabs, useSandpack} from '@codesandbox/sandpack-react'; | ||
import { | ||
FileTabs, | ||
useSandpack, | ||
useSandpackNavigation, | ||
} from '@codesandbox/sandpack-react'; | ||
import {OpenInCodeSandboxButton} from './OpenInCodeSandboxButton'; | ||
import {ResetButton} from './ResetButton'; | ||
import {DownloadButton} from './DownloadButton'; | ||
import {FilesDropdown} from './FilesDropdown'; | ||
import {DevToolsButton} from './DevToolsButton'; | ||
|
||
export function NavigationBar({ | ||
showDownload, | ||
onReset, | ||
onOpenDevTools, | ||
}: { | ||
showDownload: boolean; | ||
onReset: () => void; | ||
onOpenDevTools: (refresh: () => void) => void; | ||
}) { | ||
const {sandpack} = useSandpack(); | ||
const [dropdownActive, setDropdownActive] = React.useState(false); | ||
const {openPaths} = sandpack; | ||
const {openPaths, clients} = sandpack; | ||
const clientId = Object.keys(clients)[0]; | ||
const {refresh} = useSandpackNavigation(clientId); | ||
|
||
const resizeHandler = React.useCallback(() => { | ||
const width = window.innerWidth || document.documentElement.clientWidth; | ||
|
@@ -41,6 +48,11 @@ export function NavigationBar({ | |
return; | ||
}, [openPaths.length, resizeHandler]); | ||
|
||
const onReset = () => { | ||
|
||
sandpack.resetAllFiles(); | ||
refresh(); | ||
}; | ||
|
||
return ( | ||
<div className="bg-wash dark:bg-card-dark flex justify-between items-center relative z-10 border-b border-border dark:border-border-dark rounded-t-lg rounded-b-none"> | ||
<div className="px-4 lg:px-6"> | ||
|
@@ -51,7 +63,8 @@ export function NavigationBar({ | |
translate="yes"> | ||
{showDownload && <DownloadButton />} | ||
<ResetButton onReset={onReset} /> | ||
<OpenInCodeSandboxButton className="ml-2 md:ml-4" /> | ||
<OpenInCodeSandboxButton /> | ||
<DevToolsButton onClick={() => onOpenDevTools(refresh)} /> | ||
</div> | ||
</div> | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,29 +3,21 @@ | |
*/ | ||
|
||
import * as React from 'react'; | ||
import {useCodeSandboxLink} from '@codesandbox/sandpack-react'; | ||
import cn from 'classnames'; | ||
import {UnstyledOpenInCodeSandboxButton} from '@codesandbox/sandpack-react'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a minor Sandpack break change that fixed a bug for long sandboxes |
||
import {IconNewPage} from '../../Icon/IconNewPage'; | ||
|
||
export const OpenInCodeSandboxButton = ({className}: {className?: string}) => { | ||
const url = useCodeSandboxLink(); | ||
|
||
export const OpenInCodeSandboxButton = () => { | ||
return ( | ||
<a | ||
className={cn( | ||
'text-sm text-primary dark:text-primary-dark inline-flex items-center hover:text-link duration-100 ease-in transition mx-1', | ||
className | ||
)} | ||
href={url} | ||
rel="noreferrer noopener" | ||
target="_blank" | ||
<UnstyledOpenInCodeSandboxButton | ||
className="text-sm text-primary dark:text-primary-dark inline-flex items-center hover:text-link duration-100 ease-in transition mx-1 ml-3 md:ml-1" | ||
title="Open in CodeSandbox"> | ||
<span className="hidden md:inline"> | ||
<IconNewPage className="inline mb-0.5 text-base" /> Fork | ||
</span> | ||
<span className="inline md:hidden"> | ||
<IconNewPage className="inline mb-0.5 text-base" /> Fork | ||
</span> | ||
</a> | ||
<IconNewPage | ||
className="inline mb-0.5 ml-1 mr-1 relative" | ||
harish-sethuraman marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
width=".8em" | ||
height=".8em" | ||
style={{top: 1}} | ||
danilowoz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
/> | ||
<span className="hidden md:block">Fork</span> | ||
</UnstyledOpenInCodeSandboxButton> | ||
); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is fine 👍🏼 at least until the caching APIs become stable.