@@ -35,6 +35,10 @@ const keyBlacklist = [
3535 'innerPlugins' ,
3636] ;
3737
38+ const AssetsCache : {
39+ [ key : string ] : IPublicTypeRemoteComponentDescription ;
40+ } = { } ;
41+
3842export declare interface Editor extends StrictEventEmitter < EventEmitter , GlobalEvent . EventConfig > {
3943 addListener ( event : string | symbol , listener : ( ...args : any [ ] ) => void ) : this;
4044 once ( event : string | symbol , listener : ( ...args : any [ ] ) => void ) : this;
@@ -143,9 +147,15 @@ export class Editor extends EventEmitter implements IEditor {
143147 // 如果有远程组件描述协议,则自动加载并补充到资产包中,同时出发 designer.incrementalAssetsReady 通知组件面板更新数据
144148 if ( remoteComponentDescriptions && remoteComponentDescriptions . length ) {
145149 await Promise . all (
146- remoteComponentDescriptions . map ( async ( component : any ) => {
150+ remoteComponentDescriptions . map ( async ( component : IPublicTypeRemoteComponentDescription ) => {
147151 const { exportName, url, npm } = component ;
148- await ( new AssetLoader ( ) ) . load ( url ) ;
152+ if ( ! url || ! exportName ) {
153+ return ;
154+ }
155+ if ( ! AssetsCache [ exportName ] || ! npm ?. version || AssetsCache [ exportName ] . npm ?. version !== npm ?. version ) {
156+ await ( new AssetLoader ( ) ) . load ( url ) ;
157+ }
158+ AssetsCache [ exportName ] = component ;
149159 function setAssetsComponent ( component : any , extraNpmInfo : any = { } ) {
150160 const components = component . components ;
151161 assets . componentList = assets . componentList ?. concat ( component . componentList || [ ] ) ;
@@ -181,14 +191,14 @@ export class Editor extends EventEmitter implements IEditor {
181191 } ) ;
182192 } ) ;
183193 }
184- if ( window [ exportName ] ) {
185- if ( Array . isArray ( window [ exportName ] ) ) {
186- setArrayAssets ( window [ exportName ] as any ) ;
194+ if ( ( window as any ) [ exportName ] ) {
195+ if ( Array . isArray ( ( window as any ) [ exportName ] ) ) {
196+ setArrayAssets ( ( window as any ) [ exportName ] as any ) ;
187197 } else {
188- setAssetsComponent ( window [ exportName ] as any ) ;
198+ setAssetsComponent ( ( window as any ) [ exportName ] as any ) ;
189199 }
190200 }
191- return window [ exportName ] ;
201+ return ( window as any ) [ exportName ] ;
192202 } ) ,
193203 ) ;
194204 }
0 commit comments