@yuntijs/ui 1.0.0-beta.1 → 1.0.0-beta.2
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/ConfigProvider/index.d.ts +15 -0
- package/es/ConfigProvider/index.js +39 -0
- package/es/MonacoEditor/index.d.ts +31 -0
- package/es/MonacoEditor/index.js +104 -0
- package/es/index.d.ts +2 -0
- package/es/index.js +2 -0
- package/es/utils/genCdnUrl.d.ts +8 -0
- package/es/utils/genCdnUrl.js +20 -0
- package/package.json +5 -2
- package/umd/index.min.js +1 -1
- package/umd/index.min.js.map +1 -1
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ElementType, ReactNode } from 'react';
|
|
2
|
+
import { CDN, CdnApi } from "../utils/genCdnUrl";
|
|
3
|
+
type CdnFn = ({ pkg, version, path }: CdnApi) => string;
|
|
4
|
+
export interface Config {
|
|
5
|
+
customCdnFn?: CdnFn;
|
|
6
|
+
imgAs?: ElementType;
|
|
7
|
+
proxy?: CDN | 'custom';
|
|
8
|
+
}
|
|
9
|
+
export declare const ConfigContext: import("react").Context<Config | null>;
|
|
10
|
+
export declare const ConfigProvider: import("react").NamedExoticComponent<{
|
|
11
|
+
children: ReactNode;
|
|
12
|
+
config: Config;
|
|
13
|
+
}>;
|
|
14
|
+
export declare const useCdnFn: () => CdnFn;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { createContext, memo, useContext } from 'react';
|
|
2
|
+
import { genCdnUrl } from "../utils/genCdnUrl";
|
|
3
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
|
+
export var ConfigContext = /*#__PURE__*/createContext(null);
|
|
5
|
+
export var ConfigProvider = /*#__PURE__*/memo(function (_ref) {
|
|
6
|
+
var children = _ref.children,
|
|
7
|
+
config = _ref.config;
|
|
8
|
+
return /*#__PURE__*/_jsx(ConfigContext.Provider, {
|
|
9
|
+
value: config,
|
|
10
|
+
children: children
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
var fallback = function fallback(_ref2) {
|
|
14
|
+
var pkg = _ref2.pkg,
|
|
15
|
+
version = _ref2.version,
|
|
16
|
+
path = _ref2.path;
|
|
17
|
+
return genCdnUrl({
|
|
18
|
+
path: path,
|
|
19
|
+
pkg: pkg,
|
|
20
|
+
proxy: 'aliyun',
|
|
21
|
+
version: version
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
export var useCdnFn = function useCdnFn() {
|
|
25
|
+
var config = useContext(ConfigContext);
|
|
26
|
+
if (!config) return fallback;
|
|
27
|
+
if ((config === null || config === void 0 ? void 0 : config.proxy) !== 'custom') return function (_ref3) {
|
|
28
|
+
var pkg = _ref3.pkg,
|
|
29
|
+
version = _ref3.version,
|
|
30
|
+
path = _ref3.path;
|
|
31
|
+
return genCdnUrl({
|
|
32
|
+
path: path,
|
|
33
|
+
pkg: pkg,
|
|
34
|
+
proxy: config.proxy,
|
|
35
|
+
version: version
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
return (config === null || config === void 0 ? void 0 : config.customCdnFn) || fallback;
|
|
39
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { IDiffMonacoEditorProps, IGeneralManacoEditorProps, ISingleMonacoEditorProps } from '@alilc/lowcode-plugin-base-monaco-editor/lib/helper';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
export * from '@alilc/lowcode-plugin-base-monaco-editor/es/controller';
|
|
4
|
+
export * from '@alilc/lowcode-plugin-base-monaco-editor/es/monaco';
|
|
5
|
+
export interface BaseMonacoEditorProps extends IGeneralManacoEditorProps {
|
|
6
|
+
/** Should the editor be read only. See also domReadOnly. Defaults to false. */
|
|
7
|
+
readOnly?: boolean;
|
|
8
|
+
/** Control the rendering of line numbers. Defaults to on. */
|
|
9
|
+
lineNumbers?: 'on' | 'off' | 'relative' | 'interval' | ((lineNumber: number) => string);
|
|
10
|
+
/** Control the wrapping of the editor. Defaults to off. */
|
|
11
|
+
wordWrap?: 'off' | 'on' | 'wordWrapColumn' | 'bounded';
|
|
12
|
+
/** Enable custom contextmenu. Defaults to true. */
|
|
13
|
+
contextmenu?: boolean;
|
|
14
|
+
/** Enable the rendering of the minimap. Defaults to false. */
|
|
15
|
+
minimapEnabled?: boolean;
|
|
16
|
+
/** Control the version of monaco-editor be loaded. Defaults to 0.45.0 */
|
|
17
|
+
version?: string;
|
|
18
|
+
/** An event emitted when the content of the current model has changed. */
|
|
19
|
+
onChange?: (input: string, event: any) => void;
|
|
20
|
+
}
|
|
21
|
+
export declare const BaseMonacoEditor: React.FC<BaseMonacoEditorProps & {
|
|
22
|
+
/** Only for BaseMonacoEditor. */
|
|
23
|
+
type?: 'single' | 'diff';
|
|
24
|
+
}>;
|
|
25
|
+
export type MonacoEditorProps = ISingleMonacoEditorProps & BaseMonacoEditorProps;
|
|
26
|
+
export declare const MonacoEditor: React.FC<MonacoEditorProps>;
|
|
27
|
+
export type MonacoDiffEditorProps = IDiffMonacoEditorProps & BaseMonacoEditorProps & {
|
|
28
|
+
/** Render the differences in one editor. Defaults to off, render the differences in two side-by-side editors */
|
|
29
|
+
inlineView?: 'on' | 'off' | 'auto';
|
|
30
|
+
};
|
|
31
|
+
export declare const MonacoDiffEditor: React.FC<MonacoDiffEditorProps>;
|
|
@@ -0,0 +1,104 @@
|
|
|
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 = ["type", "editorDidMount", "readOnly", "lineNumbers", "wordWrap", "contextmenu", "minimapEnabled", "version", "requireConfig", "options", "onChange"],
|
|
5
|
+
_excluded2 = ["inlineView", "options"];
|
|
6
|
+
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; }
|
|
7
|
+
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; }
|
|
8
|
+
import { SingleMonacoEditorComponent } from '@alilc/lowcode-plugin-base-monaco-editor';
|
|
9
|
+
import React, { useMemo, useState } from 'react';
|
|
10
|
+
import { useCdnFn } from '..';
|
|
11
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
12
|
+
export * from '@alilc/lowcode-plugin-base-monaco-editor/es/controller';
|
|
13
|
+
export * from '@alilc/lowcode-plugin-base-monaco-editor/es/monaco';
|
|
14
|
+
export var BaseMonacoEditor = function BaseMonacoEditor(props) {
|
|
15
|
+
var _props$type = props.type,
|
|
16
|
+
type = _props$type === void 0 ? 'single' : _props$type,
|
|
17
|
+
editorDidMount = props.editorDidMount,
|
|
18
|
+
_props$readOnly = props.readOnly,
|
|
19
|
+
readOnly = _props$readOnly === void 0 ? false : _props$readOnly,
|
|
20
|
+
_props$lineNumbers = props.lineNumbers,
|
|
21
|
+
lineNumbers = _props$lineNumbers === void 0 ? 'on' : _props$lineNumbers,
|
|
22
|
+
_props$wordWrap = props.wordWrap,
|
|
23
|
+
wordWrap = _props$wordWrap === void 0 ? 'off' : _props$wordWrap,
|
|
24
|
+
_props$contextmenu = props.contextmenu,
|
|
25
|
+
contextmenu = _props$contextmenu === void 0 ? true : _props$contextmenu,
|
|
26
|
+
_props$minimapEnabled = props.minimapEnabled,
|
|
27
|
+
minimapEnabled = _props$minimapEnabled === void 0 ? false : _props$minimapEnabled,
|
|
28
|
+
_props$version = props.version,
|
|
29
|
+
version = _props$version === void 0 ? '0.45.0' : _props$version,
|
|
30
|
+
_props$requireConfig = props.requireConfig,
|
|
31
|
+
requireConfigFromProps = _props$requireConfig === void 0 ? {} : _props$requireConfig,
|
|
32
|
+
options = props.options,
|
|
33
|
+
onChange = props.onChange,
|
|
34
|
+
otherProps = _objectWithoutProperties(props, _excluded);
|
|
35
|
+
var _useState = useState(),
|
|
36
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
37
|
+
editorInstance = _useState2[0],
|
|
38
|
+
setEditorInstance = _useState2[1];
|
|
39
|
+
var handleEditorDidMount = function handleEditorDidMount(monaco, editor) {
|
|
40
|
+
setEditorInstance(editor);
|
|
41
|
+
editorDidMount === null || editorDidMount === void 0 || editorDidMount(monaco, editor);
|
|
42
|
+
// add onChange event for diff editor
|
|
43
|
+
if (type === 'diff') {
|
|
44
|
+
var _ref = editor.getModel(),
|
|
45
|
+
modified = _ref.modified;
|
|
46
|
+
modified.onDidChangeContent(function (event) {
|
|
47
|
+
onChange === null || onChange === void 0 || onChange(modified.getValue(), event);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
// @Todo: auto change light/dark theme
|
|
53
|
+
var editorOptions = useMemo(function () {
|
|
54
|
+
var newOps = Object.assign({}, options, {
|
|
55
|
+
readOnly: readOnly,
|
|
56
|
+
lineNumbers: lineNumbers,
|
|
57
|
+
wordWrap: wordWrap,
|
|
58
|
+
contextmenu: contextmenu,
|
|
59
|
+
minimap: minimapEnabled === undefined ? options === null || options === void 0 ? void 0 : options.minimap : Object.assign({}, options === null || options === void 0 ? void 0 : options.minimap, {
|
|
60
|
+
enabled: minimapEnabled
|
|
61
|
+
})
|
|
62
|
+
});
|
|
63
|
+
editorInstance === null || editorInstance === void 0 || editorInstance.updateOptions(newOps);
|
|
64
|
+
return newOps;
|
|
65
|
+
}, [readOnly, lineNumbers, wordWrap, contextmenu, minimapEnabled, options]);
|
|
66
|
+
var genCdnUrl = useCdnFn();
|
|
67
|
+
var requireConfig = useMemo(function () {
|
|
68
|
+
return Object.assign({}, requireConfigFromProps, {
|
|
69
|
+
paths: _objectSpread({
|
|
70
|
+
vs: genCdnUrl({
|
|
71
|
+
path: 'min/vs',
|
|
72
|
+
pkg: 'monaco-editor',
|
|
73
|
+
version: version
|
|
74
|
+
})
|
|
75
|
+
}, requireConfigFromProps.paths)
|
|
76
|
+
});
|
|
77
|
+
}, [requireConfigFromProps, version]);
|
|
78
|
+
var Editor = type === 'diff' ? SingleMonacoEditorComponent.MonacoDiffEditor : SingleMonacoEditorComponent;
|
|
79
|
+
return /*#__PURE__*/_jsx(Editor, _objectSpread({
|
|
80
|
+
editorDidMount: handleEditorDidMount,
|
|
81
|
+
onChange: onChange,
|
|
82
|
+
options: editorOptions,
|
|
83
|
+
requireConfig: requireConfig
|
|
84
|
+
}, otherProps));
|
|
85
|
+
};
|
|
86
|
+
export var MonacoEditor = function MonacoEditor(props) {
|
|
87
|
+
return /*#__PURE__*/_jsx(BaseMonacoEditor, _objectSpread(_objectSpread({}, props), {}, {
|
|
88
|
+
type: "single"
|
|
89
|
+
}));
|
|
90
|
+
};
|
|
91
|
+
export var MonacoDiffEditor = function MonacoDiffEditor(props) {
|
|
92
|
+
var _props$inlineView = props.inlineView,
|
|
93
|
+
inlineView = _props$inlineView === void 0 ? 'off' : _props$inlineView,
|
|
94
|
+
options = props.options,
|
|
95
|
+
otherProps = _objectWithoutProperties(props, _excluded2);
|
|
96
|
+
return /*#__PURE__*/_jsx(BaseMonacoEditor, _objectSpread(_objectSpread({
|
|
97
|
+
options: Object.assign({
|
|
98
|
+
useInlineViewWhenSpaceIsLimited: inlineView === 'on' || inlineView === 'auto',
|
|
99
|
+
renderSideBySide: inlineView === 'off' || inlineView === 'auto'
|
|
100
|
+
}, options)
|
|
101
|
+
}, otherProps), {}, {
|
|
102
|
+
type: "diff"
|
|
103
|
+
}));
|
|
104
|
+
};
|
package/es/index.d.ts
CHANGED
package/es/index.js
CHANGED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import urlJoin from 'url-join';
|
|
2
|
+
var UNPKG_API = 'https://unpkg.com';
|
|
3
|
+
var ALIYUN_API = 'https://registry.npmmirror.com';
|
|
4
|
+
export var genCdnUrl = function genCdnUrl(_ref) {
|
|
5
|
+
var pkg = _ref.pkg,
|
|
6
|
+
_ref$version = _ref.version,
|
|
7
|
+
version = _ref$version === void 0 ? 'latest' : _ref$version,
|
|
8
|
+
path = _ref.path,
|
|
9
|
+
proxy = _ref.proxy;
|
|
10
|
+
switch (proxy) {
|
|
11
|
+
case 'unpkg':
|
|
12
|
+
{
|
|
13
|
+
return urlJoin(UNPKG_API, "".concat(pkg, "@").concat(version), path);
|
|
14
|
+
}
|
|
15
|
+
default:
|
|
16
|
+
{
|
|
17
|
+
return urlJoin(ALIYUN_API, pkg, version, 'files', path);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yuntijs/ui",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.2",
|
|
4
4
|
"description": "☁️ Yunti UI - an open-source UI component library for building Cloud Native web apps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"yuntijs",
|
|
@@ -77,6 +77,7 @@
|
|
|
77
77
|
]
|
|
78
78
|
},
|
|
79
79
|
"dependencies": {
|
|
80
|
+
"@alilc/lowcode-plugin-base-monaco-editor": "^1.1.2",
|
|
80
81
|
"@ant-design/icons": "^5",
|
|
81
82
|
"@babel/runtime": "^7",
|
|
82
83
|
"@lobehub/ui": "^1",
|
|
@@ -85,7 +86,8 @@
|
|
|
85
86
|
"lucide-react": "latest",
|
|
86
87
|
"query-string": "^8",
|
|
87
88
|
"react-error-boundary": "^4",
|
|
88
|
-
"react-layout-kit": "^1"
|
|
89
|
+
"react-layout-kit": "^1",
|
|
90
|
+
"url-join": "^5.0.0"
|
|
89
91
|
},
|
|
90
92
|
"devDependencies": {
|
|
91
93
|
"@testing-library/react": "^14",
|
|
@@ -107,6 +109,7 @@
|
|
|
107
109
|
"jest": "^27",
|
|
108
110
|
"jsdom": "^22",
|
|
109
111
|
"lint-staged": "^15",
|
|
112
|
+
"monaco-editor": "^0.45.0",
|
|
110
113
|
"prettier": "^3",
|
|
111
114
|
"react": "^18",
|
|
112
115
|
"react-dom": "^18",
|