@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.
- package/README.md +51 -34
- package/dist/monaco-editor.cjs.development.js +22 -20
- 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 +22 -20
- package/dist/monaco-editor.esm.js.map +1 -1
- package/dist/promql/index.d.ts +2 -0
- package/package.json +1 -1
- package/src/promql/index.tsx +37 -23
package/README.md
CHANGED
|
@@ -5,42 +5,59 @@ import { PromQLMonacoEditor } from '@fc-components/monaco-editor';
|
|
|
5
5
|
|
|
6
6
|
const App = () => {
|
|
7
7
|
const [value, setValue] = React.useState<string>();
|
|
8
|
+
const promQLMonacoEditorRef = React.useRef<typeof PromQLMonacoEditor | null>(null);
|
|
8
9
|
|
|
9
10
|
return (
|
|
10
|
-
<
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
//
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
11
|
+
<div style={{ padding: 16 }}>
|
|
12
|
+
<PromQLMonacoEditor
|
|
13
|
+
ref={promQLMonacoEditorRef}
|
|
14
|
+
theme='light' // or 'dark'
|
|
15
|
+
size='middle' // 'small', 'middle', or 'large'
|
|
16
|
+
placeholder='Enter your PromQL query here...'
|
|
17
|
+
variablesNames={['$job', '$instance']} // Example variable names
|
|
18
|
+
apiPrefix='/api/n9e/proxy/1/api/v1'
|
|
19
|
+
request={(resource, options) => {
|
|
20
|
+
const params = options?.body?.toString();
|
|
21
|
+
const search = params ? `?${params}` : '';
|
|
22
|
+
return fetch(resource + search, {
|
|
23
|
+
method: 'Get',
|
|
24
|
+
headers: new Headers({
|
|
25
|
+
Authorization: `Bearer ${localStorage.getItem('access_token') || ''}`,
|
|
26
|
+
}),
|
|
27
|
+
});
|
|
28
|
+
}}
|
|
29
|
+
value={value}
|
|
30
|
+
enableAutocomplete={true} // Enable completion
|
|
31
|
+
durationVariablesCompletion={false} // Disable duration variables completion. eg. $__interval, $__range, $__rate_interval
|
|
32
|
+
interpolateString={(query) => {
|
|
33
|
+
// Interpolate variables in the query string
|
|
34
|
+
return query.replace(/\$__interval/g, '10s');
|
|
35
|
+
}}
|
|
36
|
+
onShiftEnter={(value) => {
|
|
37
|
+
console.log('Shift+Enter pressed, current value:', value);
|
|
38
|
+
}}
|
|
39
|
+
onBlur={(value) => {
|
|
40
|
+
console.log('Editor lost focus, current value:', value);
|
|
41
|
+
}}
|
|
42
|
+
onChange={(value) => {
|
|
43
|
+
console.log('Value changed:', value);
|
|
44
|
+
setValue(value);
|
|
45
|
+
}}
|
|
46
|
+
/>
|
|
47
|
+
<div>
|
|
48
|
+
<a
|
|
49
|
+
onClick={() => {
|
|
50
|
+
if (promQLMonacoEditorRef.current) {
|
|
51
|
+
const editor = promQLMonacoEditorRef.current.getEditor();
|
|
52
|
+
editor.trigger('keyboard', 'type', { text: 'Insert Text' });
|
|
53
|
+
editor.focus();
|
|
54
|
+
}
|
|
55
|
+
}}
|
|
56
|
+
>
|
|
57
|
+
Click to insert text after the cursor
|
|
58
|
+
</a>
|
|
59
|
+
</div>
|
|
60
|
+
</div>
|
|
44
61
|
);
|
|
45
62
|
};
|
|
46
63
|
|
|
@@ -2004,30 +2004,12 @@ function PromQLEditor(props) {
|
|
|
2004
2004
|
enableAutocomplete = _props$enableAutocomp === void 0 ? true : _props$enableAutocomp,
|
|
2005
2005
|
onChange = props.onChange,
|
|
2006
2006
|
onShiftEnter = props.onShiftEnter,
|
|
2007
|
-
onBlur = props.onBlur
|
|
2007
|
+
onBlur = props.onBlur,
|
|
2008
|
+
editorDidMount = props.editorDidMount;
|
|
2008
2009
|
var autocompleteDisposeFun = React.useRef(null);
|
|
2009
2010
|
var containerRef = React.useRef(null);
|
|
2010
2011
|
var dataProviderRef = React.useRef(null);
|
|
2011
2012
|
var styles = getStyles(placeholder);
|
|
2012
|
-
React.useEffect(function () {
|
|
2013
|
-
// 注册 PromQL 语言
|
|
2014
|
-
var aliases = monacoPromql.promLanguageDefinition.aliases,
|
|
2015
|
-
extensions = monacoPromql.promLanguageDefinition.extensions,
|
|
2016
|
-
mimetypes = monacoPromql.promLanguageDefinition.mimetypes;
|
|
2017
|
-
monaco.languages.register({
|
|
2018
|
-
id: PROMQL_LANG_ID,
|
|
2019
|
-
aliases: aliases,
|
|
2020
|
-
extensions: extensions,
|
|
2021
|
-
mimetypes: mimetypes
|
|
2022
|
-
});
|
|
2023
|
-
// 设置语法高亮
|
|
2024
|
-
monaco.languages.setMonarchTokensProvider(PROMQL_LANG_ID, language);
|
|
2025
|
-
// 设置语言配置
|
|
2026
|
-
monaco.languages.setLanguageConfiguration(PROMQL_LANG_ID, languageConfiguration);
|
|
2027
|
-
return function () {
|
|
2028
|
-
autocompleteDisposeFun.current == null || autocompleteDisposeFun.current();
|
|
2029
|
-
};
|
|
2030
|
-
}, []);
|
|
2031
2013
|
var handleEditorDidMount = function handleEditorDidMount(editor) {
|
|
2032
2014
|
monaco.editor.defineTheme('n9e-dark', {
|
|
2033
2015
|
base: 'vs-dark',
|
|
@@ -2136,7 +2118,27 @@ function PromQLEditor(props) {
|
|
|
2136
2118
|
monaco.editor.setModelMarkers(model, 'owner', markers);
|
|
2137
2119
|
}
|
|
2138
2120
|
});
|
|
2121
|
+
editorDidMount == null || editorDidMount(editor);
|
|
2139
2122
|
};
|
|
2123
|
+
React.useEffect(function () {
|
|
2124
|
+
// 注册 PromQL 语言
|
|
2125
|
+
var aliases = monacoPromql.promLanguageDefinition.aliases,
|
|
2126
|
+
extensions = monacoPromql.promLanguageDefinition.extensions,
|
|
2127
|
+
mimetypes = monacoPromql.promLanguageDefinition.mimetypes;
|
|
2128
|
+
monaco.languages.register({
|
|
2129
|
+
id: PROMQL_LANG_ID,
|
|
2130
|
+
aliases: aliases,
|
|
2131
|
+
extensions: extensions,
|
|
2132
|
+
mimetypes: mimetypes
|
|
2133
|
+
});
|
|
2134
|
+
// 设置语法高亮
|
|
2135
|
+
monaco.languages.setMonarchTokensProvider(PROMQL_LANG_ID, language);
|
|
2136
|
+
// 设置语言配置
|
|
2137
|
+
monaco.languages.setLanguageConfiguration(PROMQL_LANG_ID, languageConfiguration);
|
|
2138
|
+
return function () {
|
|
2139
|
+
autocompleteDisposeFun.current == null || autocompleteDisposeFun.current();
|
|
2140
|
+
};
|
|
2141
|
+
}, []);
|
|
2140
2142
|
React.useEffect(function () {
|
|
2141
2143
|
var dataProvider = dataProviderRef.current;
|
|
2142
2144
|
if (dataProvider) {
|