-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #179 from opensumi/v2.0
- Loading branch information
Showing
18 changed files
with
180 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"$schema": "node_modules/lerna/schemas/lerna-schema.json", | ||
"version": "2.0.2" | ||
"version": "2.0.4" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './mutex'; | ||
export * from './request'; | ||
export * from './types'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
export class Mutex { | ||
private mutex = Promise.resolve(); | ||
|
||
lock(): PromiseLike<() => void> { | ||
let begin: (unlock: () => void) => void = () => {}; | ||
|
||
this.mutex = this.mutex.then(() => new Promise(begin)); | ||
|
||
return new Promise((res) => { | ||
begin = res; | ||
}); | ||
} | ||
|
||
async dispatch<T>(fn: () => PromiseLike<T>): Promise<T> { | ||
const unlock = await this.lock(); | ||
try { | ||
return await Promise.resolve(fn()); | ||
} finally { | ||
unlock(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,75 @@ | ||
import { AppProvider, CodeEditor, DiffEditor } from '@codeblitzjs/ide-core'; | ||
import React from 'react'; | ||
import React, { useEffect, useState } from 'react'; | ||
import { createRoot } from 'react-dom/client'; | ||
import '@codeblitzjs/ide-core/languages'; | ||
import { SampleModule } from './module' | ||
import { SampleModule, diffsDeferred } from './module' | ||
import '../index.css'; | ||
import './index.css' | ||
|
||
const App = () => ( | ||
<AppProvider | ||
appConfig={{ | ||
workspaceDir: 'my-workspace', | ||
layoutConfig: {}, | ||
modules: [SampleModule], | ||
}} | ||
runtimeConfig={{ | ||
biz: 'startup', | ||
workspace: { | ||
filesystem: { | ||
fs: 'FileIndexSystem', | ||
options: { | ||
// 初始全量文件索引 | ||
requestFileIndex() { | ||
return Promise.resolve({ | ||
'main.html': '<div id="root"></div>', | ||
'main.css': 'body {}', | ||
'main.js': 'console.log("main")', | ||
'package.json': '{\n "name": "startup"\n}', | ||
}); | ||
}, | ||
}, | ||
} | ||
}, | ||
}} | ||
> | ||
<CodeEditor | ||
uri="main.js" | ||
style={{ width: 1000, height: 300, marginBottom: 16 }} | ||
editorOptions={{ | ||
scrollbar: { | ||
alwaysConsumeMouseWheel: false | ||
} | ||
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], | ||
}} | ||
/> | ||
<CodeEditor | ||
uri="main.css" | ||
style={{ width: 1000, height: 300 }} | ||
editorOptions={{ | ||
scrollbar: { | ||
alwaysConsumeMouseWheel: false | ||
} | ||
runtimeConfig={{ | ||
biz: 'startup', | ||
}} | ||
/> | ||
<DiffEditor | ||
originalUri="sample:/a1.js" | ||
modifiedUri="sample:/a2.js" | ||
editorOptions={{ | ||
scrollbar: { | ||
alwaysConsumeMouseWheel: false | ||
> | ||
{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 }} | ||
/> | ||
) | ||
} | ||
}} | ||
style={{ width: 1000, height: 300 }} | ||
/> | ||
</AppProvider> | ||
); | ||
})} | ||
</AppProvider> | ||
) | ||
}; | ||
|
||
createRoot(document.getElementById('main') as HTMLElement).render(<App />); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.