Merge branch 'develop' into release/1.0.16-beta

This commit is contained in:
LeoYuan 袁力皓 2022-10-24 15:09:16 +08:00
commit 298cef6f96
7 changed files with 47 additions and 7 deletions

View File

@ -352,9 +352,11 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
const _library = library || (this.get('library') as LibraryItem[]); const _library = library || (this.get('library') as LibraryItem[]);
const libraryAsset: AssetList = []; const libraryAsset: AssetList = [];
const libraryExportList: string[] = []; const libraryExportList: string[] = [];
const functionCallLibraryExportList: string[] = [];
if (_library && _library.length) { if (_library && _library.length) {
_library.forEach((item) => { _library.forEach((item) => {
const { exportMode, exportSourceLibrary } = item;
this.libraryMap[item.package] = item.library; this.libraryMap[item.package] = item.library;
if (item.async) { if (item.async) {
this.asyncLibraryMap[item.package] = item; this.asyncLibraryMap[item.package] = item;
@ -364,6 +366,11 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
`Object.defineProperty(window,'${item.exportName}',{get:()=>window.${item.library}});`, `Object.defineProperty(window,'${item.exportName}',{get:()=>window.${item.library}});`,
); );
} }
if (exportMode === 'functionCall' && exportSourceLibrary) {
functionCallLibraryExportList.push(
`window["${item.library}"] = window["${exportSourceLibrary}"]("${item.library}", "${item.package}");`,
);
}
if (item.editUrls) { if (item.editUrls) {
libraryAsset.push(item.editUrls); libraryAsset.push(item.editUrls);
} else if (item.urls) { } else if (item.urls) {
@ -372,7 +379,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
}); });
} }
libraryAsset.unshift(assetItem(AssetType.JSText, libraryExportList.join(''))); libraryAsset.unshift(assetItem(AssetType.JSText, libraryExportList.join('')));
libraryAsset.push(assetItem(AssetType.JSText, functionCallLibraryExportList.join('')));
return libraryAsset; return libraryAsset;
} }
@ -428,6 +435,9 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
if (Object.keys(this.asyncLibraryMap).length > 0) { if (Object.keys(this.asyncLibraryMap).length > 0) {
// 加载异步Library // 加载异步Library
await renderer.loadAsyncLibrary(this.asyncLibraryMap); await renderer.loadAsyncLibrary(this.asyncLibraryMap);
Object.keys(this.asyncLibraryMap).forEach(key => {
delete this.asyncLibraryMap[key];
});
} }
// step 5 ready & render // step 5 ready & render
@ -447,7 +457,14 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
async setupComponents(library) { async setupComponents(library) {
const libraryAsset: AssetList = this.buildLibrary(library); const libraryAsset: AssetList = this.buildLibrary(library);
await this.renderer.load(libraryAsset); await this.renderer?.load(libraryAsset);
if (Object.keys(this.asyncLibraryMap).length > 0) {
// 加载异步Library
await this.renderer?.loadAsyncLibrary(this.asyncLibraryMap);
Object.keys(this.asyncLibraryMap).forEach(key => {
delete this.asyncLibraryMap[key];
});
}
} }
setupEvents() { setupEvents() {

View File

@ -11,6 +11,7 @@ export interface BuiltinSimulatorRenderer {
setNativeSelection(enableFlag: boolean): void; setNativeSelection(enableFlag: boolean): void;
setDraggingState(state: boolean): void; setDraggingState(state: boolean): void;
setCopyState(state: boolean): void; setCopyState(state: boolean): void;
loadAsyncLibrary(asyncMap: { [index: string]: any }): void;
clearState(): void; clearState(): void;
run(): void; run(): void;
} }

View File

@ -386,7 +386,7 @@ export function leafWrapper(Comp: types.IBaseRenderComponent, {
/** 监听参数变化 */ /** 监听参数变化 */
initOnPropsChangeEvent(leaf = this.leaf): void { initOnPropsChangeEvent(leaf = this.leaf): void {
const dispose = leaf?.onPropChange?.((propChangeInfo: PropChangeOptions) => { const dispose = leaf?.onPropChange?.(debounce((propChangeInfo: PropChangeOptions) => {
const { const {
key, key,
newValue = null, newValue = null,
@ -433,7 +433,7 @@ export function leafWrapper(Comp: types.IBaseRenderComponent, {
}); });
this.judgeMiniUnitRender(); this.judgeMiniUnitRender();
}); }, 30));
dispose && this.disposeFunctions.push(dispose); dispose && this.disposeFunctions.push(dispose);
} }

View File

@ -16,8 +16,8 @@ jest.mock('lodash', () => {
return { return {
...original, ...original,
debounce: (fn) => () => fn(), debounce: (fn) => (...args: any[]) => fn.apply(this, args),
throttle: (fn) => () => fn(), throttle: (fn) => (...args: any[]) => fn.apply(this, args),
} }
}) })

View File

@ -97,6 +97,13 @@ export default class SettingPropEntry {
return SettingPropEntry.create(this[settingPropEntrySymbol].parent as any); return SettingPropEntry.create(this[settingPropEntrySymbol].parent as any);
} }
/**
*
*/
get top(): SettingTopEntry {
return SettingTopEntry.create(this[settingPropEntrySymbol].top);
}
/** /**
* SettingField * SettingField
*/ */

View File

@ -130,6 +130,14 @@ export interface Package {
* @todo @度城 * @todo @度城
*/ */
async?: boolean; async?: boolean;
/**
* package package
*/
exportMode?: 'functionCall';
/**
* package window
*/
exportSourceLibrary?: any;
/** /**
* window[exportName] Object * window[exportName] Object
*/ */

View File

@ -268,17 +268,24 @@ export class AssetLoader {
async loadAsyncLibrary(asyncLibraryMap: Record<string, any>) { async loadAsyncLibrary(asyncLibraryMap: Record<string, any>) {
const promiseList: any[] = []; const promiseList: any[] = [];
const libraryKeyList: any[] = []; const libraryKeyList: any[] = [];
const pkgs: any[] = [];
for (const key in asyncLibraryMap) { for (const key in asyncLibraryMap) {
// 需要异步加载 // 需要异步加载
if (asyncLibraryMap[key].async) { if (asyncLibraryMap[key].async) {
promiseList.push(window[asyncLibraryMap[key].library]); promiseList.push(window[asyncLibraryMap[key].library]);
libraryKeyList.push(asyncLibraryMap[key].library); libraryKeyList.push(asyncLibraryMap[key].library);
pkgs.push(asyncLibraryMap[key]);
} }
} }
await Promise.all(promiseList).then((mods) => { await Promise.all(promiseList).then((mods) => {
if (mods.length > 0) { if (mods.length > 0) {
mods.map((item, index) => { mods.map((item, index) => {
window[libraryKeyList[index]] = item; const { exportMode, exportSourceLibrary, library } = pkgs[index];
window[libraryKeyList[index]] =
exportMode === 'functionCall' &&
(exportSourceLibrary == null || exportSourceLibrary === library)
? item()
: item;
return item; return item;
}); });
} }