-
Notifications
You must be signed in to change notification settings - Fork 4
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 #8 from mkslanc/react-ace-demo
React ace + ace-linters demo
- Loading branch information
Showing
16 changed files
with
71 additions
and
29 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
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
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,22 +1,45 @@ | ||
import React from "react"; | ||
import React, {useEffect, useRef} from "react"; | ||
import * as ReactDOMClient from 'react-dom/client'; | ||
import AceEditor from "react-ace"; | ||
|
||
import "ace-builds/esm-resolver"; | ||
import "ace-builds/src-noconflict/ext-language_tools"; | ||
import {LanguageProvider} from "ace-linters"; | ||
|
||
function onChange(newValue) { | ||
console.log("change", newValue); | ||
let worker = new Worker(new URL('./webworker.js', import.meta.url), {type: "module"}); | ||
let languageProvider = LanguageProvider.create(worker); | ||
|
||
// Editor component | ||
function AceEditorWithLinters() { | ||
const editorRef = useRef(null); | ||
|
||
useEffect(() => { | ||
if (editorRef.current) { | ||
languageProvider.registerEditor(editorRef.current.editor); | ||
} | ||
}, []); | ||
|
||
function onChange(newValue) { | ||
console.log("change", newValue); | ||
} | ||
|
||
return (<AceEditor | ||
ref={editorRef} | ||
mode="json" | ||
theme="cobalt" | ||
onChange={onChange} | ||
name="UNIQUE_ID_OF_DIV" | ||
enableBasicAutocompletion={true} | ||
enableLiveAutocompletion={true} | ||
editorProps={{$blockScrolling: true}} | ||
height="200px" | ||
value={`{ | ||
"name": 12 | ||
"country": "Ireland" | ||
}`} | ||
/>); | ||
} | ||
|
||
// Render to the DOM | ||
var root = ReactDOMClient.createRoot(document.body); | ||
|
||
// Render editor | ||
root.render(<AceEditor | ||
mode="java" | ||
theme="cobalt" | ||
onChange={onChange} | ||
name="UNIQUE_ID_OF_DIV" | ||
editorProps={{}} | ||
height={200} | ||
/>); | ||
root.render(<AceEditorWithLinters/>); |
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,8 @@ | ||
import {defineConfig} from 'vite' | ||
|
||
export default defineConfig({ | ||
base: '', | ||
worker: { | ||
format: "es", | ||
} | ||
}) |
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,9 @@ | ||
import {ServiceManager} from "ace-linters/build/service-manager"; | ||
|
||
let manager = new ServiceManager(self); | ||
|
||
manager.registerService("json", { | ||
module: () => import("ace-linters/build/json-service"), | ||
className: "JsonService", | ||
modes: "json" | ||
}); |