diff --git a/packages/designer/src/builtin-simulator/host.ts b/packages/designer/src/builtin-simulator/host.ts index 6a8b48516..df4810566 100644 --- a/packages/designer/src/builtin-simulator/host.ts +++ b/packages/designer/src/builtin-simulator/host.ts @@ -14,6 +14,7 @@ import { isElement, isFormEvent, hasOwnProperty, + UtilsMetadata, } from '@ali/lowcode-utils'; import { DragObjectType, @@ -65,6 +66,7 @@ export interface BuiltinSimulatorProps { requestHandlersMap?: any; extraEnvironment?: Asset; library?: LibraryItem[]; + utilsMetadata?: UtilsMetadata; simulatorUrl?: Asset; theme?: Asset; componentsAsset?: Asset; diff --git a/packages/plugin-designer/src/index.tsx b/packages/plugin-designer/src/index.tsx index f1319cc4a..15fdd5ac4 100644 --- a/packages/plugin-designer/src/index.tsx +++ b/packages/plugin-designer/src/index.tsx @@ -60,10 +60,11 @@ export default class DesignerPlugin extends PureComponent { + if (librayMap[meta?.npm.package]) { + const lib = window[librayMap[meta?.npm.package]]; + } + }); + } +} \ No newline at end of file diff --git a/packages/utils/src/build-components.ts b/packages/utils/src/build-components.ts index 22bdba0a4..414033599 100644 --- a/packages/utils/src/build-components.ts +++ b/packages/utils/src/build-components.ts @@ -101,3 +101,39 @@ export function buildComponents(libraryMap: LibraryMap, }); return components; } + +export interface UtilsMetadata { + name: string; + npm: { + package: string; + version?: string; + exportName: string; + subName?: string; + destructuring?: boolean; + main?: string; + } +} + +interface LibrayMap { + [key: string]: string; +} + +export function getProjectUtils(librayMap: LibrayMap, utilsMetadata: UtilsMetadata[]) { + const projectUtils: { [packageName: string]: any } = {}; + if (utilsMetadata) { + utilsMetadata.forEach(meta => { + if (librayMap[meta?.npm?.package]) { + const lib = accessLibrary(librayMap[meta?.npm.package]); + if (lib.destructuring) { + Object.keys(lib).forEach(name => { + if (name === 'destructuring') return; + projectUtils[name] = lib[name]; + }); + } else { + projectUtils[meta?.npm?.exportName] = lib; + } + } + }); + } + return projectUtils; +} \ No newline at end of file