(
{
width = "100%",
height = "100%",
value = null,
defaultValue = "",
language = "javascript",
theme = null,
options = {},
overrideServices = {},
editorWillMount = noop,
editorDidMount = noop,
editorWillUnmount = noop,
onChange = noop,
className = null,
original = null,
originalUri,
modifiedUri,
}: MonacoDiffEditorProps,
ref: React.ForwardedRef<MonacoDiffEditorHandle>,
)
| 5 | import { noop, processSize } from "./utils"; |
| 6 | |
| 7 | function MonacoDiffEditor( |
| 8 | { |
| 9 | width = "100%", |
| 10 | height = "100%", |
| 11 | value = null, |
| 12 | defaultValue = "", |
| 13 | language = "javascript", |
| 14 | theme = null, |
| 15 | options = {}, |
| 16 | overrideServices = {}, |
| 17 | editorWillMount = noop, |
| 18 | editorDidMount = noop, |
| 19 | editorWillUnmount = noop, |
| 20 | onChange = noop, |
| 21 | className = null, |
| 22 | original = null, |
| 23 | originalUri, |
| 24 | modifiedUri, |
| 25 | }: MonacoDiffEditorProps, |
| 26 | ref: React.ForwardedRef<MonacoDiffEditorHandle>, |
| 27 | ) { |
| 28 | const containerElement = useRef<HTMLDivElement | null>(null); |
| 29 | |
| 30 | const editor = useRef<monaco.editor.IStandaloneDiffEditor | null>(null); |
| 31 | |
| 32 | const _subscription = useRef<monaco.IDisposable | null>(null); |
| 33 | |
| 34 | const __prevent_trigger_change_event = useRef<boolean | null>(null); |
| 35 | |
| 36 | const fixedWidth = processSize(width); |
| 37 | |
| 38 | const fixedHeight = processSize(height); |
| 39 | |
| 40 | const style = useMemo( |
| 41 | () => ({ |
| 42 | width: fixedWidth, |
| 43 | height: fixedHeight, |
| 44 | }), |
| 45 | [fixedWidth, fixedHeight], |
| 46 | ); |
| 47 | |
| 48 | React.useImperativeHandle(ref, () => ({ |
| 49 | get editor() { |
| 50 | return editor.current; |
| 51 | }, |
| 52 | })); |
| 53 | |
| 54 | const handleEditorWillMount = () => { |
| 55 | const finalOptions = editorWillMount(monaco); |
| 56 | return finalOptions || {}; |
| 57 | }; |
| 58 | |
| 59 | const handleEditorDidMount = () => { |
| 60 | editorDidMount(editor.current, monaco); |
| 61 | |
| 62 | const { modified } = editor.current.getModel(); |
| 63 | _subscription.current = modified.onDidChangeContent((event) => { |
| 64 | if (!__prevent_trigger_change_event.current) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…