diff --git a/packages/demo/public/schema.json b/packages/demo/public/schema.json index 8e4dfdbe6..6b35b37cf 100644 --- a/packages/demo/public/schema.json +++ b/packages/demo/public/schema.json @@ -19,12 +19,14 @@ "value": "function() {\n \t\tconsole.log('will umount');\n\t}" } }, + "methods": { "testFunc": { "type": "JSFunction", - "value": "function() { console.log('test func');}" + "value": "function() {console.log('test func');}" } }, + "props": { "ref": "outterView", "autoLoading": true, diff --git a/packages/editor-setters/src/events-setter/index.tsx b/packages/editor-setters/src/events-setter/index.tsx index 0783b8bb9..92f4eb319 100644 --- a/packages/editor-setters/src/events-setter/index.tsx +++ b/packages/editor-setters/src/events-setter/index.tsx @@ -268,9 +268,19 @@ export default class EventsSetter extends Component<{ onRelatedEventNameClick = (eventName:String) => { const {editor} = this.props.field; - editor.emit('sourceEditor.focusByFunction',{ - functionName:eventName - }) + + editor.get('skeleton').getPanel('sourceEditor').show(); + + setTimeout(()=>{ + editor.emit('sourceEditor.focusByFunction',{ + functionName:eventName + }) + },300) + + + // editor.emit('sourceEditor.focusByFunction',{ + // functionName:eventName + // }) } closeEventMenu = () => { @@ -324,6 +334,7 @@ export default class EventsSetter extends Component<{ eventDataList }) + this.props.onChange(eventDataList); //this.closeDialog(); diff --git a/packages/plugin-source-editor/src/index.tsx b/packages/plugin-source-editor/src/index.tsx index bf80b6081..642b031ad 100644 --- a/packages/plugin-source-editor/src/index.tsx +++ b/packages/plugin-source-editor/src/index.tsx @@ -99,16 +99,6 @@ export default class SourceEditor extends Component<{ //}); } - componentDidMount() {} - - openPluginPannel = () => { - const { editor } = this.props; - // 判断面板是否处于激活状态 - if (!editor.leftNav || editor.leftNav != 'sourceEditor') { - // 打开面板 - editor.emit('leftNav.change', 'sourceEditor'); - } - }; /** * 执行编辑器事件 @@ -122,7 +112,6 @@ export default class SourceEditor extends Component<{ return; } - debugger; if (this.state.selectTab == TAB_KEY.CSS_TAB) { this.setState({ selectTab: TAB_KEY.JS_TAB, @@ -173,7 +162,6 @@ export default class SourceEditor extends Component<{ this.monocoEditor.focus(); }, 100); - debugger; this.updateCode(this.monocoEditor.getModel().getValue()); } @@ -213,6 +201,10 @@ export default class SourceEditor extends Component<{ } onTabChange = (key) => { + const { editor } = this.props; + let schema = editor.get('designer').project.getSchema(); + console.log(schema); + this.setState({ selectTab: key, }); diff --git a/packages/plugin-source-editor/src/transform.ts b/packages/plugin-source-editor/src/transform.ts index 24a71ed0c..afb761381 100644 --- a/packages/plugin-source-editor/src/transform.ts +++ b/packages/plugin-source-editor/src/transform.ts @@ -59,7 +59,15 @@ const transfrom = { setFunction2Schema(functionMap,schema){ let pageNode = schema.componentsTree[0]; - pageNode.state = functionMap.state; + for (let key in functionMap){ + if (key == 'state'){ + pageNode.state = functionMap[key]; + }else{ + if (LIFECYCLES_FUNCTION_MAP.react.indexOf(key)>=0){ + // 判断有没有lifecycles节点 + } + } + } } }; @@ -104,7 +112,7 @@ function initMethodsCode(componentSchema: Object) { } function createFunctionCode(functionName: String, functionNode: Object) { - if (functionNode.type === 'JSExpression') { + if (functionNode.type === 'JSExpression' || functionNode.type === 'JSFunction') { let functionCode = functionNode.value; functionCode = functionCode.replace(/function/, functionName); return functionCode;