@yuntijs/ui 1.1.0-beta.12 → 1.1.0-beta.13
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/MonacoEditor/MonacoEditor2.d.ts +11 -0
- package/es/MonacoEditor/MonacoEditor2.js +103 -0
- package/es/index.d.ts +1 -0
- package/es/index.js +1 -0
- package/package.json +3 -2
- package/umd/index.min.js +1 -1
- package/umd/index.min.js.map +1 -1
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { EditorProps } from '@monaco-editor/react';
|
|
3
|
+
import type { Variant } from 'antd/es/config-provider';
|
|
4
|
+
export interface EditorProps2 extends EditorProps {
|
|
5
|
+
onBlur?: (input: string, event: any) => void;
|
|
6
|
+
placeholder?: string;
|
|
7
|
+
variant?: Variant;
|
|
8
|
+
enableOutline?: boolean;
|
|
9
|
+
version?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare const MonacoEditor2: React.FC<EditorProps2>;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
3
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
4
|
+
var _excluded = ["language", "theme", "placeholder", "variant", "onBlur", "enableOutline", "className", "version", "options", "onMount"];
|
|
5
|
+
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; }
|
|
6
|
+
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; }
|
|
7
|
+
import Editor, { loader } from '@monaco-editor/react';
|
|
8
|
+
import { Spin } from 'antd';
|
|
9
|
+
import { useEffect, useRef, useState } from 'react';
|
|
10
|
+
import { useCdnFn } from "../ConfigProvider";
|
|
11
|
+
import { useStyles } from "./base/style";
|
|
12
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
export var MonacoEditor2 = function MonacoEditor2(_ref) {
|
|
14
|
+
var _options$minimap;
|
|
15
|
+
var language = _ref.language,
|
|
16
|
+
theme = _ref.theme,
|
|
17
|
+
placeholder = _ref.placeholder,
|
|
18
|
+
variant = _ref.variant,
|
|
19
|
+
onBlur = _ref.onBlur,
|
|
20
|
+
enableOutline = _ref.enableOutline,
|
|
21
|
+
className = _ref.className,
|
|
22
|
+
_ref$version = _ref.version,
|
|
23
|
+
version = _ref$version === void 0 ? '0.52.2' : _ref$version,
|
|
24
|
+
_ref$options = _ref.options,
|
|
25
|
+
options = _ref$options === void 0 ? {} : _ref$options,
|
|
26
|
+
onMount = _ref.onMount,
|
|
27
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
28
|
+
var _useState = useState(false),
|
|
29
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
30
|
+
isFocus = _useState2[0],
|
|
31
|
+
setIsFocus = _useState2[1];
|
|
32
|
+
var editorRef = useRef(null);
|
|
33
|
+
var _useState3 = useState(false),
|
|
34
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
35
|
+
isMounted = _useState4[0],
|
|
36
|
+
setIsMounted = _useState4[1];
|
|
37
|
+
var _useState5 = useState(false),
|
|
38
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
39
|
+
configed = _useState6[0],
|
|
40
|
+
setConfiged = _useState6[1];
|
|
41
|
+
var _useStyles = useStyles({
|
|
42
|
+
minimapEnabled: options === null || options === void 0 || (_options$minimap = options.minimap) === null || _options$minimap === void 0 ? void 0 : _options$minimap.enabled,
|
|
43
|
+
variant: variant
|
|
44
|
+
}),
|
|
45
|
+
cx = _useStyles.cx,
|
|
46
|
+
styles = _useStyles.styles;
|
|
47
|
+
var classnames = cx(styles.base, className, {
|
|
48
|
+
've-focused': isFocus,
|
|
49
|
+
've-outline': enableOutline
|
|
50
|
+
});
|
|
51
|
+
var genCdnUrl = useCdnFn();
|
|
52
|
+
useEffect(function () {
|
|
53
|
+
loader.config({
|
|
54
|
+
paths: {
|
|
55
|
+
vs: genCdnUrl({
|
|
56
|
+
path: 'min/vs',
|
|
57
|
+
pkg: 'monaco-editor',
|
|
58
|
+
version: version
|
|
59
|
+
})
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
setConfiged(true);
|
|
63
|
+
}, [genCdnUrl, version]);
|
|
64
|
+
var handleEditorDidMount = function handleEditorDidMount(editor, monaco) {
|
|
65
|
+
editorRef.current = editor;
|
|
66
|
+
editor.onDidFocusEditorText(function () {
|
|
67
|
+
setIsFocus(true);
|
|
68
|
+
});
|
|
69
|
+
editor.onDidBlurEditorText(function (event) {
|
|
70
|
+
var _editorRef$current;
|
|
71
|
+
setIsFocus(false);
|
|
72
|
+
var value = (_editorRef$current = editorRef.current) === null || _editorRef$current === void 0 || (_editorRef$current = _editorRef$current.getModel()) === null || _editorRef$current === void 0 ? void 0 : _editorRef$current.getValue();
|
|
73
|
+
onBlur === null || onBlur === void 0 || onBlur(value !== null && value !== void 0 ? value : '', event);
|
|
74
|
+
});
|
|
75
|
+
monaco.editor.setTheme('default-theme'); // Fix: sometimes not load the default theme
|
|
76
|
+
onMount === null || onMount === void 0 || onMount(editor, monaco);
|
|
77
|
+
setIsMounted(true);
|
|
78
|
+
};
|
|
79
|
+
return /*#__PURE__*/_jsx(Spin, {
|
|
80
|
+
spinning: !configed,
|
|
81
|
+
children: configed ? /*#__PURE__*/_jsx(Editor, _objectSpread({
|
|
82
|
+
className: classnames,
|
|
83
|
+
language: language || 'text',
|
|
84
|
+
onMount: handleEditorDidMount,
|
|
85
|
+
options: _objectSpread({
|
|
86
|
+
domReadOnly: true,
|
|
87
|
+
quickSuggestions: false,
|
|
88
|
+
minimap: {
|
|
89
|
+
enabled: false
|
|
90
|
+
},
|
|
91
|
+
lineNumbersMinChars: 1,
|
|
92
|
+
// would change line num width
|
|
93
|
+
wordWrap: 'on',
|
|
94
|
+
// auto line wrap
|
|
95
|
+
unicodeHighlight: {
|
|
96
|
+
ambiguousCharacters: false
|
|
97
|
+
},
|
|
98
|
+
placeholder: placeholder
|
|
99
|
+
}, options),
|
|
100
|
+
theme: isMounted ? theme : 'default-theme' // sometimes not load the default theme
|
|
101
|
+
}, props)) : null
|
|
102
|
+
});
|
|
103
|
+
};
|
package/es/index.d.ts
CHANGED
package/es/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yuntijs/ui",
|
|
3
|
-
"version": "1.1.0-beta.
|
|
3
|
+
"version": "1.1.0-beta.13",
|
|
4
4
|
"description": "☁️ Yunti UI - an open-source UI component library for building Cloud Native web apps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"yuntijs",
|
|
@@ -89,7 +89,8 @@
|
|
|
89
89
|
"@lobehub/tts": "^1.25.1",
|
|
90
90
|
"@lobehub/ui": "^1.164.2",
|
|
91
91
|
"@melloware/react-logviewer": "^5.2.0",
|
|
92
|
-
"@monaco-editor/loader": "^1.
|
|
92
|
+
"@monaco-editor/loader": "^1.5.0",
|
|
93
|
+
"@monaco-editor/react": "^4.7.0",
|
|
93
94
|
"@shikijs/transformers": "^3.2.1",
|
|
94
95
|
"leva": "^0",
|
|
95
96
|
"lexical": "^0.23.1",
|