-
Notifications
You must be signed in to change notification settings - Fork 254
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support multiple windows in layers (#728)
- Loading branch information
Showing
8 changed files
with
133 additions
and
80 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
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,46 +1,81 @@ | ||
import type { TemplateNode } from '@onlook/models/element'; | ||
import type { LayerNode, TemplateNode } from '@onlook/models/element'; | ||
import { makeAutoObservable } from 'mobx'; | ||
|
||
export class TemplateNodeMap { | ||
export class AstRelationshipManager { | ||
templateToSelectors: Map<TemplateNode, string[]> = new Map(); | ||
|
||
selectorToInstance: Map<string, TemplateNode> = new Map(); | ||
selectorToRoot: Map<string, TemplateNode> = new Map(); | ||
selectorToWebviewId: Map<string, string> = new Map(); | ||
|
||
webviewIdToDocument: Map<string, Document> = new Map(); | ||
webviewIdToRootNode: Map<string, LayerNode> = new Map(); | ||
|
||
constructor() { | ||
makeAutoObservable(this); | ||
} | ||
isProcessed(selector: string): boolean { | ||
return this.selectorToInstance.has(selector) || this.selectorToRoot.has(selector); | ||
} | ||
|
||
remove(selector: string) { | ||
this.selectorToInstance.delete(selector); | ||
this.selectorToRoot.delete(selector); | ||
this.selectorToWebviewId.delete(selector); | ||
} | ||
|
||
getSelectors(templateNode: TemplateNode): string[] { | ||
return this.templateToSelectors.get(templateNode) || []; | ||
} | ||
|
||
getInstance(selector: string): TemplateNode | undefined { | ||
getTemplateInstance(selector: string): TemplateNode | undefined { | ||
return this.selectorToInstance.get(selector); | ||
} | ||
|
||
getRoot(selector: string): TemplateNode | undefined { | ||
getTemplateRoot(selector: string): TemplateNode | undefined { | ||
return this.selectorToRoot.get(selector); | ||
} | ||
|
||
setSelector(templateNode: TemplateNode, selector: string) { | ||
getWebviewId(selector: string): string | undefined { | ||
return this.selectorToWebviewId.get(selector); | ||
} | ||
|
||
setSelector(webviewId: string, templateNode: TemplateNode, selector: string) { | ||
const existing = this.templateToSelectors.get(templateNode) || []; | ||
if (!existing.includes(selector)) { | ||
existing.push(selector); | ||
this.templateToSelectors.set(templateNode, existing); | ||
} | ||
this.selectorToWebviewId.set(selector, webviewId); | ||
} | ||
|
||
setRoot(selector: string, templateNode: TemplateNode) { | ||
setTemplateRoot(webviewId: string, selector: string, templateNode: TemplateNode) { | ||
this.selectorToRoot.set(selector, templateNode); | ||
this.setSelector(templateNode, selector); | ||
this.setSelector(webviewId, templateNode, selector); | ||
} | ||
|
||
setInstance(selector: string, templateNode: TemplateNode) { | ||
setTemplateInstance(webviewId: string, selector: string, templateNode: TemplateNode) { | ||
this.selectorToInstance.set(selector, templateNode); | ||
this.setSelector(templateNode, selector); | ||
this.setSelector(webviewId, templateNode, selector); | ||
} | ||
|
||
getRootLayers(): LayerNode[] { | ||
return Array.from(this.webviewIdToRootNode.values()); | ||
} | ||
|
||
getRootLayer(webviewId: string): LayerNode | undefined { | ||
return this.webviewIdToRootNode.get(webviewId); | ||
} | ||
|
||
getDocument(webviewId: string): Document | undefined { | ||
return this.webviewIdToDocument.get(webviewId); | ||
} | ||
|
||
setDocument(webviewId: string, doc: Document) { | ||
this.webviewIdToDocument.set(webviewId, doc); | ||
} | ||
|
||
setRootLayer(webviewId: string, layer: LayerNode) { | ||
this.webviewIdToRootNode.set(webviewId, layer); | ||
} | ||
} |
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 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
Oops, something went wrong.