@fc-components/monaco-editor 0.1.2 → 0.1.4

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 CHANGED
@@ -4,12 +4,14 @@
4
4
  import { PromQLMonacoEditor } from '@fc-components/monaco-editor';
5
5
 
6
6
  const App = () => {
7
+ const [value, setValue] = React.useState<string>();
8
+
7
9
  return (
8
10
  <PromQLMonacoEditor
9
- theme='light'
10
- size='middle'
11
- placeholder='请输入PromQL查询语句'
12
- variablesNames={['$job', '$instance']}
11
+ theme='light' // or 'dark'
12
+ size='middle' // 'small', 'middle', or 'large'
13
+ placeholder='Enter your PromQL query here...'
14
+ variablesNames={['$job', '$instance']} // Example variable names
13
15
  apiPrefix='/api/n9e/proxy/1/api/v1'
14
16
  request={(resource, options) => {
15
17
  const params = options?.body?.toString();
@@ -21,8 +23,11 @@ const App = () => {
21
23
  }),
22
24
  });
23
25
  }}
26
+ value={value}
27
+ enableAutocomplete={true} // Enable completion
28
+ durationVariablesCompletion={false} // Disable duration variables completion. eg. $__interval, $__range, $__rate_interval
24
29
  interpolateString={(query) => {
25
- // Example interpolation function
30
+ // Interpolate variables in the query string
26
31
  return query.replace(/\$__interval/g, '10s');
27
32
  }}
28
33
  onShiftEnter={(value) => {
@@ -31,6 +36,10 @@ const App = () => {
31
36
  onBlur={(value) => {
32
37
  console.log('Editor lost focus, current value:', value);
33
38
  }}
39
+ onChange={(value) => {
40
+ console.log('Value changed:', value);
41
+ setValue(value);
42
+ }}
34
43
  />
35
44
  );
36
45
  };
@@ -872,7 +872,8 @@ var serviceUnavailable = 503;
872
872
  var CODE_MODE_SUGGESTIONS_INCOMPLETE_EVENT = 'codeModeSuggestionsIncomplete';
873
873
  var DataProvider = /*#__PURE__*/function () {
874
874
  function DataProvider(params) {
875
- var _this = this;
875
+ var _this = this,
876
+ _params$durationVaria;
876
877
  this.lookbackInterval = 60 * 60 * 1000 * 12; // 12 hours
877
878
  this.variablesNames = [];
878
879
  this.httpMethod = 'GET';
@@ -1018,6 +1019,7 @@ var DataProvider = /*#__PURE__*/function () {
1018
1019
  if (params.variablesNames) {
1019
1020
  this.variablesNames = [].concat(params.variablesNames);
1020
1021
  }
1022
+ this.durationVariablesCompletion = (_params$durationVaria = params.durationVariablesCompletion) != null ? _params$durationVaria : true;
1021
1023
  if (params.request) {
1022
1024
  this.customRequest = params.request;
1023
1025
  }
@@ -1542,7 +1544,14 @@ function _getAllFunctionsAndMetricNamesCompletions() {
1542
1544
  }));
1543
1545
  return _getAllFunctionsAndMetricNamesCompletions.apply(this, arguments);
1544
1546
  }
1545
- var DURATION_COMPLETIONS = /*#__PURE__*/['$__interval', '$__range', '$__rate_interval', '1m', '5m', '10m', '30m', '1h', '1d'].map(function (text) {
1547
+ var DURATION_COMPLETIONS = /*#__PURE__*/['1m', '5m', '10m', '30m', '1h', '1d'].map(function (text) {
1548
+ return {
1549
+ type: 'DURATION',
1550
+ label: text,
1551
+ insertText: text
1552
+ };
1553
+ });
1554
+ var DURATION_VARIABLES_COMPLETIONS = /*#__PURE__*/['$__interval', '$__range', '$__rate_interval'].map(function (text) {
1546
1555
  return {
1547
1556
  type: 'DURATION',
1548
1557
  label: text,
@@ -1770,6 +1779,9 @@ function _getLabelValuesForMetricCompletions() {
1770
1779
  function getCompletions(situation, dataProvider) {
1771
1780
  switch (situation.type) {
1772
1781
  case 'IN_DURATION':
1782
+ if (dataProvider.durationVariablesCompletion) {
1783
+ return Promise.resolve(DURATION_VARIABLES_COMPLETIONS.concat(DURATION_COMPLETIONS));
1784
+ }
1773
1785
  return Promise.resolve(DURATION_COMPLETIONS);
1774
1786
  case 'IN_FUNCTION':
1775
1787
  return getAllFunctionsAndMetricNamesCompletions(dataProvider);
@@ -1947,7 +1959,6 @@ function isErrorBoundary(boundary) {
1947
1959
 
1948
1960
  var _excluded = ["error"];
1949
1961
  var PROMQL_LANG_ID = monacoPromql.promLanguageDefinition.id;
1950
- var EDITOR_HEIGHT_OFFSET = 2;
1951
1962
  var SIZE_MAP = {
1952
1963
  small: {
1953
1964
  className: 'ant-input-sm',
@@ -1966,8 +1977,8 @@ var SIZE_MAP = {
1966
1977
  }
1967
1978
  };
1968
1979
  var themeMap = {
1969
- light: 'vs-light',
1970
- dark: 'vs-dark'
1980
+ light: 'light',
1981
+ dark: 'n9e-dark'
1971
1982
  };
1972
1983
  var getStyles = function getStyles(placeholder) {
1973
1984
  return {
@@ -2018,6 +2029,15 @@ function PromQLEditor(props) {
2018
2029
  };
2019
2030
  }, []);
2020
2031
  var handleEditorDidMount = function handleEditorDidMount(editor) {
2032
+ monaco.editor.defineTheme('n9e-dark', {
2033
+ base: 'vs-dark',
2034
+ inherit: true,
2035
+ rules: [],
2036
+ colors: {
2037
+ 'editor.background': '#00000000',
2038
+ focusBorder: '#00000000'
2039
+ }
2040
+ });
2021
2041
  var isEditorFocused = editor.createContextKey('isEditorFocused' + id, false);
2022
2042
  // we setup on-blur
2023
2043
  editor.onDidBlurEditorWidget(function () {
@@ -2027,18 +2047,19 @@ function PromQLEditor(props) {
2027
2047
  editor.onDidFocusEditorText(function () {
2028
2048
  isEditorFocused.set(true);
2029
2049
  });
2030
- var dataProvider = new DataProvider({
2031
- url: props.url,
2032
- lookbackInterval: props.lookbackInterval,
2033
- variablesNames: props.variablesNames,
2034
- request: props.request,
2035
- httpMethod: props.httpMethod,
2036
- apiPrefix: props.apiPrefix,
2037
- httpErrorHandler: props.httpErrorHandler
2038
- });
2039
- dataProviderRef.current = dataProvider;
2040
- dataProvider.start();
2041
2050
  if (enableAutocomplete) {
2051
+ var dataProvider = new DataProvider({
2052
+ url: props.url,
2053
+ lookbackInterval: props.lookbackInterval,
2054
+ variablesNames: props.variablesNames,
2055
+ durationVariablesCompletion: props.durationVariablesCompletion,
2056
+ request: props.request,
2057
+ httpMethod: props.httpMethod,
2058
+ apiPrefix: props.apiPrefix,
2059
+ httpErrorHandler: props.httpErrorHandler
2060
+ });
2061
+ dataProviderRef.current = dataProvider;
2062
+ dataProvider.start();
2042
2063
  var completionProvider = getCompletionProvider(monaco, dataProvider);
2043
2064
  var filteringCompletionProvider = _extends({}, completionProvider, {
2044
2065
  provideCompletionItems: function provideCompletionItems(model, position, context, token) {
@@ -2059,7 +2080,7 @@ function PromQLEditor(props) {
2059
2080
  var containerDiv = containerRef.current;
2060
2081
  if (containerDiv !== null) {
2061
2082
  var pixelHeight = editor.getContentHeight();
2062
- containerDiv.style.height = pixelHeight + EDITOR_HEIGHT_OFFSET + "px";
2083
+ containerDiv.style.height = pixelHeight + "px";
2063
2084
  containerDiv.style.width = '100%';
2064
2085
  var pixelWidth = containerDiv.clientWidth;
2065
2086
  editor.layout({