0
Fork 0
mirror of https://github.com/penpot/penpot-exporter-figma-plugin.git synced 2024-12-22 05:33:02 -05:00

Improve registering component properties (#201)

* improvements

* changeset

* fixes
This commit is contained in:
Alex Sánchez 2024-06-28 12:38:25 +02:00 committed by GitHub
parent 7a11ba992e
commit bd36496023
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 24 additions and 21 deletions

View file

@ -0,0 +1,5 @@
---
"penpot-exporter": patch
---
Improve registering component properties

View file

@ -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);
}
};

View file

@ -1,4 +1,5 @@
import { componentProperties, components } from '@plugin/libraries'; import { components } from '@plugin/libraries';
import { registerComponentProperties } from '@plugin/registerComponentProperties';
import { import {
transformAutoLayout, transformAutoLayout,
transformBlend, transformBlend,
@ -45,15 +46,7 @@ export const transformComponentNode = async (node: ComponentNode): Promise<Compo
}); });
if (isNonVariantComponentNode(node)) { if (isNonVariantComponentNode(node)) {
try { registerComponentProperties(node);
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);
}
} }
return { return {

View file

@ -1,4 +1,4 @@
import { componentProperties } from '@plugin/libraries'; import { registerComponentProperties } from '@plugin/registerComponentProperties';
import { import {
transformAutoLayout, transformAutoLayout,
transformBlend, transformBlend,
@ -37,15 +37,7 @@ export const transformFrameNode = async (
let referencePoint: Point = { x: node.absoluteTransform[0][2], y: node.absoluteTransform[1][2] }; let referencePoint: Point = { x: node.absoluteTransform[0][2], y: node.absoluteTransform[1][2] };
if (isComponentSetNode(node)) { if (isComponentSetNode(node)) {
try { registerComponentProperties(node);
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);
}
} }
if (!isSectionNode(node)) { if (!isSectionNode(node)) {

View file

@ -35,7 +35,7 @@ export const transformInstanceNode = async (
nodeOverrides = transformOverrides(node); nodeOverrides = transformOverrides(node);
} }
const fetchedOverrides = overrides.get(node.id) ?? []; const fetchedOverrides = [...(overrides.get(node.id) ?? [])];
if (node.visible !== mainComponent.visible) { if (node.visible !== mainComponent.visible) {
fetchedOverrides.push('visible'); fetchedOverrides.push('visible');
} }