Skip to content

Commit b03d293

Browse files
committed
Update docs
1 parent d53d208 commit b03d293

File tree

2 files changed

+79
-14
lines changed

2 files changed

+79
-14
lines changed

docs/CircuitBoardLines.js

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ function clipT(num, denom, c) {
3939
return 1;
4040
}
4141
/**
42-
* @param {Point} a
43-
* @param {Point} b
44-
* @param {BoundingBox} box [xmin, ymin, xmax, ymax]
45-
* @param {Point?} [da]
46-
* @param {Point?} [db]
42+
* @param {Point} a
43+
* @param {Point} b
44+
* @param {BoundingBox} box [xmin, ymin, xmax, ymax]
45+
* @param {Point?} [da]
46+
* @param {Point?} [db]
4747
* @return {number}
4848
*/
4949
function liangBarsky(a, b, box, da, db) {
@@ -714,16 +714,60 @@ class MapLinks {
714714
}
715715
}
716716

717+
class EyeButton {
718+
constructor() {
719+
this.hidden = null;
720+
}
721+
722+
static getEyeButton() {
723+
const eyeButtons = document.querySelectorAll('.pi-eye,.pi-eye-slash');
724+
if (eyeButtons.length > 1) {
725+
console.log('found too many eye buttons', eyeButtons); // eslint-disable-line no-console
726+
}
727+
return eyeButtons[0];
728+
}
729+
730+
check() {
731+
const eyeButton = EyeButton.getEyeButton();
732+
if (!eyeButton) {
733+
return;
734+
}
735+
const hidden = eyeButton.classList.contains('pi-eye-slash');
736+
if (this.hidden !== hidden) {
737+
this.hidden = hidden;
738+
if (this.onChange) {
739+
this.onChange(hidden);
740+
}
741+
}
742+
}
743+
744+
listenEyeButton(onChange) {
745+
this.onChange = onChange;
746+
const eyeButton = EyeButton.getEyeButton();
747+
if (!eyeButton) {
748+
setTimeout(() => this.listenEyeButton(onChange), 1000);
749+
return;
750+
}
751+
const eyeDom = eyeButton.parentNode;
752+
eyeDom.addEventListener('click', () => this.check());
753+
eyeDom.addEventListener('keyup', () => this.check());
754+
eyeDom.addEventListener('mouseup', () => this.check());
755+
}
756+
}
757+
717758
export class CircuitBoardLines {
718759
constructor() {
719760
this.canvas = null;
720761
this.mapLinks = null;
721762
this.enabled = true;
763+
this.eyeHidden = false;
722764
this.maxDirectLineDistance = Number.MAX_SAFE_INTEGER;
723765
}
724766

725767
setEnabled(e) { this.enabled = e; }
726768

769+
isShow() { return this.enabled && !this.eyeHidden; }
770+
727771
recalcMapLinksTimeout() {
728772
// calculate paths when user is idle...
729773
if (!this.skipNextRecalcTimeout) {
@@ -798,13 +842,17 @@ export class CircuitBoardLines {
798842
LGraphCanvas.prototype.drawConnections = function drawConnections(
799843
ctx,
800844
) {
801-
if (t.canvas && t.enabled) {
845+
if (t.canvas && t.isShow()) {
802846
return t.drawConnections(
803847
ctx,
804848
);
805849
}
806850
return oldDrawConnections.apply(this, arguments);
807851
};
852+
this.eyeButton = new EyeButton();
853+
this.eyeButton.listenEyeButton((hidden) => {
854+
this.eyeHidden = hidden;
855+
});
808856
}
809857

810858
initOverrides(canvas) {

docs/QuickConnection.js

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
export class QuickConnection {
1212
constructor() {
1313
this.insideConnection = null;
14-
this.enabled = true;
14+
this.enabled = false;
1515
// use inputs that already have a link to them.
1616
this.useInputsWithLinks = false;
1717
this.release_link_on_empty_shows_menu = true;
@@ -39,13 +39,25 @@ export class QuickConnection {
3939

4040
// Let's not popup the release on empty spot menu if we've released the mouse on a dot
4141
const origReleaseLink = LiteGraph.release_link_on_empty_shows_menu;
42+
const origShowConnectionMenu = t.canvas.showConnectionMenu;
4243
if (t.pointerUp()) {
43-
LiteGraph.release_link_on_empty_shows_menu = false;
44+
if (!t.isComfyUI) {
45+
LiteGraph.release_link_on_empty_shows_menu = false;
46+
} else {
47+
t.canvas.showConnectionMenu = () => {};
48+
}
4449
t.release_link_on_empty_shows_menu = false;
4550
}
4651
const ret = origProcessMouseUp.apply(this, arguments);
47-
LiteGraph.release_link_on_empty_shows_menu = origReleaseLink;
48-
t.release_link_on_empty_shows_menu = true;
52+
if (!t.release_link_on_empty_shows_menu) {
53+
if (!t.isComfyUI) {
54+
LiteGraph.release_link_on_empty_shows_menu = origReleaseLink;
55+
} else {
56+
t.canvas.showConnectionMenu = origShowConnectionMenu;
57+
t.canvas.linkConnector.reset();
58+
}
59+
t.release_link_on_empty_shows_menu = true;
60+
}
4961
return ret;
5062
};
5163

@@ -54,6 +66,7 @@ export class QuickConnection {
5466
}
5567

5668
initListeners(canvas) {
69+
this.enabled = true;
5770
this.graph = canvas.graph;
5871
this.canvas = canvas;
5972
if (!this.canvas.canvas) {
@@ -197,9 +210,6 @@ export class QuickConnection {
197210
return;
198211
}
199212

200-
ctx.save();
201-
this.canvas.ds.toCanvasContext(ctx);
202-
203213
this.insideConnection = null;
204214

205215
const connectionInfo = this.getCurrentConnection();
@@ -208,6 +218,13 @@ export class QuickConnection {
208218
const {
209219
node, input, output, slot,
210220
} = connectionInfo;
221+
if (!input && !output) {
222+
return;
223+
}
224+
225+
ctx.save();
226+
this.canvas.ds.toCanvasContext(ctx);
227+
211228
const slotPos = new Float32Array(2);
212229

213230
const isInput = input ? true : false;
@@ -435,7 +452,7 @@ export class QuickConnection {
435452

436453
ctx.font = oldFont;
437454
}
455+
ctx.restore();
438456
}
439-
ctx.restore();
440457
}
441458
}

0 commit comments

Comments
 (0)