@lyra_wang/dsh-quick-commands 0.1.0 → 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 +5 -1
  2. package/client.js +44 -6
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -24,6 +24,7 @@
24
24
 
25
25
  ## 边界
26
26
 
27
+ - 面板位置按可用空间选边(上/下),高度按窗口收;窗口太矮时贴到视口内并滚动
27
28
  - 内容上限 8000 字、最多 300 条(防止一个手滑塞满)
28
29
  - 插入是普通文本编辑,可撤销;发送会把当前草稿替换成该条内容
29
30
  - 只在本机,不跨设备同步
@@ -38,4 +39,7 @@ node --test test/store.test.mjs
38
39
 
39
40
  ## 版本
40
41
 
41
- 0.1.0 — 首个版本:全局常用指令清单、输入框按钮、面板搜索、插入 / 发送 / 编辑 / 删除。
42
+ - 0.1.3 — 面板跟随输入框宽度与位置:左右侧栏打开/关闭时重新锚定,宽度不越过输入框区域。
43
+ - 0.1.2 — 按钮文字不再被挤成竖排(flex:none + nowrap)。
44
+ - 0.1.1 — 面板不再超出可视区域:按按钮上/下的剩余空间选展开方向,宽高都夹在视口内,列表自身滚动。
45
+ - 0.1.0 — 首个版本:全局常用指令清单、输入框按钮、面板搜索、插入 / 发送 / 编辑 / 删除。
package/client.js CHANGED
@@ -108,8 +108,9 @@ window.__ModuleLoader__.load({
108
108
 
109
109
  const CSS = [
110
110
  '.dsh-quick-commands-btn{all:unset;box-sizing:border-box;display:inline-flex;align-items:center;gap:4px;height:26px;',
111
- ' padding:0 8px;border-radius:var(--dsw-radius-sm,8px);cursor:pointer;font-size:12px;',
111
+ ' flex:none;white-space:nowrap;padding:0 8px;border-radius:var(--dsw-radius-sm,8px);cursor:pointer;font-size:12px;',
112
112
  ' color:var(--dsw-alias-label-secondary,#b9b9c0)}',
113
+ '.dsh-quick-commands-btn > span{white-space:nowrap}',
113
114
  '.dsh-quick-commands-btn:hover{background:var(--dsw-alias-interactive-bg-hover,#ffffff14);color:var(--dsw-alias-label-primary,#e8e8ea)}',
114
115
  '.dsh-quick-commands-panel{position:fixed;z-index:60;width:352px;max-height:420px;display:flex;flex-direction:column;',
115
116
  ' background:var(--dsw-alias-bg-layer-1,#1f1f22);border:0.5px solid var(--dsw-alias-border-l3,#ffffff1f);',
@@ -186,9 +187,37 @@ window.__ModuleLoader__.load({
186
187
  const node = btnRef.current
187
188
  if (!node) return
188
189
  const rect = node.getBoundingClientRect()
189
- const width = 352
190
- const left = Math.max(12, Math.min(rect.left, window.innerWidth - width - 12))
191
- setAnchor({ left, bottom: window.innerHeight - rect.top + 8 })
190
+ const margin = 12
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)))
198
+ const above = rect.top - margin
199
+ const below = window.innerHeight - rect.bottom - margin
200
+ const openUp = above >= 240 || above >= below
201
+ const room = Math.max(openUp ? above : below, 0)
202
+ let next
203
+ if (room >= 160) {
204
+ const maxHeight = Math.min(420, room - 8)
205
+ next = openUp
206
+ ? { left, width, maxHeight, bottom: window.innerHeight - rect.top + 8 }
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 }
211
+ }
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
+ })
192
221
  }, [])
193
222
 
194
223
  const toggle = useCallback(() => {
@@ -217,13 +246,20 @@ window.__ModuleLoader__.load({
217
246
  if (event.key === 'Escape') setOpen(false)
218
247
  }
219
248
  const onResize = () => place()
249
+ const onScroll = () => place()
220
250
  document.addEventListener('mousedown', onDown)
221
251
  document.addEventListener('keydown', onKey)
222
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)
223
257
  return () => {
258
+ clearInterval(timer)
224
259
  document.removeEventListener('mousedown', onDown)
225
260
  document.removeEventListener('keydown', onKey)
226
261
  window.removeEventListener('resize', onResize)
262
+ window.removeEventListener('scroll', onScroll, true)
227
263
  }
228
264
  }, [open, place])
229
265
 
@@ -298,7 +334,9 @@ window.__ModuleLoader__.load({
298
334
  key: 'panel',
299
335
  ref: panelRef,
300
336
  className: ROOT + '-panel',
301
- style: { left: anchor.left + 'px', bottom: anchor.bottom + 'px' },
337
+ style: anchor.top !== undefined
338
+ ? { left: anchor.left + 'px', width: anchor.width + 'px', maxHeight: anchor.maxHeight + 'px', top: anchor.top + 'px' }
339
+ : { left: anchor.left + 'px', width: anchor.width + 'px', maxHeight: anchor.maxHeight + 'px', bottom: anchor.bottom + 'px' },
302
340
  }, [
303
341
  h('div', { key: 'head', className: ROOT + '-head' }, [
304
342
  h('span', { key: 'title', className: ROOT + '-title' }, t('panel.title')),
@@ -407,4 +445,4 @@ window.__ModuleLoader__.load({
407
445
  },
408
446
  }
409
447
  },
410
- })
448
+ })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lyra_wang/dsh-quick-commands",
3
- "version": "0.1.0",
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",