dsh-plugin-greeting-bubble 1.0.0 → 1.1.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/README.md CHANGED
@@ -30,9 +30,10 @@
30
30
 
31
31
  - 页面加载约 0.35 秒后,右下角(距右 20px、距底 84px,即输入框发送按钮上方)淡入气泡:👋 你好,腾盛 ×
32
32
  - 点气泡右侧的 **×** 关闭;关闭只对当前页面生效,**刷新页面后会再次出现**。
33
- - 位置刻意抬高到输入框上方:不会盖住发送按钮;气泡本体点击穿透,只有 × 可点,因此也不会拦住下面的输入框或右侧按钮。
34
- - 在「插件」「设置」等页面同样显示(浮层属于整个应用框架),但**不会拦截点击**:整颗气泡只有 × 接收点击,其余区域点击照常落到下面的界面。
35
- - 进入动画在系统开启“减少动态效果”时自动关闭;窄窗口下气泡最大宽度自动收缩,不会顶出屏幕。
33
+ - **按住气泡可以拖动**:光标变成抓手,拖到任意位置松手即可;位置会记在浏览器里,下次打开(包括刷新)仍在原处。
34
+ - 默认位置刻意抬到输入框上方,不会盖住发送按钮;拖动后由你决定位置。气泡本体需要接收拖动事件,所以它所在的小块区域会接住点击,其余区域不受影响。
35
+ - 在「插件」「设置」等页面同样显示(浮层属于整个应用框架)。
36
+ - 进入动画在系统开启“减少动态效果”时自动关闭;窄窗口下气泡最大宽度自动收缩,不会被拖出屏幕(拖动时自动限制在可视区内)。
36
37
 
37
38
  ## 安装
38
39
 
@@ -85,8 +86,9 @@ git clone https://github.com/liwei169/dsh-plugin-greeting-bubble.git
85
86
  | 操作 | 结果 |
86
87
  | --- | --- |
87
88
  | 页面加载 | 气泡出现(每个页面视图一次) |
89
+ | **按住气泡拖动** | 气泡跟着指针移动,松手后记住位置 |
88
90
  | 点 ×(或聚焦后按 Enter / Space) | 本次页面隐藏气泡 |
89
- | 刷新页面 | 气泡再次出现 |
91
+ | 刷新页面 | 气泡再次出现,位置保持上次拖到的位置 |
90
92
  | 插件页关闭该包的开关 | 气泡立即消失(HMR 生效时无需刷新) |
91
93
  | 插件页卸载该包 | 彻底移除,不再出现 |
92
94
 
@@ -105,9 +107,9 @@ en: { greeting: '你好,腾盛', dismiss: 'Dismiss greeting' },
105
107
 
106
108
  问候语刻意在两种语言下保持一致(它是这个插件固定的“签名语”),只有关闭按钮的提示文字跟随界面语言。想让英文界面显示英文问候,把 `en.greeting` 改成 `Hello, Tengsheng` 即可。
107
109
 
108
- ### 2. 改位置 / 间距
110
+ ### 2. 改默认位置 / 拖动记忆
109
111
 
110
- `client.js` 中的 `.dsh-greeting-bubble`:
112
+ 默认位置在 `client.js` 的 `.dsh-greeting-bubble` 里:
111
113
 
112
114
  ```css
113
115
  right: calc(20px + env(safe-area-inset-right, 0px));
@@ -116,6 +118,14 @@ bottom: calc(84px + env(safe-area-inset-bottom, 0px)); /* 输入框发送按钮
116
118
 
117
119
  改成 `left` / `top` 就能换角;把 `20px` 调大即离边更远。`bottom` 不要低于 `84px`:DSH 的发送按钮在输入卡右下角,贴近底边会在窄窗口下盖住它。
118
120
 
121
+ 拖动后的位置保存在 localStorage 的 `dsh-greeting-bubble:position:v1` 键里。想恢复默认位置,在浏览器控制台执行:
122
+
123
+ ```js
124
+ localStorage.removeItem('dsh-greeting-bubble:position:v1')
125
+ ```
126
+
127
+ 然后刷新页面即可。
128
+
119
129
  ### 3. 改视觉
120
130
 
121
131
  - 圆角、描边、阴影:`--dsw-radius-lg`、`--dsw-elevation-stroke-color`、`--dsw-elevation-prominent`,与 DSH 原生浮层一致;
@@ -175,13 +185,14 @@ package.json
175
185
  几个关键设计点:
176
186
 
177
187
  1. **渲染位置选 `shell.overlay`**:这是 `@deepseek-ai/dsh-client-ui-layout` 声明的整帧浮层(`position: absolute; inset: 0; z-index: 20; pointer-events: none`),位于所有列之上、列滚动容器之外,适合徽标、Toast、状态胶囊这类覆盖层。注册时用一个新 `id`(`greeting-bubble`)就是**追加**一条,不会替换自带的条目。
178
- 2. **两层点击穿透**:浮层本身 `pointer-events: none`,但它的每个直接子元素默认 `pointer-events: auto`。插件根节点显式设为 `none`;气泡卡片同样设为 `none`,只把 × 按钮设回 `auto`。这样即使气泡在窄窗口下与输入框有少量几何重叠,点击也会落到下面的真实控件上,不会“抢”发送或输入。
179
- 3. **高度避让**:气泡距底 `84px`,位于输入卡发送按钮(34px 圆钮)之上;发送按钮始终露出来,不被问候语遮挡。
180
- 4. **生命周期归 Cordis 管**:所有注册都放在 `ctx.effect` / `ctx.slots.inject` 里。`slots.inject` 会在槽声明存在时注册、声明消失时注销;插件停用或卸载时整个 fiber 被销毁,气泡和字典一起被清理,不需要手写 DOM 清理。
181
- 5. **工厂无副作用**:`client.js` 顶层只调用 `__ModuleLoader__.load`,真正的注册发生在 `apply()`;模块体不碰 DOM、不开定时器。
182
- 6. **样式走主题变量**:气泡用 `--dsw-alias-bg-layer-3`、`--dsw-alias-border-l3`、`--dsw-alias-label-primary`、`--dsw-alias-interactive-bg-hover` 等 token,亮/暗主题自动切换;组件内的 `<style>` 随组件卸载一起移除。
183
- 7. **文案走 locale**:`locale: NS` 让框架把 `t` 注入组件,切换界面语言时文案实时更新,无需重载。
184
- 8. **Host 端为空**:`index.js` 只导出 `export function apply() {}`。插件不注册工具、不发请求、不写会话日志,因此对模型和会话完全透明。
188
+ 2. **浮层穿透、气泡可交互**:浮层本身 `pointer-events: none`,它的直接子元素默认 `auto`。插件根节点设为 `none`;气泡卡片设回 `auto`——它必须接收指针事件才能拖动。因此只有气泡这一块会接住点击,浮层的其余区域完全穿透。
189
+ 3. **拖动实现**:`pointerdown` 时记录起始坐标与气泡矩形并 `setPointerCapture`,`pointermove` 按位移计算新坐标、限制在可视区内,`pointerup` 保存到 `localStorage` 并释放捕获;窗口缩放时也会把气泡夹回屏幕内(`ResizeObserver` 不需要,监听 `resize` 即可)。
190
+ 4. **高度避让**:默认距底 `84px`,位于输入卡发送按钮(34px 圆钮)之上;发送按钮始终露出来,不被问候语遮挡。拖动后以用户选择为准。
191
+ 5. **生命周期归 Cordis 管**:所有注册都放在 `ctx.effect` / `ctx.slots.inject` 里。`slots.inject` 会在槽声明存在时注册、声明消失时注销;插件停用或卸载时整个 fiber 被销毁,气泡和字典一起被清理,不需要手写 DOM 清理。
192
+ 6. **工厂无副作用**:`client.js` 顶层只调用 `__ModuleLoader__.load`,真正的注册发生在 `apply()`;模块体不碰 DOM、不开定时器。
193
+ 7. **样式走主题变量**:气泡用 `--dsw-alias-bg-layer-3`、`--dsw-alias-border-l3`、`--dsw-alias-label-primary`、`--dsw-alias-interactive-bg-hover` 等 token,亮/暗主题自动切换;组件内的 `<style>` 随组件卸载一起移除。
194
+ 8. **文案走 locale**:`locale: NS` 让框架把 `t` 注入组件,切换界面语言时文案实时更新,无需重载。
195
+ 9. **Host 端为空**:`index.js` 只导出 `export function apply() {}`。插件不注册工具、不发请求、不写会话日志,因此对模型和会话完全透明。
185
196
 
186
197
  ## 文件结构
187
198
 
@@ -237,16 +248,17 @@ node test/smoke.mjs
237
248
  - 面向 **DSH Web 客户端**(`dsh.client.platform: web`):桌面版窗口和浏览器版都适用;CLI / headless 模式没有界面,插件不产生任何效果。
238
249
  - 依赖 `shell.overlay` 槽;更老的 DSH 版本没有该槽时,插件会安静地不显示,不会报错。
239
250
  - 每次页面加载都会出现一次,不记忆关闭状态(如需记忆见[自定义](#自定义))。
240
- - 浮层位于整帧之上:气泡距右下角 20px、位于输入框上方(84px),窄窗口下可能与输入卡右上区域有少量视觉重叠,但气泡本身点击穿透,不会挡住输入、发送或页面按钮;点 × 即可关闭。
251
+ - 浮层位于整帧之上:气泡默认在右下角、输入框上方(距右 20px、距底 84px),可以拖到任意位置;拖动后位置记在 localStorage 里(`dsh-greeting-bubble:position:v1`)。气泡本体需要接收拖动事件,所以它所在的那一小块会接住点击,其余区域不受影响。
241
252
  - 问候语固定为中文,在任何界面语言下都不翻译;只有关闭按钮的提示文字跟随语言。
242
253
  - 插件只在本地运行,不访问网络。
243
254
 
244
255
  ## English
245
256
 
246
- A tiny DeepSeek Harness Web UI plugin that shows a “你好,腾盛” speech bubble in the bottom-right corner after the page loads. Click × to dismiss it; it returns on the next page load.
257
+ A tiny DeepSeek Harness Web UI plugin that shows a “你好,腾盛” speech bubble near the bottom-right corner after the page loads. Click × to dismiss it; it returns on the next page load. The bubble can be dragged anywhere, and its position is remembered in localStorage.
247
258
 
248
- - Install: **Plugins → Add plugin** → `https://github.com/liwei169/dsh-plugin-greeting-bubble` (or `github:liwei169/dsh-plugin-greeting-bubble`).
259
+ - Install: **Plugins → Add plugin** → `dsh-plugin-greeting-bubble` (npm), or `https://github.com/liwei169/dsh-plugin-greeting-bubble` (GitHub).
249
260
  - It registers one entry into the frame-wide `shell.overlay` slot, uses `--dsw-alias-*` theme tokens, localizes its close label, and keeps every registration inside `ctx.effect` / `ctx.slots.inject` so disabling the bundle removes the bubble again.
261
+ - Dragging uses pointer capture, clamps to the viewport, and saves the dropped position under `dsh-greeting-bubble:position:v1`.
250
262
  - No network access, no data collection, no model-facing behavior.
251
263
 
252
264
  Tested with DeepSeek Harness 0.2.2-rc.5.
package/client.js CHANGED
@@ -7,10 +7,14 @@
7
7
  * the bundle removes the bubble again without a reload.
8
8
  *
9
9
  * Rendering surface: the `shell.overlay` list slot declared by
10
- * `@deepseek-ai/dsh-client-ui-layout`. It is a frame-wide, click-through layer
11
- * above every column, so the bubble floats over the whole app without moving
12
- * any host control. Registering a fresh `id` adds an entry beside the shipped
13
- * ones instead of replacing them.
10
+ * `@deepseek-ai/dsh-client-ui-layout`. It is a frame-wide layer above every
11
+ * column, so the bubble floats over the whole app without moving any host
12
+ * control. Registering a fresh `id` adds an entry beside the shipped ones
13
+ * instead of replacing them.
14
+ *
15
+ * The bubble is draggable: pointer capture keeps the drag smooth, the card is
16
+ * clamped to the viewport, and the chosen spot is remembered in localStorage
17
+ * under `POSITION_KEY`.
14
18
  */
15
19
  window.__ModuleLoader__.load({
16
20
  id: 'dsh-plugin-greeting-bubble',
@@ -21,16 +25,49 @@ window.__ModuleLoader__.load({
21
25
  /** Locale namespace owned by this plugin (registered in `apply`). */
22
26
  const NS = 'greetingBubble';
23
27
 
28
+ /** Where the reader last dropped the bubble, as viewport px. */
29
+ const POSITION_KEY = 'dsh-greeting-bubble:position:v1';
30
+
31
+ /** Read the remembered spot; a corrupt or absent value means "default". */
32
+ function readPosition() {
33
+ try {
34
+ const raw = window.localStorage.getItem(POSITION_KEY);
35
+ if (!raw) return null;
36
+ const value = JSON.parse(raw);
37
+ if (typeof value?.x === 'number' && typeof value?.y === 'number') {
38
+ return { x: value.x, y: value.y };
39
+ }
40
+ } catch {
41
+ // Private mode, blocked storage, or malformed JSON: fall through.
42
+ }
43
+ return null;
44
+ }
45
+
46
+ /** Persist the dropped spot; failures must never break the bubble. */
47
+ function writePosition(position) {
48
+ try {
49
+ window.localStorage.setItem(POSITION_KEY, JSON.stringify(position));
50
+ } catch {
51
+ // Storage unavailable: position simply does not survive the reload.
52
+ }
53
+ }
54
+
55
+ /** Keep a value inside [min, max], tolerating a viewport smaller than the card. */
56
+ function clamp(value, min, max) {
57
+ return Math.max(min, Math.min(value, Math.max(min, max)));
58
+ }
59
+
24
60
  /**
25
61
  * Component-local stylesheet; unmounting the entry removes it with the
26
62
  * node.
27
63
  *
28
64
  * Placement notes:
29
- * - 84px above the bottom edge clears the composer's 34px send button and
30
- * its card padding, so the greeting never covers the primary control.
31
- * - The card itself is click-through (`pointer-events: none`); only the
32
- * dismiss button opts back in, so a residual overlap can never swallow a
33
- * click meant for the app underneath.
65
+ * - The default spot is 84px above the bottom edge, which clears the
66
+ * composer's 34px send button and its card padding.
67
+ * - Once dragged, the card switches to explicit `left`/`top` coordinates
68
+ * and the reader's choice is remembered.
69
+ * - The card now receives pointer events itself (it must, to be dragged);
70
+ * only the layer around it stays click-through.
34
71
  * - Radii and elevation reuse the host tokens, so the bubble reads as one
35
72
  * of the app's own floating surfaces in both themes.
36
73
  */
@@ -59,9 +96,15 @@ window.__ModuleLoader__.load({
59
96
  box-shadow: var(--dsw-elevation-prominent, 0 4px 16px rgba(0, 0, 0, 0.12));
60
97
  font-size: 13px;
61
98
  line-height: 20px;
62
- pointer-events: none;
99
+ cursor: grab;
100
+ touch-action: none;
101
+ user-select: none;
102
+ pointer-events: auto;
63
103
  animation: dsh-greeting-in 320ms cubic-bezier(0.22, 0.8, 0.24, 1) 350ms both;
64
104
  }
105
+ .dsh-greeting-bubble[data-dragging] {
106
+ cursor: grabbing;
107
+ }
65
108
  .dsh-greeting-wave {
66
109
  flex: none;
67
110
  font-size: 16px;
@@ -120,16 +163,102 @@ window.__ModuleLoader__.load({
120
163
  */
121
164
  function GreetingBubble({ t }) {
122
165
  const [dismissed, setDismissed] = React.useState(false);
166
+ const [position, setPosition] = React.useState(readPosition);
167
+ const [dragging, setDragging] = React.useState(false);
168
+ const bubbleRef = React.useRef(null);
169
+ const dragRef = React.useRef(null);
170
+
171
+ // Keep a remembered spot on screen when the window shrinks.
172
+ React.useEffect(() => {
173
+ function handleResize() {
174
+ setPosition((current) => {
175
+ const element = bubbleRef.current;
176
+ if (current === null || element === null) return current;
177
+ const x = clamp(current.x, 0, window.innerWidth - element.offsetWidth);
178
+ const y = clamp(current.y, 0, window.innerHeight - element.offsetHeight);
179
+ return x === current.x && y === current.y ? current : { x, y };
180
+ });
181
+ }
182
+ window.addEventListener('resize', handleResize);
183
+ return () => { window.removeEventListener('resize', handleResize); };
184
+ }, []);
185
+
123
186
  if (dismissed) return null;
124
187
  const text = typeof t === 'function' ? t('greeting') : '你好,腾盛';
125
188
  const dismissLabel = typeof t === 'function' ? t('dismiss') : '关闭问候气泡';
189
+
190
+ /** Start a drag: switch to absolute coordinates and capture the pointer. */
191
+ function handlePointerDown(event) {
192
+ if (event.button !== undefined && event.button !== 0) return;
193
+ if (event.target && event.target.closest && event.target.closest('button')) return;
194
+ const element = bubbleRef.current;
195
+ if (!element) return;
196
+ const rect = element.getBoundingClientRect();
197
+ dragRef.current = {
198
+ pointerId: event.pointerId,
199
+ startX: event.clientX,
200
+ startY: event.clientY,
201
+ left: rect.left,
202
+ top: rect.top,
203
+ width: rect.width,
204
+ height: rect.height,
205
+ };
206
+ setPosition({ x: rect.left, y: rect.top });
207
+ setDragging(true);
208
+ if (typeof element.setPointerCapture === 'function') {
209
+ element.setPointerCapture(event.pointerId);
210
+ }
211
+ event.preventDefault();
212
+ }
213
+
214
+ /** Move within the viewport while the pointer is captured. */
215
+ function handlePointerMove(event) {
216
+ const drag = dragRef.current;
217
+ if (drag === null || event.pointerId !== drag.pointerId) return;
218
+ const x = drag.left + event.clientX - drag.startX;
219
+ const y = drag.top + event.clientY - drag.startY;
220
+ setPosition({
221
+ x: clamp(x, 0, window.innerWidth - drag.width),
222
+ y: clamp(y, 0, window.innerHeight - drag.height),
223
+ });
224
+ }
225
+
226
+ /** Finish a drag, clamp once more, and persist the dropped spot. */
227
+ function handlePointerUp(event) {
228
+ const drag = dragRef.current;
229
+ if (drag === null || event.pointerId !== drag.pointerId) return;
230
+ dragRef.current = null;
231
+ setDragging(false);
232
+ const element = bubbleRef.current;
233
+ if (!element) return;
234
+ const rect = element.getBoundingClientRect();
235
+ const dropped = {
236
+ x: Math.round(clamp(rect.left, 0, window.innerWidth - rect.width)),
237
+ y: Math.round(clamp(rect.top, 0, window.innerHeight - rect.height)),
238
+ };
239
+ setPosition(dropped);
240
+ writePosition(dropped);
241
+ }
242
+
126
243
  return h(
127
244
  'div',
128
245
  { className: 'dsh-greeting-layer', style: { position: 'absolute', inset: 0, pointerEvents: 'none' } },
129
246
  h('style', { key: 'styles' }, STYLES),
130
247
  h(
131
248
  'div',
132
- { className: 'dsh-greeting-bubble', key: 'bubble' },
249
+ {
250
+ key: 'bubble',
251
+ ref: bubbleRef,
252
+ className: 'dsh-greeting-bubble',
253
+ 'data-dragging': dragging ? '' : undefined,
254
+ style: position === null
255
+ ? undefined
256
+ : { left: position.x, top: position.y, right: 'auto', bottom: 'auto' },
257
+ onPointerDown: handlePointerDown,
258
+ onPointerMove: handlePointerMove,
259
+ onPointerUp: handlePointerUp,
260
+ onPointerCancel: handlePointerUp,
261
+ },
133
262
  h('span', { className: 'dsh-greeting-wave', 'aria-hidden': 'true' }, '👋'),
134
263
  // `lang` pins the reading voice for this fixed Chinese phrase; the
135
264
  // status role lives on the text so the dismiss button stays outside
package/locale/en.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "meta": {
3
3
  "title": "Greeting bubble",
4
- "description": "Shows a “你好,腾盛” speech bubble near the bottom-right corner of the window, just above the message composer, after the page loads. Click × to dismiss it; it appears again on the next page load. The greeting stays Chinese in every interface language; only the close-button label is localized. The bubble is click-through except for the close button, makes no network requests, collects no data, and changes nothing else in the app. Disable or remove the bundle under Plugins to remove it.",
4
+ "description": "Shows a “你好,腾盛” speech bubble near the bottom-right corner of the window, just above the message composer, after the page loads. Drag the bubble anywhere; its position is remembered for the next visit. Click × to dismiss it; it appears again on the next page load. The greeting stays Chinese in every interface language; only the close-button label is localized. The plugin makes no network requests, collects no data, and changes nothing else in the app. Disable or remove the bundle under Plugins to remove it.",
5
5
  "detail": "docs/DETAIL.md"
6
6
  }
7
7
  }
package/locale/zh.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "meta": {
3
3
  "title": "右下角问候气泡",
4
- "description": "页面加载后,在窗口右下角、输入框上方弹出「你好,腾盛」问候气泡。点气泡上的 × 即可关闭,下次页面加载时会再次出现。问候语在任何界面语言下都保持中文,只有关闭按钮的提示文字跟随界面语言。气泡本体点击穿透,只有 × 可点;插件不联网、不收集数据,除气泡外不改变任何界面。在「插件」页停用或移除本插件即可彻底去掉。",
4
+ "description": "页面加载后,在窗口右下角、输入框上方弹出「你好,腾盛」问候气泡。按住气泡可以拖到任意位置,位置会记住,下次打开仍在原处。点气泡上的 × 即可关闭,下次页面加载时会再次出现。问候语在任何界面语言下都保持中文,只有关闭按钮的提示文字跟随界面语言。插件不联网、不收集数据,除气泡外不改变任何界面。在「插件」页停用或移除本插件即可彻底去掉。",
5
5
  "detail": "docs/DETAIL.zh.md"
6
6
  }
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-plugin-greeting-bubble",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Shows a “你好,腾盛” speech bubble in the bottom-right corner of the DeepSeek Harness Web GUI.",
5
5
  "license": "MIT",
6
6
  "publishConfig": {