dsh-better-sidebar-left 0.1.1 → 0.2.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/CHANGELOG.md CHANGED
@@ -10,7 +10,7 @@
10
10
  首个版本。把五个「会话管理类」插件合并成一个聚合包,插件列表里只出现一行。
11
11
 
12
12
  - 组件(全部从 **GitHub 仓库的本地检出** vendor,不从 npm 取):
13
- `dsh-delete-session` 0.5.0、`dsh-session-relocate` 0.3.1、`dsh-session-rename-dblclick` 0.1.4、
13
+ `dsh-delete-session` 0.5.0、`dsh-session-relocate` 0.3.1、`dsh-session-rename-dblclick` 0.3.0、
14
14
  `dsh-session-counts` 0.0.3、`dsh-declutter` 0.2.0。
15
15
  每个的上游 commit 钉在 `package.json` 的 `dsh.vendorSources`,`npm run verify:manifest` 离线核对。
16
16
  - 单一行身份:`cordis.patch.yml` 插 1 行裸包名 + 5 行 `dsh-better-sidebar-left/<后缀>`;
@@ -31,4 +31,4 @@
31
31
  `dsh-declutter` 的 npm 历史曾经和仓库不一致:`0.1.2` / `0.1.3` 只有**侧栏半部**
32
32
  (`src/index.js` 是 98 字节空壳)。`0.2.0`(两半合一 + 命名会话修复)已于 2026-11-21
33
33
  发布到 npm,`latest` 指向它;但本包的取源仍然按 GitHub commit 钉住,理由与另外四个一致:
34
- commit 是可复现的,dist-tag 不是。
34
+ commit 是可复现的,dist-tag 不是。
package/README.en.md CHANGED
@@ -11,7 +11,7 @@ Five session-management plugins in one install. **The plugin list grows by exact
11
11
  |---|---|
12
12
  | `dsh-delete-session` 0.5.0 | **Delete a session** from the sidebar row menu: a risk list (log, workspace files, quarantine folder) first, nothing touched until you confirm; plus a multi-select footer bar for batches |
13
13
  | `dsh-session-relocate` 0.3.1 | **Move across workspaces**: row menu, context menu, or drag the session row onto the target workspace - a crash-recoverable transaction, open-but-idle sessions included |
14
- | `dsh-session-rename-dblclick` 0.1.4 | **Rename in place**: one click on the header title, a double click on a sidebar row; the pill follows the shipped title (40px, 22px radius, outline on hover, brand ring while editing), Enter saves, Esc cancels |
14
+ | `dsh-session-rename-dblclick` 0.3.0 | **Rename in place**: one click on the header title, a double click on a sidebar row; the pill follows the shipped title (40px, 22px radius, outline on hover, brand ring while editing), Enter saves, Esc cancels |
15
15
  | `dsh-session-counts` 0.0.3 | **Per-workspace counts**: a badge at the end of each workspace row and a total next to the section label, following the archived filter |
16
16
  | `dsh-declutter` 0.2.0 | **Declutter**: failed/empty/synthesised turns fold away per a rule table (view attributes only, reversible, log untouched) + sidebar tidying (brand row, New session, More buttons, top gap, panel visibility and order) |
17
17
 
package/README.md CHANGED
@@ -10,7 +10,7 @@
10
10
  |---|---|
11
11
  | `dsh-delete-session` 0.5.0 | 侧栏会话行「…」菜单里的**删除会话**:先给风险清单(日志 / 工作区文件 / 隔离目录),确认后才动手;另有批量多选底栏 |
12
12
  | `dsh-session-relocate` 0.3.1 | **跨工作区移动**:会话行「…」菜单、右键菜单、直接把会话行拖到目标工作区;崩溃可恢复的事务,打开中但空闲的会话也能搬 |
13
- | `dsh-session-rename-dblclick` 0.1.4 | **就地改名**:顶栏标题单击、侧栏行双击;胶囊尺寸/配色照官方标题(40px、22px 圆角、悬停描边、聚焦品牌色),Enter 存 / Esc 取消 |
13
+ | `dsh-session-rename-dblclick` 0.3.0 | **就地改名**:顶栏标题单击、侧栏行双击;胶囊尺寸/配色照官方标题(40px、22px 圆角、悬停描边、聚焦品牌色),Enter 存 / Esc 取消 |
14
14
  | `dsh-session-counts` 0.0.3 | **工作区会话数**:每行行尾显示计数,表头显示总数,口径跟随「已归档」筛选 |
15
15
  | `dsh-declutter` 0.2.0 | **收纳与整理**:会话内失败轮/空轮/合成轮按规则表收起(只加视图属性,可逆,不改日志)+ 侧栏藏品牌行 /「新会话」/「更多」/顶部空隙,面板显隐与排序 |
16
16
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-better-sidebar-left",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "description": "Session management for DeepSeek Harness in one install: delete a session with a risk-checked confirmation, move one across workspaces (menu and drag), rename one by double-clicking its title, show per-workspace session counts, and declutter both the sidebar and the conversation's collapsed turns. Self-contained: the plugin list shows this one row, and the five components are vendored inside it - installing this plugin installs nothing else.",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -80,8 +80,8 @@
80
80
  "dsh-session-rename-dblclick": {
81
81
  "repo": "https://github.com/DDDMUC/dsh-session-rename-dblclick",
82
82
  "ref": "main",
83
- "commit": "53bbae2fefc691bf0852696496aa96693b26ff9e",
84
- "version": "0.1.4"
83
+ "commit": "b86a1c4f9bb4b631c75e6d87eda058b8ffce6f8c",
84
+ "version": "0.3.0"
85
85
  },
86
86
  "dsh-session-counts": {
87
87
  "repo": "https://github.com/DDDMUC/dsh-session-counts",
package/src/client.js CHANGED
@@ -6184,7 +6184,6 @@ window.__ModuleLoader__.load({
6184
6184
  const ROUTE = '/dsh-session-rename/rename'
6185
6185
  const MAX_TITLE = 200
6186
6186
  const STYLE_ATTR = 'data-dsh-session-rename'
6187
- const SESSION_IN_PATH = /\/session\/([^/?#]+)/
6188
6187
 
6189
6188
  const zh = typeof navigator !== 'undefined' && /^zh/i.test(navigator.language || '')
6190
6189
  const text = zh
@@ -6217,16 +6216,10 @@ window.__ModuleLoader__.load({
6217
6216
  margin: 0; border: 1px solid transparent; background: transparent;
6218
6217
  box-shadow: none; transition: none;
6219
6218
  }
6220
- /* Editing: the same pill, now wearing the brand ring - that is how the
6221
- reference paints its focused field. The interior stays transparent so
6222
- no colour is invented on top of the host theme. */
6223
- .dsr-wrap[data-editing='true'] {
6224
- border-color: var(--dsw-alias-brand-primary, #4d6bfe);
6225
- /* The reference field is FILLED (it wears the input token), not a hole cut
6226
- in the header - that fill is most of why its edit state reads as a field. */
6227
- background: var(--dsw-specific-input-major, var(--dsw-alias-bg-overlay, #ffffff));
6228
- box-shadow: var(--dsw-shadow-lv2, 0 2px 8px 0 rgba(0, 0, 0, .04));
6229
- }
6219
+ /* Editing: the colours are set inline by openEditor from tokens resolved INSIDE
6220
+ the theme scope. They cannot live here - this overlay hangs off <body>, where
6221
+ the theme variables do not exist, so a var() would fall back to something
6222
+ invented (that is exactly how the ring once came out black). */
6230
6223
  /*
6231
6224
  * Idle affordance. It CANNOT be a pseudo-element on the title: the product's
6232
6225
  * crumb is display:inline-block with overflow hidden, so anything drawn outside
@@ -6324,29 +6317,6 @@ window.__ModuleLoader__.load({
6324
6317
  return null
6325
6318
  }
6326
6319
 
6327
- /**
6328
- * The Session a sidebar row names.
6329
- *
6330
- * `data-row-key` first: current builds render the row as
6331
- * `<div role="treeitem" data-row-key="session:<id>">` with an onClick. The
6332
- * anchor this module used to require no longer exists, which made every
6333
- * double-click a silent no-op. The anchor stays as a fallback.
6334
- * @param {Element} row
6335
- * @returns {string | null}
6336
- */
6337
- function sessionIdOfRow(row) {
6338
- const key = row && typeof row.getAttribute === 'function' ? row.getAttribute('data-row-key') : null
6339
- if (typeof key === 'string' && key.startsWith('session:') && key.length > 'session:'.length) {
6340
- return key.slice('session:'.length)
6341
- }
6342
- const link = row && typeof row.querySelector === 'function' ? row.querySelector('a[href*="/session/"]') : null
6343
- return sessionIdFromHref(link && link.getAttribute('href'))
6344
- }
6345
-
6346
- function sessionIdFromHref(href) {
6347
- const match = href ? SESSION_IN_PATH.exec(href) : null
6348
- return match ? match[1] : null
6349
- }
6350
6320
 
6351
6321
  /**
6352
6322
  * Map a double-clicked node to the Session title it names.
@@ -6370,16 +6340,9 @@ window.__ModuleLoader__.load({
6370
6340
  return sessionId ? { sessionId, titleEl: crumb, surface: 'header' } : null
6371
6341
  }
6372
6342
 
6373
- // sidebar row: `data-row-key="session:<id>"` is the shipped contract.
6374
- // The row is a <div role="treeitem" data-row-key=...> with an onClick, not
6375
- // a link - requiring an anchor here matched nothing in current builds, so
6376
- // every double-click was a silent no-op.
6377
- const row = el.closest('[class*="_sessionRow"], [data-row-key^="session:"]')
6378
- if (!row) return null
6379
- const titleEl = el.closest('[class*="_title"]') || row.querySelector('[class*="_title"]')
6380
- if (!titleEl || !row.contains(titleEl)) return null
6381
- const sessionId = sessionIdOfRow(row)
6382
- return sessionId ? { sessionId, titleEl, surface: 'row' } : null
6343
+ // Sidebar rows are deliberately NOT ours: clicking a row opens the session and
6344
+ // the product owns renaming there. This plugin edits the header title only.
6345
+ return null
6383
6346
  }
6384
6347
 
6385
6348
  // --- the in-place editor ---------------------------------------------------
@@ -6387,16 +6350,6 @@ window.__ModuleLoader__.load({
6387
6350
  /** @type {null | { closed: boolean, targetEl: Element, sessionId: string }} */
6388
6351
  let editor = null
6389
6352
 
6390
- function copyFont(from, to) {
6391
- const cs = window.getComputedStyle(from)
6392
- to.style.fontFamily = cs.fontFamily
6393
- to.style.fontSize = cs.fontSize
6394
- to.style.fontWeight = cs.fontWeight
6395
- to.style.fontStyle = cs.fontStyle
6396
- to.style.letterSpacing = cs.letterSpacing
6397
- to.style.lineHeight = cs.lineHeight
6398
- to.style.textAlign = cs.textAlign
6399
- }
6400
6353
 
6401
6354
  /** Width of `text` in the title's own font, so the editor can hug the glyphs. */
6402
6355
  function measureText(el, text, font) {
@@ -6405,18 +6358,35 @@ window.__ModuleLoader__.load({
6405
6358
  const weight = font !== undefined && font !== null ? font.weight : cs.fontWeight
6406
6359
  const family = font !== undefined && font !== null ? font.family : cs.fontFamily
6407
6360
  const lineHeight = font !== undefined && font !== null ? font.lineHeight : parseFloat(cs.lineHeight) || Math.round(size * 1.35)
6361
+ const style = font !== undefined && font !== null ? font.style : cs.fontStyle
6362
+ const spacing = font !== undefined && font !== null ? font.letterSpacing : cs.letterSpacing
6363
+ // Measure with a REAL element, not canvas metrics.
6364
+ //
6365
+ // Canvas measureText and the layout engine disagree by a pixel or two per CJK
6366
+ // string, so a canvas-measured pill came out ~2px wider than the text it hugs.
6367
+ // The reference is `width: fit-content`, i.e. whatever layout says, so ask layout.
6408
6368
  let width = 0
6369
+ let probe = null
6409
6370
  try {
6410
- if (!measureText.canvas) measureText.canvas = document.createElement('canvas')
6411
- const context = measureText.canvas.getContext('2d')
6412
- context.font = `${cs.fontStyle} ${weight} ${size}px ${family}`
6413
- width = context.measureText(text).width
6414
- } catch {
6371
+ probe = document.createElement('span')
6372
+ probe.textContent = text
6373
+ probe.setAttribute('aria-hidden', 'true')
6374
+ probe.style.position = 'absolute'
6375
+ probe.style.visibility = 'hidden'
6376
+ probe.style.pointerEvents = 'none'
6377
+ probe.style.whiteSpace = 'pre'
6378
+ probe.style.font = `${style} ${weight} ${size}px ${family}`
6379
+ probe.style.lineHeight = `${lineHeight}px`
6380
+ probe.style.letterSpacing = spacing
6381
+ const host = el !== null && el !== undefined && el.parentElement !== null && el.parentElement !== undefined ? el.parentElement : document.body
6382
+ host.appendChild(probe)
6383
+ width = probe.getBoundingClientRect().width
6384
+ } catch (error) {
6415
6385
  width = 0
6386
+ } finally {
6387
+ if (probe !== null && typeof probe.remove === 'function') probe.remove()
6416
6388
  }
6417
6389
  if (!width) width = text.length * size * 0.62
6418
- const spacing = parseFloat(cs.letterSpacing)
6419
- if (Number.isFinite(spacing) && spacing !== 0) width += spacing * Math.max(text.length - 1, 0)
6420
6390
  return { width, height: lineHeight, padLeft: parseFloat(cs.paddingLeft) || 0, padTop: parseFloat(cs.paddingTop) || 0 }
6421
6391
  }
6422
6392
 
@@ -6462,6 +6432,22 @@ window.__ModuleLoader__.load({
6462
6432
 
6463
6433
  const BORDER = 1
6464
6434
  const PAD_X = 12
6435
+ // The live product draws its field with --dsl-input-height:44px and
6436
+ // --dsl-input-border-radius:22px, i.e. a 44px pill whose caps are TRUE semicircles
6437
+ // (radius = height / 2, nothing for the browser to clamp).
6438
+ //
6439
+ // A 40px pill with a 22px radius is not the same thing: CSS scales both radii by
6440
+ // 40/44, so the caps come out at 20px and read a touch tighter at both ends. That
6441
+ // is the difference one sees when the two are put side by side.
6442
+ const PILL_HEIGHT = 40
6443
+ const PILL_RADIUS = 22
6444
+ // The product EDIT state is a .ds-input with its own numbers (main.76bb554586.css):
6445
+ // .ds-input{border-radius:22px; padding:0 14px; height:var(--dsl-input-height);
6446
+ // background-color:var(--dsl-input-color); display:flex; border:none}
6447
+ // .ds-input--l{--dsl-input-height:var(--ds-control-height-l)} -> 40px
6448
+ // --dsl-input-color: var(--dsw-specific-selector) -> #f1f3f5
6449
+ const FIELD_PAD_X = 14
6450
+ const FIELD_BORDER = 0
6465
6451
 
6466
6452
  /**
6467
6453
  * The pill that the editor and the hover ring both draw.
@@ -6482,31 +6468,42 @@ window.__ModuleLoader__.load({
6482
6468
  */
6483
6469
  function pillFont(titleEl) {
6484
6470
  const cs = typeof window !== 'undefined' && typeof window.getComputedStyle === 'function' ? window.getComputedStyle(titleEl) : null
6485
- return { size: 14, weight: '600', lineHeight: 22, family: cs === null ? 'inherit' : cs.fontFamily }
6471
+ if (cs === null) return { size: 14, weight: '400', style: 'normal', lineHeight: 20, family: 'inherit', letterSpacing: 'normal' }
6472
+ return {
6473
+ size: parseFloat(cs.fontSize) || 14,
6474
+ weight: cs.fontWeight || '400',
6475
+ style: cs.fontStyle || 'normal',
6476
+ lineHeight: parseFloat(cs.lineHeight) || 20,
6477
+ family: cs.fontFamily || 'inherit',
6478
+ letterSpacing: cs.letterSpacing || 'normal',
6479
+ }
6486
6480
  }
6487
6481
 
6488
- function boxOf(titleEl, title, surface) {
6482
+ function boxOf(titleEl, title, surface, spec) {
6483
+ const padX = spec !== undefined && spec !== null && spec.padX !== undefined ? spec.padX : PAD_X
6484
+ const border = spec !== undefined && spec !== null && spec.border !== undefined ? spec.border : BORDER
6489
6485
  const rect = titleEl.getBoundingClientRect()
6490
6486
  const font = pillFont(titleEl)
6491
6487
  const metrics = measureText(titleEl, title, font)
6492
6488
  const contentHeight = Math.max(14, Math.round(font.lineHeight))
6493
- // The product pill is 40px tall over a 22px line with a 1px border, so the
6494
- // padding is (40 - 22) / 2 - 1 = 8. Counting the border is what makes it land
6495
- // on 40 instead of 42.
6496
- const target = surface === 'header' ? 40 : contentHeight + 8
6497
- const padY = Math.max(2, Math.min(12, Math.round((target - contentHeight) / 2) - BORDER))
6489
+ // Padding is computed from the BORDER as well, so the box lands on the target
6490
+ // height instead of target + 2.
6491
+ const target = surface === 'header' ? (spec !== undefined && spec !== null && spec.height !== undefined ? spec.height : PILL_HEIGHT) : contentHeight + 8
6492
+ const padY = Math.max(2, Math.min(12, Math.round((target - contentHeight) / 2) - border))
6498
6493
  const contentLeft = rect.left + metrics.padLeft
6499
6494
  const contentTop = rect.top + metrics.padTop
6500
- const room = typeof window === 'undefined' ? 0 : window.innerWidth - (contentLeft - (BORDER + PAD_X)) - 8
6495
+ const room = typeof window === 'undefined' ? 0 : window.innerWidth - (contentLeft - (border + padX)) - 8
6501
6496
  const wanted = Math.max(metrics.width + 2, 24)
6502
- const maxContent = Math.max(24, room - 2 * (BORDER + PAD_X))
6497
+ const maxContent = Math.max(24, room - 2 * (border + padX))
6503
6498
  const contentWidth = Math.round(Math.min(wanted, maxContent))
6504
6499
  return {
6505
- left: Math.round(contentLeft - (BORDER + PAD_X)),
6506
- top: Math.round(contentTop - (BORDER + padY)),
6507
- width: contentWidth + 2 * (BORDER + PAD_X),
6508
- height: contentHeight + 2 * (BORDER + padY),
6500
+ left: Math.round(contentLeft - (border + padX)),
6501
+ top: Math.round(contentTop - (border + padY)),
6502
+ width: contentWidth + 2 * (border + padX),
6503
+ height: contentHeight + 2 * (border + padY),
6509
6504
  padY,
6505
+ padX,
6506
+ border,
6510
6507
  contentHeight,
6511
6508
  }
6512
6509
  }
@@ -6529,7 +6526,7 @@ window.__ModuleLoader__.load({
6529
6526
  ringEl.style.top = `${box.top}px`
6530
6527
  ringEl.style.width = `${box.width}px`
6531
6528
  ringEl.style.height = `${box.height}px`
6532
- ringEl.style.borderRadius = box.height >= 40 ? '22px' : `${Math.round(Math.min(22, box.height / 2))}px`
6529
+ ringEl.style.borderRadius = `${Math.round(Math.min(PILL_RADIUS, box.height / 2))}px`
6533
6530
  ringEl.style.borderColor = resolveToken(titleEl, '--dsw-alias-border-l2', 'borderColor', 'rgba(0, 0, 0, 0.1)')
6534
6531
  ringEl.style.boxShadow = resolveToken(titleEl, '--dsw-shadow-lv2', 'boxShadow', 'none')
6535
6532
  if (typeof window !== 'undefined' && typeof window.getComputedStyle === 'function') {
@@ -6614,7 +6611,7 @@ window.__ModuleLoader__.load({
6614
6611
  hideRing()
6615
6612
  // The hover ring has just drawn this exact pill, so entering the editor is a
6616
6613
  // change of colour, not of geometry.
6617
- const box = boxOf(titleEl, title, target.surface)
6614
+ const box = boxOf(titleEl, title, target.surface, { padX: FIELD_PAD_X, border: FIELD_BORDER })
6618
6615
  // Declared before the log that prints it: the previous revision logged `brand`
6619
6616
  // while its const sat further down, which threw a temporal-dead-zone error inside
6620
6617
  // openEditor AFTER the click was already swallowed - so a click did nothing at all.
@@ -6654,14 +6651,17 @@ window.__ModuleLoader__.load({
6654
6651
  // paints `inset 0 0 0 1px var(--dsw-alias-brand-primary)`. Same here, so the ring
6655
6652
  // hugs the pill instead of growing it by a pixel.
6656
6653
  wrap.style.borderColor = 'transparent'
6657
- wrap.style.background = resolveToken(titleEl, '--dsw-specific-input-major', 'backgroundColor', 'transparent')
6654
+ wrap.style.background = resolveToken(titleEl, '--dsw-specific-selector', 'backgroundColor', '#f1f3f5')
6655
+ wrap.style.borderWidth = box.border + 'px'
6658
6656
  wrap.style.boxShadow = `inset 0 0 0 1px ${brand}`
6659
- wrap.style.borderRadius = box.height >= 40 ? '22px' : `${Math.round(Math.min(22, box.height / 2))}px`
6660
- wrap.style.padding = `${box.padY}px ${PAD_X}px`
6657
+ wrap.style.borderRadius = `${Math.round(Math.min(PILL_RADIUS, box.height / 2))}px`
6658
+ wrap.style.padding = `${box.padY}px ${box.padX}px`
6661
6659
  wrap.style.fontFamily = font.family
6662
6660
  wrap.style.fontSize = `${font.size}px`
6663
6661
  wrap.style.fontWeight = font.weight
6662
+ wrap.style.fontStyle = font.style
6664
6663
  wrap.style.lineHeight = `${font.lineHeight}px`
6664
+ wrap.style.letterSpacing = font.letterSpacing
6665
6665
 
6666
6666
  const input = document.createElement('input')
6667
6667
  input.className = 'dsr-input'
@@ -6704,7 +6704,11 @@ window.__ModuleLoader__.load({
6704
6704
  const focusNow = () => {
6705
6705
  if (state.closed) return
6706
6706
  input.focus({ preventScroll: true })
6707
- input.select()
6707
+ // The reference drops a caret after the last character; it does NOT select the
6708
+ // title. Selecting everything made the first keystroke replace the whole name,
6709
+ // and it repainted the text with a selection band that the reference never shows.
6710
+ const end = String(input.value).length
6711
+ if (typeof input.setSelectionRange === 'function') input.setSelectionRange(end, end)
6708
6712
  }
6709
6713
  // Next frame when there is one (some hosts without a window still run this code).
6710
6714
  if (typeof requestAnimationFrame === 'function') requestAnimationFrame(focusNow)
@@ -6713,13 +6717,7 @@ window.__ModuleLoader__.load({
6713
6717
 
6714
6718
  // --- listener --------------------------------------------------------------
6715
6719
 
6716
- // The browser's own `dblclick` is the primary trigger, but some builds route
6717
- // a row click through handlers that cancel the native double-click synthesis.
6718
- // Tracking the two clicks here keeps the gesture working either way: same
6719
- // session, within 600 ms, within 8 px of the previous click.
6720
- const DOUBLE_MS = 600
6721
- const DOUBLE_PX = 8
6722
- let lastClick = null
6720
+ // (Single-click editing only: the sidebar-row double click was removed.)
6723
6721
 
6724
6722
  /**
6725
6723
  * The header title a hover is over, or null.
@@ -6750,64 +6748,160 @@ window.__ModuleLoader__.load({
6750
6748
  hideRing()
6751
6749
  }
6752
6750
 
6753
- function onDoubleClick(event) {
6751
+ // --- sidebar row click gate ------------------------------------------------
6752
+ //
6753
+ // The product navigates on `click` (Rows.tsx: onClick -> onOpen) and only opens its
6754
+ // rename dialog on the `dblclick` that follows the second click. A fast double click
6755
+ // therefore switches the session before the dialog appears. One click cannot know
6756
+ // whether a second is coming, so the first click is held briefly: if another arrives
6757
+ // within HOLD_MS both are swallowed (the product's own dblclick still opens its
6758
+ // dialog), otherwise the click is replayed so the session opens as usual.
6759
+ // Fixed at the request's value: a normal double click finishes inside the hold, so the
6760
+ // first click of a pair is never replayed. A single click on another row's title
6761
+ // therefore navigates after this delay; a slower pair is undone by the dblclick
6762
+ // handler below, which opens the previous session again.
6763
+ const HOLD_MS = 120
6764
+ let heldClick = null
6765
+ let replaying = false
6766
+ let lastReplay = null
6767
+
6768
+ function rowOfNode(node) {
6769
+ const el = elementOf(node)
6770
+ if (!el || typeof el.closest !== 'function') return null
6771
+ return el.closest('[class*="_sessionRow"], [data-row-key^="session:"]')
6772
+ }
6773
+
6774
+ function isRowSelected(row) {
6775
+ const name = row && typeof row.className === 'string' ? row.className : ''
6776
+ return /(^|\s)[A-Za-z0-9_-]*_selected(\s|$)/.test(name)
6777
+ }
6778
+
6779
+ function releaseHeldClick() {
6780
+ if (heldClick === null) return null
6781
+ const held = heldClick
6782
+ heldClick = null
6783
+ if (held.timer !== null && typeof clearTimeout === 'function') clearTimeout(held.timer)
6784
+ return held
6785
+ }
6786
+
6787
+ function replayClick(held) {
6788
+ const row = held.row
6789
+ if (!row || row.isConnected === false) return
6790
+ let event = null
6791
+ try {
6792
+ const view = typeof window === 'undefined' ? null : window
6793
+ event = new MouseEvent('click', { bubbles: true, cancelable: true, view, detail: 1, clientX: held.x, clientY: held.y })
6794
+ } catch (error) {
6795
+ event = null
6796
+ }
6797
+ if (event === null || typeof row.dispatchEvent !== 'function') return
6798
+ // Remember what this replay is about to replace: if the user turns out to be
6799
+ // double clicking (slowly), the dblclick handler below puts the previous session
6800
+ // back so the rename never leaves them somewhere else.
6801
+ let previousRow = null
6802
+ try {
6803
+ previousRow = document.querySelector('[class*="_selected"][data-row-key^="session:"]')
6804
+ } catch (error) {
6805
+ previousRow = null
6806
+ }
6807
+ lastReplay = {
6808
+ row,
6809
+ previous: previousRow !== null && previousRow !== row ? previousRow : null,
6810
+ at: Date.now(),
6811
+ }
6812
+ replaying = true
6813
+ try {
6814
+ row.dispatchEvent(event)
6815
+ } finally {
6816
+ replaying = false
6817
+ }
6818
+ }
6819
+
6820
+ /**
6821
+ * Undo a replay that turned out to be the first half of a double click.
6822
+ *
6823
+ * Fast double clicks are already handled by the hold above. A slower one (say 350ms
6824
+ * apart) lets the replay navigate first and only then fires the product dblclick, so
6825
+ * the rename would leave the user on the wrong session. Here the previous session is
6826
+ * opened again, and the product dialog keeps opening on the row that was double
6827
+ * clicked.
6828
+ */
6829
+ function onRowDoubleClick(event) {
6830
+ if (lastReplay === null) return
6754
6831
  if (event.button !== 0) return
6755
- const target = resolveTarget(event.target)
6756
- if (!target) {
6757
- lastClick = null
6758
- return
6832
+ const row = rowOfNode(event.target)
6833
+ if (row === null || row !== lastReplay.row) return
6834
+ const el = elementOf(event.target)
6835
+ const titleEl = el && typeof el.closest === 'function' ? el.closest('[class*="_title"]') : null
6836
+ if (titleEl === null || titleEl === undefined || typeof row.contains !== 'function' || !row.contains(titleEl)) return
6837
+ const replay = lastReplay
6838
+ lastReplay = null
6839
+ if (Date.now() - replay.at > 900) return
6840
+ const previous = replay.previous
6841
+ if (previous === null || previous === undefined || previous.isConnected === false) return
6842
+ let event2 = null
6843
+ try {
6844
+ const view = typeof window === 'undefined' ? null : window
6845
+ event2 = new MouseEvent('click', { bubbles: true, cancelable: true, view, detail: 1 })
6846
+ } catch (error) {
6847
+ event2 = null
6759
6848
  }
6760
- if (target.surface === 'header') {
6761
- // Leave the event alone. The current crumb is a plain <span> with no handler of
6762
- // its own (only ancestor crumbs are buttons, and those are not this node), so
6763
- // there is nothing to defend against - and swallowing it took away the native
6764
- // "double click selects a word" inside our own input, which is exactly what one
6765
- // wants while renaming.
6766
- if (editor === null) openEditor(target)
6849
+ if (event2 === null || typeof previous.dispatchEvent !== 'function') return
6850
+ replaying = true
6851
+ try {
6852
+ previous.dispatchEvent(event2)
6853
+ } finally {
6854
+ replaying = false
6855
+ }
6856
+ }
6857
+ function onRowClick(event) {
6858
+ if (replaying) return
6859
+ if (event.button !== 0) return
6860
+ if (event.detail === 0) return
6861
+ const row = rowOfNode(event.target)
6862
+ if (row === null) return
6863
+ const el = elementOf(event.target)
6864
+ const titleEl = el && typeof el.closest === 'function' ? el.closest('[class*="_title"]') : null
6865
+ if (titleEl === null || titleEl === undefined || typeof row.contains !== 'function' || !row.contains(titleEl)) return
6866
+ if (isRowSelected(row)) return
6867
+ if (event.detail >= 2) {
6868
+ if (heldClick !== null && heldClick.row === row) {
6869
+ releaseHeldClick()
6870
+ event.preventDefault()
6871
+ event.stopPropagation()
6872
+ return
6873
+ }
6874
+ // The first half of this pair was already replayed (the hold ran out); swallow
6875
+ // the second click as well and let the dblclick handler roll the navigation back.
6876
+ if (lastReplay !== null && lastReplay.row === row && Date.now() - lastReplay.at < 900) {
6877
+ event.preventDefault()
6878
+ event.stopPropagation()
6879
+ }
6767
6880
  return
6768
6881
  }
6769
- // A row is different: the product opens ITS rename dialog on this same event
6770
- // (Rows.tsx: onDoubleClick -> onRenameRequest). Swallow it whether or not our
6771
- // editor is up, otherwise the stock modal lands on top of our input.
6882
+ const previous = releaseHeldClick()
6883
+ if (previous !== null) replayClick(previous)
6772
6884
  event.preventDefault()
6773
6885
  event.stopPropagation()
6774
- if (editor) return
6775
- openEditor(target)
6886
+ heldClick = {
6887
+ row,
6888
+ x: event.clientX,
6889
+ y: event.clientY,
6890
+ at: Date.now(),
6891
+ timer: typeof setTimeout === 'function' ? setTimeout(() => {
6892
+ const held = releaseHeldClick()
6893
+ if (held !== null) replayClick(held)
6894
+ }, HOLD_MS) : null,
6895
+ }
6776
6896
  }
6777
-
6778
6897
  function onClick(event) {
6779
6898
  if (event.button !== 0) return
6780
- if (editor) return
6899
+ if (editor !== null) return
6781
6900
  const target = resolveTarget(event.target)
6782
- if (!target) {
6783
- lastClick = null
6784
- return
6785
- }
6786
- // The header title is a plain span: clicking it does nothing in the product, so
6787
- // ONE click opens the editor - that is what the reference implementation does
6788
- // (the box is always there, a click swaps its contents for an input). A sidebar
6789
- // row is different: clicking it opens the session, so it needs the deliberate
6790
- // second click.
6791
- if (target.surface === 'header') {
6792
- lastClick = null
6793
- event.preventDefault()
6794
- event.stopPropagation()
6795
- openEditor(target)
6796
- return
6797
- }
6798
- const now = Date.now()
6799
- const previous = lastClick
6800
- lastClick = { sessionId: target.sessionId, x: event.clientX, y: event.clientY, time: now }
6801
- // A real double-click reports detail 2; the timing test covers the case
6802
- // where the browser's own synthesis never happened.
6803
- const byDetail = event.detail >= 2
6804
- const byTiming = previous !== null
6805
- && previous.sessionId === target.sessionId
6806
- && now - previous.time <= DOUBLE_MS
6807
- && Math.abs(previous.x - event.clientX) <= DOUBLE_PX
6808
- && Math.abs(previous.y - event.clientY) <= DOUBLE_PX
6809
- if (!byDetail && !byTiming) return
6810
- lastClick = null
6901
+ if (target === null) return
6902
+ // Only the header title is ours: it is a plain <span> that does nothing on click
6903
+ // in the product, so one click opens the field. Sidebar rows belong to the
6904
+ // product (a click opens the session and it owns renaming there).
6811
6905
  event.preventDefault()
6812
6906
  event.stopPropagation()
6813
6907
  openEditor(target)
@@ -6821,10 +6915,11 @@ window.__ModuleLoader__.load({
6821
6915
  // a second listener pair would open two editors over the same title.
6822
6916
  if (typeof window !== 'undefined' && window.__DSH_SESSION_RENAME__) return
6823
6917
  if (typeof window !== 'undefined') window.__DSH_SESSION_RENAME__ = true
6824
- console.info('[dsh-session-rename-dblclick] ready — double-click a session title to rename')
6918
+ console.info('[dsh-session-rename-dblclick] ready — click the header title to rename')
6825
6919
  const install = () => {
6826
- document.addEventListener('dblclick', onDoubleClick, true)
6827
6920
  document.addEventListener('click', onClick, true)
6921
+ document.addEventListener('click', onRowClick, true)
6922
+ document.addEventListener('dblclick', onRowDoubleClick, true)
6828
6923
  document.addEventListener('mouseover', onHover, true)
6829
6924
  document.addEventListener('mouseout', onOut, true)
6830
6925
  // Not every environment that runs this bundle has a window (the tests drive
@@ -6835,8 +6930,11 @@ window.__ModuleLoader__.load({
6835
6930
  window.addEventListener('resize', hideRing)
6836
6931
  }
6837
6932
  return () => {
6838
- document.removeEventListener('dblclick', onDoubleClick, true)
6839
6933
  document.removeEventListener('click', onClick, true)
6934
+ document.removeEventListener('click', onRowClick, true)
6935
+ document.removeEventListener('dblclick', onRowDoubleClick, true)
6936
+ lastReplay = null
6937
+ releaseHeldClick()
6840
6938
  document.removeEventListener('mouseover', onHover, true)
6841
6939
  document.removeEventListener('mouseout', onOut, true)
6842
6940
  if (hasWindow) {
@@ -6844,7 +6942,6 @@ window.__ModuleLoader__.load({
6844
6942
  window.removeEventListener('resize', hideRing)
6845
6943
  }
6846
6944
  hideRing()
6847
- lastClick = null
6848
6945
  finish()
6849
6946
  if (typeof window !== 'undefined') window.__DSH_SESSION_RENAME__ = false
6850
6947
  }
@@ -6854,7 +6951,7 @@ window.__ModuleLoader__.load({
6854
6951
 
6855
6952
  }
6856
6953
 
6857
- return { apply, __resolveTarget: resolveTarget, __sessionIdOfRow: sessionIdOfRow, __sessionIdForHeader: sessionIdForHeader, __openEditor: openEditor, __onDoubleClick: onDoubleClick }
6954
+ return { apply, __resolveTarget: resolveTarget, __sessionIdForHeader: sessionIdForHeader, __openEditor: openEditor }
6858
6955
  }
6859
6956
 
6860
6957
  // ===== vendored dsh-session-counts =====
@@ -9388,7 +9485,7 @@ window.__ModuleLoader__.load({
9388
9485
  const NS = 'dsh-better-sidebar-left'
9389
9486
 
9390
9487
  /** Keep in sync with package.json and src/components.js. */
9391
- const PLUGIN_VERSION = '0.1.1'
9488
+ const PLUGIN_VERSION = '0.2.0'
9392
9489
 
9393
9490
  /** Presence marker the live verifier reads. */
9394
9491
  const DEBUG_KEY = '__DSH_BETTER_SIDEBAR_LEFT__'
package/src/components.js CHANGED
@@ -24,7 +24,7 @@
24
24
  export const PLUGIN_ID = 'dsh-better-sidebar-left'
25
25
 
26
26
  /** Keep in sync with package.json and src/sidebar.js. */
27
- export const PLUGIN_VERSION = '0.1.1'
27
+ export const PLUGIN_VERSION = '0.2.0'
28
28
 
29
29
  /**
30
30
  * The five components, in the order the user meets them in the sidebar.
@@ -1,6 +1,6 @@
1
1
  // dsh-session-rename-dblclick host half (dsh-session-rename-dblclick.js), VENDORED by tools/vendor.mjs - DO NOT EDIT.
2
2
  //
3
- // Source: ../dsh-better-sidebar-left-src/components/dsh-session-rename-dblclick/index.js (v0.1.4, sha256 9a1263e486e37b58)
3
+ // Source: ../dsh-better-sidebar-left-src/components/dsh-session-rename-dblclick/index.js (v0.3.0, sha256 9a1263e486e37b58)
4
4
  // Regenerate with npm run vendor; test/sync.test.js fails when this is stale.
5
5
  //
6
6
  // src/shell.js mounts the copy named after the component, which is why this
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "dsh-delete-session": "0.5.0",
3
3
  "dsh-session-relocate": "0.3.1",
4
- "dsh-session-rename-dblclick": "0.1.4",
4
+ "dsh-session-rename-dblclick": "0.3.0",
5
5
  "dsh-session-counts": "0.0.3",
6
6
  "dsh-declutter": "0.2.0"
7
7
  }