From 9446269317124c3f5f3e94527b756eadded7d3a1 Mon Sep 17 00:00:00 2001 From: pianruijie Date: Tue, 19 Jul 2022 21:22:58 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=B9=E6=A1=86=E6=94=AF=E6=8C=81=E9=80=89?= =?UTF-8?q?=E6=8B=A9=E5=A4=96=E9=83=A8=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ib8f64cedad9502f3c35169e782dc4df25450366d --- packages/amis-editor-core/src/component/Editor.tsx | 4 +++- .../amis-editor-core/src/component/Panel/RightPanels.tsx | 1 - packages/amis-editor-core/src/component/SubEditor.tsx | 5 ++++- packages/amis-editor-core/src/store/editor.ts | 8 +++++++- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/packages/amis-editor-core/src/component/Editor.tsx b/packages/amis-editor-core/src/component/Editor.tsx index 1ac128af5..335803d53 100644 --- a/packages/amis-editor-core/src/component/Editor.tsx +++ b/packages/amis-editor-core/src/component/Editor.tsx @@ -30,6 +30,7 @@ export interface EditorProps extends PluginEventListener { theme?: string; showCustomRenderersPanel?: boolean; amisDocHost?: string; + superEditorData?: any; withSuperDataSchema?: boolean; dataBindingChange?: ( value: string, @@ -114,8 +115,8 @@ export default class Editor extends Component { value, isSubEditor = false, onChange, - data, showCustomRenderersPanel, + superEditorData, ...rest } = props; @@ -129,6 +130,7 @@ export default class Editor extends Component { isSubEditor, amisDocHost: props.amisDocHost, ctx: props.ctx, + superEditorData }, config ); diff --git a/packages/amis-editor-core/src/component/Panel/RightPanels.tsx b/packages/amis-editor-core/src/component/Panel/RightPanels.tsx index 470eada3f..103bc363c 100644 --- a/packages/amis-editor-core/src/component/Panel/RightPanels.tsx +++ b/packages/amis-editor-core/src/component/Panel/RightPanels.tsx @@ -67,7 +67,6 @@ export class RightPanels extends React.Component< const id = store.activeId; const node = store.getNodeById(id); const panelKey = store.getPanelKey(); - const renderPanel = (panel: PanelItem) => { return panel.render ? ( panel.render({ diff --git a/packages/amis-editor-core/src/component/SubEditor.tsx b/packages/amis-editor-core/src/component/SubEditor.tsx index 13228c89f..81aabe83a 100644 --- a/packages/amis-editor-core/src/component/SubEditor.tsx +++ b/packages/amis-editor-core/src/component/SubEditor.tsx @@ -2,6 +2,8 @@ import React from 'react'; import {EditorManager} from '../manager'; import {EditorStoreType} from '../store/editor'; import {render} from 'amis'; +import {createObject} from 'amis-core'; + import {observer} from 'mobx-react'; import Editor from './Editor'; import { @@ -96,6 +98,7 @@ export class SubEditor extends React.Component { const {store, manager} = this.props; const subEditorContext = store.subEditorContext; const config = manager.config; + const superEditorData = store.isSubEditor ? createObject(store.superEditorData, store.subEditorContext?.data?.__super) : store.subEditorContext?.data?.__super; return { size: 'full', @@ -134,6 +137,7 @@ export class SubEditor extends React.Component { ref={store.subEditorRef} onChange={onChange} data={store.subEditorContext?.data} + superEditorData={superEditorData} schemaFilter={manager.config.schemaFilter} theme={manager.env.theme} afterResolveEditorInfo={this.afterResolveEditorInfo} @@ -200,7 +204,6 @@ export class SubEditor extends React.Component { render() { const {store, theme, manager} = this.props; - return render( { type: 'dialog', diff --git a/packages/amis-editor-core/src/store/editor.ts b/packages/amis-editor-core/src/store/editor.ts index 670a7527a..daf61c5f0 100644 --- a/packages/amis-editor-core/src/store/editor.ts +++ b/packages/amis-editor-core/src/store/editor.ts @@ -1,4 +1,4 @@ -import {findTree, getVariable, mapObject} from 'amis-core'; +import {findTree, getVariable, mapObject, createObject} from 'amis-core'; import {cast, getEnv, Instance, types} from 'mobx-state-tree'; import { diff, @@ -188,6 +188,8 @@ export const EditorStore = types // 弹出子编辑器相关的信息 subEditorContext: types.maybe(types.frozen()), + // 子编辑器中可能需要拿到父编辑器的数据 + superEditorData: types.maybe(types.frozen()), calculateStarted: false, @@ -846,6 +848,10 @@ export const EditorStore = types item => item.versionId === self.versionId ); return idx < self.schemaHistory.length - 1; + }, + + get getSuperEditorData() { + return self.superEditorData || {} } }; })