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:
parent
7a11ba992e
commit
bd36496023
5 changed files with 24 additions and 21 deletions
5
.changeset/dirty-jobs-begin.md
Normal file
5
.changeset/dirty-jobs-begin.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
"penpot-exporter": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Improve registering component properties
|
13
plugin-src/registerComponentProperties.ts
Normal file
13
plugin-src/registerComponentProperties.ts
Normal 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);
|
||||||
|
}
|
||||||
|
};
|
|
@ -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 {
|
||||||
|
|
|
@ -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)) {
|
||||||
|
|
|
@ -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');
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue