fix: 修复 setDevice 的时机,从 currentDocument -> simualtor

fix: 根据 canDropIn 来支持选择 Page 节点时是否可添加组件
This commit is contained in:
力皓 2020-12-03 20:08:24 +08:00
parent cb9bce87c9
commit 0f14884bf1
3 changed files with 9 additions and 2 deletions

View File

@ -910,6 +910,12 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
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;
}

View File

@ -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) {

View File

@ -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);