diff --git a/packages/amis-editor-core/src/component/Panel/CodeEditorPanel.tsx b/packages/amis-editor-core/src/component/Panel/CodeEditorPanel.tsx index d2b7f6941..ad33b8bfd 100644 --- a/packages/amis-editor-core/src/component/Panel/CodeEditorPanel.tsx +++ b/packages/amis-editor-core/src/component/Panel/CodeEditorPanel.tsx @@ -1,7 +1,8 @@ import React from 'react'; import {PanelProps} from '../../plugin'; -import {autobind} from '../../util'; +import {autobind, DiffChange} from '../../util'; import AMisCodeEditor from './AMisCodeEditor'; +import type {BaseSchema} from 'amis'; export default class CodeEditorPanel extends React.Component { @autobind @@ -23,10 +24,10 @@ export default class CodeEditorPanel extends React.Component { } @autobind - onChange(...rest: any) { + onChange(value: BaseSchema, diff?: Array) { const {store} = this.props; store.patchCodeEdit(true); - this.props.onChange(rest); + this.props.onChange(value, diff); store.patchCodeEdit(false); } diff --git a/packages/amis-editor-core/src/util.ts b/packages/amis-editor-core/src/util.ts index 54815e976..60b79925c 100644 --- a/packages/amis-editor-core/src/util.ts +++ b/packages/amis-editor-core/src/util.ts @@ -934,6 +934,24 @@ export function patchDiff(left: any, changes: Array | undefined) { ); } +/** + * 添加移动端单独编辑标识 + */ +function addMobileAttribute(path: Array) { + const editorStore = (window as any)?.editorStore; + + if ( + editorStore.isMobileAloneEdit && + editorStore.isMobile && + !editorStore.isCodeEditing && + !path.slice(-1)?.[0]?.startsWith?.('__') && + path[0] !== 'body' && + path[0] !== 'mobile' + ) { + path.unshift('mobile'); + } +} + /** * 因为左侧是个不可变动的对象,所以先 copy 了对应的属性,再传给 DeepDiff.applyChange */ @@ -947,6 +965,11 @@ function applyChange(target: any, source: any, change: DiffChange) { path.pop(); } + // pc 响应式页面,纯h5页面不处理 + if (change.kind === 'E' || change.kind === 'N') { + addMobileAttribute(path); + } + path.reduce( ({target, source}, key) => { const nextSource = source[key]; @@ -969,15 +992,9 @@ function applyChange(target: any, source: any, change: DiffChange) { source } ); - const editorStore = (window as any)?.editorStore; - // pc 响应式页面,纯h5页面不处理 - if ( - editorStore.isMobileAloneEdit && - editorStore.isMobile && - !editorStore.isCodeEditing - ) { - change.path.unshift('mobile'); - } + + // 一定要要再添加一遍 + addMobileAttribute(change.path); DeepDiff.applyChange(target, source, change); }