dsh-session-superagent 0.9.267 → 0.9.268
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/CHANGELOG.md +33 -0
- package/README.md +6 -4
- package/client.js +350 -50
- package/lib/index.js +1 -1
- package/package.json +4 -2
- package/ui-orbit-popover.js +202 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,39 @@
|
|
|
2
2
|
|
|
3
3
|
格式参照 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/),版本号遵循 [语义化版本](https://semver.org/lang/zh-CN/)。
|
|
4
4
|
|
|
5
|
+
## [0.9.268] - 2026-11-05 —— InfoTip 与卫星环接入 DSH 原生浮层
|
|
6
|
+
|
|
7
|
+
### InfoTip → DSH Tooltip
|
|
8
|
+
|
|
9
|
+
- 保留 `{text,icon,warn}` 与原 trigger;使用 `top / portal / openOnClick / gap=8`;
|
|
10
|
+
- capture scroll → remount key 清掉 pinned,effect 对称清理;
|
|
11
|
+
- DSH 的 `aria-describedby` 映射为 `aria-expanded`;不添加受控 open 假 API;
|
|
12
|
+
- 仅缺 Tooltip 时只回退 InfoTip,不连带降级 Modal/Toast。
|
|
13
|
+
|
|
14
|
+
### StatusOrbit → OrbitPopover
|
|
15
|
+
|
|
16
|
+
新增 `ui-orbit-popover.js` 与 UMD 同源适配:
|
|
17
|
+
|
|
18
|
+
- `useAnchoredPosition + useDismissOnOutsidePointer + MenuSurface`;
|
|
19
|
+
- `top / end / gap=8 / margin=8`,不传 center,不宣称自动 flip;
|
|
20
|
+
- 主 surface 通过宿主 `react-dom.createPortal` 到 body,`role=dialog`;
|
|
21
|
+
- 空态 252 / 常规 368、watcher rows、轮询和动作全部保留;
|
|
22
|
+
- DSH 路径不再使用手算 left/bottom 或极大 z-index;缺原语时完整保留旧实现。
|
|
23
|
+
|
|
24
|
+
删除确认改为「先关 orbit → 独立 ConfirmDialog → 取消/完成后回焦圆环」,
|
|
25
|
+
不再让浮层层级压住确认框,也不把焦点还给已卸载的删除按钮。
|
|
26
|
+
|
|
27
|
+
### 证据
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
Tooltip 定向 5/5;Orbit 适配 10/10;Orbit 集成 7/7;主线锚点 2/2
|
|
31
|
+
npm test → 524/524
|
|
32
|
+
scripts/ui-audit.mjs → 11/11,100 分
|
|
33
|
+
对比度 → 浅色 16 组 ≤ 基线 16;深色 13 组 ≤ 基线 13
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
真实 WebView 的 portal、键鼠、焦点、读屏与叠层仍列入走查,不宣称已验。
|
|
37
|
+
|
|
5
38
|
## [0.9.267] - 2026-11-05 —— 修掉行内编辑透明遮挡,主面板接入 DSH Modal/Toast
|
|
6
39
|
|
|
7
40
|
### 修复「展开后只能看,不能改」
|
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
<img src="assets/icon-180.png" width="88" height="88" alt="">
|
|
4
4
|
|
|
5
5
|
[](LICENSE)
|
|
6
|
-
[](https://github.com/MYCF711/dsh-session-superagent/releases)
|
|
7
7
|
[](https://www.npmjs.com/package/dsh-session-superagent)
|
|
8
8
|
[](https://github.com/topics/dsh-plugin)
|
|
9
9
|
[](https://github.com/awesome-dsh-plugin/awesome-dsh-plugin)
|
|
@@ -46,11 +46,13 @@ GitHub 有新动态 → watcher 轮询 → Agent.followup(消息) → 会话跑
|
|
|
46
46
|
| 位置 | 是什么 |
|
|
47
47
|
|---|---|
|
|
48
48
|
| 输入框下面那一行的**最左端**(`轮/步 · token · 上下文环` 同一行) | **总卫星环**:一个环代表这台机器,环上每一颗卫星 = 一个在运行的会话级 superagent。绿=主理中,琥珀=已暂停,红=上次轮询失败;一圈转起来说明至少还有一个在盯。**点一下**展开详情:仓库 / 会话标题 / 间隔 / 上次轮询 / 上次唤醒 / 状态 / 错误原文。 |
|
|
49
|
-
| 中间栏「主理鱼」标签页 |
|
|
49
|
+
| 中间栏「主理鱼」标签页 | **DSH 原生结构树、素材与设计语言**(superagent 同源控件作为适配):总览 / 判定 / 触发 / 设置;Modal、Toast 等优先使用宿主 primitives,官方确无同物才最小 derived |
|
|
50
50
|
| 会话头部 | 不再挂徽章(0.3.2 起移到上面那行) |
|
|
51
51
|
|
|
52
52
|
没有主理鱼时这里画一个**灰色空环**(不转、无卫星),点开提示怎么添加 —— 不占位但也不消失,免得看着像功能坏了。
|
|
53
53
|
|
|
54
|
+
UI 开发先读 `AGENTS.md` 的「原生 DSH 优先,最小自制」;`dsh-session-superagent/host-primitives` 与 `dsh-session-superagent/orbit-popover` 导出经测试的薄适配,不实现第二套弹层。
|
|
55
|
+
|
|
54
56
|
## 环境要求
|
|
55
57
|
|
|
56
58
|
- DSH ≥ 0.2.1-rc.5(`engines.dsh`)
|
|
@@ -146,7 +148,7 @@ Gitee 私有仓库要在「设置 → 凭证」填私人令牌;公开仓库不
|
|
|
146
148
|
## 开发
|
|
147
149
|
|
|
148
150
|
```sh
|
|
149
|
-
npm test #
|
|
151
|
+
npm test # 524 项单测(带离线开关;裸 node --test 会真去 spawn gh,两分半)
|
|
150
152
|
```
|
|
151
153
|
|
|
152
154
|
### 工具输出:文本给人和 agent,JSON 给程序
|
|
@@ -206,7 +208,7 @@ dsh plugin --profile <profile> add dsh-session-superagent@latest
|
|
|
206
208
|
|
|
207
209
|
|
|
208
210
|
```bash
|
|
209
|
-
npm test #
|
|
211
|
+
npm test # 524 项单测(带离线开关,约 1.6 秒)
|
|
210
212
|
node scripts/ui-audit.mjs # 11 项 UI 指标(写死颜色 / 自造 token / 官方结构采用 …)
|
|
211
213
|
node scripts/preflight.mjs # 41 项门禁(含上面两条,外加 profile 一致性、路由面、包内容)
|
|
212
214
|
node scripts/render-preview.mjs preview.html # 双主题静态预览,直接浏览器打开
|
package/client.js
CHANGED
|
@@ -14,7 +14,7 @@ window.__ModuleLoader__.load({
|
|
|
14
14
|
const { useCallback, useEffect, useRef, useState } = React
|
|
15
15
|
|
|
16
16
|
// client.js 是 UMD:宿主原语只能走 factory 注入的 require,不能 import 相对 ESM 适配模块。
|
|
17
|
-
// 这里的参数与 ui-host-primitives.js 的 createHostUi 保持一致,仅接入本面板需要的 Modal/Toast。
|
|
17
|
+
// 这里的参数与 ui-host-primitives.js 的 createHostUi 保持一致,仅接入本面板需要的 Modal/Toast/Tooltip。
|
|
18
18
|
function dismissToast(current, id) {
|
|
19
19
|
return current && current.id === id ? null : current
|
|
20
20
|
}
|
|
@@ -51,6 +51,42 @@ window.__ModuleLoader__.load({
|
|
|
51
51
|
onDone: () => onDone(item.id),
|
|
52
52
|
})
|
|
53
53
|
}
|
|
54
|
+
// DSH 只给 trigger 合并 aria-describedby,不维护 aria-expanded。
|
|
55
|
+
// forwardRef 把宿主 ref/事件原样落到原 button;expanded 仅映射 DSH 已管理的 describedby,不另管 open。
|
|
56
|
+
const TooltipTrigger = primitives.Tooltip && typeof HostReact.forwardRef === 'function'
|
|
57
|
+
? HostReact.forwardRef(function InfoTipTrigger({ text, icon = 'question', warn, 'aria-describedby': describedBy, ...triggerProps }, ref) {
|
|
58
|
+
const triggerIcon = HostReact.isValidElement(icon) ? icon : hostH(Icon, { name: icon, size: 14 })
|
|
59
|
+
return hostH('button', {
|
|
60
|
+
...triggerProps,
|
|
61
|
+
ref,
|
|
62
|
+
type: 'button',
|
|
63
|
+
className: cx('dt-info', warn && 'dt-info-warn'),
|
|
64
|
+
'aria-label': text,
|
|
65
|
+
'aria-describedby': describedBy,
|
|
66
|
+
'aria-expanded': Boolean(describedBy),
|
|
67
|
+
}, triggerIcon)
|
|
68
|
+
})
|
|
69
|
+
: null
|
|
70
|
+
const HostTooltip = ({ text, icon = 'question', warn = false } = {}) => {
|
|
71
|
+
const TooltipPrimitive = primitive('Tooltip')
|
|
72
|
+
if (!TooltipTrigger) throw new Error('DSH Tooltip 需要宿主 React.forwardRef')
|
|
73
|
+
const [remountKey, setRemountKey] = HostReact.useState(0)
|
|
74
|
+
HostReact.useEffect(() => {
|
|
75
|
+
if (typeof window === 'undefined') return undefined
|
|
76
|
+
const closeOnScroll = () => setRemountKey((current) => current + 1)
|
|
77
|
+
// Tooltip 没有受控 open API;capture 覆盖主面板及任意嵌套滚动容器。
|
|
78
|
+
window.addEventListener('scroll', closeOnScroll, true)
|
|
79
|
+
return () => window.removeEventListener('scroll', closeOnScroll, true)
|
|
80
|
+
}, [])
|
|
81
|
+
return hostH(TooltipPrimitive, {
|
|
82
|
+
key: remountKey,
|
|
83
|
+
label: text,
|
|
84
|
+
side: 'top',
|
|
85
|
+
portal: true,
|
|
86
|
+
openOnClick: true,
|
|
87
|
+
gap: 8,
|
|
88
|
+
}, hostH(TooltipTrigger, { text, icon, warn }))
|
|
89
|
+
}
|
|
54
90
|
const createToastState = () => {
|
|
55
91
|
const [item, setItem] = HostReact.useState(null)
|
|
56
92
|
const sequence = HostReact.useRef(0)
|
|
@@ -65,22 +101,229 @@ window.__ModuleLoader__.load({
|
|
|
65
101
|
}, [])
|
|
66
102
|
return { item, notify, dismiss }
|
|
67
103
|
}
|
|
68
|
-
return { Modal: HostModal, Toast: HostToast, createToastState }
|
|
104
|
+
return { Modal: HostModal, Toast: HostToast, Tooltip: HostTooltip, createToastState }
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// 以下来源:ui-orbit-popover.js(L84e)的同一薄适配,因 client.js 是 UMD 而在 factory 内镜像。
|
|
108
|
+
// createOrbitPopover({React, primitives}) 的参数、OrbitPopover/useOrbitConfirm 调用面与来源模块一致;
|
|
109
|
+
// React.createPortal 由调用方用宿主 require('react-dom').createPortal 注入,不伪造 primitives.createPortal。
|
|
110
|
+
const DEFAULT_ORBIT_Z_INDEX = 1100
|
|
111
|
+
|
|
112
|
+
function focusIfConnected(node) {
|
|
113
|
+
if (!node || typeof node.focus !== 'function') return false
|
|
114
|
+
if ('isConnected' in node && !node.isConnected) return false
|
|
115
|
+
try {
|
|
116
|
+
node.focus()
|
|
117
|
+
return true
|
|
118
|
+
} catch {
|
|
119
|
+
return false
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function closeReason(detail) {
|
|
124
|
+
if (detail === false) return { reason: 'outside-pointer' }
|
|
125
|
+
if (typeof detail === 'string') return { reason: detail }
|
|
126
|
+
if (detail && typeof detail === 'object' && typeof detail.reason === 'string') return detail
|
|
127
|
+
return { reason: 'dismiss' }
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// 单独抽出确认 hook 只为让 StatusOrbit 在 fallback 也无条件执行同样数量的 hooks;
|
|
131
|
+
// 弹层创建仍严格要求完整 DSH 能力,缺少能力不会创建替代 Popover。
|
|
132
|
+
function createOrbitConfirm({ React: HostReact }) {
|
|
133
|
+
return function useOrbitConfirm({ orbitRef, onCloseOrbit, onRequestConfirm } = {}) {
|
|
134
|
+
const orbitRefRef = HostReact.useRef(orbitRef)
|
|
135
|
+
const onCloseOrbitRef = HostReact.useRef(onCloseOrbit)
|
|
136
|
+
const onRequestConfirmRef = HostReact.useRef(onRequestConfirm)
|
|
137
|
+
const restoreFocusRef = HostReact.useRef(null)
|
|
138
|
+
orbitRefRef.current = orbitRef
|
|
139
|
+
onCloseOrbitRef.current = onCloseOrbit
|
|
140
|
+
onRequestConfirmRef.current = onRequestConfirm
|
|
141
|
+
|
|
142
|
+
const requestConfirm = HostReact.useCallback((detail = {}) => {
|
|
143
|
+
restoreFocusRef.current = 'orbit'
|
|
144
|
+
if (typeof onCloseOrbitRef.current === 'function') {
|
|
145
|
+
onCloseOrbitRef.current({ reason: 'confirm' })
|
|
146
|
+
}
|
|
147
|
+
const request = onRequestConfirmRef.current
|
|
148
|
+
if (typeof request === 'function') {
|
|
149
|
+
const extra = detail && typeof detail === 'object' ? detail : { value: detail }
|
|
150
|
+
return request({ ...extra, reason: 'confirm', restoreFocus: 'orbit' })
|
|
151
|
+
}
|
|
152
|
+
return undefined
|
|
153
|
+
}, [])
|
|
154
|
+
|
|
155
|
+
const onConfirmClose = HostReact.useCallback(() => {
|
|
156
|
+
if (restoreFocusRef.current !== 'orbit') return false
|
|
157
|
+
restoreFocusRef.current = null
|
|
158
|
+
const ref = orbitRefRef.current
|
|
159
|
+
return focusIfConnected(ref && ref.current)
|
|
160
|
+
}, [])
|
|
161
|
+
|
|
162
|
+
return {
|
|
163
|
+
onRequestConfirm: requestConfirm,
|
|
164
|
+
onConfirmClose,
|
|
165
|
+
restoreFocus: restoreFocusRef.current,
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const useOrbitConfirm = createOrbitConfirm({ React })
|
|
171
|
+
|
|
172
|
+
function createOrbitPopover({ React: HostReact, primitives } = {}) {
|
|
173
|
+
if (!HostReact || typeof HostReact.createElement !== 'function') {
|
|
174
|
+
throw new TypeError('createOrbitPopover 需要宿主 React.createElement')
|
|
175
|
+
}
|
|
176
|
+
for (const hook of ['useRef', 'useCallback', 'useEffect']) {
|
|
177
|
+
if (typeof HostReact[hook] !== 'function') {
|
|
178
|
+
throw new TypeError(`createOrbitPopover 需要宿主 React.${hook}`)
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
if (typeof HostReact.createPortal !== 'function') {
|
|
182
|
+
throw new TypeError('createOrbitPopover 需要宿主 React.createPortal(从 react-dom 注入)')
|
|
183
|
+
}
|
|
184
|
+
if (!primitives || (typeof primitives !== 'object' && typeof primitives !== 'function')) {
|
|
185
|
+
throw new TypeError('createOrbitPopover 需要 DSH primitives')
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const primitive = (name, kind) => {
|
|
189
|
+
const value = primitives[name]
|
|
190
|
+
if (kind === 'function' ? typeof value !== 'function' : !value) {
|
|
191
|
+
throw new Error(`DSH primitives.${name} 不可用;OrbitPopover 不会创建替代弹层`)
|
|
192
|
+
}
|
|
193
|
+
return value
|
|
194
|
+
}
|
|
195
|
+
const useAnchoredPosition = primitive('useAnchoredPosition', 'function')
|
|
196
|
+
const useDismissOnOutsidePointer = primitive('useDismissOnOutsidePointer', 'function')
|
|
197
|
+
const MenuSurface = primitive('MenuSurface')
|
|
198
|
+
const hostH = HostReact.createElement
|
|
199
|
+
const createPortal = HostReact.createPortal
|
|
200
|
+
|
|
201
|
+
function OrbitPopover({
|
|
202
|
+
open,
|
|
203
|
+
anchorRef,
|
|
204
|
+
orbitRef,
|
|
205
|
+
panelRef: suppliedPanelRef,
|
|
206
|
+
onClose,
|
|
207
|
+
width,
|
|
208
|
+
zIndex = DEFAULT_ORBIT_Z_INDEX,
|
|
209
|
+
portalTarget: suppliedPortalTarget,
|
|
210
|
+
className,
|
|
211
|
+
style,
|
|
212
|
+
ariaLabel,
|
|
213
|
+
children,
|
|
214
|
+
} = {}) {
|
|
215
|
+
const internalPanelRef = HostReact.useRef(null)
|
|
216
|
+
const panelRef = suppliedPanelRef || internalPanelRef
|
|
217
|
+
const returnFocusRef = orbitRef || anchorRef
|
|
218
|
+
const onCloseRef = HostReact.useRef(onClose)
|
|
219
|
+
onCloseRef.current = onClose
|
|
220
|
+
|
|
221
|
+
const close = HostReact.useCallback((detail) => {
|
|
222
|
+
const callback = onCloseRef.current
|
|
223
|
+
if (typeof callback === 'function') callback(closeReason(detail))
|
|
224
|
+
}, [])
|
|
225
|
+
|
|
226
|
+
// 与来源适配器一致:宿主 hooks 和本地 effect 都在 open 分支前无条件调用。
|
|
227
|
+
const position = useAnchoredPosition({
|
|
228
|
+
open: Boolean(open),
|
|
229
|
+
anchorRef,
|
|
230
|
+
panelRef,
|
|
231
|
+
side: 'top',
|
|
232
|
+
align: 'end',
|
|
233
|
+
gap: 8,
|
|
234
|
+
margin: 8,
|
|
235
|
+
})
|
|
236
|
+
useDismissOnOutsidePointer(panelRef, Boolean(open), close, anchorRef)
|
|
237
|
+
|
|
238
|
+
const portalTarget = suppliedPortalTarget === undefined
|
|
239
|
+
? (typeof document !== 'undefined' ? document.body : null)
|
|
240
|
+
: suppliedPortalTarget
|
|
241
|
+
const ownerDocument = portalTarget && portalTarget.ownerDocument
|
|
242
|
+
? portalTarget.ownerDocument
|
|
243
|
+
: (typeof document !== 'undefined' ? document : null)
|
|
244
|
+
|
|
245
|
+
HostReact.useEffect(() => {
|
|
246
|
+
if (!open || !ownerDocument || typeof ownerDocument.addEventListener !== 'function') return undefined
|
|
247
|
+
focusIfConnected(panelRef.current)
|
|
248
|
+
const onKeyDown = (event) => {
|
|
249
|
+
if (!event || event.key !== 'Escape' || event.repeat) return
|
|
250
|
+
if (typeof event.preventDefault === 'function') event.preventDefault()
|
|
251
|
+
if (typeof event.stopPropagation === 'function') event.stopPropagation()
|
|
252
|
+
close({ reason: 'escape' })
|
|
253
|
+
}
|
|
254
|
+
ownerDocument.addEventListener('keydown', onKeyDown, true)
|
|
255
|
+
return () => {
|
|
256
|
+
ownerDocument.removeEventListener('keydown', onKeyDown, true)
|
|
257
|
+
focusIfConnected(returnFocusRef && returnFocusRef.current)
|
|
258
|
+
}
|
|
259
|
+
}, [open, close, ownerDocument, panelRef, returnFocusRef])
|
|
260
|
+
|
|
261
|
+
if (!open) return null
|
|
262
|
+
if (!anchorRef || typeof anchorRef !== 'object') {
|
|
263
|
+
throw new TypeError('OrbitPopover 需要调用方传入 anchorRef')
|
|
264
|
+
}
|
|
265
|
+
if (!Number.isFinite(width) || width <= 0) {
|
|
266
|
+
throw new TypeError('OrbitPopover 需要调用方传入正数 width;适配器不推导业务宽度')
|
|
267
|
+
}
|
|
268
|
+
if (!portalTarget) {
|
|
269
|
+
throw new Error('OrbitPopover portal target 不可用;不会退化为非 portal surface')
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
const surface = hostH(MenuSurface, {
|
|
273
|
+
ref: panelRef,
|
|
274
|
+
role: 'dialog',
|
|
275
|
+
'aria-label': ariaLabel,
|
|
276
|
+
tabIndex: -1,
|
|
277
|
+
className,
|
|
278
|
+
style: {
|
|
279
|
+
...style,
|
|
280
|
+
position: 'fixed',
|
|
281
|
+
left: position ? position.left : 0,
|
|
282
|
+
top: position ? position.top : 0,
|
|
283
|
+
width,
|
|
284
|
+
zIndex,
|
|
285
|
+
visibility: position ? 'visible' : 'hidden',
|
|
286
|
+
},
|
|
287
|
+
}, children)
|
|
288
|
+
return createPortal(surface, portalTarget)
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
return { OrbitPopover, useOrbitConfirm: createOrbitConfirm({ React: HostReact }) }
|
|
69
292
|
}
|
|
70
293
|
|
|
71
294
|
// 老宿主没有这个映射时 require 会抛错;可选探测失败必须完整保留本地实现。
|
|
72
295
|
let hostUi = null
|
|
296
|
+
let hostTooltip = null
|
|
297
|
+
let hostOrbit = null
|
|
73
298
|
try {
|
|
74
299
|
const primitives = require('@deepseek-ai/dsh-client-ui-primitives')
|
|
75
300
|
if (primitives && primitives.Modal && primitives.Toast && primitives.IconWarningOutlineMedium) {
|
|
76
301
|
hostUi = createHostUi({ React, primitives })
|
|
302
|
+
// Tooltip 独立探测:缺少它只回退 InfoTip,不把已接入的 Modal/Toast 一起降级。
|
|
303
|
+
if (primitives.Tooltip && typeof React.forwardRef === 'function') hostTooltip = hostUi.Tooltip
|
|
77
304
|
}
|
|
78
305
|
} catch {
|
|
79
306
|
hostUi = null
|
|
307
|
+
hostTooltip = null
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
// Orbit 独立探测:缺 MenuSurface/定位/外点 hook 或 react-dom.createPortal 任一能力,完整保留旧 StatusOrbit。
|
|
311
|
+
try {
|
|
312
|
+
const primitives = require('@deepseek-ai/dsh-client-ui-primitives')
|
|
313
|
+
if (primitives && primitives.MenuSurface
|
|
314
|
+
&& typeof primitives.useAnchoredPosition === 'function'
|
|
315
|
+
&& typeof primitives.useDismissOnOutsidePointer === 'function') {
|
|
316
|
+
const reactDom = require('react-dom')
|
|
317
|
+
if (reactDom && typeof reactDom.createPortal === 'function') {
|
|
318
|
+
hostOrbit = createOrbitPopover({ React: { ...React, createPortal: reactDom.createPortal }, primitives })
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
} catch {
|
|
322
|
+
hostOrbit = null
|
|
80
323
|
}
|
|
81
324
|
|
|
82
325
|
// 客户端版本探针:每次模块加载写一次,用来确认浏览器里跑的是哪一版
|
|
83
|
-
const CLIENT_VERSION = '0.9.
|
|
326
|
+
const CLIENT_VERSION = '0.9.268'
|
|
84
327
|
let BASE = '/session-superagent'
|
|
85
328
|
/**
|
|
86
329
|
* 挑「最新的那个服务端实例」。
|
|
@@ -484,8 +727,8 @@ window.__ModuleLoader__.load({
|
|
|
484
727
|
open ? children : null)
|
|
485
728
|
}
|
|
486
729
|
|
|
487
|
-
/**
|
|
488
|
-
function
|
|
730
|
+
/** 无 DSH Tooltip 时完整保留原实现:原 trigger、点击/失焦与本地气泡都不改写。 */
|
|
731
|
+
function FallbackInfoTip({ text, icon = 'question', warn }) {
|
|
489
732
|
const [open, setOpen] = useState(false)
|
|
490
733
|
return h('span', { style: { position: 'relative', display: 'inline-flex' } },
|
|
491
734
|
h('button', {
|
|
@@ -496,6 +739,11 @@ window.__ModuleLoader__.load({
|
|
|
496
739
|
open ? h('span', { className: 'dt-tooltip', role: 'tooltip', style: { position: 'absolute', bottom: '130%', left: 0, visibility: 'visible' } }, text) : null)
|
|
497
740
|
}
|
|
498
741
|
|
|
742
|
+
// 保持 InfoTip({text,icon,warn}) 调用面;静态分支不会在组件生命周期内改变 hooks 顺序。
|
|
743
|
+
function InfoTip(props) {
|
|
744
|
+
return hostTooltip ? h(hostTooltip, props) : h(FallbackInfoTip, props)
|
|
745
|
+
}
|
|
746
|
+
|
|
499
747
|
const Hint = ({ children }) => h('p', { className: 'dt-hint' }, children)
|
|
500
748
|
|
|
501
749
|
// ── L84c WatcherForm:新增与行内编辑共用的一份字段 schema 与草稿控件 ──
|
|
@@ -822,12 +1070,10 @@ window.__ModuleLoader__.load({
|
|
|
822
1070
|
// 直接别名而不是 h(Component, props) 转发,避免测试桩与真 React 的 children 处理差异。
|
|
823
1071
|
const PanelModal = hostUi ? hostUi.Modal : Modal
|
|
824
1072
|
|
|
825
|
-
/**
|
|
826
|
-
function
|
|
827
|
-
const [open, setOpen] = useState(false)
|
|
1073
|
+
/** 确认层与触发器分离:DSH orbit 关闭后,同一个本地 Modal 仍能由 StatusOrbit 持有。 */
|
|
1074
|
+
function ConfirmDialog({ open, label, confirmLabel = '确定执行', title = confirmLabel, message, onConfirm, onClose, modalContext = 'panel' }) {
|
|
828
1075
|
const [busy, setBusy] = useState(false)
|
|
829
1076
|
const busyRef = useRef(false)
|
|
830
|
-
const close = useCallback(() => setOpen(false), [])
|
|
831
1077
|
const confirm = async () => {
|
|
832
1078
|
// state 还没来得及重渲染时也可能连点;同步 ref 是第二道锁。
|
|
833
1079
|
if (busyRef.current) return false
|
|
@@ -835,15 +1081,38 @@ window.__ModuleLoader__.load({
|
|
|
835
1081
|
setBusy(true)
|
|
836
1082
|
try {
|
|
837
1083
|
const done = await onConfirm()
|
|
838
|
-
if (done)
|
|
1084
|
+
if (done) onClose()
|
|
839
1085
|
return done
|
|
840
1086
|
} finally {
|
|
841
1087
|
busyRef.current = false
|
|
842
1088
|
setBusy(false)
|
|
843
1089
|
}
|
|
844
1090
|
}
|
|
845
|
-
// orbit
|
|
1091
|
+
// orbit 删除明确保留 superagent 同源 Modal;普通主面板删除仍走 PanelModal,不换 RiskConfirmation。
|
|
846
1092
|
const ModalView = modalContext === 'orbit' ? Modal : PanelModal
|
|
1093
|
+
return h(ModalView, {
|
|
1094
|
+
open,
|
|
1095
|
+
title,
|
|
1096
|
+
description: message || ('确定要执行「' + label + '」操作吗?'),
|
|
1097
|
+
onClose,
|
|
1098
|
+
children: null,
|
|
1099
|
+
footer: h(React.Fragment, null,
|
|
1100
|
+
h(Btn, { variant: 'ghost', onClick: onClose }, '取消'),
|
|
1101
|
+
h(Btn, {
|
|
1102
|
+
variant: 'primary',
|
|
1103
|
+
className: cx('dt-danger', busy && 'dt-btn-busy'),
|
|
1104
|
+
disabled: busy,
|
|
1105
|
+
'aria-label': confirmLabel,
|
|
1106
|
+
'aria-busy': busy ? 'true' : undefined,
|
|
1107
|
+
onClick: confirm,
|
|
1108
|
+
}, confirmLabel)),
|
|
1109
|
+
})
|
|
1110
|
+
}
|
|
1111
|
+
|
|
1112
|
+
/** 官方 ConfirmButton 动线:触发按钮只开 Modal,取消不执行,确认期间 busy 防重复。 */
|
|
1113
|
+
function ConfirmButton({ label, confirmLabel = '确定执行', title = confirmLabel, message, onConfirm, variant = 'ghost', icon, size, modalContext = 'panel' }) {
|
|
1114
|
+
const [open, setOpen] = useState(false)
|
|
1115
|
+
const close = useCallback(() => setOpen(false), [])
|
|
847
1116
|
return h(React.Fragment, null,
|
|
848
1117
|
h(Btn, {
|
|
849
1118
|
variant,
|
|
@@ -853,23 +1122,7 @@ window.__ModuleLoader__.load({
|
|
|
853
1122
|
'aria-haspopup': 'dialog',
|
|
854
1123
|
onClick: () => setOpen(true),
|
|
855
1124
|
}, label),
|
|
856
|
-
h(
|
|
857
|
-
open,
|
|
858
|
-
title,
|
|
859
|
-
description: message || ('确定要执行「' + label + '」操作吗?'),
|
|
860
|
-
onClose: close,
|
|
861
|
-
children: null,
|
|
862
|
-
footer: h(React.Fragment, null,
|
|
863
|
-
h(Btn, { variant: 'ghost', onClick: close }, '取消'),
|
|
864
|
-
h(Btn, {
|
|
865
|
-
variant: 'primary',
|
|
866
|
-
className: cx('dt-danger', busy && 'dt-btn-busy'),
|
|
867
|
-
disabled: busy,
|
|
868
|
-
'aria-label': confirmLabel,
|
|
869
|
-
'aria-busy': busy ? 'true' : undefined,
|
|
870
|
-
onClick: confirm,
|
|
871
|
-
}, confirmLabel)),
|
|
872
|
-
}))
|
|
1125
|
+
h(ConfirmDialog, { open, label, confirmLabel, title, message, onConfirm, onClose: close, modalContext }))
|
|
873
1126
|
}
|
|
874
1127
|
|
|
875
1128
|
const watcherId = (w) => (w && w.id) || String((w && w.repo) || '') + '#' + String((w && w.sessionId) || '')
|
|
@@ -1078,6 +1331,12 @@ window.__ModuleLoader__.load({
|
|
|
1078
1331
|
const [anchor, setAnchor] = useState(null)
|
|
1079
1332
|
const btnRef = useRef(null)
|
|
1080
1333
|
const panelRef = useRef(null)
|
|
1334
|
+
const orbitConfirm = useOrbitConfirm({
|
|
1335
|
+
orbitRef: btnRef,
|
|
1336
|
+
onCloseOrbit: () => setOpen(false),
|
|
1337
|
+
// DSH 路径复用旧 anchor 槽保存待删 watcher;fallback 仍只保存手算坐标,状态槽位不变。
|
|
1338
|
+
onRequestConfirm: ({ watcher }) => setAnchor(watcher),
|
|
1339
|
+
})
|
|
1081
1340
|
|
|
1082
1341
|
// 弹层的样式(DOCK_CSS)挂在 PORTED_CSS 同一张 <style> 里,而那张表以前只有「主理鱼」面板挂载时才注入。
|
|
1083
1342
|
// 用户从没打开过面板就直接点状态栏圆环时,弹层就是一堆无样式的裸文字(真机复现过)。
|
|
@@ -1104,7 +1363,8 @@ window.__ModuleLoader__.load({
|
|
|
1104
1363
|
useEffect(() => { if (open) ensurePortedCss(true) }, [open])
|
|
1105
1364
|
|
|
1106
1365
|
useEffect(() => {
|
|
1107
|
-
|
|
1366
|
+
// 仅旧路径保留 capture mousedown / 手算焦点;DSH 由 OrbitPopover 与宿主 dismiss hook 接管。
|
|
1367
|
+
if (!open || hostOrbit) return undefined
|
|
1108
1368
|
const onDown = (event) => {
|
|
1109
1369
|
const target = event.target
|
|
1110
1370
|
if (panelRef.current && panelRef.current.contains(target)) return
|
|
@@ -1141,10 +1401,12 @@ window.__ModuleLoader__.load({
|
|
|
1141
1401
|
+ '(共 ' + list.length + ' 条)'
|
|
1142
1402
|
|
|
1143
1403
|
const toggle = () => {
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1404
|
+
if (!hostOrbit) {
|
|
1405
|
+
const el = btnRef.current
|
|
1406
|
+
if (el) {
|
|
1407
|
+
const rect = el.getBoundingClientRect()
|
|
1408
|
+
setAnchor({ x: rect.left + rect.width / 2, y: rect.top })
|
|
1409
|
+
}
|
|
1148
1410
|
}
|
|
1149
1411
|
setOpen((value) => !value)
|
|
1150
1412
|
}
|
|
@@ -1167,16 +1429,15 @@ window.__ModuleLoader__.load({
|
|
|
1167
1429
|
},
|
|
1168
1430
|
}, h(OrbitMark, { watchers: list }))
|
|
1169
1431
|
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
// 空态没什么内容,窄一点更像提示而不是一张空表格
|
|
1173
|
-
// 弹层宽度是固定的,但窗口可能更窄:按可视宽度夹一下,别溢出屏幕
|
|
1432
|
+
// DSH 固定业务宽度 252/368,坐标全部交给 useAnchoredPosition;只有 fallback 保留视口夹紧与手算 bottom。
|
|
1174
1433
|
const viewport = Number(window && window.innerWidth) || 1200
|
|
1175
|
-
const width =
|
|
1176
|
-
|
|
1434
|
+
const width = hostOrbit
|
|
1435
|
+
? (list.length === 0 ? 252 : PANEL_W)
|
|
1436
|
+
: Math.min(list.length === 0 ? 252 : PANEL_W, Math.max(240, viewport - 16))
|
|
1437
|
+
const left = !hostOrbit && anchor
|
|
1177
1438
|
? Math.max(8, Math.min(anchor.x - width / 2, (window.innerWidth || 1200) - width - 8))
|
|
1178
1439
|
: 8
|
|
1179
|
-
const bottom = anchor ? Math.max(8, (window.innerHeight || 800) - anchor.y + 8) : 64
|
|
1440
|
+
const bottom = !hostOrbit && anchor ? Math.max(8, (window.innerHeight || 800) - anchor.y + 8) : 64
|
|
1180
1441
|
|
|
1181
1442
|
const act = async (w, action) => {
|
|
1182
1443
|
// 删除只走 ConfirmButton + Modal;不要再叠一层原生确认框(同一动作问两次)。
|
|
@@ -1199,6 +1460,13 @@ window.__ModuleLoader__.load({
|
|
|
1199
1460
|
return true
|
|
1200
1461
|
}
|
|
1201
1462
|
|
|
1463
|
+
// fallback 完全保留原提前返回;DSH 即使 orbit 已关,也要继续渲染由本组件持有的确认 Modal。
|
|
1464
|
+
if (!open && !hostOrbit) return button
|
|
1465
|
+
const closeConfirm = () => {
|
|
1466
|
+
setAnchor(null)
|
|
1467
|
+
orbitConfirm.onConfirmClose()
|
|
1468
|
+
}
|
|
1469
|
+
|
|
1202
1470
|
// 悬浮面板也走移植来的 dt-* 设计系统(以前这里是一套自成体系的 inline style,
|
|
1203
1471
|
// 和原生界面放在一起能看出断层;ui-audit ⑥ 就是在盯这件事)。
|
|
1204
1472
|
// 摘要行(官方弹层的写法):主名一行 + 一行 muted 细节,细节超长就省略号。
|
|
@@ -1248,11 +1516,18 @@ window.__ModuleLoader__.load({
|
|
|
1248
1516
|
h(Btn, { size: 'sm', variant: 'ghost', onClick: () => act(w, 'poll') }, '立刻'),
|
|
1249
1517
|
h(Btn, { size: 'sm', variant: 'ghost', onClick: () => act(w, w.enabled ? 'pause' : 'resume') },
|
|
1250
1518
|
w.enabled ? '暂停' : '恢复'),
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1519
|
+
hostOrbit
|
|
1520
|
+
? h(Btn, {
|
|
1521
|
+
variant: 'ghost', size: 'sm', icon: h(Icon, { name: 'trash' }),
|
|
1522
|
+
'aria-label': '删除', 'aria-haspopup': 'dialog',
|
|
1523
|
+
// 适配器保证先 onCloseOrbit,再由 onRequestConfirm 选中待删 watcher。
|
|
1524
|
+
onClick: () => orbitConfirm.onRequestConfirm({ watcher: w }),
|
|
1525
|
+
}, '删除')
|
|
1526
|
+
: h(ConfirmButton, {
|
|
1527
|
+
label: '删除', confirmLabel: '确认删除', variant: 'ghost', size: 'sm', modalContext: 'orbit',
|
|
1528
|
+
icon: h(Icon, { name: 'trash' }),
|
|
1529
|
+
onConfirm: () => act(w, 'delete'),
|
|
1530
|
+
})))
|
|
1256
1531
|
})
|
|
1257
1532
|
|
|
1258
1533
|
// 比例条:和官方的「上下文已用」同一种表达(一眼看出多少在跑)
|
|
@@ -1262,10 +1537,7 @@ window.__ModuleLoader__.load({
|
|
|
1262
1537
|
const bar = barCounts.length === 0 ? null : h('div', { className: 'sa-dock-bar', 'aria-hidden': 'true' },
|
|
1263
1538
|
barCounts.map(([tone, n]) => h('span', { key: tone, 'data-tone': tone, style: { flexGrow: n } })))
|
|
1264
1539
|
|
|
1265
|
-
const
|
|
1266
|
-
ref: panelRef, role: 'dialog', 'aria-label': summary, tabIndex: -1, className: 'dt-card sa-dock-panel',
|
|
1267
|
-
style: { position: 'fixed', left, bottom, width, zIndex: 2147483000 },
|
|
1268
|
-
},
|
|
1540
|
+
const panelBody = h(React.Fragment, null,
|
|
1269
1541
|
h('div', { className: 'sa-dock-head' },
|
|
1270
1542
|
h('span', { className: 'sa-dock-title' }, '主理鱼'),
|
|
1271
1543
|
// 和面板统计条同一套官方素材:dt-stat(数值强 + 单位弱),不再自己发明 sa-dock-metric-*
|
|
@@ -1280,8 +1552,36 @@ window.__ModuleLoader__.load({
|
|
|
1280
1552
|
? h('div', { className: 'sa-dock-foot' }, '详细状态与凭证在「主理鱼」标签页')
|
|
1281
1553
|
: null)
|
|
1282
1554
|
|
|
1555
|
+
const panel = hostOrbit
|
|
1556
|
+
? h(hostOrbit.OrbitPopover, {
|
|
1557
|
+
open,
|
|
1558
|
+
anchorRef: btnRef,
|
|
1559
|
+
orbitRef: btnRef,
|
|
1560
|
+
panelRef,
|
|
1561
|
+
onClose: () => setOpen(false),
|
|
1562
|
+
width,
|
|
1563
|
+
className: 'dt-card sa-dock-panel',
|
|
1564
|
+
ariaLabel: summary,
|
|
1565
|
+
}, panelBody)
|
|
1566
|
+
: h('div', {
|
|
1567
|
+
ref: panelRef, role: 'dialog', 'aria-label': summary, tabIndex: -1, className: 'dt-card sa-dock-panel',
|
|
1568
|
+
style: { position: 'fixed', left, bottom, width, zIndex: 2147483000 },
|
|
1569
|
+
}, panelBody)
|
|
1570
|
+
|
|
1571
|
+
// 选中待删 watcher 时 open 已被适配器先置 false:portal surface 卸载,本地确认 Modal 才打开。
|
|
1572
|
+
const confirmation = hostOrbit && anchor
|
|
1573
|
+
? h(ConfirmDialog, {
|
|
1574
|
+
open: true,
|
|
1575
|
+
label: '删除',
|
|
1576
|
+
confirmLabel: '确认删除',
|
|
1577
|
+
title: '确认删除',
|
|
1578
|
+
modalContext: 'orbit',
|
|
1579
|
+
onConfirm: () => act(anchor, 'delete'),
|
|
1580
|
+
onClose: closeConfirm,
|
|
1581
|
+
})
|
|
1582
|
+
: null
|
|
1283
1583
|
|
|
1284
|
-
return h(React.Fragment, null, button, panel)
|
|
1584
|
+
return h(React.Fragment, null, button, panel, confirmation)
|
|
1285
1585
|
}
|
|
1286
1586
|
|
|
1287
1587
|
|
package/lib/index.js
CHANGED
|
@@ -47,7 +47,7 @@ import {
|
|
|
47
47
|
|
|
48
48
|
export const name = 'dsh-session-superagent'
|
|
49
49
|
/** 服务端版本:随 package.json 同步(meta 测试守着)。客户端据此挑「最新的那个实例」。 */
|
|
50
|
-
export const SERVER_VERSION = '0.9.
|
|
50
|
+
export const SERVER_VERSION = '0.9.268'
|
|
51
51
|
export const inject = ['tools', 'agents', 'webServer']
|
|
52
52
|
/** 一条会话每小时最多被唤醒几次(跨所有守累计)。单守上限挡不住多守叠加。 */
|
|
53
53
|
// 本进程启动时刻:用来区分「刚重启还没轮到」与「定时器真的丢了」
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-session-superagent",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.268",
|
|
4
4
|
"description": "Session-level superagent for DeepSeek Harness: watch a GitHub repository and wake a session when something needs doing. Credentials never reach the model.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
"./redact": "./lib/redact.js",
|
|
11
11
|
"./package.json": "./package.json",
|
|
12
12
|
"./client": "./client.js",
|
|
13
|
-
"./host-primitives": "./ui-host-primitives.js"
|
|
13
|
+
"./host-primitives": "./ui-host-primitives.js",
|
|
14
|
+
"./orbit-popover": "./ui-orbit-popover.js"
|
|
14
15
|
},
|
|
15
16
|
"files": [
|
|
16
17
|
"lib/index.js",
|
|
@@ -27,6 +28,7 @@
|
|
|
27
28
|
"LICENSE",
|
|
28
29
|
"client.js",
|
|
29
30
|
"ui-host-primitives.js",
|
|
31
|
+
"ui-orbit-popover.js",
|
|
30
32
|
"bin/check.mjs",
|
|
31
33
|
"assets/icon-180.png",
|
|
32
34
|
"docs/whats-new-0.9.md",
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
// L84e:StatusOrbit 的宿主弹层薄适配器。
|
|
2
|
+
// 定位与外点交给 DSH primitives;portal 交给宿主 react-dom 注入的 createPortal。
|
|
3
|
+
// 这里不包含 watcher 轮询、行数据、删除请求、确认 Modal 或另一套定位实现。
|
|
4
|
+
|
|
5
|
+
const DEFAULT_ORBIT_Z_INDEX = 1100
|
|
6
|
+
|
|
7
|
+
function focusIfConnected(node) {
|
|
8
|
+
if (!node || typeof node.focus !== 'function') return false
|
|
9
|
+
if ('isConnected' in node && !node.isConnected) return false
|
|
10
|
+
try {
|
|
11
|
+
node.focus()
|
|
12
|
+
return true
|
|
13
|
+
} catch {
|
|
14
|
+
return false
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function closeReason(detail) {
|
|
19
|
+
// DSH useDismissOnOutsidePointer 固定调用 close(false)。
|
|
20
|
+
if (detail === false) return { reason: 'outside-pointer' }
|
|
21
|
+
if (typeof detail === 'string') return { reason: detail }
|
|
22
|
+
if (detail && typeof detail === 'object' && typeof detail.reason === 'string') return detail
|
|
23
|
+
return { reason: 'dismiss' }
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* 用宿主注入的 React 与 @deepseek-ai/dsh-client-ui-primitives 创建 Orbit 弹层。
|
|
28
|
+
*
|
|
29
|
+
* React.createPortal 必须由调用方从宿主 react-dom 注入;普通 React export 没有它。
|
|
30
|
+
* 缺少任何必需能力都会显式报错,由调用方决定是否完整保留旧实现。
|
|
31
|
+
*/
|
|
32
|
+
export function createOrbitPopover({ React, primitives } = {}) {
|
|
33
|
+
if (!React || typeof React.createElement !== 'function') {
|
|
34
|
+
throw new TypeError('createOrbitPopover 需要宿主 React.createElement')
|
|
35
|
+
}
|
|
36
|
+
for (const hook of ['useRef', 'useCallback', 'useEffect']) {
|
|
37
|
+
if (typeof React[hook] !== 'function') {
|
|
38
|
+
throw new TypeError(`createOrbitPopover 需要宿主 React.${hook}`)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (typeof React.createPortal !== 'function') {
|
|
42
|
+
throw new TypeError('createOrbitPopover 需要宿主 React.createPortal(从 react-dom 注入)')
|
|
43
|
+
}
|
|
44
|
+
if (!primitives || (typeof primitives !== 'object' && typeof primitives !== 'function')) {
|
|
45
|
+
throw new TypeError('createOrbitPopover 需要 DSH primitives')
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const primitive = (name, kind) => {
|
|
49
|
+
const value = primitives[name]
|
|
50
|
+
if (kind === 'function' ? typeof value !== 'function' : !value) {
|
|
51
|
+
throw new Error(`DSH primitives.${name} 不可用;OrbitPopover 不会创建替代弹层`)
|
|
52
|
+
}
|
|
53
|
+
return value
|
|
54
|
+
}
|
|
55
|
+
const useAnchoredPosition = primitive('useAnchoredPosition', 'function')
|
|
56
|
+
const useDismissOnOutsidePointer = primitive('useDismissOnOutsidePointer', 'function')
|
|
57
|
+
const MenuSurface = primitive('MenuSurface')
|
|
58
|
+
const h = React.createElement
|
|
59
|
+
const createPortal = React.createPortal
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* 非 Modal 的 orbit 主 surface。width 必须由调用方按业务内容给出(例如 252/368)。
|
|
63
|
+
* side/align 不开放成 props,避免误传宿主未实现的 center 或虚构自动 flip。
|
|
64
|
+
*/
|
|
65
|
+
function OrbitPopover({
|
|
66
|
+
open,
|
|
67
|
+
anchorRef,
|
|
68
|
+
orbitRef,
|
|
69
|
+
panelRef: suppliedPanelRef,
|
|
70
|
+
onClose,
|
|
71
|
+
width,
|
|
72
|
+
zIndex = DEFAULT_ORBIT_Z_INDEX,
|
|
73
|
+
portalTarget: suppliedPortalTarget,
|
|
74
|
+
className,
|
|
75
|
+
style,
|
|
76
|
+
ariaLabel,
|
|
77
|
+
children,
|
|
78
|
+
} = {}) {
|
|
79
|
+
const internalPanelRef = React.useRef(null)
|
|
80
|
+
const panelRef = suppliedPanelRef || internalPanelRef
|
|
81
|
+
const returnFocusRef = orbitRef || anchorRef
|
|
82
|
+
const onCloseRef = React.useRef(onClose)
|
|
83
|
+
onCloseRef.current = onClose
|
|
84
|
+
|
|
85
|
+
// stable close:父级轮询重渲染只更新 ref,不重建外点 effect 或焦点 effect。
|
|
86
|
+
const close = React.useCallback((detail) => {
|
|
87
|
+
const callback = onCloseRef.current
|
|
88
|
+
if (typeof callback === 'function') callback(closeReason(detail))
|
|
89
|
+
}, [])
|
|
90
|
+
|
|
91
|
+
// 两个宿主 hooks 与本地 effect 都在 if (!open) return 之前无条件调用。
|
|
92
|
+
const position = useAnchoredPosition({
|
|
93
|
+
open: Boolean(open),
|
|
94
|
+
anchorRef,
|
|
95
|
+
panelRef,
|
|
96
|
+
side: 'top',
|
|
97
|
+
align: 'end',
|
|
98
|
+
gap: 8,
|
|
99
|
+
margin: 8,
|
|
100
|
+
})
|
|
101
|
+
useDismissOnOutsidePointer(panelRef, Boolean(open), close, anchorRef)
|
|
102
|
+
|
|
103
|
+
const portalTarget = suppliedPortalTarget === undefined
|
|
104
|
+
? (typeof document !== 'undefined' ? document.body : null)
|
|
105
|
+
: suppliedPortalTarget
|
|
106
|
+
const ownerDocument = portalTarget && portalTarget.ownerDocument
|
|
107
|
+
? portalTarget.ownerDocument
|
|
108
|
+
: (typeof document !== 'undefined' ? document : null)
|
|
109
|
+
|
|
110
|
+
React.useEffect(() => {
|
|
111
|
+
if (!open || !ownerDocument || typeof ownerDocument.addEventListener !== 'function') return undefined
|
|
112
|
+
|
|
113
|
+
// effect 在 portal mount 后运行;非 Modal dialog 自身接收初始焦点,不做焦点陷阱。
|
|
114
|
+
focusIfConnected(panelRef.current)
|
|
115
|
+
const onKeyDown = (event) => {
|
|
116
|
+
if (!event || event.key !== 'Escape' || event.repeat) return
|
|
117
|
+
if (typeof event.preventDefault === 'function') event.preventDefault()
|
|
118
|
+
if (typeof event.stopPropagation === 'function') event.stopPropagation()
|
|
119
|
+
close({ reason: 'escape' })
|
|
120
|
+
}
|
|
121
|
+
ownerDocument.addEventListener('keydown', onKeyDown, true)
|
|
122
|
+
return () => {
|
|
123
|
+
ownerDocument.removeEventListener('keydown', onKeyDown, true)
|
|
124
|
+
// 永远回圆环,不回面板里可能已随关闭/删除卸载的按钮。
|
|
125
|
+
focusIfConnected(returnFocusRef && returnFocusRef.current)
|
|
126
|
+
}
|
|
127
|
+
}, [open, close, ownerDocument, panelRef, returnFocusRef])
|
|
128
|
+
|
|
129
|
+
if (!open) return null
|
|
130
|
+
if (!anchorRef || typeof anchorRef !== 'object') {
|
|
131
|
+
throw new TypeError('OrbitPopover 需要调用方传入 anchorRef')
|
|
132
|
+
}
|
|
133
|
+
if (!Number.isFinite(width) || width <= 0) {
|
|
134
|
+
throw new TypeError('OrbitPopover 需要调用方传入正数 width;适配器不推导业务宽度')
|
|
135
|
+
}
|
|
136
|
+
if (!portalTarget) {
|
|
137
|
+
throw new Error('OrbitPopover portal target 不可用;不会退化为非 portal surface')
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const surface = h(MenuSurface, {
|
|
141
|
+
ref: panelRef,
|
|
142
|
+
role: 'dialog',
|
|
143
|
+
'aria-label': ariaLabel,
|
|
144
|
+
tabIndex: -1,
|
|
145
|
+
className,
|
|
146
|
+
style: {
|
|
147
|
+
...style,
|
|
148
|
+
position: 'fixed',
|
|
149
|
+
left: position ? position.left : 0,
|
|
150
|
+
top: position ? position.top : 0,
|
|
151
|
+
width,
|
|
152
|
+
zIndex,
|
|
153
|
+
// useAnchoredPosition 首帧尚未测量时不在 0,0 闪现;不自行计算另一套坐标。
|
|
154
|
+
visibility: position ? 'visible' : 'hidden',
|
|
155
|
+
},
|
|
156
|
+
}, children)
|
|
157
|
+
return createPortal(surface, portalTarget)
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* 删除确认的调用方策略。此 hook 不创建 Modal,也不保存 watcher/请求状态。
|
|
162
|
+
* requestConfirm 永远先关闭 orbit,再调用可选 onRequestConfirm 打开调用方的确认层。
|
|
163
|
+
*/
|
|
164
|
+
function useOrbitConfirm({ orbitRef, onCloseOrbit, onRequestConfirm } = {}) {
|
|
165
|
+
const orbitRefRef = React.useRef(orbitRef)
|
|
166
|
+
const onCloseOrbitRef = React.useRef(onCloseOrbit)
|
|
167
|
+
const onRequestConfirmRef = React.useRef(onRequestConfirm)
|
|
168
|
+
const restoreFocusRef = React.useRef(null)
|
|
169
|
+
orbitRefRef.current = orbitRef
|
|
170
|
+
onCloseOrbitRef.current = onCloseOrbit
|
|
171
|
+
onRequestConfirmRef.current = onRequestConfirm
|
|
172
|
+
|
|
173
|
+
const requestConfirm = React.useCallback((detail = {}) => {
|
|
174
|
+
restoreFocusRef.current = 'orbit'
|
|
175
|
+
if (typeof onCloseOrbitRef.current === 'function') {
|
|
176
|
+
onCloseOrbitRef.current({ reason: 'confirm' })
|
|
177
|
+
}
|
|
178
|
+
const request = onRequestConfirmRef.current
|
|
179
|
+
if (typeof request === 'function') {
|
|
180
|
+
const extra = detail && typeof detail === 'object' ? detail : { value: detail }
|
|
181
|
+
return request({ ...extra, reason: 'confirm', restoreFocus: 'orbit' })
|
|
182
|
+
}
|
|
183
|
+
return undefined
|
|
184
|
+
}, [])
|
|
185
|
+
|
|
186
|
+
const onConfirmClose = React.useCallback(() => {
|
|
187
|
+
if (restoreFocusRef.current !== 'orbit') return false
|
|
188
|
+
restoreFocusRef.current = null
|
|
189
|
+
const ref = orbitRefRef.current
|
|
190
|
+
// 特意只读取圆环 ref;requestConfirm 的删除按钮/opener 不参与焦点归还。
|
|
191
|
+
return focusIfConnected(ref && ref.current)
|
|
192
|
+
}, [])
|
|
193
|
+
|
|
194
|
+
return {
|
|
195
|
+
onRequestConfirm: requestConfirm,
|
|
196
|
+
onConfirmClose,
|
|
197
|
+
restoreFocus: restoreFocusRef.current,
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return { OrbitPopover, useOrbitConfirm }
|
|
202
|
+
}
|