-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: update editor * feat: update editor
- Loading branch information
Showing
3 changed files
with
127 additions
and
7 deletions.
There are no files selected for viewing
92 changes: 92 additions & 0 deletions
92
...mponents/@@plugins/src/components/studio/tugraph/domain-core/graph-query/cypherEditor.tsx
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,92 @@ | ||
// @ts-nocheck | ||
import React, { forwardRef } from 'react'; | ||
import { MonacoEnvironment, EditorProvider } from '@difizen/cofine-editor-core'; | ||
|
||
const Editor = forwardRef<any, any>((props, editorRef) => { | ||
const { value, onCreated, onChange, language = 'cypher', onInit } = props; | ||
let codeEditor: monaco.editor.IStandaloneCodeEditor; | ||
|
||
// 监听事件 | ||
let erdElement: HTMLElement | null; | ||
|
||
const installElementResizeDetector = () => { | ||
// eslint-disable-next-line react/no-find-dom-node | ||
const node = editorRef && editorRef.current; | ||
const parentNode = node && node.parentElement; | ||
erdElement = parentNode; | ||
}; | ||
|
||
React.useEffect(() => { | ||
MonacoEnvironment.loadModule( | ||
async (container: { load: (arg0: Syringe.Module) => void }) => { | ||
const dsl = await import('@difizen/cofine-language-cypher'); | ||
container.load(dsl.default); | ||
}, | ||
); | ||
MonacoEnvironment.init().then(async () => { | ||
if (editorRef && editorRef.current) { | ||
const editorProvider = | ||
MonacoEnvironment.container.get<EditorProvider>(EditorProvider); | ||
const editor = editorProvider.create(editorRef.current, { | ||
language, | ||
value, | ||
theme: 'cypherTheme', | ||
suggestLineHeight: 24, | ||
suggestLineHeight: 24, | ||
automaticLayout: true, | ||
minimap: { enabled: false }, | ||
fontSize: 14, | ||
lineHeight: 20, | ||
folding: true, | ||
wordWrap: 'on', | ||
lineDecorationsWidth: 0, | ||
lineNumbersMinChars: 3, | ||
readOnly: false, | ||
hover: { | ||
delay: 800, | ||
}, | ||
suggestSelection: 'first', | ||
wordBasedSuggestions: false, | ||
suggest: { snippetsPreventQuickSuggestions: false }, | ||
autoClosingQuotes: 'always', | ||
fixedOverflowWidgets: true, | ||
'bracketPairColorization.enabled': true, | ||
}); | ||
|
||
editorRef.current.codeEditor = codeEditor = editor.codeEditor; | ||
if (onInit) { | ||
onInit(editorRef.current.codeEditor); | ||
} | ||
installElementResizeDetector(); | ||
|
||
if (onCreated) { | ||
onCreated(editor.codeEditor); | ||
} | ||
if (onChange) { | ||
editor.codeEditor.onDidChangeModelContent(() => | ||
onChange(editor.codeEditor.getValue()), | ||
); | ||
} | ||
// registerOptions({}); | ||
} | ||
}); | ||
|
||
return () => { | ||
if (codeEditor) { | ||
codeEditor.dispose(); | ||
} | ||
}; | ||
}, [editorRef]); | ||
|
||
return ( | ||
<div | ||
ref={editorRef} | ||
style={{ | ||
width: '100%', | ||
height: '100%', | ||
}} | ||
/> | ||
); | ||
}); | ||
|
||
export default Editor; |
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