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, type VideoWidgetNode,
} from '../schema'; } from '../schema';
import { convertGoViewImageOptionToNodeProps, type GoViewImageOption } from '../widgets/image'; import { convertGoViewImageOptionToNodeProps, type GoViewImageOption } from '../widgets/image';
import { convertLegacyIframeOptionToNodeProps, type LegacyIframeOption } from '../widgets/iframe'; import { convertGoViewIframeOptionToNodeProps, type GoViewIframeOption } from '../widgets/iframe';
import { convertLegacyVideoOptionToNodeProps, type LegacyVideoOption } from '../widgets/video'; import { convertGoViewVideoOptionToNodeProps, type GoViewVideoOption } from '../widgets/video';
import { convertGoViewTextOptionToNodeProps, type GoViewTextOption } from '../widgets/text'; import { convertGoViewTextOptionToNodeProps, type GoViewTextOption } from '../widgets/text';
export interface GoViewComponentLike { export interface GoViewComponentLike {
@ -70,13 +70,19 @@ function isImage(c: GoViewComponentLike): boolean {
function isIframe(c: GoViewComponentLike): boolean { function isIframe(c: GoViewComponentLike): boolean {
const k = keyOf(c); const k = keyOf(c);
// goView variants: "Iframe", "IframeCommon", etc. // 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 { function isVideo(c: GoViewComponentLike): boolean {
const k = keyOf(c); const k = keyOf(c);
// goView variants: "Video", "VideoCommon", etc. // 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 { export function convertGoViewProjectToScreen(input: GoViewProjectLike | GoViewStorageLike): Screen {
@ -137,7 +143,7 @@ export function convertGoViewProjectToScreen(input: GoViewProjectLike | GoViewSt
} }
if (isIframe(c)) { if (isIframe(c)) {
const props = convertLegacyIframeOptionToNodeProps((c.option ?? {}) as LegacyIframeOption); const props = convertGoViewIframeOptionToNodeProps((c.option ?? {}) as GoViewIframeOption);
nodes.push({ nodes.push({
id: c.id ?? `import_iframe_${Math.random().toString(16).slice(2)}`, id: c.id ?? `import_iframe_${Math.random().toString(16).slice(2)}`,
type: 'iframe', type: 'iframe',
@ -151,7 +157,7 @@ export function convertGoViewProjectToScreen(input: GoViewProjectLike | GoViewSt
} }
if (isVideo(c)) { if (isVideo(c)) {
const props = convertLegacyVideoOptionToNodeProps((c.option ?? {}) as LegacyVideoOption); const props = convertGoViewVideoOptionToNodeProps((c.option ?? {}) as GoViewVideoOption);
nodes.push({ nodes.push({
id: c.id ?? `import_video_${Math.random().toString(16).slice(2)}`, id: c.id ?? `import_video_${Math.random().toString(16).slice(2)}`,
type: 'video', type: 'video',

View File

@ -1,13 +1,33 @@
import type { IframeWidgetNode } from '../schema'; 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; 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 { return {
src: option.dataset ?? '', src: pickSrc(option),
borderRadius: option.borderRadius, borderRadius: option.borderRadius,
}; };
} }
/**
* Back-compat export.
*/
export const convertLegacyIframeOptionToNodeProps = convertGoViewIframeOptionToNodeProps;

View File

@ -1,19 +1,47 @@
import type { VideoWidgetNode } from '../schema'; 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; loop?: boolean;
muted?: boolean; muted?: boolean;
fit?: VideoWidgetNode['props']['fit']; fit?: VideoWidgetNode['props']['fit'];
objectFit?: VideoWidgetNode['props']['fit'];
borderRadius?: number; 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 { return {
src: option.dataset ?? '', src: pickSrc(option),
loop: option.loop, loop: option.loop,
muted: option.muted, muted: option.muted,
fit: option.fit, fit: pickFit(option),
borderRadius: option.borderRadius, 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 type { GoViewImageOption } from './core/widgets/image';
export { convertGoViewImageOptionToNodeProps } from './core/widgets/image'; export { convertGoViewImageOptionToNodeProps } from './core/widgets/image';
export type { LegacyIframeOption } from './core/widgets/iframe'; export type { GoViewIframeOption, LegacyIframeOption } from './core/widgets/iframe';
export { convertLegacyIframeOptionToNodeProps } from './core/widgets/iframe'; export { convertGoViewIframeOptionToNodeProps, convertLegacyIframeOptionToNodeProps } from './core/widgets/iframe';
export type { LegacyVideoOption } from './core/widgets/video'; export type { GoViewVideoOption, LegacyVideoOption } from './core/widgets/video';
export { convertLegacyVideoOptionToNodeProps } from './core/widgets/video'; export { convertGoViewVideoOptionToNodeProps, convertLegacyVideoOptionToNodeProps } from './core/widgets/video';
export type { GoViewProjectLike, GoViewComponentLike } from './core/goview/convert'; export type { GoViewProjectLike, GoViewComponentLike } from './core/goview/convert';
export { convertGoViewProjectToScreen } from './core/goview/convert'; export { convertGoViewProjectToScreen } from './core/goview/convert';