diff --git a/packages/sdk/src/core/goview/convert.ts b/packages/sdk/src/core/goview/convert.ts index c9d94cb..6274c8f 100644 --- a/packages/sdk/src/core/goview/convert.ts +++ b/packages/sdk/src/core/goview/convert.ts @@ -3,37 +3,77 @@ import { convertGoViewTextOptionToNodeProps, type GoViewTextOption } from '../wi export interface GoViewComponentLike { id?: string; - key?: string; + + // goView component identity + key?: string; // e.g. "TextCommon" (sometimes) + chartConfig?: { key?: string }; // goView standard location + + // geometry attr?: { x: number; y: number; w: number; h: number; zIndex?: number }; + + // state status?: { lock?: boolean; hide?: boolean }; + + // goView uses "option" for widget-specific config option?: unknown; } +export interface GoViewEditCanvasConfigLike { + projectName?: string; + width?: number; + height?: number; + background?: string; +} + +export interface GoViewStorageLike { + editCanvasConfig?: GoViewEditCanvasConfigLike; + componentList?: GoViewComponentLike[]; +} + export interface GoViewProjectLike { // very loose input shape; goView has different versions/branches. width?: number; height?: number; canvas?: { width?: number; height?: number }; componentList?: GoViewComponentLike[]; + + // goView persisted store shape + editCanvasConfig?: GoViewEditCanvasConfigLike; } -export function convertGoViewProjectToScreen(input: GoViewProjectLike): Screen { - const width = input.canvas?.width ?? input.width ?? 1920; - const height = input.canvas?.height ?? input.height ?? 1080; +function isTextCommon(c: GoViewComponentLike): boolean { + const k = (c.chartConfig?.key ?? c.key ?? '').toLowerCase(); + if (k === 'textcommon') return true; + // fallback heuristic + return k.includes('text'); +} + +export function convertGoViewProjectToScreen(input: GoViewProjectLike | GoViewStorageLike): Screen { + const editCanvasConfig = (input as GoViewStorageLike).editCanvasConfig; + + const width = + editCanvasConfig?.width ?? (input as GoViewProjectLike).canvas?.width ?? (input as GoViewProjectLike).width ?? 1920; + const height = + editCanvasConfig?.height ?? (input as GoViewProjectLike).canvas?.height ?? (input as GoViewProjectLike).height ?? 1080; + + const name = editCanvasConfig?.projectName ?? 'Imported from goView'; + const background = editCanvasConfig?.background; const screen = createEmptyScreen({ version: ASTRALVIEW_SCHEMA_VERSION, width, height, - name: 'Imported from goView', + name, + background: background ? { color: background } : undefined, nodes: [], }); + const componentList = (input as GoViewStorageLike).componentList ?? (input as GoViewProjectLike).componentList ?? []; + const nodes: TextWidgetNode[] = []; - for (const c of input.componentList ?? []) { + for (const c of componentList) { // Only first: TextCommon-like - const key = c.key ?? ''; - if (!/text/i.test(key)) continue; + if (!isTextCommon(c)) continue; const rect = c.attr ? { x: c.attr.x, y: c.attr.y, w: c.attr.w, h: c.attr.h } : { x: 0, y: 0, w: 320, h: 60 }; const props = convertGoViewTextOptionToNodeProps((c.option ?? {}) as GoViewTextOption);