@fc-components/monaco-editor 0.1.1 → 0.1.2

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.
@@ -5,6 +5,7 @@ interface PromQLEditorProps {
5
5
  theme?: 'light' | 'dark';
6
6
  value?: string;
7
7
  placeholder?: string;
8
+ enableAutocomplete?: boolean;
8
9
  interpolateString?: (query: string) => string;
9
10
  onChange?: (value: string) => void;
10
11
  onShiftEnter?: (value: string) => void;
package/package.json CHANGED
@@ -1,6 +1,9 @@
1
1
  {
2
2
  "name": "@fc-components/monaco-editor",
3
- "version": "0.1.1",
3
+ "publishConfig": {
4
+ "access": "public"
5
+ },
6
+ "version": "0.1.2",
4
7
  "license": "MIT",
5
8
  "main": "dist/index.js",
6
9
  "module": "dist/monaco-editor.esm.js",
@@ -18,6 +18,7 @@ interface PromQLEditorProps {
18
18
  theme?: 'light' | 'dark';
19
19
  value?: string;
20
20
  placeholder?: string;
21
+ enableAutocomplete?: boolean;
21
22
  interpolateString?: (query: string) => string;
22
23
  onChange?: (value: string) => void;
23
24
  onShiftEnter?: (value: string) => void;
@@ -68,7 +69,7 @@ const getStyles = (placeholder?: string) => {
68
69
 
69
70
  export default function PromQLEditor(props: PromQLEditorProps & DataProviderParams) {
70
71
  const id = uuidv4();
71
- const { size = 'middle', theme = 'light', variablesNames, value, placeholder, interpolateString, onChange, onShiftEnter, onBlur } = props;
72
+ const { size = 'middle', theme = 'light', variablesNames, value, placeholder, interpolateString, enableAutocomplete = true, onChange, onShiftEnter, onBlur } = props;
72
73
  const autocompleteDisposeFun = useRef<(() => void) | null>(null);
73
74
  const containerRef = useRef<HTMLDivElement>(null);
74
75
  const dataProviderRef = useRef<DataProvider | null>(null);
@@ -118,21 +119,23 @@ export default function PromQLEditor(props: PromQLEditorProps & DataProviderPara
118
119
  dataProviderRef.current = dataProvider;
119
120
  dataProvider.start();
120
121
 
121
- const completionProvider = getCompletionProvider(monaco, dataProvider);
122
+ if (enableAutocomplete) {
123
+ const completionProvider = getCompletionProvider(monaco, dataProvider);
122
124
 
123
- const filteringCompletionProvider: monacoTypes.languages.CompletionItemProvider = {
124
- ...completionProvider,
125
- provideCompletionItems: (model, position, context, token) => {
126
- if (editor.getModel()?.id !== model.id) {
127
- return { suggestions: [] };
128
- }
129
- return completionProvider.provideCompletionItems(model, position, context, token);
130
- },
131
- };
125
+ const filteringCompletionProvider: monacoTypes.languages.CompletionItemProvider = {
126
+ ...completionProvider,
127
+ provideCompletionItems: (model, position, context, token) => {
128
+ if (editor.getModel()?.id !== model.id) {
129
+ return { suggestions: [] };
130
+ }
131
+ return completionProvider.provideCompletionItems(model, position, context, token);
132
+ },
133
+ };
132
134
 
133
- const { dispose } = monaco.languages.registerCompletionItemProvider(PROMQL_LANG_ID, filteringCompletionProvider);
135
+ const { dispose } = monaco.languages.registerCompletionItemProvider(PROMQL_LANG_ID, filteringCompletionProvider);
134
136
 
135
- autocompleteDisposeFun.current = dispose;
137
+ autocompleteDisposeFun.current = dispose;
138
+ }
136
139
 
137
140
  const updateElementHeight = () => {
138
141
  const containerDiv = containerRef.current;
@@ -158,7 +161,6 @@ export default function PromQLEditor(props: PromQLEditorProps & DataProviderPara
158
161
  editor.addCommand(
159
162
  monaco.KeyMod.Shift | monaco.KeyCode.Enter,
160
163
  () => {
161
- console.log(22222);
162
164
  onShiftEnter?.(editor.getValue());
163
165
  },
164
166
  'isEditorFocused' + id,
@@ -25,5 +25,5 @@ export function makeSelector(metricName: string, labels?: Label[], labelName?: s
25
25
  return `${label.name}${label.op}"${escapeLabelValueInExactSelector(label.value)}"`;
26
26
  });
27
27
 
28
- return `{${allLabelTexts.join(',')}}`;
28
+ return `${metricName}{${allLabelTexts.join(',')}}`;
29
29
  }