@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.
- package/README.md +68 -8
- package/dist/monaco-editor.cjs.development.js +30 -3
- 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 +31 -4
- package/dist/monaco-editor.esm.js.map +1 -1
- package/dist/promql/index.d.ts +2 -0
- package/package.json +1 -1
- package/src/promql/index.tsx +57 -3
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,7 +34,7 @@ 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
|
|
@@ -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({
|
|
@@ -2001,6 +2007,10 @@ function PromQLEditor(props) {
|
|
|
2001
2007
|
interpolateString = props.interpolateString,
|
|
2002
2008
|
_props$enableAutocomp = props.enableAutocomplete,
|
|
2003
2009
|
enableAutocomplete = _props$enableAutocomp === void 0 ? true : _props$enableAutocomp,
|
|
2010
|
+
_props$readOnly = props.readOnly,
|
|
2011
|
+
readOnly = _props$readOnly === void 0 ? false : _props$readOnly,
|
|
2012
|
+
_props$disabled = props.disabled,
|
|
2013
|
+
disabled = _props$disabled === void 0 ? false : _props$disabled,
|
|
2004
2014
|
onChange = props.onChange,
|
|
2005
2015
|
onShiftEnter = props.onShiftEnter,
|
|
2006
2016
|
onBlur = props.onBlur,
|
|
@@ -2012,6 +2022,15 @@ function PromQLEditor(props) {
|
|
|
2012
2022
|
var styles = getStyles(placeholder);
|
|
2013
2023
|
var handleEditorDidMount = function handleEditorDidMount(editor) {
|
|
2014
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
|
+
});
|
|
2015
2034
|
monaco.editor.defineTheme('n9e-dark', {
|
|
2016
2035
|
base: 'vs-dark',
|
|
2017
2036
|
inherit: true,
|
|
@@ -2026,6 +2045,12 @@ function PromQLEditor(props) {
|
|
|
2026
2045
|
editor.onDidBlurEditorWidget(function () {
|
|
2027
2046
|
isEditorFocused.set(false);
|
|
2028
2047
|
onBlur == null || onBlur(editor.getValue());
|
|
2048
|
+
// reset the selection to the current position
|
|
2049
|
+
var position = editor.getPosition();
|
|
2050
|
+
if (position) {
|
|
2051
|
+
var newSelection = new monaco.Selection(position.lineNumber, position.column, position.lineNumber, position.column);
|
|
2052
|
+
editor.setSelection(newSelection);
|
|
2053
|
+
}
|
|
2029
2054
|
});
|
|
2030
2055
|
editor.onDidFocusEditorText(function () {
|
|
2031
2056
|
isEditorFocused.set(true);
|
|
@@ -2161,7 +2186,7 @@ function PromQLEditor(props) {
|
|
|
2161
2186
|
}
|
|
2162
2187
|
}, [enableAutocomplete, props.url, props.lookbackInterval, JSON.stringify(props.variablesNames), props.durationVariablesCompletion, props.httpMethod, props.apiPrefix, placeholder]);
|
|
2163
2188
|
return React__default.createElement("div", {
|
|
2164
|
-
className: 'ant-input' + (size ? " " + SIZE_MAP[size].className : '')
|
|
2189
|
+
className: 'ant-input' + (size ? " " + SIZE_MAP[size].className : '') + (disabled ? " ant-input-disabled " + containerDisabledClassName : '') + (readOnly ? " " + containerReadOnlyClassName : '')
|
|
2165
2190
|
}, React__default.createElement("div", {
|
|
2166
2191
|
ref: containerRef
|
|
2167
2192
|
}, React__default.createElement(MonacoEditor, {
|
|
@@ -2173,6 +2198,7 @@ function PromQLEditor(props) {
|
|
|
2173
2198
|
onChange: onChange,
|
|
2174
2199
|
editorDidMount: handleEditorDidMount,
|
|
2175
2200
|
options: {
|
|
2201
|
+
readOnly: readOnly,
|
|
2176
2202
|
codeLens: false,
|
|
2177
2203
|
contextmenu: false,
|
|
2178
2204
|
fixedOverflowWidgets: true,
|
|
@@ -2203,7 +2229,8 @@ function PromQLEditor(props) {
|
|
|
2203
2229
|
},
|
|
2204
2230
|
suggestFontSize: 12,
|
|
2205
2231
|
wordWrap: 'on',
|
|
2206
|
-
automaticLayout: true
|
|
2232
|
+
automaticLayout: true,
|
|
2233
|
+
occurrencesHighlight: 'off'
|
|
2207
2234
|
}
|
|
2208
2235
|
})));
|
|
2209
2236
|
}
|