@lyra_wang/dsh-quick-commands 0.1.2 → 0.1.3

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.
Files changed (3) hide show
  1. package/README.md +1 -0
  2. package/client.js +30 -8
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -39,6 +39,7 @@ node --test test/store.test.mjs
39
39
 
40
40
  ## 版本
41
41
 
42
+ - 0.1.3 — 面板跟随输入框宽度与位置:左右侧栏打开/关闭时重新锚定,宽度不越过输入框区域。
42
43
  - 0.1.2 — 按钮文字不再被挤成竖排(flex:none + nowrap)。
43
44
  - 0.1.1 — 面板不再超出可视区域:按按钮上/下的剩余空间选展开方向,宽高都夹在视口内,列表自身滚动。
44
45
  - 0.1.0 — 首个版本:全局常用指令清单、输入框按钮、面板搜索、插入 / 发送 / 编辑 / 删除。
package/client.js CHANGED
@@ -188,21 +188,36 @@ window.__ModuleLoader__.load({
188
188
  if (!node) return
189
189
  const rect = node.getBoundingClientRect()
190
190
  const margin = 12
191
- const width = Math.min(352, window.innerWidth - margin * 2)
192
- const left = Math.max(margin, Math.min(rect.left, window.innerWidth - width - margin))
191
+ const host = node.parentElement
192
+ const hostRect = host ? host.getBoundingClientRect() : null
193
+ const usable = hostRect && hostRect.width > 120 ? Math.max(200, hostRect.width - 16) : 352
194
+ const width = Math.min(352, Math.max(240, Math.min(window.innerWidth - margin * 2, usable)))
195
+ const minLeft = Math.max(margin, hostRect ? hostRect.left : margin)
196
+ const maxLeft = Math.min(window.innerWidth - width - margin, hostRect ? hostRect.right - width : window.innerWidth - width - margin)
197
+ const left = Math.max(minLeft, Math.min(rect.left, Math.max(minLeft, maxLeft)))
193
198
  const above = rect.top - margin
194
199
  const below = window.innerHeight - rect.bottom - margin
195
200
  const openUp = above >= 240 || above >= below
196
201
  const room = Math.max(openUp ? above : below, 0)
202
+ let next
197
203
  if (room >= 160) {
198
204
  const maxHeight = Math.min(420, room - 8)
199
- setAnchor(openUp
205
+ next = openUp
200
206
  ? { left, width, maxHeight, bottom: window.innerHeight - rect.top + 8 }
201
- : { left, width, maxHeight, top: rect.bottom + 8 })
202
- return
207
+ : { left, width, maxHeight, top: rect.bottom + 8 }
208
+ } else {
209
+ // Neither side has room: pin to the viewport and let the list scroll.
210
+ next = { left, width, maxHeight: Math.max(160, window.innerHeight - margin * 2), top: margin }
203
211
  }
204
- // Neither side has room: pin to the viewport and let the list scroll.
205
- setAnchor({ left, width, maxHeight: Math.max(160, window.innerHeight - margin * 2), top: margin })
212
+ setAnchor((current) => {
213
+ if (current
214
+ && current.left === next.left
215
+ && current.width === next.width
216
+ && current.maxHeight === next.maxHeight
217
+ && current.top === next.top
218
+ && current.bottom === next.bottom) return current
219
+ return next
220
+ })
206
221
  }, [])
207
222
 
208
223
  const toggle = useCallback(() => {
@@ -231,13 +246,20 @@ window.__ModuleLoader__.load({
231
246
  if (event.key === 'Escape') setOpen(false)
232
247
  }
233
248
  const onResize = () => place()
249
+ const onScroll = () => place()
234
250
  document.addEventListener('mousedown', onDown)
235
251
  document.addEventListener('keydown', onKey)
236
252
  window.addEventListener('resize', onResize)
253
+ window.addEventListener('scroll', onScroll, true)
254
+ // Sidebars opening or the composer reflowing move the button without a
255
+ // resize event; re-anchor while the panel is open.
256
+ const timer = setInterval(() => place(), 400)
237
257
  return () => {
258
+ clearInterval(timer)
238
259
  document.removeEventListener('mousedown', onDown)
239
260
  document.removeEventListener('keydown', onKey)
240
261
  window.removeEventListener('resize', onResize)
262
+ window.removeEventListener('scroll', onScroll, true)
241
263
  }
242
264
  }, [open, place])
243
265
 
@@ -423,4 +445,4 @@ window.__ModuleLoader__.load({
423
445
  },
424
446
  }
425
447
  },
426
- })
448
+ })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lyra_wang/dsh-quick-commands",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Quick commands for DeepSeek Harness: one button next to the composer keeps your reusable snippets, inserts them as editable text, or sends one in a click.",
5
5
  "license": "MIT",
6
6
  "type": "module",