dsh-conversation-float 0.3.2 → 0.3.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.
package/client.js CHANGED
@@ -54,6 +54,12 @@ window.__ModuleLoader__.load({
54
54
  }
55
55
  })()
56
56
  const MenuItemButton = primitives?.MenuItemButton ?? null
57
+ /**
58
+ * DSH's own right-sidebar glyph. Its expand and collapse controls use the
59
+ * panel-left outline mirrored, so a rescue row wearing the same icon reads
60
+ * as "this Conversation is behind the right bar", not as a second window.
61
+ */
62
+ const PanelLeftIcon = primitives?.IconPanelLeftOutlineRegular ?? null
57
63
 
58
64
  /**
59
65
  * Copy for every locale DSH ships. The word for the Conversation is read
@@ -203,6 +209,10 @@ window.__ModuleLoader__.load({
203
209
  const ANCHOR_ATTR = 'data-dsh-conversation-float-anchor'
204
210
  /** Set on a taskbar row's button, with the Session its window shows. */
205
211
  const ROW_MARK_ATTR = 'data-dsh-conversation-float-row'
212
+ /** Set on a rescue row's button: the Session docked in a railed right bar. */
213
+ const RESCUE_ATTR = 'data-dsh-conversation-float-rescue'
214
+ /** The left row a docked Conversation gets while the right bar is collapsed. */
215
+ const RESCUE_ID = 'conversation-rescue:'
206
216
  const CHAT_ID = 'conversation-float-panel'
207
217
  const CHAT_KIND = 'conversation-float-panel'
208
218
  /** A resource address our own tab type claims; the panel is opened by it. */
@@ -352,6 +362,9 @@ window.__ModuleLoader__.load({
352
362
  }
353
363
  }
354
364
  refreshSwitchChips()
365
+ // A pass may have moved the Conversation into or out of a railed right
366
+ // bar: the left rescue row follows the column, not a timer.
367
+ scheduleRescueSync()
355
368
  // The transcript's height is a layout fact: refresh the float's own
356
369
  // scroll lane here, where the composer has already settled.
357
370
  for (const win of windows.values()) syncScrollbar(win)
@@ -364,8 +377,6 @@ window.__ModuleLoader__.load({
364
377
  let pendingChromeless = false
365
378
  /** The last sane band geometry, kept for when the columns are hidden. */
366
379
  let lastBand = null
367
- /** Sidebar state captured when the float opened; restored when it closes. */
368
- let savedChrome = null
369
380
  /**
370
381
  * A retry of the sidebar arrangement, cancelable by the user's own hand.
371
382
  *
@@ -374,14 +385,10 @@ window.__ModuleLoader__.load({
374
385
  * never kept. A hand on the sidebars now ends the retry directly.
375
386
  */
376
387
  let chromeApplyStop = null
377
- /** Set while docking to the right sidebar: the column is not going home. */
378
- let dockingRight = false
379
388
  /** Set when a minimise is waiting for the float that carries the column. */
380
389
  let pendingMinimise = false
381
390
  /** The Session list projection, when the Client exposes it. */
382
391
  let sessions = null
383
- /** Set while the float is being reopened from the drawer. */
384
- let suspendRestore = false
385
392
  /** The drop preview overlay, created on demand. */
386
393
  let preview = null
387
394
 
@@ -582,10 +589,6 @@ window.__ModuleLoader__.load({
582
589
  const ownPanel = floatPanel()
583
590
  if (ownPanel !== null) ownPanel.setAttribute(OWN_FLOAT_ATTR, '')
584
591
 
585
- // A host has taken the column, so a docking that was waiting for its tab
586
- // has arrived: the restore guard must not outlive it.
587
- dockingRight = false
588
-
589
592
  // The left-hand action asked for the conversation while no float existed.
590
593
  // The body is mounted in a layout effect — before paint — so minimising
591
594
  // here means the window is never painted on its way out.
@@ -881,27 +884,16 @@ window.__ModuleLoader__.load({
881
884
  } catch { /* no window yet */ }
882
885
  }
883
886
 
884
- function detachColumn(keepChrome = false) {
887
+ function detachColumn() {
885
888
  const column = movedColumn
886
889
  const home = movedFrom
887
890
  if (column !== null) column.removeAttribute(COLUMN_ATTR)
888
891
  movedColumn = null
889
892
  movedFrom = null
890
893
  notifyState()
891
- // Closing is the plugin's doing, even when a click on the panel's own
892
- // close button started it. Nothing has to be suppressed for that: the
893
- // restore below compares against a snapshot taken before the float
894
- // opened, so a re-rail cannot be mistaken for the user's arrangement.
895
894
  for (const el of document.querySelectorAll(`[${OWN_FLOAT_ATTR}]`)) el.removeAttribute(OWN_FLOAT_ATTR)
896
895
  // The float is leaving the screen: the rest of DSH has to come back.
897
896
  if (chromeless) setChromeless(false)
898
- // A float that goes home hands the sidebars back as they were — but only
899
- // when it really goes home. Moving the live column between hosts (back
900
- // out of the left drawer, a remounted float body) also detaches it for
901
- // a frame; restoring there would collapse the sidebars under a float
902
- // that is still on screen.
903
- if (!keepChrome && !dockingRight && !suspendRestore) scheduleRestoreChrome()
904
- dockingRight = false
905
897
  if (column === null) return
906
898
  noteColumnMoved()
907
899
  column.style.width = ''
@@ -1357,39 +1349,18 @@ window.__ModuleLoader__.load({
1357
1349
  }
1358
1350
 
1359
1351
  /**
1360
- * Bring the rest of DSH back. Hiding the columns lets DSH re-rail the left
1361
- * sidebar, so the window used to come back as "only the right column": a
1362
- * reveal opens the drawer again, the same way opening the float does.
1352
+ * Bring the rest of DSH back after the float hid it. The sidebars are left
1353
+ * exactly as the user last had them: this plugin no longer puts a captured
1354
+ * arrangement back.
1363
1355
  */
1364
- function revealChrome(forceDrawer = false) {
1356
+ function revealChrome() {
1365
1357
  setChromeless(false)
1366
- // The columns are opened by the plugin, and a hand on them ends any retry
1367
- // this pass started (see the pointerdown tracker in apply()), so the
1368
- // user's own first click is never swallowed by a settle window.
1369
- // Back to the arrangement the window had: whatever the user last left the
1370
- // sidebars in, or the pair the float found. Never a blanket "both open" —
1371
- // that would undo a sidebar the user closed on purpose.
1372
- const base = restoreTarget()
1373
- // Stowing the float needs its drawer row on screen, whatever the target.
1374
- // The forced drawer is folded into the target itself: a separate toggle
1375
- // would be undone by the retry pass that follows it.
1376
- const target = base === null ? null : forceDrawer ? { ...base, leftCollapsed: false } : base
1377
- if (target !== null) {
1378
- applyChromeTarget(target)
1379
- return
1380
- }
1381
- if (!forceDrawer) return
1382
- try {
1383
- if (leftCollapsed()) layout?.toggleSidebar?.()
1384
- } catch (error) {
1385
- report('[conversation-float] could not expand the left sidebar:', error)
1386
- }
1387
1358
  }
1388
1359
 
1389
1360
  /**
1390
- * Match the sidebars to the snapshot, and report whether they already do.
1361
+ * Match the sidebars to a target, and report whether they already do.
1391
1362
  * Right goes first because opening the left drawer rails the right column
1392
- * on a narrow window; doing the left last leaves the pair the snapshot
1363
+ * on a narrow window; doing the left last leaves the pair the target
1393
1364
  * asked for.
1394
1365
  */
1395
1366
  function applyChromeSnapshot(saved) {
@@ -1450,42 +1421,6 @@ window.__ModuleLoader__.load({
1450
1421
  return { leftCollapsed: leftCollapsed(), rightExpanded: rightExpanded() }
1451
1422
  }
1452
1423
 
1453
- /**
1454
- * Remember the sidebars as they were before the float forced them open.
1455
- * The capture happens once, before the plugin touches anything, and is
1456
- * never refreshed while the float is up: a later sample would record the
1457
- * forced state instead, and then every close would look like the user's
1458
- * choice and nothing would ever be restored.
1459
- */
1460
- function saveChromeState() {
1461
- if (savedChrome !== null) return
1462
- savedChrome = chromeNow()
1463
- }
1464
-
1465
- /**
1466
- * A detach is not a close until the float is really gone. The drawer row
1467
- * re-hosts the live column and a remounted body re-attaches it, and both
1468
- * detach it for a frame; the chrome is restored only when nothing took the
1469
- * column back and no panel is left to finish tearing down.
1470
- */
1471
- function scheduleRestoreChrome(depth = 0) {
1472
- window.requestAnimationFrame(() => {
1473
- // A host took the column back: the float is still open, not closed.
1474
- if (movedColumn !== null) return
1475
- // The panel is still on its way out; give it a few frames.
1476
- if (floatPanel() !== null) {
1477
- if (depth < 12) scheduleRestoreChrome(depth + 1)
1478
- return
1479
- }
1480
- restoreChrome()
1481
- })
1482
- }
1483
-
1484
- /** The pair a reveal or a close puts back: the snapshot taken on open. */
1485
- function restoreTarget() {
1486
- return savedChrome
1487
- }
1488
-
1489
1424
  /** Match the sidebars to a target, retrying while the dock kit settles. */
1490
1425
  function applyChromeTarget(target) {
1491
1426
  // A toggle the dock kit queued needs a commit to land, so a retry fired
@@ -1524,13 +1459,6 @@ window.__ModuleLoader__.load({
1524
1459
  return rightOk && leftOk
1525
1460
  }
1526
1461
 
1527
- function restoreChrome() {
1528
- const target = restoreTarget()
1529
- savedChrome = null
1530
- if (target === null) return
1531
- applyChromeTarget(target)
1532
- }
1533
-
1534
1462
  /** Open (or focus) the float at the dock kit's own default seat. */
1535
1463
  /**
1536
1464
  * Give this Conversation a window.
@@ -1543,7 +1471,7 @@ window.__ModuleLoader__.load({
1543
1471
  function openFloatAtDefault() {
1544
1472
  const sessionId = liveSession()
1545
1473
  if (sessionId === null) return
1546
- saveChromeState()
1474
+ invokedThisRun.add(sessionId)
1547
1475
  if (tabIdFor(sessionId) !== null) {
1548
1476
  // The tab exists. Floating it is the SAME tab moving, never a second
1549
1477
  // one: a docked page is floated through the dock kit's own intent, and
@@ -1871,16 +1799,12 @@ window.__ModuleLoader__.load({
1871
1799
  // dock asked for from a page lands in the centre instead.
1872
1800
  if (zone === 'right' && mainPanelOpen()) zone = 'centre'
1873
1801
  if (zone === 'right') {
1874
- dockingRight = true
1875
- // The float leaves as an ordinary right-sidebar tab. The sidebar
1876
- // snapshot belonged to the float: keeping it would let a close of that
1877
- // tab — possibly hours later — move the sidebars back in time.
1878
- savedChrome = null
1879
1802
  // Our window and the right-sidebar page are the same tab: the window
1880
1803
  // goes first, or it would outlive the page it was showing and sit there
1881
1804
  // blank while the tab moves underneath it.
1882
1805
  const shown = liveSession()
1883
1806
  if (shown !== null) {
1807
+ invokedThisRun.add(shown)
1884
1808
  // A re-hosted body keeps its React tree and loses the column's
1885
1809
  // bookkeeping with it; closing the tab first gives the page a fresh
1886
1810
  // body that attaches the column again.
@@ -2205,19 +2129,22 @@ window.__ModuleLoader__.load({
2205
2129
  const WINDOW_SCROLLBAR_THUMB_ATTR = 'data-dsh-conversation-float-window-scrollbar-thumb'
2206
2130
  const WINDOW_TITLE_ATTR = 'data-dsh-conversation-float-window-title'
2207
2131
  const WINDOW_HIDE_PANE_ATTR = 'data-dsh-conversation-float-hide-pane'
2132
+ /**
2133
+ * The key an older build used for a stored window rectangle.
2134
+ *
2135
+ * Nothing writes it any more: a float effect lives for the run that made it
2136
+ * and is not restored from a previous one. The prefix is kept only so the
2137
+ * startup pass can clear what earlier builds left behind.
2138
+ */
2208
2139
  const WINDOW_KEY = 'dsh-conversation-float.window.'
2209
2140
  /**
2210
- * The generation of a stored window rectangle.
2141
+ * sessionId -> the rectangle the user dragged out in THIS run.
2211
2142
  *
2212
- * A stored rect is either a size the user dragged out or the default that was
2213
- * in force the first time that Session's window opened. When the default
2214
- * changes, an old record is not a choice — it is the previous default, and
2215
- * honouring it hides the new size for every Session that was ever opened.
2216
- * The stamp tells the two apart: a record from an older build is ignored
2217
- * once, so the first open after an upgrade takes the new default, and every
2218
- * size the user drags out from then on is kept exactly as before.
2143
+ * Kept in memory on purpose. A window position is part of the float, and a
2144
+ * float is a temporary arrangement: opening DSH again starts with none, so
2145
+ * nothing from the last run may come back — not the window, not its place.
2219
2146
  */
2220
- const WINDOW_RECT_VERSION = 2
2147
+ const windowRects = new Map()
2221
2148
  /**
2222
2149
  * One per-Session content epoch.
2223
2150
  *
@@ -2249,6 +2176,16 @@ window.__ModuleLoader__.load({
2249
2176
 
2250
2177
  /** sessionId -> { el, body, title, header, resizer, rect } */
2251
2178
  const windows = new Map()
2179
+ /**
2180
+ * Sessions whose float the user asked for in THIS run.
2181
+ *
2182
+ * DSH persists each Session's right sidebar to localStorage and restores it
2183
+ * on start. Our docked tab travels with that snapshot, so it can mount again
2184
+ * in a run that never opened it. Such a body is not a float the user asked
2185
+ * for: it closes its own tab before it can move the Conversation into a
2186
+ * hidden page, which is how "the last float came back on click" is fixed.
2187
+ */
2188
+ const invokedThisRun = new Set()
2252
2189
  /**
2253
2190
  * The band the float windows live in.
2254
2191
  *
@@ -2266,25 +2203,30 @@ window.__ModuleLoader__.load({
2266
2203
  const WINDOW_Z_TOP = 900
2267
2204
 
2268
2205
  function readWindowRect(sessionId) {
2269
- try {
2270
- const raw = window.localStorage.getItem(WINDOW_KEY + sessionId)
2271
- if (raw === null) return null
2272
- const r = JSON.parse(raw)
2273
- if (!r || typeof r.x !== 'number' || typeof r.y !== 'number' || typeof r.width !== 'number' || typeof r.height !== 'number') return null
2274
- // A rect written by an older build: the default it was sized against is
2275
- // not the default any more, so it is not a size anybody chose.
2276
- if (r.v !== WINDOW_RECT_VERSION) return null
2277
- return r
2278
- } catch {
2279
- return null
2280
- }
2206
+ const rect = windowRects.get(sessionId)
2207
+ if (rect === undefined) return null
2208
+ return { ...rect }
2281
2209
  }
2282
2210
 
2283
2211
  function writeWindowRect(sessionId, rect) {
2212
+ windowRects.set(sessionId, { ...rect })
2213
+ capSessionMap(windowRects, 64)
2214
+ }
2215
+
2216
+ /**
2217
+ * Drop every rectangle an earlier build stored before rectangles became
2218
+ * per-run. Left in place, those records would be the only float state that
2219
+ * outlived a restart; the startup pass removes them once.
2220
+ */
2221
+ function clearStoredWindowRects() {
2284
2222
  try {
2285
- window.localStorage.setItem(WINDOW_KEY + sessionId, JSON.stringify({ ...rect, v: WINDOW_RECT_VERSION }))
2223
+ const store = window.localStorage
2224
+ for (let index = store.length - 1; index >= 0; index -= 1) {
2225
+ const key = store.key(index)
2226
+ if (key !== null && key.startsWith(WINDOW_KEY)) store.removeItem(key)
2227
+ }
2286
2228
  } catch {
2287
- /* a full quota must not break the float */
2229
+ /* storage may be unavailable; nothing to clear then */
2288
2230
  }
2289
2231
  }
2290
2232
 
@@ -2635,7 +2577,7 @@ window.__ModuleLoader__.load({
2635
2577
  // which travels with the column, is the only copy of that switch.
2636
2578
  const chip = switchChip(() => switchToWindow(sessionId))
2637
2579
  header.appendChild(chip)
2638
- header.appendChild(windowButton(t('minimize'), '—', () => hideWindow(sessionId)))
2580
+ header.appendChild(windowButton(t('minimize'), '—', () => minimiseWindow(sessionId)))
2639
2581
  header.appendChild(windowButton(t('close'), '✕', () => closeWindow(sessionId)))
2640
2582
  const scrollbar = document.createElement('div')
2641
2583
  scrollbar.setAttribute(WINDOW_SCROLLBAR_ATTR, '')
@@ -2745,9 +2687,12 @@ window.__ModuleLoader__.load({
2745
2687
  * in the same tick: `openSession` runs its `selectPanel(null)` synchronously,
2746
2688
  * and no React render can happen between two writes of one JavaScript task,
2747
2689
  * so the slot never actually empties and the page never unmounts.
2690
+ *
2691
+ * A rescue row is the exception: its whole promise is "take me back to that
2692
+ * Conversation", so it passes `keepPage = false` and lets the page close.
2748
2693
  */
2749
- function switchToWindow(sessionId) {
2750
- const page = mainPanelOpen() ? currentPanel() : null
2694
+ function switchToWindow(sessionId, keepPage = true) {
2695
+ const page = keepPage && mainPanelOpen() ? currentPanel() : null
2751
2696
  let switched = false
2752
2697
  let threw = false
2753
2698
  try {
@@ -2818,10 +2763,47 @@ window.__ModuleLoader__.load({
2818
2763
  bumpContentEpoch(sessionId)
2819
2764
  // The body mounts with the window: one frame later is when it can report
2820
2765
  // how tall the transcript really is.
2821
- requestAnimationFrame(() => syncScrollbar(win))
2766
+ requestAnimationFrame(() => {
2767
+ syncScrollbar(win)
2768
+ scheduleRescueSync()
2769
+ })
2822
2770
  return win
2823
2771
  }
2824
2772
 
2773
+ /**
2774
+ * The title bar's dash: put this window away.
2775
+ *
2776
+ * A window that had hidden the rest of DSH left the screen behind nothing
2777
+ * when it went away — a blank page with no key but Escape. So the dash also
2778
+ * ends the hidden arrangement: the interface comes back and both bars are
2779
+ * put away, which leaves the left taskbar row as the way to the window.
2780
+ */
2781
+ function minimiseWindow(sessionId) {
2782
+ // "Alone" is the state the blank screen comes from: the interface is
2783
+ // hidden AND this was the last window on it. With another window still up
2784
+ // there is something to see, and revealing DSH would undo a choice the
2785
+ // hand did not make.
2786
+ let another = false
2787
+ for (const [id, win] of windows) {
2788
+ if (id === sessionId || win.el.hidden) continue
2789
+ another = true
2790
+ break
2791
+ }
2792
+ const wasAlone = chromeless && !another
2793
+ hideWindow(sessionId)
2794
+ if (!wasAlone) {
2795
+ notifyState()
2796
+ return
2797
+ }
2798
+ setChromeless(false)
2799
+ // A window that was the only thing on screen leaves nothing behind: the
2800
+ // interface is back and both bars are put away, so the taskbar row is the
2801
+ // way in. This is a fixed arrangement the hand asked for, not a captured
2802
+ // one.
2803
+ applyChromeTarget({ leftCollapsed: true, rightExpanded: false })
2804
+ notifyState()
2805
+ }
2806
+
2825
2807
  function hideWindow(sessionId) {
2826
2808
  const win = windows.get(sessionId)
2827
2809
  if (win === undefined) return
@@ -2864,6 +2846,7 @@ window.__ModuleLoader__.load({
2864
2846
  win.el.remove()
2865
2847
  queueMicrotask(syncTaskbar)
2866
2848
  refreshSwitchChips()
2849
+ scheduleRescueSync()
2867
2850
  }
2868
2851
 
2869
2852
  /**
@@ -2952,6 +2935,211 @@ window.__ModuleLoader__.load({
2952
2935
  }
2953
2936
  }
2954
2937
 
2938
+ /* ------------------------------------- the collapsed right bar's way back */
2939
+
2940
+ /**
2941
+ * DSH stores each Session's right-sidebar surface under this prefix.
2942
+ *
2943
+ * A Session's panel is drawn only while that Session is on screen, so from
2944
+ * another Session the DOM cannot answer "is that Session's bar railed?".
2945
+ * The stored surface carries exactly that: the tabs with their kind, which
2946
+ * pane hosts them (dock or float), and that Session's own `expanded` flag.
2947
+ */
2948
+ const SIDEBAR_SURFACE_KEY = 'dsh.sidebar-right.v1.'
2949
+
2950
+ /** sessionId -> the left row that recalls a docked page while its right bar is railed. */
2951
+ const rescueRows = new Map()
2952
+ /** Sessions whose restored tab this run has already asked to close. */
2953
+ const restoredCleared = new Set()
2954
+ /** Set while a rescue-row sync is already waiting for the next frame. */
2955
+ let rescueSyncQueued = false
2956
+ /** Set once this plugin instance is gone: a queued sync must not register anew. */
2957
+ let rescueSyncOff = false
2958
+
2959
+ function scheduleRescueSync() {
2960
+ if (rescueSyncQueued || rescueSyncOff) return
2961
+ rescueSyncQueued = true
2962
+ window.requestAnimationFrame(() => {
2963
+ rescueSyncQueued = false
2964
+ if (rescueSyncOff) return
2965
+ try { syncRescueRows() } catch (error) { report('[conversation-float] rescue rows failed:', error) }
2966
+ })
2967
+ }
2968
+
2969
+ /** One Session's stored right-sidebar layout, or null when it has none. */
2970
+ function storedSidebarLayout(sessionId) {
2971
+ try {
2972
+ const raw = window.localStorage.getItem(SIDEBAR_SURFACE_KEY + sessionId)
2973
+ if (raw === null) return null
2974
+ const saved = JSON.parse(raw)?.bySession?.[sessionId]
2975
+ if (saved === null || saved === undefined) return null
2976
+ return typeof saved.layout === 'object' && saved.layout !== null ? saved.layout : null
2977
+ } catch (error) {
2978
+ return null
2979
+ }
2980
+ }
2981
+
2982
+ /** Whether a stored surface holds OUR tab as a docked page. */
2983
+ function storedDockHoldsOurs(layout) {
2984
+ if (layout === null || typeof layout !== 'object') return false
2985
+ const tabs = layout.tabs
2986
+ if (tabs === null || tabs === undefined || typeof tabs !== 'object') return false
2987
+ let ours = null
2988
+ for (const tabId of Object.keys(tabs)) {
2989
+ if (tabs[tabId]?.kind === CHAT_KIND) { ours = tabId; break }
2990
+ }
2991
+ if (ours === null) return false
2992
+ const nodes = layout.nodes
2993
+ if (nodes === null || nodes === undefined || typeof nodes !== 'object') return false
2994
+ for (const nodeId of Object.keys(nodes)) {
2995
+ const node = nodes[nodeId]
2996
+ if (node === null || node === undefined || node.kind !== 'pane') continue
2997
+ if (node.host !== 'dock') continue
2998
+ if (!Array.isArray(node.tabs)) continue
2999
+ if (node.tabs.includes(ours)) return true
3000
+ }
3001
+ return false
3002
+ }
3003
+
3004
+ /**
3005
+ * Sessions whose docked Conversation this run put in a railed right bar.
3006
+ *
3007
+ * The run gate is the whole of "no float outlives a restart": a dock carried
3008
+ * in DSH's own snapshot from an earlier run is not this run's arrangement,
3009
+ * even though it is still stored.
3010
+ *
3011
+ * A page owns the main slot without touching any Session's stored right
3012
+ * bar, so a railed dock behind a page is still a railed dock: the row stays
3013
+ * on screen there, or the page would hide the only way back to it.
3014
+ */
3015
+ function storedRaisedDocks() {
3016
+ const out = []
3017
+ try {
3018
+ const store = window.localStorage
3019
+ for (let index = 0; index < store.length; index += 1) {
3020
+ const key = store.key(index)
3021
+ if (key === null || !key.startsWith(SIDEBAR_SURFACE_KEY)) continue
3022
+ const sessionId = key.slice(SIDEBAR_SURFACE_KEY.length)
3023
+ if (sessionId === '' || windows.has(sessionId)) continue
3024
+ if (!invokedThisRun.has(sessionId)) continue
3025
+ const layout = storedSidebarLayout(sessionId)
3026
+ if (layout === null || layout.expanded === true) continue
3027
+ if (!storedDockHoldsOurs(layout)) continue
3028
+ out.push(sessionId)
3029
+ }
3030
+ } catch (error) {
3031
+ report('[conversation-float] could not read the stored right sidebar:', error)
3032
+ }
3033
+ return out
3034
+ }
3035
+
3036
+ /**
3037
+ * Close a tab DSH restored from a previous run, before its page can take the
3038
+ * Conversation. Only the Session on screen has a mounted surface to close in.
3039
+ */
3040
+ function clearRestoredDock(sessionId) {
3041
+ if (sessionId === null || invokedThisRun.has(sessionId)) return
3042
+ if (restoredCleared.has(sessionId)) return
3043
+ if (tabIdFor(sessionId) === null) return
3044
+ restoredCleared.add(sessionId)
3045
+ queueMicrotask(() => {
3046
+ try {
3047
+ closeTabFor(sessionId)
3048
+ } catch (error) {
3049
+ report('[conversation-float] could not clear a restored tab:', error)
3050
+ }
3051
+ })
3052
+ }
3053
+
3054
+ /**
3055
+ * Keep one left-sidebar row per docked Conversation whose own right bar is
3056
+ * railed. The row is the only key such a page has: collapsing the bar hides
3057
+ * the tab strip, the page and the Conversation with it — and the panel is
3058
+ * not even drawn once another Session takes the screen, or once a page
3059
+ * outside the conversation suppresses the right column. The row stays.
3060
+ */
3061
+ function syncRescueRows() {
3062
+ if (ctxRef === null) return
3063
+ clearRestoredDock(liveSession())
3064
+ const wanted = new Map()
3065
+ for (const sessionId of storedRaisedDocks()) {
3066
+ wanted.set(sessionId, sessionTitle(sessionId) ?? t('floatTitle'))
3067
+ }
3068
+ for (const [sessionId, entry] of [...rescueRows]) {
3069
+ if (wanted.get(sessionId) === entry.label) continue
3070
+ rescueRows.delete(sessionId)
3071
+ try { entry.dispose() } catch { /* the slot may be gone */ }
3072
+ }
3073
+ for (const [sessionId, label] of wanted) {
3074
+ if (rescueRows.has(sessionId)) continue
3075
+ try {
3076
+ const dispose = ctxRef.slots.register(
3077
+ { name: 'sidebar.panellist', id: RESCUE_ID + sessionId, order: 21, label: () => label },
3078
+ makeRescueIcon(sessionId),
3079
+ )
3080
+ rescueRows.set(sessionId, { label, dispose })
3081
+ } catch (error) {
3082
+ report('[conversation-float] could not register the rescue row:', error)
3083
+ }
3084
+ }
3085
+ }
3086
+
3087
+ /**
3088
+ * Bring one Session's railed right bar back onto the screen, EXPANDING it.
3089
+ *
3090
+ * The row's promise is "switch to this Conversation and show it", not "flip
3091
+ * the bar": a bar that is already expanded must not collapse under a press
3092
+ * that was meant to reveal the Conversation.
3093
+ */
3094
+ function expandBarFor(sessionId) {
3095
+ const layout = storedSidebarLayout(sessionId)
3096
+ if (layout !== null && layout.expanded === true) return
3097
+ // The expand control rides the Conversation header of the Session on
3098
+ // screen; after the switch it belongs to this Session.
3099
+ const expand = document.querySelector('[data-sidebar-right-expand]')
3100
+ if (expand instanceof HTMLElement) {
3101
+ try { expand.click(); return } catch { /* the button may be mid-swap */ }
3102
+ }
3103
+ // No header control (the Conversation header is not drawn): only this
3104
+ // Session's own railed panel may open, never a bar that is already open.
3105
+ const panel = document.querySelector(`[data-sidebar-right-session="${sessionId}"][data-sidebar-right-panel]`)
3106
+ if (panel === null || panel.getAttribute('data-sidebar-right-open') !== null) return
3107
+ try {
3108
+ sidebarRight?.toggleExpanded?.()
3109
+ } catch (error) {
3110
+ report('[conversation-float] could not expand the right sidebar:', error)
3111
+ }
3112
+ }
3113
+
3114
+ /**
3115
+ * The left rescue row's press: that Session on screen, its right bar open.
3116
+ *
3117
+ * The expand control belongs to whichever Conversation header is on screen,
3118
+ * so it has to wait for the switch to land — firing it before the commit
3119
+ * would expand the previous Session's bar, or skip this one.
3120
+ */
3121
+ function rescueDocked(sessionId) {
3122
+ // Pressed from a page, the row means "take me back to that Conversation":
3123
+ // the page has to give way for the dock to be shown. The ordinary switch
3124
+ // keeps the page; this is the one exception.
3125
+ switchToWindow(sessionId, false)
3126
+ untilFrame(
3127
+ () => {
3128
+ const column = findColumn()
3129
+ return column !== null && columnSession(column) === sessionId
3130
+ },
3131
+ () => {
3132
+ expandBarFor(sessionId)
3133
+ scheduleRescueSync()
3134
+ },
3135
+ 2000,
3136
+ () => {
3137
+ expandBarFor(sessionId)
3138
+ scheduleRescueSync()
3139
+ },
3140
+ )
3141
+ }
3142
+
2955
3143
  /**
2956
3144
  * A taskbar row is DSH's own main-panel button: selecting it replaces the
2957
3145
  * central entry, which would take a plugin or automation page away. When a
@@ -2959,10 +3147,20 @@ window.__ModuleLoader__.load({
2959
3147
  * the page must stay where it is.
2960
3148
  */
2961
3149
  function taskbarRowPress(event) {
3150
+ // Any press may have railed or unrailed the right bar: a cheap check that
3151
+ // follows the click is what keeps the rescue row in step with the bar.
3152
+ scheduleRescueSync()
2962
3153
  const target = event.target
2963
3154
  if (!(target instanceof Element)) return
2964
- const row = target.closest(`button[${ROW_MARK_ATTR}]`)
3155
+ const row = target.closest(`button[${ROW_MARK_ATTR}], button[${RESCUE_ATTR}]`)
2965
3156
  if (row === null) return
3157
+ const rescueId = row.getAttribute(RESCUE_ATTR)
3158
+ if (rescueId !== null && rescueId !== '') {
3159
+ event.preventDefault()
3160
+ event.stopPropagation()
3161
+ rescueDocked(rescueId)
3162
+ return
3163
+ }
2966
3164
  const sessionId = row.getAttribute(ROW_MARK_ATTR)
2967
3165
  if (sessionId === null || sessionId === '') return
2968
3166
  event.preventDefault()
@@ -3025,6 +3223,11 @@ window.__ModuleLoader__.load({
3025
3223
  .dsw-menu-row:hover { background: var(--dsw-alias-bg-layer-2); }
3026
3224
  .dsw-menu-row:focus-visible { outline: 2px solid var(--dsw-alias-brand-primary); outline-offset: -2px; }
3027
3225
  .dsw-icon:focus-visible { outline: 2px solid var(--dsw-alias-brand-primary); outline-offset: 1px; }
3226
+ /* The rescue row wears DSH's right-panel glyph, mirrored exactly like the
3227
+ right sidebar's own expand/collapse controls. */
3228
+ [data-dsh-conversation-float-rescue][data-dsh-conversation-float-rescue-icon="panel"] svg {
3229
+ transform: scaleX(-1);
3230
+ }
3028
3231
  .dsw-host {
3029
3232
  position: relative;
3030
3233
  display: flex; flex-direction: column;
@@ -3210,6 +3413,32 @@ window.__ModuleLoader__.load({
3210
3413
  }
3211
3414
  }
3212
3415
 
3416
+ /**
3417
+ * The glyph of a rescue row.
3418
+ *
3419
+ * DSH's own right-sidebar glyph, not our window: the header's expand
3420
+ * control uses the panel-left outline mirrored, so the row matches the
3421
+ * control it stands in for. A host without primitives falls back to the
3422
+ * window glyph, and the stylesheet mirrors only the real one.
3423
+ */
3424
+ function makeRescueIcon(sessionId) {
3425
+ return function RescueIcon({ size = 16 }) {
3426
+ const ref = React.useRef(null)
3427
+ React.useLayoutEffect(() => {
3428
+ const icon = ref.current
3429
+ const row = icon === null ? null : icon.closest('button')
3430
+ if (row !== null) {
3431
+ row.setAttribute(RESCUE_ATTR, sessionId)
3432
+ // Lets a probe — and the mirror rule below — tell DSH's glyph
3433
+ // apart from the fallback a host without primitives gets.
3434
+ row.setAttribute('data-dsh-conversation-float-rescue-icon', PanelLeftIcon === null ? 'window' : 'panel')
3435
+ }
3436
+ })
3437
+ const glyph = PanelLeftIcon === null ? h(Icon, { name: 'window', size }) : h(PanelLeftIcon, { size })
3438
+ return h('span', { ref, style: { display: 'contents' } }, glyph)
3439
+ }
3440
+ }
3441
+
3213
3442
  /**
3214
3443
  * The floating tab's body.
3215
3444
  *
@@ -3266,6 +3495,8 @@ window.__ModuleLoader__.load({
3266
3495
  sessionRef.current = sessionId
3267
3496
  let disposed = false
3268
3497
  let seenPane = null
3498
+ /** Set once this body has asked for its own tab to be closed. */
3499
+ let closing = false
3269
3500
  const onEpoch = (id) => {
3270
3501
  if (id === sessionRef.current) setEpoch((value) => value + 1)
3271
3502
  }
@@ -3279,6 +3510,23 @@ window.__ModuleLoader__.load({
3279
3510
  if (disposed) return
3280
3511
  const el = host.current
3281
3512
  if (el === null) return
3513
+ // DSH restores a Session's right sidebar from localStorage, and our
3514
+ // docked tab is part of that snapshot. A body mounting in a run that
3515
+ // never asked for this float is the previous run's arrangement coming
3516
+ // back; closing the tab is what keeps it from outliving a restart.
3517
+ if (!closing && sessionId !== null && !invokedThisRun.has(sessionId) && tabIdFor(sessionId) !== null) {
3518
+ closing = true
3519
+ // Deferred out of the commit that is mounting this body: a store
3520
+ // write here would unmount the tab from inside its own layout pass.
3521
+ queueMicrotask(() => {
3522
+ try {
3523
+ closeTabFor(sessionId)
3524
+ } catch (error) {
3525
+ report('[conversation-float] could not clear a restored tab:', error)
3526
+ }
3527
+ })
3528
+ return
3529
+ }
3282
3530
  const pane = el.closest('[' + FLOAT_ATTR + ']')
3283
3531
  const paneChanged = pane !== seenPane
3284
3532
  seenPane = pane
@@ -3357,7 +3605,7 @@ window.__ModuleLoader__.load({
3357
3605
  const page = mainPanelOpen() && (columnNow === null || columnSession(columnNow) === null)
3358
3606
  if (page && movedColumn !== null && win !== undefined && win.body.contains(movedColumn)) {
3359
3607
  try {
3360
- detachColumn(true)
3608
+ detachColumn()
3361
3609
  } catch (error) {
3362
3610
  report('[conversation-float] could not hand the page its column:', error)
3363
3611
  }
@@ -3507,7 +3755,7 @@ window.__ModuleLoader__.load({
3507
3755
  ctxRef = ctx
3508
3756
  // Build marker: lets a probe tell a re-imported client.js from the copy
3509
3757
  // the host still holds in memory (a page refresh does NOT reload it).
3510
- try { window.__dshFloatBuild = 'pagebands-0.3.2' } catch { /* no window yet */ }
3758
+ try { window.__dshFloatBuild = 'nosnapshot-0.3.3-r2' } catch { /* no window yet */ }
3511
3759
  ctx.effect(() => {
3512
3760
  try {
3513
3761
  return ctx.locale.register(NS, Object.fromEntries(LOCALES.map((id) => [id, { title: COPY[id].floatTitle, description: COPY[id].description }])))
@@ -3550,8 +3798,17 @@ window.__ModuleLoader__.load({
3550
3798
  if (typeof chromeApplyStop === 'function') chromeApplyStop()
3551
3799
  }
3552
3800
  window.addEventListener('pointerdown', onHand, true)
3801
+ // The right bar's own keyboard shortcut (primary+Backslash) is not a
3802
+ // click: a rescue row must still follow a bar collapsed that way.
3803
+ const onBarKey = (event) => {
3804
+ if (event.code !== 'Backslash' && event.key !== '\\') return
3805
+ if (!event.ctrlKey && !event.metaKey) return
3806
+ scheduleRescueSync()
3807
+ }
3808
+ window.addEventListener('keydown', onBarKey, true)
3553
3809
  return () => {
3554
3810
  window.removeEventListener('keydown', escapeOnKey, true)
3811
+ window.removeEventListener('keydown', onBarKey, true)
3555
3812
  document.removeEventListener('click', taskbarRowPress, true)
3556
3813
  window.removeEventListener('pointerdown', onHand, true)
3557
3814
  }
@@ -3571,6 +3828,24 @@ window.__ModuleLoader__.load({
3571
3828
  // A previous build hid the two shipped View buttons; put them back.
3572
3829
  for (const el of document.querySelectorAll('[data-dsh-conversation-float-core-tab]')) el.removeAttribute('data-dsh-conversation-float-core-tab')
3573
3830
  setChromeless(false)
3831
+ // No float effect outlives the run that made it: a rectangle an older
3832
+ // build stored is the only piece that could, and it goes now.
3833
+ clearStoredWindowRects()
3834
+ // A tab the previous run left in the current Session's stored surface is
3835
+ // closed as soon as that surface exists; untilFrame ends the moment it
3836
+ // does, so a normal boot pays one store read per frame for nothing.
3837
+ untilFrame(
3838
+ () => {
3839
+ const live = liveSession()
3840
+ return live !== null && tabIdFor(live) !== null
3841
+ },
3842
+ () => {
3843
+ clearRestoredDock(liveSession())
3844
+ scheduleRescueSync()
3845
+ },
3846
+ 3000,
3847
+ )
3848
+ scheduleRescueSync()
3574
3849
 
3575
3850
 
3576
3851
  ctx.effect(() => {
@@ -3692,6 +3967,12 @@ window.__ModuleLoader__.load({
3692
3967
  scanned: scanned === null ? null : columnSession(scanned),
3693
3968
  columns: document.querySelectorAll('[data-conversation-session]').length,
3694
3969
  windows: windows.size,
3970
+ rescue: {
3971
+ rows: rescueRows.size,
3972
+ sessions: [...rescueRows.keys()],
3973
+ cleared: [...restoredCleared],
3974
+ },
3975
+ invoked: [...invokedThisRun],
3695
3976
  compat: compatReport(),
3696
3977
  lastError: window.__dshFloatLastError ?? null,
3697
3978
  waits: pendingWaits.size,
@@ -3712,9 +3993,9 @@ window.__ModuleLoader__.load({
3712
3993
  get moved() {
3713
3994
  return movedColumn !== null
3714
3995
  },
3715
- /** What the sidebars restore is working from, for the test harness. */
3996
+ /** What the sidebar retry is working from, for the test harness. */
3716
3997
  get chrome() {
3717
- return { saved: savedChrome, chromeless, retrying: typeof chromeApplyStop === 'function' }
3998
+ return { chromeless, retrying: typeof chromeApplyStop === 'function' }
3718
3999
  },
3719
4000
  }
3720
4001
  // The probe is READ-ONLY unless a page asked for the harness. The
@@ -3728,7 +4009,11 @@ window.__ModuleLoader__.load({
3728
4009
  }
3729
4010
  ctx.effect(() => {
3730
4011
  window.addEventListener('resize', reclampWindows)
3731
- return () => window.removeEventListener('resize', reclampWindows)
4012
+ window.addEventListener('resize', scheduleRescueSync)
4013
+ return () => {
4014
+ window.removeEventListener('resize', reclampWindows)
4015
+ window.removeEventListener('resize', scheduleRescueSync)
4016
+ }
3732
4017
  })
3733
4018
 
3734
4019
  // The Session on screen is DSH's own state, and DSH publishes it: one
@@ -3793,10 +4078,13 @@ window.__ModuleLoader__.load({
3793
4078
  ctx.effect(() => () => {
3794
4079
  // Nothing this instance scheduled may outlive it: every wait is a
3795
4080
  // frame loop, and a frame loop left running holds a dead closure.
4081
+ rescueSyncOff = true
3796
4082
  cancelWaits()
3797
4083
  hidePreview()
3798
- // Unloading is not a user close: leave the sidebars alone.
3799
- suspendRestore = true
4084
+ for (const dispose of rescueRows.values()) {
4085
+ try { dispose() } catch { /* the slot may be gone */ }
4086
+ }
4087
+ rescueRows.clear()
3800
4088
  detachColumn()
3801
4089
  delete window.__dshSessionWindow
3802
4090
  })