refactor(gui): features register their own settings surfaces

Settings collaboration direction (recorded in the note): the shell only
provides composition faces — feature plugins register themselves. The
General section moves into the ui-settings shell (order 0, skeleton
rows) and declares the settings.general.item list slot; locale registers
the Language row and ui-theme the Appearance row (each with its own
store mirror, dictionaries, and ledger-judged deferral); the
ui-settings-general package is gone. ui-settings-models becomes
ui-models — a feature package that contributes its Settings section
rather than a settings-owned satellite. The item-slot SlotMap entry is
authored in the ui-settings contract and repeated verbatim in
locale/ui-theme (reference-cycle avoidance; declaration merging keeps
the copies identical).
This commit is contained in:
imccyu
2026-07-26 02:51:36 +08:00
parent 2ee4cda066
commit 23a60ade67
62 changed files with 1008 additions and 1049 deletions

View File

@@ -1,131 +0,0 @@
/* General section rows (figma 501:29983 'Options'): four groups, 16px
* vertical padding each, hairline separator under all but the last. The
* shell's content column owns the outer horizontal padding. */
.section {
display: flex;
flex-direction: column;
width: 100%;
}
/* Title + trailing control row (figma 'Setting-Cell': gap 8, pad 16/0). */
.row {
display: flex;
align-items: center;
gap: 8px;
padding: 16px 0;
border-bottom: 1px solid var(--dsw-alias-border-l2);
}
/* Title + full-width body group (figma 'Frame 2117131229': column, gap 8). */
.group {
display: flex;
flex-direction: column;
gap: 8px;
padding: 16px 0;
border-bottom: 1px solid var(--dsw-alias-border-l2);
}
.last {
border-bottom: none;
}
/* Leading text column (figma 'Frame 2036083120': gap 4, pad-right 48). */
.rowText {
flex: 1;
min-width: 0;
display: flex;
flex-direction: column;
gap: 4px;
padding-right: 48px;
}
.title {
font-size: 14px;
font-weight: 400;
line-height: 22px;
color: var(--dsw-alias-label-primary);
}
.desc {
font-size: 12px;
font-weight: 400;
line-height: 18px;
color: var(--dsw-alias-label-tertiary);
}
/* Selector pill (figma 'Selector': h36 r18, fill #F5F6F7, pad 0/14, gap 12). */
.selector {
display: inline-flex;
align-items: center;
gap: 12px;
height: 36px;
padding: 0 14px;
border: none;
border-radius: 18px;
background: var(--dsw-alias-bg-module-platform);
font: inherit;
font-size: 14px;
line-height: 22px;
color: var(--dsw-alias-label-primary);
cursor: pointer;
}
.selector:disabled {
cursor: default;
}
.chevron {
flex: none;
}
/* Cube rows share an 8px gap; cubes stretch to equal height. */
.cubeRow {
display: flex;
align-items: stretch;
gap: 8px;
}
/* Tool Call mode cube (figma '.Selector Cube' 418w r16; horizontal inset =
* outer pad 4 + inner .Menu_cell pad 10, vertical = inner pad 8). */
.modeCube {
box-sizing: border-box;
width: 418px;
display: flex;
flex-direction: column;
justify-content: center;
gap: 2px;
padding: 8px 14px;
border: 1px solid var(--dsw-alias-border-l2);
border-radius: 16px;
background: transparent;
text-align: left;
}
/* Appearance cube (figma '.Selector Cube' 276x82 r16, pad 20/32, centered
* icon-over-label column, gap 4). */
.themeCube {
box-sizing: border-box;
width: 276px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 4px;
padding: 20px 32px;
border: 1px solid var(--dsw-alias-border-l2);
border-radius: 16px;
background: transparent;
font: inherit;
font-size: 14px;
line-height: 22px;
color: var(--dsw-alias-label-primary);
cursor: pointer;
}
/* Selected cube: #F5F6F7 fill + #ADB2B8 border (static token — the bluish-400
* step has no alias-layer name). */
.selected {
background: var(--dsw-alias-bg-module-platform);
border-color: var(--dsw-static-neutral-bluish-400);
}

View File

@@ -1,118 +0,0 @@
/**
* General settings section: Permission and Tool Call skeleton rows (visual
* only, no interaction), live Language and Appearance preference rows wired
* through the injected setLocale/setTheme callbacks and the snapshot-mirror
* store. Figma: Settings > Content > Options (501:29983).
*/
import { useState } from 'react'
import clsx from 'clsx'
import {
IconChevronDownOutline14, IconDarkOutline16, IconFollowsystemOutline16, IconLightOutline16,
Menu,
} from '@deepseek-ai/dsh-client-ui-primitives'
import type { GeneralSectionComponentProps, ThemePreferenceId } from './contract.ts'
import css from './GeneralSection.module.css'
/** Appearance cube order and icons (figma 501:30015-30017: Light, Dark, System). */
const THEME_CUBES: readonly { id: ThemePreferenceId; labelKey: string; Icon: typeof IconLightOutline16 }[] = [
{ id: 'light', labelKey: 'appearance.light', Icon: IconLightOutline16 },
{ id: 'dark', labelKey: 'appearance.dark', Icon: IconDarkOutline16 },
{ id: 'system', labelKey: 'appearance.system', Icon: IconFollowsystemOutline16 },
]
/**
* Render the General section content column.
* @param props - composed slot props (contract.ts).
* @returns the section element tree.
*/
export function GeneralSection(props: GeneralSectionComponentProps) {
const { t, setLocale, setTheme, useStore } = props
const localeActive = useStore(s => s.localeActive)
const localeOptions = useStore(s => s.localeOptions)
const themePreference = useStore(s => s.themePreference)
const [languageOpen, setLanguageOpen] = useState(false)
const activeLocaleLabel = localeOptions.find(l => l.id === localeActive)?.label ?? localeActive
return (
<div className={css.section}>
{/* Permission (skeleton): disabled selector pill. */}
<div className={css.row}>
<div className={css.rowText}>
<div className={css.title}>{t('permission.title')}</div>
<div className={css.desc}>{t('permission.desc')}</div>
</div>
<button type="button" className={css.selector} disabled>
{t('permission.value')}
<IconChevronDownOutline14 className={css.chevron} />
</button>
</div>
{/* Tool Call (skeleton): schema cube pinned selected, code cube unselected. */}
<div className={css.group}>
<div className={css.title}>{t('toolcall.title')}</div>
<div className={css.cubeRow}>
<div className={clsx(css.modeCube, css.selected)}>
<div className={css.title}>{t('toolcall.schema.title')}</div>
<div className={css.desc}>{t('toolcall.schema.desc')}</div>
</div>
<div className={css.modeCube}>
<div className={css.title}>{t('toolcall.code.title')}</div>
<div className={css.desc}>{t('toolcall.code.desc')}</div>
</div>
</div>
</div>
{/* Language: selector pill opens the locale menu. */}
<div className={css.row}>
<div className={css.rowText}>
<div className={css.title}>{t('language.title')}</div>
</div>
<Menu
open={languageOpen}
onClose={() => { setLanguageOpen(false) }}
items={localeOptions.map(l => ({ id: l.id, label: l.label }))}
selectedId={localeActive}
onSelect={(id) => {
setLocale(id)
setLanguageOpen(false)
}}
align="end"
portal
anchor={(
<button
type="button"
className={css.selector}
aria-haspopup="menu"
aria-expanded={languageOpen}
onClick={() => { setLanguageOpen(v => !v) }}
>
{activeLocaleLabel}
<IconChevronDownOutline14 className={css.chevron} />
</button>
)}
/>
</div>
{/* Appearance: three preference cubes; selection follows the persisted
* preference, never the resolved active theme. */}
<div className={clsx(css.group, css.last)}>
<div className={css.title}>{t('appearance.title')}</div>
<div className={css.cubeRow}>
{THEME_CUBES.map(({ id, labelKey, Icon }) => (
<button
key={id}
type="button"
className={clsx(css.themeCube, themePreference === id && css.selected)}
aria-pressed={themePreference === id}
onClick={() => { setTheme(id) }}
>
<Icon />
{t(labelKey)}
</button>
))}
</div>
</div>
</div>
)
}

View File

@@ -1,66 +0,0 @@
/**
* General section component contract: the slot-store state shape, the
* injected business face, and the composed props type. The component imports
* only from here; service snapshot shapes are mirrored as plain rows so the
* presentation layer stays decoupled from the locale/theme packages.
*/
import type { PropsRuntime, PropsStore } from '@deepseek-ai/dsh-client-ui-slots'
// Type-only: pulls the shell's SlotMap merge (the 'settings.section' entry).
import type {} from '@deepseek-ai/dsh-client-ui-settings/client'
import type { createGeneralSettingsStore } from './store.ts'
/** One selectable locale row projected into the store (id + self-described label). */
export interface LocaleOptionRow {
/** Locale id (the setLocale argument). */
id: string
/** Display name in its own language (中文 / English). */
label: string
}
/** Theme preference union mirrored from the theme service snapshot. */
export type ThemePreferenceId = 'light' | 'dark' | 'system'
/**
* Store state: mirrors of the locale/theme service snapshots, written only by
* the plugin's apply-world change listeners (components have no write path —
* preference writes go through the injected callbacks to the services, and
* the resulting change events flow back into this mirror).
*/
export interface GeneralSettingsState {
/** Active locale id. */
localeActive: string
/** Selectable locales in display order. */
localeOptions: LocaleOptionRow[]
/** Locale service revision (re-renders translated copy on dictionary/locale changes); -1 until first sync. */
localeRevision: number
/** Persisted theme preference (selection state reads this, never the resolved active theme). */
themePreference: ThemePreferenceId
/** Theme service revision; -1 until first sync. */
themeRevision: number
}
/**
* Registrant-private injected share of the General section (assembled in
* apply): the namespace-bound translate function (stable identity — re-render
* on locale change comes from the store revision, not from `t`) and the two
* preference write callbacks.
*/
export interface GeneralSectionInjected {
/** Translate a `settings.general` dictionary key to the active-locale text. */
t: (key: string) => string
/** Switch the active locale (a registered locale id). */
setLocale: (id: string) => void
/** Switch the theme preference. */
setTheme: (id: ThemePreferenceId) => void
}
/** Store handle type for the props share (type-only; the factory stays internal to apply and tests). */
export type GeneralSettingsStoreHandle = ReturnType<typeof createGeneralSettingsStore>
/**
* Full component props of the General section: the section owner share
* (empty marker) plus the store share and the injected face. No child slots
* are declared; menu open state is component-local viewing state.
*/
export type GeneralSectionComponentProps =
PropsRuntime<'settings.section'> & PropsStore<GeneralSettingsStoreHandle> & GeneralSectionInjected

View File

@@ -1,117 +0,0 @@
/**
* General settings section plugin, browser half. Registers the `general`
* entry into the shell-declared `settings.section` list slot; Language and
* Appearance are live preferences projected from ctx.locale / ctx.theme
* through this entry's slot store. Export discipline: packages/client/AGENTS.md.
*/
import type { ClientContext } from '@deepseek-ai/dsh-client-runtime/client'
import type { BoundActions } from '@deepseek-ai/dsh-client-ui-slots'
// Type-only: pulls the shell's SlotMap merge (the 'settings.section' entry).
import type {} from '@deepseek-ai/dsh-client-ui-settings/client'
// Type-only: the locale/theme Context+Events merges and snapshot shapes.
import type { LocaleSnapshot } from '@deepseek-ai/dsh-client-locale/client'
import type { ThemeSnapshot } from '@deepseek-ai/dsh-client-ui-theme/client'
import type { GeneralSectionInjected } from './contract.ts'
import { createGeneralSettingsStore } from './store.ts'
import { en, zh } from './locales.ts'
import { GeneralSection } from './GeneralSection.tsx'
export type {
GeneralSectionComponentProps, GeneralSectionInjected, GeneralSettingsState,
GeneralSettingsStoreHandle, LocaleOptionRow, ThemePreferenceId,
} from './contract.ts'
/** Dictionary namespace owned by this section (also the nav-label reference prefix). */
const NS = 'settings.general'
/**
* Required services (cordis fiber inject). The target slot is declared by
* ui-settings' apply, whose activation order relative to this one is NOT
* constrained; registration goes through declaration-aware deferral.
*/
export const inject = ['slots', 'locale', 'theme']
/**
* Register the `settings.general` dictionaries and the General section entry
* once the `settings.section` declaration is on the ledger. The slot store
* mirrors the locale/theme snapshots: change listeners attach here in apply,
* write through the bound actions captured at inject time, and the inject
* factory re-syncs from the getters so no event is lost between registration
* and first render (the store's revision guard drops stale duplicates).
* @param ctx - client root context.
*/
export function apply(ctx: ClientContext): void {
ctx.effect(() => {
const disposeZh = ctx.locale.register(NS, 'zh', zh)
const disposeEn = ctx.locale.register(NS, 'en', en)
return () => {
disposeZh()
disposeEn()
}
}, 'ui-settings-general: dictionaries')
const store = createGeneralSettingsStore()
let bound: BoundActions<typeof store> | undefined
const syncLocale = (snapshot: LocaleSnapshot): void => {
bound?.syncLocale(
snapshot.active,
snapshot.locales.map(l => ({ id: l.id, label: l.label })),
snapshot.revision,
)
}
const syncTheme = (snapshot: ThemeSnapshot): void => {
bound?.syncTheme(snapshot.preference, snapshot.revision)
}
ctx.on('locale/change', syncLocale)
ctx.on('theme/change', syncTheme)
const injected = (actions: BoundActions<typeof store>): GeneralSectionInjected => {
bound = actions
syncLocale(ctx.locale.getLocale())
syncTheme(ctx.theme.getTheme())
return {
t: ctx.locale.bind(NS),
setLocale: (id) => { ctx.locale.setLocale(id) },
setTheme: (id) => { ctx.theme.setTheme(id) },
}
}
ctx.effect(() => {
let dispose: (() => void) | undefined
// Presence is judged on the ledger, not on the local disposer: an HMR
// collapse of the declaring entry removes this entry from the slot core
// while `dispose` stays set (the stale disposer is a no-op), so a local
// guard would block the re-registration when the declaration returns.
const registered = (): boolean =>
ctx.slots.entries('settings.section').some(e => e.component === GeneralSection)
const tryRegister = (): void => {
if (ctx.slots.spec('settings.section') === undefined || registered()) return
dispose = ctx.slots.register({
name: 'settings.section',
id: 'general',
order: 0,
label: ctx.locale.bind(NS)('nav'),
store,
inject: injected,
}, GeneralSection)
}
// Nav labels are registrant-localized: re-register on locale change so
// the ledger carries fresh text (the version bump re-renders the shell).
// The ledger check mirrors tryRegister: after an HMR collapse `dispose`
// stays set while the entry is gone — relabeling then must stay quiet.
const offLocale = ctx.on('locale/change', () => {
if (dispose === undefined || !registered()) return
dispose()
dispose = undefined
tryRegister()
})
const unsubscribe = ctx.slots.subscribe('settings.section', () => { tryRegister() })
tryRegister()
return () => {
offLocale()
unsubscribe()
dispose?.()
}
}, 'ui-settings-general: section registration')
}

View File

@@ -1,42 +0,0 @@
/**
* `settings.general` namespace dictionaries. Skeleton-row technical copy
* (Read only / Schema mode / Code mode and their descriptions) is shared
* verbatim across locales per the Figma design.
*/
import type { LocaleDict } from '@deepseek-ai/dsh-client-locale/client'
const SHARED = {
'permission.value': 'Read only',
'toolcall.schema.title': 'Schema mode',
'toolcall.schema.desc': 'Traditional function calling — invoke tools one at a time',
'toolcall.code.title': 'Code mode',
'toolcall.code.desc': 'Chain multiple tools with code — multi-step orchestration',
} satisfies LocaleDict
/** Simplified Chinese dictionary. */
export const zh: LocaleDict = {
...SHARED,
'nav': '通用设置',
'permission.title': '权限',
'permission.desc': '选择默认权限模式',
'toolcall.title': '工具调用',
'language.title': '语言',
'appearance.title': '外观',
'appearance.light': '浅色',
'appearance.dark': '深色',
'appearance.system': '跟随系统',
}
/** English dictionary. */
export const en: LocaleDict = {
...SHARED,
'nav': 'General',
'permission.title': 'Permission',
'permission.desc': 'Choose default permission mode',
'toolcall.title': 'Tool Call',
'language.title': 'Language',
'appearance.title': 'Appearance',
'appearance.light': 'Light',
'appearance.dark': 'Dark',
'appearance.system': 'System',
}

View File

@@ -1,43 +0,0 @@
/**
* General section slot store: locale/theme snapshot mirrors. The plugin
* creates the handle at apply time (identity follows the fiber) and its
* change listeners are the only writers; components read via props.useStore.
*/
import { defineStore, type EngineStoreHandle } from '@deepseek-ai/dsh-client-runtime/client'
import type { GeneralSettingsState, LocaleOptionRow, ThemePreferenceId } from './contract.ts'
/** Declared action shape used to give the exported factory a stable return type. */
type GeneralSettingsActions = {
syncLocale: (draft: GeneralSettingsState, active: string, options: LocaleOptionRow[], revision: number) => void
syncTheme: (draft: GeneralSettingsState, preference: ThemePreferenceId, revision: number) => void
}
/**
* Declares the General section state and write surface. Revisions start at -1
* so the apply-time initial sync (revision 0) always lands as a change.
* @returns the store handle.
*/
export function createGeneralSettingsStore(): EngineStoreHandle<GeneralSettingsState, GeneralSettingsActions> {
return defineStore({
init: (): GeneralSettingsState => ({
localeActive: '',
localeOptions: [],
localeRevision: -1,
themePreference: 'system',
themeRevision: -1,
}),
actions: {
syncLocale: (d, active: string, options: LocaleOptionRow[], revision: number) => {
if (revision <= d.localeRevision) return
d.localeActive = active
d.localeOptions = options
d.localeRevision = revision
},
syncTheme: (d, preference: ThemePreferenceId, revision: number) => {
if (revision <= d.themeRevision) return
d.themePreference = preference
d.themeRevision = revision
},
},
})
}

View File

@@ -1,6 +0,0 @@
declare module '*.module.css' {
const classes: Record<string, string>
export default classes
}
declare module '*.css'

View File

@@ -1,4 +0,0 @@
/** Host loader entry for the browser implementation exported from `./client`. */
/** Host plugin body — no host-side behavior for the general settings plugin. */
export function apply(): void {}

View File

@@ -1,32 +0,0 @@
/**
* Package-owned invariant companion for `@deepseek-ai/dsh-client-ui-settings-general`.
* @module @deepseek-ai/dsh-client-ui-settings-general/invariant
*/
/* jscpd:ignore-start */
import type { Context } from 'cordis'
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
const PACKAGE_NAME = '@deepseek-ai/dsh-client-ui-settings-general'
/** Cordis companion plugin name. */
export const name = 'client-ui-settings-general-invariant'
/** Service required before the companion can reserve package ownership. */
export const inject = ['invariants']
/**
* No runtime invariant: a section plugin projecting two service change events
* into its own slot store — it emits no cordis events of its own and owns no
* cross-plugin mutable relation; snapshot/store agreement is asserted by this
* package's behavior specs.
*/
const install: InvariantInstaller = () => {}
/**
* Register this package's invariant companion.
* @param ctx - Cordis context carrying the invariant service.
* @returns the installed registration's disposer after setup succeeds.
*/
export const apply = (ctx: Context): Promise<() => void> =>
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
/* jscpd:ignore-end */