From ace25204cc6e392f1120dc70142949c330c339ac Mon Sep 17 00:00:00 2001 From: rgthree Date: Wed, 6 Sep 2023 23:54:55 -0400 Subject: [PATCH] Fix 'Add Comfy Action' Sub Menu item --- js/fast_actions_button.js | 3 ++- js/utils.js | 5 ----- ts/fast_actions_button.ts | 7 ++++--- ts/typings/index.d.ts | 2 ++ ts/utils.ts | 13 +++++++------ tsconfig.json | 14 +++++++++----- 6 files changed, 24 insertions(+), 20 deletions(-) create mode 100644 ts/typings/index.d.ts diff --git a/js/fast_actions_button.js b/js/fast_actions_button.js index f7a3884..807dc71 100644 --- a/js/fast_actions_button.js +++ b/js/fast_actions_button.js @@ -1,6 +1,7 @@ import { app } from "../../scripts/app.js"; import { BaseAnyInputConnectedNode } from "./base_any_input_connected_node.js"; import { NodeTypesString } from "./constants.js"; +import { addMenuItem } from "./utils.js"; const MODE_ALWAYS = 0; const MODE_MUTE = 2; const MODE_BYPASS = 4; @@ -217,7 +218,7 @@ FastActionsButton['@shortcutModifier'] = { type: 'combo', values: ['ctrl', 'alt' FastActionsButton['@shortcutKey'] = { type: 'string' }; FastActionsButton.collapsible = false; app.registerExtension({ - name: "rgthree.FastButtonAction", + name: "rgthree.FastActionsButton", registerCustomNodes() { FastActionsButton.setUp(FastActionsButton); }, diff --git a/js/utils.js b/js/utils.js index c0f916d..8bf1576 100644 --- a/js/utils.js +++ b/js/utils.js @@ -125,11 +125,6 @@ export function getConnectionPosForLayout(node, isInput, slotNumber, out) { console.log('No connection found.. weird', isInput, slotNumber); return out; } - if (cxn.hidden) { - out[0] = node.pos[0] - 100000; - out[1] = node.pos[1] - 100000; - return out; - } if (cxn.disabled) { if (cxn.color_on !== '#666665') { cxn._color_on_org = cxn._color_on_org || cxn.color_on; diff --git a/ts/fast_actions_button.ts b/ts/fast_actions_button.ts index 9ef33fb..fab63f8 100644 --- a/ts/fast_actions_button.ts +++ b/ts/fast_actions_button.ts @@ -6,6 +6,8 @@ import { RgthreeBaseNode } from "./base_node.js"; import { NodeTypesString } from "./constants.js"; import { ComfyApp, ComfyWidget } from "./typings/comfy.js"; import type {IWidget, LGraph, LGraphNode, SerializedLGraphNode} from './typings/litegraph.js'; +import type {Constructor} from './typings/index.js' +import { addMenuItem } from "./utils.js"; const MODE_ALWAYS = 0; const MODE_MUTE = 2; @@ -279,10 +281,9 @@ class FastActionsButton extends BaseAnyInputConnectedNode { } - static override setUp(clazz: new(...args: any[]) => T) { + static override setUp(clazz: Constructor) { BaseAnyInputConnectedNode.setUp(clazz); - // @ts-ignore: Fix incorrect litegraph typings. addMenuItem(clazz, app, { name: '➕ Append a Comfy Action', callback: (nodeArg: LGraphNode) => { @@ -296,7 +297,7 @@ class FastActionsButton extends BaseAnyInputConnectedNode { app.registerExtension({ - name: "rgthree.FastButtonAction", + name: "rgthree.FastActionsButton", registerCustomNodes() { FastActionsButton.setUp(FastActionsButton); }, diff --git a/ts/typings/index.d.ts b/ts/typings/index.d.ts new file mode 100644 index 0000000..4899496 --- /dev/null +++ b/ts/typings/index.d.ts @@ -0,0 +1,2 @@ + +export type Constructor = new(...args: any[]) => T; \ No newline at end of file diff --git a/ts/utils.ts b/ts/utils.ts index 4b52701..86c4ff1 100644 --- a/ts/utils.ts +++ b/ts/utils.ts @@ -1,5 +1,6 @@ import type {ComfyApp} from './typings/comfy'; import {Vector2, LGraphCanvas as TLGraphCanvas, ContextMenuItem, LLink, LGraph, IContextMenuOptions, ContextMenu, LGraphNode as TLGraphNode, LiteGraph as TLiteGraph} from './typings/litegraph.js'; +import type {Constructor} from './typings/index.js' // @ts-ignore import {api} from '../../scripts/api.js'; @@ -47,7 +48,7 @@ interface MenuConfig { subMenuOptions?: string[]; } -export function addMenuItem(node: typeof LGraphNode, _app: ComfyApp, config: MenuConfig) { +export function addMenuItem(node: Constructor, _app: ComfyApp, config: MenuConfig) { const oldGetExtraMenuOptions = node.prototype.getExtraMenuOptions; node.prototype.getExtraMenuOptions = function(canvas: TLGraphCanvas, menuOptions: ContextMenuItem[]) { oldGetExtraMenuOptions && oldGetExtraMenuOptions.apply(this, [canvas, menuOptions]); @@ -162,11 +163,11 @@ export function getConnectionPosForLayout(node: TLGraphNode, isInput: boolean, s } // Experimental; doesn't work without node.clip_area set (so it won't draw outside), // but litegraph.core inexplicably clips the title off which we want... so, no go. - if (cxn.hidden) { - out[0] = node.pos[0] - 100000 - out[1] = node.pos[1] - 100000 - return out - } + // if (cxn.hidden) { + // out[0] = node.pos[0] - 100000 + // out[1] = node.pos[1] - 100000 + // return out + // } if (cxn.disabled) { // Let's store the original colors if have them and haven't yet overridden if (cxn.color_on !== '#666665') { diff --git a/tsconfig.json b/tsconfig.json index da33f25..c4e2d45 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,10 +2,14 @@ "compilerOptions": { "target": "es2019", "module": "ESNext", - "typeRoots": [ - "./ts/typings", - ], - "outDir": "./js/", + // "typeRoots": [ + // "./ts/typings", + // ], + "baseUrl": "./", + "paths": { + "*": ["ts/typings/*"], + }, + "outDir": "js/", "removeComments": true, "strict": true, "noImplicitAny": true, @@ -28,7 +32,7 @@ "skipLibCheck": true, }, "include": [ - "ts/*.ts", + "ts/*.ts", "ts/typings/index.d.ts", ], "exclude": [ "**/*.spec.ts",