feat(sdk): improve legacy iframe/video import conversion

This commit is contained in:
ErSan 2026-01-27 19:43:23 +08:00
parent 98b47749e9
commit 299326e060
4 changed files with 73 additions and 19 deletions

View File

@ -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',

View File

@ -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;

View File

@ -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;

View File

@ -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';