mirror of
https://git.datalinker.icu/comfyanonymous/ComfyUI
synced 2026-11-21 16:57:07 +08:00
approximately preserve scroll position
This commit is contained in:
parent
c968159b4c
commit
ee2cf8772e
@ -204,6 +204,7 @@ class ComfyList {
|
|||||||
this.#reverse = reverse || false;
|
this.#reverse = reverse || false;
|
||||||
this.element = $el("div.comfy-list");
|
this.element = $el("div.comfy-list");
|
||||||
this.element.style.display = "none";
|
this.element.style.display = "none";
|
||||||
|
this.last_keys = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
get visible() {
|
get visible() {
|
||||||
@ -212,50 +213,67 @@ class ComfyList {
|
|||||||
|
|
||||||
async load() {
|
async load() {
|
||||||
const items = await api.getItems(this.#type);
|
const items = await api.getItems(this.#type);
|
||||||
this.element.replaceChildren(
|
const keys = Object.keys(items);
|
||||||
...Object.keys(items).flatMap((section) => [
|
var entry = (item) => {
|
||||||
$el("h4", {
|
// Allow items to specify a custom remove action (e.g. for interrupt current prompt)
|
||||||
textContent: section,
|
const removeAction = item.remove || {
|
||||||
}),
|
name: "Delete",
|
||||||
$el("div.comfy-list-items", [
|
cb: () => api.deleteItem(this.#type, item.prompt[1]),
|
||||||
...(this.#reverse ? items[section].reverse() : items[section]).map((item) => {
|
};
|
||||||
// Allow items to specify a custom remove action (e.g. for interrupt current prompt)
|
return $el("div", {textContent: item.prompt[0] + ": "}, [
|
||||||
const removeAction = item.remove || {
|
$el("button", {
|
||||||
name: "Delete",
|
textContent: "Load",
|
||||||
cb: () => api.deleteItem(this.#type, item.prompt[1]),
|
onclick: async () => {
|
||||||
};
|
await app.loadGraphData(item.prompt[3].extra_pnginfo.workflow, true, false);
|
||||||
return $el("div", {textContent: item.prompt[0] + ": "}, [
|
if (item.outputs) {
|
||||||
$el("button", {
|
app.nodeOutputs = item.outputs;
|
||||||
textContent: "Load",
|
}
|
||||||
onclick: async () => {
|
},
|
||||||
await app.loadGraphData(item.prompt[3].extra_pnginfo.workflow, true, false);
|
}),
|
||||||
if (item.outputs) {
|
$el("button", {
|
||||||
app.nodeOutputs = item.outputs;
|
textContent: removeAction.name,
|
||||||
}
|
onclick: async () => {
|
||||||
},
|
await removeAction.cb();
|
||||||
}),
|
await this.update();
|
||||||
$el("button", {
|
},
|
||||||
textContent: removeAction.name,
|
}),
|
||||||
onclick: async () => {
|
]);
|
||||||
await removeAction.cb();
|
|
||||||
await this.update();
|
};
|
||||||
},
|
|
||||||
}),
|
if (JSON.stringify(keys) === JSON.stringify(this.last_keys)) {
|
||||||
]);
|
// we can replace inside the container elements instead of recreating them
|
||||||
}),
|
// this will preserve the scroll position approximately
|
||||||
]),
|
// to truely preserve the scroll position, we would need to do something react-like
|
||||||
]),
|
// in the sense of preserving the DOM nodes and reusing them
|
||||||
$el("div.comfy-list-actions", [
|
Array.from(this.element.getElementsByClassName("comfy-list-items")).forEach((section, i) =>
|
||||||
$el("button", {
|
section.replaceChildren(...(this.#reverse ? items[keys[i]].reverse() : items[keys[i]]).map(entry))
|
||||||
textContent: "Clear " + this.#text,
|
);
|
||||||
onclick: async () => {
|
|
||||||
await api.clearItems(this.#type);
|
} else {
|
||||||
await this.load();
|
this.last_keys = keys;
|
||||||
},
|
// rebuild the list of lists
|
||||||
}),
|
this.element.replaceChildren(
|
||||||
$el("button", {textContent: "Refresh", onclick: () => this.load()}),
|
...keys.flatMap((section) => [
|
||||||
])
|
$el("h4", {
|
||||||
);
|
textContent: section,
|
||||||
|
}),
|
||||||
|
$el("div.comfy-list-items", [
|
||||||
|
...(this.#reverse ? items[section].reverse() : items[section]).map(entry),
|
||||||
|
]),
|
||||||
|
]),
|
||||||
|
$el("div.comfy-list-actions", [
|
||||||
|
$el("button", {
|
||||||
|
textContent: "Clear " + this.#text,
|
||||||
|
onclick: async () => {
|
||||||
|
await api.clearItems(this.#type);
|
||||||
|
await this.load();
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
$el("button", {textContent: "Refresh", onclick: () => this.load()}),
|
||||||
|
])
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async update() {
|
async update() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user