Skip to content

Commit

Permalink
Fix components (#193)
Browse files Browse the repository at this point in the history
* Fix components

* fix lint
  • Loading branch information
jordisala1991 authored Jun 26, 2024
1 parent b003704 commit 1ebdf3e
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 15 deletions.
10 changes: 10 additions & 0 deletions common/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,13 @@ export const toObject = <T>(map: Map<string, T>): Record<string, T> => {
export const toArray = <T>(map: Map<string, T>): [string, T][] => {
return Array.from(map.entries());
};

export const init = <T>(map: Map<string, T>, records: Record<string, T>) => {
map.clear();

const entries = Object.entries(records);

for (const [key, value] of entries) {
map.set(key, value);
}
};
3 changes: 2 additions & 1 deletion ui-src/parser/creators/createComponentsLibrary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import { sleep } from '@common/sleep';

import { sendMessage } from '@ui/context';
import { PenpotFile } from '@ui/lib/types/penpotFile';
import { UiComponent, componentShapes, components as uiComponents } from '@ui/parser';
import { componentShapes, components as uiComponents } from '@ui/parser';
import { symbolFills, symbolStrokes } from '@ui/parser/creators/symbols';
import { UiComponent } from '@ui/types';

import { createItems } from '.';

Expand Down
13 changes: 1 addition & 12 deletions ui-src/parser/libraries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,7 @@ import { TypographyStyle } from '@ui/lib/types/shapes/textShape';
import { FillStyle } from '@ui/lib/types/utils/fill';
import { ImageColor } from '@ui/lib/types/utils/imageColor';
import { Uuid } from '@ui/lib/types/utils/uuid';

export type UiComponent = {
componentId: Uuid;
mainInstancePage?: Uuid;
mainInstanceId: Uuid;
componentFigmaId: string;
};

export const init = <T>(records: Record<string, T>, map: Map<string, T>) => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
map = new Map(Object.entries(records));
};
import { UiComponent } from '@ui/types';

export const typographies: Map<string, TypographyStyle> = new Map();
export const images: Map<string, ImageColor> = new Map();
Expand Down
5 changes: 3 additions & 2 deletions ui-src/parser/parse.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { init } from '@common/map';
import { sleep } from '@common/sleep';

import { sendMessage } from '@ui/context';
import { createFile } from '@ui/lib/penpot';
import { PenpotFile } from '@ui/lib/types/penpotFile';
import { TypographyStyle } from '@ui/lib/types/shapes/textShape';
import { FillStyle } from '@ui/lib/types/utils/fill';
import { colors, componentShapes, images, init, typographies } from '@ui/parser';
import { colors, componentShapes, images, typographies } from '@ui/parser';
import { buildFile } from '@ui/parser/creators';
import { PenpotDocument } from '@ui/types';

Expand Down Expand Up @@ -124,7 +125,7 @@ export const parse = async ({
paintStyles,
textStyles
}: PenpotDocument) => {
init(components, componentShapes);
init(componentShapes, components);

const file = createFile(name);

Expand Down
8 changes: 8 additions & 0 deletions ui-src/types/component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { LayoutAttributes, LayoutChildAttributes } from '@ui/lib/types/shapes/layout';
import { ShapeAttributes, ShapeGeomAttributes } from '@ui/lib/types/shapes/shape';
import { Children } from '@ui/lib/types/utils/children';
import { Uuid } from '@ui/lib/types/utils/uuid';

export type ComponentRoot = {
figmaId: string;
Expand All @@ -27,3 +28,10 @@ export type ComponentInstance = ShapeGeomAttributes &
showContent?: boolean;
type: 'instance';
};

export type UiComponent = {
componentId: Uuid;
mainInstancePage?: Uuid;
mainInstanceId: Uuid;
componentFigmaId: string;
};

0 comments on commit 1ebdf3e

Please sign in to comment.