Gallery widget selected index
This commit is contained in:
@@ -47,10 +47,7 @@
|
|||||||
|
|
||||||
function queuePrompt() {
|
function queuePrompt() {
|
||||||
console.log("Queuing!");
|
console.log("Queuing!");
|
||||||
let subworkflow = $uiState.subWorkflow;
|
app.queuePrompt(0, 1);
|
||||||
if (subworkflow === "")
|
|
||||||
subworkflow = null
|
|
||||||
app.queuePrompt(0, 1, subworkflow);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$: if (app?.lCanvas) app.lCanvas.allow_dragnodes = !$uiState.nodesLocked;
|
$: if (app?.lCanvas) app.lCanvas.allow_dragnodes = !$uiState.nodesLocked;
|
||||||
@@ -233,7 +230,6 @@
|
|||||||
<!-- <Checkbox label="Lock Nodes" bind:value={$uiState.nodesLocked}/>
|
<!-- <Checkbox label="Lock Nodes" bind:value={$uiState.nodesLocked}/>
|
||||||
<Checkbox label="Disable Interaction" bind:value={$uiState.graphLocked}/> -->
|
<Checkbox label="Disable Interaction" bind:value={$uiState.graphLocked}/> -->
|
||||||
<Checkbox label="Auto-Add UI" bind:value={$uiState.autoAddUI}/>
|
<Checkbox label="Auto-Add UI" bind:value={$uiState.autoAddUI}/>
|
||||||
<TextBox bind:value={$uiState.subWorkflow} label="Subworkflow" show_label={true} lines={1} max_lines={1}/>
|
|
||||||
<label class="label" for="enable-ui-editing">
|
<label class="label" for="enable-ui-editing">
|
||||||
<BlockTitle>Enable UI Editing</BlockTitle>
|
<BlockTitle>Enable UI Editing</BlockTitle>
|
||||||
<select id="enable-ui-editing" name="enable-ui-editing" bind:value={$uiState.uiEditMode}>
|
<select id="enable-ui-editing" name="enable-ui-editing" bind:value={$uiState.uiEditMode}>
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
export let name: string = "";
|
export let name: string = "";
|
||||||
let value_: string = ""
|
let value_: string = ""
|
||||||
|
|
||||||
|
$: value;
|
||||||
$: handleChange(value);
|
$: handleChange(value);
|
||||||
|
|
||||||
const dispatch = createEventDispatcher<{
|
const dispatch = createEventDispatcher<{
|
||||||
@@ -16,6 +17,7 @@
|
|||||||
}>();
|
}>();
|
||||||
|
|
||||||
function handleChange(val: string) {
|
function handleChange(val: string) {
|
||||||
|
console.debug("combo handleChange", val, value_)
|
||||||
if (val != value_)
|
if (val != value_)
|
||||||
dispatch("change", val);
|
dispatch("change", val);
|
||||||
value_ = val
|
value_ = val
|
||||||
|
|||||||
@@ -48,7 +48,7 @@
|
|||||||
return spec.name in node.properties
|
return spec.name in node.properties
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateAttribute(entry: AttributesSpec, value: any) {
|
function updateAttribute(entry: AttributesSpec, target: IDragItem, value: any) {
|
||||||
if (target) {
|
if (target) {
|
||||||
const name = entry.name
|
const name = entry.name
|
||||||
console.warn("updateAttribute", name, value)
|
console.warn("updateAttribute", name, value)
|
||||||
@@ -136,15 +136,15 @@
|
|||||||
{#if spec.type === "string"}
|
{#if spec.type === "string"}
|
||||||
<TextBox
|
<TextBox
|
||||||
value={target.attrs[spec.name]}
|
value={target.attrs[spec.name]}
|
||||||
on:change={(e) => updateAttribute(spec, e.detail)}
|
on:change={(e) => updateAttribute(spec, target, e.detail)}
|
||||||
on:input={(e) => updateAttribute(spec, e.detail)}
|
on:input={(e) => updateAttribute(spec, target, e.detail)}
|
||||||
label={spec.name}
|
label={spec.name}
|
||||||
max_lines={1}
|
max_lines={1}
|
||||||
/>
|
/>
|
||||||
{:else if spec.type === "boolean"}
|
{:else if spec.type === "boolean"}
|
||||||
<Checkbox
|
<Checkbox
|
||||||
value={target.attrs[spec.name]}
|
value={target.attrs[spec.name]}
|
||||||
on:change={(e) => updateAttribute(spec, e.detail)}
|
on:change={(e) => updateAttribute(spec, target, e.detail)}
|
||||||
label={spec.name}
|
label={spec.name}
|
||||||
/>
|
/>
|
||||||
{:else if spec.type === "number"}
|
{:else if spec.type === "number"}
|
||||||
@@ -152,14 +152,14 @@
|
|||||||
name={spec.name}
|
name={spec.name}
|
||||||
value={target.attrs[spec.name]}
|
value={target.attrs[spec.name]}
|
||||||
step={1}
|
step={1}
|
||||||
on:change={(e) => updateAttribute(spec, e.detail)}
|
on:change={(e) => updateAttribute(spec, target, e.detail)}
|
||||||
/>
|
/>
|
||||||
{:else if spec.type === "enum"}
|
{:else if spec.type === "enum"}
|
||||||
<ComfyComboProperty
|
<ComfyComboProperty
|
||||||
name={spec.name}
|
name={spec.name}
|
||||||
value={target.attrs[spec.name]}
|
value={target.attrs[spec.name]}
|
||||||
values={spec.values}
|
values={spec.values}
|
||||||
on:changed={(e) => updateAttribute(spec, e.detail)}
|
on:change={(e) => updateAttribute(spec, target, e.detail)}
|
||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
@@ -192,7 +192,7 @@
|
|||||||
name={spec.name}
|
name={spec.name}
|
||||||
value={node.properties[spec.name]}
|
value={node.properties[spec.name]}
|
||||||
values={spec.values}
|
values={spec.values}
|
||||||
on:changed={(e) => updateProperty(spec, e.detail)}
|
on:change={(e) => updateProperty(spec, e.detail)}
|
||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
@@ -224,7 +224,7 @@
|
|||||||
name={spec.name}
|
name={spec.name}
|
||||||
value={getVar(node, spec)}
|
value={getVar(node, spec)}
|
||||||
values={spec.values}
|
values={spec.values}
|
||||||
on:changed={(e) => updateVar(spec, e.detail)}
|
on:change={(e) => updateVar(spec, e.detail)}
|
||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
@@ -257,7 +257,7 @@
|
|||||||
name={spec.name}
|
name={spec.name}
|
||||||
value={$layoutState.attrs[spec.name]}
|
value={$layoutState.attrs[spec.name]}
|
||||||
values={spec.values}
|
values={spec.values}
|
||||||
on:changed={(e) => updateWorkflowAttribute(spec, e.detail)}
|
on:change={(e) => updateWorkflowAttribute(spec, e.detail)}
|
||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -96,11 +96,11 @@ export default class ComfyImageCacheNode extends ComfyGraphNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private setIndex(newIndex: number, force: boolean = false) {
|
private setIndex(newIndex: number, force: boolean = false) {
|
||||||
console.debug("[ComfyImageCacheNode] setIndex", newIndex, force)
|
|
||||||
|
|
||||||
if (newIndex === this.properties.index && !force)
|
if (newIndex === this.properties.index && !force)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
console.debug("[ComfyImageCacheNode] setIndex", newIndex, force)
|
||||||
|
|
||||||
if (!this.properties.images || newIndex < 0 || newIndex >= this.properties.images.images.length) {
|
if (!this.properties.images || newIndex < 0 || newIndex >= this.properties.images.images.length) {
|
||||||
console.debug("[ComfyImageCacheNode] invalid indexes", newIndex, this.properties.images)
|
console.debug("[ComfyImageCacheNode] invalid indexes", newIndex, this.properties.images)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -48,9 +48,9 @@ export abstract class ComfyWidgetNode<T = any> extends ComfyGraphNode {
|
|||||||
override isBackendNode = false;
|
override isBackendNode = false;
|
||||||
override serialize_widgets = true;
|
override serialize_widgets = true;
|
||||||
|
|
||||||
outputIndex: number = 0;
|
outputIndex: number | null = 0;
|
||||||
inputIndex: number = 0;
|
inputIndex: number = 0;
|
||||||
changedIndex: number = 1;
|
changedIndex: number | null = 1;
|
||||||
|
|
||||||
displayWidget: ITextWidget;
|
displayWidget: ITextWidget;
|
||||||
|
|
||||||
@@ -91,10 +91,10 @@ export abstract class ComfyWidgetNode<T = any> extends ComfyGraphNode {
|
|||||||
console.debug("[Widget] valueUpdated", this, value)
|
console.debug("[Widget] valueUpdated", this, value)
|
||||||
this.displayWidget.value = this.formatValue(value)
|
this.displayWidget.value = this.formatValue(value)
|
||||||
|
|
||||||
if (this.outputs.length >= this.outputIndex) {
|
if (this.outputIndex !== null && this.outputs.length >= this.outputIndex) {
|
||||||
this.setOutputData(this.outputIndex, get(this.value))
|
this.setOutputData(this.outputIndex, get(this.value))
|
||||||
}
|
}
|
||||||
if (this.outputs.length >= this.changedIndex) {
|
if (this.changedIndex !== null & this.outputs.length >= this.changedIndex) {
|
||||||
const changedOutput = this.outputs[this.changedIndex]
|
const changedOutput = this.outputs[this.changedIndex]
|
||||||
if (changedOutput.type === BuiltInSlotType.EVENT)
|
if (changedOutput.type === BuiltInSlotType.EVENT)
|
||||||
this.triggerSlot(this.changedIndex, "changed")
|
this.triggerSlot(this.changedIndex, "changed")
|
||||||
@@ -407,25 +407,34 @@ export class ComfyGalleryNode extends ComfyWidgetNode<GradioFileData[]> {
|
|||||||
static slotLayout: SlotLayout = {
|
static slotLayout: SlotLayout = {
|
||||||
inputs: [
|
inputs: [
|
||||||
{ name: "images", type: "OUTPUT" },
|
{ name: "images", type: "OUTPUT" },
|
||||||
{ name: "store", type: BuiltInSlotType.ACTION }
|
{ name: "store", type: BuiltInSlotType.ACTION },
|
||||||
|
{ name: "clear", type: BuiltInSlotType.ACTION }
|
||||||
|
],
|
||||||
|
outputs: [
|
||||||
|
{ name: "selected_index", type: "number" }
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
override svelteComponentType = GalleryWidget
|
override svelteComponentType = GalleryWidget
|
||||||
override copyFromInputLink = false;
|
override copyFromInputLink = false;
|
||||||
|
override outputIndex = null;
|
||||||
|
override changedIndex = null;
|
||||||
|
|
||||||
|
index: number = 0;
|
||||||
|
|
||||||
constructor(name?: string) {
|
constructor(name?: string) {
|
||||||
super(name, [])
|
super(name, [])
|
||||||
}
|
}
|
||||||
|
|
||||||
override afterQueued() {
|
override onExecute() {
|
||||||
let queue = get(queueState)
|
this.setOutputData(0, this.index)
|
||||||
if (!(typeof queue.queueRemaining === "number" && queue.queueRemaining > 1)) {
|
|
||||||
this.setValue([])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override onAction() {
|
override onAction(action: any) {
|
||||||
|
if (action === "clear") {
|
||||||
|
this.setValue([])
|
||||||
|
}
|
||||||
|
else if (action === "store") {
|
||||||
const link = this.getInputLink(0)
|
const link = this.getInputLink(0)
|
||||||
if (link.data && "images" in link.data) {
|
if (link.data && "images" in link.data) {
|
||||||
const data = link.data as GalleryOutput
|
const data = link.data as GalleryOutput
|
||||||
@@ -433,8 +442,10 @@ export class ComfyGalleryNode extends ComfyWidgetNode<GradioFileData[]> {
|
|||||||
|
|
||||||
const galleryItems: GradioFileData[] = this.convertItems(link.data)
|
const galleryItems: GradioFileData[] = this.convertItems(link.data)
|
||||||
|
|
||||||
const currentValue = get(this.value)
|
// const currentValue = get(this.value)
|
||||||
this.setValue(currentValue.concat(galleryItems))
|
// this.setValue(currentValue.concat(galleryItems))
|
||||||
|
this.setValue(galleryItems)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -461,6 +472,7 @@ export class ComfyGalleryNode extends ComfyWidgetNode<GradioFileData[]> {
|
|||||||
else {
|
else {
|
||||||
super.setValue([])
|
super.setValue([])
|
||||||
}
|
}
|
||||||
|
this.index = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ export type UIState = {
|
|||||||
graphLocked: boolean,
|
graphLocked: boolean,
|
||||||
autoAddUI: boolean,
|
autoAddUI: boolean,
|
||||||
uiEditMode: UIEditMode,
|
uiEditMode: UIEditMode,
|
||||||
subWorkflow: string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export type WritableUIStateStore = Writable<UIState>;
|
export type WritableUIStateStore = Writable<UIState>;
|
||||||
@@ -21,7 +20,6 @@ const store: WritableUIStateStore = writable(
|
|||||||
nodesLocked: false,
|
nodesLocked: false,
|
||||||
autoAddUI: true,
|
autoAddUI: true,
|
||||||
uiEditMode: "disabled",
|
uiEditMode: "disabled",
|
||||||
subWorkflow: "default"
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const uiStateStore: WritableUIStateStore =
|
const uiStateStore: WritableUIStateStore =
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
import type { Writable } from "svelte/store";
|
import type { Writable } from "svelte/store";
|
||||||
import type { ComfyGalleryNode } from "$lib/nodes/ComfyWidgetNodes";
|
import type { ComfyGalleryNode } from "$lib/nodes/ComfyWidgetNodes";
|
||||||
import type { FileData as GradioFileData } from "@gradio/upload";
|
import type { FileData as GradioFileData } from "@gradio/upload";
|
||||||
|
import type { SelectData as GradioSelectData } from "@gradio/utils";
|
||||||
|
|
||||||
export let widget: WidgetLayout | null = null;
|
export let widget: WidgetLayout | null = null;
|
||||||
let node: ComfyGalleryNode | null = null;
|
let node: ComfyGalleryNode | null = null;
|
||||||
@@ -21,6 +22,7 @@
|
|||||||
node = widget.node as ComfyGalleryNode
|
node = widget.node as ComfyGalleryNode
|
||||||
nodeValue = node.value;
|
nodeValue = node.value;
|
||||||
propsChanged = node.propsChanged;
|
propsChanged = node.propsChanged;
|
||||||
|
node.index = 0;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -31,7 +33,8 @@
|
|||||||
}
|
}
|
||||||
let element: HTMLDivElement;
|
let element: HTMLDivElement;
|
||||||
|
|
||||||
function updateForLightbox() {
|
function onSelect(e: CustomEvent<GradioSelectData>) {
|
||||||
|
// Setup lightbox
|
||||||
// Wait for gradio gallery to show the large preview image, if no timeout then
|
// Wait for gradio gallery to show the large preview image, if no timeout then
|
||||||
// the event might fire too early
|
// the event might fire too early
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
@@ -41,6 +44,9 @@
|
|||||||
}
|
}
|
||||||
ImageViewer.instance.updateOnBackgroundChange();
|
ImageViewer.instance.updateOnBackgroundChange();
|
||||||
}, 200)
|
}, 200)
|
||||||
|
|
||||||
|
// Update index
|
||||||
|
node.index = e.detail.index as number;
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
@@ -55,7 +61,7 @@
|
|||||||
{style}
|
{style}
|
||||||
root={""}
|
root={""}
|
||||||
root_url={""}
|
root_url={""}
|
||||||
on:select={updateForLightbox}
|
on:select={onSelect}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</Block>
|
</Block>
|
||||||
|
|||||||
Reference in New Issue
Block a user