From 7383d87125a467f2325785ff61552d5fd29c0156 Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Wed, 10 Apr 2024 11:14:12 +0000 Subject: [PATCH] add group --- src/ui/converters/createPenpotGroup.ts | 7 ++++++- src/ui/lib/penpot.d.ts | 4 ++-- src/ui/lib/types/group/groupAttributes.d.ts | 7 +++++++ src/ui/lib/types/group/groupShape.d.ts | 4 ++++ 4 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 src/ui/lib/types/group/groupAttributes.d.ts create mode 100644 src/ui/lib/types/group/groupShape.d.ts diff --git a/src/ui/converters/createPenpotGroup.ts b/src/ui/converters/createPenpotGroup.ts index fb0dfca..4d3fffb 100644 --- a/src/ui/converters/createPenpotGroup.ts +++ b/src/ui/converters/createPenpotGroup.ts @@ -7,9 +7,14 @@ export const createPenpotGroup = ( baseX: number, baseY: number ) => { - file.penpotFile.addGroup({ name: node.name }); + file.penpotFile.addGroup({ + type: Symbol.for('group'), + name: node.name + }); + for (const child of node.children) { createPenpotItem(file, child, baseX, baseY); } + file.penpotFile.closeGroup(); }; diff --git a/src/ui/lib/penpot.d.ts b/src/ui/lib/penpot.d.ts index 9d3c131..776a506 100644 --- a/src/ui/lib/penpot.d.ts +++ b/src/ui/lib/penpot.d.ts @@ -1,4 +1,5 @@ import { CircleShape } from './types/circle/circleShape'; +import { GroupShape } from './types/group/groupShape'; import { ImageShape } from './types/image/imageShape'; import { RectShape } from './types/rect/rectShape'; import { TextShape } from './types/text/textShape'; @@ -12,8 +13,7 @@ export interface PenpotFile { // eslint-disable-next-line @typescript-eslint/no-explicit-any addArtboard(artboard: any): void; closeArtboard(): void; - // eslint-disable-next-line @typescript-eslint/no-explicit-any - addGroup(group: any): void; + addGroup(group: GroupShape): void; closeGroup(): void; createRect(rect: RectShape): void; createCircle(circle: CircleShape): void; diff --git a/src/ui/lib/types/group/groupAttributes.d.ts b/src/ui/lib/types/group/groupAttributes.d.ts new file mode 100644 index 0000000..2712e30 --- /dev/null +++ b/src/ui/lib/types/group/groupAttributes.d.ts @@ -0,0 +1,7 @@ +export type GroupAttributes = { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + id?: any; + type: symbol; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + shapes?: any[]; +}; diff --git a/src/ui/lib/types/group/groupShape.d.ts b/src/ui/lib/types/group/groupShape.d.ts new file mode 100644 index 0000000..b8b7181 --- /dev/null +++ b/src/ui/lib/types/group/groupShape.d.ts @@ -0,0 +1,4 @@ +import { Shape } from '../shape'; +import { GroupAttributes } from './groupAttributes'; + +export type GroupShape = Shape & GroupAttributes;