@fc-components/monaco-editor 0.1.26 → 0.1.27
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/dist/monaco-editor.cjs.development.js +22 -18
- 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 -18
- package/dist/monaco-editor.esm.js.map +1 -1
- package/dist/promql/completion/situation.d.ts +1 -0
- package/dist/promql/index.d.ts +0 -1
- package/package.json +1 -1
- package/src/promql/completion/getCompletionProvider.ts +15 -1
- package/src/promql/completion/situation.ts +8 -0
- package/src/promql/index.tsx +0 -18
package/dist/promql/index.d.ts
CHANGED
|
@@ -17,7 +17,6 @@ interface PromQLEditorProps {
|
|
|
17
17
|
onEnter?: (value: string) => void;
|
|
18
18
|
onBlur?: (value: string) => void;
|
|
19
19
|
editorDidMount?: (editor: monacoTypes.editor.IStandaloneCodeEditor) => void;
|
|
20
|
-
debugEscKey?: boolean;
|
|
21
20
|
}
|
|
22
21
|
export default function PromQLEditor(props: PromQLEditorProps & DataProviderParams): React.JSX.Element;
|
|
23
22
|
export {};
|
package/package.json
CHANGED
|
@@ -70,6 +70,20 @@ export function getCompletionProvider(monaco: Monaco, dataProvider: DataProvider
|
|
|
70
70
|
// to stop it, we use a number-as-string sortkey,
|
|
71
71
|
// so that monaco keeps the order we use
|
|
72
72
|
const maxIndexDigits = items.length.toString().length;
|
|
73
|
+
|
|
74
|
+
// Determine the completion range based on situation type
|
|
75
|
+
let completionRange = range;
|
|
76
|
+
if (situation && situation.type === 'IN_LABEL_SELECTOR_WITH_LABEL_NAME' && situation.betweenQuotes) {
|
|
77
|
+
// For label values within quotes, replace from the start of the value to the current position
|
|
78
|
+
const valueStartPosition = model.getPositionAt(situation.valueStartPos);
|
|
79
|
+
completionRange = monaco.Range.lift({
|
|
80
|
+
startLineNumber: valueStartPosition.lineNumber,
|
|
81
|
+
endLineNumber: position.lineNumber,
|
|
82
|
+
startColumn: valueStartPosition.column,
|
|
83
|
+
endColumn: position.column,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
73
87
|
const suggestions: monacoTypes.languages.CompletionItem[] = items.map((item, index) => ({
|
|
74
88
|
kind: getMonacoCompletionItemKind(item.type, monaco),
|
|
75
89
|
label: item.label,
|
|
@@ -77,7 +91,7 @@ export function getCompletionProvider(monaco: Monaco, dataProvider: DataProvider
|
|
|
77
91
|
detail: item.detail,
|
|
78
92
|
documentation: item.documentation,
|
|
79
93
|
sortText: index.toString().padStart(maxIndexDigits, '0'), // to force the order we have
|
|
80
|
-
range,
|
|
94
|
+
range: completionRange,
|
|
81
95
|
command: item.triggerOnInsert
|
|
82
96
|
? {
|
|
83
97
|
id: 'editor.action.triggerSuggest',
|
|
@@ -145,6 +145,7 @@ export type Situation =
|
|
|
145
145
|
labelName: string;
|
|
146
146
|
betweenQuotes: boolean;
|
|
147
147
|
otherLabels: Label[];
|
|
148
|
+
valueStartPos: number;
|
|
148
149
|
};
|
|
149
150
|
|
|
150
151
|
type Resolver = {
|
|
@@ -335,6 +336,11 @@ function resolveLabelMatcher(node: SyntaxNode, text: string, _pos: number): Situ
|
|
|
335
336
|
// - or an error node (like in `{job=^}`)
|
|
336
337
|
const inStringNode = !node.type.isError;
|
|
337
338
|
|
|
339
|
+
// calculate where the value starts
|
|
340
|
+
// for string nodes, it's after the opening quote
|
|
341
|
+
// for error nodes, it's at the node start
|
|
342
|
+
const valueStartPos = inStringNode ? node.from + 1 : node.from;
|
|
343
|
+
|
|
338
344
|
const parent = walk(node, [['parent', UnquotedLabelMatcher]]);
|
|
339
345
|
if (parent === null) {
|
|
340
346
|
return null;
|
|
@@ -370,6 +376,7 @@ function resolveLabelMatcher(node: SyntaxNode, text: string, _pos: number): Situ
|
|
|
370
376
|
labelName,
|
|
371
377
|
betweenQuotes: inStringNode,
|
|
372
378
|
otherLabels,
|
|
379
|
+
valueStartPos,
|
|
373
380
|
};
|
|
374
381
|
}
|
|
375
382
|
|
|
@@ -381,6 +388,7 @@ function resolveLabelMatcher(node: SyntaxNode, text: string, _pos: number): Situ
|
|
|
381
388
|
labelName,
|
|
382
389
|
betweenQuotes: inStringNode,
|
|
383
390
|
otherLabels,
|
|
391
|
+
valueStartPos,
|
|
384
392
|
};
|
|
385
393
|
}
|
|
386
394
|
|
package/src/promql/index.tsx
CHANGED
|
@@ -30,7 +30,6 @@ interface PromQLEditorProps {
|
|
|
30
30
|
onEnter?: (value: string) => void;
|
|
31
31
|
onBlur?: (value: string) => void;
|
|
32
32
|
editorDidMount?: (editor: monacoTypes.editor.IStandaloneCodeEditor) => void;
|
|
33
|
-
debugEscKey?: boolean;
|
|
34
33
|
}
|
|
35
34
|
|
|
36
35
|
const PROMQL_LANG_ID = promLanguageDefinition.id;
|
|
@@ -104,7 +103,6 @@ export default function PromQLEditor(props: PromQLEditorProps & DataProviderPara
|
|
|
104
103
|
onEnter,
|
|
105
104
|
onBlur,
|
|
106
105
|
editorDidMount,
|
|
107
|
-
debugEscKey = false,
|
|
108
106
|
} = props;
|
|
109
107
|
const autocompleteDisposeFun = useRef<(() => void) | null>(null);
|
|
110
108
|
const containerRef = useRef<HTMLDivElement>(null);
|
|
@@ -213,22 +211,6 @@ export default function PromQLEditor(props: PromQLEditorProps & DataProviderPara
|
|
|
213
211
|
'!suggestWidgetVisible && isEditorFocused' + id,
|
|
214
212
|
);
|
|
215
213
|
|
|
216
|
-
editor.addCommand(
|
|
217
|
-
monaco.KeyCode.Escape,
|
|
218
|
-
() => {
|
|
219
|
-
if (debugEscKey) {
|
|
220
|
-
const suggestWidgetVisible = (editor as any)?._contextKeyService?.getContextKeyValue?.('suggestWidgetVisible');
|
|
221
|
-
// eslint-disable-next-line no-console
|
|
222
|
-
console.log('[PromQLEditor][ESC]', {
|
|
223
|
-
suggestWidgetVisible,
|
|
224
|
-
valueLength: editor.getValue().length,
|
|
225
|
-
});
|
|
226
|
-
}
|
|
227
|
-
editor.trigger('keyboard', 'hideSuggestWidget', {});
|
|
228
|
-
},
|
|
229
|
-
'suggestWidgetVisible && isEditorFocused' + id,
|
|
230
|
-
);
|
|
231
|
-
|
|
232
214
|
// Initialize previous content tracking
|
|
233
215
|
previousContentRef.current = editor.getValue();
|
|
234
216
|
lastDeletionTriggerTimeRef.current = 0;
|