mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-01-15 18:58:11 +00:00
feat: 🎸 完善 utils 面板, 默认不用传入类型则表示支持NPM, TNPM 和 function 类型
This commit is contained in:
parent
425c24d03b
commit
3e9a445001
@ -24,6 +24,11 @@
|
|||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@ali/lowcode-editor-core": "^1.0.8-0",
|
"@ali/lowcode-editor-core": "^1.0.8-0",
|
||||||
|
"@formily/next": "^1.3.2",
|
||||||
|
"@formily/next-components": "^1.3.2",
|
||||||
|
"@formily/react-schema-renderer": "^1.3.2",
|
||||||
|
"react-monaco-editor": "^0.40.0",
|
||||||
|
"styled-components": "^5.2.0",
|
||||||
"prop-types": "^15.5.8",
|
"prop-types": "^15.5.8",
|
||||||
"react": "^16.8.1",
|
"react": "^16.8.1",
|
||||||
"react-dom": "^16.8.1",
|
"react-dom": "^16.8.1",
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import noop from 'lodash/noop';
|
|||||||
export interface JSFunctionProps {
|
export interface JSFunctionProps {
|
||||||
className: string;
|
className: string;
|
||||||
value: string;
|
value: string;
|
||||||
|
defaultValue: string;
|
||||||
onChange?: (val: string) => void;
|
onChange?: (val: string) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -21,6 +22,29 @@ class InternalJSFunction extends PureComponent<JSFunctionProps, unknown> {
|
|||||||
|
|
||||||
private monacoRef: MonacoRef | null = null;
|
private monacoRef: MonacoRef | null = null;
|
||||||
|
|
||||||
|
componentDidMount() {
|
||||||
|
const { value, defaultValue, onChange } = this.props;
|
||||||
|
|
||||||
|
if (!value && defaultValue && onChange) {
|
||||||
|
onChange(defaultValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const { value, defaultValue } = this.props;
|
||||||
|
return (
|
||||||
|
<MonacoEditor
|
||||||
|
theme="vs-dark"
|
||||||
|
width={400}
|
||||||
|
height={150}
|
||||||
|
defaultValue={value || defaultValue}
|
||||||
|
language="js"
|
||||||
|
onChange={this.handleEditorChange}
|
||||||
|
editorWillMount={this.handleEditorWillMount}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
private handleEditorChange = () => {
|
private handleEditorChange = () => {
|
||||||
if (
|
if (
|
||||||
this.monacoRef &&
|
this.monacoRef &&
|
||||||
@ -35,21 +59,6 @@ class InternalJSFunction extends PureComponent<JSFunctionProps, unknown> {
|
|||||||
private handleEditorWillMount: EditorWillMount = (monaco) => {
|
private handleEditorWillMount: EditorWillMount = (monaco) => {
|
||||||
this.monacoRef = monaco;
|
this.monacoRef = monaco;
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
|
||||||
const { value } = this.props;
|
|
||||||
return (
|
|
||||||
<MonacoEditor
|
|
||||||
theme="vs-dark"
|
|
||||||
width={400}
|
|
||||||
height={150}
|
|
||||||
defaultValue={value}
|
|
||||||
language="js"
|
|
||||||
onChange={this.handleEditorChange}
|
|
||||||
editorWillMount={this.handleEditorWillMount}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const JSFunction = connect()(InternalJSFunction);
|
export const JSFunction = connect()(InternalJSFunction);
|
||||||
|
|||||||
@ -13,7 +13,7 @@ export interface UtilsPaneProps extends PluginProps {
|
|||||||
/**
|
/**
|
||||||
* 支持的 Util 的类型
|
* 支持的 Util 的类型
|
||||||
*/
|
*/
|
||||||
utilsTypes: UtilTypeInfo[];
|
utilsTypes?: UtilTypeInfo[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 初始的 Utils (若 schema 中尚未定义 utils)
|
* 初始的 Utils (若 schema 中尚未定义 utils)
|
||||||
|
|||||||
@ -51,7 +51,7 @@ export class UtilList extends PureComponent<UtilsListProps, State> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private handleRemoveDataSource = (id: any) => {
|
private handleRemoveUtilItem = (id: any) => {
|
||||||
if (this.props.onRemoveUtil) {
|
if (this.props.onRemoveUtil) {
|
||||||
this.props.onRemoveUtil(id);
|
this.props.onRemoveUtil(id);
|
||||||
}
|
}
|
||||||
@ -103,7 +103,7 @@ export class UtilList extends PureComponent<UtilsListProps, State> {
|
|||||||
复制
|
复制
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
<Button size="small" onClick={this.handleRemoveDataSource.bind(this, item.name)}>
|
<Button size="small" onClick={this.handleRemoveUtilItem.bind(this, item.name)}>
|
||||||
删除
|
删除
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -136,7 +136,7 @@ export class UtilsPane extends PureComponent<UtilsPaneProps, State> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.openEditDataSourceTab(cloneDeep(targetUtil));
|
this.openEditItemTab(cloneDeep(targetUtil));
|
||||||
};
|
};
|
||||||
|
|
||||||
private handleTabChange = (activeTabKey: string | number) => {
|
private handleTabChange = (activeTabKey: string | number) => {
|
||||||
@ -165,19 +165,19 @@ export class UtilsPane extends PureComponent<UtilsPaneProps, State> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private handleCreateItemBtnClick = (dataSourceType: string) => {
|
private handleCreateItemBtnClick = (utilType: string) => {
|
||||||
this.openCreateItemTab({
|
this.openCreateItemTab({
|
||||||
type: dataSourceType as UtilItem['type'],
|
type: utilType as UtilItem['type'],
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
private handleCreateItemMenuBtnClick = (dataSourceType: string) => {
|
private handleCreateItemMenuBtnClick = (utilType: string) => {
|
||||||
this.openCreateItemTab({
|
this.openCreateItemTab({
|
||||||
type: dataSourceType as UtilItem['type'],
|
type: utilType as UtilItem['type'],
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
private openEditDataSourceTab = (utilItem: UtilItem) => {
|
private openEditItemTab = (utilItem: UtilItem) => {
|
||||||
const { tabItems } = this.state;
|
const { tabItems } = this.state;
|
||||||
|
|
||||||
if (!tabItems.find((item) => item.key === PaneTabKey.Edit)) {
|
if (!tabItems.find((item) => item.key === PaneTabKey.Edit)) {
|
||||||
@ -287,7 +287,7 @@ export class UtilsPane extends PureComponent<UtilsPaneProps, State> {
|
|||||||
const { activeTabKey, tabItems } = this.state;
|
const { activeTabKey, tabItems } = this.state;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="lowcode-plugin-datasource-pane">
|
<div className="lowcode-plugin-utils-pane">
|
||||||
<Tab
|
<Tab
|
||||||
activeKey={activeTabKey}
|
activeKey={activeTabKey}
|
||||||
extra={this.renderTabExtraContent()}
|
extra={this.renderTabExtraContent()}
|
||||||
|
|||||||
@ -1,31 +1,31 @@
|
|||||||
import { UtilItem } from '@ali/lowcode-types';
|
import { UtilItem } from '@ali/lowcode-types';
|
||||||
|
|
||||||
export const DEFAULT_UTILS: UtilItem[] = [
|
export const DEFAULT_UTILS: UtilItem[] = [
|
||||||
{
|
// {
|
||||||
type: 'npm',
|
// type: 'npm',
|
||||||
name: 'clone',
|
// name: 'clone',
|
||||||
content: {
|
// content: {
|
||||||
package: 'lodash',
|
// package: 'lodash',
|
||||||
destructuring: true,
|
// destructuring: true,
|
||||||
},
|
// },
|
||||||
},
|
// },
|
||||||
{
|
// {
|
||||||
type: 'npm',
|
// type: 'npm',
|
||||||
name: 'moment',
|
// name: 'moment',
|
||||||
content: {
|
// content: {
|
||||||
package: 'moment',
|
// package: 'moment',
|
||||||
destructuring: false,
|
// destructuring: false,
|
||||||
},
|
// },
|
||||||
},
|
// },
|
||||||
{
|
// {
|
||||||
type: 'function',
|
// type: 'function',
|
||||||
name: 'record',
|
// name: 'record',
|
||||||
content: {
|
// content: {
|
||||||
type: 'JSFunction',
|
// type: 'JSFunction',
|
||||||
value: `function(logkey, gmkey, gokey, reqMethod) {
|
// value: `function(logkey, gmkey, gokey, reqMethod) {
|
||||||
goldlog.record('/demo.event.' + logkey, gmkey, gokey, reqMethod);
|
// goldlog.record('/demo.event.' + logkey, gmkey, gokey, reqMethod);
|
||||||
}
|
// }
|
||||||
`,
|
// `,
|
||||||
},
|
// },
|
||||||
},
|
// },
|
||||||
];
|
];
|
||||||
|
|||||||
@ -9,8 +9,8 @@ import React, { PureComponent } from 'react';
|
|||||||
import { JSFunction } from './form-components';
|
import { JSFunction } from './form-components';
|
||||||
|
|
||||||
registerValidationFormats({
|
registerValidationFormats({
|
||||||
util_npm_version_format: /^\d+\.\d+\.\d+(-[a-z0-9-]+(\.[a-z0-9]+))?$/i,
|
util_npm_version_format: /^\d+\.\d+\.\d+(-[a-z0-9-]+(\.[a-z0-9]+))?$/i, // 版本号的规范
|
||||||
util_name_js_identifier: /[a-z$_][a-z$_0-9]+/i,
|
util_name_js_identifier: /^[a-z$_][a-z$_0-9]*$/i, // JS 标识符的规范
|
||||||
});
|
});
|
||||||
|
|
||||||
type FlatUtilItem = {
|
type FlatUtilItem = {
|
||||||
@ -160,7 +160,7 @@ export class UtilsForm extends PureComponent<UtilsFormProps, unknown> {
|
|||||||
const { item } = this.props;
|
const { item } = this.props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="lowcode-plugin-datasource-form">
|
<div className="lowcode-plugin-utils-form">
|
||||||
<SchemaForm
|
<SchemaForm
|
||||||
onSubmit={this.handleFormSubmit}
|
onSubmit={this.handleFormSubmit}
|
||||||
components={this.formComponents}
|
components={this.formComponents}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user