Skip to content

Commit

Permalink
Improve registering component properties (#201)
Browse files Browse the repository at this point in the history
* improvements

* changeset

* fixes
  • Loading branch information
Cenadros authored Jun 28, 2024
1 parent 7a11ba9 commit bd36496
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 21 deletions.
5 changes: 5 additions & 0 deletions .changeset/dirty-jobs-begin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"penpot-exporter": patch
---

Improve registering component properties
13 changes: 13 additions & 0 deletions plugin-src/registerComponentProperties.ts
Original file line number Diff line number Diff line change
@@ -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);
}
};
13 changes: 3 additions & 10 deletions plugin-src/transformers/transformComponentNode.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { componentProperties, components } from '@plugin/libraries';
import { components } from '@plugin/libraries';
import { registerComponentProperties } from '@plugin/registerComponentProperties';
import {
transformAutoLayout,
transformBlend,
Expand Down Expand Up @@ -45,15 +46,7 @@ export const transformComponentNode = async (node: ComponentNode): Promise<Compo
});

if (isNonVariantComponentNode(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);
}

return {
Expand Down
12 changes: 2 additions & 10 deletions plugin-src/transformers/transformFrameNode.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { componentProperties } from '@plugin/libraries';
import { registerComponentProperties } from '@plugin/registerComponentProperties';
import {
transformAutoLayout,
transformBlend,
Expand Down Expand Up @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion plugin-src/transformers/transformInstanceNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down

0 comments on commit bd36496

Please sign in to comment.