Formerly KrillinAI, VideoTranslation and Dubbing Tool for 120+ Languages. Open-source AI workspace for creators, powered by Codex. Video downloader, video translation, create videos, images, audios, and edits with Agents in one place. For your Social Media like YouTube, TikTok, Instagram, etc.
TypeScript agent-skillscodex-clideskop-appdubbingimage-generationlocalizationskillsttsvideo-editingvideo-generationvideo-transcriptionvideo-translation
feat(web): refine template detail modal
卡皮巴拉ed353792200b
diff --git a/apps/web/src/features/conversation/CreatorDashboard.test.tsx b/apps/web/src/features/conversation/CreatorDashboard.test.tsxindex bb335a62..97cdbe5a 100644--- a/apps/web/src/features/conversation/CreatorDashboard.test.tsx+++ b/apps/web/src/features/conversation/CreatorDashboard.test.tsx@@ -167,19 +167,21 @@ describe('CreatorDashboard', () => {expect(onSelectPreset).not.toHaveBeenCalled();expect(screen.getByRole('heading', { name: 'B站双语精翻' })).toBeInTheDocument();- expect(screen.getByRole('heading', { name: '成果预览' })).toBeInTheDocument();+ expect(screen.queryByRole('heading', { name: '成果预览' })).not.toBeInTheDocument();const previewTrigger = screen.getByRole('button', { name: '全屏查看B站双语精翻完整作品' });expect(previewTrigger.querySelector('img')).toHaveAttribute('src', `/creator-presets/${'d'.repeat(64)}.webp`);expect(screen.getByText('英文视频翻译为简体中文。')).toBeInTheDocument();expect(screen.getByText('英语 → 简体中文')).toBeInTheDocument();- expect(screen.getByRole('heading', { name: '提示词' })).toBeInTheDocument();+ expect(screen.getByRole('heading', { name: 'PROMPT 正文' })).toBeInTheDocument();+ expect(screen.getByRole('button', { name: '复制 Prompt' })).toBeDisabled();expect(screen.getByText('此模板使用固定配置,无需预设提示词。')).toBeInTheDocument();const detailPage = document.querySelector<HTMLElement>('.creator-template-detail-page');const detailLayout = document.querySelector<HTMLElement>('.creator-template-detail-layout');const promptSection = document.querySelector<HTMLElement>('.creator-template-prompt-section');- expect(detailLayout).not.toContainElement(promptSection);- expect(detailPage?.lastElementChild).toBe(promptSection);+ expect(screen.getByRole('dialog', { name: 'B站双语精翻' })).toBe(detailPage);+ expect(detailLayout?.querySelector('.creator-template-detail-info')).toContainElement(promptSection);+ expect(screen.getByRole('button', { name: '查看B站双语精翻模板详情' })).toBeInTheDocument();expect(screen.getByRole('list', { name: '模板标签' })).toHaveTextContent('B站双语字幕翻译');expect(screen.getByRole('button', { name: '使用此模板' })).toBeInTheDocument();@@ -223,6 +225,16 @@ describe('CreatorDashboard', () => {await waitFor(() => expect(trigger).toHaveFocus());});+ it('copies the raw prompt from the detail card', async () => {+ const writeText = vi.fn().mockResolvedValue(undefined);+ Object.defineProperty(navigator, 'clipboard', { configurable: true, value: { writeText } });+ render(<CreatorDashboard presets={presets} />);+ fireEvent.click(screen.getByRole('button', { name: '查看电商商品主图增强版模板详情' }));+ fireEvent.click(screen.getByRole('button', { name: '复制 Prompt' }));+ expect(writeText).toHaveBeenCalledWith(presets[1]!.prompt);+ expect(await screen.findByRole('button', { name: '已复制' })).toBeInTheDocument();+ });+it('renders video examples with controls and a full preview', async () => {render(<CreatorDashboard presets={presets} />);fireEvent.click(screen.getByRole('tab', { name: '视频创作' }));diff --git a/apps/web/src/features/conversation/CreatorDashboard.tsx b/apps/web/src/features/conversation/CreatorDashboard.tsxindex e690dcc1..649a1ce9 100644--- a/apps/web/src/features/conversation/CreatorDashboard.tsx+++ b/apps/web/src/features/conversation/CreatorDashboard.tsx@@ -3,8 +3,8 @@ import type {CreatorRuntimeWorkspace} from '@opencreator/protocol';import {- ArrowLeft,ChevronDown,+ Copy,ExternalLink,Maximize2,Play,@@ -150,6 +150,7 @@ export function CreatorDashboard(props: {const [searchOpen, setSearchOpen] = useState(false);const [selectedPresetIdentity, setSelectedPresetIdentity] = useState<string>();const [previewOpen, setPreviewOpen] = useState(false);+ const [promptCopied, setPromptCopied] = useState(false);const [promptHasOverflow, setPromptHasOverflow] = useState(false);const [promptAtEnd, setPromptAtEnd] = useState(true);const [recentPresetIds, setRecentPresetIds] = useState<string[]>(readRecentPresetIds);@@ -214,6 +215,7 @@ export function CreatorDashboard(props: {const selectedPreset = selectedPresetIdentity === undefined? undefined: presets.find(preset => presetIdentity(preset) === selectedPresetIdentity);+ useEffect(() => { setPromptCopied(false); }, [selectedPresetIdentity]);useLayoutEffect(() => {const filter = tagsFilterRef.current;const measure = tagsMeasureRef.current;@@ -288,12 +290,20 @@ export function CreatorDashboard(props: {useLayoutEffect(() => {if (selectedPresetIdentity === undefined) return;- const scrollContainer = detailPageRef.current?.closest<HTMLElement>('.creator-home-wrap');- if (scrollContainer !== null && scrollContainer !== undefined) {- scrollContainer.scrollTop = 0;- }+ const info = detailPageRef.current?.querySelector<HTMLElement>('.creator-template-detail-info');+ if (info) info.scrollTop = 0;}, [selectedPresetIdentity]);+ useEffect(() => {+ if (selectedPreset === undefined) return;+ const onEscape = (event: KeyboardEvent) => {+ if (event.key !== 'Escape' || previewOpen) return;+ setSelectedPresetIdentity(undefined);+ };+ document.addEventListener('keydown', onEscape);+ return () => document.removeEventListener('keydown', onEscape);+ }, [selectedPreset, previewOpen]);+useLayoutEffect(() => {const prompt = promptRef.current;if (prompt === null) {@@ -341,37 +351,37 @@ export function CreatorDashboard(props: {}}- if (selectedPreset !== undefined) {+ const detail = selectedPreset === undefined ? null : (() => {const identity = presetIdentity(selectedPreset);const busy = busyIdentities.has(identity);const previewUrl = selectedPreset.previewUrl ?? selectedPreset.coverUrl;return (<>- <div ref={detailPageRef} className="creator-dashboard creator-template-detail-page">+ <div className="creator-template-detail-backdrop" onMouseDown={event => {+ if (event.target === event.currentTarget) setSelectedPresetIdentity(undefined);+ }}>+ <div ref={detailPageRef} className="creator-dashboard creator-template-detail-page" role="dialog" aria-modal="true" aria-label={selectedPreset.title}><header className="creator-template-detail-toolbar">- <button- type="button"- className="creator-template-back"- onClick={() => {- setPreviewOpen(false);- setSelectedPresetIdentity(undefined);- setActionError(undefined);- }}- >- <ArrowLeft size={16} aria-hidden="true" />- {language === 'en-US' ? 'Back to templates' : '返回模板列表'}- </button>- <span>{moduleLabel(selectedPreset.module, language === 'zh-CN' ? 'zh-CN' : 'en-US')}</span>+ <div className="creator-template-detail-heading">+ <h1>{selectedPreset.title}</h1>+ <p>{selectedPreset.description}</p>+ </div>+ <div className="creator-template-detail-actions">+ <button className="creator-template-use-button" type="button" disabled={busy} aria-busy={busy} onClick={() => void selectPreset(selectedPreset)}>+ <WandSparkles size={17} aria-hidden="true" />+ {busy ? (language === 'en-US' ? 'Creating...' : '正在创建...') : (language === 'en-US' ? 'Use this template' : '使用此模板')}+ </button>+ <button type="button" className="creator-template-back" aria-label={language === 'en-US' ? 'Back to templates' : '返回模板列表'} title={language === 'en-US' ? 'Back to templates' : '返回模板列表'} onClick={() => { setSelectedPresetIdentity(undefined); setActionError(undefined); }}>+ <X size={18} aria-hidden="true" />+ </button>+ </div></header><div className="creator-template-detail-layout"><sectionclassName="creator-template-outcome"- aria-labelledby="creator-template-outcome-title"+ aria-label={language === 'en-US' ? 'Example result' : '示例图片'}>- <h2 id="creator-template-outcome-title">- {language === 'en-US' ? 'Example result' : '成果预览'}- </h2>{selectedPreset.previewVideoUrl === undefined ? (<buttonref={previewTriggerRef}@@ -417,10 +427,26 @@ export function CreatorDashboard(props: {</section><aside className="creator-template-detail-info">- <div className="creator-template-detail-intro">- <h1>{selectedPreset.title}</h1>- <p>{selectedPreset.description}</p>- </div>+ <section className="creator-template-detail-section creator-template-prompt-section">+ <div className={`creator-template-prompt-card${promptHasOverflow ? ' is-scrollable' : ''}${promptAtEnd ? ' is-at-end' : ''}`}>+ <div className="creator-template-prompt-heading">+ <h2>{language === 'en-US' ? 'PROMPT' : 'PROMPT 正文'}</h2>+ <button type="button" disabled={selectedPreset.prompt === null} onClick={() => {+ if (selectedPreset.prompt === null) return;+ void navigator.clipboard.writeText(selectedPreset.prompt).then(() => setPromptCopied(true)).catch(() => setPromptCopied(false));+ }}>+ <Copy size={16} aria-hidden="true" />+ {promptCopied ? (language === 'en-US' ? 'Copied' : '已复制') : (language === 'en-US' ? 'Copy prompt' : '复制 Prompt')}+ </button>+ </div>+ <p ref={promptRef} onScroll={updatePromptOverflow} className={selectedPreset.prompt === null ? 'creator-template-detail-empty' : 'creator-template-prompt'}>+ {selectedPreset.prompt === null+ ? (language === 'en-US' ? 'This template uses fixed settings and does not require a preset prompt.' : '此模板使用固定配置,无需预设提示词。')+ : renderPromptVariables(selectedPreset.prompt, language === 'zh-CN' ? 'zh-CN' : 'en-US')}+ </p>+ <span className="creator-template-prompt-scroll-cue" aria-hidden="true"><ChevronDown size={17} /></span>+ </div>+ </section>{selectedPreset.author === undefined ? null : (<section@@ -500,44 +526,9 @@ export function CreatorDashboard(props: {<p className="creator-template-action-error" role="alert">{actionError}</p>) : null}- <button- className="creator-template-use-button"- type="button"- disabled={busy}- aria-busy={busy}- onClick={() => void selectPreset(selectedPreset)}- >- <WandSparkles size={17} aria-hidden="true" />- {busy- ? (language === 'en-US' ? 'Creating...' : '正在创建...')- : (language === 'en-US' ? 'Use this template' : '使用此模板')}- </button></aside></div>-- <section className="creator-template-detail-section creator-template-prompt-section">- <h2>{language === 'en-US' ? 'Prompt' : '提示词'}</h2>- <div className={`creator-template-prompt-card${promptHasOverflow- ? ' is-scrollable'- : ''}${promptAtEnd ? ' is-at-end' : ''}`}>- <p- ref={promptRef}- onScroll={updatePromptOverflow}- className={selectedPreset.prompt === null- ? 'creator-template-detail-empty'- : 'creator-template-prompt'}- >- {selectedPreset.prompt === null- ? (language === 'en-US'- ? 'This template uses fixed settings and does not require a preset prompt.'- : '此模板使用固定配置,无需预设提示词。')- : renderPromptVariables(selectedPreset.prompt, language === 'zh-CN' ? 'zh-CN' : 'en-US')}- </p>- <span className="creator-template-prompt-scroll-cue" aria-hidden="true">- <ChevronDown size={17} />- </span>- </div>- </section>+ </div></div>{!previewOpen ? null : createPortal(<div@@ -584,9 +575,10 @@ export function CreatorDashboard(props: {)}</>);- }+ })();return (+ <><div className="creator-dashboard"><divclassName="creator-template-tabs"@@ -762,7 +754,7 @@ export function CreatorDashboard(props: {</button></div>) : null}- {actionError ? (+ {actionError && selectedPreset === undefined ? (<p className="creator-template-action-error" role="alert">{actionError}</p>) : null}@@ -818,6 +810,8 @@ export function CreatorDashboard(props: {) : null}</section></div>+ {detail === null ? null : createPortal(detail, document.body)}+ </>);}diff --git a/apps/web/src/styles/app-css.test.ts b/apps/web/src/styles/app-css.test.tsindex da717eea..4106e90e 100644--- a/apps/web/src/styles/app-css.test.ts+++ b/apps/web/src/styles/app-css.test.ts@@ -38,6 +38,12 @@ function hexChannels(value: string): number[] {}describe('app CSS visual contracts', () => {+ it('keeps template preview media elevated above the global flat-surface reset', () => {+ const previewMedia = cssBlock('.creator-template-outcome-media img,\n.creator-template-outcome-media video');+ expect(previewMedia).toContain('box-shadow:');+ expect(previewMedia).toContain('!important;');+ });+it('keeps the video template marker centered, subdued and non-interactive', () => {const marker = cssBlock('.creator-template-play-marker');expect(marker).toContain('--creator-template-play-size: 40px;');diff --git a/apps/web/src/styles/app.css b/apps/web/src/styles/app.cssindex d8a6992b..5647982b 100644--- a/apps/web/src/styles/app.css+++ b/apps/web/src/styles/app.css@@ -3832,18 +3832,46 @@ html.is-pane-resizing * {}.creator-template-detail-page {- width: min(1120px, 100%);- gap: 16px;+ width: min(1500px, 94vw);+ height: min(920px, 94dvh);+ min-height: 0;+ display: flex;+ flex-direction: column;+ gap: 0;+ margin: 0;+ overflow: hidden;+ border: 1px solid var(--border);+ border-radius: 8px;+ background: var(--surface-popover);+ box-shadow: 0 24px 80px rgb(0 0 0 / 0.25);+}++.creator-template-detail-backdrop {+ position: fixed;+ inset: 0;+ z-index: 150;+ display: grid;+ place-items: center;+ padding: 12px;+ background: rgb(12 15 20 / 0.55);}.creator-template-detail-toolbar {- min-height: 36px;+ min-height: 78px;display: flex;align-items: center;justify-content: space-between;gap: 16px;+ padding: 14px 24px;+ border-bottom: 1px solid var(--border);}+.creator-template-detail-heading { min-width: 0; }+.creator-template-detail-heading h1 { margin: 0; font-size: 18px; line-height: 1.3; }+.creator-template-detail-heading p { margin: 4px 0 0; color: var(--muted); font-size: 13px; line-height: 1.4; }+.creator-template-detail-actions { display: flex; align-items: center; gap: 12px; flex: 0 0 auto; }+.creator-template-detail-actions .creator-template-use-button { margin: 0; }+.creator-template-detail-toolbar > span {color: var(--muted);font-size: 12px;@@ -3880,16 +3908,20 @@ html.is-pane-resizing * {.creator-template-detail-layout {min-width: 0;+ min-height: 0;+ flex: 1;display: grid;- grid-template-columns: minmax(0, 1.55fr) minmax(300px, 0.85fr);- gap: 28px;- align-items: start;+ grid-template-columns: minmax(0, 1.9fr) minmax(320px, 1fr);+ gap: 0;}.creator-template-outcome {min-width: 0;- display: grid;- gap: 10px;+ min-height: 0;+ display: flex;+ flex-direction: column;+ padding: 24px;+ background: color-mix(in srgb, var(--surface-popover) 75%, var(--surface-2));}.creator-template-outcome h2,@@ -3904,34 +3936,49 @@ html.is-pane-resizing * {.creator-template-outcome-media {position: relative;width: 100%;- aspect-ratio: 4 / 3;- display: grid;- place-items: center;- overflow: hidden;+ flex: 1;+ min-height: 0;+ display: flex;+ align-items: center;+ justify-content: center;+ overflow: visible;padding: 0;- border: 1px solid var(--border-hairline);- border-radius: 8px;- background: #18191c;+ border: 0;+ border-radius: 0;+ background: transparent;color: rgba(255, 255, 255, 0.9);cursor: zoom-in;}.creator-template-outcome-media img,.creator-template-outcome-media video {- position: absolute;- inset: 0;- width: 100%;- height: 100%;+ width: auto;+ height: auto;+ max-width: 100%;+ max-height: 100%;display: block;object-fit: contain;+ border-radius: 8px;+ box-shadow:+ 0 0 0 1px rgb(0 0 0 / 0.07),+ 0 4px 8px rgb(0 0 0 / 0.12),+ 0 14px 30px -4px rgb(0 0 0 / 0.2),+ 0 34px 68px -14px rgb(0 0 0 / 0.24) !important;+ transition: box-shadow 160ms ease, transform 160ms ease;}.creator-template-outcome-video {cursor: default;}-.creator-template-outcome-media:hover img {- opacity: 0.92;+.creator-template-outcome-media:hover img,+.creator-template-outcome-media:hover video {+ box-shadow:+ 0 0 0 1px rgb(0 0 0 / 0.08),+ 0 5px 10px rgb(0 0 0 / 0.13),+ 0 17px 34px -4px rgb(0 0 0 / 0.22),+ 0 40px 76px -14px rgb(0 0 0 / 0.27) !important;+ transform: translateY(-2px);}.creator-template-outcome-media:focus-visible {@@ -3953,8 +4000,14 @@ html.is-pane-resizing * {background: rgba(18, 19, 22, 0.82);box-shadow: 0 4px 16px rgba(0, 0, 0, 0.22);pointer-events: none;+ opacity: 0;+ transition: opacity 140ms ease;}+.creator-template-outcome-media:hover .creator-template-outcome-expand,+.creator-template-outcome-media:focus-visible .creator-template-outcome-expand,+.creator-template-outcome-media:focus-within .creator-template-outcome-expand { opacity: 1; }+button.creator-template-outcome-expand {padding: 0;color: rgba(255, 255, 255, 0.9);@@ -4019,10 +4072,13 @@ button.creator-template-outcome-expand:hover {.creator-template-detail-info {min-width: 0;+ min-height: 0;display: flex;flex-direction: column;gap: 18px;- padding-left: 24px;+ overflow-y: auto;+ overscroll-behavior: contain;+ padding: 24px;border-left: 1px solid var(--border-hairline);}@@ -4055,7 +4111,7 @@ button.creator-template-outcome-expand:hover {padding: 10px;border: 1px solid var(--border);border-radius: 8px;- background: var(--surface-2);+ background: transparent;box-shadow: 0 2px 8px rgb(0 0 0 / 0.08) !important;}@@ -4134,17 +4190,42 @@ button.creator-template-outcome-expand:hover {.creator-template-prompt-section {min-width: 0;- gap: 12px;- padding-top: 18px;+ gap: 0;+ padding-top: 0;+ border-top: 0;+}++.creator-template-prompt-heading {+ display: flex;+ align-items: center;+ justify-content: space-between;+ gap: 8px;+ padding: 14px 16px 0;}+.creator-template-prompt-heading h2 { font-size: 12px; letter-spacing: 0; }+.creator-template-prompt-heading button {+ display: inline-flex;+ align-items: center;+ gap: 6px;+ padding: 5px 0 5px 6px;+ border: 0;+ background: transparent;+ color: var(--muted);+ font-size: 12px;+ cursor: pointer;+}+.creator-template-prompt-heading button:hover:not(:disabled) { color: var(--text); }+.creator-template-prompt-heading button:disabled { opacity: 0.5; cursor: default; }+.creator-template-prompt-heading button:focus-visible { outline: 2px solid var(--state-focus-ring); }+.creator-template-prompt-card {position: relative;min-width: 0;overflow: hidden;border: 1px solid var(--border);border-radius: 8px;- background: var(--surface-2);+ background: transparent;box-shadow:0 2px 10px rgb(0 0 0 / 0.09),inset 0 1px 0 rgb(255 255 255 / 0.05) !important;@@ -4162,17 +4243,20 @@ button.creator-template-outcome-expand:hover {}.creator-template-prompt-section .creator-template-prompt {- max-height: 320px;+ height: 240px;overflow-y: auto;- padding: 14px 18px;+ padding: 12px 16px 16px;border-left: 0;+ font-family: ui-monospace, SFMono-Regular, Menlo, monospace;+ font-weight: 600;scrollbar-gutter: stable;scrollbar-color: var(--border-strong) transparent;scrollbar-width: thin;}.creator-template-prompt-section .creator-template-detail-empty {- padding: 14px 18px;+ height: 240px;+ padding: 12px 16px 16px;border-left: 0;}@@ -4218,7 +4302,7 @@ button.creator-template-outcome-expand:hover {bottom: 0;left: 0;height: 54px;- background: linear-gradient(to bottom, transparent, var(--surface-2));+ background: linear-gradient(to bottom, transparent, var(--surface-popover));pointer-events: none;}@@ -4322,16 +4406,26 @@ button.creator-template-outcome-expand:hover {padding: 44px 16px 40px;}+ .creator-template-detail-page { width: min(700px, 96vw); height: 94dvh; }.creator-template-detail-layout {grid-template-columns: minmax(0, 1fr);- gap: 22px;+ grid-template-rows: minmax(210px, 42%) minmax(0, 1fr);}.creator-template-detail-info {- padding: 22px 0 0;+ padding: 20px;border-top: 1px solid var(--border-hairline);border-left: 0;}+ .creator-template-outcome { padding: 16px; }+}++@media (max-width: 600px) {+ .creator-template-detail-toolbar { padding: 12px 16px; }+ .creator-template-detail-heading h1 { font-size: 15px; }+ .creator-template-detail-heading p { display: none; }+ .creator-template-detail-actions { gap: 4px; }+ .creator-template-detail-actions .creator-template-use-button { padding: 8px; font-size: 12px; }}@media (max-width: 700px) {