mirror of
https://github.com/penpot/penpot-exporter-figma-plugin.git
synced 2025-01-03 13:20:37 -05:00
be5ff3be8e
* remote components processing * changeset * fixes * fixes * fixes * fixes * fix everything * revert for now * fixes * change delete nodes flag --------- Co-authored-by: Jordi Sala Morales <jordism91@gmail.com>
30 lines
805 B
TypeScript
30 lines
805 B
TypeScript
class RemoteComponentsLibrary {
|
|
private components: Record<string, ComponentNode | ComponentSetNode> = {};
|
|
private queue: string[] = [];
|
|
|
|
public register(id: string, component: ComponentNode | ComponentSetNode) {
|
|
if (!Object.prototype.hasOwnProperty.call(this.components, id)) {
|
|
this.queue.push(id);
|
|
}
|
|
|
|
this.components[id] = component;
|
|
}
|
|
|
|
public get(id: string): ComponentNode | ComponentSetNode | undefined {
|
|
return this.components[id];
|
|
}
|
|
|
|
public next(): ComponentNode | ComponentSetNode {
|
|
const lastKey = this.queue.pop();
|
|
|
|
if (!lastKey) throw new Error('No components to pop');
|
|
|
|
return this.components[lastKey];
|
|
}
|
|
|
|
public remaining(): number {
|
|
return this.queue.length;
|
|
}
|
|
}
|
|
|
|
export const remoteComponentLibrary = new RemoteComponentsLibrary();
|