From 0f14884bf175c0cc854c4a2688f004717f5f4907 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8A=9B=E7=9A=93?= Date: Thu, 3 Dec 2020 20:08:24 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20setDevice=20?= =?UTF-8?q?=E7=9A=84=E6=97=B6=E6=9C=BA=EF=BC=8C=E4=BB=8E=20currentDocument?= =?UTF-8?q?=20->=20simualtor=20fix:=20=E6=A0=B9=E6=8D=AE=20canDropIn=20?= =?UTF-8?q?=E6=9D=A5=E6=94=AF=E6=8C=81=E9=80=89=E6=8B=A9=20Page=20?= =?UTF-8?q?=E8=8A=82=E7=82=B9=E6=97=B6=E6=98=AF=E5=90=A6=E5=8F=AF=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/designer/src/document/node/node.ts | 6 ++++++ packages/designer/src/project/project.ts | 1 + packages/editor-preset-vision/src/viewport.ts | 4 ++-- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/designer/src/document/node/node.ts b/packages/designer/src/document/node/node.ts index ab9ee9422..f4486ecbf 100644 --- a/packages/designer/src/document/node/node.ts +++ b/packages/designer/src/document/node/node.ts @@ -910,6 +910,12 @@ export class Node { if (dropElement) { return { container: dropElement, ref }; } + const rootCanDropIn = this.componentMeta?.prototype?.options?.canDropIn; + if (rootCanDropIn === undefined + || rootCanDropIn === true + || (typeof rootCanDropIn === 'function' && rootCanDropIn(node))) { + return { container: this, ref }; + } // 假如最后找不到合适位置,返回 undefined 阻止继续插入节点 return undefined; } diff --git a/packages/designer/src/project/project.ts b/packages/designer/src/project/project.ts index 9a482d3ee..da5f775fd 100644 --- a/packages/designer/src/project/project.ts +++ b/packages/designer/src/project/project.ts @@ -248,6 +248,7 @@ export class Project { private mountSimulator(simulator: ISimulatorHost) { // TODO: 多设备 simulator 支持 this._simulator = simulator; + this.designer.editor.set('simulator', simulator); } setRendererReady(renderer: any) { diff --git a/packages/editor-preset-vision/src/viewport.ts b/packages/editor-preset-vision/src/viewport.ts index 66eaabf43..c21b29f02 100644 --- a/packages/editor-preset-vision/src/viewport.ts +++ b/packages/editor-preset-vision/src/viewport.ts @@ -194,8 +194,8 @@ export class Viewport { async setDevice(device = 'pc') { if (this.getDevice() !== device) { this.device = device; - const currentDocument = await editor.onceGot('currentDocument'); - currentDocument?.simulator?.set('device', device === 'mobile' ? 'mobile' : 'default'); + const simulator = await editor.onceGot('simulator'); + simulator?.set('device', device === 'mobile' ? 'mobile' : 'default'); // Flags.setSimulator(device); // this.applyMediaCSS(); this.emitter.emit('devicechange', device);