mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-28 02:02:08 +00:00
Fix IColorable.getColorOption (#551)
* Fix IColorable.getColorOption * nit
This commit is contained in:
@@ -64,23 +64,20 @@ export class LGraphGroup implements Positionable, IPinnable, IColorable {
|
|||||||
: "#AAA"
|
: "#AAA"
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The color option used to set {@link color}. */
|
|
||||||
#colorOption: ColorOption | null = null
|
|
||||||
|
|
||||||
/** @inheritdoc {@link IColorable.setColorOption} */
|
/** @inheritdoc {@link IColorable.setColorOption} */
|
||||||
setColorOption(colorOption: ColorOption | null): void {
|
setColorOption(colorOption: ColorOption | null): void {
|
||||||
if (colorOption == null) {
|
if (colorOption == null) {
|
||||||
delete this.color
|
delete this.color
|
||||||
this.#colorOption = null
|
|
||||||
} else {
|
} else {
|
||||||
this.color = colorOption.groupcolor
|
this.color = colorOption.groupcolor
|
||||||
this.#colorOption = colorOption
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @inheritdoc {@link IColorable.getColorOption} */
|
/** @inheritdoc {@link IColorable.getColorOption} */
|
||||||
getColorOption(): ColorOption | null {
|
getColorOption(): ColorOption | null {
|
||||||
return this.#colorOption
|
return Object.values(LGraphCanvas.node_colors).find(
|
||||||
|
colorOption => colorOption.groupcolor === this.color,
|
||||||
|
) ?? null
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Position of the group, as x,y co-ordinates in graph space */
|
/** Position of the group, as x,y co-ordinates in graph space */
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import type {
|
|||||||
import type { LGraph } from "./LGraph"
|
import type { LGraph } from "./LGraph"
|
||||||
import type { IBaseWidget, IWidget, TWidgetValue } from "./types/widgets"
|
import type { IBaseWidget, IWidget, TWidgetValue } from "./types/widgets"
|
||||||
import type { ISerialisedNode } from "./types/serialisation"
|
import type { ISerialisedNode } from "./types/serialisation"
|
||||||
import type { LGraphCanvas } from "./LGraphCanvas"
|
import { LGraphCanvas } from "./LGraphCanvas"
|
||||||
import type { CanvasMouseEvent } from "./types/events"
|
import type { CanvasMouseEvent } from "./types/events"
|
||||||
import type { DragAndScale } from "./DragAndScale"
|
import type { DragAndScale } from "./DragAndScale"
|
||||||
import type { RerouteId } from "./Reroute"
|
import type { RerouteId } from "./Reroute"
|
||||||
@@ -236,25 +236,23 @@ export class LGraphNode implements Positionable, IPinnable, IColorable {
|
|||||||
return this.boxcolor || colState || LiteGraph.NODE_DEFAULT_BOXCOLOR
|
return this.boxcolor || colState || LiteGraph.NODE_DEFAULT_BOXCOLOR
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The color option used to set {@link color} and {@link bgcolor}. */
|
|
||||||
#colorOption: ColorOption | null = null
|
|
||||||
|
|
||||||
/** @inheritdoc {@link IColorable.setColorOption} */
|
/** @inheritdoc {@link IColorable.setColorOption} */
|
||||||
setColorOption(colorOption: ColorOption | null): void {
|
setColorOption(colorOption: ColorOption | null): void {
|
||||||
if (colorOption == null) {
|
if (colorOption == null) {
|
||||||
delete this.color
|
delete this.color
|
||||||
delete this.bgcolor
|
delete this.bgcolor
|
||||||
this.#colorOption = null
|
|
||||||
} else {
|
} else {
|
||||||
this.color = colorOption.color
|
this.color = colorOption.color
|
||||||
this.bgcolor = colorOption.bgcolor
|
this.bgcolor = colorOption.bgcolor
|
||||||
this.#colorOption = colorOption
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @inheritdoc {@link IColorable.getColorOption} */
|
/** @inheritdoc {@link IColorable.getColorOption} */
|
||||||
getColorOption(): ColorOption | null {
|
getColorOption(): ColorOption | null {
|
||||||
return this.#colorOption
|
return Object.values(LGraphCanvas.node_colors).find(
|
||||||
|
colorOption =>
|
||||||
|
colorOption.color === this.color && colorOption.bgcolor === this.bgcolor,
|
||||||
|
) ?? null
|
||||||
}
|
}
|
||||||
|
|
||||||
exec_version: number
|
exec_version: number
|
||||||
|
|||||||
@@ -83,6 +83,13 @@ export interface IColorable {
|
|||||||
getColorOption(): ColorOption | null
|
getColorOption(): ColorOption | null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if an object is an instance of {@link IColorable}.
|
||||||
|
*/
|
||||||
|
export const isColorable = (obj: unknown): obj is IColorable => {
|
||||||
|
return typeof obj === "object" && obj !== null && "setColorOption" in obj && "getColorOption" in obj
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An object that can be pinned.
|
* An object that can be pinned.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -20,7 +20,9 @@ import type {
|
|||||||
Rect32,
|
Rect32,
|
||||||
Size,
|
Size,
|
||||||
ColorOption,
|
ColorOption,
|
||||||
|
IColorable,
|
||||||
} from "./interfaces"
|
} from "./interfaces"
|
||||||
|
import { isColorable } from "./interfaces"
|
||||||
import type { SlotShape, LabelPosition, SlotDirection, SlotType } from "./draw"
|
import type { SlotShape, LabelPosition, SlotDirection, SlotType } from "./draw"
|
||||||
import type { IWidget } from "./types/widgets"
|
import type { IWidget } from "./types/widgets"
|
||||||
import type { RenderShape, TitleMode } from "./types/globalEnums"
|
import type { RenderShape, TitleMode } from "./types/globalEnums"
|
||||||
@@ -72,6 +74,8 @@ export {
|
|||||||
Rect32,
|
Rect32,
|
||||||
Size,
|
Size,
|
||||||
ColorOption,
|
ColorOption,
|
||||||
|
IColorable,
|
||||||
|
isColorable,
|
||||||
}
|
}
|
||||||
export { IWidget }
|
export { IWidget }
|
||||||
export { LGraphBadge, BadgePosition }
|
export { LGraphBadge, BadgePosition }
|
||||||
|
|||||||
Reference in New Issue
Block a user