@fc-components/monaco-editor 0.1.2 → 0.1.4
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 +14 -5
- package/dist/monaco-editor.cjs.development.js +38 -17
- 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 +38 -17
- package/dist/monaco-editor.esm.js.map +1 -1
- package/dist/promql/completion/DataProvider.d.ts +1 -0
- package/dist/promql/index.d.ts +1 -0
- package/dist/promql/types.d.ts +1 -0
- package/package.json +1 -1
- package/src/promql/completion/DataProvider.ts +2 -0
- package/src/promql/completion/completions.ts +10 -1
- package/src/promql/index.tsx +27 -16
- package/src/promql/types.ts +1 -0
|
@@ -13,6 +13,7 @@ export declare class DataProvider {
|
|
|
13
13
|
metrics: string[];
|
|
14
14
|
labelKeys: string[];
|
|
15
15
|
metricsMetadata?: PromMetricsMetadata;
|
|
16
|
+
durationVariablesCompletion: boolean;
|
|
16
17
|
constructor(params: DataProviderParams);
|
|
17
18
|
getVariablesNames(): string[];
|
|
18
19
|
setVariablesNames(variablesNames: string[]): void;
|
package/dist/promql/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ interface PromQLEditorProps {
|
|
|
6
6
|
value?: string;
|
|
7
7
|
placeholder?: string;
|
|
8
8
|
enableAutocomplete?: boolean;
|
|
9
|
+
durationVariablesCompletion?: boolean;
|
|
9
10
|
interpolateString?: (query: string) => string;
|
|
10
11
|
onChange?: (value: string) => void;
|
|
11
12
|
onShiftEnter?: (value: string) => void;
|
package/dist/promql/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -30,6 +30,7 @@ export class DataProvider {
|
|
|
30
30
|
metrics: string[];
|
|
31
31
|
labelKeys: string[];
|
|
32
32
|
metricsMetadata?: PromMetricsMetadata;
|
|
33
|
+
durationVariablesCompletion: boolean;
|
|
33
34
|
|
|
34
35
|
constructor(params: DataProviderParams) {
|
|
35
36
|
this.inputInRange = '';
|
|
@@ -44,6 +45,7 @@ export class DataProvider {
|
|
|
44
45
|
if (params.variablesNames) {
|
|
45
46
|
this.variablesNames = [...params.variablesNames];
|
|
46
47
|
}
|
|
48
|
+
this.durationVariablesCompletion = params.durationVariablesCompletion ?? true;
|
|
47
49
|
if (params.request) {
|
|
48
50
|
this.customRequest = params.request;
|
|
49
51
|
}
|
|
@@ -61,7 +61,13 @@ async function getAllFunctionsAndMetricNamesCompletions(dataProvider: DataProvid
|
|
|
61
61
|
return [...FUNCTION_COMPLETIONS, ...metricNames];
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
const DURATION_COMPLETIONS: Completion[] = ['
|
|
64
|
+
const DURATION_COMPLETIONS: Completion[] = ['1m', '5m', '10m', '30m', '1h', '1d'].map((text) => ({
|
|
65
|
+
type: 'DURATION',
|
|
66
|
+
label: text,
|
|
67
|
+
insertText: text,
|
|
68
|
+
}));
|
|
69
|
+
|
|
70
|
+
const DURATION_VARIABLES_COMPLETIONS: Completion[] = ['$__interval', '$__range', '$__rate_interval'].map((text) => ({
|
|
65
71
|
type: 'DURATION',
|
|
66
72
|
label: text,
|
|
67
73
|
insertText: text,
|
|
@@ -165,6 +171,9 @@ async function getLabelValuesForMetricCompletions(
|
|
|
165
171
|
export function getCompletions(situation: Situation, dataProvider: DataProvider): Promise<Completion[]> {
|
|
166
172
|
switch (situation.type) {
|
|
167
173
|
case 'IN_DURATION':
|
|
174
|
+
if (dataProvider.durationVariablesCompletion) {
|
|
175
|
+
return Promise.resolve(DURATION_VARIABLES_COMPLETIONS.concat(DURATION_COMPLETIONS));
|
|
176
|
+
}
|
|
168
177
|
return Promise.resolve(DURATION_COMPLETIONS);
|
|
169
178
|
case 'IN_FUNCTION':
|
|
170
179
|
return getAllFunctionsAndMetricNamesCompletions(dataProvider);
|
package/src/promql/index.tsx
CHANGED
|
@@ -19,6 +19,7 @@ interface PromQLEditorProps {
|
|
|
19
19
|
value?: string;
|
|
20
20
|
placeholder?: string;
|
|
21
21
|
enableAutocomplete?: boolean;
|
|
22
|
+
durationVariablesCompletion?: boolean;
|
|
22
23
|
interpolateString?: (query: string) => string;
|
|
23
24
|
onChange?: (value: string) => void;
|
|
24
25
|
onShiftEnter?: (value: string) => void;
|
|
@@ -26,7 +27,6 @@ interface PromQLEditorProps {
|
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
const PROMQL_LANG_ID = promLanguageDefinition.id;
|
|
29
|
-
const EDITOR_HEIGHT_OFFSET = 2;
|
|
30
30
|
const SIZE_MAP: Record<
|
|
31
31
|
string,
|
|
32
32
|
{
|
|
@@ -52,8 +52,8 @@ const SIZE_MAP: Record<
|
|
|
52
52
|
},
|
|
53
53
|
};
|
|
54
54
|
const themeMap: Record<string, string> = {
|
|
55
|
-
light: '
|
|
56
|
-
dark: '
|
|
55
|
+
light: 'light',
|
|
56
|
+
dark: 'n9e-dark',
|
|
57
57
|
};
|
|
58
58
|
|
|
59
59
|
const getStyles = (placeholder?: string) => {
|
|
@@ -97,6 +97,16 @@ export default function PromQLEditor(props: PromQLEditorProps & DataProviderPara
|
|
|
97
97
|
}, []);
|
|
98
98
|
|
|
99
99
|
const handleEditorDidMount = (editor: monacoTypes.editor.IStandaloneCodeEditor) => {
|
|
100
|
+
monaco.editor.defineTheme('n9e-dark', {
|
|
101
|
+
base: 'vs-dark',
|
|
102
|
+
inherit: true,
|
|
103
|
+
rules: [],
|
|
104
|
+
colors: {
|
|
105
|
+
'editor.background': '#00000000',
|
|
106
|
+
focusBorder: '#00000000',
|
|
107
|
+
},
|
|
108
|
+
});
|
|
109
|
+
|
|
100
110
|
const isEditorFocused = editor.createContextKey<boolean>('isEditorFocused' + id, false);
|
|
101
111
|
// we setup on-blur
|
|
102
112
|
editor.onDidBlurEditorWidget(() => {
|
|
@@ -107,19 +117,20 @@ export default function PromQLEditor(props: PromQLEditorProps & DataProviderPara
|
|
|
107
117
|
isEditorFocused.set(true);
|
|
108
118
|
});
|
|
109
119
|
|
|
110
|
-
const dataProvider = new DataProvider({
|
|
111
|
-
url: props.url,
|
|
112
|
-
lookbackInterval: props.lookbackInterval,
|
|
113
|
-
variablesNames: props.variablesNames,
|
|
114
|
-
request: props.request,
|
|
115
|
-
httpMethod: props.httpMethod,
|
|
116
|
-
apiPrefix: props.apiPrefix,
|
|
117
|
-
httpErrorHandler: props.httpErrorHandler,
|
|
118
|
-
});
|
|
119
|
-
dataProviderRef.current = dataProvider;
|
|
120
|
-
dataProvider.start();
|
|
121
|
-
|
|
122
120
|
if (enableAutocomplete) {
|
|
121
|
+
const dataProvider = new DataProvider({
|
|
122
|
+
url: props.url,
|
|
123
|
+
lookbackInterval: props.lookbackInterval,
|
|
124
|
+
variablesNames: props.variablesNames,
|
|
125
|
+
durationVariablesCompletion: props.durationVariablesCompletion,
|
|
126
|
+
request: props.request,
|
|
127
|
+
httpMethod: props.httpMethod,
|
|
128
|
+
apiPrefix: props.apiPrefix,
|
|
129
|
+
httpErrorHandler: props.httpErrorHandler,
|
|
130
|
+
});
|
|
131
|
+
dataProviderRef.current = dataProvider;
|
|
132
|
+
dataProvider.start();
|
|
133
|
+
|
|
123
134
|
const completionProvider = getCompletionProvider(monaco, dataProvider);
|
|
124
135
|
|
|
125
136
|
const filteringCompletionProvider: monacoTypes.languages.CompletionItemProvider = {
|
|
@@ -141,7 +152,7 @@ export default function PromQLEditor(props: PromQLEditorProps & DataProviderPara
|
|
|
141
152
|
const containerDiv = containerRef.current;
|
|
142
153
|
if (containerDiv !== null) {
|
|
143
154
|
const pixelHeight = editor.getContentHeight();
|
|
144
|
-
containerDiv.style.height = `${pixelHeight
|
|
155
|
+
containerDiv.style.height = `${pixelHeight}px`;
|
|
145
156
|
containerDiv.style.width = '100%';
|
|
146
157
|
const pixelWidth = containerDiv.clientWidth;
|
|
147
158
|
editor.layout({ width: pixelWidth, height: pixelHeight });
|
package/src/promql/types.ts
CHANGED