@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/README.md
CHANGED
|
@@ -5,16 +5,23 @@ import { PromQLMonacoEditor } from '@fc-components/monaco-editor';
|
|
|
5
5
|
|
|
6
6
|
const App = () => {
|
|
7
7
|
const [value, setValue] = React.useState<string>();
|
|
8
|
-
const
|
|
8
|
+
const [enableAutocomplete, setEnableAutocomplete] = React.useState<boolean>(true);
|
|
9
|
+
const [variablesNames, setVariablesNames] = React.useState<string[]>(['$job', '$instance']);
|
|
10
|
+
const [placeholder, setPlaceholder] = React.useState<string>('Enter your PromQL query here...');
|
|
11
|
+
const [theme, setTheme] = React.useState<'light' | 'dark'>('light');
|
|
12
|
+
const [readOnly, setReadOnly] = React.useState<boolean>(false);
|
|
13
|
+
const [disabled, setDisabled] = React.useState<boolean>(false);
|
|
14
|
+
const editorRef = React.useRef<monacoTypes.editor.IStandaloneCodeEditor | null>(null);
|
|
9
15
|
|
|
10
16
|
return (
|
|
11
17
|
<div style={{ padding: 16 }}>
|
|
12
18
|
<PromQLMonacoEditor
|
|
13
|
-
|
|
14
|
-
|
|
19
|
+
readOnly={readOnly} // Set to true to make the editor read-only
|
|
20
|
+
disabled={disabled} // Set to true to disable the editor
|
|
21
|
+
theme={theme} // or 'dark'
|
|
15
22
|
size='middle' // 'small', 'middle', or 'large'
|
|
16
|
-
placeholder=
|
|
17
|
-
variablesNames={
|
|
23
|
+
placeholder={placeholder}
|
|
24
|
+
variablesNames={variablesNames} // Example variable names
|
|
18
25
|
apiPrefix='/api/n9e/proxy/1/api/v1'
|
|
19
26
|
request={(resource, options) => {
|
|
20
27
|
const params = options?.body?.toString();
|
|
@@ -27,14 +34,14 @@ const App = () => {
|
|
|
27
34
|
});
|
|
28
35
|
}}
|
|
29
36
|
value={value}
|
|
30
|
-
enableAutocomplete={
|
|
37
|
+
enableAutocomplete={enableAutocomplete} // Enable completion
|
|
31
38
|
durationVariablesCompletion={false} // Disable duration variables completion. eg. $__interval, $__range, $__rate_interval
|
|
32
39
|
interpolateString={(query) => {
|
|
33
40
|
// Interpolate variables in the query string
|
|
34
41
|
return query.replace(/\$__interval/g, '10s');
|
|
35
42
|
}}
|
|
36
|
-
|
|
37
|
-
console.log('
|
|
43
|
+
onEnter={(value) => {
|
|
44
|
+
console.log('Enter pressed, current value:', value);
|
|
38
45
|
}}
|
|
39
46
|
onBlur={(value) => {
|
|
40
47
|
console.log('Editor lost focus, current value:', value);
|
|
@@ -43,12 +50,65 @@ const App = () => {
|
|
|
43
50
|
console.log('Value changed:', value);
|
|
44
51
|
setValue(value);
|
|
45
52
|
}}
|
|
53
|
+
editorDidMount={(editor) => {
|
|
54
|
+
editorRef.current = editor;
|
|
55
|
+
}}
|
|
46
56
|
/>
|
|
57
|
+
<div style={{ marginTop: 16 }}>
|
|
58
|
+
<label>
|
|
59
|
+
<input type='checkbox' checked={enableAutocomplete} onChange={(e) => setEnableAutocomplete(e.target.checked)} /> Enable Autocomplete
|
|
60
|
+
</label>
|
|
61
|
+
<label style={{ marginLeft: 16 }}>
|
|
62
|
+
<a
|
|
63
|
+
onClick={() => {
|
|
64
|
+
setVariablesNames(['$job', '$instance', '$newVariable']);
|
|
65
|
+
}}
|
|
66
|
+
>
|
|
67
|
+
Update Variables
|
|
68
|
+
</a>
|
|
69
|
+
</label>
|
|
70
|
+
<label style={{ marginLeft: 16 }}>
|
|
71
|
+
<a
|
|
72
|
+
onClick={() => {
|
|
73
|
+
setPlaceholder('New Placeholder Text');
|
|
74
|
+
}}
|
|
75
|
+
>
|
|
76
|
+
Update Placeholder
|
|
77
|
+
</a>
|
|
78
|
+
</label>
|
|
79
|
+
<label style={{ marginLeft: 16 }}>
|
|
80
|
+
<a
|
|
81
|
+
onClick={() => {
|
|
82
|
+
setTheme(theme === 'light' ? 'dark' : 'light');
|
|
83
|
+
}}
|
|
84
|
+
>
|
|
85
|
+
Switch theme
|
|
86
|
+
</a>
|
|
87
|
+
</label>
|
|
88
|
+
<label style={{ marginLeft: 16 }}>
|
|
89
|
+
<a
|
|
90
|
+
onClick={() => {
|
|
91
|
+
setReadOnly(!readOnly);
|
|
92
|
+
}}
|
|
93
|
+
>
|
|
94
|
+
Switch Read-Only Mode
|
|
95
|
+
</a>
|
|
96
|
+
</label>
|
|
97
|
+
<label style={{ marginLeft: 16 }}>
|
|
98
|
+
<a
|
|
99
|
+
onClick={() => {
|
|
100
|
+
setDisabled(!disabled);
|
|
101
|
+
}}
|
|
102
|
+
>
|
|
103
|
+
Switch Disabled Mode
|
|
104
|
+
</a>
|
|
105
|
+
</label>
|
|
106
|
+
</div>
|
|
47
107
|
<div>
|
|
48
108
|
<a
|
|
49
109
|
onClick={() => {
|
|
50
|
-
if (
|
|
51
|
-
const editor =
|
|
110
|
+
if (editorRef.current) {
|
|
111
|
+
const editor = editorRef.current;
|
|
52
112
|
editor.trigger('keyboard', 'type', { text: 'Insert Text' });
|
|
53
113
|
editor.focus();
|
|
54
114
|
}
|
|
@@ -235,6 +235,9 @@ function _setPrototypeOf(t, e) {
|
|
|
235
235
|
return t.__proto__ = e, t;
|
|
236
236
|
}, _setPrototypeOf(t, e);
|
|
237
237
|
}
|
|
238
|
+
function _taggedTemplateLiteralLoose(e, t) {
|
|
239
|
+
return t || (t = e.slice(0)), e.raw = t, e;
|
|
240
|
+
}
|
|
238
241
|
function _toPrimitive(t, r) {
|
|
239
242
|
if ("object" != typeof t || !t) return t;
|
|
240
243
|
var e = t[Symbol.toPrimitive];
|
|
@@ -1958,6 +1961,7 @@ function isErrorBoundary(boundary) {
|
|
|
1958
1961
|
}
|
|
1959
1962
|
|
|
1960
1963
|
var _excluded = ["error"];
|
|
1964
|
+
var _templateObject, _templateObject2;
|
|
1961
1965
|
var PROMQL_LANG_ID = monacoPromql.promLanguageDefinition.id;
|
|
1962
1966
|
var SIZE_MAP = {
|
|
1963
1967
|
small: {
|
|
@@ -1977,9 +1981,11 @@ var SIZE_MAP = {
|
|
|
1977
1981
|
}
|
|
1978
1982
|
};
|
|
1979
1983
|
var themeMap = {
|
|
1980
|
-
light: 'light',
|
|
1984
|
+
light: 'n9e-light',
|
|
1981
1985
|
dark: 'n9e-dark'
|
|
1982
1986
|
};
|
|
1987
|
+
var containerDisabledClassName = /*#__PURE__*/css.css(_templateObject || (_templateObject = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n .monaco-editor {\n user-select: none;\n pointer-events: none;\n }\n"])));
|
|
1988
|
+
var containerReadOnlyClassName = /*#__PURE__*/css.css(_templateObject2 || (_templateObject2 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n .monaco-editor .cursors-layer > .cursor {\n opacity: 0 !important; /* \u5B8C\u5168\u900F\u660E */\n }\n"])));
|
|
1983
1989
|
var getStyles = function getStyles(placeholder) {
|
|
1984
1990
|
return {
|
|
1985
1991
|
placeholder: css.css({
|
|
@@ -2003,8 +2009,10 @@ function PromQLEditor(props) {
|
|
|
2003
2009
|
enableAutocomplete = _props$enableAutocomp === void 0 ? true : _props$enableAutocomp,
|
|
2004
2010
|
_props$readOnly = props.readOnly,
|
|
2005
2011
|
readOnly = _props$readOnly === void 0 ? false : _props$readOnly,
|
|
2012
|
+
_props$disabled = props.disabled,
|
|
2013
|
+
disabled = _props$disabled === void 0 ? false : _props$disabled,
|
|
2006
2014
|
onChange = props.onChange,
|
|
2007
|
-
|
|
2015
|
+
onEnter = props.onEnter,
|
|
2008
2016
|
onBlur = props.onBlur,
|
|
2009
2017
|
editorDidMount = props.editorDidMount;
|
|
2010
2018
|
var autocompleteDisposeFun = React.useRef(null);
|
|
@@ -2014,6 +2022,15 @@ function PromQLEditor(props) {
|
|
|
2014
2022
|
var styles = getStyles(placeholder);
|
|
2015
2023
|
var handleEditorDidMount = function handleEditorDidMount(editor) {
|
|
2016
2024
|
editorRef.current = editor;
|
|
2025
|
+
monaco.editor.defineTheme('n9e-light', {
|
|
2026
|
+
base: 'vs',
|
|
2027
|
+
inherit: true,
|
|
2028
|
+
rules: [],
|
|
2029
|
+
colors: {
|
|
2030
|
+
'editor.background': '#00000000',
|
|
2031
|
+
focusBorder: '#00000000'
|
|
2032
|
+
}
|
|
2033
|
+
});
|
|
2017
2034
|
monaco.editor.defineTheme('n9e-dark', {
|
|
2018
2035
|
base: 'vs-dark',
|
|
2019
2036
|
inherit: true,
|
|
@@ -2059,10 +2076,32 @@ function PromQLEditor(props) {
|
|
|
2059
2076
|
keybinding: monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyF,
|
|
2060
2077
|
command: null
|
|
2061
2078
|
});
|
|
2062
|
-
//
|
|
2079
|
+
// 设置 Shift + Enter 为在光标位置换行
|
|
2063
2080
|
editor.addCommand(monaco.KeyMod.Shift | monaco.KeyCode.Enter, function () {
|
|
2064
|
-
|
|
2081
|
+
// 在光标位置插入换行符
|
|
2082
|
+
var position = editor.getPosition();
|
|
2083
|
+
if (position) {
|
|
2084
|
+
editor.executeEdits('shift-enter', [{
|
|
2085
|
+
range: new monaco.Range(position.lineNumber, position.column, position.lineNumber, position.column),
|
|
2086
|
+
text: '\n'
|
|
2087
|
+
}]);
|
|
2088
|
+
// 将光标移动到新行
|
|
2089
|
+
editor.setPosition({
|
|
2090
|
+
lineNumber: position.lineNumber + 1,
|
|
2091
|
+
column: 1
|
|
2092
|
+
});
|
|
2093
|
+
}
|
|
2065
2094
|
}, 'isEditorFocused' + id);
|
|
2095
|
+
// 完全阻止 Enter 键的默认行为(包括换行)
|
|
2096
|
+
monaco.editor.addKeybindingRule({
|
|
2097
|
+
keybinding: monaco.KeyCode.Enter,
|
|
2098
|
+
command: '-',
|
|
2099
|
+
when: '!suggestWidgetVisible'
|
|
2100
|
+
});
|
|
2101
|
+
// handle: enter - 只有在没有建议窗口时才执行自定义行为
|
|
2102
|
+
editor.addCommand(monaco.KeyCode.Enter, function () {
|
|
2103
|
+
onEnter == null || onEnter(editor.getValue());
|
|
2104
|
+
}, '!suggestWidgetVisible && isEditorFocused' + id);
|
|
2066
2105
|
editor.onDidChangeModelContent(function () {
|
|
2067
2106
|
var model = editor.getModel();
|
|
2068
2107
|
if (model) {
|
|
@@ -2169,7 +2208,7 @@ function PromQLEditor(props) {
|
|
|
2169
2208
|
}
|
|
2170
2209
|
}, [enableAutocomplete, props.url, props.lookbackInterval, JSON.stringify(props.variablesNames), props.durationVariablesCompletion, props.httpMethod, props.apiPrefix, placeholder]);
|
|
2171
2210
|
return React__default.createElement("div", {
|
|
2172
|
-
className: 'ant-input' + (size ? " " + SIZE_MAP[size].className : '')
|
|
2211
|
+
className: 'ant-input' + (size ? " " + SIZE_MAP[size].className : '') + (disabled ? " ant-input-disabled " + containerDisabledClassName : '') + (readOnly ? " " + containerReadOnlyClassName : '')
|
|
2173
2212
|
}, React__default.createElement("div", {
|
|
2174
2213
|
ref: containerRef
|
|
2175
2214
|
}, React__default.createElement(MonacoEditor, {
|