@yuntijs/ui 1.0.0-beta.9 → 1.0.0-beta.91
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/es/App/index.d.ts +7 -0
- package/es/App/index.js +19 -0
- package/es/ButtonGroup/index.d.ts +24 -0
- package/es/ButtonGroup/index.js +66 -0
- package/es/Card/index.d.ts +1 -0
- package/es/Card/index.js +1 -0
- package/es/CardList/Item/index.d.ts +4 -0
- package/es/CardList/Item/index.js +43 -0
- package/es/CardList/Item/style.d.ts +0 -0
- package/es/CardList/Item/style.js +0 -0
- package/es/CardList/index.d.ts +2 -0
- package/es/CardList/index.js +39 -0
- package/es/ChatInputArea/desktop/ChatInputArea.d.ts +19 -0
- package/es/ChatInputArea/desktop/ChatInputArea.js +72 -0
- package/es/ChatInputArea/index.d.ts +6 -0
- package/es/ChatInputArea/index.js +6 -0
- package/es/ChatItem/components/Actions.d.ts +10 -0
- package/es/ChatItem/components/Actions.js +23 -0
- package/es/ChatItem/components/MessageContent.d.ts +21 -0
- package/es/ChatItem/components/MessageContent.js +59 -0
- package/es/ChatItem/index.d.ts +4 -0
- package/es/ChatItem/index.js +120 -0
- package/es/ChatItem/style.d.ts +25 -0
- package/es/ChatItem/style.js +39 -0
- package/es/ChatItem/type.d.ts +86 -0
- package/es/ChatItem/type.js +1 -0
- package/es/CollapseGroup/index.d.ts +4 -0
- package/es/CollapseGroup/index.js +23 -0
- package/es/CollapseGroup/style.d.ts +3 -0
- package/es/CollapseGroup/style.js +11 -0
- package/es/ConfigProvider/index.d.ts +3 -0
- package/es/ConfigProvider/index.js +17 -11
- package/es/Descriptions/index.d.ts +14 -0
- package/es/Descriptions/index.js +31 -0
- package/es/Descriptions/style.d.ts +4 -0
- package/es/Descriptions/style.js +24 -0
- package/es/Divider/index.d.ts +38 -0
- package/es/Divider/index.js +66 -0
- package/es/Divider/style.d.ts +3 -0
- package/es/Divider/style.js +12 -0
- package/es/DragPanel/index.d.ts +10 -0
- package/es/DragPanel/index.js +97 -0
- package/es/DragPanel/style.d.ts +7 -0
- package/es/DragPanel/style.js +15 -0
- package/es/Drawer/index.d.ts +13 -0
- package/es/Drawer/index.js +20 -0
- package/es/Drawer/style.d.ts +4 -0
- package/es/Drawer/style.js +16 -0
- package/es/Dropdown/index.d.ts +14 -0
- package/es/Dropdown/index.js +59 -0
- package/es/Dropdown/style.d.ts +7 -0
- package/es/Dropdown/style.js +13 -0
- package/es/EditableMessage/index.d.ts +75 -0
- package/es/EditableMessage/index.js +99 -0
- package/es/Form/collapse-list/index.d.ts +40 -0
- package/es/Form/collapse-list/index.js +209 -0
- package/es/Form/collapse-list/style.d.ts +5 -0
- package/es/Form/collapse-list/style.js +13 -0
- package/es/Form/index.d.ts +8 -0
- package/es/Form/index.js +5 -0
- package/es/FormHelper/autoFocus.d.ts +10 -0
- package/es/FormHelper/autoFocus.js +38 -0
- package/es/FormHelper/index.d.ts +13 -0
- package/es/FormHelper/index.js +41 -0
- package/es/Highlighter/FullFeatured.d.ts +18 -0
- package/es/Highlighter/FullFeatured.js +102 -0
- package/es/Highlighter/SyntaxHighlighter/index.d.ts +7 -0
- package/es/Highlighter/SyntaxHighlighter/index.js +51 -0
- package/es/Highlighter/SyntaxHighlighter/style.d.ts +5 -0
- package/es/Highlighter/SyntaxHighlighter/style.js +16 -0
- package/es/Highlighter/index.d.ts +50 -0
- package/es/Highlighter/index.js +77 -0
- package/es/Highlighter/style.d.ts +9 -0
- package/es/Highlighter/style.js +23 -0
- package/es/Highlighter/theme.d.ts +1 -0
- package/es/Highlighter/theme.js +1661 -0
- package/es/JsonViewer/index.d.ts +21 -0
- package/es/JsonViewer/index.js +121 -0
- package/es/JsonViewer/style.d.ts +7 -0
- package/es/JsonViewer/style.js +19 -0
- package/es/LogViewer/index.d.ts +10 -0
- package/es/LogViewer/index.js +141 -0
- package/es/LogViewer/style.d.ts +6 -0
- package/es/LogViewer/style.js +16 -0
- package/es/LogViewer/types.d.ts +235 -0
- package/es/LogViewer/types.js +1 -0
- package/es/Mentions/constants.d.ts +6 -0
- package/es/Mentions/constants.js +28 -0
- package/es/Mentions/hooks.d.ts +20 -0
- package/es/Mentions/hooks.js +133 -0
- package/es/Mentions/index.d.ts +23 -0
- package/es/Mentions/index.js +157 -0
- package/es/Mentions/plugins/OnBlurBlockPlugin.d.ts +7 -0
- package/es/Mentions/plugins/OnBlurBlockPlugin.js +35 -0
- package/es/Mentions/plugins/custom-text/node.d.ts +11 -0
- package/es/Mentions/plugins/custom-text/node.js +72 -0
- package/es/Mentions/plugins/editable.d.ts +4 -0
- package/es/Mentions/plugins/editable.js +13 -0
- package/es/Mentions/plugins/mention-node/component.d.ts +6 -0
- package/es/Mentions/plugins/mention-node/component.js +64 -0
- package/es/Mentions/plugins/mention-node/index.d.ts +9 -0
- package/es/Mentions/plugins/mention-node/index.js +32 -0
- package/es/Mentions/plugins/mention-node/node.d.ts +22 -0
- package/es/Mentions/plugins/mention-node/node.js +100 -0
- package/es/Mentions/plugins/mention-node/replacement.d.ts +5 -0
- package/es/Mentions/plugins/mention-node/replacement.js +43 -0
- package/es/Mentions/plugins/mention-node/style.d.ts +8 -0
- package/es/Mentions/plugins/mention-node/style.js +47 -0
- package/es/Mentions/plugins/mention-node/utils.d.ts +4 -0
- package/es/Mentions/plugins/mention-node/utils.js +10 -0
- package/es/Mentions/plugins/mention-picker/hooks.d.ts +5 -0
- package/es/Mentions/plugins/mention-picker/hooks.js +65 -0
- package/es/Mentions/plugins/mention-picker/index.d.ts +39 -0
- package/es/Mentions/plugins/mention-picker/index.js +137 -0
- package/es/Mentions/plugins/mention-picker/menu-item.d.ts +12 -0
- package/es/Mentions/plugins/mention-picker/menu-item.js +73 -0
- package/es/Mentions/plugins/mention-picker/menu.d.ts +10 -0
- package/es/Mentions/plugins/mention-picker/menu.js +31 -0
- package/es/Mentions/plugins/mention-picker/style.d.ts +11 -0
- package/es/Mentions/plugins/mention-picker/style.js +19 -0
- package/es/Mentions/plugins/mention-picker/utils.d.ts +31 -0
- package/es/Mentions/plugins/mention-picker/utils.js +66 -0
- package/es/Mentions/provider.d.ts +12 -0
- package/es/Mentions/provider.js +15 -0
- package/es/Mentions/style.d.ts +11 -0
- package/es/Mentions/style.js +22 -0
- package/es/Mentions/types.d.ts +12 -0
- package/es/Mentions/types.js +1 -0
- package/es/Mentions/utils.d.ts +9 -0
- package/es/Mentions/utils.js +95 -0
- package/es/Modal/index.d.ts +19 -0
- package/es/Modal/index.js +36 -0
- package/es/Modal/style.d.ts +4 -0
- package/es/Modal/style.js +17 -0
- package/es/MonacoEditor/base/controller.d.ts +17 -0
- package/es/MonacoEditor/base/controller.js +49 -0
- package/es/MonacoEditor/base/helper.d.ts +65 -0
- package/es/MonacoEditor/base/helper.js +324 -0
- package/es/MonacoEditor/base/index.d.ts +39 -0
- package/es/MonacoEditor/base/index.js +238 -0
- package/es/MonacoEditor/base/monaco.d.ts +6 -0
- package/es/MonacoEditor/base/monaco.js +64 -0
- package/es/MonacoEditor/{style.d.ts → base/style.d.ts} +4 -1
- package/es/MonacoEditor/base/style.js +43 -0
- package/es/MonacoEditor/index.d.ts +5 -4
- package/es/MonacoEditor/index.js +26 -62
- package/es/Page/Breadcrumb/index.d.ts +9 -0
- package/es/Page/Breadcrumb/index.js +56 -0
- package/es/Page/Content/index.d.ts +4 -0
- package/es/Page/Content/index.js +59 -0
- package/es/Page/Content/style.d.ts +3 -0
- package/es/Page/Content/style.js +12 -0
- package/es/Page/Footer/index.d.ts +2 -0
- package/es/Page/Footer/index.js +6 -0
- package/es/Page/Header/Icon.d.ts +17 -0
- package/es/Page/Header/Icon.js +42 -0
- package/es/Page/Header/index.d.ts +43 -0
- package/es/Page/Header/index.js +202 -0
- package/es/Page/Header/style.d.ts +12 -0
- package/es/Page/Header/style.js +21 -0
- package/es/Page/Page.d.ts +9 -0
- package/es/Page/Page.js +49 -0
- package/es/Page/PageContext.d.ts +15 -0
- package/es/Page/PageContext.js +21 -0
- package/es/Page/Title/index.d.ts +5 -0
- package/es/Page/Title/index.js +18 -0
- package/es/Page/Title/style.d.ts +3 -0
- package/es/Page/Title/style.js +10 -0
- package/es/Page/index.d.ts +18 -0
- package/es/Page/index.js +15 -0
- package/es/Page/style.d.ts +3 -0
- package/es/Page/style.js +10 -0
- package/es/ProCard/Card/index.d.ts +6 -0
- package/es/ProCard/Card/index.js +25 -0
- package/es/ProCard/Card/style.d.ts +7 -0
- package/es/ProCard/Card/style.js +15 -0
- package/es/ProCard/Content/index.d.ts +4 -0
- package/es/ProCard/Content/index.js +24 -0
- package/es/ProCard/Content/style.d.ts +3 -0
- package/es/ProCard/Content/style.js +10 -0
- package/es/ProCard/Descriptions/index.d.ts +4 -0
- package/es/ProCard/Descriptions/index.js +28 -0
- package/es/ProCard/Descriptions/style.d.ts +3 -0
- package/es/ProCard/Descriptions/style.js +12 -0
- package/es/ProCard/Header/index.d.ts +15 -0
- package/es/ProCard/Header/index.js +86 -0
- package/es/ProCard/Header/style.d.ts +12 -0
- package/es/ProCard/Header/style.js +21 -0
- package/es/ProCard/index.d.ts +13 -0
- package/es/ProCard/index.js +8 -0
- package/es/SelectCard/index.d.ts +33 -0
- package/es/SelectCard/index.js +132 -0
- package/es/SelectCard/style.d.ts +10 -0
- package/es/SelectCard/style.js +42 -0
- package/es/SliderInput/index.js +2 -2
- package/es/Status/index.d.ts +7 -0
- package/es/Status/index.js +39 -0
- package/es/Status/style.d.ts +4 -0
- package/es/Status/style.js +14 -0
- package/es/Table/collapse/index.d.ts +9 -0
- package/es/Table/collapse/index.js +39 -0
- package/es/Table/collapse/style.d.ts +3 -0
- package/es/Table/collapse/style.js +11 -0
- package/es/Table/index.d.ts +20 -0
- package/es/Table/index.js +56 -0
- package/es/Typography/index.d.ts +32 -0
- package/es/Typography/index.js +77 -0
- package/es/WaveformIcon/index.d.ts +9 -0
- package/es/WaveformIcon/index.js +51 -0
- package/es/hooks/languageMap.d.ts +1 -0
- package/es/hooks/languageMap.js +1 -0
- package/es/hooks/useHighlight.d.ts +5 -0
- package/es/hooks/useHighlight.js +78 -0
- package/es/index.d.ts +38 -3
- package/es/index.js +48 -3
- package/es/notification/index.d.ts +24 -0
- package/es/notification/index.js +237 -0
- package/es/notification/style.d.ts +2 -0
- package/es/notification/style.js +28 -0
- package/es/styles/colors/colors.d.ts +39 -0
- package/es/styles/colors/colors.js +86 -0
- package/es/styles/colors/generateColorPalette.d.ts +11 -0
- package/es/styles/colors/generateColorPalette.js +31 -0
- package/es/styles/colors/neutralColors.d.ts +9 -0
- package/es/styles/colors/neutralColors.js +32 -0
- package/es/styles/index.d.ts +4 -0
- package/es/styles/index.js +4 -0
- package/es/useSpeechSynthes/const/polyfill.d.ts +3 -0
- package/es/useSpeechSynthes/const/polyfill.js +21 -0
- package/es/useSpeechSynthes/index.d.ts +13 -0
- package/es/useSpeechSynthes/index.js +69 -0
- package/es/utils/constants.d.ts +1 -0
- package/es/utils/constants.js +1 -0
- package/es/utils/tools.d.ts +1 -0
- package/es/utils/tools.js +1 -0
- package/package.json +31 -9
- package/umd/index.min.css +2 -0
- package/umd/index.min.css.map +1 -0
- package/umd/index.min.js +1 -1
- package/umd/index.min.js.map +1 -1
- package/es/MonacoEditor/style.js +0 -24
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
3
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
4
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
5
|
+
/* eslint-disable no-empty */
|
|
6
|
+
|
|
7
|
+
import { useEffect, useRef, useState } from 'react';
|
|
8
|
+
import { isBrowser } from "../../utils/tools";
|
|
9
|
+
import { getMonaco } from "./monaco";
|
|
10
|
+
|
|
11
|
+
// @todo fill type def for monaco editor without refering monaco editor
|
|
12
|
+
/**
|
|
13
|
+
* @see https://microsoft.github.io/monaco-editor/api/index.html
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
var CURRENT_LANGUAGE = isBrowser ? (window.locale || window.localStorage.getItem('vdev-locale') || '').replace(/_/, '-') || 'zh-CN' : 'zh-CN';
|
|
17
|
+
export var WORD_EDITOR_INITIALIZING = CURRENT_LANGUAGE === 'en-US' ? 'Initializing Editor' : '编辑器初始化中';
|
|
18
|
+
export var INITIAL_OPTIONS = {
|
|
19
|
+
fontSize: 12,
|
|
20
|
+
tabSize: 2,
|
|
21
|
+
fontFamily: 'Menlo, Monaco, Courier New, monospace',
|
|
22
|
+
folding: true,
|
|
23
|
+
minimap: {
|
|
24
|
+
enabled: false
|
|
25
|
+
},
|
|
26
|
+
autoIndent: 'advanced',
|
|
27
|
+
contextmenu: true,
|
|
28
|
+
useTabStops: true,
|
|
29
|
+
// wordBasedSuggestions: true,
|
|
30
|
+
formatOnPaste: true,
|
|
31
|
+
automaticLayout: true,
|
|
32
|
+
lineNumbers: 'on',
|
|
33
|
+
wordWrap: 'off',
|
|
34
|
+
scrollBeyondLastLine: false,
|
|
35
|
+
fixedOverflowWidgets: false,
|
|
36
|
+
snippetSuggestions: 'top',
|
|
37
|
+
scrollbar: {
|
|
38
|
+
vertical: 'auto',
|
|
39
|
+
horizontal: 'auto',
|
|
40
|
+
verticalScrollbarSize: 10,
|
|
41
|
+
horizontalScrollbarSize: 10
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
var DIFF_EDITOR_INITIAL_OPTIONS = {
|
|
45
|
+
fontSize: 12,
|
|
46
|
+
fontFamily: 'Menlo, Monaco, Courier New, monospace',
|
|
47
|
+
folding: true,
|
|
48
|
+
minimap: {
|
|
49
|
+
enabled: false
|
|
50
|
+
},
|
|
51
|
+
autoIndent: 'advanced',
|
|
52
|
+
contextmenu: true,
|
|
53
|
+
useTabStops: true,
|
|
54
|
+
formatOnPaste: true,
|
|
55
|
+
automaticLayout: true,
|
|
56
|
+
lineNumbers: 'on',
|
|
57
|
+
wordWrap: 'off',
|
|
58
|
+
scrollBeyondLastLine: false,
|
|
59
|
+
fixedOverflowWidgets: false,
|
|
60
|
+
snippetSuggestions: 'top',
|
|
61
|
+
scrollbar: {
|
|
62
|
+
vertical: 'auto',
|
|
63
|
+
horizontal: 'auto',
|
|
64
|
+
verticalScrollbarSize: 10,
|
|
65
|
+
horizontalScrollbarSize: 10
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
function usePrevious(value) {
|
|
69
|
+
var ref = useRef();
|
|
70
|
+
useEffect(function () {
|
|
71
|
+
ref.current = value;
|
|
72
|
+
}, [value]);
|
|
73
|
+
return ref.current;
|
|
74
|
+
}
|
|
75
|
+
function getOrCreateModel(monaco, value, language, path) {
|
|
76
|
+
if (path) {
|
|
77
|
+
var prevModel = monaco.editor.getModel(monaco.Uri.parse(path));
|
|
78
|
+
if (prevModel) {
|
|
79
|
+
return prevModel;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return monaco.editor.createModel(value, language, path ? monaco.Uri.parse(path) : undefined);
|
|
83
|
+
}
|
|
84
|
+
export var useEditor = function useEditor(type, props) {
|
|
85
|
+
var editorDidMount = props.editorDidMount,
|
|
86
|
+
editorWillMount = props.editorWillMount,
|
|
87
|
+
theme = props.theme,
|
|
88
|
+
value = props.value,
|
|
89
|
+
path = props.path,
|
|
90
|
+
language = props.language,
|
|
91
|
+
saveViewState = props.saveViewState,
|
|
92
|
+
defaultValue = props.defaultValue,
|
|
93
|
+
enhancers = props.enhancers;
|
|
94
|
+
var _useState = useState(false),
|
|
95
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
96
|
+
isEditorReady = _useState2[0],
|
|
97
|
+
setIsEditorReady = _useState2[1];
|
|
98
|
+
var _useState3 = useState(false),
|
|
99
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
100
|
+
focused = _useState4[0],
|
|
101
|
+
setFocused = _useState4[1];
|
|
102
|
+
var _useState5 = useState(false),
|
|
103
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
104
|
+
loading = _useState6[0],
|
|
105
|
+
setLoading = _useState6[1];
|
|
106
|
+
var defaultValueRef = useRef(defaultValue);
|
|
107
|
+
var valueRef = useRef(value);
|
|
108
|
+
var languageRef = useRef(language || 'text');
|
|
109
|
+
var pathRef = useRef(path);
|
|
110
|
+
var previousPath = usePrevious(path);
|
|
111
|
+
var requireConfigRef = useRef(props.requireConfig);
|
|
112
|
+
var optionRef = useRef(props.options);
|
|
113
|
+
var monacoRef = useRef();
|
|
114
|
+
var editorRef = useRef();
|
|
115
|
+
var containerRef = useRef();
|
|
116
|
+
var typeRef = useRef(type);
|
|
117
|
+
var editorDidMountRef = useRef();
|
|
118
|
+
var editorWillMountRef = useRef();
|
|
119
|
+
var decomposeRef = useRef(false);
|
|
120
|
+
var viewStatusRef = useRef(new Map());
|
|
121
|
+
var enhancersRef = useRef({});
|
|
122
|
+
useEffect(function () {
|
|
123
|
+
enhancersRef.current.enhancers = enhancers;
|
|
124
|
+
}, [enhancers]);
|
|
125
|
+
useEffect(function () {
|
|
126
|
+
editorDidMountRef.current = editorDidMount;
|
|
127
|
+
}, [editorDidMount]);
|
|
128
|
+
useEffect(function () {
|
|
129
|
+
editorWillMountRef.current = editorWillMount;
|
|
130
|
+
}, [editorWillMount]);
|
|
131
|
+
useEffect(function () {
|
|
132
|
+
valueRef.current = value;
|
|
133
|
+
}, [value]);
|
|
134
|
+
useEffect(function () {
|
|
135
|
+
languageRef.current = language;
|
|
136
|
+
}, [language]);
|
|
137
|
+
useEffect(function () {
|
|
138
|
+
defaultValueRef.current = defaultValue;
|
|
139
|
+
}, [defaultValue]);
|
|
140
|
+
|
|
141
|
+
// make sure loader / editor only init once
|
|
142
|
+
useEffect(function () {
|
|
143
|
+
setLoading(true);
|
|
144
|
+
getMonaco(requireConfigRef.current).then(function (monaco) {
|
|
145
|
+
var _enhancersRef$current;
|
|
146
|
+
// 兼容旧版本 monaco-editor 写死 MonacoEnvironment 的问题
|
|
147
|
+
window.MonacoEnvironment = undefined;
|
|
148
|
+
if (typeof window.define === 'function' && window.define.amd) {
|
|
149
|
+
// make monaco-editor's loader work with webpack's umd loader
|
|
150
|
+
// @see https://github.com/microsoft/monaco-editor/issues/2283
|
|
151
|
+
delete window.define.amd;
|
|
152
|
+
}
|
|
153
|
+
monacoRef.current = monaco;
|
|
154
|
+
try {
|
|
155
|
+
var _editorWillMountRef$c;
|
|
156
|
+
(_editorWillMountRef$c = editorWillMountRef.current) === null || _editorWillMountRef$c === void 0 || _editorWillMountRef$c.call(editorWillMountRef, monaco);
|
|
157
|
+
} catch (_unused) {}
|
|
158
|
+
if (!containerRef.current) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
var editor;
|
|
162
|
+
if (typeRef.current === 'single') {
|
|
163
|
+
var _ref, _valueRef$current;
|
|
164
|
+
var model = getOrCreateModel(monaco, (_ref = (_valueRef$current = valueRef.current) !== null && _valueRef$current !== void 0 ? _valueRef$current : defaultValueRef.current) !== null && _ref !== void 0 ? _ref : '', languageRef.current, pathRef.current);
|
|
165
|
+
editor = monaco.editor.create(containerRef.current, _objectSpread(_objectSpread({
|
|
166
|
+
automaticLayout: true
|
|
167
|
+
}, INITIAL_OPTIONS), optionRef.current));
|
|
168
|
+
editor.setModel(model);
|
|
169
|
+
} else {
|
|
170
|
+
var originalModel = monaco.editor.createModel(valueRef.current, languageRef.current);
|
|
171
|
+
var modifiedModel = monaco.editor.createModel(valueRef.current, languageRef.current);
|
|
172
|
+
editor = monaco.editor.createDiffEditor(containerRef.current, _objectSpread(_objectSpread({
|
|
173
|
+
automaticLayout: true
|
|
174
|
+
}, DIFF_EDITOR_INITIAL_OPTIONS), optionRef.current));
|
|
175
|
+
editor.setModel({
|
|
176
|
+
original: originalModel,
|
|
177
|
+
modified: modifiedModel
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
editorRef.current = editor;
|
|
181
|
+
(_enhancersRef$current = enhancersRef.current.enhancers) === null || _enhancersRef$current === void 0 || _enhancersRef$current.forEach(function (en) {
|
|
182
|
+
return en(monaco, editor);
|
|
183
|
+
});
|
|
184
|
+
try {
|
|
185
|
+
var _editorDidMountRef$cu;
|
|
186
|
+
(_editorDidMountRef$cu = editorDidMountRef.current) === null || _editorDidMountRef$cu === void 0 || _editorDidMountRef$cu.call(editorDidMountRef, monaco, editor);
|
|
187
|
+
} catch (_unused2) {}
|
|
188
|
+
if (!decomposeRef.current) {
|
|
189
|
+
setIsEditorReady(true);
|
|
190
|
+
}
|
|
191
|
+
}).catch(function (error) {
|
|
192
|
+
// eslint-disable-next-line no-console
|
|
193
|
+
console.error('Monaco Editor Load Error!', error);
|
|
194
|
+
}).then(function () {
|
|
195
|
+
if (!decomposeRef.current) {
|
|
196
|
+
setLoading(false);
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
}, []);
|
|
200
|
+
useEffect(function () {
|
|
201
|
+
var _monacoRef$current;
|
|
202
|
+
if (!isEditorReady) {
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
(_monacoRef$current = monacoRef.current) === null || _monacoRef$current === void 0 || _monacoRef$current.editor.setTheme(theme);
|
|
206
|
+
}, [isEditorReady, theme]);
|
|
207
|
+
|
|
208
|
+
// focus status
|
|
209
|
+
useEffect(function () {
|
|
210
|
+
if (!isEditorReady) {
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
var editor = type === 'diff' ? editorRef.current.getModifiedEditor() : editorRef.current;
|
|
214
|
+
editor === null || editor === void 0 || editor.onDidFocusEditorText(function () {
|
|
215
|
+
if (!decomposeRef.current) {
|
|
216
|
+
setFocused(true);
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
editor === null || editor === void 0 || editor.onDidBlurEditorText(function () {
|
|
220
|
+
if (!decomposeRef.current) {
|
|
221
|
+
setFocused(false);
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
}, [isEditorReady, type]);
|
|
225
|
+
|
|
226
|
+
// decomposing status
|
|
227
|
+
useEffect(function () {
|
|
228
|
+
return function () {
|
|
229
|
+
decomposeRef.current = true;
|
|
230
|
+
};
|
|
231
|
+
}, []);
|
|
232
|
+
|
|
233
|
+
// controlled value -- diff mode / without path only
|
|
234
|
+
useEffect(function () {
|
|
235
|
+
var _ref2, _monacoRef$current2, _editor$getOption;
|
|
236
|
+
if (!isEditorReady) {
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
if (type !== 'diff' && !!path) {
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
var editor = type === 'diff' ? editorRef.current.getModifiedEditor() : editorRef.current;
|
|
243
|
+
var nextValue = (_ref2 = value !== null && value !== void 0 ? value : defaultValueRef.current) !== null && _ref2 !== void 0 ? _ref2 : '';
|
|
244
|
+
var readOnly = (_monacoRef$current2 = monacoRef.current) === null || _monacoRef$current2 === void 0 ? void 0 : _monacoRef$current2.editor.EditorOption.readOnly;
|
|
245
|
+
if (readOnly && editor !== null && editor !== void 0 && (_editor$getOption = editor.getOption) !== null && _editor$getOption !== void 0 && _editor$getOption.call(editor, readOnly)) {
|
|
246
|
+
editor === null || editor === void 0 || editor.setValue(nextValue);
|
|
247
|
+
} else if (value !== (editor === null || editor === void 0 ? void 0 : editor.getValue())) {
|
|
248
|
+
editor === null || editor === void 0 || editor.executeEdits('', [{
|
|
249
|
+
range: editor === null || editor === void 0 ? void 0 : editor.getModel().getFullModelRange(),
|
|
250
|
+
text: nextValue,
|
|
251
|
+
forceMoveMarkers: true
|
|
252
|
+
}]);
|
|
253
|
+
editor === null || editor === void 0 || editor.pushUndoStop();
|
|
254
|
+
}
|
|
255
|
+
}, [isEditorReady, path, type, value]);
|
|
256
|
+
|
|
257
|
+
// multi-model && controlled value (shouldn't be diff mode)
|
|
258
|
+
useEffect(function () {
|
|
259
|
+
var _valueRef$current2, _editorRef$current;
|
|
260
|
+
if (!isEditorReady) {
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
if (type === 'diff') {
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
if (path === previousPath) {
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
var model = getOrCreateModel(monacoRef.current, (_valueRef$current2 = valueRef.current) !== null && _valueRef$current2 !== void 0 ? _valueRef$current2 : defaultValueRef.current, languageRef.current, path);
|
|
270
|
+
var editor = editorRef.current;
|
|
271
|
+
if (valueRef.current !== null && valueRef.current !== undefined && model.getValue() !== valueRef.current) {
|
|
272
|
+
model.setValue(valueRef.current);
|
|
273
|
+
}
|
|
274
|
+
if (model !== ((_editorRef$current = editorRef.current) === null || _editorRef$current === void 0 ? void 0 : _editorRef$current.getModel())) {
|
|
275
|
+
if (saveViewState) {
|
|
276
|
+
viewStatusRef.current.set(previousPath, editor.saveViewState());
|
|
277
|
+
}
|
|
278
|
+
editor.setModel(model);
|
|
279
|
+
if (saveViewState) {
|
|
280
|
+
editor.restoreViewState(viewStatusRef.current.get(path));
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}, [isEditorReady, value, path, previousPath, type, saveViewState]);
|
|
284
|
+
var retEditorRef = editorRef;
|
|
285
|
+
return {
|
|
286
|
+
isEditorReady: isEditorReady,
|
|
287
|
+
focused: focused,
|
|
288
|
+
loading: loading,
|
|
289
|
+
containerRef: containerRef,
|
|
290
|
+
monacoRef: monacoRef,
|
|
291
|
+
editorRef: retEditorRef,
|
|
292
|
+
valueRef: valueRef
|
|
293
|
+
};
|
|
294
|
+
};
|
|
295
|
+
export var useFullScreen = function useFullScreen(editor) {
|
|
296
|
+
var _useState7 = useState(false),
|
|
297
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
298
|
+
isFullScreen = _useState8[0],
|
|
299
|
+
setIsFullScreen = _useState8[1];
|
|
300
|
+
var fullScreen = function fullScreen() {
|
|
301
|
+
if (isFullScreen) {
|
|
302
|
+
setIsFullScreen(false);
|
|
303
|
+
editor === null || editor === void 0 || editor.updateOptions(_objectSpread(_objectSpread({}, editor === null || editor === void 0 ? void 0 : editor.getOptions()), {}, {
|
|
304
|
+
minimap: {
|
|
305
|
+
enabled: false
|
|
306
|
+
}
|
|
307
|
+
}));
|
|
308
|
+
editor === null || editor === void 0 || editor.layout();
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
setIsFullScreen(true);
|
|
312
|
+
// 更新小地图配置
|
|
313
|
+
editor === null || editor === void 0 || editor.updateOptions(_objectSpread(_objectSpread({}, editor === null || editor === void 0 ? void 0 : editor.getOptions()), {}, {
|
|
314
|
+
minimap: {
|
|
315
|
+
enabled: true
|
|
316
|
+
}
|
|
317
|
+
}));
|
|
318
|
+
editor === null || editor === void 0 || editor.layout();
|
|
319
|
+
};
|
|
320
|
+
return {
|
|
321
|
+
isFullScreen: isFullScreen,
|
|
322
|
+
fullScreen: fullScreen
|
|
323
|
+
};
|
|
324
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { editor } from 'monaco-editor';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { IDiffMonacoEditorProps, ISingleMonacoEditorProps } from './helper';
|
|
4
|
+
export * from './controller';
|
|
5
|
+
export * from './monaco';
|
|
6
|
+
declare function noop(): void;
|
|
7
|
+
export declare const SingleMonacoEditorComponent: React.FC<ISingleMonacoEditorProps & {
|
|
8
|
+
variant?: "filled" | "borderless" | "outlined" | undefined;
|
|
9
|
+
}> & {
|
|
10
|
+
displayName: string;
|
|
11
|
+
defaultProps: {
|
|
12
|
+
width: string;
|
|
13
|
+
height: number;
|
|
14
|
+
defaultValue: string;
|
|
15
|
+
language: string;
|
|
16
|
+
options: editor.IStandaloneEditorConstructionOptions;
|
|
17
|
+
editorDidMount: typeof noop;
|
|
18
|
+
editorWillMount: typeof noop;
|
|
19
|
+
onChange: typeof noop;
|
|
20
|
+
requireConfig: {};
|
|
21
|
+
};
|
|
22
|
+
MonacoDiffEditor: React.FC<IDiffMonacoEditorProps & {
|
|
23
|
+
variant?: "filled" | "borderless" | "outlined" | undefined;
|
|
24
|
+
}> & {
|
|
25
|
+
displayName: string;
|
|
26
|
+
defaultProps: {
|
|
27
|
+
width: string;
|
|
28
|
+
height: number;
|
|
29
|
+
defaultValue: string;
|
|
30
|
+
language: string;
|
|
31
|
+
options: editor.IStandaloneEditorConstructionOptions;
|
|
32
|
+
editorDidMount: typeof noop;
|
|
33
|
+
editorWillMount: typeof noop;
|
|
34
|
+
onChange: typeof noop;
|
|
35
|
+
requireConfig: {};
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
export default SingleMonacoEditorComponent;
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import { Icon } from '@lobehub/ui';
|
|
2
|
+
import { Button } from 'antd';
|
|
3
|
+
import { Maximize2, Minimize2 } from 'lucide-react';
|
|
4
|
+
import React, { useEffect, useMemo, useRef } from 'react';
|
|
5
|
+
import { INITIAL_OPTIONS, WORD_EDITOR_INITIALIZING, useEditor, useFullScreen } from "./helper";
|
|
6
|
+
import { useStyles } from "./style";
|
|
7
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
9
|
+
export * from "./controller";
|
|
10
|
+
export * from "./monaco";
|
|
11
|
+
function noop() {}
|
|
12
|
+
var SingleMonacoEditor = function SingleMonacoEditor(props) {
|
|
13
|
+
var _props$options;
|
|
14
|
+
var onChange = props.onChange,
|
|
15
|
+
enableOutline = props.enableOutline,
|
|
16
|
+
width = props.width,
|
|
17
|
+
height = props.height,
|
|
18
|
+
language = props.language,
|
|
19
|
+
supportFullScreen = props.supportFullScreen;
|
|
20
|
+
var onChangeRef = useRef(onChange);
|
|
21
|
+
var _useEditor = useEditor('single', props),
|
|
22
|
+
isEditorReady = _useEditor.isEditorReady,
|
|
23
|
+
focused = _useEditor.focused,
|
|
24
|
+
loading = _useEditor.loading,
|
|
25
|
+
containerRef = _useEditor.containerRef,
|
|
26
|
+
monacoRef = _useEditor.monacoRef,
|
|
27
|
+
editorRef = _useEditor.editorRef,
|
|
28
|
+
valueRef = _useEditor.valueRef;
|
|
29
|
+
var subscriptionRef = useRef();
|
|
30
|
+
var _useFullScreen = useFullScreen(editorRef === null || editorRef === void 0 ? void 0 : editorRef.current),
|
|
31
|
+
isFullScreen = _useFullScreen.isFullScreen,
|
|
32
|
+
fullScreen = _useFullScreen.fullScreen;
|
|
33
|
+
var _useStyles = useStyles({
|
|
34
|
+
isFullScreen: isFullScreen,
|
|
35
|
+
minimapEnabled: (_props$options = props.options) === null || _props$options === void 0 || (_props$options = _props$options.minimap) === null || _props$options === void 0 ? void 0 : _props$options.enabled,
|
|
36
|
+
variant: props.variant
|
|
37
|
+
}),
|
|
38
|
+
cx = _useStyles.cx,
|
|
39
|
+
styles = _useStyles.styles;
|
|
40
|
+
var className = cx(styles.base, props.className, {
|
|
41
|
+
've-focused': focused,
|
|
42
|
+
've-outline': enableOutline
|
|
43
|
+
});
|
|
44
|
+
var style = useMemo(function () {
|
|
45
|
+
return {
|
|
46
|
+
width: width,
|
|
47
|
+
height: height
|
|
48
|
+
};
|
|
49
|
+
}, [width, height]);
|
|
50
|
+
useEffect(function () {
|
|
51
|
+
onChangeRef.current = onChange;
|
|
52
|
+
}, [onChange]);
|
|
53
|
+
useEffect(function () {
|
|
54
|
+
if (isEditorReady) {
|
|
55
|
+
var _subscriptionRef$curr;
|
|
56
|
+
var editorInstance = editorRef.current;
|
|
57
|
+
(_subscriptionRef$curr = subscriptionRef.current) === null || _subscriptionRef$curr === void 0 || _subscriptionRef$curr.dispose();
|
|
58
|
+
subscriptionRef.current = editorInstance === null || editorInstance === void 0 ? void 0 : editorInstance.onDidChangeModelContent(function (event) {
|
|
59
|
+
var _editorInstance$getMo;
|
|
60
|
+
var editorValue = editorInstance === null || editorInstance === void 0 || (_editorInstance$getMo = editorInstance.getModel()) === null || _editorInstance$getMo === void 0 ? void 0 : _editorInstance$getMo.getValue();
|
|
61
|
+
if (valueRef.current !== editorValue) {
|
|
62
|
+
var _onChangeRef$current;
|
|
63
|
+
(_onChangeRef$current = onChangeRef.current) === null || _onChangeRef$current === void 0 || _onChangeRef$current.call(onChangeRef, editorValue, event);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}, [editorRef, isEditorReady, subscriptionRef, valueRef]);
|
|
68
|
+
useEffect(function () {
|
|
69
|
+
return function () {
|
|
70
|
+
var _subscriptionRef$curr2, _editorInstance$getMo2, _editorRef$current;
|
|
71
|
+
var editorInstance = editorRef.current;
|
|
72
|
+
(_subscriptionRef$curr2 = subscriptionRef.current) === null || _subscriptionRef$curr2 === void 0 || _subscriptionRef$curr2.dispose();
|
|
73
|
+
editorInstance === null || editorInstance === void 0 || (_editorInstance$getMo2 = editorInstance.getModel()) === null || _editorInstance$getMo2 === void 0 || _editorInstance$getMo2.dispose();
|
|
74
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
75
|
+
(_editorRef$current = editorRef.current) === null || _editorRef$current === void 0 || _editorRef$current.dispose();
|
|
76
|
+
};
|
|
77
|
+
}, [editorRef]);
|
|
78
|
+
useEffect(function () {
|
|
79
|
+
var _editorRef$current2;
|
|
80
|
+
if (!isEditorReady) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
var model = (_editorRef$current2 = editorRef.current) === null || _editorRef$current2 === void 0 ? void 0 : _editorRef$current2.getModel();
|
|
84
|
+
if (model) {
|
|
85
|
+
var _monacoRef$current;
|
|
86
|
+
(_monacoRef$current = monacoRef.current) === null || _monacoRef$current === void 0 || _monacoRef$current.editor.setModelLanguage(model, language);
|
|
87
|
+
}
|
|
88
|
+
}, [editorRef, isEditorReady, language, monacoRef]);
|
|
89
|
+
return /*#__PURE__*/_jsxs("div", {
|
|
90
|
+
className: className,
|
|
91
|
+
style: props.style,
|
|
92
|
+
children: [loading && /*#__PURE__*/_jsx("span", {
|
|
93
|
+
className: cx(styles.loading, 'loading'),
|
|
94
|
+
children: WORD_EDITOR_INITIALIZING
|
|
95
|
+
}), /*#__PURE__*/_jsx("div", {
|
|
96
|
+
className: "react-monaco-editor-container",
|
|
97
|
+
ref: containerRef,
|
|
98
|
+
style: style,
|
|
99
|
+
children: supportFullScreen && /*#__PURE__*/_jsx(Button, {
|
|
100
|
+
className: styles.fullScreenBtn,
|
|
101
|
+
icon: /*#__PURE__*/_jsx(Icon, {
|
|
102
|
+
icon: isFullScreen ? Minimize2 : Maximize2
|
|
103
|
+
}),
|
|
104
|
+
onClick: fullScreen,
|
|
105
|
+
size: "small",
|
|
106
|
+
type: "text"
|
|
107
|
+
})
|
|
108
|
+
})]
|
|
109
|
+
});
|
|
110
|
+
};
|
|
111
|
+
var DiffMonacoEditor = function DiffMonacoEditor(props) {
|
|
112
|
+
var enableOutline = props.enableOutline,
|
|
113
|
+
width = props.width,
|
|
114
|
+
height = props.height,
|
|
115
|
+
language = props.language,
|
|
116
|
+
onChange = props.onChange,
|
|
117
|
+
original = props.original,
|
|
118
|
+
supportFullScreen = props.supportFullScreen;
|
|
119
|
+
var onChangeRef = useRef(onChange);
|
|
120
|
+
var _useEditor2 = useEditor('diff', props),
|
|
121
|
+
isEditorReady = _useEditor2.isEditorReady,
|
|
122
|
+
focused = _useEditor2.focused,
|
|
123
|
+
loading = _useEditor2.loading,
|
|
124
|
+
containerRef = _useEditor2.containerRef,
|
|
125
|
+
monacoRef = _useEditor2.monacoRef,
|
|
126
|
+
editorRef = _useEditor2.editorRef,
|
|
127
|
+
valueRef = _useEditor2.valueRef;
|
|
128
|
+
var _useFullScreen2 = useFullScreen(),
|
|
129
|
+
isFullScreen = _useFullScreen2.isFullScreen,
|
|
130
|
+
fullScreen = _useFullScreen2.fullScreen;
|
|
131
|
+
var _useStyles2 = useStyles({
|
|
132
|
+
isFullScreen: isFullScreen,
|
|
133
|
+
diff: true,
|
|
134
|
+
variant: props.variant
|
|
135
|
+
}),
|
|
136
|
+
cx = _useStyles2.cx,
|
|
137
|
+
styles = _useStyles2.styles;
|
|
138
|
+
var className = cx(styles.base, props.className, {
|
|
139
|
+
've-focused': focused,
|
|
140
|
+
've-outline': enableOutline
|
|
141
|
+
});
|
|
142
|
+
var style = useMemo(function () {
|
|
143
|
+
return {
|
|
144
|
+
width: width,
|
|
145
|
+
height: height
|
|
146
|
+
};
|
|
147
|
+
}, [width, height]);
|
|
148
|
+
useEffect(function () {
|
|
149
|
+
onChangeRef.current = onChange;
|
|
150
|
+
}, [onChange]);
|
|
151
|
+
useEffect(function () {
|
|
152
|
+
var _editorRef$current$ge;
|
|
153
|
+
if (!isEditorReady) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
(_editorRef$current$ge = editorRef.current.getModel()) === null || _editorRef$current$ge === void 0 || _editorRef$current$ge.original.setValue(original !== null && original !== void 0 ? original : '');
|
|
157
|
+
var _ref = editorRef.current.getModel() || {},
|
|
158
|
+
modified = _ref.modified;
|
|
159
|
+
modified === null || modified === void 0 || modified.onDidChangeContent(function (event) {
|
|
160
|
+
var editorValue = modified.getValue();
|
|
161
|
+
if (valueRef.current !== editorValue) {
|
|
162
|
+
var _onChangeRef$current2;
|
|
163
|
+
(_onChangeRef$current2 = onChangeRef.current) === null || _onChangeRef$current2 === void 0 || _onChangeRef$current2.call(onChangeRef, editorValue, event);
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
}, [editorRef, isEditorReady, original, valueRef]);
|
|
167
|
+
useEffect(function () {
|
|
168
|
+
return function () {
|
|
169
|
+
var _editorRef$current3, _editorRef$current4, _editorRef$current5;
|
|
170
|
+
(_editorRef$current3 = editorRef.current) === null || _editorRef$current3 === void 0 || (_editorRef$current3 = _editorRef$current3.getModel()) === null || _editorRef$current3 === void 0 || (_editorRef$current3 = _editorRef$current3.original) === null || _editorRef$current3 === void 0 || _editorRef$current3.dispose();
|
|
171
|
+
(_editorRef$current4 = editorRef.current) === null || _editorRef$current4 === void 0 || (_editorRef$current4 = _editorRef$current4.getModel()) === null || _editorRef$current4 === void 0 || (_editorRef$current4 = _editorRef$current4.modified) === null || _editorRef$current4 === void 0 || _editorRef$current4.dispose();
|
|
172
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
173
|
+
(_editorRef$current5 = editorRef.current) === null || _editorRef$current5 === void 0 || _editorRef$current5.dispose();
|
|
174
|
+
};
|
|
175
|
+
}, [editorRef]);
|
|
176
|
+
useEffect(function () {
|
|
177
|
+
var _editorRef$current6, _monacoRef$current2, _monacoRef$current3;
|
|
178
|
+
if (!isEditorReady) {
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
var _ref2 = ((_editorRef$current6 = editorRef.current) === null || _editorRef$current6 === void 0 ? void 0 : _editorRef$current6.getModel()) || {},
|
|
182
|
+
originalModel = _ref2.original,
|
|
183
|
+
modifiedModel = _ref2.modified;
|
|
184
|
+
(_monacoRef$current2 = monacoRef.current) === null || _monacoRef$current2 === void 0 || _monacoRef$current2.editor.setModelLanguage(originalModel, language);
|
|
185
|
+
(_monacoRef$current3 = monacoRef.current) === null || _monacoRef$current3 === void 0 || _monacoRef$current3.editor.setModelLanguage(modifiedModel, language);
|
|
186
|
+
}, [editorRef, isEditorReady, language, monacoRef]);
|
|
187
|
+
return /*#__PURE__*/_jsxs("div", {
|
|
188
|
+
className: className,
|
|
189
|
+
style: props.style,
|
|
190
|
+
children: [loading && /*#__PURE__*/_jsx("span", {
|
|
191
|
+
className: cx(styles.loading, 'loading'),
|
|
192
|
+
children: WORD_EDITOR_INITIALIZING
|
|
193
|
+
}), /*#__PURE__*/_jsx("div", {
|
|
194
|
+
className: "react-monaco-editor-container react-monaco-editor-diff-container",
|
|
195
|
+
ref: containerRef,
|
|
196
|
+
style: style,
|
|
197
|
+
children: supportFullScreen && /*#__PURE__*/_jsx(Button, {
|
|
198
|
+
className: styles.fullScreenBtn,
|
|
199
|
+
icon: /*#__PURE__*/_jsx(Icon, {
|
|
200
|
+
icon: isFullScreen ? Minimize2 : Maximize2
|
|
201
|
+
}),
|
|
202
|
+
onClick: fullScreen,
|
|
203
|
+
size: "small",
|
|
204
|
+
type: "text"
|
|
205
|
+
})
|
|
206
|
+
})]
|
|
207
|
+
});
|
|
208
|
+
};
|
|
209
|
+
var DiffMonacoEditorComponent = Object.assign(DiffMonacoEditor, {
|
|
210
|
+
displayName: 'DiffMonacoEditor',
|
|
211
|
+
defaultProps: {
|
|
212
|
+
width: '100%',
|
|
213
|
+
height: 150,
|
|
214
|
+
defaultValue: '',
|
|
215
|
+
language: 'javascript',
|
|
216
|
+
options: INITIAL_OPTIONS,
|
|
217
|
+
editorDidMount: noop,
|
|
218
|
+
editorWillMount: noop,
|
|
219
|
+
onChange: noop,
|
|
220
|
+
requireConfig: {}
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
export var SingleMonacoEditorComponent = Object.assign(SingleMonacoEditor, {
|
|
224
|
+
displayName: 'SingleMonacoEditor',
|
|
225
|
+
defaultProps: {
|
|
226
|
+
width: '100%',
|
|
227
|
+
height: 150,
|
|
228
|
+
defaultValue: '',
|
|
229
|
+
language: 'javascript',
|
|
230
|
+
options: INITIAL_OPTIONS,
|
|
231
|
+
editorDidMount: noop,
|
|
232
|
+
editorWillMount: noop,
|
|
233
|
+
onChange: noop,
|
|
234
|
+
requireConfig: {}
|
|
235
|
+
},
|
|
236
|
+
MonacoDiffEditor: DiffMonacoEditorComponent
|
|
237
|
+
});
|
|
238
|
+
export default SingleMonacoEditorComponent;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Monaco } from '@monaco-editor/loader';
|
|
2
|
+
import { EditorMeta } from './controller';
|
|
3
|
+
export declare const getSingletonMonaco: (options?: any) => Promise<typeof import("monaco-editor")>;
|
|
4
|
+
export declare const getCommonMonaco: (config: any) => Promise<Monaco>;
|
|
5
|
+
export declare function getMonaco(config?: any): Promise<typeof import("monaco-editor")>;
|
|
6
|
+
export declare function configure(config: EditorMeta): void;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
2
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
3
|
+
import loader from '@monaco-editor/loader';
|
|
4
|
+
import { isEqual } from 'lodash-es';
|
|
5
|
+
import { controller } from "./controller";
|
|
6
|
+
export var getSingletonMonaco = function () {
|
|
7
|
+
var monaco;
|
|
8
|
+
var prevOptions;
|
|
9
|
+
return /*#__PURE__*/function () {
|
|
10
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(options) {
|
|
11
|
+
var hasConfig;
|
|
12
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
13
|
+
while (1) switch (_context.prev = _context.next) {
|
|
14
|
+
case 0:
|
|
15
|
+
if (!(!monaco || !isEqual(prevOptions, options))) {
|
|
16
|
+
_context.next = 7;
|
|
17
|
+
break;
|
|
18
|
+
}
|
|
19
|
+
hasConfig = Object.keys(options || {}).length > 0;
|
|
20
|
+
loader.config(hasConfig ? options : {
|
|
21
|
+
paths: {
|
|
22
|
+
vs: 'https://g.alicdn.com/code/lib/monaco-editor/0.33.0/min/vs'
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
// eslint-disable-next-line require-atomic-updates
|
|
26
|
+
_context.next = 5;
|
|
27
|
+
return loader.init();
|
|
28
|
+
case 5:
|
|
29
|
+
monaco = _context.sent;
|
|
30
|
+
// eslint-disable-next-line require-atomic-updates
|
|
31
|
+
prevOptions = options;
|
|
32
|
+
case 7:
|
|
33
|
+
return _context.abrupt("return", monaco);
|
|
34
|
+
case 8:
|
|
35
|
+
case "end":
|
|
36
|
+
return _context.stop();
|
|
37
|
+
}
|
|
38
|
+
}, _callee);
|
|
39
|
+
}));
|
|
40
|
+
return function (_x) {
|
|
41
|
+
return _ref.apply(this, arguments);
|
|
42
|
+
};
|
|
43
|
+
}();
|
|
44
|
+
}();
|
|
45
|
+
export var getCommonMonaco = function getCommonMonaco(config) {
|
|
46
|
+
if (config) {
|
|
47
|
+
loader.config(config);
|
|
48
|
+
} else {
|
|
49
|
+
loader.config({
|
|
50
|
+
paths: {
|
|
51
|
+
vs: 'https://g.alicdn.com/code/lib/monaco-editor/0.31.1/min/vs'
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
return loader.init();
|
|
56
|
+
};
|
|
57
|
+
export function getMonaco(config) {
|
|
58
|
+
var hasConfig = Object.keys(config || {}).length > 0;
|
|
59
|
+
var monacoConfig = hasConfig ? config : undefined;
|
|
60
|
+
return controller.getMeta().singleton ? getSingletonMonaco(monacoConfig) : getCommonMonaco(monacoConfig);
|
|
61
|
+
}
|
|
62
|
+
export function configure(config) {
|
|
63
|
+
controller.updateMeta(config);
|
|
64
|
+
}
|
|
@@ -4,7 +4,10 @@
|
|
|
4
4
|
export declare const useStyles: (props?: {
|
|
5
5
|
minimapEnabled?: boolean | undefined;
|
|
6
6
|
isFullScreen?: boolean | undefined;
|
|
7
|
+
diff?: boolean | undefined;
|
|
8
|
+
variant?: "filled" | "borderless" | "outlined" | undefined;
|
|
7
9
|
} | undefined) => import("antd-style").ReturnStyles<{
|
|
8
10
|
base: import("antd-style").SerializedStyles;
|
|
9
|
-
|
|
11
|
+
fullScreenBtn: import("antd-style").SerializedStyles;
|
|
12
|
+
loading: import("antd-style").SerializedStyles;
|
|
10
13
|
}>;
|