@fc-components/monaco-editor 0.1.4 → 0.1.5
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.
- package/README.md +51 -34
- package/dist/monaco-editor.cjs.development.js +31 -22
- package/dist/monaco-editor.cjs.development.js.map +1 -1
- package/dist/monaco-editor.cjs.production.min.js +1 -1
- package/dist/monaco-editor.cjs.production.min.js.map +1 -1
- package/dist/monaco-editor.esm.js +32 -23
- package/dist/monaco-editor.esm.js.map +1 -1
- package/dist/promql/index.d.ts +2 -2
- package/package.json +1 -1
- package/src/promql/index.tsx +32 -25
package/dist/promql/index.d.ts
CHANGED
|
@@ -12,5 +12,5 @@ interface PromQLEditorProps {
|
|
|
12
12
|
onShiftEnter?: (value: string) => void;
|
|
13
13
|
onBlur?: (value: string) => void;
|
|
14
14
|
}
|
|
15
|
-
|
|
16
|
-
export
|
|
15
|
+
declare const _default: React.ForwardRefExoticComponent<PromQLEditorProps & DataProviderParams & React.RefAttributes<unknown>>;
|
|
16
|
+
export default _default;
|
package/package.json
CHANGED
package/src/promql/index.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useEffect, useRef } from 'react';
|
|
1
|
+
import React, { forwardRef, useEffect, useRef, useImperativeHandle } 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';
|
|
@@ -67,36 +67,16 @@ const getStyles = (placeholder?: string) => {
|
|
|
67
67
|
};
|
|
68
68
|
};
|
|
69
69
|
|
|
70
|
-
export default function PromQLEditor(props: PromQLEditorProps & DataProviderParams) {
|
|
70
|
+
export default forwardRef(function PromQLEditor(props: PromQLEditorProps & DataProviderParams, ref) {
|
|
71
71
|
const id = uuidv4();
|
|
72
72
|
const { size = 'middle', theme = 'light', variablesNames, value, placeholder, interpolateString, enableAutocomplete = true, onChange, onShiftEnter, onBlur } = props;
|
|
73
73
|
const autocompleteDisposeFun = useRef<(() => void) | null>(null);
|
|
74
74
|
const containerRef = useRef<HTMLDivElement>(null);
|
|
75
75
|
const dataProviderRef = useRef<DataProvider | null>(null);
|
|
76
|
+
const editorRef = useRef<monacoTypes.editor.IStandaloneCodeEditor | null>(null);
|
|
76
77
|
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
78
|
const handleEditorDidMount = (editor: monacoTypes.editor.IStandaloneCodeEditor) => {
|
|
79
|
+
editorRef.current = editor;
|
|
100
80
|
monaco.editor.defineTheme('n9e-dark', {
|
|
101
81
|
base: 'vs-dark',
|
|
102
82
|
inherit: true,
|
|
@@ -228,6 +208,33 @@ export default function PromQLEditor(props: PromQLEditorProps & DataProviderPara
|
|
|
228
208
|
}
|
|
229
209
|
}, [JSON.stringify(variablesNames)]);
|
|
230
210
|
|
|
211
|
+
useEffect(() => {
|
|
212
|
+
// 注册 PromQL 语言
|
|
213
|
+
const { aliases, extensions, mimetypes } = promLanguageDefinition;
|
|
214
|
+
monaco.languages.register({
|
|
215
|
+
id: PROMQL_LANG_ID,
|
|
216
|
+
aliases,
|
|
217
|
+
extensions,
|
|
218
|
+
mimetypes,
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
// 设置语法高亮
|
|
222
|
+
monaco.languages.setMonarchTokensProvider(PROMQL_LANG_ID, language as any);
|
|
223
|
+
|
|
224
|
+
// 设置语言配置
|
|
225
|
+
monaco.languages.setLanguageConfiguration(PROMQL_LANG_ID, languageConfiguration as any);
|
|
226
|
+
|
|
227
|
+
return () => {
|
|
228
|
+
autocompleteDisposeFun.current?.();
|
|
229
|
+
};
|
|
230
|
+
}, []);
|
|
231
|
+
|
|
232
|
+
useImperativeHandle(ref, () => ({
|
|
233
|
+
getEditor: () => {
|
|
234
|
+
return editorRef.current;
|
|
235
|
+
},
|
|
236
|
+
}));
|
|
237
|
+
|
|
231
238
|
return (
|
|
232
239
|
<div className={'ant-input' + (size ? ` ${SIZE_MAP[size].className}` : '')}>
|
|
233
240
|
<div ref={containerRef}>
|
|
@@ -273,4 +280,4 @@ export default function PromQLEditor(props: PromQLEditorProps & DataProviderPara
|
|
|
273
280
|
</div>
|
|
274
281
|
</div>
|
|
275
282
|
);
|
|
276
|
-
}
|
|
283
|
+
});
|