-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathindex.tsx
More file actions
75 lines (70 loc) · 2.09 KB
/
Copy pathindex.tsx
File metadata and controls
75 lines (70 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { AppProvider, CodeEditor, DiffEditor } from '@codeblitzjs/ide-core';
import React, { useEffect, useState } from 'react';
import { createRoot } from 'react-dom/client';
import '@codeblitzjs/ide-core/languages';
import { SampleModule, diffsDeferred } from './module'
import '../index.css';
import './index.css'
const App = () => {
const [diffs, setDiffs] = useState<{filePath: string, oldFileContent: string | null, newFileContent: string | null }[]>([])
useEffect(() => {
setTimeout(() => {
const diffs = [{
filePath: 'a.js',
oldFileContent: null,
newFileContent: 'console.log(123)'
}, {
filePath: 'a1.js',
oldFileContent: 'const add = (x, y) => {\n return x + y\n}',
newFileContent: 'const add = (x, y) => {\n return x + y + 1\n}'
}]
setDiffs(diffs)
diffsDeferred.resolve(diffs)
}, 1000)
}, [])
if (!diffs) return null
return (
<AppProvider
appConfig={{
workspaceDir: 'my-workspace',
layoutConfig: {},
modules: [SampleModule],
}}
runtimeConfig={{
biz: 'startup',
}}
>
{diffs.map(({ filePath, oldFileContent, newFileContent }) => {
if (!oldFileContent) {
return (
<CodeEditor
key={filePath}
uri={`sample://new/${filePath}`}
style={{ width: 1000, height: 300, marginBottom: 16 }}
editorOptions={{
scrollbar: {
alwaysConsumeMouseWheel: false
}
}}
/>
)
} else {
return (
<DiffEditor
key={filePath}
originalUri={`sample://old/${filePath}`}
modifiedUri={`sample://new/${filePath}`}
editorOptions={{
scrollbar: {
alwaysConsumeMouseWheel: false
}
}}
style={{ width: 1000, height: 300 }}
/>
)
}
})}
</AppProvider>
)
};
createRoot(document.getElementById('main') as HTMLElement).render(<App />);