diff --git a/src/ui/SourceEditor.tsx b/src/ui/SourceEditor.tsx new file mode 100644 index 00000000..9a1ad1f4 --- /dev/null +++ b/src/ui/SourceEditor.tsx @@ -0,0 +1,29 @@ +import { markdown as markdownLanguageSupport } from '@codemirror/lang-markdown' +import type { CodeMirrorRef } from '@codesandbox/sandpack-react/components/CodeEditor/CodeMirror' +import { SandpackProvider, CodeEditor as TheEditorFromSandpack } from '@codesandbox/sandpack-react' +import React from 'react' +import { useEmitterValues, usePublisher } from '../system/EditorSystemComponent' + +export const SourceEditor = () => { + const [markdown] = useEmitterValues('markdownSourceFromEditor') + const updateMarkdown = usePublisher('markdownSourceFromEditor') + const codeMirrorRef = React.useRef(null) + + return ( +
+ + + + + +
+ ) +} diff --git a/src/ui/SourcePlugin.tsx b/src/ui/SourcePlugin.tsx index b2533a62..2d9c8634 100644 --- a/src/ui/SourcePlugin.tsx +++ b/src/ui/SourcePlugin.tsx @@ -1,15 +1,14 @@ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ /* eslint-disable @typescript-eslint/no-unsafe-assignment */ -import { markdown as markdownLanguageSupport } from '@codemirror/lang-markdown' -import { SandpackProvider, CodeEditor as TheEditorFromSandpack } from '@codesandbox/sandpack-react' -import { CodeMirrorRef } from '@codesandbox/sandpack-react/components/CodeEditor/CodeMirror' import React from 'react' import { Diff, Hunk, parseDiff } from 'react-diff-view' import { diffLines, formatLines } from 'unidiff' -import { useEmitterValues, usePublisher } from '../system/EditorSystemComponent' +import { useEmitterValues } from '../system/EditorSystemComponent' import 'react-diff-view/style/index.css' +const SourceEditor = React.lazy(() => import('./SourceEditor').then((module) => ({ default: module.SourceEditor }))) + export function DiffViewer({ oldText, newText }: { oldText: string; newText: string }) { const diffText = formatLines(diffLines(oldText, newText), { context: 3 }) if (diffText.trim() === '') return
No changes
@@ -38,29 +37,11 @@ export const ViewModeToggler: React.FC = ({ children }) => {
{children}
{viewMode === 'diff' ? : null} - {viewMode === 'markdown' ? : null} -
- ) -} - -export const SourceEditor = () => { - const [markdown] = useEmitterValues('markdownSourceFromEditor') - const updateMarkdown = usePublisher('markdownSourceFromEditor') - const codeMirrorRef = React.useRef(null) - - return ( -
- - - + {viewMode === 'markdown' ? ( + + + + ) : null}
) }