diff --git a/src/core/local-disk/shapes-to-document.mapper.ts b/src/core/local-disk/shapes-to-document.mapper.ts index e32bbe69..d34a23c0 100644 --- a/src/core/local-disk/shapes-to-document.mapper.ts +++ b/src/core/local-disk/shapes-to-document.mapper.ts @@ -1,3 +1,4 @@ +import { FONT_SIZE_VALUES } from '@/common/components/mock-components/front-components/shape.const'; import { ShapeModel } from '../model'; import { DocumentModel } from '../providers/canvas/canvas.model'; import { QuickMockFileContract } from './local-disk.model'; @@ -21,18 +22,89 @@ export const mapFromQuickMockFileDocumentToApplicationDocument = ( }; }; +const mapTextElementFromV0_1ToV0_2 = (shape: ShapeModel): ShapeModel => { + switch (shape.type) { + case 'heading1': + return { + ...shape, + otherProps: { + ...shape, + fontSize: FONT_SIZE_VALUES.HEADING1, + }, + }; + case 'heading2': + return { + ...shape, + otherProps: { + ...shape, + fontSize: FONT_SIZE_VALUES.HEADING2, + }, + }; + case 'heading3': + return { + ...shape, + otherProps: { + ...shape, + fontSize: FONT_SIZE_VALUES.HEADING3, + }, + }; + case 'link': + return { + ...shape, + otherProps: { + ...shape, + fontSize: FONT_SIZE_VALUES.LINK, + }, + }; + case 'normaltext': + return { + ...shape, + otherProps: { + ...shape, + fontSize: FONT_SIZE_VALUES.NORMALTEXT, + }, + }; + case 'smalltext': + return { + ...shape, + otherProps: { + ...shape, + fontSize: FONT_SIZE_VALUES.SMALLTEXT, + }, + }; + case 'paragraph': + return { + ...shape, + otherProps: { + ...shape, + fontSize: FONT_SIZE_VALUES.PARAGRAPH, + }, + }; + default: + return shape; + } +}; + +const setTextElementsDefaultFontSizeV0_1 = ( + shapes: ShapeModel[] +): ShapeModel[] => { + return shapes.map(mapTextElementFromV0_1ToV0_2); +}; + // Example function to handle version 0.1 parsing export const mapFromQuickMockFileDocumentToApplicationDocumentV0_1 = ( fileDocument: QuickMockFileContract ): DocumentModel => { // Combine all shapes into a single page - const combinedShapes: ShapeModel[] = fileDocument.pages.reduce( + let combinedShapes: ShapeModel[] = fileDocument.pages.reduce( (acc: ShapeModel[], page) => { return acc.concat(page.shapes); }, [] ); + combinedShapes = setTextElementsDefaultFontSizeV0_1(combinedShapes); + return { activePageIndex: 0, pages: [ diff --git a/src/core/local-disk/use-local-disk.hook.ts b/src/core/local-disk/use-local-disk.hook.ts index 1d5bd4ea..fbcb3f18 100644 --- a/src/core/local-disk/use-local-disk.hook.ts +++ b/src/core/local-disk/use-local-disk.hook.ts @@ -58,7 +58,6 @@ export const useLocalDisk = () => { reader.onload = () => { const content = reader.result as string; const parseData: QuickMockFileContract = JSON.parse(content); - if (parseData.version === '0.1') { // Handle version 0.1 parsing const appDocument =