diff --git a/packages/toolpad-app/package.json b/packages/toolpad-app/package.json index d818e64fc60..e0604e286b4 100644 --- a/packages/toolpad-app/package.json +++ b/packages/toolpad-app/package.json @@ -66,6 +66,7 @@ "json-to-ts": "^1.7.0", "json5": "^2.2.1", "lodash-es": "^4.17.21", + "monaco-editor": "0.34.0-dev.20220725", "next": "12.2.0", "node-fetch": "^3.2.6", "node-fetch-har": "^1.0.1", @@ -110,7 +111,6 @@ "eslint-config-prettier": "^8.3.0", "eslint-plugin-import": "^2.25.3", "glob": "^8.0.3", - "monaco-editor": "^0.34.0-dev.20220722", "webpack": "^5.73.0" }, "typings": "./index.d.ts", diff --git a/packages/toolpad-app/src/components/MonacoEditor.tsx b/packages/toolpad-app/src/components/MonacoEditor.tsx index 45d4d5c1f7e..a6a05ea8f4d 100644 --- a/packages/toolpad-app/src/components/MonacoEditor.tsx +++ b/packages/toolpad-app/src/components/MonacoEditor.tsx @@ -10,6 +10,7 @@ import clsx from 'clsx'; import cuid from 'cuid'; import invariant from 'invariant'; import monacoEditorTheme from '../monacoEditorTheme'; +import muiTheme from '../theme'; function getExtension(language: string): string { switch (language) { @@ -107,6 +108,19 @@ const EditorRoot = styled('div')(({ theme }) => ({ }, })); +let overflowWidgetsDomNode: HTMLDivElement | null = null; +function getOverflowWidgetsDomNode(): HTMLDivElement { + if (!overflowWidgetsDomNode) { + overflowWidgetsDomNode = document.createElement('div'); + // See https://github.com/microsoft/monaco-editor/issues/2233#issuecomment-913170212 + overflowWidgetsDomNode.classList.add('monaco-editor'); + overflowWidgetsDomNode.style.zIndex = String(muiTheme.zIndex.tooltip + 1); + document.body.append(overflowWidgetsDomNode); + } + + return overflowWidgetsDomNode; +} + export interface MonacoEditorHandle { editor: monaco.editor.IStandaloneCodeEditor; monaco: typeof monaco; @@ -190,6 +204,9 @@ export default React.forwardRef(function tabSize: 2, automaticLayout: true, theme: monacoEditorTheme, + fixedOverflowWidgets: true, + // See https://github.com/microsoft/monaco-editor/issues/181 + overflowWidgetsDomNode: getOverflowWidgetsDomNode(), ...extraOptions, }); diff --git a/yarn.lock b/yarn.lock index d10296d3bef..cd9036abfbf 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8954,10 +8954,10 @@ modify-values@^1.0.0: resolved "https://registry.yarnpkg.com/modify-values/-/modify-values-1.0.1.tgz#b3939fa605546474e3e3e3c63d64bd43b4ee6022" integrity sha512-xV2bxeN6F7oYjZWTe/YPAy6MN2M+sL4u/Rlm2AHCIVGfo2p1yGmBHQ6vHehl4bRTZBdHu3TSkWdYgkwpYzAGSw== -monaco-editor@^0.34.0-dev.20220722: - version "0.34.0-dev.20220722" - resolved "https://registry.yarnpkg.com/monaco-editor/-/monaco-editor-0.34.0-dev.20220722.tgz#58bbb9477c2790c346c156e80d74585b6691b2e3" - integrity sha512-6l2hFsHOJE+5TQFDoWBeoACKcissTeLD5+xJ2HrtvP86sHnpnZy7ffbcFQCKpInJKIBSP7+y/bpctYn8eSAYTQ== +monaco-editor@0.34.0-dev.20220725: + version "0.34.0-dev.20220725" + resolved "https://registry.yarnpkg.com/monaco-editor/-/monaco-editor-0.34.0-dev.20220725.tgz#79e6bdef9dd3e1e5a66ebbbef549604064695b22" + integrity sha512-MiuJINwVQyqEEieWQ2NEcapjmi2MiAibthhpK2Tj2pd5tMHtZMO2PpoAKQla1cwxfhTlkb7e+cv0a+CN7Cl67A== mrmime@^1.0.0: version "1.0.1"