mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-05 15:40:10 +00:00
* [refactor] Improve renderer architecture organization Building on PR #5388, this refines the renderer domain structure: **Key improvements:** - Group all transform utilities in `transform/` subdirectory for better cohesion - Move canvas state to dedicated `renderer/core/canvas/` domain - Consolidate coordinate system logic (TransformPane, useTransformState, sync utilities) **File organization:** - `renderer/core/canvas/canvasStore.ts` (was `stores/graphStore.ts`) - `renderer/core/layout/transform/` contains all coordinate system utilities - Transform sync utilities co-located with core transform logic This creates clearer domain boundaries and groups related functionality while building on the foundation established in PR #5388. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * fix: Clean up linter-modified files * Fix import paths and clean up unused imports after rebase - Update all remaining @/stores/graphStore references to @/renderer/core/canvas/canvasStore - Remove unused imports from selection toolbox components - All tests pass, only reka-ui upstream issue remains in typecheck 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * [auto-fix] Apply ESLint and Prettier fixes --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: GitHub Action <action@github.com>
107 lines
2.5 KiB
TypeScript
107 lines
2.5 KiB
TypeScript
import { useI18n } from 'vue-i18n'
|
|
|
|
import type { Direction } from '@/lib/litegraph/src/interfaces'
|
|
import { alignNodes, distributeNodes } from '@/lib/litegraph/src/utils/arrange'
|
|
import { useCanvasStore } from '@/renderer/core/canvas/canvasStore'
|
|
import { isLGraphNode } from '@/utils/litegraphUtil'
|
|
|
|
import { useCanvasRefresh } from './useCanvasRefresh'
|
|
|
|
interface AlignOption {
|
|
name: string
|
|
localizedName: string
|
|
value: Direction
|
|
icon: string
|
|
}
|
|
|
|
interface DistributeOption {
|
|
name: string
|
|
localizedName: string
|
|
value: boolean // true for horizontal, false for vertical
|
|
icon: string
|
|
}
|
|
|
|
/**
|
|
* Composable for handling node alignment and distribution
|
|
*/
|
|
export function useNodeArrangement() {
|
|
const { t } = useI18n()
|
|
const canvasStore = useCanvasStore()
|
|
const canvasRefresh = useCanvasRefresh()
|
|
const alignOptions: AlignOption[] = [
|
|
{
|
|
name: 'top',
|
|
localizedName: t('contextMenu.Top'),
|
|
value: 'top',
|
|
icon: 'icon-[lucide--align-start-vertical]'
|
|
},
|
|
{
|
|
name: 'bottom',
|
|
localizedName: t('contextMenu.Bottom'),
|
|
value: 'bottom',
|
|
icon: 'icon-[lucide--align-end-vertical]'
|
|
},
|
|
{
|
|
name: 'left',
|
|
localizedName: t('contextMenu.Left'),
|
|
value: 'left',
|
|
icon: 'icon-[lucide--align-start-horizontal]'
|
|
},
|
|
{
|
|
name: 'right',
|
|
localizedName: t('contextMenu.Right'),
|
|
value: 'right',
|
|
icon: 'icon-[lucide--align-end-horizontal]'
|
|
}
|
|
]
|
|
|
|
const distributeOptions: DistributeOption[] = [
|
|
{
|
|
name: 'horizontal',
|
|
localizedName: t('contextMenu.Horizontal'),
|
|
value: true,
|
|
icon: 'icon-[lucide--align-center-horizontal]'
|
|
},
|
|
{
|
|
name: 'vertical',
|
|
localizedName: t('contextMenu.Vertical'),
|
|
value: false,
|
|
icon: 'icon-[lucide--align-center-vertical]'
|
|
}
|
|
]
|
|
|
|
const applyAlign = (alignOption: AlignOption) => {
|
|
const selectedNodes = Array.from(canvasStore.selectedItems).filter((item) =>
|
|
isLGraphNode(item)
|
|
)
|
|
|
|
if (selectedNodes.length === 0) {
|
|
return
|
|
}
|
|
|
|
alignNodes(selectedNodes, alignOption.value)
|
|
|
|
canvasRefresh.refreshCanvas()
|
|
}
|
|
|
|
const applyDistribute = (distributeOption: DistributeOption) => {
|
|
const selectedNodes = Array.from(canvasStore.selectedItems).filter((item) =>
|
|
isLGraphNode(item)
|
|
)
|
|
|
|
if (selectedNodes.length < 2) {
|
|
return
|
|
}
|
|
|
|
distributeNodes(selectedNodes, distributeOption.value)
|
|
canvasRefresh.refreshCanvas()
|
|
}
|
|
|
|
return {
|
|
alignOptions,
|
|
distributeOptions,
|
|
applyAlign,
|
|
applyDistribute
|
|
}
|
|
}
|