diff --git a/package-lock.json b/package-lock.json index ff46b6cb6..8829170e9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -44,7 +44,7 @@ "jquery": "^3.7.1", "json-schema-to-ts": "^3.1.1", "launchdarkly-js-client-sdk": "^3.5.0", - "monaco-editor": "^0.52.0", + "monaco-editor": "0.51.0", "monaco-yaml": "^5.2.3", "ng-showdown": "^1.1.0", "prop-types": "^15.8.1", @@ -22466,10 +22466,9 @@ } }, "node_modules/monaco-editor": { - "version": "0.52.0", - "resolved": "https://registry.npmjs.org/monaco-editor/-/monaco-editor-0.52.0.tgz", - "integrity": "sha512-OeWhNpABLCeTqubfqLMXGsqf6OmPU6pHM85kF3dhy6kq5hnhuVS1p3VrEW/XhWHc71P2tHyS5JFySD8mgs1crw==", - "license": "MIT" + "version": "0.51.0", + "resolved": "https://registry.npmjs.org/monaco-editor/-/monaco-editor-0.51.0.tgz", + "integrity": "sha512-xaGwVV1fq343cM7aOYB6lVE4Ugf0UyimdD/x5PWcWBMKENwectaEu77FAN7c5sFiyumqeJdX1RPTh1ocioyDjw==" }, "node_modules/monaco-editor-webpack-plugin": { "version": "7.1.0", diff --git a/package.json b/package.json index a4511c591..82762bc1d 100644 --- a/package.json +++ b/package.json @@ -89,7 +89,7 @@ "jquery": "^3.7.1", "json-schema-to-ts": "^3.1.1", "launchdarkly-js-client-sdk": "^3.5.0", - "monaco-editor": "^0.52.0", + "monaco-editor": "0.51.0", "monaco-yaml": "^5.2.3", "ng-showdown": "^1.1.0", "prop-types": "^15.8.1", diff --git a/source/javascripts/components/YmlEditor/YmlEditor.tsx b/source/javascripts/components/YmlEditor/YmlEditor.tsx index 83e5d39af..8fed44eca 100644 --- a/source/javascripts/components/YmlEditor/YmlEditor.tsx +++ b/source/javascripts/components/YmlEditor/YmlEditor.tsx @@ -1,5 +1,7 @@ +import { useEffect, useState } from 'react'; + import Editor from '@monaco-editor/react'; -import { configureMonacoYaml } from 'monaco-yaml'; +import { configureMonacoYaml, MonacoYaml } from 'monaco-yaml'; type YmlEditorProps = { isLoading?: boolean; @@ -7,11 +9,13 @@ type YmlEditorProps = { yml: string; onChange: (changedText?: string) => void; }; + const YmlEditor = ({ isLoading, readonly, yml, onChange }: YmlEditorProps) => { - const defaultSchema = { - uri: 'https://json.schemastore.org/bitrise.json', - fileMatch: ['*'], - }; + const [monacoYaml, setMonacoYaml] = useState(); + + useEffect(() => { + return monacoYaml?.dispose; + }, [monacoYaml]); return ( { value={isLoading ? 'Loading...' : yml} theme="vs-dark" options={{ - readOnly: readonly || isLoading, roundedSelection: false, scrollBeyondLastLine: false, + readOnly: readonly || isLoading, stickyScroll: { enabled: true, }, }} - onMount={(_, monaco) => { - configureMonacoYaml(monaco, { - validate: true, - enableSchemaRequest: true, - format: true, - hover: true, - completion: true, - schemas: [defaultSchema], - }); + beforeMount={(monaco) => { + setMonacoYaml( + configureMonacoYaml(monaco, { + hover: true, + format: true, + validate: true, + completion: true, + enableSchemaRequest: true, + schemas: [{ uri: 'https://json.schemastore.org/bitrise.json', fileMatch: ['*'] }], + }), + ); }} onChange={onChange} />