@fc-components/monaco-editor 0.1.9 → 0.1.11

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,8 @@ interface PromQLEditorProps {
8
8
  placeholder?: string;
9
9
  enableAutocomplete?: boolean;
10
10
  durationVariablesCompletion?: boolean;
11
+ readOnly?: boolean;
12
+ disabled?: boolean;
11
13
  interpolateString?: (query: string) => string;
12
14
  onChange?: (value: string) => void;
13
15
  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.11",
7
7
  "license": "MIT",
8
8
  "main": "dist/index.js",
9
9
  "module": "dist/monaco-editor.esm.js",
@@ -20,6 +20,8 @@ interface PromQLEditorProps {
20
20
  placeholder?: string;
21
21
  enableAutocomplete?: boolean;
22
22
  durationVariablesCompletion?: boolean;
23
+ readOnly?: boolean;
24
+ disabled?: boolean;
23
25
  interpolateString?: (query: string) => string;
24
26
  onChange?: (value: string) => void;
25
27
  onShiftEnter?: (value: string) => void;
@@ -53,10 +55,23 @@ const SIZE_MAP: Record<
53
55
  },
54
56
  };
55
57
  const themeMap: Record<string, string> = {
56
- light: 'light',
58
+ light: 'n9e-light',
57
59
  dark: 'n9e-dark',
58
60
  };
59
61
 
62
+ const containerDisabledClassName = css`
63
+ .monaco-editor {
64
+ user-select: none;
65
+ pointer-events: none;
66
+ }
67
+ `;
68
+
69
+ const containerReadOnlyClassName = css`
70
+ .monaco-editor .cursors-layer > .cursor {
71
+ opacity: 0 !important; /* 完全透明 */
72
+ }
73
+ `;
74
+
60
75
  const getStyles = (placeholder?: string) => {
61
76
  return {
62
77
  placeholder: css({
@@ -70,7 +85,20 @@ const getStyles = (placeholder?: string) => {
70
85
 
71
86
  export default function PromQLEditor(props: PromQLEditorProps & DataProviderParams) {
72
87
  const id = uuidv4();
73
- const { size = 'middle', theme = 'light', value, placeholder, interpolateString, enableAutocomplete = true, onChange, onShiftEnter, onBlur, editorDidMount } = props;
88
+ const {
89
+ size = 'middle',
90
+ theme = 'light',
91
+ value,
92
+ placeholder,
93
+ interpolateString,
94
+ enableAutocomplete = true,
95
+ readOnly = false,
96
+ disabled = false,
97
+ onChange,
98
+ onShiftEnter,
99
+ onBlur,
100
+ editorDidMount,
101
+ } = props;
74
102
  const autocompleteDisposeFun = useRef<(() => void) | null>(null);
75
103
  const containerRef = useRef<HTMLDivElement>(null);
76
104
  const dataProviderRef = useRef<DataProvider | null>(null);
@@ -79,6 +107,16 @@ export default function PromQLEditor(props: PromQLEditorProps & DataProviderPara
79
107
  const handleEditorDidMount = (editor: monacoTypes.editor.IStandaloneCodeEditor) => {
80
108
  editorRef.current = editor;
81
109
 
110
+ monaco.editor.defineTheme('n9e-light', {
111
+ base: 'vs',
112
+ inherit: true,
113
+ rules: [],
114
+ colors: {
115
+ 'editor.background': '#00000000',
116
+ focusBorder: '#00000000',
117
+ },
118
+ });
119
+
82
120
  monaco.editor.defineTheme('n9e-dark', {
83
121
  base: 'vs-dark',
84
122
  inherit: true,
@@ -94,7 +132,14 @@ export default function PromQLEditor(props: PromQLEditorProps & DataProviderPara
94
132
  editor.onDidBlurEditorWidget(() => {
95
133
  isEditorFocused.set(false);
96
134
  onBlur?.(editor.getValue());
135
+ // reset the selection to the current position
136
+ const position = editor.getPosition();
137
+ if (position) {
138
+ const newSelection = new monaco.Selection(position.lineNumber, position.column, position.lineNumber, position.column);
139
+ editor.setSelection(newSelection);
140
+ }
97
141
  });
142
+
98
143
  editor.onDidFocusEditorText(() => {
99
144
  isEditorFocused.set(true);
100
145
  });
@@ -259,7 +304,14 @@ export default function PromQLEditor(props: PromQLEditorProps & DataProviderPara
259
304
  ]);
260
305
 
261
306
  return (
262
- <div className={'ant-input' + (size ? ` ${SIZE_MAP[size].className}` : '')}>
307
+ <div
308
+ className={
309
+ 'ant-input' +
310
+ (size ? ` ${SIZE_MAP[size].className}` : '') +
311
+ (disabled ? ` ant-input-disabled ${containerDisabledClassName}` : '') +
312
+ (readOnly ? ` ${containerReadOnlyClassName}` : '')
313
+ }
314
+ >
263
315
  <div ref={containerRef}>
264
316
  <MonacoEditor
265
317
  width='100%'
@@ -270,6 +322,7 @@ export default function PromQLEditor(props: PromQLEditorProps & DataProviderPara
270
322
  onChange={onChange}
271
323
  editorDidMount={handleEditorDidMount}
272
324
  options={{
325
+ readOnly,
273
326
  codeLens: false,
274
327
  contextmenu: false,
275
328
  fixedOverflowWidgets: true,
@@ -299,6 +352,7 @@ export default function PromQLEditor(props: PromQLEditorProps & DataProviderPara
299
352
  suggestFontSize: 12,
300
353
  wordWrap: 'on',
301
354
  automaticLayout: true,
355
+ occurrencesHighlight: 'off', // Disable word highlighting
302
356
  }}
303
357
  />
304
358
  </div>