mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-25 16:59:45 +00:00
Apply new code format standard (#217)
This commit is contained in:
@@ -1,72 +1,72 @@
|
||||
import { NodeSearchService } from "@/services/nodeSearchService";
|
||||
import { ComfyNodeDef } from "@/types/apiTypes";
|
||||
import { defineStore } from "pinia";
|
||||
import { NodeSearchService } from '@/services/nodeSearchService'
|
||||
import { ComfyNodeDef } from '@/types/apiTypes'
|
||||
import { defineStore } from 'pinia'
|
||||
|
||||
export const SYSTEM_NODE_DEFS: ComfyNodeDef[] = [
|
||||
{
|
||||
name: "PrimitiveNode",
|
||||
display_name: "Primitive",
|
||||
category: "utils",
|
||||
name: 'PrimitiveNode',
|
||||
display_name: 'Primitive',
|
||||
category: 'utils',
|
||||
input: { required: {}, optional: {} },
|
||||
output: ["*"],
|
||||
output_name: ["connect to widget input"],
|
||||
output: ['*'],
|
||||
output_name: ['connect to widget input'],
|
||||
output_is_list: [false],
|
||||
python_module: "nodes",
|
||||
description: "Primitive values like numbers, strings, and booleans.",
|
||||
python_module: 'nodes',
|
||||
description: 'Primitive values like numbers, strings, and booleans.'
|
||||
},
|
||||
{
|
||||
name: "Reroute",
|
||||
display_name: "Reroute",
|
||||
category: "utils",
|
||||
input: { required: { "": ["*"] }, optional: {} },
|
||||
output: ["*"],
|
||||
output_name: [""],
|
||||
name: 'Reroute',
|
||||
display_name: 'Reroute',
|
||||
category: 'utils',
|
||||
input: { required: { '': ['*'] }, optional: {} },
|
||||
output: ['*'],
|
||||
output_name: [''],
|
||||
output_is_list: [false],
|
||||
python_module: "nodes",
|
||||
description: "Reroute the connection to another node.",
|
||||
python_module: 'nodes',
|
||||
description: 'Reroute the connection to another node.'
|
||||
},
|
||||
{
|
||||
name: "Note",
|
||||
display_name: "Note",
|
||||
category: "utils",
|
||||
name: 'Note',
|
||||
display_name: 'Note',
|
||||
category: 'utils',
|
||||
input: { required: {}, optional: {} },
|
||||
output: [],
|
||||
output_name: [],
|
||||
output_is_list: [],
|
||||
python_module: "nodes",
|
||||
description: "Node that add notes to your project",
|
||||
},
|
||||
];
|
||||
python_module: 'nodes',
|
||||
description: 'Node that add notes to your project'
|
||||
}
|
||||
]
|
||||
|
||||
const SYSTEM_NODE_DEFS_BY_NAME = SYSTEM_NODE_DEFS.reduce((acc, nodeDef) => {
|
||||
acc[nodeDef.name] = nodeDef;
|
||||
return acc;
|
||||
}, {}) as Record<string, ComfyNodeDef>;
|
||||
acc[nodeDef.name] = nodeDef
|
||||
return acc
|
||||
}, {}) as Record<string, ComfyNodeDef>
|
||||
|
||||
interface State {
|
||||
nodeDefsByName: Record<string, ComfyNodeDef>;
|
||||
nodeDefsByName: Record<string, ComfyNodeDef>
|
||||
}
|
||||
|
||||
export const useNodeDefStore = defineStore("nodeDef", {
|
||||
export const useNodeDefStore = defineStore('nodeDef', {
|
||||
state: (): State => ({
|
||||
nodeDefsByName: SYSTEM_NODE_DEFS_BY_NAME,
|
||||
nodeDefsByName: SYSTEM_NODE_DEFS_BY_NAME
|
||||
}),
|
||||
getters: {
|
||||
nodeDefs(state) {
|
||||
return Object.values(state.nodeDefsByName);
|
||||
return Object.values(state.nodeDefsByName)
|
||||
},
|
||||
nodeSearchService(state) {
|
||||
return new NodeSearchService(Object.values(state.nodeDefsByName));
|
||||
},
|
||||
return new NodeSearchService(Object.values(state.nodeDefsByName))
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
addNodeDef(nodeDef: ComfyNodeDef) {
|
||||
this.nodeDefsByName[nodeDef.name] = nodeDef;
|
||||
this.nodeDefsByName[nodeDef.name] = nodeDef
|
||||
},
|
||||
addNodeDefs(nodeDefs: ComfyNodeDef[]) {
|
||||
for (const nodeDef of nodeDefs) {
|
||||
this.nodeDefsByName[nodeDef.name] = nodeDef;
|
||||
this.nodeDefsByName[nodeDef.name] = nodeDef
|
||||
}
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1,184 +1,184 @@
|
||||
import { api } from "@/scripts/api";
|
||||
import { app } from "@/scripts/app";
|
||||
import { api } from '@/scripts/api'
|
||||
import { app } from '@/scripts/app'
|
||||
import {
|
||||
validateTaskItem,
|
||||
TaskItem,
|
||||
TaskType,
|
||||
TaskPrompt,
|
||||
TaskStatus,
|
||||
TaskOutput,
|
||||
} from "@/types/apiTypes";
|
||||
import { plainToClass } from "class-transformer";
|
||||
import _ from "lodash";
|
||||
import { defineStore } from "pinia";
|
||||
import { toRaw } from "vue";
|
||||
TaskOutput
|
||||
} from '@/types/apiTypes'
|
||||
import { plainToClass } from 'class-transformer'
|
||||
import _ from 'lodash'
|
||||
import { defineStore } from 'pinia'
|
||||
import { toRaw } from 'vue'
|
||||
|
||||
// Task type used in the API.
|
||||
export type APITaskType = "queue" | "history";
|
||||
export type APITaskType = 'queue' | 'history'
|
||||
|
||||
export enum TaskItemDisplayStatus {
|
||||
Running = "Running",
|
||||
Pending = "Pending",
|
||||
Completed = "Completed",
|
||||
Failed = "Failed",
|
||||
Cancelled = "Cancelled",
|
||||
Running = 'Running',
|
||||
Pending = 'Pending',
|
||||
Completed = 'Completed',
|
||||
Failed = 'Failed',
|
||||
Cancelled = 'Cancelled'
|
||||
}
|
||||
|
||||
export class TaskItemImpl {
|
||||
taskType: TaskType;
|
||||
prompt: TaskPrompt;
|
||||
status?: TaskStatus;
|
||||
outputs?: TaskOutput;
|
||||
taskType: TaskType
|
||||
prompt: TaskPrompt
|
||||
status?: TaskStatus
|
||||
outputs?: TaskOutput
|
||||
|
||||
get apiTaskType(): APITaskType {
|
||||
switch (this.taskType) {
|
||||
case "Running":
|
||||
case "Pending":
|
||||
return "queue";
|
||||
case "History":
|
||||
return "history";
|
||||
case 'Running':
|
||||
case 'Pending':
|
||||
return 'queue'
|
||||
case 'History':
|
||||
return 'history'
|
||||
}
|
||||
}
|
||||
|
||||
get queueIndex() {
|
||||
return this.prompt[0];
|
||||
return this.prompt[0]
|
||||
}
|
||||
|
||||
get promptId() {
|
||||
return this.prompt[1];
|
||||
return this.prompt[1]
|
||||
}
|
||||
|
||||
get promptInputs() {
|
||||
return this.prompt[2];
|
||||
return this.prompt[2]
|
||||
}
|
||||
|
||||
get extraData() {
|
||||
return this.prompt[3];
|
||||
return this.prompt[3]
|
||||
}
|
||||
|
||||
get outputsToExecute() {
|
||||
return this.prompt[4];
|
||||
return this.prompt[4]
|
||||
}
|
||||
|
||||
get extraPngInfo() {
|
||||
return this.extraData.extra_pnginfo;
|
||||
return this.extraData.extra_pnginfo
|
||||
}
|
||||
|
||||
get clientId() {
|
||||
return this.extraData.client_id;
|
||||
return this.extraData.client_id
|
||||
}
|
||||
|
||||
get workflow() {
|
||||
return this.extraPngInfo.workflow;
|
||||
return this.extraPngInfo.workflow
|
||||
}
|
||||
|
||||
get messages() {
|
||||
return this.status?.messages || [];
|
||||
return this.status?.messages || []
|
||||
}
|
||||
|
||||
get interrupted() {
|
||||
return _.some(
|
||||
this.messages,
|
||||
(message) => message[0] === "execution_interrupted"
|
||||
);
|
||||
(message) => message[0] === 'execution_interrupted'
|
||||
)
|
||||
}
|
||||
|
||||
get isHistory() {
|
||||
return this.taskType === "History";
|
||||
return this.taskType === 'History'
|
||||
}
|
||||
|
||||
get isRunning() {
|
||||
return this.taskType === "Running";
|
||||
return this.taskType === 'Running'
|
||||
}
|
||||
|
||||
get displayStatus(): TaskItemDisplayStatus {
|
||||
switch (this.taskType) {
|
||||
case "Running":
|
||||
return TaskItemDisplayStatus.Running;
|
||||
case "Pending":
|
||||
return TaskItemDisplayStatus.Pending;
|
||||
case "History":
|
||||
case 'Running':
|
||||
return TaskItemDisplayStatus.Running
|
||||
case 'Pending':
|
||||
return TaskItemDisplayStatus.Pending
|
||||
case 'History':
|
||||
switch (this.status!.status_str) {
|
||||
case "success":
|
||||
return TaskItemDisplayStatus.Completed;
|
||||
case "error":
|
||||
case 'success':
|
||||
return TaskItemDisplayStatus.Completed
|
||||
case 'error':
|
||||
return this.interrupted
|
||||
? TaskItemDisplayStatus.Cancelled
|
||||
: TaskItemDisplayStatus.Failed;
|
||||
: TaskItemDisplayStatus.Failed
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
get executionStartTimestamp() {
|
||||
const message = this.messages.find(
|
||||
(message) => message[0] === "execution_start"
|
||||
);
|
||||
return message ? message[1].timestamp : undefined;
|
||||
(message) => message[0] === 'execution_start'
|
||||
)
|
||||
return message ? message[1].timestamp : undefined
|
||||
}
|
||||
|
||||
get executionEndTimestamp() {
|
||||
const messages = this.messages.filter((message) =>
|
||||
[
|
||||
"execution_success",
|
||||
"execution_interrupted",
|
||||
"execution_error",
|
||||
'execution_success',
|
||||
'execution_interrupted',
|
||||
'execution_error'
|
||||
].includes(message[0])
|
||||
);
|
||||
)
|
||||
if (!messages.length) {
|
||||
return undefined;
|
||||
return undefined
|
||||
}
|
||||
return _.max(messages.map((message) => message[1].timestamp));
|
||||
return _.max(messages.map((message) => message[1].timestamp))
|
||||
}
|
||||
|
||||
get executionTime() {
|
||||
if (!this.executionStartTimestamp || !this.executionEndTimestamp) {
|
||||
return undefined;
|
||||
return undefined
|
||||
}
|
||||
return this.executionEndTimestamp - this.executionStartTimestamp;
|
||||
return this.executionEndTimestamp - this.executionStartTimestamp
|
||||
}
|
||||
|
||||
get executionTimeInSeconds() {
|
||||
return this.executionTime !== undefined
|
||||
? this.executionTime / 1000
|
||||
: undefined;
|
||||
: undefined
|
||||
}
|
||||
|
||||
public async loadWorkflow() {
|
||||
await app.loadGraphData(toRaw(this.workflow));
|
||||
await app.loadGraphData(toRaw(this.workflow))
|
||||
if (this.outputs) {
|
||||
app.nodeOutputs = toRaw(this.outputs);
|
||||
app.nodeOutputs = toRaw(this.outputs)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
interface State {
|
||||
runningTasks: TaskItemImpl[];
|
||||
pendingTasks: TaskItemImpl[];
|
||||
historyTasks: TaskItemImpl[];
|
||||
runningTasks: TaskItemImpl[]
|
||||
pendingTasks: TaskItemImpl[]
|
||||
historyTasks: TaskItemImpl[]
|
||||
}
|
||||
|
||||
export const useQueueStore = defineStore("queue", {
|
||||
export const useQueueStore = defineStore('queue', {
|
||||
state: (): State => ({
|
||||
runningTasks: [],
|
||||
pendingTasks: [],
|
||||
historyTasks: [],
|
||||
historyTasks: []
|
||||
}),
|
||||
getters: {
|
||||
tasks(state) {
|
||||
return [
|
||||
...state.pendingTasks,
|
||||
...state.runningTasks,
|
||||
...state.historyTasks,
|
||||
];
|
||||
},
|
||||
...state.historyTasks
|
||||
]
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
// Fetch the queue data from the API
|
||||
async update() {
|
||||
const [queue, history] = await Promise.all([
|
||||
api.getQueue(),
|
||||
api.getHistory(),
|
||||
]);
|
||||
api.getHistory()
|
||||
])
|
||||
|
||||
const toClassAll = (tasks: TaskItem[]): TaskItemImpl[] =>
|
||||
tasks
|
||||
@@ -186,21 +186,21 @@ export const useQueueStore = defineStore("queue", {
|
||||
.filter((result) => result.success)
|
||||
.map((result) => plainToClass(TaskItemImpl, result.data))
|
||||
// Desc order to show the latest tasks first
|
||||
.sort((a, b) => b.queueIndex - a.queueIndex);
|
||||
.sort((a, b) => b.queueIndex - a.queueIndex)
|
||||
|
||||
this.runningTasks = toClassAll(queue.Running);
|
||||
this.pendingTasks = toClassAll(queue.Pending);
|
||||
this.historyTasks = toClassAll(history.History);
|
||||
this.runningTasks = toClassAll(queue.Running)
|
||||
this.pendingTasks = toClassAll(queue.Pending)
|
||||
this.historyTasks = toClassAll(history.History)
|
||||
},
|
||||
async clear() {
|
||||
await Promise.all(
|
||||
["queue", "history"].map((type) => api.clearItems(type))
|
||||
);
|
||||
await this.update();
|
||||
['queue', 'history'].map((type) => api.clearItems(type))
|
||||
)
|
||||
await this.update()
|
||||
},
|
||||
async delete(task: TaskItemImpl) {
|
||||
await api.deleteItem(task.apiTaskType, task.promptId);
|
||||
await this.update();
|
||||
},
|
||||
},
|
||||
});
|
||||
await api.deleteItem(task.apiTaskType, task.promptId)
|
||||
await this.update()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -7,35 +7,35 @@
|
||||
* settings directly updates the settingStore.settingValues.
|
||||
*/
|
||||
|
||||
import { app } from "@/scripts/app";
|
||||
import { ComfySettingsDialog } from "@/scripts/ui/settings";
|
||||
import { defineStore } from "pinia";
|
||||
import { app } from '@/scripts/app'
|
||||
import { ComfySettingsDialog } from '@/scripts/ui/settings'
|
||||
import { defineStore } from 'pinia'
|
||||
|
||||
interface State {
|
||||
settingValues: Record<string, any>;
|
||||
settingValues: Record<string, any>
|
||||
}
|
||||
|
||||
export const useSettingStore = defineStore("setting", {
|
||||
export const useSettingStore = defineStore('setting', {
|
||||
state: (): State => ({
|
||||
settingValues: {},
|
||||
settingValues: {}
|
||||
}),
|
||||
actions: {
|
||||
addSettings(settings: ComfySettingsDialog) {
|
||||
for (const id in settings.settingsLookup) {
|
||||
const value = settings.getSettingValue(id);
|
||||
this.settingValues[id] = value;
|
||||
const value = settings.getSettingValue(id)
|
||||
this.settingValues[id] = value
|
||||
}
|
||||
},
|
||||
|
||||
set(key: string, value: any) {
|
||||
this.settingValues[key] = value;
|
||||
app.ui.settings.setSettingValue(key, value);
|
||||
this.settingValues[key] = value
|
||||
app.ui.settings.setSettingValue(key, value)
|
||||
},
|
||||
|
||||
get(key: string) {
|
||||
return (
|
||||
this.settingValues[key] ?? app.ui.settings.getSettingDefaultValue(key)
|
||||
);
|
||||
},
|
||||
},
|
||||
});
|
||||
)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1,32 +1,32 @@
|
||||
import { defineStore } from "pinia";
|
||||
import { defineStore } from 'pinia'
|
||||
|
||||
interface WorkspaceState {
|
||||
activeSidebarTab: string | null;
|
||||
sidebarTabsOrder: string[]; // Array of tab IDs in order
|
||||
activeSidebarTab: string | null
|
||||
sidebarTabsOrder: string[] // Array of tab IDs in order
|
||||
}
|
||||
|
||||
export const useWorkspaceStore = defineStore("workspace", {
|
||||
export const useWorkspaceStore = defineStore('workspace', {
|
||||
state: (): WorkspaceState => ({
|
||||
activeSidebarTab: null,
|
||||
sidebarTabsOrder: [],
|
||||
sidebarTabsOrder: []
|
||||
}),
|
||||
actions: {
|
||||
updateActiveSidebarTab(tabId: string) {
|
||||
this.activeSidebarTab = tabId;
|
||||
this.activeSidebarTab = tabId
|
||||
},
|
||||
updateSidebarOrder(newOrder: string[]) {
|
||||
this.sidebarTabsOrder = newOrder;
|
||||
this.sidebarTabsOrder = newOrder
|
||||
},
|
||||
serialize() {
|
||||
return JSON.stringify({
|
||||
activeSidebarTab: this.activeSidebarTab,
|
||||
sidebarTabsOrder: this.sidebarTabsOrder,
|
||||
});
|
||||
sidebarTabsOrder: this.sidebarTabsOrder
|
||||
})
|
||||
},
|
||||
deserialize(state: string) {
|
||||
const parsedState = JSON.parse(state);
|
||||
this.sidebarTabsOrder = parsedState.sidebarTabsOrder;
|
||||
this.activeSidebarTab = parsedState.activeSidebarTab;
|
||||
},
|
||||
},
|
||||
});
|
||||
const parsedState = JSON.parse(state)
|
||||
this.sidebarTabsOrder = parsedState.sidebarTabsOrder
|
||||
this.activeSidebarTab = parsedState.activeSidebarTab
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user