Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 73 additions & 1 deletion src/core/local-disk/shapes-to-document.mapper.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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<ShapeModel[]>(
let combinedShapes: ShapeModel[] = fileDocument.pages.reduce<ShapeModel[]>(
(acc: ShapeModel[], page) => {
return acc.concat(page.shapes);
},
[]
);

combinedShapes = setTextElementsDefaultFontSizeV0_1(combinedShapes);

return {
activePageIndex: 0,
pages: [
Expand Down
1 change: 0 additions & 1 deletion src/core/local-disk/use-local-disk.hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down