mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-07-17 09:18:26 +00:00
Compare commits
11 Commits
feat/media
...
split/bill
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f2d632385b | ||
|
|
fa2e174d81 | ||
|
|
a898e39d20 | ||
|
|
2ef341dcd8 | ||
|
|
1815c7f7a4 | ||
|
|
287b9eb980 | ||
|
|
06b0471257 | ||
|
|
8120142f49 | ||
|
|
3164e6ab61 | ||
|
|
731512c655 | ||
|
|
c0ad1e98c2 |
3
.github/workflows/ci-website-build.yaml
vendored
3
.github/workflows/ci-website-build.yaml
vendored
@@ -40,3 +40,6 @@ jobs:
|
||||
WEBSITE_ASHBY_API_KEY: ${{ secrets.WEBSITE_ASHBY_API_KEY }}
|
||||
WEBSITE_ASHBY_JOB_BOARD_NAME: ${{ secrets.WEBSITE_ASHBY_JOB_BOARD_NAME }}
|
||||
run: pnpm --filter @comfyorg/website build
|
||||
|
||||
- name: Validate JSON-LD structured data
|
||||
run: pnpm --filter @comfyorg/website validate:jsonld
|
||||
|
||||
@@ -76,10 +76,14 @@ test.describe('Affiliates landing — desktop interactions', () => {
|
||||
return match?.textContent ?? null
|
||||
})
|
||||
expect(faqJsonLd, 'FAQ JSON-LD script').not.toBeNull()
|
||||
const parsed = JSON.parse(faqJsonLd!)
|
||||
expect(parsed['@type']).toBe('FAQPage')
|
||||
expect(Array.isArray(parsed.mainEntity)).toBe(true)
|
||||
expect(parsed.mainEntity.length).toBe(FAQ_COUNT)
|
||||
const graph = JSON.parse(faqJsonLd!)['@graph'] as {
|
||||
'@type': string
|
||||
mainEntity?: unknown[]
|
||||
}[]
|
||||
const faqPage = graph.find((node) => node['@type'] === 'FAQPage')
|
||||
expect(faqPage, 'FAQPage node in @graph').toBeDefined()
|
||||
expect(Array.isArray(faqPage!.mainEntity)).toBe(true)
|
||||
expect(faqPage!.mainEntity!.length).toBe(FAQ_COUNT)
|
||||
})
|
||||
|
||||
test('Apply Now CTA opens the application form in a new tab', async ({
|
||||
|
||||
158
apps/website/e2e/learning.spec.ts
Normal file
158
apps/website/e2e/learning.spec.ts
Normal file
@@ -0,0 +1,158 @@
|
||||
import { expect } from '@playwright/test'
|
||||
|
||||
import { learningTutorials } from '../src/data/learningTutorials'
|
||||
import { t } from '../src/i18n/translations'
|
||||
import { test } from './fixtures/blockExternalMedia'
|
||||
|
||||
const tutorialButtonName = (title: string, locale: 'en' | 'zh-CN') =>
|
||||
`${t('learning.tutorials.titlePrefix', locale)} ${title}`
|
||||
|
||||
test.describe('Learning page @smoke', () => {
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await page.goto('/learning')
|
||||
})
|
||||
|
||||
test('has correct title', async ({ page }) => {
|
||||
await expect(page).toHaveTitle('Learning — Comfy')
|
||||
})
|
||||
|
||||
test('hero headline references ComfyUI', async ({ page }) => {
|
||||
const heading = page.getByRole('heading', { level: 1 })
|
||||
await expect(heading).toBeVisible()
|
||||
await expect(heading).toContainText(t('learning.heroTitle.before', 'en'))
|
||||
await expect(heading).toContainText('ComfyUI')
|
||||
await expect(heading).toContainText(t('learning.heroTitle.line2', 'en'))
|
||||
})
|
||||
|
||||
test('featured workflow section shows title and author', async ({ page }) => {
|
||||
await expect(
|
||||
page.getByRole('heading', {
|
||||
name: t('learning.featured.title', 'en'),
|
||||
level: 2
|
||||
})
|
||||
).toBeVisible()
|
||||
await expect(
|
||||
page.getByText(t('learning.featured.author', 'en'))
|
||||
).toBeVisible()
|
||||
})
|
||||
|
||||
test('renders every tutorial from the data source', async ({ page }) => {
|
||||
await expect(
|
||||
page.getByRole('heading', {
|
||||
name: t('learning.tutorials.heading', 'en'),
|
||||
level: 2
|
||||
})
|
||||
).toBeVisible()
|
||||
|
||||
for (const tutorial of learningTutorials) {
|
||||
await expect(
|
||||
page.getByRole('button', {
|
||||
name: tutorialButtonName(tutorial.title.en, 'en')
|
||||
})
|
||||
).toBeVisible()
|
||||
}
|
||||
})
|
||||
|
||||
test('tutorials with a workflow link expose an external Try Workflow link', async ({
|
||||
page
|
||||
}) => {
|
||||
const linkedTutorials = learningTutorials.filter(
|
||||
(tutorial) => tutorial.href
|
||||
)
|
||||
const workflowLinks = page.getByRole('link', {
|
||||
name: t('cta.tryWorkflow', 'en')
|
||||
})
|
||||
const hrefs = await workflowLinks.evaluateAll((links) =>
|
||||
links.map((link) => link.getAttribute('href'))
|
||||
)
|
||||
for (const tutorial of linkedTutorials) {
|
||||
expect(hrefs).toContain(tutorial.href)
|
||||
}
|
||||
})
|
||||
|
||||
test('call to action links to contact sales', async ({ page }) => {
|
||||
await expect(
|
||||
page.getByRole('heading', {
|
||||
name: t('learning.cta.heading', 'en'),
|
||||
level: 2
|
||||
})
|
||||
).toBeVisible()
|
||||
await expect(
|
||||
page.getByRole('link', { name: t('learning.cta.contactSales', 'en') })
|
||||
).toHaveAttribute('href', '/contact')
|
||||
})
|
||||
})
|
||||
|
||||
test.describe('Learning tutorial dialog', () => {
|
||||
test('opens a tutorial video and dismisses via the close button', async ({
|
||||
page
|
||||
}) => {
|
||||
const [firstTutorial] = learningTutorials
|
||||
await page.goto('/learning')
|
||||
|
||||
const openButton = page.getByRole('button', {
|
||||
name: tutorialButtonName(firstTutorial.title.en, 'en')
|
||||
})
|
||||
await openButton.scrollIntoViewIfNeeded()
|
||||
|
||||
const dialog = page.getByRole('dialog', { name: firstTutorial.title.en })
|
||||
// TutorialsSection is hydrated via `client:visible`; retry the click until
|
||||
// Vue responds by opening the dialog.
|
||||
await expect(async () => {
|
||||
await openButton.click()
|
||||
await expect(dialog).toBeVisible({ timeout: 1_000 })
|
||||
}).toPass({ timeout: 10_000 })
|
||||
|
||||
await expect(
|
||||
dialog.getByRole('heading', { level: 2, name: firstTutorial.title.en })
|
||||
).toBeVisible()
|
||||
|
||||
await dialog
|
||||
.getByRole('button', { name: t('gallery.detail.close', 'en') })
|
||||
.click()
|
||||
await expect(dialog).toBeHidden()
|
||||
})
|
||||
|
||||
test('dismisses the dialog with the Escape key', async ({ page }) => {
|
||||
const [firstTutorial] = learningTutorials
|
||||
await page.goto('/learning')
|
||||
|
||||
const openButton = page.getByRole('button', {
|
||||
name: tutorialButtonName(firstTutorial.title.en, 'en')
|
||||
})
|
||||
await openButton.scrollIntoViewIfNeeded()
|
||||
|
||||
const dialog = page.getByRole('dialog', { name: firstTutorial.title.en })
|
||||
await expect(async () => {
|
||||
await openButton.click()
|
||||
await expect(dialog).toBeVisible({ timeout: 1_000 })
|
||||
}).toPass({ timeout: 10_000 })
|
||||
|
||||
await page.keyboard.press('Escape')
|
||||
await expect(dialog).toBeHidden()
|
||||
})
|
||||
})
|
||||
|
||||
test.describe('Learning page (zh-CN) @smoke', () => {
|
||||
test('renders localized title, headings, and tutorials', async ({ page }) => {
|
||||
await page.goto('/zh-CN/learning')
|
||||
|
||||
await expect(page).toHaveTitle('学习 — Comfy')
|
||||
await expect(page.getByRole('heading', { level: 1 })).toContainText(
|
||||
/[一-鿿]/
|
||||
)
|
||||
await expect(
|
||||
page.getByRole('heading', {
|
||||
name: t('learning.tutorials.heading', 'zh-CN'),
|
||||
level: 2
|
||||
})
|
||||
).toBeVisible()
|
||||
|
||||
const [firstTutorial] = learningTutorials
|
||||
await expect(
|
||||
page.getByRole('button', {
|
||||
name: tutorialButtonName(firstTutorial.title['zh-CN'], 'zh-CN')
|
||||
})
|
||||
).toBeVisible()
|
||||
})
|
||||
})
|
||||
@@ -17,7 +17,8 @@
|
||||
"test:visual:update": "playwright test --project visual --update-snapshots",
|
||||
"ashby:refresh-snapshot": "tsx ./scripts/refresh-ashby-snapshot.ts",
|
||||
"cloud-nodes:refresh-snapshot": "tsx ./scripts/refresh-cloud-nodes-snapshot.ts",
|
||||
"generate:models": "tsx ./scripts/generate-models.ts"
|
||||
"generate:models": "tsx ./scripts/generate-models.ts",
|
||||
"validate:jsonld": "tsx ./scripts/validate-jsonld.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"@astrojs/sitemap": "catalog:",
|
||||
|
||||
129
apps/website/scripts/validate-jsonld.ts
Normal file
129
apps/website/scripts/validate-jsonld.ts
Normal file
@@ -0,0 +1,129 @@
|
||||
import { readFileSync, readdirSync } from 'node:fs'
|
||||
import { join } from 'node:path'
|
||||
|
||||
import { collectGraphIds } from '../src/utils/jsonLd'
|
||||
|
||||
const DIST_DIR = join(process.cwd(), 'dist')
|
||||
const JSON_LD_BLOCK =
|
||||
/<script[^>]*type=["']application\/ld\+json["'][^>]*>([\s\S]*?)<\/script>/gi
|
||||
|
||||
interface Violation {
|
||||
file: string
|
||||
message: string
|
||||
}
|
||||
|
||||
function htmlFiles(dir: string): string[] {
|
||||
return readdirSync(dir, { recursive: true })
|
||||
.map(String)
|
||||
.filter((entry) => entry.endsWith('.html'))
|
||||
.map((entry) => join(dir, entry))
|
||||
}
|
||||
|
||||
function typesOf(node: Record<string, unknown>): string[] {
|
||||
const type = node['@type']
|
||||
if (typeof type === 'string') return [type]
|
||||
if (Array.isArray(type)) {
|
||||
return type.filter((t): t is string => typeof t === 'string')
|
||||
}
|
||||
return []
|
||||
}
|
||||
|
||||
function hasValidPrice(node: Record<string, unknown>): boolean {
|
||||
const price = node.price
|
||||
const priceStr = price == null ? '' : String(price).trim()
|
||||
return priceStr !== '' && !Number.isNaN(Number(priceStr))
|
||||
}
|
||||
|
||||
function checkHonesty(
|
||||
value: unknown,
|
||||
file: string,
|
||||
violations: Violation[]
|
||||
): void {
|
||||
const walk = (node: unknown): void => {
|
||||
if (Array.isArray(node)) {
|
||||
node.forEach(walk)
|
||||
return
|
||||
}
|
||||
if (!node || typeof node !== 'object') return
|
||||
const record = node as Record<string, unknown>
|
||||
const types = typesOf(record)
|
||||
if (types.includes('Review') || types.includes('AggregateRating')) {
|
||||
violations.push({
|
||||
file,
|
||||
message: `dishonest node type ${types.join('/')}`
|
||||
})
|
||||
}
|
||||
if ('aggregateRating' in record || 'review' in record) {
|
||||
violations.push({
|
||||
file,
|
||||
message: 'node carries a review/aggregateRating'
|
||||
})
|
||||
}
|
||||
if (
|
||||
types.includes('Offer') &&
|
||||
(!hasValidPrice(record) || !record.priceCurrency)
|
||||
) {
|
||||
violations.push({
|
||||
file,
|
||||
message: 'Offer missing priceCurrency or a concrete price'
|
||||
})
|
||||
}
|
||||
Object.values(record).forEach(walk)
|
||||
}
|
||||
walk(value)
|
||||
}
|
||||
|
||||
function validateFile(file: string): Violation[] {
|
||||
const html = readFileSync(file, 'utf8')
|
||||
const violations: Violation[] = []
|
||||
const definedIds = new Set<string>()
|
||||
const referencedIds: string[] = []
|
||||
|
||||
for (const match of html.matchAll(JSON_LD_BLOCK)) {
|
||||
let parsed: unknown
|
||||
try {
|
||||
parsed = JSON.parse(match[1])
|
||||
} catch (error) {
|
||||
violations.push({ file, message: `invalid JSON-LD: ${String(error)}` })
|
||||
continue
|
||||
}
|
||||
checkHonesty(parsed, file, violations)
|
||||
const { defined, references } = collectGraphIds(parsed)
|
||||
defined.forEach((id) => definedIds.add(id))
|
||||
referencedIds.push(...references)
|
||||
}
|
||||
|
||||
for (const id of referencedIds) {
|
||||
if (!definedIds.has(id)) {
|
||||
violations.push({ file, message: `unresolved @id reference: ${id}` })
|
||||
}
|
||||
}
|
||||
|
||||
return violations
|
||||
}
|
||||
|
||||
function main(): void {
|
||||
const files = htmlFiles(DIST_DIR)
|
||||
|
||||
if (files.length === 0) {
|
||||
console.error(
|
||||
`JSON-LD validation found no HTML in ${DIST_DIR} — build first.`
|
||||
)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
const violations = files.flatMap(validateFile)
|
||||
if (violations.length > 0) {
|
||||
console.error(`JSON-LD validation failed (${violations.length} issue(s)):`)
|
||||
for (const { file, message } of violations) {
|
||||
console.error(` ${file.replace(DIST_DIR, 'dist')}: ${message}`)
|
||||
}
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
process.stdout.write(
|
||||
`JSON-LD validation passed across ${files.length} page(s).\n`
|
||||
)
|
||||
}
|
||||
|
||||
main()
|
||||
41
apps/website/src/components/blocks/HeroBackdrop01.stories.ts
Normal file
41
apps/website/src/components/blocks/HeroBackdrop01.stories.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import type { Meta, StoryObj } from '@storybook/vue3-vite'
|
||||
|
||||
import HeroBackdrop01 from './HeroBackdrop01.vue'
|
||||
|
||||
const sampleImage =
|
||||
'https://images.unsplash.com/photo-1451187580459-43490279c0fa?auto=format&fit=crop&w=1600&q=80'
|
||||
|
||||
const meta: Meta<typeof HeroBackdrop01> = {
|
||||
title: 'Website/Blocks/HeroBackdrop01',
|
||||
component: HeroBackdrop01,
|
||||
tags: ['autodocs'],
|
||||
args: {
|
||||
backdrop: { type: 'image', src: sampleImage, alt: 'Abstract gradient' },
|
||||
title: 'Build anything\nwith ComfyUI',
|
||||
subtitle:
|
||||
'A powerful, modular visual interface for building and running AI workflows.'
|
||||
}
|
||||
}
|
||||
|
||||
export default meta
|
||||
type Story = StoryObj<typeof meta>
|
||||
|
||||
export const Default: Story = {}
|
||||
|
||||
export const WithBadge: Story = {
|
||||
args: {
|
||||
badgeText: 'New'
|
||||
}
|
||||
}
|
||||
|
||||
export const WithFootnote: Story = {
|
||||
args: {
|
||||
footnote: 'Available on Windows, macOS, and Linux.'
|
||||
}
|
||||
}
|
||||
|
||||
export const NoBackdrop: Story = {
|
||||
args: {
|
||||
backdrop: undefined
|
||||
}
|
||||
}
|
||||
193
apps/website/src/components/blocks/HeroBackdrop01.vue
Normal file
193
apps/website/src/components/blocks/HeroBackdrop01.vue
Normal file
@@ -0,0 +1,193 @@
|
||||
<script setup lang="ts">
|
||||
import { cn } from '@comfyorg/tailwind-utils'
|
||||
|
||||
import { computed } from 'vue'
|
||||
import type { HTMLAttributes } from 'vue'
|
||||
|
||||
import { prefersReducedMotion } from '../../composables/useReducedMotion'
|
||||
import ProductHeroBadge from '../common/ProductHeroBadge.vue'
|
||||
|
||||
type Backdrop =
|
||||
| { type: 'image'; src: string; alt?: string }
|
||||
| { type: 'video'; src: string; poster?: string; alt?: string }
|
||||
|
||||
const {
|
||||
backdrop,
|
||||
mobileBackdrop,
|
||||
badgeText,
|
||||
badgeLogoSrc,
|
||||
badgeLogoAlt,
|
||||
title,
|
||||
subtitle,
|
||||
footnote,
|
||||
class: className
|
||||
} = defineProps<{
|
||||
backdrop?: Backdrop
|
||||
mobileBackdrop?: Backdrop
|
||||
badgeText?: string
|
||||
badgeLogoSrc?: string
|
||||
badgeLogoAlt?: string
|
||||
title: string
|
||||
subtitle?: string
|
||||
footnote?: string
|
||||
class?: HTMLAttributes['class']
|
||||
}>()
|
||||
|
||||
// Respect prefers-reduced-motion: don't autoplay the looping backdrop video
|
||||
// (WCAG 2.2.2). The paused video falls back to its poster/first frame.
|
||||
const reduceMotion = computed(() => prefersReducedMotion())
|
||||
|
||||
// Removing the reactive `autoplay` attribute only suppresses the *initial*
|
||||
// play; it can't pause a video the browser has already started. That is
|
||||
// exactly the SSR case: the server renders `autoplay` (it can't read the
|
||||
// client's motion preference), the browser begins playback on parse, and the
|
||||
// post-hydration attribute removal is too late. Pause on mount so
|
||||
// reduced-motion users get the poster frame instead of a looping video.
|
||||
const pauseIfReduced = (el: unknown) => {
|
||||
if (el instanceof HTMLVideoElement && reduceMotion.value) el.pause()
|
||||
}
|
||||
|
||||
// On mobile the backdrop is an in-flow rounded card above the content; on
|
||||
// desktop it is the full-bleed background behind it. A single element serves
|
||||
// both roles via responsive classes — mobileBackdrop only swaps the source.
|
||||
const sharedBackdropClass =
|
||||
'relative aspect-3/2 w-full rounded-3xl object-cover lg:absolute lg:inset-0 lg:aspect-auto lg:size-full lg:rounded-none'
|
||||
|
||||
// When both breakpoints use images, serve them from a single responsive <img>
|
||||
// so the browser fetches only the source matching the viewport. Two
|
||||
// `hidden`/`lg:hidden`-toggled <img> layers would each download (display:none
|
||||
// does not stop the fetch), doubling the high-priority load on an
|
||||
// LCP-critical hero. Videos or a mixed image/video pair can't collapse this
|
||||
// way and fall back to breakpoint-toggled layers below.
|
||||
const responsiveImage = computed(() => {
|
||||
if (backdrop?.type !== 'image') return null
|
||||
if (mobileBackdrop && mobileBackdrop.type !== 'image') return null
|
||||
const base = mobileBackdrop ?? backdrop
|
||||
return {
|
||||
src: base.src,
|
||||
alt: backdrop.alt ?? mobileBackdrop?.alt ?? '',
|
||||
// Larger-viewport source; omitted when one image serves both breakpoints.
|
||||
desktopSrc: mobileBackdrop ? backdrop.src : undefined
|
||||
}
|
||||
})
|
||||
|
||||
// Fallback for videos and mixed image/video pairs: toggle assets by breakpoint.
|
||||
const backdropLayers = computed(() => {
|
||||
if (!backdrop) return []
|
||||
if (mobileBackdrop) {
|
||||
return [
|
||||
{
|
||||
backdrop: mobileBackdrop,
|
||||
class: 'relative aspect-3/2 w-full rounded-3xl object-cover lg:hidden'
|
||||
},
|
||||
{
|
||||
backdrop,
|
||||
class: 'absolute inset-0 hidden size-full object-cover lg:block'
|
||||
}
|
||||
]
|
||||
}
|
||||
return [{ backdrop, class: sharedBackdropClass }]
|
||||
})
|
||||
|
||||
const scrimShape = 'farthest-side at 50% 50%'
|
||||
const scrimStyle = {
|
||||
background: `radial-gradient(${scrimShape}, color-mix(in srgb, var(--color-primary-warm-white) 80%, transparent) 0%, transparent 80%)`,
|
||||
maskImage: `radial-gradient(${scrimShape}, #000 45%, transparent 90%)`,
|
||||
WebkitMaskImage: `radial-gradient(${scrimShape}, #000 45%, transparent 90%)`
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section
|
||||
:class="cn('max-w-9xl mx-auto px-4 pt-4 lg:px-6 lg:pt-6', className)"
|
||||
>
|
||||
<div class="relative overflow-hidden rounded-3xl">
|
||||
<slot name="backdrop">
|
||||
<picture v-if="responsiveImage" class="contents">
|
||||
<source
|
||||
v-if="responsiveImage.desktopSrc"
|
||||
:srcset="responsiveImage.desktopSrc"
|
||||
media="(min-width: 1024px)"
|
||||
/>
|
||||
<img
|
||||
:src="responsiveImage.src"
|
||||
:alt="responsiveImage.alt"
|
||||
fetchpriority="high"
|
||||
decoding="async"
|
||||
:class="sharedBackdropClass"
|
||||
/>
|
||||
</picture>
|
||||
|
||||
<template v-else>
|
||||
<template v-for="(layer, i) in backdropLayers" :key="i">
|
||||
<video
|
||||
v-if="layer.backdrop.type === 'video'"
|
||||
:ref="pauseIfReduced"
|
||||
:src="layer.backdrop.src"
|
||||
:poster="layer.backdrop.poster"
|
||||
:aria-label="layer.backdrop.alt"
|
||||
:aria-hidden="layer.backdrop.alt ? undefined : true"
|
||||
:autoplay="!reduceMotion"
|
||||
loop
|
||||
muted
|
||||
playsinline
|
||||
preload="metadata"
|
||||
:class="layer.class"
|
||||
/>
|
||||
<img
|
||||
v-else
|
||||
:src="layer.backdrop.src"
|
||||
:alt="layer.backdrop.alt ?? ''"
|
||||
fetchpriority="high"
|
||||
decoding="async"
|
||||
:class="layer.class"
|
||||
/>
|
||||
</template>
|
||||
</template>
|
||||
</slot>
|
||||
|
||||
<div
|
||||
class="relative flex flex-col justify-center px-0 pt-6 pb-8 lg:min-h-176 lg:px-16 lg:py-24"
|
||||
>
|
||||
<div class="relative w-full max-w-xl">
|
||||
<div
|
||||
aria-hidden="true"
|
||||
class="pointer-events-none absolute -inset-12 hidden backdrop-blur-md lg:-inset-16 lg:block"
|
||||
:style="scrimStyle"
|
||||
/>
|
||||
|
||||
<div class="relative">
|
||||
<ProductHeroBadge
|
||||
v-if="badgeText"
|
||||
:text="badgeText"
|
||||
:logo-src="badgeLogoSrc"
|
||||
:logo-alt="badgeLogoAlt"
|
||||
/>
|
||||
|
||||
<h1
|
||||
class="mt-10 text-4xl/tight font-light tracking-tight whitespace-pre-line text-primary-comfy-canvas lg:text-6xl/tight lg:text-primary-comfy-ink"
|
||||
>
|
||||
{{ title }}
|
||||
</h1>
|
||||
|
||||
<p
|
||||
v-if="subtitle"
|
||||
class="mt-8 max-w-md text-base text-primary-comfy-canvas lg:text-lg lg:text-primary-comfy-ink"
|
||||
>
|
||||
{{ subtitle }}
|
||||
</p>
|
||||
|
||||
<p
|
||||
v-if="footnote"
|
||||
class="mt-10 text-sm text-primary-comfy-canvas lg:text-primary-comfy-ink"
|
||||
>
|
||||
{{ footnote }}
|
||||
</p>
|
||||
|
||||
<slot />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
12
apps/website/src/components/common/JsonLdGraph.astro
Normal file
12
apps/website/src/components/common/JsonLdGraph.astro
Normal file
@@ -0,0 +1,12 @@
|
||||
---
|
||||
import type { JsonLdGraph } from '../../utils/jsonLd'
|
||||
import { escapeJsonLd } from '../../utils/escapeJsonLd'
|
||||
|
||||
interface Props {
|
||||
graph: JsonLdGraph
|
||||
}
|
||||
|
||||
const { graph } = Astro.props
|
||||
---
|
||||
|
||||
<script is:inline type="application/ld+json" set:html={escapeJsonLd(graph)} />
|
||||
53
apps/website/src/config/pricing.ts
Normal file
53
apps/website/src/config/pricing.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { t } from '../i18n/translations'
|
||||
import type { Locale, TranslationKey } from '../i18n/translations'
|
||||
import { externalLinks } from './routes'
|
||||
|
||||
interface PricingTier {
|
||||
slug: string
|
||||
labelKey: TranslationKey
|
||||
priceKey: TranslationKey
|
||||
}
|
||||
|
||||
const tiers: PricingTier[] = [
|
||||
{
|
||||
slug: 'standard',
|
||||
labelKey: 'pricing.plan.standard.label',
|
||||
priceKey: 'pricing.plan.standard.price'
|
||||
},
|
||||
{
|
||||
slug: 'creator',
|
||||
labelKey: 'pricing.plan.creator.label',
|
||||
priceKey: 'pricing.plan.creator.price'
|
||||
},
|
||||
{
|
||||
slug: 'pro',
|
||||
labelKey: 'pricing.plan.pro.label',
|
||||
priceKey: 'pricing.plan.pro.price'
|
||||
}
|
||||
]
|
||||
|
||||
export interface PricingOffer {
|
||||
name: string
|
||||
price: string
|
||||
url: string
|
||||
}
|
||||
|
||||
export function pricingOffers(locale: Locale): PricingOffer[] {
|
||||
return tiers.flatMap((tier) => {
|
||||
const display = t(tier.priceKey, locale).trim()
|
||||
const match = /^\$(\d+(?:\.\d+)?)$/.exec(display)
|
||||
if (!match) {
|
||||
console.warn(
|
||||
`pricingOffers: skipping tier "${tier.slug}" (${locale}) — price "${display}" is not a plain USD amount`
|
||||
)
|
||||
return []
|
||||
}
|
||||
return [
|
||||
{
|
||||
name: t(tier.labelKey, locale),
|
||||
price: match[1],
|
||||
url: `${externalLinks.cloud}/cloud/subscribe?tier=${tier.slug}&cycle=monthly`
|
||||
}
|
||||
]
|
||||
})
|
||||
}
|
||||
@@ -82,14 +82,19 @@ export const externalLinks = {
|
||||
docsApi: 'https://docs.comfy.org/development/cloud/overview#quick-start',
|
||||
docsMcp: 'https://docs.comfy.org/agent-tools/cloud',
|
||||
docsSubscription: 'https://docs.comfy.org/support/subscription/subscribing',
|
||||
g2ComfyUi: 'https://www.g2.com/products/comfyui',
|
||||
github: 'https://github.com/Comfy-Org/ComfyUI',
|
||||
githubInstall: 'https://github.com/Comfy-Org/ComfyUI#installing',
|
||||
instagram: 'https://www.instagram.com/comfyui/',
|
||||
linkedin: 'https://www.linkedin.com/company/comfyui',
|
||||
mcpSkills: 'https://github.com/Comfy-Org/comfy-skills',
|
||||
platform: 'https://platform.comfy.org',
|
||||
platformUsage: 'https://platform.comfy.org/profile/usage',
|
||||
reddit: 'https://www.reddit.com/r/comfyui/',
|
||||
support: 'https://support.comfy.org/hc/en-us',
|
||||
wikidataComfyOrg: 'https://www.wikidata.org/wiki/Q130598554',
|
||||
wikidataComfyUi: 'https://www.wikidata.org/wiki/Q127798647',
|
||||
wikipediaComfyUi: 'https://en.wikipedia.org/wiki/ComfyUI',
|
||||
workflows: 'https://comfy.org/workflows',
|
||||
x: 'https://x.com/ComfyUI',
|
||||
youtube: 'https://www.youtube.com/@ComfyOrg'
|
||||
|
||||
@@ -2190,6 +2190,13 @@ const translations = {
|
||||
'nav.ctaCloudPrefix': { en: 'LAUNCH', 'zh-CN': '启动' },
|
||||
'nav.ctaCloudCore': { en: 'CLOUD', 'zh-CN': '云端' },
|
||||
'nav.home': { en: 'Comfy home', 'zh-CN': 'Comfy 首页' },
|
||||
'breadcrumb.home': { en: 'Home', 'zh-CN': '首页' },
|
||||
'breadcrumb.about': { en: 'About Us', 'zh-CN': '关于我们' },
|
||||
'breadcrumb.contact': { en: 'Contact', 'zh-CN': '联系我们' },
|
||||
'breadcrumb.download': { en: 'Download', 'zh-CN': '下载' },
|
||||
'breadcrumb.careers': { en: 'Careers', 'zh-CN': '招聘' },
|
||||
'breadcrumb.pricing': { en: 'Pricing', 'zh-CN': '定价' },
|
||||
'breadcrumb.supportedNodes': { en: 'Supported Nodes', 'zh-CN': '支持的节点' },
|
||||
'nav.menu': { en: 'Menu', 'zh-CN': '菜单' },
|
||||
'nav.toggleMenu': { en: 'Toggle menu', 'zh-CN': '切换菜单' },
|
||||
'nav.close': { en: 'Close', 'zh-CN': '关闭' },
|
||||
@@ -4061,7 +4068,6 @@ const translations = {
|
||||
en: 'This page is being redesigned. Check back soon.',
|
||||
'zh-CN': '此页面正在重新设计中,请稍后再来。'
|
||||
},
|
||||
'demos.breadcrumb.home': { en: 'Home', 'zh-CN': '首页' },
|
||||
'demos.breadcrumb.demos': { en: 'Demos', 'zh-CN': '演示' },
|
||||
|
||||
'customers.story.whatsNext': {
|
||||
@@ -4157,10 +4163,6 @@ const translations = {
|
||||
en: "Run the world's leading AI models in ComfyUI",
|
||||
'zh-CN': '在 ComfyUI 中运行世界领先的 AI 模型'
|
||||
},
|
||||
'models.breadcrumb.home': {
|
||||
en: 'Home',
|
||||
'zh-CN': '首页'
|
||||
},
|
||||
'models.breadcrumb.models': {
|
||||
en: 'Supported Models',
|
||||
'zh-CN': '支持的模型'
|
||||
|
||||
@@ -14,8 +14,10 @@ import {
|
||||
createBannerVersion,
|
||||
evaluateBannerVisibility
|
||||
} from '../utils/banner'
|
||||
import { escapeJsonLd } from '../utils/escapeJsonLd'
|
||||
import { fetchGitHubStars, formatStarCount } from '../utils/github'
|
||||
import { buildPageGraph, pageContext } from '../utils/jsonLd'
|
||||
import type { Crumb, JsonLdNode, WebPageType } from '../utils/jsonLd'
|
||||
import JsonLdGraph from '../components/common/JsonLdGraph.astro'
|
||||
|
||||
interface Props {
|
||||
title: string
|
||||
@@ -23,6 +25,10 @@ interface Props {
|
||||
keywords?: string[]
|
||||
ogImage?: string
|
||||
noindex?: boolean
|
||||
pageType?: WebPageType
|
||||
breadcrumbs?: Crumb[]
|
||||
mainEntityId?: string
|
||||
extraJsonLd?: (JsonLdNode | null | undefined)[]
|
||||
}
|
||||
|
||||
const {
|
||||
@@ -31,15 +37,21 @@ const {
|
||||
keywords,
|
||||
ogImage = 'https://media.comfy.org/website/comfy.webp',
|
||||
noindex = false,
|
||||
pageType,
|
||||
breadcrumbs,
|
||||
mainEntityId,
|
||||
extraJsonLd,
|
||||
} = Astro.props
|
||||
|
||||
const keywordsContent = keywords && keywords.length > 0 ? keywords.join(', ') : undefined
|
||||
|
||||
const siteBase = Astro.site ?? 'https://comfy.org'
|
||||
const canonicalURL = new URL(Astro.url.pathname, siteBase)
|
||||
const ogImageURL = new URL(ogImage, siteBase)
|
||||
const rawLocale = Astro.currentLocale ?? 'en'
|
||||
const locale: Locale = rawLocale === 'zh-CN' ? 'zh-CN' : 'en'
|
||||
const { siteUrl, locale, url } = pageContext(
|
||||
Astro.site,
|
||||
Astro.url.pathname,
|
||||
Astro.currentLocale,
|
||||
)
|
||||
const canonicalURL = new URL(url)
|
||||
const ogImageURL = new URL(ogImage, Astro.site ?? 'https://comfy.org')
|
||||
const rawStars = await fetchGitHubStars('Comfy-Org', 'ComfyUI')
|
||||
const githubStars = rawStars ? formatStarCount(rawStars) : ''
|
||||
|
||||
@@ -58,28 +70,21 @@ const bannerVersion = createBannerVersion(bannerData, locale)
|
||||
const gtmId = 'GTM-NP9JM6K7'
|
||||
const gtmEnabled = import.meta.env.PROD
|
||||
|
||||
const organizationJsonLd = {
|
||||
'@context': 'https://schema.org',
|
||||
'@type': 'Organization',
|
||||
name: 'Comfy Org',
|
||||
url: 'https://comfy.org',
|
||||
logo: 'https://comfy.org/icons/logomark.svg',
|
||||
sameAs: [
|
||||
'https://github.com/comfyanonymous/ComfyUI',
|
||||
'https://discord.gg/comfyorg',
|
||||
'https://x.com/comaboratory',
|
||||
'https://reddit.com/r/comfyui',
|
||||
'https://linkedin.com/company/comfyorg',
|
||||
'https://instagram.com/comfyorg',
|
||||
],
|
||||
}
|
||||
|
||||
const websiteJsonLd = {
|
||||
'@context': 'https://schema.org',
|
||||
'@type': 'WebSite',
|
||||
name: 'Comfy',
|
||||
url: 'https://comfy.org',
|
||||
}
|
||||
const structuredData = noindex
|
||||
? undefined
|
||||
: buildPageGraph(
|
||||
{ siteUrl, locale },
|
||||
{
|
||||
url,
|
||||
name: title,
|
||||
description,
|
||||
imageUrl: ogImageURL.href,
|
||||
type: pageType,
|
||||
crumbs: breadcrumbs,
|
||||
mainEntityId,
|
||||
},
|
||||
...(extraJsonLd ?? []),
|
||||
)
|
||||
---
|
||||
|
||||
<!doctype html>
|
||||
@@ -121,10 +126,7 @@ const websiteJsonLd = {
|
||||
<meta name="twitter:image" content={ogImageURL.href} />
|
||||
|
||||
<!-- Structured Data -->
|
||||
<script is:inline type="application/ld+json" set:html={escapeJsonLd(organizationJsonLd)} />
|
||||
<script is:inline type="application/ld+json" set:html={escapeJsonLd(websiteJsonLd)} />
|
||||
<slot name="head" />
|
||||
|
||||
{structuredData && <JsonLdGraph graph={structuredData} />}
|
||||
<slot name="head" />
|
||||
|
||||
<!-- Google Tag Manager -->
|
||||
@@ -144,7 +146,6 @@ const websiteJsonLd = {
|
||||
)}
|
||||
|
||||
<ClientRouter />
|
||||
<slot name="head" />
|
||||
|
||||
<!-- Hide an already-dismissed announcement banner before first paint (no flash/shift). -->
|
||||
{bannerVisible && (
|
||||
|
||||
@@ -5,9 +5,25 @@ import StorySection from '../components/about/StorySection.vue'
|
||||
import OurValuesSection from '../components/about/OurValuesSection.vue'
|
||||
import ValuesSection from '../components/about/ValuesSection.vue'
|
||||
import CareersSection from '../components/about/CareersSection.vue'
|
||||
import { t } from '../i18n/translations'
|
||||
import { absoluteUrl, organizationId, pageContext } from '../utils/jsonLd'
|
||||
|
||||
const { siteUrl, locale } = pageContext(
|
||||
Astro.site,
|
||||
Astro.url.pathname,
|
||||
Astro.currentLocale,
|
||||
)
|
||||
---
|
||||
|
||||
<BaseLayout title="About Us — Comfy">
|
||||
<BaseLayout
|
||||
title="About Us — Comfy"
|
||||
pageType="AboutPage"
|
||||
mainEntityId={organizationId(siteUrl)}
|
||||
breadcrumbs={[
|
||||
{ name: t('breadcrumb.home', locale), url: absoluteUrl(Astro.site, '/') },
|
||||
{ name: t('breadcrumb.about', locale) },
|
||||
]}
|
||||
>
|
||||
<HeroSection client:load />
|
||||
<StorySection />
|
||||
<OurValuesSection />
|
||||
|
||||
@@ -9,34 +9,36 @@ import HeroSection from '../../templates/affiliate/HeroSection.vue'
|
||||
import HowItWorksSection from '../../templates/affiliate/HowItWorksSection.vue'
|
||||
import { affiliateFaqs } from '../../data/affiliateFaq'
|
||||
import { t } from '../../i18n/translations'
|
||||
import type { JsonLdNode } from '../../utils/jsonLd'
|
||||
import { absoluteUrl, jsonLdId, pageContext } from '../../utils/jsonLd'
|
||||
|
||||
const locale = 'en' as const
|
||||
|
||||
const faqJsonLd = {
|
||||
'@context': 'https://schema.org',
|
||||
const pageTitle = t('affiliate.page.title', 'en')
|
||||
const pageDescription = t('affiliate.page.description', 'en')
|
||||
const { locale, url } = pageContext(
|
||||
Astro.site,
|
||||
Astro.url.pathname,
|
||||
Astro.currentLocale,
|
||||
)
|
||||
const faqPage: JsonLdNode = {
|
||||
'@type': 'FAQPage',
|
||||
'@id': jsonLdId(url, 'faq'),
|
||||
mainEntity: affiliateFaqs.map((faq) => ({
|
||||
'@type': 'Question',
|
||||
name: faq.question[locale],
|
||||
acceptedAnswer: {
|
||||
'@type': 'Answer',
|
||||
text: faq.answer[locale]
|
||||
}
|
||||
}))
|
||||
acceptedAnswer: { '@type': 'Answer', text: faq.answer[locale] },
|
||||
})),
|
||||
}
|
||||
---
|
||||
|
||||
<BaseLayout
|
||||
title={t('affiliate.page.title', locale)}
|
||||
description={t('affiliate.page.description', locale)}
|
||||
title={pageTitle}
|
||||
description={pageDescription}
|
||||
breadcrumbs={[
|
||||
{ name: t('breadcrumb.home', locale), url: absoluteUrl(Astro.site, '/') },
|
||||
{ name: pageTitle },
|
||||
]}
|
||||
extraJsonLd={[faqPage]}
|
||||
>
|
||||
<Fragment slot="head">
|
||||
<script
|
||||
is:inline
|
||||
type="application/ld+json"
|
||||
set:html={JSON.stringify(faqJsonLd)}
|
||||
/>
|
||||
</Fragment>
|
||||
|
||||
<HeroSection />
|
||||
<HowItWorksSection />
|
||||
|
||||
@@ -7,6 +7,13 @@ import TeamPhotosSection from '../components/careers/TeamPhotosSection.vue'
|
||||
import FAQSection from '../components/common/FAQSection.vue'
|
||||
import { fetchRolesForBuild } from '../utils/ashby'
|
||||
import { reportAshbyOutcome } from '../utils/ashby.ci'
|
||||
import { t } from '../i18n/translations'
|
||||
import {
|
||||
absoluteUrl,
|
||||
itemListNode,
|
||||
jsonLdId,
|
||||
pageContext,
|
||||
} from '../utils/jsonLd'
|
||||
|
||||
const outcome = await fetchRolesForBuild()
|
||||
reportAshbyOutcome(outcome)
|
||||
@@ -19,11 +26,31 @@ if (outcome.status === 'failed') {
|
||||
}
|
||||
|
||||
const departments = outcome.snapshot.departments
|
||||
|
||||
const { siteUrl, locale, url } = pageContext(
|
||||
Astro.site,
|
||||
Astro.url.pathname,
|
||||
Astro.currentLocale,
|
||||
)
|
||||
const roles = itemListNode(
|
||||
url,
|
||||
t('breadcrumb.careers', locale),
|
||||
departments.flatMap((department) =>
|
||||
department.roles.map((role) => ({ name: role.title, url: role.jobUrl })),
|
||||
),
|
||||
)
|
||||
---
|
||||
|
||||
<BaseLayout
|
||||
title="Careers — Comfy"
|
||||
description="Join the team building the operating system for generative AI. Open roles in engineering, design, marketing, and more."
|
||||
pageType="CollectionPage"
|
||||
mainEntityId={jsonLdId(url, 'itemlist')}
|
||||
breadcrumbs={[
|
||||
{ name: t('breadcrumb.home', locale), url: absoluteUrl(Astro.site, '/') },
|
||||
{ name: t('breadcrumb.careers', locale) },
|
||||
]}
|
||||
extraJsonLd={[roles]}
|
||||
>
|
||||
<HeroSection />
|
||||
<RolesSection departments={departments} client:visible />
|
||||
|
||||
@@ -2,9 +2,41 @@
|
||||
import BaseLayout from '../../layouts/BaseLayout.astro'
|
||||
import PriceSection from '../../components/pricing/PriceSection.vue'
|
||||
import WhatsIncludedSection from '../../components/pricing/WhatsIncludedSection.vue'
|
||||
import { pricingOffers } from '../../config/pricing'
|
||||
import { t } from '../../i18n/translations'
|
||||
import {
|
||||
absoluteUrl,
|
||||
jsonLdId,
|
||||
pageContext,
|
||||
productNode,
|
||||
} from '../../utils/jsonLd'
|
||||
|
||||
const { siteUrl, locale, url } = pageContext(
|
||||
Astro.site,
|
||||
Astro.url.pathname,
|
||||
Astro.currentLocale,
|
||||
)
|
||||
const productId = jsonLdId(url, 'product')
|
||||
---
|
||||
|
||||
<BaseLayout title="Pricing — Comfy Cloud">
|
||||
<BaseLayout
|
||||
title="Pricing — Comfy Cloud"
|
||||
mainEntityId={productId}
|
||||
breadcrumbs={[
|
||||
{ name: t('breadcrumb.home', locale), url: absoluteUrl(Astro.site, '/') },
|
||||
{ name: 'Comfy Cloud', url: absoluteUrl(Astro.site, '/cloud') },
|
||||
{ name: t('breadcrumb.pricing', locale) },
|
||||
]}
|
||||
extraJsonLd={[
|
||||
productNode({
|
||||
siteUrl,
|
||||
id: productId,
|
||||
name: 'Comfy Cloud',
|
||||
url,
|
||||
offers: pricingOffers(locale),
|
||||
}),
|
||||
]}
|
||||
>
|
||||
<PriceSection client:load />
|
||||
<WhatsIncludedSection />
|
||||
</BaseLayout>
|
||||
|
||||
@@ -4,39 +4,44 @@ import HeroSection from '../../components/cloud-nodes/HeroSection.vue'
|
||||
import PackGridSection from '../../components/cloud-nodes/PackGridSection.vue'
|
||||
import { t } from '../../i18n/translations'
|
||||
import { loadPacksForBuild } from '../../utils/cloudNodes.build'
|
||||
import { escapeJsonLd } from '../../utils/escapeJsonLd'
|
||||
import {
|
||||
absoluteUrl,
|
||||
itemListNode,
|
||||
jsonLdId,
|
||||
pageContext,
|
||||
} from '../../utils/jsonLd'
|
||||
|
||||
const packs = await loadPacksForBuild()
|
||||
|
||||
const siteBase = Astro.site ?? new URL('https://comfy.org')
|
||||
const pageUrl = new URL('/cloud/supported-nodes', siteBase).href
|
||||
|
||||
const itemListJsonLd = {
|
||||
'@context': 'https://schema.org',
|
||||
'@type': 'ItemList',
|
||||
name: 'Custom-node packs supported on Comfy Cloud',
|
||||
url: pageUrl,
|
||||
numberOfItems: packs.length,
|
||||
itemListElement: packs.map((pack, index) => ({
|
||||
'@type': 'ListItem',
|
||||
position: index + 1,
|
||||
url: new URL(`/cloud/supported-nodes/${pack.id}`, siteBase).href,
|
||||
const title = t('cloudNodes.meta.title', 'en')
|
||||
const description = t('cloudNodes.meta.description', 'en')
|
||||
const { url, locale } = pageContext(
|
||||
Astro.site,
|
||||
Astro.url.pathname,
|
||||
Astro.currentLocale,
|
||||
)
|
||||
const packList = itemListNode(
|
||||
url,
|
||||
title,
|
||||
packs.map((pack) => ({
|
||||
name: pack.displayName,
|
||||
image: pack.bannerUrl || pack.iconUrl
|
||||
}))
|
||||
}
|
||||
url: absoluteUrl(Astro.site, `/cloud/supported-nodes/${pack.id}`),
|
||||
})),
|
||||
)
|
||||
---
|
||||
|
||||
<BaseLayout
|
||||
title={t('cloudNodes.meta.title', 'en')}
|
||||
description={t('cloudNodes.meta.description', 'en')}
|
||||
title={title}
|
||||
description={description}
|
||||
pageType="CollectionPage"
|
||||
mainEntityId={jsonLdId(url, 'itemlist')}
|
||||
breadcrumbs={[
|
||||
{ name: t('breadcrumb.home', locale), url: absoluteUrl(Astro.site, '/') },
|
||||
{ name: 'Comfy Cloud', url: absoluteUrl(Astro.site, '/cloud') },
|
||||
{ name: t('breadcrumb.supportedNodes', locale) },
|
||||
]}
|
||||
extraJsonLd={[packList]}
|
||||
>
|
||||
<script
|
||||
is:inline
|
||||
slot="head"
|
||||
type="application/ld+json"
|
||||
set:html={escapeJsonLd(itemListJsonLd)}
|
||||
/>
|
||||
<HeroSection client:visible />
|
||||
<PackGridSection packs={packs} client:visible />
|
||||
</BaseLayout>
|
||||
|
||||
@@ -7,7 +7,12 @@ import PackDetail from '../../../components/cloud-nodes/PackDetail.vue'
|
||||
import BaseLayout from '../../../layouts/BaseLayout.astro'
|
||||
import { t } from '../../../i18n/translations'
|
||||
import { loadPacksForBuild } from '../../../utils/cloudNodes.build'
|
||||
import { escapeJsonLd } from '../../../utils/escapeJsonLd'
|
||||
import {
|
||||
absoluteUrl,
|
||||
jsonLdId,
|
||||
pageContext,
|
||||
softwareApplicationNode,
|
||||
} from '../../../utils/jsonLd'
|
||||
|
||||
export const getStaticPaths: GetStaticPaths = async () => {
|
||||
const packs = await loadPacksForBuild()
|
||||
@@ -29,35 +34,45 @@ const metaDescription = t('cloudNodes.detail.metaDescription', 'en')
|
||||
.replace('{nodeCount}', String(pack.nodes.length))
|
||||
.replace('{description}', description)
|
||||
|
||||
const siteBase = Astro.site ?? new URL('https://comfy.org')
|
||||
const pageUrl = new URL(`/cloud/supported-nodes/${pack.id}`, siteBase).href
|
||||
|
||||
const softwareJsonLd = {
|
||||
'@context': 'https://schema.org',
|
||||
'@type': 'SoftwareApplication',
|
||||
const { siteUrl, locale, url } = pageContext(
|
||||
Astro.site,
|
||||
Astro.url.pathname,
|
||||
Astro.currentLocale,
|
||||
)
|
||||
const softwareId = jsonLdId(url, 'software')
|
||||
const software = softwareApplicationNode({
|
||||
siteUrl,
|
||||
id: softwareId,
|
||||
name: pack.displayName,
|
||||
url,
|
||||
applicationCategory: 'DeveloperApplication',
|
||||
applicationSubCategory: 'ComfyUI custom-node pack',
|
||||
operatingSystem: 'Comfy Cloud (managed)',
|
||||
url: pageUrl,
|
||||
description,
|
||||
description: pack.description || undefined,
|
||||
image: pack.bannerUrl || pack.iconUrl,
|
||||
softwareVersion: pack.latestVersion,
|
||||
license: pack.license,
|
||||
codeRepository: pack.repoUrl,
|
||||
author: pack.publisher?.name
|
||||
? { '@type': 'Person', name: pack.publisher.name }
|
||||
: undefined,
|
||||
offers: { '@type': 'Offer', price: 0, priceCurrency: 'USD' }
|
||||
}
|
||||
authorName: pack.publisher?.name,
|
||||
isFree: true,
|
||||
})
|
||||
---
|
||||
|
||||
<BaseLayout title={title} description={metaDescription} ogImage={pack.bannerUrl}>
|
||||
<script
|
||||
is:inline
|
||||
slot="head"
|
||||
type="application/ld+json"
|
||||
set:html={escapeJsonLd(softwareJsonLd)}
|
||||
/>
|
||||
<BaseLayout
|
||||
title={title}
|
||||
description={metaDescription}
|
||||
ogImage={pack.bannerUrl}
|
||||
mainEntityId={softwareId}
|
||||
breadcrumbs={[
|
||||
{ name: t('breadcrumb.home', locale), url: absoluteUrl(Astro.site, '/') },
|
||||
{ name: 'Comfy Cloud', url: absoluteUrl(Astro.site, '/cloud') },
|
||||
{
|
||||
name: t('breadcrumb.supportedNodes', locale),
|
||||
url: absoluteUrl(Astro.site, '/cloud/supported-nodes'),
|
||||
},
|
||||
{ name: pack.displayName },
|
||||
]}
|
||||
extraJsonLd={[software]}
|
||||
>
|
||||
<PackDetail pack={pack} />
|
||||
</BaseLayout>
|
||||
|
||||
@@ -2,9 +2,25 @@
|
||||
import BaseLayout from '../layouts/BaseLayout.astro'
|
||||
import FormSection from '../components/contact/FormSection.vue'
|
||||
import SocialProofBarSection from '../components/common/SocialProofBarSection.vue'
|
||||
import { t } from '../i18n/translations'
|
||||
import { absoluteUrl, organizationId, pageContext } from '../utils/jsonLd'
|
||||
|
||||
const { siteUrl, locale } = pageContext(
|
||||
Astro.site,
|
||||
Astro.url.pathname,
|
||||
Astro.currentLocale,
|
||||
)
|
||||
---
|
||||
|
||||
<BaseLayout title="Contact — Comfy">
|
||||
<BaseLayout
|
||||
title="Contact — Comfy"
|
||||
pageType="ContactPage"
|
||||
mainEntityId={organizationId(siteUrl)}
|
||||
breadcrumbs={[
|
||||
{ name: t('breadcrumb.home', locale), url: absoluteUrl(Astro.site, '/') },
|
||||
{ name: t('breadcrumb.contact', locale) },
|
||||
]}
|
||||
>
|
||||
<FormSection client:load />
|
||||
<SocialProofBarSection />
|
||||
</BaseLayout>
|
||||
|
||||
@@ -7,6 +7,13 @@ import DemoTranscript from '../../components/demos/DemoTranscript.vue'
|
||||
import DemoNavSection from '../../components/demos/DemoNavSection.vue'
|
||||
import { demos, getDemoBySlug, getNextDemo } from '../../config/demos'
|
||||
import { t } from '../../i18n/translations'
|
||||
import type { JsonLdNode } from '../../utils/jsonLd'
|
||||
import {
|
||||
absoluteUrl,
|
||||
jsonLdId,
|
||||
organizationId,
|
||||
pageContext,
|
||||
} from '../../utils/jsonLd'
|
||||
|
||||
export const getStaticPaths: GetStaticPaths = () => {
|
||||
return demos.map((demo) => ({
|
||||
@@ -19,68 +26,34 @@ const demo = getDemoBySlug(slug as string)!
|
||||
const nextDemo = getNextDemo(slug as string)
|
||||
const title = t(demo.title)
|
||||
const description = t(demo.description)
|
||||
const canonicalURL = new URL(`/demos/${demo.slug}`, Astro.site)
|
||||
|
||||
const howToJsonLd = {
|
||||
'@context': 'https://schema.org',
|
||||
'@type': 'HowTo',
|
||||
name: title,
|
||||
description,
|
||||
image: new URL(demo.ogImage, Astro.site).href,
|
||||
totalTime: demo.durationIso,
|
||||
datePublished: demo.publishedDate,
|
||||
dateModified: demo.modifiedDate,
|
||||
author: {
|
||||
'@type': 'Organization',
|
||||
name: 'Comfy Org',
|
||||
url: 'https://comfy.org'
|
||||
}
|
||||
}
|
||||
|
||||
const learningResourceJsonLd = {
|
||||
'@context': 'https://schema.org',
|
||||
'@type': 'LearningResource',
|
||||
name: title,
|
||||
description,
|
||||
learningResourceType: 'interactive tutorial',
|
||||
interactivityType: 'active',
|
||||
educationalLevel: demo.difficulty === 'beginner'
|
||||
const { siteUrl, locale, url } = pageContext(
|
||||
Astro.site,
|
||||
Astro.url.pathname,
|
||||
Astro.currentLocale,
|
||||
)
|
||||
const educationalLevel =
|
||||
demo.difficulty === 'beginner'
|
||||
? 'Beginner'
|
||||
: demo.difficulty === 'intermediate'
|
||||
? 'Intermediate'
|
||||
: 'Advanced',
|
||||
url: canonicalURL.href,
|
||||
: 'Advanced'
|
||||
const learningId = jsonLdId(url, 'learning')
|
||||
const learningResource: JsonLdNode = {
|
||||
'@type': 'LearningResource',
|
||||
'@id': learningId,
|
||||
name: title,
|
||||
description,
|
||||
url,
|
||||
image: new URL(demo.ogImage, Astro.site).href,
|
||||
learningResourceType: 'interactive tutorial',
|
||||
interactivityType: 'active',
|
||||
educationalLevel,
|
||||
timeRequired: demo.durationIso,
|
||||
datePublished: demo.publishedDate,
|
||||
dateModified: demo.modifiedDate,
|
||||
author: {
|
||||
'@type': 'Organization',
|
||||
name: 'Comfy Org',
|
||||
url: 'https://comfy.org'
|
||||
}
|
||||
}
|
||||
|
||||
const breadcrumbJsonLd = {
|
||||
'@context': 'https://schema.org',
|
||||
'@type': 'BreadcrumbList',
|
||||
itemListElement: [
|
||||
{
|
||||
'@type': 'ListItem',
|
||||
position: 1,
|
||||
name: t('demos.breadcrumb.home'),
|
||||
item: 'https://comfy.org'
|
||||
},
|
||||
{
|
||||
'@type': 'ListItem',
|
||||
position: 2,
|
||||
name: t('demos.breadcrumb.demos'),
|
||||
item: 'https://comfy.org/demos'
|
||||
},
|
||||
{
|
||||
'@type': 'ListItem',
|
||||
position: 3,
|
||||
name: title
|
||||
}
|
||||
]
|
||||
isPartOf: { '@id': jsonLdId(url, 'webpage') },
|
||||
author: { '@id': organizationId(siteUrl) },
|
||||
}
|
||||
---
|
||||
|
||||
@@ -88,25 +61,20 @@ const breadcrumbJsonLd = {
|
||||
title={`${title} — Comfy`}
|
||||
description={description}
|
||||
ogImage={demo.ogImage}
|
||||
mainEntityId={learningId}
|
||||
breadcrumbs={[
|
||||
{ name: t('breadcrumb.home', locale), url: absoluteUrl(Astro.site, '/') },
|
||||
{
|
||||
name: t('demos.breadcrumb.demos', locale),
|
||||
url: absoluteUrl(Astro.site, '/demos'),
|
||||
},
|
||||
{ name: title },
|
||||
]}
|
||||
extraJsonLd={[learningResource]}
|
||||
>
|
||||
<Fragment slot="head">
|
||||
<meta property="article:published_time" content={demo.publishedDate} />
|
||||
<meta property="article:modified_time" content={demo.modifiedDate} />
|
||||
<script
|
||||
is:inline
|
||||
type="application/ld+json"
|
||||
set:html={JSON.stringify(howToJsonLd)}
|
||||
/>
|
||||
<script
|
||||
is:inline
|
||||
type="application/ld+json"
|
||||
set:html={JSON.stringify(learningResourceJsonLd)}
|
||||
/>
|
||||
<script
|
||||
is:inline
|
||||
type="application/ld+json"
|
||||
set:html={JSON.stringify(breadcrumbJsonLd)}
|
||||
/>
|
||||
<link rel="preconnect" href="https://demo.arcade.software" />
|
||||
</Fragment>
|
||||
|
||||
|
||||
@@ -8,11 +8,29 @@ import EcoSystemSection from '../components/product/local/EcoSystemSection.vue'
|
||||
import ProductCardsSection from '../components/product/local/ProductCardsSection.vue'
|
||||
import FAQSection from '../components/product/local/FAQSection.vue'
|
||||
import { t } from '../i18n/translations'
|
||||
import {
|
||||
absoluteUrl,
|
||||
comfyUiApplicationNode,
|
||||
comfyUiSoftwareId,
|
||||
pageContext,
|
||||
} from '../utils/jsonLd'
|
||||
|
||||
const { siteUrl, locale } = pageContext(
|
||||
Astro.site,
|
||||
Astro.url.pathname,
|
||||
Astro.currentLocale,
|
||||
)
|
||||
---
|
||||
|
||||
<BaseLayout
|
||||
title="Download Comfy Desktop — Run AI on Your Hardware"
|
||||
description={t('download.hero.subtitle', 'en')}
|
||||
mainEntityId={comfyUiSoftwareId(siteUrl)}
|
||||
breadcrumbs={[
|
||||
{ name: t('breadcrumb.home', locale), url: absoluteUrl(Astro.site, '/') },
|
||||
{ name: t('breadcrumb.download', locale) },
|
||||
]}
|
||||
extraJsonLd={[comfyUiApplicationNode(siteUrl)]}
|
||||
keywords={['comfyui app', 'comfyui desktop app', 'comfyui desktop', 'comfy ui application', 'comfyui download', 'download comfyui', 'comfyui windows', 'comfyui mac', 'comfyui linux']}
|
||||
>
|
||||
<CloudBannerSection />
|
||||
|
||||
@@ -9,11 +9,28 @@ import CaseStudySpotlightSection from "../components/home/CaseStudySpotlightSect
|
||||
import GetStartedSection from "../components/home/GetStartedSection.vue";
|
||||
import BuildWhatSection from "../components/home/BuildWhatSection.vue";
|
||||
import { t } from "../i18n/translations";
|
||||
import {
|
||||
comfyUiApplicationNode,
|
||||
comfyUiSoftwareId,
|
||||
comfyUiSourceCodeNode,
|
||||
pageContext,
|
||||
} from "../utils/jsonLd";
|
||||
|
||||
const { siteUrl } = pageContext(
|
||||
Astro.site,
|
||||
Astro.url.pathname,
|
||||
Astro.currentLocale,
|
||||
);
|
||||
---
|
||||
|
||||
<BaseLayout
|
||||
title="Comfy — Professional Control of Visual AI"
|
||||
description={t("hero.subtitle", "en")}
|
||||
mainEntityId={comfyUiSoftwareId(siteUrl)}
|
||||
extraJsonLd={[
|
||||
comfyUiApplicationNode(siteUrl),
|
||||
comfyUiSourceCodeNode(siteUrl),
|
||||
]}
|
||||
keywords={[
|
||||
"comfyui app",
|
||||
"comfyui web app",
|
||||
|
||||
@@ -4,6 +4,13 @@ import BaseLayout from '../../../layouts/BaseLayout.astro'
|
||||
import ModelHeroSection from '../../../components/models/ModelHeroSection.vue'
|
||||
import { models, getModelBySlug } from '../../../config/models'
|
||||
import { t } from '../../../i18n/translations'
|
||||
import type { JsonLdNode } from '../../../utils/jsonLd'
|
||||
import {
|
||||
absoluteUrl,
|
||||
jsonLdId,
|
||||
pageContext,
|
||||
softwareApplicationNode,
|
||||
} from '../../../utils/jsonLd'
|
||||
|
||||
export const getStaticPaths: GetStaticPaths = () => {
|
||||
return models.map((model) => ({
|
||||
@@ -19,7 +26,6 @@ if (model.canonicalSlug) {
|
||||
}
|
||||
|
||||
const { displayName } = model
|
||||
const canonicalURL = new URL(`/p/supported-models/${model.slug}`, Astro.site)
|
||||
|
||||
const dirDescriptions: Record<string, string> = {
|
||||
diffusion_models: 'a diffusion model that generates images or video from text and image prompts',
|
||||
@@ -40,55 +46,31 @@ const dirDescriptions: Record<string, string> = {
|
||||
const dirDesc = dirDescriptions[model.directory] ?? 'an AI model'
|
||||
const whatIsDescription = `${displayName} is ${dirDesc}. You can run it locally in ComfyUI with full control over every parameter, or access it through Comfy Cloud. ComfyUI's node-based workflow editor lets you connect ${displayName} with ControlNets, LoRAs, upscalers, and custom nodes to build any pipeline you need. There are ${model.workflowCount} community workflow templates using ${displayName} on Comfy Hub, ready to load and customize.`
|
||||
|
||||
const softwareAppJsonLd = {
|
||||
'@context': 'https://schema.org',
|
||||
'@type': 'SoftwareApplication',
|
||||
const pageTitle = `${displayName} in ComfyUI`
|
||||
const pageDescription = `Run ${displayName} in ComfyUI with full parameter control. ${model.workflowCount} community workflow templates, step-by-step tutorials, and free local inference.`
|
||||
|
||||
const { siteUrl, locale, url } = pageContext(
|
||||
Astro.site,
|
||||
Astro.url.pathname,
|
||||
Astro.currentLocale,
|
||||
)
|
||||
const softwareId = jsonLdId(url, 'software')
|
||||
const software = softwareApplicationNode({
|
||||
siteUrl,
|
||||
id: softwareId,
|
||||
name: displayName,
|
||||
url,
|
||||
applicationCategory: 'MultimediaApplication',
|
||||
operatingSystem: 'Any',
|
||||
url: canonicalURL.href,
|
||||
author: {
|
||||
'@type': 'Organization',
|
||||
name: 'Comfy Org',
|
||||
url: 'https://comfy.org'
|
||||
}
|
||||
}
|
||||
|
||||
const breadcrumbJsonLd = {
|
||||
'@context': 'https://schema.org',
|
||||
'@type': 'BreadcrumbList',
|
||||
itemListElement: [
|
||||
{
|
||||
'@type': 'ListItem',
|
||||
position: 1,
|
||||
name: t('models.breadcrumb.home'),
|
||||
item: 'https://comfy.org'
|
||||
},
|
||||
{
|
||||
'@type': 'ListItem',
|
||||
position: 2,
|
||||
name: t('models.breadcrumb.models'),
|
||||
item: 'https://comfy.org/p/supported-models'
|
||||
},
|
||||
{
|
||||
'@type': 'ListItem',
|
||||
position: 3,
|
||||
name: displayName
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
const faqJsonLd = {
|
||||
'@context': 'https://schema.org',
|
||||
})
|
||||
const faqPage: JsonLdNode = {
|
||||
'@type': 'FAQPage',
|
||||
'@id': jsonLdId(url, 'faq'),
|
||||
mainEntity: [
|
||||
{
|
||||
'@type': 'Question',
|
||||
name: `What is ${displayName}?`,
|
||||
acceptedAnswer: {
|
||||
'@type': 'Answer',
|
||||
text: whatIsDescription
|
||||
}
|
||||
acceptedAnswer: { '@type': 'Answer', text: whatIsDescription },
|
||||
},
|
||||
{
|
||||
'@type': 'Question',
|
||||
@@ -97,54 +79,44 @@ const faqJsonLd = {
|
||||
'@type': 'Answer',
|
||||
text: model.docsUrl
|
||||
? `Follow the step-by-step tutorial at ${model.docsUrl}. You can also load any of the ${model.workflowCount} community workflow templates that use ${displayName} directly in ComfyUI.`
|
||||
: `Open ComfyUI and browse the ${model.workflowCount} community workflow templates that use ${displayName}. Load one as a starting point, then customize the nodes and parameters to fit your use case.`
|
||||
}
|
||||
: `Open ComfyUI and browse the ${model.workflowCount} community workflow templates that use ${displayName}. Load one as a starting point, then customize the nodes and parameters to fit your use case.`,
|
||||
},
|
||||
},
|
||||
{
|
||||
'@type': 'Question',
|
||||
name: `How many ComfyUI workflows use ${displayName}?`,
|
||||
acceptedAnswer: {
|
||||
'@type': 'Answer',
|
||||
text: `There are ${model.workflowCount} community workflow templates that use ${displayName} on Comfy Hub. Each template is ready to run in ComfyUI and can be customized to suit your project.`
|
||||
}
|
||||
text: `There are ${model.workflowCount} community workflow templates that use ${displayName} on Comfy Hub. Each template is ready to run in ComfyUI and can be customized to suit your project.`,
|
||||
},
|
||||
},
|
||||
{
|
||||
'@type': 'Question',
|
||||
name: `Is ${displayName} free to use in ComfyUI?`,
|
||||
acceptedAnswer: {
|
||||
'@type': 'Answer',
|
||||
text: `ComfyUI is free and open source. ${model.huggingFaceUrl ? `${displayName} weights are available to download from Hugging Face.` : `${displayName} is available as a cloud API through Comfy Cloud.`} You only pay for compute when running on Comfy Cloud; local inference on your own hardware is always free.`
|
||||
}
|
||||
}
|
||||
]
|
||||
text: `ComfyUI is free and open source. ${model.huggingFaceUrl ? `${displayName} weights are available to download from Hugging Face.` : `${displayName} is available as a cloud API through Comfy Cloud.`} You only pay for compute when running on Comfy Cloud; local inference on your own hardware is always free.`,
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
const pageTitle = `${displayName} in ComfyUI`
|
||||
const pageDescription = `Run ${displayName} in ComfyUI with full parameter control. ${model.workflowCount} community workflow templates, step-by-step tutorials, and free local inference.`
|
||||
---
|
||||
|
||||
<BaseLayout
|
||||
title={`${pageTitle} — Comfy`}
|
||||
description={pageDescription}
|
||||
ogImage={model.thumbnailUrl}
|
||||
mainEntityId={softwareId}
|
||||
breadcrumbs={[
|
||||
{ name: t('breadcrumb.home', locale), url: absoluteUrl(Astro.site, '/') },
|
||||
{
|
||||
name: t('models.breadcrumb.models', locale),
|
||||
url: absoluteUrl(Astro.site, '/p/supported-models'),
|
||||
},
|
||||
{ name: displayName },
|
||||
]}
|
||||
extraJsonLd={[software, faqPage]}
|
||||
>
|
||||
<Fragment slot="head">
|
||||
<script
|
||||
is:inline
|
||||
type="application/ld+json"
|
||||
set:html={JSON.stringify(softwareAppJsonLd)}
|
||||
/>
|
||||
<script
|
||||
is:inline
|
||||
type="application/ld+json"
|
||||
set:html={JSON.stringify(breadcrumbJsonLd)}
|
||||
/>
|
||||
<script
|
||||
is:inline
|
||||
type="application/ld+json"
|
||||
set:html={JSON.stringify(faqJsonLd)}
|
||||
/>
|
||||
</Fragment>
|
||||
|
||||
<ModelHeroSection
|
||||
displayName={displayName}
|
||||
|
||||
@@ -2,10 +2,29 @@
|
||||
import BaseLayout from '../../../layouts/BaseLayout.astro'
|
||||
import { models } from '../../../config/models'
|
||||
import { t } from '../../../i18n/translations'
|
||||
import {
|
||||
absoluteUrl,
|
||||
itemListNode,
|
||||
jsonLdId,
|
||||
pageContext,
|
||||
} from '../../../utils/jsonLd'
|
||||
|
||||
const title = t('models.index.title')
|
||||
const subtitle = t('models.index.subtitle')
|
||||
|
||||
const { url, locale } = pageContext(
|
||||
Astro.site,
|
||||
Astro.url.pathname,
|
||||
Astro.currentLocale,
|
||||
)
|
||||
const modelList = itemListNode(
|
||||
url,
|
||||
title,
|
||||
models.map((model) => ({
|
||||
url: absoluteUrl(Astro.site, `/p/supported-models/${model.slug}`),
|
||||
})),
|
||||
)
|
||||
|
||||
const dirLabel: Record<string, string> = {
|
||||
diffusion_models: 'Diffusion',
|
||||
checkpoints: 'Checkpoint',
|
||||
@@ -26,6 +45,13 @@ const dirLabel: Record<string, string> = {
|
||||
<BaseLayout
|
||||
title={`${title} — Comfy`}
|
||||
description={subtitle}
|
||||
pageType="CollectionPage"
|
||||
mainEntityId={jsonLdId(url, 'itemlist')}
|
||||
breadcrumbs={[
|
||||
{ name: t('breadcrumb.home', locale), url: absoluteUrl(Astro.site, '/') },
|
||||
{ name: title },
|
||||
]}
|
||||
extraJsonLd={[modelList]}
|
||||
>
|
||||
<div class="mx-auto max-w-7xl px-6 py-16 lg:px-8 lg:py-24">
|
||||
<header class="mb-12">
|
||||
|
||||
@@ -5,9 +5,29 @@ import StorySection from '../../components/about/StorySection.vue'
|
||||
import OurValuesSection from '../../components/about/OurValuesSection.vue'
|
||||
import ValuesSection from '../../components/about/ValuesSection.vue'
|
||||
import CareersSection from '../../components/about/CareersSection.vue'
|
||||
import { t } from '../../i18n/translations'
|
||||
import { absoluteUrl, organizationId, pageContext } from '../../utils/jsonLd'
|
||||
|
||||
const { siteUrl, locale } = pageContext(
|
||||
Astro.site,
|
||||
Astro.url.pathname,
|
||||
Astro.currentLocale,
|
||||
)
|
||||
---
|
||||
|
||||
<BaseLayout title="关于我们 — Comfy" description="了解 ComfyUI 背后的团队和使命——开源的生成式 AI 平台。">
|
||||
<BaseLayout
|
||||
title="关于我们 — Comfy"
|
||||
description="了解 ComfyUI 背后的团队和使命——开源的生成式 AI 平台。"
|
||||
pageType="AboutPage"
|
||||
mainEntityId={organizationId(siteUrl)}
|
||||
breadcrumbs={[
|
||||
{
|
||||
name: t('breadcrumb.home', locale),
|
||||
url: absoluteUrl(Astro.site, '/zh-CN'),
|
||||
},
|
||||
{ name: t('breadcrumb.about', locale) },
|
||||
]}
|
||||
>
|
||||
<HeroSection locale="zh-CN" client:load />
|
||||
<StorySection locale="zh-CN" />
|
||||
<OurValuesSection locale="zh-CN" />
|
||||
|
||||
@@ -7,6 +7,13 @@ import TeamPhotosSection from '../../components/careers/TeamPhotosSection.vue'
|
||||
import FAQSection from '../../components/common/FAQSection.vue'
|
||||
import { fetchRolesForBuild } from '../../utils/ashby'
|
||||
import { reportAshbyOutcome } from '../../utils/ashby.ci'
|
||||
import { t } from '../../i18n/translations'
|
||||
import {
|
||||
absoluteUrl,
|
||||
itemListNode,
|
||||
jsonLdId,
|
||||
pageContext,
|
||||
} from '../../utils/jsonLd'
|
||||
|
||||
const outcome = await fetchRolesForBuild()
|
||||
reportAshbyOutcome(outcome)
|
||||
@@ -19,11 +26,34 @@ if (outcome.status === 'failed') {
|
||||
}
|
||||
|
||||
const departments = outcome.snapshot.departments
|
||||
|
||||
const { siteUrl, locale, url } = pageContext(
|
||||
Astro.site,
|
||||
Astro.url.pathname,
|
||||
Astro.currentLocale,
|
||||
)
|
||||
const roles = itemListNode(
|
||||
url,
|
||||
t('breadcrumb.careers', locale),
|
||||
departments.flatMap((department) =>
|
||||
department.roles.map((role) => ({ name: role.title, url: role.jobUrl })),
|
||||
),
|
||||
)
|
||||
---
|
||||
|
||||
<BaseLayout
|
||||
title="招聘 — Comfy"
|
||||
description="加入构建生成式 AI 操作系统的团队。工程、设计、市场营销等岗位开放招聘中。"
|
||||
pageType="CollectionPage"
|
||||
mainEntityId={jsonLdId(url, 'itemlist')}
|
||||
breadcrumbs={[
|
||||
{
|
||||
name: t('breadcrumb.home', locale),
|
||||
url: absoluteUrl(Astro.site, '/zh-CN'),
|
||||
},
|
||||
{ name: t('breadcrumb.careers', locale) },
|
||||
]}
|
||||
extraJsonLd={[roles]}
|
||||
>
|
||||
<HeroSection locale="zh-CN" />
|
||||
<RolesSection locale="zh-CN" departments={departments} client:visible />
|
||||
|
||||
@@ -2,9 +2,44 @@
|
||||
import BaseLayout from '../../../layouts/BaseLayout.astro'
|
||||
import PriceSection from '../../../components/pricing/PriceSection.vue'
|
||||
import WhatsIncludedSection from '../../../components/pricing/WhatsIncludedSection.vue'
|
||||
import { pricingOffers } from '../../../config/pricing'
|
||||
import { t } from '../../../i18n/translations'
|
||||
import {
|
||||
absoluteUrl,
|
||||
jsonLdId,
|
||||
pageContext,
|
||||
productNode,
|
||||
} from '../../../utils/jsonLd'
|
||||
|
||||
const { siteUrl, locale, url } = pageContext(
|
||||
Astro.site,
|
||||
Astro.url.pathname,
|
||||
Astro.currentLocale,
|
||||
)
|
||||
const productId = jsonLdId(url, 'product')
|
||||
---
|
||||
|
||||
<BaseLayout title="定价 — Comfy Cloud">
|
||||
<BaseLayout
|
||||
title="定价 — Comfy Cloud"
|
||||
mainEntityId={productId}
|
||||
breadcrumbs={[
|
||||
{
|
||||
name: t('breadcrumb.home', locale),
|
||||
url: absoluteUrl(Astro.site, '/zh-CN'),
|
||||
},
|
||||
{ name: 'Comfy Cloud', url: absoluteUrl(Astro.site, '/zh-CN/cloud') },
|
||||
{ name: t('breadcrumb.pricing', locale) },
|
||||
]}
|
||||
extraJsonLd={[
|
||||
productNode({
|
||||
siteUrl,
|
||||
id: productId,
|
||||
name: 'Comfy Cloud',
|
||||
url,
|
||||
offers: pricingOffers(locale),
|
||||
}),
|
||||
]}
|
||||
>
|
||||
<PriceSection locale="zh-CN" client:load />
|
||||
<WhatsIncludedSection locale="zh-CN" />
|
||||
</BaseLayout>
|
||||
|
||||
@@ -4,39 +4,47 @@ import HeroSection from '../../../components/cloud-nodes/HeroSection.vue'
|
||||
import PackGridSection from '../../../components/cloud-nodes/PackGridSection.vue'
|
||||
import { t } from '../../../i18n/translations'
|
||||
import { loadPacksForBuild } from '../../../utils/cloudNodes.build'
|
||||
import { escapeJsonLd } from '../../../utils/escapeJsonLd'
|
||||
import {
|
||||
absoluteUrl,
|
||||
itemListNode,
|
||||
jsonLdId,
|
||||
pageContext,
|
||||
} from '../../../utils/jsonLd'
|
||||
|
||||
const packs = await loadPacksForBuild()
|
||||
|
||||
const siteBase = Astro.site ?? new URL('https://comfy.org')
|
||||
const pageUrl = new URL('/zh-CN/cloud/supported-nodes', siteBase).href
|
||||
|
||||
const itemListJsonLd = {
|
||||
'@context': 'https://schema.org',
|
||||
'@type': 'ItemList',
|
||||
name: 'Comfy Cloud 支持的自定义节点包',
|
||||
url: pageUrl,
|
||||
numberOfItems: packs.length,
|
||||
itemListElement: packs.map((pack, index) => ({
|
||||
'@type': 'ListItem',
|
||||
position: index + 1,
|
||||
url: new URL(`/zh-CN/cloud/supported-nodes/${pack.id}`, siteBase).href,
|
||||
const title = t('cloudNodes.meta.title', 'zh-CN')
|
||||
const description = t('cloudNodes.meta.description', 'zh-CN')
|
||||
const { url, locale } = pageContext(
|
||||
Astro.site,
|
||||
Astro.url.pathname,
|
||||
Astro.currentLocale,
|
||||
)
|
||||
const packList = itemListNode(
|
||||
url,
|
||||
title,
|
||||
packs.map((pack) => ({
|
||||
name: pack.displayName,
|
||||
image: pack.bannerUrl || pack.iconUrl
|
||||
}))
|
||||
}
|
||||
url: absoluteUrl(Astro.site, `/zh-CN/cloud/supported-nodes/${pack.id}`),
|
||||
})),
|
||||
)
|
||||
---
|
||||
|
||||
<BaseLayout
|
||||
title={t('cloudNodes.meta.title', 'zh-CN')}
|
||||
description={t('cloudNodes.meta.description', 'zh-CN')}
|
||||
title={title}
|
||||
description={description}
|
||||
pageType="CollectionPage"
|
||||
mainEntityId={jsonLdId(url, 'itemlist')}
|
||||
breadcrumbs={[
|
||||
{
|
||||
name: t('breadcrumb.home', locale),
|
||||
url: absoluteUrl(Astro.site, '/zh-CN'),
|
||||
},
|
||||
{ name: 'Comfy Cloud', url: absoluteUrl(Astro.site, '/zh-CN/cloud') },
|
||||
{ name: t('breadcrumb.supportedNodes', locale) },
|
||||
]}
|
||||
extraJsonLd={[packList]}
|
||||
>
|
||||
<script
|
||||
is:inline
|
||||
slot="head"
|
||||
type="application/ld+json"
|
||||
set:html={escapeJsonLd(itemListJsonLd)}
|
||||
/>
|
||||
<HeroSection locale="zh-CN" client:visible />
|
||||
<PackGridSection locale="zh-CN" packs={packs} client:visible />
|
||||
</BaseLayout>
|
||||
|
||||
@@ -7,7 +7,12 @@ import PackDetail from '../../../../components/cloud-nodes/PackDetail.vue'
|
||||
import BaseLayout from '../../../../layouts/BaseLayout.astro'
|
||||
import { t } from '../../../../i18n/translations'
|
||||
import { loadPacksForBuild } from '../../../../utils/cloudNodes.build'
|
||||
import { escapeJsonLd } from '../../../../utils/escapeJsonLd'
|
||||
import {
|
||||
absoluteUrl,
|
||||
jsonLdId,
|
||||
pageContext,
|
||||
softwareApplicationNode,
|
||||
} from '../../../../utils/jsonLd'
|
||||
|
||||
export const getStaticPaths: GetStaticPaths = async () => {
|
||||
const packs = await loadPacksForBuild()
|
||||
@@ -29,35 +34,48 @@ const metaDescription = t('cloudNodes.detail.metaDescription', 'zh-CN')
|
||||
.replace('{nodeCount}', String(pack.nodes.length))
|
||||
.replace('{description}', description)
|
||||
|
||||
const siteBase = Astro.site ?? new URL('https://comfy.org')
|
||||
const pageUrl = new URL(`/zh-CN/cloud/supported-nodes/${pack.id}`, siteBase).href
|
||||
|
||||
const softwareJsonLd = {
|
||||
'@context': 'https://schema.org',
|
||||
'@type': 'SoftwareApplication',
|
||||
const { siteUrl, locale, url } = pageContext(
|
||||
Astro.site,
|
||||
Astro.url.pathname,
|
||||
Astro.currentLocale,
|
||||
)
|
||||
const softwareId = jsonLdId(url, 'software')
|
||||
const software = softwareApplicationNode({
|
||||
siteUrl,
|
||||
id: softwareId,
|
||||
name: pack.displayName,
|
||||
url,
|
||||
applicationCategory: 'DeveloperApplication',
|
||||
applicationSubCategory: 'ComfyUI custom-node pack',
|
||||
operatingSystem: 'Comfy Cloud (managed)',
|
||||
url: pageUrl,
|
||||
description,
|
||||
description: pack.description || undefined,
|
||||
image: pack.bannerUrl || pack.iconUrl,
|
||||
softwareVersion: pack.latestVersion,
|
||||
license: pack.license,
|
||||
codeRepository: pack.repoUrl,
|
||||
author: pack.publisher?.name
|
||||
? { '@type': 'Person', name: pack.publisher.name }
|
||||
: undefined,
|
||||
offers: { '@type': 'Offer', price: 0, priceCurrency: 'USD' }
|
||||
}
|
||||
authorName: pack.publisher?.name,
|
||||
isFree: true,
|
||||
})
|
||||
---
|
||||
|
||||
<BaseLayout title={title} description={metaDescription} ogImage={pack.bannerUrl}>
|
||||
<script
|
||||
is:inline
|
||||
slot="head"
|
||||
type="application/ld+json"
|
||||
set:html={escapeJsonLd(softwareJsonLd)}
|
||||
/>
|
||||
<BaseLayout
|
||||
title={title}
|
||||
description={metaDescription}
|
||||
ogImage={pack.bannerUrl}
|
||||
mainEntityId={softwareId}
|
||||
breadcrumbs={[
|
||||
{
|
||||
name: t('breadcrumb.home', locale),
|
||||
url: absoluteUrl(Astro.site, '/zh-CN'),
|
||||
},
|
||||
{ name: 'Comfy Cloud', url: absoluteUrl(Astro.site, '/zh-CN/cloud') },
|
||||
{
|
||||
name: t('breadcrumb.supportedNodes', locale),
|
||||
url: absoluteUrl(Astro.site, '/zh-CN/cloud/supported-nodes'),
|
||||
},
|
||||
{ name: pack.displayName },
|
||||
]}
|
||||
extraJsonLd={[software]}
|
||||
>
|
||||
<PackDetail pack={pack} locale="zh-CN" />
|
||||
</BaseLayout>
|
||||
|
||||
@@ -2,9 +2,28 @@
|
||||
import BaseLayout from '../../layouts/BaseLayout.astro'
|
||||
import FormSection from '../../components/contact/FormSection.vue'
|
||||
import SocialProofBarSection from '../../components/common/SocialProofBarSection.vue'
|
||||
import { t } from '../../i18n/translations'
|
||||
import { absoluteUrl, organizationId, pageContext } from '../../utils/jsonLd'
|
||||
|
||||
const { siteUrl, locale } = pageContext(
|
||||
Astro.site,
|
||||
Astro.url.pathname,
|
||||
Astro.currentLocale,
|
||||
)
|
||||
---
|
||||
|
||||
<BaseLayout title="联系我们 — Comfy">
|
||||
<BaseLayout
|
||||
title="联系我们 — Comfy"
|
||||
pageType="ContactPage"
|
||||
mainEntityId={organizationId(siteUrl)}
|
||||
breadcrumbs={[
|
||||
{
|
||||
name: t('breadcrumb.home', locale),
|
||||
url: absoluteUrl(Astro.site, '/zh-CN'),
|
||||
},
|
||||
{ name: t('breadcrumb.contact', locale) },
|
||||
]}
|
||||
>
|
||||
<FormSection locale="zh-CN" client:load />
|
||||
<SocialProofBarSection />
|
||||
</BaseLayout>
|
||||
|
||||
@@ -7,6 +7,13 @@ import DemoTranscript from '../../../components/demos/DemoTranscript.vue'
|
||||
import DemoNavSection from '../../../components/demos/DemoNavSection.vue'
|
||||
import { demos, getDemoBySlug, getNextDemo } from '../../../config/demos'
|
||||
import { t } from '../../../i18n/translations'
|
||||
import type { JsonLdNode } from '../../../utils/jsonLd'
|
||||
import {
|
||||
absoluteUrl,
|
||||
jsonLdId,
|
||||
organizationId,
|
||||
pageContext,
|
||||
} from '../../../utils/jsonLd'
|
||||
|
||||
export const getStaticPaths: GetStaticPaths = () => {
|
||||
return demos.map((demo) => ({
|
||||
@@ -19,68 +26,34 @@ const demo = getDemoBySlug(slug as string)!
|
||||
const nextDemo = getNextDemo(slug as string)
|
||||
const title = t(demo.title, 'zh-CN')
|
||||
const description = t(demo.description, 'zh-CN')
|
||||
const canonicalURL = new URL(`/zh-CN/demos/${demo.slug}`, Astro.site)
|
||||
|
||||
const howToJsonLd = {
|
||||
'@context': 'https://schema.org',
|
||||
'@type': 'HowTo',
|
||||
name: title,
|
||||
description,
|
||||
image: new URL(demo.ogImage, Astro.site).href,
|
||||
totalTime: demo.durationIso,
|
||||
datePublished: demo.publishedDate,
|
||||
dateModified: demo.modifiedDate,
|
||||
author: {
|
||||
'@type': 'Organization',
|
||||
name: 'Comfy Org',
|
||||
url: 'https://comfy.org'
|
||||
}
|
||||
}
|
||||
|
||||
const learningResourceJsonLd = {
|
||||
'@context': 'https://schema.org',
|
||||
'@type': 'LearningResource',
|
||||
name: title,
|
||||
description,
|
||||
learningResourceType: 'interactive tutorial',
|
||||
interactivityType: 'active',
|
||||
educationalLevel: demo.difficulty === 'beginner'
|
||||
const { siteUrl, locale, url } = pageContext(
|
||||
Astro.site,
|
||||
Astro.url.pathname,
|
||||
Astro.currentLocale,
|
||||
)
|
||||
const educationalLevel =
|
||||
demo.difficulty === 'beginner'
|
||||
? 'Beginner'
|
||||
: demo.difficulty === 'intermediate'
|
||||
? 'Intermediate'
|
||||
: 'Advanced',
|
||||
url: canonicalURL.href,
|
||||
: 'Advanced'
|
||||
const learningId = jsonLdId(url, 'learning')
|
||||
const learningResource: JsonLdNode = {
|
||||
'@type': 'LearningResource',
|
||||
'@id': learningId,
|
||||
name: title,
|
||||
description,
|
||||
url,
|
||||
image: new URL(demo.ogImage, Astro.site).href,
|
||||
learningResourceType: 'interactive tutorial',
|
||||
interactivityType: 'active',
|
||||
educationalLevel,
|
||||
timeRequired: demo.durationIso,
|
||||
datePublished: demo.publishedDate,
|
||||
dateModified: demo.modifiedDate,
|
||||
author: {
|
||||
'@type': 'Organization',
|
||||
name: 'Comfy Org',
|
||||
url: 'https://comfy.org'
|
||||
}
|
||||
}
|
||||
|
||||
const breadcrumbJsonLd = {
|
||||
'@context': 'https://schema.org',
|
||||
'@type': 'BreadcrumbList',
|
||||
itemListElement: [
|
||||
{
|
||||
'@type': 'ListItem',
|
||||
position: 1,
|
||||
name: t('demos.breadcrumb.home', 'zh-CN'),
|
||||
item: 'https://comfy.org/zh-CN'
|
||||
},
|
||||
{
|
||||
'@type': 'ListItem',
|
||||
position: 2,
|
||||
name: t('demos.breadcrumb.demos', 'zh-CN'),
|
||||
item: 'https://comfy.org/zh-CN/demos'
|
||||
},
|
||||
{
|
||||
'@type': 'ListItem',
|
||||
position: 3,
|
||||
name: title
|
||||
}
|
||||
]
|
||||
isPartOf: { '@id': jsonLdId(url, 'webpage') },
|
||||
author: { '@id': organizationId(siteUrl) },
|
||||
}
|
||||
---
|
||||
|
||||
@@ -88,25 +61,23 @@ const breadcrumbJsonLd = {
|
||||
title={`${title} — Comfy`}
|
||||
description={description}
|
||||
ogImage={demo.ogImage}
|
||||
mainEntityId={learningId}
|
||||
breadcrumbs={[
|
||||
{
|
||||
name: t('breadcrumb.home', locale),
|
||||
url: absoluteUrl(Astro.site, '/zh-CN'),
|
||||
},
|
||||
{
|
||||
name: t('demos.breadcrumb.demos', locale),
|
||||
url: absoluteUrl(Astro.site, '/zh-CN/demos'),
|
||||
},
|
||||
{ name: title },
|
||||
]}
|
||||
extraJsonLd={[learningResource]}
|
||||
>
|
||||
<Fragment slot="head">
|
||||
<meta property="article:published_time" content={demo.publishedDate} />
|
||||
<meta property="article:modified_time" content={demo.modifiedDate} />
|
||||
<script
|
||||
is:inline
|
||||
type="application/ld+json"
|
||||
set:html={JSON.stringify(howToJsonLd)}
|
||||
/>
|
||||
<script
|
||||
is:inline
|
||||
type="application/ld+json"
|
||||
set:html={JSON.stringify(learningResourceJsonLd)}
|
||||
/>
|
||||
<script
|
||||
is:inline
|
||||
type="application/ld+json"
|
||||
set:html={JSON.stringify(breadcrumbJsonLd)}
|
||||
/>
|
||||
<link rel="preconnect" href="https://demo.arcade.software" />
|
||||
</Fragment>
|
||||
|
||||
|
||||
@@ -8,11 +8,32 @@ import EcoSystemSection from '../../components/product/local/EcoSystemSection.vu
|
||||
import ProductCardsSection from '../../components/product/local/ProductCardsSection.vue'
|
||||
import FAQSection from '../../components/product/local/FAQSection.vue'
|
||||
import { t } from '../../i18n/translations'
|
||||
import {
|
||||
absoluteUrl,
|
||||
comfyUiApplicationNode,
|
||||
comfyUiSoftwareId,
|
||||
pageContext,
|
||||
} from '../../utils/jsonLd'
|
||||
|
||||
const { siteUrl, locale } = pageContext(
|
||||
Astro.site,
|
||||
Astro.url.pathname,
|
||||
Astro.currentLocale,
|
||||
)
|
||||
---
|
||||
|
||||
<BaseLayout
|
||||
title="下载 Comfy 桌面版 — 在您的硬件上运行 AI"
|
||||
description={t('download.hero.subtitle', 'zh-CN')}
|
||||
mainEntityId={comfyUiSoftwareId(siteUrl)}
|
||||
breadcrumbs={[
|
||||
{
|
||||
name: t('breadcrumb.home', locale),
|
||||
url: absoluteUrl(Astro.site, '/zh-CN'),
|
||||
},
|
||||
{ name: t('breadcrumb.download', locale) },
|
||||
]}
|
||||
extraJsonLd={[comfyUiApplicationNode(siteUrl)]}
|
||||
keywords={['comfyui app', 'comfyui desktop app', 'comfyui download', 'ComfyUI 下载', 'ComfyUI 桌面应用', 'ComfyUI 应用', 'ComfyUI Windows', 'ComfyUI macOS', 'ComfyUI Linux']}
|
||||
>
|
||||
<CloudBannerSection locale="zh-CN" />
|
||||
|
||||
@@ -9,11 +9,25 @@ import CaseStudySpotlightSection from '../../components/home/CaseStudySpotlightS
|
||||
import GetStartedSection from '../../components/home/GetStartedSection.vue'
|
||||
import BuildWhatSection from '../../components/home/BuildWhatSection.vue'
|
||||
import { t } from '../../i18n/translations'
|
||||
import {
|
||||
comfyUiApplicationNode,
|
||||
comfyUiSoftwareId,
|
||||
comfyUiSourceCodeNode,
|
||||
pageContext,
|
||||
} from '../../utils/jsonLd'
|
||||
|
||||
const { siteUrl } = pageContext(
|
||||
Astro.site,
|
||||
Astro.url.pathname,
|
||||
Astro.currentLocale,
|
||||
)
|
||||
---
|
||||
|
||||
<BaseLayout
|
||||
title="Comfy — 视觉 AI 的最强可控性"
|
||||
description={t('hero.subtitle', 'zh-CN')}
|
||||
mainEntityId={comfyUiSoftwareId(siteUrl)}
|
||||
extraJsonLd={[comfyUiApplicationNode(siteUrl), comfyUiSourceCodeNode(siteUrl)]}
|
||||
keywords={['comfyui app', 'comfyui web app', 'comfyui application', 'ComfyUI 应用', 'ComfyUI 网页版', 'ComfyUI 桌面应用', 'ComfyUI 下载', '可视化 AI', '节点式 AI', '生成式 AI 工作流']}
|
||||
>
|
||||
<HeroSection locale="zh-CN" client:load />
|
||||
|
||||
212
apps/website/src/utils/jsonLd.test.ts
Normal file
212
apps/website/src/utils/jsonLd.test.ts
Normal file
@@ -0,0 +1,212 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
import { externalLinks } from '../config/routes'
|
||||
import { escapeJsonLd } from './escapeJsonLd'
|
||||
import type { JsonLdGraph } from './jsonLd'
|
||||
import {
|
||||
absoluteUrl,
|
||||
buildPageGraph,
|
||||
collectGraphIds,
|
||||
comfyUiApplicationNode,
|
||||
comfyUiSoftwareId,
|
||||
comfyUiSourceCodeNode,
|
||||
itemListNode,
|
||||
jsonLdId,
|
||||
organizationId,
|
||||
pageContext,
|
||||
productNode,
|
||||
softwareApplicationNode
|
||||
} from './jsonLd'
|
||||
|
||||
const siteUrl = 'https://comfy.org'
|
||||
const site = new URL('https://comfy.org/')
|
||||
|
||||
function typeNames(graph: JsonLdGraph): string[] {
|
||||
return graph['@graph'].map((node) => node['@type'])
|
||||
}
|
||||
|
||||
describe('absoluteUrl', () => {
|
||||
it('resolves internal paths to their trailing-slash canonical form', () => {
|
||||
expect(absoluteUrl(site, '/cloud')).toBe('https://comfy.org/cloud/')
|
||||
expect(absoluteUrl(site, '/about/')).toBe('https://comfy.org/about/')
|
||||
expect(absoluteUrl(site, '/')).toBe('https://comfy.org/')
|
||||
})
|
||||
})
|
||||
|
||||
describe('pageContext', () => {
|
||||
it('derives siteUrl, locale and canonical url from the Astro globals', () => {
|
||||
expect(pageContext(site, '/about/', undefined)).toEqual({
|
||||
siteUrl,
|
||||
locale: 'en',
|
||||
url: 'https://comfy.org/about/'
|
||||
})
|
||||
expect(pageContext(site, '/zh-CN/', 'zh-CN').locale).toBe('zh-CN')
|
||||
})
|
||||
})
|
||||
|
||||
describe('itemListNode', () => {
|
||||
it('counts items and omits per-item names when not supplied', () => {
|
||||
const node = itemListNode('https://comfy.org/careers/', 'Careers', [
|
||||
{ url: 'https://jobs.example/1' },
|
||||
{ url: 'https://jobs.example/2', name: 'Designer' }
|
||||
])
|
||||
expect(node.numberOfItems).toBe(2)
|
||||
const items = node.itemListElement as Record<string, unknown>[]
|
||||
expect('name' in items[0]).toBe(false)
|
||||
expect(items[1].name).toBe('Designer')
|
||||
})
|
||||
})
|
||||
|
||||
describe('softwareApplicationNode', () => {
|
||||
it('claims Comfy Org as author and publisher only when first-party', () => {
|
||||
const node = softwareApplicationNode({
|
||||
siteUrl,
|
||||
id: jsonLdId(siteUrl, 'software'),
|
||||
name: 'ComfyUI',
|
||||
url: siteUrl,
|
||||
firstParty: true,
|
||||
applicationCategory: 'MultimediaApplication',
|
||||
isFree: true
|
||||
})
|
||||
const orgRef = { '@id': organizationId(siteUrl) }
|
||||
expect(node.author).toEqual(orgRef)
|
||||
expect(node.publisher).toEqual(orgRef)
|
||||
expect(node.offers).toEqual({
|
||||
'@type': 'Offer',
|
||||
price: 0,
|
||||
priceCurrency: 'USD',
|
||||
seller: orgRef
|
||||
})
|
||||
})
|
||||
|
||||
it('does not name Comfy Org as seller on a third-party free offer', () => {
|
||||
const node = softwareApplicationNode({
|
||||
siteUrl,
|
||||
id: 'https://comfy.org/cloud/supported-nodes/foo/#software',
|
||||
name: 'Foo Pack',
|
||||
url: 'https://comfy.org/cloud/supported-nodes/foo/',
|
||||
applicationCategory: 'DeveloperApplication',
|
||||
isFree: true
|
||||
})
|
||||
expect((node.offers as Record<string, unknown>).seller).toBeUndefined()
|
||||
})
|
||||
|
||||
it('credits a known third-party author without claiming to publish it', () => {
|
||||
const node = softwareApplicationNode({
|
||||
siteUrl,
|
||||
id: 'https://comfy.org/cloud/supported-nodes/foo/#software',
|
||||
name: 'Foo Pack',
|
||||
url: 'https://comfy.org/cloud/supported-nodes/foo/',
|
||||
applicationCategory: 'DeveloperApplication',
|
||||
authorName: 'Jane Dev'
|
||||
})
|
||||
expect(node.author).toEqual({ '@type': 'Person', name: 'Jane Dev' })
|
||||
expect(node.publisher).toBeUndefined()
|
||||
})
|
||||
|
||||
it('claims no author or publisher for third-party software with no author', () => {
|
||||
const node = softwareApplicationNode({
|
||||
siteUrl,
|
||||
id: 'https://comfy.org/p/supported-models/foo/#software',
|
||||
name: 'Foo Model',
|
||||
url: 'https://comfy.org/p/supported-models/foo/',
|
||||
applicationCategory: 'MultimediaApplication'
|
||||
})
|
||||
expect(node.author).toBeUndefined()
|
||||
expect(node.publisher).toBeUndefined()
|
||||
})
|
||||
})
|
||||
|
||||
describe('sameAs encyclopedic references', () => {
|
||||
it('links the organization to its Wikidata entity', () => {
|
||||
const graph = buildPageGraph(
|
||||
{ siteUrl, locale: 'en' },
|
||||
{ url: `${siteUrl}/`, name: 'Home' }
|
||||
)
|
||||
const org = graph['@graph'].find((node) => node['@type'] === 'Organization')
|
||||
expect(org?.sameAs).toContain(externalLinks.wikidataComfyOrg)
|
||||
})
|
||||
|
||||
it('links the ComfyUI application to its Wikidata, Wikipedia and G2 entities', () => {
|
||||
const node = comfyUiApplicationNode(siteUrl)
|
||||
expect(node.sameAs).toEqual([
|
||||
externalLinks.wikidataComfyUi,
|
||||
externalLinks.wikipediaComfyUi,
|
||||
externalLinks.g2ComfyUi
|
||||
])
|
||||
})
|
||||
|
||||
it('omits sameAs for third-party software', () => {
|
||||
const node = softwareApplicationNode({
|
||||
siteUrl,
|
||||
id: 'https://comfy.org/p/supported-models/foo/#software',
|
||||
name: 'Foo Model',
|
||||
url: 'https://comfy.org/p/supported-models/foo/',
|
||||
applicationCategory: 'MultimediaApplication'
|
||||
})
|
||||
expect(node.sameAs).toBeUndefined()
|
||||
})
|
||||
})
|
||||
|
||||
describe('productNode', () => {
|
||||
it('gives every offer a currency and price', () => {
|
||||
const node = productNode({
|
||||
siteUrl,
|
||||
id: 'https://comfy.org/cloud/pricing/#product',
|
||||
name: 'Comfy Cloud',
|
||||
url: 'https://comfy.org/cloud/pricing/',
|
||||
offers: [{ name: 'Standard', price: '20' }]
|
||||
})
|
||||
const offers = node.offers as Record<string, unknown>[]
|
||||
expect(offers[0].price).toBe('20')
|
||||
expect(offers[0].priceCurrency).toBe('USD')
|
||||
expect(offers[0].seller).toEqual({ '@id': organizationId(siteUrl) })
|
||||
})
|
||||
})
|
||||
|
||||
describe('comfyUiSourceCodeNode', () => {
|
||||
it('links the source code to the ComfyUI application via targetProduct', () => {
|
||||
const node = comfyUiSourceCodeNode(siteUrl)
|
||||
expect(node.targetProduct).toEqual({ '@id': comfyUiSoftwareId(siteUrl) })
|
||||
})
|
||||
})
|
||||
|
||||
describe('buildPageGraph', () => {
|
||||
const url = 'https://comfy.org/cloud/pricing/'
|
||||
const graph = buildPageGraph(
|
||||
{ siteUrl, locale: 'en' },
|
||||
{
|
||||
url,
|
||||
name: 'Pricing',
|
||||
type: 'CollectionPage',
|
||||
mainEntityId: jsonLdId(url, 'itemlist'),
|
||||
crumbs: [{ name: 'Home', url: `${siteUrl}/` }, { name: 'Pricing' }]
|
||||
},
|
||||
itemListNode(url, 'Plans', [{ url: `${siteUrl}/one/` }])
|
||||
)
|
||||
|
||||
it('always includes the site-wide organization, website and page entity', () => {
|
||||
expect(typeNames(graph)).toContain('Organization')
|
||||
expect(typeNames(graph)).toContain('WebSite')
|
||||
expect(typeNames(graph)).toContain('CollectionPage')
|
||||
})
|
||||
|
||||
it('produces a graph where every @id reference resolves', () => {
|
||||
const { defined, references } = collectGraphIds(graph)
|
||||
for (const reference of references) {
|
||||
expect(defined.has(reference)).toBe(true)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe('escapeJsonLd on a built graph', () => {
|
||||
it('neutralizes a </script> breakout in a page name', () => {
|
||||
const graph = buildPageGraph(
|
||||
{ siteUrl, locale: 'en' },
|
||||
{ url: `${siteUrl}/x/`, name: '</script><script>alert(1)</script>' }
|
||||
)
|
||||
const serialized = escapeJsonLd(graph)
|
||||
expect(serialized).not.toContain('</script>')
|
||||
expect(serialized).toContain('\\u003c')
|
||||
})
|
||||
})
|
||||
377
apps/website/src/utils/jsonLd.ts
Normal file
377
apps/website/src/utils/jsonLd.ts
Normal file
@@ -0,0 +1,377 @@
|
||||
import { externalLinks } from '../config/routes'
|
||||
import type { Locale } from '../i18n/translations'
|
||||
|
||||
export type JsonLdNode = Record<string, unknown> & { '@type': string }
|
||||
|
||||
export interface JsonLdGraph {
|
||||
'@context': 'https://schema.org'
|
||||
'@graph': JsonLdNode[]
|
||||
}
|
||||
|
||||
export interface PageContext {
|
||||
siteUrl: string
|
||||
locale: Locale
|
||||
}
|
||||
|
||||
export type WebPageType =
|
||||
| 'WebPage'
|
||||
| 'AboutPage'
|
||||
| 'ContactPage'
|
||||
| 'CollectionPage'
|
||||
|
||||
export interface Crumb {
|
||||
name: string
|
||||
url?: string
|
||||
}
|
||||
|
||||
const sameAs = [
|
||||
externalLinks.github,
|
||||
externalLinks.x,
|
||||
externalLinks.youtube,
|
||||
externalLinks.discord,
|
||||
externalLinks.instagram,
|
||||
externalLinks.reddit,
|
||||
externalLinks.linkedin,
|
||||
// Wikidata entity for the organization, so the Knowledge Graph can resolve it.
|
||||
externalLinks.wikidataComfyOrg
|
||||
]
|
||||
|
||||
// Authoritative encyclopedic and review-platform references for the ComfyUI software entity.
|
||||
const comfyUiSameAs = [
|
||||
externalLinks.wikidataComfyUi,
|
||||
externalLinks.wikipediaComfyUi,
|
||||
externalLinks.g2ComfyUi
|
||||
]
|
||||
|
||||
function siteUrlFrom(site: URL | undefined): string {
|
||||
return (site?.href ?? 'https://comfy.org/').replace(/\/$/, '')
|
||||
}
|
||||
|
||||
export function absoluteUrl(site: URL | undefined, path: string): string {
|
||||
const resolved = new URL(path, site ?? 'https://comfy.org').href
|
||||
return resolved.endsWith('/') ? resolved : `${resolved}/`
|
||||
}
|
||||
|
||||
export function pageContext(
|
||||
site: URL | undefined,
|
||||
pathname: string,
|
||||
currentLocale: string | undefined
|
||||
): PageContext & { url: string } {
|
||||
return {
|
||||
siteUrl: siteUrlFrom(site),
|
||||
locale: currentLocale === 'zh-CN' ? 'zh-CN' : 'en',
|
||||
url: absoluteUrl(site, pathname)
|
||||
}
|
||||
}
|
||||
|
||||
export function jsonLdId(pageUrl: string, fragment: string): string {
|
||||
return `${pageUrl}#${fragment}`
|
||||
}
|
||||
|
||||
export function organizationId(siteUrl: string): string {
|
||||
return `${siteUrl}/#organization`
|
||||
}
|
||||
|
||||
function websiteId(siteUrl: string): string {
|
||||
return `${siteUrl}/#website`
|
||||
}
|
||||
|
||||
function buildGraph(...nodes: (JsonLdNode | null | undefined)[]): JsonLdGraph {
|
||||
return {
|
||||
'@context': 'https://schema.org',
|
||||
'@graph': nodes.filter((node): node is JsonLdNode => Boolean(node))
|
||||
}
|
||||
}
|
||||
|
||||
function organizationNode(siteUrl: string): JsonLdNode {
|
||||
return {
|
||||
'@type': 'Organization',
|
||||
'@id': organizationId(siteUrl),
|
||||
name: 'Comfy Org',
|
||||
url: siteUrl,
|
||||
logo: {
|
||||
'@type': 'ImageObject',
|
||||
url: `${siteUrl}/web-app-manifest-512x512.png`,
|
||||
width: 512,
|
||||
height: 512
|
||||
},
|
||||
sameAs
|
||||
}
|
||||
}
|
||||
|
||||
function websiteNode(siteUrl: string): JsonLdNode {
|
||||
return {
|
||||
'@type': 'WebSite',
|
||||
'@id': websiteId(siteUrl),
|
||||
name: 'Comfy',
|
||||
url: siteUrl,
|
||||
publisher: { '@id': organizationId(siteUrl) }
|
||||
}
|
||||
}
|
||||
|
||||
function breadcrumbNode(pageUrl: string, crumbs: Crumb[]): JsonLdNode {
|
||||
return {
|
||||
'@type': 'BreadcrumbList',
|
||||
'@id': jsonLdId(pageUrl, 'breadcrumb'),
|
||||
itemListElement: crumbs.map((crumb, index) => {
|
||||
const isLast = index === crumbs.length - 1
|
||||
return isLast || !crumb.url
|
||||
? { '@type': 'ListItem', position: index + 1, name: crumb.name }
|
||||
: {
|
||||
'@type': 'ListItem',
|
||||
position: index + 1,
|
||||
name: crumb.name,
|
||||
item: crumb.url
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export function itemListNode(
|
||||
pageUrl: string,
|
||||
name: string,
|
||||
items: { url: string; name?: string }[]
|
||||
): JsonLdNode {
|
||||
return {
|
||||
'@type': 'ItemList',
|
||||
'@id': jsonLdId(pageUrl, 'itemlist'),
|
||||
name,
|
||||
numberOfItems: items.length,
|
||||
itemListElement: items.map((item, index) => ({
|
||||
'@type': 'ListItem',
|
||||
position: index + 1,
|
||||
url: item.url,
|
||||
...(item.name ? { name: item.name } : {})
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
interface WebPageInput {
|
||||
siteUrl: string
|
||||
locale: Locale
|
||||
url: string
|
||||
name: string
|
||||
description?: string
|
||||
imageUrl?: string
|
||||
crumbs?: Crumb[]
|
||||
mainEntityId?: string
|
||||
}
|
||||
|
||||
function webPageNode(input: WebPageInput, type: WebPageType): JsonLdNode {
|
||||
const hasCrumbs = Boolean(input.crumbs && input.crumbs.length > 0)
|
||||
return {
|
||||
'@type': type,
|
||||
'@id': jsonLdId(input.url, 'webpage'),
|
||||
url: input.url,
|
||||
name: input.name,
|
||||
description: input.description,
|
||||
isPartOf: { '@id': websiteId(input.siteUrl) },
|
||||
primaryImageOfPage: input.imageUrl
|
||||
? { '@type': 'ImageObject', url: input.imageUrl }
|
||||
: undefined,
|
||||
breadcrumb: hasCrumbs
|
||||
? { '@id': jsonLdId(input.url, 'breadcrumb') }
|
||||
: undefined,
|
||||
mainEntity: input.mainEntityId ? { '@id': input.mainEntityId } : undefined,
|
||||
inLanguage: input.locale
|
||||
}
|
||||
}
|
||||
|
||||
export interface SoftwareAppInput {
|
||||
siteUrl: string
|
||||
id: string
|
||||
name: string
|
||||
url: string
|
||||
applicationCategory: string
|
||||
firstParty?: boolean
|
||||
applicationSubCategory?: string
|
||||
description?: string
|
||||
operatingSystem?: string
|
||||
image?: string
|
||||
softwareVersion?: string
|
||||
license?: string
|
||||
codeRepository?: string
|
||||
authorName?: string
|
||||
isFree?: boolean
|
||||
sameAs?: string[]
|
||||
}
|
||||
|
||||
export function softwareApplicationNode(input: SoftwareAppInput): JsonLdNode {
|
||||
const orgRef = { '@id': organizationId(input.siteUrl) }
|
||||
const author = input.firstParty
|
||||
? orgRef
|
||||
: input.authorName
|
||||
? { '@type': 'Person', name: input.authorName }
|
||||
: undefined
|
||||
return {
|
||||
'@type': 'SoftwareApplication',
|
||||
'@id': input.id,
|
||||
name: input.name,
|
||||
url: input.url,
|
||||
applicationCategory: input.applicationCategory,
|
||||
applicationSubCategory: input.applicationSubCategory,
|
||||
description: input.description,
|
||||
operatingSystem: input.operatingSystem,
|
||||
image: input.image,
|
||||
softwareVersion: input.softwareVersion,
|
||||
license: input.license,
|
||||
codeRepository: input.codeRepository,
|
||||
author,
|
||||
publisher: input.firstParty ? orgRef : undefined,
|
||||
sameAs: input.sameAs,
|
||||
offers: input.isFree
|
||||
? {
|
||||
'@type': 'Offer',
|
||||
price: 0,
|
||||
priceCurrency: 'USD',
|
||||
seller: input.firstParty ? orgRef : undefined
|
||||
}
|
||||
: undefined
|
||||
}
|
||||
}
|
||||
|
||||
interface SourceCodeInput {
|
||||
siteUrl: string
|
||||
id: string
|
||||
name: string
|
||||
codeRepository: string
|
||||
programmingLanguage?: string
|
||||
targetProductId?: string
|
||||
}
|
||||
|
||||
function softwareSourceCodeNode(input: SourceCodeInput): JsonLdNode {
|
||||
return {
|
||||
'@type': 'SoftwareSourceCode',
|
||||
'@id': input.id,
|
||||
name: input.name,
|
||||
codeRepository: input.codeRepository,
|
||||
programmingLanguage: input.programmingLanguage,
|
||||
targetProduct: input.targetProductId
|
||||
? { '@id': input.targetProductId }
|
||||
: undefined,
|
||||
author: { '@id': organizationId(input.siteUrl) }
|
||||
}
|
||||
}
|
||||
|
||||
export function comfyUiSoftwareId(siteUrl: string): string {
|
||||
return `${siteUrl}/#software`
|
||||
}
|
||||
|
||||
export function comfyUiApplicationNode(siteUrl: string): JsonLdNode {
|
||||
return softwareApplicationNode({
|
||||
siteUrl,
|
||||
id: comfyUiSoftwareId(siteUrl),
|
||||
name: 'ComfyUI',
|
||||
url: siteUrl,
|
||||
firstParty: true,
|
||||
applicationCategory: 'MultimediaApplication',
|
||||
operatingSystem: 'Windows, macOS, Linux',
|
||||
isFree: true,
|
||||
sameAs: comfyUiSameAs
|
||||
})
|
||||
}
|
||||
|
||||
export function comfyUiSourceCodeNode(siteUrl: string): JsonLdNode {
|
||||
return softwareSourceCodeNode({
|
||||
siteUrl,
|
||||
id: `${siteUrl}/#sourcecode`,
|
||||
name: 'ComfyUI',
|
||||
codeRepository: externalLinks.github,
|
||||
programmingLanguage: 'Python',
|
||||
targetProductId: comfyUiSoftwareId(siteUrl)
|
||||
})
|
||||
}
|
||||
|
||||
interface OfferInput {
|
||||
name: string
|
||||
price: string | number
|
||||
url?: string
|
||||
}
|
||||
|
||||
export interface ProductInput {
|
||||
siteUrl: string
|
||||
id: string
|
||||
name: string
|
||||
url: string
|
||||
offers: OfferInput[]
|
||||
}
|
||||
|
||||
export function productNode(input: ProductInput): JsonLdNode {
|
||||
return {
|
||||
'@type': 'Product',
|
||||
'@id': input.id,
|
||||
name: input.name,
|
||||
url: input.url,
|
||||
brand: { '@id': organizationId(input.siteUrl) },
|
||||
offers: input.offers.map((offer) => ({
|
||||
'@type': 'Offer',
|
||||
name: offer.name,
|
||||
price: offer.price,
|
||||
priceCurrency: 'USD',
|
||||
url: offer.url,
|
||||
seller: { '@id': organizationId(input.siteUrl) },
|
||||
priceSpecification: {
|
||||
'@type': 'UnitPriceSpecification',
|
||||
price: offer.price,
|
||||
priceCurrency: 'USD',
|
||||
unitText: 'MONTH'
|
||||
}
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
export interface PageGraphInput {
|
||||
url: string
|
||||
name: string
|
||||
type?: WebPageType
|
||||
description?: string
|
||||
imageUrl?: string
|
||||
crumbs?: Crumb[]
|
||||
mainEntityId?: string
|
||||
}
|
||||
|
||||
export function buildPageGraph(
|
||||
ctx: PageContext,
|
||||
page: PageGraphInput,
|
||||
...extraNodes: (JsonLdNode | null | undefined)[]
|
||||
): JsonLdGraph {
|
||||
const { type = 'WebPage', ...rest } = page
|
||||
const input: WebPageInput = {
|
||||
...rest,
|
||||
siteUrl: ctx.siteUrl,
|
||||
locale: ctx.locale
|
||||
}
|
||||
const hasCrumbs = Boolean(page.crumbs && page.crumbs.length > 0)
|
||||
return buildGraph(
|
||||
organizationNode(ctx.siteUrl),
|
||||
websiteNode(ctx.siteUrl),
|
||||
webPageNode(input, type),
|
||||
hasCrumbs ? breadcrumbNode(page.url, page.crumbs!) : undefined,
|
||||
...extraNodes
|
||||
)
|
||||
}
|
||||
|
||||
export function collectGraphIds(value: unknown): {
|
||||
defined: Set<string>
|
||||
references: string[]
|
||||
} {
|
||||
const defined = new Set<string>()
|
||||
const references: string[] = []
|
||||
const walk = (node: unknown): void => {
|
||||
if (Array.isArray(node)) {
|
||||
node.forEach(walk)
|
||||
return
|
||||
}
|
||||
if (node && typeof node === 'object') {
|
||||
const record = node as Record<string, unknown>
|
||||
const id = record['@id']
|
||||
if (typeof id === 'string') {
|
||||
if (Object.keys(record).length === 1) references.push(id)
|
||||
else defined.add(id)
|
||||
}
|
||||
Object.values(record).forEach(walk)
|
||||
}
|
||||
}
|
||||
walk(value)
|
||||
return { defined, references }
|
||||
}
|
||||
279
browser_tests/tests/cloudSecrets.spec.ts
Normal file
279
browser_tests/tests/cloudSecrets.spec.ts
Normal file
@@ -0,0 +1,279 @@
|
||||
import { expect } from '@playwright/test'
|
||||
import type { Page, Route } from '@playwright/test'
|
||||
|
||||
import type { RemoteConfig } from '@/platform/remoteConfig/types'
|
||||
|
||||
import { comfyPageFixture as test } from '@e2e/fixtures/ComfyPage'
|
||||
import { bootCloud, mockCloudBoot } from '@e2e/fixtures/utils/cloudBootMocks'
|
||||
import { jsonRoute } from '@e2e/fixtures/utils/jsonRoute'
|
||||
|
||||
/**
|
||||
* End-to-end coverage for the user-secrets (API keys) surface in the cloud app:
|
||||
* add a provider key, see it listed, delete it — the full CRUD round-trip —
|
||||
* plus the entitlement contract that a non-entitled account never sees the
|
||||
* gated providers.
|
||||
*
|
||||
* Drives a raw `page` against fully-mocked endpoints (the `comfyPage` fixture
|
||||
* would reach the OSS devtools backend during setup); `mockCloudBoot` +
|
||||
* `bootCloud` boot the app signed-in, and this spec layers a stateful in-memory
|
||||
* `/secrets` backend on top so the flow is deterministic and never touches a
|
||||
* real server.
|
||||
*/
|
||||
const APP_URL = process.env.PLAYWRIGHT_TEST_URL || 'http://localhost:8188'
|
||||
|
||||
// `/api/features` is the remote-config source. Enabling user secrets is what
|
||||
// surfaces the Secrets settings panel for a signed-in user.
|
||||
const BOOT_FEATURES = {
|
||||
user_secrets_enabled: true
|
||||
} satisfies RemoteConfig
|
||||
|
||||
// TutorialCompleted suppresses the new-user template browser, whose modal
|
||||
// overlay (z-1700) would otherwise intercept clicks on the settings dialog.
|
||||
const BOOT_SETTINGS = { 'Comfy.TutorialCompleted': true }
|
||||
|
||||
// The plaintext key a user types in. It must be sent on create but NEVER echoed
|
||||
// back by the API or rendered anywhere in the UI.
|
||||
const RUNWAY_KEY_VALUE = 'sk-runway-do-not-echo-0xDEADBEEF'
|
||||
|
||||
interface SecretRecord {
|
||||
id: string
|
||||
name: string
|
||||
provider?: string
|
||||
created_at: string
|
||||
updated_at: string
|
||||
last_used_at?: string
|
||||
}
|
||||
|
||||
interface CreateCapture {
|
||||
name?: string
|
||||
provider?: string
|
||||
secret_value?: string
|
||||
}
|
||||
|
||||
interface SecretsBackend {
|
||||
/** Bodies received by POST /secrets, in order — for asserting what was sent. */
|
||||
createRequests: CreateCapture[]
|
||||
/** Current server-side store — for asserting delete actually removed a row. */
|
||||
store: SecretRecord[]
|
||||
}
|
||||
|
||||
/**
|
||||
* Stateful mock of the ingest `/secrets` surface. A single route handler
|
||||
* branches on path + method so registration order can never make a specific
|
||||
* path (`/secrets/providers`, `/secrets/:id`) lose to the collection glob.
|
||||
*
|
||||
* `providerIds` models entitlement: an entitled account sees runway/gemini,
|
||||
* a non-entitled account gets an empty list (the server omits them).
|
||||
*/
|
||||
async function mockSecretsBackend(
|
||||
page: Page,
|
||||
providerIds: string[]
|
||||
): Promise<SecretsBackend> {
|
||||
const backend: SecretsBackend = { createRequests: [], store: [] }
|
||||
let idSeq = 0
|
||||
|
||||
const respondList = (route: Route) =>
|
||||
route.fulfill(jsonRoute({ data: backend.store }))
|
||||
|
||||
await page.route('**/api/secrets**', async (route) => {
|
||||
const request = route.request()
|
||||
const { pathname } = new URL(request.url())
|
||||
const method = request.method()
|
||||
|
||||
// The glob `**/api/secrets**` also matches the panel's own lazy-loaded
|
||||
// source module (`/src/platform/secrets/api/secretsApi.ts`), whose path
|
||||
// contains the `/api/secrets` substring. Fulfilling that dev-server module
|
||||
// request with JSON breaks the dynamic import and the panel never mounts.
|
||||
// Anchor to the start of the pathname so only genuine `/api/secrets…` API
|
||||
// routes are handled; everything else falls through to the real Vite server.
|
||||
if (!/^\/api\/secrets(\/|$)/.test(pathname)) {
|
||||
return route.continue()
|
||||
}
|
||||
|
||||
// GET /secrets/providers — the entitlement-gated provider allowlist.
|
||||
if (pathname.endsWith('/secrets/providers')) {
|
||||
return route.fulfill(
|
||||
jsonRoute({ data: providerIds.map((id) => ({ id })) })
|
||||
)
|
||||
}
|
||||
|
||||
// /secrets/:id — item routes (only DELETE is exercised by this flow).
|
||||
const itemMatch = pathname.match(/\/secrets\/([^/]+)$/)
|
||||
if (itemMatch) {
|
||||
const id = itemMatch[1]
|
||||
if (method === 'DELETE') {
|
||||
backend.store = backend.store.filter((s) => s.id !== id)
|
||||
return route.fulfill({ status: 204, body: '' })
|
||||
}
|
||||
return respondList(route)
|
||||
}
|
||||
|
||||
// /secrets — collection routes.
|
||||
if (method === 'POST') {
|
||||
const body = (request.postDataJSON() ?? {}) as CreateCapture
|
||||
backend.createRequests.push(body)
|
||||
idSeq += 1
|
||||
const created: SecretRecord = {
|
||||
id: `00000000-0000-4000-8000-${String(idSeq).padStart(12, '0')}`,
|
||||
name: body.name ?? '',
|
||||
provider: body.provider,
|
||||
created_at: '2026-07-08T00:00:00Z',
|
||||
updated_at: '2026-07-08T00:00:00Z'
|
||||
}
|
||||
backend.store.push(created)
|
||||
// Response echoes metadata ONLY — the schema has no secret_value field.
|
||||
return route.fulfill(jsonRoute(created))
|
||||
}
|
||||
|
||||
// GET /secrets (list).
|
||||
return respondList(route)
|
||||
})
|
||||
|
||||
return backend
|
||||
}
|
||||
|
||||
/**
|
||||
* Open the settings dialog and land on the Secrets panel, waiting for both the
|
||||
* provider allowlist and the secret list to resolve so subsequent assertions
|
||||
* are not racing the panel's on-mount fetches.
|
||||
*/
|
||||
async function openSecretsPanel(page: Page) {
|
||||
const settingsDialog = page.getByTestId('settings-dialog')
|
||||
|
||||
await page.evaluate(() => {
|
||||
const app = window.app
|
||||
if (!app) throw new Error('window.app is not available')
|
||||
return app.extensionManager.command.execute('Comfy.ShowSettingsDialog')
|
||||
})
|
||||
await settingsDialog.waitFor({ state: 'visible' })
|
||||
|
||||
const providersResolved = page.waitForResponse((r) =>
|
||||
r.url().includes('/api/secrets/providers')
|
||||
)
|
||||
const listResolved = page.waitForResponse(
|
||||
(r) =>
|
||||
/\/api\/secrets(\?|$)/.test(r.url()) && r.request().method() === 'GET'
|
||||
)
|
||||
|
||||
await settingsDialog
|
||||
.locator('nav')
|
||||
.getByRole('button', { name: 'Secrets' })
|
||||
.click()
|
||||
|
||||
await Promise.all([providersResolved, listResolved])
|
||||
return settingsDialog
|
||||
}
|
||||
|
||||
test.describe('Cloud user secrets (API keys)', { tag: '@cloud' }, () => {
|
||||
test('an entitled account can add, list, and delete a provider key', async ({
|
||||
page
|
||||
}) => {
|
||||
test.slow()
|
||||
|
||||
await mockCloudBoot(page, {
|
||||
features: BOOT_FEATURES,
|
||||
settings: BOOT_SETTINGS
|
||||
})
|
||||
await bootCloud(page)
|
||||
const backend = await mockSecretsBackend(page, ['runway', 'gemini'])
|
||||
|
||||
await page.goto(APP_URL)
|
||||
await page.waitForFunction(() => !!window.app?.extensionManager, null, {
|
||||
timeout: 45_000
|
||||
})
|
||||
|
||||
const settingsDialog = await openSecretsPanel(page)
|
||||
|
||||
// Empty state before anything is added.
|
||||
await expect(settingsDialog.getByText(/No secrets stored/)).toBeVisible()
|
||||
|
||||
// --- ADD -------------------------------------------------------------
|
||||
await settingsDialog.getByRole('button', { name: 'Add Secret' }).click()
|
||||
|
||||
const formDialog = page
|
||||
.getByRole('dialog')
|
||||
.filter({ hasText: 'Secret Value' })
|
||||
await expect(formDialog).toBeVisible()
|
||||
|
||||
// Pick the entitled Runway provider from the server-driven dropdown.
|
||||
await formDialog.locator('#secret-provider').click()
|
||||
await page.getByRole('option', { name: 'Runway' }).click()
|
||||
|
||||
await formDialog.locator('#secret-name').fill('My Runway Key')
|
||||
await formDialog.locator('input[type="password"]').fill(RUNWAY_KEY_VALUE)
|
||||
|
||||
await formDialog.getByRole('button', { name: 'Save', exact: true }).click()
|
||||
await expect(formDialog).toBeHidden()
|
||||
|
||||
// --- LIST ------------------------------------------------------------
|
||||
await expect(settingsDialog.getByText('My Runway Key')).toBeVisible()
|
||||
await expect(settingsDialog.getByText(/No secrets stored/)).toBeHidden()
|
||||
|
||||
// The create request carried the plaintext value + provider...
|
||||
expect(backend.createRequests).toHaveLength(1)
|
||||
expect(backend.createRequests[0]).toMatchObject({
|
||||
name: 'My Runway Key',
|
||||
provider: 'runway',
|
||||
secret_value: RUNWAY_KEY_VALUE
|
||||
})
|
||||
// ...but the value must never be echoed back into the list — the API
|
||||
// response carries metadata only, so nothing should render it as text.
|
||||
await expect(page.getByText(RUNWAY_KEY_VALUE)).toHaveCount(0)
|
||||
|
||||
// --- DELETE ----------------------------------------------------------
|
||||
await settingsDialog
|
||||
.getByRole('button', { name: 'Delete', exact: true })
|
||||
.click()
|
||||
|
||||
const confirmDialog = page
|
||||
.getByRole('dialog')
|
||||
.filter({ hasText: 'Delete Secret' })
|
||||
await confirmDialog
|
||||
.getByRole('button', { name: 'Delete', exact: true })
|
||||
.click()
|
||||
|
||||
await expect(settingsDialog.getByText('My Runway Key')).toBeHidden()
|
||||
await expect(settingsDialog.getByText(/No secrets stored/)).toBeVisible()
|
||||
expect(backend.store).toHaveLength(0)
|
||||
})
|
||||
|
||||
test('a non-entitled account never sees the gated providers', async ({
|
||||
page
|
||||
}) => {
|
||||
test.slow()
|
||||
|
||||
await mockCloudBoot(page, {
|
||||
features: BOOT_FEATURES,
|
||||
settings: BOOT_SETTINGS
|
||||
})
|
||||
await bootCloud(page)
|
||||
// Non-entitled: the server omits runway/gemini from the allowlist.
|
||||
await mockSecretsBackend(page, [])
|
||||
|
||||
await page.goto(APP_URL)
|
||||
await page.waitForFunction(() => !!window.app?.extensionManager, null, {
|
||||
timeout: 45_000
|
||||
})
|
||||
|
||||
const settingsDialog = await openSecretsPanel(page)
|
||||
await expect(settingsDialog.getByText(/No secrets stored/)).toBeVisible()
|
||||
|
||||
// The add form opens, but its provider dropdown is empty — the gated
|
||||
// providers must not appear anywhere.
|
||||
await settingsDialog.getByRole('button', { name: 'Add Secret' }).click()
|
||||
const formDialog = page
|
||||
.getByRole('dialog')
|
||||
.filter({ hasText: 'Secret Value' })
|
||||
await expect(formDialog).toBeVisible()
|
||||
|
||||
await formDialog.locator('#secret-provider').click()
|
||||
// Anchor on the opened listbox so the absence assertions below can't pass
|
||||
// vacuously against a dropdown that never opened.
|
||||
const providerListbox = page.getByRole('listbox')
|
||||
await expect(providerListbox).toBeVisible()
|
||||
// An empty allowlist must yield an empty dropdown. Asserting zero options
|
||||
// (not just runway/gemini absent) also rejects the fetch-failure fallback,
|
||||
// where `availableProviders` is null and the default providers would show.
|
||||
await expect(providerListbox.getByRole('option')).toHaveCount(0)
|
||||
})
|
||||
})
|
||||
@@ -1,7 +1,13 @@
|
||||
import { mergeTests } from '@playwright/test'
|
||||
|
||||
import {
|
||||
comfyPageFixture as test,
|
||||
comfyExpect as expect
|
||||
} from '@e2e/fixtures/ComfyPage'
|
||||
import { ExecutionHelper } from '@e2e/fixtures/helpers/ExecutionHelper'
|
||||
import { webSocketFixture } from '@e2e/fixtures/ws'
|
||||
|
||||
const wstest = mergeTests(test, webSocketFixture)
|
||||
|
||||
test.describe('Preview as Text node', () => {
|
||||
test('does not include preview widget values in the API prompt', async ({
|
||||
@@ -39,4 +45,34 @@ test.describe('Preview as Text node', () => {
|
||||
expect(previewEntry!.inputs).not.toHaveProperty('preview_text')
|
||||
expect(previewEntry!.inputs).not.toHaveProperty('previewMode')
|
||||
})
|
||||
|
||||
wstest(
|
||||
'restoring workflow restores state',
|
||||
{ tag: '@vue-nodes' },
|
||||
async ({ comfyPage, getWebSocket }) => {
|
||||
const execution = new ExecutionHelper(comfyPage, await getWebSocket())
|
||||
|
||||
await comfyPage.menu.topbar.newWorkflowButton.click()
|
||||
await comfyPage.searchBoxV2.addNode('Preview as Text')
|
||||
const node = await comfyPage.vueNodes.getFixtureByTitle('Preview as Text')
|
||||
const preview = node.root.locator('textarea')
|
||||
|
||||
await test.step('node previews execution result', async () => {
|
||||
const id = await comfyPage.vueNodes.getNodeIdByTitle('Preview as Text')
|
||||
execution.executed('', id, { text: 'massive fennec ears' })
|
||||
await expect(preview).toHaveValue('massive fennec ears')
|
||||
})
|
||||
|
||||
await test.step('swap to a different workflow and back', async () => {
|
||||
await comfyPage.menu.topbar.getTab(0).click()
|
||||
await expect(node.root).toBeHidden()
|
||||
await comfyPage.menu.topbar.getTab(1).click()
|
||||
await expect(node.root).toBeVisible()
|
||||
})
|
||||
|
||||
await expect(preview, 'previous output is restored').toHaveValue(
|
||||
'massive fennec ears'
|
||||
)
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
@@ -54,6 +54,14 @@ const config: KnipConfig = {
|
||||
'.github/workflows/ci-oss-assets-validation.yaml',
|
||||
// Pending integration in stacked PR
|
||||
'src/components/sidebar/tabs/nodeLibrary/CustomNodesPanel.vue',
|
||||
// Pending integration in the workspace-settings stacked PRs: consumed by
|
||||
// split/auto-reload + split/allowlist (Switch) and split/member-auditing
|
||||
// + split/allowlist (Pagination); each consumer removes its entry
|
||||
'src/components/ui/switch/Switch.vue',
|
||||
'src/components/ui/pagination/Pagination.vue',
|
||||
// Pending integration: consumed by split/plan-credits-tabs (Overview) and
|
||||
// split/allowlist (Models); each consumer removes this entry
|
||||
'src/platform/workspace/composables/useAutoPageSize.ts',
|
||||
// Marketing media tooling — adopted by pages in a follow-up PR
|
||||
'apps/website/src/components/common/SiteVideo.vue',
|
||||
'apps/website/src/utils/marketingImage.ts',
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { ZIndex } from '@primeuix/utils/zindex'
|
||||
import type { MenuItem } from 'primevue/menuitem'
|
||||
import {
|
||||
DropdownMenuArrow,
|
||||
@@ -11,15 +12,21 @@ import { computed, ref, toValue } from 'vue'
|
||||
|
||||
import DropdownItem from '@/components/common/DropdownItem.vue'
|
||||
import Button from '@/components/ui/button/Button.vue'
|
||||
import { useModalLiftedZIndex } from '@/composables/useModalLiftedZIndex'
|
||||
import { cn } from '@comfyorg/tailwind-utils'
|
||||
import type { ButtonVariants } from '../ui/button/button.variants'
|
||||
|
||||
// Shared base for @primeuix's auto-incrementing 'modal' z-index counter.
|
||||
const MODAL_BASE_Z_INDEX = 1700
|
||||
|
||||
defineOptions({
|
||||
inheritAttrs: false
|
||||
})
|
||||
|
||||
const { itemClass: itemProp, contentClass: contentProp } = defineProps<{
|
||||
const {
|
||||
itemClass: itemProp,
|
||||
contentClass: contentProp,
|
||||
modal = true
|
||||
} = defineProps<{
|
||||
entries?: MenuItem[]
|
||||
icon?: string
|
||||
to?: string | HTMLElement
|
||||
@@ -27,6 +34,7 @@ const { itemClass: itemProp, contentClass: contentProp } = defineProps<{
|
||||
contentClass?: string
|
||||
buttonSize?: ButtonVariants['size']
|
||||
buttonClass?: string
|
||||
modal?: boolean
|
||||
}>()
|
||||
|
||||
const itemClass = computed(() =>
|
||||
@@ -43,12 +51,19 @@ const contentClass = computed(() =>
|
||||
)
|
||||
)
|
||||
|
||||
// Body-portaled content keeps its static z-1700 unless a dialog that joined
|
||||
// @primeuix's auto-incrementing 'modal' counter is open above it; then lift
|
||||
// past that dialog so the menu isn't hidden behind it.
|
||||
const open = ref(false)
|
||||
const contentStyle = useModalLiftedZIndex(open)
|
||||
const contentStyle = computed(() => {
|
||||
if (!open.value) return undefined
|
||||
const topZIndex = ZIndex.getCurrent('modal')
|
||||
return topZIndex >= MODAL_BASE_Z_INDEX ? { zIndex: topZIndex + 1 } : undefined
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<DropdownMenuRoot v-model:open="open">
|
||||
<DropdownMenuRoot v-model:open="open" :modal>
|
||||
<DropdownMenuTrigger as-child>
|
||||
<slot name="button">
|
||||
<Button :size="buttonSize ?? 'icon'" :class="buttonClass">
|
||||
|
||||
40
src/components/common/SelectionBar.vue
Normal file
40
src/components/common/SelectionBar.vue
Normal file
@@ -0,0 +1,40 @@
|
||||
<template>
|
||||
<div class="relative mx-2">
|
||||
<div
|
||||
class="absolute bottom-6 left-1/2 z-40 flex w-full max-w-78 -translate-x-1/2 items-center gap-2 rounded-lg bg-base-foreground p-2 text-base-background shadow-interface"
|
||||
>
|
||||
<Button
|
||||
v-tooltip.top="{ value: deselectLabel, showDelay: 300 }"
|
||||
variant="inverted"
|
||||
size="icon-lg"
|
||||
type="button"
|
||||
:aria-label="deselectLabel"
|
||||
class="rounded-lg hover:bg-base-background/10"
|
||||
@click="emit('deselect')"
|
||||
>
|
||||
<i class="icon-[lucide--x] size-4" />
|
||||
</Button>
|
||||
<span class="pr-6 text-sm font-bold whitespace-nowrap tabular-nums">
|
||||
{{ label }}
|
||||
</span>
|
||||
<div class="ml-auto flex shrink-0 items-center gap-1">
|
||||
<slot />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import Button from '@/components/ui/button/Button.vue'
|
||||
|
||||
defineProps<{
|
||||
/** The "N selected" text; the caller formats it (pluralization, wording). */
|
||||
label: string
|
||||
/** Accessible label + tooltip for the deselect button. */
|
||||
deselectLabel: string
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
deselect: []
|
||||
}>()
|
||||
</script>
|
||||
@@ -14,7 +14,7 @@
|
||||
class="p-1 text-amber-400"
|
||||
>
|
||||
<template #icon>
|
||||
<i class="icon-[lucide--component]" />
|
||||
<i class="icon-[lucide--coins]" />
|
||||
</template>
|
||||
</Tag>
|
||||
<div :class="textClass">
|
||||
|
||||
@@ -449,6 +449,12 @@ describe('shouldPreventRekaDismiss', () => {
|
||||
expect(event.defaultPrevented).toBe(false)
|
||||
})
|
||||
|
||||
it('focus-outside never dismisses when dismissOnFocusOutside is false', () => {
|
||||
const event = makeEvent(document.body)
|
||||
onRekaFocusOutside(event, { dismissOnFocusOutside: false })
|
||||
expect(event.defaultPrevented).toBe(true)
|
||||
})
|
||||
|
||||
it('focus-outside on a sibling Reka portal does not dismiss the parent', () => {
|
||||
const portal = document.createElement('div')
|
||||
portal.setAttribute('role', 'dialog')
|
||||
|
||||
@@ -32,7 +32,9 @@
|
||||
dialogStore.activeKey === item.key
|
||||
)
|
||||
"
|
||||
@focus-outside="onRekaFocusOutside"
|
||||
@focus-outside="
|
||||
(e) => onRekaFocusOutside(e, item.dialogComponentProps)
|
||||
"
|
||||
@mousedown="() => dialogStore.riseDialog({ key: item.key })"
|
||||
>
|
||||
<template v-if="item.dialogComponentProps.headless">
|
||||
|
||||
@@ -86,7 +86,7 @@
|
||||
@max-reached="showCeilingWarning = true"
|
||||
>
|
||||
<template #prefix>
|
||||
<i class="icon-[lucide--component] size-4 shrink-0 text-gold-500" />
|
||||
<i class="icon-[lucide--coins] size-4 shrink-0 text-gold-500" />
|
||||
</template>
|
||||
</FormattedNumberStepper>
|
||||
</div>
|
||||
@@ -98,7 +98,7 @@
|
||||
v-if="isBelowMin"
|
||||
class="m-0 flex items-center justify-center gap-1 px-8 pt-4 text-center text-sm text-red-500"
|
||||
>
|
||||
<i class="icon-[lucide--component] size-4" />
|
||||
<i class="icon-[lucide--coins] size-4" />
|
||||
{{
|
||||
$t('credits.topUp.minRequired', {
|
||||
credits: formatNumber(usdToCredits(MIN_AMOUNT))
|
||||
@@ -109,7 +109,7 @@
|
||||
v-if="showCeilingWarning"
|
||||
class="m-0 flex items-center justify-center gap-1 px-8 pt-4 text-center text-sm text-gold-500"
|
||||
>
|
||||
<i class="icon-[lucide--component] size-4" />
|
||||
<i class="icon-[lucide--coins] size-4" />
|
||||
{{
|
||||
$t('credits.topUp.maxAllowed', {
|
||||
credits: formatNumber(usdToCredits(MAX_AMOUNT))
|
||||
|
||||
@@ -12,7 +12,7 @@ const PRIMEVUE_OVERLAY_SELECTORS =
|
||||
// dismiss itself. These selectors cover the portaled roots so we can treat
|
||||
// interactions on them as inside.
|
||||
const REKA_PORTAL_SELECTORS =
|
||||
'[data-reka-popper-content-wrapper], [data-reka-dialog-content], [data-reka-menu-content], [data-reka-context-menu-content], [role="dialog"], [role="menu"], [role="listbox"], [role="tooltip"]'
|
||||
'[data-reka-popper-content-wrapper], [data-reka-dialog-content], [data-reka-menu-content], [data-reka-context-menu-content], [role="dialog"], [role="menu"], [role="listbox"], [role="tooltip"], [aria-haspopup="menu"], [aria-haspopup="dialog"], [aria-haspopup="listbox"]'
|
||||
|
||||
const OUTSIDE_LAYER_SELECTORS = `${PRIMEVUE_OVERLAY_SELECTORS}, ${REKA_PORTAL_SELECTORS}`
|
||||
|
||||
@@ -53,7 +53,22 @@ export function onRekaPointerDownOutside(
|
||||
// nested Reka or PrimeVue dialog teleported to body). Without this guard a
|
||||
// non-modal Reka dialog would dismiss itself the moment a nested dialog
|
||||
// receives focus.
|
||||
export function onRekaFocusOutside(event: OutsideEvent) {
|
||||
//
|
||||
// A container dialog (e.g. Settings) that hosts nested confirm/edit dialogs can
|
||||
// also lose focus to an ordinary app element — not just a portal — when a
|
||||
// nested dialog closes and the element it focused was removed (deleting the
|
||||
// selected row). That programmatic focus shift is not a dismiss intent, so such
|
||||
// a dialog opts out of focus-outside dismissal entirely via
|
||||
// `dismissOnFocusOutside: false`; it still dismisses on escape or an outside
|
||||
// pointer.
|
||||
export function onRekaFocusOutside(
|
||||
event: OutsideEvent,
|
||||
options: { dismissOnFocusOutside?: boolean } = {}
|
||||
) {
|
||||
if (options.dismissOnFocusOutside === false) {
|
||||
event.preventDefault()
|
||||
return
|
||||
}
|
||||
if (isInsideOverlay(event.detail.originalEvent.target)) {
|
||||
event.preventDefault()
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
)
|
||||
"
|
||||
>
|
||||
<i class="icon-[lucide--component] h-full bg-amber-400" />
|
||||
<i class="icon-[lucide--coins] h-full bg-amber-400" />
|
||||
<span class="truncate" v-text="text" />
|
||||
</span>
|
||||
<span
|
||||
|
||||
@@ -51,7 +51,7 @@
|
||||
>
|
||||
<i
|
||||
aria-hidden="true"
|
||||
class="icon-[lucide--component] size-3 text-amber-400"
|
||||
class="icon-[lucide--coins] size-3 text-amber-400"
|
||||
/>
|
||||
<i
|
||||
aria-hidden="true"
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
<template>
|
||||
<div class="flex h-full flex-col">
|
||||
<!-- Assets Grid -->
|
||||
<!-- key on gridMode remounts the virtualizer so it re-measures cell size
|
||||
when switching density (it caches item height/width otherwise). -->
|
||||
<VirtualGrid
|
||||
:key="gridMode"
|
||||
class="flex-1"
|
||||
:items="assetItems"
|
||||
:grid-style="gridStyle"
|
||||
@@ -31,22 +28,13 @@ import { computed } from 'vue'
|
||||
|
||||
import VirtualGrid from '@/components/common/VirtualGrid.vue'
|
||||
import MediaAssetCard from '@/platform/assets/components/MediaAssetCard.vue'
|
||||
import { gridColumnsForMode } from '@/platform/assets/components/mediaAssetViewOptions'
|
||||
import type { MediaAssetViewMode } from '@/platform/assets/components/mediaAssetViewOptions'
|
||||
import type { AssetItem } from '@/platform/assets/schemas/assetSchema'
|
||||
|
||||
const {
|
||||
assets,
|
||||
isSelected,
|
||||
showOutputCount,
|
||||
getOutputCount,
|
||||
gridMode = 'grid-small'
|
||||
} = defineProps<{
|
||||
const { assets, isSelected, showOutputCount, getOutputCount } = defineProps<{
|
||||
assets: AssetItem[]
|
||||
isSelected: (assetId: string) => boolean
|
||||
showOutputCount: (asset: AssetItem) => boolean
|
||||
getOutputCount: (asset: AssetItem) => number
|
||||
gridMode?: MediaAssetViewMode
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
@@ -66,10 +54,10 @@ const assetItems = computed<AssetGridItem[]>(() =>
|
||||
}))
|
||||
)
|
||||
|
||||
const gridStyle = computed(() => ({
|
||||
const gridStyle = {
|
||||
display: 'grid',
|
||||
gridTemplateColumns: gridColumnsForMode(gridMode),
|
||||
gridTemplateColumns: 'repeat(auto-fill, minmax(min(200px, 30vw), 1fr))',
|
||||
padding: '0 0.5rem',
|
||||
gap: '0.5rem'
|
||||
}))
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -39,7 +39,6 @@
|
||||
v-model:sort-by="sortBy"
|
||||
v-model:view-mode="viewMode"
|
||||
v-model:media-type-filters="mediaTypeFilters"
|
||||
v-model:date-filter="dateFilter"
|
||||
bottom-divider
|
||||
:show-generation-time-sort="activeTab === 'output'"
|
||||
/>
|
||||
@@ -86,7 +85,6 @@
|
||||
</div>
|
||||
<div
|
||||
v-else
|
||||
ref="assetPaneRef"
|
||||
class="relative size-full py-2"
|
||||
@click="handleEmptySpaceClick"
|
||||
>
|
||||
@@ -108,7 +106,6 @@
|
||||
:is-selected="isSelected"
|
||||
:show-output-count="shouldShowOutputCount"
|
||||
:get-output-count="getOutputCount"
|
||||
:grid-mode="viewMode"
|
||||
@select-asset="handleAssetSelect"
|
||||
@context-menu="handleAssetContextMenu"
|
||||
@approach-end="handleApproachEnd"
|
||||
@@ -183,13 +180,9 @@ import Button from '@/components/ui/button/Button.vue'
|
||||
import MediaAssetContextMenu from '@/platform/assets/components/MediaAssetContextMenu.vue'
|
||||
import MediaAssetFilterBar from '@/platform/assets/components/MediaAssetFilterBar.vue'
|
||||
import MediaAssetSelectionBar from '@/platform/assets/components/MediaAssetSelectionBar.vue'
|
||||
import type { MediaAssetViewMode } from '@/platform/assets/components/mediaAssetViewOptions'
|
||||
import { getAssetType } from '@/platform/assets/composables/media/assetMappers'
|
||||
import { useAssetsApi } from '@/platform/assets/composables/media/useAssetsApi'
|
||||
import {
|
||||
shouldInterceptSelectAll,
|
||||
useAssetSelection
|
||||
} from '@/platform/assets/composables/useAssetSelection'
|
||||
import { useAssetSelection } from '@/platform/assets/composables/useAssetSelection'
|
||||
import { useMediaAssetActions } from '@/platform/assets/composables/useMediaAssetActions'
|
||||
import { useMediaAssetFiltering } from '@/platform/assets/composables/useMediaAssetFiltering'
|
||||
import { useOutputStacks } from '@/platform/assets/composables/useOutputStacks'
|
||||
@@ -222,16 +215,11 @@ const folderJobId = ref<string | null>(null)
|
||||
const folderExecutionTime = ref<number | undefined>(undefined)
|
||||
const expectedFolderCount = ref(0)
|
||||
const isInFolderView = computed(() => folderJobId.value !== null)
|
||||
const viewMode = useStorage<MediaAssetViewMode>(
|
||||
const viewMode = useStorage<'list' | 'grid'>(
|
||||
'Comfy.Assets.Sidebar.ViewMode',
|
||||
'grid-small'
|
||||
'grid'
|
||||
)
|
||||
// Migrate the pre-split legacy 'grid' value to the dense grid.
|
||||
if (!['list', 'grid-small', 'grid-large'].includes(viewMode.value)) {
|
||||
viewMode.value = 'grid-small'
|
||||
}
|
||||
const isListView = computed(() => viewMode.value === 'list')
|
||||
const assetPaneRef = ref<HTMLElement>()
|
||||
|
||||
const contextMenuRef = ref<InstanceType<typeof MediaAssetContextMenu>>()
|
||||
const contextMenuAsset = ref<AssetItem | null>(null)
|
||||
@@ -272,7 +260,6 @@ const outputAssets = useAssetsApi('output')
|
||||
const {
|
||||
isSelected,
|
||||
handleAssetClick,
|
||||
selectAll,
|
||||
hasSelection,
|
||||
clearSelection,
|
||||
getSelectedAssets,
|
||||
@@ -329,7 +316,7 @@ const baseAssets = computed(() => {
|
||||
})
|
||||
|
||||
// Use media asset filtering composable
|
||||
const { searchQuery, sortBy, mediaTypeFilters, dateFilter, filteredAssets } =
|
||||
const { searchQuery, sortBy, mediaTypeFilters, filteredAssets } =
|
||||
useMediaAssetFiltering(baseAssets)
|
||||
|
||||
const displayAssets = computed(() => {
|
||||
@@ -431,10 +418,8 @@ watch(
|
||||
activeTab,
|
||||
() => {
|
||||
clearSelection()
|
||||
// Clear search + filters when switching tabs so no stale filter hides results.
|
||||
// Clear search when switching tabs
|
||||
searchQuery.value = ''
|
||||
mediaTypeFilters.value = []
|
||||
dateFilter.value = ''
|
||||
// Reset pagination state when tab changes
|
||||
void refreshAssets()
|
||||
},
|
||||
@@ -577,27 +562,12 @@ const exitFolderView = () => {
|
||||
searchQuery.value = ''
|
||||
}
|
||||
|
||||
function handleSelectAllKeydown(event: KeyboardEvent) {
|
||||
if (!shouldInterceptSelectAll(event, assetPaneRef.value)) return
|
||||
// Stop the event before the canvas keybinding handler runs: it is a
|
||||
// bubble-phase window listener whose Comfy.Canvas.SelectAll is scoped to
|
||||
// graph-canvas-container, which the asset pane lives inside — so without this
|
||||
// it would also select every node. Capture phase beats the bubble listener.
|
||||
event.preventDefault()
|
||||
event.stopImmediatePropagation()
|
||||
selectAll(visibleAssets.value)
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
activateSelection()
|
||||
window.addEventListener('keydown', handleSelectAllKeydown, { capture: true })
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
deactivateSelection()
|
||||
window.removeEventListener('keydown', handleSelectAllKeydown, {
|
||||
capture: true
|
||||
})
|
||||
})
|
||||
|
||||
const handleDeselectAll = () => {
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
|
||||
<!-- Credits Section -->
|
||||
<div v-if="isActiveSubscription" class="flex items-center gap-2 px-4 py-2">
|
||||
<i class="icon-[lucide--component] text-sm text-amber-400" />
|
||||
<i class="icon-[lucide--coins] text-sm text-amber-400" />
|
||||
<Skeleton v-if="isLoading" width="4rem" height="1.25rem" class="w-full" />
|
||||
<span v-else class="text-base font-semibold text-base-foreground">{{
|
||||
formattedBalance
|
||||
|
||||
72
src/components/ui/pagination/Pagination.vue
Normal file
72
src/components/ui/pagination/Pagination.vue
Normal file
@@ -0,0 +1,72 @@
|
||||
<template>
|
||||
<PaginationRoot
|
||||
:page="page"
|
||||
:total="total"
|
||||
:items-per-page="itemsPerPage"
|
||||
:sibling-count="1"
|
||||
show-edges
|
||||
@update:page="(p: number) => emit('update:page', p)"
|
||||
>
|
||||
<div class="flex items-center gap-1">
|
||||
<PaginationPrev as-child>
|
||||
<Button variant="muted-textonly" size="md" class="text-sm">
|
||||
<i class="icon-[lucide--chevron-left] size-4" />
|
||||
{{ $t('g.previous') }}
|
||||
</Button>
|
||||
</PaginationPrev>
|
||||
<PaginationList v-slot="{ items }" class="flex items-center gap-1">
|
||||
<template v-for="(item, index) in items" :key="index">
|
||||
<PaginationListItem
|
||||
v-if="item.type === 'page'"
|
||||
:value="item.value"
|
||||
as-child
|
||||
>
|
||||
<Button
|
||||
:variant="item.value === page ? 'secondary' : 'muted-textonly'"
|
||||
size="icon"
|
||||
>
|
||||
{{ item.value }}
|
||||
</Button>
|
||||
</PaginationListItem>
|
||||
<PaginationEllipsis v-else :index="index" :class="ellipsisClass">
|
||||
…
|
||||
</PaginationEllipsis>
|
||||
</template>
|
||||
</PaginationList>
|
||||
<PaginationNext as-child>
|
||||
<Button variant="muted-textonly" size="md" class="text-sm">
|
||||
{{ $t('g.next') }}
|
||||
<i class="icon-[lucide--chevron-right] size-4" />
|
||||
</Button>
|
||||
</PaginationNext>
|
||||
</div>
|
||||
</PaginationRoot>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
PaginationEllipsis,
|
||||
PaginationList,
|
||||
PaginationListItem,
|
||||
PaginationNext,
|
||||
PaginationPrev,
|
||||
PaginationRoot
|
||||
} from 'reka-ui'
|
||||
|
||||
import Button from '@/components/ui/button/Button.vue'
|
||||
|
||||
const {
|
||||
page = 1,
|
||||
total,
|
||||
itemsPerPage = 10
|
||||
} = defineProps<{
|
||||
page?: number
|
||||
total: number
|
||||
itemsPerPage?: number
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{ 'update:page': [page: number] }>()
|
||||
|
||||
const ellipsisClass =
|
||||
'inline-flex size-8 items-center justify-center text-sm text-muted-foreground'
|
||||
</script>
|
||||
@@ -35,7 +35,7 @@ export const searchInputSizeConfig = {
|
||||
icon: 'size-4',
|
||||
iconPos: 'left-2.5',
|
||||
inputPl: 'pl-8',
|
||||
inputText: 'text-xs',
|
||||
inputText: 'text-sm',
|
||||
clearPos: 'left-2.5'
|
||||
},
|
||||
xl: {
|
||||
|
||||
30
src/components/ui/switch/Switch.vue
Normal file
30
src/components/ui/switch/Switch.vue
Normal file
@@ -0,0 +1,30 @@
|
||||
<template>
|
||||
<SwitchRoot
|
||||
v-model="checked"
|
||||
:disabled
|
||||
:class="
|
||||
cn(
|
||||
'inline-flex h-5 w-9 shrink-0 cursor-pointer items-center rounded-full border border-transparent px-0.5 transition-colors focus-visible:ring-2 focus-visible:ring-primary/50 focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50',
|
||||
checked ? 'bg-primary' : 'bg-interface-stroke'
|
||||
)
|
||||
"
|
||||
>
|
||||
<SwitchThumb
|
||||
:class="
|
||||
cn(
|
||||
'pointer-events-none block size-4 rounded-full bg-white shadow-sm transition-transform',
|
||||
checked ? 'translate-x-3.5' : 'translate-x-0'
|
||||
)
|
||||
"
|
||||
/>
|
||||
</SwitchRoot>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { SwitchRoot, SwitchThumb } from 'reka-ui'
|
||||
|
||||
import { cn } from '@comfyorg/tailwind-utils'
|
||||
|
||||
const { disabled = false } = defineProps<{ disabled?: boolean }>()
|
||||
const checked = defineModel<boolean>({ default: false })
|
||||
</script>
|
||||
17
src/components/ui/table/Table.vue
Normal file
17
src/components/ui/table/Table.vue
Normal file
@@ -0,0 +1,17 @@
|
||||
<template>
|
||||
<div :class="cn('relative w-full overflow-auto', className)">
|
||||
<table
|
||||
class="w-full caption-bottom border-separate border-spacing-0 text-sm"
|
||||
>
|
||||
<slot />
|
||||
</table>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import type { HTMLAttributes } from 'vue'
|
||||
|
||||
import { cn } from '@comfyorg/tailwind-utils'
|
||||
|
||||
const { class: className } = defineProps<{ class?: HTMLAttributes['class'] }>()
|
||||
</script>
|
||||
13
src/components/ui/table/TableBody.vue
Normal file
13
src/components/ui/table/TableBody.vue
Normal file
@@ -0,0 +1,13 @@
|
||||
<template>
|
||||
<tbody :class="cn('[&_tr:last-child]:border-0', className)">
|
||||
<slot />
|
||||
</tbody>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import type { HTMLAttributes } from 'vue'
|
||||
|
||||
import { cn } from '@comfyorg/tailwind-utils'
|
||||
|
||||
const { class: className } = defineProps<{ class?: HTMLAttributes['class'] }>()
|
||||
</script>
|
||||
13
src/components/ui/table/TableCell.vue
Normal file
13
src/components/ui/table/TableCell.vue
Normal file
@@ -0,0 +1,13 @@
|
||||
<template>
|
||||
<td :class="cn('px-2 py-2.5 align-middle whitespace-nowrap', className)">
|
||||
<slot />
|
||||
</td>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import type { HTMLAttributes } from 'vue'
|
||||
|
||||
import { cn } from '@comfyorg/tailwind-utils'
|
||||
|
||||
const { class: className } = defineProps<{ class?: HTMLAttributes['class'] }>()
|
||||
</script>
|
||||
21
src/components/ui/table/TableHead.vue
Normal file
21
src/components/ui/table/TableHead.vue
Normal file
@@ -0,0 +1,21 @@
|
||||
<template>
|
||||
<th
|
||||
scope="col"
|
||||
:class="
|
||||
cn(
|
||||
'h-10 px-2 text-left align-middle text-sm font-normal whitespace-nowrap text-muted-foreground',
|
||||
className
|
||||
)
|
||||
"
|
||||
>
|
||||
<slot />
|
||||
</th>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import type { HTMLAttributes } from 'vue'
|
||||
|
||||
import { cn } from '@comfyorg/tailwind-utils'
|
||||
|
||||
const { class: className } = defineProps<{ class?: HTMLAttributes['class'] }>()
|
||||
</script>
|
||||
15
src/components/ui/table/TableHeader.vue
Normal file
15
src/components/ui/table/TableHeader.vue
Normal file
@@ -0,0 +1,15 @@
|
||||
<template>
|
||||
<thead
|
||||
:class="cn('[&_tr]:border-b [&_tr]:border-interface-stroke/60', className)"
|
||||
>
|
||||
<slot />
|
||||
</thead>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import type { HTMLAttributes } from 'vue'
|
||||
|
||||
import { cn } from '@comfyorg/tailwind-utils'
|
||||
|
||||
const { class: className } = defineProps<{ class?: HTMLAttributes['class'] }>()
|
||||
</script>
|
||||
20
src/components/ui/table/TableRow.vue
Normal file
20
src/components/ui/table/TableRow.vue
Normal file
@@ -0,0 +1,20 @@
|
||||
<template>
|
||||
<tr
|
||||
:class="
|
||||
cn(
|
||||
'border-b border-interface-stroke/60 transition-colors hover:bg-secondary-background/50 data-[state=selected]:bg-secondary-background/50',
|
||||
className
|
||||
)
|
||||
"
|
||||
>
|
||||
<slot />
|
||||
</tr>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import type { HTMLAttributes } from 'vue'
|
||||
|
||||
import { cn } from '@comfyorg/tailwind-utils'
|
||||
|
||||
const { class: className } = defineProps<{ class?: HTMLAttributes['class'] }>()
|
||||
</script>
|
||||
@@ -14,7 +14,12 @@
|
||||
>
|
||||
<header
|
||||
data-component-id="LeftPanelHeader"
|
||||
class="flex h-18 w-full shrink-0 items-center-safe gap-2 pr-3 pl-6"
|
||||
:class="
|
||||
cn(
|
||||
'flex h-18 w-full shrink-0 items-center-safe gap-2 pr-3 pl-6',
|
||||
headerHeightClass
|
||||
)
|
||||
"
|
||||
>
|
||||
<slot name="leftPanelHeaderTitle" />
|
||||
<Button
|
||||
@@ -33,7 +38,12 @@
|
||||
<div class="flex flex-col overflow-hidden bg-base-background">
|
||||
<header
|
||||
v-if="$slots.header"
|
||||
class="flex h-18 w-full items-center justify-between gap-2 px-6"
|
||||
:class="
|
||||
cn(
|
||||
'flex h-18 w-full items-center justify-between gap-2 px-6',
|
||||
headerHeightClass
|
||||
)
|
||||
"
|
||||
>
|
||||
<div class="flex min-w-0 flex-1 gap-2">
|
||||
<Button
|
||||
@@ -151,20 +161,22 @@ const SIZE_CLASSES = {
|
||||
} as const
|
||||
|
||||
type ModalSize = keyof typeof SIZE_CLASSES
|
||||
type ContentPadding = 'default' | 'compact' | 'none'
|
||||
type ContentPadding = 'default' | 'compact' | 'none' | 'flush'
|
||||
|
||||
const {
|
||||
contentTitle,
|
||||
rightPanelTitle,
|
||||
size = 'lg',
|
||||
leftPanelWidth = '14rem',
|
||||
contentPadding = 'default'
|
||||
contentPadding = 'default',
|
||||
headerHeightClass = 'h-18'
|
||||
} = defineProps<{
|
||||
contentTitle: string
|
||||
rightPanelTitle?: string
|
||||
size?: ModalSize
|
||||
leftPanelWidth?: string
|
||||
contentPadding?: ContentPadding
|
||||
headerHeightClass?: string
|
||||
}>()
|
||||
|
||||
const sizeClasses = computed(() => SIZE_CLASSES[size])
|
||||
@@ -204,7 +216,10 @@ const contentContainerClass = computed(() =>
|
||||
cn(
|
||||
'flex scrollbar-custom min-h-0 flex-1 flex-col overflow-y-auto',
|
||||
contentPadding === 'default' && 'px-6 pt-0 pb-10',
|
||||
contentPadding === 'compact' && 'px-6 pt-0 pb-2'
|
||||
contentPadding === 'compact' && 'px-6 pt-0 pb-2',
|
||||
// Keep the horizontal inset but let content run to the bottom edge (it
|
||||
// clips there instead of ending above a padding gap).
|
||||
contentPadding === 'flush' && 'px-6 pt-0'
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@@ -107,6 +107,8 @@ export interface BillingState {
|
||||
|
||||
export interface BillingContext extends BillingState, BillingActions {
|
||||
type: ComputedRef<BillingType>
|
||||
/** Subscription paused on a failed payment (`subscriptionStatus === 'paused'`). */
|
||||
isPaused: ComputedRef<boolean>
|
||||
/**
|
||||
* True when the active team workspace is still on a pre-credit-slider
|
||||
* (legacy) per-member tier plan, which keeps the old team pricing table.
|
||||
|
||||
@@ -147,6 +147,7 @@ function useBillingContextInternal(): BillingContext {
|
||||
const subscriptionStatus = computed(() =>
|
||||
toValue(activeContext.value.subscriptionStatus)
|
||||
)
|
||||
const isPaused = computed(() => subscriptionStatus.value === 'paused')
|
||||
const tier = computed(() => toValue(activeContext.value.tier))
|
||||
const renewalDate = computed(() => toValue(activeContext.value.renewalDate))
|
||||
|
||||
@@ -301,6 +302,7 @@ function useBillingContextInternal(): BillingContext {
|
||||
isLegacyTeamPlan,
|
||||
billingStatus,
|
||||
subscriptionStatus,
|
||||
isPaused,
|
||||
tier,
|
||||
renewalDate,
|
||||
getMaxSeats,
|
||||
|
||||
@@ -90,7 +90,9 @@ export function useExternalLink() {
|
||||
githubFrontend: 'https://github.com/Comfy-Org/ComfyUI_frontend',
|
||||
githubElectron: 'https://github.com/Comfy-Org/electron',
|
||||
forum: 'https://forum.comfy.org/',
|
||||
comfyOrg: 'https://www.comfy.org/'
|
||||
comfyOrg: 'https://www.comfy.org/',
|
||||
teamPlanRequests:
|
||||
'https://comfy-org.portal.usepylon.com/forms/team-plan-requests'
|
||||
}
|
||||
|
||||
/** Common doc paths for use with buildDocsUrl */
|
||||
|
||||
@@ -9,7 +9,9 @@ import {
|
||||
updateTextPreviewWidgets
|
||||
} from '@/extensions/core/textPreviewWidgets'
|
||||
import type { ComfyNodeDef } from '@/schemas/nodeDefSchema'
|
||||
import { app } from '@/scripts/app'
|
||||
import { useExtensionService } from '@/services/extensionService'
|
||||
import { getNodeByLocatorId } from '@/utils/graphTraversalUtil'
|
||||
|
||||
useExtensionService().registerExtension({
|
||||
name: 'Comfy.PreviewAny',
|
||||
@@ -30,5 +32,11 @@ useExtensionService().registerExtension({
|
||||
onExecuted?.apply(this, [message])
|
||||
updateTextPreviewWidgets(this, message)
|
||||
}
|
||||
},
|
||||
onNodeOutputsUpdated(nodeOutputs) {
|
||||
for (const [nodeLocatorId, output] of Object.entries(nodeOutputs)) {
|
||||
const node = getNodeByLocatorId(app.rootGraph, nodeLocatorId)
|
||||
if (node?.type === 'PreviewAny') updateTextPreviewWidgets(node, output)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -893,8 +893,6 @@
|
||||
"title": "Media Assets",
|
||||
"sortNewestFirst": "Newest first",
|
||||
"sortOldestFirst": "Oldest first",
|
||||
"sortAToZ": "Name (A → Z)",
|
||||
"sortZToA": "Name (Z → A)",
|
||||
"sortLongestFirst": "Generation time (longest first)",
|
||||
"sortFastestFirst": "Generation time (fastest first)",
|
||||
"filterImage": "Image",
|
||||
@@ -902,20 +900,6 @@
|
||||
"filterAudio": "Audio",
|
||||
"filter3D": "3D",
|
||||
"filterText": "Text",
|
||||
"filterBy": "Filter by...",
|
||||
"filterNoMatches": "No matches",
|
||||
"filterMediaType": "Media type",
|
||||
"filterDate": "Date",
|
||||
"filterGroupAttribute": "Attribute",
|
||||
"dateAll": "All time",
|
||||
"dateToday": "Today",
|
||||
"datePastWeek": "Past 7 days",
|
||||
"datePastMonth": "Past 30 days",
|
||||
"dateThisYear": "This year",
|
||||
"clearFilters": "Clear all",
|
||||
"removeFilter": "Remove {label} filter",
|
||||
"viewGridSmall": "Grid (small)",
|
||||
"viewGridLarge": "Grid (large)",
|
||||
"viewSettings": "View settings"
|
||||
},
|
||||
"backToAssets": "Back to all assets",
|
||||
@@ -1000,6 +984,7 @@
|
||||
"currentNode": "Current node:",
|
||||
"viewAllJobs": "View all jobs",
|
||||
"viewList": "List view",
|
||||
"viewGrid": "Grid view",
|
||||
"running": "running",
|
||||
"preview": "Preview",
|
||||
"interruptAll": "Interrupt all running jobs",
|
||||
@@ -2608,7 +2593,7 @@
|
||||
"additionalCreditsInfo": "About additional credits",
|
||||
"additionalCredits": "Additional credits",
|
||||
"additionalCreditsInUse": "In use",
|
||||
"usedAfterMonthly": "Used after monthly runs out",
|
||||
"usedAfterMonthly": "Used after plan credits run out",
|
||||
"monthlyCreditsUsedUpTitle": "Monthly credits are used up. Refills {date}",
|
||||
"monthlyCreditsUsedUpTitleNoDate": "Monthly credits are used up",
|
||||
"monthlyCreditsUsedUpDescription": "You're now spending additional credits.",
|
||||
@@ -2846,7 +2831,10 @@
|
||||
"planUpdated": "Your plan has been successfully updated.",
|
||||
"receiptEmailed": "A receipt has been emailed to you.",
|
||||
"sendInvites": "Send invites"
|
||||
}
|
||||
},
|
||||
"enterprisePlanName": "Enterprise",
|
||||
"percentUsed": "{percent}% used",
|
||||
"usageProgress": "{used} of {total} credits used"
|
||||
},
|
||||
"userSettings": {
|
||||
"title": "My Account Settings",
|
||||
@@ -2861,7 +2849,7 @@
|
||||
"workspacePanel": {
|
||||
"invite": "Invite",
|
||||
"inviteMember": "Invite member",
|
||||
"inviteLimitReached": "You've reached the maximum of {count} members",
|
||||
"inviteLimitReached": "Your workspace is at the member limit",
|
||||
"tabs": {
|
||||
"dashboard": "Dashboard",
|
||||
"planCredits": "Plan & Credits",
|
||||
@@ -2876,12 +2864,17 @@
|
||||
"pendingInvitesCount": "{count} pending invite | {count} pending invites",
|
||||
"tabs": {
|
||||
"active": "Active",
|
||||
"pendingCount": "Pending ({count})"
|
||||
"pendingCount": "Pending ({count})",
|
||||
"membersCount": "Members ({count})",
|
||||
"pending": "Pending"
|
||||
},
|
||||
"columns": {
|
||||
"inviteDate": "Invite date",
|
||||
"expiryDate": "Expiry date",
|
||||
"role": "Role"
|
||||
"role": "Role",
|
||||
"creditsUsed": "Credits used this month",
|
||||
"email": "Email",
|
||||
"lastActivity": "Last activity"
|
||||
},
|
||||
"actions": {
|
||||
"resendInvite": "Resend invite",
|
||||
@@ -2897,14 +2890,22 @@
|
||||
"contactUs": "Contact us",
|
||||
"noInvites": "No pending invites",
|
||||
"noMembers": "No members",
|
||||
"searchPlaceholder": "Search..."
|
||||
"searchPlaceholder": "Search...",
|
||||
"activity": {
|
||||
"daysAgo": "{count} day ago | {count} days ago",
|
||||
"hoursAgo": "{n} hr ago",
|
||||
"justNow": "just now",
|
||||
"minutesAgo": "{n} min ago"
|
||||
},
|
||||
"membersUsage": "{count} of {max} total members."
|
||||
},
|
||||
"menu": {
|
||||
"editWorkspace": "Edit workspace details",
|
||||
"leaveWorkspace": "Leave Workspace",
|
||||
"deleteWorkspace": "Delete Workspace",
|
||||
"deleteWorkspaceDisabledTooltip": "Cancel your workspace's active subscription first",
|
||||
"creatorCannotLeave": "The workspace creator can't leave the workspace they created"
|
||||
"creatorCannotLeave": "The workspace creator can't leave the workspace they created",
|
||||
"renameWorkspace": "Rename Workspace"
|
||||
},
|
||||
"editWorkspaceDialog": {
|
||||
"title": "Edit workspace details",
|
||||
@@ -2993,6 +2994,71 @@
|
||||
"failedToDeleteWorkspace": "Failed to delete workspace",
|
||||
"failedToLeaveWorkspace": "Failed to leave workspace",
|
||||
"failedToFetchWorkspaces": "Failed to load workspaces"
|
||||
},
|
||||
"charactersLeft": "{count} character left | {count} characters left",
|
||||
"doubleClickToRename": "Double-click to rename",
|
||||
"editWorkspaceImage": "Edit workspace image",
|
||||
"memberLimitDialog": {
|
||||
"message": "All seats are filled. To invite someone new, remove a member, rescind an invite, or request more seats.",
|
||||
"title": "Workspace is at the member limit"
|
||||
},
|
||||
"requestMore": "Request more",
|
||||
"workflowQueuedDialog": {
|
||||
"message": "Max workflow capacity reached. It'll start automatically as capacity opens up. If this happens often, you can also request for more capacity.",
|
||||
"title": "Your workflow is queued"
|
||||
},
|
||||
"billingStatus": {
|
||||
"ending": {
|
||||
"body": "Members keep full access until then. Reactivate to keep your shared credits and seats.",
|
||||
"reactivate": "Reactivate plan",
|
||||
"title": "Your team plan ends on {date}"
|
||||
},
|
||||
"outOfCredits": {
|
||||
"addCredits": "Add credits",
|
||||
"body": "Your team has used all its credits. Add more credits to continue generating or wait until credits refill on {date}.",
|
||||
"bodyNoDate": "Your team has used all its credits. Add more credits to continue generating.",
|
||||
"dismiss": "Dismiss",
|
||||
"title": "Out of credits"
|
||||
},
|
||||
"paused": {
|
||||
"body": "This workspace's subscription is paused. Update payment to resume.",
|
||||
"memberBody": "This workspace's subscription is paused. Your workspace admins need to update the payment method.",
|
||||
"title": "Subscription paused"
|
||||
},
|
||||
"updatePayment": "Update payment",
|
||||
"warning": {
|
||||
"body": "Your last payment didn't go through. Your subscription will pause on {date} unless payment is updated.",
|
||||
"title": "Payment declined"
|
||||
}
|
||||
},
|
||||
"overview": {
|
||||
"changePlan": "Change plan",
|
||||
"inactive": {
|
||||
"reactivate": "Reactivate plan",
|
||||
"subtitle": "Reactivate your team plan to add more members and run workflows",
|
||||
"subtitleEnterprise": "Reactivate your enterprise plan to add more members and run workflows",
|
||||
"title": "Inactive team subscription",
|
||||
"titleEnterprise": "Inactive enterprise subscription"
|
||||
},
|
||||
"learnMore": "Learn more",
|
||||
"managePayment": "Manage payment",
|
||||
"messageSupport": "Message support",
|
||||
"paused": "Paused",
|
||||
"perMonth": "mo",
|
||||
"pricingTable": "Partner Nodes pricing table",
|
||||
"renewsOn": "Renews on {date}",
|
||||
"seeMore": "See more",
|
||||
"snapshot": {
|
||||
"creditsUsed": "Credits used",
|
||||
"empty": {
|
||||
"recentActivity": "No activity yet",
|
||||
"topSpenders": "No credits used yet this month"
|
||||
},
|
||||
"lastActivity": "Last activity",
|
||||
"recentActivity": "Recent activity",
|
||||
"topSpenders": "Top spenders",
|
||||
"user": "User"
|
||||
}
|
||||
}
|
||||
},
|
||||
"teamWorkspacesDialog": {
|
||||
@@ -3005,7 +3071,7 @@
|
||||
"newWorkspace": "New workspace",
|
||||
"namePlaceholder": "e.g. Marketing Team",
|
||||
"createWorkspace": "Create workspace",
|
||||
"nameValidationError": "Name must be 1–50 characters using letters, numbers, spaces, or common punctuation."
|
||||
"nameValidationError": "Name must be 1–30 characters using letters, numbers, spaces, or common punctuation."
|
||||
},
|
||||
"workspaceSwitcher": {
|
||||
"switchWorkspace": "Switch workspace",
|
||||
@@ -3015,7 +3081,8 @@
|
||||
"roleMember": "Member",
|
||||
"createWorkspace": "Create a workspace",
|
||||
"maxWorkspacesReached": "You can only own 10 workspaces. Delete one to create a new one.",
|
||||
"failedToSwitch": "Failed to switch workspace"
|
||||
"failedToSwitch": "Failed to switch workspace",
|
||||
"roleAdmin": "Admin"
|
||||
},
|
||||
"selectionToolbox": {
|
||||
"executeButton": {
|
||||
@@ -3137,57 +3204,52 @@
|
||||
"cloudOnboarding": {
|
||||
"skipToCloudApp": "Skip to the cloud app",
|
||||
"survey": {
|
||||
"title": "Cloud Survey",
|
||||
"title": "Let's get to know you",
|
||||
"placeholder": "Survey questions placeholder",
|
||||
"intro": "Help us tailor your ComfyUI experience.",
|
||||
"intro": "A few quick questions so we can set up ComfyUI for you.",
|
||||
"otherPlaceholder": "Tell us more",
|
||||
"errors": {
|
||||
"chooseAnOption": "Please choose an option.",
|
||||
"selectAtLeastOne": "Please select at least one option.",
|
||||
"describeAnswer": "Please describe your answer."
|
||||
},
|
||||
"steps": {
|
||||
"usage": "How do you plan to use ComfyUI?",
|
||||
"familiarity": "How familiar are you with ComfyUI?",
|
||||
"intent": "What do you want to create with ComfyUI?",
|
||||
"source": "Where did you hear about ComfyUI?"
|
||||
"describeAnswer": "Please describe your answer.",
|
||||
"answerTooLong": "Please keep your answer under {max} characters."
|
||||
},
|
||||
"options": {
|
||||
"usage": {
|
||||
"personal": "Personal use",
|
||||
"work": "Work",
|
||||
"education": "Education (student or educator)"
|
||||
},
|
||||
"familiarity": {
|
||||
"new": "New — never used it",
|
||||
"starting": "Beginner — following tutorials",
|
||||
"basics": "Intermediate — comfortable with basics",
|
||||
"advanced": "Advanced — build and edit workflows",
|
||||
"expert": "Expert — I help others"
|
||||
},
|
||||
"intent": {
|
||||
"workflows": "Custom workflows or pipelines",
|
||||
"custom_nodes": "Custom nodes",
|
||||
"videos": "Videos",
|
||||
"images": "Images",
|
||||
"3d_game": "3D assets / game assets",
|
||||
"audio": "Audio / music",
|
||||
"apps": "Simplified Apps from workflows",
|
||||
"api": "API endpoints to run workflows",
|
||||
"not_sure": "Not sure"
|
||||
"video": "Video",
|
||||
"workflows": "Workflows and pipelines",
|
||||
"apps_api": "Apps and APIs",
|
||||
"exploring": "Just exploring",
|
||||
"other": "Something else",
|
||||
"otherPlaceholder": "What do you want to make?"
|
||||
},
|
||||
"experience": {
|
||||
"new": "New to ComfyUI",
|
||||
"some": "I know my way around",
|
||||
"pro": "I'm a power user"
|
||||
},
|
||||
"focus": {
|
||||
"custom_nodes": "Custom nodes",
|
||||
"pipelines": "Automated pipelines",
|
||||
"products": "Products for others"
|
||||
},
|
||||
"source": {
|
||||
"social": "Social media",
|
||||
"friend": "A friend or colleague",
|
||||
"search": "Web search",
|
||||
"community": "A community or forum",
|
||||
"other": "Somewhere else",
|
||||
"otherPlaceholder": "Where did you find us?"
|
||||
},
|
||||
"source_social": {
|
||||
"youtube": "YouTube",
|
||||
"reddit": "Reddit",
|
||||
"twitter": "Twitter / X",
|
||||
"twitter": "X (Twitter)",
|
||||
"instagram": "Instagram",
|
||||
"tiktok": "TikTok",
|
||||
"linkedin": "LinkedIn",
|
||||
"friend": "Friend or colleague",
|
||||
"search": "Google / search",
|
||||
"newsletter": "Newsletter or blog",
|
||||
"conference": "Conference or event",
|
||||
"discord": "Discord / community",
|
||||
"github": "GitHub",
|
||||
"other": "Other"
|
||||
"discord": "Discord"
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -3280,10 +3342,11 @@
|
||||
"cloudForgotPassword_emailRequired": "Email is required",
|
||||
"cloudForgotPassword_passwordResetSent": "Password reset sent",
|
||||
"cloudForgotPassword_passwordResetError": "Failed to send password reset email",
|
||||
"cloudSurvey_steps_usage": "How do you plan to use ComfyUI?",
|
||||
"cloudSurvey_steps_familiarity": "How familiar are you with ComfyUI?",
|
||||
"cloudSurvey_steps_intent": "What do you want to create with ComfyUI?",
|
||||
"cloudSurvey_steps_source": "Where did you hear about ComfyUI?",
|
||||
"cloudSurvey_steps_intent": "What do you want to make?",
|
||||
"cloudSurvey_steps_experience": "How well do you know ComfyUI?",
|
||||
"cloudSurvey_steps_focus": "What are you building?",
|
||||
"cloudSurvey_steps_source": "How did you find us?",
|
||||
"cloudSurvey_steps_source_social": "Which platform?",
|
||||
"assetBrowser": {
|
||||
"allCategory": "All {category}",
|
||||
"allModels": "All Models",
|
||||
@@ -3497,8 +3560,8 @@
|
||||
},
|
||||
"selection": {
|
||||
"selectedCount": "{count} selected",
|
||||
"unselectCount": "Unselect {count}",
|
||||
"multipleSelectedAssets": "Multiple assets selected",
|
||||
"deselectAll": "Deselect all",
|
||||
"downloadSelected": "Download",
|
||||
"downloadSelectedAll": "Download all",
|
||||
"deleteSelected": "Delete",
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
: $t('assetBrowser.ariaLabel.loadingAsset')
|
||||
"
|
||||
:tabindex="loading ? -1 : 0"
|
||||
:aria-pressed="selected"
|
||||
:class="
|
||||
cn(
|
||||
'flex cursor-pointer flex-col overflow-hidden rounded-lg p-2 transition-colors duration-200',
|
||||
@@ -55,19 +54,20 @@
|
||||
<i class="icon-[lucide--trash-2] size-5" />
|
||||
</LoadingOverlay>
|
||||
|
||||
<!-- Action buttons overlay (top-right) -->
|
||||
<!-- Action buttons overlay (top-left) -->
|
||||
<div
|
||||
v-if="showActionsOverlay"
|
||||
class="absolute top-2 right-2 flex flex-wrap justify-end gap-2"
|
||||
class="absolute top-2 left-2 flex flex-wrap justify-start gap-2"
|
||||
>
|
||||
<IconGroup background-class="bg-white">
|
||||
<Button
|
||||
v-if="canInspect"
|
||||
variant="overlay-white"
|
||||
size="icon"
|
||||
:aria-label="$t('mediaAsset.actions.download')"
|
||||
@click.stop="asset && actions.downloadAssets([asset])"
|
||||
:aria-label="$t('mediaAsset.actions.zoom')"
|
||||
@click.stop="handleZoomClick"
|
||||
>
|
||||
<i class="icon-[lucide--download] size-4" />
|
||||
<i class="icon-[lucide--zoom-in] size-4" />
|
||||
</Button>
|
||||
<Button
|
||||
variant="overlay-white"
|
||||
@@ -81,15 +81,6 @@
|
||||
</Button>
|
||||
</IconGroup>
|
||||
</div>
|
||||
|
||||
<!-- Selected check (top-left) -->
|
||||
<div
|
||||
v-if="selected"
|
||||
class="absolute top-2 left-2 flex size-6 items-center justify-center rounded-full bg-white text-black shadow-sm"
|
||||
aria-hidden="true"
|
||||
>
|
||||
<i class="icon-[lucide--check] size-4" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Bottom Area: Media Info -->
|
||||
@@ -110,30 +101,34 @@
|
||||
</div>
|
||||
|
||||
<!-- Content -->
|
||||
<div v-else-if="asset && adaptedAsset" class="flex flex-col gap-1">
|
||||
<!-- Title + output count -->
|
||||
<div class="flex items-center justify-between gap-1.5">
|
||||
<MediaTitle :file-name="fileName" class="min-w-0" />
|
||||
<!-- Output count -->
|
||||
<div v-if="showOutputCount" class="shrink-0">
|
||||
<Button
|
||||
v-tooltip.top.pt:pointer-events-none="
|
||||
$t('mediaAsset.actions.seeMoreOutputs')
|
||||
"
|
||||
:aria-label="$t('mediaAsset.actions.seeMoreOutputs')"
|
||||
variant="secondary"
|
||||
size="sm"
|
||||
@click.stop="handleOutputCountClick"
|
||||
>
|
||||
<i class="icon-[lucide--layers] size-4" />
|
||||
<span>{{ outputCount }}</span>
|
||||
</Button>
|
||||
<div
|
||||
v-else-if="asset && adaptedAsset"
|
||||
class="flex items-end justify-between gap-1.5"
|
||||
>
|
||||
<!-- Left side: Media name and metadata -->
|
||||
<div class="flex flex-col gap-1">
|
||||
<!-- Title -->
|
||||
<MediaTitle :file-name="fileName" />
|
||||
<!-- Metadata -->
|
||||
<div class="flex gap-1.5 text-xs text-muted-foreground">
|
||||
<span v-if="formattedDuration">{{ formattedDuration }}</span>
|
||||
<span v-if="metaInfo">{{ metaInfo }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<!-- File details -->
|
||||
<div class="flex items-center gap-1.5 text-xs text-muted-foreground">
|
||||
<span v-if="formattedDuration">{{ formattedDuration }}</span>
|
||||
<span v-if="metaInfo">{{ metaInfo }}</span>
|
||||
|
||||
<!-- Right side: Output count -->
|
||||
<div v-if="showOutputCount" class="shrink-0">
|
||||
<Button
|
||||
v-tooltip.top.pt:pointer-events-none="
|
||||
$t('mediaAsset.actions.seeMoreOutputs')
|
||||
"
|
||||
:aria-label="$t('mediaAsset.actions.seeMoreOutputs')"
|
||||
variant="secondary"
|
||||
@click.stop="handleOutputCountClick"
|
||||
>
|
||||
<i class="icon-[lucide--layers] size-4" />
|
||||
<span>{{ outputCount }}</span>
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -290,24 +285,16 @@ const displayImageDimensions = computed(() =>
|
||||
resolveDisplayImageDimensions(asset, imageDimensions.value)
|
||||
)
|
||||
|
||||
const format = computed(() => {
|
||||
const suffix = getFilenameDetails(asset?.name ?? '').suffix
|
||||
return suffix ? suffix.toUpperCase() : ''
|
||||
})
|
||||
|
||||
// Meta line: "FORMAT dimensions" for images, otherwise "FORMAT size".
|
||||
// Get metadata info based on file kind
|
||||
const metaInfo = computed(() => {
|
||||
if (!asset) return ''
|
||||
const parts: string[] = []
|
||||
if (format.value) parts.push(format.value)
|
||||
if (fileKind.value === 'image' && displayImageDimensions.value) {
|
||||
parts.push(
|
||||
`${displayImageDimensions.value.width}x${displayImageDimensions.value.height}`
|
||||
)
|
||||
} else if (asset.size) {
|
||||
parts.push(formatSize(asset.size))
|
||||
return `${displayImageDimensions.value.width}x${displayImageDimensions.value.height}`
|
||||
}
|
||||
return parts.join(' ')
|
||||
if (asset.size && ['video', 'audio', '3D'].includes(fileKind.value)) {
|
||||
return formatSize(asset.size)
|
||||
}
|
||||
return ''
|
||||
})
|
||||
|
||||
const showActionsOverlay = computed(() => {
|
||||
|
||||
@@ -1,118 +1,72 @@
|
||||
<template>
|
||||
<div>
|
||||
<SidebarTopArea>
|
||||
<MediaAssetSearchField
|
||||
v-model="searchQuery"
|
||||
:placeholder="
|
||||
$t('g.searchPlaceholder', {
|
||||
subject: $t('sideToolbar.labels.assets')
|
||||
})
|
||||
"
|
||||
/>
|
||||
<template #actions>
|
||||
<MediaAssetFilterMenu
|
||||
v-if="isCloud"
|
||||
v-model:media-type-filters="mediaTypeFilters"
|
||||
v-model:date-filter="dateFilter"
|
||||
:active="hasActiveFilters"
|
||||
/>
|
||||
<MediaAssetSettingsButton
|
||||
v-tooltip.top="{ value: $t('sideToolbar.mediaAssets.viewSettings') }"
|
||||
>
|
||||
<template #default>
|
||||
<MediaAssetSettingsMenu
|
||||
v-model:view-mode="viewMode"
|
||||
v-model:sort-by="sortBy"
|
||||
:show-sort-options="isCloud"
|
||||
:show-generation-time-sort
|
||||
/>
|
||||
</template>
|
||||
</MediaAssetSettingsButton>
|
||||
</template>
|
||||
</SidebarTopArea>
|
||||
|
||||
<MediaAssetFilterChips
|
||||
v-if="filterChips.length"
|
||||
:chips="filterChips"
|
||||
class="px-2 pb-2 2xl:px-4"
|
||||
@remove="removeChip"
|
||||
@clear="clearAllFilters"
|
||||
<SidebarTopArea :bottom-divider>
|
||||
<SearchInput
|
||||
:model-value="searchQuery"
|
||||
:placeholder="
|
||||
$t('g.searchPlaceholder', { subject: $t('sideToolbar.labels.assets') })
|
||||
"
|
||||
@update:model-value="handleSearchChange"
|
||||
/>
|
||||
|
||||
<div
|
||||
v-if="bottomDivider"
|
||||
class="border-t border-dashed border-comfy-input"
|
||||
/>
|
||||
</div>
|
||||
<template #actions>
|
||||
<MediaAssetFilterButton
|
||||
v-if="isCloud"
|
||||
v-tooltip.top="{ value: $t('assetBrowser.filterBy') }"
|
||||
>
|
||||
<template #default="{ close }">
|
||||
<MediaAssetFilterMenu
|
||||
:media-type-filters
|
||||
:close
|
||||
@update:media-type-filters="handleMediaTypeFiltersChange"
|
||||
/>
|
||||
</template>
|
||||
</MediaAssetFilterButton>
|
||||
<MediaAssetSettingsButton
|
||||
v-tooltip.top="{ value: $t('sideToolbar.mediaAssets.viewSettings') }"
|
||||
>
|
||||
<template #default>
|
||||
<MediaAssetSettingsMenu
|
||||
v-model:view-mode="viewMode"
|
||||
v-model:sort-by="sortBy"
|
||||
:show-sort-options="isCloud"
|
||||
:show-generation-time-sort
|
||||
/>
|
||||
</template>
|
||||
</MediaAssetSettingsButton>
|
||||
</template>
|
||||
</SidebarTopArea>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
import SidebarTopArea from '@/components/sidebar/tabs/SidebarTopArea.vue'
|
||||
import SearchInput from '@/components/ui/search-input/SearchInput.vue'
|
||||
import { isCloud } from '@/platform/distribution/types'
|
||||
|
||||
import {
|
||||
DATE_VALUES,
|
||||
MEDIA_TYPE_VALUES,
|
||||
labelKeyForValue
|
||||
} from './mediaAssetFilterFacets'
|
||||
import type { MediaAssetViewMode } from './mediaAssetViewOptions'
|
||||
import type { FilterChipDescriptor } from './MediaAssetFilterChips.vue'
|
||||
import MediaAssetFilterChips from './MediaAssetFilterChips.vue'
|
||||
import MediaAssetFilterButton from './MediaAssetFilterButton.vue'
|
||||
import MediaAssetFilterMenu from './MediaAssetFilterMenu.vue'
|
||||
import MediaAssetSearchField from './MediaAssetSearchField.vue'
|
||||
import MediaAssetSettingsButton from './MediaAssetSettingsButton.vue'
|
||||
import MediaAssetSettingsMenu from './MediaAssetSettingsMenu.vue'
|
||||
import type { SortBy } from './MediaAssetSettingsMenu.vue'
|
||||
|
||||
const { showGenerationTimeSort = false, bottomDivider = false } = defineProps<{
|
||||
searchQuery: string
|
||||
showGenerationTimeSort?: boolean
|
||||
mediaTypeFilters: string[]
|
||||
bottomDivider?: boolean
|
||||
}>()
|
||||
|
||||
const searchQuery = defineModel<string>('searchQuery', { required: true })
|
||||
const emit = defineEmits<{
|
||||
'update:searchQuery': [value: string]
|
||||
'update:mediaTypeFilters': [value: string[]]
|
||||
}>()
|
||||
|
||||
const sortBy = defineModel<SortBy>('sortBy', { required: true })
|
||||
const viewMode = defineModel<MediaAssetViewMode>('viewMode', { required: true })
|
||||
const dateFilter = defineModel<string>('dateFilter', { required: true })
|
||||
const mediaTypeFilters = defineModel<string[]>('mediaTypeFilters', {
|
||||
required: true
|
||||
})
|
||||
const viewMode = defineModel<'list' | 'grid'>('viewMode', { required: true })
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
const filterChips = computed<FilterChipDescriptor[]>(() => {
|
||||
const chips: FilterChipDescriptor[] = mediaTypeFilters.value.map((type) => ({
|
||||
key: `media:${type}`,
|
||||
label: t(labelKeyForValue(MEDIA_TYPE_VALUES, type) ?? type)
|
||||
}))
|
||||
if (dateFilter.value) {
|
||||
chips.push({
|
||||
key: 'date',
|
||||
label: t(
|
||||
labelKeyForValue(DATE_VALUES, dateFilter.value) ?? dateFilter.value
|
||||
)
|
||||
})
|
||||
}
|
||||
return chips
|
||||
})
|
||||
|
||||
const hasActiveFilters = computed(() => filterChips.value.length > 0)
|
||||
|
||||
function removeChip(key: string) {
|
||||
if (key === 'date') {
|
||||
dateFilter.value = ''
|
||||
return
|
||||
}
|
||||
const type = key.slice('media:'.length)
|
||||
mediaTypeFilters.value = mediaTypeFilters.value.filter(
|
||||
(value) => value !== type
|
||||
)
|
||||
const handleSearchChange = (value: string | undefined) => {
|
||||
emit('update:searchQuery', value ?? '')
|
||||
}
|
||||
|
||||
function clearAllFilters() {
|
||||
dateFilter.value = ''
|
||||
mediaTypeFilters.value = []
|
||||
const handleMediaTypeFiltersChange = (value: string[]) => {
|
||||
emit('update:mediaTypeFilters', value)
|
||||
}
|
||||
</script>
|
||||
|
||||
23
src/platform/assets/components/MediaAssetFilterButton.vue
Normal file
23
src/platform/assets/components/MediaAssetFilterButton.vue
Normal file
@@ -0,0 +1,23 @@
|
||||
<template>
|
||||
<div class="inline-flex items-center">
|
||||
<Popover>
|
||||
<template #button>
|
||||
<Button
|
||||
variant="secondary"
|
||||
size="icon"
|
||||
:aria-label="$t('assetBrowser.filterBy')"
|
||||
>
|
||||
<i class="icon-[lucide--list-filter]" />
|
||||
</Button>
|
||||
</template>
|
||||
<template #default="{ close }">
|
||||
<slot :close />
|
||||
</template>
|
||||
</Popover>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import Button from '@/components/ui/button/Button.vue'
|
||||
import Popover from '@/components/ui/Popover.vue'
|
||||
</script>
|
||||
@@ -1,24 +0,0 @@
|
||||
<template>
|
||||
<span
|
||||
class="inline-flex items-center gap-1 rounded-md bg-secondary-background py-1 pr-1 pl-2 text-xs whitespace-nowrap"
|
||||
>
|
||||
<span>{{ label }}</span>
|
||||
<Button
|
||||
variant="textonly"
|
||||
size="icon"
|
||||
class="size-4 rounded-sm p-0 hover:bg-secondary-background-hover"
|
||||
:aria-label="$t('sideToolbar.mediaAssets.removeFilter', { label })"
|
||||
@click="emit('remove')"
|
||||
>
|
||||
<i class="icon-[lucide--x] size-3" />
|
||||
</Button>
|
||||
</span>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import Button from '@/components/ui/button/Button.vue'
|
||||
|
||||
defineProps<{ label: string }>()
|
||||
|
||||
const emit = defineEmits<{ remove: [] }>()
|
||||
</script>
|
||||
@@ -1,35 +0,0 @@
|
||||
<template>
|
||||
<div class="flex flex-wrap items-center gap-1.5">
|
||||
<MediaAssetFilterChip
|
||||
v-for="chip in chips"
|
||||
:key="chip.key"
|
||||
:label="chip.label"
|
||||
@remove="emit('remove', chip.key)"
|
||||
/>
|
||||
<Button
|
||||
variant="textonly"
|
||||
class="h-6 px-1.5 text-xs text-muted-foreground"
|
||||
@click="emit('clear')"
|
||||
>
|
||||
{{ $t('sideToolbar.mediaAssets.clearFilters') }}
|
||||
</Button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import Button from '@/components/ui/button/Button.vue'
|
||||
|
||||
import MediaAssetFilterChip from './MediaAssetFilterChip.vue'
|
||||
|
||||
export interface FilterChipDescriptor {
|
||||
key: string
|
||||
label: string
|
||||
}
|
||||
|
||||
defineProps<{ chips: FilterChipDescriptor[] }>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
remove: [key: string]
|
||||
clear: []
|
||||
}>()
|
||||
</script>
|
||||
@@ -1,122 +1,94 @@
|
||||
import { render, screen } from '@testing-library/vue'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import { createI18n } from 'vue-i18n'
|
||||
|
||||
import enMessages from '@/locales/en/main.json' with { type: 'json' }
|
||||
import MediaAssetFilterMenu from '@/platform/assets/components/MediaAssetFilterMenu.vue'
|
||||
|
||||
const i18n = createI18n({
|
||||
legacy: false,
|
||||
locale: 'en',
|
||||
messages: { en: enMessages }
|
||||
})
|
||||
vi.mock('vue-i18n', () => ({
|
||||
useI18n: () => ({
|
||||
t: (key: string) => key
|
||||
})
|
||||
}))
|
||||
|
||||
interface Overrides {
|
||||
mediaTypeFilters?: string[]
|
||||
dateFilter?: string
|
||||
}
|
||||
|
||||
function renderMenu(overrides: Overrides = {}) {
|
||||
const onMedia = vi.fn()
|
||||
const onDate = vi.fn()
|
||||
function renderMenu(mediaTypeFilters: string[] = []) {
|
||||
const onUpdate = vi.fn()
|
||||
const utils = render(MediaAssetFilterMenu, {
|
||||
props: {
|
||||
mediaTypeFilters: overrides.mediaTypeFilters ?? [],
|
||||
dateFilter: overrides.dateFilter ?? '',
|
||||
'onUpdate:mediaTypeFilters': onMedia,
|
||||
'onUpdate:dateFilter': onDate
|
||||
mediaTypeFilters,
|
||||
'onUpdate:mediaTypeFilters': onUpdate
|
||||
},
|
||||
global: { plugins: [i18n] }
|
||||
global: {
|
||||
mocks: {
|
||||
$t: (key: string) => key
|
||||
}
|
||||
}
|
||||
})
|
||||
return { ...utils, onMedia, onDate, user: userEvent.setup() }
|
||||
return { ...utils, onUpdate, user: userEvent.setup() }
|
||||
}
|
||||
|
||||
const CAT = {
|
||||
media: 'Media type',
|
||||
date: 'Date'
|
||||
const labelByType: Record<string, string> = {
|
||||
image: 'sideToolbar.mediaAssets.filterImage',
|
||||
video: 'sideToolbar.mediaAssets.filterVideo',
|
||||
audio: 'sideToolbar.mediaAssets.filterAudio',
|
||||
'3d': 'sideToolbar.mediaAssets.filter3D',
|
||||
text: 'sideToolbar.mediaAssets.filterText'
|
||||
}
|
||||
|
||||
async function openMenu(user: ReturnType<typeof userEvent.setup>) {
|
||||
await user.click(screen.getByRole('button', { name: 'Filter by' }))
|
||||
}
|
||||
|
||||
function categoryItem(label: string) {
|
||||
return screen.getByRole('menuitem', { name: new RegExp(label) })
|
||||
function getCheckbox(type: keyof typeof labelByType): HTMLElement {
|
||||
return screen.getByRole('checkbox', { name: labelByType[type] })
|
||||
}
|
||||
|
||||
describe('MediaAssetFilterMenu', () => {
|
||||
it('lists every filter category', async () => {
|
||||
const { user } = renderMenu()
|
||||
await openMenu(user)
|
||||
expect(categoryItem(CAT.media)).toBeTruthy()
|
||||
expect(categoryItem(CAT.date)).toBeTruthy()
|
||||
it('renders all media-type checkboxes', () => {
|
||||
renderMenu()
|
||||
|
||||
const checkboxes = screen.getAllByRole('checkbox')
|
||||
expect(checkboxes).toHaveLength(5)
|
||||
for (const type of Object.keys(labelByType)) {
|
||||
expect(getCheckbox(type)).toBeTruthy()
|
||||
}
|
||||
})
|
||||
|
||||
it('surfaces a matching value via flat search and applies it', async () => {
|
||||
const { onMedia, user } = renderMenu()
|
||||
await openMenu(user)
|
||||
await user.type(screen.getByRole('textbox'), 'video')
|
||||
it('reflects checked state from the prop via aria-checked', () => {
|
||||
renderMenu(['image', '3d'])
|
||||
|
||||
await user.click(screen.getByRole('menuitemcheckbox', { name: 'Video' }))
|
||||
expect(onMedia).toHaveBeenCalledWith(['video'])
|
||||
expect(getCheckbox('image').getAttribute('aria-checked')).toBe('true')
|
||||
expect(getCheckbox('3d').getAttribute('aria-checked')).toBe('true')
|
||||
expect(getCheckbox('video').getAttribute('aria-checked')).toBe('false')
|
||||
expect(getCheckbox('audio').getAttribute('aria-checked')).toBe('false')
|
||||
})
|
||||
|
||||
it('applies a date preset via flat search', async () => {
|
||||
const { onDate, user } = renderMenu()
|
||||
await openMenu(user)
|
||||
await user.type(screen.getByRole('textbox'), 'today')
|
||||
it('emits an array containing the new type when an unchecked box is clicked', async () => {
|
||||
const { onUpdate, user } = renderMenu([])
|
||||
await user.click(getCheckbox('video'))
|
||||
|
||||
await user.click(screen.getByRole('menuitemcheckbox', { name: 'Today' }))
|
||||
expect(onDate).toHaveBeenCalledWith('today')
|
||||
expect(onUpdate).toHaveBeenCalledTimes(1)
|
||||
expect(onUpdate).toHaveBeenCalledWith(['video'])
|
||||
})
|
||||
|
||||
it('toggles a date preset off when it is already applied', async () => {
|
||||
const { onDate, user } = renderMenu({ dateFilter: 'today' })
|
||||
await openMenu(user)
|
||||
await user.type(screen.getByRole('textbox'), 'today')
|
||||
it('emits an array without the type when a checked box is clicked again', async () => {
|
||||
const { onUpdate, user } = renderMenu(['image', 'audio'])
|
||||
await user.click(getCheckbox('audio'))
|
||||
|
||||
const row = screen.getByRole('menuitemcheckbox', { name: 'Today' })
|
||||
expect(row).toHaveAttribute('aria-checked', 'true')
|
||||
|
||||
await user.click(row)
|
||||
expect(onDate).toHaveBeenCalledWith('')
|
||||
expect(onUpdate).toHaveBeenCalledWith(['image'])
|
||||
})
|
||||
|
||||
it('moves focus into the results with arrow keys after searching', async () => {
|
||||
const { user } = renderMenu()
|
||||
await openMenu(user)
|
||||
await user.type(screen.getByRole('textbox'), 'a')
|
||||
it('appends to the existing filter list rather than replacing it', async () => {
|
||||
const { onUpdate, user } = renderMenu(['image'])
|
||||
await user.click(getCheckbox('video'))
|
||||
|
||||
const results = screen.getAllByRole('menuitemcheckbox')
|
||||
await user.keyboard('{ArrowDown}')
|
||||
expect(results[0]).toHaveFocus()
|
||||
|
||||
screen.getByRole('textbox').focus()
|
||||
await user.keyboard('{ArrowUp}')
|
||||
expect(results[results.length - 1]).toHaveFocus()
|
||||
expect(onUpdate).toHaveBeenCalledWith(['image', 'video'])
|
||||
})
|
||||
|
||||
it('toggles a media value off when it is already applied', async () => {
|
||||
const { onMedia, user } = renderMenu({ mediaTypeFilters: ['video'] })
|
||||
await openMenu(user)
|
||||
await user.type(screen.getByRole('textbox'), 'video')
|
||||
it('toggles via keyboard (Enter and Space)', async () => {
|
||||
const { onUpdate, user } = renderMenu([])
|
||||
|
||||
const row = screen.getByRole('menuitemcheckbox', { name: 'Video' })
|
||||
expect(row).toHaveAttribute('aria-checked', 'true')
|
||||
getCheckbox('image').focus()
|
||||
await user.keyboard('{Enter}')
|
||||
expect(onUpdate).toHaveBeenLastCalledWith(['image'])
|
||||
|
||||
await user.click(row)
|
||||
expect(onMedia).toHaveBeenCalledWith([])
|
||||
})
|
||||
|
||||
it('shows Clear all and resets every facet when a filter is applied', async () => {
|
||||
const { onMedia, onDate, user } = renderMenu({
|
||||
mediaTypeFilters: ['image'],
|
||||
dateFilter: 'today'
|
||||
})
|
||||
await openMenu(user)
|
||||
await user.click(screen.getByRole('menuitem', { name: 'Clear all' }))
|
||||
expect(onMedia).toHaveBeenCalledWith([])
|
||||
expect(onDate).toHaveBeenCalledWith('')
|
||||
getCheckbox('audio').focus()
|
||||
await user.keyboard(' ')
|
||||
expect(onUpdate).toHaveBeenLastCalledWith(['audio'])
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,327 +1,72 @@
|
||||
<!--
|
||||
TODO: Extract checkbox pattern into reusable Checkbox component
|
||||
- Create src/components/input/Checkbox.vue with:
|
||||
- Hidden native <input type="checkbox"> for accessibility
|
||||
- Custom visual styling matching this implementation
|
||||
- Semantic tokens (--primary-background, --input-surface, etc.)
|
||||
- Use this Checkbox component in:
|
||||
- MediaAssetFilterMenu.vue (this file)
|
||||
- MultiSelect.vue option template
|
||||
- SingleSelect.vue if needed
|
||||
- Benefits: Consistent checkbox UI, better maintainability, reusable design system component
|
||||
-->
|
||||
<template>
|
||||
<DropdownMenuRoot v-model:open="open">
|
||||
<DropdownMenuTrigger as-child>
|
||||
<Button
|
||||
variant="secondary"
|
||||
size="icon"
|
||||
class="relative"
|
||||
:aria-label="$t('assetBrowser.filterBy')"
|
||||
<div class="m-0 flex flex-col gap-0 p-0">
|
||||
<div
|
||||
v-for="filter in filters"
|
||||
:key="filter.type"
|
||||
class="flex h-10 min-w-32 cursor-pointer items-center gap-2 rounded-lg px-2 hover:bg-secondary-background-hover"
|
||||
tabindex="0"
|
||||
role="checkbox"
|
||||
:aria-checked="mediaTypeFilters.includes(filter.type)"
|
||||
@click="toggleMediaType(filter.type)"
|
||||
@keydown.enter.prevent="toggleMediaType(filter.type)"
|
||||
@keydown.space.prevent="toggleMediaType(filter.type)"
|
||||
>
|
||||
<div
|
||||
class="flex size-4 shrink-0 items-center justify-center rounded-sm p-0.5 transition-all duration-200"
|
||||
:class="
|
||||
mediaTypeFilters.includes(filter.type)
|
||||
? 'border-primary-background bg-primary-background'
|
||||
: 'bg-secondary-background'
|
||||
"
|
||||
>
|
||||
<i class="icon-[lucide--list-filter]" />
|
||||
<span
|
||||
v-if="active"
|
||||
class="absolute top-1 right-1 size-1.5 rounded-full bg-primary-background"
|
||||
<i
|
||||
v-if="mediaTypeFilters.includes(filter.type)"
|
||||
class="icon-[lucide--check] text-xs font-bold text-white"
|
||||
/>
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
|
||||
<DropdownMenuPortal>
|
||||
<DropdownMenuContent
|
||||
side="bottom"
|
||||
align="start"
|
||||
:side-offset="6"
|
||||
:collision-padding="10"
|
||||
:style="contentStyle"
|
||||
:class="menuClass"
|
||||
@open-auto-focus.prevent="focusSearch"
|
||||
>
|
||||
<div class="flex h-10 items-center gap-2 px-3">
|
||||
<i
|
||||
class="icon-[lucide--search] size-4 shrink-0 text-muted-foreground"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
<input
|
||||
ref="searchRef"
|
||||
v-model="query"
|
||||
type="text"
|
||||
:placeholder="$t('sideToolbar.mediaAssets.filterBy')"
|
||||
class="min-w-0 flex-1 border-none bg-transparent text-sm text-base-foreground outline-none placeholder:text-muted-foreground"
|
||||
@keydown="onSearchKeydown"
|
||||
/>
|
||||
</div>
|
||||
<DropdownMenuSeparator class="h-px bg-border-subtle" />
|
||||
|
||||
<div class="max-h-80 overflow-y-auto p-1">
|
||||
<template v-if="query.trim()">
|
||||
<template v-for="section in searchSections" :key="section.facet">
|
||||
<DropdownMenuLabel :class="groupLabelClass">
|
||||
{{ catLabel(section.facet) }}
|
||||
</DropdownMenuLabel>
|
||||
<DropdownMenuCheckboxItem
|
||||
v-for="row in section.rows"
|
||||
:key="row.value"
|
||||
:model-value="isApplied(section.facet, row.value)"
|
||||
:class="rowClass"
|
||||
@select.prevent="toggleFacetValue(section.facet, row.value)"
|
||||
>
|
||||
<i :class="cn(CAT_ICON[section.facet], iconClass)" />
|
||||
<span :class="labelClass">{{ row.text }}</span>
|
||||
<i
|
||||
v-if="isApplied(section.facet, row.value)"
|
||||
:class="checkClass"
|
||||
/>
|
||||
</DropdownMenuCheckboxItem>
|
||||
</template>
|
||||
<div
|
||||
v-if="searchSections.length === 0"
|
||||
class="px-2 py-1.5 text-sm text-muted-foreground"
|
||||
>
|
||||
{{ $t('sideToolbar.mediaAssets.filterNoMatches') }}
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template v-else>
|
||||
<template v-for="group in groups" :key="group.key">
|
||||
<DropdownMenuLabel :class="groupLabelClass">
|
||||
{{ $t(group.label) }}
|
||||
</DropdownMenuLabel>
|
||||
<DropdownMenuSub v-for="cat in group.cats" :key="cat">
|
||||
<DropdownMenuSubTrigger
|
||||
:class="
|
||||
cn(
|
||||
rowClass,
|
||||
'data-[state=open]:bg-secondary-background-hover'
|
||||
)
|
||||
"
|
||||
>
|
||||
<i :class="cn(CAT_ICON[cat], iconClass)" />
|
||||
<span :class="labelClass">{{ catLabel(cat) }}</span>
|
||||
<span v-if="appliedCount(cat) > 0" :class="countClass">
|
||||
{{ appliedCount(cat) }}
|
||||
</span>
|
||||
<i
|
||||
class="icon-[lucide--chevron-right] size-4 shrink-0 text-muted-foreground"
|
||||
/>
|
||||
</DropdownMenuSubTrigger>
|
||||
<DropdownMenuPortal>
|
||||
<DropdownMenuSubContent
|
||||
:side-offset="2"
|
||||
:collision-padding="10"
|
||||
:style="contentStyle"
|
||||
:class="menuClass"
|
||||
>
|
||||
<div class="p-1">
|
||||
<DropdownMenuCheckboxItem
|
||||
v-for="opt in valuesFor(cat)"
|
||||
:key="opt.value"
|
||||
:model-value="isApplied(cat, opt.value)"
|
||||
:class="rowClass"
|
||||
@select.prevent="toggleFacetValue(cat, opt.value)"
|
||||
>
|
||||
<span :class="labelClass">{{ opt.text }}</span>
|
||||
<i
|
||||
v-if="isApplied(cat, opt.value)"
|
||||
:class="checkClass"
|
||||
/>
|
||||
</DropdownMenuCheckboxItem>
|
||||
</div>
|
||||
</DropdownMenuSubContent>
|
||||
</DropdownMenuPortal>
|
||||
</DropdownMenuSub>
|
||||
</template>
|
||||
</template>
|
||||
</div>
|
||||
|
||||
<template v-if="anyApplied">
|
||||
<DropdownMenuSeparator class="h-px bg-border-subtle" />
|
||||
<DropdownMenuItem
|
||||
class="flex h-10 items-center px-3 text-sm text-muted-foreground outline-none data-highlighted:text-base-foreground"
|
||||
@select.prevent="clearAll"
|
||||
>
|
||||
{{ $t('sideToolbar.mediaAssets.clearFilters') }}
|
||||
</DropdownMenuItem>
|
||||
</template>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenuPortal>
|
||||
</DropdownMenuRoot>
|
||||
</div>
|
||||
<span class="text-sm">{{ $t(filter.label) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { cn } from '@comfyorg/tailwind-utils'
|
||||
import {
|
||||
DropdownMenuCheckboxItem,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuLabel,
|
||||
DropdownMenuPortal,
|
||||
DropdownMenuRoot,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuSub,
|
||||
DropdownMenuSubContent,
|
||||
DropdownMenuSubTrigger,
|
||||
DropdownMenuTrigger
|
||||
} from 'reka-ui'
|
||||
import { computed, nextTick, ref } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
import Button from '@/components/ui/button/Button.vue'
|
||||
import { useModalLiftedZIndex } from '@/composables/useModalLiftedZIndex'
|
||||
|
||||
import { DATE_VALUES, MEDIA_TYPE_VALUES } from './mediaAssetFilterFacets'
|
||||
import type { FacetValue } from './mediaAssetFilterFacets'
|
||||
|
||||
type FacetKey = 'media' | 'date'
|
||||
interface ValueOption {
|
||||
value: string
|
||||
text: string
|
||||
}
|
||||
|
||||
const { active = false } = defineProps<{
|
||||
active?: boolean
|
||||
const { mediaTypeFilters } = defineProps<{
|
||||
mediaTypeFilters: string[]
|
||||
}>()
|
||||
|
||||
const mediaTypeFilters = defineModel<string[]>('mediaTypeFilters', {
|
||||
required: true
|
||||
})
|
||||
const dateFilter = defineModel<string>('dateFilter', { required: true })
|
||||
const emit = defineEmits<{
|
||||
'update:mediaTypeFilters': [value: string[]]
|
||||
}>()
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
const open = ref(false)
|
||||
const contentStyle = useModalLiftedZIndex(open)
|
||||
const searchRef = ref<HTMLInputElement>()
|
||||
const query = ref('')
|
||||
|
||||
const menuClass =
|
||||
'data-[side=top]:animate-slideDownAndFade data-[side=right]:animate-slideLeftAndFade data-[side=bottom]:animate-slideUpAndFade data-[side=left]:animate-slideRightAndFade z-1700 flex w-56 flex-col rounded-lg border border-border-subtle bg-base-background shadow-sm will-change-[opacity,transform]'
|
||||
const groupLabelClass =
|
||||
'px-2 pt-2 pb-1 text-xs font-semibold tracking-wide text-muted-foreground uppercase'
|
||||
const rowClass =
|
||||
'flex h-8 w-full cursor-pointer items-center gap-2 rounded-sm px-2 text-sm outline-none data-highlighted:bg-secondary-background-hover'
|
||||
const iconClass = 'size-4 shrink-0 text-muted-foreground'
|
||||
const labelClass = 'min-w-0 flex-1 truncate text-left text-base-foreground'
|
||||
const checkClass = 'icon-[lucide--check] size-4 shrink-0 text-base-foreground'
|
||||
const countClass =
|
||||
'flex h-5 min-w-5 shrink-0 items-center justify-center rounded-full bg-secondary-background px-1 text-xs text-muted-foreground tabular-nums'
|
||||
|
||||
const CAT_ICON: Record<FacetKey, string> = {
|
||||
media: 'icon-[lucide--image]',
|
||||
date: 'icon-[lucide--calendar]'
|
||||
}
|
||||
const CAT_LABEL: Record<FacetKey, string> = {
|
||||
media: 'sideToolbar.mediaAssets.filterMediaType',
|
||||
date: 'sideToolbar.mediaAssets.filterDate'
|
||||
}
|
||||
const catLabel = (cat: FacetKey) => t(CAT_LABEL[cat])
|
||||
|
||||
const groups: { key: string; label: string; cats: FacetKey[] }[] = [
|
||||
{
|
||||
key: 'attribute',
|
||||
label: 'sideToolbar.mediaAssets.filterGroupAttribute',
|
||||
cats: ['media', 'date']
|
||||
}
|
||||
const filters = [
|
||||
{ type: 'image', label: 'sideToolbar.mediaAssets.filterImage' },
|
||||
{ type: 'video', label: 'sideToolbar.mediaAssets.filterVideo' },
|
||||
{ type: 'audio', label: 'sideToolbar.mediaAssets.filterAudio' },
|
||||
{ type: '3d', label: 'sideToolbar.mediaAssets.filter3D' },
|
||||
{ type: 'text', label: 'sideToolbar.mediaAssets.filterText' }
|
||||
]
|
||||
|
||||
// Values that clear a single-select facet — excluded from flat search results.
|
||||
const CLEAR_VALUES = new Set(['', 'all'])
|
||||
|
||||
function toOptions(values: FacetValue[]): ValueOption[] {
|
||||
return values.map((facetValue) => ({
|
||||
value: facetValue.value,
|
||||
text: t(facetValue.labelKey)
|
||||
}))
|
||||
}
|
||||
|
||||
function valuesFor(cat: FacetKey): ValueOption[] {
|
||||
switch (cat) {
|
||||
case 'media':
|
||||
return toOptions(MEDIA_TYPE_VALUES)
|
||||
case 'date':
|
||||
return toOptions(DATE_VALUES)
|
||||
const toggleMediaType = (type: string) => {
|
||||
const isCurrentlySelected = mediaTypeFilters.includes(type)
|
||||
if (isCurrentlySelected) {
|
||||
emit(
|
||||
'update:mediaTypeFilters',
|
||||
mediaTypeFilters.filter((t) => t !== type)
|
||||
)
|
||||
} else {
|
||||
emit('update:mediaTypeFilters', [...mediaTypeFilters, type])
|
||||
}
|
||||
}
|
||||
|
||||
const searchSections = computed(() => {
|
||||
const q = query.value.trim().toLowerCase()
|
||||
if (!q) return []
|
||||
return groups
|
||||
.flatMap((g) => g.cats)
|
||||
.map((facet) => ({
|
||||
facet,
|
||||
rows: valuesFor(facet).filter(
|
||||
(o) => !CLEAR_VALUES.has(o.value) && o.text.toLowerCase().includes(q)
|
||||
)
|
||||
}))
|
||||
.filter((s) => s.rows.length)
|
||||
})
|
||||
|
||||
function isApplied(cat: FacetKey, value: string): boolean {
|
||||
switch (cat) {
|
||||
case 'media':
|
||||
return mediaTypeFilters.value.includes(value)
|
||||
case 'date':
|
||||
return dateFilter.value === value
|
||||
}
|
||||
}
|
||||
|
||||
function appliedCount(cat: FacetKey): number {
|
||||
switch (cat) {
|
||||
case 'media':
|
||||
return mediaTypeFilters.value.length
|
||||
case 'date':
|
||||
return dateFilter.value ? 1 : 0
|
||||
}
|
||||
}
|
||||
|
||||
function toggleFacetValue(cat: FacetKey, value: string) {
|
||||
switch (cat) {
|
||||
case 'date':
|
||||
dateFilter.value = dateFilter.value === value ? '' : value
|
||||
return
|
||||
case 'media':
|
||||
mediaTypeFilters.value = mediaTypeFilters.value.includes(value)
|
||||
? mediaTypeFilters.value.filter((v) => v !== value)
|
||||
: [...mediaTypeFilters.value, value]
|
||||
}
|
||||
}
|
||||
|
||||
const anyApplied = computed(
|
||||
() => mediaTypeFilters.value.length > 0 || !!dateFilter.value
|
||||
)
|
||||
|
||||
function clearAll() {
|
||||
mediaTypeFilters.value = []
|
||||
dateFilter.value = ''
|
||||
}
|
||||
|
||||
function menuItems(fromEl: HTMLElement): HTMLElement[] {
|
||||
const menu = fromEl.closest('[role="menu"]')
|
||||
return menu
|
||||
? Array.from(
|
||||
menu.querySelectorAll<HTMLElement>(
|
||||
'[role^="menuitem"]:not([aria-disabled="true"])'
|
||||
)
|
||||
)
|
||||
: []
|
||||
}
|
||||
|
||||
// The search box owns its keys: Down/Up hand focus into the results (reka drives
|
||||
// nav from there), and printable keys stay in the box so reka's menu typeahead
|
||||
// can't steal focus. Stopping propagation keeps global canvas keybindings out.
|
||||
// Escape / Enter still reach the menu.
|
||||
function onSearchKeydown(event: KeyboardEvent) {
|
||||
if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
|
||||
const items = menuItems(event.currentTarget as HTMLElement)
|
||||
if (!items.length) return
|
||||
event.preventDefault()
|
||||
event.stopPropagation()
|
||||
const target =
|
||||
event.key === 'ArrowDown' ? items[0] : items[items.length - 1]
|
||||
target.focus()
|
||||
return
|
||||
}
|
||||
if (
|
||||
event.key.length === 1 &&
|
||||
!event.ctrlKey &&
|
||||
!event.metaKey &&
|
||||
!event.altKey
|
||||
) {
|
||||
event.stopPropagation()
|
||||
}
|
||||
}
|
||||
|
||||
function focusSearch() {
|
||||
query.value = ''
|
||||
void nextTick(() => searchRef.value?.focus())
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
<template>
|
||||
<div
|
||||
class="focus-within:ring-secondary-foreground flex h-8 min-w-0 flex-1 items-center gap-2 rounded-lg bg-secondary-background px-3 focus-within:ring-1"
|
||||
>
|
||||
<i
|
||||
class="icon-[lucide--search] size-4 shrink-0 text-muted-foreground"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
<input
|
||||
v-model="model"
|
||||
type="text"
|
||||
:placeholder="placeholder"
|
||||
class="min-w-0 flex-1 border-none bg-transparent text-sm text-base-foreground outline-none placeholder:text-muted-foreground"
|
||||
/>
|
||||
<Button
|
||||
v-if="model"
|
||||
variant="textonly"
|
||||
size="icon-sm"
|
||||
:aria-label="$t('g.clear')"
|
||||
@click="model = ''"
|
||||
>
|
||||
<i class="icon-[lucide--x] size-3.5" />
|
||||
</Button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import Button from '@/components/ui/button/Button.vue'
|
||||
|
||||
const { placeholder = '' } = defineProps<{ placeholder?: string }>()
|
||||
|
||||
const model = defineModel<string>({ required: true })
|
||||
</script>
|
||||
@@ -12,7 +12,7 @@ const i18n = createI18n({
|
||||
en: {
|
||||
mediaAsset: {
|
||||
selection: {
|
||||
unselectCount: 'Unselect {count}',
|
||||
deselectAll: 'Deselect all',
|
||||
downloadSelected: 'Download',
|
||||
deleteSelected: 'Delete',
|
||||
selectedCount: '{count} selected'
|
||||
@@ -39,7 +39,7 @@ describe('MediaAssetSelectionBar', () => {
|
||||
|
||||
it('emits deselect when the close button is clicked', async () => {
|
||||
const { emitted } = renderBar({ count: 2 })
|
||||
await userEvent.click(screen.getByRole('button', { name: 'Unselect 2' }))
|
||||
await userEvent.click(screen.getByRole('button', { name: 'Deselect all' }))
|
||||
expect(emitted().deselect).toHaveLength(1)
|
||||
})
|
||||
|
||||
|
||||
@@ -1,67 +1,48 @@
|
||||
<template>
|
||||
<div class="relative mx-2">
|
||||
<div
|
||||
data-testid="assets-selection-bar"
|
||||
class="absolute bottom-6 left-1/2 z-40 flex w-full max-w-78 -translate-x-1/2 items-center gap-2 rounded-lg bg-base-foreground p-2 text-base-background shadow-interface"
|
||||
<SelectionBar
|
||||
data-testid="assets-selection-bar"
|
||||
:label="$t('mediaAsset.selection.selectedCount', { count })"
|
||||
:deselect-label="$t('mediaAsset.selection.deselectAll')"
|
||||
@deselect="emit('deselect')"
|
||||
>
|
||||
<Button
|
||||
v-tooltip.top="{
|
||||
value: $t('mediaAsset.selection.downloadSelected'),
|
||||
showDelay: 300
|
||||
}"
|
||||
variant="inverted"
|
||||
size="icon-lg"
|
||||
type="button"
|
||||
data-testid="assets-download-selected"
|
||||
:aria-label="$t('mediaAsset.selection.downloadSelected')"
|
||||
class="rounded-lg hover:bg-base-background/10"
|
||||
@click="emit('download')"
|
||||
>
|
||||
<i class="icon-[lucide--download] size-4" />
|
||||
</Button>
|
||||
<template v-if="showDelete">
|
||||
<span class="h-6 w-px bg-base-background/20" aria-hidden="true" />
|
||||
<Button
|
||||
v-tooltip.top="{
|
||||
value: $t('mediaAsset.selection.unselectCount', { count }),
|
||||
value: $t('mediaAsset.selection.deleteSelected'),
|
||||
showDelay: 300
|
||||
}"
|
||||
variant="inverted"
|
||||
size="icon-lg"
|
||||
type="button"
|
||||
data-testid="assets-deselect-selected"
|
||||
:aria-label="$t('mediaAsset.selection.unselectCount', { count })"
|
||||
data-testid="assets-delete-selected"
|
||||
:aria-label="$t('mediaAsset.selection.deleteSelected')"
|
||||
class="rounded-lg hover:bg-base-background/10"
|
||||
@click="emit('deselect')"
|
||||
@click="emit('delete')"
|
||||
>
|
||||
<i class="icon-[lucide--x] size-4" />
|
||||
<i class="icon-[lucide--trash-2] size-4" />
|
||||
</Button>
|
||||
<span class="pr-6 text-sm font-bold whitespace-nowrap tabular-nums">
|
||||
{{ $t('mediaAsset.selection.selectedCount', { count }) }}
|
||||
</span>
|
||||
<div class="ml-auto flex shrink-0 items-center gap-1">
|
||||
<Button
|
||||
v-tooltip.top="{
|
||||
value: $t('mediaAsset.selection.downloadSelected'),
|
||||
showDelay: 300
|
||||
}"
|
||||
variant="inverted"
|
||||
size="icon-lg"
|
||||
type="button"
|
||||
data-testid="assets-download-selected"
|
||||
:aria-label="$t('mediaAsset.selection.downloadSelected')"
|
||||
class="rounded-lg hover:bg-base-background/10"
|
||||
@click="emit('download')"
|
||||
>
|
||||
<i class="icon-[lucide--download] size-4" />
|
||||
</Button>
|
||||
<template v-if="showDelete">
|
||||
<span class="h-6 w-px bg-base-background/20" aria-hidden="true" />
|
||||
<Button
|
||||
v-tooltip.top="{
|
||||
value: $t('mediaAsset.selection.deleteSelected'),
|
||||
showDelay: 300
|
||||
}"
|
||||
variant="inverted"
|
||||
size="icon-lg"
|
||||
type="button"
|
||||
data-testid="assets-delete-selected"
|
||||
:aria-label="$t('mediaAsset.selection.deleteSelected')"
|
||||
class="rounded-lg hover:bg-base-background/10"
|
||||
@click="emit('delete')"
|
||||
>
|
||||
<i class="icon-[lucide--trash-2] size-4" />
|
||||
</Button>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</SelectionBar>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import SelectionBar from '@/components/common/SelectionBar.vue'
|
||||
import Button from '@/components/ui/button/Button.vue'
|
||||
|
||||
const { count, showDelete = true } = defineProps<{
|
||||
|
||||
@@ -2,41 +2,28 @@ import { render, screen } from '@testing-library/vue'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { defineComponent, ref } from 'vue'
|
||||
import { createI18n } from 'vue-i18n'
|
||||
|
||||
import enMessages from '@/locales/en/main.json' with { type: 'json' }
|
||||
import MediaAssetSettingsMenu from '@/platform/assets/components/MediaAssetSettingsMenu.vue'
|
||||
import type { SortBy } from '@/platform/assets/components/MediaAssetSettingsMenu.vue'
|
||||
|
||||
const i18n = createI18n({
|
||||
legacy: false,
|
||||
locale: 'en',
|
||||
messages: { en: enMessages }
|
||||
})
|
||||
|
||||
const KEYS = {
|
||||
list: 'List view',
|
||||
gridSmall: 'Grid (small)',
|
||||
gridLarge: 'Grid (large)',
|
||||
newest: 'Newest first',
|
||||
oldest: 'Oldest first',
|
||||
longest: 'Generation time (longest first)',
|
||||
fastest: 'Generation time (fastest first)',
|
||||
az: 'Name (A → Z)',
|
||||
za: 'Name (Z → A)'
|
||||
list: 'sideToolbar.queueProgressOverlay.viewList',
|
||||
grid: 'sideToolbar.queueProgressOverlay.viewGrid',
|
||||
newest: 'sideToolbar.mediaAssets.sortNewestFirst',
|
||||
oldest: 'sideToolbar.mediaAssets.sortOldestFirst',
|
||||
longest: 'sideToolbar.mediaAssets.sortLongestFirst',
|
||||
fastest: 'sideToolbar.mediaAssets.sortFastestFirst'
|
||||
} as const
|
||||
|
||||
type ViewMode = 'list' | 'grid-small' | 'grid-large'
|
||||
|
||||
interface MountOptions {
|
||||
viewMode?: ViewMode
|
||||
viewMode?: 'list' | 'grid'
|
||||
sortBy?: SortBy
|
||||
showSortOptions?: boolean
|
||||
showGenerationTimeSort?: boolean
|
||||
}
|
||||
|
||||
function mountWithModels(options: MountOptions = {}) {
|
||||
const viewMode = ref<ViewMode>(options.viewMode ?? 'list')
|
||||
const viewMode = ref<'list' | 'grid'>(options.viewMode ?? 'list')
|
||||
const sortBy = ref<SortBy>(options.sortBy ?? 'newest')
|
||||
|
||||
const Host = defineComponent({
|
||||
@@ -61,7 +48,9 @@ function mountWithModels(options: MountOptions = {}) {
|
||||
|
||||
const utils = render(Host, {
|
||||
global: {
|
||||
plugins: [i18n]
|
||||
mocks: {
|
||||
$t: (key: string) => key
|
||||
}
|
||||
}
|
||||
})
|
||||
return { ...utils, viewMode, sortBy, user: userEvent.setup() }
|
||||
@@ -73,24 +62,17 @@ function getButton(label: string): HTMLElement {
|
||||
|
||||
describe('MediaAssetSettingsMenu', () => {
|
||||
describe('view-mode options (always visible)', () => {
|
||||
it('renders list and both grid view options', () => {
|
||||
it('renders both list and grid view options', () => {
|
||||
mountWithModels()
|
||||
expect(getButton(KEYS.list)).toBeTruthy()
|
||||
expect(getButton(KEYS.gridSmall)).toBeTruthy()
|
||||
expect(getButton(KEYS.gridLarge)).toBeTruthy()
|
||||
expect(getButton(KEYS.grid)).toBeTruthy()
|
||||
})
|
||||
|
||||
it.for([
|
||||
{ key: KEYS.gridSmall, expected: 'grid-small' },
|
||||
{ key: KEYS.gridLarge, expected: 'grid-large' }
|
||||
] as const)(
|
||||
'updates the v-model:viewMode to $expected when an option is clicked',
|
||||
async ({ key, expected }) => {
|
||||
const { viewMode, user } = mountWithModels({ viewMode: 'list' })
|
||||
await user.click(getButton(key))
|
||||
expect(viewMode.value).toBe(expected)
|
||||
}
|
||||
)
|
||||
it('updates the v-model:viewMode when an option is clicked', async () => {
|
||||
const { viewMode, user } = mountWithModels({ viewMode: 'list' })
|
||||
await user.click(getButton(KEYS.grid))
|
||||
expect(viewMode.value).toBe('grid')
|
||||
})
|
||||
})
|
||||
|
||||
describe('sort options (gated by showSortOptions)', () => {
|
||||
@@ -130,9 +112,7 @@ describe('MediaAssetSettingsMenu', () => {
|
||||
{ key: 'newest', expected: 'newest' },
|
||||
{ key: 'oldest', expected: 'oldest' },
|
||||
{ key: 'longest', expected: 'longest' },
|
||||
{ key: 'fastest', expected: 'fastest' },
|
||||
{ key: 'az', expected: 'az' },
|
||||
{ key: 'za', expected: 'za' }
|
||||
{ key: 'fastest', expected: 'fastest' }
|
||||
]
|
||||
|
||||
for (const { key, expected } of cases) {
|
||||
|
||||
@@ -18,30 +18,15 @@
|
||||
<Button
|
||||
variant="textonly"
|
||||
class="w-full"
|
||||
@click="handleViewModeChange('grid-small')"
|
||||
>
|
||||
<span class="flex items-center gap-2">
|
||||
<i class="icon-[lucide--grid-3x3] size-4" />
|
||||
<span>{{ $t('sideToolbar.mediaAssets.viewGridSmall') }}</span>
|
||||
</span>
|
||||
<i
|
||||
class="ml-auto icon-[lucide--check] size-4"
|
||||
:class="viewMode !== 'grid-small' && 'opacity-0'"
|
||||
/>
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
variant="textonly"
|
||||
class="w-full"
|
||||
@click="handleViewModeChange('grid-large')"
|
||||
@click="handleViewModeChange('grid')"
|
||||
>
|
||||
<span class="flex items-center gap-2">
|
||||
<i class="icon-[lucide--layout-grid] size-4" />
|
||||
<span>{{ $t('sideToolbar.mediaAssets.viewGridLarge') }}</span>
|
||||
<span>{{ $t('sideToolbar.queueProgressOverlay.viewGrid') }}</span>
|
||||
</span>
|
||||
<i
|
||||
class="ml-auto icon-[lucide--check] size-4"
|
||||
:class="viewMode !== 'grid-large' && 'opacity-0'"
|
||||
:class="viewMode !== 'grid' && 'opacity-0'"
|
||||
/>
|
||||
</Button>
|
||||
|
||||
@@ -72,22 +57,6 @@
|
||||
/>
|
||||
</Button>
|
||||
|
||||
<Button variant="textonly" class="w-full" @click="handleSortChange('az')">
|
||||
<span>{{ $t('sideToolbar.mediaAssets.sortAToZ') }}</span>
|
||||
<i
|
||||
class="ml-auto icon-[lucide--check] size-4"
|
||||
:class="sortBy !== 'az' && 'opacity-0'"
|
||||
/>
|
||||
</Button>
|
||||
|
||||
<Button variant="textonly" class="w-full" @click="handleSortChange('za')">
|
||||
<span>{{ $t('sideToolbar.mediaAssets.sortZToA') }}</span>
|
||||
<i
|
||||
class="ml-auto icon-[lucide--check] size-4"
|
||||
:class="sortBy !== 'za' && 'opacity-0'"
|
||||
/>
|
||||
</Button>
|
||||
|
||||
<template v-if="showGenerationTimeSort">
|
||||
<Button
|
||||
variant="textonly"
|
||||
@@ -120,9 +89,7 @@
|
||||
<script setup lang="ts">
|
||||
import Button from '@/components/ui/button/Button.vue'
|
||||
|
||||
import type { MediaAssetViewMode } from './mediaAssetViewOptions'
|
||||
|
||||
export type SortBy = 'newest' | 'oldest' | 'longest' | 'fastest' | 'az' | 'za'
|
||||
export type SortBy = 'newest' | 'oldest' | 'longest' | 'fastest'
|
||||
|
||||
const { showSortOptions = false, showGenerationTimeSort = false } =
|
||||
defineProps<{
|
||||
@@ -130,10 +97,10 @@ const { showSortOptions = false, showGenerationTimeSort = false } =
|
||||
showGenerationTimeSort?: boolean
|
||||
}>()
|
||||
|
||||
const viewMode = defineModel<MediaAssetViewMode>('viewMode', { required: true })
|
||||
const viewMode = defineModel<'list' | 'grid'>('viewMode', { required: true })
|
||||
const sortBy = defineModel<SortBy>('sortBy', { required: true })
|
||||
|
||||
function handleViewModeChange(value: MediaAssetViewMode) {
|
||||
function handleViewModeChange(value: 'list' | 'grid') {
|
||||
viewMode.value = value
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
<template>
|
||||
<p class="m-0 truncate text-sm/tight text-base-foreground" :title="fileName">
|
||||
<p
|
||||
class="m-0 line-clamp-2 text-sm/tight break-all text-base-foreground"
|
||||
:title="fileName"
|
||||
>
|
||||
{{ fileName }}
|
||||
</p>
|
||||
</template>
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
/**
|
||||
* Single source of the media-assets filter facet values and their i18n label
|
||||
* keys, shared by the filter menu (which renders the option rows) and the
|
||||
* filter bar (which labels the applied-filter chips) so the two never drift.
|
||||
*/
|
||||
|
||||
export interface FacetValue {
|
||||
value: string
|
||||
labelKey: string
|
||||
}
|
||||
|
||||
export const MEDIA_TYPE_VALUES: FacetValue[] = [
|
||||
{ value: 'image', labelKey: 'sideToolbar.mediaAssets.filterImage' },
|
||||
{ value: 'video', labelKey: 'sideToolbar.mediaAssets.filterVideo' },
|
||||
{ value: 'audio', labelKey: 'sideToolbar.mediaAssets.filterAudio' },
|
||||
{ value: '3d', labelKey: 'sideToolbar.mediaAssets.filter3D' },
|
||||
{ value: 'text', labelKey: 'sideToolbar.mediaAssets.filterText' }
|
||||
]
|
||||
|
||||
export const DATE_VALUES: FacetValue[] = [
|
||||
{ value: '', labelKey: 'sideToolbar.mediaAssets.dateAll' },
|
||||
{ value: 'today', labelKey: 'sideToolbar.mediaAssets.dateToday' },
|
||||
{ value: 'week', labelKey: 'sideToolbar.mediaAssets.datePastWeek' },
|
||||
{ value: 'month', labelKey: 'sideToolbar.mediaAssets.datePastMonth' },
|
||||
{ value: 'year', labelKey: 'sideToolbar.mediaAssets.dateThisYear' }
|
||||
]
|
||||
|
||||
export function labelKeyForValue(
|
||||
values: FacetValue[],
|
||||
value: string
|
||||
): string | undefined {
|
||||
return values.find((facetValue) => facetValue.value === value)?.labelKey
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
/** Sidebar view mode: a list, or one of two grid tile sizes. */
|
||||
export type MediaAssetViewMode = 'list' | 'grid-small' | 'grid-large'
|
||||
|
||||
/** `grid-template-columns` for a grid view mode ('list' falls back to the dense grid). */
|
||||
export function gridColumnsForMode(mode: MediaAssetViewMode): string {
|
||||
const minWidth = mode === 'grid-large' ? 240 : 128
|
||||
return `repeat(auto-fill, minmax(min(${minWidth}px, 30vw), 1fr))`
|
||||
}
|
||||
@@ -22,10 +22,7 @@ vi.mock('@vueuse/core', async (importOriginal) => {
|
||||
}
|
||||
})
|
||||
|
||||
import {
|
||||
shouldInterceptSelectAll,
|
||||
useAssetSelection
|
||||
} from './useAssetSelection'
|
||||
import { useAssetSelection } from './useAssetSelection'
|
||||
import { useAssetSelectionStore } from './useAssetSelectionStore'
|
||||
|
||||
function createMockAssets(count: number): AssetItem[] {
|
||||
@@ -135,51 +132,6 @@ describe('useAssetSelection', () => {
|
||||
expect(isSelected('asset-1')).toBe(true)
|
||||
expect(selectedCount.value).toBe(1)
|
||||
})
|
||||
|
||||
it('deselects when clicking the only selected asset again', () => {
|
||||
const { handleAssetClick, isSelected, selectedCount } =
|
||||
useAssetSelection()
|
||||
const assets = createMockAssets(3)
|
||||
|
||||
handleAssetClick(assets[0], 0, assets)
|
||||
expect(selectedCount.value).toBe(1)
|
||||
|
||||
handleAssetClick(assets[0], 0, assets)
|
||||
expect(isSelected('asset-0')).toBe(false)
|
||||
expect(selectedCount.value).toBe(0)
|
||||
})
|
||||
|
||||
it('starts a new selection after deselecting the anchor', () => {
|
||||
const { handleAssetClick, isSelected, selectedCount } =
|
||||
useAssetSelection()
|
||||
const assets = createMockAssets(3)
|
||||
|
||||
handleAssetClick(assets[0], 0, assets)
|
||||
handleAssetClick(assets[0], 0, assets)
|
||||
mockShiftKey.value = true
|
||||
handleAssetClick(assets[2], 2, assets)
|
||||
|
||||
expect(isSelected('asset-0')).toBe(false)
|
||||
expect(isSelected('asset-2')).toBe(true)
|
||||
expect(selectedCount.value).toBe(1)
|
||||
})
|
||||
|
||||
it('collapses a multi-selection to the clicked asset rather than deselecting', () => {
|
||||
const { handleAssetClick, isSelected, selectedCount } =
|
||||
useAssetSelection()
|
||||
const assets = createMockAssets(3)
|
||||
|
||||
handleAssetClick(assets[0], 0, assets)
|
||||
mockCtrlKey.value = true
|
||||
handleAssetClick(assets[1], 1, assets)
|
||||
mockCtrlKey.value = false
|
||||
expect(selectedCount.value).toBe(2)
|
||||
|
||||
handleAssetClick(assets[0], 0, assets)
|
||||
expect(isSelected('asset-0')).toBe(true)
|
||||
expect(isSelected('asset-1')).toBe(false)
|
||||
expect(selectedCount.value).toBe(1)
|
||||
})
|
||||
})
|
||||
|
||||
describe('handleAssetClick - shift+click', () => {
|
||||
@@ -321,61 +273,3 @@ describe('useAssetSelection', () => {
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('shouldInterceptSelectAll', () => {
|
||||
function interceptsOn(
|
||||
focusedTag: string,
|
||||
init: KeyboardEventInit = { key: 'a', metaKey: true },
|
||||
{ insidePane = true, contentEditable = false } = {}
|
||||
): boolean {
|
||||
const pane = document.createElement('div')
|
||||
document.body.append(pane)
|
||||
const focused = document.createElement(focusedTag)
|
||||
if (contentEditable) {
|
||||
Object.defineProperty(focused, 'isContentEditable', { value: true })
|
||||
}
|
||||
;(insidePane ? pane : document.body).append(focused)
|
||||
|
||||
let result = false
|
||||
const record = (event: Event) => {
|
||||
result = shouldInterceptSelectAll(event as KeyboardEvent, pane)
|
||||
}
|
||||
window.addEventListener('keydown', record, { capture: true })
|
||||
focused.dispatchEvent(
|
||||
new KeyboardEvent('keydown', { ...init, bubbles: true })
|
||||
)
|
||||
window.removeEventListener('keydown', record, { capture: true })
|
||||
pane.remove()
|
||||
focused.remove()
|
||||
return result
|
||||
}
|
||||
|
||||
it('intercepts Cmd+A and Ctrl+A on non-text elements inside the pane', () => {
|
||||
expect(interceptsOn('div', { key: 'a', metaKey: true })).toBe(true)
|
||||
expect(interceptsOn('div', { key: 'A', ctrlKey: true })).toBe(true)
|
||||
})
|
||||
|
||||
it('requires the select-all chord', () => {
|
||||
expect(interceptsOn('div', { key: 'a' })).toBe(false)
|
||||
expect(interceptsOn('div', { key: 'b', metaKey: true })).toBe(false)
|
||||
})
|
||||
|
||||
it('leaves native select-all to text-entry elements', () => {
|
||||
for (const tag of ['input', 'textarea', 'select']) {
|
||||
expect(interceptsOn(tag, { key: 'a', metaKey: true })).toBe(false)
|
||||
}
|
||||
expect(
|
||||
interceptsOn(
|
||||
'div',
|
||||
{ key: 'a', metaKey: true },
|
||||
{ contentEditable: true }
|
||||
)
|
||||
).toBe(false)
|
||||
})
|
||||
|
||||
it('ignores the chord when focus is outside the pane', () => {
|
||||
expect(
|
||||
interceptsOn('div', { key: 'a', metaKey: true }, { insidePane: false })
|
||||
).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -8,25 +8,6 @@ import {
|
||||
getTotalAssetOutputCount
|
||||
} from '@/platform/assets/utils/outputAssetUtil'
|
||||
|
||||
/**
|
||||
* True when a Cmd/Ctrl+A keydown should become "select all assets": the chord
|
||||
* matches, focus is inside the asset pane, and the target is not a text-entry
|
||||
* element (those keep native select-all).
|
||||
*/
|
||||
export function shouldInterceptSelectAll(
|
||||
event: KeyboardEvent,
|
||||
pane: HTMLElement | undefined
|
||||
): boolean {
|
||||
if (event.key !== 'a' && event.key !== 'A') return false
|
||||
if (!event.metaKey && !event.ctrlKey) return false
|
||||
const target = event.target
|
||||
if (!(target instanceof HTMLElement) || !pane?.contains(target)) return false
|
||||
return !(
|
||||
target.isContentEditable ||
|
||||
['INPUT', 'TEXTAREA', 'SELECT'].includes(target.tagName)
|
||||
)
|
||||
}
|
||||
|
||||
export function useAssetSelection() {
|
||||
const selectionStore = useAssetSelectionStore()
|
||||
|
||||
@@ -102,16 +83,7 @@ export function useAssetSelection() {
|
||||
return
|
||||
}
|
||||
|
||||
// Normal Click: deselect when it is already the sole selection, otherwise
|
||||
// collapse to a single selection.
|
||||
if (
|
||||
selectionStore.isSelected(assetId) &&
|
||||
selectionStore.selectedCount === 1
|
||||
) {
|
||||
selectionStore.clearSelection()
|
||||
setAnchor(-1, null)
|
||||
return
|
||||
}
|
||||
// Normal Click: Single selection
|
||||
selectionStore.clearSelection()
|
||||
selectionStore.addToSelection(assetId)
|
||||
setAnchor(index, assetId)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { ref } from 'vue'
|
||||
|
||||
import { useMediaAssetFiltering } from '@/platform/assets/composables/useMediaAssetFiltering'
|
||||
@@ -169,92 +169,6 @@ describe('useMediaAssetFiltering', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('alphabetical sort', () => {
|
||||
it('sorts A→Z by display name (case-insensitive)', () => {
|
||||
const assets = ref<AssetItem[]>([
|
||||
makeAsset({ id: 'b', name: 'banana.png' }),
|
||||
makeAsset({ id: 'a', name: 'Apple.png' }),
|
||||
makeAsset({ id: 'c', name: 'cherry.png' })
|
||||
])
|
||||
const { sortBy, filteredAssets } = useMediaAssetFiltering(assets)
|
||||
|
||||
sortBy.value = 'az'
|
||||
expect(ids(filteredAssets.value)).toEqual(['a', 'b', 'c'])
|
||||
})
|
||||
|
||||
it('sorts Z→A by display name (case-insensitive)', () => {
|
||||
const assets = ref<AssetItem[]>([
|
||||
makeAsset({ id: 'b', name: 'banana.png' }),
|
||||
makeAsset({ id: 'a', name: 'Apple.png' }),
|
||||
makeAsset({ id: 'c', name: 'cherry.png' })
|
||||
])
|
||||
const { sortBy, filteredAssets } = useMediaAssetFiltering(assets)
|
||||
|
||||
sortBy.value = 'za'
|
||||
expect(ids(filteredAssets.value)).toEqual(['c', 'b', 'a'])
|
||||
})
|
||||
})
|
||||
|
||||
describe('date filter', () => {
|
||||
afterEach(() => {
|
||||
vi.useRealTimers()
|
||||
})
|
||||
|
||||
function datedAssets() {
|
||||
const now = Date.now()
|
||||
return ref<AssetItem[]>([
|
||||
makeAsset({ id: 'recent', name: 'a.png', createTime: now }),
|
||||
makeAsset({
|
||||
id: 'stale',
|
||||
name: 'b.png',
|
||||
createTime: now - 40 * 86_400_000
|
||||
})
|
||||
])
|
||||
}
|
||||
|
||||
it('returns every asset when no date preset is set', () => {
|
||||
const { filteredAssets } = useMediaAssetFiltering(datedAssets())
|
||||
|
||||
expect(ids(filteredAssets.value).sort()).toEqual(['recent', 'stale'])
|
||||
})
|
||||
|
||||
it('keeps only assets inside the selected preset window', () => {
|
||||
const { dateFilter, filteredAssets } =
|
||||
useMediaAssetFiltering(datedAssets())
|
||||
|
||||
dateFilter.value = 'month'
|
||||
expect(ids(filteredAssets.value)).toEqual(['recent'])
|
||||
})
|
||||
|
||||
it('today cuts off at local midnight', () => {
|
||||
vi.useFakeTimers()
|
||||
vi.setSystemTime(new Date(2026, 5, 15, 12, 0, 0))
|
||||
const midnight = new Date(2026, 5, 15, 0, 0, 0).getTime()
|
||||
const assets = ref<AssetItem[]>([
|
||||
makeAsset({ id: 'this-morning', name: 'a.png', createTime: midnight }),
|
||||
makeAsset({ id: 'yesterday', name: 'b.png', createTime: midnight - 1 })
|
||||
])
|
||||
const { dateFilter, filteredAssets } = useMediaAssetFiltering(assets)
|
||||
|
||||
dateFilter.value = 'today'
|
||||
expect(ids(filteredAssets.value)).toEqual(['this-morning'])
|
||||
})
|
||||
|
||||
it('year cuts off at January 1', () => {
|
||||
vi.useFakeTimers()
|
||||
vi.setSystemTime(new Date(2026, 5, 15))
|
||||
const janFirst = new Date(2026, 0, 1).getTime()
|
||||
const assets = ref<AssetItem[]>([
|
||||
makeAsset({ id: 'this-year', name: 'a.png', createTime: janFirst }),
|
||||
makeAsset({ id: 'last-year', name: 'b.png', createTime: janFirst - 1 })
|
||||
])
|
||||
const { dateFilter, filteredAssets } = useMediaAssetFiltering(assets)
|
||||
|
||||
dateFilter.value = 'year'
|
||||
expect(ids(filteredAssets.value)).toEqual(['this-year'])
|
||||
})
|
||||
})
|
||||
|
||||
describe('composition', () => {
|
||||
it('applies media-type filter then sort', () => {
|
||||
const t1 = 1_000_000
|
||||
|
||||
@@ -7,7 +7,7 @@ import type { Ref } from 'vue'
|
||||
import type { AssetItem } from '@/platform/assets/schemas/assetSchema'
|
||||
import { getMediaTypeFromFilename } from '@/utils/formatUtil'
|
||||
|
||||
type SortOption = 'newest' | 'oldest' | 'longest' | 'fastest' | 'az' | 'za'
|
||||
type SortOption = 'newest' | 'oldest' | 'longest' | 'fastest'
|
||||
|
||||
/**
|
||||
* Get timestamp from asset (either create_time or created_at)
|
||||
@@ -26,30 +26,6 @@ const getAssetExecutionTime = (asset: AssetItem): number => {
|
||||
return (asset.user_metadata?.executionTimeInSeconds as number) ?? 0
|
||||
}
|
||||
|
||||
/** Case-insensitive display name used for alphabetical sorting. */
|
||||
const getAssetSortName = (asset: AssetItem): string => {
|
||||
return (asset.display_name || asset.name || '').toLowerCase()
|
||||
}
|
||||
|
||||
/** Inclusive lower bound (ms) for a date preset. */
|
||||
const datePresetStart = (preset: string): number => {
|
||||
const now = Date.now()
|
||||
const start = new Date(now)
|
||||
switch (preset) {
|
||||
case 'today':
|
||||
start.setHours(0, 0, 0, 0)
|
||||
return start.getTime()
|
||||
case 'week':
|
||||
return now - 7 * 86_400_000
|
||||
case 'month':
|
||||
return now - 30 * 86_400_000
|
||||
case 'year':
|
||||
return new Date(start.getFullYear(), 0, 1).getTime()
|
||||
default:
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Media Asset Filtering composable
|
||||
* Manages search, filter, and sort for media assets
|
||||
@@ -59,7 +35,6 @@ export function useMediaAssetFiltering(assets: Ref<AssetItem[]>) {
|
||||
const debouncedSearchQuery = refDebounced(searchQuery, 50)
|
||||
const sortBy = ref<SortOption>('newest')
|
||||
const mediaTypeFilters = ref<string[]>([])
|
||||
const dateFilter = ref('')
|
||||
|
||||
const fuseOptions = {
|
||||
keys: ['display_name', 'name'],
|
||||
@@ -92,40 +67,24 @@ export function useMediaAssetFiltering(assets: Ref<AssetItem[]>) {
|
||||
})
|
||||
})
|
||||
|
||||
const dateFiltered = computed(() => {
|
||||
if (!dateFilter.value) {
|
||||
return typeFiltered.value
|
||||
}
|
||||
const start = datePresetStart(dateFilter.value)
|
||||
return typeFiltered.value.filter((asset) => getAssetTime(asset) >= start)
|
||||
})
|
||||
|
||||
const filteredAssets = computed(() => {
|
||||
// Sort by create_time (output assets) or created_at (input assets)
|
||||
switch (sortBy.value) {
|
||||
case 'oldest':
|
||||
// Ascending order (oldest first)
|
||||
return sortByUtil(dateFiltered.value, [getAssetTime])
|
||||
return sortByUtil(typeFiltered.value, [getAssetTime])
|
||||
case 'longest':
|
||||
// Descending order (longest execution time first)
|
||||
return sortByUtil(dateFiltered.value, [
|
||||
return sortByUtil(typeFiltered.value, [
|
||||
(asset) => -getAssetExecutionTime(asset)
|
||||
])
|
||||
case 'fastest':
|
||||
// Ascending order (fastest execution time first)
|
||||
return sortByUtil(dateFiltered.value, [getAssetExecutionTime])
|
||||
case 'az':
|
||||
return [...dateFiltered.value].sort((a, b) =>
|
||||
getAssetSortName(a).localeCompare(getAssetSortName(b))
|
||||
)
|
||||
case 'za':
|
||||
return [...dateFiltered.value].sort((a, b) =>
|
||||
getAssetSortName(b).localeCompare(getAssetSortName(a))
|
||||
)
|
||||
return sortByUtil(typeFiltered.value, [getAssetExecutionTime])
|
||||
case 'newest':
|
||||
default:
|
||||
// Descending order (newest first) - negate for descending
|
||||
return sortByUtil(dateFiltered.value, [(asset) => -getAssetTime(asset)])
|
||||
return sortByUtil(typeFiltered.value, [(asset) => -getAssetTime(asset)])
|
||||
}
|
||||
})
|
||||
|
||||
@@ -133,7 +92,6 @@ export function useMediaAssetFiltering(assets: Ref<AssetItem[]>) {
|
||||
searchQuery,
|
||||
sortBy,
|
||||
mediaTypeFilters,
|
||||
dateFilter,
|
||||
filteredAssets
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
<template>
|
||||
<div class="flex h-[700px] max-h-[85vh] w-[320px] max-w-[90vw] flex-col">
|
||||
<div
|
||||
class="dark-theme flex max-h-[85vh] w-full max-w-md flex-col overflow-y-auto px-4 sm:px-6"
|
||||
>
|
||||
<h1
|
||||
class="-mb-1 font-inter text-xl/8 font-semibold tracking-wide text-primary-comfy-canvas sm:text-2xl/8"
|
||||
>
|
||||
{{ $t('cloudOnboarding.survey.title') }}
|
||||
</h1>
|
||||
<DynamicSurveyForm
|
||||
:key="activeSurvey.version"
|
||||
:survey="activeSurvey"
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
import { render, screen } from '@testing-library/vue'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { createMemoryHistory, createRouter } from 'vue-router'
|
||||
|
||||
import CloudTemplate from './CloudTemplate.vue'
|
||||
|
||||
const renderWithMeta = async (meta: Record<string, unknown>) => {
|
||||
const router = createRouter({
|
||||
history: createMemoryHistory(),
|
||||
routes: [{ path: '/', name: 'test', component: CloudTemplate, meta }]
|
||||
})
|
||||
await router.push('/')
|
||||
await router.isReady()
|
||||
return render(CloudTemplate, {
|
||||
global: {
|
||||
plugins: [router],
|
||||
stubs: {
|
||||
CloudHeroCarousel: { template: '<div data-testid="hero" />' },
|
||||
CloudTemplateFooter: true
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
describe('CloudTemplate', () => {
|
||||
it('shows the hero carousel when the route does not hide it', async () => {
|
||||
await renderWithMeta({})
|
||||
expect(screen.getByTestId('hero')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('hides the hero carousel when route.meta.hideHero is set', async () => {
|
||||
await renderWithMeta({ hideHero: true })
|
||||
expect(screen.queryByTestId('hero')).not.toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
@@ -13,15 +13,22 @@
|
||||
</div>
|
||||
<CloudTemplateFooter />
|
||||
</div>
|
||||
<div class="relative hidden flex-1 overflow-hidden py-2 pr-2 lg:block">
|
||||
<div
|
||||
v-if="!route.meta.hideHero"
|
||||
class="relative hidden flex-1 overflow-hidden py-2 pr-2 lg:block"
|
||||
>
|
||||
<CloudHeroCarousel />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { useRoute } from 'vue-router'
|
||||
|
||||
import CloudHeroCarousel from '@/platform/cloud/onboarding/components/CloudHeroCarousel.vue'
|
||||
import CloudTemplateFooter from '@/platform/cloud/onboarding/components/CloudTemplateFooter.vue'
|
||||
|
||||
const route = useRoute()
|
||||
</script>
|
||||
<style>
|
||||
@import '../assets/css/fonts.css';
|
||||
|
||||
@@ -5,20 +5,22 @@
|
||||
<a
|
||||
href="https://www.comfy.org/terms-of-service"
|
||||
target="_blank"
|
||||
class="cursor-pointer text-sm text-gray-600 no-underline"
|
||||
rel="noopener noreferrer"
|
||||
class="cursor-pointer text-sm text-primary-comfy-canvas/60 no-underline"
|
||||
>
|
||||
{{ t('auth.login.termsLink') }}
|
||||
</a>
|
||||
<a
|
||||
href="https://www.comfy.org/privacy-policy"
|
||||
target="_blank"
|
||||
class="cursor-pointer text-sm text-gray-600 no-underline"
|
||||
rel="noopener noreferrer"
|
||||
class="cursor-pointer text-sm text-primary-comfy-canvas/60 no-underline"
|
||||
>
|
||||
{{ t('auth.login.privacyLink') }}
|
||||
</a>
|
||||
<a
|
||||
href="https://support.comfy.org"
|
||||
class="cursor-pointer text-sm text-gray-600 no-underline"
|
||||
class="cursor-pointer text-sm text-primary-comfy-canvas/60 no-underline"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
|
||||
@@ -94,7 +94,7 @@ export const cloudOnboardingRoutes: RouteRecordRaw[] = [
|
||||
name: 'cloud-survey',
|
||||
component: () =>
|
||||
import('@/platform/cloud/onboarding/CloudSurveyView.vue'),
|
||||
meta: { requiresAuth: true }
|
||||
meta: { requiresAuth: true, hideHero: true }
|
||||
},
|
||||
{
|
||||
path: 'oauth/consent',
|
||||
@@ -106,7 +106,7 @@ export const cloudOnboardingRoutes: RouteRecordRaw[] = [
|
||||
name: 'cloud-user-check',
|
||||
component: () =>
|
||||
import('@/platform/cloud/onboarding/UserCheckView.vue'),
|
||||
meta: { requiresAuth: true }
|
||||
meta: { requiresAuth: true, hideHero: true }
|
||||
},
|
||||
{
|
||||
path: 'sorry-contact-support',
|
||||
|
||||
176
src/platform/cloud/onboarding/survey/DynamicSurveyField.test.ts
Normal file
176
src/platform/cloud/onboarding/survey/DynamicSurveyField.test.ts
Normal file
@@ -0,0 +1,176 @@
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { render, screen } from '@testing-library/vue'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { createI18n } from 'vue-i18n'
|
||||
|
||||
import enMessages from '@/locales/en/main.json'
|
||||
import type { OnboardingSurveyField } from '@/platform/remoteConfig/types'
|
||||
|
||||
import DynamicSurveyField from './DynamicSurveyField.vue'
|
||||
|
||||
const renderField = (
|
||||
field: OnboardingSurveyField,
|
||||
props: {
|
||||
modelValue?: string | string[]
|
||||
otherValue?: string
|
||||
errorMessage?: string
|
||||
} = {},
|
||||
locale = 'en'
|
||||
) =>
|
||||
render(DynamicSurveyField, {
|
||||
global: {
|
||||
plugins: [
|
||||
createI18n({ legacy: false, locale, messages: { en: enMessages } })
|
||||
]
|
||||
},
|
||||
props: { field, modelValue: undefined, ...props }
|
||||
})
|
||||
|
||||
const optionButton = (label: string) =>
|
||||
screen.getByRole('button', { name: label })
|
||||
|
||||
describe('DynamicSurveyField', () => {
|
||||
const singleField: OnboardingSurveyField = {
|
||||
id: 'intent',
|
||||
type: 'single',
|
||||
label: 'What do you want to make?',
|
||||
required: true,
|
||||
options: [
|
||||
{ value: 'images', label: 'Images', icon: 'icon-[lucide--image]' },
|
||||
{ value: 'video', label: 'Video' }
|
||||
]
|
||||
}
|
||||
|
||||
it('renders the label and one card per option', () => {
|
||||
renderField(singleField)
|
||||
expect(screen.getByText('What do you want to make?')).toBeVisible()
|
||||
expect(screen.getByText('Images')).toBeInTheDocument()
|
||||
expect(screen.getByText('Video')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('emits the chosen value for a single-select card', async () => {
|
||||
const user = userEvent.setup()
|
||||
const { emitted } = renderField(singleField)
|
||||
|
||||
await user.click(screen.getByText('Images'))
|
||||
expect(emitted()['update:modelValue']?.[0]).toEqual(['images'])
|
||||
})
|
||||
|
||||
it('marks the selected single card as on (aria-pressed/state)', () => {
|
||||
renderField(singleField, { modelValue: 'images' })
|
||||
expect(optionButton('Images')).toHaveAttribute('data-state', 'on')
|
||||
expect(optionButton('Video')).toHaveAttribute('data-state', 'off')
|
||||
})
|
||||
|
||||
it('gives each option card a stable "<fieldId>-<value>" id', () => {
|
||||
renderField(singleField)
|
||||
expect(optionButton('Images')).toHaveAttribute('id', 'intent-images')
|
||||
expect(optionButton('Video')).toHaveAttribute('id', 'intent-video')
|
||||
})
|
||||
|
||||
const multiField: OnboardingSurveyField = {
|
||||
id: 'making',
|
||||
type: 'multi',
|
||||
label: 'Pick some',
|
||||
required: true,
|
||||
options: [
|
||||
{ value: 'a', label: 'Making A' },
|
||||
{ value: 'b', label: 'Making B' }
|
||||
]
|
||||
}
|
||||
|
||||
it('emits an array for a multi-select card and reflects current selection', async () => {
|
||||
const user = userEvent.setup()
|
||||
const { emitted } = renderField(multiField, { modelValue: ['a'] })
|
||||
|
||||
expect(optionButton('Making A')).toHaveAttribute('data-state', 'on')
|
||||
await user.click(screen.getByText('Making B'))
|
||||
const events = emitted()['update:modelValue'] as unknown[][] | undefined
|
||||
const last = events?.at(-1)?.[0]
|
||||
expect(last).toEqual(expect.arrayContaining(['a', 'b']))
|
||||
})
|
||||
|
||||
it('shows the "other" free-text input only when "other" is selected and emits it', async () => {
|
||||
const user = userEvent.setup()
|
||||
const otherField: OnboardingSurveyField = {
|
||||
id: 'source',
|
||||
type: 'single',
|
||||
label: 'How did you find us?',
|
||||
required: true,
|
||||
allowOther: true,
|
||||
otherFieldId: 'sourceOther',
|
||||
options: [
|
||||
{ value: 'search', label: 'Web search' },
|
||||
{ value: 'other', label: 'Somewhere else' }
|
||||
]
|
||||
}
|
||||
|
||||
const { rerender, emitted } = renderField(otherField, {
|
||||
modelValue: 'search'
|
||||
})
|
||||
expect(
|
||||
screen.queryByPlaceholderText('Where did you find us?')
|
||||
).not.toBeInTheDocument()
|
||||
|
||||
await rerender({ field: otherField, modelValue: 'other', otherValue: '' })
|
||||
const input = screen.getByPlaceholderText('Where did you find us?')
|
||||
await user.type(input, 'A podcast')
|
||||
expect(emitted()['update:otherValue']?.length).toBeGreaterThan(0)
|
||||
})
|
||||
|
||||
it('renders a text field and emits typed input', async () => {
|
||||
const user = userEvent.setup()
|
||||
const textField: OnboardingSurveyField = {
|
||||
id: 'note',
|
||||
type: 'text',
|
||||
label: 'Anything else?',
|
||||
placeholder: 'Your note'
|
||||
}
|
||||
const { emitted } = renderField(textField)
|
||||
|
||||
await user.type(screen.getByPlaceholderText('Your note'), 'Hi')
|
||||
expect(emitted()['update:modelValue']?.length).toBeGreaterThan(0)
|
||||
})
|
||||
|
||||
it('resolves labels via labelKey, locale map, and falls back to the value', () => {
|
||||
renderField(
|
||||
{
|
||||
id: 'q',
|
||||
type: 'single',
|
||||
labelKey: 'cloudSurvey_steps_intent',
|
||||
options: [
|
||||
{ value: 'x', label: { en: 'Ex', ko: '엑스' } },
|
||||
{ value: 'raw' } // no label → falls back to the value
|
||||
]
|
||||
},
|
||||
{}
|
||||
)
|
||||
expect(screen.getByText('What do you want to make?')).toBeVisible()
|
||||
expect(screen.getByText('Ex')).toBeInTheDocument()
|
||||
expect(screen.getByText('raw')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('resolves a field label from a locale map when no labelKey is set', () => {
|
||||
renderField({
|
||||
id: 'q',
|
||||
type: 'single',
|
||||
label: { en: 'Server question', ko: '서버 질문' },
|
||||
options: [{ value: 'a', label: 'A' }]
|
||||
})
|
||||
expect(screen.getByText('Server question')).toBeVisible()
|
||||
})
|
||||
|
||||
it('falls back to the field id when neither labelKey nor label resolves', () => {
|
||||
renderField({
|
||||
id: 'bare_field_id',
|
||||
type: 'single',
|
||||
options: [{ value: 'a', label: 'A' }]
|
||||
})
|
||||
expect(screen.getByText('bare_field_id')).toBeVisible()
|
||||
})
|
||||
|
||||
it('renders the error message when provided', () => {
|
||||
renderField(singleField, { errorMessage: 'Please choose an option.' })
|
||||
expect(screen.getByText('Please choose an option.')).toBeVisible()
|
||||
})
|
||||
})
|
||||
@@ -2,62 +2,72 @@
|
||||
<fieldset
|
||||
v-if="field.type !== 'text'"
|
||||
:aria-invalid="Boolean(errorMessage)"
|
||||
class="flex flex-col gap-4 border-0 p-0"
|
||||
class="m-0 flex flex-col gap-4 border-0 p-0"
|
||||
>
|
||||
<legend class="mb-2 block text-lg font-medium text-base-foreground">
|
||||
<legend class="mb-2 block text-lg font-medium text-primary-comfy-canvas">
|
||||
{{ resolvedLabel }}
|
||||
</legend>
|
||||
<template v-if="field.type === 'single'">
|
||||
<div
|
||||
<ToggleGroup
|
||||
v-if="field.type === 'single'"
|
||||
:model-value="(modelValue as string) ?? ''"
|
||||
type="single"
|
||||
class="flex w-full flex-col gap-2"
|
||||
@update:model-value="onSingleChange"
|
||||
>
|
||||
<ToggleGroupItem
|
||||
v-for="option in field.options"
|
||||
:id="`${field.id}-${option.value}`"
|
||||
:key="option.value"
|
||||
class="flex items-center gap-3"
|
||||
:value="option.value"
|
||||
:class="optionCardClass"
|
||||
>
|
||||
<RadioButton
|
||||
:model-value="(modelValue as string) ?? ''"
|
||||
:input-id="`${field.id}-${option.value}`"
|
||||
:name="field.id"
|
||||
:value="option.value"
|
||||
:dt="checkedTokens"
|
||||
@update:model-value="onSingleChange"
|
||||
<i
|
||||
v-if="option.icon"
|
||||
:class="
|
||||
cn('size-4 shrink-0 text-primary-comfy-canvas/60', option.icon)
|
||||
"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
<label
|
||||
:for="`${field.id}-${option.value}`"
|
||||
class="cursor-pointer text-sm"
|
||||
>{{ resolveOptionLabel(option) }}</label
|
||||
>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else>
|
||||
<div
|
||||
<span class="flex-1">{{ resolveOptionLabel(option) }}</span>
|
||||
<i :class="checkMarkClass" aria-hidden="true" />
|
||||
</ToggleGroupItem>
|
||||
</ToggleGroup>
|
||||
<ToggleGroup
|
||||
v-else
|
||||
:model-value="(modelValue as string[]) ?? []"
|
||||
type="multiple"
|
||||
class="flex w-full flex-col gap-2"
|
||||
@update:model-value="onMultiChange"
|
||||
>
|
||||
<ToggleGroupItem
|
||||
v-for="option in field.options"
|
||||
:id="`${field.id}-${option.value}`"
|
||||
:key="option.value"
|
||||
class="flex items-center gap-3"
|
||||
:value="option.value"
|
||||
:class="optionCardClass"
|
||||
>
|
||||
<Checkbox
|
||||
:model-value="(modelValue as string[]) ?? []"
|
||||
:input-id="`${field.id}-${option.value}`"
|
||||
:value="option.value"
|
||||
:dt="checkedTokens"
|
||||
@update:model-value="onMultiChange"
|
||||
<i
|
||||
v-if="option.icon"
|
||||
:class="
|
||||
cn('size-4 shrink-0 text-primary-comfy-canvas/60', option.icon)
|
||||
"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
<label
|
||||
:for="`${field.id}-${option.value}`"
|
||||
class="cursor-pointer text-sm"
|
||||
>{{ resolveOptionLabel(option) }}</label
|
||||
>
|
||||
</div>
|
||||
</template>
|
||||
<span class="flex-1">{{ resolveOptionLabel(option) }}</span>
|
||||
<i :class="checkMarkClass" aria-hidden="true" />
|
||||
</ToggleGroupItem>
|
||||
</ToggleGroup>
|
||||
<Input
|
||||
v-if="field.allowOther && field.otherFieldId && modelValue === 'other'"
|
||||
v-if="field.allowOther && field.otherFieldId && isOtherSelected"
|
||||
:model-value="(otherValue as string) ?? ''"
|
||||
:class="inputClass"
|
||||
:maxlength="OTHER_TEXT_MAX_LENGTH"
|
||||
:placeholder="
|
||||
$t(
|
||||
`cloudOnboarding.survey.options.${field.id}.otherPlaceholder`,
|
||||
$t('cloudOnboarding.survey.otherPlaceholder')
|
||||
)
|
||||
"
|
||||
class="ml-1"
|
||||
@update:model-value="onOtherChange"
|
||||
/>
|
||||
<p v-if="errorMessage" class="text-danger text-xs">{{ errorMessage }}</p>
|
||||
@@ -65,7 +75,7 @@
|
||||
<div v-else class="flex flex-col gap-3">
|
||||
<label
|
||||
:for="controlId"
|
||||
class="block text-lg font-medium text-base-foreground"
|
||||
class="block text-lg font-medium text-primary-comfy-canvas"
|
||||
>
|
||||
{{ resolvedLabel }}
|
||||
</label>
|
||||
@@ -74,6 +84,7 @@
|
||||
:model-value="(modelValue as string) ?? ''"
|
||||
:placeholder="field.placeholder"
|
||||
:aria-invalid="Boolean(errorMessage)"
|
||||
:class="inputClass"
|
||||
@update:model-value="onTextChange"
|
||||
/>
|
||||
<p v-if="errorMessage" class="text-danger text-xs">{{ errorMessage }}</p>
|
||||
@@ -81,18 +92,20 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import Checkbox from 'primevue/checkbox'
|
||||
import RadioButton from 'primevue/radiobutton'
|
||||
import { useId } from 'vue'
|
||||
import { cn } from '@comfyorg/tailwind-utils'
|
||||
import { computed, useId } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
import Input from '@/components/ui/input/Input.vue'
|
||||
import { ToggleGroup, ToggleGroupItem } from '@/components/ui/toggle-group'
|
||||
import type {
|
||||
LocalizedString,
|
||||
OnboardingSurveyField,
|
||||
OnboardingSurveyOption
|
||||
} from '@/platform/remoteConfig/types'
|
||||
|
||||
import { OTHER_TEXT_MAX_LENGTH } from './surveySchema'
|
||||
|
||||
const {
|
||||
field,
|
||||
modelValue,
|
||||
@@ -113,25 +126,31 @@ const emit = defineEmits<{
|
||||
const { t, te, locale } = useI18n()
|
||||
const controlId = useId()
|
||||
|
||||
const optionCardClass =
|
||||
'group h-auto w-full items-center justify-start gap-3 rounded-md border border-solid border-smoke-800/10 bg-smoke-800/10 px-4 py-3 text-left text-sm text-primary-comfy-canvas shadow-inset-highlight transition-colors hover:bg-sand-300/20 data-[state=on]:bg-sand-300/15 data-[state=on]:ring-1 data-[state=on]:ring-inset data-[state=on]:ring-brand-yellow'
|
||||
|
||||
const checkMarkClass =
|
||||
'icon-[lucide--check] size-4 shrink-0 text-brand-yellow opacity-0 group-data-[state=on]:opacity-100'
|
||||
|
||||
const inputClass =
|
||||
'border-smoke-800/10 bg-smoke-800/10 text-primary-comfy-canvas placeholder:text-primary-comfy-canvas/50 focus-visible:ring-inset'
|
||||
|
||||
const isOtherSelected = computed(() =>
|
||||
Array.isArray(modelValue)
|
||||
? modelValue.includes('other')
|
||||
: modelValue === 'other'
|
||||
)
|
||||
|
||||
const resolveLocalized = (value: LocalizedString): string => {
|
||||
if (typeof value === 'string') return value
|
||||
return value[locale.value] ?? value.en ?? Object.values(value)[0] ?? ''
|
||||
}
|
||||
|
||||
const checkedTokens = {
|
||||
checked: {
|
||||
background: 'var(--color-electric-400)',
|
||||
borderColor: 'var(--color-electric-400)',
|
||||
hoverBackground: 'var(--color-electric-400)',
|
||||
hoverBorderColor: 'var(--color-electric-400)'
|
||||
}
|
||||
}
|
||||
|
||||
const resolvedLabel = (() => {
|
||||
const resolvedLabel = computed(() => {
|
||||
if (field.labelKey && te(field.labelKey)) return t(field.labelKey)
|
||||
if (field.label != null) return resolveLocalized(field.label)
|
||||
return field.id
|
||||
})()
|
||||
})
|
||||
|
||||
const resolveOptionLabel = (option: OnboardingSurveyOption): string => {
|
||||
if (option.labelKey && te(option.labelKey)) return t(option.labelKey)
|
||||
@@ -143,13 +162,10 @@ const onSingleChange = (value: unknown) => {
|
||||
emit('update:modelValue', typeof value === 'string' ? value : '')
|
||||
}
|
||||
const onMultiChange = (value: unknown) => {
|
||||
if (!Array.isArray(value)) {
|
||||
emit('update:modelValue', [])
|
||||
return
|
||||
}
|
||||
const selected = Array.isArray(value) ? value : []
|
||||
emit(
|
||||
'update:modelValue',
|
||||
value.filter((v): v is string => typeof v === 'string')
|
||||
selected.filter((v): v is string => typeof v === 'string')
|
||||
)
|
||||
}
|
||||
const onTextChange = (value: string | number | undefined) => {
|
||||
|
||||
@@ -1,320 +1,383 @@
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { render, screen } from '@testing-library/vue'
|
||||
import PrimeVue from 'primevue/config'
|
||||
import { render, screen, waitFor } from '@testing-library/vue'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { createI18n } from 'vue-i18n'
|
||||
|
||||
import enMessages from '@/locales/en/main.json'
|
||||
import type { OnboardingSurvey } from '@/platform/remoteConfig/types'
|
||||
|
||||
import DynamicSurveyForm from './DynamicSurveyForm.vue'
|
||||
|
||||
const flushPromises = () => new Promise((resolve) => setTimeout(resolve, 0))
|
||||
|
||||
const i18n = createI18n({
|
||||
legacy: false,
|
||||
locale: 'en',
|
||||
messages: {
|
||||
en: {
|
||||
g: { back: 'Back', next: 'Next', submit: 'Submit' },
|
||||
cloudOnboarding: {
|
||||
survey: {
|
||||
intro: 'Help us tailor your ComfyUI experience.',
|
||||
errors: {
|
||||
chooseAnOption: 'Please choose an option.',
|
||||
selectAtLeastOne: 'Please select at least one option.',
|
||||
describeAnswer: 'Please describe your answer.'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
import { defaultOnboardingSurvey } from './defaultSurveySchema'
|
||||
|
||||
const renderForm = (survey: OnboardingSurvey) =>
|
||||
render(DynamicSurveyForm, {
|
||||
global: { plugins: [PrimeVue, i18n] },
|
||||
global: {
|
||||
plugins: [
|
||||
createI18n({
|
||||
legacy: false,
|
||||
locale: 'en',
|
||||
messages: { en: enMessages }
|
||||
})
|
||||
]
|
||||
},
|
||||
props: { survey }
|
||||
})
|
||||
|
||||
const clickOption = (user: ReturnType<typeof userEvent.setup>, label: string) =>
|
||||
user.click(screen.getByText(label))
|
||||
|
||||
const firstSubmitPayload = (
|
||||
emitted: Record<string, unknown[]>
|
||||
): Record<string, unknown> | undefined =>
|
||||
(emitted.submit?.[0] as [Record<string, unknown>] | undefined)?.[0]
|
||||
|
||||
const twoStepSurvey: OnboardingSurvey = {
|
||||
version: 1,
|
||||
introKey: 'cloudOnboarding.survey.intro',
|
||||
fields: [
|
||||
{
|
||||
id: 'usage',
|
||||
type: 'single',
|
||||
label: 'How do you plan to use ComfyUI?',
|
||||
required: true,
|
||||
options: [
|
||||
{ value: 'personal', label: 'Personal use' },
|
||||
{ value: 'work', label: 'Work' }
|
||||
]
|
||||
},
|
||||
{
|
||||
id: 'intent',
|
||||
type: 'multi',
|
||||
label: 'What do you want to create with ComfyUI?',
|
||||
type: 'single',
|
||||
label: 'What do you want to make?',
|
||||
required: true,
|
||||
options: [
|
||||
{ value: 'images', label: 'Images' },
|
||||
{ value: 'videos', label: 'Videos' }
|
||||
{ value: 'video', label: 'Video' }
|
||||
]
|
||||
},
|
||||
{
|
||||
id: 'making',
|
||||
type: 'multi',
|
||||
label: 'Pick everything that applies',
|
||||
required: true,
|
||||
options: [
|
||||
{ value: 'a', label: 'Making A' },
|
||||
{ value: 'b', label: 'Making B' }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
describe('DynamicSurveyForm', () => {
|
||||
it('renders the intro text and the first field options', () => {
|
||||
renderForm(twoStepSurvey)
|
||||
const branchedSurvey: OnboardingSurvey = {
|
||||
version: 1,
|
||||
fields: [
|
||||
{
|
||||
id: 'intent',
|
||||
type: 'single',
|
||||
label: 'What do you want to make?',
|
||||
required: true,
|
||||
options: [
|
||||
{ value: 'workflows', label: 'Workflows' },
|
||||
{ value: 'images', label: 'Images' }
|
||||
]
|
||||
},
|
||||
{
|
||||
id: 'focus',
|
||||
type: 'single',
|
||||
label: 'What are you building?',
|
||||
required: true,
|
||||
showWhen: { field: 'intent', equals: 'workflows' },
|
||||
options: [{ value: 'custom_nodes', label: 'Custom nodes' }]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
expect(
|
||||
screen.getByText('Help us tailor your ComfyUI experience.')
|
||||
).toBeInTheDocument()
|
||||
expect(screen.getByText('How do you plan to use ComfyUI?')).toBeVisible()
|
||||
expect(screen.getByLabelText('Personal use')).toBeInTheDocument()
|
||||
expect(screen.getByLabelText('Work')).toBeInTheDocument()
|
||||
describe('DynamicSurveyForm', () => {
|
||||
it('renders the real default schema (v3) with its first question and options', () => {
|
||||
expect(defaultOnboardingSurvey.version).toBe(3)
|
||||
const firstField = defaultOnboardingSurvey.fields[0]!
|
||||
renderForm(defaultOnboardingSurvey)
|
||||
|
||||
expect(screen.getByText('What do you want to make?')).toBeVisible()
|
||||
expect(screen.getByText('Images')).toBeInTheDocument()
|
||||
expect(screen.getAllByRole('button')).toHaveLength(
|
||||
firstField.options!.length
|
||||
)
|
||||
})
|
||||
|
||||
it('disables Next until the user selects an option, then advances', async () => {
|
||||
it('auto-advances when a single-select option is chosen', async () => {
|
||||
const user = userEvent.setup()
|
||||
renderForm(twoStepSurvey)
|
||||
|
||||
const next = screen.getByRole('button', { name: 'Next' })
|
||||
expect(next).toBeDisabled()
|
||||
|
||||
await user.click(screen.getByLabelText('Personal use'))
|
||||
expect(next).toBeEnabled()
|
||||
|
||||
await user.click(next)
|
||||
await flushPromises()
|
||||
// No Next click — choosing the card advances the wizard.
|
||||
await clickOption(user, 'Images')
|
||||
|
||||
expect(
|
||||
screen.getByText('What do you want to create with ComfyUI?')
|
||||
await screen.findByText('Pick everything that applies')
|
||||
).toBeVisible()
|
||||
expect(screen.getByLabelText('Images')).toBeInTheDocument()
|
||||
expect(screen.getByRole('button', { name: 'Back' })).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('does not auto-advance a multi-select step; Submit gates on a choice', async () => {
|
||||
const user = userEvent.setup()
|
||||
renderForm(twoStepSurvey)
|
||||
|
||||
await clickOption(user, 'Images')
|
||||
|
||||
const submit = await screen.findByRole('button', { name: 'Submit' })
|
||||
expect(submit).toBeDisabled()
|
||||
|
||||
await clickOption(user, 'Making A')
|
||||
// Still on the multi step (no auto-advance), now submittable.
|
||||
expect(screen.getByText('Pick everything that applies')).toBeVisible()
|
||||
await waitFor(() => expect(submit).toBeEnabled())
|
||||
})
|
||||
|
||||
it('navigates back to the previous step', async () => {
|
||||
const user = userEvent.setup()
|
||||
renderForm(twoStepSurvey)
|
||||
|
||||
await user.click(screen.getByLabelText('Personal use'))
|
||||
await user.click(screen.getByRole('button', { name: 'Next' }))
|
||||
await flushPromises()
|
||||
await clickOption(user, 'Images')
|
||||
expect(
|
||||
screen.getByText('What do you want to create with ComfyUI?')
|
||||
await screen.findByText('Pick everything that applies')
|
||||
).toBeVisible()
|
||||
|
||||
await user.click(screen.getByRole('button', { name: 'Back' }))
|
||||
await flushPromises()
|
||||
expect(screen.getByText('How do you plan to use ComfyUI?')).toBeVisible()
|
||||
expect(await screen.findByText('What do you want to make?')).toBeVisible()
|
||||
})
|
||||
|
||||
it('resolves option and field labels via labelKey when provided', () => {
|
||||
const localizedI18n = createI18n({
|
||||
legacy: false,
|
||||
locale: 'en',
|
||||
messages: {
|
||||
en: {
|
||||
g: { back: 'Back', next: 'Next', submit: 'Submit' },
|
||||
cloudOnboarding: {
|
||||
survey: {
|
||||
intro: 'Help us tailor your ComfyUI experience.',
|
||||
errors: {
|
||||
chooseAnOption: '',
|
||||
selectAtLeastOne: '',
|
||||
describeAnswer: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
survey_label: 'Localized question?',
|
||||
survey_a: 'Localized A',
|
||||
survey_b: 'Localized B'
|
||||
}
|
||||
}
|
||||
})
|
||||
it('offers Next on an already-answered single-select reached via Back', async () => {
|
||||
const user = userEvent.setup()
|
||||
renderForm(twoStepSurvey)
|
||||
|
||||
render(DynamicSurveyForm, {
|
||||
global: { plugins: [PrimeVue, localizedI18n] },
|
||||
props: {
|
||||
survey: {
|
||||
version: 1,
|
||||
fields: [
|
||||
{
|
||||
id: 'q',
|
||||
type: 'single',
|
||||
labelKey: 'survey_label',
|
||||
required: true,
|
||||
options: [
|
||||
{ value: 'a', labelKey: 'survey_a' },
|
||||
{ value: 'b', labelKey: 'survey_b' }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
})
|
||||
await clickOption(user, 'Images')
|
||||
await screen.findByText('Pick everything that applies')
|
||||
await user.click(screen.getByRole('button', { name: 'Back' }))
|
||||
|
||||
expect(screen.getByText('Localized question?')).toBeVisible()
|
||||
expect(screen.getByLabelText('Localized A')).toBeInTheDocument()
|
||||
expect(screen.getByLabelText('Localized B')).toBeInTheDocument()
|
||||
const next = await screen.findByRole('button', { name: 'Next' })
|
||||
await user.click(next)
|
||||
expect(
|
||||
await screen.findByText('Pick everything that applies')
|
||||
).toBeVisible()
|
||||
})
|
||||
|
||||
it('renders server-supplied translations from a label locale map', () => {
|
||||
const koreanI18n = createI18n({
|
||||
legacy: false,
|
||||
locale: 'ko',
|
||||
fallbackLocale: 'en',
|
||||
messages: {
|
||||
en: {
|
||||
g: { back: 'Back', next: 'Next', submit: 'Submit' },
|
||||
cloudOnboarding: {
|
||||
survey: {
|
||||
intro: '',
|
||||
errors: {
|
||||
chooseAnOption: '',
|
||||
selectAtLeastOne: '',
|
||||
describeAnswer: ''
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
ko: { g: { back: '뒤로', next: '다음', submit: '제출' } }
|
||||
}
|
||||
})
|
||||
it('reveals a branched follow-up step from the answer and submits it', async () => {
|
||||
const user = userEvent.setup()
|
||||
const { emitted } = renderForm(branchedSurvey)
|
||||
|
||||
render(DynamicSurveyForm, {
|
||||
global: { plugins: [PrimeVue, koreanI18n] },
|
||||
props: {
|
||||
survey: {
|
||||
version: 1,
|
||||
fields: [
|
||||
{
|
||||
id: 'usage',
|
||||
type: 'single',
|
||||
label: {
|
||||
en: 'How will you use it?',
|
||||
ko: '어떻게 사용하시겠어요?'
|
||||
},
|
||||
required: true,
|
||||
options: [
|
||||
{
|
||||
value: 'personal',
|
||||
label: { en: 'Personal use', ko: '개인 용도' }
|
||||
},
|
||||
{ value: 'work', label: { en: 'Work', ko: '업무' } }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
})
|
||||
await clickOption(user, 'Workflows')
|
||||
expect(await screen.findByText('What are you building?')).toBeVisible()
|
||||
|
||||
expect(screen.getByText('어떻게 사용하시겠어요?')).toBeVisible()
|
||||
expect(screen.getByLabelText('개인 용도')).toBeInTheDocument()
|
||||
expect(screen.getByLabelText('업무')).toBeInTheDocument()
|
||||
await clickOption(user, 'Custom nodes')
|
||||
await user.click(await screen.findByRole('button', { name: 'Submit' }))
|
||||
|
||||
await waitFor(() =>
|
||||
expect(firstSubmitPayload(emitted())).toEqual({
|
||||
intent: 'workflows',
|
||||
focus: 'custom_nodes'
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it('falls back to English when current locale missing from label map', () => {
|
||||
const fallbackI18n = createI18n({
|
||||
legacy: false,
|
||||
locale: 'fr',
|
||||
fallbackLocale: 'en',
|
||||
messages: {
|
||||
en: {
|
||||
g: { back: 'Back', next: 'Next', submit: 'Submit' },
|
||||
cloudOnboarding: {
|
||||
survey: {
|
||||
intro: '',
|
||||
errors: {
|
||||
chooseAnOption: '',
|
||||
selectAtLeastOne: '',
|
||||
describeAnswer: ''
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
fr: {}
|
||||
}
|
||||
})
|
||||
it('hides the branched step when the answer does not match', async () => {
|
||||
const user = userEvent.setup()
|
||||
const { emitted } = renderForm(branchedSurvey)
|
||||
|
||||
render(DynamicSurveyForm, {
|
||||
global: { plugins: [PrimeVue, fallbackI18n] },
|
||||
props: {
|
||||
survey: {
|
||||
version: 1,
|
||||
fields: [
|
||||
{
|
||||
id: 'q',
|
||||
type: 'single',
|
||||
label: { en: 'English question', ko: '한국어' },
|
||||
required: true,
|
||||
options: [
|
||||
{ value: 'a', label: { en: 'English A', ko: '한국어 A' } }
|
||||
]
|
||||
}
|
||||
// 'images' is the last visible step (focus hidden) → Submit, no branch.
|
||||
await clickOption(user, 'Images')
|
||||
const submit = await screen.findByRole('button', { name: 'Submit' })
|
||||
expect(screen.queryByText('What are you building?')).not.toBeInTheDocument()
|
||||
|
||||
await user.click(submit)
|
||||
await waitFor(() =>
|
||||
expect(firstSubmitPayload(emitted())).toEqual({
|
||||
intent: 'images',
|
||||
focus: ''
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it('requires the "other" free-text before submitting, then submits it', async () => {
|
||||
const user = userEvent.setup()
|
||||
const otherSurvey: OnboardingSurvey = {
|
||||
version: 1,
|
||||
fields: [
|
||||
{
|
||||
id: 'source',
|
||||
type: 'single',
|
||||
label: 'How did you find us?',
|
||||
required: true,
|
||||
allowOther: true,
|
||||
otherFieldId: 'sourceOther',
|
||||
options: [
|
||||
{ value: 'search', label: 'Web search' },
|
||||
{ value: 'other', label: 'Somewhere else' }
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
const { emitted } = renderForm(otherSurvey)
|
||||
|
||||
// Selecting 'other' must NOT auto-advance — the text box is required.
|
||||
await clickOption(user, 'Somewhere else')
|
||||
const submit = await screen.findByRole('button', { name: 'Submit' })
|
||||
expect(submit).toBeDisabled()
|
||||
|
||||
await user.type(
|
||||
await screen.findByPlaceholderText('Where did you find us?'),
|
||||
'A newsletter'
|
||||
)
|
||||
await waitFor(() => expect(submit).toBeEnabled())
|
||||
|
||||
await user.click(submit)
|
||||
await waitFor(() =>
|
||||
expect(firstSubmitPayload(emitted())).toEqual({ source: 'A newsletter' })
|
||||
)
|
||||
})
|
||||
|
||||
it('surfaces the free-text error once "other" text is touched then cleared', async () => {
|
||||
const user = userEvent.setup()
|
||||
const otherSurvey: OnboardingSurvey = {
|
||||
version: 1,
|
||||
fields: [
|
||||
{
|
||||
id: 'source',
|
||||
type: 'single',
|
||||
label: 'How did you find us?',
|
||||
required: true,
|
||||
allowOther: true,
|
||||
otherFieldId: 'sourceOther',
|
||||
options: [
|
||||
{ value: 'search', label: 'Web search' },
|
||||
{ value: 'other', label: 'Somewhere else' }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
renderForm(otherSurvey)
|
||||
|
||||
await clickOption(user, 'Somewhere else')
|
||||
const input = await screen.findByPlaceholderText('Where did you find us?')
|
||||
// Type then clear → the free-text field is touched but empty, so its
|
||||
// required error surfaces.
|
||||
await user.type(input, 'x')
|
||||
await user.clear(input)
|
||||
expect(
|
||||
await screen.findByText('Please describe your answer.')
|
||||
).toBeVisible()
|
||||
})
|
||||
|
||||
it('shows a required-field error only after the user interacts, not before', async () => {
|
||||
const user = userEvent.setup()
|
||||
renderForm({
|
||||
version: 1,
|
||||
fields: [
|
||||
{
|
||||
id: 'making',
|
||||
type: 'multi',
|
||||
label: 'Pick everything that applies',
|
||||
required: true,
|
||||
options: [{ value: 'a', label: 'Making A' }]
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
// fr is not in the map → falls back to en
|
||||
expect(screen.getByText('English question')).toBeVisible()
|
||||
expect(screen.getByLabelText('English A')).toBeInTheDocument()
|
||||
// No error on first render (field untouched).
|
||||
expect(
|
||||
screen.queryByText('Please select at least one option.')
|
||||
).not.toBeInTheDocument()
|
||||
|
||||
// Select then clear → field is touched but empty → error surfaces.
|
||||
await user.click(screen.getByText('Making A'))
|
||||
await user.click(screen.getByText('Making A'))
|
||||
expect(
|
||||
await screen.findByText('Please select at least one option.')
|
||||
).toBeVisible()
|
||||
})
|
||||
|
||||
it('allows advancing past an optional field while still empty', async () => {
|
||||
const user = userEvent.setup()
|
||||
render(DynamicSurveyForm, {
|
||||
global: { plugins: [PrimeVue, i18n] },
|
||||
props: {
|
||||
survey: {
|
||||
version: 1,
|
||||
fields: [
|
||||
{
|
||||
id: 'q1',
|
||||
type: 'single',
|
||||
label: 'Optional question?',
|
||||
options: [
|
||||
{ value: 'a', label: 'A' },
|
||||
{ value: 'b', label: 'B' }
|
||||
]
|
||||
// no required: true — should be skippable
|
||||
},
|
||||
{
|
||||
id: 'q2',
|
||||
type: 'single',
|
||||
label: 'Required question?',
|
||||
required: true,
|
||||
options: [{ value: 'c', label: 'C' }]
|
||||
}
|
||||
renderForm({
|
||||
version: 1,
|
||||
fields: [
|
||||
{
|
||||
id: 'q1',
|
||||
type: 'single',
|
||||
label: 'Optional question?',
|
||||
options: [
|
||||
{ value: 'a', label: 'A' },
|
||||
{ value: 'b', label: 'B' }
|
||||
]
|
||||
// no required: true — should be skippable
|
||||
},
|
||||
{
|
||||
id: 'q2',
|
||||
type: 'single',
|
||||
label: 'Required question?',
|
||||
required: true,
|
||||
options: [{ value: 'c', label: 'C' }]
|
||||
}
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
const next = screen.getByRole('button', { name: 'Next' })
|
||||
expect(next).toBeEnabled()
|
||||
|
||||
await user.click(next)
|
||||
await flushPromises()
|
||||
expect(screen.getByText('Required question?')).toBeVisible()
|
||||
expect(await screen.findByText('Required question?')).toBeVisible()
|
||||
})
|
||||
|
||||
it('enables Submit only after the multi-select field has at least one choice', async () => {
|
||||
it('resets to the first step when the survey prop changes', async () => {
|
||||
const user = userEvent.setup()
|
||||
renderForm(twoStepSurvey)
|
||||
const { rerender } = render(DynamicSurveyForm, {
|
||||
global: {
|
||||
plugins: [
|
||||
createI18n({
|
||||
legacy: false,
|
||||
locale: 'en',
|
||||
messages: { en: enMessages }
|
||||
})
|
||||
]
|
||||
},
|
||||
props: { survey: twoStepSurvey }
|
||||
})
|
||||
|
||||
await user.click(screen.getByLabelText('Work'))
|
||||
await user.click(screen.getByRole('button', { name: 'Next' }))
|
||||
await flushPromises()
|
||||
await clickOption(user, 'Images')
|
||||
expect(
|
||||
await screen.findByText('Pick everything that applies')
|
||||
).toBeVisible()
|
||||
|
||||
const submitBtn = screen.getByRole('button', { name: 'Submit' })
|
||||
expect(submitBtn).toBeDisabled()
|
||||
await rerender({ survey: branchedSurvey })
|
||||
// Back on step 0 of the new survey (no Back button on the first step).
|
||||
expect(await screen.findByText('What do you want to make?')).toBeVisible()
|
||||
expect(
|
||||
screen.queryByRole('button', { name: 'Back' })
|
||||
).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
await user.click(screen.getByRole('checkbox', { name: /Images/i }))
|
||||
await flushPromises()
|
||||
expect(submitBtn).toBeEnabled()
|
||||
it('renders server-supplied label translations and falls back to English', () => {
|
||||
render(DynamicSurveyForm, {
|
||||
global: {
|
||||
plugins: [
|
||||
createI18n({
|
||||
legacy: false,
|
||||
locale: 'ko',
|
||||
fallbackLocale: 'en',
|
||||
messages: { en: enMessages, ko: { g: { next: '다음' } } }
|
||||
})
|
||||
]
|
||||
},
|
||||
props: {
|
||||
survey: {
|
||||
version: 1,
|
||||
fields: [
|
||||
{
|
||||
id: 'intent',
|
||||
type: 'single',
|
||||
label: { en: 'What will you make?', ko: '무엇을 만들 건가요?' },
|
||||
required: true,
|
||||
options: [
|
||||
// ko provided → localized; ko missing → English fallback
|
||||
{ value: 'images', label: { en: 'Images', ko: '이미지' } },
|
||||
{ value: 'video', label: { en: 'Video' } }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
expect(screen.getByText('무엇을 만들 건가요?')).toBeVisible()
|
||||
expect(screen.getByText('이미지')).toBeInTheDocument()
|
||||
expect(screen.getByText('Video')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,109 +1,118 @@
|
||||
<template>
|
||||
<form class="flex size-full flex-col" @submit.prevent="onSubmit">
|
||||
<p v-if="introText" class="mb-4 text-sm text-muted">
|
||||
<form class="flex w-full flex-col" @submit.prevent="onSubmit">
|
||||
<p v-if="introText" class="mb-4 text-sm text-muted-foreground">
|
||||
{{ introText }}
|
||||
</p>
|
||||
<div
|
||||
class="mb-8 h-2 w-full overflow-hidden rounded-full bg-secondary-background"
|
||||
class="mb-8 h-1.5 w-full overflow-hidden rounded-full bg-primary-comfy-canvas/10"
|
||||
>
|
||||
<div
|
||||
class="h-full bg-electric-400 transition-[width] duration-300 ease-out"
|
||||
class="h-full bg-brand-yellow transition-[width] duration-300 ease-out"
|
||||
:style="{ width: `${progressPercent}%` }"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-1 flex-col overflow-hidden">
|
||||
<div
|
||||
v-if="currentField"
|
||||
:key="currentField.id"
|
||||
class="flex flex-1 flex-col gap-4 overflow-y-auto pr-1"
|
||||
>
|
||||
<DynamicSurveyField
|
||||
:field="currentField"
|
||||
:model-value="values[currentField.id]"
|
||||
:other-value="
|
||||
currentField.otherFieldId
|
||||
? (values[currentField.otherFieldId] as string)
|
||||
: undefined
|
||||
"
|
||||
:error-message="
|
||||
errors[currentField.id] ??
|
||||
(currentField.otherFieldId
|
||||
? errors[currentField.otherFieldId]
|
||||
: undefined)
|
||||
"
|
||||
@update:model-value="(value) => onFieldChange(currentField.id, value)"
|
||||
@update:other-value="
|
||||
(value) =>
|
||||
currentField.otherFieldId &&
|
||||
onFieldChange(currentField.otherFieldId, value)
|
||||
"
|
||||
/>
|
||||
<div
|
||||
class="overflow-hidden transition-[height] duration-300 ease-out"
|
||||
:style="animatedHeightStyle"
|
||||
>
|
||||
<div ref="questionContent" class="relative">
|
||||
<Transition
|
||||
enter-active-class="transition-opacity duration-300 ease-out"
|
||||
enter-from-class="opacity-0"
|
||||
leave-active-class="absolute inset-x-0 top-0 transition-opacity duration-300 ease-out"
|
||||
leave-to-class="opacity-0"
|
||||
>
|
||||
<div
|
||||
v-if="currentField"
|
||||
:key="currentField.id"
|
||||
class="flex flex-col gap-4"
|
||||
>
|
||||
<DynamicSurveyField
|
||||
:field="currentField"
|
||||
:model-value="values[currentField.id]"
|
||||
:other-value="
|
||||
currentField.otherFieldId
|
||||
? (values[currentField.otherFieldId] as string)
|
||||
: undefined
|
||||
"
|
||||
:error-message="currentError"
|
||||
@update:model-value="
|
||||
(value) => void onFieldChange(currentField.id, value)
|
||||
"
|
||||
@update:other-value="
|
||||
(value) =>
|
||||
currentField.otherFieldId &&
|
||||
void onFieldChange(currentField.otherFieldId, value)
|
||||
"
|
||||
/>
|
||||
</div>
|
||||
</Transition>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex gap-6 pt-4">
|
||||
<div
|
||||
v-if="!isFirst || showNext || isLast"
|
||||
class="mt-8 flex items-center justify-between gap-4"
|
||||
>
|
||||
<Button
|
||||
v-if="!isFirst"
|
||||
type="button"
|
||||
variant="secondary"
|
||||
class="h-10 flex-1 text-white"
|
||||
variant="link"
|
||||
size="lg"
|
||||
class="px-0 text-primary-comfy-canvas/70 hover:text-primary-comfy-canvas"
|
||||
@click="goPrevious"
|
||||
>
|
||||
<i class="icon-[lucide--chevron-left] size-4" aria-hidden="true" />
|
||||
{{ $t('g.back') }}
|
||||
</Button>
|
||||
<span v-else class="flex-1" />
|
||||
<span v-else />
|
||||
<Button
|
||||
v-if="!isLast"
|
||||
v-if="showNext"
|
||||
type="button"
|
||||
size="lg"
|
||||
:disabled="!isCurrentValid"
|
||||
:class="
|
||||
cn(
|
||||
'h-10 flex-1 border-none',
|
||||
isCurrentValid
|
||||
? 'bg-electric-400 text-black hover:bg-electric-400/85'
|
||||
: 'bg-zinc-800 text-zinc-500'
|
||||
)
|
||||
"
|
||||
class="bg-brand-yellow text-primary-comfy-ink hover:bg-brand-yellow/85 disabled:bg-smoke-800/10 disabled:text-primary-comfy-canvas/40 disabled:opacity-100"
|
||||
@click="goNext"
|
||||
>
|
||||
{{ $t('g.next') }}
|
||||
<i class="icon-[lucide--chevron-right] size-4" aria-hidden="true" />
|
||||
</Button>
|
||||
<Button
|
||||
v-else
|
||||
v-else-if="isLast"
|
||||
type="submit"
|
||||
size="lg"
|
||||
:disabled="!isCurrentValid || isSubmitting"
|
||||
:loading="isSubmitting"
|
||||
:class="
|
||||
cn(
|
||||
'h-10 flex-1 border-none',
|
||||
isCurrentValid && !isSubmitting
|
||||
? 'bg-electric-400 text-black hover:bg-electric-400/85'
|
||||
: 'bg-zinc-800 text-zinc-500'
|
||||
)
|
||||
"
|
||||
class="bg-brand-yellow text-primary-comfy-ink hover:bg-brand-yellow/85 disabled:bg-smoke-800/10 disabled:text-primary-comfy-canvas/40 disabled:opacity-100"
|
||||
>
|
||||
{{ $t('g.submit') }}
|
||||
</Button>
|
||||
<span v-else />
|
||||
</div>
|
||||
</form>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { cn } from '@comfyorg/tailwind-utils'
|
||||
import { useElementSize } from '@vueuse/core'
|
||||
import { toTypedSchema } from '@vee-validate/zod'
|
||||
import { useForm } from 'vee-validate'
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import { computed, nextTick, ref, useTemplateRef, watch } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
import Button from '@/components/ui/button/Button.vue'
|
||||
import type { OnboardingSurvey } from '@/platform/remoteConfig/types'
|
||||
import type {
|
||||
OnboardingSurvey,
|
||||
OnboardingSurveyField
|
||||
} from '@/platform/remoteConfig/types'
|
||||
|
||||
import DynamicSurveyField from './DynamicSurveyField.vue'
|
||||
import {
|
||||
buildInitialValues,
|
||||
buildSubmissionPayload,
|
||||
buildZodSchema,
|
||||
hasNonEmptyValue,
|
||||
isOtherValue,
|
||||
prepareSurvey,
|
||||
visibleFields
|
||||
} from './surveySchema'
|
||||
@@ -147,6 +156,8 @@ watch(
|
||||
liveValues.value = { ...fresh }
|
||||
resetForm({ values: fresh })
|
||||
stepIndex.value = 0
|
||||
touched.value = new Set()
|
||||
isAdvancing.value = false
|
||||
}
|
||||
)
|
||||
|
||||
@@ -154,11 +165,43 @@ const visible = computed(() =>
|
||||
visibleFields(preparedSurvey.value, values as SurveyValues)
|
||||
)
|
||||
const stepIndex = ref(0)
|
||||
const touched = ref(new Set<string>())
|
||||
const isAdvancing = ref(false)
|
||||
|
||||
const questionContent = useTemplateRef<HTMLElement>('questionContent')
|
||||
const { height: contentHeight } = useElementSize(questionContent)
|
||||
const animatedHeightStyle = computed(() =>
|
||||
contentHeight.value ? { height: `${contentHeight.value}px` } : {}
|
||||
)
|
||||
|
||||
const currentField = computed(() => visible.value[stepIndex.value])
|
||||
const isFirst = computed(() => stepIndex.value === 0)
|
||||
const isLast = computed(() => stepIndex.value === visible.value.length - 1)
|
||||
|
||||
const showNext = computed(() => {
|
||||
if (isLast.value || isAdvancing.value) return false
|
||||
const field = currentField.value
|
||||
if (!field) return false
|
||||
if (field.type !== 'single') return true
|
||||
return !(field.required && !hasNonEmptyValue(values[field.id]))
|
||||
})
|
||||
|
||||
const currentError = computed(() => {
|
||||
const field = currentField.value
|
||||
if (!field) return undefined
|
||||
if (touched.value.has(field.id) && errors.value[field.id]) {
|
||||
return errors.value[field.id]
|
||||
}
|
||||
if (
|
||||
field.otherFieldId &&
|
||||
touched.value.has(field.otherFieldId) &&
|
||||
errors.value[field.otherFieldId]
|
||||
) {
|
||||
return errors.value[field.otherFieldId]
|
||||
}
|
||||
return undefined
|
||||
})
|
||||
|
||||
const totalSteps = computed(() => Math.max(visible.value.length, 1))
|
||||
const progressPercent = computed(() =>
|
||||
Math.max(
|
||||
@@ -172,26 +215,41 @@ const isCurrentValid = computed(() => {
|
||||
if (!field) return false
|
||||
|
||||
const value = values[field.id]
|
||||
const isEmpty =
|
||||
field.type === 'multi'
|
||||
? !Array.isArray(value) || value.length === 0
|
||||
: typeof value !== 'string' || value.length === 0
|
||||
if (!hasNonEmptyValue(value)) return !field.required
|
||||
|
||||
if (isEmpty) return !field.required
|
||||
|
||||
if (field.allowOther && field.otherFieldId && value === 'other') {
|
||||
if (field.allowOther && field.otherFieldId && isOtherValue(value)) {
|
||||
const other = values[field.otherFieldId]
|
||||
return typeof other === 'string' && other.trim().length > 0
|
||||
}
|
||||
return true
|
||||
})
|
||||
|
||||
const onFieldChange = (id: string, value: string | string[]) => {
|
||||
const isAutoAdvanceValue = (field: OnboardingSurveyField, value: unknown) =>
|
||||
field.type === 'single' &&
|
||||
typeof value === 'string' &&
|
||||
value !== '' &&
|
||||
value !== 'other'
|
||||
|
||||
const markTouched = (id: string) => {
|
||||
touched.value = new Set(touched.value).add(id)
|
||||
}
|
||||
|
||||
const onFieldChange = async (id: string, value: string | string[]) => {
|
||||
if (isAdvancing.value) return
|
||||
markTouched(id)
|
||||
setFieldValue(id, value)
|
||||
liveValues.value = { ...liveValues.value, [id]: value }
|
||||
if (stepIndex.value > visible.value.length - 1) {
|
||||
stepIndex.value = Math.max(0, visible.value.length - 1)
|
||||
}
|
||||
|
||||
const field = currentField.value
|
||||
if (field?.id === id && isAutoAdvanceValue(field, value)) {
|
||||
isAdvancing.value = true
|
||||
await nextTick()
|
||||
goNext()
|
||||
isAdvancing.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const goNext = () => {
|
||||
@@ -202,6 +260,11 @@ const goPrevious = () => {
|
||||
}
|
||||
|
||||
const onSubmit = async () => {
|
||||
const field = currentField.value
|
||||
if (field) {
|
||||
markTouched(field.id)
|
||||
if (field.otherFieldId) markTouched(field.otherFieldId)
|
||||
}
|
||||
const result = await validate()
|
||||
if (!result.valid) return
|
||||
emit(
|
||||
|
||||
@@ -1,55 +1,61 @@
|
||||
import type { OnboardingSurvey } from '@/platform/remoteConfig/types'
|
||||
import type {
|
||||
OnboardingSurvey,
|
||||
OnboardingSurveyOption
|
||||
} from '@/platform/remoteConfig/types'
|
||||
|
||||
const optionsFor = (
|
||||
fieldId: string,
|
||||
values: string[]
|
||||
): { value: string; labelKey: string }[] =>
|
||||
values: string[],
|
||||
icons: Record<string, string> = {}
|
||||
): OnboardingSurveyOption[] =>
|
||||
values.map((value) => ({
|
||||
value,
|
||||
labelKey: `cloudOnboarding.survey.options.${fieldId}.${value}`
|
||||
labelKey: `cloudOnboarding.survey.options.${fieldId}.${value}`,
|
||||
...(icons[value] ? { icon: icons[value] } : {})
|
||||
}))
|
||||
|
||||
export const defaultOnboardingSurvey: OnboardingSurvey = {
|
||||
version: 2,
|
||||
version: 3,
|
||||
introKey: 'cloudOnboarding.survey.intro',
|
||||
fields: [
|
||||
{
|
||||
id: 'usage',
|
||||
type: 'single',
|
||||
labelKey: 'cloudSurvey_steps_usage',
|
||||
required: true,
|
||||
options: optionsFor('usage', ['personal', 'work', 'education'])
|
||||
},
|
||||
{
|
||||
id: 'familiarity',
|
||||
type: 'single',
|
||||
labelKey: 'cloudSurvey_steps_familiarity',
|
||||
required: true,
|
||||
options: optionsFor('familiarity', [
|
||||
'new',
|
||||
'starting',
|
||||
'basics',
|
||||
'advanced',
|
||||
'expert'
|
||||
])
|
||||
},
|
||||
{
|
||||
id: 'intent',
|
||||
type: 'multi',
|
||||
type: 'single',
|
||||
labelKey: 'cloudSurvey_steps_intent',
|
||||
required: true,
|
||||
randomize: true,
|
||||
options: optionsFor('intent', [
|
||||
'workflows',
|
||||
'custom_nodes',
|
||||
'videos',
|
||||
'images',
|
||||
'3d_game',
|
||||
'audio',
|
||||
'apps',
|
||||
'api',
|
||||
'not_sure'
|
||||
])
|
||||
allowOther: true,
|
||||
otherFieldId: 'intentOther',
|
||||
options: optionsFor(
|
||||
'intent',
|
||||
['images', 'video', 'workflows', 'apps_api', 'exploring', 'other'],
|
||||
{
|
||||
images: 'icon-[lucide--image]',
|
||||
video: 'icon-[lucide--video]',
|
||||
workflows: 'icon-[lucide--workflow]',
|
||||
apps_api: 'icon-[lucide--blocks]',
|
||||
exploring: 'icon-[lucide--compass]',
|
||||
other: 'icon-[lucide--pencil]'
|
||||
}
|
||||
)
|
||||
},
|
||||
{
|
||||
id: 'experience',
|
||||
type: 'single',
|
||||
labelKey: 'cloudSurvey_steps_experience',
|
||||
required: true,
|
||||
options: optionsFor('experience', ['new', 'some', 'pro'], {
|
||||
new: 'icon-[lucide--sprout]',
|
||||
some: 'icon-[lucide--map]',
|
||||
pro: 'icon-[lucide--rocket]'
|
||||
})
|
||||
},
|
||||
{
|
||||
id: 'focus',
|
||||
type: 'single',
|
||||
labelKey: 'cloudSurvey_steps_focus',
|
||||
required: true,
|
||||
showWhen: { field: 'intent', equals: ['workflows', 'apps_api'] },
|
||||
options: optionsFor('focus', ['custom_nodes', 'pipelines', 'products'])
|
||||
},
|
||||
{
|
||||
id: 'source',
|
||||
@@ -57,19 +63,31 @@ export const defaultOnboardingSurvey: OnboardingSurvey = {
|
||||
labelKey: 'cloudSurvey_steps_source',
|
||||
required: true,
|
||||
randomize: true,
|
||||
allowOther: true,
|
||||
otherFieldId: 'sourceOther',
|
||||
options: optionsFor('source', [
|
||||
'social',
|
||||
'friend',
|
||||
'search',
|
||||
'community',
|
||||
'other'
|
||||
])
|
||||
},
|
||||
{
|
||||
id: 'source_social',
|
||||
type: 'single',
|
||||
labelKey: 'cloudSurvey_steps_source_social',
|
||||
required: true,
|
||||
randomize: true,
|
||||
showWhen: { field: 'source', equals: 'social' },
|
||||
options: optionsFor('source_social', [
|
||||
'youtube',
|
||||
'reddit',
|
||||
'twitter',
|
||||
'instagram',
|
||||
'tiktok',
|
||||
'linkedin',
|
||||
'friend',
|
||||
'search',
|
||||
'newsletter',
|
||||
'conference',
|
||||
'discord',
|
||||
'github',
|
||||
'other'
|
||||
'discord'
|
||||
])
|
||||
}
|
||||
]
|
||||
|
||||
@@ -2,10 +2,13 @@ import { describe, expect, it } from 'vitest'
|
||||
|
||||
import type { OnboardingSurvey } from '@/platform/remoteConfig/types'
|
||||
|
||||
import { defaultOnboardingSurvey } from './defaultSurveySchema'
|
||||
import {
|
||||
OTHER_TEXT_MAX_LENGTH,
|
||||
buildInitialValues,
|
||||
buildSubmissionPayload,
|
||||
buildZodSchema,
|
||||
hasNonEmptyValue,
|
||||
prepareSurvey,
|
||||
visibleFields
|
||||
} from './surveySchema'
|
||||
@@ -246,3 +249,179 @@ describe('prepareSurvey', () => {
|
||||
expect(values.slice(0, -2).sort()).toEqual(['a', 'b'])
|
||||
})
|
||||
})
|
||||
|
||||
describe('defaultOnboardingSurvey branching', () => {
|
||||
const idsFor = (values: Record<string, string | string[]>) =>
|
||||
visibleFields(defaultOnboardingSurvey, values).map((f) => f.id)
|
||||
|
||||
it('asks only the core steps when no branch condition is met', () => {
|
||||
expect(idsFor({ intent: 'images', source: 'friend' })).toEqual([
|
||||
'intent',
|
||||
'experience',
|
||||
'source'
|
||||
])
|
||||
})
|
||||
|
||||
it('asks every step when both branches are active', () => {
|
||||
expect(idsFor({ intent: 'workflows', source: 'social' })).toEqual([
|
||||
'intent',
|
||||
'experience',
|
||||
'focus',
|
||||
'source',
|
||||
'source_social'
|
||||
])
|
||||
})
|
||||
|
||||
it('asks focus only for builder intents (workflows / apps_api)', () => {
|
||||
expect(idsFor({ intent: 'workflows' })).toContain('focus')
|
||||
expect(idsFor({ intent: 'apps_api' })).toContain('focus')
|
||||
expect(idsFor({ intent: 'images' })).not.toContain('focus')
|
||||
expect(idsFor({ intent: 'exploring' })).not.toContain('focus')
|
||||
})
|
||||
|
||||
it('asks source_social only when source is social', () => {
|
||||
expect(idsFor({ source: 'social' })).toContain('source_social')
|
||||
expect(idsFor({ source: 'friend' })).not.toContain('source_social')
|
||||
})
|
||||
|
||||
it('zeroes hidden branch fields in the submission payload', () => {
|
||||
const payload = buildSubmissionPayload(defaultOnboardingSurvey, {
|
||||
intent: 'images',
|
||||
experience: 'new',
|
||||
source: 'friend'
|
||||
})
|
||||
expect(payload).toMatchObject({
|
||||
intent: 'images',
|
||||
experience: 'new',
|
||||
source: 'friend',
|
||||
focus: '',
|
||||
source_social: ''
|
||||
})
|
||||
})
|
||||
|
||||
it('prefers free-text over the "other" sentinel for intent and source', () => {
|
||||
const payload = buildSubmissionPayload(defaultOnboardingSurvey, {
|
||||
intent: 'other',
|
||||
intentOther: ' Comics ',
|
||||
experience: 'pro',
|
||||
source: 'other',
|
||||
sourceOther: 'A podcast'
|
||||
})
|
||||
expect(payload.intent).toBe('Comics')
|
||||
expect(payload.source).toBe('A podcast')
|
||||
})
|
||||
})
|
||||
|
||||
describe('hasNonEmptyValue', () => {
|
||||
const cases: [string | string[] | undefined, boolean][] = [
|
||||
[undefined, false],
|
||||
['', false],
|
||||
[[], false],
|
||||
['a', true],
|
||||
[['a'], true],
|
||||
[['a', 'b'], true]
|
||||
]
|
||||
it.for(cases)('treats %o as non-empty=%o', ([value, expected]) => {
|
||||
expect(hasNonEmptyValue(value)).toBe(expected)
|
||||
})
|
||||
})
|
||||
|
||||
describe('multi-select allowOther', () => {
|
||||
const multiOtherSurvey: OnboardingSurvey = {
|
||||
version: 1,
|
||||
fields: [
|
||||
{
|
||||
id: 'making',
|
||||
type: 'multi',
|
||||
required: true,
|
||||
allowOther: true,
|
||||
otherFieldId: 'makingOther',
|
||||
options: [
|
||||
{ value: 'a', labelKey: 'a' },
|
||||
{ value: 'other', labelKey: 'other' }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
it('requires the free-text when a multi field includes "other"', () => {
|
||||
const schema = buildZodSchema(multiOtherSurvey, {
|
||||
making: ['a', 'other'],
|
||||
makingOther: ''
|
||||
})
|
||||
expect(
|
||||
schema.safeParse({ making: ['a', 'other'], makingOther: '' }).success
|
||||
).toBe(false)
|
||||
expect(
|
||||
schema.safeParse({ making: ['a', 'other'], makingOther: 'Comics' })
|
||||
.success
|
||||
).toBe(true)
|
||||
})
|
||||
|
||||
it('does not require the free-text when "other" is not among the choices', () => {
|
||||
const schema = buildZodSchema(multiOtherSurvey, {
|
||||
making: ['a'],
|
||||
makingOther: ''
|
||||
})
|
||||
expect(schema.safeParse({ making: ['a'], makingOther: '' }).success).toBe(
|
||||
true
|
||||
)
|
||||
})
|
||||
|
||||
it('keeps the array and surfaces the trimmed free-text separately', () => {
|
||||
const payload = buildSubmissionPayload(multiOtherSurvey, {
|
||||
making: ['a', 'other'],
|
||||
makingOther: ' Comics '
|
||||
})
|
||||
expect(payload.making).toEqual(['a', 'other'])
|
||||
expect(payload.makingOther).toBe('Comics')
|
||||
})
|
||||
})
|
||||
|
||||
describe('other free-text validation', () => {
|
||||
const otherSurvey: OnboardingSurvey = {
|
||||
version: 1,
|
||||
fields: [
|
||||
{
|
||||
id: 'source',
|
||||
type: 'single',
|
||||
required: true,
|
||||
allowOther: true,
|
||||
otherFieldId: 'sourceOther',
|
||||
options: [
|
||||
{ value: 'search', labelKey: 'search' },
|
||||
{ value: 'other', labelKey: 'other' }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
it('rejects a whitespace-only "other" answer', () => {
|
||||
const schema = buildZodSchema(otherSurvey, {
|
||||
source: 'other',
|
||||
sourceOther: ' '
|
||||
})
|
||||
expect(
|
||||
schema.safeParse({ source: 'other', sourceOther: ' ' }).success
|
||||
).toBe(false)
|
||||
})
|
||||
|
||||
it('rejects an "other" answer longer than the max length', () => {
|
||||
const schema = buildZodSchema(otherSurvey, {
|
||||
source: 'other',
|
||||
sourceOther: 'x'.repeat(OTHER_TEXT_MAX_LENGTH + 1)
|
||||
})
|
||||
expect(
|
||||
schema.safeParse({
|
||||
source: 'other',
|
||||
sourceOther: 'x'.repeat(OTHER_TEXT_MAX_LENGTH + 1)
|
||||
}).success
|
||||
).toBe(false)
|
||||
expect(
|
||||
schema.safeParse({
|
||||
source: 'other',
|
||||
sourceOther: 'x'.repeat(OTHER_TEXT_MAX_LENGTH)
|
||||
}).success
|
||||
).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -9,12 +9,19 @@ import type {
|
||||
|
||||
export type SurveyValues = Record<string, string | string[] | undefined>
|
||||
|
||||
const hasNonEmptyValue = (current: string | string[] | undefined): boolean => {
|
||||
export const OTHER_TEXT_MAX_LENGTH = 200
|
||||
|
||||
export const hasNonEmptyValue = (
|
||||
current: string | string[] | undefined
|
||||
): boolean => {
|
||||
if (current === undefined || current === '') return false
|
||||
if (Array.isArray(current)) return current.length > 0
|
||||
return true
|
||||
}
|
||||
|
||||
export const isOtherValue = (current: string | string[] | undefined): boolean =>
|
||||
Array.isArray(current) ? current.includes('other') : current === 'other'
|
||||
|
||||
const conditionMatches = (
|
||||
condition: OnboardingSurveyFieldCondition | undefined,
|
||||
values: SurveyValues
|
||||
@@ -54,7 +61,7 @@ export const prepareSurvey = (survey: OnboardingSurvey): OnboardingSurvey => ({
|
||||
fields: survey.fields.map(randomizeOptions)
|
||||
})
|
||||
|
||||
type Translator = (key: string) => string
|
||||
type Translator = (key: string, named?: Record<string, unknown>) => string
|
||||
|
||||
const identityTranslator: Translator = (key) => key
|
||||
|
||||
@@ -87,11 +94,19 @@ export const buildZodSchema = (
|
||||
if (
|
||||
field.allowOther &&
|
||||
field.otherFieldId &&
|
||||
values[field.id] === 'other'
|
||||
isOtherValue(values[field.id])
|
||||
) {
|
||||
shape[field.otherFieldId] = z.string().min(1, {
|
||||
message: t('cloudOnboarding.survey.errors.describeAnswer')
|
||||
})
|
||||
shape[field.otherFieldId] = z
|
||||
.string()
|
||||
.trim()
|
||||
.min(1, {
|
||||
message: t('cloudOnboarding.survey.errors.describeAnswer')
|
||||
})
|
||||
.max(OTHER_TEXT_MAX_LENGTH, {
|
||||
message: t('cloudOnboarding.survey.errors.answerTooLong', {
|
||||
max: OTHER_TEXT_MAX_LENGTH
|
||||
})
|
||||
})
|
||||
} else if (field.otherFieldId) {
|
||||
shape[field.otherFieldId] = z.string().optional()
|
||||
}
|
||||
@@ -120,17 +135,23 @@ export const buildSubmissionPayload = (
|
||||
continue
|
||||
}
|
||||
const value = values[field.id]
|
||||
const otherRaw = field.otherFieldId ? values[field.otherFieldId] : undefined
|
||||
if (
|
||||
const otherFieldId = field.otherFieldId
|
||||
const otherRaw = otherFieldId ? values[otherFieldId] : undefined
|
||||
const otherText =
|
||||
field.allowOther &&
|
||||
field.otherFieldId &&
|
||||
value === 'other' &&
|
||||
otherFieldId &&
|
||||
isOtherValue(value) &&
|
||||
typeof otherRaw === 'string'
|
||||
) {
|
||||
const other = otherRaw.trim()
|
||||
payload[field.id] = other || 'other'
|
||||
? otherRaw.trim()
|
||||
: undefined
|
||||
|
||||
if (otherText !== undefined && field.type !== 'multi') {
|
||||
payload[field.id] = otherText || 'other'
|
||||
} else {
|
||||
payload[field.id] = field.type === 'multi' ? (value ?? []) : (value ?? '')
|
||||
if (otherText !== undefined && otherFieldId) {
|
||||
payload[otherFieldId] = otherText
|
||||
}
|
||||
}
|
||||
}
|
||||
return payload
|
||||
|
||||
@@ -53,6 +53,7 @@ vi.mock('@/composables/billing/useBillingContext', () => ({
|
||||
useBillingContext: () => ({
|
||||
balance: computed(() => state.balance),
|
||||
subscription: computed(() => state.subscription),
|
||||
isPaused: computed(() => false),
|
||||
isActiveSubscription: computed(() => state.isActiveSubscription),
|
||||
isFreeTier: computed(() => state.isFreeTier),
|
||||
currentTeamCreditStop: computed(() => state.currentTeamCreditStop),
|
||||
@@ -97,24 +98,14 @@ const i18n = createI18n({
|
||||
remaining: 'remaining',
|
||||
refreshCredits: 'Refresh credits',
|
||||
monthly: 'Monthly',
|
||||
refillsDate: 'Refills {date}',
|
||||
refillsNextCycle: 'Refills next cycle',
|
||||
creditsUsed: '{used} used',
|
||||
creditsLeftOfTotal: '{remaining} left of {total}',
|
||||
monthlyUsageProgress: '{used} of {total} monthly credits used',
|
||||
yearly: 'Yearly',
|
||||
percentUsed: '{percent}% used',
|
||||
usageProgress: '{used} of {total} credits used',
|
||||
additionalCreditsInfo: 'About additional credits',
|
||||
additionalCreditsTooltip: 'Credits you add on top of your plan.',
|
||||
additionalCredits: 'Additional credits',
|
||||
additionalCreditsInUse: 'In use',
|
||||
usedAfterMonthly: 'Used after monthly runs out',
|
||||
monthlyCreditsUsedUpTitle:
|
||||
'Monthly credits are used up. Refills {date}',
|
||||
monthlyCreditsUsedUpTitleNoDate: 'Monthly credits are used up',
|
||||
monthlyCreditsUsedUpDescription:
|
||||
"You're now spending additional credits.",
|
||||
outOfCreditsTitle: "You're out of credits. Credits refill {date}",
|
||||
outOfCreditsTitleNoDate: "You're out of credits",
|
||||
outOfCreditsDescription: 'Add more credits to continue generating.',
|
||||
usedAfterMonthly: 'Used after plan credits run out',
|
||||
addCredits: 'Add credits',
|
||||
upgradeToAddCredits: 'Upgrade to add credits'
|
||||
}
|
||||
@@ -178,27 +169,19 @@ describe('CreditsTile', () => {
|
||||
it('renders the monthly usage bar and additional breakdown', () => {
|
||||
activeProSubscription()
|
||||
const { container } = renderTile()
|
||||
// PRO monthly allowance = 21,100; remaining 422 -> used 20,678.
|
||||
// PRO monthly allowance = 21,100; remaining 422 -> used 20,678 -> 98%.
|
||||
expect(container.textContent).toContain('Monthly')
|
||||
expect(container.textContent).toMatch(/Refills Feb/)
|
||||
expect(container.textContent).toContain('20,678 used')
|
||||
expect(container.textContent).toContain('422 left of 21,100')
|
||||
expect(container.textContent).toContain('98% used')
|
||||
expect(container.textContent).toContain('Additional credits')
|
||||
expect(container.textContent).toContain('633')
|
||||
expect(container.textContent).toContain('Used after monthly runs out')
|
||||
expect(container.textContent).toContain('Used after plan credits run out')
|
||||
})
|
||||
|
||||
it('renders a compact monthly summary for narrow containers', () => {
|
||||
activeProSubscription()
|
||||
const { container } = renderTile()
|
||||
expect(container.textContent).toContain('422 left of 21K')
|
||||
})
|
||||
|
||||
it('uses the team credit stop monthly grant for the monthly total', () => {
|
||||
it('uses the team credit stop grant for a monthly allowance', () => {
|
||||
state.isActiveSubscription = true
|
||||
state.subscription = {
|
||||
tier: 'TEAM',
|
||||
duration: 'ANNUAL',
|
||||
duration: 'MONTHLY',
|
||||
renewalDate: '2026-02-20T12:00:00Z'
|
||||
}
|
||||
state.currentTeamCreditStop = {
|
||||
@@ -207,13 +190,15 @@ describe('CreditsTile', () => {
|
||||
stop_usd: 2500
|
||||
}
|
||||
state.balance = { amountMicros: 0, cloudCreditBalanceMicros: 200 }
|
||||
const { container } = renderTile()
|
||||
// Monthly total is the stop's raw monthly grant, not the tier fallback,
|
||||
// and is not multiplied by 12 for annual billing.
|
||||
expect(container.textContent).toContain('422 left of 527,500')
|
||||
renderTile()
|
||||
// Allowance is the stop's grant, not the tier fallback.
|
||||
expect(screen.getByRole('progressbar')).toHaveAttribute(
|
||||
'aria-valuemax',
|
||||
'527500'
|
||||
)
|
||||
})
|
||||
|
||||
it('uses the per-month nominal grant for an annual personal tier', () => {
|
||||
it('grants the full year upfront for an annual plan', () => {
|
||||
state.isActiveSubscription = true
|
||||
state.subscription = {
|
||||
tier: 'PRO',
|
||||
@@ -221,35 +206,25 @@ describe('CreditsTile', () => {
|
||||
renewalDate: '2026-02-20T12:00:00Z'
|
||||
}
|
||||
state.balance = { amountMicros: 0, cloudCreditBalanceMicros: 200 }
|
||||
const { container } = renderTile()
|
||||
// Annual billing still grants the monthly nominal (21,100), not 12x.
|
||||
expect(container.textContent).toContain('422 left of 21,100')
|
||||
expect(container.textContent).not.toContain('253,200')
|
||||
renderTile()
|
||||
// Annual plans grant the whole year at once: 21,100 x 12.
|
||||
expect(screen.getByRole('progressbar')).toHaveAttribute(
|
||||
'aria-valuemax',
|
||||
'253200'
|
||||
)
|
||||
})
|
||||
|
||||
it('falls back to a dateless refills label when renewal date is missing', () => {
|
||||
activeProSubscription()
|
||||
state.subscription = { tier: 'PRO', duration: 'MONTHLY', renewalDate: null }
|
||||
const { container } = renderTile()
|
||||
expect(container.textContent).toContain('Refills next cycle')
|
||||
expect(container.textContent).not.toContain('Refills Feb')
|
||||
})
|
||||
|
||||
it('uses a dateless out-of-credits notice when renewal date is invalid', () => {
|
||||
activeProSubscription()
|
||||
it('labels the allowance by billing duration (yearly for annual)', () => {
|
||||
state.isActiveSubscription = true
|
||||
state.subscription = {
|
||||
tier: 'PRO',
|
||||
duration: 'MONTHLY',
|
||||
renewalDate: 'not-a-date'
|
||||
duration: 'ANNUAL',
|
||||
renewalDate: '2026-02-20T12:00:00Z'
|
||||
}
|
||||
state.balance = {
|
||||
amountMicros: 0,
|
||||
cloudCreditBalanceMicros: 0,
|
||||
prepaidBalanceMicros: 0
|
||||
}
|
||||
const { container } = renderTile()
|
||||
expect(container.textContent).toContain("You're out of credits")
|
||||
expect(container.textContent).not.toContain('Credits refill')
|
||||
state.balance = { amountMicros: 0, cloudCreditBalanceMicros: 200 }
|
||||
renderTile()
|
||||
expect(screen.getByText('Yearly')).toBeInTheDocument()
|
||||
expect(screen.queryByText('Monthly')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('hides the breakdown and forces zeros in the zero state', () => {
|
||||
@@ -271,11 +246,9 @@ describe('CreditsTile', () => {
|
||||
expect(screen.queryByText('Add credits')).toBeNull()
|
||||
})
|
||||
|
||||
it('shows no depletion notice or in-use badge while monthly credits remain', () => {
|
||||
it('shows no in-use badge while monthly credits remain', () => {
|
||||
activeProSubscription()
|
||||
const { container } = renderTile()
|
||||
expect(container.textContent).not.toContain('Monthly credits are used up')
|
||||
expect(container.textContent).not.toContain("You're out of credits")
|
||||
renderTile()
|
||||
expect(screen.queryByText('In use')).toBeNull()
|
||||
})
|
||||
|
||||
@@ -286,42 +259,29 @@ describe('CreditsTile', () => {
|
||||
cloudCreditBalanceMicros: 0,
|
||||
prepaidBalanceMicros: 300
|
||||
}
|
||||
const { container } = renderTile()
|
||||
expect(container.textContent).toContain(
|
||||
'Monthly credits are used up. Refills Feb 20'
|
||||
)
|
||||
expect(container.textContent).toContain(
|
||||
"You're now spending additional credits."
|
||||
)
|
||||
renderTile()
|
||||
expect(screen.getByText('In use')).toBeTruthy()
|
||||
expect(screen.getByText('Add credits').dataset.variant).toBe('secondary')
|
||||
expect(screen.getByText('Add credits').dataset.variant).toBe('tertiary')
|
||||
})
|
||||
|
||||
it('emphasizes add-credits when fully out of credits', () => {
|
||||
it('emphasizes add-credits when fully out of credits, without a punch-out notice', () => {
|
||||
activeProSubscription()
|
||||
state.balance = {
|
||||
amountMicros: 0,
|
||||
cloudCreditBalanceMicros: 0,
|
||||
prepaidBalanceMicros: 0
|
||||
}
|
||||
const { container } = renderTile()
|
||||
expect(container.textContent).toContain(
|
||||
"You're out of credits. Credits refill Feb 20"
|
||||
)
|
||||
expect(container.textContent).toContain(
|
||||
'Add more credits to continue generating.'
|
||||
)
|
||||
renderTile()
|
||||
expect(screen.queryByText('In use')).toBeNull()
|
||||
expect(screen.getByText('Add credits').dataset.variant).toBe('inverted')
|
||||
})
|
||||
|
||||
it('suppresses the depletion notice until the balance has loaded', () => {
|
||||
it('shows no in-use badge until the balance has loaded', () => {
|
||||
activeProSubscription()
|
||||
state.balance = null
|
||||
state.isLoading = true
|
||||
const { container } = renderTile()
|
||||
expect(container.textContent).not.toContain('Monthly credits are used up')
|
||||
expect(container.textContent).not.toContain("You're out of credits")
|
||||
renderTile()
|
||||
expect(screen.queryByText('In use')).toBeNull()
|
||||
})
|
||||
|
||||
it('routes add-credits through telemetry + the top-up dialog', async () => {
|
||||
|
||||
@@ -1,6 +1,15 @@
|
||||
<template>
|
||||
<div
|
||||
class="@container relative flex flex-col gap-6 rounded-2xl border border-interface-stroke bg-modal-panel-background px-6 py-5"
|
||||
:class="
|
||||
cn(
|
||||
'@container relative flex flex-col gap-6 rounded-2xl border border-interface-stroke bg-modal-panel-background px-6 py-5 transition-opacity',
|
||||
// Paused subscriptions can't spend credits, so dim the whole tile to
|
||||
// read as frozen and defer to the Update-payment banner. A lapsed plan
|
||||
// (frozen) reads the same way.
|
||||
(isPaused || frozen) && 'opacity-50',
|
||||
customClass
|
||||
)
|
||||
"
|
||||
>
|
||||
<Button
|
||||
variant="muted-textonly"
|
||||
@@ -19,8 +28,10 @@
|
||||
</div>
|
||||
<Skeleton v-if="isLoadingBalance" width="8rem" height="2rem" />
|
||||
<div v-else class="flex items-baseline gap-2">
|
||||
<i class="icon-[lucide--component] size-4 self-center text-credit" />
|
||||
<span class="text-2xl leading-none font-bold">{{ displayTotal }}</span>
|
||||
<i class="icon-[lucide--coins] size-4 self-center text-credit" />
|
||||
<span class="text-2xl leading-none font-bold tabular-nums">{{
|
||||
displayTotal
|
||||
}}</span>
|
||||
<span class="text-sm text-muted @max-[300px]:hidden">{{
|
||||
$t('subscription.remaining')
|
||||
}}</span>
|
||||
@@ -28,37 +39,22 @@
|
||||
</div>
|
||||
|
||||
<template v-if="showBreakdown">
|
||||
<div
|
||||
v-if="emptyStateNotice"
|
||||
class="flex items-start gap-2 rounded-lg bg-base-background p-3 text-sm"
|
||||
>
|
||||
<i
|
||||
class="mt-0.5 icon-[lucide--info] size-4 shrink-0 text-base-foreground"
|
||||
/>
|
||||
<div class="flex flex-col gap-1">
|
||||
<span class="text-base-foreground">{{ emptyStateNotice.title }}</span>
|
||||
<span class="text-muted">{{ emptyStateNotice.description }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="showBar"
|
||||
:class="cn('flex flex-col gap-2', isMonthlyDepleted && 'opacity-30')"
|
||||
:class="cn('flex flex-col gap-2', isAllowanceDepleted && 'opacity-30')"
|
||||
>
|
||||
<div class="flex items-center justify-between text-sm">
|
||||
<span class="text-text-primary">{{
|
||||
$t('subscription.monthly')
|
||||
}}</span>
|
||||
<span class="text-muted">{{ cycleLabel }}</span>
|
||||
<span class="text-muted">
|
||||
{{ refillsLabel }}
|
||||
{{ cycleStatusLabel }}
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
role="progressbar"
|
||||
:aria-valuenow="usage.used"
|
||||
:aria-valuemin="0"
|
||||
:aria-valuemax="monthlyTotalCredits ?? 0"
|
||||
:aria-valuetext="monthlyUsageLabel"
|
||||
:aria-valuemax="allowanceTotalCredits ?? 0"
|
||||
:aria-valuetext="cycleUsageLabel"
|
||||
class="h-2 w-full overflow-hidden rounded-full bg-secondary-background-hover"
|
||||
>
|
||||
<div
|
||||
@@ -66,40 +62,6 @@
|
||||
:style="{ width: usedBarWidth }"
|
||||
/>
|
||||
</div>
|
||||
<div class="flex items-center justify-between gap-2 text-sm">
|
||||
<Skeleton
|
||||
v-if="isLoadingBalance"
|
||||
class="@max-[300px]:hidden"
|
||||
width="5rem"
|
||||
height="1rem"
|
||||
/>
|
||||
<span v-else class="text-muted @max-[300px]:hidden">
|
||||
{{ $t('subscription.creditsUsed', { used: usedDisplay }) }}
|
||||
</span>
|
||||
<Skeleton v-if="isLoadingBalance" width="9rem" height="1rem" />
|
||||
<span
|
||||
v-else
|
||||
class="flex items-center gap-1 font-bold text-text-primary"
|
||||
>
|
||||
<i class="icon-[lucide--component] size-4 text-credit" />
|
||||
<span class="@max-[180px]:hidden">
|
||||
{{
|
||||
$t('subscription.creditsLeftOfTotal', {
|
||||
remaining: monthlyBonusCredits,
|
||||
total: monthlyTotalDisplay
|
||||
})
|
||||
}}
|
||||
</span>
|
||||
<span class="hidden @max-[180px]:inline">
|
||||
{{
|
||||
$t('subscription.creditsLeftOfTotal', {
|
||||
remaining: monthlyRemainingCompact,
|
||||
total: monthlyTotalCompact
|
||||
})
|
||||
}}
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="h-px w-full bg-interface-stroke" />
|
||||
@@ -118,7 +80,7 @@
|
||||
variant="muted-textonly"
|
||||
size="icon-sm"
|
||||
:aria-label="$t('subscription.additionalCreditsInfo')"
|
||||
class="text-muted"
|
||||
class="flex cursor-help appearance-none items-center border-none bg-transparent p-0 text-muted transition-colors hover:text-text-primary"
|
||||
>
|
||||
<i class="icon-[lucide--info] size-4" />
|
||||
</Button>
|
||||
@@ -132,9 +94,9 @@
|
||||
<Skeleton v-if="isLoadingBalance" width="3rem" height="1rem" />
|
||||
<span
|
||||
v-else
|
||||
class="flex items-center gap-1 font-bold text-text-primary"
|
||||
class="flex items-center gap-1 font-bold text-text-primary tabular-nums"
|
||||
>
|
||||
<i class="icon-[lucide--component] size-4 text-credit" />
|
||||
<i class="icon-[lucide--coins] size-4 text-credit" />
|
||||
{{ displayPrepaid }}
|
||||
</span>
|
||||
</div>
|
||||
@@ -156,15 +118,10 @@
|
||||
</Button>
|
||||
<Button
|
||||
v-else
|
||||
:variant="isOutOfCredits ? 'inverted' : 'secondary'"
|
||||
:variant="isOutOfCredits ? 'inverted' : 'tertiary'"
|
||||
size="lg"
|
||||
:class="
|
||||
cn(
|
||||
'w-full font-normal',
|
||||
!isOutOfCredits &&
|
||||
'bg-interface-menu-component-surface-selected text-text-primary'
|
||||
)
|
||||
"
|
||||
class="w-full font-normal"
|
||||
:disabled="isPaused || frozen"
|
||||
@click="handleAddCredits"
|
||||
>
|
||||
{{ $t('subscription.addCredits') }}
|
||||
@@ -178,6 +135,7 @@ import { cn } from '@comfyorg/tailwind-utils'
|
||||
import { useEventListener } from '@vueuse/core'
|
||||
import Skeleton from 'primevue/skeleton'
|
||||
import { computed, onMounted } from 'vue'
|
||||
import type { HTMLAttributes } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
import { formatCredits } from '@/base/credits/comfyCredits'
|
||||
@@ -186,40 +144,45 @@ import { useBillingContext } from '@/composables/billing/useBillingContext'
|
||||
import { useErrorHandling } from '@/composables/useErrorHandling'
|
||||
import { useSubscriptionCredits } from '@/platform/cloud/subscription/composables/useSubscriptionCredits'
|
||||
import { useSubscriptionDialog } from '@/platform/cloud/subscription/composables/useSubscriptionDialog'
|
||||
import {
|
||||
DEFAULT_TIER_KEY,
|
||||
TIER_TO_KEY,
|
||||
getTierCredits
|
||||
} from '@/platform/cloud/subscription/constants/tierPricing'
|
||||
import { computeMonthlyUsage } from '@/platform/cloud/subscription/utils/creditsProgress'
|
||||
import { useTelemetry } from '@/platform/telemetry'
|
||||
import { consumePendingTopup } from '@/platform/telemetry/topupTracker'
|
||||
import { useWorkspaceUI } from '@/platform/workspace/composables/useWorkspaceUI'
|
||||
import { useDialogService } from '@/services/dialogService'
|
||||
|
||||
const { zeroState = false } = defineProps<{
|
||||
const {
|
||||
zeroState = false,
|
||||
frozen = false,
|
||||
class: customClass
|
||||
} = defineProps<{
|
||||
/** Forces the zero-credit display (e.g. unsubscribed / member view). */
|
||||
zeroState?: boolean
|
||||
/**
|
||||
* Renders the full breakdown but dimmed and non-interactive, for a lapsed
|
||||
* subscription that still has a shape to show. Mirrors the paused treatment.
|
||||
*/
|
||||
frozen?: boolean
|
||||
class?: HTMLAttributes['class']
|
||||
}>()
|
||||
|
||||
const { locale, t } = useI18n()
|
||||
|
||||
const {
|
||||
subscription,
|
||||
isPaused,
|
||||
balance,
|
||||
isActiveSubscription,
|
||||
isFreeTier,
|
||||
currentTeamCreditStop,
|
||||
fetchBalance,
|
||||
fetchStatus
|
||||
} = useBillingContext()
|
||||
const {
|
||||
monthlyBonusCredits,
|
||||
prepaidCredits,
|
||||
totalCredits,
|
||||
monthlyBonusCreditsValue,
|
||||
prepaidCreditsValue,
|
||||
isLoadingBalance
|
||||
isLoadingBalance,
|
||||
allowanceTotalCredits,
|
||||
usage
|
||||
} = useSubscriptionCredits()
|
||||
const { permissions } = useWorkspaceUI()
|
||||
const { showPricingTable } = useSubscriptionDialog()
|
||||
@@ -227,40 +190,18 @@ const { wrapWithErrorHandlingAsync } = useErrorHandling()
|
||||
const dialogService = useDialogService()
|
||||
const telemetry = useTelemetry()
|
||||
|
||||
const tierKey = computed(() => {
|
||||
const tier = subscription.value?.tier
|
||||
if (!tier) return DEFAULT_TIER_KEY
|
||||
return TIER_TO_KEY[tier] ?? DEFAULT_TIER_KEY
|
||||
})
|
||||
|
||||
const monthlyTotalCredits = computed<number | null>(() => {
|
||||
const teamStop = currentTeamCreditStop.value
|
||||
if (teamStop) return teamStop.credits_monthly
|
||||
return getTierCredits(tierKey.value)
|
||||
})
|
||||
|
||||
const usage = computed(() =>
|
||||
computeMonthlyUsage(
|
||||
monthlyBonusCreditsValue.value,
|
||||
monthlyTotalCredits.value ?? 0
|
||||
)
|
||||
const cycleLabel = computed(() =>
|
||||
subscription.value?.duration === 'ANNUAL'
|
||||
? t('subscription.yearly')
|
||||
: t('subscription.monthly')
|
||||
)
|
||||
|
||||
const refillsDateShort = computed(() => {
|
||||
const raw = subscription.value?.renewalDate
|
||||
if (!raw) return ''
|
||||
const date = new Date(raw)
|
||||
return Number.isNaN(date.getTime())
|
||||
? ''
|
||||
: date.toLocaleDateString(locale.value, { month: 'short', day: 'numeric' })
|
||||
})
|
||||
const cycleUsedPercent = computed(() =>
|
||||
Math.round(usage.value.usedFraction * 100)
|
||||
)
|
||||
|
||||
const hasRefillsDate = computed(() => refillsDateShort.value !== '')
|
||||
|
||||
const refillsLabel = computed(() =>
|
||||
hasRefillsDate.value
|
||||
? t('subscription.refillsDate', { date: refillsDateShort.value })
|
||||
: t('subscription.refillsNextCycle')
|
||||
const cycleStatusLabel = computed(() =>
|
||||
t('subscription.percentUsed', { percent: cycleUsedPercent.value })
|
||||
)
|
||||
|
||||
const formatCreditCount = (value: number) =>
|
||||
@@ -270,82 +211,58 @@ const formatCreditCount = (value: number) =>
|
||||
numberOptions: { maximumFractionDigits: 0 }
|
||||
})
|
||||
|
||||
const monthlyTotalDisplay = computed(() => {
|
||||
const total = monthlyTotalCredits.value
|
||||
const allowanceTotalDisplay = computed(() => {
|
||||
const total = allowanceTotalCredits.value
|
||||
return total === null ? '—' : formatCreditCount(total)
|
||||
})
|
||||
|
||||
const usedDisplay = computed(() => formatCreditCount(usage.value.used))
|
||||
|
||||
const compactNumber = computed(
|
||||
() => new Intl.NumberFormat(locale.value, { notation: 'compact' })
|
||||
)
|
||||
const monthlyRemainingCompact = computed(() =>
|
||||
compactNumber.value.format(monthlyBonusCreditsValue.value)
|
||||
)
|
||||
const monthlyTotalCompact = computed(() => {
|
||||
const total = monthlyTotalCredits.value
|
||||
return total === null ? '—' : compactNumber.value.format(total)
|
||||
})
|
||||
|
||||
const displayTotal = computed(() => (zeroState ? '0' : totalCredits.value))
|
||||
const displayPrepaid = computed(() => (zeroState ? '0' : prepaidCredits.value))
|
||||
const usedBarWidth = computed(
|
||||
() => `${(usage.value.usedFraction * 100).toFixed(2)}%`
|
||||
)
|
||||
const monthlyUsageLabel = computed(() =>
|
||||
t('subscription.monthlyUsageProgress', {
|
||||
const cycleUsageLabel = computed(() =>
|
||||
t('subscription.usageProgress', {
|
||||
used: usedDisplay.value,
|
||||
total: monthlyTotalDisplay.value
|
||||
total: allowanceTotalDisplay.value
|
||||
})
|
||||
)
|
||||
|
||||
const showBreakdown = computed(() => isActiveSubscription.value && !zeroState)
|
||||
const showBreakdown = computed(
|
||||
() => (isActiveSubscription.value || frozen) && !zeroState
|
||||
)
|
||||
const showBar = computed(
|
||||
() =>
|
||||
showBreakdown.value &&
|
||||
monthlyTotalCredits.value !== null &&
|
||||
monthlyTotalCredits.value > 0
|
||||
allowanceTotalCredits.value !== null &&
|
||||
allowanceTotalCredits.value > 0
|
||||
)
|
||||
const showActionButton = computed(
|
||||
() => isActiveSubscription.value && !zeroState && permissions.value.canTopUp
|
||||
() =>
|
||||
(isActiveSubscription.value || frozen) &&
|
||||
!zeroState &&
|
||||
permissions.value.canTopUp
|
||||
)
|
||||
|
||||
const isMonthlyDepleted = computed(
|
||||
const isAllowanceDepleted = computed(
|
||||
() =>
|
||||
!isPaused.value &&
|
||||
!frozen &&
|
||||
showBar.value &&
|
||||
!isLoadingBalance.value &&
|
||||
balance.value != null &&
|
||||
monthlyBonusCreditsValue.value <= 0
|
||||
)
|
||||
const isOutOfCredits = computed(
|
||||
() => isMonthlyDepleted.value && prepaidCreditsValue.value <= 0
|
||||
)
|
||||
const isSpendingAdditional = computed(
|
||||
() => isMonthlyDepleted.value && prepaidCreditsValue.value > 0
|
||||
() => isAllowanceDepleted.value && prepaidCreditsValue.value > 0
|
||||
)
|
||||
// Fully out (monthly depleted and no additional credits left): emphasize the
|
||||
// add-credits button. Spending-additional keeps the quieter tertiary.
|
||||
const isOutOfCredits = computed(
|
||||
() => isAllowanceDepleted.value && prepaidCreditsValue.value <= 0
|
||||
)
|
||||
|
||||
const emptyStateNotice = computed(() => {
|
||||
if (isOutOfCredits.value) {
|
||||
return {
|
||||
title: hasRefillsDate.value
|
||||
? t('subscription.outOfCreditsTitle', { date: refillsDateShort.value })
|
||||
: t('subscription.outOfCreditsTitleNoDate'),
|
||||
description: t('subscription.outOfCreditsDescription')
|
||||
}
|
||||
}
|
||||
if (isMonthlyDepleted.value) {
|
||||
return {
|
||||
title: hasRefillsDate.value
|
||||
? t('subscription.monthlyCreditsUsedUpTitle', {
|
||||
date: refillsDateShort.value
|
||||
})
|
||||
: t('subscription.monthlyCreditsUsedUpTitleNoDate'),
|
||||
description: t('subscription.monthlyCreditsUsedUpDescription')
|
||||
}
|
||||
}
|
||||
return null
|
||||
})
|
||||
|
||||
const handleRefresh = wrapWithErrorHandlingAsync(async () => {
|
||||
await Promise.all([fetchBalance(), fetchStatus()])
|
||||
|
||||
@@ -6,6 +6,12 @@ import {
|
||||
formatCreditsFromCents
|
||||
} from '@/base/credits/comfyCredits'
|
||||
import { useBillingContext } from '@/composables/billing/useBillingContext'
|
||||
import {
|
||||
DEFAULT_TIER_KEY,
|
||||
TIER_TO_KEY,
|
||||
getTierCredits
|
||||
} from '@/platform/cloud/subscription/constants/tierPricing'
|
||||
import { computeMonthlyUsage } from '@/platform/cloud/subscription/utils/creditsProgress'
|
||||
|
||||
/**
|
||||
* Composable for handling subscription credit calculations and formatting.
|
||||
@@ -64,12 +70,44 @@ export function useSubscriptionCredits() {
|
||||
creditsFromMicros(toValue(billingContext.balance)?.prepaidBalanceMicros)
|
||||
)
|
||||
|
||||
// Total credits granted for the current billing cycle. Team plans read the
|
||||
// credit stop; personal tiers read the tier grant. Annual plans front-load the
|
||||
// whole year, so multiply the monthly nominal by the cycle length.
|
||||
const cycleMonths = computed(() =>
|
||||
toValue(billingContext.subscription)?.duration === 'ANNUAL' ? 12 : 1
|
||||
)
|
||||
const allowanceTotalCredits = computed<number | null>(() => {
|
||||
const teamStop = toValue(billingContext.currentTeamCreditStop)
|
||||
const tier = toValue(billingContext.subscription)?.tier
|
||||
const tierKey = tier
|
||||
? (TIER_TO_KEY[tier] ?? DEFAULT_TIER_KEY)
|
||||
: DEFAULT_TIER_KEY
|
||||
const monthly = teamStop
|
||||
? teamStop.credits_monthly
|
||||
: getTierCredits(tierKey)
|
||||
return monthly === null ? null : monthly * cycleMonths.value
|
||||
})
|
||||
|
||||
// Usage of that allowance drives the credits bar. Paused plans read as unused
|
||||
// (credits are frozen), so force it to zero.
|
||||
const usage = computed(() => {
|
||||
const base = computeMonthlyUsage(
|
||||
monthlyBonusCreditsValue.value,
|
||||
allowanceTotalCredits.value ?? 0
|
||||
)
|
||||
return toValue(billingContext.isPaused)
|
||||
? { ...base, used: 0, usedFraction: 0 }
|
||||
: base
|
||||
})
|
||||
|
||||
return {
|
||||
totalCredits,
|
||||
monthlyBonusCredits,
|
||||
prepaidCredits,
|
||||
monthlyBonusCreditsValue,
|
||||
prepaidCreditsValue,
|
||||
isLoadingBalance
|
||||
isLoadingBalance,
|
||||
allowanceTotalCredits,
|
||||
usage
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ export type OnboardingSurveyOption = {
|
||||
value: string
|
||||
label?: LocalizedString
|
||||
labelKey?: string
|
||||
icon?: string
|
||||
}
|
||||
|
||||
export type OnboardingSurveyFieldCondition = {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user