@fc-components/monaco-editor 0.1.5 → 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
- declare const _default: React.ForwardRefExoticComponent<PromQLEditorProps & DataProviderParams & React.RefAttributes<unknown>>;
16
- export default _default;
17
+ export default function PromQLEditor(props: PromQLEditorProps & DataProviderParams): React.JSX.Element;
18
+ export {};
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.1.5",
6
+ "version": "0.1.6",
7
7
  "license": "MIT",
8
8
  "main": "dist/index.js",
9
9
  "module": "dist/monaco-editor.esm.js",
@@ -1,4 +1,4 @@
1
- import React, { forwardRef, useEffect, useRef, useImperativeHandle } from 'react';
1
+ import React, { useEffect, useRef } from 'react';
2
2
  import MonacoEditor from 'react-monaco-editor';
3
3
  import * as monaco from 'monaco-editor';
4
4
  import { promLanguageDefinition } from 'monaco-promql';
@@ -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;
@@ -67,16 +68,26 @@ const getStyles = (placeholder?: string) => {
67
68
  };
68
69
  };
69
70
 
70
- export default forwardRef(function PromQLEditor(props: PromQLEditorProps & DataProviderParams, ref) {
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
- const editorRef = useRef<monacoTypes.editor.IStandaloneCodeEditor | null>(null);
77
89
  const styles = getStyles(placeholder);
78
90
  const handleEditorDidMount = (editor: monacoTypes.editor.IStandaloneCodeEditor) => {
79
- editorRef.current = editor;
80
91
  monaco.editor.defineTheme('n9e-dark', {
81
92
  base: 'vs-dark',
82
93
  inherit: true,
@@ -199,14 +210,9 @@ export default forwardRef(function PromQLEditor(props: PromQLEditorProps & DataP
199
210
  monaco.editor.setModelMarkers(model, 'owner', markers);
200
211
  }
201
212
  });
202
- };
203
213
 
204
- useEffect(() => {
205
- const dataProvider = dataProviderRef.current;
206
- if (dataProvider) {
207
- dataProvider.setVariablesNames(variablesNames || []);
208
- }
209
- }, [JSON.stringify(variablesNames)]);
214
+ editorDidMount?.(editor);
215
+ };
210
216
 
211
217
  useEffect(() => {
212
218
  // 注册 PromQL 语言
@@ -229,11 +235,12 @@ export default forwardRef(function PromQLEditor(props: PromQLEditorProps & DataP
229
235
  };
230
236
  }, []);
231
237
 
232
- useImperativeHandle(ref, () => ({
233
- getEditor: () => {
234
- return editorRef.current;
235
- },
236
- }));
238
+ useEffect(() => {
239
+ const dataProvider = dataProviderRef.current;
240
+ if (dataProvider) {
241
+ dataProvider.setVariablesNames(variablesNames || []);
242
+ }
243
+ }, [JSON.stringify(variablesNames)]);
237
244
 
238
245
  return (
239
246
  <div className={'ant-input' + (size ? ` ${SIZE_MAP[size].className}` : '')}>
@@ -280,4 +287,4 @@ export default forwardRef(function PromQLEditor(props: PromQLEditorProps & DataP
280
287
  </div>
281
288
  </div>
282
289
  );
283
- });
290
+ }