-
Notifications
You must be signed in to change notification settings - Fork 890
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add json worker to monaco editor (#3424)
* feat: add json worker and language implement in dashboards Signed-off-by: suzhou <[email protected]> --------- Signed-off-by: suzhou <[email protected]> Co-authored-by: Anan Zhuang <[email protected]> Co-authored-by: Josh Romero <[email protected]>
- Loading branch information
1 parent
152fc9f
commit 725a2a1
Showing
9 changed files
with
65 additions
and
15 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
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { registerWorker } from '../worker_store'; | ||
// @ts-ignore | ||
import jsonWorkerSrc from '!!raw-loader!../../target/public/json.editor.worker.js'; | ||
|
||
registerWorker('json', jsonWorkerSrc); |
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,8 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
// @ts-ignore | ||
/* eslint-disable-next-line @osd/eslint/module_migration */ | ||
import 'monaco-editor/esm/vs/language/json/json.worker.js'; |
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,17 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { getWorker } from './worker_store'; | ||
|
||
// @ts-ignore | ||
window.MonacoEnvironment = { | ||
getWorker: (module: string, languageId: string) => { | ||
const workerSrc = getWorker(languageId); | ||
if (workerSrc) { | ||
const blob = new Blob([workerSrc], { type: 'application/javascript' }); | ||
return new Worker(URL.createObjectURL(blob)); | ||
} | ||
}, | ||
}; |
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,19 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
const workerStoreMap: Record<string, string> = {}; | ||
|
||
export const registerWorker = (workerId: string, worker: string) => { | ||
if (!workerStoreMap[workerId]) { | ||
workerStoreMap[workerId] = worker; | ||
return true; | ||
} | ||
|
||
return false; | ||
}; | ||
|
||
export const getWorker = (workerId: string) => { | ||
return workerStoreMap[workerId]; | ||
}; |
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