@fc-components/monaco-editor 0.1.2 → 0.1.3

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
@@ -6,10 +6,8 @@ import { PromQLMonacoEditor } from '@fc-components/monaco-editor';
6
6
  const App = () => {
7
7
  return (
8
8
  <PromQLMonacoEditor
9
- theme='light'
10
- size='middle'
11
- placeholder='请输入PromQL查询语句'
12
- variablesNames={['$job', '$instance']}
9
+ placeholder='Enter your PromQL query here...'
10
+ variablesNames={['$job', '$instance']} // Example variable names
13
11
  apiPrefix='/api/n9e/proxy/1/api/v1'
14
12
  request={(resource, options) => {
15
13
  const params = options?.body?.toString();
@@ -21,8 +19,10 @@ const App = () => {
21
19
  }),
22
20
  });
23
21
  }}
22
+ enableAutocomplete={true} // Enable completion
23
+ durationVariablesCompletion={false} // Disable duration variables completion. eg. $__interval, $__range, $__rate_interval
24
24
  interpolateString={(query) => {
25
- // Example interpolation function
25
+ // Interpolate variables in the query string
26
26
  return query.replace(/\$__interval/g, '10s');
27
27
  }}
28
28
  onShiftEnter={(value) => {
@@ -31,6 +31,9 @@ const App = () => {
31
31
  onBlur={(value) => {
32
32
  console.log('Editor lost focus, current value:', value);
33
33
  }}
34
+ onChange={(value) => {
35
+ console.log('Value changed:', value);
36
+ }}
34
37
  />
35
38
  );
36
39
  };
@@ -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);
@@ -2027,18 +2039,19 @@ function PromQLEditor(props) {
2027
2039
  editor.onDidFocusEditorText(function () {
2028
2040
  isEditorFocused.set(true);
2029
2041
  });
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
2042
  if (enableAutocomplete) {
2043
+ var dataProvider = new DataProvider({
2044
+ url: props.url,
2045
+ lookbackInterval: props.lookbackInterval,
2046
+ variablesNames: props.variablesNames,
2047
+ durationVariablesCompletion: props.durationVariablesCompletion,
2048
+ request: props.request,
2049
+ httpMethod: props.httpMethod,
2050
+ apiPrefix: props.apiPrefix,
2051
+ httpErrorHandler: props.httpErrorHandler
2052
+ });
2053
+ dataProviderRef.current = dataProvider;
2054
+ dataProvider.start();
2042
2055
  var completionProvider = getCompletionProvider(monaco, dataProvider);
2043
2056
  var filteringCompletionProvider = _extends({}, completionProvider, {
2044
2057
  provideCompletionItems: function provideCompletionItems(model, position, context, token) {