From 8c3169532e491212652ccfd11f0da72c816872d7 Mon Sep 17 00:00:00 2001 From: kangwei Date: Mon, 22 Jun 2020 21:12:13 +0800 Subject: [PATCH] load proto to iframe loopup parent --- .../editor-preset-vision/src/bundle/bundle.ts | 2 +- .../src/bundle/prototype.ts | 26 ++++++++++++------- .../editor-preset-vision/src/bundle/trunk.ts | 5 ++-- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/packages/editor-preset-vision/src/bundle/bundle.ts b/packages/editor-preset-vision/src/bundle/bundle.ts index 39fe63abf..c913b7e84 100644 --- a/packages/editor-preset-vision/src/bundle/bundle.ts +++ b/packages/editor-preset-vision/src/bundle/bundle.ts @@ -57,7 +57,7 @@ export default class Bundle { this.revisePrototype(item, prototype); const componentName = item.componentName || prototype.getComponentName()!; const matchedView = this.viewsMap[componentName] || null; - if (!prototype.getView() && matchedView) { + if (matchedView) { prototype.setView(matchedView); } this.registerPrototype(prototype); diff --git a/packages/editor-preset-vision/src/bundle/prototype.ts b/packages/editor-preset-vision/src/bundle/prototype.ts index 90553cb73..86a9a0c92 100644 --- a/packages/editor-preset-vision/src/bundle/prototype.ts +++ b/packages/editor-preset-vision/src/bundle/prototype.ts @@ -212,24 +212,30 @@ class Prototype { static addGlobalExtraActions = addGlobalExtraActions; static removeGlobalPropsConfigure = removeGlobalPropsConfigure; static overridePropsConfigure = overridePropsConfigure; - static create(config: OldPrototypeConfig | ComponentMetadata | ComponentMeta) { - return new Prototype(config); + static create(config: OldPrototypeConfig | ComponentMetadata | ComponentMeta, lookup: boolean = false) { + return new Prototype(config, lookup); } readonly isPrototype = true; readonly meta: ComponentMeta; readonly options: OldPrototypeConfig | ComponentMetadata; - constructor(input: OldPrototypeConfig | ComponentMetadata | ComponentMeta) { - if (isComponentMeta(input)) { - this.meta = input; - this.options = input.getMetadata(); + constructor(input: OldPrototypeConfig | ComponentMetadata | ComponentMeta, lookup: boolean = false) { + if (lookup) { + this.meta = designer.getComponentMeta(input.componentName); + this.options = this.meta.getMetadata(); + return this.meta.prototype || this; } else { - this.options = input; - const metadata = isNewSpec(input) ? input : upgradeMetadata(input); - this.meta = designer.createComponentMeta(metadata); + if (isComponentMeta(input)) { + this.meta = input; + this.options = input.getMetadata(); + } else { + this.options = input; + const metadata = isNewSpec(input) ? input : upgradeMetadata(input); + this.meta = designer.createComponentMeta(metadata); + } + (this.meta as any).prototype = this; } - (this.meta as any).prototype = this; } getId() { diff --git a/packages/editor-preset-vision/src/bundle/trunk.ts b/packages/editor-preset-vision/src/bundle/trunk.ts index f38f1db2c..b8e0f19d6 100644 --- a/packages/editor-preset-vision/src/bundle/trunk.ts +++ b/packages/editor-preset-vision/src/bundle/trunk.ts @@ -24,7 +24,8 @@ export class Trunk { } getList(): any[] { - return this.trunk.reduceRight((prev, cur) => prev.concat(cur.getList()), []); + const list = this.trunk.reduceRight((prev, cur) => prev.concat(cur.getList()), []); + return Array.from(new Set(list)); } getPrototype(name: string) { @@ -85,7 +86,7 @@ export class Trunk { } registerSetter(type: string, setter: CustomView | RegisteredSetter) { - console.warn('Trunk.registerSetter is deprecated'); + // console.warn('Trunk.registerSetter is deprecated'); registerSetter(type, setter); }