Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
"seeAllWorkflows": "See all workflows",
"showWorkflow": "Show {title}",
"openWorkflow": "Open {title} on Comfy Hub",
"openWorkflowCta": "Open",
"previousWorkflow": "Previous workflow",
"nextWorkflow": "Next workflow",
"workflowsUnavailable": "Example workflows couldn't be loaded. Check your connection and try again.",
"retry": "Try again"
},
Expand Down
3 changes: 3 additions & 0 deletions locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
"seeAllWorkflows": "查看全部工作流",
"showWorkflow": "显示 {title}",
"openWorkflow": "在 Comfy Hub 打开 {title}",
"openWorkflowCta": "打开",
"previousWorkflow": "上一个工作流",
"nextWorkflow": "下一个工作流",
"workflowsUnavailable": "无法加载示例工作流。请检查网络连接后重试。",
"retry": "重试"
},
Expand Down
90 changes: 89 additions & 1 deletion src/renderer/src/panel/HomeView.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ async function openHome() {
function arc(wrapper: VueWrapper): string[] {
return wrapper
.findAll('[data-testid="home-workflow-card"]:not([aria-hidden="true"])')
.map((card) => ({ offset: Number(card.attributes('data-arc-offset')), text: card.text() }))
.map((card) => ({
offset: Number(card.attributes('data-arc-offset')),
text: card.get('[data-testid="home-workflow-name"]').text()
}))
.sort((left, right) => left.offset - right.offset)
.map((card) => `${card.offset}:${card.text}`)
}
Expand Down Expand Up @@ -201,6 +204,91 @@ describe('Home example workflows', () => {
expect(cardAt(wrapper, 0).text()).toContain('Workflow 1')
})

it('turns the carousel with the previous and next arrows', async () => {
listHomeWorkflows.mockResolvedValue(SEVEN_WORKFLOWS)
const wrapper = await openHome()
const next = wrapper.get('[data-testid="home-workflow-next"]')
const previous = wrapper.get('[data-testid="home-workflow-previous"]')

expect(next.attributes('aria-label')).toBe('Next workflow')
expect(previous.attributes('aria-label')).toBe('Previous workflow')

await next.trigger('click')
await next.trigger('click')
expect(cardAt(wrapper, 0).text()).toContain('Workflow 2')

await previous.trigger('click')
await previous.trigger('click')
await previous.trigger('click')
expect(cardAt(wrapper, 0).text()).toContain('Workflow 6')
expect(openCatalogWorkflow).not.toHaveBeenCalled()
})

it('stops the arrows at the ends of a short list and leaves them out for a single card', async () => {
listHomeWorkflows.mockResolvedValue([UPSCALE, TALK])
const wrapper = await openHome()
const next = wrapper.get('[data-testid="home-workflow-next"]')
const previous = wrapper.get('[data-testid="home-workflow-previous"]')

expect(previous.attributes('disabled')).toBeDefined()
expect(next.attributes('disabled')).toBeUndefined()

await next.trigger('click')
expect(cardAt(wrapper, 0).text()).toContain('Make your character talk')
expect(next.attributes('disabled')).toBeDefined()
expect(previous.attributes('disabled')).toBeUndefined()

listHomeWorkflows.mockResolvedValue([UPSCALE])
const single = await openHome()
expect(single.find('[data-testid="home-workflow-next"]').exists()).toBe(false)
expect(single.find('[data-testid="home-workflow-previous"]').exists()).toBe(false)
})

it('keeps keyboard focus on an arrow when the one in use reaches the end of a short list', async () => {
listHomeWorkflows.mockResolvedValue([UPSCALE, TALK])
const wrapper = await openHome()
const next = wrapper.get<HTMLButtonElement>('[data-testid="home-workflow-next"]')
const previous = wrapper.get<HTMLButtonElement>('[data-testid="home-workflow-previous"]')

next.element.focus()
await next.trigger('click')
await flushPromises()

expect(next.element.disabled).toBe(true)
expect(document.activeElement).toBe(previous.element)
})

it('turns with the arrow keys from an arrow button and moves card focus to the new front card', async () => {
listHomeWorkflows.mockResolvedValue(SEVEN_WORKFLOWS)
const wrapper = await openHome()

const next = wrapper.get('[data-testid="home-workflow-next"]')
await next.trigger('keydown', { key: 'ArrowRight' })
expect(cardAt(wrapper, 0).text()).toContain('Workflow 1')

const front = cardAt(wrapper, 0).element as HTMLButtonElement
front.focus()
await cardAt(wrapper, 0).trigger('keydown', { key: 'ArrowRight' })
await flushPromises()

expect(cardAt(wrapper, 0).text()).toContain('Workflow 2')
expect(document.activeElement).toBe(cardAt(wrapper, 0).element)
})

it('offers Open on the front card only, and opens that workflow from it', async () => {
listHomeWorkflows.mockResolvedValue(SEVEN_WORKFLOWS)
const wrapper = await openHome()
const ctas = wrapper.findAll('[data-testid="home-workflow-cta"]')

expect(ctas).toHaveLength(1)
expect(cardAt(wrapper, 0).find('[data-testid="home-workflow-cta"]').text()).toBe('Open')
expect(ctas[0]!.attributes('aria-hidden')).toBe('true')

await ctas[0]!.trigger('click')

expect(openCatalogWorkflow).toHaveBeenCalledExactlyOnceWith('workflow-0')
})

it('turns the carousel when it is dragged, and does not open the card the drag ends on', async () => {
listHomeWorkflows.mockResolvedValue(SEVEN_WORKFLOWS)
const wrapper = await openHome()
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/src/panel/HomeView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type LoadState = 'loading' | 'ready' | 'unavailable'

const HOME_BUILD_LIMIT = 3
const TEXT_LINK_CLASS =
'h-6 gap-1.5 rounded-[7px] px-1.5 text-[13px]/5 font-medium text-muted-foreground hover:bg-secondary hover:text-foreground'
'-my-1 h-8 gap-1.5 rounded-lg px-3 text-[13px]/5 font-medium text-muted-foreground hover:bg-secondary hover:text-foreground'

const emit = defineEmits<{
pick: [installation: Installation]
Expand Down
204 changes: 135 additions & 69 deletions src/renderer/src/panel/home/HomeWorkflowCarousel.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts">
import { computed, onBeforeUnmount, ref, watch } from 'vue'
import { computed, nextTick, onBeforeUnmount, ref, useTemplateRef, watch } from 'vue'
import { useI18n } from 'vue-i18n'
import { ImageOff } from 'lucide-vue-next'
import { ChevronLeft, ChevronRight, ImageOff } from 'lucide-vue-next'
import type { CatalogWorkflow } from '../../types/ipc'

interface ArcSlot {
Expand All @@ -11,6 +11,9 @@ interface ArcSlot {
layer: number
}

const STEP_CLASS =
'absolute top-[150px] z-10 grid size-9 -translate-y-1/2 place-items-center rounded-[8px] border-0 bg-transparent p-0 text-muted-foreground opacity-50 outline-none transition-[opacity,background-color,color] duration-200 group-hover/arc:opacity-90 hover:bg-foreground/7 hover:text-foreground hover:opacity-100 focus-visible:bg-foreground/7 focus-visible:text-foreground focus-visible:opacity-100 active:scale-94 disabled:pointer-events-none disabled:opacity-0 motion-reduce:transition-none'

const ARC_REACH = 2
const OFFSTAGE = ARC_REACH + 1
const DRAG_PIXELS_PER_CARD = 150
Expand Down Expand Up @@ -51,6 +54,30 @@ const loadedThumbnails = ref(new Set<string>())
const brokenThumbnails = ref(new Set<string>())

const wraps = computed(() => workflows.length > ARC_REACH * 2)
const atFirst = computed(() => !wraps.value && frontPosition.value === 0)
const atLast = computed(() => !wraps.value && frontPosition.value === workflows.length - 1)

const arc = useTemplateRef<HTMLUListElement>('arc')
const stepButtons = useTemplateRef<HTMLButtonElement[]>('stepButtons')

const steps = computed(() => [
{
direction: -1,
label: t('home.previousWorkflow'),
icon: ChevronLeft,
side: 'left-[max(8px,calc(50%-420px))]',
disabled: atFirst.value,
testId: 'home-workflow-previous'
},
{
direction: 1,
label: t('home.nextWorkflow'),
icon: ChevronRight,
side: 'right-[max(8px,calc(50%-420px))]',
disabled: atLast.value,
testId: 'home-workflow-next'
}
])

function offsetFrom(position: number, index: number): number {
const count = workflows.length
Expand Down Expand Up @@ -151,6 +178,16 @@ function startDrag(event: PointerEvent): void {

onBeforeUnmount(stopDrag)

async function turn(direction: number): Promise<void> {
const focused = document.activeElement
const cardHadFocus = arc.value?.contains(focused) ?? false
const focusedArrow = stepButtons.value?.find((button) => button === focused)
moveTo(frontPosition.value + direction)
await nextTick()
if (cardHadFocus) arc.value?.querySelector<HTMLButtonElement>('[aria-current="true"]')?.focus()
else if (focusedArrow?.disabled) stepButtons.value?.find((button) => !button.disabled)?.focus()
}

function activate(card: { workflow: CatalogWorkflow; offset: number }): void {
if (clickBelongsToDrag) return
if (card.offset === 0) emit('open', card.workflow)
Expand All @@ -159,75 +196,104 @@ function activate(card: { workflow: CatalogWorkflow; offset: number }): void {
</script>

<template>
<ul
class="relative m-0 h-75 w-full touch-pan-y list-none p-0 select-none [perspective:3000px]"
:class="dragging ? 'cursor-grabbing' : 'cursor-grab'"
data-testid="home-workflow-carousel"
@pointerdown="startDrag"
@keydown.left.prevent="moveTo(frontPosition - 1)"
@keydown.right.prevent="moveTo(frontPosition + 1)"
>
<li v-for="card in arcCards" :key="card.workflow.id" class="contents">
<button
type="button"
class="absolute top-0 left-1/2 -ml-32 h-75 w-64 cursor-[inherit] overflow-hidden rounded-[18px] border-0 bg-[#1d1d1d] p-0 text-left shadow-[0_28px_56px_rgb(0_0_0/0.8)] outline-none focus-visible:ring-2 focus-visible:ring-ring"
:class="[
jumpedAcross.has(card.workflow.id)
? 'transition-none'
: 'transition-[transform,opacity] duration-500 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none',
!card.onStage && 'pointer-events-none'
]"
:style="slotStyle(card.offset)"
:aria-label="
card.offset === 0
? t('home.openWorkflow', { title: card.workflow.title })
: t('home.showWorkflow', { title: card.workflow.title })
"
:aria-current="card.offset === 0 ? 'true' : undefined"
:aria-hidden="card.onStage ? undefined : 'true'"
:tabindex="card.onStage ? undefined : -1"
data-testid="home-workflow-card"
:data-arc-offset="card.offset"
@click="activate(card)"
>
<img
v-if="showsThumbnail(card.workflow)"
:src="card.workflow.thumbnailUrl ?? undefined"
alt=""
draggable="false"
class="absolute inset-0 size-full object-cover transition-opacity duration-300 motion-reduce:transition-none"
:class="loadedThumbnails.has(card.workflow.id) ? 'opacity-100' : 'opacity-0'"
:data-loaded="loadedThumbnails.has(card.workflow.id)"
@load="markThumbnailLoaded(card.workflow)"
@error="markThumbnailBroken(card.workflow)"
/>
<span
v-else
class="absolute inset-0 flex items-center justify-center text-subtle-foreground"
<div class="group/arc relative" @keydown.left.prevent="turn(-1)" @keydown.right.prevent="turn(1)">
<ul
ref="arc"
class="relative m-0 h-75 w-full touch-pan-y list-none p-0 select-none [perspective:3000px]"
:class="dragging ? 'cursor-grabbing' : 'cursor-grab'"
data-testid="home-workflow-carousel"
@pointerdown="startDrag"
>
<li v-for="card in arcCards" :key="card.workflow.id" class="contents">
<button
type="button"
class="group/card absolute top-0 left-1/2 -ml-32 h-75 w-64 cursor-[inherit] overflow-hidden rounded-[18px] border-0 bg-[#1d1d1d] p-0 text-left shadow-[0_28px_56px_rgb(0_0_0/0.8)] outline-none focus-visible:ring-2 focus-visible:ring-ring"
:class="[
jumpedAcross.has(card.workflow.id)
? 'transition-none'
: 'transition-[transform,opacity] duration-500 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none',
!card.onStage && 'pointer-events-none'
]"
:style="slotStyle(card.offset)"
:aria-label="
card.offset === 0
? t('home.openWorkflow', { title: card.workflow.title })
: t('home.showWorkflow', { title: card.workflow.title })
"
:aria-current="card.offset === 0 ? 'true' : undefined"
:aria-hidden="card.onStage ? undefined : 'true'"
:tabindex="card.onStage ? undefined : -1"
data-testid="home-workflow-card"
:data-arc-offset="card.offset"
@click="activate(card)"
>
<ImageOff :size="22" aria-hidden="true" />
</span>
<span
class="absolute inset-x-0 top-0 h-[45%] bg-linear-to-b from-black/62 via-black/28 via-55% to-transparent"
aria-hidden="true"
/>
<span
class="absolute inset-0 bg-linear-to-t from-black/75 via-black/40 via-30% to-transparent to-55%"
aria-hidden="true"
/>
<span class="absolute inset-x-3.5 bottom-4 flex flex-col">
<span class="truncate text-sm/[17px] font-medium text-white">
{{ card.workflow.title }}
<img
v-if="showsThumbnail(card.workflow)"
:src="card.workflow.thumbnailUrl ?? undefined"
alt=""
draggable="false"
class="absolute inset-0 size-full object-cover transition-opacity duration-300 motion-reduce:transition-none"
:class="loadedThumbnails.has(card.workflow.id) ? 'opacity-100' : 'opacity-0'"
:data-loaded="loadedThumbnails.has(card.workflow.id)"
@load="markThumbnailLoaded(card.workflow)"
@error="markThumbnailBroken(card.workflow)"
/>
<span
v-else
class="absolute inset-0 flex items-center justify-center text-subtle-foreground"
>
<ImageOff :size="22" aria-hidden="true" />
</span>
<span v-if="card.workflow.description" class="truncate text-[13px]/[18px] text-white/70">
{{ card.workflow.description }}
<span
class="absolute inset-x-0 top-0 h-[45%] bg-linear-to-b from-black/62 via-black/28 via-55% to-transparent"
aria-hidden="true"
/>
<span
class="absolute inset-0 bg-linear-to-t from-black/75 via-black/40 via-30% to-transparent to-55%"
aria-hidden="true"
/>
<span class="absolute inset-x-3.5 bottom-4 flex items-center gap-2.5">
<span class="flex min-w-0 flex-1 flex-col" data-testid="home-workflow-name">
<span class="truncate text-sm/[17px] font-medium text-white">
{{ card.workflow.title }}
</span>
<span
v-if="card.workflow.description"
class="truncate text-[13px]/[18px] text-white/70"
>
{{ card.workflow.description }}
</span>
</span>
<span
v-if="card.offset === 0"
class="hidden h-[30px] flex-none items-center rounded-[var(--radius-control)] bg-white px-3.5 text-[12.5px] font-semibold text-[#111] shadow-[0_0_0_1px_rgb(0_0_0/0.06),0_8px_20px_-6px_rgb(0_0_0/0.5)] transition-[opacity,translate,display] transition-discrete duration-200 ease-[cubic-bezier(0.19,1,0.22,1)] group-hover/card:inline-flex group-focus-visible/card:inline-flex starting:translate-y-1 starting:opacity-0 motion-reduce:transition-none"
aria-hidden="true"
data-testid="home-workflow-cta"
>
{{ t('home.openWorkflowCta') }}
</span>
</span>
</span>
<span
class="pointer-events-none absolute inset-0 bg-[#090909] opacity-(--arc-dim) transition-opacity duration-500 motion-reduce:transition-none"
aria-hidden="true"
/>
<span
class="pointer-events-none absolute inset-0 bg-[#090909] opacity-(--arc-dim) transition-opacity duration-500 motion-reduce:transition-none"
aria-hidden="true"
/>
</button>
</li>
</ul>
<template v-if="workflows.length > 1">
<button
v-for="arrow in steps"
:key="arrow.direction"
ref="stepButtons"
type="button"
:class="[STEP_CLASS, arrow.side]"
:aria-label="arrow.label"
:disabled="arrow.disabled"
:data-testid="arrow.testId"
@click="turn(arrow.direction)"
>
<component :is="arrow.icon" :size="20" aria-hidden="true" />
</button>
</li>
</ul>
</template>
</div>
</template>
Loading