Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve registering component properties #201

Merged
merged 3 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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