Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Cenadros committed Jun 6, 2024
1 parent cec9529 commit 4a9b42f
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 17 deletions.
17 changes: 7 additions & 10 deletions plugin-src/RemoteComponentLibrary.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
class RemoteComponentsLibrary {
private components: Record<string, ComponentNode | ComponentSetNode> = {};
private keys: string[] = [];
private queue: string[] = [];

public register(id: string, component: ComponentNode | ComponentSetNode) {
if (!Object.prototype.hasOwnProperty.call(this.components, id)) {
this.keys.push(id);
this.queue.push(id);
}

this.components[id] = component;
Expand All @@ -14,19 +14,16 @@ class RemoteComponentsLibrary {
return this.components[id];
}

public pop(): ComponentNode | ComponentSetNode {
const lastKey = this.keys.pop();
public next(): ComponentNode | ComponentSetNode {
const lastKey = this.queue.pop();

if (!lastKey) throw new Error('No components to pop');

const value = this.components[lastKey];
delete this.components[lastKey];

return value;
return this.components[lastKey];
}

public length(): number {
return this.keys.length;
public remaining(): number {
return this.queue.length;
}
}

Expand Down
1 change: 1 addition & 0 deletions plugin-src/transformers/transformComponentNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const transformComponentNode = async (
type: 'component',
name: node.name,
path: node.parent?.type === 'COMPONENT_SET' ? node.parent.name : '',
showContent: !node.clipsContent,
...transformFigmaIds(node),
...transformFills(node),
...transformEffects(node),
Expand Down
2 changes: 1 addition & 1 deletion plugin-src/transformers/transformDocumentNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const transformDocumentNode = async (node: DocumentNode): Promise<PenpotD
await sleep(0);
}

if (remoteComponentLibrary.length() > 0) {
if (remoteComponentLibrary.remaining() > 0) {
children.push({
name: 'External Components',
children: await translateRemoteChildren()
Expand Down
5 changes: 3 additions & 2 deletions plugin-src/transformers/transformInstanceNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ export const transformInstanceNode = async (
): Promise<ComponentInstance | undefined> => {
const mainComponent = await node.getMainComponentAsync();

if (mainComponent === null || isUnprocessableComponent(mainComponent)) {
if (mainComponent === null) {
return;
}

if (isExternalComponent(mainComponent)) {
if (isExternalComponent(mainComponent) || isUnprocessableComponent(mainComponent)) {
await registerExternalComponents(mainComponent);
}

Expand All @@ -34,6 +34,7 @@ export const transformInstanceNode = async (
name: node.name,
mainComponentFigmaId: mainComponent.id,
isComponentRoot: isComponentRoot(node),
showContent: !node.clipsContent,
...transformFigmaIds(node),
...transformFills(node),
...transformEffects(node),
Expand Down
4 changes: 2 additions & 2 deletions plugin-src/translators/translateChildren.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ export const translateChildren = async (
export const translateRemoteChildren = async (): Promise<PenpotNode[]> => {
const transformedChildren: PenpotNode[] = [];

while (remoteComponentLibrary.length() > 0) {
const child = remoteComponentLibrary.pop();
while (remoteComponentLibrary.remaining() > 0) {
const child = remoteComponentLibrary.next();

const penpotNode = await transformSceneNode(child);

Expand Down
1 change: 1 addition & 0 deletions ui-src/lib/types/shapes/componentShape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export type ComponentAttributes = {
type?: 'component';
name: string;
path: string;
showContent?: boolean;
mainInstanceId?: Uuid;
mainInstancePage?: Uuid;
};
1 change: 0 additions & 1 deletion ui-src/parser/creators/createComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export const createComponent = (file: PenpotFile, { figmaId }: ComponentRoot) =>

const frameId = createArtboard(file, {
...component,
showContent: true,
componentFile: file.getId(),
componentId,
componentRoot: true,
Expand Down
1 change: 0 additions & 1 deletion ui-src/parser/creators/createComponentInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export const createComponentInstance = (

createArtboard(file, {
...rest,
showContent: true,
shapeRef: uiComponent.mainInstanceId,
componentFile: file.getId(),
componentRoot: isComponentRoot,
Expand Down
1 change: 1 addition & 0 deletions ui-src/types/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ export type ComponentInstance = ShapeGeomAttributes &
figmaId?: string;
figmaRelatedId?: string;
isComponentRoot: boolean;
showContent?: boolean;
type: 'instance';
};

0 comments on commit 4a9b42f

Please sign in to comment.