diff --git a/apps/typegpu-docs/src/components/CodeEditor.tsx b/apps/typegpu-docs/src/components/CodeEditor.tsx index 90ab90aa57..7e3c7b4d7a 100644 --- a/apps/typegpu-docs/src/components/CodeEditor.tsx +++ b/apps/typegpu-docs/src/components/CodeEditor.tsx @@ -6,7 +6,10 @@ import Editor, { import type { editor } from 'monaco-editor'; import { entries, filter, fromEntries, isTruthy, map, pipe } from 'remeda'; import { SANDBOX_MODULES } from '../utils/examples/sandboxModules.ts'; -import type { ExampleSrcFile } from '../utils/examples/types.ts'; +import type { + ExampleCommonFile, + ExampleSrcFile, +} from '../utils/examples/types.ts'; import { tsCompilerOptions } from '../utils/liveEditor/embeddedTypeScript.ts'; function handleEditorWillMount(monaco: Monaco) { @@ -56,7 +59,7 @@ function handleEditorOnMount(editor: editor.IStandaloneCodeEditor) { } type Props = { - file: ExampleSrcFile; + file: ExampleSrcFile | ExampleCommonFile; shown: boolean; }; @@ -68,6 +71,11 @@ const createCodeEditorComponent = ( (props: Props) => { const { file, shown } = props; + // Monaco needs relative paths to work correctly and '../../common/file.ts' will not do + const path = 'common' in file + ? `common/${file.path}` + : `${file.exampleKey.replace('--', '/')}/${file.path}`; + return (
+ ); } diff --git a/apps/typegpu-docs/src/components/ExampleView.tsx b/apps/typegpu-docs/src/components/ExampleView.tsx index bc3611bdcc..72aaf91d74 100644 --- a/apps/typegpu-docs/src/components/ExampleView.tsx +++ b/apps/typegpu-docs/src/components/ExampleView.tsx @@ -10,7 +10,11 @@ import { ExecutionCancelledError } from '../utils/examples/errors.ts'; import { exampleControlsAtom } from '../utils/examples/exampleControlAtom.ts'; import { executeExample } from '../utils/examples/exampleRunner.ts'; import type { ExampleState } from '../utils/examples/exampleState.ts'; -import type { Example } from '../utils/examples/types.ts'; +import type { + Example, + ExampleCommonFile, + ExampleSrcFile, +} from '../utils/examples/types.ts'; import { isGPUSupported } from '../utils/isGPUSupported.ts'; import { HtmlCodeEditor, TsCodeEditor } from './CodeEditor.tsx'; import { ControlPanel } from './ControlPanel.tsx'; @@ -20,6 +24,7 @@ import { openInStackBlitz } from './stackblitz/openInStackBlitz.ts'; type Props = { example: Example; + common: ExampleCommonFile[]; isPlayground?: boolean; }; @@ -66,8 +71,8 @@ function useExample( }, [setSnackbarText, setExampleControlParams]); } -export function ExampleView({ example }: Props) { - const { tsFiles, tsImport, htmlFile } = example; +export function ExampleView({ example, common }: Props) { + const { tsFiles: srcFiles, tsImport, htmlFile } = example; const [snackbarText, setSnackbarText] = useAtom(currentSnackbarAtom); const [currentFilePath, setCurrentFilePath] = useState('index.ts'); @@ -76,6 +81,7 @@ export function ExampleView({ example }: Props) { const codeEditorMobileShowing = useAtomValue(codeEditorShownMobileAtom); const exampleHtmlRef = useRef(null); + const tsFiles = filterRelevantTsFiles(srcFiles, common); const filePaths = tsFiles.map((file) => file.path); const editorTabsList = [ 'index.ts', @@ -171,7 +177,7 @@ export function ExampleView({ example }: Props) {
-