@fc-components/monaco-editor 0.1.10 → 0.1.12
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 +70 -10
- package/dist/monaco-editor.cjs.development.js +44 -5
- 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 +44 -5
- package/dist/monaco-editor.esm.js.map +1 -1
- package/dist/promql/index.d.ts +2 -1
- package/package.json +1 -1
- package/src/promql/index.tsx +68 -6
package/dist/promql/index.d.ts
CHANGED
|
@@ -9,9 +9,10 @@ interface PromQLEditorProps {
|
|
|
9
9
|
enableAutocomplete?: boolean;
|
|
10
10
|
durationVariablesCompletion?: boolean;
|
|
11
11
|
readOnly?: boolean;
|
|
12
|
+
disabled?: boolean;
|
|
12
13
|
interpolateString?: (query: string) => string;
|
|
13
14
|
onChange?: (value: string) => void;
|
|
14
|
-
|
|
15
|
+
onEnter?: (value: string) => void;
|
|
15
16
|
onBlur?: (value: string) => void;
|
|
16
17
|
editorDidMount?: (editor: monacoTypes.editor.IStandaloneCodeEditor) => void;
|
|
17
18
|
}
|
package/package.json
CHANGED
package/src/promql/index.tsx
CHANGED
|
@@ -21,9 +21,10 @@ interface PromQLEditorProps {
|
|
|
21
21
|
enableAutocomplete?: boolean;
|
|
22
22
|
durationVariablesCompletion?: boolean;
|
|
23
23
|
readOnly?: boolean;
|
|
24
|
+
disabled?: boolean;
|
|
24
25
|
interpolateString?: (query: string) => string;
|
|
25
26
|
onChange?: (value: string) => void;
|
|
26
|
-
|
|
27
|
+
onEnter?: (value: string) => void;
|
|
27
28
|
onBlur?: (value: string) => void;
|
|
28
29
|
editorDidMount?: (editor: monacoTypes.editor.IStandaloneCodeEditor) => void;
|
|
29
30
|
}
|
|
@@ -54,10 +55,23 @@ const SIZE_MAP: Record<
|
|
|
54
55
|
},
|
|
55
56
|
};
|
|
56
57
|
const themeMap: Record<string, string> = {
|
|
57
|
-
light: 'light',
|
|
58
|
+
light: 'n9e-light',
|
|
58
59
|
dark: 'n9e-dark',
|
|
59
60
|
};
|
|
60
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
|
+
|
|
61
75
|
const getStyles = (placeholder?: string) => {
|
|
62
76
|
return {
|
|
63
77
|
placeholder: css({
|
|
@@ -79,8 +93,9 @@ export default function PromQLEditor(props: PromQLEditorProps & DataProviderPara
|
|
|
79
93
|
interpolateString,
|
|
80
94
|
enableAutocomplete = true,
|
|
81
95
|
readOnly = false,
|
|
96
|
+
disabled = false,
|
|
82
97
|
onChange,
|
|
83
|
-
|
|
98
|
+
onEnter,
|
|
84
99
|
onBlur,
|
|
85
100
|
editorDidMount,
|
|
86
101
|
} = props;
|
|
@@ -92,6 +107,16 @@ export default function PromQLEditor(props: PromQLEditorProps & DataProviderPara
|
|
|
92
107
|
const handleEditorDidMount = (editor: monacoTypes.editor.IStandaloneCodeEditor) => {
|
|
93
108
|
editorRef.current = editor;
|
|
94
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
|
+
|
|
95
120
|
monaco.editor.defineTheme('n9e-dark', {
|
|
96
121
|
base: 'vs-dark',
|
|
97
122
|
inherit: true,
|
|
@@ -140,15 +165,45 @@ export default function PromQLEditor(props: PromQLEditorProps & DataProviderPara
|
|
|
140
165
|
command: null,
|
|
141
166
|
});
|
|
142
167
|
|
|
143
|
-
//
|
|
168
|
+
// 设置 Shift + Enter 为在光标位置换行
|
|
144
169
|
editor.addCommand(
|
|
145
170
|
monaco.KeyMod.Shift | monaco.KeyCode.Enter,
|
|
146
171
|
() => {
|
|
147
|
-
|
|
172
|
+
// 在光标位置插入换行符
|
|
173
|
+
const position = editor.getPosition();
|
|
174
|
+
if (position) {
|
|
175
|
+
editor.executeEdits('shift-enter', [
|
|
176
|
+
{
|
|
177
|
+
range: new monaco.Range(position.lineNumber, position.column, position.lineNumber, position.column),
|
|
178
|
+
text: '\n',
|
|
179
|
+
},
|
|
180
|
+
]);
|
|
181
|
+
// 将光标移动到新行
|
|
182
|
+
editor.setPosition({
|
|
183
|
+
lineNumber: position.lineNumber + 1,
|
|
184
|
+
column: 1,
|
|
185
|
+
});
|
|
186
|
+
}
|
|
148
187
|
},
|
|
149
188
|
'isEditorFocused' + id,
|
|
150
189
|
);
|
|
151
190
|
|
|
191
|
+
// 完全阻止 Enter 键的默认行为(包括换行)
|
|
192
|
+
monaco.editor.addKeybindingRule({
|
|
193
|
+
keybinding: monaco.KeyCode.Enter,
|
|
194
|
+
command: '-',
|
|
195
|
+
when: '!suggestWidgetVisible',
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
// handle: enter - 只有在没有建议窗口时才执行自定义行为
|
|
199
|
+
editor.addCommand(
|
|
200
|
+
monaco.KeyCode.Enter,
|
|
201
|
+
() => {
|
|
202
|
+
onEnter?.(editor.getValue());
|
|
203
|
+
},
|
|
204
|
+
'!suggestWidgetVisible && isEditorFocused' + id,
|
|
205
|
+
);
|
|
206
|
+
|
|
152
207
|
editor.onDidChangeModelContent(() => {
|
|
153
208
|
const model = editor.getModel();
|
|
154
209
|
if (model) {
|
|
@@ -279,7 +334,14 @@ export default function PromQLEditor(props: PromQLEditorProps & DataProviderPara
|
|
|
279
334
|
]);
|
|
280
335
|
|
|
281
336
|
return (
|
|
282
|
-
<div
|
|
337
|
+
<div
|
|
338
|
+
className={
|
|
339
|
+
'ant-input' +
|
|
340
|
+
(size ? ` ${SIZE_MAP[size].className}` : '') +
|
|
341
|
+
(disabled ? ` ant-input-disabled ${containerDisabledClassName}` : '') +
|
|
342
|
+
(readOnly ? ` ${containerReadOnlyClassName}` : '')
|
|
343
|
+
}
|
|
344
|
+
>
|
|
283
345
|
<div ref={containerRef}>
|
|
284
346
|
<MonacoEditor
|
|
285
347
|
width='100%'
|