mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-03-08 06:30:04 +00:00
## Summary Redesigned node search with categories ## Changes - **What**: Adds a v2 search component, leaving the existing implementation untouched - It also brings onboard the incomplete node library & preview changes, disabled and behind a hidden setting - **Breaking**: Changes the 'default' value of the node search setting to v2, adding v1 (legacy) as an option ## Screenshots (if applicable) https://github.com/user-attachments/assets/2ab797df-58f0-48e8-8b20-2a1809e3735f ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-8987-V2-Node-Search-hidden-Node-Library-changes-30c6d73d36508160902bcb92553f147c) by [Unito](https://www.unito.io) --------- Co-authored-by: Yourz <crazilou@vip.qq.com> Co-authored-by: Amp <amp@ampcode.com> Co-authored-by: github-actions <github-actions@github.com> Co-authored-by: GitHub Action <action@github.com> Co-authored-by: Christian Byrne <cbyrne@comfy.org>
70 lines
1.6 KiB
Vue
70 lines
1.6 KiB
Vue
<template>
|
|
<div
|
|
ref="containerRef"
|
|
:class="
|
|
cn('overflow-hidden whitespace-nowrap', !isScrolling && 'text-ellipsis')
|
|
"
|
|
>
|
|
<slot />
|
|
</div>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import { useElementHover, useElementSize, useRafFn } from '@vueuse/core'
|
|
import { ref, watch } from 'vue'
|
|
|
|
import { cn } from '@/utils/tailwindUtil'
|
|
|
|
const { speed = 70 } = defineProps<{
|
|
/** Scroll speed in pixels per second */
|
|
speed?: number
|
|
}>()
|
|
|
|
const containerRef = ref<HTMLElement | null>(null)
|
|
const isHovered = useElementHover(containerRef, { delayEnter: 350 })
|
|
const { width: containerWidth } = useElementSize(containerRef)
|
|
const isScrolling = ref(false)
|
|
let scrollStartTime = 0
|
|
let overflowAmount = 0
|
|
|
|
const { pause, resume } = useRafFn(
|
|
({ timestamp }) => {
|
|
const el = containerRef.value
|
|
if (!el || overflowAmount <= 0) return pause()
|
|
|
|
const elapsed = timestamp - scrollStartTime
|
|
const duration = (overflowAmount / speed) * 1000
|
|
const progress = Math.min(elapsed / duration, 1)
|
|
el.scrollLeft = overflowAmount * progress
|
|
|
|
if (progress >= 1) pause()
|
|
},
|
|
{ immediate: false }
|
|
)
|
|
|
|
function startScroll() {
|
|
const el = containerRef.value
|
|
if (!el) return
|
|
|
|
overflowAmount = el.scrollWidth - containerWidth.value
|
|
if (overflowAmount <= 0) return
|
|
|
|
isScrolling.value = true
|
|
scrollStartTime = performance.now()
|
|
resume()
|
|
}
|
|
|
|
function stopScroll() {
|
|
pause()
|
|
if (containerRef.value) {
|
|
containerRef.value.scrollLeft = 0
|
|
}
|
|
isScrolling.value = false
|
|
}
|
|
|
|
watch(isHovered, (hovered) => {
|
|
if (hovered) startScroll()
|
|
else stopScroll()
|
|
})
|
|
</script>
|