mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-10 18:10:08 +00:00
* move ref initialization to the component * remove redundant init * [refactor] Move minimap to domain-driven renderer structure - Create new src/renderer/extensions/minimap/ structure following domain-driven design - Add composables: useMinimapGraph, useMinimapViewport, useMinimapRenderer, useMinimapInteraction, useMinimapSettings - Add minimapCanvasRenderer with efficient batched rendering - Add comprehensive type definitions in types.ts - Remove old src/composables/useMinimap.ts composable - Implement proper separation of concerns with dedicated composables for each domain The new structure provides cleaner APIs, better performance through batched rendering, and improved maintainability through domain separation. * [test] Fix minimap tests for new renderer structure - Update all test imports to use new renderer paths - Fix mock implementations to match new composable APIs - Add proper RAF mocking for throttled functions - Fix type assertions to handle strict TypeScript checks - Update test expectations for new implementation behavior - Fix viewport transform calculations in tests - Handle async/throttled behavior correctly in tests All 28 minimap tests now passing with new architecture. * [fix] Remove unused init import in MiniMap component * [refactor] Move useWorkflowThumbnail to renderer/thumbnail structure - Moved useWorkflowThumbnail from src/composables to src/renderer/thumbnail/composables - Updated all imports in components, stores and services - Moved test file to match new structure - This ensures all rendering-related composables live in the renderer directory * [test] Fix minimap canvas renderer test for connections - Fixed mock setup for graph links to match LiteGraph's hybrid Map/Object structure - LiteGraph expects links to be accessible both as a Map and as an object - Test now properly verifies connection rendering functionality
192 lines
5.1 KiB
Vue
192 lines
5.1 KiB
Vue
<template>
|
|
<div
|
|
ref="workflowTabRef"
|
|
class="flex p-2 gap-2 workflow-tab"
|
|
v-bind="$attrs"
|
|
@mouseenter="handleMouseEnter"
|
|
@mouseleave="handleMouseLeave"
|
|
@click="handleClick"
|
|
>
|
|
<span class="workflow-label text-sm max-w-[150px] truncate inline-block">
|
|
{{ workflowOption.workflow.filename }}
|
|
</span>
|
|
<div class="relative">
|
|
<span v-if="shouldShowStatusIndicator" class="status-indicator">•</span>
|
|
<Button
|
|
class="close-button p-0 w-auto"
|
|
icon="pi pi-times"
|
|
text
|
|
severity="secondary"
|
|
size="small"
|
|
@click.stop="onCloseWorkflow(workflowOption)"
|
|
/>
|
|
</div>
|
|
</div>
|
|
|
|
<WorkflowTabPopover
|
|
ref="popoverRef"
|
|
:workflow-filename="workflowOption.workflow.filename"
|
|
:thumbnail-url="thumbnailUrl"
|
|
:is-active-tab="isActiveTab"
|
|
/>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import Button from 'primevue/button'
|
|
import { computed, onUnmounted, ref } from 'vue'
|
|
import { useI18n } from 'vue-i18n'
|
|
|
|
import {
|
|
usePragmaticDraggable,
|
|
usePragmaticDroppable
|
|
} from '@/composables/usePragmaticDragAndDrop'
|
|
import { useWorkflowThumbnail } from '@/renderer/thumbnail/composables/useWorkflowThumbnail'
|
|
import { useWorkflowService } from '@/services/workflowService'
|
|
import { useSettingStore } from '@/stores/settingStore'
|
|
import { ComfyWorkflow } from '@/stores/workflowStore'
|
|
import { useWorkflowStore } from '@/stores/workflowStore'
|
|
import { useWorkspaceStore } from '@/stores/workspaceStore'
|
|
|
|
import WorkflowTabPopover from './WorkflowTabPopover.vue'
|
|
|
|
interface WorkflowOption {
|
|
value: string
|
|
workflow: ComfyWorkflow
|
|
}
|
|
|
|
const props = defineProps<{
|
|
class?: string
|
|
workflowOption: WorkflowOption
|
|
}>()
|
|
|
|
const { t } = useI18n()
|
|
|
|
const workspaceStore = useWorkspaceStore()
|
|
const workflowStore = useWorkflowStore()
|
|
const settingStore = useSettingStore()
|
|
const workflowTabRef = ref<HTMLElement | null>(null)
|
|
const popoverRef = ref<InstanceType<typeof WorkflowTabPopover> | null>(null)
|
|
const workflowThumbnail = useWorkflowThumbnail()
|
|
|
|
// Use computed refs to cache autosave settings
|
|
const autoSaveSetting = computed(() =>
|
|
settingStore.get('Comfy.Workflow.AutoSave')
|
|
)
|
|
const autoSaveDelay = computed(() =>
|
|
settingStore.get('Comfy.Workflow.AutoSaveDelay')
|
|
)
|
|
|
|
const shouldShowStatusIndicator = computed(() => {
|
|
if (workspaceStore.shiftDown) {
|
|
// Branch 1: Shift key is held down, do not show the status indicator.
|
|
return false
|
|
}
|
|
if (!props.workflowOption.workflow.isPersisted) {
|
|
// Branch 2: Workflow is not persisted, show the status indicator.
|
|
return true
|
|
}
|
|
if (props.workflowOption.workflow.isModified) {
|
|
// Branch 3: Workflow is modified.
|
|
if (autoSaveSetting.value === 'off') {
|
|
// Sub-branch 3a: Autosave is off, so show the status indicator.
|
|
return true
|
|
}
|
|
if (autoSaveSetting.value === 'after delay' && autoSaveDelay.value > 3000) {
|
|
// Sub-branch 3b: Autosave delay is too high, so show the status indicator.
|
|
return true
|
|
}
|
|
// Sub-branch 3c: Workflow is modified but no condition applies, do not show the status indicator.
|
|
return false
|
|
}
|
|
// Default: do not show the status indicator. This should not be reachable.
|
|
return false
|
|
})
|
|
|
|
const isActiveTab = computed(() => {
|
|
return workflowStore.activeWorkflow?.key === props.workflowOption.workflow.key
|
|
})
|
|
|
|
const thumbnailUrl = computed(() => {
|
|
return workflowThumbnail.getThumbnail(props.workflowOption.workflow.key)
|
|
})
|
|
|
|
// Event handlers that delegate to the popover component
|
|
const handleMouseEnter = (event: Event) => {
|
|
popoverRef.value?.showPopover(event)
|
|
}
|
|
|
|
const handleMouseLeave = () => {
|
|
popoverRef.value?.hidePopover()
|
|
}
|
|
|
|
const handleClick = (event: Event) => {
|
|
popoverRef.value?.togglePopover(event)
|
|
}
|
|
|
|
const closeWorkflows = async (options: WorkflowOption[]) => {
|
|
for (const opt of options) {
|
|
if (
|
|
!(await useWorkflowService().closeWorkflow(opt.workflow, {
|
|
warnIfUnsaved: !workspaceStore.shiftDown,
|
|
hint: t('sideToolbar.workflowTab.dirtyCloseHint')
|
|
}))
|
|
) {
|
|
// User clicked cancel
|
|
break
|
|
}
|
|
}
|
|
}
|
|
|
|
const onCloseWorkflow = async (option: WorkflowOption) => {
|
|
await closeWorkflows([option])
|
|
}
|
|
const tabGetter = () => workflowTabRef.value as HTMLElement
|
|
|
|
usePragmaticDraggable(tabGetter, {
|
|
getInitialData: () => {
|
|
return {
|
|
workflowKey: props.workflowOption.workflow.key
|
|
}
|
|
}
|
|
})
|
|
|
|
usePragmaticDroppable(tabGetter, {
|
|
getData: () => {
|
|
return {
|
|
workflowKey: props.workflowOption.workflow.key
|
|
}
|
|
},
|
|
onDrop: (e) => {
|
|
const fromIndex = workflowStore.openWorkflows.findIndex(
|
|
(wf) => wf.key === e.source.data.workflowKey
|
|
)
|
|
const toIndex = workflowStore.openWorkflows.findIndex(
|
|
(wf) => wf.key === e.location.current.dropTargets[0]?.data.workflowKey
|
|
)
|
|
if (fromIndex !== toIndex) {
|
|
workflowStore.reorderWorkflows(fromIndex, toIndex)
|
|
}
|
|
}
|
|
})
|
|
|
|
onUnmounted(() => {
|
|
popoverRef.value?.hidePopover()
|
|
})
|
|
</script>
|
|
|
|
<style scoped>
|
|
.status-indicator {
|
|
@apply absolute font-bold;
|
|
font-size: 1.5rem;
|
|
top: 50%;
|
|
left: 50%;
|
|
transform: translate(-50%, -50%);
|
|
}
|
|
</style>
|
|
|
|
<style>
|
|
.p-tooltip.workflow-tab-tooltip {
|
|
z-index: 1200 !important;
|
|
}
|
|
</style>
|