# dsh-settings-ui kit — 使用与开发手册(v0.3.0) > 面向「用 kit 给 DSH Web/桌面端开发 UI」的完整手册。API 以本仓库 `lib/client.js` 为准;本文与代码不一致时以代码为准,并请更新本文。 ## 0. 安装(官方 npm) 对外用户安装 kit(一步完成「加依赖 + reconcile 追加进 `dsh.profile.bundles`」): ```sh dsh plugin --profile add dsh-settings-ui ``` npm latest 目前 **0.2.22**;0.4.0 发布后同命令升级(`add dsh-settings-ui@latest`)。本机开发/打包工作流见 `HANDOFF.md` §5/§6。 ## 1. 定位与架构 - kit 是**纯客户端 Cordis 服务**:对外暴露 `ctx.settingsUi`(消费方 `inject: ['slots', 'settingsUi']`);kit 自身注入面 `inject: ['slots', 'locale']`(`locale` = 官方 locale 插件服务,统计卡字典注册用;官方壳必带,缺席环境 kit 不激活)。 - 一句话:**一套 `--dsw-*` token 统一样式 + 原子组件 + 设置状态机 + 两类注册入口(设置页卡片 / 自由浮层窗口)**,插件不再手写 CSS 与加载/保存状态。 - 结构:`lib/index.js`(host 空壳)+ `lib/client.js`(全部能力,`window.__ModuleLoader__.load` CJS 工厂,无构建步骤,改完 `node --check`);TypeScript 消费方用 `lib/client.d.ts`(export `./client` types 条件)。 - 单测:`node --test test/`(沙箱内用 `node test/kit.test.mjs`,见 HANDOFF §6);45 项。 - 版本:`package.json.version` 与 `lib/client.js` 内 `KIT_VERSION` 常量**必须同步**;统计卡显示该版本号供核对。 - 样式注入:`ensureStyle()` 幂等注入一次(id **带版本号** `dsh-settings-ui-style-v`,0.2.18 起——旧版 kit 副本先注入的样式不会阻塞新版),全部类名 `sui-` 前缀,不污染其它插件。 ## 2. 快速上手 ```js window.__ModuleLoader__.load({ id: 'my-plugin', factory: (require) => { const React = require('react') const plugin = { name: 'my-plugin', inject: ['slots', 'settingsUi'], apply(ctx) { const ui = ctx.settingsUi const store = ui.createSettingsStore({ get: () => call('get'), update: (p) => call('update', p) }) ui.section({ id: 'my-plugin', order: 300, label: () => '我的设置', inject: () => ({ ui, store }), render: MySection, }) }, } return plugin }, }) ``` ## 3. API 参考 ### 3.1 原子组件(全部挂在 `ui.*`,样式共享注入一次) | 组件 | 用途 | props | |---|---|---| | `ui.h` | `React.createElement` 别名 | `(type, props, ...children)` | | `ui.SectionHeader` | 标题 + 描述 | `{ title, desc? }` | | `ui.Field` | 标签+控件+提示竖排 | `{ label, hint?, children }` | | `ui.TextInput` | 单行输入 | `{ value, onChange, placeholder?, type?, disabled?, autoFocus?, onKeyDown?, min?, max? }` | | `ui.TextArea` | 多行(等宽) | `{ value, onChange, placeholder?, rows?, disabled?, onKeyDown? }` | | `ui.Select` | 下拉 | `{ value, onChange, disabled?, children }`(children 为 `