@fc-components/monaco-editor 0.1.1 → 0.1.3
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 +30 -17
- package/dist/monaco-editor.cjs.development.js +45 -29
- 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 +45 -29
- package/dist/monaco-editor.esm.js.map +1 -1
- package/dist/promql/completion/DataProvider.d.ts +1 -0
- package/dist/promql/index.d.ts +2 -0
- package/dist/promql/types.d.ts +1 -0
- package/package.json +4 -1
- package/src/promql/completion/DataProvider.ts +2 -0
- package/src/promql/completion/completions.ts +10 -1
- package/src/promql/index.tsx +29 -25
- package/src/promql/types.ts +1 -0
- package/src/promql/util.ts +1 -1
|
@@ -856,7 +856,7 @@ function makeSelector(metricName, labels, labelName) {
|
|
|
856
856
|
var allLabelTexts = allLabels.map(function (label) {
|
|
857
857
|
return "" + label.name + label.op + "\"" + escapeLabelValueInExactSelector(label.value) + "\"";
|
|
858
858
|
});
|
|
859
|
-
return "{" + allLabelTexts.join(',') + "}";
|
|
859
|
+
return metricName + "{" + allLabelTexts.join(',') + "}";
|
|
860
860
|
}
|
|
861
861
|
|
|
862
862
|
var DEFAULT_SERIES_LIMIT = '40000';
|
|
@@ -866,7 +866,8 @@ var serviceUnavailable = 503;
|
|
|
866
866
|
var CODE_MODE_SUGGESTIONS_INCOMPLETE_EVENT = 'codeModeSuggestionsIncomplete';
|
|
867
867
|
var DataProvider = /*#__PURE__*/function () {
|
|
868
868
|
function DataProvider(params) {
|
|
869
|
-
var _this = this
|
|
869
|
+
var _this = this,
|
|
870
|
+
_params$durationVaria;
|
|
870
871
|
this.lookbackInterval = 60 * 60 * 1000 * 12; // 12 hours
|
|
871
872
|
this.variablesNames = [];
|
|
872
873
|
this.httpMethod = 'GET';
|
|
@@ -1012,6 +1013,7 @@ var DataProvider = /*#__PURE__*/function () {
|
|
|
1012
1013
|
if (params.variablesNames) {
|
|
1013
1014
|
this.variablesNames = [].concat(params.variablesNames);
|
|
1014
1015
|
}
|
|
1016
|
+
this.durationVariablesCompletion = (_params$durationVaria = params.durationVariablesCompletion) != null ? _params$durationVaria : true;
|
|
1015
1017
|
if (params.request) {
|
|
1016
1018
|
this.customRequest = params.request;
|
|
1017
1019
|
}
|
|
@@ -1536,7 +1538,14 @@ function _getAllFunctionsAndMetricNamesCompletions() {
|
|
|
1536
1538
|
}));
|
|
1537
1539
|
return _getAllFunctionsAndMetricNamesCompletions.apply(this, arguments);
|
|
1538
1540
|
}
|
|
1539
|
-
var DURATION_COMPLETIONS = /*#__PURE__*/['
|
|
1541
|
+
var DURATION_COMPLETIONS = /*#__PURE__*/['1m', '5m', '10m', '30m', '1h', '1d'].map(function (text) {
|
|
1542
|
+
return {
|
|
1543
|
+
type: 'DURATION',
|
|
1544
|
+
label: text,
|
|
1545
|
+
insertText: text
|
|
1546
|
+
};
|
|
1547
|
+
});
|
|
1548
|
+
var DURATION_VARIABLES_COMPLETIONS = /*#__PURE__*/['$__interval', '$__range', '$__rate_interval'].map(function (text) {
|
|
1540
1549
|
return {
|
|
1541
1550
|
type: 'DURATION',
|
|
1542
1551
|
label: text,
|
|
@@ -1764,6 +1773,9 @@ function _getLabelValuesForMetricCompletions() {
|
|
|
1764
1773
|
function getCompletions(situation, dataProvider) {
|
|
1765
1774
|
switch (situation.type) {
|
|
1766
1775
|
case 'IN_DURATION':
|
|
1776
|
+
if (dataProvider.durationVariablesCompletion) {
|
|
1777
|
+
return Promise.resolve(DURATION_VARIABLES_COMPLETIONS.concat(DURATION_COMPLETIONS));
|
|
1778
|
+
}
|
|
1767
1779
|
return Promise.resolve(DURATION_COMPLETIONS);
|
|
1768
1780
|
case 'IN_FUNCTION':
|
|
1769
1781
|
return getAllFunctionsAndMetricNamesCompletions(dataProvider);
|
|
@@ -1983,6 +1995,8 @@ function PromQLEditor(props) {
|
|
|
1983
1995
|
value = props.value,
|
|
1984
1996
|
placeholder = props.placeholder,
|
|
1985
1997
|
interpolateString = props.interpolateString,
|
|
1998
|
+
_props$enableAutocomp = props.enableAutocomplete,
|
|
1999
|
+
enableAutocomplete = _props$enableAutocomp === void 0 ? true : _props$enableAutocomp,
|
|
1986
2000
|
onChange = props.onChange,
|
|
1987
2001
|
onShiftEnter = props.onShiftEnter,
|
|
1988
2002
|
onBlur = props.onBlur;
|
|
@@ -2019,32 +2033,35 @@ function PromQLEditor(props) {
|
|
|
2019
2033
|
editor$1.onDidFocusEditorText(function () {
|
|
2020
2034
|
isEditorFocused.set(true);
|
|
2021
2035
|
});
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2036
|
+
if (enableAutocomplete) {
|
|
2037
|
+
var dataProvider = new DataProvider({
|
|
2038
|
+
url: props.url,
|
|
2039
|
+
lookbackInterval: props.lookbackInterval,
|
|
2040
|
+
variablesNames: props.variablesNames,
|
|
2041
|
+
durationVariablesCompletion: props.durationVariablesCompletion,
|
|
2042
|
+
request: props.request,
|
|
2043
|
+
httpMethod: props.httpMethod,
|
|
2044
|
+
apiPrefix: props.apiPrefix,
|
|
2045
|
+
httpErrorHandler: props.httpErrorHandler
|
|
2046
|
+
});
|
|
2047
|
+
dataProviderRef.current = dataProvider;
|
|
2048
|
+
dataProvider.start();
|
|
2049
|
+
var completionProvider = getCompletionProvider(monaco, dataProvider);
|
|
2050
|
+
var filteringCompletionProvider = _extends({}, completionProvider, {
|
|
2051
|
+
provideCompletionItems: function provideCompletionItems(model, position, context, token) {
|
|
2052
|
+
var _editor$getModel;
|
|
2053
|
+
if (((_editor$getModel = editor$1.getModel()) == null ? void 0 : _editor$getModel.id) !== model.id) {
|
|
2054
|
+
return {
|
|
2055
|
+
suggestions: []
|
|
2056
|
+
};
|
|
2057
|
+
}
|
|
2058
|
+
return completionProvider.provideCompletionItems(model, position, context, token);
|
|
2041
2059
|
}
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
autocompleteDisposeFun.current = dispose;
|
|
2060
|
+
});
|
|
2061
|
+
var _monaco$languages$reg = languages.registerCompletionItemProvider(PROMQL_LANG_ID, filteringCompletionProvider),
|
|
2062
|
+
dispose = _monaco$languages$reg.dispose;
|
|
2063
|
+
autocompleteDisposeFun.current = dispose;
|
|
2064
|
+
}
|
|
2048
2065
|
var updateElementHeight = function updateElementHeight() {
|
|
2049
2066
|
var containerDiv = containerRef.current;
|
|
2050
2067
|
if (containerDiv !== null) {
|
|
@@ -2067,7 +2084,6 @@ function PromQLEditor(props) {
|
|
|
2067
2084
|
});
|
|
2068
2085
|
// handle: shift + enter
|
|
2069
2086
|
editor$1.addCommand(KeyMod.Shift | KeyCode.Enter, function () {
|
|
2070
|
-
console.log(22222);
|
|
2071
2087
|
onShiftEnter == null || onShiftEnter(editor$1.getValue());
|
|
2072
2088
|
}, 'isEditorFocused' + id);
|
|
2073
2089
|
if (placeholder) {
|