From 299326e0603acbb230d18c7b79e4998326e3ec46 Mon Sep 17 00:00:00 2001 From: ErSan Date: Tue, 27 Jan 2026 19:43:23 +0800 Subject: [PATCH] feat(sdk): improve legacy iframe/video import conversion --- packages/sdk/src/core/goview/convert.ts | 18 ++++++++---- packages/sdk/src/core/widgets/iframe.ts | 28 +++++++++++++++--- packages/sdk/src/core/widgets/video.ts | 38 +++++++++++++++++++++---- packages/sdk/src/index.ts | 8 +++--- 4 files changed, 73 insertions(+), 19 deletions(-) diff --git a/packages/sdk/src/core/goview/convert.ts b/packages/sdk/src/core/goview/convert.ts index ef8a68a..40a48db 100644 --- a/packages/sdk/src/core/goview/convert.ts +++ b/packages/sdk/src/core/goview/convert.ts @@ -8,8 +8,8 @@ import { type VideoWidgetNode, } from '../schema'; import { convertGoViewImageOptionToNodeProps, type GoViewImageOption } from '../widgets/image'; -import { convertLegacyIframeOptionToNodeProps, type LegacyIframeOption } from '../widgets/iframe'; -import { convertLegacyVideoOptionToNodeProps, type LegacyVideoOption } from '../widgets/video'; +import { convertGoViewIframeOptionToNodeProps, type GoViewIframeOption } from '../widgets/iframe'; +import { convertGoViewVideoOptionToNodeProps, type GoViewVideoOption } from '../widgets/video'; import { convertGoViewTextOptionToNodeProps, type GoViewTextOption } from '../widgets/text'; export interface GoViewComponentLike { @@ -70,13 +70,19 @@ function isImage(c: GoViewComponentLike): boolean { function isIframe(c: GoViewComponentLike): boolean { const k = keyOf(c); // goView variants: "Iframe", "IframeCommon", etc. - return k === 'iframe' || k.includes('iframe'); + if (k === 'iframe' || k.includes('iframe')) return true; + + // Other names seen in low-code editors for embedded web content. + return k.includes('embed') || k.includes('web') || k.includes('html'); } function isVideo(c: GoViewComponentLike): boolean { const k = keyOf(c); // goView variants: "Video", "VideoCommon", etc. - return k === 'video' || k.includes('video'); + if (k === 'video' || k.includes('video')) return true; + + // Other names seen in the wild. + return k.includes('mp4') || k.includes('media') || k.includes('player'); } export function convertGoViewProjectToScreen(input: GoViewProjectLike | GoViewStorageLike): Screen { @@ -137,7 +143,7 @@ export function convertGoViewProjectToScreen(input: GoViewProjectLike | GoViewSt } if (isIframe(c)) { - const props = convertLegacyIframeOptionToNodeProps((c.option ?? {}) as LegacyIframeOption); + const props = convertGoViewIframeOptionToNodeProps((c.option ?? {}) as GoViewIframeOption); nodes.push({ id: c.id ?? `import_iframe_${Math.random().toString(16).slice(2)}`, type: 'iframe', @@ -151,7 +157,7 @@ export function convertGoViewProjectToScreen(input: GoViewProjectLike | GoViewSt } if (isVideo(c)) { - const props = convertLegacyVideoOptionToNodeProps((c.option ?? {}) as LegacyVideoOption); + const props = convertGoViewVideoOptionToNodeProps((c.option ?? {}) as GoViewVideoOption); nodes.push({ id: c.id ?? `import_video_${Math.random().toString(16).slice(2)}`, type: 'video', diff --git a/packages/sdk/src/core/widgets/iframe.ts b/packages/sdk/src/core/widgets/iframe.ts index e9e5ae6..179f6c5 100644 --- a/packages/sdk/src/core/widgets/iframe.ts +++ b/packages/sdk/src/core/widgets/iframe.ts @@ -1,13 +1,33 @@ import type { IframeWidgetNode } from '../schema'; -export interface LegacyIframeOption { - dataset: string; +/** + * goView iframe option shape varies across versions. + * Keep it permissive and normalize the common fields. + */ +export interface GoViewIframeOption { + dataset?: string; + src?: string; + url?: string; borderRadius?: number; } -export function convertLegacyIframeOptionToNodeProps(option: LegacyIframeOption): IframeWidgetNode['props'] { +/** + * Back-compat alias (older code used "LegacyIframeOption"). + */ +export type LegacyIframeOption = GoViewIframeOption; + +function pickSrc(option: GoViewIframeOption): string { + return option.dataset ?? option.src ?? option.url ?? ''; +} + +export function convertGoViewIframeOptionToNodeProps(option: GoViewIframeOption): IframeWidgetNode['props'] { return { - src: option.dataset ?? '', + src: pickSrc(option), borderRadius: option.borderRadius, }; } + +/** + * Back-compat export. + */ +export const convertLegacyIframeOptionToNodeProps = convertGoViewIframeOptionToNodeProps; diff --git a/packages/sdk/src/core/widgets/video.ts b/packages/sdk/src/core/widgets/video.ts index 166e30d..689efe0 100644 --- a/packages/sdk/src/core/widgets/video.ts +++ b/packages/sdk/src/core/widgets/video.ts @@ -1,19 +1,47 @@ import type { VideoWidgetNode } from '../schema'; -export interface LegacyVideoOption { - dataset: string; +/** + * goView video option shape varies across versions. + * Keep it permissive and normalize the common fields. + */ +export interface GoViewVideoOption { + dataset?: string; + src?: string; + url?: string; + loop?: boolean; muted?: boolean; + fit?: VideoWidgetNode['props']['fit']; + objectFit?: VideoWidgetNode['props']['fit']; + borderRadius?: number; } -export function convertLegacyVideoOptionToNodeProps(option: LegacyVideoOption): VideoWidgetNode['props'] { +/** + * Back-compat alias (older code used "LegacyVideoOption"). + */ +export type LegacyVideoOption = GoViewVideoOption; + +function pickSrc(option: GoViewVideoOption): string { + return option.dataset ?? option.src ?? option.url ?? ''; +} + +function pickFit(option: GoViewVideoOption): VideoWidgetNode['props']['fit'] | undefined { + return option.fit ?? option.objectFit; +} + +export function convertGoViewVideoOptionToNodeProps(option: GoViewVideoOption): VideoWidgetNode['props'] { return { - src: option.dataset ?? '', + src: pickSrc(option), loop: option.loop, muted: option.muted, - fit: option.fit, + fit: pickFit(option), borderRadius: option.borderRadius, }; } + +/** + * Back-compat export. + */ +export const convertLegacyVideoOptionToNodeProps = convertGoViewVideoOptionToNodeProps; diff --git a/packages/sdk/src/index.ts b/packages/sdk/src/index.ts index ab345b6..89e65d3 100644 --- a/packages/sdk/src/index.ts +++ b/packages/sdk/src/index.ts @@ -27,11 +27,11 @@ export { convertGoViewTextOptionToNodeProps } from './core/widgets/text'; export type { GoViewImageOption } from './core/widgets/image'; export { convertGoViewImageOptionToNodeProps } from './core/widgets/image'; -export type { LegacyIframeOption } from './core/widgets/iframe'; -export { convertLegacyIframeOptionToNodeProps } from './core/widgets/iframe'; +export type { GoViewIframeOption, LegacyIframeOption } from './core/widgets/iframe'; +export { convertGoViewIframeOptionToNodeProps, convertLegacyIframeOptionToNodeProps } from './core/widgets/iframe'; -export type { LegacyVideoOption } from './core/widgets/video'; -export { convertLegacyVideoOptionToNodeProps } from './core/widgets/video'; +export type { GoViewVideoOption, LegacyVideoOption } from './core/widgets/video'; +export { convertGoViewVideoOptionToNodeProps, convertLegacyVideoOptionToNodeProps } from './core/widgets/video'; export type { GoViewProjectLike, GoViewComponentLike } from './core/goview/convert'; export { convertGoViewProjectToScreen } from './core/goview/convert';