From 8b0c9189e2af82596b6cf8c24df3c7756a4c182c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8A=9B=E7=9A=93?= Date: Fri, 18 Jun 2021 12:01:17 +0800 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E5=85=83=E6=95=B0=E6=8D=AE=E6=9B=B4=E6=96=B0=E5=90=8E=20Settin?= =?UTF-8?q?gTopEntry=20=E6=9C=AA=E5=90=8C=E6=AD=A5=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E7=9A=84=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/designer/src/component-meta.ts | 15 +++++++++++++++ .../src/designer/setting/setting-top-entry.ts | 8 ++++++++ 2 files changed, 23 insertions(+) diff --git a/packages/designer/src/component-meta.ts b/packages/designer/src/component-meta.ts index 398f827d2..e40256d40 100644 --- a/packages/designer/src/component-meta.ts +++ b/packages/designer/src/component-meta.ts @@ -23,6 +23,7 @@ import { IconRemove } from './icons/remove'; import { IconClone } from './icons/clone'; import { ReactElement } from 'react'; import { IconHidden } from './icons/hidden'; +import EventEmitter from 'events'; function ensureAList(list?: string | string[]): string[] | null { if (!list) { @@ -66,6 +67,8 @@ export class ComponentMeta { private _npm?: NpmInfo; + private emitter: EventEmitter = new EventEmitter(); + get npm() { return this._npm; } @@ -229,6 +232,11 @@ export class ComponentMeta { this._isContainer = false; this._isModal = false; } + this.emitter.emit('metadata_change'); + } + + refreshMetadata() { + this.parseMetadata(this.getMetadata()); } private transformMetadata(metadta: ComponentMetadata): TransformedComponentMetadata { @@ -297,6 +305,13 @@ export class ComponentMeta { return true; } + onMetadataChange(fn: (args: any) => void): () => void { + this.emitter.on('metadata_change', fn); + return () => { + this.emitter.removeListener('metadata_change', fn); + }; + } + // compatiable vision prototype?: any; } diff --git a/packages/designer/src/designer/setting/setting-top-entry.ts b/packages/designer/src/designer/setting/setting-top-entry.ts index ab09d355c..6e03cc66a 100644 --- a/packages/designer/src/designer/setting/setting-top-entry.ts +++ b/packages/designer/src/designer/setting/setting-top-entry.ts @@ -80,6 +80,8 @@ export class SettingTopEntry implements SettingEntry { // clear fields this.setupItems(); + + this.setupEvents(); } private setupComponentMeta() { @@ -120,6 +122,12 @@ export class SettingTopEntry implements SettingEntry { } } + private setupEvents() { + this.componentMeta?.onMetadataChange(() => { + this.setupItems(); + }); + } + /** * 获取当前属性值 */ From 3c07142f711644e4cb0837d6244142efb79b2ac5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8A=9B=E7=9A=93?= Date: Fri, 18 Jun 2021 16:45:34 +0800 Subject: [PATCH 2/3] =?UTF-8?q?fix:=20=E5=85=B3=E9=97=AD=E4=BD=8E=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E7=BB=84=E4=BB=B6=E5=9C=A8=E9=A1=B5=E9=9D=A2=E5=BC=95?= =?UTF-8?q?=E7=94=A8=E6=97=B6=E7=9A=84=E5=8E=9F=E5=9C=B0=E7=BC=96=E8=BE=91?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/designer/src/builtin-simulator/host.ts | 4 ++-- packages/designer/src/document/node/node.ts | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/designer/src/builtin-simulator/host.ts b/packages/designer/src/builtin-simulator/host.ts index 1a5d12cfd..7ad6547bb 100644 --- a/packages/designer/src/builtin-simulator/host.ts +++ b/packages/designer/src/builtin-simulator/host.ts @@ -17,7 +17,7 @@ import { } from '../simulator'; import Viewport from './viewport'; import { createSimulator } from './create-simulator'; -import { Node, ParentalNode, contains, isRootNode } from '../document'; +import { Node, ParentalNode, contains, isRootNode, isLowCodeComponent } from '../document'; import ResourceConsumer from './resource-consumer'; import { AssetLevel, @@ -792,7 +792,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost Date: Tue, 22 Jun 2021 10:58:09 +0800 Subject: [PATCH 3/3] =?UTF-8?q?refactor(perf):=20=E8=8A=82=E7=82=B9?= =?UTF-8?q?=E5=B1=9E=E6=80=A7=20settingEntry=20=E6=8C=89=E9=9C=80=E6=9E=84?= =?UTF-8?q?=E9=80=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/designer/src/document/node/node.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/designer/src/document/node/node.ts b/packages/designer/src/document/node/node.ts index b55ee359a..9dfde4baf 100644 --- a/packages/designer/src/document/node/node.ts +++ b/packages/designer/src/document/node/node.ts @@ -156,8 +156,6 @@ export class Node { return this.componentMeta.icon; } - readonly settingEntry: SettingTopEntry; - private isInited = false; constructor(readonly document: DocumentModel, nodeSchema: Schema, options: any = {}) { @@ -168,13 +166,11 @@ export class Node { this.props = new Props(this, { children: isDOMText(children) || isJSExpression(children) ? children : '', }); - this.settingEntry = this.document.designer.createSettingEntry([this]); } else { // 这里 props 被初始化两次,一次 new,一次 import,new 的实例需要给 propsReducer 的钩子去使用, // import 是为了使用钩子返回的值,并非完全幂等的操作,部分行为执行两次会有 bug, // 所以在 props 里会对 new / import 做一些区别化的解析 this.props = new Props(this, props, extras); - this.settingEntry = this.document.designer.createSettingEntry([this]); this._children = new NodeChildren(this as ParentalNode, this.initialChildren(children)); this._children.internalInitParent(); this.props.import( @@ -188,6 +184,14 @@ export class Node { this.emitter = new EventEmitter(); } + _settingEntry: SettingTopEntry; + + get settingEntry(): SettingTopEntry { + if (this._settingEntry) return this._settingEntry; + this._settingEntry = this.document.designer.createSettingEntry([this]); + return this._settingEntry; + } + private initProps(props: any): any { return this.document.designer.transformProps(props, this, TransformStage.Init); }