Merge remote-tracking branch 'origin/release/1.0.0' into refactor/code-style

# Conflicts:
#	packages/editor-setters/src/expression-setter/index.tsx
#	packages/plugin-source-editor/src/index.tsx
#	packages/plugin-source-editor/src/transform.ts
This commit is contained in:
wuji.xwt 2020-09-11 17:25:40 +08:00
commit 0a29c80928
5 changed files with 51 additions and 28 deletions

View File

@ -68,12 +68,13 @@ export default class ExpressionView extends PureComponent {
return val;
}
constructor(props: Readonly) {
constructor(props: Readonly<{}>) {
super(props);
this.expression = React.createRef();
this.i18n = generateI18n(props.locale, props.messages);
this.state = {
value: ExpressionView.getInitValue(props.value),
context: props.context || {},
dataSource: props.dataSource || [],
};
}
@ -126,23 +127,32 @@ export default class ExpressionView extends PureComponent {
* @return {Array}
*/
getDataSource(tempStr: string): any[] {
// eslint-disable-next-line no-useless-escape
if (/[^\w\.]$/.test(tempStr)) {
return [];
} else if (tempStr === null || tempStr === '') {
return this.getContextKeys([]);
} else if (/\w\.$/.test(tempStr)) {
const currentField = this.getCurrentFiled(tempStr);
if (!currentField) return null;
let tempKeys = this.getObjectKeys(currentField.str);
tempKeys = this.getContextKeys(tempKeys);
if (!tempKeys) return null;
return tempKeys;
} else if (/\.$/.test(tempStr)) {
return [];
} else {
return null;
const {editor} = this.props.field;
const schema = editor.get('designer').project.getSchema();
const stateMap = schema.componentsTree[0].state;
let dataSource = [];
for (let key in stateMap){
dataSource.push(`this.state.${key}`);
}
// if (/[^\w\.]$/.test(tempStr)) {
// return [];
// } else if (tempStr === null || tempStr === '') {
// return this.getContextKeys([]);
// } else if (/\w\.$/.test(tempStr)) {
// const currentField = this.getCurrentFiled(tempStr);
// if (!currentField) return null;
// let tempKeys = this.getObjectKeys(currentField.str);
// tempKeys = this.getContextKeys(tempKeys);
// if (!tempKeys) return null;
// return tempKeys;
// } else if (/\.$/.test(tempStr)) {
// return [];
// } else {
// return null;
// }
return dataSource;
}
/**

View File

@ -1,6 +1,6 @@
{
"name": "@ali/lowcode-plugin-source-editor",
"version": "1.0.8-0",
"version": "1.0.8-beta-1",
"description": "alibaba lowcode editor source-editor plugin",
"files": [
"es",

View File

@ -13,6 +13,12 @@
height: 100%;
}
.button-container{
position: absolute;
top: 0px;
right: 10px;
}
.editor-context-container{
height: 100%;
width: 100%;

View File

@ -14,7 +14,7 @@ const TAB_KEY = {
const defaultEditorOption = {
width: '100%',
height: '100%',
height: '95%',
options: {
readOnly: false,
automaticLayout: true,
@ -46,8 +46,6 @@ export default class SourceEditor extends Component<{
}> {
private monocoEditor;
private monocoEditorCss;
private editorCmd;
private editorJsRef = React.createRef();
@ -56,12 +54,17 @@ export default class SourceEditor extends Component<{
private editorNode;
private editorParentNode;
state = {
isFullScreen:false,
tabKey: TAB_KEY.JS_TAB,
isShowSaveBtn:true
};
// eslint-disable-next-line react/no-deprecated
componentWillMount() {
const { editor } = this.props;
// 添加函数
editor.on('sourceEditor.addFunction', (params: FunctionEventParam) => {
this.callEditorEvent('sourceEditor.addFunction', params);
@ -72,7 +75,6 @@ export default class SourceEditor extends Component<{
this.callEditorEvent('sourceEditor.focusByFunction', params);
});
// 插件面板关闭事件,监听规则同上
editor.on('skeleton.panel-dock.unactive', (pluginName) => {
if (pluginName == 'sourceEditor') {
@ -93,7 +95,6 @@ export default class SourceEditor extends Component<{
componentDidMount() {
this.editorNode = this.editorJsRef.current; // 记录当前dom节点
this.editorParentNode = this.editorNode.parentNode; // 记录父节点;
}
/**
@ -268,11 +269,12 @@ export default class SourceEditor extends Component<{
if (newSchema != '' && JSON.stringify(newSchema) != oldSchemaStr) {
editor.get('designer').project.setSchema(newSchema);
successFlag && Message.success('保存成功')
}
};
render() {
const { selectTab, jsCode, css } = this.state;
const { selectTab, jsCode, css ,isShowSaveBtn} = this.state;
const tabs = [
{ tab: 'index.js', key: TAB_KEY.JS_TAB },
{ tab: 'style.css', key: TAB_KEY.CSS_TAB },
@ -280,12 +282,13 @@ export default class SourceEditor extends Component<{
return (
<div className="source-editor-container">
<Tab size="small" shape="wrapped" onChange={this.onTabChange} activeKey={selectTab}>
{tabs.map((item) => (
<Tab.Item key={item.key} title={item.tab} />
))}
</Tab>
{ isShowSaveBtn && <div className="button-container"><Button type="primary" onClick={()=>this.saveSchema(successFlag)}></Button></div>}
<div style={{ height: '100%' }} className="editor-context-container">
<div id="jsEditorDom" className="editor-context" ref={this.editorJsRef}>

View File

@ -54,8 +54,12 @@ const transfrom = {
return `\n\t${functionName}(){\n\t}\n`;
},
setFunction2Schema(functionMap, schema) {
const pageNode = schema.componentsTree[0];
setFunction2Schema(functionMap, schema){
let pageNode = schema.componentsTree[0];
// 先清除原有的schema的值
delete pageNode.state;
pageNode.lifeCycles = {};
pageNode.methods = {};
if (!pageNode) return '';
for (const key in functionMap) {
if (key == 'state') {