@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/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
|
|
|
@@ -1990,7 +1990,7 @@ var getStyles = function getStyles(placeholder) {
|
|
|
1990
1990
|
})
|
|
1991
1991
|
};
|
|
1992
1992
|
};
|
|
1993
|
-
function PromQLEditor(props) {
|
|
1993
|
+
var index = /*#__PURE__*/React.forwardRef(function PromQLEditor(props, ref) {
|
|
1994
1994
|
var id = uuid.v4();
|
|
1995
1995
|
var _props$size = props.size,
|
|
1996
1996
|
size = _props$size === void 0 ? 'middle' : _props$size,
|
|
@@ -2008,27 +2008,10 @@ function PromQLEditor(props) {
|
|
|
2008
2008
|
var autocompleteDisposeFun = React.useRef(null);
|
|
2009
2009
|
var containerRef = React.useRef(null);
|
|
2010
2010
|
var dataProviderRef = React.useRef(null);
|
|
2011
|
+
var editorRef = 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) {
|
|
2014
|
+
editorRef.current = editor;
|
|
2032
2015
|
monaco.editor.defineTheme('n9e-dark', {
|
|
2033
2016
|
base: 'vs-dark',
|
|
2034
2017
|
inherit: true,
|
|
@@ -2143,6 +2126,32 @@ function PromQLEditor(props) {
|
|
|
2143
2126
|
dataProvider.setVariablesNames(variablesNames || []);
|
|
2144
2127
|
}
|
|
2145
2128
|
}, [JSON.stringify(variablesNames)]);
|
|
2129
|
+
React.useEffect(function () {
|
|
2130
|
+
// 注册 PromQL 语言
|
|
2131
|
+
var aliases = monacoPromql.promLanguageDefinition.aliases,
|
|
2132
|
+
extensions = monacoPromql.promLanguageDefinition.extensions,
|
|
2133
|
+
mimetypes = monacoPromql.promLanguageDefinition.mimetypes;
|
|
2134
|
+
monaco.languages.register({
|
|
2135
|
+
id: PROMQL_LANG_ID,
|
|
2136
|
+
aliases: aliases,
|
|
2137
|
+
extensions: extensions,
|
|
2138
|
+
mimetypes: mimetypes
|
|
2139
|
+
});
|
|
2140
|
+
// 设置语法高亮
|
|
2141
|
+
monaco.languages.setMonarchTokensProvider(PROMQL_LANG_ID, language);
|
|
2142
|
+
// 设置语言配置
|
|
2143
|
+
monaco.languages.setLanguageConfiguration(PROMQL_LANG_ID, languageConfiguration);
|
|
2144
|
+
return function () {
|
|
2145
|
+
autocompleteDisposeFun.current == null || autocompleteDisposeFun.current();
|
|
2146
|
+
};
|
|
2147
|
+
}, []);
|
|
2148
|
+
React.useImperativeHandle(ref, function () {
|
|
2149
|
+
return {
|
|
2150
|
+
getEditor: function getEditor() {
|
|
2151
|
+
return editorRef.current;
|
|
2152
|
+
}
|
|
2153
|
+
};
|
|
2154
|
+
});
|
|
2146
2155
|
return React__default.createElement("div", {
|
|
2147
2156
|
className: 'ant-input' + (size ? " " + SIZE_MAP[size].className : '')
|
|
2148
2157
|
}, React__default.createElement("div", {
|
|
@@ -2188,7 +2197,7 @@ function PromQLEditor(props) {
|
|
|
2188
2197
|
wordWrap: 'on'
|
|
2189
2198
|
}
|
|
2190
2199
|
})));
|
|
2191
|
-
}
|
|
2200
|
+
});
|
|
2192
2201
|
|
|
2193
|
-
exports.PromQLMonacoEditor =
|
|
2202
|
+
exports.PromQLMonacoEditor = index;
|
|
2194
2203
|
//# sourceMappingURL=monaco-editor.cjs.development.js.map
|