mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-28 11:08:12 +08:00
Clean up code with better naming
This commit is contained in:
@@ -13,33 +13,33 @@ export function createAppWindowState(editor: Editor) {
|
||||
});
|
||||
|
||||
// Set up message subscriptions on creation
|
||||
editor.subscriptions.subscribeJsMessage(UpdatePlatform, (updatePlatform) => {
|
||||
editor.subscriptions.subscribeJsMessage(UpdatePlatform, (data) => {
|
||||
update((state) => {
|
||||
state.platform = updatePlatform.platform;
|
||||
state.platform = data.platform;
|
||||
return state;
|
||||
});
|
||||
});
|
||||
editor.subscriptions.subscribeJsMessage(UpdateMaximized, (updateMaximized) => {
|
||||
editor.subscriptions.subscribeJsMessage(UpdateMaximized, (data) => {
|
||||
update((state) => {
|
||||
state.maximized = updateMaximized.maximized;
|
||||
state.maximized = data.maximized;
|
||||
return state;
|
||||
});
|
||||
});
|
||||
editor.subscriptions.subscribeJsMessage(UpdateFullscreen, (updateFullscreen) => {
|
||||
editor.subscriptions.subscribeJsMessage(UpdateFullscreen, (data) => {
|
||||
update((state) => {
|
||||
state.fullscreen = updateFullscreen.fullscreen;
|
||||
state.fullscreen = data.fullscreen;
|
||||
return state;
|
||||
});
|
||||
});
|
||||
editor.subscriptions.subscribeJsMessage(UpdateViewportHolePunch, (viewportHolePunch) => {
|
||||
editor.subscriptions.subscribeJsMessage(UpdateViewportHolePunch, (data) => {
|
||||
update((state) => {
|
||||
state.viewportHolePunch = viewportHolePunch.active;
|
||||
state.viewportHolePunch = data.active;
|
||||
return state;
|
||||
});
|
||||
});
|
||||
editor.subscriptions.subscribeJsMessage(UpdateUIScale, (uiScale) => {
|
||||
editor.subscriptions.subscribeJsMessage(UpdateUIScale, (data) => {
|
||||
update((state) => {
|
||||
state.uiScale = uiScale.scale;
|
||||
state.uiScale = data.scale;
|
||||
return state;
|
||||
});
|
||||
});
|
||||
|
||||
@@ -45,33 +45,33 @@ export function createDialogState(editor: Editor) {
|
||||
}
|
||||
|
||||
// Subscribe to process backend events
|
||||
editor.subscriptions.subscribeJsMessage(DisplayDialog, (displayDialog) => {
|
||||
editor.subscriptions.subscribeJsMessage(DisplayDialog, (data) => {
|
||||
update((state) => {
|
||||
state.visible = true;
|
||||
|
||||
state.title = displayDialog.title;
|
||||
state.icon = displayDialog.icon;
|
||||
state.title = data.title;
|
||||
state.icon = data.icon;
|
||||
|
||||
return state;
|
||||
});
|
||||
});
|
||||
editor.subscriptions.subscribeJsMessage(UpdateDialogButtons, (updateDialogButtons) => {
|
||||
editor.subscriptions.subscribeJsMessage(UpdateDialogButtons, (data) => {
|
||||
update((state) => {
|
||||
patchLayout(state.buttons, updateDialogButtons);
|
||||
patchLayout(state.buttons, data);
|
||||
|
||||
return state;
|
||||
});
|
||||
});
|
||||
editor.subscriptions.subscribeJsMessage(UpdateDialogColumn1, (updateDialogColumn1) => {
|
||||
editor.subscriptions.subscribeJsMessage(UpdateDialogColumn1, (data) => {
|
||||
update((state) => {
|
||||
patchLayout(state.column1, updateDialogColumn1);
|
||||
patchLayout(state.column1, data);
|
||||
|
||||
return state;
|
||||
});
|
||||
});
|
||||
editor.subscriptions.subscribeJsMessage(UpdateDialogColumn2, (updateDialogColumn2) => {
|
||||
editor.subscriptions.subscribeJsMessage(UpdateDialogColumn2, (data) => {
|
||||
update((state) => {
|
||||
patchLayout(state.column2, updateDialogColumn2);
|
||||
patchLayout(state.column2, data);
|
||||
|
||||
return state;
|
||||
});
|
||||
|
||||
@@ -30,55 +30,55 @@ export function createDocumentState(editor: Editor) {
|
||||
const { subscribe, update } = state;
|
||||
|
||||
// Update layouts
|
||||
editor.subscriptions.subscribeJsMessage(UpdateGraphFadeArtwork, (updateGraphFadeArtwork) => {
|
||||
editor.subscriptions.subscribeJsMessage(UpdateGraphFadeArtwork, (data) => {
|
||||
update((state) => {
|
||||
state.fadeArtwork = updateGraphFadeArtwork.percentage;
|
||||
state.fadeArtwork = data.percentage;
|
||||
return state;
|
||||
});
|
||||
});
|
||||
editor.subscriptions.subscribeJsMessage(UpdateToolOptionsLayout, async (updateToolOptionsLayout) => {
|
||||
editor.subscriptions.subscribeJsMessage(UpdateToolOptionsLayout, async (data) => {
|
||||
await tick();
|
||||
|
||||
update((state) => {
|
||||
patchLayout(state.toolOptionsLayout, updateToolOptionsLayout);
|
||||
patchLayout(state.toolOptionsLayout, data);
|
||||
return state;
|
||||
});
|
||||
});
|
||||
editor.subscriptions.subscribeJsMessage(UpdateDocumentBarLayout, async (updateDocumentBarLayout) => {
|
||||
editor.subscriptions.subscribeJsMessage(UpdateDocumentBarLayout, async (data) => {
|
||||
await tick();
|
||||
|
||||
update((state) => {
|
||||
patchLayout(state.documentBarLayout, updateDocumentBarLayout);
|
||||
patchLayout(state.documentBarLayout, data);
|
||||
return state;
|
||||
});
|
||||
});
|
||||
editor.subscriptions.subscribeJsMessage(UpdateToolShelfLayout, async (updateToolShelfLayout) => {
|
||||
editor.subscriptions.subscribeJsMessage(UpdateToolShelfLayout, async (data) => {
|
||||
await tick();
|
||||
|
||||
update((state) => {
|
||||
patchLayout(state.toolShelfLayout, updateToolShelfLayout);
|
||||
patchLayout(state.toolShelfLayout, data);
|
||||
return state;
|
||||
});
|
||||
});
|
||||
editor.subscriptions.subscribeJsMessage(UpdateWorkingColorsLayout, async (updateWorkingColorsLayout) => {
|
||||
editor.subscriptions.subscribeJsMessage(UpdateWorkingColorsLayout, async (data) => {
|
||||
await tick();
|
||||
|
||||
update((state) => {
|
||||
patchLayout(state.workingColorsLayout, updateWorkingColorsLayout);
|
||||
patchLayout(state.workingColorsLayout, data);
|
||||
return state;
|
||||
});
|
||||
});
|
||||
editor.subscriptions.subscribeJsMessage(UpdateNodeGraphControlBarLayout, (updateNodeGraphControlBarLayout) => {
|
||||
editor.subscriptions.subscribeJsMessage(UpdateNodeGraphControlBarLayout, (data) => {
|
||||
update((state) => {
|
||||
patchLayout(state.nodeGraphControlBarLayout, updateNodeGraphControlBarLayout);
|
||||
patchLayout(state.nodeGraphControlBarLayout, data);
|
||||
return state;
|
||||
});
|
||||
});
|
||||
|
||||
// Show or hide the graph view overlay
|
||||
editor.subscriptions.subscribeJsMessage(UpdateGraphViewOverlay, (updateGraphViewOverlay) => {
|
||||
editor.subscriptions.subscribeJsMessage(UpdateGraphViewOverlay, (data) => {
|
||||
update((state) => {
|
||||
state.graphViewOverlayOpen = updateGraphViewOverlay.open;
|
||||
state.graphViewOverlayOpen = data.open;
|
||||
return state;
|
||||
});
|
||||
});
|
||||
|
||||
@@ -62,87 +62,87 @@ export function createNodeGraphState(editor: Editor) {
|
||||
}
|
||||
|
||||
// Set up message subscriptions on creation
|
||||
editor.subscriptions.subscribeJsMessage(SendUIMetadata, (uiMetadata) => {
|
||||
editor.subscriptions.subscribeJsMessage(SendUIMetadata, (data) => {
|
||||
update((state) => {
|
||||
state.nodeDescriptions = uiMetadata.nodeDescriptions;
|
||||
state.nodeTypes = uiMetadata.nodeTypes;
|
||||
state.nodeDescriptions = data.nodeDescriptions;
|
||||
state.nodeTypes = data.nodeTypes;
|
||||
return state;
|
||||
});
|
||||
});
|
||||
editor.subscriptions.subscribeJsMessage(UpdateBox, (updateBox) => {
|
||||
editor.subscriptions.subscribeJsMessage(UpdateBox, (data) => {
|
||||
update((state) => {
|
||||
state.box = updateBox.box;
|
||||
state.box = data.box;
|
||||
return state;
|
||||
});
|
||||
});
|
||||
editor.subscriptions.subscribeJsMessage(UpdateClickTargets, (UpdateClickTargets) => {
|
||||
editor.subscriptions.subscribeJsMessage(UpdateClickTargets, (data) => {
|
||||
update((state) => {
|
||||
state.clickTargets = UpdateClickTargets.clickTargets;
|
||||
state.clickTargets = data.clickTargets;
|
||||
return state;
|
||||
});
|
||||
});
|
||||
editor.subscriptions.subscribeJsMessage(UpdateContextMenuInformation, (updateContextMenuInformation) => {
|
||||
editor.subscriptions.subscribeJsMessage(UpdateContextMenuInformation, (data) => {
|
||||
update((state) => {
|
||||
state.contextMenuInformation = updateContextMenuInformation.contextMenuInformation;
|
||||
state.contextMenuInformation = data.contextMenuInformation;
|
||||
return state;
|
||||
});
|
||||
});
|
||||
editor.subscriptions.subscribeJsMessage(UpdateImportReorderIndex, (updateImportReorderIndex) => {
|
||||
editor.subscriptions.subscribeJsMessage(UpdateImportReorderIndex, (data) => {
|
||||
update((state) => {
|
||||
state.reorderImportIndex = updateImportReorderIndex.importIndex;
|
||||
state.reorderImportIndex = data.importIndex;
|
||||
return state;
|
||||
});
|
||||
});
|
||||
editor.subscriptions.subscribeJsMessage(UpdateExportReorderIndex, (updateExportReorderIndex) => {
|
||||
editor.subscriptions.subscribeJsMessage(UpdateExportReorderIndex, (data) => {
|
||||
update((state) => {
|
||||
state.reorderExportIndex = updateExportReorderIndex.exportIndex;
|
||||
state.reorderExportIndex = data.exportIndex;
|
||||
return state;
|
||||
});
|
||||
});
|
||||
editor.subscriptions.subscribeJsMessage(UpdateImportsExports, (updateImportsExports) => {
|
||||
editor.subscriptions.subscribeJsMessage(UpdateImportsExports, (data) => {
|
||||
update((state) => {
|
||||
state.updateImportsExports = updateImportsExports;
|
||||
state.updateImportsExports = data;
|
||||
return state;
|
||||
});
|
||||
});
|
||||
editor.subscriptions.subscribeJsMessage(UpdateInSelectedNetwork, (updateInSelectedNetwork) => {
|
||||
editor.subscriptions.subscribeJsMessage(UpdateInSelectedNetwork, (data) => {
|
||||
update((state) => {
|
||||
state.inSelectedNetwork = updateInSelectedNetwork.inSelectedNetwork;
|
||||
state.inSelectedNetwork = data.inSelectedNetwork;
|
||||
return state;
|
||||
});
|
||||
});
|
||||
editor.subscriptions.subscribeJsMessage(UpdateLayerWidths, (updateLayerWidths) => {
|
||||
editor.subscriptions.subscribeJsMessage(UpdateLayerWidths, (data) => {
|
||||
update((state) => {
|
||||
state.layerWidths = updateLayerWidths.layerWidths;
|
||||
state.chainWidths = updateLayerWidths.chainWidths;
|
||||
state.hasLeftInputWire = updateLayerWidths.hasLeftInputWire;
|
||||
state.layerWidths = data.layerWidths;
|
||||
state.chainWidths = data.chainWidths;
|
||||
state.hasLeftInputWire = data.hasLeftInputWire;
|
||||
return state;
|
||||
});
|
||||
});
|
||||
editor.subscriptions.subscribeJsMessage(UpdateNodeGraphNodes, (updateNodeGraphNodes) => {
|
||||
editor.subscriptions.subscribeJsMessage(UpdateNodeGraphNodes, (data) => {
|
||||
update((state) => {
|
||||
state.nodes.clear();
|
||||
updateNodeGraphNodes.nodes.forEach((node) => {
|
||||
data.nodes.forEach((node) => {
|
||||
state.nodes.set(node.id, node);
|
||||
});
|
||||
return state;
|
||||
});
|
||||
});
|
||||
editor.subscriptions.subscribeJsMessage(UpdateNodeGraphErrorDiagnostic, (updateNodeGraphErrorDiagnostic) => {
|
||||
editor.subscriptions.subscribeJsMessage(UpdateNodeGraphErrorDiagnostic, (data) => {
|
||||
update((state) => {
|
||||
state.error = updateNodeGraphErrorDiagnostic.error;
|
||||
state.error = data.error;
|
||||
return state;
|
||||
});
|
||||
});
|
||||
editor.subscriptions.subscribeJsMessage(UpdateVisibleNodes, (updateVisibleNodes) => {
|
||||
editor.subscriptions.subscribeJsMessage(UpdateVisibleNodes, (data) => {
|
||||
update((state) => {
|
||||
state.visibleNodes = new Set<bigint>(updateVisibleNodes.nodes);
|
||||
state.visibleNodes = new Set<bigint>(data.nodes);
|
||||
return state;
|
||||
});
|
||||
});
|
||||
editor.subscriptions.subscribeJsMessage(UpdateNodeGraphWires, (updateNodeWires) => {
|
||||
editor.subscriptions.subscribeJsMessage(UpdateNodeGraphWires, (data) => {
|
||||
update((state) => {
|
||||
updateNodeWires.wires.forEach((wireUpdate) => {
|
||||
data.wires.forEach((wireUpdate) => {
|
||||
let inputMap = state.wires.get(wireUpdate.id);
|
||||
// If it doesn't exist, create it and set it in the outer map
|
||||
if (!inputMap) {
|
||||
@@ -158,33 +158,33 @@ export function createNodeGraphState(editor: Editor) {
|
||||
return state;
|
||||
});
|
||||
});
|
||||
editor.subscriptions.subscribeJsMessage(ClearAllNodeGraphWires, (_) => {
|
||||
editor.subscriptions.subscribeJsMessage(ClearAllNodeGraphWires, () => {
|
||||
update((state) => {
|
||||
state.wires.clear();
|
||||
return state;
|
||||
});
|
||||
});
|
||||
editor.subscriptions.subscribeJsMessage(UpdateNodeGraphSelection, (updateNodeGraphSelection) => {
|
||||
editor.subscriptions.subscribeJsMessage(UpdateNodeGraphSelection, (data) => {
|
||||
update((state) => {
|
||||
state.selected = updateNodeGraphSelection.selected;
|
||||
state.selected = data.selected;
|
||||
return state;
|
||||
});
|
||||
});
|
||||
editor.subscriptions.subscribeJsMessage(UpdateNodeGraphTransform, (updateNodeGraphTransform) => {
|
||||
editor.subscriptions.subscribeJsMessage(UpdateNodeGraphTransform, (data) => {
|
||||
update((state) => {
|
||||
state.transform = updateNodeGraphTransform.transform;
|
||||
state.transform = data.transform;
|
||||
return state;
|
||||
});
|
||||
});
|
||||
editor.subscriptions.subscribeJsMessage(UpdateNodeThumbnail, (updateNodeThumbnail) => {
|
||||
editor.subscriptions.subscribeJsMessage(UpdateNodeThumbnail, (data) => {
|
||||
update((state) => {
|
||||
state.thumbnails.set(updateNodeThumbnail.id, updateNodeThumbnail.value);
|
||||
state.thumbnails.set(data.id, data.value);
|
||||
return state;
|
||||
});
|
||||
});
|
||||
editor.subscriptions.subscribeJsMessage(UpdateWirePathInProgress, (updateWirePathInProgress) => {
|
||||
editor.subscriptions.subscribeJsMessage(UpdateWirePathInProgress, (data) => {
|
||||
update((state) => {
|
||||
state.wirePathInProgress = updateWirePathInProgress.wirePath;
|
||||
state.wirePathInProgress = data.wirePath;
|
||||
return state;
|
||||
});
|
||||
});
|
||||
|
||||
@@ -29,26 +29,26 @@ export function createPortfolioState(editor: Editor) {
|
||||
});
|
||||
|
||||
// Set up message subscriptions on creation
|
||||
editor.subscriptions.subscribeJsMessage(UpdateOpenDocumentsList, (updateOpenDocumentList) => {
|
||||
editor.subscriptions.subscribeJsMessage(UpdateOpenDocumentsList, (data) => {
|
||||
update((state) => {
|
||||
state.documents = updateOpenDocumentList.openDocuments;
|
||||
state.documents = data.openDocuments;
|
||||
return state;
|
||||
});
|
||||
});
|
||||
editor.subscriptions.subscribeJsMessage(UpdateActiveDocument, (updateActiveDocument) => {
|
||||
editor.subscriptions.subscribeJsMessage(UpdateActiveDocument, (data) => {
|
||||
update((state) => {
|
||||
// Assume we receive a correct document id
|
||||
const activeId = state.documents.findIndex((doc) => doc.id === updateActiveDocument.documentId);
|
||||
const activeId = state.documents.findIndex((doc) => doc.id === data.documentId);
|
||||
state.activeDocumentIndex = activeId;
|
||||
return state;
|
||||
});
|
||||
});
|
||||
editor.subscriptions.subscribeJsMessage(TriggerFetchAndOpenDocument, async (triggerFetchAndOpenDocument) => {
|
||||
editor.subscriptions.subscribeJsMessage(TriggerFetchAndOpenDocument, async (data) => {
|
||||
try {
|
||||
const { name, filename } = triggerFetchAndOpenDocument;
|
||||
const { name, filename } = data;
|
||||
const url = new URL(`demo-artwork/${filename}`, document.location.href);
|
||||
const data = await fetch(url);
|
||||
const content = await data.text();
|
||||
const response = await fetch(url);
|
||||
const content = await response.text();
|
||||
|
||||
editor.handle.openDocumentFile(name, content);
|
||||
} catch {
|
||||
@@ -90,14 +90,14 @@ export function createPortfolioState(editor: Editor) {
|
||||
const imageData = await extractPixelData(new Blob([new Uint8Array(data.content.data)], { type: data.type }));
|
||||
editor.handle.pasteImage(data.filename, new Uint8Array(imageData.data), imageData.width, imageData.height);
|
||||
});
|
||||
editor.subscriptions.subscribeJsMessage(TriggerSaveDocument, (triggerSaveDocument) => {
|
||||
downloadFile(triggerSaveDocument.name, triggerSaveDocument.content);
|
||||
editor.subscriptions.subscribeJsMessage(TriggerSaveDocument, (data) => {
|
||||
downloadFile(data.name, data.content);
|
||||
});
|
||||
editor.subscriptions.subscribeJsMessage(TriggerSaveFile, (triggerFileDownload) => {
|
||||
downloadFile(triggerFileDownload.name, triggerFileDownload.content);
|
||||
editor.subscriptions.subscribeJsMessage(TriggerSaveFile, (data) => {
|
||||
downloadFile(data.name, data.content);
|
||||
});
|
||||
editor.subscriptions.subscribeJsMessage(TriggerExportImage, async (TriggerExportImage) => {
|
||||
const { svg, name, mime, size } = TriggerExportImage;
|
||||
editor.subscriptions.subscribeJsMessage(TriggerExportImage, async (data) => {
|
||||
const { svg, name, mime, size } = data;
|
||||
|
||||
// Fill the canvas with white if it'll be a JPEG (which does not support transparency and defaults to black)
|
||||
const backgroundColor = mime.endsWith("jpeg") ? "white" : undefined;
|
||||
@@ -112,21 +112,21 @@ export function createPortfolioState(editor: Editor) {
|
||||
// Fail silently if there's an error rasterizing the SVG, such as a zero-sized image
|
||||
}
|
||||
});
|
||||
editor.subscriptions.subscribeJsMessage(UpdateDataPanelState, async (updateDataPanelState) => {
|
||||
editor.subscriptions.subscribeJsMessage(UpdateDataPanelState, async (data) => {
|
||||
update((state) => {
|
||||
state.dataPanelOpen = updateDataPanelState.open;
|
||||
state.dataPanelOpen = data.open;
|
||||
return state;
|
||||
});
|
||||
});
|
||||
editor.subscriptions.subscribeJsMessage(UpdatePropertiesPanelState, async (updatePropertiesPanelState) => {
|
||||
editor.subscriptions.subscribeJsMessage(UpdatePropertiesPanelState, async (data) => {
|
||||
update((state) => {
|
||||
state.propertiesPanelOpen = updatePropertiesPanelState.open;
|
||||
state.propertiesPanelOpen = data.open;
|
||||
return state;
|
||||
});
|
||||
});
|
||||
editor.subscriptions.subscribeJsMessage(UpdateLayersPanelState, async (updateLayersPanelState) => {
|
||||
editor.subscriptions.subscribeJsMessage(UpdateLayersPanelState, async (data) => {
|
||||
update((state) => {
|
||||
state.layersPanelOpen = updateLayersPanelState.open;
|
||||
state.layersPanelOpen = data.open;
|
||||
return state;
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user