From 822332f0cf086cc78c196d2e93c265af6389f284 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20S=C3=A1nchez?= Date: Fri, 28 Jun 2024 12:35:27 +0200 Subject: [PATCH 1/3] improvements --- plugin-src/registerComponentProperties.ts | 13 +++++++++++++ plugin-src/transformers/transformComponentNode.ts | 13 +++---------- plugin-src/transformers/transformFrameNode.ts | 12 ++---------- plugin-src/transformers/transformInstanceNode.ts | 2 +- plugin-src/translators/translateTouched.ts | 2 ++ 5 files changed, 21 insertions(+), 21 deletions(-) create mode 100644 plugin-src/registerComponentProperties.ts diff --git a/plugin-src/registerComponentProperties.ts b/plugin-src/registerComponentProperties.ts new file mode 100644 index 00000000..3fcd1241 --- /dev/null +++ b/plugin-src/registerComponentProperties.ts @@ -0,0 +1,13 @@ +import { componentProperties } from '@plugin/libraries'; + +export const registerComponentProperties = (node: ComponentSetNode | ComponentNode) => { + try { + Object.entries(node.componentPropertyDefinitions).forEach(([key, value]) => { + if (value.type === 'TEXT' || value.type === 'BOOLEAN') { + componentProperties.set(key, value); + } + }); + } catch (error) { + console.error('Error registering component properties', node, error); + } +}; diff --git a/plugin-src/transformers/transformComponentNode.ts b/plugin-src/transformers/transformComponentNode.ts index 2a7886fa..3eb3eff3 100644 --- a/plugin-src/transformers/transformComponentNode.ts +++ b/plugin-src/transformers/transformComponentNode.ts @@ -1,4 +1,5 @@ -import { componentProperties, components } from '@plugin/libraries'; +import { components } from '@plugin/libraries'; +import { registerComponentProperties } from '@plugin/registerComponentProperties'; import { transformAutoLayout, transformBlend, @@ -45,15 +46,7 @@ export const transformComponentNode = async (node: ComponentNode): Promise { - if (value.type === 'TEXT' || value.type === 'BOOLEAN') { - componentProperties.set(key, value); - } - }); - } catch (error) { - console.error('Error registering component properties', error); - } + registerComponentProperties(node); } return { diff --git a/plugin-src/transformers/transformFrameNode.ts b/plugin-src/transformers/transformFrameNode.ts index 39e4032f..aa7e5e0c 100644 --- a/plugin-src/transformers/transformFrameNode.ts +++ b/plugin-src/transformers/transformFrameNode.ts @@ -1,4 +1,4 @@ -import { componentProperties } from '@plugin/libraries'; +import { registerComponentProperties } from '@plugin/registerComponentProperties'; import { transformAutoLayout, transformBlend, @@ -37,15 +37,7 @@ export const transformFrameNode = async ( let referencePoint: Point = { x: node.absoluteTransform[0][2], y: node.absoluteTransform[1][2] }; if (isComponentSetNode(node)) { - try { - Object.entries(node.componentPropertyDefinitions).forEach(([key, value]) => { - if (value.type === 'TEXT' || value.type === 'BOOLEAN') { - componentProperties.set(key, value); - } - }); - } catch (error) { - console.error('Error registering component properties', error); - } + registerComponentProperties(node); } if (!isSectionNode(node)) { diff --git a/plugin-src/transformers/transformInstanceNode.ts b/plugin-src/transformers/transformInstanceNode.ts index d1c16489..ec9f1922 100644 --- a/plugin-src/transformers/transformInstanceNode.ts +++ b/plugin-src/transformers/transformInstanceNode.ts @@ -35,7 +35,7 @@ export const transformInstanceNode = async ( nodeOverrides = transformOverrides(node); } - const fetchedOverrides = overrides.get(node.id) ?? []; + const fetchedOverrides = [...(overrides.get(node.id) ?? [])]; if (node.visible !== mainComponent.visible) { fetchedOverrides.push('visible'); } diff --git a/plugin-src/translators/translateTouched.ts b/plugin-src/translators/translateTouched.ts index d94b8e98..54719919 100644 --- a/plugin-src/translators/translateTouched.ts +++ b/plugin-src/translators/translateTouched.ts @@ -1,3 +1,5 @@ +import { componentProperties } from '@plugin/libraries'; + import { SyncGroups } from '@ui/lib/types/utils/syncGroups'; type SyncAttributes = { From 486dd64c50c16d53723715bc5fdfb73fc0a0e06b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20S=C3=A1nchez?= Date: Fri, 28 Jun 2024 12:35:51 +0200 Subject: [PATCH 2/3] changeset --- .changeset/dirty-jobs-begin.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/dirty-jobs-begin.md diff --git a/.changeset/dirty-jobs-begin.md b/.changeset/dirty-jobs-begin.md new file mode 100644 index 00000000..951e328a --- /dev/null +++ b/.changeset/dirty-jobs-begin.md @@ -0,0 +1,5 @@ +--- +"penpot-exporter": patch +--- + +Improve registering component properties From 777abc30bc8da192589a7a8d6c0c712defceeb60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20S=C3=A1nchez?= Date: Fri, 28 Jun 2024 12:37:19 +0200 Subject: [PATCH 3/3] fixes --- plugin-src/translators/translateTouched.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/plugin-src/translators/translateTouched.ts b/plugin-src/translators/translateTouched.ts index 54719919..d94b8e98 100644 --- a/plugin-src/translators/translateTouched.ts +++ b/plugin-src/translators/translateTouched.ts @@ -1,5 +1,3 @@ -import { componentProperties } from '@plugin/libraries'; - import { SyncGroups } from '@ui/lib/types/utils/syncGroups'; type SyncAttributes = {