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; return val;
} }
constructor(props: Readonly) { constructor(props: Readonly<{}>) {
super(props); super(props);
this.expression = React.createRef(); this.expression = React.createRef();
this.i18n = generateI18n(props.locale, props.messages); this.i18n = generateI18n(props.locale, props.messages);
this.state = { this.state = {
value: ExpressionView.getInitValue(props.value), value: ExpressionView.getInitValue(props.value),
context: props.context || {},
dataSource: props.dataSource || [], dataSource: props.dataSource || [],
}; };
} }
@ -126,23 +127,32 @@ export default class ExpressionView extends PureComponent {
* @return {Array} * @return {Array}
*/ */
getDataSource(tempStr: string): any[] { getDataSource(tempStr: string): any[] {
// eslint-disable-next-line no-useless-escape const {editor} = this.props.field;
if (/[^\w\.]$/.test(tempStr)) { const schema = editor.get('designer').project.getSchema();
return []; const stateMap = schema.componentsTree[0].state;
} else if (tempStr === null || tempStr === '') { let dataSource = [];
return this.getContextKeys([]);
} else if (/\w\.$/.test(tempStr)) { for (let key in stateMap){
const currentField = this.getCurrentFiled(tempStr); dataSource.push(`this.state.${key}`);
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;
} }
// 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", "name": "@ali/lowcode-plugin-source-editor",
"version": "1.0.8-0", "version": "1.0.8-beta-1",
"description": "alibaba lowcode editor source-editor plugin", "description": "alibaba lowcode editor source-editor plugin",
"files": [ "files": [
"es", "es",

View File

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

View File

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

View File

@ -55,7 +55,11 @@ const transfrom = {
}, },
setFunction2Schema(functionMap, schema){ setFunction2Schema(functionMap, schema){
const pageNode = schema.componentsTree[0]; let pageNode = schema.componentsTree[0];
// 先清除原有的schema的值
delete pageNode.state;
pageNode.lifeCycles = {};
pageNode.methods = {};
if (!pageNode) return ''; if (!pageNode) return '';
for (const key in functionMap) { for (const key in functionMap) {
if (key == 'state') { if (key == 'state') {