diff --git a/src/core/local-disk/shapes-to-document.mapper.ts b/src/core/local-disk/shapes-to-document.mapper.ts index 042c5dc0..5d62c54c 100644 --- a/src/core/local-disk/shapes-to-document.mapper.ts +++ b/src/core/local-disk/shapes-to-document.mapper.ts @@ -4,7 +4,7 @@ import { createDefaultCanvasSize, DocumentModel, } from '../providers/canvas/canvas.model'; -import { QuickMockFileContract } from './local-disk.model'; +import { Page, QuickMockFileContract } from './local-disk.model'; import { APP_CONSTANTS } from '../providers/canvas/canvas.model'; export const mapFromShapesArrayToQuickMockFileDocument = ( @@ -24,7 +24,7 @@ export const mapFromQuickMockFileDocumentToApplicationDocument = ( ): DocumentModel => { return { activePageIndex: 0, - pages: fileDocument.pages, + pages: AdaptMinor_0_2_Updates(fileDocument.pages), customColors: fileDocument.customColors || new Array(APP_CONSTANTS.COLOR_SLOTS).fill(null), @@ -32,6 +32,48 @@ export const mapFromQuickMockFileDocumentToApplicationDocument = ( }; }; +const AdaptMinor_0_2_Updates = (pages: Page[]): Page[] => { + return pages.map(page => { + return { + ...page, + shapes: page.shapes.map( + AddDefaultValuesForInputPropsPlaceHolderAndPassword + ), + }; + }); +}; + +const AddDefaultValuesForInputPropsPlaceHolderAndPassword = ( + shape: ShapeModel +) => { + switch (shape.type) { + case 'input': + return { + ...shape, + otherProps: { + ...shape.otherProps, + isPlaceholder: + // Small update no need to go for 0_3, but input placeHolder needs to have default value + // if undefined + shape.otherProps?.isPlaceholder !== undefined + ? shape.otherProps?.isPlaceholder + : true, + textColor: + // Small update, no need to go for 0_3, + // but input textColor needs to have default value + // if undefined, and textColor was placeholder gray color + // in this case change it to black + shape.otherProps?.isPlaceholder === undefined && + shape.otherProps?.textColor === '#8c8c8c' + ? '#000000' + : shape.otherProps?.textColor, + }, + }; + default: + return shape; + } +}; + const mapTextElementFromV0_1ToV0_2 = (shape: ShapeModel): ShapeModel => { switch (shape.type) { case 'heading1':