Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/components/ChartsPlayground/Playground/Editor.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import {ChartData} from '@gravity-ui/charts';
import {Button, Flex, Hotkey, Text} from '@gravity-ui/uikit';
import {Editor as MonacoEditor, OnMount} from '@monaco-editor/react';
import {KeyCode, KeyMod, type editor} from 'monaco-editor';
// Type-only: importing values from `monaco-editor` would bundle the whole package, which
// @monaco-editor/react already loads separately at runtime. Key codes come from the
// monaco instance handed to onMount instead.
import type {editor} from 'monaco-editor';
import {useTranslation} from 'next-i18next';
import React, {FC, useCallback, useRef, useState} from 'react';

Expand Down Expand Up @@ -67,12 +70,12 @@ export const Editor: FC<Props> = ({data, onApplyChanges, onReset}) => {
[],
);

const handleMount = useCallback(
(editor: editor.IStandaloneCodeEditor) => {
const handleMount = useCallback<OnMount>(
(editor, monaco) => {
editorRef.current = editor;
editor.setValue(JSON.stringify(data, null, 2));
// eslint-disable-next-line no-bitwise
editor.addCommand(KeyMod.CtrlCmd | KeyCode.Enter, handleApplyChanges);
editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.Enter, handleApplyChanges);
},
[data],
);
Expand Down
13 changes: 9 additions & 4 deletions src/components/GraphPlayground/Playground/Editor/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {TBlock, TBlockId, TConnection} from '@gravity-ui/graph';
import {Button, Flex, Hotkey, Text} from '@gravity-ui/uikit';
import {Editor, OnMount, OnValidate, loader} from '@monaco-editor/react';
import {KeyCode, KeyMod} from 'monaco-editor/esm/vs/editor/editor.api';
import {Ref, forwardRef, useCallback, useImperativeHandle, useRef, useState} from 'react';

import {block} from '../../../../utils';
Expand Down Expand Up @@ -117,11 +116,17 @@ export const ConfigEditor = forwardRef(function ConfigEditor(
<Flex direction="column" className={b()}>
<Flex grow={1}>
<Editor
onMount={(editor) => {
onMount={(editor, monaco) => {
monacoRef.current = editor;
monacoRef.current?.setValue(JSON.stringify(valueRef.current, null, 2));
// eslint-disable-next-line no-bitwise
editor.addCommand(KeyMod.CtrlCmd | KeyCode.Enter, applyChanges);
// Key codes come from the monaco instance rather than a static import
// of `monaco-editor`, which would bundle the whole package alongside
// the copy @monaco-editor/react already loads at runtime.
editor.addCommand(
// eslint-disable-next-line no-bitwise
monaco.KeyMod.CtrlCmd | monaco.KeyCode.Enter,
applyChanges,
);
}}
onValidate={(markers) => {
setErrorMarker(markers.filter((m) => m.severity === 8)[0] || null);
Expand Down
Loading