From a3015961ed9a2d6c67a9dea37bf5bf1951742942 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=87=91=E7=A6=85?= Date: Sun, 16 Aug 2020 16:56:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=8E=9F=E7=94=9F=20HTML=20?= =?UTF-8?q?=E6=A0=87=E7=AD=BE=E4=BD=9C=E4=B8=BA=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/demo/public/assets.json | 10 +--------- packages/utils/src/build-components.ts | 14 +++++++++++--- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/demo/public/assets.json b/packages/demo/public/assets.json index ae741151a..90c43755a 100644 --- a/packages/demo/public/assets.json +++ b/packages/demo/public/assets.json @@ -13425,15 +13425,7 @@ "props": { "href": "https://fusion.design", "target": "_blank", - "children": { - "type": "JSSlot", - "value": { - "componentName": "Typography.Text", - "props": { - "children": "这是一个超链接" - } - } - } + "children": "这是一个超链接" } } } diff --git a/packages/utils/src/build-components.ts b/packages/utils/src/build-components.ts index 10fef43d0..7dfeed3bc 100644 --- a/packages/utils/src/build-components.ts +++ b/packages/utils/src/build-components.ts @@ -1,5 +1,5 @@ -import { ComponentType } from 'react'; -import { NpmInfo} from '@ali/lowcode-types'; +import { ComponentType, forwardRef, createElement } from 'react'; +import { NpmInfo } from '@ali/lowcode-types'; import { isReactComponent } from './is-react'; import { isESModule } from './is-es-module'; @@ -11,8 +11,16 @@ function accessLibrary(library: string | object) { if (typeof library !== 'string') { return library; } + + return (window as any)[library] || generateHtmlComp(library); +} - return (window as any)[library] || library; +export function generateHtmlComp(library: string) { + if (['a', 'img', 'div', 'span', 'svg'].includes(library)) { + return forwardRef((props, ref) => { + return createElement(library, { ref, ...props }, props.children); + }); + } } export function getSubComponent(library: any, paths: string[]) {