mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-21 02:18:13 +08:00
Split apart the frontend Editor type into SubscriptionsRouter and EditorHandle (#3923)
* Remove the unused Editor.raw/wasmMemory/wasmImport * Split out Editor.subscriptions * Replace editor.handle.* with editor.* (1 of 2) * Replace editor.handle.* with editor.* (2 of 2) * Replace Editor typedef with EditorHandle import * Pluralize subscription-router and rename subscriptionsRef->subscriptionsRouter and editorRef->editorHandle * Remove editor.ts * Update the readme * Fix demo art loading bug
This commit is contained in:
@@ -3,8 +3,7 @@
|
||||
import { cubicInOut } from "svelte/easing";
|
||||
import { fade } from "svelte/transition";
|
||||
|
||||
import type { FrontendGraphInput, FrontendGraphOutput, FrontendNode } from "@graphite/../wasm/pkg/graphite_wasm";
|
||||
import type { Editor } from "@graphite/editor";
|
||||
import type { EditorHandle, FrontendGraphInput, FrontendGraphOutput, FrontendNode } from "@graphite/../wasm/pkg/graphite_wasm";
|
||||
import type { DocumentStore } from "@graphite/stores/document";
|
||||
import { closeContextMenu } from "@graphite/stores/node-graph";
|
||||
import type { NodeGraphStore } from "@graphite/stores/node-graph";
|
||||
@@ -20,7 +19,7 @@
|
||||
const GRID_SIZE = 24;
|
||||
const FADE_TRANSITION = { duration: 200, easing: cubicInOut };
|
||||
|
||||
const editor = getContext<Editor>("editor");
|
||||
const editor = getContext<EditorHandle>("editor");
|
||||
const nodeGraph = getContext<NodeGraphStore>("nodeGraph");
|
||||
const documentState = getContext<DocumentStore>("document");
|
||||
|
||||
@@ -83,7 +82,7 @@
|
||||
if (editingNameImportIndex !== undefined) {
|
||||
if (!(event.target instanceof HTMLInputElement)) return;
|
||||
let text = event.target.value;
|
||||
editor.handle.setImportName(editingNameImportIndex, text);
|
||||
editor.setImportName(editingNameImportIndex, text);
|
||||
editingNameImportIndex = undefined;
|
||||
}
|
||||
}
|
||||
@@ -92,7 +91,7 @@
|
||||
if (editingNameExportIndex !== undefined) {
|
||||
if (!(event.target instanceof HTMLInputElement)) return;
|
||||
let text = event.target.value;
|
||||
editor.handle.setExportName(editingNameExportIndex, text);
|
||||
editor.setExportName(editingNameExportIndex, text);
|
||||
editingNameExportIndex = undefined;
|
||||
}
|
||||
}
|
||||
@@ -111,7 +110,7 @@
|
||||
function createNode(identifier: string) {
|
||||
if ($nodeGraph.contextMenuInformation === undefined) return;
|
||||
|
||||
editor.handle.createNode(identifier, $nodeGraph.contextMenuInformation.contextMenuCoordinates[0], $nodeGraph.contextMenuInformation.contextMenuCoordinates[1]);
|
||||
editor.createNode(identifier, $nodeGraph.contextMenuInformation.contextMenuCoordinates[0], $nodeGraph.contextMenuInformation.contextMenuCoordinates[1]);
|
||||
}
|
||||
|
||||
function nodeBorderMask(nodeWidth: number, primaryInputExists: boolean, exposedSecondaryInputs: number, primaryOutputExists: boolean, exposedSecondaryOutputs: number): string {
|
||||
@@ -174,11 +173,11 @@
|
||||
}
|
||||
|
||||
function outputConnectedToText(output: FrontendGraphOutput): string {
|
||||
return editor.handle.inDevelopmentMode() ? output.connectedTo.join("\n") : "";
|
||||
return editor.inDevelopmentMode() ? output.connectedTo.join("\n") : "";
|
||||
}
|
||||
|
||||
function inputConnectedToText(input: FrontendGraphInput): string {
|
||||
return editor.handle.inDevelopmentMode() ? input.connectedTo : "";
|
||||
return editor.inDevelopmentMode() ? input.connectedTo : "";
|
||||
}
|
||||
|
||||
function zipWithUndefined(arr1: FrontendGraphInput[], arr2: FrontendGraphOutput[]) {
|
||||
@@ -220,7 +219,7 @@
|
||||
<TextButton
|
||||
label="Merge Selected Nodes"
|
||||
action={() => {
|
||||
editor.handle.mergeSelectedNodes();
|
||||
editor.mergeSelectedNodes();
|
||||
closeContextMenu();
|
||||
}}
|
||||
flush={true}
|
||||
@@ -230,7 +229,7 @@
|
||||
label={currentlyIsNode ? "Display as Layer" : "Display as Node"}
|
||||
action={() => {
|
||||
if ($nodeGraph.contextMenuInformation?.contextMenuData.type === "ModifyNode") {
|
||||
editor.handle.setToNodeOrLayer($nodeGraph.contextMenuInformation.contextMenuData.data.nodeId, currentlyIsNode);
|
||||
editor.setToNodeOrLayer($nodeGraph.contextMenuInformation.contextMenuData.data.nodeId, currentlyIsNode);
|
||||
}
|
||||
closeContextMenu();
|
||||
}}
|
||||
@@ -244,9 +243,9 @@
|
||||
label={allLocked ? "Unlock" : "Lock"}
|
||||
action={() => {
|
||||
if ($nodeGraph.selected.includes(nodeId)) {
|
||||
editor.handle.toggleSelectedLocked();
|
||||
editor.toggleSelectedLocked();
|
||||
} else {
|
||||
editor.handle.toggleLayerLock(nodeId);
|
||||
editor.toggleLayerLock(nodeId);
|
||||
}
|
||||
closeContextMenu();
|
||||
}}
|
||||
@@ -383,7 +382,7 @@
|
||||
style:--offset-top={($nodeGraph.updateImportsExports.importPosition[1] - 12) / 24}
|
||||
style:--offset-left={($nodeGraph.updateImportsExports.importPosition[0] - 12) / 24}
|
||||
>
|
||||
<IconButton size={24} icon="Add" action={() => editor.handle.addPrimaryImport()} />
|
||||
<IconButton size={24} icon="Add" action={() => editor.addPrimaryImport()} />
|
||||
</div>
|
||||
{/if}
|
||||
{/each}
|
||||
@@ -454,7 +453,7 @@
|
||||
style:--offset-left={($nodeGraph.updateImportsExports.exportPosition[0] - 12) / 24}
|
||||
style:--offset-top={($nodeGraph.updateImportsExports.exportPosition[1] - 12) / 24}
|
||||
>
|
||||
<IconButton size={24} icon="Add" action={() => editor.handle.addPrimaryExport()} />
|
||||
<IconButton size={24} icon="Add" action={() => editor.addPrimaryExport()} />
|
||||
</div>
|
||||
{/if}
|
||||
{/each}
|
||||
@@ -465,14 +464,14 @@
|
||||
style:--offset-left={($nodeGraph.updateImportsExports.importPosition[0] - 12) / 24}
|
||||
style:--offset-top={($nodeGraph.updateImportsExports.importPosition[1] - 12) / 24 + $nodeGraph.updateImportsExports.imports.length}
|
||||
>
|
||||
<IconButton size={24} icon="Add" action={() => editor.handle.addSecondaryImport()} />
|
||||
<IconButton size={24} icon="Add" action={() => editor.addSecondaryImport()} />
|
||||
</div>
|
||||
<div
|
||||
class="plus"
|
||||
style:--offset-left={($nodeGraph.updateImportsExports.exportPosition[0] - 12) / 24}
|
||||
style:--offset-top={($nodeGraph.updateImportsExports.exportPosition[1] - 12) / 24 + $nodeGraph.updateImportsExports.exports.length}
|
||||
>
|
||||
<IconButton size={24} icon="Add" action={() => editor.handle.addSecondaryExport()} />
|
||||
<IconButton size={24} icon="Add" action={() => editor.addSecondaryExport()} />
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
@@ -522,7 +521,7 @@
|
||||
style:--node-chain-area-left-extension={layerChainWidth !== 0 ? layerChainWidth + 0.5 : 0}
|
||||
data-tooltip-label={nodeNameTooltipLabel(node)}
|
||||
data-tooltip-description={`
|
||||
${(description || "").trim()}${editor.handle.inDevelopmentMode() ? `\n\nID: ${node.id}. Position: (${node.position[0]}, ${node.position[1]}).` : ""}
|
||||
${(description || "").trim()}${editor.inDevelopmentMode() ? `\n\nID: ${node.id}. Position: (${node.position[0]}, ${node.position[1]}).` : ""}
|
||||
`.trim()}
|
||||
data-node={node.id}
|
||||
>
|
||||
@@ -685,7 +684,7 @@
|
||||
style:--data-color-dim={`var(--color-data-${(node.primaryOutput?.dataType || "General").toLowerCase()}-dim)`}
|
||||
data-tooltip-label={nodeNameTooltipLabel(node)}
|
||||
data-tooltip-description={`
|
||||
${(description || "").trim()}${editor.handle.inDevelopmentMode() ? `\n\nID: ${node.id}. Position: (${node.position[0]}, ${node.position[1]}).` : ""}
|
||||
${(description || "").trim()}${editor.inDevelopmentMode() ? `\n\nID: ${node.id}. Position: (${node.position[0]}, ${node.position[1]}).` : ""}
|
||||
`.trim()}
|
||||
data-node={node.id}
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user