Skip to content

DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.

fix(ui): GoalBar 动作统一官方 tertiary,Chip 的 composerTrigger 对齐 PermissionSelect

hairyf0b953388eb94
diff --git a/packages/dsh-tauri-ui/src/client/components/checkbox.tsx b/packages/dsh-tauri-ui/src/client/components/checkbox.tsx
index 740b725e..f9664faa 100644
--- a/packages/dsh-tauri-ui/src/client/components/checkbox.tsx
+++ b/packages/dsh-tauri-ui/src/client/components/checkbox.tsx
@@ -1,9 +1,10 @@
import type { ReactElement } from 'react'
import type { CheckboxProps } from './checkbox.types'
-export const CHECKBOX_STYLE_ID = 'dsh-tauri-ui-checkbox-styles'
import { useMountStyle } from '../hooks/use-mount-style'
import checkboxStyle from './checkbox.cssr'
+export const CHECKBOX_STYLE_ID = 'dsh-tauri-ui-checkbox-styles'
+
export function Checkbox({ checked, disabled, onChange, children, 'aria-label': ariaLabel, title }: CheckboxProps): ReactElement {
useMountStyle(checkboxStyle, CHECKBOX_STYLE_ID)
return (
diff --git a/packages/dsh-tauri-ui/src/client/components/chip.cssr.test.tsx b/packages/dsh-tauri-ui/src/client/components/chip.cssr.test.tsx
new file mode 100644
index 00000000..5cf89b20
--- /dev/null
+++ b/packages/dsh-tauri-ui/src/client/components/chip.cssr.test.tsx
@@ -0,0 +1,91 @@
+import { createElement } from 'react'
+import { renderToStaticMarkup } from 'react-dom/server'
+import { describe, expect, it, vi } from 'vitest'
+import { Chip } from './chip'
+import chipStyle from './chip.cssr'
+
+vi.mock('dsh-tauri/client', () => ({ compact: (values: unknown[]) => values.filter(Boolean) }))
+
+const VARIANTS = ['seat', 'composerTrigger', 'selector'] as const
+const CHEVRON_SVG = '.dshp-chip .dshp-chip__chevron svg'
+const TRIGGER_ICON_SVG = '.dshp-chip.dshp-chip--composerTrigger .dshp-chip__icon svg'
+
+const css = chipStyle.render()
+
+function draw(variant: (typeof VARIANTS)[number]): string {
+ return renderToStaticMarkup(createElement(Chip, {
+ variant,
+ icon: createElement('svg', { 'data-icon': true }),
+ badge: createElement('span', { 'data-badge': true }),
+ chevron: createElement('svg', { 'data-chevron': true }),
+ open: true,
+ }, 'label'))
+}
+
+function ruleBody(selector: string): string {
+ const start = css.indexOf(`${selector} {`)
+ expect(start, `no emitted rule for ${selector}`).toBeGreaterThan(-1)
+ return css.slice(start, css.indexOf('}', start))
+}
+
+const markup = VARIANTS.map(draw).join('')
+const elementClasses = [...markup.matchAll(/class="([^"]*)"/g)].map(match => match[1].split(' '))
+const renderedClasses = new Set(elementClasses.flat())
+const emittedClasses = [...new Set(css.match(/\.dshp-[\w-]+/g) ?? [])].map(token => token.slice(1))
+
+describe('chip cssr contract', () => {
+ it('emits only classes the rendered chip carries', () => {
+ expect(emittedClasses.filter(token => !renderedClasses.has(token))).toEqual([])
+ })
+
+ it('matches every modifier selector against a rendered element', () => {
+ for (const variant of VARIANTS) {
+ const required = ['dshp-chip', `dshp-chip--${variant}`]
+ expect(css).toContain(`.${required.join('.')}`)
+ expect(elementClasses.some(tokens => required.every(token => tokens.includes(token))), variant).toBe(true)
+ }
+ })
+
+ it('wraps the composer trigger like PermissionSelect', () => {
+ const trigger = draw('composerTrigger')
+ expect(trigger).toContain('class="dshp-chip dshp-chip--composerTrigger"')
+ expect(trigger).toContain('<span class="dshp-chip__icon" aria-hidden="true">')
+ expect(trigger).toContain('<span class="dshp-chip__label">label</span>')
+ expect(trigger).toContain('<span class="dshp-chip__badge" aria-hidden="true">')
+ expect(trigger.indexOf('dshp-chip__label')).toBeLessThan(trigger.indexOf('dshp-chip__badge'))
+ expect(trigger.indexOf('dshp-chip__badge')).toBeLessThan(trigger.indexOf('dshp-chip__chevron'))
+ })
+
+ it('keeps PermissionRow.selector unwrapped', () => {
+ expect(draw('selector')).toContain('class="dshp-chip dshp-chip--selector"><svg data-icon')
+ expect(draw('selector')).not.toContain('dshp-chip__label')
+ })
+
+ it('collapses the label on the composer row container', () => {
+ expect(css).toContain('@container (max-width: 460px) {')
+ expect(css).toContain('.dshp-chip--composerTrigger:has(.dshp-chip__icon) .dshp-chip__label {')
+ expect(draw('composerTrigger')).toContain('class="dshp-chip__label"')
+ })
+
+ it('pins the chevron glyph once, for every variant', () => {
+ const chevron = ruleBody(CHEVRON_SVG)
+ expect(chevron).toContain('width: 11px')
+ expect(chevron).toContain('height: 11px')
+ for (const variant of VARIANTS) {
+ expect(css).not.toContain(`.dshp-chip--${variant} .dshp-chip__chevron svg`)
+ expect(draw(variant)).toContain('class="dshp-chip__chevron"')
+ }
+ })
+
+ it('pins the trigger icon to the official 14px and leaves the seat icon to its caller', () => {
+ const icon = ruleBody(TRIGGER_ICON_SVG)
+ expect(icon).toContain('width: 14px')
+ expect(icon).toContain('height: 14px')
+ expect(css).not.toContain('.dshp-chip--seat .dshp-chip__icon svg')
+ })
+
+ it('hides the decorative wrappers from assistive tech', () => {
+ for (const span of ['dshp-chip__icon', 'dshp-chip__badge', 'dshp-chip__chevron'])
+ expect(draw('composerTrigger')).toContain(`class="${span}" aria-hidden="true"`)
+ })
+})
diff --git a/packages/dsh-tauri-ui/src/client/components/chip.cssr.ts b/packages/dsh-tauri-ui/src/client/components/chip.cssr.ts
index 072beb53..07f384f5 100644
--- a/packages/dsh-tauri-ui/src/client/components/chip.cssr.ts
+++ b/packages/dsh-tauri-ui/src/client/components/chip.cssr.ts
@@ -4,90 +4,128 @@ import { cssr } from '../utils/cssr'
const { c, bem: { b, e, m } } = cssr
const { dimmed, focusRing, hover, modulePlatform, primary, secondary } = sharedStyles
-export default b('chip', {}, [
- m('seat', {
- display: 'inline-flex',
- alignItems: 'center',
- gap: '4px',
- minWidth: '0',
- maxWidth: 'min(100%, 240px)',
- minHeight: '28px',
- padding: '0 8px',
- border: 'none',
- borderRadius: '16px',
- background: 'transparent',
- color: primary,
- fontSize: '13px',
- lineHeight: '20px',
- fontWeight: '500',
- whiteSpace: 'nowrap',
- cursor: 'pointer',
- }, [
- c('&:not(:disabled):hover, &[aria-expanded=\'true\']', { background: hover }),
- c('&:disabled', {
- cursor: 'default',
- color: 'var(--dsw-alias-label-quaternary)',
- }),
- e('chevron', {
+const labelEllipsis = {
+ minWidth: '0',
+ overflow: 'hidden',
+ textOverflow: 'ellipsis',
+ whiteSpace: 'nowrap',
+} as const
+
+// css-render 只把 @media/@supports 当块级选择器(isMediaOrSupports),官方那条 @container 只能顶层 raw 发出。
+const COMPOSER_TRIGGER_COLLAPSE = [
+ '@container (max-width: 460px) {',
+ ' .dshp-chip--composerTrigger:has(.dshp-chip__icon) .dshp-chip__label {',
+ ' display: none;',
+ ' }',
+ '}',
+].join('\n')
+
+export default c([
+ b('chip', {}, [
+ // 官方三种 chip 的 chevron 同为一枚细描边 14px artwork;gravity 实心箭头在 14px 下宽 +20.8%、高 +35.6%、
+ // 笔画重 +49.9%,实测光学等效点为 11px。属字形属性,故置于块级供三种 variant 共用,调用方传 size 也不再漂移。
+ e('chevron', {}, [
+ c('& svg', { width: '11px', height: '11px' }),
+ ]),
+ m('seat', {
display: 'inline-flex',
- flex: '0 0 auto',
- color: 'var(--dsw-alias-label-caption)',
- }),
- ]),
- m('composerTrigger', {
- display: 'inline-flex',
- alignItems: 'center',
- gap: '4px',
- minWidth: '0',
- maxWidth: '220px',
- height: '28px',
- padding: '0 4px 0 8px',
- border: 'none',
- borderRadius: '24px',
- outline: 'none',
- background: 'transparent',
- color: secondary,
- fontSize: '13px',
- lineHeight: '20px',
- fontWeight: '500',
- cursor: 'pointer',
- }, [
- c('&:hover:not(:disabled)', { background: hover }),
- c('&:focus-visible', { ...focusRing }),
- c('&:disabled', {
- color: dimmed,
- cursor: 'default',
- }),
- e('chevron', {
+ alignItems: 'center',
+ gap: '4px',
+ minWidth: '0',
+ maxWidth: 'min(100%, 240px)',
+ minHeight: '28px',
+ padding: '0 8px',
+ border: 'none',
+ borderRadius: '16px',
+ background: 'transparent',
+ color: primary,
+ fontSize: '13px',
+ lineHeight: '20px',
+ fontWeight: '500',
+ whiteSpace: 'nowrap',
+ cursor: 'pointer',
+ }, [
+ c('&:not(:disabled):hover, &[aria-expanded=\'true\']', { background: hover }),
+ c('&:disabled', {
+ cursor: 'default',
+ color: 'var(--dsw-alias-label-quaternary)',
+ }),
+ e('icon', {
+ display: 'inline-flex',
+ flex: '0 0 auto',
+ color: primary,
+ }),
+ e('label', labelEllipsis),
+ e('chevron', {
+ display: 'inline-flex',
+ flex: '0 0 auto',
+ color: 'var(--dsw-alias-label-caption)',
+ }),
+ ]),
+ m('composerTrigger', {
display: 'inline-flex',
- flex: '0 0 auto',
- color: 'var(--dsw-alias-label-caption)',
- transition: 'transform 120ms ease',
+ alignItems: 'center',
+ gap: '4px',
+ minWidth: '0',
+ maxWidth: '220px',
+ height: '28px',
+ padding: '0 4px 0 8px',
+ border: 'none',
+ borderRadius: '24px',
+ outline: 'none',
+ background: 'transparent',
+ color: secondary,
+ fontSize: '13px',
+ lineHeight: '20px',
+ fontWeight: '500',
+ cursor: 'pointer',
}, [
- c('&[data-open=\'true\']', { transform: 'rotate(180deg)' }),
+ c('&:hover:not(:disabled)', { background: hover }),
+ c('&:focus-visible', { ...focusRing }),
+ c('&:disabled', {
+ color: dimmed,
+ cursor: 'default',
+ }),
+ e('icon', {
+ display: 'inline-flex',
+ flex: '0 0 auto',
+ }, [
+ c('& svg', { width: '14px', height: '14px' }),
+ ]),
+ e('label', labelEllipsis),
+ e('badge', { flex: '0 0 auto' }),
+ e('chevron', {
+ display: 'inline-flex',
+ flex: '0 0 auto',
+ color: 'var(--dsw-alias-label-caption)',
+ transition: 'transform 120ms ease',
+ }, [
+ c('&[data-open=\'true\']', { transform: 'rotate(180deg)' }),
+ ]),
]),
- ]),
- m('selector', {
- display: 'inline-flex',
- alignItems: 'center',
- gap: '12px',
- height: '36px',
- padding: '0 14px',
- border: 'none',
- borderRadius: '18px',
- background: modulePlatform,
- font: 'inherit',
- fontSize: '14px',
- lineHeight: '22px',
- color: primary,
- cursor: 'pointer',
- }, [
- c('&:hover:not(:disabled)', { background: hover }),
- c('&:disabled', { cursor: 'default' }),
- e('chevron', {
+ m('selector', {
display: 'inline-flex',
- flex: '0 0 auto',
- color: 'var(--dsw-alias-label-caption)',
- }),
+ alignItems: 'center',
+ gap: '12px',
+ height: '36px',
+ padding: '0 14px',
+ border: 'none',
+ borderRadius: '18px',
+ background: modulePlatform,
+ font: 'inherit',
+ fontSize: '14px',
+ lineHeight: '22px',
+ color: primary,
+ cursor: 'pointer',
+ }, [
+ c('&:hover:not(:disabled)', { background: hover }),
+ c('&:disabled', { cursor: 'default' }),
+ e('chevron', {
+ display: 'inline-flex',
+ flex: '0 0 auto',
+ color: 'var(--dsw-alias-label-caption)',
+ }),
+ ]),
]),
+ c('', { raw: COMPOSER_TRIGGER_COLLAPSE }),
])
diff --git a/packages/dsh-tauri-ui/src/client/components/chip.tsx b/packages/dsh-tauri-ui/src/client/components/chip.tsx
index 714e0732..e5a21844 100644
--- a/packages/dsh-tauri-ui/src/client/components/chip.tsx
+++ b/packages/dsh-tauri-ui/src/client/components/chip.tsx
@@ -6,19 +6,22 @@ import chipStyle from './chip.cssr'
const CHIP_STYLE_ID = 'dsh-tauri-ui-chip-styles'
-export function Chip({ variant, icon, chevron, open, className, children, ...rest }: ChipProps): ReactElement {
+export function Chip({ variant, icon, badge, chevron, open, className, children, ...rest }: ChipProps): ReactElement {
useMountStyle(chipStyle, CHIP_STYLE_ID)
+ // 官方 PermissionRow.selector 不包 icon/label/badge,其余两个 variant 按 PermissionSelect/AgentPresetSeat 包裹。
+ const wraps = variant !== 'selector'
return (
<button
type="button"
className={compact(['dshp-chip', `dshp-chip--${variant}`, className]).join(' ')}
{...rest}
>
- {icon}
- {children}
+ {wraps && icon != null ? <span className="dshp-chip__icon" aria-hidden>{icon}</span> : icon}
+ {wraps && children != null ? <span className="dshp-chip__label">{children}</span> : children}
+ {wraps && badge != null ? <span className="dshp-chip__badge" aria-hidden>{badge}</span> : badge}
{chevron === undefined
? null
- : <span className="dshp-chip__chevron" data-open={open === true ? 'true' : undefined}>{chevron}</span>}
+ : <span className="dshp-chip__chevron" aria-hidden data-open={open === true ? 'true' : undefined}>{chevron}</span>}
</button>
)
}
diff --git a/packages/dsh-tauri-ui/src/client/components/chip.types.ts b/packages/dsh-tauri-ui/src/client/components/chip.types.ts
index 64e339c2..9f406842 100644
--- a/packages/dsh-tauri-ui/src/client/components/chip.types.ts
+++ b/packages/dsh-tauri-ui/src/client/components/chip.types.ts
@@ -5,6 +5,7 @@ export type ChipVariant = 'seat' | 'composerTrigger' | 'selector'
export interface ChipProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'children'> {
variant: ChipVariant
icon?: ReactNode
+ badge?: ReactNode
chevron?: ReactNode
open?: boolean
children?: ReactNode
diff --git a/packages/dsh-tauri-ui/src/client/components/goal-bar.cssr.ts b/packages/dsh-tauri-ui/src/client/components/goal-bar.cssr.ts
index 930525de..d4ccd095 100644
--- a/packages/dsh-tauri-ui/src/client/components/goal-bar.cssr.ts
+++ b/packages/dsh-tauri-ui/src/client/components/goal-bar.cssr.ts
@@ -3,7 +3,6 @@ import { cssr } from '../utils/cssr'
const { c, bem: { b, e, m } } = cssr
const { dimmed, error, focusRing, hover, primary, secondary, tertiary } = sharedStyles
-
export default b('goal-bar', {
'position': 'relative',
'isolation': 'isolate',
@@ -49,7 +48,7 @@ export default b('goal-bar', {
overflow: 'hidden',
fontSize: '13px',
lineHeight: '20px',
- color: dimmed,
+ color: 'var(--dsw-alias-label-primary-dimmed, var(--dsw-alias-label-dimmed))',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
}),
@@ -68,6 +67,7 @@ export default b('goal-bar', {
alignItems: 'center',
gap: '10px',
flex: 'none',
+ marginLeft: 'auto',
}),
e('action', {
display: 'inline-flex',
@@ -77,22 +77,47 @@ export default b('goal-bar', {
padding: '0',
border: '0',
background: 'transparent',
- color: tertiary,
+ color: primary,
font: 'inherit',
fontSize: '13px',
lineHeight: '20px',
borderRadius: '6px',
+ textDecoration: 'underline',
+ textDecorationColor: 'transparent',
+ textUnderlineOffset: '2px',
+ transition: 'text-decoration-color 120ms ease',
cursor: 'pointer',
}, [
- c('&:hover:not(:disabled)', { color: secondary, background: hover }),
+ c('&:hover:not(:disabled)', {
+ textDecorationColor: 'currentcolor',
+ }),
c('&:focus-visible', { ...focusRing }),
c('&:disabled', {
color: dimmed,
cursor: 'default',
opacity: '0.4',
}),
- ]),
- m('danger', { color: error }, [
- c('&:hover:not(:disabled)', { color: `color-mix(in srgb, ${error} 78%, ${primary})` }),
+ m('icon', {
+ width: '28px',
+ height: '28px',
+ padding: '0',
+ border: 'none',
+ borderRadius: '999px',
+ cornerShape: 'round',
+ background: 'transparent',
+ color: tertiary,
+ textDecoration: 'none',
+ cursor: 'pointer',
+ }, [
+ c('&:hover:not(:disabled)', {
+ background: hover,
+ color: secondary,
+ }),
+ c('&:disabled', {
+ color: tertiary,
+ cursor: 'default',
+ opacity: '0.4',
+ }),
+ ]),
]),
])
diff --git a/packages/dsh-tauri-ui/src/client/components/goal-bar.tsx b/packages/dsh-tauri-ui/src/client/components/goal-bar.tsx
index 22ed480f..dfa342d1 100644
--- a/packages/dsh-tauri-ui/src/client/components/goal-bar.tsx
+++ b/packages/dsh-tauri-ui/src/client/components/goal-bar.tsx
@@ -30,7 +30,7 @@ export function GoalBar({
}
export function GoalBarAction({
- variant = 'default',
+ iconOnly = false,
className,
children,
...rest
@@ -39,7 +39,7 @@ export function GoalBarAction({
return (
<button
type="button"
- className={compact(['dshp-goal-bar__action', variant === 'default' ? undefined : `dshp-goal-bar--${variant}`, className]).join(' ')}
+ className={compact(['dshp-goal-bar__action', iconOnly ? 'dshp-goal-bar__action--icon' : undefined, className]).join(' ')}
{...rest}
>
{children}
diff --git a/packages/dsh-tauri-ui/src/client/components/goal-bar.types.ts b/packages/dsh-tauri-ui/src/client/components/goal-bar.types.ts
index 176101e4..34423609 100644
--- a/packages/dsh-tauri-ui/src/client/components/goal-bar.types.ts
+++ b/packages/dsh-tauri-ui/src/client/components/goal-bar.types.ts
@@ -1,7 +1,5 @@
import type { ButtonHTMLAttributes, HTMLAttributes, ReactNode } from 'react'
-export type GoalBarActionVariant = 'default' | 'danger'
-
export interface GoalBarProps extends Omit<HTMLAttributes<HTMLDivElement>, 'children'> {
glyph?: ReactNode
label?: ReactNode
@@ -12,6 +10,6 @@ export interface GoalBarProps extends Omit<HTMLAttributes<HTMLDivElement>, 'chil
}
export interface GoalBarActionProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'children'> {
- variant?: GoalBarActionVariant
+ iconOnly?: boolean
children?: ReactNode
}
diff --git a/packages/dsh-tauri-ui/src/client/components/icon-button.tsx b/packages/dsh-tauri-ui/src/client/components/icon-button.tsx
index 5f2bebf8..fd1281a6 100644
--- a/packages/dsh-tauri-ui/src/client/components/icon-button.tsx
+++ b/packages/dsh-tauri-ui/src/client/components/icon-button.tsx
@@ -1,5 +1,4 @@
-import type { ReactElement } from 'react'
-import type { ButtonHTMLAttributes, ReactNode } from 'react'
+import type { ButtonHTMLAttributes, ReactElement, ReactNode } from 'react'
import { compact } from 'dsh-tauri/client'
import { useMountStyle } from '../hooks/use-mount-style'
diff --git a/packages/dsh-tauri-ui/src/client/components/icons.tsx b/packages/dsh-tauri-ui/src/client/components/icons.tsx
index 5ffc259b..f3a0c663 100644
--- a/packages/dsh-tauri-ui/src/client/components/icons.tsx
+++ b/packages/dsh-tauri-ui/src/client/components/icons.tsx
@@ -1,7 +1,7 @@
export { default as Alarm } from '@gravity-ui/icons/Alarm'
-export { default as ArrowDownToLine } from '@gravity-ui/icons/ArrowDownToLine'
export { default as ArrowLeft } from '@gravity-ui/icons/ArrowLeft'
export { default as ArrowRight } from '@gravity-ui/icons/ArrowRight'
+export { default as ArrowRightFromSquare } from '@gravity-ui/icons/ArrowRightFromSquare'
export { default as ArrowRotateRight } from '@gravity-ui/icons/ArrowRotateRight'
export { default as ArrowUpRight } from '@gravity-ui/icons/ArrowUpRight'
export { default as ArrowUturnCcwLeft } from '@gravity-ui/icons/ArrowUturnCcwLeft'
@@ -34,5 +34,7 @@ export { default as Person } from '@gravity-ui/icons/Person'
export { default as PlugConnection } from '@gravity-ui/icons/PlugConnection'
export { default as Plus } from '@gravity-ui/icons/Plus'
export { default as Puzzle } from '@gravity-ui/icons/Puzzle'
+export { default as TerminalLine } from '@gravity-ui/icons/TerminalLine'
export { default as TrashBin } from '@gravity-ui/icons/TrashBin'
export { default as TriangleExclamation } from '@gravity-ui/icons/TriangleExclamation'
+export { default as Xmark } from '@gravity-ui/icons/Xmark'
diff --git a/packages/dsh-tauri-ui/src/client/components/styles.test.tsx b/packages/dsh-tauri-ui/src/client/components/styles.test.tsx
new file mode 100644
index 00000000..5ecc4951
--- /dev/null
+++ b/packages/dsh-tauri-ui/src/client/components/styles.test.tsx
@@ -0,0 +1,418 @@
+import type { ComponentType, ReactElement, ReactNode } from 'react'
+import { readFileSync } from 'node:fs'
+import { fileURLToPath } from 'node:url'
+import { createElement } from 'react'
+import { renderToStaticMarkup } from 'react-dom/server'
+import { describe, expect, it, vi } from 'vitest'
+import globalStyle from '../styles/global.cssr'
+import turnNavigationStyle from '../styles/index.cssr'
+import { HeroWorkspace } from '../ui/hero-workspace'
+import heroWorkspaceStyle from '../ui/hero-workspace.cssr'
+import { AutoConfigAllButton } from '../ui/model-extras/auto-config-all-button'
+import { configEditorStyle } from '../ui/model-extras/config-editor.cssr'
+import { ModelCompatFields } from '../ui/model-extras/model-compat-fields'
+import modelCompatFieldsStyle from '../ui/model-extras/model-compat-fields.cssr'
+import { ModelConfigToolbar } from '../ui/model-extras/model-config-toolbar'
+import modelExtrasStyle from '../ui/model-extras/model-extras.cssr'
+import { ModelFetchConfigButton } from '../ui/model-extras/model-fetch-config-button'
+import { SettingsNavIcon } from '../ui/nav-icon'
+import navIconStyle from '../ui/nav-icon.cssr'
+import { PanelPage } from '../ui/panel-page'
+import panelPageStyle from '../ui/panel-page.cssr'
+import { SegmentedControl } from '../ui/segmented-control'
+import segmentedControlStyle from '../ui/segmented-control.cssr'
+import { SettingsSidebar } from '../ui/sidebar'
+import sidebarStyle from '../ui/sidebar.cssr'
+import { SettingsTrigger } from '../ui/trigger'
+import triggerStyle from '../ui/trigger.cssr'
+import { Button } from './button'
+import buttonStyle from './button.cssr'
+import { Checkbox } from './checkbox'
+import checkboxStyle from './checkbox.cssr'
+import { Chip } from './chip'
+import chipStyle from './chip.cssr'
+import { GoalBar, GoalBarAction } from './goal-bar'
+import goalBarStyle from './goal-bar.cssr'
+import { IconButton } from './icon-button'
+import iconButtonStyle from './icon-button.cssr'
+import { Tag } from './tag'
+import tagStyle from './tag.cssr'
+
+const stores = vi.hoisted(() => ({
+ settings: {
+ open: false,
+ activeId: undefined as string | undefined,
+ query: '',
+ railWidth: undefined as number | undefined,
+ },
+ sections: {
+ rows: [] as { id: string, label: string }[],
+ onboarding: [] as { id: string, label: string }[],
+ },
+}))
+
+vi.mock('../store', () => ({
+ store: { settings: stores.settings, sections: stores.sections },
+}))
+
+vi.mock('dsh-tauri/client', () => ({
+ compact: (values: unknown[]): unknown[] => values.filter(Boolean),
+ uniq: (values: unknown[]): unknown[] => [...new Set(values)],
+ isEmpty: (values: readonly unknown[]): boolean => values.length === 0,
+ clamp: (value: number, min: number, max: number): number => Math.min(Math.max(value, min), max),
+ get: (record: Record<string, unknown>, key: string, fallback?: unknown): unknown => record[key] ?? fallback,
+ useEventListener: (): void => {},
+ useStore: (module: unknown): unknown => module,
+ defineStore: (definition: {
+ state: () => Record<string, unknown>
+ actions: Record<string, (...args: never[]) => unknown>
+ }): Record<string, unknown> => {
+ const state = definition.state()
+ return {
+ ...state,
+ ...Object.fromEntries(Object.entries(definition.actions).map(([name, action]) => [name, action.bind(state)])),
+ }
+ },
+ defineLocale: (namespace: string, dicts: { zh: Record<string, string>, en: Record<string, string> }) => ({
+ NS: namespace,
+ text: (key: string): string => dicts.zh[key] ?? key,
+ activeLocale: (): string => 'zh',
+ isEnglishLocale: (): boolean => false,
+ useLocale: (): string => 'zh',
+ registerLocale: (): (() => void) => () => {},
+ }),
+}))
+
+vi.mock('@deepseek-ai/dsh-client-ui-primitives', () => ({
+ Button: (props: { children?: ReactNode, icon?: ReactNode, className?: string, disabled?: boolean, title?: string, onClick?: () => void }) => (
+ <button type="button" className={props.className} disabled={props.disabled} title={props.title} onClick={props.onClick}>
+ {props.icon}
+ {props.children}
+ </button>
+ ),
+ Tag: (props: { children?: ReactNode, className?: string, tone?: string }) => (
+ <span className={props.className} data-tone={props.tone}>{props.children}</span>
+ ),
+ Switch: (props: { checked: boolean, disabled?: boolean, label: string, title?: string }) => (
+ <button type="button" role="switch" aria-checked={props.checked} disabled={props.disabled} aria-label={props.label} title={props.title} />
+ ),
+ Menu: (props: { anchor?: ReactNode, items?: readonly { id: string, icon?: ReactNode }[] }) => (
+ <>
+ {props.anchor}
+ {(props.items ?? []).map(entry => <span key={entry.id}>{entry.icon}</span>)}
+ </>
+ ),
+ Modal: (props: { children?: ReactNode, footer?: ReactNode }) => (
+ <div>
+ {props.children}
+ {props.footer}
+ </div>
+ ),
+}))
+
+vi.mock('@deepseek-ai/dsh-client-ui-renderer', () => ({
+ SlotOutlet: () => null,
+}))
+
+const HERE = fileURLToPath(new URL('.', import.meta.url))
+const PROBE = { settingsNs: 'ns', profilePath: [] }
+const t = (key: string): string => key
+
+function draw(component: unknown, props: Record<string, unknown> = {}): string {
+ return renderToStaticMarkup(node(component, props))
+}
+
+function node(component: unknown, props: Record<string, unknown> = {}): ReactElement {
+ return createElement(component as unknown as ComponentType<Record<string, unknown>>, props)
+}
+
+function selectorHook(state: unknown): (select: (value: unknown) => unknown) => unknown {
+ return select => select(state)
+}
+
+function readSource(...files: string[]): string {
+ return files.map(file => readFileSync(`${HERE}${file}`, 'utf8')).join('\n')
+}
+
+function stripGroups(input: string, open: string, close: string): string {
+ let depth = 0
+ let output = ''
+ for (const char of input) {
+ if (char === open) {
+ depth += 1
+ continue
+ }
+ if (char === close) {
+ depth = Math.max(0, depth - 1)
+ continue
+ }
+ if (depth === 0)
+ output += char
+ }
+ return output
+}
+
+function selectorParts(css: string): string[] {
+ return css
+ .replace(/@[\w-][^{]*\{/g, ' ')
+ .split('}')
+ .map(chunk => chunk.split('{')[0] ?? '')
+ .map(chunk => chunk.replace(/\s+/g, ' ').trim())
+ .filter(chunk => chunk !== '')
+ .flatMap(chunk => stripGroups(stripGroups(chunk, '(', ')'), '[', ']').split(','))
+ .map(part => part.trim())
+ .filter(part => part !== '')
+}
+
+function classesIn(segment: string): string[] {
+ return [...segment.matchAll(/\.([\w-]+)/g)].map(match => match[1] ?? '').filter(name => name !== '')
+}
+
+function renderedClassSets(markup: string): Set<string>[] {
+ return [...markup.matchAll(/class="([^"]*)"/g)].map(match =>
+ new Set((match[1] ?? '').split(/\s+/).filter(name => name !== '')),
+ )
+}
+
+interface GatedClass {
+ token: string
+ literal: string
+}
+
+interface AuditCase {
+ name: string
+ style: { render: () => string }
+ markup: () => string
+ sources: string[]
+ gated?: GatedClass[]
+}
+
+const SESSION_HOOK = selectorHook({ phase: 'loading', byId: {} })
+
+const CASES: AuditCase[] = [
+ {
+ name: 'components/button',
+ style: buttonStyle,
+ sources: ['button.tsx'],
+ markup: () => ['elevated', 'add', 'addGhost', 'danger']
+ .flatMap(variant => ['sm', 'md'].map(size => draw(Button, { variant, size, children: 'x' })))
+ .join(''),
+ },
+ {
+ name: 'components/checkbox',
+ style: checkboxStyle,
+ sources: ['checkbox.tsx'],
+ markup: () => draw(Checkbox, { checked: false, onChange: () => {}, children: 'x' }),
+ },
+ {
+ name: 'components/chip',
+ style: chipStyle,
+ sources: ['chip.tsx'],
+ markup: () => ['seat', 'composerTrigger', 'selector']
+ .map(variant => draw(Chip, { variant, icon: createElement('span'), badge: createElement('span'), chevron: createElement('span'), open: true, children: 'x' }))
+ .join(''),
+ },
+ {
+ name: 'components/goal-bar',
+ style: goalBarStyle,
+ sources: ['goal-bar.tsx'],
+ markup: () => [
+ draw(GoalBar, {
+ glyph: 'g',
+ label: 'l',
+ objective: 'o',
+ error: 'e',
+ actions: node(GoalBarAction, { children: 'd' }),
+ children: node(GoalBarAction, { 'iconOnly': true, 'aria-label': 'i' }),
+ }),
+ draw(GoalBarAction, { children: 'd' }),
+ draw(GoalBarAction, { children: 'x' }),
+ ].join(''),
+ },
+ {
+ name: 'components/icon-button',
+ style: iconButtonStyle,
+ sources: ['icon-button.tsx'],
+ markup: () => ['search', 'toolbar', 'model', 'round', 'row', 'help', 'action']
+ .map(variant => draw(IconButton, { variant, children: 'x' }))
+ .join(''),
+ },
+ {
+ name: 'components/tag',
+ style: tagStyle,
+ sources: ['tag.tsx'],
+ markup: () => [
+ draw(Tag, { variant: 'version', tone: 'neutral', children: 'v' }),
+ draw(Tag, { variant: 'status', tone: 'danger', children: 's' }),
+ draw(Tag, { variant: 'status', tone: 'info', children: 's' }),
+ draw(Tag, { variant: 'status', tone: 'outline', children: 's' }),
+ draw(Tag, { variant: 'version', tone: 'outline', children: 'v' }),
+ ].join(''),
+ },
+ {
+ name: 'ui/hero-workspace',
+ style: heroWorkspaceStyle,
+ sources: ['../ui/hero-workspace.tsx', '../constants/index.ts'],
+ markup: () => draw(HeroWorkspace, {
+ open: true,
+ onPick: () => {},
+ onClose: () => {},
+ startUngrouped: () => {},
+ useWorkspaces: selectorHook({ items: [], phase: 'pending' }),
+ useSessions: selectorHook({}),
+ }),
+ },
+ {
+ name: 'ui/nav-icon',
+ style: navIconStyle,
+ sources: ['../ui/nav-icon.tsx'],
+ markup: () => draw(SettingsNavIcon, { id: 'models' }),
+ },
+ {
+ name: 'ui/panel-page',
+ style: panelPageStyle,
+ sources: ['../ui/panel-page.tsx'],
+ markup: () => draw(PanelPage, { children: createElement('span') }),
+ },
+ {
+ name: 'ui/segmented-control',
+ style: segmentedControlStyle,
+ sources: ['../ui/segmented-control.tsx'],
+ markup: () => draw(SegmentedControl, {
+ id: 'mode',
+ label: 'Mode',
+ value: 'b',
+ options: [{ value: 'a', label: 'A' }, { value: 'b', label: 'B' }],
+ onChange: () => {},
+ }),
+ },
+ {
+ name: 'ui/sidebar',
+ style: sidebarStyle,
+ sources: ['../ui/sidebar.tsx', '../constants/index.ts'],
+ gated: [{ token: 'dshp-settings-sidebar__handle--dragging', literal: '__handle--dragging' }],
+ markup: () => {
+ stores.settings.open = true
+ stores.settings.activeId = 'models'
+ stores.sections.rows = [{ id: 'models', label: 'Models' }]
+ const filled = draw(SettingsSidebar, { useSessions: SESSION_HOOK })
+ stores.sections.rows = []
+ const empty = draw(SettingsSidebar, { useSessions: SESSION_HOOK })
+ stores.settings.open = false
+ return `${filled}${empty}`
+ },
+ },
+ {
+ name: 'ui/trigger',
+ style: triggerStyle,
+ sources: ['../ui/trigger.tsx'],
+ markup: () => [
+ draw(SettingsTrigger, { wide: true, useSessions: SESSION_HOOK }),
+ draw(SettingsTrigger, { wide: false, useSessions: SESSION_HOOK }),
+ ].join(''),
+ },
+ {
+ name: 'ui/model-extras/config-editor',
+ style: configEditorStyle,
+ sources: ['../ui/model-extras/model-config-toolbar.tsx'],
+ markup: () => draw(ModelConfigToolbar, { t, editor: { editor: 'system', command: '' } }),
+ },
+ {
+ name: 'ui/model-extras/model-compat-fields',
+ style: modelCompatFieldsStyle,
+ sources: ['../ui/model-extras/model-compat-fields.tsx'],
+ markup: () => draw(ModelCompatFields, {
+ t,
+ model: { reasoningEfforts: { low: 'low' } },
+ index: 0,
+ templateCompat: true,
+ onPatch: () => {},
+ }),
+ },
+ {
+ name: 'ui/model-extras/model-extras',
+ style: modelExtrasStyle,
+ sources: [
+ '../ui/model-extras/model-config-toolbar.tsx',
+ '../ui/model-extras/auto-config-all-button.tsx',
+ '../ui/model-extras/model-fetch-config-button.tsx',
+ ],
+ gated: [
+ { token: 'dshp-model-extras__dialog-label', literal: 'dshp-model-extras__dialog-label' },
+ { token: 'dshp-model-extras__input', literal: 'dshp-model-extras__input' },
+ { token: 'dshp-model-extras__dialog-hint', literal: 'dshp-model-extras__dialog-hint' },
+ { token: 'dshp-model-extras__dialog-error', literal: 'dshp-model-extras__dialog-error' },
+ { token: 'dshp-model-extras__notice', literal: 'dshp-model-extras__notice' },
+ { token: 'dshp-model-extras__notice--failed', literal: 'dshp-model-extras__notice--failed' },
+ { token: 'dshp-model-extras__notice--done', literal: 'dshp-model-extras__notice--done' },
+ ],
+ markup: () => [
+ draw(ModelConfigToolbar, { t, onOpenConfig: () => {}, editor: { editor: 'system', command: '' } }),
+ draw(AutoConfigAllButton, { t, models: [{ id: 'm' }], probe: PROBE }),
+ draw(ModelFetchConfigButton, { t, modelId: 'm', models: [{ id: 'm' }], probe: PROBE }),
+ ].join(''),
+ },
+ {
+ name: 'styles/global',
+ style: globalStyle,
+ sources: [],
+ markup: () => '',
+ },
+ {
+ name: 'styles/index',
+ style: turnNavigationStyle,
+ sources: [],
+ markup: () => '',
+ },
+]
+
+describe('cssr class contract', () => {
+ for (const auditCase of CASES) {
+ it(`${auditCase.name} emits only classes its component renders`, () => {
+ const parts = selectorParts(auditCase.style.render())
+ const markup = auditCase.markup()
+ const elements = renderedClassSets(markup)
+ const rendered = new Set(elements.flatMap(set => [...set]))
+ const emitted = [...new Set(parts.flatMap(classesIn))].filter(token => token.startsWith('dshp-')).sort()
+ const gated = auditCase.gated ?? []
+ const missing = emitted.filter(token => !rendered.has(token))
+
+ expect(missing, `${auditCase.name} emits classes no rendered element carries`).toEqual(gated.map(item => item.token).sort())
+ for (const item of gated)
+ expect(readSource(...auditCase.sources), `gated literal for ${item.token}`).toContain(item.literal)
+
+ const unsatisfiable = parts.filter((part) => {
+ return part.split(/[\s>+~]+/).filter(segment => segment !== '').some((segment) => {
+ const classes = classesIn(segment)
+ if (classes.length < 2)
+ return false
+ if (!classes.every(name => rendered.has(name)))
+ return false
+ return !elements.some(set => classes.every(name => set.has(name)))
+ })
+ })
+
+ expect([...new Set(unsatisfiable)], `${auditCase.name} has compound selectors no single element can carry`).toEqual([])
+ })
+ }
+
+ it('keeps the goal-bar modifier on the action element instead of the block', () => {
+ const parts = selectorParts(goalBarStyle.render())
+ expect(parts).toContain('.dshp-goal-bar .dshp-goal-bar__action.dshp-goal-bar__action--icon')
+ expect(parts.filter(part => part.includes('dshp-goal-bar--icon') || part.includes('dshp-goal-bar--danger'))).toEqual([])
+ expect(parts.filter(part => part.includes('dshp-goal-bar__action--danger'))).toEqual([])
+ const icon = draw(GoalBarAction, { 'iconOnly': true, 'aria-label': 'i' })
+ const classes = [...icon.matchAll(/class="([^"]*)"/g)].map(match => match[1] ?? '')
+ expect(classes).toContain('dshp-goal-bar__action dshp-goal-bar__action--icon')
+ })
+
+ it('drops the dead model-extras open, busy and hover classes', () => {
+ const css = modelExtrasStyle.render()
+ expect(css).toContain('.dshp-model-extras__link[aria-expanded=\'true\']')
+ expect(css).not.toContain('dshp-model-extras__link--open')
+ expect(css).not.toContain('dshp-model-extras__busy')
+ const trigger = draw(ModelConfigToolbar, { t, editor: { editor: 'system', command: '' } })
+ expect(trigger).toContain('class="dshp-model-extras__link dshp-model-config-toolbar__trigger"')
+ expect(trigger).toContain('aria-expanded="false"')
+ })
+})
diff --git a/packages/dsh-tauri-ui/src/client/ui/model-extras/model-extras.cssr.ts b/packages/dsh-tauri-ui/src/client/ui/model-extras/model-extras.cssr.ts
index e5bf62eb..40112a1a 100644
--- a/packages/dsh-tauri-ui/src/client/ui/model-extras/model-extras.cssr.ts
+++ b/packages/dsh-tauri-ui/src/client/ui/model-extras/model-extras.cssr.ts
@@ -4,7 +4,7 @@ import { cssr } from '../../utils/cssr'
export const MODEL_EXTRAS_STYLE_ID = 'dsh-tauri-ui-model-extras-styles'
const { c } = cssr
-const { primary, secondary, tertiary, error, success, hover, borderL4, layer1, modulePlatform, focusRing } = sharedStyles
+const { primary, secondary, tertiary, error, success, hover, borderL4, layer1, focusRing } = sharedStyles
export default c([
c('.dshp-model-extras__row', {
@@ -40,7 +40,7 @@ export default c([
cursor: 'not-allowed',
opacity: '0.5',
}),
- c('&.dshp-model-extras__link--open', {
+ c('&[aria-expanded=\'true\']', {
color: secondary,
}),
]),
@@ -97,8 +97,4 @@ export default c([
lineHeight: '20px',
color: error,
}),
- c('.dshp-model-extras__busy', {
- background: modulePlatform,
- color: tertiary,
- }),
])