Add accumulator preview reordering

This commit is contained in:
2026-06-25 08:52:53 +02:00
parent 55477bd826
commit 4e5370626f
3 changed files with 104 additions and 0 deletions
+51
View File
@@ -283,6 +283,57 @@ def accumulator_delete_entries(
return result
def accumulator_move_entry(
store_key: str,
entry_id: str = "",
index: int = 0,
direction: str = "up",
) -> dict[str, Any]:
key = str(store_key or "").strip()
if not key:
raise ValueError("store_key is required for accumulator preview actions")
store = _ACCUMULATOR_STORES.setdefault(key, [])
if not store:
result = accumulator_list_entries(key)
result["moved"] = False
return result
zero_index = -1
entry_id = str(entry_id or "").strip()
if entry_id:
for current_index, entry in enumerate(store):
if str(entry.get("id") or "") == entry_id:
zero_index = current_index
break
elif int(index) > 0:
candidate = int(index) - 1
if candidate < len(store):
zero_index = candidate
else:
raise ValueError("entry_id or 1-based index is required")
if zero_index < 0:
result = accumulator_list_entries(key)
result["moved"] = False
return result
direction = str(direction or "up").strip().lower()
if direction == "top":
target_index = 0
elif direction == "bottom":
target_index = len(store) - 1
elif direction == "down":
target_index = min(len(store) - 1, zero_index + 1)
else:
target_index = max(0, zero_index - 1)
moved = target_index != zero_index
if moved:
entry = store.pop(zero_index)
store.insert(target_index, entry)
result = accumulator_list_entries(key)
result["moved"] = moved
result["from_index"] = zero_index + 1
result["to_index"] = target_index + 1
return result
def _require_image_saving() -> None:
if folder_paths is None or np is None or Image is None:
raise RuntimeError("Image preview/save helpers require ComfyUI image dependencies.")