dsh-conversation-float 0.1.2 → 0.1.4
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 +15 -5
- package/client.js +1064 -126
- package/docs/README.de.md +46 -36
- package/docs/README.es.md +43 -33
- package/docs/README.fr.md +41 -31
- package/docs/README.ja.md +18 -8
- package/docs/README.pt.md +38 -28
- package/docs/README.ru.md +39 -29
- package/docs/README.zh.md +21 -11
- package/package.json +1 -1
package/client.js
CHANGED
|
@@ -33,6 +33,20 @@ window.__ModuleLoader__.load({
|
|
|
33
33
|
|
|
34
34
|
const NS = 'dsh-conversation-float'
|
|
35
35
|
|
|
36
|
+
/**
|
|
37
|
+
* The dock kit's own menu row. It ships in the browser module table, the same
|
|
38
|
+
* place React comes from, so a client bundle may require it without declaring
|
|
39
|
+
* anything extra; the plain button is only for a host that lacks it.
|
|
40
|
+
*/
|
|
41
|
+
const primitives = (() => {
|
|
42
|
+
try {
|
|
43
|
+
return require('@deepseek-ai/dsh-client-ui-primitives') ?? null
|
|
44
|
+
} catch {
|
|
45
|
+
return null
|
|
46
|
+
}
|
|
47
|
+
})()
|
|
48
|
+
const MenuItemButton = primitives?.MenuItemButton ?? null
|
|
49
|
+
|
|
36
50
|
/**
|
|
37
51
|
* Copy for every locale DSH ships. The word for the Conversation is read
|
|
38
52
|
* from this table only, so the panel title, the sidebar row and the entry
|
|
@@ -43,6 +57,11 @@ window.__ModuleLoader__.load({
|
|
|
43
57
|
"conversation": "会话",
|
|
44
58
|
"floatTitle": "会话浮窗",
|
|
45
59
|
"showDsh": "显示 DSH 界面",
|
|
60
|
+
"hideDsh": "隐藏 DSH 界面",
|
|
61
|
+
|
|
62
|
+
"moveLeft": "会话收至此处",
|
|
63
|
+
|
|
64
|
+
"moveRight": "会话移至此处",
|
|
46
65
|
"stow": "放进左栏",
|
|
47
66
|
"center": "回到中间",
|
|
48
67
|
"dock": "停到右栏",
|
|
@@ -52,6 +71,11 @@ window.__ModuleLoader__.load({
|
|
|
52
71
|
"conversation": "Conversation",
|
|
53
72
|
"floatTitle": "Conversation float",
|
|
54
73
|
"showDsh": "Show DSH",
|
|
74
|
+
"hideDsh": "Hide DSH",
|
|
75
|
+
|
|
76
|
+
"moveLeft": "Stow the conversation here",
|
|
77
|
+
|
|
78
|
+
"moveRight": "Move the conversation here",
|
|
55
79
|
"stow": "Stow in the left sidebar",
|
|
56
80
|
"center": "Return to the middle",
|
|
57
81
|
"dock": "Dock in the right sidebar",
|
|
@@ -61,6 +85,11 @@ window.__ModuleLoader__.load({
|
|
|
61
85
|
"conversation": "Konversation",
|
|
62
86
|
"floatTitle": "Konversations-Float",
|
|
63
87
|
"showDsh": "DSH anzeigen",
|
|
88
|
+
"hideDsh": "DSH ausblenden",
|
|
89
|
+
|
|
90
|
+
"moveLeft": "Konversation hierher legen",
|
|
91
|
+
|
|
92
|
+
"moveRight": "Konversation hierher verschieben",
|
|
64
93
|
"stow": "In der linken Seitenleiste ablegen",
|
|
65
94
|
"center": "Zurück in die Mitte",
|
|
66
95
|
"dock": "In der rechten Seitenleiste andocken",
|
|
@@ -70,6 +99,11 @@ window.__ModuleLoader__.load({
|
|
|
70
99
|
"conversation": "Conversación",
|
|
71
100
|
"floatTitle": "Ventana flotante de conversación",
|
|
72
101
|
"showDsh": "Mostrar DSH",
|
|
102
|
+
"hideDsh": "Ocultar DSH",
|
|
103
|
+
|
|
104
|
+
"moveLeft": "Guardar la conversación aquí",
|
|
105
|
+
|
|
106
|
+
"moveRight": "Mover la conversación aquí",
|
|
73
107
|
"stow": "Guardar en la barra izquierda",
|
|
74
108
|
"center": "Volver al centro",
|
|
75
109
|
"dock": "Acoplar en la barra derecha",
|
|
@@ -79,6 +113,11 @@ window.__ModuleLoader__.load({
|
|
|
79
113
|
"conversation": "Conversation",
|
|
80
114
|
"floatTitle": "Fenêtre flottante de conversation",
|
|
81
115
|
"showDsh": "Afficher DSH",
|
|
116
|
+
"hideDsh": "Masquer DSH",
|
|
117
|
+
|
|
118
|
+
"moveLeft": "Ranger la conversation ici",
|
|
119
|
+
|
|
120
|
+
"moveRight": "Déplacer la conversation ici",
|
|
82
121
|
"stow": "Placer dans la barre latérale gauche",
|
|
83
122
|
"center": "Revenir au centre",
|
|
84
123
|
"dock": "Ancrer dans la barre latérale droite",
|
|
@@ -88,6 +127,11 @@ window.__ModuleLoader__.load({
|
|
|
88
127
|
"conversation": "会話",
|
|
89
128
|
"floatTitle": "会話フロート",
|
|
90
129
|
"showDsh": "DSH を表示",
|
|
130
|
+
"hideDsh": "DSH を隠す",
|
|
131
|
+
|
|
132
|
+
"moveLeft": "会話をここにしまう",
|
|
133
|
+
|
|
134
|
+
"moveRight": "会話をここへ移動",
|
|
91
135
|
"stow": "左サイドバーにしまう",
|
|
92
136
|
"center": "中央に戻す",
|
|
93
137
|
"dock": "右サイドバーにドッキング",
|
|
@@ -97,6 +141,11 @@ window.__ModuleLoader__.load({
|
|
|
97
141
|
"conversation": "Conversa",
|
|
98
142
|
"floatTitle": "Janela flutuante da conversa",
|
|
99
143
|
"showDsh": "Mostrar DSH",
|
|
144
|
+
"hideDsh": "Ocultar DSH",
|
|
145
|
+
|
|
146
|
+
"moveLeft": "Guardar a conversa aqui",
|
|
147
|
+
|
|
148
|
+
"moveRight": "Mover a conversa para aqui",
|
|
100
149
|
"stow": "Guardar na barra lateral esquerda",
|
|
101
150
|
"center": "Voltar ao centro",
|
|
102
151
|
"dock": "Ancorar na barra lateral direita",
|
|
@@ -106,6 +155,11 @@ window.__ModuleLoader__.load({
|
|
|
106
155
|
"conversation": "Беседа",
|
|
107
156
|
"floatTitle": "Плавающее окно беседы",
|
|
108
157
|
"showDsh": "Показать DSH",
|
|
158
|
+
"hideDsh": "Скрыть DSH",
|
|
159
|
+
|
|
160
|
+
"moveLeft": "Убрать беседу сюда",
|
|
161
|
+
|
|
162
|
+
"moveRight": "Переместить беседу сюда",
|
|
109
163
|
"stow": "Убрать в левую панель",
|
|
110
164
|
"center": "Вернуть в центр",
|
|
111
165
|
"dock": "Закрепить в правой панели",
|
|
@@ -133,10 +187,14 @@ window.__ModuleLoader__.load({
|
|
|
133
187
|
const CHAT_ADDRESS = 'dsh-resource://conversation-float'
|
|
134
188
|
/** The left sidebar row, and the main-panel key it addresses. */
|
|
135
189
|
const DOCK_ROW_ID = 'conversation-float'
|
|
190
|
+
/** Marks that row's own glyph, so a Conversation named like a shipped row is not mistaken for it. */
|
|
191
|
+
const ROW_MARK_ATTR = 'data-dsh-conversation-float-row'
|
|
136
192
|
/** How long a band must be held before it draws and before it can land. */
|
|
137
193
|
const DWELL_MS = 1200
|
|
138
194
|
/** The dock kit's own marker for a floating panel. */
|
|
139
195
|
const FLOAT_ATTR = 'data-dockkit-float'
|
|
196
|
+
/** Marks our own tab body, so the reconcile pass never reads another plugin's. */
|
|
197
|
+
const BODY_ATTR = 'data-dsh-conversation-float-body'
|
|
140
198
|
/** Set on the float panel while it is stowed in the left drawer. */
|
|
141
199
|
const STOW_ATTR = 'data-dsh-conversation-float-stowed'
|
|
142
200
|
/** Marks the float that hosts our tab, so our rules hit no other panel. */
|
|
@@ -148,7 +206,11 @@ window.__ModuleLoader__.load({
|
|
|
148
206
|
let layout = null
|
|
149
207
|
let movedColumn = null
|
|
150
208
|
let movedFrom = null
|
|
151
|
-
/**
|
|
209
|
+
/**
|
|
210
|
+
* Whether the left sidebar currently holds the re-opener row. It stays for
|
|
211
|
+
* as long as ANY of our floats is stowed, whichever Conversation that is:
|
|
212
|
+
* the row is the way back, and switching Conversations must not take it away.
|
|
213
|
+
*/
|
|
152
214
|
let dockedLeft = false
|
|
153
215
|
/** Whether the rest of DSH is currently hidden behind the float. */
|
|
154
216
|
let chromeless = false
|
|
@@ -165,18 +227,40 @@ window.__ModuleLoader__.load({
|
|
|
165
227
|
let lastBand = null
|
|
166
228
|
/** Sidebar state captured when the float opened; restored when it closes. */
|
|
167
229
|
let savedChrome = null
|
|
168
|
-
/**
|
|
169
|
-
let
|
|
230
|
+
/** The pair the user last left the sidebars in while the float was up. */
|
|
231
|
+
let touchedChrome = null
|
|
170
232
|
/** How long after a press or a key a column change still counts as the user's. */
|
|
171
233
|
const GESTURE_WINDOW = 900
|
|
172
234
|
/** How long the float's own force-open needs to settle before sampling. */
|
|
173
235
|
const FORCE_SETTLE_MS = 1200
|
|
174
236
|
/** The last time the user pressed a key or a mouse button, in ms. */
|
|
175
237
|
let gestureAt = 0
|
|
238
|
+
/**
|
|
239
|
+
* Whether the user's hand is currently on a float. The dock kit moves the
|
|
240
|
+
* panel on its own drag; a seat applied from here during that drag would
|
|
241
|
+
* snap it back to where the plugin last put it.
|
|
242
|
+
*/
|
|
243
|
+
let draggingFloat = false
|
|
244
|
+
/** Press position of that drag, until it moves past the slop. */
|
|
245
|
+
let floatGrab = null
|
|
176
246
|
/** While the plugin moves the columns itself, changes are not the user's. */
|
|
177
247
|
let holdOffUntil = 0
|
|
178
248
|
/** Set while docking to the right sidebar: the column is not going home. */
|
|
179
249
|
let dockingRight = false
|
|
250
|
+
/** Set when the drawer action is waiting for the float that carries the column. */
|
|
251
|
+
let pendingStow = false
|
|
252
|
+
/**
|
|
253
|
+
* The Conversation whose float is stowed in the left drawer, or null. The
|
|
254
|
+
* row carries this Conversation's name and pressing it returns there, so
|
|
255
|
+
* switching Conversations must repoint neither.
|
|
256
|
+
*/
|
|
257
|
+
let stowedSession = null
|
|
258
|
+
/** The label the drawer row was registered with; a different one re-registers. */
|
|
259
|
+
let dockLabel = null
|
|
260
|
+
/** The Session list projection, when the Client exposes it. */
|
|
261
|
+
let sessions = null
|
|
262
|
+
/** Session navigation, used by the drawer row. */
|
|
263
|
+
let uiWorkspace = null
|
|
180
264
|
/** Set while the float is being reopened from the drawer. */
|
|
181
265
|
let suspendRestore = false
|
|
182
266
|
/** Disposer of the `sidebar.panellist` row, while it is registered. */
|
|
@@ -186,6 +270,13 @@ window.__ModuleLoader__.load({
|
|
|
186
270
|
|
|
187
271
|
/* ------------------------------------------------------- the live column */
|
|
188
272
|
|
|
273
|
+
/**
|
|
274
|
+
* The frame column that carries the Conversation. An ANCESTOR is moved, never
|
|
275
|
+
* the Conversation node itself: React keeps child lists inside the nodes it
|
|
276
|
+
* owns, so pulling one of those children out of its parent breaks the next
|
|
277
|
+
* reconciliation — a Session switch then renders nothing at all. Moving the
|
|
278
|
+
* column keeps every list inside the moved subtree intact.
|
|
279
|
+
*/
|
|
189
280
|
function findColumn() {
|
|
190
281
|
if (movedColumn !== null && movedColumn.isConnected) return movedColumn
|
|
191
282
|
const candidates = [
|
|
@@ -196,6 +287,16 @@ window.__ModuleLoader__.load({
|
|
|
196
287
|
]
|
|
197
288
|
for (const anchor of candidates) {
|
|
198
289
|
if (anchor === null) continue
|
|
290
|
+
// While the Conversation is hosted by one of our bodies, the column is
|
|
291
|
+
// that body's own child — walking up instead would climb out of the
|
|
292
|
+
// right sidebar and name the whole right column as "the column", and
|
|
293
|
+
// moving that into the float feeds it its own ancestor.
|
|
294
|
+
const body = anchor.closest(`[${BODY_ATTR}]`)
|
|
295
|
+
if (body !== null) {
|
|
296
|
+
for (const child of Array.from(body.children)) {
|
|
297
|
+
if (child.contains(anchor)) return child
|
|
298
|
+
}
|
|
299
|
+
}
|
|
199
300
|
let node = anchor
|
|
200
301
|
while (node.parentElement !== null) {
|
|
201
302
|
const parent = node.parentElement
|
|
@@ -220,11 +321,39 @@ window.__ModuleLoader__.load({
|
|
|
220
321
|
}
|
|
221
322
|
}
|
|
222
323
|
|
|
223
|
-
/**
|
|
324
|
+
/** The room the sidebars leave in the middle: their two inner edges. */
|
|
325
|
+
function middleRoom() {
|
|
326
|
+
const width = window.innerWidth
|
|
327
|
+
const overlay = document.querySelector('[data-shell-overlay]')
|
|
328
|
+
const frame = overlay === null ? null : overlay.parentElement
|
|
329
|
+
let left = 0
|
|
330
|
+
let right = width
|
|
331
|
+
if (frame !== null) {
|
|
332
|
+
const sidebar = frame.firstElementChild
|
|
333
|
+
if (sidebar !== null) {
|
|
334
|
+
const box = sidebar.getBoundingClientRect()
|
|
335
|
+
if (box.width > 80) left = Math.round(box.right)
|
|
336
|
+
}
|
|
337
|
+
const rightColumn = frame.querySelector('[data-rightbar-col]')
|
|
338
|
+
if (rightColumn !== null) {
|
|
339
|
+
const box = rightColumn.getBoundingClientRect()
|
|
340
|
+
if (box.width > 80) right = Math.round(box.left)
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
return { left, right: Math.max(left, right) }
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* Upper-left corner of that seat: centred in the room the sidebars leave,
|
|
348
|
+
* snapped, clear of the frame. With the window showing nothing but the
|
|
349
|
+
* float those columns measure zero and the seat falls back to the window.
|
|
350
|
+
*/
|
|
224
351
|
function floatSeat(size) {
|
|
225
352
|
const snap = (value) => Math.max(0, Math.round(value / GRID) * GRID)
|
|
353
|
+
const room = middleRoom()
|
|
354
|
+
const free = room.right - room.left
|
|
226
355
|
return {
|
|
227
|
-
x: snap(
|
|
356
|
+
x: free > size.width ? snap(room.left + (free - size.width) / 2) : snap(room.left),
|
|
228
357
|
y: Math.max(48, snap((window.innerHeight - size.height) / 2)),
|
|
229
358
|
}
|
|
230
359
|
}
|
|
@@ -237,6 +366,9 @@ window.__ModuleLoader__.load({
|
|
|
237
366
|
* The pane id is the float element's own `data-dockkit-float` value.
|
|
238
367
|
*/
|
|
239
368
|
function sizeFloat() {
|
|
369
|
+
// Never move a panel the user has their hand on: the seat is a starting
|
|
370
|
+
// place, and re-applying it mid-drag yanks the float out from under them.
|
|
371
|
+
if (draggingFloat) return
|
|
240
372
|
const panel = floatPanel()
|
|
241
373
|
if (panel === null) return
|
|
242
374
|
const paneId = panel.getAttribute(FLOAT_ATTR) ?? document.querySelector(`[${FLOAT_ATTR}]`)?.getAttribute(FLOAT_ATTR)
|
|
@@ -306,10 +438,15 @@ window.__ModuleLoader__.load({
|
|
|
306
438
|
return false
|
|
307
439
|
}
|
|
308
440
|
}
|
|
309
|
-
function attachColumn(container) {
|
|
441
|
+
function attachColumn(container, keepHome = false) {
|
|
310
442
|
const column = findColumn()
|
|
311
443
|
if (column === null || container === null) return null
|
|
312
|
-
|
|
444
|
+
// Never feed a node its own descendant: that append throws and leaves the
|
|
445
|
+
// bookkeeping pointing at a node that was never moved.
|
|
446
|
+
if (column.contains(container)) return null
|
|
447
|
+
// A retained body that takes the column over from another body keeps the
|
|
448
|
+
// seat recorded first: the middle column, never the tab it came from.
|
|
449
|
+
if (!keepHome || movedFrom === null) movedFrom = { parent: column.parentNode, next: column.nextSibling }
|
|
313
450
|
movedColumn = column
|
|
314
451
|
column.style.width = "100%"
|
|
315
452
|
column.style.height = "100%"
|
|
@@ -323,6 +460,15 @@ window.__ModuleLoader__.load({
|
|
|
323
460
|
// intent its own resize drag uses — for the configured one.
|
|
324
461
|
sizeFloat()
|
|
325
462
|
|
|
463
|
+
// A host has taken the column, so a docking that was waiting for its tab
|
|
464
|
+
// has arrived: the restore guard must not outlive it.
|
|
465
|
+
dockingRight = false
|
|
466
|
+
|
|
467
|
+
// The drawer action asked for the conversation while no float existed. The
|
|
468
|
+
// body is mounted in a layout effect — before paint — so stowing here means
|
|
469
|
+
// the float is never painted on its way into the drawer.
|
|
470
|
+
if (pendingStow && flushPendingStow()) return column
|
|
471
|
+
|
|
326
472
|
// The float body is mounted now, so a hide that was waiting for it can be
|
|
327
473
|
// applied against a real float element.
|
|
328
474
|
if (pendingChromeless) setChromeless(true)
|
|
@@ -330,6 +476,25 @@ window.__ModuleLoader__.load({
|
|
|
330
476
|
}
|
|
331
477
|
|
|
332
478
|
|
|
479
|
+
/**
|
|
480
|
+
* Where the column belongs in the frame: the seat recorded when it was
|
|
481
|
+
* taken, or — when a re-render replaced that seat's neighbours — the spot
|
|
482
|
+
* the middle column keeps, right before the right column.
|
|
483
|
+
*/
|
|
484
|
+
function homeSeat(home) {
|
|
485
|
+
if (home !== null && home.parent !== null && home.parent.isConnected) {
|
|
486
|
+
const next = home.next
|
|
487
|
+
if (next === null || next.parentNode === home.parent) return { parent: home.parent, before: next }
|
|
488
|
+
}
|
|
489
|
+
const overlay = document.querySelector('[data-shell-overlay]')
|
|
490
|
+
const frame = overlay === null ? null : overlay.parentElement
|
|
491
|
+
if (frame === null) return null
|
|
492
|
+
const before = frame.querySelector(':scope > [data-rightbar-col]') ??
|
|
493
|
+
frame.querySelector(':scope > [data-shell-bottom]') ??
|
|
494
|
+
frame.querySelector(':scope > [data-shell-overlay]')
|
|
495
|
+
return { parent: frame, before }
|
|
496
|
+
}
|
|
497
|
+
|
|
333
498
|
/** The frame's middle column, used when the recorded home was re-rendered. */
|
|
334
499
|
function currentCenter() {
|
|
335
500
|
const overlay = document.querySelector('[data-shell-overlay]')
|
|
@@ -346,11 +511,32 @@ window.__ModuleLoader__.load({
|
|
|
346
511
|
return null
|
|
347
512
|
}
|
|
348
513
|
|
|
349
|
-
|
|
514
|
+
/**
|
|
515
|
+
* Whether DSH is showing a page (plugins, automation, settings) in the main
|
|
516
|
+
* panel instead of the Conversation. The panel host lives inside the column
|
|
517
|
+
* we move, so a page rendered while the column sits in a float — and DSH
|
|
518
|
+
* suppresses the whole float while a page is open — would be invisible.
|
|
519
|
+
*/
|
|
520
|
+
function mainPanelOpen() {
|
|
521
|
+
const slot = document.querySelector('[data-slot="main"]')
|
|
522
|
+
if (slot === null) return false
|
|
523
|
+
for (const child of slot.children) {
|
|
524
|
+
if (child.getAttribute('data-slot') === 'main.conversation') continue
|
|
525
|
+
return true
|
|
526
|
+
}
|
|
527
|
+
return false
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
function detachColumn(keepChrome = false) {
|
|
350
531
|
const column = movedColumn
|
|
351
532
|
const home = movedFrom
|
|
352
533
|
movedColumn = null
|
|
353
534
|
movedFrom = null
|
|
535
|
+
notifyState()
|
|
536
|
+
// Closing is the plugin's doing, even when a click on the panel's own
|
|
537
|
+
// close button started it: the columns DSH re-rails on the way out must
|
|
538
|
+
// not be read as the user's own arrangement.
|
|
539
|
+
holdOff(1200)
|
|
354
540
|
for (const el of document.querySelectorAll(`[${OWN_FLOAT_ATTR}]`)) el.removeAttribute(OWN_FLOAT_ATTR)
|
|
355
541
|
// The float is leaving the screen: the rest of DSH has to come back.
|
|
356
542
|
if (chromeless) setChromeless(false)
|
|
@@ -359,7 +545,7 @@ window.__ModuleLoader__.load({
|
|
|
359
545
|
// out of the left drawer, a remounted float body) also detaches it for
|
|
360
546
|
// a frame; restoring there would collapse the sidebars under a float
|
|
361
547
|
// that is still on screen.
|
|
362
|
-
if (!dockingRight && !suspendRestore) scheduleRestoreChrome()
|
|
548
|
+
if (!keepChrome && !dockingRight && !suspendRestore) scheduleRestoreChrome()
|
|
363
549
|
dockingRight = false
|
|
364
550
|
if (column === null) return
|
|
365
551
|
column.style.width = ''
|
|
@@ -367,8 +553,13 @@ window.__ModuleLoader__.load({
|
|
|
367
553
|
column.style.minWidth = ''
|
|
368
554
|
column.style.minHeight = ''
|
|
369
555
|
column.style.overflow = ''
|
|
370
|
-
|
|
371
|
-
|
|
556
|
+
// DSH took the Conversation down while it was ours (a main panel opened,
|
|
557
|
+
// the Session changed): a node React has removed must not be put back, or
|
|
558
|
+
// a stale copy of the conversation would sit in the middle column.
|
|
559
|
+
if (!column.isConnected) return
|
|
560
|
+
const seat = homeSeat(home)
|
|
561
|
+
if (seat !== null) {
|
|
562
|
+
seat.parent.insertBefore(column, seat.before)
|
|
372
563
|
return
|
|
373
564
|
}
|
|
374
565
|
// The recorded seat is gone (the panel took it down with it): put the
|
|
@@ -391,11 +582,55 @@ window.__ModuleLoader__.load({
|
|
|
391
582
|
let sizeTries = 0
|
|
392
583
|
let seenParent = null
|
|
393
584
|
let seenHost = null
|
|
585
|
+
/** Whether the last pass saw the host suppressed by a main panel. */
|
|
586
|
+
let wasSuppressed = false
|
|
394
587
|
let frame = 0
|
|
395
588
|
const check = () => {
|
|
396
589
|
frame = 0
|
|
397
590
|
if (movedColumn !== null && !movedColumn.isConnected) detachColumn()
|
|
591
|
+
// A float belongs to one Session: the right sidebar keeps one panel per
|
|
592
|
+
// Session and hides the rest. Switching Sessions leaves the column in
|
|
593
|
+
// the panel of the one the window has left, where it measures zero —
|
|
594
|
+
// the new Session then has no visible Conversation at all (a blank
|
|
595
|
+
// window). The column comes home as soon as its float is not the one.
|
|
596
|
+
// The column can also end up inside a float with no bookkeeping at all
|
|
597
|
+
// (a docking hand-off that dropped it there): take it back and send it
|
|
598
|
+
// home, or the Conversation would sit in a hidden panel for good.
|
|
599
|
+
if (movedColumn === null) {
|
|
600
|
+
const stray = findColumn()
|
|
601
|
+
const host = stray === null ? null : stray.closest(`[${FLOAT_ATTR}]`)
|
|
602
|
+
if (host !== null && (!floatHostsSession(host, columnSession(stray)) || !panelVisible(host))) {
|
|
603
|
+
movedColumn = stray
|
|
604
|
+
movedFrom = null
|
|
605
|
+
detachColumn(true)
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
const aboard = movedColumn === null ? null : movedColumn.closest(`[${FLOAT_ATTR}]`)
|
|
609
|
+
if (aboard !== null) {
|
|
610
|
+
const showing = columnSession(movedColumn)
|
|
611
|
+
const foreign = !floatHostsSession(aboard, showing)
|
|
612
|
+
const visible = panelVisible(aboard)
|
|
613
|
+
if (foreign || !visible) {
|
|
614
|
+
// Switching Conversations is not closing the float: the column comes
|
|
615
|
+
// home, but the sidebars and the drawer row stay exactly as they are.
|
|
616
|
+
detachColumn(true)
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
// A page owns the main panel: hand the column back to the frame for as
|
|
620
|
+
// long as it lasts, or the page would be drawn inside a hidden float.
|
|
621
|
+
const pageOpen = mainPanelOpen()
|
|
622
|
+
if (pageOpen && movedColumn !== null && movedColumn.closest('[data-rightbar-col]') !== null) {
|
|
623
|
+
detachColumn(true)
|
|
624
|
+
}
|
|
625
|
+
// A docked tab's body is retained across tab, Session and collapse
|
|
626
|
+
// changes, so the column follows whichever of those bodies is on
|
|
627
|
+
// screen instead of being handed back to the middle column.
|
|
628
|
+
if (!pageOpen) reconcileDockedHost()
|
|
398
629
|
const panel = floatPanel()
|
|
630
|
+
// A stow asked for while the conversation was still a docked tab lands
|
|
631
|
+
// here: the tab's body is retained, so floating it remounts nothing and
|
|
632
|
+
// the request would otherwise stay pending forever.
|
|
633
|
+
if (pendingStow) flushPendingStow()
|
|
399
634
|
// Never stay hidden without a float: that is a blank window.
|
|
400
635
|
if (chromeless && panel === null) setChromeless(false)
|
|
401
636
|
// The repairs below walk the whole frame, so they run only when the
|
|
@@ -420,12 +655,23 @@ window.__ModuleLoader__.load({
|
|
|
420
655
|
seenFloat = panel
|
|
421
656
|
seenParent = parent
|
|
422
657
|
seenHost = host
|
|
423
|
-
if (panel !== null)
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
658
|
+
if (panel !== null && chromeless) refreshChromeless()
|
|
659
|
+
}
|
|
660
|
+
// The float may lose its body to a panel page or a re-render without its
|
|
661
|
+
// own structure changing, so the body is healed on every pass — but never
|
|
662
|
+
// while the host is suppressed for a main panel, or the conversation
|
|
663
|
+
// would be parked in a hidden float.
|
|
664
|
+
if (panel !== null && !panel.hasAttribute('aria-hidden') && !pageOpen) healFloatBody()
|
|
665
|
+
// A main panel suppresses the float, and the dock kit gives it back at a
|
|
666
|
+
// fresh default seat: put it where the sidebars leave room again.
|
|
667
|
+
if (panel !== null) {
|
|
668
|
+
const suppressed = panel.hasAttribute('aria-hidden')
|
|
669
|
+
if (wasSuppressed && !suppressed) settleFloatSeat()
|
|
670
|
+
wasSuppressed = suppressed
|
|
427
671
|
}
|
|
428
672
|
noteChromeChange()
|
|
673
|
+
// The row follows the markers, whichever Conversation they belong to.
|
|
674
|
+
syncDrawerRow()
|
|
429
675
|
}
|
|
430
676
|
|
|
431
677
|
|
|
@@ -435,9 +681,45 @@ window.__ModuleLoader__.load({
|
|
|
435
681
|
}
|
|
436
682
|
const observer = new MutationObserver(schedule)
|
|
437
683
|
observer.observe(document.body, { childList: true, subtree: true })
|
|
684
|
+
// A safety pass: Session switches, page swaps and a torn-down body can
|
|
685
|
+
// all land between two mutation batches, and a missed pass leaves the
|
|
686
|
+
// Conversation inside a hidden panel. The reaper is cheap on a quiet
|
|
687
|
+
// window and it never has to wait longer than this.
|
|
688
|
+
const safety = window.setInterval(check, 600)
|
|
689
|
+
|
|
690
|
+
// Switching tab, Session, or collapsing the column leaves the nodes in
|
|
691
|
+
// place and only rewrites attributes: a retained body never remounts, so
|
|
692
|
+
// those changes have to reach the check as well.
|
|
693
|
+
const attributeObserver = new MutationObserver((records) => {
|
|
694
|
+
for (const record of records) {
|
|
695
|
+
const target = record.target
|
|
696
|
+
if (!(target instanceof Element)) continue
|
|
697
|
+
if (target.closest('[data-rightbar-col]') !== null) {
|
|
698
|
+
schedule()
|
|
699
|
+
return
|
|
700
|
+
}
|
|
701
|
+
// The drawer is the other column whose arrangement matters here; its
|
|
702
|
+
// collapse rewrites attributes rather than the node list.
|
|
703
|
+
const drawer = frameSidebar()
|
|
704
|
+
if (drawer !== null && (drawer === target || drawer.contains(target))) {
|
|
705
|
+
schedule()
|
|
706
|
+
return
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
})
|
|
710
|
+
attributeObserver.observe(document.body, {
|
|
711
|
+
attributes: true,
|
|
712
|
+
// The Session marker counts: a Session switch can hide the old panel
|
|
713
|
+
// first and rewrite this marker a commit later, and the reaper has to
|
|
714
|
+
// run again when it does.
|
|
715
|
+
attributeFilter: ['hidden', 'class', 'style', 'aria-hidden', 'data-conversation-session', 'data-dockkit-float'],
|
|
716
|
+
subtree: true,
|
|
717
|
+
})
|
|
438
718
|
|
|
439
719
|
return () => {
|
|
440
720
|
observer.disconnect()
|
|
721
|
+
attributeObserver.disconnect()
|
|
722
|
+
window.clearInterval(safety)
|
|
441
723
|
if (frame !== 0) window.cancelAnimationFrame(frame)
|
|
442
724
|
}
|
|
443
725
|
}
|
|
@@ -450,13 +732,168 @@ window.__ModuleLoader__.load({
|
|
|
450
732
|
function healFloatBody() {
|
|
451
733
|
const panel = floatPanel()
|
|
452
734
|
if (panel === null) return
|
|
735
|
+
// A float of a Session the window has left, or one hidden behind another
|
|
736
|
+
// Session, is not a host: healing into it would hide the live Conversation.
|
|
737
|
+
if (!panelVisible(panel)) return
|
|
453
738
|
const host = panel.querySelector('.dsw-host')
|
|
454
739
|
if (host === null) return
|
|
455
|
-
if (movedColumn !== null && host.contains(movedColumn)) return
|
|
456
740
|
const column = findColumn()
|
|
457
|
-
if (column === null
|
|
458
|
-
|
|
741
|
+
if (column === null) return
|
|
742
|
+
if (!floatHostsSession(panel, columnSession(column))) return
|
|
743
|
+
// A stowed float is a drawer, not a seat: returning to this Conversation
|
|
744
|
+
// shows the drawer state again — the column lives in the hidden panel and
|
|
745
|
+
// the middle stays empty until the row brings it back.
|
|
746
|
+
if (panel.hasAttribute(STOW_ATTR)) {
|
|
747
|
+
if (movedColumn === null || !host.contains(movedColumn)) attachColumn(host, movedColumn !== null)
|
|
748
|
+
return
|
|
749
|
+
}
|
|
750
|
+
if (host.contains(column)) {
|
|
751
|
+
// The body was torn down between two passes and the column is already
|
|
752
|
+
// back inside it, but nothing records that: adopt it. An untracked
|
|
753
|
+
// column is not watched, so the next Session switch would leave the
|
|
754
|
+
// Conversation inside a hidden panel for good.
|
|
755
|
+
adoptColumn(column)
|
|
756
|
+
return
|
|
757
|
+
}
|
|
758
|
+
// A column that is already ours keeps the seat it came from: the float is
|
|
759
|
+
// a temporary host, never the place it goes home to.
|
|
760
|
+
attachColumn(host, movedColumn !== null)
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
/** Take the live column back without moving it: the host already holds it. */
|
|
764
|
+
function adoptColumn(column) {
|
|
765
|
+
movedColumn = column
|
|
766
|
+
if (column.style.width !== '100%') {
|
|
767
|
+
column.style.width = '100%'
|
|
768
|
+
column.style.height = '100%'
|
|
769
|
+
column.style.minWidth = '0'
|
|
770
|
+
column.style.minHeight = '0'
|
|
771
|
+
column.style.overflow = 'hidden'
|
|
772
|
+
}
|
|
773
|
+
if (movedFrom === null) {
|
|
774
|
+
const seat = homeSeat(null)
|
|
775
|
+
if (seat !== null) movedFrom = { parent: seat.parent, next: seat.before }
|
|
776
|
+
}
|
|
777
|
+
const ownPanel = floatPanel()
|
|
778
|
+
// The float keeps the seat the user gave it: this pass runs on every DOM
|
|
779
|
+
// change, so asking the dock kit for the default rectangle here would drag
|
|
780
|
+
// the panel back under the pointer and make it impossible to move.
|
|
781
|
+
if (ownPanel !== null && !ownPanel.hasAttribute(OWN_FLOAT_ATTR)) ownPanel.setAttribute(OWN_FLOAT_ATTR, '')
|
|
782
|
+
}
|
|
783
|
+
/** Every mounted body of our own tab: one per right-sidebar Session. */
|
|
784
|
+
function dockedHosts() {
|
|
785
|
+
const hosts = []
|
|
786
|
+
for (const host of document.querySelectorAll(`[data-sidebar-right-tab] [${BODY_ATTR}]`)) {
|
|
787
|
+
// The floating panel's body is not a docked one.
|
|
788
|
+
if (host.closest(`[${FLOAT_ATTR}]`) === null) hosts.push(host)
|
|
789
|
+
}
|
|
790
|
+
return hosts
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
/** The frame's left column (the drawer), when the frame is mounted. */
|
|
794
|
+
function frameSidebar() {
|
|
795
|
+
const overlay = document.querySelector('[data-shell-overlay]')
|
|
796
|
+
const frame = overlay === null ? null : overlay.parentElement
|
|
797
|
+
return frame === null ? null : frame.firstElementChild
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
/** Whether a host is on screen: a retained body of a hidden tab is not. */
|
|
801
|
+
function hostOnScreen(host) {
|
|
802
|
+
if (!host.isConnected) return false
|
|
803
|
+
const box = host.getBoundingClientRect()
|
|
804
|
+
return box.width > 0 && box.height > 0
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
/** The Session the column is showing right now. */
|
|
808
|
+
function columnSession(column) {
|
|
809
|
+
const mark = column.querySelector('[data-conversation-session]')
|
|
810
|
+
return mark === null ? null : mark.getAttribute('data-conversation-session')
|
|
459
811
|
}
|
|
812
|
+
|
|
813
|
+
/** The Session a docked body belongs to. */
|
|
814
|
+
function hostSession(host) {
|
|
815
|
+
const owner = host.closest('[data-sidebar-right-session]')
|
|
816
|
+
return owner === null ? null : owner.getAttribute('data-sidebar-right-session')
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
/** The Session a floating panel belongs to, or null when it carries none. */
|
|
820
|
+
function floatOwnerSession(panel) {
|
|
821
|
+
const owner = panel.closest('[data-sidebar-right-session]')
|
|
822
|
+
return owner === null ? null : owner.getAttribute('data-sidebar-right-session')
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
/**
|
|
826
|
+
* Whether a panel can be seen. The right sidebar keeps one panel per Session
|
|
827
|
+
* and hides the others, so a float of a Session the window has left measures
|
|
828
|
+
* zero: it is still mounted, and it must never be treated as the live host.
|
|
829
|
+
*/
|
|
830
|
+
function panelVisible(panel) {
|
|
831
|
+
if (!panel.isConnected) return false
|
|
832
|
+
if (panel.closest('[hidden], [aria-hidden="true"]') !== null) return false
|
|
833
|
+
const box = panel.getBoundingClientRect()
|
|
834
|
+
return box.width > 0 && box.height > 0
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
/** Whether a float may host the conversation currently showing `session`. */
|
|
838
|
+
function floatHostsSession(panel, session) {
|
|
839
|
+
const owner = floatOwnerSession(panel)
|
|
840
|
+
return owner === null || session === null || owner === session
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
/** The last Session the live Conversation was seen showing. */
|
|
844
|
+
let lastSession = null
|
|
845
|
+
/**
|
|
846
|
+
* The Session the live Conversation is showing right now. It falls back to
|
|
847
|
+
* the last one seen: opening a main panel takes the Conversation down for a
|
|
848
|
+
* commit, and the drawer row press has to know which Conversation it means.
|
|
849
|
+
*/
|
|
850
|
+
function liveSession() {
|
|
851
|
+
const column = movedColumn ?? findColumn()
|
|
852
|
+
const shown = column === null ? null : columnSession(column)
|
|
853
|
+
if (shown !== null) lastSession = shown
|
|
854
|
+
return shown ?? lastSession
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
/**
|
|
858
|
+
* The Conversation column has one host at a time, and a docked tab body is
|
|
859
|
+
* retained rather than unmounted when the user switches tab, switches
|
|
860
|
+
* Session, or collapses the column. So the column follows whichever of
|
|
861
|
+
* those bodies is the one on screen: an unmounted body took the column back
|
|
862
|
+
* to the middle column, and a body that is never remounted would otherwise
|
|
863
|
+
* sit empty while the column stayed in a tab nobody is looking at.
|
|
864
|
+
*
|
|
865
|
+
* A body only ever holds the column while its own Session is the one on
|
|
866
|
+
* screen. The column shows whichever Session is current, so leaving it in
|
|
867
|
+
* the retained body of a Session the user has left would hide the Session
|
|
868
|
+
* they switched to — the window would go blank.
|
|
869
|
+
*/
|
|
870
|
+
function reconcileDockedHost() {
|
|
871
|
+
// A floating panel owns the column while it is on screen; a docked tab
|
|
872
|
+
// behind it never takes the column away.
|
|
873
|
+
if (movedColumn !== null && movedColumn.closest(`[${FLOAT_ATTR}]`) !== null) return
|
|
874
|
+
const hosts = dockedHosts()
|
|
875
|
+
if (hosts.length === 0) return
|
|
876
|
+
const column = movedColumn ?? findColumn()
|
|
877
|
+
const session = column === null ? null : columnSession(column)
|
|
878
|
+
const mine = hosts.filter((host) => {
|
|
879
|
+
if (session === null) return true
|
|
880
|
+
const owner = hostSession(host)
|
|
881
|
+
return owner === null || owner === session
|
|
882
|
+
})
|
|
883
|
+
const visible = mine.find(hostOnScreen)
|
|
884
|
+
if (visible !== undefined) {
|
|
885
|
+
if (movedColumn !== null && visible.contains(movedColumn)) return
|
|
886
|
+
attachColumn(visible, movedColumn !== null)
|
|
887
|
+
return
|
|
888
|
+
}
|
|
889
|
+
// Another tab of this Session is: the retained body is exactly where the
|
|
890
|
+
// column belongs, and the middle column stays empty behind the tab strip.
|
|
891
|
+
if (mine.length > 0) return
|
|
892
|
+
// The Session changed: the middle column is the seat for whatever the
|
|
893
|
+
// window shows now, exactly as it was before the body was retained.
|
|
894
|
+
if (movedColumn !== null) detachColumn()
|
|
895
|
+
}
|
|
896
|
+
|
|
460
897
|
/** Re-apply the hide list: the float may have moved to another branch. */
|
|
461
898
|
function refreshChromeless() {
|
|
462
899
|
for (const el of document.querySelectorAll(`[${CHROME_ATTR}]`)) el.removeAttribute(CHROME_ATTR)
|
|
@@ -491,6 +928,13 @@ window.__ModuleLoader__.load({
|
|
|
491
928
|
return hidden
|
|
492
929
|
}
|
|
493
930
|
|
|
931
|
+
/** What the entry's tooltip promises for the next press. */
|
|
932
|
+
function entryTitle() {
|
|
933
|
+
if (chromeless) return t('showDsh')
|
|
934
|
+
const panel = floatPanel()
|
|
935
|
+
return panel === null || panel.hasAttribute(STOW_ATTR) ? t('floatTitle') : t('hideDsh')
|
|
936
|
+
}
|
|
937
|
+
|
|
494
938
|
function setChromeless(next) {
|
|
495
939
|
if (next) {
|
|
496
940
|
// The float mounts asynchronously: hiding before it exists would hide
|
|
@@ -511,7 +955,7 @@ window.__ModuleLoader__.load({
|
|
|
511
955
|
}
|
|
512
956
|
try {
|
|
513
957
|
const button = document.querySelector(`[${ANCHOR_ATTR}]`)
|
|
514
|
-
if (button !== null) button.title =
|
|
958
|
+
if (button !== null) button.title = entryTitle()
|
|
515
959
|
} catch {
|
|
516
960
|
/* the button may not be mounted */
|
|
517
961
|
}
|
|
@@ -522,25 +966,30 @@ window.__ModuleLoader__.load({
|
|
|
522
966
|
* sidebar, so the window used to come back as "only the right column": a
|
|
523
967
|
* reveal opens the drawer again, the same way opening the float does.
|
|
524
968
|
*/
|
|
525
|
-
function revealChrome() {
|
|
969
|
+
function revealChrome(forceDrawer = false) {
|
|
526
970
|
setChromeless(false)
|
|
527
971
|
// The columns opened here are the plugin's doing, not the user's: a
|
|
528
972
|
// short settle, not a long one, or the user's own first click after the
|
|
529
973
|
// reveal would be ignored as if it were the plugin's.
|
|
530
974
|
holdOff(400)
|
|
531
|
-
//
|
|
532
|
-
//
|
|
533
|
-
//
|
|
975
|
+
// Back to the arrangement the window had: whatever the user last left the
|
|
976
|
+
// sidebars in, or the pair the float found. Never a blanket "both open" —
|
|
977
|
+
// that would undo a sidebar the user closed on purpose.
|
|
978
|
+
const base = restoreTarget()
|
|
979
|
+
// Stowing the float needs its drawer row on screen, whatever the target.
|
|
980
|
+
// The forced drawer is folded into the target itself: a separate toggle
|
|
981
|
+
// would be undone by the retry pass that follows it.
|
|
982
|
+
const target = base === null ? null : forceDrawer ? { ...base, leftCollapsed: false } : base
|
|
983
|
+
if (target !== null) {
|
|
984
|
+
applyChromeTarget(target)
|
|
985
|
+
return
|
|
986
|
+
}
|
|
987
|
+
if (!forceDrawer) return
|
|
534
988
|
try {
|
|
535
989
|
if (leftCollapsed()) layout?.toggleSidebar?.()
|
|
536
990
|
} catch (error) {
|
|
537
991
|
console.warn('[conversation-float] could not expand the left sidebar:', error)
|
|
538
992
|
}
|
|
539
|
-
try {
|
|
540
|
-
if (sidebarRight !== null && sidebarRight.isExpanded?.() === false) sidebarRight.toggleExpanded?.()
|
|
541
|
-
} catch (error) {
|
|
542
|
-
console.warn('[conversation-float] could not expand the right sidebar:', error)
|
|
543
|
-
}
|
|
544
993
|
}
|
|
545
994
|
|
|
546
995
|
/**
|
|
@@ -620,10 +1069,60 @@ window.__ModuleLoader__.load({
|
|
|
620
1069
|
function noteGesture(event) {
|
|
621
1070
|
if (performance.now() < holdOffUntil) return
|
|
622
1071
|
const target = event.target
|
|
623
|
-
if (target instanceof Element
|
|
1072
|
+
if (!(target instanceof Element)) return
|
|
1073
|
+
// The entry and the float are the plugin's own surfaces: a press there is
|
|
1074
|
+
// a drag, a page click or a close, never a sidebar the user just moved.
|
|
1075
|
+
if (target.closest(`[${ANCHOR_ATTR}]`) !== null) return
|
|
1076
|
+
if (target.closest(`[${FLOAT_ATTR}]`) !== null) return
|
|
624
1077
|
gestureAt = performance.now()
|
|
625
1078
|
}
|
|
626
1079
|
|
|
1080
|
+
/**
|
|
1081
|
+
* Note a hand on a float. DSH's dock kit moves the panel itself; from the
|
|
1082
|
+
* first real movement this plugin must stop re-applying the seat, or the
|
|
1083
|
+
* float is pulled back to where the plugin last put it.
|
|
1084
|
+
*/
|
|
1085
|
+
function trackFloatGrab() {
|
|
1086
|
+
const press = (event) => {
|
|
1087
|
+
if (event.button !== undefined && event.button !== 0) return
|
|
1088
|
+
const target = event.target
|
|
1089
|
+
if (!(target instanceof Element)) return
|
|
1090
|
+
if (target.closest(`[${FLOAT_ATTR}]`) === null) return
|
|
1091
|
+
if (movedColumn !== null && movedColumn.contains(target)) return
|
|
1092
|
+
floatGrab = { x: event.clientX, y: event.clientY }
|
|
1093
|
+
}
|
|
1094
|
+
const move = (event) => {
|
|
1095
|
+
if (floatGrab === null) return
|
|
1096
|
+
const dx = event.clientX - floatGrab.x
|
|
1097
|
+
const dy = event.clientY - floatGrab.y
|
|
1098
|
+
// A press that never moves is a click on the float's chrome, not a drag.
|
|
1099
|
+
if (dx * dx + dy * dy > 36) draggingFloat = true
|
|
1100
|
+
}
|
|
1101
|
+
const release = () => {
|
|
1102
|
+
floatGrab = null
|
|
1103
|
+
if (!draggingFloat) return
|
|
1104
|
+
// Let the dock kit finish its own drop before a seat may be applied.
|
|
1105
|
+
window.setTimeout(() => {
|
|
1106
|
+
if (floatGrab === null) draggingFloat = false
|
|
1107
|
+
}, 300)
|
|
1108
|
+
}
|
|
1109
|
+
const pairs = [
|
|
1110
|
+
['pointerdown', press],
|
|
1111
|
+
['mousedown', press],
|
|
1112
|
+
['pointermove', move],
|
|
1113
|
+
['mousemove', move],
|
|
1114
|
+
['pointerup', release],
|
|
1115
|
+
['mouseup', release],
|
|
1116
|
+
['pointercancel', release],
|
|
1117
|
+
]
|
|
1118
|
+
for (const [name, handler] of pairs) window.addEventListener(name, handler, true)
|
|
1119
|
+
window.addEventListener('blur', release)
|
|
1120
|
+
return () => {
|
|
1121
|
+
for (const [name, handler] of pairs) window.removeEventListener(name, handler, true)
|
|
1122
|
+
window.removeEventListener('blur', release)
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
|
|
627
1126
|
/**
|
|
628
1127
|
* Remember the sidebars as they were before the float forced them open.
|
|
629
1128
|
* The capture happens once, before the plugin touches anything, and is
|
|
@@ -634,7 +1133,7 @@ window.__ModuleLoader__.load({
|
|
|
634
1133
|
function saveChromeState() {
|
|
635
1134
|
if (savedChrome !== null) return
|
|
636
1135
|
savedChrome = chromeNow()
|
|
637
|
-
|
|
1136
|
+
touchedChrome = null
|
|
638
1137
|
// The force-open that follows is the plugin's doing, not the user's.
|
|
639
1138
|
holdOff(FORCE_SETTLE_MS)
|
|
640
1139
|
}
|
|
@@ -659,12 +1158,12 @@ window.__ModuleLoader__.load({
|
|
|
659
1158
|
if (dockedLeft || (floatPanel() !== null && movedColumn === null)) return
|
|
660
1159
|
const now = performance.now()
|
|
661
1160
|
if (now < holdOffUntil) return
|
|
662
|
-
const current = chromeNow()
|
|
663
|
-
// Back on the snapshot's own pair: there is nothing to remember, and the
|
|
664
|
-
// restore would be a no-op anyway.
|
|
665
|
-
if (current.leftCollapsed === savedChrome.leftCollapsed && current.rightExpanded === savedChrome.rightExpanded) return
|
|
666
1161
|
if (now - gestureAt > GESTURE_WINDOW) return
|
|
667
|
-
|
|
1162
|
+
// The user's own arrangement outranks the pair the float found: a reveal
|
|
1163
|
+
// or a close puts back whatever they last chose. With no such choice the
|
|
1164
|
+
// snapshot stays the target, so the restore is a no-op when they left the
|
|
1165
|
+
// sidebars exactly as the float found them.
|
|
1166
|
+
touchedChrome = chromeNow()
|
|
668
1167
|
}
|
|
669
1168
|
|
|
670
1169
|
/**
|
|
@@ -687,22 +1186,23 @@ window.__ModuleLoader__.load({
|
|
|
687
1186
|
}
|
|
688
1187
|
|
|
689
1188
|
/**
|
|
690
|
-
* Put back
|
|
691
|
-
* while the float's tab is still being
|
|
692
|
-
* swallow a toggle aimed at a surface that
|
|
693
|
-
* is reapplied until both columns match it or
|
|
1189
|
+
* Put back the sidebars the window had: the user's own last arrangement, or
|
|
1190
|
+
* the pair the float found. This runs while the float's tab is still being
|
|
1191
|
+
* torn down, and the dock kit can swallow a toggle aimed at a surface that
|
|
1192
|
+
* is on its way out: the target is reapplied until both columns match it or
|
|
1193
|
+
* the attempts run out.
|
|
694
1194
|
*/
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
1195
|
+
/** The pair a reveal or a close puts back: the user's own, else the float's. */
|
|
1196
|
+
function restoreTarget() {
|
|
1197
|
+
return touchedChrome ?? savedChrome
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1200
|
+
/** Match the sidebars to a target, retrying while the dock kit settles. */
|
|
1201
|
+
function applyChromeTarget(target) {
|
|
702
1202
|
let tries = 0
|
|
703
1203
|
const apply = () => {
|
|
704
1204
|
tries += 1
|
|
705
|
-
if (applyChromeSnapshot(
|
|
1205
|
+
if (applyChromeSnapshot(target)) return
|
|
706
1206
|
// A toggle the dock kit queued needs a moment to land; retrying on the
|
|
707
1207
|
// next frame would read the old state and toggle straight back.
|
|
708
1208
|
if (tries < 8) window.setTimeout(apply, 200)
|
|
@@ -710,6 +1210,15 @@ window.__ModuleLoader__.load({
|
|
|
710
1210
|
window.requestAnimationFrame(apply)
|
|
711
1211
|
}
|
|
712
1212
|
|
|
1213
|
+
function restoreChrome() {
|
|
1214
|
+
const target = restoreTarget()
|
|
1215
|
+
savedChrome = null
|
|
1216
|
+
touchedChrome = null
|
|
1217
|
+
if (target === null) return
|
|
1218
|
+
holdOff(1500)
|
|
1219
|
+
applyChromeTarget(target)
|
|
1220
|
+
}
|
|
1221
|
+
|
|
713
1222
|
/** Open (or focus) the float at the dock kit's own default seat. */
|
|
714
1223
|
function openFloatAtDefault() {
|
|
715
1224
|
saveChromeState()
|
|
@@ -728,7 +1237,11 @@ window.__ModuleLoader__.load({
|
|
|
728
1237
|
console.warn('[conversation-float] could not expand the right sidebar:', error)
|
|
729
1238
|
}
|
|
730
1239
|
if (floatExistingTab()) {
|
|
731
|
-
|
|
1240
|
+
notifyState()
|
|
1241
|
+
settleFloatSeat()
|
|
1242
|
+
// The tab was retained, so its body does not mount again: a stow that
|
|
1243
|
+
// was waiting for that mount has to be finished here, now.
|
|
1244
|
+
flushPendingStow()
|
|
732
1245
|
return
|
|
733
1246
|
}
|
|
734
1247
|
try {
|
|
@@ -736,56 +1249,144 @@ window.__ModuleLoader__.load({
|
|
|
736
1249
|
} catch (error) {
|
|
737
1250
|
console.warn('[conversation-float] could not open the floating panel:', error)
|
|
738
1251
|
}
|
|
739
|
-
// Opening the float
|
|
740
|
-
|
|
1252
|
+
// Opening the float keeps the rest of DSH on screen: the entry drops the
|
|
1253
|
+
// window to the float on the NEXT press, not this one.
|
|
1254
|
+
notifyState()
|
|
1255
|
+
settleFloatSeat()
|
|
741
1256
|
}
|
|
742
1257
|
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
1258
|
+
/**
|
|
1259
|
+
* Keep asking for the seat while the sidebars finish opening. The expand
|
|
1260
|
+
* runs on the same tick as the panel and the column slides in after that, so
|
|
1261
|
+
* the first measurements see a room that is still moving; the passes stop
|
|
1262
|
+
* once the float already sits where the settled room puts it.
|
|
1263
|
+
*/
|
|
1264
|
+
function settleFloatSeat(attempt = 0) {
|
|
1265
|
+
// The float is already readable at the size asked for; a hand on it wins.
|
|
1266
|
+
if (draggingFloat) return
|
|
1267
|
+
const panel = floatPanel()
|
|
1268
|
+
if (panel !== null) {
|
|
1269
|
+
const size = floatSize()
|
|
1270
|
+
const seat = floatSeat(size)
|
|
1271
|
+
const box = panel.getBoundingClientRect()
|
|
1272
|
+
if (Math.abs(box.x - seat.x) > 8 || Math.abs(box.width - size.width) > 24) sizeFloat()
|
|
1273
|
+
}
|
|
1274
|
+
if (attempt < 5) window.setTimeout(() => settleFloatSeat(attempt + 1), 250)
|
|
1275
|
+
}
|
|
1276
|
+
|
|
1277
|
+
function openFloating(attempt = 0) {
|
|
1278
|
+
// The float of the Conversation on screen: bring that one back. A stow
|
|
1279
|
+
// that belongs to another Conversation stays in the drawer — the row is
|
|
1280
|
+
// shared, the panels are not.
|
|
1281
|
+
const stowed = stowedFloat()
|
|
1282
|
+
if (stowed !== null) {
|
|
1283
|
+
stowed.removeAttribute(STOW_ATTR)
|
|
1284
|
+
if (floatOwnerSession(stowed) === stowedSession) stowedSession = null
|
|
1285
|
+
syncDrawerRow()
|
|
1286
|
+
notifyState()
|
|
1287
|
+
// The live column returns to this float on the next watcher pass; the
|
|
1288
|
+
// panel keeps the seat it had, so a reopened float does not recentre.
|
|
747
1289
|
return
|
|
748
1290
|
}
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
1291
|
+
if (floatPanel() !== null) {
|
|
1292
|
+
notifyState()
|
|
1293
|
+
return
|
|
1294
|
+
}
|
|
1295
|
+
// The drawer row opens a main panel first, and the dock kit suppresses a
|
|
1296
|
+
// float while a page owns the panel: ask again once that page has closed.
|
|
1297
|
+
if (mainPanelOpen()) {
|
|
1298
|
+
if (attempt < 15) window.setTimeout(() => openFloating(attempt + 1), 40)
|
|
1299
|
+
return
|
|
1300
|
+
}
|
|
1301
|
+
openFloatAtDefault()
|
|
758
1302
|
}
|
|
759
1303
|
|
|
760
|
-
/**
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
1304
|
+
/**
|
|
1305
|
+
* The stowed float belonging to the Conversation on screen, or null.
|
|
1306
|
+
*
|
|
1307
|
+
* It is found by owner, not by visibility: pressing the drawer row opens a
|
|
1308
|
+
* main panel first, and that hides every Session panel for a commit — the
|
|
1309
|
+
* one frame in which this lookup has to keep working.
|
|
1310
|
+
*/
|
|
1311
|
+
function stowedFloat() {
|
|
1312
|
+
const showing = liveSession()
|
|
1313
|
+
for (const el of document.querySelectorAll(`[${STOW_ATTR}]`)) {
|
|
1314
|
+
const owner = floatOwnerSession(el)
|
|
1315
|
+
if (owner === null || showing === null || owner === showing) return el
|
|
767
1316
|
}
|
|
1317
|
+
return null
|
|
1318
|
+
}
|
|
1319
|
+
|
|
1320
|
+
/** Whether any of our floats is stowed, in any Conversation. */
|
|
1321
|
+
function anyStowed() {
|
|
1322
|
+
return document.querySelector(`[${STOW_ATTR}]`) !== null
|
|
1323
|
+
}
|
|
1324
|
+
|
|
1325
|
+
/** The stored title the row promises: the stowed Conversation's own name. */
|
|
1326
|
+
function sessionTitle(id) {
|
|
1327
|
+
if (id === null) return null
|
|
768
1328
|
try {
|
|
769
|
-
const
|
|
770
|
-
|
|
771
|
-
const walk = (value, depth) => {
|
|
772
|
-
if (value === null || value === undefined || depth > 6) return
|
|
773
|
-
if (Array.isArray(value)) {
|
|
774
|
-
for (const item of value) walk(item, depth + 1)
|
|
775
|
-
return
|
|
776
|
-
}
|
|
777
|
-
if (typeof value !== 'object') return
|
|
778
|
-
if (value.kind === CHAT_KIND && typeof value.id === 'string') found.add(value.id)
|
|
779
|
-
for (const key of Object.keys(value)) walk(value[key], depth + 1)
|
|
780
|
-
}
|
|
781
|
-
walk(snapshot, 0)
|
|
782
|
-
const ids = Array.from(found)
|
|
783
|
-
return ids.length === 1 ? ids[0] : (ids[ids.length - 1] ?? null)
|
|
1329
|
+
const title = sessions?.list?.getSnapshot?.()?.byId?.[id]?.title
|
|
1330
|
+
return typeof title === 'string' && title.trim() !== '' ? title.trim() : null
|
|
784
1331
|
} catch {
|
|
785
1332
|
return null
|
|
786
1333
|
}
|
|
787
1334
|
}
|
|
788
1335
|
|
|
1336
|
+
/** What the drawer row says: the stowed Conversation, else the plugin's name. */
|
|
1337
|
+
function dockRowLabel() {
|
|
1338
|
+
return sessionTitle(stowedSession ?? stowedOwner()) ?? t('floatTitle')
|
|
1339
|
+
}
|
|
1340
|
+
|
|
1341
|
+
/**
|
|
1342
|
+
* The Conversation a stowed float belongs to, read from the panel itself so
|
|
1343
|
+
* that a marker left over from an earlier run still names someone.
|
|
1344
|
+
*/
|
|
1345
|
+
function stowedOwner() {
|
|
1346
|
+
const el = document.querySelector(`[${STOW_ATTR}]`)
|
|
1347
|
+
if (el === null) return null
|
|
1348
|
+
return floatOwnerSession(el) ?? liveSession()
|
|
1349
|
+
}
|
|
1350
|
+
|
|
1351
|
+
/**
|
|
1352
|
+
* The row lives while a stowed float exists, and it is named after that
|
|
1353
|
+
* Conversation. It stays put when the window switches Sessions: the row is
|
|
1354
|
+
* the way back to the stowed one, never a view of the current one.
|
|
1355
|
+
*/
|
|
1356
|
+
function syncDrawerRow() {
|
|
1357
|
+
dockedLeft = anyStowed()
|
|
1358
|
+
if (!dockedLeft) {
|
|
1359
|
+
stowedSession = null
|
|
1360
|
+
syncDockRow()
|
|
1361
|
+
return
|
|
1362
|
+
}
|
|
1363
|
+
if (stowedSession === null) stowedSession = stowedOwner()
|
|
1364
|
+
// One box, never a pile: a state left by an earlier build (several
|
|
1365
|
+
// markers at once) is pruned down to the row's own Conversation.
|
|
1366
|
+
if (document.querySelectorAll(`[${STOW_ATTR}]`).length > 1) releaseStowedExcept(stowedSession)
|
|
1367
|
+
syncDockRow()
|
|
1368
|
+
}
|
|
1369
|
+
|
|
1370
|
+
/**
|
|
1371
|
+
* The tab id of our docked occurrence for the Conversation on screen, or
|
|
1372
|
+
* null. It is read from the markup of that Session, never from the global
|
|
1373
|
+
* tab inventory: the inventory lists every Session's tabs, and floating one
|
|
1374
|
+
* Session's tab into another would hand the wrong Conversation to the float.
|
|
1375
|
+
*/
|
|
1376
|
+
function floatTabId() {
|
|
1377
|
+
const sessionId = liveSession()
|
|
1378
|
+
for (const tab of document.querySelectorAll('[data-sidebar-right-tab]')) {
|
|
1379
|
+
const id = tab.getAttribute('data-sidebar-right-tab')
|
|
1380
|
+
if (id === null) continue
|
|
1381
|
+
const owner = tab.closest('[data-sidebar-right-session]')
|
|
1382
|
+
const ownerSid = owner === null ? null : owner.getAttribute('data-sidebar-right-session')
|
|
1383
|
+
if (sessionId !== null && ownerSid !== null && ownerSid !== sessionId) continue
|
|
1384
|
+
if (tab.querySelector(`[${BODY_ATTR}]`) === null) continue
|
|
1385
|
+
return id
|
|
1386
|
+
}
|
|
1387
|
+
return null
|
|
1388
|
+
}
|
|
1389
|
+
|
|
789
1390
|
/** Close the float; the column comes home through the watcher. */
|
|
790
1391
|
function closeFloat() {
|
|
791
1392
|
const id = floatTabId()
|
|
@@ -827,6 +1428,10 @@ window.__ModuleLoader__.load({
|
|
|
827
1428
|
const rightCol = frame.querySelector('[data-rightbar-col]')
|
|
828
1429
|
if (rightCol !== null) right = Math.round(rightCol.getBoundingClientRect().left)
|
|
829
1430
|
}
|
|
1431
|
+
// A collapsed right column measures at the window's edge, which would leave
|
|
1432
|
+
// the "dock right" band zero wide and unreachable; keep a third of the
|
|
1433
|
+
// window aimable there, and the docking itself opens the column.
|
|
1434
|
+
if (right >= width - 1) right = Math.round((width * 2) / 3)
|
|
830
1435
|
// While the columns are hidden the measurements collapse; keep the last
|
|
831
1436
|
// geometry that made sense so a drag does not land in nonsense bands.
|
|
832
1437
|
const sane = left >= 0 && right > left + 80 && right <= width + 1
|
|
@@ -847,7 +1452,15 @@ window.__ModuleLoader__.load({
|
|
|
847
1452
|
return 'center'
|
|
848
1453
|
}
|
|
849
1454
|
|
|
850
|
-
|
|
1455
|
+
/**
|
|
1456
|
+
* The band's caption, read at draw time. It used to be a table built once at
|
|
1457
|
+
* load: a language switch then left the preview saying the old words.
|
|
1458
|
+
*/
|
|
1459
|
+
function zoneLabel(zone) {
|
|
1460
|
+
if (zone === 'left') return t('stow')
|
|
1461
|
+
if (zone === 'right') return t('dock')
|
|
1462
|
+
return t('center')
|
|
1463
|
+
}
|
|
851
1464
|
|
|
852
1465
|
function previewRect(zone, band) {
|
|
853
1466
|
if (zone === 'left') return [0, 0, band.left, band.height]
|
|
@@ -877,7 +1490,7 @@ window.__ModuleLoader__.load({
|
|
|
877
1490
|
preview.el.style.transform = `translate3d(${left}px, ${top}px, 0)`
|
|
878
1491
|
preview.el.style.width = `${width}px`
|
|
879
1492
|
preview.el.style.height = `${height}px`
|
|
880
|
-
preview.label.textContent =
|
|
1493
|
+
preview.label.textContent = zoneLabel(zone)
|
|
881
1494
|
}
|
|
882
1495
|
|
|
883
1496
|
function hidePreview() {
|
|
@@ -900,31 +1513,110 @@ window.__ModuleLoader__.load({
|
|
|
900
1513
|
function floatPanel() {
|
|
901
1514
|
const column = movedColumn
|
|
902
1515
|
const fromColumn = column === null ? null : column.closest(`[${FLOAT_ATTR}]`)
|
|
903
|
-
|
|
1516
|
+
if (fromColumn !== null) return fromColumn
|
|
1517
|
+
// The right sidebar keeps one mounted panel per Session and hides the
|
|
1518
|
+
// ones the window has left. A foreign float is not *the* float: reading it
|
|
1519
|
+
// as one would make the entry believe a panel is on screen and hide DSH
|
|
1520
|
+
// around a window that holds nothing at all.
|
|
1521
|
+
const showing = liveSession()
|
|
1522
|
+
for (const el of document.querySelectorAll(`[${FLOAT_ATTR}]`)) {
|
|
1523
|
+
if (el.closest('[hidden], [aria-hidden="true"]') !== null) continue
|
|
1524
|
+
const owner = floatOwnerSession(el)
|
|
1525
|
+
if (owner !== null && showing !== null && owner !== showing) continue
|
|
1526
|
+
return el
|
|
1527
|
+
}
|
|
1528
|
+
return null
|
|
904
1529
|
}
|
|
905
1530
|
|
|
906
1531
|
function stowFloat() {
|
|
907
1532
|
const el = floatPanel()
|
|
908
1533
|
if (el === null) return false
|
|
1534
|
+
const owner = floatOwnerSession(el) ?? liveSession()
|
|
1535
|
+
// The left drawer holds exactly one Conversation: stowing a new one
|
|
1536
|
+
// replaces the resident, whose float is closed so it goes back to its
|
|
1537
|
+
// own place instead of lingering as an unreachable hidden panel.
|
|
1538
|
+
releaseStowedExcept(owner)
|
|
909
1539
|
el.setAttribute(STOW_ATTR, '')
|
|
1540
|
+
// The row is this Conversation's way back: record who was stowed before
|
|
1541
|
+
// the marker is read back, or a switch would re-point the row later.
|
|
1542
|
+
stowedSession = owner
|
|
1543
|
+
syncDrawerRow()
|
|
910
1544
|
return true
|
|
911
1545
|
}
|
|
912
1546
|
|
|
1547
|
+
/** Close every stowed float of a Conversation other than `keep`. */
|
|
1548
|
+
function releaseStowedExcept(keep) {
|
|
1549
|
+
for (const el of [...document.querySelectorAll(`[${STOW_ATTR}]`)]) {
|
|
1550
|
+
const owner = floatOwnerSession(el)
|
|
1551
|
+
if (owner !== null && owner === keep) continue
|
|
1552
|
+
releaseStowed(el)
|
|
1553
|
+
}
|
|
1554
|
+
}
|
|
1555
|
+
|
|
1556
|
+
/**
|
|
1557
|
+
* Take one float out of the drawer: it goes back to being an ordinary
|
|
1558
|
+
* float, exactly the state it had before it was stowed. It is not closed —
|
|
1559
|
+
* closing a Session's float unmounts its body, and that body's cleanup
|
|
1560
|
+
* would hand the live Conversation column home with it.
|
|
1561
|
+
*/
|
|
1562
|
+
function releaseStowed(el) {
|
|
1563
|
+
el.removeAttribute(STOW_ATTR)
|
|
1564
|
+
}
|
|
1565
|
+
|
|
1566
|
+
/**
|
|
1567
|
+
* Finish a stow that was asked for before its float existed. The first
|
|
1568
|
+
* request arrives while the conversation is still a docked tab — the tab's
|
|
1569
|
+
* body is retained, so floating it does NOT remount the body and
|
|
1570
|
+
* {@link attachColumn} never runs again. Without this the request would sit
|
|
1571
|
+
* in `pendingStow` forever: the conversation would come back as a float
|
|
1572
|
+
* instead of landing in the drawer, which is exactly what the menu entry
|
|
1573
|
+
* promised it would not do.
|
|
1574
|
+
*
|
|
1575
|
+
* @returns whether the float was stowed.
|
|
1576
|
+
*/
|
|
1577
|
+
function flushPendingStow() {
|
|
1578
|
+
if (!pendingStow) return false
|
|
1579
|
+
const panel = floatPanel()
|
|
1580
|
+
if (panel === null) return false
|
|
1581
|
+
// A float of another Session cannot host this Conversation.
|
|
1582
|
+
if (!floatHostsSession(panel, liveSession())) return false
|
|
1583
|
+
pendingStow = false
|
|
1584
|
+
pendingChromeless = false
|
|
1585
|
+
if (!stowFloat()) return false
|
|
1586
|
+
revealChrome(true)
|
|
1587
|
+
window.setTimeout(notifyState, 0)
|
|
1588
|
+
return true
|
|
1589
|
+
}
|
|
1590
|
+
|
|
1591
|
+
/** Abandon a stow that could not be completed; the row follows the markers. */
|
|
1592
|
+
function resetDrawer() {
|
|
1593
|
+
if (pendingStow) {
|
|
1594
|
+
pendingStow = false
|
|
1595
|
+
pendingChromeless = false
|
|
1596
|
+
}
|
|
1597
|
+
syncDrawerRow()
|
|
1598
|
+
}
|
|
1599
|
+
|
|
913
1600
|
function unstowFloat() {
|
|
914
1601
|
for (const el of document.querySelectorAll(`[${STOW_ATTR}]`)) el.removeAttribute(STOW_ATTR)
|
|
1602
|
+
stowedSession = null
|
|
1603
|
+
syncDrawerRow()
|
|
915
1604
|
}
|
|
916
1605
|
|
|
917
1606
|
function drop(zone) {
|
|
918
1607
|
if (zone === 'right') {
|
|
919
|
-
dockedLeft = false
|
|
920
1608
|
dockingRight = true
|
|
921
1609
|
// The float leaves as an ordinary right-sidebar tab. The sidebar
|
|
922
1610
|
// snapshot belonged to the float: keeping it would let a close of that
|
|
923
1611
|
// tab — possibly hours later — move the sidebars back in time.
|
|
924
1612
|
savedChrome = null
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
1613
|
+
touchedChrome = null
|
|
1614
|
+
const docked = floatPanel()
|
|
1615
|
+
if (docked !== null) {
|
|
1616
|
+
docked.removeAttribute(STOW_ATTR)
|
|
1617
|
+
if (floatOwnerSession(docked) === stowedSession) stowedSession = null
|
|
1618
|
+
}
|
|
1619
|
+
syncDrawerRow()
|
|
928
1620
|
try {
|
|
929
1621
|
sidebarRight?.openResource(CHAT_ADDRESS, { kind: CHAT_KIND, destination: 'sidebar' })
|
|
930
1622
|
} catch (error) {
|
|
@@ -933,20 +1625,56 @@ window.__ModuleLoader__.load({
|
|
|
933
1625
|
return
|
|
934
1626
|
}
|
|
935
1627
|
if (zone === 'left') {
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
1628
|
+
if (!stowFloat()) {
|
|
1629
|
+
// No panel to hide: a row without a float would be a button that
|
|
1630
|
+
// reaches nowhere, so the conversation goes back to the middle.
|
|
1631
|
+
resetDrawer()
|
|
1632
|
+
closeFloat()
|
|
1633
|
+
}
|
|
1634
|
+
// The drawer row lives in the left sidebar: bring the chrome back and
|
|
1635
|
+
// make sure that drawer is open, whatever arrangement comes back.
|
|
1636
|
+
revealChrome(true)
|
|
942
1637
|
return
|
|
943
1638
|
}
|
|
944
|
-
|
|
945
|
-
syncDockRow()
|
|
1639
|
+
syncDrawerRow()
|
|
946
1640
|
revealChrome()
|
|
947
1641
|
closeFloat()
|
|
948
1642
|
}
|
|
949
1643
|
|
|
1644
|
+
/* ------------------------------------------------------ the menu entries */
|
|
1645
|
+
|
|
1646
|
+
/**
|
|
1647
|
+
* Whether the live conversation is a docked tab of the right sidebar. The
|
|
1648
|
+
* menu entry that says "move it here" has nothing to do when it is already.
|
|
1649
|
+
*/
|
|
1650
|
+
function conversationInRightbar() {
|
|
1651
|
+
const column = movedColumn ?? findColumn()
|
|
1652
|
+
if (column === null) return false
|
|
1653
|
+
if (column.closest(`[${FLOAT_ATTR}]`) !== null) return false
|
|
1654
|
+
return column.closest('[data-rightbar-col]') !== null
|
|
1655
|
+
}
|
|
1656
|
+
|
|
1657
|
+
/** Dock the conversation in the right sidebar, exactly as a drop does. */
|
|
1658
|
+
function moveConversationRight() {
|
|
1659
|
+
drop('right')
|
|
1660
|
+
}
|
|
1661
|
+
|
|
1662
|
+
/**
|
|
1663
|
+
* Stow the conversation in the left drawer, as a drop there does. Without a
|
|
1664
|
+
* float there is no panel to stow, so the float is opened first and the
|
|
1665
|
+
* stow runs the moment its body mounts — before the first paint — which is
|
|
1666
|
+
* why the conversation never flashes on screen on its way into the drawer.
|
|
1667
|
+
*/
|
|
1668
|
+
function moveConversationLeft() {
|
|
1669
|
+
if (stowedFloat() !== null) return
|
|
1670
|
+
if (floatPanel() !== null) {
|
|
1671
|
+
drop('left')
|
|
1672
|
+
return
|
|
1673
|
+
}
|
|
1674
|
+
pendingStow = true
|
|
1675
|
+
openFloating()
|
|
1676
|
+
}
|
|
1677
|
+
|
|
950
1678
|
/**
|
|
951
1679
|
* Watch the float's own drag. DSH owns the dragging; we only listen. A press
|
|
952
1680
|
* on the float's chrome opens a sequence; a press inside the Conversation
|
|
@@ -1160,26 +1888,39 @@ window.__ModuleLoader__.load({
|
|
|
1160
1888
|
/* ----------------------------------------------------------- the drawer */
|
|
1161
1889
|
|
|
1162
1890
|
function syncDockRow() {
|
|
1163
|
-
if (dockedLeft
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1891
|
+
if (!dockedLeft) {
|
|
1892
|
+
disposeDockRow()
|
|
1893
|
+
dockLabel = null
|
|
1894
|
+
return
|
|
1895
|
+
}
|
|
1896
|
+
// The sidebar resolves a row's label once, when it registers: a row that
|
|
1897
|
+
// must say a different Conversation's name is re-registered, never
|
|
1898
|
+
// rewritten under the sidebar's feet.
|
|
1899
|
+
const label = dockRowLabel()
|
|
1900
|
+
if (dockRow !== null && label === dockLabel) return
|
|
1901
|
+
disposeDockRow()
|
|
1902
|
+
dockLabel = label
|
|
1903
|
+
try {
|
|
1904
|
+
dockRow = ctxRef.slots.register(
|
|
1905
|
+
{ name: 'sidebar.panellist', id: DOCK_ROW_ID, order: 20, label: () => dockLabel },
|
|
1906
|
+
DockIcon,
|
|
1907
|
+
)
|
|
1908
|
+
} catch (error) {
|
|
1909
|
+
console.warn('[conversation-float] could not register the sidebar row:', error)
|
|
1179
1910
|
dockRow = null
|
|
1180
1911
|
}
|
|
1181
1912
|
}
|
|
1182
1913
|
|
|
1914
|
+
function disposeDockRow() {
|
|
1915
|
+
if (dockRow === null) return
|
|
1916
|
+
try {
|
|
1917
|
+
dockRow()
|
|
1918
|
+
} catch {
|
|
1919
|
+
/* already disposed with the slot */
|
|
1920
|
+
}
|
|
1921
|
+
dockRow = null
|
|
1922
|
+
}
|
|
1923
|
+
|
|
1183
1924
|
let ctxRef = null
|
|
1184
1925
|
|
|
1185
1926
|
/* ---------------------------------------------------------- components */
|
|
@@ -1205,11 +1946,22 @@ window.__ModuleLoader__.load({
|
|
|
1205
1946
|
const CSS = `
|
|
1206
1947
|
.dsw-icon {
|
|
1207
1948
|
display: inline-flex; align-items: center; justify-content: center;
|
|
1208
|
-
|
|
1949
|
+
/* Same box as the header's own ghost buttons: 28x28, 8px corner. */
|
|
1950
|
+
width: 28px; height: 28px; padding: 0; border: 0; border-radius: 8px;
|
|
1209
1951
|
background: transparent; color: var(--dsw-alias-label-secondary); cursor: pointer;
|
|
1210
1952
|
transition: background .12s ease, color .12s ease;
|
|
1211
1953
|
}
|
|
1212
|
-
|
|
1954
|
+
/* Same hover surface as the Conversation header's own ghost buttons — a
|
|
1955
|
+
filled layer that is visible on light backgrounds too. */
|
|
1956
|
+
.dsw-icon:hover { background: var(--dsw-alias-interactive-bg-hover, var(--dsw-alias-bg-layer-2)); color: var(--dsw-alias-label-primary); }
|
|
1957
|
+
/* The menu row used only when the host carries no MenuItemButton primitive. */
|
|
1958
|
+
.dsw-menu-row {
|
|
1959
|
+
display: flex; align-items: center; width: 100%; min-height: 32px;
|
|
1960
|
+
padding: 6px 10px; border: 0; border-radius: 6px; background: transparent;
|
|
1961
|
+
font: inherit; text-align: left; color: var(--dsw-alias-label-primary); cursor: pointer;
|
|
1962
|
+
}
|
|
1963
|
+
.dsw-menu-row:hover { background: var(--dsw-alias-bg-layer-2); }
|
|
1964
|
+
.dsw-menu-row:focus-visible { outline: 2px solid var(--dsw-alias-brand-primary); outline-offset: -2px; }
|
|
1213
1965
|
.dsw-icon:focus-visible { outline: 2px solid var(--dsw-alias-brand-primary); outline-offset: 1px; }
|
|
1214
1966
|
.dsw-host {
|
|
1215
1967
|
position: relative;
|
|
@@ -1261,9 +2013,10 @@ window.__ModuleLoader__.load({
|
|
|
1261
2013
|
* rest of DSH back — or hides it again.
|
|
1262
2014
|
*/
|
|
1263
2015
|
function onEntryClick() {
|
|
1264
|
-
//
|
|
1265
|
-
//
|
|
1266
|
-
|
|
2016
|
+
// No float of this Conversation on screen, or one stowed in the drawer:
|
|
2017
|
+
// the button brings the float back instead of toggling the window.
|
|
2018
|
+
const panel = floatPanel()
|
|
2019
|
+
if (panel === null || panel.hasAttribute(STOW_ATTR)) {
|
|
1267
2020
|
openFloating()
|
|
1268
2021
|
return
|
|
1269
2022
|
}
|
|
@@ -1271,6 +2024,94 @@ window.__ModuleLoader__.load({
|
|
|
1271
2024
|
else setChromeless(true)
|
|
1272
2025
|
}
|
|
1273
2026
|
|
|
2027
|
+
/**
|
|
2028
|
+
* The drawer row is DSH's own panel button: pressing it would select the
|
|
2029
|
+
* plugin's main-panel entry, which takes the Conversation down for a commit
|
|
2030
|
+
* — and the dock kit refuses to open a float while a page owns the panel.
|
|
2031
|
+
* Take the press in the capture phase instead: the row means "return to the
|
|
2032
|
+
* stowed Conversation", never "open a page".
|
|
2033
|
+
*/
|
|
2034
|
+
function drawerRowPress(event) {
|
|
2035
|
+
const target = event.target
|
|
2036
|
+
if (!(target instanceof Element)) return
|
|
2037
|
+
const button = target.closest('button')
|
|
2038
|
+
if (button === null) return
|
|
2039
|
+
// The row carries the stowed Conversation's own name, which may collide
|
|
2040
|
+
// with a shipped row's name: the glyph we render is what tells it apart.
|
|
2041
|
+
if (button.querySelector(`[${ROW_MARK_ATTR}]`) === null) return
|
|
2042
|
+
if (button.getAttribute('aria-label') !== (dockLabel ?? dockRowLabel())) return
|
|
2043
|
+
const drawer = frameSidebar()
|
|
2044
|
+
if (drawer === null || !drawer.contains(button)) return
|
|
2045
|
+
event.preventDefault()
|
|
2046
|
+
event.stopPropagation()
|
|
2047
|
+
bringStowedBack()
|
|
2048
|
+
}
|
|
2049
|
+
|
|
2050
|
+
/**
|
|
2051
|
+
* The row's promise: show that Conversation again, with its float back on
|
|
2052
|
+
* screen. The window may be looking at another Conversation — the marker is
|
|
2053
|
+
* shared, the panels are not — so the row switches to the stowed one first.
|
|
2054
|
+
* Its float is already mounted in the right column and only hidden, so once
|
|
2055
|
+
* the switch lands it just has to be un-hidden.
|
|
2056
|
+
*/
|
|
2057
|
+
function bringStowedBack() {
|
|
2058
|
+
const id = stowedSession ?? stowedOwner()
|
|
2059
|
+
if (id === null) {
|
|
2060
|
+
openFloating()
|
|
2061
|
+
return
|
|
2062
|
+
}
|
|
2063
|
+
if (liveSession() === id) {
|
|
2064
|
+
revealStowed(id)
|
|
2065
|
+
return
|
|
2066
|
+
}
|
|
2067
|
+
try {
|
|
2068
|
+
uiWorkspace?.openSession?.(id)
|
|
2069
|
+
} catch (error) {
|
|
2070
|
+
console.warn('[conversation-float] could not return to the stowed Conversation:', error)
|
|
2071
|
+
return
|
|
2072
|
+
}
|
|
2073
|
+
awaitStowedSession(id, 0)
|
|
2074
|
+
}
|
|
2075
|
+
|
|
2076
|
+
/** Wait for the switch to land, then reveal the float; give up at ~3s. */
|
|
2077
|
+
function awaitStowedSession(id, attempt) {
|
|
2078
|
+
if (liveSession() === id) {
|
|
2079
|
+
revealStowed(id)
|
|
2080
|
+
return
|
|
2081
|
+
}
|
|
2082
|
+
if (attempt >= 60) {
|
|
2083
|
+
console.warn('[conversation-float] the stowed Conversation did not open; the row stays')
|
|
2084
|
+
return
|
|
2085
|
+
}
|
|
2086
|
+
window.setTimeout(() => awaitStowedSession(id, attempt + 1), 50)
|
|
2087
|
+
}
|
|
2088
|
+
|
|
2089
|
+
/** Un-hide the stowed float of `id` and keep the column that hosts it open. */
|
|
2090
|
+
function revealStowed(id) {
|
|
2091
|
+
const el = stowedFloatOf(id)
|
|
2092
|
+
if (el !== null) el.removeAttribute(STOW_ATTR)
|
|
2093
|
+
stowedSession = null
|
|
2094
|
+
syncDrawerRow()
|
|
2095
|
+
// The float lives in the right column: a collapsed one has nowhere to put
|
|
2096
|
+
// it, so the same expansion an open does applies here.
|
|
2097
|
+
try {
|
|
2098
|
+
if (sidebarRight !== null && sidebarRight.isExpanded?.() === false) sidebarRight.toggleExpanded?.()
|
|
2099
|
+
} catch (error) {
|
|
2100
|
+
console.warn('[conversation-float] could not expand the right sidebar:', error)
|
|
2101
|
+
}
|
|
2102
|
+
notifyState()
|
|
2103
|
+
sizeFloat()
|
|
2104
|
+
settleFloatSeat()
|
|
2105
|
+
}
|
|
2106
|
+
|
|
2107
|
+
/** The stowed float belonging to `id`, whichever Session is on screen. */
|
|
2108
|
+
function stowedFloatOf(id) {
|
|
2109
|
+
for (const el of document.querySelectorAll(`[${STOW_ATTR}]`)) {
|
|
2110
|
+
if (floatOwnerSession(el) === id) return el
|
|
2111
|
+
}
|
|
2112
|
+
return null
|
|
2113
|
+
}
|
|
2114
|
+
|
|
1274
2115
|
/** Escape always brings DSH back: the way out of a hidden window. */
|
|
1275
2116
|
function escapeOnKey(event) {
|
|
1276
2117
|
if (event.key !== 'Escape' || !chromeless) return
|
|
@@ -1290,8 +2131,8 @@ window.__ModuleLoader__.load({
|
|
|
1290
2131
|
{
|
|
1291
2132
|
type: 'button',
|
|
1292
2133
|
className: 'dsw-icon',
|
|
1293
|
-
title:
|
|
1294
|
-
'aria-label':
|
|
2134
|
+
title: entryTitle(),
|
|
2135
|
+
'aria-label': entryTitle(),
|
|
1295
2136
|
[ANCHOR_ATTR]: '',
|
|
1296
2137
|
onClick: onEntryClick,
|
|
1297
2138
|
},
|
|
@@ -1302,7 +2143,7 @@ window.__ModuleLoader__.load({
|
|
|
1302
2143
|
|
|
1303
2144
|
/** The left sidebar row's glyph. The row itself is owned by the sidebar. */
|
|
1304
2145
|
function DockIcon({ size = 16 }) {
|
|
1305
|
-
return h(Icon, { name: 'window', size })
|
|
2146
|
+
return h('span', { [ROW_MARK_ATTR]: '', style: { display: 'contents' } }, h(Icon, { name: 'window', size }))
|
|
1306
2147
|
}
|
|
1307
2148
|
|
|
1308
2149
|
/**
|
|
@@ -1338,7 +2179,45 @@ window.__ModuleLoader__.load({
|
|
|
1338
2179
|
detachColumn()
|
|
1339
2180
|
}
|
|
1340
2181
|
}, [])
|
|
1341
|
-
return h('div', { className: 'dsw-host', ref: host }, h(Styles))
|
|
2182
|
+
return h('div', { className: 'dsw-host', ref: host, [BODY_ATTR]: '' }, h(Styles))
|
|
2183
|
+
}
|
|
2184
|
+
|
|
2185
|
+
/**
|
|
2186
|
+
* One menu row: the dock kit's own row component when the browser module
|
|
2187
|
+
* table carries it, a plain menu button otherwise. Selecting it closes the
|
|
2188
|
+
* menu first, the way every shipped row does.
|
|
2189
|
+
*/
|
|
2190
|
+
function MoveRow({ onDismiss, label, onSelect }) {
|
|
2191
|
+
const select = () => {
|
|
2192
|
+
try {
|
|
2193
|
+
onDismiss?.()
|
|
2194
|
+
} catch {
|
|
2195
|
+
/* the menu may already be gone */
|
|
2196
|
+
}
|
|
2197
|
+
onSelect()
|
|
2198
|
+
}
|
|
2199
|
+
// The shipped rows lead with a 16px glyph; ours keeps the window one so the
|
|
2200
|
+
// row sits on the same grid instead of starting where the icons do.
|
|
2201
|
+
if (MenuItemButton !== null) return h(MenuItemButton, { icon: h(Icon, { name: 'window' }), onSelect: select }, label)
|
|
2202
|
+
return h('button', { type: 'button', role: 'menuitem', className: 'dsw-menu-row', onClick: select }, label)
|
|
2203
|
+
}
|
|
2204
|
+
|
|
2205
|
+
/**
|
|
2206
|
+
* The left sidebar's More menu: stow the conversation in that drawer. It
|
|
2207
|
+
* hides itself once the float is already stowed there.
|
|
2208
|
+
*/
|
|
2209
|
+
function MoveLeftRow({ onDismiss }) {
|
|
2210
|
+
if (stowedFloat() !== null) return null
|
|
2211
|
+
return h(MoveRow, { onDismiss, label: t('moveLeft'), onSelect: moveConversationLeft })
|
|
2212
|
+
}
|
|
2213
|
+
|
|
2214
|
+
/**
|
|
2215
|
+
* The right sidebar guide's More menu: dock the conversation as a tab there.
|
|
2216
|
+
* It hides itself once the conversation already is one.
|
|
2217
|
+
*/
|
|
2218
|
+
function MoveRightRow({ onDismiss }) {
|
|
2219
|
+
if (conversationInRightbar()) return null
|
|
2220
|
+
return h(MoveRow, { onDismiss, label: t('moveRight'), onSelect: moveConversationRight })
|
|
1342
2221
|
}
|
|
1343
2222
|
|
|
1344
2223
|
/* --------------------------------------------------------------- wiring */
|
|
@@ -1355,6 +2234,15 @@ window.__ModuleLoader__.load({
|
|
|
1355
2234
|
}
|
|
1356
2235
|
})
|
|
1357
2236
|
|
|
2237
|
+
// A language switch happens while the window is open: the entry's own
|
|
2238
|
+
// caption and an outline that is already drawn follow the new table.
|
|
2239
|
+
ctx.effect(() =>
|
|
2240
|
+
ctx.locale.subscribe(() => {
|
|
2241
|
+
notifyState()
|
|
2242
|
+
if (preview !== null && preview.zone !== null) preview.label.textContent = zoneLabel(preview.zone)
|
|
2243
|
+
}),
|
|
2244
|
+
)
|
|
2245
|
+
|
|
1358
2246
|
const register = (slot, id, component, options = {}) =>
|
|
1359
2247
|
ctx.effect(() =>
|
|
1360
2248
|
ctx.slots.inject(slot, () =>
|
|
@@ -1363,14 +2251,25 @@ window.__ModuleLoader__.load({
|
|
|
1363
2251
|
)
|
|
1364
2252
|
|
|
1365
2253
|
register('conversation.session.header.utilities', 'conversation-float-control', HeaderAction, { order: 30 })
|
|
2254
|
+
// The same two destinations a drop offers, as rows in the sidebars' own
|
|
2255
|
+
// More menus — below the shipped rows, which register at the default 0.
|
|
2256
|
+
register('sidebar.panellist.actions', 'conversation-float-stow', MoveLeftRow, { order: 100 })
|
|
2257
|
+
register('sidebar.right.tab.guide.actions', 'conversation-float-move', MoveRightRow, { order: 100 })
|
|
1366
2258
|
|
|
1367
2259
|
ctx.effect(() => watchColumn())
|
|
1368
2260
|
|
|
1369
2261
|
ctx.effect(() => {
|
|
1370
2262
|
window.addEventListener('keydown', escapeOnKey, true)
|
|
1371
|
-
|
|
2263
|
+
document.addEventListener('click', drawerRowPress, true)
|
|
2264
|
+
return () => {
|
|
2265
|
+
window.removeEventListener('keydown', escapeOnKey, true)
|
|
2266
|
+
document.removeEventListener('click', drawerRowPress, true)
|
|
2267
|
+
}
|
|
1372
2268
|
})
|
|
1373
2269
|
|
|
2270
|
+
// A hand on a float outranks any seat this plugin remembered.
|
|
2271
|
+
ctx.effect(() => trackFloatGrab())
|
|
2272
|
+
|
|
1374
2273
|
// A press or a key is the only evidence that a column moved by the
|
|
1375
2274
|
// user's hand rather than by DSH re-railing it.
|
|
1376
2275
|
ctx.effect(() => {
|
|
@@ -1419,6 +2318,36 @@ window.__ModuleLoader__.load({
|
|
|
1419
2318
|
return dispose
|
|
1420
2319
|
})
|
|
1421
2320
|
|
|
2321
|
+
// The drawer row is named after the Conversation that was stowed and
|
|
2322
|
+
// returns to it: the Session list supplies the name, workspace
|
|
2323
|
+
// navigation re-opens the Conversation.
|
|
2324
|
+
ctx.effect(() => {
|
|
2325
|
+
const dispose = ctx.inject(['sessions', 'uiWorkspace'], (sub) => {
|
|
2326
|
+
sessions = sub.sessions ?? null
|
|
2327
|
+
uiWorkspace = sub.uiWorkspace ?? null
|
|
2328
|
+
let off = null
|
|
2329
|
+
try {
|
|
2330
|
+
if (typeof sessions?.list?.subscribe === 'function') {
|
|
2331
|
+
off = sessions.list.subscribe(() => {
|
|
2332
|
+
if (dockedLeft) syncDrawerRow()
|
|
2333
|
+
})
|
|
2334
|
+
}
|
|
2335
|
+
} catch (error) {
|
|
2336
|
+
console.warn('[conversation-float] could not follow the Session list:', error)
|
|
2337
|
+
}
|
|
2338
|
+
return () => {
|
|
2339
|
+
try {
|
|
2340
|
+
off?.()
|
|
2341
|
+
} catch {
|
|
2342
|
+
/* the projection is already gone */
|
|
2343
|
+
}
|
|
2344
|
+
sessions = null
|
|
2345
|
+
uiWorkspace = null
|
|
2346
|
+
}
|
|
2347
|
+
})
|
|
2348
|
+
return dispose
|
|
2349
|
+
})
|
|
2350
|
+
|
|
1422
2351
|
ctx.effect(() =>
|
|
1423
2352
|
ctx.inject(['sidebarRightTabs', 'sidebarRight'], (sub) => {
|
|
1424
2353
|
sidebarRight = sub.sidebarRight ?? null
|
|
@@ -1427,6 +2356,11 @@ window.__ModuleLoader__.load({
|
|
|
1427
2356
|
id: CHAT_ID,
|
|
1428
2357
|
kind: CHAT_KIND,
|
|
1429
2358
|
title: () => t('conversation'),
|
|
2359
|
+
// The body hosts the live Conversation column. DSH unmounts an
|
|
2360
|
+
// unretained body on every tab switch, and that unmount is what
|
|
2361
|
+
// handed the column back to the middle column. Retaining the
|
|
2362
|
+
// body keeps the column where the user docked it.
|
|
2363
|
+
keepMounted: true,
|
|
1430
2364
|
}),
|
|
1431
2365
|
)
|
|
1432
2366
|
sub.effect(() =>
|
|
@@ -1456,6 +2390,10 @@ window.__ModuleLoader__.load({
|
|
|
1456
2390
|
get dockedLeft() {
|
|
1457
2391
|
return dockedLeft
|
|
1458
2392
|
},
|
|
2393
|
+
/** What the sidebars restore is working from, for the test harness. */
|
|
2394
|
+
get chrome() {
|
|
2395
|
+
return { saved: savedChrome, touched: touchedChrome, chromeless, hiddenAt: holdOffUntil }
|
|
2396
|
+
},
|
|
1459
2397
|
}
|
|
1460
2398
|
ctx.effect(() => () => {
|
|
1461
2399
|
hidePreview()
|