* feat(sidebar): right-click menu pack — Duplicate, Tags, + New directory move Three sibling sidebar slices bundled because they all extend the same workflow-row right-click menu in `web/sidebar/tree.js` and share a small schema/store surface in `workflows_store.js`. Refactor cleanup is held back for a separate PR (issue #47) so this diff stays a "no behavior change to existing flows" feature add. Changes ------- - Right-click "Duplicate…" → name modal with `<name> (copy)` default; deep-clones the source graph into a new entry in the same directory via `saveWorkflowEntry`. The duplicate inherits the source's tags so the user's categorization carries over. Same-name duplicates fall through to the existing archive-on-collision behavior. Closes #58. - Right-click "Tags…" → chip-row modal with add/remove. Each edit fires its own `persistMutation` so changes survive a mid-edit close. New `showTagsModal` in `modals.js` mirrors the existing `showInputModal` / `showConfirmModal` shape (escape-key teardown, overlay-click dismissal centralized in `makeModalShell`). - New Tags sidebar section between Workflows. Flat list of tag folders; each tag holds the workflows carrying it (sorted A→Z). Click loads the workflow from its real path. Archived workflows are filtered out of the section so the active view stays clean — their tags persist on the entry, so a restore brings them back. Search matches tag name OR workflow name. - Right-click "+ New directory…" / "+ New subdirectory under <path>…" in the Move-to flow. Both create a fresh directory and move the workflow into it as one atomic mutation; if the move can't land, the new directory is rolled back so the cache never leaks an empty orphan. Closes #57. Schema additions (back-compatible) ---------------------------------- - Workflow entries gain optional `tags: string[]`. `normalizeDirNode` trims, drops empties, and dedupes case-sensitively, so old entries without a tags field load as `tags: []` and the rest of the code can assume the field always exists. Pre-v0.3 stores load fine. - New exports in `workflows_store.js`: `getWorkflowTags`, `addTag`, `removeTag`. `getWorkflowGraph` is now also exported so the duplicate flow can deep-clone without reaching into the cache directly. Why one PR for three issues --------------------------- All three slices touch `workflowRowContextMenu` in `tree.js` and the mutator API in `workflows_store.js`. A coherent UX-feature scope ("next batch of workflow menu enhancements") reviews more cheaply as one diff than three near-identical PRs. Issue #47 (refactor / tidiness pass) stays separate because mixing refactor and feature in the same diff defeats the point of the split — that work is queued for a follow-up PR. Testing ------- - `python tools/preflight_release.py --skip manager-meta -v` PASS (static / dispatch / workflows fixtures, all 3 stages). - `node --input-type=module --check` passes on each modified JS file. - Browser smoke test: pending — needs a ComfyUI session for the user to verify the three menu actions and the Tags section against a real workflow store. The CI gates are Python-only and don't catch JS regressions in the sidebar by themselves. Related ------- - Closes #57 (move-to: + New directory…) - Closes #58 (Duplicate) - Implements the right-click + section parts of #56 (Tags); the issue body's `addTag` / `removeTag` / `listAllTags()` ops landed under slightly different names (`addTag`, `removeTag`, `gatherTags`). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix(sidebar): address review findings on PR #59 Self-review pass against the validated agent findings. Five fixes total across the three issues' surface, holding refactor/file-size concerns for follow-up #47 widening. Fixes ----- - **HIGH** `normalizeDirNode` now rejects non-string `tags` elements outright instead of `String(raw).trim()` coercing them. `null` / `undefined` / `true` / `123` no longer silently surface as the literal tag strings `"null"` / `"undefined"` / etc. — `stats.dropped` increments instead so the existing console warning catches malformed migrations. Closes review HIGH-1. - **HIGH** Tags modal now distinguishes "no tags yet" from "workflow no longer exists." The `getCurrentTags` adapter no longer collapses `null` to `[]`, and `renderChips` renders an explicit gone-state with disabled add input + descriptive placeholder. Prevents users typing into a doomed modal when a concurrent action (another tab, drag-and-drop) deletes the workflow under them. Closes review HIGH-3. - **MEDIUM** Duplicate flow re-validates source existence at submit-time inside the `mutate` callback. Without it, a concurrent delete of the source between menu-open and submit would let `saveWorkflowEntry`'s `ensureDirectoryAtPath` silently re-create the parent directory and paste a clone of the captured graph — effectively undoing someone else's delete. Now returns `false` on missing source, surfacing "Could not duplicate — <name> no longer exists." Closes review MEDIUM-6. - **MEDIUM** Duplicate flow now routes inherited tags through the public `addTag` mutator instead of writing `dir.workflows[newName].tags` directly. Keeps the tree.js UI layer outside the store's internal shape. The whole sequence still rides on one `persistMutation` snapshot — commit failure rolls back save + tag adds together. Closes review MEDIUM-5. - **LOW** `gatherTags` comment block clarifies that grouping is case-sensitive but search filter is case-insensitive substring. The comment previously said "Comparison is case-sensitive" which was technically true for grouping but misleading on its own. Skipped with rationale ---------------------- - **HIGH-2 modal cache desync on persist failure** — agent analysis was wrong on trace. `renderChips` reads from cache, X-click does not optimistically remove the chip from DOM, and `restore()` reverts cache to pre-mutation. DOM and cache stay consistent across every commit-failure path. Cross-tab updates aren't reflected, but that's a project-wide cache-coherency concern, not specific to this PR. - **HIGH-4 tree.js size** — real architectural concern but follow-up only. Track on #47 widening (or a sibling extraction issue). Adding extraction in this PR would mix refactor with feature. - **MEDIUM-7 tag API asymmetry** — agent claimed `addTag`'s parameter reassignment differed from neighbors, but verified the existing convention IS parameter reassignment (`addDirectory`, `renameDirectory`, `renameWorkflow`, `moveDirectory` all do `name = (name || "").trim();`). The defensive-copy difference between `getWorkflowTags` and `getWorkflowGraph` is intentional. - **MEDIUM-8 top-level "Archive" name** — pre-existing semantic shared by toolbar Create-directory and save-modal "+ New directory." Restricting only the right-click new-dir entry would be inconsistent. Filing as a separate cross-cutting issue is the cleaner path. - **LOW magic strings / modals.js size** — both queued for #47. Validation ---------- - `python tools/preflight_release.py --skip manager-meta -v` PASS. - `node --input-type=module --check` on all three modified JS files — clean. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
143 lines
10 KiB
JavaScript
143 lines
10 KiB
JavaScript
// =============================================================================
|
|
// Configuration — static "always shown" entries.
|
|
//
|
|
// You normally don't need to edit this. To grow the panel from inside
|
|
// ComfyUI, use either:
|
|
// • the "+" button at the top of the sidebar (with a canvas node selected), or
|
|
// • right-click a canvas node → "Add to Kforge Labs".
|
|
//
|
|
// Those additions are stored in the browser's localStorage and surface as
|
|
// the "My Picks" group at the top of the tree.
|
|
// =============================================================================
|
|
export const REPOS = [
|
|
{
|
|
label: "Koolook",
|
|
categoryRoot: "Koolook",
|
|
select: "all",
|
|
excludePatterns: [/\bdeprecated\b/i],
|
|
},
|
|
];
|
|
|
|
// `TAB_ID` is the stable identifier ComfyUI persists per-user — never rename
|
|
// or existing tab state (pinning, tab order) gets orphaned. The visible
|
|
// title and tooltip can change freely.
|
|
export const TAB_ID = "koolook.curatedNodes";
|
|
export const TAB_TITLE = "Kforge Labs";
|
|
export const TAB_TOOLTIP = "Kforge Labs — curated nodes & workflows";
|
|
export const TAB_ICON = "pi pi-star";
|
|
export const ROOT_GROUP_LABEL = "Nodes (favorites)";
|
|
export const WORKFLOWS_GROUP_LABEL = "Workflows";
|
|
|
|
// Defaults JSON files live in web/ alongside the entry; this module is one
|
|
// level deeper at web/sidebar/, so the relative URL needs the extra `..`.
|
|
export const STORAGE_KEY = "koolook.curated.userPicks.v1";
|
|
export const SEEDED_KEY = "koolook.curated.seeded.v1";
|
|
export const PICKS_CHANGED_EVENT = "koolook-picks-changed";
|
|
export const DEFAULTS_URL = new URL("../curated_defaults.json", import.meta.url).href;
|
|
|
|
export const WORKFLOWS_USERDATA_PATH = "koolook_workflows.json";
|
|
export const WORKFLOWS_FALLBACK_KEY = "koolook.workflows.fallback.v1";
|
|
export const WORKFLOWS_SEEDED_KEY = "koolook.workflows.seeded.v1";
|
|
export const WORKFLOWS_CHANGED_EVENT = "koolook-workflows-changed";
|
|
export const WORKFLOWS_DEFAULTS_URL = new URL("../workflow_defaults.json", import.meta.url).href;
|
|
|
|
// =============================================================================
|
|
// Styles
|
|
// =============================================================================
|
|
const STYLE_ID = "koolook-sidebar-style";
|
|
export function ensureStyle() {
|
|
if (document.getElementById(STYLE_ID)) return;
|
|
const s = document.createElement("style");
|
|
s.id = STYLE_ID;
|
|
s.textContent = `
|
|
.koolook-sidebar { display: flex; flex-direction: column; height: 100%; font-size: 13px; user-select: none; }
|
|
.koolook-search-row { margin: 6px; flex-shrink: 0; }
|
|
.koolook-actions-row { display: flex; align-items: center; gap: 4px; padding: 2px 6px; flex-shrink: 0; }
|
|
.koolook-actions-label { font-size: 10px; opacity: 0.55; text-transform: uppercase; letter-spacing: 0.08em; flex: 1; font-weight: 600; }
|
|
.koolook-tree-divider { margin: 8px 8px; border-top: 1px solid rgba(255,255,255,0.08); flex-shrink: 0; }
|
|
.koolook-search-wrap { position: relative; width: 100%; }
|
|
.koolook-search-icon { position: absolute; left: 8px; top: 50%; transform: translateY(-50%); opacity: 0.55; font-size: 11px; pointer-events: none; }
|
|
.koolook-search { width: 100%; padding: 5px 8px 5px 26px; box-sizing: border-box; background: var(--comfy-input-bg, rgba(0,0,0,0.25)); border: 1px solid var(--border-color, rgba(255,255,255,0.1)); border-radius: 4px; color: var(--input-text, inherit); font-size: 12px; outline: none; }
|
|
.koolook-search:focus { border-color: var(--p-primary-color, rgba(100,150,255,0.5)); }
|
|
.koolook-add-btn { padding: 0 12px; background: var(--comfy-input-bg, rgba(0,0,0,0.25)); border: 1px solid var(--border-color, rgba(255,255,255,0.1)); border-radius: 4px; cursor: pointer; color: var(--input-text, inherit); font-size: 16px; line-height: 1; flex-shrink: 0; }
|
|
.koolook-add-btn:hover { background: rgba(255,255,255,0.1); }
|
|
.koolook-add-btn:active { background: rgba(255,255,255,0.15); }
|
|
.koolook-icon-btn { padding: 0 10px; font-size: 12px; }
|
|
.koolook-icon-btn:disabled { opacity: 0.35; cursor: not-allowed; }
|
|
.koolook-tree { flex: 1; overflow-y: auto; padding: 0 4px 8px; }
|
|
.koolook-row { display: flex; align-items: center; padding: 3px 6px; cursor: pointer; gap: 6px; border-radius: 3px; line-height: 1.3; }
|
|
.koolook-row:hover { background: var(--comfy-input-bg, rgba(255,255,255,0.06)); }
|
|
.koolook-chevron { width: 10px; display: inline-block; opacity: 0.7; text-align: center; font-size: 10px; flex-shrink: 0; }
|
|
.koolook-folder-icon { opacity: 0.85; flex-shrink: 0; }
|
|
.koolook-pin-icon { color: #ffb84d; opacity: 0.95; flex-shrink: 0; }
|
|
.koolook-workflows-icon { color: #6db4ff; opacity: 0.95; flex-shrink: 0; }
|
|
.koolook-archive-icon { opacity: 0.55; flex-shrink: 0; }
|
|
.koolook-leaf-icon { opacity: 0.7; flex-shrink: 0; font-size: 11px; }
|
|
.koolook-leaf-dot { width: 6px; height: 6px; margin: 0 2px; border-radius: 50%; background: rgba(255,255,255,0.45); flex-shrink: 0; }
|
|
.koolook-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
.koolook-count { background: rgba(255,255,255,0.08); padding: 1px 7px; border-radius: 8px; font-size: 11px; opacity: 0.75; }
|
|
.koolook-children { padding-left: 14px; }
|
|
.koolook-empty { padding: 14px 8px; opacity: 0.65; font-size: 12px; line-height: 1.4; }
|
|
.koolook-leaf .koolook-chevron { visibility: hidden; }
|
|
.koolook-remove { padding: 0 4px; margin-left: 2px; opacity: 0; font-size: 14px; line-height: 1; cursor: pointer; flex-shrink: 0; }
|
|
.koolook-row:hover .koolook-remove { opacity: 0.5; }
|
|
.koolook-remove:hover { opacity: 1 !important; color: #ff7777; }
|
|
.koolook-section-divider { border-top: 1px solid var(--border-color, rgba(255,255,255,0.08)); margin: 8px 4px 0; }
|
|
.koolook-toast { position: fixed; bottom: 30px; right: 30px; background: rgba(40,40,40,0.95); color: #fff; padding: 8px 14px; border-radius: 4px; font-size: 12px; z-index: 9999; transition: opacity 0.3s; box-shadow: 0 2px 8px rgba(0,0,0,0.4); pointer-events: none; max-width: 360px; }
|
|
.koolook-modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.55); z-index: 9998; display: flex; align-items: center; justify-content: center; }
|
|
.koolook-modal { background: var(--comfy-menu-bg, #2a2a2a); border: 1px solid var(--border-color, rgba(255,255,255,0.15)); border-radius: 6px; padding: 16px 18px; min-width: 320px; max-width: 440px; box-shadow: 0 6px 24px rgba(0,0,0,0.55); color: var(--input-text, inherit); }
|
|
.koolook-modal-title { font-size: 14px; font-weight: 600; margin-bottom: 12px; }
|
|
.koolook-modal-message { font-size: 12px; opacity: 0.85; margin-bottom: 14px; line-height: 1.45; }
|
|
.koolook-modal-label { font-size: 11px; opacity: 0.7; margin: 6px 0 4px; display: block; text-transform: uppercase; letter-spacing: 0.04em; }
|
|
.koolook-modal-input, .koolook-modal-select { width: 100%; padding: 6px 8px; background: var(--comfy-input-bg, rgba(0,0,0,0.3)); border: 1px solid var(--border-color, rgba(255,255,255,0.1)); border-radius: 4px; color: inherit; font-size: 13px; box-sizing: border-box; outline: none; }
|
|
.koolook-modal-input:focus, .koolook-modal-select:focus { border-color: var(--p-primary-color, rgba(100,150,255,0.5)); }
|
|
.koolook-modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
|
|
.koolook-modal-btn { padding: 6px 14px; background: var(--comfy-input-bg, rgba(0,0,0,0.3)); border: 1px solid var(--border-color, rgba(255,255,255,0.1)); border-radius: 4px; color: inherit; cursor: pointer; font-size: 12px; }
|
|
.koolook-modal-btn:hover { background: rgba(255,255,255,0.1); }
|
|
.koolook-modal-btn-primary { background: rgba(80,140,235,0.35); border-color: rgba(80,140,235,0.55); }
|
|
.koolook-modal-btn-primary:hover { background: rgba(80,140,235,0.5); }
|
|
.koolook-modal-btn-danger { background: rgba(220,80,80,0.25); border-color: rgba(220,80,80,0.5); }
|
|
.koolook-modal-btn-danger:hover { background: rgba(220,80,80,0.4); }
|
|
.koolook-context-menu { position: fixed; background: var(--comfy-menu-bg, #2a2a2a); border: 1px solid var(--border-color, rgba(255,255,255,0.15)); border-radius: 4px; padding: 4px 0; min-width: 160px; z-index: 9999; box-shadow: 0 4px 12px rgba(0,0,0,0.4); font-size: 12px; }
|
|
.koolook-context-item { padding: 5px 12px; cursor: pointer; }
|
|
.koolook-context-item:hover { background: rgba(255,255,255,0.08); }
|
|
.koolook-context-danger { color: #ff8888; }
|
|
.koolook-context-sep { height: 1px; background: rgba(255,255,255,0.1); margin: 4px 0; }
|
|
.koolook-context-submenu-arrow { float: right; opacity: 0.5; }
|
|
.koolook-row[draggable="true"] { cursor: grab; }
|
|
.koolook-row[draggable="true"]:active { cursor: grabbing; }
|
|
.koolook-drop-target { background: rgba(80,140,235,0.18) !important; outline: 2px solid rgba(80,140,235,0.6); outline-offset: -2px; }
|
|
.koolook-tags-chips { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 4px; min-height: 22px; align-items: center; }
|
|
.koolook-tags-empty { opacity: 0.55; font-size: 12px; }
|
|
.koolook-tag-chip { display: inline-flex; align-items: center; gap: 4px; background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.12); border-radius: 10px; padding: 2px 4px 2px 9px; font-size: 11px; line-height: 1.4; }
|
|
.koolook-tag-chip-x { cursor: pointer; opacity: 0.6; padding: 0 4px; font-size: 13px; line-height: 1; border-radius: 50%; }
|
|
.koolook-tag-chip-x:hover { opacity: 1; color: #ff7777; background: rgba(255,255,255,0.06); }
|
|
.koolook-tag-add-row { display: flex; gap: 6px; align-items: center; }
|
|
.koolook-tag-add-row .koolook-modal-input { flex: 1; }
|
|
`;
|
|
document.head.appendChild(s);
|
|
}
|
|
|
|
// =============================================================================
|
|
// Toast helper
|
|
// =============================================================================
|
|
export function toast(msg, duration = 2200) {
|
|
const t = document.createElement("div");
|
|
t.className = "koolook-toast";
|
|
t.textContent = msg;
|
|
document.body.appendChild(t);
|
|
setTimeout(() => {
|
|
t.style.opacity = "0";
|
|
setTimeout(() => t.remove(), 300);
|
|
}, duration);
|
|
}
|
|
|
|
// =============================================================================
|
|
// Sort helper — human-alphabetical (case-insensitive). Use everywhere we sort
|
|
// names, labels, or directory entries so the order in the sidebar matches what
|
|
// a user would expect from an A→Z list.
|
|
// =============================================================================
|
|
export function compareNames(a, b) {
|
|
return String(a).localeCompare(String(b), undefined, { sensitivity: "base" });
|
|
}
|