From b23231e8d013a603bc73917a1ae7c8ff1caf83c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8A=9B=E7=9A=93?= Date: Mon, 10 May 2021 17:10:37 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E8=AE=BE=E8=AE=A1?= =?UTF-8?q?=E5=99=A8=E9=87=8C=E7=9A=84=20utils=20=E6=B3=A8=E5=85=A5?= =?UTF-8?q?=E6=9C=BA=E5=88=B6=20(vu-xxx=20&=20=E7=AE=80=E5=8D=95=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E7=9A=84=20umd)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../designer/src/builtin-simulator/host.ts | 2 ++ packages/plugin-designer/src/index.tsx | 5 ++- .../react-simulator-renderer/src/renderer.ts | 6 ++-- .../src/utils/misc.ts | 26 ++++++++++++++ packages/utils/src/build-components.ts | 36 +++++++++++++++++++ 5 files changed, 70 insertions(+), 5 deletions(-) create mode 100644 packages/react-simulator-renderer/src/utils/misc.ts 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