From dc3dab4e1c48aaf3cf270d5c4f41e7e5c773cc99 Mon Sep 17 00:00:00 2001 From: Chenlei Hu Date: Sat, 26 Oct 2024 17:05:42 -0400 Subject: [PATCH] Enable ts-strict for commandStore (#1321) --- src/extensions/core/clipspace.ts | 1 - src/scripts/app.ts | 2 ++ src/scripts/ui.ts | 1 - src/stores/commandStore.ts | 25 ++++++++++++------------- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/extensions/core/clipspace.ts b/src/extensions/core/clipspace.ts index b76caef43..a2c9403ca 100644 --- a/src/extensions/core/clipspace.ts +++ b/src/extensions/core/clipspace.ts @@ -188,7 +188,6 @@ export class ClipspaceDialog extends ComfyDialog { app.registerExtension({ name: 'Comfy.Clipspace', init(app) { - // @ts-expect-error Move to ComfyApp app.openClipspace = function () { if (!ClipspaceDialog.instance) { ClipspaceDialog.instance = new ClipspaceDialog() diff --git a/src/scripts/app.ts b/src/scripts/app.ts index 1dc33a49b..d9167b648 100644 --- a/src/scripts/app.ts +++ b/src/scripts/app.ts @@ -148,6 +148,8 @@ export class ComfyApp { canvasContainer: HTMLElement menu: ComfyAppMenu bypassBgColor: string + // Set by Comfy.Clipspace extension + openClipspace: () => void = () => {} /** * @deprecated Use useExecutionStore().executingNodeId instead diff --git a/src/scripts/ui.ts b/src/scripts/ui.ts index e96711cf5..8695030ab 100644 --- a/src/scripts/ui.ts +++ b/src/scripts/ui.ts @@ -611,7 +611,6 @@ export class ComfyUI { $el('button', { id: 'comfy-clipspace-button', textContent: 'Clipspace', - // @ts-expect-error Move to ComfyApp onclick: () => app.openClipspace() }), $el('button', { diff --git a/src/stores/commandStore.ts b/src/stores/commandStore.ts index db7306dd1..d1ec6400a 100644 --- a/src/stores/commandStore.ts +++ b/src/stores/commandStore.ts @@ -1,4 +1,3 @@ -// @ts-strict-ignore import { app } from '@/scripts/app' import { api } from '@/scripts/api' import { defineStore } from 'pinia' @@ -123,7 +122,7 @@ export const useCommandStore = defineStore('command', () => { app.workflowManager.setWorkflow(null) app.clean() app.graph.clear() - app.workflowManager.activeWorkflow.track() + app.workflowManager.activeWorkflow?.track() } }, { @@ -149,7 +148,7 @@ export const useCommandStore = defineStore('command', () => { label: 'Save Workflow', menubarLabel: 'Save', function: () => { - app.workflowManager.activeWorkflow.save() + app.workflowManager.activeWorkflow?.save() } }, { @@ -158,7 +157,7 @@ export const useCommandStore = defineStore('command', () => { label: 'Save Workflow As', menubarLabel: 'Save As', function: () => { - app.workflowManager.activeWorkflow.save(true) + app.workflowManager.activeWorkflow?.save(true) } }, { @@ -223,7 +222,7 @@ export const useCommandStore = defineStore('command', () => { icon: 'pi pi-clipboard', label: 'Clipspace', function: () => { - app['openClipspace']?.() + app.openClipspace() } }, { @@ -274,10 +273,10 @@ export const useCommandStore = defineStore('command', () => { label: 'Zoom In', function: () => { const ds = app.canvas.ds - ds.changeScale(ds.scale * 1.1, [ - ds.element.width / 2, - ds.element.height / 2 - ]) + ds.changeScale( + ds.scale * 1.1, + ds.element ? [ds.element.width / 2, ds.element.height / 2] : undefined + ) app.canvas.setDirty(true, true) } }, @@ -287,10 +286,10 @@ export const useCommandStore = defineStore('command', () => { label: 'Zoom Out', function: () => { const ds = app.canvas.ds - ds.changeScale(ds.scale / 1.1, [ - ds.element.width / 2, - ds.element.height / 2 - ]) + ds.changeScale( + ds.scale / 1.1, + ds.element ? [ds.element.width / 2, ds.element.height / 2] : undefined + ) app.canvas.setDirty(true, true) } },