Skip to content

Commit

Permalink
fix: 修复编辑器预览模式弹窗的上下文信息会丢失的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
hsm-lv committed Jul 9, 2024
1 parent f16b3ad commit 2f0918e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/amis-editor-core/src/component/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,14 @@ export default class Editor extends Component<EditorProps> {
theme: props.theme,
isSubEditor,
amisDocHost: props.amisDocHost,
ctx: props.ctx,
superEditorData,
appLocale: props.appLocale,
appCorpusData: props?.amisEnv?.replaceText,
i18nEnabled: props?.i18nEnabled ?? false
},
config
);
this.store.setCtx(props.ctx);
this.store.setSchema(value);
if (showCustomRenderersPanel !== undefined) {
this.store.setShowCustomRenderersPanel(showCustomRenderersPanel);
Expand Down
3 changes: 2 additions & 1 deletion packages/amis-editor-core/src/component/IFramePreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ export default class IFramePreview extends React.Component<IFramePreviewProps> {
...rest,
key: editable ? 'edit-mode' : 'preview-mode',
theme: env.theme,
data: data ?? store.ctx,
data: data,
context: store.ctx,
locale: appLocale,
editorDialogMountNode: this.getDialogMountRef
},
Expand Down
3 changes: 2 additions & 1 deletion packages/amis-editor-core/src/component/Preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,8 @@ class SmartPreview extends React.Component<SmartPreviewProps> {
...rest,
key: editable ? 'edit-mode' : 'preview-mode',
theme: env.theme,
data: data ?? store.ctx,
data: data,
context: store.ctx,
locale: appLocale,
editorDialogMountNode: this.getDialogMountRef
},
Expand Down
12 changes: 11 additions & 1 deletion packages/amis-editor-core/src/store/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {
mapTree,
eachTree,
extendObject,
createObject
createObject,
extractObjectChain
} from 'amis-core';
import {cast, getEnv, Instance, types} from 'mobx-state-tree';
import {
Expand Down Expand Up @@ -1060,6 +1061,15 @@ export const MainStore = types
},

setCtx(value: any) {
if (value?.__super) {
// context 不支持链式,如果这样下发了,需要转成普通对象。
// 目前平台会下发这种数据,为了防止数据丢失做个处理
value = extractObjectChain(value).reduce(
(obj, item) => Object.assign(obj, item),
{}
);
}

self.ctx = value;
},

Expand Down

0 comments on commit 2f0918e

Please sign in to comment.