@fc-components/monaco-editor 0.1.3 → 0.1.5

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.
@@ -1,4 +1,4 @@
1
- import React, { useRef, useEffect } from 'react';
1
+ import React, { forwardRef, useRef, useEffect, useImperativeHandle } from 'react';
2
2
  import MonacoEditor from 'react-monaco-editor';
3
3
  import * as monaco from 'monaco-editor';
4
4
  import { languages, editor, KeyMod, KeyCode, Range, MarkerSeverity } from 'monaco-editor';
@@ -1953,7 +1953,6 @@ function isErrorBoundary(boundary) {
1953
1953
 
1954
1954
  var _excluded = ["error"];
1955
1955
  var PROMQL_LANG_ID = promLanguageDefinition.id;
1956
- var EDITOR_HEIGHT_OFFSET = 2;
1957
1956
  var SIZE_MAP = {
1958
1957
  small: {
1959
1958
  className: 'ant-input-sm',
@@ -1972,8 +1971,8 @@ var SIZE_MAP = {
1972
1971
  }
1973
1972
  };
1974
1973
  var themeMap = {
1975
- light: 'vs-light',
1976
- dark: 'vs-dark'
1974
+ light: 'light',
1975
+ dark: 'n9e-dark'
1977
1976
  };
1978
1977
  var getStyles = function getStyles(placeholder) {
1979
1978
  return {
@@ -1985,7 +1984,7 @@ var getStyles = function getStyles(placeholder) {
1985
1984
  })
1986
1985
  };
1987
1986
  };
1988
- function PromQLEditor(props) {
1987
+ var index = /*#__PURE__*/forwardRef(function PromQLEditor(props, ref) {
1989
1988
  var id = v4();
1990
1989
  var _props$size = props.size,
1991
1990
  size = _props$size === void 0 ? 'middle' : _props$size,
@@ -2003,27 +2002,19 @@ function PromQLEditor(props) {
2003
2002
  var autocompleteDisposeFun = useRef(null);
2004
2003
  var containerRef = useRef(null);
2005
2004
  var dataProviderRef = useRef(null);
2005
+ var editorRef = useRef(null);
2006
2006
  var styles = getStyles(placeholder);
2007
- useEffect(function () {
2008
- // 注册 PromQL 语言
2009
- var aliases = promLanguageDefinition.aliases,
2010
- extensions = promLanguageDefinition.extensions,
2011
- mimetypes = promLanguageDefinition.mimetypes;
2012
- languages.register({
2013
- id: PROMQL_LANG_ID,
2014
- aliases: aliases,
2015
- extensions: extensions,
2016
- mimetypes: mimetypes
2017
- });
2018
- // 设置语法高亮
2019
- languages.setMonarchTokensProvider(PROMQL_LANG_ID, language);
2020
- // 设置语言配置
2021
- languages.setLanguageConfiguration(PROMQL_LANG_ID, languageConfiguration);
2022
- return function () {
2023
- autocompleteDisposeFun.current == null || autocompleteDisposeFun.current();
2024
- };
2025
- }, []);
2026
2007
  var handleEditorDidMount = function handleEditorDidMount(editor$1) {
2008
+ editorRef.current = editor$1;
2009
+ editor.defineTheme('n9e-dark', {
2010
+ base: 'vs-dark',
2011
+ inherit: true,
2012
+ rules: [],
2013
+ colors: {
2014
+ 'editor.background': '#00000000',
2015
+ focusBorder: '#00000000'
2016
+ }
2017
+ });
2027
2018
  var isEditorFocused = editor$1.createContextKey('isEditorFocused' + id, false);
2028
2019
  // we setup on-blur
2029
2020
  editor$1.onDidBlurEditorWidget(function () {
@@ -2066,7 +2057,7 @@ function PromQLEditor(props) {
2066
2057
  var containerDiv = containerRef.current;
2067
2058
  if (containerDiv !== null) {
2068
2059
  var pixelHeight = editor$1.getContentHeight();
2069
- containerDiv.style.height = pixelHeight + EDITOR_HEIGHT_OFFSET + "px";
2060
+ containerDiv.style.height = pixelHeight + "px";
2070
2061
  containerDiv.style.width = '100%';
2071
2062
  var pixelWidth = containerDiv.clientWidth;
2072
2063
  editor$1.layout({
@@ -2129,6 +2120,32 @@ function PromQLEditor(props) {
2129
2120
  dataProvider.setVariablesNames(variablesNames || []);
2130
2121
  }
2131
2122
  }, [JSON.stringify(variablesNames)]);
2123
+ useEffect(function () {
2124
+ // 注册 PromQL 语言
2125
+ var aliases = promLanguageDefinition.aliases,
2126
+ extensions = promLanguageDefinition.extensions,
2127
+ mimetypes = promLanguageDefinition.mimetypes;
2128
+ languages.register({
2129
+ id: PROMQL_LANG_ID,
2130
+ aliases: aliases,
2131
+ extensions: extensions,
2132
+ mimetypes: mimetypes
2133
+ });
2134
+ // 设置语法高亮
2135
+ languages.setMonarchTokensProvider(PROMQL_LANG_ID, language);
2136
+ // 设置语言配置
2137
+ languages.setLanguageConfiguration(PROMQL_LANG_ID, languageConfiguration);
2138
+ return function () {
2139
+ autocompleteDisposeFun.current == null || autocompleteDisposeFun.current();
2140
+ };
2141
+ }, []);
2142
+ useImperativeHandle(ref, function () {
2143
+ return {
2144
+ getEditor: function getEditor() {
2145
+ return editorRef.current;
2146
+ }
2147
+ };
2148
+ });
2132
2149
  return React.createElement("div", {
2133
2150
  className: 'ant-input' + (size ? " " + SIZE_MAP[size].className : '')
2134
2151
  }, React.createElement("div", {
@@ -2174,7 +2191,7 @@ function PromQLEditor(props) {
2174
2191
  wordWrap: 'on'
2175
2192
  }
2176
2193
  })));
2177
- }
2194
+ });
2178
2195
 
2179
- export { PromQLEditor as PromQLMonacoEditor };
2196
+ export { index as PromQLMonacoEditor };
2180
2197
  //# sourceMappingURL=monaco-editor.esm.js.map