@fc-components/monaco-editor 0.1.4 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,5 @@
1
1
  import React from 'react';
2
+ import type * as monacoTypes from 'monaco-editor/esm/vs/editor/editor.api';
2
3
  import type { DataProviderParams } from './types';
3
4
  interface PromQLEditorProps {
4
5
  size?: 'small' | 'middle' | 'large';
@@ -11,6 +12,7 @@ interface PromQLEditorProps {
11
12
  onChange?: (value: string) => void;
12
13
  onShiftEnter?: (value: string) => void;
13
14
  onBlur?: (value: string) => void;
15
+ editorDidMount?: (editor: monacoTypes.editor.IStandaloneCodeEditor) => void;
14
16
  }
15
17
  export default function PromQLEditor(props: PromQLEditorProps & DataProviderParams): React.JSX.Element;
16
18
  export {};
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.1.4",
6
+ "version": "0.1.6",
7
7
  "license": "MIT",
8
8
  "main": "dist/index.js",
9
9
  "module": "dist/monaco-editor.esm.js",
@@ -24,6 +24,7 @@ interface PromQLEditorProps {
24
24
  onChange?: (value: string) => void;
25
25
  onShiftEnter?: (value: string) => void;
26
26
  onBlur?: (value: string) => void;
27
+ editorDidMount?: (editor: monacoTypes.editor.IStandaloneCodeEditor) => void;
27
28
  }
28
29
 
29
30
  const PROMQL_LANG_ID = promLanguageDefinition.id;
@@ -69,33 +70,23 @@ const getStyles = (placeholder?: string) => {
69
70
 
70
71
  export default function PromQLEditor(props: PromQLEditorProps & DataProviderParams) {
71
72
  const id = uuidv4();
72
- const { size = 'middle', theme = 'light', variablesNames, value, placeholder, interpolateString, enableAutocomplete = true, onChange, onShiftEnter, onBlur } = props;
73
+ const {
74
+ size = 'middle',
75
+ theme = 'light',
76
+ variablesNames,
77
+ value,
78
+ placeholder,
79
+ interpolateString,
80
+ enableAutocomplete = true,
81
+ onChange,
82
+ onShiftEnter,
83
+ onBlur,
84
+ editorDidMount,
85
+ } = props;
73
86
  const autocompleteDisposeFun = useRef<(() => void) | null>(null);
74
87
  const containerRef = useRef<HTMLDivElement>(null);
75
88
  const dataProviderRef = useRef<DataProvider | null>(null);
76
89
  const styles = getStyles(placeholder);
77
-
78
- useEffect(() => {
79
- // 注册 PromQL 语言
80
- const { aliases, extensions, mimetypes } = promLanguageDefinition;
81
- monaco.languages.register({
82
- id: PROMQL_LANG_ID,
83
- aliases,
84
- extensions,
85
- mimetypes,
86
- });
87
-
88
- // 设置语法高亮
89
- monaco.languages.setMonarchTokensProvider(PROMQL_LANG_ID, language as any);
90
-
91
- // 设置语言配置
92
- monaco.languages.setLanguageConfiguration(PROMQL_LANG_ID, languageConfiguration as any);
93
-
94
- return () => {
95
- autocompleteDisposeFun.current?.();
96
- };
97
- }, []);
98
-
99
90
  const handleEditorDidMount = (editor: monacoTypes.editor.IStandaloneCodeEditor) => {
100
91
  monaco.editor.defineTheme('n9e-dark', {
101
92
  base: 'vs-dark',
@@ -219,8 +210,31 @@ export default function PromQLEditor(props: PromQLEditorProps & DataProviderPara
219
210
  monaco.editor.setModelMarkers(model, 'owner', markers);
220
211
  }
221
212
  });
213
+
214
+ editorDidMount?.(editor);
222
215
  };
223
216
 
217
+ useEffect(() => {
218
+ // 注册 PromQL 语言
219
+ const { aliases, extensions, mimetypes } = promLanguageDefinition;
220
+ monaco.languages.register({
221
+ id: PROMQL_LANG_ID,
222
+ aliases,
223
+ extensions,
224
+ mimetypes,
225
+ });
226
+
227
+ // 设置语法高亮
228
+ monaco.languages.setMonarchTokensProvider(PROMQL_LANG_ID, language as any);
229
+
230
+ // 设置语言配置
231
+ monaco.languages.setLanguageConfiguration(PROMQL_LANG_ID, languageConfiguration as any);
232
+
233
+ return () => {
234
+ autocompleteDisposeFun.current?.();
235
+ };
236
+ }, []);
237
+
224
238
  useEffect(() => {
225
239
  const dataProvider = dataProviderRef.current;
226
240
  if (dataProvider) {