@fc-components/monaco-editor 0.1.9 → 0.1.10

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.
@@ -8,6 +8,7 @@ interface PromQLEditorProps {
8
8
  placeholder?: string;
9
9
  enableAutocomplete?: boolean;
10
10
  durationVariablesCompletion?: boolean;
11
+ readOnly?: boolean;
11
12
  interpolateString?: (query: string) => string;
12
13
  onChange?: (value: string) => void;
13
14
  onShiftEnter?: (value: string) => void;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.1.9",
6
+ "version": "0.1.10",
7
7
  "license": "MIT",
8
8
  "main": "dist/index.js",
9
9
  "module": "dist/monaco-editor.esm.js",
@@ -20,6 +20,7 @@ interface PromQLEditorProps {
20
20
  placeholder?: string;
21
21
  enableAutocomplete?: boolean;
22
22
  durationVariablesCompletion?: boolean;
23
+ readOnly?: boolean;
23
24
  interpolateString?: (query: string) => string;
24
25
  onChange?: (value: string) => void;
25
26
  onShiftEnter?: (value: string) => void;
@@ -70,7 +71,19 @@ const getStyles = (placeholder?: string) => {
70
71
 
71
72
  export default function PromQLEditor(props: PromQLEditorProps & DataProviderParams) {
72
73
  const id = uuidv4();
73
- const { size = 'middle', theme = 'light', value, placeholder, interpolateString, enableAutocomplete = true, onChange, onShiftEnter, onBlur, editorDidMount } = props;
74
+ const {
75
+ size = 'middle',
76
+ theme = 'light',
77
+ value,
78
+ placeholder,
79
+ interpolateString,
80
+ enableAutocomplete = true,
81
+ readOnly = false,
82
+ onChange,
83
+ onShiftEnter,
84
+ onBlur,
85
+ editorDidMount,
86
+ } = props;
74
87
  const autocompleteDisposeFun = useRef<(() => void) | null>(null);
75
88
  const containerRef = useRef<HTMLDivElement>(null);
76
89
  const dataProviderRef = useRef<DataProvider | null>(null);
@@ -94,7 +107,14 @@ export default function PromQLEditor(props: PromQLEditorProps & DataProviderPara
94
107
  editor.onDidBlurEditorWidget(() => {
95
108
  isEditorFocused.set(false);
96
109
  onBlur?.(editor.getValue());
110
+ // reset the selection to the current position
111
+ const position = editor.getPosition();
112
+ if (position) {
113
+ const newSelection = new monaco.Selection(position.lineNumber, position.column, position.lineNumber, position.column);
114
+ editor.setSelection(newSelection);
115
+ }
97
116
  });
117
+
98
118
  editor.onDidFocusEditorText(() => {
99
119
  isEditorFocused.set(true);
100
120
  });
@@ -270,6 +290,7 @@ export default function PromQLEditor(props: PromQLEditorProps & DataProviderPara
270
290
  onChange={onChange}
271
291
  editorDidMount={handleEditorDidMount}
272
292
  options={{
293
+ readOnly,
273
294
  codeLens: false,
274
295
  contextmenu: false,
275
296
  fixedOverflowWidgets: true,
@@ -299,6 +320,7 @@ export default function PromQLEditor(props: PromQLEditorProps & DataProviderPara
299
320
  suggestFontSize: 12,
300
321
  wordWrap: 'on',
301
322
  automaticLayout: true,
323
+ occurrencesHighlight: 'off', // Disable word highlighting
302
324
  }}
303
325
  />
304
326
  </div>