Skip to content

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

refactor(ui): migrate to the rebuilt core protocols

hairyf8920ff04de4d
diff --git a/packages/dsh-tauri-ui/src/client/components/index.ts b/packages/dsh-tauri-ui/src/client/components/index.ts
index 672efca2..498f54d0 100644
--- a/packages/dsh-tauri-ui/src/client/components/index.ts
+++ b/packages/dsh-tauri-ui/src/client/components/index.ts
@@ -1,30 +1,5 @@
-export { Icon } from './icon'
-export type { IconComponent, IconProps, SharedIconProps } from './icon'
-export {
- ArrowDownToLine,
- ArrowRight,
- ArrowRotateRight,
- ArrowUpRight,
- ArrowUturnCcwLeft,
- Calendar,
- ChevronDown,
- ChevronUp,
- CirclePause,
- CirclePlay,
- CircleTree,
- Clock,
- CommentPlus,
- Ellipsis,
- EllipsisVertical,
- FilePlus,
- FolderOpen,
- GraduationCap,
- LogoGithub,
- Magnifier,
- PlugConnection,
- Plus,
- Puzzle,
- TrashBin,
-} from './icons'
-export { MenuSelect } from './menu-select'
+export * from './icon'
+export type * from './icon'
+export * from './icons'
+export * from './menu-select'
export { circleTreeSvg, clockSvg, FishMark, IconPlaceholder, PanelLeftOutline } from './special-icons'
diff --git a/packages/dsh-tauri-ui/src/client/components/sidebar.tsx b/packages/dsh-tauri-ui/src/client/components/sidebar.tsx
index 571c2f52..2b828161 100644
--- a/packages/dsh-tauri-ui/src/client/components/sidebar.tsx
+++ b/packages/dsh-tauri-ui/src/client/components/sidebar.tsx
@@ -28,6 +28,7 @@ import { SlotOutlet } from '@deepseek-ai/dsh-client-ui-renderer'
* 职责边界:拖拽交互 → hooks/use-rail-drag.ts;下层/外部表面隐藏 →
* dom/settings-obstructions.ts;本文件只保留组件状态 + JSX + 打开期副作用。
*/
+import { useEventListener } from 'dsh-tauri/client'
import { useEffect, useRef } from 'react'
import {
SETTINGS_SECTION_SLOT,
@@ -43,7 +44,7 @@ import {
RAIL_WIDTH_DEFAULT,
selectSection,
setRailWidth,
- settingsStore,
+ store,
useSettingsUi,
} from '../store'
import { useMountStyle } from '../utils/style'
@@ -64,18 +65,15 @@ export function SettingsSidebar(_props: SettingsSidebarProps): ReactElement | nu
useMountStyle(settingsSidebarStyle, SETTINGS_STYLE_ID)
const searchRef = useRef<HTMLInputElement>(null)
const { dragging, onHandlePointerDown } = useRailDrag()
+ const documentRef = useRef<Document | null | undefined>(
+ typeof document === 'undefined' ? undefined : document,
+ )
- // Esc 关闭(仅打开期间挂载监听,与官方 SettingsPanel 同生命周期)。
- useEffect(() => {
- if (!ui.open)
- return
- const onKeyDown = (event: KeyboardEvent): void => {
- if (event.key === 'Escape')
- closeSettings()
- }
- document.addEventListener('keydown', onKeyDown)
- return () => document.removeEventListener('keydown', onKeyDown)
- }, [ui.open])
+ // Esc 关闭:文档级 keydown 由 reause 托管(卸载自动移除;仅打开期间生效)。
+ useEventListener(documentRef, 'keydown', (event: KeyboardEvent) => {
+ if (ui.open && event.key === 'Escape')
+ closeSettings()
+ })
// 打开时聚焦搜索框;并按官方 sidebar 槽的实际渲染宽度同步左栏宽度(item 3)。
useEffect(() => {
@@ -133,7 +131,7 @@ export function SettingsSidebar(_props: SettingsSidebarProps): ReactElement | nu
placeholder={settingsText('search')}
aria-label={settingsText('search')}
onChange={event =>
- settingsStore.set(state => ({ ...state, query: event.target.value }))}
+ store.settings.setQuery(event.target.value)}
/>
<nav className="dshp-settings-sidebar__nav" aria-label={settingsText('settings')}>
{visible.map(row => (
diff --git a/packages/dsh-tauri-ui/src/client/hooks/sections.ts b/packages/dsh-tauri-ui/src/client/hooks/sections.ts
index 6b69efdc..2963fab7 100644
--- a/packages/dsh-tauri-ui/src/client/hooks/sections.ts
+++ b/packages/dsh-tauri-ui/src/client/hooks/sections.ts
@@ -1,8 +1,10 @@
import type { SettingsRow } from '../types'
-import { useMemo, useSyncExternalStore } from 'react'
+import { useStore } from 'dsh-tauri/client'
+import { useMemo } from 'react'
import { SETTINGS_ONBOARDING_SLOT, SETTINGS_SECTION_SLOT } from '../constants'
import { useSettingsLocale } from '../locales'
import { getSettingsSlots } from '../register/sections'
+import { store } from '../store'
export type { SettingsRow } from '../types'
/**
@@ -10,8 +12,11 @@ export type { SettingsRow } from '../types'
*
* 官方 SettingsRoot 用 inject hooks(sections / onboardingSteps)把
* 'settings.section' / 'settings.onboarding' 两个 list 槽的注册条目投影为
- * 导航行。这里做同样的事,但更贴近 renderer 自身的 uSES 习惯:订阅槽位
- * 版本 + locale 变更,重算 `entries(key) -> {id, order, label}` 排序行。
+ * 导航行。这里做同样的事:订阅槽位 revision + locale 变更,重算
+ * `entries(key) -> {id, order, label}` 排序行。
+ *
+ * 槽位变更不经自建订阅器:注册中心的注册/声明通知由 register/sections.ts 在
+ * apply 期订阅并推进 store.slots 的 revision,本文件经 useStore 按 key 订阅。
*
* label 与官方一致经 resolveSlotLabel 语义解析(函数型 label 即按当前
* locale 求值,所以 locale 变更也要触发重算)。
@@ -45,21 +50,16 @@ function projectRows(slotKey: string): SettingsRow[] {
}
/**
- * 订阅一个 list 槽的注册/声明变更(uSES:getVersion 做快照,变更在
- * microtask 批量通知后重渲染)。
+ * 订阅一个 list 槽的注册/声明变更。
+ *
+ * revision 由 register/sections.ts 的 apply 期订阅推进(见 store/modules/slots.ts),
+ * 这里只经 useStore 读取并按 key 精确重渲染。
* @param slotKey - 槽 key。
- * @returns 当前版本号。
+ * @returns 当前 revision。
*/
function useSlotVersion(slotKey: string): number {
- const slots = getSettingsSlots()
- return useSyncExternalStore(
- (onChange) => {
- if (!slots)
- return () => {}
- return slots.subscribe(slotKey as never, onChange)
- },
- () => (slots ? slots.getVersion(slotKey as never) : 0),
- )
+ const { revisions } = useStore(store.slots)
+ return revisions[slotKey] ?? 0
}
/** 设置分区导航行('settings.section' 投影;订阅槽位与 locale 变更)。 */
diff --git a/packages/dsh-tauri-ui/src/client/index.ts b/packages/dsh-tauri-ui/src/client/index.ts
index 10b5a0f6..0629d831 100644
--- a/packages/dsh-tauri-ui/src/client/index.ts
+++ b/packages/dsh-tauri-ui/src/client/index.ts
@@ -18,26 +18,21 @@ import type {} from '@deepseek-ai/dsh-client-ui-layout/client'
* 渲染官方各分区(SlotOutlet 由 renderer 的一行导出补丁提供)。
* (槽位注册在 register/sidebar.ts;拖拽交互在 hooks/use-rail-drag.ts;
* 下层/外部表面隐藏补丁在 dom/settings-obstructions.ts)
- * - store/ 触发器与侧边栏共享 {open, activeId, query}。
+ * - store/ 触发器与侧边栏共享 {open, activeId, query}(valtio-define 域存储)。
* - hooks/sections.ts + register/sections.ts 'settings.section' /
- * 'settings.onboarding' 注册条目的导航行投影(hooks 订阅槽位与 locale
- * 变更;installer 持有 slotsRef)。
+ * 'settings.onboarding' 注册条目的导航行投影(installer 持有 slotsRef
+ * 并订阅槽位变更,hooks 读 store.slots 的 revision)。
* - locales/ 本插件文案(返回应用/搜索设置…)双语注册。
*
* 保留了骨架期的 `shell.overlay` 条目(id dsh-tauri-ui)作为未来 chrome
- * 的落点,与设置侧边栏(id dsh-tauri-ui-settings)并行不冲突。
+ * 的落点,与设置侧边栏(id dsh-tauri-ui-settings)并行不冲突;注册一律走
+ * register/ 下的 `defineRegister` feature,由 controller 托管卸载清理。
*/
import type { ClientContext } from 'dsh-tauri/client'
import { SlotOutlet } from '@deepseek-ai/dsh-client-ui-renderer'
-import { TauriUiSeat } from './components/seat'
-import {
- SETTINGS_REGISTRANT,
- SETTINGS_SHELL_OVERLAY_SLOT,
- SETTINGS_SHELL_SEAT_ID,
- SETTINGS_UI_PLUGIN,
- TURN_NAVIGATION_STYLE_ID,
-} from './constants'
+import { SETTINGS_UI_PLUGIN, TURN_NAVIGATION_STYLE_ID } from './constants'
import { registerSettingsLocale } from './locales'
+import { registerShellSeat } from './register/seat'
import { registerSettingsSections } from './register/sections'
import { registerSettingsSidebar } from './register/sidebar'
import { registerSettingsTrigger } from './register/trigger'
@@ -67,19 +62,8 @@ export function apply(ctx: ClientContext): void {
// alpha 的 slot 必须先由父条目的 children 表声明才能注册进入;shell.overlay
// 由 ui-layout 的 AppFrame 声明,故通过 inject 等其声明(live)后再注册,
// 避免 `slot "shell.overlay" is not declared` 运行时报错。
- ctx.effect(
- () =>
- ctx.slots.inject(SETTINGS_SHELL_OVERLAY_SLOT, () =>
- ctx.slots.register(
- {
- name: SETTINGS_SHELL_OVERLAY_SLOT,
- id: SETTINGS_SHELL_SEAT_ID,
- registrant: SETTINGS_REGISTRANT,
- },
- TauriUiSeat,
- )),
- 'dsh-tauri-ui: shell.overlay seat',
- )
+ // (注册体在 register/seat.ts;controller 负责卸载时撤销 inject。)
+ ctx.effect(registerShellSeat, 'dsh-tauri-ui: shell.overlay seat')
// 第一项功能:设置弹窗 → 侧边栏。
// 侧边栏依赖 renderer 补丁导出的 <SlotOutlet>(任意槽渲染的入口)。核心未带
@@ -98,14 +82,14 @@ export function apply(ctx: ClientContext): void {
'dsh-tauri-ui: global styles',
)
registerSettingsLocale(ctx)
- // 设置分区投影:引用清理也走 effect(插件卸载后 slotsRef 复位,避免跨实例残留)。
+ // 设置分区投影:槽位订阅与引用清理也走 effect(插件卸载后订阅取消、slotsRef 复位)。
ctx.effect(
() => registerSettingsSections(ctx.slots as never),
'dsh-tauri-ui: settings sections projection',
)
if (typeof SlotOutlet === 'function') {
- registerSettingsSidebar(ctx)
- registerSettingsTrigger(ctx)
+ ctx.effect(registerSettingsSidebar, 'dsh-tauri-ui: settings sidebar')
+ ctx.effect(registerSettingsTrigger, 'dsh-tauri-ui: settings trigger')
}
else {
console.warn(
diff --git a/packages/dsh-tauri-ui/src/client/locales/index.ts b/packages/dsh-tauri-ui/src/client/locales/index.ts
index 368a9e3a..b949c1e2 100644
--- a/packages/dsh-tauri-ui/src/client/locales/index.ts
+++ b/packages/dsh-tauri-ui/src/client/locales/index.ts
@@ -6,25 +6,23 @@
* 且无需增广 LocaleNamespaceMap(避免外部类型依赖)。
*
* 组件侧不引入框架的 `t` 座(那需要 register option locale + 增广),
- * 改用一个极薄的 uSES 桥:apply 时订阅 locale 变更并推进 rev ->
- * 组件订阅 rev 重渲染,文案按当前 active locale 从本地字典读取。
+ * 改用 store.locale 的 revision:apply 时订阅 locale 变更并 bump ->
+ * 组件经 useStore(store.locale) 订阅 rev 重渲染,文案按当前 active locale
+ * 从本地字典读取。
*/
import type { ClientContext } from 'dsh-tauri/client'
import type { SettingsUiKey } from '../types'
-import { createExternalStore } from 'dsh-tauri/client'
-import { useSyncExternalStore } from 'react'
+import { useStore } from 'dsh-tauri/client'
import { DICT_EN, DICT_ZH, SETTINGS_UI_NS } from '../constants'
+import { store } from '../store'
export type { SettingsUiKey } from '../types'
/** 活跃语言 id(module 级缓存,apply 时初始化并由订阅推进)。 */
let activeLocale = 'en'
-/** locale 变更推进器:revision 前进 -> uSES 订阅方重渲染。 */
-export const settingsLocaleRev = createExternalStore({ rev: 0 })
-
/**
- * 在 apply 里安装:注册本插件的双语字典,并桥接 locale 变更到 rev。
+ * 在 apply 里安装:注册本插件的双语字典,并桥接 locale 变更到 store.locale。
* @param ctx - 客户端根上下文(须已注入 locale 服务)。
*/
export function registerSettingsLocale(ctx: ClientContext): void {
@@ -33,7 +31,7 @@ export function registerSettingsLocale(ctx: ClientContext): void {
ctx.locale.register(SETTINGS_UI_NS, 'en', DICT_EN)
ctx.locale.subscribe(() => {
activeLocale = ctx.locale.getLocale().active
- settingsLocaleRev.set(s => ({ ...s, rev: s.rev + 1 }))
+ store.locale.bump()
})
}
@@ -43,6 +41,7 @@ export function settingsText(key: SettingsUiKey): string {
}
/** 组件内订阅 locale 变更(revision 前进即重渲染)。 */
-export function useSettingsLocale(): void {
- useSyncExternalStore(settingsLocaleRev.subscribe, () => settingsLocaleRev.getSnapshot().rev)
+export function useSettingsLocale(): number {
+ const { rev } = useStore(store.locale)
+ return rev
}
diff --git a/packages/dsh-tauri-ui/src/client/register/seat.ts b/packages/dsh-tauri-ui/src/client/register/seat.ts
new file mode 100644
index 00000000..2fa64a62
--- /dev/null
+++ b/packages/dsh-tauri-ui/src/client/register/seat.ts
@@ -0,0 +1,29 @@
+import type { ClientContext } from 'dsh-tauri/client'
+import { defineRegister } from 'dsh-tauri/client'
+import { TauriUiSeat } from '../components/seat'
+import {
+ SETTINGS_REGISTRANT,
+ SETTINGS_SHELL_OVERLAY_SLOT,
+ SETTINGS_SHELL_SEAT_ID,
+} from '../constants'
+
+/**
+ * register/seat.ts — shell.overlay 落点座位注册(骨架占位,defineRegister)。
+ *
+ * 骨架期落点:未来桌面 chrome(顶部导航/窗口控件等)在此渲染。shell.overlay
+ * 由 ui-layout 的 AppFrame 声明,故通过 inject 等其声明(live)后再注册;
+ * 注册句柄交给 controller,插件卸载时随 effect 一并撤销。
+ */
+export const registerShellSeat = defineRegister<ClientContext>((controller, ctx) => {
+ controller.add(
+ ctx.slots.inject(SETTINGS_SHELL_OVERLAY_SLOT, () =>
+ ctx.slots.register(
+ {
+ name: SETTINGS_SHELL_OVERLAY_SLOT,
+ id: SETTINGS_SHELL_SEAT_ID,
+ registrant: SETTINGS_REGISTRANT,
+ },
+ TauriUiSeat,
+ )),
+ )
+})
diff --git a/packages/dsh-tauri-ui/src/client/register/sections.ts b/packages/dsh-tauri-ui/src/client/register/sections.ts
index 034903bb..2aedcb21 100644
--- a/packages/dsh-tauri-ui/src/client/register/sections.ts
+++ b/packages/dsh-tauri-ui/src/client/register/sections.ts
@@ -1,27 +1,37 @@
import type { SlotRegistry } from '@deepseek-ai/dsh-client-ui-renderer/client'
+import { SETTINGS_ONBOARDING_SLOT, SETTINGS_SECTION_SLOT } from '../constants'
+import { store } from '../store'
/**
* register/sections.ts — 'settings.section' / 'settings.onboarding' 投影的
* 安装器半区:持有槽注册中心的模块引用(slotsRef),供 hooks/sections.ts
- * 的只读投影 hooks 在 render 期经 getSettingsSlots() 订阅。
+ * 的只读投影 hooks 在 render 期经 getSettingsSlots() 读取。
*
- * 引用所有权与卸载清理只存在本文件:registerSettingsSections 在 apply 时把
- * ctx.slots 写入,返回的卸载函数在插件卸载后清除模块引用,避免跨实例残留。
+ * 引用所有权、变更订阅与卸载清理只存在本文件:registerSettingsSections 在
+ * apply 时把 ctx.slots 写入并订阅两个 list 槽(变更即推进 store.slots 对应
+ * revision),返回的卸载函数在插件卸载后取消订阅并清除模块引用,避免跨实例残留。
*/
-/** apply 时存入的槽注册中心(hooks/sections.ts 在 render 期经它订阅/投影)。 */
+/** apply 时存入的槽注册中心(hooks/sections.ts 在 render 期经它投影)。 */
type SettingsSlots = SlotRegistry
+/** 被投影的槽位 key(与 hooks/sections.ts 的两个投影一一对应)。 */
+const PROJECTED_SLOT_KEYS = [SETTINGS_SECTION_SLOT, SETTINGS_ONBOARDING_SLOT] as const
+
let slotsRef: SettingsSlots | undefined
/**
- * 在 apply 里安装:把 ctx.slots 引用留给投影 hooks,返回卸载清理。
- * @param slots - 客户端 slota 注册中心(ctx.slots)。
- * @returns 卸载函数(插件卸载后清除模块引用,避免跨实例残留)。
+ * 在 apply 里安装:把 ctx.slots 引用留给投影 hooks,并订阅槽位变更推进 store。
+ * @param slots - 客户端 slots 注册中心(ctx.slots)。
+ * @returns 卸载函数(取消订阅并清除模块引用,避免跨实例残留)。
*/
export function registerSettingsSections(slots: SettingsSlots): () => void {
slotsRef = slots
+ const unsubscribes = PROJECTED_SLOT_KEYS.map(key =>
+ slots.subscribe(key as never, () => store.slots.bump(key)))
return () => {
+ for (const unsubscribe of unsubscribes)
+ unsubscribe()
if (slotsRef === slots)
slotsRef = undefined
}
diff --git a/packages/dsh-tauri-ui/src/client/register/sidebar.ts b/packages/dsh-tauri-ui/src/client/register/sidebar.ts
index 94308f97..5eabeb6f 100644
--- a/packages/dsh-tauri-ui/src/client/register/sidebar.ts
+++ b/packages/dsh-tauri-ui/src/client/register/sidebar.ts
@@ -1,4 +1,5 @@
import type { ClientContext } from 'dsh-tauri/client'
+import { defineRegister } from 'dsh-tauri/client'
import { SettingsSidebar } from '../components/sidebar'
import {
SETTINGS_REGISTRANT,
@@ -7,20 +8,18 @@ import {
} from '../constants'
/**
- * register/sidebar.ts — shell.overlay 设置侧边栏条目注册。
+ * register/sidebar.ts — shell.overlay 设置侧边栏条目注册(defineRegister)。
*
* shell.overlay 由 ui-layout 的 AppFrame 声明;alpha 要求注册进入前该槽已
- * 由父条目 children 表声明,故用 inject 等其声明 live 后再注册。
- * @param ctx - 客户端根上下文。
+ * 由父条目 children 表声明,故用 inject 等其声明 live 后再注册。inject 的
+ * 撤销句柄交给 controller:插件卸载时随 effect 一并撤销(与旧 ctx.effect 同语义)。
*/
-export function registerSettingsSidebar(ctx: ClientContext): void {
- ctx.effect(
- () =>
- ctx.slots.inject(SETTINGS_SHELL_OVERLAY_SLOT, () =>
- ctx.slots.register(
- { name: SETTINGS_SHELL_OVERLAY_SLOT, id: SETTINGS_SIDEBAR_ID, registrant: SETTINGS_REGISTRANT, inject: () => ({}) } as never,
- SettingsSidebar as never,
- )),
- 'dsh-tauri-ui: settings sidebar',
+export const registerSettingsSidebar = defineRegister<ClientContext>((controller, ctx) => {
+ controller.add(
+ ctx.slots.inject(SETTINGS_SHELL_OVERLAY_SLOT, () =>
+ ctx.slots.register(
+ { name: SETTINGS_SHELL_OVERLAY_SLOT, id: SETTINGS_SIDEBAR_ID, registrant: SETTINGS_REGISTRANT, inject: () => ({}) } as never,
+ SettingsSidebar as never,
+ )),
)
-}
+})
diff --git a/packages/dsh-tauri-ui/src/client/register/trigger.ts b/packages/dsh-tauri-ui/src/client/register/trigger.ts
index ad8199f2..33b57cfb 100644
--- a/packages/dsh-tauri-ui/src/client/register/trigger.ts
+++ b/packages/dsh-tauri-ui/src/client/register/trigger.ts
@@ -1,4 +1,5 @@
import type { ClientContext } from 'dsh-tauri/client'
+import { defineRegister } from 'dsh-tauri/client'
import { SettingsTrigger } from '../components/trigger'
import {
SETTINGS_REGISTRANT,
@@ -12,12 +13,14 @@ import {
* 'sidebar.settings' 不属于本插件类型图的 SlotMap 键(声明权在 ui-sidebar,
* 类型未提升到根 node_modules),此处对 options 显式 cast 以通过 K 收窄;
* 组件 props 仍由本地 SettingsTriggerProps 提供类型保证。
- * @param ctx - 客户端根上下文。
+ * inject 的撤销句柄交给 controller:插件卸载时随 effect 一并撤销。
*/
-export function registerSettingsTrigger(ctx: ClientContext): void {
- ctx.slots.inject(SETTINGS_SIDEBAR_SLOT as never, () =>
- ctx.slots.register(
- { name: SETTINGS_SIDEBAR_SLOT, priority: SETTINGS_TRIGGER_PRIORITY, registrant: SETTINGS_REGISTRANT } as never,
- SettingsTrigger,
- ))
-}
+export const registerSettingsTrigger = defineRegister<ClientContext>((controller, ctx) => {
+ controller.add(
+ ctx.slots.inject(SETTINGS_SIDEBAR_SLOT as never, () =>
+ ctx.slots.register(
+ { name: SETTINGS_SIDEBAR_SLOT, priority: SETTINGS_TRIGGER_PRIORITY, registrant: SETTINGS_REGISTRANT } as never,
+ SettingsTrigger,
+ )),
+ )
+})
diff --git a/packages/dsh-tauri-ui/src/client/store/index.ts b/packages/dsh-tauri-ui/src/client/store/index.ts
index 0c527b0f..5911d717 100644
--- a/packages/dsh-tauri-ui/src/client/store/index.ts
+++ b/packages/dsh-tauri-ui/src/client/store/index.ts
@@ -1,71 +1,59 @@
import type { SettingsUiState } from '../types'
-import { createExternalStore } from 'dsh-tauri/client'
-import { useSyncExternalStore } from 'react'
+import { useStore } from 'dsh-tauri/client'
import { RAIL_WIDTH_MAX, RAIL_WIDTH_MIN } from '../constants'
+import { locale } from './modules/locale'
+import { settings } from './modules/settings'
+import { slots } from './modules/slots'
export { RAIL_WIDTH_DEFAULT } from '../constants'
export type { SettingsUiState } from '../types'
/**
- * store.ts — dsh-tauri-ui 设置侧边栏的共享 UI 状态。
+ * store/index.ts — dsh-tauri-ui 客户端共享状态的统一出口(valtio-define 域存储聚合)。
*
- * 触发器(sidebar.settings 槽内)与侧边栏(shell.overlay 槽内)是同一插件
- * 的两个独立注册条目,凭一个模块级 SnapshotStore 共享开关/当前分区/搜索词:
- * - 触发器把 open 置 true(并可选跳到某分区);
- * - 侧边栏订阅 open/activeId/query 渲染,Esc 或“返回应用”置 false。
- *
- * createExternalStore 是框架无关的 uSES 安全状态源
- * (getSnapshot 在变更间返回同一引用;set 返回不可变新状态)。
+ * 每个域一份 `modules/<domain>.ts`(state 只放数据、写入走 actions),本文件只做
+ * 聚合与旧调用点兼容:触发器/侧边栏/拖拽 hooks 继续用下面这些薄包装函数名,
+ * 组件内订阅统一走 `useStore(store.<domain>)`。
*/
+export const store = {
+ locale,
+ settings,
+ slots,
+}
+
/**
- * 左栏宽度合约,与官方 sidebar 面板一致:
- * defineStore init sidebar:280,setSidebar clamp clampWidth(px, 264, 420),关闭即忘
- * (官方“closing a panel forgets its drag width”——不持久化,重开回默认)。
+ * 钳制到左栏合约区间(镜像官方 clampWidth 语义)。
*/
-/** 钳制到左栏合约区间(镜像官方 clampWidth 语义)。 */
export function clampRailWidth(px: number): number {
return Math.min(RAIL_WIDTH_MAX, Math.max(RAIL_WIDTH_MIN, px))
}
-/** 全局唯一共享状态源(模块级单例;插件重载时随 bundle 重建,可接受)。 */
-export const settingsStore = createExternalStore<SettingsUiState>({
- open: false,
- activeId: undefined,
- query: '',
- railWidth: undefined,
-})
-
/** 打开侧边栏;可选直接跳到一个设置分区(onboarding 的 openSection 用)。 */
export function openSettings(sectionId?: string): void {
- settingsStore.set(s => ({
- ...s,
- open: true,
- ...(sectionId !== undefined ? { activeId: sectionId } : {}),
- }))
+ store.settings.openAt(sectionId)
}
/** 关闭侧边栏并复位视图状态(与官方 close 的复位语义一致;宽度也即忘)。 */
export function closeSettings(): void {
- settingsStore.set(s => ({
- ...s,
- open: false,
- activeId: undefined,
- query: '',
- railWidth: undefined,
- }))
+ store.settings.close()
}
/** 切换左栏当前分区。 */
export function selectSection(id: string): void {
- settingsStore.set(s => ({ ...s, activeId: id }))
+ store.settings.select(id)
}
/** 拖拽中实时写入左栏宽度(调用方已按合约钳制)。 */
export function setRailWidth(px: number): void {
- settingsStore.set(s => ({ ...s, railWidth: px }))
+ store.settings.setRailWidth(px)
}
-/** 组件内读取 UI 状态(uSES;state 引用在 update 之间稳定)。 */
+/**
+ * 组件内订阅共享 UI 状态。
+ *
+ * `sync: true`:搜索框是受控输入,valtio 默认的批量通知可能丢光标位置——
+ * 这里保持旧 uSES 的同步语义。
+ */
export function useSettingsUi(): SettingsUiState {
- return useSyncExternalStore(settingsStore.subscribe, settingsStore.getSnapshot)
+ return useStore(store.settings, { sync: true })
}
diff --git a/packages/dsh-tauri-ui/src/client/store/modules/locale.ts b/packages/dsh-tauri-ui/src/client/store/modules/locale.ts
new file mode 100644
index 00000000..9d7d1b04
--- /dev/null
+++ b/packages/dsh-tauri-ui/src/client/store/modules/locale.ts
@@ -0,0 +1,18 @@
+import { defineStore } from 'dsh-tauri/client'
+
+/**
+ * store/modules/locale.ts — 活跃语言变更的 revision 推进器(valtio-define 域存储)。
+ *
+ * locale 服务是外部事件源:apply 时(registerSettingsLocale)订阅它,变更到达即
+ * bump();组件经 useStore(store.locale) 订阅 rev,前进即重渲染并按当前 locale
+ * 重读本地字典。这样组件侧不需要自造 uSES 订阅器。
+ */
+export const locale = defineStore({
+ state: () => ({ rev: 0 }),
+ actions: {
+ /** 推进 revision(订阅方随之重渲染)。 */
+ bump() {
+ this.rev++
+ },
+ },
+})
diff --git a/packages/dsh-tauri-ui/src/client/store/modules/settings.ts b/packages/dsh-tauri-ui/src/client/store/modules/settings.ts
new file mode 100644
index 00000000..4fed3610
--- /dev/null
+++ b/packages/dsh-tauri-ui/src/client/store/modules/settings.ts
@@ -0,0 +1,51 @@
+import type { SettingsUiState } from '../../types'
+import { defineStore } from 'dsh-tauri/client'
+
+/**
+ * store/modules/settings.ts — 设置侧边栏的共享 UI 状态(valtio-define 域存储)。
+ *
+ * 触发器(sidebar.settings 槽内)与侧边栏(shell.overlay 槽内)是同一插件
+ * 的两个独立注册条目,凭一个模块级 store 共享开关/当前分区/搜索词:
+ * - 触发器把 open 置 true(并可选跳到某分区);
+ * - 侧边栏订阅 open/activeId/query 渲染,Esc 或“返回应用”置 false。
+ *
+ * state 只放数据,写入一律走 actions(`this` 即 state 代理)。
+ * 左栏宽度合约与官方 sidebar 面板一致:
+ * defineStore init sidebar:280,setSidebar clamp clampWidth(px, 264, 420),关闭即忘
+ * (官方“closing a panel forgets its drag width”——不持久化,重开回默认)。
+ */
+export const settings = defineStore({
+ state: (): SettingsUiState => ({
+ open: false,
+ activeId: undefined,
+ query: '',
+ railWidth: undefined,
+ }),
+ actions: {
+ /** 打开侧边栏;可选直接跳到一个设置分区(onboarding 的 openSection 用)。 */
+ openAt(sectionId?: string) {
+ this.open = true
+ if (sectionId !== undefined)
+ this.activeId = sectionId
+ },
+ /** 关闭侧边栏并复位视图状态(与官方 close 的复位语义一致;宽度也即忘)。 */
+ close() {
+ this.open = false
+ this.activeId = undefined
+ this.query = ''
+ this.railWidth = undefined
+ },
+ /** 切换左栏当前分区。 */
+ select(id: string) {
+ this.activeId = id
+ },
+ /** 写入搜索词(侧边栏搜索框的受控值)。 */
+ setQuery(query: string) {
+ this.query = query
+ },
+ /** 拖拽中实时写入左栏宽度(调用方已按合约钳制)。 */
+ setRailWidth(px: number) {
+ this.railWidth = px
+ },
+ },
+})
diff --git a/packages/dsh-tauri-ui/src/client/store/modules/slots.ts b/packages/dsh-tauri-ui/src/client/store/modules/slots.ts
new file mode 100644
index 00000000..4b67d9e2
--- /dev/null
+++ b/packages/dsh-tauri-ui/src/client/store/modules/slots.ts
@@ -0,0 +1,25 @@
+import { defineStore } from 'dsh-tauri/client'
+import { SETTINGS_ONBOARDING_SLOT, SETTINGS_SECTION_SLOT } from '../../constants'
+
+/**
+ * store/modules/slots.ts — 官方槽位注册中心投影的 revision 镜像。
+ *
+ * 'settings.section' / 'settings.onboarding' 的注册/注销由官方 slots 注册中心
+ * 通知(register/sections.ts 在 apply 期订阅,注册中心引用的所有权与清理都留在
+ * 那里);本 store 按槽 key 记 revision,投影 hooks 经 useStore 读取对应 key,
+ * 变更即重算导航行。两个被投影的 key 预置为 0,读取路径不存在“缺失键”分支。
+ */
+export const slots = defineStore({
+ state: (): { revisions: Record<string, number> } => ({
+ revisions: {
+ [SETTINGS_SECTION_SLOT]: 0,
+ [SETTINGS_ONBOARDING_SLOT]: 0,
+ },
+ }),
+ actions: {
+ /** 推进某个槽 key 的 revision(注册/声明变更通知到达时调用)。 */
+ bump(key: string) {
+ this.revisions[key] = (this.revisions[key] ?? 0) + 1
+ },
+ },
+})