UX fix & init clean up

- Fixed the UX
  - Node can now be selected, without the html area picking it up.
 - That makes it so the space bar can still be pressed to pan on the canvas, while the node was selected, by selecting the html area
- Double clicking works and hover edit icon as well.
- Middle mouse panning does NOT work. WIll never work...
- Cleaned up the __init__.py so it's ComfyUI standard and Manager compatible. We will see...
This commit is contained in:
Alex Furer
2025-10-10 22:11:30 +02:00
parent 983bffae06
commit 863f7cefef
2 changed files with 69 additions and 28 deletions
+18 -3
View File
@@ -1,15 +1,30 @@
# AF - Enhanced HTML-Note Node for ComfyUI
# File: __init__.py
"""
@author: Alex Furer
@title: AF - Enhanced HTML Note
@nickname: AF - Enhanced HTML Note
@description: A ComfyUI custom node that allows you to create a note node with HTML support.
"""
import os
from .AF_Enhanced_HTML_Note import NODE_CLASS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS
__all__ = ['NODE_CLASS_MAPPINGS', 'NODE_DISPLAY_NAME_MAPPINGS', 'WEB_DIRECTORY']
# Tell ComfyUI about our web files
WEB_DIRECTORY = "./web"
__all__ = ['NODE_CLASS_MAPPINGS', 'NODE_DISPLAY_NAME_MAPPINGS', 'WEB_DIRECTORY']
__version__ = "0.0.05"
__author__ = "Alex Furer"
__title__ = "AF - Enhanced HTML Note"
__description__ = " ComfyUI custom node that allows you to create a note node with HTML support."
__license__ = "MIT"
__changelog__ = [
"v0.0.05 - Made edit mode less intrusive and keep ComfyUI canvas navigation (panning, zooming [space bar] and [H] now work to pan around the canvas)",
"v0.0.04 - Fixed node selection and resizing by removing OUTPUT_NODE and using proper widget approach. Double clicking is now used to edit the html Mouse interaction is now persistent to ComfyUI behavior. Except middle mouse button for panning.",
"v0.0.03 - Fixed node resizing issues on save/reload. Improved selection and edit mode behavior to match ComfyUI core notes. Fixed middle mouse button panning over the node. Improved HTML indentation in default content",
"v0.0.02 - Fixed naming consistency to HTML_Note Implemented single-window toggle behavior",
"v0.0.01 - Initial Version"
]
print("* * * * * * * * * * * * * * * * * * * * * * * * * *")
print(r"""
+51 -25
View File
@@ -27,25 +27,43 @@ const AF_HTML_NOTE_STYLES = `
height: 100%;
overflow-y: auto;
flex: 1;
/* NO pointer-events here - let ComfyUI handle interactions */
/* Prevent text selection */
user-select: none;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
cursor: default;
/* Prevent keyboard focus */
outline: none;
}
.af-html-note-editor {
width: 100%;
height: 100%;
background: var(--comfy-menu-bg, #2a2a2a);
border: 1px solid var(--border-color, #555);
padding: 8px;
font-family: 'Monaco', 'Consolas', 'Courier New', monospace;
line-height: 1.4;
color: var(--input-text, #ffffff);
box-sizing: border-box;
resize: none;
outline: none;
font-size: 14px;
display: none;
flex: 1;
}
/* Ensure content area can't be focused */
.af-html-note-content:focus {
outline: none;
}
.af-html-note-editor {
width: 100%;
height: 100%;
background: var(--comfy-menu-bg, #2a2a2a);
border: 1px solid var(--border-color, #555);
padding: 8px;
font-family: 'Monaco', 'Consolas', 'Courier New', monospace;
line-height: 1.4;
color: var(--input-text, #ffffff);
box-sizing: border-box;
resize: none;
outline: none;
font-size: 14px;
display: none;
flex: 1;
/* Add text selection capabilities */
user-select: auto;
-webkit-user-select: auto;
-moz-user-select: auto;
-ms-user-select: auto;
cursor: text;
}
/* Floating edit button */
.af-floating-edit-btn {
@@ -363,7 +381,10 @@ app.registerExtension({
e.stopPropagation();
}
});
// Comment
this.contentElement.setAttribute('tabindex', '-1');
this.editorElement.addEventListener('blur', () => {
setTimeout(() => {
if (this.isEditMode && document.activeElement !== this.editorElement) {
@@ -371,7 +392,15 @@ app.registerExtension({
}
}, 10);
});
this.contentElement.addEventListener('mousedown', (e) => {
// Prevent the content area from getting focus on click
e.preventDefault();
// But don't stop propagation - let ComfyUI handle node selection
// Only prevent the default focus behavior
});
// Add as DOM widget
this.addDOMWidget("html_note_display", "div", this.containerElement);
};
@@ -410,24 +439,22 @@ app.registerExtension({
this.handleLinksInHTML();
};
// Update the link handler to temporarily enable pointer events for links
nodeType.prototype.handleLinksInHTML = function() {
if (!this.contentElement) return;
const links = this.contentElement.querySelectorAll('a');
links.forEach(link => {
// Remove any existing handlers
link.onclick = null;
// Add clean, simple handler
link.addEventListener('click', (e) => {
// Only handle links when Ctrl is active
if (!document.body.classList.contains('af-ctrl-active')) {
e.preventDefault();
e.stopPropagation();
return false;
}
// Ctrl is held - handle external links only
// Clean, simple link handling
if (link.href &&
!link.href.startsWith('javascript:') &&
!(link.href.startsWith('#') || link.href === '#')) {
@@ -435,13 +462,12 @@ app.registerExtension({
window.open(link.href, '_blank');
}
// Stop propagation to ComfyUI
e.stopPropagation();
return false;
});
});
};
// Global Ctrl key handling
let ctrlKeyActive = false;