dsh-leader-agent 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.agents/skills/e2e-scenarios/SKILL.md +3 -2
- package/.agents/skills/leader-mode/SKILL.md +1 -0
- package/.agents/skills/leader-mode/playbooks/implementation.md +1 -1
- package/.agents/skills/leader-mode/playbooks/testing.md +46 -0
- package/README.md +13 -7
- package/README_ZH.md +13 -7
- package/lib/client.js +1524 -483
- package/locale/de.json +11 -1
- package/locale/en.json +11 -1
- package/locale/es.json +11 -1
- package/locale/fr.json +11 -1
- package/locale/ja.json +11 -1
- package/locale/pt.json +11 -1
- package/locale/ru.json +11 -1
- package/locale/zh.json +11 -1
- package/package.json +2 -1
- package/src/client/board-card.js +99 -28
- package/src/client/board-mode.js +116 -0
- package/src/client/board-rail-plan.js +159 -0
- package/src/client/board-rail.js +254 -0
- package/src/client/board-settings.js +169 -0
- package/src/client/board-styles.js +390 -7
- package/src/client/board.js +179 -13
- package/src/client/index.js +11 -1
- package/src/client/locales.generated.js +80 -0
- package/src/client/motion-preference.js +59 -0
- package/src/client/project-panel-logic.js +3 -2
- package/src/client/project-panel.js +37 -4
- package/src/client/project-section.js +6 -1
- package/src/client/session-tabs.js +13 -3
- package/src/host/dispatch.js +104 -39
- package/src/host/index.js +41 -9
- package/src/host/message.js +6 -2
- package/src/host/projects/service.js +19 -1
- package/src/host/projects/session-index.js +20 -0
- package/src/host/worker-sessions.js +11 -7
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 线路图覆盖层:在卡片列表下面垫一层 SVG,画出主干、节点与支线。
|
|
3
|
+
*
|
|
4
|
+
* 它不改列表的 DOM 语义——卡片、链接、会话入口都还是原来的元素,这一层只负责
|
|
5
|
+
* 「看得见连线」。所有几何都在渲染后实测:卡面高度随标题换行变,语言一换就变,
|
|
6
|
+
* 写死坐标的图在别的语言下必然错位。
|
|
7
|
+
*
|
|
8
|
+
* 动画只给「执行中」的线:金色光点沿路径跑,来源是槽位会话快照的 running 跳变,
|
|
9
|
+
* 不是随机装饰。`prefers-reduced-motion` 下只留静态线,不跑光点。
|
|
10
|
+
*
|
|
11
|
+
* @module dsh-leader-agent/client/board-rail
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { createElement, useEffect, useLayoutEffect, useRef, useState } from 'react'
|
|
15
|
+
import { planRailLanes, railNodeState, RAIL_LANE_HOT, RAIL_LANE_WARN } from './board-rail-plan.js'
|
|
16
|
+
import { prefersReducedMotion, watchReducedMotion } from './motion-preference.js'
|
|
17
|
+
|
|
18
|
+
const SVG_NS = 'http://www.w3.org/2000/svg'
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* 同时跑光点的上限。
|
|
22
|
+
*
|
|
23
|
+
* 二十张卡一起亮不是「工作流」,是圣诞树;超过这个数只保留静态金色,不再跑头。
|
|
24
|
+
*/
|
|
25
|
+
const MAX_ANIMATED_LANES = 6
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* 造一个 SVG 元素。
|
|
29
|
+
*
|
|
30
|
+
* @param {string} tag - 标签名
|
|
31
|
+
* @param {Record<string, unknown>} [attrs] - 属性
|
|
32
|
+
* @returns {object} SVG 元素
|
|
33
|
+
*/
|
|
34
|
+
function svgNode(tag, attrs = {}) {
|
|
35
|
+
const node = document.createElementNS(SVG_NS, tag)
|
|
36
|
+
for (const [key, value] of Object.entries(attrs)) node.setAttribute(key, String(value))
|
|
37
|
+
return node
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* 造一条路径。
|
|
42
|
+
*
|
|
43
|
+
* @param {string} d - path 数据
|
|
44
|
+
* @param {string} className - 类名
|
|
45
|
+
* @returns {object} SVG path
|
|
46
|
+
*/
|
|
47
|
+
function pathNode(d, className) {
|
|
48
|
+
return svgNode('path', { d, class: className })
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* 跟随系统的「减少动态效果」偏好。
|
|
53
|
+
*
|
|
54
|
+
* SMIL 光点不受 CSS 媒体查询管:偏好如果在看板打开后才切到 reduce,已经挂上的
|
|
55
|
+
* comet 会继续跑。订阅变化后重画,绘制层才能把光点摘掉。
|
|
56
|
+
*
|
|
57
|
+
* @returns {boolean} 当前是否要求减少动态效果
|
|
58
|
+
*/
|
|
59
|
+
function usePrefersReducedMotion() {
|
|
60
|
+
const [reduced, setReduced] = useState(prefersReducedMotion)
|
|
61
|
+
useEffect(() => watchReducedMotion(globalThis, setReduced), [])
|
|
62
|
+
return reduced
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* 让一段金色高亮沿路径流动。
|
|
67
|
+
*
|
|
68
|
+
* dash 长度按路径实测长度给:短支线整条亮,长主干留一段跑动的光。用 CSS 变量把
|
|
69
|
+
* 起止偏移带到 keyframes 里,避免为每条线写一份样式。
|
|
70
|
+
*
|
|
71
|
+
* @param {object} path - SVG path
|
|
72
|
+
* @param {number} phase - 相位,错开同时起跑的光点
|
|
73
|
+
* @returns {void}
|
|
74
|
+
*/
|
|
75
|
+
function primeFlow(path, phase) {
|
|
76
|
+
let length = 200
|
|
77
|
+
try {
|
|
78
|
+
length = path.getTotalLength()
|
|
79
|
+
} catch {
|
|
80
|
+
// 路径退化(零长度)时按默认长度算,最多是一段不动的线
|
|
81
|
+
}
|
|
82
|
+
const dash = Math.min(120, Math.max(44, length * 0.55))
|
|
83
|
+
path.style.strokeDasharray = `${dash} ${length + dash * 2}`
|
|
84
|
+
path.style.setProperty('--dla-from', `${dash}px`)
|
|
85
|
+
path.style.setProperty('--dla-to', `${-(length + dash * 2)}px`)
|
|
86
|
+
path.style.animationDelay = `${-(phase % 7) * 0.31}s`
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* 量一个元素相对内容区的矩形。
|
|
91
|
+
*
|
|
92
|
+
* @param {object} element - DOM 元素
|
|
93
|
+
* @param {DOMRect} base - 内容区矩形
|
|
94
|
+
* @returns {{x: number, y: number, cx: number, cy: number, right: number}} 相对坐标
|
|
95
|
+
*/
|
|
96
|
+
function measure(element, base) {
|
|
97
|
+
const rect = element.getBoundingClientRect()
|
|
98
|
+
return {
|
|
99
|
+
x: rect.left - base.left,
|
|
100
|
+
y: rect.top - base.top,
|
|
101
|
+
cx: rect.left - base.left + rect.width / 2,
|
|
102
|
+
cy: rect.top - base.top + rect.height / 2,
|
|
103
|
+
right: rect.right - base.left,
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* 重画整张线路图。
|
|
109
|
+
*
|
|
110
|
+
* @param {object} svg - 覆盖层
|
|
111
|
+
* @param {{ orthogonal?: boolean, theme?: string, reduced?: boolean }} options - 走线方式、主题与动效偏好
|
|
112
|
+
* @returns {void}
|
|
113
|
+
*/
|
|
114
|
+
function drawRail(svg, options = {}) {
|
|
115
|
+
const stage = svg.parentElement
|
|
116
|
+
if (stage === null) return
|
|
117
|
+
svg.replaceChildren()
|
|
118
|
+
|
|
119
|
+
const rowElements = [...stage.querySelectorAll('[data-rail-row]')]
|
|
120
|
+
if (rowElements.length === 0) return
|
|
121
|
+
|
|
122
|
+
const base = stage.getBoundingClientRect()
|
|
123
|
+
const dot = stage.querySelector('[data-rail-leader-dot]')
|
|
124
|
+
const leader = dot === null ? { cx: 20, cy: 0 } : measure(dot, base)
|
|
125
|
+
|
|
126
|
+
const rows = []
|
|
127
|
+
for (const row of rowElements) {
|
|
128
|
+
const cardElement = row.querySelector('.dsh-leader-agent-board-card')
|
|
129
|
+
if (cardElement === null) continue
|
|
130
|
+
const card = measure(cardElement, base)
|
|
131
|
+
const slots = [...row.querySelectorAll('[data-rail-slot]')]
|
|
132
|
+
.map((slot) => {
|
|
133
|
+
const rect = measure(slot, base)
|
|
134
|
+
// 支线停在圆点左缘外 2px:画到圆心上会从首字上穿过去
|
|
135
|
+
return { x: rect.cx - 12, y: rect.cy, status: slot.dataset.railState }
|
|
136
|
+
})
|
|
137
|
+
rows.push({
|
|
138
|
+
status: row.dataset.railStatus ?? 'none',
|
|
139
|
+
cardX: card.x,
|
|
140
|
+
cardRight: card.right,
|
|
141
|
+
cy: card.cy,
|
|
142
|
+
slots,
|
|
143
|
+
})
|
|
144
|
+
}
|
|
145
|
+
if (rows.length === 0) return
|
|
146
|
+
|
|
147
|
+
const trunkX = leader.cx
|
|
148
|
+
const lastY = rows[rows.length - 1].cy
|
|
149
|
+
svg.appendChild(pathNode(`M${trunkX},${leader.cy} L${trunkX},${lastY}`, 'dsh-leader-agent-board-rail-trunk'))
|
|
150
|
+
|
|
151
|
+
rows.forEach((row) => {
|
|
152
|
+
const nodeClass = `dsh-leader-agent-board-rail-node dsh-leader-agent-board-rail-node-${railNodeState(row.status)}`
|
|
153
|
+
svg.appendChild(options.orthogonal === true
|
|
154
|
+
? svgNode('rect', { x: trunkX - 3.2, y: row.cy - 3.2, width: 6.4, height: 6.4, rx: 1.2, class: nodeClass })
|
|
155
|
+
: svgNode('circle', { cx: trunkX, cy: row.cy, r: 3.4, class: nodeClass }))
|
|
156
|
+
// 浅色皮的节点是方块,再加扩散圆环会变成「光晕」,那正是浅色最忌讳的材质
|
|
157
|
+
if (row.status === 'running' && options.theme !== 'light') {
|
|
158
|
+
svg.appendChild(svgNode('circle', {
|
|
159
|
+
cx: trunkX,
|
|
160
|
+
cy: row.cy,
|
|
161
|
+
r: 9,
|
|
162
|
+
class: 'dsh-leader-agent-board-rail-halo',
|
|
163
|
+
}))
|
|
164
|
+
}
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
const reduced = options.reduced === true
|
|
168
|
+
let animated = 0
|
|
169
|
+
planRailLanes({ trunkX, leaderY: leader.cy, rows, orthogonal: options.orthogonal }).forEach((lane, index) => {
|
|
170
|
+
if (lane.kind === RAIL_LANE_HOT) {
|
|
171
|
+
svg.appendChild(pathNode(lane.d, 'dsh-leader-agent-board-rail-hot'))
|
|
172
|
+
if (reduced || animated >= MAX_ANIMATED_LANES) return
|
|
173
|
+
animated += 1
|
|
174
|
+
const trail = pathNode(lane.d, 'dsh-leader-agent-board-rail-trail')
|
|
175
|
+
svg.appendChild(trail)
|
|
176
|
+
primeFlow(trail, index)
|
|
177
|
+
const comet = svgNode('circle', { r: 3, class: 'dsh-leader-agent-board-rail-comet' })
|
|
178
|
+
comet.appendChild(svgNode('animateMotion', {
|
|
179
|
+
dur: '2400ms',
|
|
180
|
+
begin: `${(index % 7) * 0.28}s`,
|
|
181
|
+
repeatCount: 'indefinite',
|
|
182
|
+
path: lane.d,
|
|
183
|
+
}))
|
|
184
|
+
svg.appendChild(comet)
|
|
185
|
+
return
|
|
186
|
+
}
|
|
187
|
+
if (lane.kind === RAIL_LANE_WARN) {
|
|
188
|
+
svg.appendChild(pathNode(lane.d, 'dsh-leader-agent-board-rail-warn'))
|
|
189
|
+
return
|
|
190
|
+
}
|
|
191
|
+
svg.appendChild(pathNode(lane.d, 'dsh-leader-agent-board-rail-edge'))
|
|
192
|
+
})
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* 线路图覆盖层。
|
|
197
|
+
*
|
|
198
|
+
* `railKey` 是行身份与状态的签名:卡片轮询每 2 秒会换一个新数组,但签名不变时
|
|
199
|
+
* 不必重画——重画会让光点从头再跑一遍。stage 宽高另并入绘制签名。
|
|
200
|
+
*
|
|
201
|
+
* @param {object} props - 组件属性
|
|
202
|
+
* @param {string} props.railKey - 行与状态的签名
|
|
203
|
+
* @returns {object} React 元素
|
|
204
|
+
*/
|
|
205
|
+
export function BoardRail({ railKey, orthogonal, theme }) {
|
|
206
|
+
const ref = useRef(null)
|
|
207
|
+
const reduced = usePrefersReducedMotion()
|
|
208
|
+
// 最近一次真正画上去的完整签名(内容 + 几何)。隐藏/显示只改可见性,不改
|
|
209
|
+
// 内容与几何;用它把「右栏重新可见」的 0 → N 尺寸变化挡在重画之外——重画会
|
|
210
|
+
// 重建 SVG,SMIL 光点跟着从头起跑。
|
|
211
|
+
const drawnKey = useRef('')
|
|
212
|
+
|
|
213
|
+
useLayoutEffect(() => {
|
|
214
|
+
const svg = ref.current
|
|
215
|
+
if (svg === null) return undefined
|
|
216
|
+
const stage = svg.parentElement
|
|
217
|
+
if (stage === null) return undefined
|
|
218
|
+
let timer = 0
|
|
219
|
+
const draw = () => {
|
|
220
|
+
// 宿主用 display:none 隐藏非当前会话的右栏:尺寸归零不是布局变化
|
|
221
|
+
if (stage.clientWidth === 0 || stage.clientHeight === 0) return
|
|
222
|
+
// 卡面标题固定单行后,行中心只随行高变化;宽度决定换行,高度覆盖 locale/
|
|
223
|
+
// 字体与链接行导致的整卡高度变化,两者合起来就够,不必逐行量几何。
|
|
224
|
+
const key = `${railKey}|${orthogonal}|${theme}|${reduced}|${stage.clientWidth}x${stage.clientHeight}`
|
|
225
|
+
if (key === drawnKey.current) return
|
|
226
|
+
drawnKey.current = key
|
|
227
|
+
drawRail(svg, { orthogonal, theme, reduced })
|
|
228
|
+
}
|
|
229
|
+
draw()
|
|
230
|
+
if (typeof ResizeObserver === 'undefined') return undefined
|
|
231
|
+
const observer = new ResizeObserver(() => {
|
|
232
|
+
// 尾防抖:连续拖拽期间每次回调都重置计时,整个拖拽过程中线路图停在旧宽度上
|
|
233
|
+
// (错位),停手 80ms 后只画最后一次。换来的是不逐帧重建 SMIL 节点。
|
|
234
|
+
clearTimeout(timer)
|
|
235
|
+
timer = setTimeout(() => {
|
|
236
|
+
draw()
|
|
237
|
+
// 防抖真正跑完的信号:e2e 等它递增后再断言,不用睡固定时间——重画即使
|
|
238
|
+
// 发生也已经在 draw() 里做完了。
|
|
239
|
+
svg.dataset.railSettled = String(Number(svg.dataset.railSettled ?? '0') + 1)
|
|
240
|
+
}, 80)
|
|
241
|
+
})
|
|
242
|
+
observer.observe(stage)
|
|
243
|
+
return () => {
|
|
244
|
+
clearTimeout(timer)
|
|
245
|
+
observer.disconnect()
|
|
246
|
+
}
|
|
247
|
+
}, [railKey, orthogonal, theme, reduced])
|
|
248
|
+
|
|
249
|
+
return createElement('svg', {
|
|
250
|
+
ref,
|
|
251
|
+
className: 'dsh-leader-agent-board-rail',
|
|
252
|
+
'aria-hidden': 'true',
|
|
253
|
+
})
|
|
254
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 看板的设置页:注册到宿主的 `settings.section`,提供「工作 / 炫酷」两种模式。
|
|
3
|
+
*
|
|
4
|
+
* 宿主的设置导航是把槽位里的注册项直接列出来,没有官方白名单(见
|
|
5
|
+
* `dsh-client-ui-settings-general` 的 `useSections`);官方「模型」页也是普通注册。
|
|
6
|
+
* 因此这里不需要宿主改动,也不需要 companion package。
|
|
7
|
+
*
|
|
8
|
+
* `ctx.slots.inject` 在槽位不存在时不会执行回调:旧宿主上没有这一节,设置页
|
|
9
|
+
* 自然不出现,不会让插件在启动路径上抛错;看板按默认模式走。
|
|
10
|
+
*
|
|
11
|
+
* @module dsh-leader-agent/client/board-settings
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { createElement, useEffect, useState } from 'react'
|
|
15
|
+
import {
|
|
16
|
+
BOARD_MODE_CINEMA,
|
|
17
|
+
BOARD_MODE_WORK,
|
|
18
|
+
BOARD_MODES,
|
|
19
|
+
readBoardMode,
|
|
20
|
+
subscribeBoardMode,
|
|
21
|
+
setBoardMode,
|
|
22
|
+
} from './board-mode.js'
|
|
23
|
+
import { readLocalStorage } from './guide-card-logic.js'
|
|
24
|
+
import { ensureBoardStyles } from './board-styles.js'
|
|
25
|
+
|
|
26
|
+
/** 注册键:与插件 id 同值,宿主按它排序与定位。 */
|
|
27
|
+
const SECTION_ID = 'dsh-leader-agent'
|
|
28
|
+
|
|
29
|
+
/** 设置导航里的排序:排在官方模型/搜索等页面之后。 */
|
|
30
|
+
const SECTION_ORDER = 90
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* 模式到字典键。
|
|
34
|
+
*
|
|
35
|
+
* 写成静态表而不是拼 `board.mode.${value}.title`:locale 门禁按字面量扫描
|
|
36
|
+
* 「哪些键被引用」,拼出来的键会被判成没人用。
|
|
37
|
+
*/
|
|
38
|
+
const MODE_KEYS = Object.freeze({
|
|
39
|
+
[BOARD_MODE_CINEMA]: { title: 'board.mode.cinema.title', desc: 'board.mode.cinema.desc' },
|
|
40
|
+
[BOARD_MODE_WORK]: { title: 'board.mode.work.title', desc: 'board.mode.work.desc' },
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* 模式选项的小预览图。
|
|
45
|
+
*
|
|
46
|
+
* 只是示意:用两个 SVG 画出「主干 + 节点」与「三行列表」,让用户在点之前就能
|
|
47
|
+
* 分辨两个模式。图形颜色走 currentColor,执行者圆点取宿主强调色(不写死琥珀:
|
|
48
|
+
* 浅色宿主的 accent 是蓝的,固定琥珀会与看板实际配色对不上),一起跟随主题。
|
|
49
|
+
*
|
|
50
|
+
* @param {boolean} cinema - 是否画线路图
|
|
51
|
+
* @returns {object} React 元素
|
|
52
|
+
*/
|
|
53
|
+
function ModePreview({ cinema }) {
|
|
54
|
+
if (cinema) {
|
|
55
|
+
return createElement(
|
|
56
|
+
'svg',
|
|
57
|
+
{ width: 44, height: 30, viewBox: '0 0 44 30', fill: 'none', 'aria-hidden': 'true' },
|
|
58
|
+
createElement('path', { d: 'M10 4V26', stroke: 'currentColor', strokeOpacity: 0.45, strokeWidth: 1.5 }),
|
|
59
|
+
createElement('path', { d: 'M10 9H20M10 18H20M10 26H20', stroke: 'currentColor', strokeOpacity: 0.45, strokeWidth: 1.5 }),
|
|
60
|
+
createElement('circle', { cx: 10, cy: 9, r: 2, fill: 'currentColor' }),
|
|
61
|
+
createElement('circle', { cx: 10, cy: 18, r: 2, fill: 'currentColor' }),
|
|
62
|
+
createElement('circle', { cx: 10, cy: 26, r: 2, fill: 'currentColor' }),
|
|
63
|
+
createElement('circle', { cx: 36, cy: 9, r: 2.6, className: 'dsh-leader-agent-settings-preview-dot' }),
|
|
64
|
+
)
|
|
65
|
+
}
|
|
66
|
+
return createElement(
|
|
67
|
+
'svg',
|
|
68
|
+
{ width: 44, height: 30, viewBox: '0 0 44 30', fill: 'none', 'aria-hidden': 'true' },
|
|
69
|
+
createElement('rect', { x: 4, y: 4, width: 36, height: 6, rx: 2, fill: 'currentColor', fillOpacity: 0.22 }),
|
|
70
|
+
createElement('rect', { x: 4, y: 12, width: 36, height: 6, rx: 2, fill: 'currentColor', fillOpacity: 0.22 }),
|
|
71
|
+
createElement('rect', { x: 4, y: 20, width: 36, height: 6, rx: 2, fill: 'currentColor', fillOpacity: 0.22 }),
|
|
72
|
+
)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* 一个模式选项。
|
|
77
|
+
*
|
|
78
|
+
* @param {object} props - 组件属性
|
|
79
|
+
* @param {string} props.value - 该选项的模式值
|
|
80
|
+
* @param {string} props.mode - 当前生效的模式
|
|
81
|
+
* @param {(value: string) => void} props.onChoose - 选择回调
|
|
82
|
+
* @param {(key: string) => string} props.t - 翻译函数
|
|
83
|
+
* @returns {object} React 元素
|
|
84
|
+
*/
|
|
85
|
+
function ModeOption({ value, mode, onChoose, t }) {
|
|
86
|
+
const selected = value === mode
|
|
87
|
+
return createElement(
|
|
88
|
+
'button',
|
|
89
|
+
{
|
|
90
|
+
type: 'button',
|
|
91
|
+
role: 'radio',
|
|
92
|
+
'aria-checked': selected,
|
|
93
|
+
className: selected
|
|
94
|
+
? 'dsh-leader-agent-settings-option dsh-leader-agent-settings-option-selected'
|
|
95
|
+
: 'dsh-leader-agent-settings-option',
|
|
96
|
+
onClick: () => { onChoose(value) },
|
|
97
|
+
},
|
|
98
|
+
createElement(
|
|
99
|
+
'span',
|
|
100
|
+
{ className: 'dsh-leader-agent-settings-preview' },
|
|
101
|
+
createElement(ModePreview, { cinema: value === BOARD_MODE_CINEMA }),
|
|
102
|
+
),
|
|
103
|
+
createElement(
|
|
104
|
+
'span',
|
|
105
|
+
{ className: 'dsh-leader-agent-settings-copy' },
|
|
106
|
+
createElement('b', null, t(MODE_KEYS[value].title)),
|
|
107
|
+
createElement('span', null, t(MODE_KEYS[value].desc)),
|
|
108
|
+
),
|
|
109
|
+
createElement('span', { className: 'dsh-leader-agent-settings-radio', 'aria-hidden': 'true' }),
|
|
110
|
+
)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* 设置页主体。
|
|
115
|
+
*
|
|
116
|
+
* @param {object} props - 组件属性
|
|
117
|
+
* @param {(key: string) => string} props.t - 翻译函数
|
|
118
|
+
* @returns {object} React 元素
|
|
119
|
+
*/
|
|
120
|
+
function BoardSettingsSection({ t }) {
|
|
121
|
+
const storage = readLocalStorage(globalThis)
|
|
122
|
+
const [mode, setMode] = useState(() => readBoardMode(storage))
|
|
123
|
+
// 设置页打开期间,别的窗口或组件改了模式也要跟上。
|
|
124
|
+
useEffect(() => subscribeBoardMode(setMode), [])
|
|
125
|
+
|
|
126
|
+
return createElement(
|
|
127
|
+
'section',
|
|
128
|
+
{ className: 'dsh-leader-agent-settings' },
|
|
129
|
+
createElement('h3', { className: 'dsh-leader-agent-settings-title' }, t('board.settings.title')),
|
|
130
|
+
createElement('p', { className: 'dsh-leader-agent-settings-desc' }, t('board.settings.desc')),
|
|
131
|
+
createElement(
|
|
132
|
+
'div',
|
|
133
|
+
{
|
|
134
|
+
className: 'dsh-leader-agent-settings-options',
|
|
135
|
+
role: 'radiogroup',
|
|
136
|
+
'aria-label': t('board.settings.title'),
|
|
137
|
+
},
|
|
138
|
+
BOARD_MODES.map((value) => createElement(ModeOption, {
|
|
139
|
+
key: value,
|
|
140
|
+
value,
|
|
141
|
+
mode,
|
|
142
|
+
onChoose: (next) => setMode(setBoardMode(storage, next)),
|
|
143
|
+
t,
|
|
144
|
+
})),
|
|
145
|
+
),
|
|
146
|
+
createElement('p', { className: 'dsh-leader-agent-settings-scope' }, t('board.settings.scope')),
|
|
147
|
+
)
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* 注册设置页。
|
|
152
|
+
*
|
|
153
|
+
* 样式表在这里一并注入:设置页可能先于看板被打开,等看板挂载再注入会闪一下
|
|
154
|
+
* 无样式的页面。
|
|
155
|
+
*
|
|
156
|
+
* @param {object} ctx - 客户端上下文
|
|
157
|
+
* @param {(key: string) => string} t - 翻译函数
|
|
158
|
+
* @returns {void}
|
|
159
|
+
*/
|
|
160
|
+
export function mountBoardSettings(ctx, t) {
|
|
161
|
+
ensureBoardStyles()
|
|
162
|
+
ctx.effect(() => ctx.slots.inject('settings.section', () => ctx.slots.register({
|
|
163
|
+
name: 'settings.section',
|
|
164
|
+
id: SECTION_ID,
|
|
165
|
+
order: SECTION_ORDER,
|
|
166
|
+
label: () => t('board.settings.nav'),
|
|
167
|
+
inject: () => ({ t }),
|
|
168
|
+
}, BoardSettingsSection)), 'dsh-leader-agent 设置页')
|
|
169
|
+
}
|