mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-19 22:09:37 +00:00
## Summary Fix tree explorer row sizing: consistent row height and prevent horizontal overflow. ## Changes - **What**: 1. Reduce node bookmark button from `size-6` (24px) to `size-5` (20px) so node and folder rows both have 36px height, matching `TreeVirtualizer` estimate-size and fixing tree list overlap. 2. Change row width from `w-full` to `w-[calc(100%-var(--spacing)*4)]` to prevent horizontal overflow while keeping `mx-2` margin. ## Review Focus Pure UI change — no test coverage needed. Verify tree rows render at consistent height and no horizontal overflow occurs. ## Screenshots (if applicable) | Before | After | | -------- | ------- | |<img width="1218" height="1662" alt="image" src="https://github.com/user-attachments/assets/89c799ab-cef3-40ee-88ca-900f5d3c7890" />|<img width="407" height="758" alt="image" src="https://github.com/user-attachments/assets/f9aa4569-aaf8-467f-9dde-a187151af9aa" />| N/A ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-10501-fix-tree-explorer-row-height-and-width-overflow-32e6d73d3650819aa645c2262693ec62) by [Unito](https://www.unito.io) --------- Co-authored-by: Amp <amp@ampcode.com>
179 lines
4.7 KiB
Vue
179 lines
4.7 KiB
Vue
<template>
|
|
<TreeItem
|
|
v-slot="{ isExpanded, isSelected, handleToggle, handleSelect }"
|
|
:value="item.value"
|
|
:level="item.level"
|
|
as-child
|
|
>
|
|
<!-- Node -->
|
|
<div
|
|
v-if="item.value.type === 'node'"
|
|
v-bind="$attrs"
|
|
:class="cn(ROW_CLASS, isSelected && 'bg-comfy-input')"
|
|
:style="rowStyle"
|
|
draggable="true"
|
|
@click.stop="handleClick($event, handleToggle, handleSelect)"
|
|
@contextmenu="handleContextMenu"
|
|
@mouseenter="handleMouseEnter"
|
|
@mouseleave="handleMouseLeave"
|
|
@dragstart="handleDragStart"
|
|
@dragend="handleDragEnd"
|
|
>
|
|
<i class="icon-[comfy--node] size-4 shrink-0 text-muted-foreground" />
|
|
<span class="text-foreground min-w-0 flex-1 truncate text-sm">
|
|
<slot name="node" :node="item.value">
|
|
{{ item.value.label }}
|
|
</slot>
|
|
</span>
|
|
<button
|
|
:class="
|
|
cn(
|
|
'hover:text-foreground flex size-4 shrink-0 cursor-pointer items-center justify-center rounded-sm border-none bg-transparent text-muted-foreground',
|
|
'opacity-0 group-hover/tree-node:opacity-100'
|
|
)
|
|
"
|
|
:aria-label="$t('icon.bookmark')"
|
|
@click.stop="toggleBookmark"
|
|
>
|
|
<i
|
|
:class="
|
|
cn(
|
|
isBookmarked ? 'pi pi-bookmark-fill' : 'pi pi-bookmark',
|
|
'text-xs'
|
|
)
|
|
"
|
|
/>
|
|
</button>
|
|
</div>
|
|
|
|
<!-- Folder -->
|
|
<div
|
|
v-else
|
|
v-bind="$attrs"
|
|
:class="cn(ROW_CLASS, isSelected && 'bg-comfy-input')"
|
|
:style="rowStyle"
|
|
@click.stop="handleClick($event, handleToggle, handleSelect)"
|
|
>
|
|
<i
|
|
v-if="item.hasChildren"
|
|
:class="
|
|
cn(
|
|
'icon-[lucide--chevron-down] size-4 shrink-0 text-muted-foreground transition-transform',
|
|
!isExpanded && '-rotate-90'
|
|
)
|
|
"
|
|
/>
|
|
<i
|
|
:class="cn(item.value.icon, 'size-4 shrink-0 text-muted-foreground')"
|
|
/>
|
|
<span class="text-foreground min-w-0 flex-1 truncate text-sm">
|
|
<slot name="folder" :node="item.value">
|
|
{{ item.value.label }}
|
|
</slot>
|
|
</span>
|
|
</div>
|
|
</TreeItem>
|
|
|
|
<Teleport
|
|
v-if="showPreview && item.value.type === 'node' && item.value.data"
|
|
to="body"
|
|
>
|
|
<div
|
|
:ref="(el) => (previewRef = el as HTMLElement)"
|
|
:style="nodePreviewStyle"
|
|
>
|
|
<NodePreviewCard :node-def="item.value.data as ComfyNodeDefImpl" />
|
|
</div>
|
|
</Teleport>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import type { FlattenedItem } from 'reka-ui'
|
|
import { TreeItem } from 'reka-ui'
|
|
import { computed, inject } from 'vue'
|
|
|
|
import NodePreviewCard from '@/components/node/NodePreviewCard.vue'
|
|
import { useNodePreviewAndDrag } from '@/composables/node/useNodePreviewAndDrag'
|
|
import { useNodeBookmarkStore } from '@/stores/nodeBookmarkStore'
|
|
import type { ComfyNodeDefImpl } from '@/stores/nodeDefStore'
|
|
import { InjectKeyContextMenuNode } from '@/types/treeExplorerTypes'
|
|
import type { RenderedTreeExplorerNode } from '@/types/treeExplorerTypes'
|
|
import { cn } from '@/utils/tailwindUtil'
|
|
|
|
defineOptions({
|
|
inheritAttrs: false
|
|
})
|
|
|
|
const ROW_CLASS =
|
|
'group/tree-node flex w-full min-w-0 cursor-pointer select-none items-center gap-3 overflow-hidden py-2 outline-none hover:bg-comfy-input rounded'
|
|
|
|
const { item } = defineProps<{
|
|
item: FlattenedItem<RenderedTreeExplorerNode<ComfyNodeDefImpl>>
|
|
}>()
|
|
|
|
const emit = defineEmits<{
|
|
nodeClick: [
|
|
node: RenderedTreeExplorerNode<ComfyNodeDefImpl>,
|
|
event: MouseEvent
|
|
]
|
|
}>()
|
|
|
|
const contextMenuNode = inject(InjectKeyContextMenuNode)
|
|
const nodeBookmarkStore = useNodeBookmarkStore()
|
|
|
|
const nodeDef = computed(() => item.value.data)
|
|
|
|
const isBookmarked = computed(() => {
|
|
if (!nodeDef.value) return false
|
|
return nodeBookmarkStore.isBookmarked(nodeDef.value)
|
|
})
|
|
|
|
function toggleBookmark() {
|
|
if (nodeDef.value) {
|
|
nodeBookmarkStore.toggleBookmark(nodeDef.value)
|
|
}
|
|
}
|
|
|
|
const {
|
|
previewRef,
|
|
showPreview,
|
|
nodePreviewStyle,
|
|
handleMouseEnter: baseHandleMouseEnter,
|
|
handleMouseLeave,
|
|
handleDragStart: baseHandleDragStart,
|
|
handleDragEnd
|
|
} = useNodePreviewAndDrag(nodeDef)
|
|
|
|
const rowStyle = computed(() => ({
|
|
paddingLeft: `${8 + (item.level - 1) * 24}px`
|
|
}))
|
|
|
|
function handleClick(
|
|
e: MouseEvent,
|
|
handleToggle: () => void,
|
|
handleSelect: () => void
|
|
) {
|
|
handleSelect()
|
|
if (item.value.type === 'folder') {
|
|
handleToggle()
|
|
}
|
|
emit('nodeClick', item.value, e)
|
|
}
|
|
|
|
function handleContextMenu() {
|
|
if (contextMenuNode) {
|
|
contextMenuNode.value = item.value
|
|
}
|
|
}
|
|
|
|
function handleMouseEnter(e: MouseEvent) {
|
|
if (item.value.type !== 'node') return
|
|
baseHandleMouseEnter(e)
|
|
}
|
|
|
|
function handleDragStart(e: DragEvent) {
|
|
if (item.value.type !== 'node' || !item.value.data) return
|
|
baseHandleDragStart(e)
|
|
}
|
|
</script>
|