Skip to content

Commit

Permalink
improved linker components ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
diStyApps committed Nov 10, 2024
1 parent 21fef72 commit 5f18e89
Show file tree
Hide file tree
Showing 8 changed files with 372 additions and 252 deletions.
2 changes: 1 addition & 1 deletion __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
NODE_DISPLAY_NAME_MAPPINGS: Dict[str, str] = {}
APP_CONFIGS: List[AppConfig] = []
APP_NAME: str = "Flow"
APP_VERSION: str = "0.2.0"
APP_VERSION: str = "0.2.1"
PURPLE = "\033[38;5;129m"
RESET = "\033[0m"
FLOWMSG = f"{PURPLE}Flow{RESET}"
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[project]
name = "comfyui-disty-flow"
description = "Flow is a custom node designed to provide a more user-friendly interface for ComfyUI by acting as an alternative user interface for running workflows. It is not a replacement for workflow creation.\nFlow is currently in the early stages of development, so expect bugs and ongoing feature enhancements. With your support and feedback, Flow will settle into a steady stream."
version = "0.2.0"
version = "0.2.1"
license = {file = "LICENSE"}

[project.urls]
Expand Down
3 changes: 1 addition & 2 deletions web/linker/app.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@

import { initializeSaveOptions, updateWorkflowConfig } from './configHandler.js';
import { initializeFileHandlers } from './fileHandler.js';
import { displayNodes, displayNodeInfo } from './nodeHandler.js';
import { initializeMultiComponentHandler } from './multiComponentHandler.js';

const state = {
nodeToCustomNodeMap: {},
assignedComponents: {},
assignedComponents: [],
multiComponents: [],
components: [],
flowId: '',
Expand Down
260 changes: 157 additions & 103 deletions web/linker/componentHandler.js

Large diffs are not rendered by default.

52 changes: 24 additions & 28 deletions web/linker/configHandler.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { componentTypes } from '/core/js/common/scripts/componentTypes.js';
import { getSortOrderForNodeType } from './componentHandler.js';

function updateWorkflowConfig(state) {
const workflowConfigElement = document.getElementById('workflowConfig');
const saveOptionsElement = document.getElementById('saveOptions');
if (!workflowConfigElement || !saveOptionsElement) return;

const workflowConfig = buildWorkflowConfig(state);
const isCompactFormat = isCompactFormatSelected();
const isLeanFormat = isLeanFormatSelected(); const indentation = isCompactFormat ? 0 : 2;
const isLeanFormat = isLeanFormatSelected();
const indentation = isCompactFormat ? 0 : 2;
const fullConfigJSON = JSON.stringify(workflowConfig, null, indentation);

workflowConfigElement.textContent = fullConfigJSON;
Expand All @@ -25,45 +24,42 @@ function buildWorkflowConfig(state) {
url: state.flowUrl || "linker",
description: flowDescriptionInput.value || "Flow linker"
};
Object.keys(componentTypes).forEach(type => {
Object.keys(componentTypes).forEach(type => {
const pluralType = `${type}s`;
if (type !== 'multiComponent') {
workflowConfig[pluralType] = [];
}
});

const sortedNodes = Object.entries(state.assignedComponents || {})
.sort((a, b) => {
const nodeTypeA = state.nodeToCustomNodeMap[a[0]]?.classType;
const nodeTypeB = state.nodeToCustomNodeMap[b[0]]?.classType;
return getSortOrderForNodeType(nodeTypeA) - getSortOrderForNodeType(nodeTypeB);
const multiComponentIndices = new Set();
state.multiComponents.forEach(multiComponent => {
multiComponent.components.forEach(({ index }) => {
multiComponentIndices.add(index);
});
});

for (const [nodeId, components] of sortedNodes) {
components.forEach(component => {
if (component.inMultiComponent) return;

const { type, params } = component;
const fieldName = `${type}s`;
state.assignedComponents.forEach(({ nodeId, component }, index) => {
if (component.inMultiComponent) return;

if (!workflowConfig[fieldName]) return;
const { type, params } = component;
const fieldName = `${type}s`;

params.id = ensureUniqueComponentId(workflowConfig[fieldName], params.id);
const componentData = extractComponentData(component, type);
if (!workflowConfig[fieldName]) return;

if (type === 'dimensionSelector') {
componentData.nodePath = `${nodeId}.inputs`;
}
workflowConfig[fieldName].push(componentData);
params.id = ensureUniqueComponentId(workflowConfig[fieldName], params.id);
const componentData = extractComponentData(component, type);

});
}
if (type === 'dimensionSelector') {
componentData.nodePath = `${nodeId}.inputs`;
}
workflowConfig[fieldName].push(componentData);
});

if (state.multiComponents && state.multiComponents.length > 0) {
if (state.multiComponents && state.multiComponents.length > 0) {
workflowConfig.multiComponents = state.multiComponents.map(multiComponent => {
const componentGroups = {};

multiComponent.components.forEach(({ nodeId, component }) => {
multiComponent.components.forEach(({ component, index }) => {
const { type } = component;
const componentData = extractComponentData(component, type);

Expand All @@ -84,7 +80,8 @@ function buildWorkflowConfig(state) {
});
}

const isLeanFormat = isLeanFormatSelected(); if (isLeanFormat) {
const isLeanFormat = isLeanFormatSelected();
if (isLeanFormat) {
removeEmptyFields(workflowConfig, ['id', 'name', 'url', 'description']);
}

Expand Down Expand Up @@ -308,7 +305,6 @@ async function previewFlow(workflowConfigElement, state) {
window.parent.postMessage({ type: 'loadFlow', flowUrl: "linker" }, '*');

})

.catch(() => alert('Failed to save configuration. Please try again.'));
} catch (error) {
console.error('Error during preview:', error);
Expand Down
Loading

0 comments on commit 5f18e89

Please sign in to comment.