mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-02 14:27:40 +00:00
[TS] Use strict mode in LLink & Reroute (#602)
- Adds fallback colour if reroute colour is somehow nullish
This commit is contained in:
@@ -815,7 +815,7 @@ export class LGraphNode implements Positionable, IPinnable, IColorable {
|
||||
* @param slot
|
||||
* @param data
|
||||
*/
|
||||
setOutputData(slot: number, data: unknown): void {
|
||||
setOutputData(slot: number, data: number | string | boolean | { toToolTip?(): string }): void {
|
||||
if (!this.outputs) return
|
||||
|
||||
// this maybe slow and a niche case
|
||||
|
||||
13
src/LLink.ts
13
src/LLink.ts
@@ -1,4 +1,3 @@
|
||||
// @ts-strict-ignore
|
||||
import type {
|
||||
CanvasColour,
|
||||
LinkNetwork,
|
||||
@@ -46,9 +45,9 @@ export class LLink implements LinkSegment, Serialisable<SerialisableLLink> {
|
||||
/** @inheritdoc */
|
||||
_centreAngle?: number
|
||||
|
||||
#color?: CanvasColour
|
||||
#color?: CanvasColour | null
|
||||
/** Custom colour for this link only */
|
||||
public get color(): CanvasColour {
|
||||
public get color(): CanvasColour | null | undefined {
|
||||
return this.#color
|
||||
}
|
||||
|
||||
@@ -108,7 +107,9 @@ export class LLink implements LinkSegment, Serialisable<SerialisableLLink> {
|
||||
network: LinkNetwork,
|
||||
linkSegment: LinkSegment,
|
||||
): Reroute[] {
|
||||
return network.reroutes.get(linkSegment.parentId)
|
||||
if (!linkSegment.parentId) return []
|
||||
return network.reroutes
|
||||
.get(linkSegment.parentId)
|
||||
?.getReroutes() ?? []
|
||||
}
|
||||
|
||||
@@ -125,7 +126,9 @@ export class LLink implements LinkSegment, Serialisable<SerialisableLLink> {
|
||||
linkSegment: LinkSegment,
|
||||
rerouteId: RerouteId,
|
||||
): Reroute | null | undefined {
|
||||
return network.reroutes.get(linkSegment.parentId)
|
||||
if (!linkSegment.parentId) return
|
||||
return network.reroutes
|
||||
.get(linkSegment.parentId)
|
||||
?.findNextReroute(rerouteId)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// @ts-strict-ignore
|
||||
import type {
|
||||
CanvasColour,
|
||||
LinkSegment,
|
||||
@@ -31,12 +30,12 @@ export class Reroute implements Positionable, LinkSegment, Serialisable<Serialis
|
||||
|
||||
#parentId?: RerouteId
|
||||
/** @inheritdoc */
|
||||
public get parentId(): RerouteId {
|
||||
public get parentId(): RerouteId | undefined {
|
||||
return this.#parentId
|
||||
}
|
||||
|
||||
/** Ignores attempts to create an infinite loop. @inheritdoc */
|
||||
public set parentId(value: RerouteId) {
|
||||
public set parentId(value) {
|
||||
if (value === this.id) return
|
||||
if (this.getReroutes() === null) return
|
||||
this.#parentId = value
|
||||
@@ -98,16 +97,22 @@ export class Reroute implements Positionable, LinkSegment, Serialisable<Serialis
|
||||
/** @inheritdoc */
|
||||
get origin_id(): NodeId | undefined {
|
||||
// if (!this.linkIds.size) return this.#network.deref()?.reroutes.get(this.parentId)
|
||||
return this.#network.deref()
|
||||
?.links.get(this.linkIds.values().next().value)
|
||||
?.origin_id
|
||||
const nextId = this.linkIds.values().next().value
|
||||
return nextId === undefined
|
||||
? undefined
|
||||
: this.#network.deref()
|
||||
?.links.get(nextId)
|
||||
?.origin_id
|
||||
}
|
||||
|
||||
/** @inheritdoc */
|
||||
get origin_slot(): number | undefined {
|
||||
return this.#network.deref()
|
||||
?.links.get(this.linkIds.values().next().value)
|
||||
?.origin_slot
|
||||
const nextId = this.linkIds.values().next().value
|
||||
return nextId === undefined
|
||||
? undefined
|
||||
: this.#network.deref()
|
||||
?.links.get(nextId)
|
||||
?.origin_slot
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -200,6 +205,7 @@ export class Reroute implements Positionable, LinkSegment, Serialisable<Serialis
|
||||
if (this.#parentId === withParentId) return this
|
||||
if (visited.has(this)) return null
|
||||
visited.add(this)
|
||||
if (this.#parentId === undefined) return
|
||||
|
||||
return this.#network
|
||||
.deref()
|
||||
@@ -279,7 +285,7 @@ export class Reroute implements Positionable, LinkSegment, Serialisable<Serialis
|
||||
*/
|
||||
draw(ctx: CanvasRenderingContext2D): void {
|
||||
const { pos } = this
|
||||
ctx.fillStyle = this._colour
|
||||
ctx.fillStyle = this._colour ?? "#18184d"
|
||||
ctx.beginPath()
|
||||
ctx.arc(pos[0], pos[1], Reroute.radius, 0, 2 * Math.PI)
|
||||
ctx.fill()
|
||||
|
||||
@@ -128,9 +128,9 @@ export interface LinkSegment {
|
||||
_centreAngle?: number
|
||||
|
||||
/** Output node ID */
|
||||
readonly origin_id: NodeId
|
||||
readonly origin_id: NodeId | undefined
|
||||
/** Output slot index */
|
||||
readonly origin_slot: number
|
||||
readonly origin_slot: number | undefined
|
||||
}
|
||||
|
||||
export interface IInputOrOutput {
|
||||
|
||||
Reference in New Issue
Block a user