-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/main' into feature/component-i…
…nstance
- Loading branch information
Showing
19 changed files
with
137 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { ComponentShape } from '@ui/lib/types/shapes/componentShape'; | ||
|
||
class ComponentLibrary { | ||
private components: Record<string, ComponentShape> = {}; | ||
|
||
public register(id: string, component: ComponentShape) { | ||
this.components[id] = component; | ||
} | ||
|
||
public get(id: string): ComponentShape | undefined { | ||
return this.components[id]; | ||
} | ||
|
||
public all(): Record<string, ComponentShape> { | ||
return this.components; | ||
} | ||
|
||
public init(components: Record<string, ComponentShape>): void { | ||
this.components = components; | ||
} | ||
} | ||
|
||
export const componentsLibrary = new ComponentLibrary(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
import { PenpotDocument } from '@ui/lib/types/penpotDocument'; | ||
import { componentsLibrary } from '@plugin/ComponentLibrary'; | ||
|
||
import { PenpotDocument } from '@ui/types'; | ||
|
||
import { transformPageNode } from '.'; | ||
|
||
export const transformDocumentNode = async (node: DocumentNode): Promise<PenpotDocument> => { | ||
return { | ||
name: node.name, | ||
children: await Promise.all(node.children.map(child => transformPageNode(child))) | ||
children: await Promise.all(node.children.map(child => transformPageNode(child))), | ||
components: componentsLibrary.all() | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import { PenpotNode } from '@ui/lib/types/penpotNode'; | ||
import { PenpotNode } from '@ui/types'; | ||
|
||
export type Children = { children?: PenpotNode[] }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,34 @@ | ||
import { componentsLibrary } from '@plugin/ComponentLibrary'; | ||
|
||
import { PenpotFile } from '@ui/lib/types/penpotFile'; | ||
import { ComponentShape } from '@ui/lib/types/shapes/componentShape'; | ||
import { components } from '@ui/parser/libraries'; | ||
import { uiComponents } from '@ui/parser/libraries'; | ||
import { ComponentRoot } from '@ui/types'; | ||
|
||
import { createArtboard } from '.'; | ||
|
||
export const createComponent = ( | ||
file: PenpotFile, | ||
{ type, path, children = [], ...rest }: ComponentShape | ||
) => { | ||
export const createComponent = (file: PenpotFile, { figmaId }: ComponentRoot) => { | ||
const frameId = file.newId(); | ||
const componentId = file.newId(); | ||
|
||
const commonStructure = { | ||
...rest, | ||
children, | ||
const component = componentsLibrary.get(figmaId); | ||
if (!component) { | ||
return; | ||
} | ||
|
||
createArtboard(file, { | ||
...component, | ||
componentFile: file.getId(), | ||
componentId: componentId, | ||
componentRoot: true, | ||
mainInstance: true | ||
}; | ||
|
||
createArtboard(file, { | ||
...commonStructure, | ||
id: frameId, | ||
mainInstance: true, | ||
id: frameId, | ||
type: 'frame' | ||
}); | ||
|
||
components.add({ | ||
...commonStructure, | ||
id: componentId, | ||
mainInstanceId: frameId, | ||
uiComponents.register(figmaId, { | ||
componentId, | ||
mainInstancePage: file.getCurrentPageId(), | ||
path, | ||
type | ||
componentFigmaId: figmaId, | ||
mainInstanceId: frameId | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { Uuid } from '@ui/lib/types/utils/uuid'; | ||
|
||
type UiComponent = { | ||
componentId: Uuid; | ||
mainInstancePage: Uuid; | ||
mainInstanceId: Uuid; | ||
componentFigmaId: string; | ||
}; | ||
|
||
class UiComponents { | ||
private components: Record<string, UiComponent> = {}; | ||
|
||
public register(id: string, component: UiComponent) { | ||
this.components[id] = component; | ||
} | ||
|
||
public get(id: string): UiComponent | undefined { | ||
return this.components[id]; | ||
} | ||
|
||
public all(): UiComponent[] { | ||
return Object.values(this.components); | ||
} | ||
|
||
public init() { | ||
this.components = {}; | ||
} | ||
} | ||
|
||
export const uiComponents = new UiComponents(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export * from './Components'; | ||
export * from './UiComponents'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export type ComponentRoot = { | ||
figmaId: string; | ||
type: 'component'; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './componentRoot'; | ||
export * from './penpotDocument'; | ||
export * from './penpotNode'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { PenpotPage } from '@ui/lib/types/penpotPage'; | ||
import { ComponentShape } from '@ui/lib/types/shapes/componentShape'; | ||
|
||
export type PenpotDocument = { | ||
name: string; | ||
children?: PenpotPage[]; | ||
components: Record<string, ComponentShape>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters