dsh-conversation-float 0.1.4 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +80 -47
- package/client.js +2165 -965
- package/docs/README.de.md +79 -46
- package/docs/README.es.md +79 -46
- package/docs/README.fr.md +80 -47
- package/docs/README.ja.md +78 -45
- package/docs/README.pt.md +81 -48
- package/docs/README.ru.md +79 -46
- package/docs/README.zh.md +82 -49
- package/package.json +2 -2
package/client.js
CHANGED
|
@@ -10,12 +10,12 @@
|
|
|
10
10
|
* the panel (same document, same React root, so events and reconciliation keep
|
|
11
11
|
* working) and moved back to its seat when the panel closes.
|
|
12
12
|
*
|
|
13
|
-
* While the
|
|
13
|
+
* While the window is on screen it can be dragged onto three drop bands:
|
|
14
14
|
*
|
|
15
|
-
* left the
|
|
16
|
-
*
|
|
17
|
-
* exactly as it is while the
|
|
18
|
-
* center the
|
|
15
|
+
* left the window minimises — still mounted, hidden — and its taskbar row
|
|
16
|
+
* in the left sidebar brings it back; the centre column stays empty,
|
|
17
|
+
* exactly as it is while the window is on screen
|
|
18
|
+
* center the window closes and the Conversation returns to its column
|
|
19
19
|
* right the tab is handed to the right sidebar, where DSH docks it
|
|
20
20
|
*
|
|
21
21
|
* The bands are measured once per drag. Holding the press for {@link DWELL_MS}
|
|
@@ -29,6 +29,7 @@ window.__ModuleLoader__.load({
|
|
|
29
29
|
'use strict'
|
|
30
30
|
|
|
31
31
|
const React = require('react')
|
|
32
|
+
const ReactDOM = require('react-dom')
|
|
32
33
|
const h = React.createElement
|
|
33
34
|
|
|
34
35
|
const NS = 'dsh-conversation-float'
|
|
@@ -58,13 +59,16 @@ window.__ModuleLoader__.load({
|
|
|
58
59
|
"floatTitle": "会话浮窗",
|
|
59
60
|
"showDsh": "显示 DSH 界面",
|
|
60
61
|
"hideDsh": "隐藏 DSH 界面",
|
|
61
|
-
|
|
62
62
|
"moveLeft": "会话收至此处",
|
|
63
63
|
|
|
64
64
|
"moveRight": "会话移至此处",
|
|
65
65
|
"stow": "放进左栏",
|
|
66
66
|
"center": "回到中间",
|
|
67
67
|
"dock": "停到右栏",
|
|
68
|
+
"toMain": "将主对话",
|
|
69
|
+
"switchTo": "切换到当前会话",
|
|
70
|
+
"minimize": "收起浮窗",
|
|
71
|
+
"close": "关闭浮窗",
|
|
68
72
|
"description": "把会话视图做成 DSH 自带的浮窗:拖到左边收进左栏抽屉、拖到中间回到中栏、拖到右边停进右侧栏。"
|
|
69
73
|
},
|
|
70
74
|
"en": {
|
|
@@ -72,13 +76,16 @@ window.__ModuleLoader__.load({
|
|
|
72
76
|
"floatTitle": "Conversation float",
|
|
73
77
|
"showDsh": "Show DSH",
|
|
74
78
|
"hideDsh": "Hide DSH",
|
|
75
|
-
|
|
76
79
|
"moveLeft": "Stow the conversation here",
|
|
77
80
|
|
|
78
81
|
"moveRight": "Move the conversation here",
|
|
79
82
|
"stow": "Stow in the left sidebar",
|
|
80
83
|
"center": "Return to the middle",
|
|
81
84
|
"dock": "Dock in the right sidebar",
|
|
85
|
+
"toMain": "Main conversation: ",
|
|
86
|
+
"switchTo": "Switch to this conversation",
|
|
87
|
+
"minimize": "Minimize",
|
|
88
|
+
"close": "Close",
|
|
82
89
|
"description": "Turns the Conversation view into DSH own floating panel: drag it left to stow it in the sidebar drawer, centre to return it to the middle column, right to dock it in the right sidebar."
|
|
83
90
|
},
|
|
84
91
|
"de": {
|
|
@@ -86,13 +93,14 @@ window.__ModuleLoader__.load({
|
|
|
86
93
|
"floatTitle": "Konversations-Float",
|
|
87
94
|
"showDsh": "DSH anzeigen",
|
|
88
95
|
"hideDsh": "DSH ausblenden",
|
|
89
|
-
|
|
90
96
|
"moveLeft": "Konversation hierher legen",
|
|
91
97
|
|
|
92
98
|
"moveRight": "Konversation hierher verschieben",
|
|
93
99
|
"stow": "In der linken Seitenleiste ablegen",
|
|
94
100
|
"center": "Zurück in die Mitte",
|
|
95
101
|
"dock": "In der rechten Seitenleiste andocken",
|
|
102
|
+
"toMain": "Hauptkonversation: ",
|
|
103
|
+
"switchTo": "Zu dieser Konversation wechseln",
|
|
96
104
|
"description": "Macht die Konversationsansicht zu DSH eigenem schwebenden Panel: nach links ziehen legt sie in der linken Seitenleiste ab, Mitte bringt sie zurück, rechts dockt sie rechts an."
|
|
97
105
|
},
|
|
98
106
|
"es": {
|
|
@@ -100,13 +108,14 @@ window.__ModuleLoader__.load({
|
|
|
100
108
|
"floatTitle": "Ventana flotante de conversación",
|
|
101
109
|
"showDsh": "Mostrar DSH",
|
|
102
110
|
"hideDsh": "Ocultar DSH",
|
|
103
|
-
|
|
104
111
|
"moveLeft": "Guardar la conversación aquí",
|
|
105
112
|
|
|
106
113
|
"moveRight": "Mover la conversación aquí",
|
|
107
114
|
"stow": "Guardar en la barra izquierda",
|
|
108
115
|
"center": "Volver al centro",
|
|
109
116
|
"dock": "Acoplar en la barra derecha",
|
|
117
|
+
"toMain": "Conversación principal: ",
|
|
118
|
+
"switchTo": "Cambiar a esta conversación",
|
|
110
119
|
"description": "Convierte la vista de conversación en el panel flotante propio de DSH: a la izquierda se guarda en la barra lateral, al centro vuelve a la columna central, a la derecha se acopla a la barra derecha."
|
|
111
120
|
},
|
|
112
121
|
"fr": {
|
|
@@ -114,13 +123,14 @@ window.__ModuleLoader__.load({
|
|
|
114
123
|
"floatTitle": "Fenêtre flottante de conversation",
|
|
115
124
|
"showDsh": "Afficher DSH",
|
|
116
125
|
"hideDsh": "Masquer DSH",
|
|
117
|
-
|
|
118
126
|
"moveLeft": "Ranger la conversation ici",
|
|
119
127
|
|
|
120
128
|
"moveRight": "Déplacer la conversation ici",
|
|
121
129
|
"stow": "Placer dans la barre latérale gauche",
|
|
122
130
|
"center": "Revenir au centre",
|
|
123
131
|
"dock": "Ancrer dans la barre latérale droite",
|
|
132
|
+
"toMain": "Conversation principale : ",
|
|
133
|
+
"switchTo": "Passer à cette conversation",
|
|
124
134
|
"description": "Transforme la vue de conversation en panneau flottant propre à DSH : à gauche il se range dans la barre latérale, au centre il revient dans la colonne, à droite il s ancre à droite."
|
|
125
135
|
},
|
|
126
136
|
"ja": {
|
|
@@ -128,13 +138,14 @@ window.__ModuleLoader__.load({
|
|
|
128
138
|
"floatTitle": "会話フロート",
|
|
129
139
|
"showDsh": "DSH を表示",
|
|
130
140
|
"hideDsh": "DSH を隠す",
|
|
131
|
-
|
|
132
141
|
"moveLeft": "会話をここにしまう",
|
|
133
142
|
|
|
134
143
|
"moveRight": "会話をここへ移動",
|
|
135
144
|
"stow": "左サイドバーにしまう",
|
|
136
145
|
"center": "中央に戻す",
|
|
137
146
|
"dock": "右サイドバーにドッキング",
|
|
147
|
+
"toMain": "メインの会話を",
|
|
148
|
+
"switchTo": "この会話に切り替え",
|
|
138
149
|
"description": "会話ビューを DSH 自身のフロートパネルにします。左へドラッグで左サイドバーに収納、中央で中央列に戻り、右で右サイドバーにドッキングします。"
|
|
139
150
|
},
|
|
140
151
|
"pt": {
|
|
@@ -142,13 +153,14 @@ window.__ModuleLoader__.load({
|
|
|
142
153
|
"floatTitle": "Janela flutuante da conversa",
|
|
143
154
|
"showDsh": "Mostrar DSH",
|
|
144
155
|
"hideDsh": "Ocultar DSH",
|
|
145
|
-
|
|
146
156
|
"moveLeft": "Guardar a conversa aqui",
|
|
147
157
|
|
|
148
158
|
"moveRight": "Mover a conversa para aqui",
|
|
149
159
|
"stow": "Guardar na barra lateral esquerda",
|
|
150
160
|
"center": "Voltar ao centro",
|
|
151
161
|
"dock": "Ancorar na barra lateral direita",
|
|
162
|
+
"toMain": "Conversa principal: ",
|
|
163
|
+
"switchTo": "Mudar para esta conversa",
|
|
152
164
|
"description": "Transforma a vista de conversa no painel flutuante do próprio DSH: à esquerda guarda na barra lateral, no centro volta à coluna central, à direita ancora na barra direita."
|
|
153
165
|
},
|
|
154
166
|
"ru": {
|
|
@@ -156,13 +168,14 @@ window.__ModuleLoader__.load({
|
|
|
156
168
|
"floatTitle": "Плавающее окно беседы",
|
|
157
169
|
"showDsh": "Показать DSH",
|
|
158
170
|
"hideDsh": "Скрыть DSH",
|
|
159
|
-
|
|
160
171
|
"moveLeft": "Убрать беседу сюда",
|
|
161
172
|
|
|
162
173
|
"moveRight": "Переместить беседу сюда",
|
|
163
174
|
"stow": "Убрать в левую панель",
|
|
164
175
|
"center": "Вернуть в центр",
|
|
165
176
|
"dock": "Закрепить в правой панели",
|
|
177
|
+
"toMain": "Основная беседа: ",
|
|
178
|
+
"switchTo": "Перейти к этой беседе",
|
|
166
179
|
"description": "Превращает вид беседы в собственное плавающее окно DSH: влево — убрать в левую панель, в центр — вернуть в средний столбец, вправо — закрепить в правой панели."
|
|
167
180
|
}
|
|
168
181
|
}
|
|
@@ -181,93 +194,271 @@ window.__ModuleLoader__.load({
|
|
|
181
194
|
return table[key] ?? COPY.en[key] ?? key
|
|
182
195
|
}
|
|
183
196
|
const ANCHOR_ATTR = 'data-dsh-conversation-float-anchor'
|
|
197
|
+
/** Set on a taskbar row's button, with the Session its window shows. */
|
|
198
|
+
const ROW_MARK_ATTR = 'data-dsh-conversation-float-row'
|
|
184
199
|
const CHAT_ID = 'conversation-float-panel'
|
|
185
200
|
const CHAT_KIND = 'conversation-float-panel'
|
|
186
201
|
/** A resource address our own tab type claims; the panel is opened by it. */
|
|
187
202
|
const CHAT_ADDRESS = 'dsh-resource://conversation-float'
|
|
188
|
-
/**
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
203
|
+
/**
|
|
204
|
+
* How long a band must be held before it draws and before it can land.
|
|
205
|
+
*
|
|
206
|
+
* This is the only wall clock the plugin keeps, and it is a HAND constant,
|
|
207
|
+
* not a guess at a commit. On a touch screen every drag crosses a band —
|
|
208
|
+
* the window is most of the width — so "drag" has to mean "move the window"
|
|
209
|
+
* and "hold, then drag" means "move the Conversation". Shortening it makes
|
|
210
|
+
* the guard against a stray brush weaker, and no device measurement here
|
|
211
|
+
* shows the shorter hold surviving that; 1200ms stands until one does.
|
|
212
|
+
*/
|
|
193
213
|
const DWELL_MS = 1200
|
|
214
|
+
/** Marks the window whose hold has armed the bands. */
|
|
215
|
+
const ARMED_ATTR = 'data-dsh-conversation-float-armed'
|
|
216
|
+
|
|
194
217
|
/** The dock kit's own marker for a floating panel. */
|
|
195
218
|
const FLOAT_ATTR = 'data-dockkit-float'
|
|
196
219
|
/** Marks our own tab body, so the reconcile pass never reads another plugin's. */
|
|
197
220
|
const BODY_ATTR = 'data-dsh-conversation-float-body'
|
|
198
|
-
/** Set on the float panel while it is stowed in the left drawer. */
|
|
199
|
-
const STOW_ATTR = 'data-dsh-conversation-float-stowed'
|
|
200
221
|
/** Marks the float that hosts our tab, so our rules hit no other panel. */
|
|
201
222
|
const OWN_FLOAT_ATTR = 'data-dsh-conversation-float-float'
|
|
202
223
|
/** Set on every frame column that the float is temporarily hiding. */
|
|
203
224
|
const CHROME_ATTR = 'data-dsh-conversation-float-chromeless'
|
|
225
|
+
/** Set on the one frame column this plugin has moved somewhere. */
|
|
226
|
+
const COLUMN_ATTR = 'data-dsh-conversation-float-column'
|
|
227
|
+
/**
|
|
228
|
+
* Set on a body that renders a Session's own Conversation content instead of
|
|
229
|
+
* hosting the live column. Such a body shows the transcript only: the one
|
|
230
|
+
* composer belongs to the Session on screen.
|
|
231
|
+
*/
|
|
232
|
+
const FACTORY_ATTR = 'data-dsh-conversation-float-factory'
|
|
233
|
+
/** A live-Session factory view that keeps its header and composer. */
|
|
234
|
+
const FACTORY_LIVE_ATTR = 'data-dsh-conversation-float-factory-live'
|
|
204
235
|
|
|
205
236
|
let sidebarRight = null
|
|
206
237
|
let layout = null
|
|
207
238
|
let movedColumn = null
|
|
208
239
|
let movedFrom = null
|
|
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
|
-
*/
|
|
214
|
-
let dockedLeft = false
|
|
215
240
|
/** Whether the rest of DSH is currently hidden behind the float. */
|
|
216
241
|
let chromeless = false
|
|
217
242
|
|
|
243
|
+
|
|
218
244
|
/** Re-render subscribers: the entry button says one thing per state. */
|
|
219
245
|
const stateListeners = new Set()
|
|
220
246
|
|
|
221
247
|
function notifyState() {
|
|
222
248
|
for (const fn of stateListeners) fn()
|
|
223
249
|
}
|
|
250
|
+
/**
|
|
251
|
+
* The layout tick: every mounted float body re-decides which host it is for.
|
|
252
|
+
*
|
|
253
|
+
* This runs when something that could change the answer happens — the
|
|
254
|
+
* Session on screen changes, or the Session list does — instead of every
|
|
255
|
+
* body polling on its own clock. Independent timers were what let two floats
|
|
256
|
+
* race for the one column.
|
|
257
|
+
*/
|
|
258
|
+
const layoutListeners = new Set()
|
|
259
|
+
/** Set while a pass runs: the plugin's own DOM writes must not ask for one. */
|
|
260
|
+
let inLayout = false
|
|
261
|
+
/** Whether the main slot carried a page during the last pass. */
|
|
262
|
+
let lastPageOpen = false
|
|
263
|
+
/**
|
|
264
|
+
* What one layout pass has already worked out.
|
|
265
|
+
*
|
|
266
|
+
* While a page owns the main slot the Conversation column is gone, so every
|
|
267
|
+
* lookup of it degrades to a whole-document scan plus forced layout reads —
|
|
268
|
+
* and every mounted body asked three times in the same pass. One pass has
|
|
269
|
+
* one answer; anything that moves the column drops it.
|
|
270
|
+
*/
|
|
271
|
+
let passMemo = null
|
|
272
|
+
/** Whether this pass moved the Conversation between hosts. */
|
|
273
|
+
let columnMovedInPass = false
|
|
274
|
+
function beginPass() {
|
|
275
|
+
passMemo = { column: null, columnKnown: false, live: null, liveKnown: false, page: false, pageKnown: false }
|
|
276
|
+
columnMovedInPass = false
|
|
277
|
+
}
|
|
278
|
+
function endPass() {
|
|
279
|
+
passMemo = null
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Note that this pass moved the Conversation between hosts.
|
|
283
|
+
*
|
|
284
|
+
* A move keeps the node and the Session it shows, so the memo survives it:
|
|
285
|
+
* only forgetColumn() drops a column, and that is where the memo is cleared.
|
|
286
|
+
*/
|
|
287
|
+
function noteColumnMoved() {
|
|
288
|
+
columnMovedInPass = true
|
|
289
|
+
}
|
|
290
|
+
function notifyLayout() {
|
|
291
|
+
if (inLayout) return
|
|
292
|
+
// Retried on every pass rather than on a timer: until the workspace
|
|
293
|
+
// service is up there is nothing to subscribe to, and a pass is exactly
|
|
294
|
+
// what happens when anything else changes.
|
|
295
|
+
followSelection()
|
|
296
|
+
const pageOpen = mainPanelOpen()
|
|
297
|
+
const pageChanged = pageOpen !== lastPageOpen
|
|
298
|
+
lastPageOpen = pageOpen
|
|
299
|
+
// A page owns the main slot: the Conversation is not on screen, the column
|
|
300
|
+
// is home and every body already shows its own transcript. Nothing a pass
|
|
301
|
+
// could decide is different until the page closes — and that transition is
|
|
302
|
+
// what the flag above catches.
|
|
303
|
+
if (pageOpen && !pageChanged) return
|
|
304
|
+
inLayout = true
|
|
305
|
+
beginPass()
|
|
306
|
+
try {
|
|
307
|
+
// Repair the host first: every body below decides from "the Session on
|
|
308
|
+
// screen", and a column parked in a page the window has left answers
|
|
309
|
+
// that question with the old Conversation.
|
|
310
|
+
try {
|
|
311
|
+
reconcileLiveColumn()
|
|
312
|
+
} catch (error) {
|
|
313
|
+
report('[conversation-float] column reconcile failed:', error)
|
|
314
|
+
}
|
|
315
|
+
for (const listener of [...layoutListeners]) {
|
|
316
|
+
try {
|
|
317
|
+
listener()
|
|
318
|
+
} catch (error) {
|
|
319
|
+
report('[conversation-float] layout pass failed:', error)
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
// The pass may have moved the Conversation between hosts, and a copy that
|
|
323
|
+
// left in the same breath can take the composer's editor with it. A pass
|
|
324
|
+
// that moved nothing cannot have broken it, so the subtree query that
|
|
325
|
+
// looks for the composer stays out of the common case.
|
|
326
|
+
if (columnMovedInPass) {
|
|
327
|
+
try {
|
|
328
|
+
healComposer()
|
|
329
|
+
} catch (error) {
|
|
330
|
+
report('[conversation-float] composer heal failed:', error)
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
refreshSwitchChips()
|
|
334
|
+
} finally {
|
|
335
|
+
inLayout = false
|
|
336
|
+
endPass()
|
|
337
|
+
}
|
|
338
|
+
}
|
|
224
339
|
/** Set when the hide was requested before the float finished mounting. */
|
|
225
340
|
let pendingChromeless = false
|
|
226
341
|
/** The last sane band geometry, kept for when the columns are hidden. */
|
|
227
342
|
let lastBand = null
|
|
228
343
|
/** Sidebar state captured when the float opened; restored when it closes. */
|
|
229
344
|
let savedChrome = null
|
|
230
|
-
/** The pair the user last left the sidebars in while the float was up. */
|
|
231
|
-
let touchedChrome = null
|
|
232
|
-
/** How long after a press or a key a column change still counts as the user's. */
|
|
233
|
-
const GESTURE_WINDOW = 900
|
|
234
|
-
/** How long the float's own force-open needs to settle before sampling. */
|
|
235
|
-
const FORCE_SETTLE_MS = 1200
|
|
236
|
-
/** The last time the user pressed a key or a mouse button, in ms. */
|
|
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
|
|
246
|
-
/** While the plugin moves the columns itself, changes are not the user's. */
|
|
247
|
-
let holdOffUntil = 0
|
|
248
|
-
/** Set while docking to the right sidebar: the column is not going home. */
|
|
249
|
-
let dockingRight = false
|
|
250
|
-
/** Set when the drawer action is waiting for the float that carries the column. */
|
|
251
|
-
let pendingStow = false
|
|
252
345
|
/**
|
|
253
|
-
*
|
|
254
|
-
*
|
|
255
|
-
*
|
|
346
|
+
* A retry of the sidebar arrangement, cancelable by the user's own hand.
|
|
347
|
+
*
|
|
348
|
+
* This replaced a time window that claimed to suppress "changes the plugin
|
|
349
|
+
* caused": nothing ever read that window, so the promise in the comment was
|
|
350
|
+
* never kept. A hand on the sidebars now ends the retry directly.
|
|
256
351
|
*/
|
|
257
|
-
let
|
|
258
|
-
/**
|
|
259
|
-
let
|
|
352
|
+
let chromeApplyStop = null
|
|
353
|
+
/** Set while docking to the right sidebar: the column is not going home. */
|
|
354
|
+
let dockingRight = false
|
|
355
|
+
/** Set when a minimise is waiting for the float that carries the column. */
|
|
356
|
+
let pendingMinimise = false
|
|
260
357
|
/** The Session list projection, when the Client exposes it. */
|
|
261
358
|
let sessions = null
|
|
262
|
-
/** Session navigation, used by the drawer row. */
|
|
263
|
-
let uiWorkspace = null
|
|
264
359
|
/** Set while the float is being reopened from the drawer. */
|
|
265
360
|
let suspendRestore = false
|
|
266
|
-
/** Disposer of the `sidebar.panellist` row, while it is registered. */
|
|
267
|
-
let dockRow = null
|
|
268
361
|
/** The drop preview overlay, created on demand. */
|
|
269
362
|
let preview = null
|
|
270
363
|
|
|
364
|
+
/* ------------------------------------------------------------- timing */
|
|
365
|
+
|
|
366
|
+
/*
|
|
367
|
+
* Two kinds of waiting live here, and they are not the same thing.
|
|
368
|
+
*
|
|
369
|
+
* A duration that measures a HAND — the hold that arms the drop bands
|
|
370
|
+
* ({@link DWELL_MS}) — cannot be replaced by anything: the decision is the
|
|
371
|
+
* user's, and only the clock knows when it was made.
|
|
372
|
+
*
|
|
373
|
+
* A duration that guesses when another system commits is the fragile kind:
|
|
374
|
+
* it expires early on a busy frame and late on an idle one. Those waits are
|
|
375
|
+
* written as the condition they want and re-read once per frame
|
|
376
|
+
* ({@link untilFrame}), so they end the frame the commit arrives.
|
|
377
|
+
*
|
|
378
|
+
* There are no settle durations left either. A step that has to follow a
|
|
379
|
+
* close defers with queueMicrotask, which is "after this commit" without a
|
|
380
|
+
* duration: later than the unmount, earlier than any input. The touch hold
|
|
381
|
+
* below is the only wall clock in the plugin.
|
|
382
|
+
*/
|
|
383
|
+
|
|
384
|
+
/** Frame-driven waits owned by the plugin instance; they die with it. */
|
|
385
|
+
const pendingWaits = new Set()
|
|
386
|
+
|
|
387
|
+
function cancelWaits() {
|
|
388
|
+
for (const stop of [...pendingWaits]) stop()
|
|
389
|
+
pendingWaits.clear()
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* Re-read `check` every frame until it returns true, then call `then`.
|
|
394
|
+
*
|
|
395
|
+
* `deadlineMs` is a backstop for a condition that can never come true (the
|
|
396
|
+
* Session was closed mid-flight), never the way a normal wait ends.
|
|
397
|
+
*
|
|
398
|
+
* @param check read once per frame; true ends the wait
|
|
399
|
+
* @param then run on the frame the condition holds
|
|
400
|
+
* @param deadlineMs when to give up, and `onExpire` what to do instead
|
|
401
|
+
*/
|
|
402
|
+
function untilFrame(check, then, deadlineMs = 2000, onExpire = null) {
|
|
403
|
+
const started = performance.now()
|
|
404
|
+
let raf = 0
|
|
405
|
+
let done = false
|
|
406
|
+
const stop = () => {
|
|
407
|
+
if (done) return
|
|
408
|
+
done = true
|
|
409
|
+
pendingWaits.delete(stop)
|
|
410
|
+
if (raf !== 0) window.cancelAnimationFrame(raf)
|
|
411
|
+
}
|
|
412
|
+
const step = () => {
|
|
413
|
+
raf = 0
|
|
414
|
+
if (done) return
|
|
415
|
+
let ok = false
|
|
416
|
+
try { ok = check() === true } catch { ok = false }
|
|
417
|
+
if (ok) {
|
|
418
|
+
stop()
|
|
419
|
+
try { then?.() } catch (error) { report('[conversation-float] a deferred step failed:', error) }
|
|
420
|
+
return
|
|
421
|
+
}
|
|
422
|
+
if (performance.now() - started > deadlineMs) {
|
|
423
|
+
stop()
|
|
424
|
+
try { onExpire?.() } catch (error) { report('[conversation-float] a deferred fallback failed:', error) }
|
|
425
|
+
return
|
|
426
|
+
}
|
|
427
|
+
raf = window.requestAnimationFrame(step)
|
|
428
|
+
}
|
|
429
|
+
pendingWaits.add(stop)
|
|
430
|
+
raf = window.requestAnimationFrame(step)
|
|
431
|
+
return stop
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* The plugin's single diagnostic sink.
|
|
436
|
+
*
|
|
437
|
+
* Every failure in this file used to end at console.warn, which is fine to
|
|
438
|
+
* write and impossible to read back: a band that silently did nothing left
|
|
439
|
+
* no trace a user could hand over. Keeping the last one lets diag() report
|
|
440
|
+
* what actually went wrong.
|
|
441
|
+
*/
|
|
442
|
+
/** Whether a page asked for the mutating probe surface. */
|
|
443
|
+
function floatDebugEnabled() {
|
|
444
|
+
try {
|
|
445
|
+
if (window.__dshFloatDebug === true) return true
|
|
446
|
+
return /[?&]dshFloatDebug=1\b/.test(window.location.search)
|
|
447
|
+
} catch {
|
|
448
|
+
return false
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
function report(...args) {
|
|
453
|
+
try {
|
|
454
|
+
window.__dshFloatLastError = {
|
|
455
|
+
at: Date.now(),
|
|
456
|
+
text: args.map((value) => (value && value.stack) || String(value)).join(' '),
|
|
457
|
+
}
|
|
458
|
+
} catch { /* no window yet */ }
|
|
459
|
+
console.warn(...args)
|
|
460
|
+
}
|
|
461
|
+
|
|
271
462
|
/* ------------------------------------------------------- the live column */
|
|
272
463
|
|
|
273
464
|
/**
|
|
@@ -278,24 +469,50 @@ window.__ModuleLoader__.load({
|
|
|
278
469
|
* column keeps every list inside the moved subtree intact.
|
|
279
470
|
*/
|
|
280
471
|
function findColumn() {
|
|
281
|
-
if (
|
|
472
|
+
if (passMemo !== null && passMemo.columnKnown) return passMemo.column
|
|
473
|
+
const column = movedColumn !== null && movedColumn.isConnected ? movedColumn : scanColumn()
|
|
474
|
+
if (passMemo !== null) {
|
|
475
|
+
passMemo.column = column
|
|
476
|
+
passMemo.columnKnown = true
|
|
477
|
+
}
|
|
478
|
+
return column
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
/**
|
|
482
|
+
* The frame's own Conversation column, read without trusting the record of
|
|
483
|
+
* which node this plugin moved.
|
|
484
|
+
*
|
|
485
|
+
* A Session switch can take the column we were holding out of the document
|
|
486
|
+
* (DSH unmounts the Session and draws the next one), and the record then
|
|
487
|
+
* names a node nobody can see. Every repair below has to be able to ask
|
|
488
|
+
* "what does the frame say right now", and this is how it asks.
|
|
489
|
+
*/
|
|
490
|
+
function scanColumn() {
|
|
491
|
+
// The window renders a Conversation of its own. That one is never the
|
|
492
|
+
// middle column this helper is looking for, so it is skipped by name.
|
|
493
|
+
const insideOurs = (el) => el !== null && el.closest(`[${WINDOW_ATTR}]`) !== null
|
|
282
494
|
const candidates = [
|
|
283
|
-
document.
|
|
495
|
+
[...document.querySelectorAll('[data-conversation-session]')].find((el) => !insideOurs(el)) ?? null,
|
|
284
496
|
document.querySelector(`[${ANCHOR_ATTR}]`),
|
|
285
497
|
document.querySelector('[data-conversation-header-corner]'),
|
|
286
498
|
document.querySelector('[data-conversation-tabs]'),
|
|
287
499
|
]
|
|
288
500
|
for (const anchor of candidates) {
|
|
289
|
-
if (anchor === null) continue
|
|
501
|
+
if (anchor === null || insideOurs(anchor)) continue
|
|
290
502
|
// While the Conversation is hosted by one of our bodies, the column is
|
|
291
503
|
// that body's own child — walking up instead would climb out of the
|
|
292
504
|
// right sidebar and name the whole right column as "the column", and
|
|
293
505
|
// moving that into the float feeds it its own ancestor.
|
|
294
506
|
const body = anchor.closest(`[${BODY_ATTR}]`)
|
|
295
507
|
if (body !== null) {
|
|
508
|
+
// Only a column WE moved into this body counts. A body rendering a
|
|
509
|
+
// Conversation of its own (a docked page) has the anchor as a view;
|
|
510
|
+
// reading that view as the frame's column made the panel believe it
|
|
511
|
+
// was hosting the live column while it was rendering a copy.
|
|
296
512
|
for (const child of Array.from(body.children)) {
|
|
297
|
-
if (child.contains(anchor)) return child
|
|
513
|
+
if (child.hasAttribute(COLUMN_ATTR) && child.contains(anchor)) return child
|
|
298
514
|
}
|
|
515
|
+
return null
|
|
299
516
|
}
|
|
300
517
|
let node = anchor
|
|
301
518
|
while (node.parentElement !== null) {
|
|
@@ -366,9 +583,6 @@ window.__ModuleLoader__.load({
|
|
|
366
583
|
* The pane id is the float element's own `data-dockkit-float` value.
|
|
367
584
|
*/
|
|
368
585
|
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
|
|
372
586
|
const panel = floatPanel()
|
|
373
587
|
if (panel === null) return
|
|
374
588
|
const paneId = panel.getAttribute(FLOAT_ATTR) ?? document.querySelector(`[${FLOAT_ATTR}]`)?.getAttribute(FLOAT_ATTR)
|
|
@@ -397,45 +611,7 @@ window.__ModuleLoader__.load({
|
|
|
397
611
|
try {
|
|
398
612
|
seat.actions.resizeFloat(seat.sessionId, paneId, rect)
|
|
399
613
|
} catch (error) {
|
|
400
|
-
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
/** The session's dock-kit action face, or null when it is not reachable. */
|
|
404
|
-
function sessionSeat() {
|
|
405
|
-
try {
|
|
406
|
-
const direct = sidebarRight?.require?.()
|
|
407
|
-
if (direct !== undefined && direct !== null) return direct
|
|
408
|
-
} catch {
|
|
409
|
-
/* fall through to the per-session face */
|
|
410
|
-
}
|
|
411
|
-
try {
|
|
412
|
-
const sessionId = sidebarRight?.mounted?.getSnapshot?.()
|
|
413
|
-
const actions = sessionId === undefined ? undefined : sidebarRight?.actionsFor?.(sessionId)
|
|
414
|
-
if (actions !== undefined && actions !== null) return { sessionId, actions }
|
|
415
|
-
} catch {
|
|
416
|
-
return null
|
|
417
|
-
}
|
|
418
|
-
return null
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
/** Float our tab for real, with the size we want. */
|
|
422
|
-
function floatExistingTab() {
|
|
423
|
-
if (floatPanel() !== null) {
|
|
424
|
-
sizeFloat()
|
|
425
|
-
return true
|
|
426
|
-
}
|
|
427
|
-
const tabId = floatTabId()
|
|
428
|
-
if (tabId === null) return false
|
|
429
|
-
const seat = sessionSeat()
|
|
430
|
-
if (seat === null || typeof seat.actions?.floatTab !== 'function') return false
|
|
431
|
-
const size = floatSize()
|
|
432
|
-
const corner = floatSeat(size)
|
|
433
|
-
try {
|
|
434
|
-
seat.actions.floatTab(seat.sessionId, tabId, { ...corner, width: size.width, height: size.height })
|
|
435
|
-
return true
|
|
436
|
-
} catch (error) {
|
|
437
|
-
console.warn('[conversation-float] could not float the docked tab:', error)
|
|
438
|
-
return false
|
|
614
|
+
report('[conversation-float] could not size the floating panel:', error)
|
|
439
615
|
}
|
|
440
616
|
}
|
|
441
617
|
function attachColumn(container, keepHome = false) {
|
|
@@ -446,14 +622,29 @@ window.__ModuleLoader__.load({
|
|
|
446
622
|
if (column.contains(container)) return null
|
|
447
623
|
// A retained body that takes the column over from another body keeps the
|
|
448
624
|
// seat recorded first: the middle column, never the tab it came from.
|
|
449
|
-
if (!keepHome || movedFrom === null)
|
|
625
|
+
if (!keepHome || movedFrom === null) {
|
|
626
|
+
const parent = column.parentNode
|
|
627
|
+
// Any host counts, not just a window: a docked page is retained the same
|
|
628
|
+
// way and can be closed at any moment. The seat worth remembering is the
|
|
629
|
+
// frame's, never the host it is leaving.
|
|
630
|
+
const fromHost = parent !== null && typeof parent.closest === 'function'
|
|
631
|
+
&& (parent.closest(`[${WINDOW_ATTR}]`) !== null || parent.closest(`[${BODY_ATTR}]`) !== null)
|
|
632
|
+
if (fromHost) {
|
|
633
|
+
const seat = homeSeat(null)
|
|
634
|
+
movedFrom = seat === null ? null : { parent: seat.parent, next: seat.before }
|
|
635
|
+
} else {
|
|
636
|
+
movedFrom = { parent, next: column.nextSibling }
|
|
637
|
+
}
|
|
638
|
+
}
|
|
450
639
|
movedColumn = column
|
|
640
|
+
column.setAttribute(COLUMN_ATTR, '')
|
|
451
641
|
column.style.width = "100%"
|
|
452
642
|
column.style.height = "100%"
|
|
453
643
|
column.style.minWidth = "0"
|
|
454
644
|
column.style.minHeight = "0"
|
|
455
645
|
column.style.overflow = "hidden"
|
|
456
646
|
container.appendChild(column)
|
|
647
|
+
noteColumnMoved()
|
|
457
648
|
const ownPanel = floatPanel()
|
|
458
649
|
if (ownPanel !== null) ownPanel.setAttribute(OWN_FLOAT_ATTR, '')
|
|
459
650
|
// The dock kit gives a new float its own seat; ask it — through the same
|
|
@@ -464,10 +655,10 @@ window.__ModuleLoader__.load({
|
|
|
464
655
|
// has arrived: the restore guard must not outlive it.
|
|
465
656
|
dockingRight = false
|
|
466
657
|
|
|
467
|
-
// The
|
|
468
|
-
// body is mounted in a layout effect — before paint — so
|
|
469
|
-
// the
|
|
470
|
-
if (
|
|
658
|
+
// The left-hand action asked for the conversation while no float existed.
|
|
659
|
+
// The body is mounted in a layout effect — before paint — so minimising
|
|
660
|
+
// here means the window is never painted on its way out.
|
|
661
|
+
if (pendingMinimise && flushPendingMinimise()) return column
|
|
471
662
|
|
|
472
663
|
// The float body is mounted now, so a hide that was waiting for it can be
|
|
473
664
|
// applied against a real float element.
|
|
@@ -518,25 +709,258 @@ window.__ModuleLoader__.load({
|
|
|
518
709
|
* suppresses the whole float while a page is open — would be invisible.
|
|
519
710
|
*/
|
|
520
711
|
function mainPanelOpen() {
|
|
712
|
+
if (passMemo !== null && passMemo.pageKnown) return passMemo.page
|
|
521
713
|
const slot = document.querySelector('[data-slot="main"]')
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
714
|
+
let open = false
|
|
715
|
+
if (slot !== null) {
|
|
716
|
+
for (const child of slot.children) {
|
|
717
|
+
if (child.getAttribute('data-slot') === 'main.conversation') continue
|
|
718
|
+
open = true
|
|
719
|
+
break
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
if (passMemo !== null) {
|
|
723
|
+
passMemo.page = open
|
|
724
|
+
passMemo.pageKnown = true
|
|
725
|
+
}
|
|
726
|
+
return open
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
/* --------------------------------------------------------- internals */
|
|
730
|
+
/*
|
|
731
|
+
* DSH internals adapter: the only places this plugin reads something DSH
|
|
732
|
+
* does not publish. Keeping them named in one block means an upgrade has
|
|
733
|
+
* one place to look instead of five:
|
|
734
|
+
*
|
|
735
|
+
* 1. the Lexical editor, reached through the React fiber of its box
|
|
736
|
+
* (composerEditor)
|
|
737
|
+
* 2. editor.setRootElement, the only way to give that editor its box back
|
|
738
|
+
* (healComposer)
|
|
739
|
+
* 3. conversation.input.shell(id).persistDraft, the Session's single draft
|
|
740
|
+
* slot (guardDraftWriter)
|
|
741
|
+
*
|
|
742
|
+
* compatReport() probes all three; diag() reports it. A build that lost one
|
|
743
|
+
* of them should say so on the first diagnostic rather than on the first
|
|
744
|
+
* keystroke that goes nowhere.
|
|
745
|
+
*/
|
|
746
|
+
|
|
747
|
+
/* ------------------------------------------------------ the live composer */
|
|
748
|
+
|
|
749
|
+
/**
|
|
750
|
+
* The Lexical editor behind a composer box, read off the box itself.
|
|
751
|
+
*
|
|
752
|
+
* The composer does not own its editable surface: `ComposerContentEditable`
|
|
753
|
+
* hands the same editor a DOM node (`editor.setRootElement(el)`) on mount
|
|
754
|
+
* and `null` on unmount, and one editor can only ever have one root. The
|
|
755
|
+
* box therefore reports the editor that renders into it, which is the only
|
|
756
|
+
* handle this plugin needs.
|
|
757
|
+
*/
|
|
758
|
+
function composerEditor(box) {
|
|
759
|
+
const key = Object.keys(box).find((name) => name.startsWith('__reactFiber$'))
|
|
760
|
+
if (key === undefined) return null
|
|
761
|
+
let fiber = box[key]
|
|
762
|
+
for (let depth = 0; fiber && depth < 24; depth += 1, fiber = fiber.return) {
|
|
763
|
+
const props = fiber.memoizedProps
|
|
764
|
+
if (props && props.editor && typeof props.editor.setRootElement === 'function') return props.editor
|
|
765
|
+
}
|
|
766
|
+
return null
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
/**
|
|
770
|
+
* Give the composer on screen its editor back.
|
|
771
|
+
*
|
|
772
|
+
* A Session's input is one shell with one editor. Our window renders a
|
|
773
|
+
* transcript of a Session that is not the live one, and that copy mounts a
|
|
774
|
+
* composer of its own on the SAME editor; when the copy goes away it calls
|
|
775
|
+
* `setRootElement(null)`, and the composer the user is now looking at is a
|
|
776
|
+
* dead box: it keeps whatever text was left in it, typing never reaches the
|
|
777
|
+
* shell, and the draft the send button reads is the one the shell had before
|
|
778
|
+
* the switch. Nothing in DSH re-attaches it, because the surviving composer
|
|
779
|
+
* never remounted — its DOM was moved, not rendered. Re-attaching the editor
|
|
780
|
+
* is what heals it, and the shell's own document (the persisted draft) comes
|
|
781
|
+
* back with it.
|
|
782
|
+
*
|
|
783
|
+
* @returns whether the editor had to be re-attached
|
|
784
|
+
*/
|
|
785
|
+
function healComposer() {
|
|
786
|
+
// The composer that needs healing belongs to the Conversation ON SCREEN,
|
|
787
|
+
// and that is not always the column this plugin moved: while the live
|
|
788
|
+
// Session sits in the middle column, a window's copy can take the editor
|
|
789
|
+
// and the plugin holds nothing at all. Reading only `movedColumn` healed
|
|
790
|
+
// the case that cannot happen and skipped the one that does.
|
|
791
|
+
const column = (movedColumn !== null && movedColumn.isConnected) ? movedColumn : findColumn()
|
|
792
|
+
if (column === null || !column.isConnected) return false
|
|
793
|
+
const sessionId = columnSession(column) ?? selectedSession()
|
|
794
|
+
if (sessionId === null) return false
|
|
795
|
+
let changed = false
|
|
796
|
+
const seat = column.querySelector('[data-composer-seat]')
|
|
797
|
+
const box = seat === null
|
|
798
|
+
? null
|
|
799
|
+
: [...seat.querySelectorAll('[contenteditable]')].find((el) => el.getAttribute('contenteditable') !== 'false') ?? null
|
|
800
|
+
if (box !== null) {
|
|
801
|
+
const editor = composerEditor(box)
|
|
802
|
+
if (editor !== null) {
|
|
803
|
+
let root = box
|
|
804
|
+
try {
|
|
805
|
+
root = editor.getRootElement()
|
|
806
|
+
} catch {
|
|
807
|
+
root = box
|
|
808
|
+
}
|
|
809
|
+
if (root !== box) {
|
|
810
|
+
try {
|
|
811
|
+
editor.setRootElement(box)
|
|
812
|
+
changed = true
|
|
813
|
+
} catch (error) {
|
|
814
|
+
report('[conversation-float] could not re-attach the composer:', error)
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
try {
|
|
820
|
+
if (guardDraftWriter(sessionId)) changed = true
|
|
821
|
+
} catch (error) {
|
|
822
|
+
report('[conversation-float] could not restore the draft writer:', error)
|
|
823
|
+
}
|
|
824
|
+
return changed
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
/** sessionId -> { shell, write }: the draft writer bound while this Session was live. */
|
|
828
|
+
const liveDraftWriters = new Map()
|
|
829
|
+
|
|
830
|
+
/** Which of the three published-nowhere hooks are present right now. */
|
|
831
|
+
function compatReport() {
|
|
832
|
+
const column = findColumn()
|
|
833
|
+
const seat = (column ?? document).querySelector('[data-composer-seat]')
|
|
834
|
+
const box = seat === null
|
|
835
|
+
? null
|
|
836
|
+
: [...seat.querySelectorAll('[contenteditable]')].find((el) => el.getAttribute('contenteditable') !== 'false') ?? null
|
|
837
|
+
const editor = box === null ? null : composerEditor(box)
|
|
838
|
+
let shellOk = false
|
|
839
|
+
try {
|
|
840
|
+
const conversation = typeof ctxRef?.get === 'function' ? ctxRef.get('conversation') : null
|
|
841
|
+
const id = columnSession(column ?? document.body) ?? selectedSession()
|
|
842
|
+
const shell = id === null || conversation === null || conversation === undefined ? null : conversation.input?.shell?.(id)
|
|
843
|
+
shellOk = shell !== null && shell !== undefined && typeof shell.bindDraftPersistence === 'function'
|
|
844
|
+
} catch {
|
|
845
|
+
shellOk = false
|
|
846
|
+
}
|
|
847
|
+
return {
|
|
848
|
+
fiberEditor: editor !== null,
|
|
849
|
+
setRootElement: editor !== null && typeof editor.setRootElement === 'function',
|
|
850
|
+
draftShell: shellOk,
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
/** The Session's input shell — the one object holding its editor and draft slot. */
|
|
855
|
+
function draftShellOf(sessionId) {
|
|
856
|
+
try {
|
|
857
|
+
const conversation = typeof ctxRef?.get === 'function' ? ctxRef.get('conversation') : null
|
|
858
|
+
const shell = conversation === null || conversation === undefined
|
|
859
|
+
? null
|
|
860
|
+
: conversation.input?.shell?.(sessionId)
|
|
861
|
+
return shell !== null && shell !== undefined && typeof shell.bindDraftPersistence === 'function' ? shell : null
|
|
862
|
+
} catch (error) {
|
|
863
|
+
return null
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
/**
|
|
868
|
+
* Put the Session's draft writer back after a copy cleared it.
|
|
869
|
+
*
|
|
870
|
+
* The writer is a single field on the input shell (`persistDraft`), and a
|
|
871
|
+
* cleared field is how the draft stops reaching storage while the composer
|
|
872
|
+
* still looks alive. The writer DSH bound while this Session was the one on
|
|
873
|
+
* screen is the right one: it writes the draft into the Conversation store
|
|
874
|
+
* the reload path and the send button read. It is only ever put back into an
|
|
875
|
+
* EMPTY slot — a writer DSH has bound since is never replaced, so a
|
|
876
|
+
* remounted composer keeps its own.
|
|
877
|
+
*
|
|
878
|
+
* @returns whether the slot had to be filled
|
|
879
|
+
*/
|
|
880
|
+
function guardDraftWriter(sessionId) {
|
|
881
|
+
const shell = draftShellOf(sessionId)
|
|
882
|
+
if (shell === null) return false
|
|
883
|
+
const current = shell.persistDraft
|
|
884
|
+
const known = liveDraftWriters.get(sessionId)
|
|
885
|
+
if (current !== undefined && current !== null) {
|
|
886
|
+
if (known === undefined || known.shell !== shell) {
|
|
887
|
+
liveDraftWriters.set(sessionId, { shell, write: current })
|
|
888
|
+
capSessionMap(liveDraftWriters)
|
|
889
|
+
}
|
|
890
|
+
return false
|
|
526
891
|
}
|
|
527
|
-
return false
|
|
892
|
+
if (known === undefined || known.shell !== shell) return false
|
|
893
|
+
try {
|
|
894
|
+
shell.persistDraft = known.write
|
|
895
|
+
} catch (error) {
|
|
896
|
+
return false
|
|
897
|
+
}
|
|
898
|
+
return true
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
/**
|
|
902
|
+
* Re-attach the composer now, and again once the layout has settled.
|
|
903
|
+
*
|
|
904
|
+
* The copy that steals the editor goes away a commit after the pass that
|
|
905
|
+
* notices the Session is live again, so one attempt can land before the
|
|
906
|
+
* thief has finished leaving.
|
|
907
|
+
*/
|
|
908
|
+
function healComposerSoon() {
|
|
909
|
+
const heal = () => {
|
|
910
|
+
try { healComposer() } catch (error) { report('[conversation-float] composer heal failed:', error) }
|
|
911
|
+
}
|
|
912
|
+
heal()
|
|
913
|
+
// The copy that steals the editor goes away a commit after the pass that
|
|
914
|
+
// notices the Session is live again, so one attempt can land before the
|
|
915
|
+
// thief has finished leaving. Waiting on the editor ends the wait on the
|
|
916
|
+
// frame it is back; the three fixed delays it used to have expired before
|
|
917
|
+
// or after that commit depending on how busy the frame was.
|
|
918
|
+
const box = liveComposerBox()
|
|
919
|
+
if (box === null) return
|
|
920
|
+
untilFrame(() => {
|
|
921
|
+
heal()
|
|
922
|
+
return editorAttachedTo(box)
|
|
923
|
+
}, null, 1200)
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
/** The contenteditable of the Conversation on screen, wherever it lives. */
|
|
927
|
+
function liveComposerBox() {
|
|
928
|
+
const column = (movedColumn !== null && movedColumn.isConnected) ? movedColumn : findColumn()
|
|
929
|
+
const root = column ?? document
|
|
930
|
+
const seat = root.querySelector('[data-composer-seat]')
|
|
931
|
+
if (seat === null) return null
|
|
932
|
+
return [...seat.querySelectorAll('[contenteditable]')]
|
|
933
|
+
.find((el) => el.getAttribute('contenteditable') !== 'false') ?? null
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
/** Whether the editor that renders into `box` is attached to it right now. */
|
|
937
|
+
function editorAttachedTo(box) {
|
|
938
|
+
if (box === null) return false
|
|
939
|
+
const editor = composerEditor(box)
|
|
940
|
+
if (editor === null) return false
|
|
941
|
+
try { return editor.getRootElement() === box } catch { return false }
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
/** Where the column went on its way home (probe only, read by the tests). */
|
|
945
|
+
function markDetach(where) {
|
|
946
|
+
try {
|
|
947
|
+
const box = window.__dshFloatDetach ?? (window.__dshFloatDetach = { seat: 0, center: 0, fallback: 0, nowhere: 0, disconnected: 0, calls: 0 })
|
|
948
|
+
box.calls += 1
|
|
949
|
+
box[where] = (box[where] ?? 0) + 1
|
|
950
|
+
} catch { /* no window yet */ }
|
|
528
951
|
}
|
|
529
952
|
|
|
530
953
|
function detachColumn(keepChrome = false) {
|
|
531
954
|
const column = movedColumn
|
|
532
955
|
const home = movedFrom
|
|
956
|
+
if (column !== null) column.removeAttribute(COLUMN_ATTR)
|
|
533
957
|
movedColumn = null
|
|
534
958
|
movedFrom = null
|
|
535
959
|
notifyState()
|
|
536
960
|
// Closing is the plugin's doing, even when a click on the panel's own
|
|
537
|
-
// close button started it
|
|
538
|
-
//
|
|
539
|
-
|
|
961
|
+
// close button started it. Nothing has to be suppressed for that: the
|
|
962
|
+
// restore below compares against a snapshot taken before the float
|
|
963
|
+
// opened, so a re-rail cannot be mistaken for the user's arrangement.
|
|
540
964
|
for (const el of document.querySelectorAll(`[${OWN_FLOAT_ATTR}]`)) el.removeAttribute(OWN_FLOAT_ATTR)
|
|
541
965
|
// The float is leaving the screen: the rest of DSH has to come back.
|
|
542
966
|
if (chromeless) setChromeless(false)
|
|
@@ -548,6 +972,7 @@ window.__ModuleLoader__.load({
|
|
|
548
972
|
if (!keepChrome && !dockingRight && !suspendRestore) scheduleRestoreChrome()
|
|
549
973
|
dockingRight = false
|
|
550
974
|
if (column === null) return
|
|
975
|
+
noteColumnMoved()
|
|
551
976
|
column.style.width = ''
|
|
552
977
|
column.style.height = ''
|
|
553
978
|
column.style.minWidth = ''
|
|
@@ -556,230 +981,51 @@ window.__ModuleLoader__.load({
|
|
|
556
981
|
// DSH took the Conversation down while it was ours (a main panel opened,
|
|
557
982
|
// the Session changed): a node React has removed must not be put back, or
|
|
558
983
|
// a stale copy of the conversation would sit in the middle column.
|
|
559
|
-
if (!column.isConnected)
|
|
984
|
+
if (!column.isConnected) {
|
|
985
|
+
markDetach('disconnected')
|
|
986
|
+
// ...unless nothing else shows this Conversation any more: then the node
|
|
987
|
+
// left the document with the window that hosted it, and putting it back
|
|
988
|
+
// in the frame beats a blank screen that never comes back.
|
|
989
|
+
//
|
|
990
|
+
// The test used to be a plain `[data-conversation-session]` query, which
|
|
991
|
+
// every float's own transcript copy answers as well — so with one other
|
|
992
|
+
// window open the rescue never fired and the screen stayed blank for
|
|
993
|
+
// good. Only a column the frame could actually use may count as a
|
|
994
|
+
// survivor.
|
|
995
|
+
if (scanColumn() === null) {
|
|
996
|
+
const seat = homeSeat(home)
|
|
997
|
+
if (seat !== null) {
|
|
998
|
+
markDetach('rescued')
|
|
999
|
+
seat.parent.insertBefore(column, seat.before)
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
return
|
|
1003
|
+
}
|
|
560
1004
|
const seat = homeSeat(home)
|
|
561
1005
|
if (seat !== null) {
|
|
1006
|
+
markDetach('seat')
|
|
562
1007
|
seat.parent.insertBefore(column, seat.before)
|
|
563
1008
|
return
|
|
564
1009
|
}
|
|
565
1010
|
// The recorded seat is gone (the panel took it down with it): put the
|
|
566
1011
|
// column back in the middle column so the session is never lost.
|
|
567
1012
|
const center = currentCenter()
|
|
568
|
-
if (center !== null)
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
/**
|
|
572
|
-
* A closed floating panel can take our body down without running its
|
|
573
|
-
* cleanup first, so the column is watched directly: as soon as its container
|
|
574
|
-
* leaves the document it goes home.
|
|
575
|
-
*/
|
|
576
|
-
function watchColumn() {
|
|
577
|
-
/** The float element the last repair ran against. */
|
|
578
|
-
let seenFloat = null
|
|
579
|
-
/** The float whose fixed size was last applied. */
|
|
580
|
-
let sizedFloat = null
|
|
581
|
-
/** Attempts made to settle that float size. */
|
|
582
|
-
let sizeTries = 0
|
|
583
|
-
let seenParent = null
|
|
584
|
-
let seenHost = null
|
|
585
|
-
/** Whether the last pass saw the host suppressed by a main panel. */
|
|
586
|
-
let wasSuppressed = false
|
|
587
|
-
let frame = 0
|
|
588
|
-
const check = () => {
|
|
589
|
-
frame = 0
|
|
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()
|
|
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()
|
|
634
|
-
// Never stay hidden without a float: that is a blank window.
|
|
635
|
-
if (chromeless && panel === null) setChromeless(false)
|
|
636
|
-
// The repairs below walk the whole frame, so they run only when the
|
|
637
|
-
// float moves house (a new panel, a new parent column, or a new body)
|
|
638
|
-
// and never on every mutation a drag produces.
|
|
639
|
-
const parent = panel === null ? null : panel.parentElement
|
|
640
|
-
const host = panel === null ? null : panel.querySelector(".dsw-host")
|
|
641
|
-
if (panel !== null) {
|
|
642
|
-
if (panel !== sizedFloat) {
|
|
643
|
-
sizedFloat = panel
|
|
644
|
-
sizeTries = 0
|
|
645
|
-
}
|
|
646
|
-
const want = floatSize()
|
|
647
|
-
const box = panel.getBoundingClientRect()
|
|
648
|
-
const off = Math.abs(box.width - want.width) > 24 || Math.abs(box.height - want.height) > 24
|
|
649
|
-
if (off && sizeTries < 4) {
|
|
650
|
-
sizeTries += 1
|
|
651
|
-
sizeFloat()
|
|
652
|
-
}
|
|
653
|
-
}
|
|
654
|
-
if (panel !== seenFloat || parent !== seenParent || host !== seenHost) {
|
|
655
|
-
seenFloat = panel
|
|
656
|
-
seenParent = parent
|
|
657
|
-
seenHost = host
|
|
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
|
|
671
|
-
}
|
|
672
|
-
noteChromeChange()
|
|
673
|
-
// The row follows the markers, whichever Conversation they belong to.
|
|
674
|
-
syncDrawerRow()
|
|
675
|
-
}
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
const schedule = () => {
|
|
679
|
-
if (frame !== 0) return
|
|
680
|
-
frame = window.requestAnimationFrame(check)
|
|
681
|
-
}
|
|
682
|
-
const observer = new MutationObserver(schedule)
|
|
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
|
-
})
|
|
718
|
-
|
|
719
|
-
return () => {
|
|
720
|
-
observer.disconnect()
|
|
721
|
-
attributeObserver.disconnect()
|
|
722
|
-
window.clearInterval(safety)
|
|
723
|
-
if (frame !== 0) window.cancelAnimationFrame(frame)
|
|
724
|
-
}
|
|
725
|
-
}
|
|
726
|
-
|
|
727
|
-
/**
|
|
728
|
-
* A float that lost its body — clicking the drawer row re-lays the main
|
|
729
|
-
* column, the panel remounts, and the Conversation is momentarily out of the
|
|
730
|
-
* document — is put back together here. An empty float is worse than a flash.
|
|
731
|
-
*/
|
|
732
|
-
function healFloatBody() {
|
|
733
|
-
const panel = floatPanel()
|
|
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
|
|
738
|
-
const host = panel.querySelector('.dsw-host')
|
|
739
|
-
if (host === null) return
|
|
740
|
-
const column = findColumn()
|
|
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)
|
|
1013
|
+
if (center !== null) {
|
|
1014
|
+
markDetach('center')
|
|
1015
|
+
center.appendChild(column)
|
|
748
1016
|
return
|
|
749
1017
|
}
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
1018
|
+
// Last resort: keep it in the frame instead of letting it leave the
|
|
1019
|
+
// document with the window that hosted it.
|
|
1020
|
+
const frame = document.querySelector('[data-shell-overlay]')?.parentElement ?? null
|
|
1021
|
+
if (frame !== null) {
|
|
1022
|
+
markDetach('fallback')
|
|
1023
|
+
frame.insertBefore(column, frame.querySelector(':scope > [data-rightbar-col]'))
|
|
756
1024
|
return
|
|
757
1025
|
}
|
|
758
|
-
|
|
759
|
-
// a temporary host, never the place it goes home to.
|
|
760
|
-
attachColumn(host, movedColumn !== null)
|
|
1026
|
+
markDetach('nowhere')
|
|
761
1027
|
}
|
|
762
1028
|
|
|
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
1029
|
/** Every mounted body of our own tab: one per right-sidebar Session. */
|
|
784
1030
|
function dockedHosts() {
|
|
785
1031
|
const hosts = []
|
|
@@ -790,13 +1036,6 @@ window.__ModuleLoader__.load({
|
|
|
790
1036
|
return hosts
|
|
791
1037
|
}
|
|
792
1038
|
|
|
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
1039
|
/** Whether a host is on screen: a retained body of a hidden tab is not. */
|
|
801
1040
|
function hostOnScreen(host) {
|
|
802
1041
|
if (!host.isConnected) return false
|
|
@@ -840,6 +1079,8 @@ window.__ModuleLoader__.load({
|
|
|
840
1079
|
return owner === null || session === null || owner === session
|
|
841
1080
|
}
|
|
842
1081
|
|
|
1082
|
+
/** When the recorded column was first seen outside the document, in ms. */
|
|
1083
|
+
let columnOrphanedAt = 0
|
|
843
1084
|
/** The last Session the live Conversation was seen showing. */
|
|
844
1085
|
let lastSession = null
|
|
845
1086
|
/**
|
|
@@ -848,63 +1089,278 @@ window.__ModuleLoader__.load({
|
|
|
848
1089
|
* commit, and the drawer row press has to know which Conversation it means.
|
|
849
1090
|
*/
|
|
850
1091
|
function liveSession() {
|
|
851
|
-
|
|
1092
|
+
// Read through findColumn(), never `movedColumn ?? ...`: a recorded node
|
|
1093
|
+
// that has left the document still answers columnSession() with the
|
|
1094
|
+
// Session it used to show, and that freezes every decision on a
|
|
1095
|
+
// Conversation the user already left.
|
|
1096
|
+
if (passMemo !== null && passMemo.liveKnown) return passMemo.live
|
|
1097
|
+
const column = findColumn()
|
|
1098
|
+
let answer = null
|
|
852
1099
|
const shown = column === null ? null : columnSession(column)
|
|
853
|
-
if (shown !== null)
|
|
854
|
-
|
|
1100
|
+
if (shown !== null) {
|
|
1101
|
+
answer = shown
|
|
1102
|
+
} else {
|
|
1103
|
+
// A docked page can be the Conversation's only home; its Session is the
|
|
1104
|
+
// one on screen and the entry must still find it.
|
|
1105
|
+
const docked = dockedBodySession()
|
|
1106
|
+
answer = docked !== null ? docked : lastSession
|
|
1107
|
+
}
|
|
1108
|
+
if (answer !== null) lastSession = answer
|
|
1109
|
+
if (passMemo !== null) {
|
|
1110
|
+
passMemo.live = answer
|
|
1111
|
+
passMemo.liveKnown = true
|
|
1112
|
+
}
|
|
1113
|
+
return answer
|
|
855
1114
|
}
|
|
856
1115
|
|
|
1116
|
+
/** Set while a deferred layout pass is already queued. */
|
|
1117
|
+
let kickScheduled = false
|
|
857
1118
|
/**
|
|
858
|
-
*
|
|
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.
|
|
1119
|
+
* Queue one layout pass once the browser has committed the current frame.
|
|
864
1120
|
*
|
|
865
|
-
*
|
|
866
|
-
*
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
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
|
|
1121
|
+
* Two frames, not one: DSH writes the current Session, then React commits the
|
|
1122
|
+
* column for it. A pass that runs between the two sees the old nodes.
|
|
1123
|
+
*/
|
|
1124
|
+
function kickLayout(frames = 2) {
|
|
1125
|
+
if (kickScheduled) return
|
|
1126
|
+
kickScheduled = true
|
|
1127
|
+
const run = () => {
|
|
1128
|
+
kickScheduled = false
|
|
1129
|
+
notifyLayout()
|
|
888
1130
|
}
|
|
889
|
-
//
|
|
890
|
-
//
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
if (movedColumn !== null) detachColumn()
|
|
1131
|
+
// A page taking or leaving the slot swaps whole subtrees and has no Session
|
|
1132
|
+
// commit to wait behind: one frame is enough there. A Session switch writes
|
|
1133
|
+
// its store before React commits the column, so that one keeps the second.
|
|
1134
|
+
if (frames >= 2) window.requestAnimationFrame(() => window.requestAnimationFrame(run))
|
|
1135
|
+
else window.requestAnimationFrame(run)
|
|
895
1136
|
}
|
|
896
1137
|
|
|
897
|
-
/**
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
1138
|
+
/**
|
|
1139
|
+
* Subscribe to the one store that says which Session is on screen.
|
|
1140
|
+
*
|
|
1141
|
+
* The service may not be up when this plugin mounts, so the subscription is
|
|
1142
|
+
* taken as soon as it can be: once here, and again on every layout pass until it
|
|
1143
|
+
* takes. A Session switch then reaches every float in the same task it
|
|
1144
|
+
* happens in, instead of waiting for a tick.
|
|
1145
|
+
*/
|
|
1146
|
+
let followingSelection = false
|
|
1147
|
+
function followSelection() {
|
|
1148
|
+
if (followingSelection) return
|
|
1149
|
+
let selection = null
|
|
1150
|
+
try {
|
|
1151
|
+
const workspace = typeof ctxRef?.get === 'function' ? ctxRef.get('uiWorkspace') : null
|
|
1152
|
+
selection = workspace === null || workspace === undefined ? null : workspace.selection ?? null
|
|
1153
|
+
} catch (error) {
|
|
1154
|
+
return
|
|
1155
|
+
}
|
|
1156
|
+
if (selection === null || typeof selection.subscribe !== 'function') return
|
|
1157
|
+
followingSelection = true
|
|
1158
|
+
try {
|
|
1159
|
+
// The store is written before React commits the new Session's DOM, so the
|
|
1160
|
+
// pass waits for the frame to be painted: deciding against the previous
|
|
1161
|
+
// Session's nodes is exactly how a column ends up parked.
|
|
1162
|
+
selection.subscribe(() => kickLayout())
|
|
1163
|
+
} catch (error) {
|
|
1164
|
+
followingSelection = false
|
|
1165
|
+
report('[conversation-float] could not follow the current Session:', error)
|
|
1166
|
+
}
|
|
901
1167
|
}
|
|
902
|
-
/* ---------------------------------------------------------- the chrome */
|
|
903
1168
|
|
|
904
1169
|
/**
|
|
905
|
-
*
|
|
906
|
-
*
|
|
907
|
-
*
|
|
1170
|
+
* The Session DSH itself says is on screen.
|
|
1171
|
+
*
|
|
1172
|
+
* The workspace navigation service keeps exactly one answer, in one store
|
|
1173
|
+
* (`uiWorkspace.selection`, persisted as `dsh.sessions.current`), and writes
|
|
1174
|
+
* it on every Session switch. It is the only source that does not depend on
|
|
1175
|
+
* a column node this plugin may be holding somewhere off screen.
|
|
1176
|
+
*/
|
|
1177
|
+
function selectedSession() {
|
|
1178
|
+
try {
|
|
1179
|
+
const workspace = typeof ctxRef?.get === 'function' ? ctxRef.get('uiWorkspace') : null
|
|
1180
|
+
const snapshot = workspace === null || workspace === undefined ? null : workspace.selection?.getSnapshot?.()
|
|
1181
|
+
const id = snapshot?.sessionId
|
|
1182
|
+
return typeof id === 'string' && id !== '' ? id : null
|
|
1183
|
+
} catch (error) {
|
|
1184
|
+
return null
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1188
|
+
/**
|
|
1189
|
+
* The container that should carry this Session's Conversation, if one exists:
|
|
1190
|
+
* its window's body, or the right-sidebar page DSH is showing for it. Null
|
|
1191
|
+
* means there is nowhere but the middle column.
|
|
1192
|
+
*/
|
|
1193
|
+
function hostForSession(sessionId) {
|
|
1194
|
+
if (sessionId === null) return null
|
|
1195
|
+
const win = windows.get(sessionId)
|
|
1196
|
+
if (win !== undefined) return win.body
|
|
1197
|
+
for (const host of dockedHosts()) {
|
|
1198
|
+
if (host.closest(`[${FLOAT_ATTR}]`) !== null) continue
|
|
1199
|
+
if (!hostOnScreen(host)) continue
|
|
1200
|
+
const owner = hostSession(host)
|
|
1201
|
+
if (owner === null || owner === sessionId) return host
|
|
1202
|
+
}
|
|
1203
|
+
return null
|
|
1204
|
+
}
|
|
1205
|
+
|
|
1206
|
+
/**
|
|
1207
|
+
* Hand the column to whoever should carry this Session, in ONE move.
|
|
1208
|
+
*
|
|
1209
|
+
* Parking it at home first and letting the next body pick it up later is what
|
|
1210
|
+
* the eye sees as "it jumps to the middle on every switch": the two moves land
|
|
1211
|
+
* in different passes. A host that already exists takes it directly; only a
|
|
1212
|
+
* Session with no host at all sends the column home.
|
|
1213
|
+
*
|
|
1214
|
+
* @returns whether the column was moved
|
|
1215
|
+
*/
|
|
1216
|
+
function handOffColumn(sessionId) {
|
|
1217
|
+
const host = hostForSession(sessionId)
|
|
1218
|
+
if (host !== null) {
|
|
1219
|
+
if (movedColumn !== null && host.contains(movedColumn)) return false
|
|
1220
|
+
try {
|
|
1221
|
+
attachColumn(host, movedColumn !== null)
|
|
1222
|
+
} catch (error) {
|
|
1223
|
+
report('[conversation-float] could not hand the conversation over:', error)
|
|
1224
|
+
}
|
|
1225
|
+
return true
|
|
1226
|
+
}
|
|
1227
|
+
detachColumn(true)
|
|
1228
|
+
return true
|
|
1229
|
+
}
|
|
1230
|
+
|
|
1231
|
+
/**
|
|
1232
|
+
* Hand the Conversation back when the host it was moved into stops being it.
|
|
1233
|
+
*
|
|
1234
|
+
* The right sidebar keeps one page per Session and hides the rest, so a
|
|
1235
|
+
* Conversation docked there stays inside a page the window has left. Reading
|
|
1236
|
+
* that page's Session as "the one on screen" used to freeze the plugin on
|
|
1237
|
+
* the old Conversation: the float of the new one never took the column, so
|
|
1238
|
+
* the page tabs and the composer stayed behind in the sidebar, the middle
|
|
1239
|
+
* column stayed empty, and closing anything afterwards left a blank page.
|
|
1240
|
+
*
|
|
1241
|
+
* Three states have to be told apart, because the answer is not the same:
|
|
1242
|
+
*
|
|
1243
|
+
* our own window, or a dock-kit float the column lives there on purpose
|
|
1244
|
+
* the frame's middle column it is already home
|
|
1245
|
+
* a docked page of another Session taken back (see below)
|
|
1246
|
+
*
|
|
1247
|
+
* "Taken back" is either a release — when DSH has already drawn a column of
|
|
1248
|
+
* its own, ours is a leftover and putting it beside the live one would show
|
|
1249
|
+
* the same Conversation twice — or a detach, when ours is still the only
|
|
1250
|
+
* Conversation surface there is.
|
|
1251
|
+
*
|
|
1252
|
+
* @returns whether anything was repaired
|
|
1253
|
+
*/
|
|
1254
|
+
function reconcileLiveColumn() {
|
|
1255
|
+
const column = movedColumn
|
|
1256
|
+
if (column === null) {
|
|
1257
|
+
columnOrphanedAt = 0
|
|
1258
|
+
return false
|
|
1259
|
+
}
|
|
1260
|
+
if (!column.isConnected) {
|
|
1261
|
+
// DSH took the node down with the Session it belonged to. If it has
|
|
1262
|
+
// drawn a column of its own, ours is a leftover and has to be dropped —
|
|
1263
|
+
// putting it back would show the old Conversation beside the new one.
|
|
1264
|
+
if (scanColumn() !== null) {
|
|
1265
|
+
columnOrphanedAt = 0
|
|
1266
|
+
forgetColumn(column, false)
|
|
1267
|
+
return true
|
|
1268
|
+
}
|
|
1269
|
+
// Nothing shows the Conversation at all. The frame may be one commit
|
|
1270
|
+
// away from drawing it, so give it a moment before rescuing ours: a
|
|
1271
|
+
// rescue that races the frame's own column leaves two of them.
|
|
1272
|
+
if (columnOrphanedAt === 0) {
|
|
1273
|
+
columnOrphanedAt = Date.now()
|
|
1274
|
+
return false
|
|
1275
|
+
}
|
|
1276
|
+
if (Date.now() - columnOrphanedAt < 700) return false
|
|
1277
|
+
columnOrphanedAt = 0
|
|
1278
|
+
detachColumn(true)
|
|
1279
|
+
return true
|
|
1280
|
+
}
|
|
1281
|
+
columnOrphanedAt = 0
|
|
1282
|
+
if (column.closest(`[${WINDOW_ATTR}]`) !== null) return false
|
|
1283
|
+
if (column.closest(`[${FLOAT_ATTR}]`) !== null) return false
|
|
1284
|
+
const page = column.closest('[data-sidebar-right-session]')
|
|
1285
|
+
if (page === null) return false
|
|
1286
|
+
const owner = page.getAttribute('data-sidebar-right-session')
|
|
1287
|
+
const live = selectedSession() ?? dockedBodySession()
|
|
1288
|
+
if (live === null || owner === null || owner === live) return false
|
|
1289
|
+
// A tab can belong to a subagent chat, which is addressed rather than
|
|
1290
|
+
// named: such an address is not a Session, so a mismatch with it means
|
|
1291
|
+
// nothing and must not take the column away.
|
|
1292
|
+
if (!knownSession(owner) || !knownSession(live)) return false
|
|
1293
|
+
const fresh = scanColumn()
|
|
1294
|
+
if (fresh !== null && fresh !== column) {
|
|
1295
|
+
forgetColumn(column, true)
|
|
1296
|
+
return true
|
|
1297
|
+
}
|
|
1298
|
+
// Straight to whatever should carry the Session we switched to — never
|
|
1299
|
+
// through the middle column, which is the visible "jump".
|
|
1300
|
+
handOffColumn(live)
|
|
1301
|
+
return true
|
|
1302
|
+
}
|
|
1303
|
+
|
|
1304
|
+
/** Whether an id names a Session the list knows (or the list is unreadable). */
|
|
1305
|
+
function knownSession(id) {
|
|
1306
|
+
try {
|
|
1307
|
+
const byId = sessions?.list?.getSnapshot?.()?.byId
|
|
1308
|
+
if (byId === undefined || byId === null) return true
|
|
1309
|
+
return Object.prototype.hasOwnProperty.call(byId, id)
|
|
1310
|
+
} catch (error) {
|
|
1311
|
+
return true
|
|
1312
|
+
}
|
|
1313
|
+
}
|
|
1314
|
+
|
|
1315
|
+
/**
|
|
1316
|
+
* Let go of a column without putting it back.
|
|
1317
|
+
*
|
|
1318
|
+
* @param column the node the bookkeeping names, which may already be gone
|
|
1319
|
+
* @param discardDom also take it out of the tab body it sits in. Only for a
|
|
1320
|
+
* leftover: DSH has drawn a column of its own, so this one
|
|
1321
|
+
* is a copy nothing renders into any more, and keeping it
|
|
1322
|
+
* would show two Conversations the next time that page is
|
|
1323
|
+
* opened.
|
|
1324
|
+
*/
|
|
1325
|
+
function forgetColumn(column, discardDom) {
|
|
1326
|
+
if (movedColumn === column) {
|
|
1327
|
+
movedColumn = null
|
|
1328
|
+
movedFrom = null
|
|
1329
|
+
}
|
|
1330
|
+
if (column === null) return
|
|
1331
|
+
column.removeAttribute(COLUMN_ATTR)
|
|
1332
|
+
column.style.width = ''
|
|
1333
|
+
column.style.height = ''
|
|
1334
|
+
column.style.minWidth = ''
|
|
1335
|
+
column.style.minHeight = ''
|
|
1336
|
+
column.style.overflow = ''
|
|
1337
|
+
if (discardDom && column.isConnected && column.closest(`[${BODY_ATTR}]`) !== null) column.remove()
|
|
1338
|
+
noteColumnMoved()
|
|
1339
|
+
// The column is gone: no pass may keep answering with it.
|
|
1340
|
+
if (passMemo !== null) {
|
|
1341
|
+
passMemo.columnKnown = false
|
|
1342
|
+
passMemo.liveKnown = false
|
|
1343
|
+
}
|
|
1344
|
+
notifyState()
|
|
1345
|
+
}
|
|
1346
|
+
|
|
1347
|
+
/** The Session of the right-sidebar page that is on screen, if any. */
|
|
1348
|
+
function dockedBodySession() {
|
|
1349
|
+
for (const host of document.querySelectorAll(`[${BODY_ATTR}]`)) {
|
|
1350
|
+
if (host.closest(`[${FLOAT_ATTR}]`) !== null) continue
|
|
1351
|
+
if (!hostOnScreen(host)) continue
|
|
1352
|
+
const owner = hostSession(host)
|
|
1353
|
+
if (owner !== null) return owner
|
|
1354
|
+
}
|
|
1355
|
+
return null
|
|
1356
|
+
}
|
|
1357
|
+
|
|
1358
|
+
/* ---------------------------------------------------------- the chrome */
|
|
1359
|
+
|
|
1360
|
+
/**
|
|
1361
|
+
* Hide everything the float does not need. Clicking the entry opens the
|
|
1362
|
+
* float and leaves the window showing nothing but the float; the same
|
|
1363
|
+
* button then brings the rest of DSH back (and hides it again).
|
|
908
1364
|
*/
|
|
909
1365
|
function chromeTargets() {
|
|
910
1366
|
const overlay = document.querySelector('[data-shell-overlay]')
|
|
@@ -930,16 +1386,18 @@ window.__ModuleLoader__.load({
|
|
|
930
1386
|
|
|
931
1387
|
/** What the entry's tooltip promises for the next press. */
|
|
932
1388
|
function entryTitle() {
|
|
933
|
-
|
|
934
|
-
const
|
|
935
|
-
|
|
1389
|
+
const sessionId = liveSession()
|
|
1390
|
+
const win = sessionId === null ? undefined : windows.get(sessionId)
|
|
1391
|
+
if (win === undefined || win.el.hidden) return t('floatTitle')
|
|
1392
|
+
return chromeless ? t('showDsh') : t('hideDsh')
|
|
936
1393
|
}
|
|
937
1394
|
|
|
938
1395
|
function setChromeless(next) {
|
|
939
1396
|
if (next) {
|
|
940
1397
|
// The float mounts asynchronously: hiding before it exists would hide
|
|
941
|
-
// every column, including the one that is about to host it.
|
|
942
|
-
|
|
1398
|
+
// every column, including the one that is about to host it. Our own
|
|
1399
|
+
// window is not a dock-kit float, so both count as "something to keep".
|
|
1400
|
+
if (floatPanel() === null && windows.size === 0) {
|
|
943
1401
|
pendingChromeless = true
|
|
944
1402
|
return
|
|
945
1403
|
}
|
|
@@ -968,10 +1426,9 @@ window.__ModuleLoader__.load({
|
|
|
968
1426
|
*/
|
|
969
1427
|
function revealChrome(forceDrawer = false) {
|
|
970
1428
|
setChromeless(false)
|
|
971
|
-
// The columns opened
|
|
972
|
-
//
|
|
973
|
-
//
|
|
974
|
-
holdOff(400)
|
|
1429
|
+
// The columns are opened by the plugin, and a hand on them ends any retry
|
|
1430
|
+
// this pass started (see the pointerdown tracker in apply()), so the
|
|
1431
|
+
// user's own first click is never swallowed by a settle window.
|
|
975
1432
|
// Back to the arrangement the window had: whatever the user last left the
|
|
976
1433
|
// sidebars in, or the pair the float found. Never a blanket "both open" —
|
|
977
1434
|
// that would undo a sidebar the user closed on purpose.
|
|
@@ -988,7 +1445,7 @@ window.__ModuleLoader__.load({
|
|
|
988
1445
|
try {
|
|
989
1446
|
if (leftCollapsed()) layout?.toggleSidebar?.()
|
|
990
1447
|
} catch (error) {
|
|
991
|
-
|
|
1448
|
+
report('[conversation-float] could not expand the left sidebar:', error)
|
|
992
1449
|
}
|
|
993
1450
|
}
|
|
994
1451
|
|
|
@@ -1015,7 +1472,7 @@ window.__ModuleLoader__.load({
|
|
|
1015
1472
|
sidebarRight?.toggleExpanded?.()
|
|
1016
1473
|
}
|
|
1017
1474
|
} catch (error) {
|
|
1018
|
-
|
|
1475
|
+
report('[conversation-float] could not restore the right sidebar:', error)
|
|
1019
1476
|
}
|
|
1020
1477
|
try {
|
|
1021
1478
|
if (wantLeft !== null && wantLeft !== leftCollapsed()) {
|
|
@@ -1023,7 +1480,7 @@ window.__ModuleLoader__.load({
|
|
|
1023
1480
|
layout?.toggleSidebar?.()
|
|
1024
1481
|
}
|
|
1025
1482
|
} catch (error) {
|
|
1026
|
-
|
|
1483
|
+
report('[conversation-float] could not restore the left sidebar:', error)
|
|
1027
1484
|
}
|
|
1028
1485
|
return matched
|
|
1029
1486
|
}
|
|
@@ -1056,73 +1513,6 @@ window.__ModuleLoader__.load({
|
|
|
1056
1513
|
return { leftCollapsed: leftCollapsed(), rightExpanded: rightExpanded() }
|
|
1057
1514
|
}
|
|
1058
1515
|
|
|
1059
|
-
/** The plugin is about to move a column itself: ignore the fallout. */
|
|
1060
|
-
function holdOff(ms = 1200) {
|
|
1061
|
-
holdOffUntil = performance.now() + ms
|
|
1062
|
-
}
|
|
1063
|
-
|
|
1064
|
-
/**
|
|
1065
|
-
* Only the user's own hand can author a column change: a press or a key
|
|
1066
|
-
* just before it does, DSH railing a column on its own does not. The
|
|
1067
|
-
* plugin's own entry button is excluded — it moves the columns by design.
|
|
1068
|
-
*/
|
|
1069
|
-
function noteGesture(event) {
|
|
1070
|
-
if (performance.now() < holdOffUntil) return
|
|
1071
|
-
const target = event.target
|
|
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
|
|
1077
|
-
gestureAt = performance.now()
|
|
1078
|
-
}
|
|
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
|
-
|
|
1126
1516
|
/**
|
|
1127
1517
|
* Remember the sidebars as they were before the float forced them open.
|
|
1128
1518
|
* The capture happens once, before the plugin touches anything, and is
|
|
@@ -1133,37 +1523,6 @@ window.__ModuleLoader__.load({
|
|
|
1133
1523
|
function saveChromeState() {
|
|
1134
1524
|
if (savedChrome !== null) return
|
|
1135
1525
|
savedChrome = chromeNow()
|
|
1136
|
-
touchedChrome = null
|
|
1137
|
-
// The force-open that follows is the plugin's doing, not the user's.
|
|
1138
|
-
holdOff(FORCE_SETTLE_MS)
|
|
1139
|
-
}
|
|
1140
|
-
|
|
1141
|
-
/**
|
|
1142
|
-
* The float forces both sidebars open and hides them. A column that sits
|
|
1143
|
-
* away from the snapshot after that was either moved by the user or railed
|
|
1144
|
-
* by DSH on its own; only the first outranks the snapshot, and only a
|
|
1145
|
-
* press or a key just before the change tells the two apart. Both
|
|
1146
|
-
* directions count: closing a column the float opened, and opening one it
|
|
1147
|
-
* failed to open, are equally the user's choice.
|
|
1148
|
-
*/
|
|
1149
|
-
function noteChromeChange() {
|
|
1150
|
-
if (savedChrome === null) return
|
|
1151
|
-
// While the columns are hidden their geometry says nothing: DSH rails the
|
|
1152
|
-
// left sidebar on its own there, and reading that as the user's choice
|
|
1153
|
-
// would cancel the restore the float promised.
|
|
1154
|
-
if (chromeless || pendingChromeless) return
|
|
1155
|
-
// A re-host (out of the drawer, a remounted body) leaves the column out
|
|
1156
|
-
// of the document and the right column reading "not expanded" for a
|
|
1157
|
-
// frame. That is the plugin moving, never the user choosing.
|
|
1158
|
-
if (dockedLeft || (floatPanel() !== null && movedColumn === null)) return
|
|
1159
|
-
const now = performance.now()
|
|
1160
|
-
if (now < holdOffUntil) return
|
|
1161
|
-
if (now - gestureAt > GESTURE_WINDOW) return
|
|
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()
|
|
1167
1526
|
}
|
|
1168
1527
|
|
|
1169
1528
|
/**
|
|
@@ -1175,7 +1534,7 @@ window.__ModuleLoader__.load({
|
|
|
1175
1534
|
function scheduleRestoreChrome(depth = 0) {
|
|
1176
1535
|
window.requestAnimationFrame(() => {
|
|
1177
1536
|
// A host took the column back: the float is still open, not closed.
|
|
1178
|
-
if (
|
|
1537
|
+
if (movedColumn !== null) return
|
|
1179
1538
|
// The panel is still on its way out; give it a few frames.
|
|
1180
1539
|
if (floatPanel() !== null) {
|
|
1181
1540
|
if (depth < 12) scheduleRestoreChrome(depth + 1)
|
|
@@ -1185,144 +1544,117 @@ window.__ModuleLoader__.load({
|
|
|
1185
1544
|
})
|
|
1186
1545
|
}
|
|
1187
1546
|
|
|
1188
|
-
/**
|
|
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.
|
|
1194
|
-
*/
|
|
1195
|
-
/** The pair a reveal or a close puts back: the user's own, else the float's. */
|
|
1547
|
+
/** The pair a reveal or a close puts back: the snapshot taken on open. */
|
|
1196
1548
|
function restoreTarget() {
|
|
1197
|
-
return
|
|
1549
|
+
return savedChrome
|
|
1198
1550
|
}
|
|
1199
1551
|
|
|
1200
1552
|
/** Match the sidebars to a target, retrying while the dock kit settles. */
|
|
1201
1553
|
function applyChromeTarget(target) {
|
|
1202
|
-
|
|
1554
|
+
// A toggle the dock kit queued needs a commit to land, so a retry fired
|
|
1555
|
+
// before that commit reads the old state and toggles straight back. The
|
|
1556
|
+
// retry therefore waits for the sidebars to STOP MOVING before it fires,
|
|
1557
|
+
// instead of firing on a fixed 200ms beat that was both too early (double
|
|
1558
|
+
// toggles) and too late (a visible lag on close).
|
|
1559
|
+
let attempts = 0
|
|
1560
|
+
let seen = null
|
|
1561
|
+
let stable = 0
|
|
1203
1562
|
const apply = () => {
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1563
|
+
if (chromeMatches(target)) return true
|
|
1564
|
+
attempts += 1
|
|
1565
|
+
if (attempts > 3) return true
|
|
1566
|
+
applyChromeSnapshot(target)
|
|
1567
|
+
return false
|
|
1209
1568
|
}
|
|
1210
|
-
|
|
1569
|
+
if (apply()) return
|
|
1570
|
+
chromeApplyStop = untilFrame(() => {
|
|
1571
|
+
if (chromeMatches(target)) return true
|
|
1572
|
+
const now = JSON.stringify(chromeNow())
|
|
1573
|
+
if (now === seen) stable += 1
|
|
1574
|
+
else { seen = now; stable = 0 }
|
|
1575
|
+
return stable >= 3 && apply()
|
|
1576
|
+
}, null, 3000)
|
|
1577
|
+
}
|
|
1578
|
+
|
|
1579
|
+
/** Whether the sidebars already stand where `target` wants them. */
|
|
1580
|
+
function chromeMatches(target) {
|
|
1581
|
+
if (target === null || target === undefined) return true
|
|
1582
|
+
const now = chromeNow()
|
|
1583
|
+
const wantRight = target.rightExpanded
|
|
1584
|
+
const wantLeft = target.leftCollapsed
|
|
1585
|
+
const rightOk = wantRight === null || wantRight === undefined ? true : now.rightExpanded === (wantRight === true)
|
|
1586
|
+
const leftOk = wantLeft === null || wantLeft === undefined ? true : now.leftCollapsed === wantLeft
|
|
1587
|
+
return rightOk && leftOk
|
|
1211
1588
|
}
|
|
1212
1589
|
|
|
1213
1590
|
function restoreChrome() {
|
|
1214
1591
|
const target = restoreTarget()
|
|
1215
1592
|
savedChrome = null
|
|
1216
|
-
touchedChrome = null
|
|
1217
1593
|
if (target === null) return
|
|
1218
|
-
holdOff(1500)
|
|
1219
1594
|
applyChromeTarget(target)
|
|
1220
1595
|
}
|
|
1221
1596
|
|
|
1222
1597
|
/** Open (or focus) the float at the dock kit's own default seat. */
|
|
1598
|
+
/**
|
|
1599
|
+
* Give this Conversation a window.
|
|
1600
|
+
*
|
|
1601
|
+
* The window is ours, so no sidebar has to be opened for it and nothing is
|
|
1602
|
+
* re-seated: the tab body mounts and the body is what owns the window. A tab
|
|
1603
|
+
* kept from an earlier run is reused — its body is still mounted, so only
|
|
1604
|
+
* the window has to come back.
|
|
1605
|
+
*/
|
|
1223
1606
|
function openFloatAtDefault() {
|
|
1607
|
+
const sessionId = liveSession()
|
|
1608
|
+
if (sessionId === null) return
|
|
1224
1609
|
saveChromeState()
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1610
|
+
if (tabIdFor(sessionId) !== null) {
|
|
1611
|
+
// The tab exists. Floating it is the SAME tab moving, never a second
|
|
1612
|
+
// one: a docked page is floated through the dock kit's own intent, and
|
|
1613
|
+
// the re-hosted body then raises this Conversation's window.
|
|
1614
|
+
if (floatPanel() === null) {
|
|
1615
|
+
// Docked page: close it and open a fresh float, so the floating body
|
|
1616
|
+
// mounts against a clean tree and takes the column with it.
|
|
1617
|
+
closeTabFor(sessionId)
|
|
1618
|
+
// The new body must mount against a tree the old tab has left, so the
|
|
1619
|
+
// open waits for the tab to be gone rather than for 60ms to pass.
|
|
1620
|
+
// Close first, then open into the freed slot. The microtask is the
|
|
1621
|
+
// whole ordering guarantee: it runs after the commit that unmounts
|
|
1622
|
+
// the closed body, and before anything the user can see or press.
|
|
1623
|
+
queueMicrotask(() => {
|
|
1624
|
+
try {
|
|
1625
|
+
sidebarRight?.openResource(CHAT_ADDRESS, { kind: CHAT_KIND, destination: 'float' })
|
|
1626
|
+
} catch (error) {
|
|
1627
|
+
report('[conversation-float] could not open the floating tab:', error)
|
|
1628
|
+
}
|
|
1629
|
+
})
|
|
1630
|
+
notifyState()
|
|
1631
|
+
return
|
|
1632
|
+
}
|
|
1633
|
+
showWindow(sessionId)
|
|
1240
1634
|
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()
|
|
1245
1635
|
return
|
|
1246
1636
|
}
|
|
1247
1637
|
try {
|
|
1248
1638
|
sidebarRight?.openResource(CHAT_ADDRESS, { kind: CHAT_KIND, destination: 'float' })
|
|
1249
1639
|
} catch (error) {
|
|
1250
|
-
|
|
1640
|
+
report('[conversation-float] could not open the floating tab:', error)
|
|
1251
1641
|
}
|
|
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
1642
|
notifyState()
|
|
1255
|
-
settleFloatSeat()
|
|
1256
1643
|
}
|
|
1257
1644
|
|
|
1258
|
-
/**
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
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.
|
|
1289
|
-
return
|
|
1290
|
-
}
|
|
1291
|
-
if (floatPanel() !== null) {
|
|
1645
|
+
/** Open this Conversation's window, or bring it back from the taskbar. */
|
|
1646
|
+
function openFloating() {
|
|
1647
|
+
const sessionId = liveSession()
|
|
1648
|
+
if (sessionId === null) return
|
|
1649
|
+
if (windows.has(sessionId)) {
|
|
1650
|
+
showWindow(sessionId)
|
|
1292
1651
|
notifyState()
|
|
1293
1652
|
return
|
|
1294
1653
|
}
|
|
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
1654
|
openFloatAtDefault()
|
|
1302
1655
|
}
|
|
1303
1656
|
|
|
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
|
|
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. */
|
|
1657
|
+
/** A Conversation's stored title, as the sidebars and windows show it. */
|
|
1326
1658
|
function sessionTitle(id) {
|
|
1327
1659
|
if (id === null) return null
|
|
1328
1660
|
try {
|
|
@@ -1333,74 +1665,12 @@ window.__ModuleLoader__.load({
|
|
|
1333
1665
|
}
|
|
1334
1666
|
}
|
|
1335
1667
|
|
|
1336
|
-
/**
|
|
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
|
-
|
|
1390
|
-
/** Close the float; the column comes home through the watcher. */
|
|
1668
|
+
/** Close this Conversation's window: its tab goes, the window with it. */
|
|
1391
1669
|
function closeFloat() {
|
|
1392
|
-
const
|
|
1393
|
-
if (
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
}
|
|
1397
|
-
try {
|
|
1398
|
-
sidebarRight.hide(id)
|
|
1399
|
-
return true
|
|
1400
|
-
} catch (error) {
|
|
1401
|
-
console.warn('[conversation-float] could not hide the floating tab:', error)
|
|
1402
|
-
return false
|
|
1403
|
-
}
|
|
1670
|
+
const sessionId = liveSession()
|
|
1671
|
+
if (sessionId === null) return false
|
|
1672
|
+
closeWindow(sessionId)
|
|
1673
|
+
return true
|
|
1404
1674
|
}
|
|
1405
1675
|
|
|
1406
1676
|
/* ---------------------------------------------------------------- bands */
|
|
@@ -1462,6 +1732,22 @@ window.__ModuleLoader__.load({
|
|
|
1462
1732
|
return t('center')
|
|
1463
1733
|
}
|
|
1464
1734
|
|
|
1735
|
+
/**
|
|
1736
|
+
* The band's caption for the window under the hand.
|
|
1737
|
+
*
|
|
1738
|
+
* A band moves the Conversation on screen, never the window the hand holds:
|
|
1739
|
+
* dragging a second float says nothing about which Conversation goes where.
|
|
1740
|
+
* So the outline names its cargo — the main one — whenever the window being
|
|
1741
|
+
* dragged is not itself that Conversation.
|
|
1742
|
+
*
|
|
1743
|
+
* @param zone the band under the pointer
|
|
1744
|
+
* @param own whether the dragged window carries the Conversation on screen
|
|
1745
|
+
*/
|
|
1746
|
+
function previewLabel(zone, own) {
|
|
1747
|
+
const label = zoneLabel(zone)
|
|
1748
|
+
return own ? label : t('toMain') + label
|
|
1749
|
+
}
|
|
1750
|
+
|
|
1465
1751
|
function previewRect(zone, band) {
|
|
1466
1752
|
if (zone === 'left') return [0, 0, band.left, band.height]
|
|
1467
1753
|
if (zone === 'right') return [band.right, 0, band.width - band.right, band.height]
|
|
@@ -1473,7 +1759,7 @@ window.__ModuleLoader__.load({
|
|
|
1473
1759
|
* rewrote four styles (after a layout read) on every pointer move, and that
|
|
1474
1760
|
* is what made the drag stutter next to DSH's own dragging.
|
|
1475
1761
|
*/
|
|
1476
|
-
function showPreview(zone, band) {
|
|
1762
|
+
function showPreview(zone, band, own = true) {
|
|
1477
1763
|
if (preview === null) {
|
|
1478
1764
|
const el = document.createElement('div')
|
|
1479
1765
|
el.className = 'dsw-preview'
|
|
@@ -1481,16 +1767,24 @@ window.__ModuleLoader__.load({
|
|
|
1481
1767
|
label.className = 'dsw-preview-label'
|
|
1482
1768
|
el.appendChild(label)
|
|
1483
1769
|
document.body.appendChild(el)
|
|
1484
|
-
preview = { el, label, zone: null }
|
|
1485
|
-
}
|
|
1486
|
-
|
|
1770
|
+
preview = { el, label, zone: null, own: true }
|
|
1771
|
+
}
|
|
1772
|
+
// The caption changes with OWNERSHIP as well as with the band: the same
|
|
1773
|
+
// band dropped from another window names a different Conversation.
|
|
1774
|
+
if (preview.zone === zone && preview.own === own) return
|
|
1775
|
+
// The outline marks the band the window will land in, so it has to sit
|
|
1776
|
+
// ABOVE every float window. The windows live in a band that starts at
|
|
1777
|
+
// 20000 and climbs as they are raised, so the outline takes the current
|
|
1778
|
+
// ceiling plus a margin instead of a fixed number that goes stale.
|
|
1779
|
+
preview.el.style.zIndex = String(Math.min(windowZ + 10, 950))
|
|
1487
1780
|
if (preview.el.style.display === 'none') preview.el.style.display = ''
|
|
1488
1781
|
preview.zone = zone
|
|
1782
|
+
preview.own = own
|
|
1489
1783
|
const [left, top, width, height] = previewRect(zone, band)
|
|
1490
1784
|
preview.el.style.transform = `translate3d(${left}px, ${top}px, 0)`
|
|
1491
1785
|
preview.el.style.width = `${width}px`
|
|
1492
1786
|
preview.el.style.height = `${height}px`
|
|
1493
|
-
preview.label.textContent =
|
|
1787
|
+
preview.label.textContent = previewLabel(zone, own)
|
|
1494
1788
|
}
|
|
1495
1789
|
|
|
1496
1790
|
function hidePreview() {
|
|
@@ -1528,79 +1822,82 @@ window.__ModuleLoader__.load({
|
|
|
1528
1822
|
return null
|
|
1529
1823
|
}
|
|
1530
1824
|
|
|
1531
|
-
function stowFloat() {
|
|
1532
|
-
const el = floatPanel()
|
|
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)
|
|
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()
|
|
1544
|
-
return true
|
|
1545
|
-
}
|
|
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
1825
|
/**
|
|
1567
1826
|
* Finish a stow that was asked for before its float existed. The first
|
|
1568
1827
|
* request arrives while the conversation is still a docked tab — the tab's
|
|
1569
1828
|
* body is retained, so floating it does NOT remount the body and
|
|
1570
1829
|
* {@link attachColumn} never runs again. Without this the request would sit
|
|
1571
|
-
* in `
|
|
1572
|
-
* instead of
|
|
1573
|
-
* promised it would not do.
|
|
1830
|
+
* in `pendingMinimise` forever: the conversation would come back on screen
|
|
1831
|
+
* instead of being put away, which is what the menu entry promised.
|
|
1574
1832
|
*
|
|
1575
|
-
* @returns whether the
|
|
1833
|
+
* @returns whether the window was minimised.
|
|
1576
1834
|
*/
|
|
1577
|
-
function
|
|
1578
|
-
if (!
|
|
1835
|
+
function flushPendingMinimise() {
|
|
1836
|
+
if (!pendingMinimise) return false
|
|
1579
1837
|
const panel = floatPanel()
|
|
1580
1838
|
if (panel === null) return false
|
|
1581
1839
|
// A float of another Session cannot host this Conversation.
|
|
1582
1840
|
if (!floatHostsSession(panel, liveSession())) return false
|
|
1583
|
-
|
|
1841
|
+
pendingMinimise = false
|
|
1584
1842
|
pendingChromeless = false
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1843
|
+
// Minimise, not stow: the drawer row this used to build belonged to the
|
|
1844
|
+
// dock-kit panel of the old architecture. A window's taskbar row already
|
|
1845
|
+
// exists from the moment it opens, so hiding it IS the left-hand action.
|
|
1846
|
+
const shown = liveSession()
|
|
1847
|
+
if (shown === null || !windows.has(shown)) return false
|
|
1848
|
+
hideWindow(shown)
|
|
1849
|
+
if (chromeless) revealChrome()
|
|
1850
|
+
notifyState()
|
|
1588
1851
|
return true
|
|
1589
1852
|
}
|
|
1590
1853
|
|
|
1591
|
-
/**
|
|
1592
|
-
function
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1854
|
+
/** Close this Conversation's tab for good: the next host mounts a new body. */
|
|
1855
|
+
function closeTabFor(sessionId) {
|
|
1856
|
+
const id = tabIdFor(sessionId)
|
|
1857
|
+
if (id === null) return false
|
|
1858
|
+
try {
|
|
1859
|
+
if (typeof sidebarRight?.closeIn === 'function') sidebarRight.closeIn(sessionId, id)
|
|
1860
|
+
else sidebarRight?.hide?.(id)
|
|
1861
|
+
return true
|
|
1862
|
+
} catch (error) {
|
|
1863
|
+
report('[conversation-float] could not close the tab:', error)
|
|
1864
|
+
return false
|
|
1596
1865
|
}
|
|
1597
|
-
syncDrawerRow()
|
|
1598
1866
|
}
|
|
1599
1867
|
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1868
|
+
/**
|
|
1869
|
+
* The left band, asked of whichever host the main Conversation has.
|
|
1870
|
+
*
|
|
1871
|
+
* A band always acts on the Conversation on screen, never on the window the
|
|
1872
|
+
* hand happens to hold, so this has to work from all three seats it can be
|
|
1873
|
+
* in:
|
|
1874
|
+
*
|
|
1875
|
+
* its own window minimised — still mounted, hidden, its taskbar row
|
|
1876
|
+
* in the left sidebar is the way back
|
|
1877
|
+
* a docked tab floated, then minimised the moment its body mounts
|
|
1878
|
+
* the middle column the same: a window is opened and put away at once
|
|
1879
|
+
*
|
|
1880
|
+
* It used to read "no window, so close it" — which closed nothing while the
|
|
1881
|
+
* Conversation sat in the middle, and only sent it back to the middle when
|
|
1882
|
+
* it was docked. A drop on the left band then never reached the left.
|
|
1883
|
+
*/
|
|
1884
|
+
function stowLiveConversation() {
|
|
1885
|
+
const shown = liveSession()
|
|
1886
|
+
if (shown !== null && windows.has(shown)) {
|
|
1887
|
+
hideWindow(shown)
|
|
1888
|
+
notifyState()
|
|
1889
|
+
} else if (floatPanel() !== null) {
|
|
1890
|
+
// A float this build did not create: closing it is all that is left.
|
|
1891
|
+
closeFloat()
|
|
1892
|
+
} else {
|
|
1893
|
+
// No window of its own yet. Opening one and minimising it before its
|
|
1894
|
+
// first paint is exactly what the sidebar's own row does.
|
|
1895
|
+
pendingMinimise = true
|
|
1896
|
+
openFloating()
|
|
1897
|
+
}
|
|
1898
|
+
// A minimised float must not leave an empty screen behind: the rest of
|
|
1899
|
+
// DSH only comes back if the float was the thing hiding it.
|
|
1900
|
+
if (chromeless) revealChrome()
|
|
1604
1901
|
}
|
|
1605
1902
|
|
|
1606
1903
|
function drop(zone) {
|
|
@@ -1610,39 +1907,50 @@ window.__ModuleLoader__.load({
|
|
|
1610
1907
|
// snapshot belonged to the float: keeping it would let a close of that
|
|
1611
1908
|
// tab — possibly hours later — move the sidebars back in time.
|
|
1612
1909
|
savedChrome = null
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
console.warn('[conversation-float] could not dock to the right sidebar:', error)
|
|
1910
|
+
// Our window and the right-sidebar page are the same tab: the window
|
|
1911
|
+
// goes first, or it would outlive the page it was showing and sit there
|
|
1912
|
+
// blank while the tab moves underneath it.
|
|
1913
|
+
const shown = liveSession()
|
|
1914
|
+
if (shown !== null) {
|
|
1915
|
+
// A re-hosted body keeps its React tree and loses the column's
|
|
1916
|
+
// bookkeeping with it; closing the tab first gives the page a fresh
|
|
1917
|
+
// body that attaches the column again.
|
|
1918
|
+
closeTabFor(shown)
|
|
1919
|
+
if (windows.has(shown)) destroyWindow(shown)
|
|
1624
1920
|
}
|
|
1921
|
+
// Same ordering rule as the float: after the unmount commit, nothing
|
|
1922
|
+
// visible in between.
|
|
1923
|
+
queueMicrotask(() => {
|
|
1924
|
+
try {
|
|
1925
|
+
sidebarRight?.openResource(CHAT_ADDRESS, { kind: CHAT_KIND, destination: 'sidebar' })
|
|
1926
|
+
} catch (error) {
|
|
1927
|
+
report('[conversation-float] could not dock to the right sidebar:', error)
|
|
1928
|
+
}
|
|
1929
|
+
})
|
|
1625
1930
|
return
|
|
1626
1931
|
}
|
|
1627
1932
|
if (zone === 'left') {
|
|
1628
|
-
|
|
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)
|
|
1933
|
+
stowLiveConversation()
|
|
1637
1934
|
return
|
|
1638
1935
|
}
|
|
1639
|
-
syncDrawerRow()
|
|
1640
1936
|
revealChrome()
|
|
1641
1937
|
closeFloat()
|
|
1642
1938
|
}
|
|
1643
1939
|
|
|
1644
1940
|
/* ------------------------------------------------------ the menu entries */
|
|
1645
1941
|
|
|
1942
|
+
/**
|
|
1943
|
+
* Whether the live conversation is minimised into the left sidebar. Its
|
|
1944
|
+
* window is still mounted but hidden, and its taskbar row is the way back,
|
|
1945
|
+
* so the "stow here" row has nothing left to do.
|
|
1946
|
+
*/
|
|
1947
|
+
function conversationInLeftbar() {
|
|
1948
|
+
const shown = liveSession()
|
|
1949
|
+
if (shown === null) return false
|
|
1950
|
+
const win = windows.get(shown)
|
|
1951
|
+
return win !== undefined && win.el.hidden
|
|
1952
|
+
}
|
|
1953
|
+
|
|
1646
1954
|
/**
|
|
1647
1955
|
* Whether the live conversation is a docked tab of the right sidebar. The
|
|
1648
1956
|
* menu entry that says "move it here" has nothing to do when it is already.
|
|
@@ -1660,19 +1968,13 @@ window.__ModuleLoader__.load({
|
|
|
1660
1968
|
}
|
|
1661
1969
|
|
|
1662
1970
|
/**
|
|
1663
|
-
*
|
|
1664
|
-
*
|
|
1665
|
-
*
|
|
1666
|
-
* why the
|
|
1971
|
+
* Minimise the conversation's window, as a drop on the left band does.
|
|
1972
|
+
* Without a window there is nothing to minimise, so one is opened first and
|
|
1973
|
+
* the minimise runs the moment its body mounts — before the first paint —
|
|
1974
|
+
* which is why the window never flashes on screen on its way out.
|
|
1667
1975
|
*/
|
|
1668
1976
|
function moveConversationLeft() {
|
|
1669
|
-
|
|
1670
|
-
if (floatPanel() !== null) {
|
|
1671
|
-
drop('left')
|
|
1672
|
-
return
|
|
1673
|
-
}
|
|
1674
|
-
pendingStow = true
|
|
1675
|
-
openFloating()
|
|
1977
|
+
stowLiveConversation()
|
|
1676
1978
|
}
|
|
1677
1979
|
|
|
1678
1980
|
/**
|
|
@@ -1680,12 +1982,18 @@ window.__ModuleLoader__.load({
|
|
|
1680
1982
|
* on the float's chrome opens a sequence; a press inside the Conversation
|
|
1681
1983
|
* column does not, because that one is a text selection.
|
|
1682
1984
|
*/
|
|
1683
|
-
function trackPanelDrag(container) {
|
|
1985
|
+
function trackPanelDrag(container, sessionId) {
|
|
1684
1986
|
let down = null
|
|
1685
1987
|
let band = null
|
|
1686
1988
|
let root = null
|
|
1687
1989
|
let frame = 0
|
|
1688
1990
|
let pending = null
|
|
1991
|
+
/**
|
|
1992
|
+
* Whether this window carries the Conversation on screen. The outline's
|
|
1993
|
+
* caption depends on it: a band acts on the main Conversation, so a drag
|
|
1994
|
+
* of any other window has to say whose Conversation is being moved.
|
|
1995
|
+
*/
|
|
1996
|
+
const draggingMain = () => sessionId === null || sessionId === liveSession()
|
|
1689
1997
|
/** The band under the pointer right now. */
|
|
1690
1998
|
let hovered = null
|
|
1691
1999
|
/** The band the outline currently shows. */
|
|
@@ -1699,7 +2007,9 @@ window.__ModuleLoader__.load({
|
|
|
1699
2007
|
/** Resolved per pointer sequence: the panel mounts after this body does. */
|
|
1700
2008
|
const floatRoot = () => {
|
|
1701
2009
|
if (root !== null && root.isConnected) return root
|
|
1702
|
-
|
|
2010
|
+
// The float used to BE the dock kit's panel. It is a window of our own
|
|
2011
|
+
// now, drawn under the root, so the press may land in either.
|
|
2012
|
+
root = container.isConnected ? container.closest(`[${FLOAT_ATTR}], [${WINDOW_ATTR}]`) : null
|
|
1703
2013
|
return root
|
|
1704
2014
|
}
|
|
1705
2015
|
|
|
@@ -1714,7 +2024,7 @@ window.__ModuleLoader__.load({
|
|
|
1714
2024
|
if (!judging || drawn === hovered) return
|
|
1715
2025
|
drawn = hovered
|
|
1716
2026
|
if (drawn === null) hidePreview()
|
|
1717
|
-
else showPreview(drawn, band)
|
|
2027
|
+
else showPreview(drawn, band, draggingMain())
|
|
1718
2028
|
}
|
|
1719
2029
|
|
|
1720
2030
|
const onDown = (event) => {
|
|
@@ -1767,6 +2077,9 @@ window.__ModuleLoader__.load({
|
|
|
1767
2077
|
return
|
|
1768
2078
|
}
|
|
1769
2079
|
judging = true
|
|
2080
|
+
// Show the hold that armed it: without a visible change, a hold that
|
|
2081
|
+
// did nothing and a hold that armed look exactly the same.
|
|
2082
|
+
try { floatRoot()?.setAttribute(ARMED_ATTR, '') } catch { /* no window */ }
|
|
1770
2083
|
// A still hold never produced a move, so take the band from where
|
|
1771
2084
|
// the pointer is right now instead of leaving it unset.
|
|
1772
2085
|
if (hovered === null) hovered = zoneAt(down.lastX ?? down.x, band)
|
|
@@ -1813,6 +2126,7 @@ window.__ModuleLoader__.load({
|
|
|
1813
2126
|
if (pending !== null) flush()
|
|
1814
2127
|
stopJudge()
|
|
1815
2128
|
const target = judging ? hovered : null
|
|
2129
|
+
try { floatRoot()?.removeAttribute(ARMED_ATTR) } catch { /* already gone */ }
|
|
1816
2130
|
down = null
|
|
1817
2131
|
band = null
|
|
1818
2132
|
pending = null
|
|
@@ -1887,41 +2201,601 @@ window.__ModuleLoader__.load({
|
|
|
1887
2201
|
|
|
1888
2202
|
/* ----------------------------------------------------------- the drawer */
|
|
1889
2203
|
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
2204
|
+
let ctxRef = null
|
|
2205
|
+
|
|
2206
|
+
/* ------------------------------------------------------- the float window */
|
|
2207
|
+
|
|
2208
|
+
/**
|
|
2209
|
+
* A float is OUR window: one element per Conversation, parented to `#root`
|
|
2210
|
+
* rather than to a column, so it stays on screen while the window looks at
|
|
2211
|
+
* another Session or another page.
|
|
2212
|
+
*
|
|
2213
|
+
* The Conversation is rendered by DSH's own `conversation.content` factory
|
|
2214
|
+
* inside this Session's right-sidebar tab body. That body is registered
|
|
2215
|
+
* `keepMounted`, so DSH keeps it — and the Session subtree that owns it —
|
|
2216
|
+
* alive off screen (`SidebarSessionViews.prune` only retires a view without a
|
|
2217
|
+
* retained tab). The body's content node is then moved into this window.
|
|
2218
|
+
*/
|
|
2219
|
+
const WINDOW_ATTR = 'data-dsh-conversation-float-window'
|
|
2220
|
+
const WINDOW_BODY_ATTR = 'data-dsh-conversation-float-window-body'
|
|
2221
|
+
const WINDOW_GRIP_ATTR = 'data-dsh-conversation-float-window-grip'
|
|
2222
|
+
const WINDOW_RESIZE_ATTR = 'data-dsh-conversation-float-window-resize'
|
|
2223
|
+
const WINDOW_TITLE_ATTR = 'data-dsh-conversation-float-window-title'
|
|
2224
|
+
const WINDOW_HIDE_PANE_ATTR = 'data-dsh-conversation-float-hide-pane'
|
|
2225
|
+
const WINDOW_KEY = 'dsh-conversation-float.window.'
|
|
2226
|
+
/**
|
|
2227
|
+
* One per-Session content epoch.
|
|
2228
|
+
*
|
|
2229
|
+
* DSH binds a Session's draft writer into a SINGLE slot
|
|
2230
|
+
* (`inputHub.shell(id).bindDraftPersistence`), so whichever Conversation
|
|
2231
|
+
* view mounted last owns typing. The window and the middle column therefore
|
|
2232
|
+
* hand the slot back and forth by remounting, never by fighting for it.
|
|
2233
|
+
*/
|
|
2234
|
+
const contentEpochs = new Map()
|
|
2235
|
+
const epochListeners = new Set()
|
|
2236
|
+
|
|
2237
|
+
/** Keep a per-Session record from growing for Sessions nobody opened. */
|
|
2238
|
+
function capSessionMap(map, limit = 64) {
|
|
2239
|
+
while (map.size > limit) {
|
|
2240
|
+
const oldest = map.keys().next()
|
|
2241
|
+
if (oldest.done === true) return
|
|
2242
|
+
map.delete(oldest.value)
|
|
2243
|
+
}
|
|
2244
|
+
}
|
|
2245
|
+
|
|
2246
|
+
function bumpContentEpoch(sessionId) {
|
|
2247
|
+
if (sessionId === null) return
|
|
2248
|
+
contentEpochs.set(sessionId, (contentEpochs.get(sessionId) ?? 0) + 1)
|
|
2249
|
+
capSessionMap(contentEpochs)
|
|
2250
|
+
for (const listener of [...epochListeners]) {
|
|
2251
|
+
try { listener(sessionId) } catch { /* a listener may be unmounting */ }
|
|
1895
2252
|
}
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
2253
|
+
}
|
|
2254
|
+
|
|
2255
|
+
/** sessionId -> { el, body, title, header, resizer, rect } */
|
|
2256
|
+
const windows = new Map()
|
|
2257
|
+
/**
|
|
2258
|
+
* The band the float windows live in.
|
|
2259
|
+
*
|
|
2260
|
+
* The band has to sit between two things measured in DSH's own stylesheets:
|
|
2261
|
+
*
|
|
2262
|
+
* below the popovers — menus, bubbles and the usage/stat dialogs are
|
|
2263
|
+
* portaled to document.body at z-index 1100, and modals at 1000. A window
|
|
2264
|
+
* above them paints over the panel it just opened, so clicking "model",
|
|
2265
|
+
* "permission" or "usage" looks like nothing happened.
|
|
2266
|
+
*
|
|
2267
|
+
* above the frame — the shell tops out around 71 and the dock kit's own
|
|
2268
|
+
* float layer is 60.
|
|
2269
|
+
*/
|
|
2270
|
+
let windowZ = 700
|
|
2271
|
+
const WINDOW_Z_TOP = 900
|
|
2272
|
+
|
|
2273
|
+
function readWindowRect(sessionId) {
|
|
1903
2274
|
try {
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
)
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
2275
|
+
const raw = window.localStorage.getItem(WINDOW_KEY + sessionId)
|
|
2276
|
+
if (raw === null) return null
|
|
2277
|
+
const r = JSON.parse(raw)
|
|
2278
|
+
if (!r || typeof r.x !== 'number' || typeof r.y !== 'number' || typeof r.width !== 'number' || typeof r.height !== 'number') return null
|
|
2279
|
+
return r
|
|
2280
|
+
} catch {
|
|
2281
|
+
return null
|
|
1911
2282
|
}
|
|
1912
2283
|
}
|
|
1913
2284
|
|
|
1914
|
-
function
|
|
1915
|
-
if (dockRow === null) return
|
|
2285
|
+
function writeWindowRect(sessionId, rect) {
|
|
1916
2286
|
try {
|
|
1917
|
-
|
|
2287
|
+
window.localStorage.setItem(WINDOW_KEY + sessionId, JSON.stringify(rect))
|
|
1918
2288
|
} catch {
|
|
1919
|
-
/*
|
|
2289
|
+
/* a full quota must not break the float */
|
|
1920
2290
|
}
|
|
1921
|
-
dockRow = null
|
|
1922
2291
|
}
|
|
1923
2292
|
|
|
1924
|
-
|
|
2293
|
+
/**
|
|
2294
|
+
* Keep a window fully on screen.
|
|
2295
|
+
*
|
|
2296
|
+
* The composer is the last row of the Conversation, so a window whose bottom
|
|
2297
|
+
* hangs past the viewport hides exactly the control this float exists to
|
|
2298
|
+
* keep usable. A window taller than the viewport starts at the top instead.
|
|
2299
|
+
*/
|
|
2300
|
+
/**
|
|
2301
|
+
* The strip at the top of the window that belongs to DSH, not to the page.
|
|
2302
|
+
*
|
|
2303
|
+
* On Windows the caption is an overlay drawn ON the web content, so a fixed
|
|
2304
|
+
* window whose header slides under it can no longer be grabbed: the window
|
|
2305
|
+
* is stuck. Every window therefore stops at this line, and none may start
|
|
2306
|
+
* above it.
|
|
2307
|
+
*/
|
|
2308
|
+
function windowTopInset() {
|
|
2309
|
+
const root = getComputedStyle(document.documentElement)
|
|
2310
|
+
for (const name of ['--dsh-windows-titlebar-height', '--dsh-frame-top-clearance']) {
|
|
2311
|
+
const raw = root.getPropertyValue(name).trim()
|
|
2312
|
+
const px = Number.parseFloat(raw)
|
|
2313
|
+
if (Number.isFinite(px) && px > 0) return Math.round(px)
|
|
2314
|
+
}
|
|
2315
|
+
return 48
|
|
2316
|
+
}
|
|
2317
|
+
|
|
2318
|
+
function clampRect(rect) {
|
|
2319
|
+
const top = windowTopInset()
|
|
2320
|
+
const usable = Math.max(160, window.innerHeight - top)
|
|
2321
|
+
const width = Math.max(320, Math.min(rect.width, window.innerWidth))
|
|
2322
|
+
const height = Math.max(240, Math.min(rect.height, usable))
|
|
2323
|
+
const maxX = Math.max(0, window.innerWidth - width)
|
|
2324
|
+
const maxY = Math.max(top, window.innerHeight - height)
|
|
2325
|
+
const x = Math.max(0, Math.min(rect.x, maxX))
|
|
2326
|
+
const y = Math.max(top, Math.min(rect.y, maxY))
|
|
2327
|
+
return { x: Math.round(x), y: Math.round(y), width: Math.round(width), height: Math.round(height) }
|
|
2328
|
+
}
|
|
2329
|
+
|
|
2330
|
+
/** Re-fit every window after the application window itself changes size. */
|
|
2331
|
+
function reclampWindows() {
|
|
2332
|
+
for (const win of windows.values()) applyWindowRect(win, clampRect(win.rect))
|
|
2333
|
+
}
|
|
2334
|
+
|
|
2335
|
+
function defaultWindowRect() {
|
|
2336
|
+
const top = windowTopInset()
|
|
2337
|
+
const width = Math.min(920, Math.round(window.innerWidth * 0.62))
|
|
2338
|
+
const height = Math.min(720, Math.round((window.innerHeight - top) * 0.86))
|
|
2339
|
+
return clampRect({
|
|
2340
|
+
x: Math.round((window.innerWidth - width) / 2),
|
|
2341
|
+
y: Math.round(top + (window.innerHeight - top - height) / 2),
|
|
2342
|
+
width,
|
|
2343
|
+
height,
|
|
2344
|
+
})
|
|
2345
|
+
}
|
|
2346
|
+
|
|
2347
|
+
function applyWindowRect(win, rect) {
|
|
2348
|
+
win.rect = rect
|
|
2349
|
+
win.el.style.left = rect.x + 'px'
|
|
2350
|
+
win.el.style.top = rect.y + 'px'
|
|
2351
|
+
win.el.style.width = rect.width + 'px'
|
|
2352
|
+
win.el.style.height = rect.height + 'px'
|
|
2353
|
+
}
|
|
2354
|
+
|
|
2355
|
+
/**
|
|
2356
|
+
* Renumber the whole stack, keeping its order.
|
|
2357
|
+
*
|
|
2358
|
+
* The band the windows live in is bounded, so raising one past the ceiling
|
|
2359
|
+
* used to drop it straight onto the floor value: two windows could then
|
|
2360
|
+
* share a level, and "the window on top" would answer with whichever the map
|
|
2361
|
+
* happened to list last.
|
|
2362
|
+
*/
|
|
2363
|
+
function restackWindows() {
|
|
2364
|
+
const stack = [...windows.values()].sort((a, b) => {
|
|
2365
|
+
const za = Number.parseFloat(a.el.style.zIndex)
|
|
2366
|
+
const zb = Number.parseFloat(b.el.style.zIndex)
|
|
2367
|
+
return (Number.isFinite(za) ? za : 0) - (Number.isFinite(zb) ? zb : 0)
|
|
2368
|
+
})
|
|
2369
|
+
let z = 700
|
|
2370
|
+
for (const win of stack) {
|
|
2371
|
+
z += 1
|
|
2372
|
+
win.el.style.zIndex = String(z)
|
|
2373
|
+
}
|
|
2374
|
+
windowZ = z
|
|
2375
|
+
}
|
|
2376
|
+
|
|
2377
|
+
function raiseWindow(sessionId) {
|
|
2378
|
+
const win = windows.get(sessionId)
|
|
2379
|
+
if (win === undefined) return
|
|
2380
|
+
if (windowZ >= WINDOW_Z_TOP) restackWindows()
|
|
2381
|
+
windowZ = Math.min(windowZ + 1, WINDOW_Z_TOP)
|
|
2382
|
+
win.el.style.zIndex = String(windowZ)
|
|
2383
|
+
refreshSwitchChips()
|
|
2384
|
+
}
|
|
2385
|
+
|
|
2386
|
+
/**
|
|
2387
|
+
* Offer the switch chip on the window at the top of the stack.
|
|
2388
|
+
*
|
|
2389
|
+
* A float of a Conversation that is not the one on screen is a transcript
|
|
2390
|
+
* and nothing else: it owns neither the header nor the composer, so the way
|
|
2391
|
+
* into it is to make it the current Conversation. That offer belongs to the
|
|
2392
|
+
* window the user just raised — by a press on its taskbar row or by dragging
|
|
2393
|
+
* it up — so it appears on one window, never on the one being read.
|
|
2394
|
+
*/
|
|
2395
|
+
function refreshSwitchChips() {
|
|
2396
|
+
const live = liveSession()
|
|
2397
|
+
const top = topWindow()
|
|
2398
|
+
const label = t('switchTo')
|
|
2399
|
+
for (const [id, win] of windows) {
|
|
2400
|
+
const chip = win.switchChip
|
|
2401
|
+
if (chip === undefined) continue
|
|
2402
|
+
const show = id === top && id !== live
|
|
2403
|
+
if (chip.hidden !== !show) chip.hidden = !show
|
|
2404
|
+
if (chip.textContent !== label) chip.textContent = label
|
|
2405
|
+
if (chip.title !== label) chip.title = label
|
|
2406
|
+
}
|
|
2407
|
+
}
|
|
2408
|
+
|
|
2409
|
+
/** The id of the window at the top of the stack that is on screen, if any. */
|
|
2410
|
+
function topWindow() {
|
|
2411
|
+
let top = null
|
|
2412
|
+
let topZ = -Infinity
|
|
2413
|
+
for (const [id, win] of windows) {
|
|
2414
|
+
if (win.el.hidden) continue
|
|
2415
|
+
const z = Number.parseFloat(win.el.style.zIndex)
|
|
2416
|
+
if (!Number.isFinite(z)) continue
|
|
2417
|
+
if (z >= topZ) {
|
|
2418
|
+
topZ = z
|
|
2419
|
+
top = id
|
|
2420
|
+
}
|
|
2421
|
+
}
|
|
2422
|
+
return top
|
|
2423
|
+
}
|
|
2424
|
+
|
|
2425
|
+
function windowButton(label, glyph, onClick) {
|
|
2426
|
+
const button = document.createElement('button')
|
|
2427
|
+
button.type = 'button'
|
|
2428
|
+
button.setAttribute('aria-label', label)
|
|
2429
|
+
button.title = label
|
|
2430
|
+
button.textContent = glyph
|
|
2431
|
+
// 30px is the largest that fits the 34px header, and still far short of
|
|
2432
|
+
// the 44px a fingertip wants: the header would have to grow for that.
|
|
2433
|
+
button.style.cssText = 'width:30px;height:30px;flex:none;display:inline-flex;align-items:center;justify-content:center;border:0;border-radius:6px;background:transparent;color:var(--dsw-alias-label-secondary);font:14px/1 system-ui;cursor:pointer'
|
|
2434
|
+
button.addEventListener('pointerdown', (event) => {
|
|
2435
|
+
event.stopPropagation()
|
|
2436
|
+
})
|
|
2437
|
+
button.addEventListener('click', (event) => {
|
|
2438
|
+
event.stopPropagation()
|
|
2439
|
+
onClick()
|
|
2440
|
+
})
|
|
2441
|
+
return button
|
|
2442
|
+
}
|
|
2443
|
+
|
|
2444
|
+
/**
|
|
2445
|
+
* The header chip that makes this window's Conversation the current one.
|
|
2446
|
+
*
|
|
2447
|
+
* It stays hidden until the window is the one on top: every window would
|
|
2448
|
+
* otherwise carry the same offer, and the press would mean "bring this one
|
|
2449
|
+
* forward" on a window the user is not even looking at.
|
|
2450
|
+
*/
|
|
2451
|
+
function switchChip(onClick) {
|
|
2452
|
+
const button = document.createElement('button')
|
|
2453
|
+
button.type = 'button'
|
|
2454
|
+
button.setAttribute('data-dsh-conversation-float-switch', '')
|
|
2455
|
+
button.textContent = t('switchTo')
|
|
2456
|
+
button.title = t('switchTo')
|
|
2457
|
+
button.hidden = true
|
|
2458
|
+
button.style.cssText = 'flex:none;height:22px;padding:0 8px;border:0;border-radius:6px;background:var(--dsw-alias-interactive-bg-hover, rgba(0,0,0,.08));color:var(--dsw-alias-label-primary, #111);font:11px/1 ui-sans-serif,system-ui;white-space:nowrap;cursor:pointer'
|
|
2459
|
+
button.addEventListener('pointerdown', (event) => event.stopPropagation())
|
|
2460
|
+
button.addEventListener('click', (event) => {
|
|
2461
|
+
event.stopPropagation()
|
|
2462
|
+
onClick()
|
|
2463
|
+
})
|
|
2464
|
+
return button
|
|
2465
|
+
}
|
|
2466
|
+
|
|
2467
|
+
/**
|
|
2468
|
+
* The Conversation's own page tabs — the ones the header draws.
|
|
2469
|
+
*
|
|
2470
|
+
* They live in the main column's header, which belongs to the Session on
|
|
2471
|
+
* screen. A press on one runs DSH's selectView, so the view ledger, the store
|
|
2472
|
+
* and both columns move together; nothing here re-implements that.
|
|
2473
|
+
*/
|
|
2474
|
+
function nativeViewTabs() {
|
|
2475
|
+
return [...document.querySelectorAll('[role="tab"]')].filter((tab) => (
|
|
2476
|
+
tab.closest('[data-dockkit-tab]') === null &&
|
|
2477
|
+
tab.closest(`[${WINDOW_ATTR}]`) === null
|
|
2478
|
+
))
|
|
2479
|
+
}
|
|
2480
|
+
|
|
2481
|
+
function ensureWindow(sessionId) {
|
|
2482
|
+
const existing = windows.get(sessionId)
|
|
2483
|
+
if (existing !== undefined) return existing
|
|
2484
|
+
const root = document.getElementById('root')
|
|
2485
|
+
if (root === null) return null
|
|
2486
|
+
const el = document.createElement('div')
|
|
2487
|
+
el.setAttribute(WINDOW_ATTR, sessionId)
|
|
2488
|
+
el.setAttribute('role', 'dialog')
|
|
2489
|
+
// Named by its own title, and focusable as a whole: a dialog announced
|
|
2490
|
+
// without a name is just "dialog" to a screen reader.
|
|
2491
|
+
const titleId = 'dsh-float-title-' + sessionId
|
|
2492
|
+
el.setAttribute('aria-labelledby', titleId)
|
|
2493
|
+
el.tabIndex = -1
|
|
2494
|
+
const header = document.createElement('div')
|
|
2495
|
+
header.setAttribute(WINDOW_GRIP_ATTR, '')
|
|
2496
|
+
header.tabIndex = -1
|
|
2497
|
+
const title = document.createElement('span')
|
|
2498
|
+
title.setAttribute(WINDOW_TITLE_ATTR, '')
|
|
2499
|
+
title.id = titleId
|
|
2500
|
+
title.style.cssText = 'flex:1 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font:600 12px/1.2 ui-sans-serif,system-ui'
|
|
2501
|
+
title.textContent = sessionTitle(sessionId) ?? t('floatTitle')
|
|
2502
|
+
const body = document.createElement('div')
|
|
2503
|
+
body.setAttribute(WINDOW_BODY_ATTR, '')
|
|
2504
|
+
const resizer = document.createElement('div')
|
|
2505
|
+
resizer.setAttribute(WINDOW_RESIZE_ATTR, '')
|
|
2506
|
+
header.appendChild(title)
|
|
2507
|
+
// The title bar carries no page chips: the Conversation's own header,
|
|
2508
|
+
// which travels with the column, is the only copy of that switch.
|
|
2509
|
+
const chip = switchChip(() => switchToWindow(sessionId))
|
|
2510
|
+
header.appendChild(chip)
|
|
2511
|
+
header.appendChild(windowButton(t('minimize'), '—', () => hideWindow(sessionId)))
|
|
2512
|
+
header.appendChild(windowButton(t('close'), '✕', () => closeWindow(sessionId)))
|
|
2513
|
+
el.appendChild(header)
|
|
2514
|
+
el.appendChild(body)
|
|
2515
|
+
el.appendChild(resizer)
|
|
2516
|
+
el.hidden = true
|
|
2517
|
+
root.appendChild(el)
|
|
2518
|
+
const win = {
|
|
2519
|
+
el, body, title, header, resizer, switchChip: chip,
|
|
2520
|
+
rect: readWindowRect(sessionId) ?? defaultWindowRect(),
|
|
2521
|
+
}
|
|
2522
|
+
windows.set(sessionId, win)
|
|
2523
|
+
applyWindowRect(win, clampRect(win.rect))
|
|
2524
|
+
bindWindowDrag(sessionId, win)
|
|
2525
|
+
// The float carries the three drop bands: hold it still, then drag to the
|
|
2526
|
+
// left sidebar (stow), the middle (return) or the right sidebar (dock).
|
|
2527
|
+
win.stopBandDrag = trackPanelDrag(el, sessionId)
|
|
2528
|
+
refreshSwitchChips()
|
|
2529
|
+
// Slot registration must not run inside the commit that mounted the tab
|
|
2530
|
+
// body: a microtask leaves that commit behind without waiting a whole
|
|
2531
|
+
// macrotask for it.
|
|
2532
|
+
queueMicrotask(syncTaskbar)
|
|
2533
|
+
return win
|
|
2534
|
+
}
|
|
2535
|
+
|
|
2536
|
+
function bindWindowDrag(sessionId, win) {
|
|
2537
|
+
let grab = null
|
|
2538
|
+
win.el.addEventListener('pointerdown', () => raiseWindow(sessionId), true)
|
|
2539
|
+
win.header.addEventListener('pointerdown', (event) => {
|
|
2540
|
+
if (event.button !== 0) return
|
|
2541
|
+
grab = { x: event.clientX, y: event.clientY, rect: win.rect }
|
|
2542
|
+
try { win.header.setPointerCapture(event.pointerId) } catch { /* older engines */ }
|
|
2543
|
+
event.preventDefault()
|
|
2544
|
+
})
|
|
2545
|
+
win.header.addEventListener('pointermove', (event) => {
|
|
2546
|
+
if (grab === null) return
|
|
2547
|
+
applyWindowRect(win, clampRect({
|
|
2548
|
+
x: grab.rect.x + (event.clientX - grab.x),
|
|
2549
|
+
y: grab.rect.y + (event.clientY - grab.y),
|
|
2550
|
+
width: grab.rect.width,
|
|
2551
|
+
height: grab.rect.height,
|
|
2552
|
+
}))
|
|
2553
|
+
})
|
|
2554
|
+
const drop = () => {
|
|
2555
|
+
if (grab === null) return
|
|
2556
|
+
grab = null
|
|
2557
|
+
writeWindowRect(sessionId, win.rect)
|
|
2558
|
+
}
|
|
2559
|
+
win.header.addEventListener('pointerup', drop)
|
|
2560
|
+
win.header.addEventListener('pointercancel', drop)
|
|
2561
|
+
|
|
2562
|
+
let sizing = null
|
|
2563
|
+
win.resizer.addEventListener('pointerdown', (event) => {
|
|
2564
|
+
if (event.button !== 0) return
|
|
2565
|
+
sizing = { x: event.clientX, y: event.clientY, rect: win.rect }
|
|
2566
|
+
try { win.resizer.setPointerCapture(event.pointerId) } catch { /* older engines */ }
|
|
2567
|
+
event.preventDefault()
|
|
2568
|
+
event.stopPropagation()
|
|
2569
|
+
})
|
|
2570
|
+
win.resizer.addEventListener('pointermove', (event) => {
|
|
2571
|
+
if (sizing === null) return
|
|
2572
|
+
applyWindowRect(win, clampRect({
|
|
2573
|
+
x: sizing.rect.x,
|
|
2574
|
+
y: sizing.rect.y,
|
|
2575
|
+
width: sizing.rect.width + (event.clientX - sizing.x),
|
|
2576
|
+
height: sizing.rect.height + (event.clientY - sizing.y),
|
|
2577
|
+
}))
|
|
2578
|
+
})
|
|
2579
|
+
const settled = () => {
|
|
2580
|
+
if (sizing === null) return
|
|
2581
|
+
sizing = null
|
|
2582
|
+
writeWindowRect(sessionId, win.rect)
|
|
2583
|
+
}
|
|
2584
|
+
win.resizer.addEventListener('pointerup', settled)
|
|
2585
|
+
win.resizer.addEventListener('pointercancel', settled)
|
|
2586
|
+
}
|
|
2587
|
+
|
|
2588
|
+
/**
|
|
2589
|
+
* Make another Conversation the one on screen.
|
|
2590
|
+
*
|
|
2591
|
+
* DSH's own navigation entry does the switch, so the view ledger, the store
|
|
2592
|
+
* and both columns move together — the same call the sidebar's session rows
|
|
2593
|
+
* make. The window then re-decides its own mode on the next layout pass, and
|
|
2594
|
+
* the real column, header and composer follow it in.
|
|
2595
|
+
*/
|
|
2596
|
+
function switchToWindow(sessionId) {
|
|
2597
|
+
let switched = false
|
|
2598
|
+
try {
|
|
2599
|
+
const workspace = typeof ctxRef?.get === 'function' ? ctxRef.get('uiWorkspace') : null
|
|
2600
|
+
if (workspace !== null && workspace !== undefined && typeof workspace.openSession === 'function') {
|
|
2601
|
+
workspace.openSession(sessionId)
|
|
2602
|
+
switched = true
|
|
2603
|
+
}
|
|
2604
|
+
} catch (error) {
|
|
2605
|
+
report('[conversation-float] could not switch the conversation:', error)
|
|
2606
|
+
}
|
|
2607
|
+
if (!switched) {
|
|
2608
|
+
report('[conversation-float] no uiWorkspace service to switch the Session')
|
|
2609
|
+
return
|
|
2610
|
+
}
|
|
2611
|
+
raiseWindow(sessionId)
|
|
2612
|
+
// Bodies re-decide on a slow safety net; a switch must not wait for it.
|
|
2613
|
+
// The column is what changes when the switch lands, so the wait ends on
|
|
2614
|
+
// that change: a pass is taken whenever the column shows a Session it did
|
|
2615
|
+
// not show last, and the wait finishes once it shows ours. Three guessed
|
|
2616
|
+
// delays could all fire before the column moved, or long after.
|
|
2617
|
+
notifyLayout()
|
|
2618
|
+
refreshSwitchChips()
|
|
2619
|
+
let lastSeen = '__start__'
|
|
2620
|
+
untilFrame(() => {
|
|
2621
|
+
const column = findColumn()
|
|
2622
|
+
const shown = column === null ? null : columnSession(column)
|
|
2623
|
+
if (shown !== lastSeen) {
|
|
2624
|
+
lastSeen = shown
|
|
2625
|
+
notifyLayout()
|
|
2626
|
+
refreshSwitchChips()
|
|
2627
|
+
}
|
|
2628
|
+
return shown === sessionId
|
|
2629
|
+
}, null, 2500)
|
|
2630
|
+
}
|
|
2631
|
+
|
|
2632
|
+
function showWindow(sessionId) {
|
|
2633
|
+
const win = ensureWindow(sessionId)
|
|
2634
|
+
if (win === null) return null
|
|
2635
|
+
win.el.hidden = false
|
|
2636
|
+
raiseWindow(sessionId)
|
|
2637
|
+
// Move focus into the window that was just opened, unless the user is
|
|
2638
|
+
// already working inside it: a window that opens without focus leaves a
|
|
2639
|
+
// keyboard user tabbing into a hidden subtree behind it.
|
|
2640
|
+
try {
|
|
2641
|
+
const active = document.activeElement
|
|
2642
|
+
if (active === null || !win.el.contains(active)) win.el.focus({ preventScroll: true })
|
|
2643
|
+
} catch { /* older engines */ }
|
|
2644
|
+
// Typing belongs to the view that just took the screen.
|
|
2645
|
+
bumpContentEpoch(sessionId)
|
|
2646
|
+
return win
|
|
2647
|
+
}
|
|
2648
|
+
|
|
2649
|
+
function hideWindow(sessionId) {
|
|
2650
|
+
const win = windows.get(sessionId)
|
|
2651
|
+
if (win === undefined) return
|
|
2652
|
+
win.el.hidden = true
|
|
2653
|
+
// The window keeps its body mounted while minimised, so the middle
|
|
2654
|
+
// column has to take the draft slot back for its own composer — once the
|
|
2655
|
+
// column is actually back home, not 60ms later.
|
|
2656
|
+
if (liveSession() === sessionId) {
|
|
2657
|
+
untilFrame(() => {
|
|
2658
|
+
const column = findColumn()
|
|
2659
|
+
return column !== null && column.isConnected && column.closest(`[${WINDOW_ATTR}]`) === null
|
|
2660
|
+
}, healComposerSoon, 1200)
|
|
2661
|
+
}
|
|
2662
|
+
refreshSwitchChips()
|
|
2663
|
+
}
|
|
2664
|
+
|
|
2665
|
+
function destroyWindow(sessionId) {
|
|
2666
|
+
const win = windows.get(sessionId)
|
|
2667
|
+
if (win === undefined) return
|
|
2668
|
+
windows.delete(sessionId)
|
|
2669
|
+
// The live column comes home before its host leaves: a node removed with
|
|
2670
|
+
// the window would be a Conversation nobody can find again.
|
|
2671
|
+
if (movedColumn !== null && win.el.contains(movedColumn)) detachColumn()
|
|
2672
|
+
if (typeof win.stopBandDrag === 'function') {
|
|
2673
|
+
try { win.stopBandDrag() } catch { /* listeners already gone */ }
|
|
2674
|
+
win.stopBandDrag = null
|
|
2675
|
+
}
|
|
2676
|
+
win.el.remove()
|
|
2677
|
+
queueMicrotask(syncTaskbar)
|
|
2678
|
+
refreshSwitchChips()
|
|
2679
|
+
}
|
|
2680
|
+
|
|
2681
|
+
/**
|
|
2682
|
+
* The id of OUR tab in one Session, asked of the Session's own tab list.
|
|
2683
|
+
*
|
|
2684
|
+
* Reading it from the markup was how the previous build got it, and that
|
|
2685
|
+
* routine could not tell one Session's tab from another's once the body had
|
|
2686
|
+
* been lifted out of the strip: closing a float then closed the wrong tab.
|
|
2687
|
+
*/
|
|
2688
|
+
function tabIdFor(sessionId) {
|
|
2689
|
+
if (sessionId === null) return null
|
|
2690
|
+
try {
|
|
2691
|
+
const tabs = sidebarRight?.tabsIn?.(sessionId) ?? []
|
|
2692
|
+
const mine = tabs.find((tab) => tab && tab.kind === CHAT_KIND)
|
|
2693
|
+
return typeof mine?.id === 'string' ? mine.id : null
|
|
2694
|
+
} catch (error) {
|
|
2695
|
+
report('[conversation-float] could not read this Session tab list:', error)
|
|
2696
|
+
return null
|
|
2697
|
+
}
|
|
2698
|
+
}
|
|
2699
|
+
|
|
2700
|
+
/**
|
|
2701
|
+
* Close a Conversation's float for good.
|
|
2702
|
+
*
|
|
2703
|
+
* The TAB goes first. 'hide' only collapses a docked column, which left the
|
|
2704
|
+
* body mounted with an empty host — the next float opened into that body was
|
|
2705
|
+
* blank. Closing the tab unmounts the body, and the body's own cleanup takes
|
|
2706
|
+
* the window down with it.
|
|
2707
|
+
*/
|
|
2708
|
+
function closeWindow(sessionId) {
|
|
2709
|
+
const id = tabIdFor(sessionId)
|
|
2710
|
+
if (id !== null) {
|
|
2711
|
+
try {
|
|
2712
|
+
if (typeof sidebarRight?.closeIn === 'function') sidebarRight.closeIn(sessionId, id)
|
|
2713
|
+
else sidebarRight?.hide?.(id)
|
|
2714
|
+
} catch (error) {
|
|
2715
|
+
report('[conversation-float] could not close the tab:', error)
|
|
2716
|
+
}
|
|
2717
|
+
}
|
|
2718
|
+
// A docked tab DSH refuses to close leaves the body alive: the window must
|
|
2719
|
+
// not outlive it as an orphan pointing at nothing.
|
|
2720
|
+
untilFrame(
|
|
2721
|
+
() => !windows.has(sessionId),
|
|
2722
|
+
() => { if (liveSession() === sessionId) healComposerSoon() },
|
|
2723
|
+
600,
|
|
2724
|
+
() => {
|
|
2725
|
+
if (windows.has(sessionId)) destroyWindow(sessionId)
|
|
2726
|
+
if (liveSession() === sessionId) healComposerSoon()
|
|
2727
|
+
},
|
|
2728
|
+
)
|
|
2729
|
+
}
|
|
2730
|
+
|
|
2731
|
+
/* ------------------------------------------------------- the taskbar */
|
|
2732
|
+
|
|
2733
|
+
/** sessionId -> disposers for its sidebar row and the panel entry behind it. */
|
|
2734
|
+
const taskRows = new Map()
|
|
2735
|
+
|
|
2736
|
+
/**
|
|
2737
|
+
* The left sidebar is the taskbar: one row per open window, named after its
|
|
2738
|
+
* Conversation. The row is a panel row, so it needs a main-panel entry to
|
|
2739
|
+
* select; that entry shows the window and hands the centre back.
|
|
2740
|
+
*/
|
|
2741
|
+
function syncTaskbar() {
|
|
2742
|
+
if (ctxRef === null) return
|
|
2743
|
+
for (const [sessionId] of windows) {
|
|
2744
|
+
if (taskRows.has(sessionId)) continue
|
|
2745
|
+
const rowId = 'conversation-window:' + sessionId
|
|
2746
|
+
const label = sessionTitle(sessionId) ?? t('floatTitle')
|
|
2747
|
+
try {
|
|
2748
|
+
const disposePanel = ctxRef.slots.register({ name: 'main', key: rowId, locale: NS }, makeWindowPanel(sessionId))
|
|
2749
|
+
const disposeRow = ctxRef.slots.register(
|
|
2750
|
+
{ name: 'sidebar.panellist', id: rowId, order: 20, label: () => label },
|
|
2751
|
+
makeDockIcon(sessionId),
|
|
2752
|
+
)
|
|
2753
|
+
taskRows.set(sessionId, [disposePanel, disposeRow])
|
|
2754
|
+
} catch (error) {
|
|
2755
|
+
report('[conversation-float] could not register the taskbar row:', error)
|
|
2756
|
+
}
|
|
2757
|
+
}
|
|
2758
|
+
for (const [sessionId, disposers] of [...taskRows]) {
|
|
2759
|
+
if (windows.has(sessionId)) continue
|
|
2760
|
+
taskRows.delete(sessionId)
|
|
2761
|
+
for (const off of disposers) {
|
|
2762
|
+
try { off() } catch { /* the slot may be gone */ }
|
|
2763
|
+
}
|
|
2764
|
+
}
|
|
2765
|
+
}
|
|
2766
|
+
|
|
2767
|
+
/**
|
|
2768
|
+
* A taskbar row is DSH's own main-panel button: selecting it replaces the
|
|
2769
|
+
* central entry, which would take a plugin or automation page away. When a
|
|
2770
|
+
* page owns the main slot the row means only "bring that window forward";
|
|
2771
|
+
* the page must stay where it is.
|
|
2772
|
+
*/
|
|
2773
|
+
function taskbarRowPress(event) {
|
|
2774
|
+
const target = event.target
|
|
2775
|
+
if (!(target instanceof Element)) return
|
|
2776
|
+
const row = target.closest(`button[${ROW_MARK_ATTR}]`)
|
|
2777
|
+
if (row === null) return
|
|
2778
|
+
const sessionId = row.getAttribute(ROW_MARK_ATTR)
|
|
2779
|
+
if (sessionId === null || sessionId === '') return
|
|
2780
|
+
event.preventDefault()
|
|
2781
|
+
event.stopPropagation()
|
|
2782
|
+
showWindow(sessionId)
|
|
2783
|
+
}
|
|
2784
|
+
|
|
2785
|
+
/** Selecting a taskbar row shows that window and returns the centre. */
|
|
2786
|
+
function makeWindowPanel(sessionId) {
|
|
2787
|
+
return function WindowPanel() {
|
|
2788
|
+
React.useEffect(() => {
|
|
2789
|
+
showWindow(sessionId)
|
|
2790
|
+
try {
|
|
2791
|
+
layout?.selectPanel?.(null)
|
|
2792
|
+
} catch (error) {
|
|
2793
|
+
report('[conversation-float] could not restore the conversation panel:', error)
|
|
2794
|
+
}
|
|
2795
|
+
}, [])
|
|
2796
|
+
return null
|
|
2797
|
+
}
|
|
2798
|
+
}
|
|
1925
2799
|
|
|
1926
2800
|
/* ---------------------------------------------------------- components */
|
|
1927
2801
|
|
|
@@ -1969,8 +2843,12 @@ window.__ModuleLoader__.load({
|
|
|
1969
2843
|
width: 100%; height: 100%; min-height: 0; overflow: hidden;
|
|
1970
2844
|
background: var(--dsw-alias-bg-base);
|
|
1971
2845
|
}
|
|
2846
|
+
/* Fallback only: showPreview() raises this above the windows' own band. */
|
|
1972
2847
|
.dsw-preview {
|
|
1973
|
-
|
|
2848
|
+
/* Same band as the windows (700..950). It used to claim 20050 while the code
|
|
2849
|
+
raised it to min(windowZ + 10, 950), so the two disagreed and the value
|
|
2850
|
+
that won depended on whether the inline style had been written yet. */
|
|
2851
|
+
position: fixed; left: 0; top: 0; z-index: 940; pointer-events: none;
|
|
1974
2852
|
will-change: transform, width, height;
|
|
1975
2853
|
border: 2px dashed var(--dsw-alias-brand-primary, #4d6bfe);
|
|
1976
2854
|
border-radius: 12px;
|
|
@@ -1979,18 +2857,61 @@ window.__ModuleLoader__.load({
|
|
|
1979
2857
|
display: flex; align-items: center; justify-content: center;
|
|
1980
2858
|
transition: transform .09s ease, width .09s ease, height .09s ease;
|
|
1981
2859
|
}
|
|
1982
|
-
/* The float, stowed in the left drawer: mounted, so the centre stays empty. */
|
|
1983
|
-
[data-dsh-conversation-float-stowed] {
|
|
1984
|
-
opacity: 0 !important;
|
|
1985
|
-
visibility: hidden !important;
|
|
1986
|
-
pointer-events: none !important;
|
|
1987
|
-
}
|
|
1988
2860
|
/* Touch: the grip owns the gesture, so a press is not turned into a scroll. */
|
|
1989
2861
|
[data-dsh-conversation-float-float] [data-dockkit-float-grip] {
|
|
1990
2862
|
touch-action: none;
|
|
1991
2863
|
-webkit-user-select: none; user-select: none;
|
|
1992
2864
|
-webkit-touch-callout: none;
|
|
1993
2865
|
}
|
|
2866
|
+
|
|
2867
|
+
/* The float window: a layer of our own, drawn above the frame's columns. */
|
|
2868
|
+
[data-dsh-conversation-float-window] {
|
|
2869
|
+
position: fixed; z-index: 700;
|
|
2870
|
+
display: flex; flex-direction: column;
|
|
2871
|
+
min-width: 320px; min-height: 240px;
|
|
2872
|
+
background: var(--dsw-alias-bg-base, #fff);
|
|
2873
|
+
border: 1px solid var(--dsw-alias-border-l3, rgba(0, 0, 0, .14));
|
|
2874
|
+
border-radius: 12px;
|
|
2875
|
+
box-shadow: 0 18px 48px rgba(15, 23, 42, .28);
|
|
2876
|
+
overflow: hidden;
|
|
2877
|
+
}
|
|
2878
|
+
[data-dsh-conversation-float-window][hidden] { display: none; }
|
|
2879
|
+
/* The hold that arms the bands, shown on the grip. */
|
|
2880
|
+
[data-dsh-conversation-float-armed] [data-dsh-conversation-float-window-grip] {
|
|
2881
|
+
background: color-mix(in srgb, var(--dsw-alias-brand-primary, #4d6bfe) 16%, var(--dsw-alias-bg-layer-2, #f5f6f8));
|
|
2882
|
+
}
|
|
2883
|
+
[data-dsh-conversation-float-switch][hidden] { display: none; }
|
|
2884
|
+
[data-dsh-conversation-float-window-grip] {
|
|
2885
|
+
flex: none; display: flex; align-items: center; gap: 4px;
|
|
2886
|
+
height: 34px; padding: 0 6px 0 12px;
|
|
2887
|
+
background: var(--dsw-alias-bg-layer-2, #f5f6f8);
|
|
2888
|
+
border-bottom: 1px solid var(--dsw-alias-border-l4, rgba(0, 0, 0, .08));
|
|
2889
|
+
cursor: grab; user-select: none; touch-action: none;
|
|
2890
|
+
color: var(--dsw-alias-label-primary, #111);
|
|
2891
|
+
}
|
|
2892
|
+
[data-dsh-conversation-float-window-grip]:active { cursor: grabbing; }
|
|
2893
|
+
[data-dsh-conversation-float-window-body] {
|
|
2894
|
+
flex: 1 1 auto; min-height: 0; min-width: 0; display: flex; flex-direction: column;
|
|
2895
|
+
background: var(--dsw-alias-bg-base, #fff); overflow: hidden;
|
|
2896
|
+
}
|
|
2897
|
+
[data-dsh-conversation-float-window-body] > * { flex: 1 1 auto; min-height: 0; min-width: 0; }
|
|
2898
|
+
/* A body that renders its own Conversation is a transcript and nothing else.
|
|
2899
|
+
Exactly one composer exists on screen — the one that travels with the live
|
|
2900
|
+
column, the same way the Conversation header does — so the copies DSH builds
|
|
2901
|
+
for these bodies are taken out. They used to be live input boxes whose draft
|
|
2902
|
+
writer was a second claimant on the Session's single slot. */
|
|
2903
|
+
[data-dsh-conversation-float-factory] [data-composer-seat] { display: none !important; }
|
|
2904
|
+
[data-dsh-conversation-float-factory-live] [data-composer-seat] { display: flex !important; }
|
|
2905
|
+
[data-dsh-conversation-float-factory-live] [data-dsh-conversation-float-anchor] { display: none !important; }
|
|
2906
|
+
[data-dsh-conversation-float-window-resize] {
|
|
2907
|
+
position: absolute; right: 0; bottom: 0; width: 22px; height: 22px;
|
|
2908
|
+
cursor: nwse-resize; touch-action: none;
|
|
2909
|
+
background: linear-gradient(135deg, transparent 50%, var(--dsw-alias-border-l3, rgba(0, 0, 0, .22)) 50%);
|
|
2910
|
+
}
|
|
2911
|
+
[data-dsh-conversation-float-hide-pane] {
|
|
2912
|
+
visibility: hidden !important;
|
|
2913
|
+
pointer-events: none !important;
|
|
2914
|
+
}
|
|
1994
2915
|
/* Everything the float hides while it is the only thing on screen. */
|
|
1995
2916
|
[data-dsh-conversation-float-chromeless] {
|
|
1996
2917
|
display: none !important;
|
|
@@ -2013,106 +2934,35 @@ window.__ModuleLoader__.load({
|
|
|
2013
2934
|
* rest of DSH back — or hides it again.
|
|
2014
2935
|
*/
|
|
2015
2936
|
function onEntryClick() {
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
const
|
|
2019
|
-
if (
|
|
2020
|
-
openFloating()
|
|
2021
|
-
return
|
|
2022
|
-
}
|
|
2023
|
-
if (chromeless) revealChrome()
|
|
2024
|
-
else setChromeless(true)
|
|
2025
|
-
}
|
|
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) {
|
|
2937
|
+
const sessionId = liveSession()
|
|
2938
|
+
if (sessionId === null) return
|
|
2939
|
+
const win = windows.get(sessionId)
|
|
2940
|
+
if (win === undefined) {
|
|
2060
2941
|
openFloating()
|
|
2061
2942
|
return
|
|
2062
2943
|
}
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
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')
|
|
2944
|
+
// A window put away with its own dash comes back first: hiding the rest
|
|
2945
|
+
// of DSH around a hidden window would leave an empty screen.
|
|
2946
|
+
if (win.el.hidden) {
|
|
2947
|
+
showWindow(sessionId)
|
|
2948
|
+
notifyState()
|
|
2084
2949
|
return
|
|
2085
2950
|
}
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
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
|
-
}
|
|
2951
|
+
// The original design: this press does not collapse the float, it takes
|
|
2952
|
+
// the rest of DSH off the screen and leaves the float alone; the next
|
|
2953
|
+
// press brings the interface back.
|
|
2954
|
+
setChromeless(!chromeless)
|
|
2102
2955
|
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
2956
|
}
|
|
2114
2957
|
|
|
2115
|
-
/**
|
|
2958
|
+
/**
|
|
2959
|
+
* Escape: bring DSH back when the columns are hidden, close the window when
|
|
2960
|
+
* the hand is inside one.
|
|
2961
|
+
*
|
|
2962
|
+
* Only acts on our own surfaces. Escape is a shared key in DSH (menus,
|
|
2963
|
+
* dialogs, a running answer), and a capture-phase listener that took it
|
|
2964
|
+
* globally would be stealing it from the app.
|
|
2965
|
+
*/
|
|
2116
2966
|
function escapeOnKey(event) {
|
|
2117
2967
|
if (event.key !== 'Escape' || !chromeless) return
|
|
2118
2968
|
revealChrome()
|
|
@@ -2141,45 +2991,272 @@ window.__ModuleLoader__.load({
|
|
|
2141
2991
|
)
|
|
2142
2992
|
}
|
|
2143
2993
|
|
|
2144
|
-
/**
|
|
2145
|
-
|
|
2146
|
-
|
|
2994
|
+
/**
|
|
2995
|
+
* The left sidebar row's glyph. The row itself is owned by the sidebar; we
|
|
2996
|
+
* mark its button so a capture listener can tell our taskbar from a shipped
|
|
2997
|
+
* row, and know which Session's window the row means.
|
|
2998
|
+
*/
|
|
2999
|
+
function makeDockIcon(sessionId) {
|
|
3000
|
+
return function DockIcon({ size = 16 }) {
|
|
3001
|
+
const ref = React.useRef(null)
|
|
3002
|
+
React.useLayoutEffect(() => {
|
|
3003
|
+
const icon = ref.current
|
|
3004
|
+
const row = icon === null ? null : icon.closest('button')
|
|
3005
|
+
if (row !== null) row.setAttribute(ROW_MARK_ATTR, sessionId)
|
|
3006
|
+
})
|
|
3007
|
+
return h('span', { ref, style: { display: 'contents' } }, h(Icon, { name: 'window', size }))
|
|
3008
|
+
}
|
|
2147
3009
|
}
|
|
2148
3010
|
|
|
2149
3011
|
/**
|
|
2150
|
-
* The
|
|
2151
|
-
*
|
|
2152
|
-
*
|
|
3012
|
+
* The floating tab's body.
|
|
3013
|
+
*
|
|
3014
|
+
* ONE Conversation has ONE view. Its draft writer is a single slot
|
|
3015
|
+
* (`bindDraftPersistence`): the view that mounts last takes the slot, and
|
|
3016
|
+
* when that view unmounts it clears the slot while the first view — still on
|
|
3017
|
+
* screen — can never bind again. The composer then accepts text that never
|
|
3018
|
+
* reaches the store, which is the reported "typing does nothing" bug.
|
|
3019
|
+
*
|
|
3020
|
+
* So this body renders a Conversation of its own only while the live one
|
|
3021
|
+
* belongs to another Session. For its own Session it hosts the LIVE middle
|
|
3022
|
+
* column — the same node the middle column shows — so the composer keeps the
|
|
3023
|
+
* writer it always had.
|
|
2153
3024
|
*/
|
|
2154
|
-
function
|
|
2155
|
-
React.
|
|
2156
|
-
|
|
3025
|
+
function SessionPanel(props) {
|
|
3026
|
+
const host = React.useRef(null)
|
|
3027
|
+
const sessionRef = React.useRef(null)
|
|
3028
|
+
/** Where the live column goes while this body hosts it. */
|
|
3029
|
+
const hostEl = React.useRef(null)
|
|
3030
|
+
/** The dock-kit float pane this body was last seen in. */
|
|
3031
|
+
const paneRef = React.useRef(null)
|
|
3032
|
+
const [portalTarget, setPortalTarget] = React.useState(null)
|
|
3033
|
+
const [epoch, setEpoch] = React.useState(0)
|
|
3034
|
+
/**
|
|
3035
|
+
* 'column' the live middle column lives in this body
|
|
3036
|
+
* 'factory-live' the live Conversation is on a page: a full copy stays
|
|
3037
|
+
* here, with header, View tabs and composer
|
|
3038
|
+
* 'factory' a Conversation of a Session that is not live: record only
|
|
3039
|
+
* null the first layout pass has not decided yet — render
|
|
3040
|
+
* NOTHING, because a factory view that mounts and unmounts
|
|
3041
|
+
* for nothing would clear the draft slot on its way out.
|
|
3042
|
+
*/
|
|
3043
|
+
const [mode, setMode] = React.useState(null)
|
|
3044
|
+
/** True while this body sits in a dock-kit float pane and has our window. */
|
|
3045
|
+
const [floating, setFloating] = React.useState(false)
|
|
3046
|
+
const content = React.useMemo(() => {
|
|
3047
|
+
if (typeof props.renderFactorySlot !== 'function') return null
|
|
2157
3048
|
try {
|
|
2158
|
-
|
|
3049
|
+
// 'embedded', not 'main': the embedded variant is the one DSH gives a
|
|
3050
|
+
// Conversation that lives outside the main root. Its stylesheet keys on
|
|
3051
|
+
// [data-content-phase=active] to let the message list grow and pin the
|
|
3052
|
+
// composer to the bottom; as 'main' the list is squashed and the
|
|
3053
|
+
// composer is pushed thousands of pixels out of the window.
|
|
3054
|
+
return props.renderFactorySlot('conversation.content', { variant: 'embedded', phase: 'active', hero: false })
|
|
2159
3055
|
} catch (error) {
|
|
2160
|
-
|
|
3056
|
+
report('[conversation-float] could not render the conversation content:', error)
|
|
3057
|
+
return null
|
|
2161
3058
|
}
|
|
2162
|
-
}, [])
|
|
2163
|
-
return null
|
|
2164
|
-
}
|
|
2165
|
-
|
|
2166
|
-
/** The floating panel's body: it holds the live Conversation column. */
|
|
2167
|
-
function SessionPanel() {
|
|
2168
|
-
const host = React.useRef(null)
|
|
3059
|
+
}, [props.renderFactorySlot])
|
|
2169
3060
|
React.useLayoutEffect(() => {
|
|
2170
3061
|
const container = host.current
|
|
2171
3062
|
if (container === null) return undefined
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
const
|
|
3063
|
+
const sessionId = container.closest('[data-sidebar-right-session]')?.getAttribute('data-sidebar-right-session') ?? null
|
|
3064
|
+
sessionRef.current = sessionId
|
|
3065
|
+
let disposed = false
|
|
3066
|
+
let seenPane = null
|
|
3067
|
+
const onEpoch = (id) => {
|
|
3068
|
+
if (id === sessionRef.current) setEpoch((value) => value + 1)
|
|
3069
|
+
}
|
|
3070
|
+
epochListeners.add(onEpoch)
|
|
3071
|
+
/**
|
|
3072
|
+
* DSH can move this very body between the float pane and a right-sidebar
|
|
3073
|
+
* page without remounting it, so the host is decided on every pass and
|
|
3074
|
+
* not once at mount.
|
|
3075
|
+
*/
|
|
3076
|
+
const decide = () => {
|
|
3077
|
+
if (disposed) return
|
|
3078
|
+
const el = host.current
|
|
3079
|
+
if (el === null) return
|
|
3080
|
+
const pane = el.closest('[' + FLOAT_ATTR + ']')
|
|
3081
|
+
const paneChanged = pane !== seenPane
|
|
3082
|
+
seenPane = pane
|
|
3083
|
+
paneRef.current = pane
|
|
3084
|
+
let win = sessionId === null ? undefined : windows.get(sessionId)
|
|
3085
|
+
if (pane !== null && sessionId !== null) {
|
|
3086
|
+
let created = false
|
|
3087
|
+
if (win === undefined) {
|
|
3088
|
+
try {
|
|
3089
|
+
win = ensureWindow(sessionId)
|
|
3090
|
+
created = win !== undefined
|
|
3091
|
+
} catch (error) {
|
|
3092
|
+
report('[conversation-float] could not lift the conversation into its window:', error)
|
|
3093
|
+
win = undefined
|
|
3094
|
+
}
|
|
3095
|
+
}
|
|
3096
|
+
if (win !== undefined) {
|
|
3097
|
+
pane.setAttribute(WINDOW_HIDE_PANE_ATTR, '')
|
|
3098
|
+
if (created || paneChanged) showWindow(sessionId)
|
|
3099
|
+
}
|
|
3100
|
+
setFloating(win !== undefined)
|
|
3101
|
+
setPortalTarget(win === undefined ? null : win.body)
|
|
3102
|
+
} else {
|
|
3103
|
+
if (win !== undefined) {
|
|
3104
|
+
// The tab left the float for a sidebar page: our window has no
|
|
3105
|
+
// tenant behind it any more, and a stray empty window is worse
|
|
3106
|
+
// than none at all.
|
|
3107
|
+
destroyWindow(sessionId)
|
|
3108
|
+
win = undefined
|
|
3109
|
+
}
|
|
3110
|
+
setFloating(false)
|
|
3111
|
+
setPortalTarget(null)
|
|
3112
|
+
}
|
|
3113
|
+
// A column that belongs to another Conversation must not stay in this
|
|
3114
|
+
// float: switching Sessions would paint the new Conversation inside
|
|
3115
|
+
// it, and the Conversation's own page would then be blank.
|
|
3116
|
+
if (movedColumn !== null && sessionId !== null && win !== undefined && win.body.contains(movedColumn)) {
|
|
3117
|
+
const held = columnSession(movedColumn)
|
|
3118
|
+
if (held !== null && held !== sessionId) {
|
|
3119
|
+
// Only a float left on a LATER page has to put the column back on
|
|
3120
|
+
// the first one; one that was already on the first page must not
|
|
3121
|
+
// make the Session jump for no reason.
|
|
3122
|
+
const tabsBefore = nativeViewTabs()
|
|
3123
|
+
const onFirstPage = tabsBefore[0] === undefined || tabsBefore[0].getAttribute('aria-selected') === 'true'
|
|
3124
|
+
handOffColumn(selectedSession() ?? liveSession())
|
|
3125
|
+
if (!onFirstPage) {
|
|
3126
|
+
// The tab strip re-renders on the commit this pass is inside;
|
|
3127
|
+
// one frame later is the first moment its selection is readable.
|
|
3128
|
+
window.requestAnimationFrame(() => {
|
|
3129
|
+
const first = nativeViewTabs()[0]
|
|
3130
|
+
if (first === undefined) return
|
|
3131
|
+
if (first.getAttribute('aria-selected') === 'true') return
|
|
3132
|
+
try { first.click() } catch { /* the header may be gone */ }
|
|
3133
|
+
})
|
|
3134
|
+
}
|
|
3135
|
+
}
|
|
3136
|
+
}
|
|
3137
|
+
// DSH is mid-render during a Session change and the Session on screen
|
|
3138
|
+
// is momentarily unreadable. Flipping to "not mine" there would mount a
|
|
3139
|
+
// second view of the live Conversation, and a second view takes the
|
|
3140
|
+
// draft writer for good. When the answer is unknown, keep the last one.
|
|
3141
|
+
const live = liveSession()
|
|
3142
|
+
if (live === null) return
|
|
3143
|
+
const mine = live === sessionId
|
|
3144
|
+
const target = pane !== null && win !== undefined ? win.body : el
|
|
3145
|
+
hostEl.current = target
|
|
3146
|
+
// A page that is not a Conversation (plugins, automations, settings)
|
|
3147
|
+
// renders into the very slot the column carries. Hosting the column now
|
|
3148
|
+
// would paint that page inside this window, and the window would follow
|
|
3149
|
+
// the user out of the Conversation — the View tab strip turning into a
|
|
3150
|
+
// plugin page's header and the composer disappearing with it. The page
|
|
3151
|
+
// belongs to the middle column, so the column goes home and this body
|
|
3152
|
+
// shows the transcript of its own Session instead: the same thing a
|
|
3153
|
+
// window of a Session that is not the live one shows.
|
|
3154
|
+
const columnNow = findColumn()
|
|
3155
|
+
const page = mainPanelOpen() && (columnNow === null || columnSession(columnNow) === null)
|
|
3156
|
+
if (page && movedColumn !== null && win !== undefined && win.body.contains(movedColumn)) {
|
|
3157
|
+
try {
|
|
3158
|
+
detachColumn(true)
|
|
3159
|
+
} catch (error) {
|
|
3160
|
+
report('[conversation-float] could not hand the page its column:', error)
|
|
3161
|
+
}
|
|
3162
|
+
}
|
|
3163
|
+
// A floated body always hosts the live column. A docked page hosts it
|
|
3164
|
+
// too when there is a column to host — that is what puts the real
|
|
3165
|
+
// header, and its Conversation/Trajectory tabs, inside the page.
|
|
3166
|
+
// A minimised float KEEPS the column: the point of floating is that the
|
|
3167
|
+
// Conversation leaves DSH, and a hidden window is where it lives while
|
|
3168
|
+
// minimised. Only a body without a column to host renders its own view,
|
|
3169
|
+
// and so does every body while a page outside the Conversation is open.
|
|
3170
|
+
// A page outside the conversation takes the main slot, so the real
|
|
3171
|
+
// column goes home and the page lands in the ordinary frame. The live
|
|
3172
|
+
// Session's window stays on screen and keeps a full Conversation of
|
|
3173
|
+
// its own: header, View tabs and composer, not the read-only record a
|
|
3174
|
+
// window of another Session shows. The page is behind the window.
|
|
3175
|
+
if (page && mine && chromeless) revealChrome()
|
|
3176
|
+
const next = (mine && !page)
|
|
3177
|
+
? (pane !== null ? 'column' : (findColumn() !== null ? 'column' : 'factory'))
|
|
3178
|
+
: (mine && page ? 'factory-live' : 'factory')
|
|
3179
|
+
setMode((prev) => (prev === next ? prev : next))
|
|
3180
|
+
// Never re-append a column that is already inside: that would re-size
|
|
3181
|
+
// the float under the user's hand.
|
|
3182
|
+
if (next === 'column' && (movedColumn === null || !target.contains(movedColumn))) {
|
|
3183
|
+
// Another float may still be holding it: that float's own pass sees a
|
|
3184
|
+
// foreign column and releases it, so wait for that instead of yanking
|
|
3185
|
+
// the Conversation out from under it.
|
|
3186
|
+
const holder = movedColumn === null ? null : movedColumn.closest(`[${WINDOW_ATTR}]`)
|
|
3187
|
+
const holderId = holder === null ? null : holder.getAttribute(WINDOW_ATTR)
|
|
3188
|
+
if (holderId === null || holderId === sessionId) {
|
|
3189
|
+
try { attachColumn(target) } catch (error) {
|
|
3190
|
+
report('[conversation-float] could not host the live column:', error)
|
|
3191
|
+
}
|
|
3192
|
+
}
|
|
3193
|
+
}
|
|
3194
|
+
}
|
|
3195
|
+
layoutListeners.add(decide)
|
|
3196
|
+
decide()
|
|
3197
|
+
// No clock of its own: this body re-decides when DSH says the Session
|
|
3198
|
+
// changed, when a window opens or closes.
|
|
2177
3199
|
return () => {
|
|
2178
|
-
|
|
2179
|
-
|
|
3200
|
+
try {
|
|
3201
|
+
disposed = true
|
|
3202
|
+
epochListeners.delete(onEpoch)
|
|
3203
|
+
layoutListeners.delete(decide)
|
|
3204
|
+
const pane = paneRef.current
|
|
3205
|
+
paneRef.current = null
|
|
3206
|
+
if (pane !== null) pane.removeAttribute(WINDOW_HIDE_PANE_ATTR)
|
|
3207
|
+
setPortalTarget(null)
|
|
3208
|
+
const gone = sessionRef.current
|
|
3209
|
+
sessionRef.current = null
|
|
3210
|
+
if (gone !== null) destroyWindow(gone)
|
|
3211
|
+
} catch (error) {
|
|
3212
|
+
report('[conversation-float] window cleanup failed:', error)
|
|
3213
|
+
}
|
|
2180
3214
|
}
|
|
2181
3215
|
}, [])
|
|
2182
|
-
|
|
3216
|
+
// Hosting the live column replaces the factory view: hand it back the
|
|
3217
|
+
// moment this Conversation stops being the one on screen.
|
|
3218
|
+
React.useLayoutEffect(() => {
|
|
3219
|
+
if (mode !== 'column') return undefined
|
|
3220
|
+
const target = hostEl.current
|
|
3221
|
+
if (target === null) return undefined
|
|
3222
|
+
if (movedColumn === null || !target.contains(movedColumn)) attachColumn(target)
|
|
3223
|
+
// The copy that was showing this Conversation until this commit can take
|
|
3224
|
+
// the composer's editor down with it, and the composer that survives is
|
|
3225
|
+
// the one the user is about to type into.
|
|
3226
|
+
healComposerSoon()
|
|
3227
|
+
return () => {
|
|
3228
|
+
// Only take the column home while THIS body still holds it: a page
|
|
3229
|
+
// that has already adopted it must not lose it to a window teardown.
|
|
3230
|
+
if (movedColumn !== null && target.contains(movedColumn)) detachColumn()
|
|
3231
|
+
}
|
|
3232
|
+
}, [mode, portalTarget, floating])
|
|
3233
|
+
const hostProps = { className: 'dsw-host', ref: host, [BODY_ATTR]: '' }
|
|
3234
|
+
let body = null
|
|
3235
|
+
// A body only ever renders a Conversation of its OWN when that
|
|
3236
|
+
// Conversation is not the live one — hosting the live column replaces it.
|
|
3237
|
+
if (mode === 'factory' || mode === 'factory-live') {
|
|
3238
|
+
// Marked, so the stylesheet can take the composer out of this body and
|
|
3239
|
+
// leave the transcript. A factory-live body is the exception: it is the
|
|
3240
|
+
// live Session while a page owns the main slot, so it keeps the header,
|
|
3241
|
+
// the View tabs and the composer instead of degrading to a record.
|
|
3242
|
+
const live = mode === 'factory-live'
|
|
3243
|
+
let header = null
|
|
3244
|
+
if (live && typeof props.renderSlot === 'function') {
|
|
3245
|
+
try {
|
|
3246
|
+
header = props.renderSlot('conversation.session.header', { hideChrome: false })
|
|
3247
|
+
} catch (error) {
|
|
3248
|
+
report('[conversation-float] could not render the live header:', error)
|
|
3249
|
+
}
|
|
3250
|
+
}
|
|
3251
|
+
const shell = h('div', {
|
|
3252
|
+
key: epoch,
|
|
3253
|
+
[FACTORY_ATTR]: '',
|
|
3254
|
+
[FACTORY_LIVE_ATTR]: live ? '' : undefined,
|
|
3255
|
+
style: { display: 'flex', flexDirection: 'column', flex: '1 1 auto', minHeight: 0, minWidth: 0, height: '100%' },
|
|
3256
|
+
}, header, content)
|
|
3257
|
+
body = floating && portalTarget !== null ? ReactDOM.createPortal(shell, portalTarget) : shell
|
|
3258
|
+
}
|
|
3259
|
+
return h('div', hostProps, h(Styles), body)
|
|
2183
3260
|
}
|
|
2184
3261
|
|
|
2185
3262
|
/**
|
|
@@ -2203,11 +3280,11 @@ window.__ModuleLoader__.load({
|
|
|
2203
3280
|
}
|
|
2204
3281
|
|
|
2205
3282
|
/**
|
|
2206
|
-
* The left sidebar's More menu:
|
|
2207
|
-
*
|
|
3283
|
+
* The left sidebar's More menu: put the conversation's window away. The row
|
|
3284
|
+
* that brings it back lives in this same sidebar.
|
|
2208
3285
|
*/
|
|
2209
3286
|
function MoveLeftRow({ onDismiss }) {
|
|
2210
|
-
if (
|
|
3287
|
+
if (conversationInLeftbar()) return null
|
|
2211
3288
|
return h(MoveRow, { onDismiss, label: t('moveLeft'), onSelect: moveConversationLeft })
|
|
2212
3289
|
}
|
|
2213
3290
|
|
|
@@ -2226,6 +3303,9 @@ window.__ModuleLoader__.load({
|
|
|
2226
3303
|
inject: ['slots', 'locale'],
|
|
2227
3304
|
apply(ctx) {
|
|
2228
3305
|
ctxRef = ctx
|
|
3306
|
+
// Build marker: lets a probe tell a re-imported client.js from the copy
|
|
3307
|
+
// the host still holds in memory (a page refresh does NOT reload it).
|
|
3308
|
+
try { window.__dshFloatBuild = 'rowguard-0.2.7' } catch { /* no window yet */ }
|
|
2229
3309
|
ctx.effect(() => {
|
|
2230
3310
|
try {
|
|
2231
3311
|
return ctx.locale.register(NS, Object.fromEntries(LOCALES.map((id) => [id, { title: COPY[id].floatTitle, description: COPY[id].description }])))
|
|
@@ -2239,7 +3319,7 @@ window.__ModuleLoader__.load({
|
|
|
2239
3319
|
ctx.effect(() =>
|
|
2240
3320
|
ctx.locale.subscribe(() => {
|
|
2241
3321
|
notifyState()
|
|
2242
|
-
if (preview !== null && preview.zone !== null) preview.label.textContent =
|
|
3322
|
+
if (preview !== null && preview.zone !== null) preview.label.textContent = previewLabel(preview.zone, preview.own)
|
|
2243
3323
|
}),
|
|
2244
3324
|
)
|
|
2245
3325
|
|
|
@@ -2256,28 +3336,22 @@ window.__ModuleLoader__.load({
|
|
|
2256
3336
|
register('sidebar.panellist.actions', 'conversation-float-stow', MoveLeftRow, { order: 100 })
|
|
2257
3337
|
register('sidebar.right.tab.guide.actions', 'conversation-float-move', MoveRightRow, { order: 100 })
|
|
2258
3338
|
|
|
2259
|
-
ctx.effect(() => watchColumn())
|
|
2260
|
-
|
|
2261
3339
|
ctx.effect(() => {
|
|
2262
3340
|
window.addEventListener('keydown', escapeOnKey, true)
|
|
2263
|
-
document.addEventListener('click',
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
3341
|
+
document.addEventListener('click', taskbarRowPress, true)
|
|
3342
|
+
// A hand on the sidebars outranks any retry the plugin started: it
|
|
3343
|
+
// ends the retry instead of being read as a state that disagrees.
|
|
3344
|
+
const onHand = (event) => {
|
|
3345
|
+
const target = event.target
|
|
3346
|
+
if (!(target instanceof Element)) return
|
|
3347
|
+
if (target.closest(`[${FLOAT_ATTR}], [${WINDOW_ATTR}]`) !== null) return
|
|
3348
|
+
if (typeof chromeApplyStop === 'function') chromeApplyStop()
|
|
2267
3349
|
}
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
// A hand on a float outranks any seat this plugin remembered.
|
|
2271
|
-
ctx.effect(() => trackFloatGrab())
|
|
2272
|
-
|
|
2273
|
-
// A press or a key is the only evidence that a column moved by the
|
|
2274
|
-
// user's hand rather than by DSH re-railing it.
|
|
2275
|
-
ctx.effect(() => {
|
|
2276
|
-
document.addEventListener('pointerdown', noteGesture, true)
|
|
2277
|
-
document.addEventListener('keydown', noteGesture, true)
|
|
3350
|
+
window.addEventListener('pointerdown', onHand, true)
|
|
2278
3351
|
return () => {
|
|
2279
|
-
|
|
2280
|
-
document.removeEventListener('
|
|
3352
|
+
window.removeEventListener('keydown', escapeOnKey, true)
|
|
3353
|
+
document.removeEventListener('click', taskbarRowPress, true)
|
|
3354
|
+
window.removeEventListener('pointerdown', onHand, true)
|
|
2281
3355
|
}
|
|
2282
3356
|
})
|
|
2283
3357
|
|
|
@@ -2302,12 +3376,6 @@ window.__ModuleLoader__.load({
|
|
|
2302
3376
|
setChromeless(false)
|
|
2303
3377
|
|
|
2304
3378
|
|
|
2305
|
-
ctx.effect(() =>
|
|
2306
|
-
ctx.slots.inject('main', () =>
|
|
2307
|
-
ctx.slots.register({ name: 'main', key: DOCK_ROW_ID, locale: NS }, DockPanel),
|
|
2308
|
-
),
|
|
2309
|
-
)
|
|
2310
|
-
|
|
2311
3379
|
ctx.effect(() => {
|
|
2312
3380
|
const dispose = ctx.inject(['layout'], (sub) => {
|
|
2313
3381
|
layout = sub.layout ?? null
|
|
@@ -2318,22 +3386,20 @@ window.__ModuleLoader__.load({
|
|
|
2318
3386
|
return dispose
|
|
2319
3387
|
})
|
|
2320
3388
|
|
|
2321
|
-
// The
|
|
2322
|
-
//
|
|
2323
|
-
// navigation re-opens the Conversation.
|
|
3389
|
+
// The Session list drives every re-decide: it supplies the titles the
|
|
3390
|
+
// sidebars and windows show, and a change to it means the layout moved.
|
|
2324
3391
|
ctx.effect(() => {
|
|
2325
|
-
const dispose = ctx.inject(['sessions'
|
|
3392
|
+
const dispose = ctx.inject(['sessions'], (sub) => {
|
|
2326
3393
|
sessions = sub.sessions ?? null
|
|
2327
|
-
uiWorkspace = sub.uiWorkspace ?? null
|
|
2328
3394
|
let off = null
|
|
2329
3395
|
try {
|
|
2330
3396
|
if (typeof sessions?.list?.subscribe === 'function') {
|
|
2331
3397
|
off = sessions.list.subscribe(() => {
|
|
2332
|
-
|
|
3398
|
+
notifyLayout()
|
|
2333
3399
|
})
|
|
2334
3400
|
}
|
|
2335
3401
|
} catch (error) {
|
|
2336
|
-
|
|
3402
|
+
report('[conversation-float] could not follow the Session list:', error)
|
|
2337
3403
|
}
|
|
2338
3404
|
return () => {
|
|
2339
3405
|
try {
|
|
@@ -2342,7 +3408,6 @@ window.__ModuleLoader__.load({
|
|
|
2342
3408
|
/* the projection is already gone */
|
|
2343
3409
|
}
|
|
2344
3410
|
sessions = null
|
|
2345
|
-
uiWorkspace = null
|
|
2346
3411
|
}
|
|
2347
3412
|
})
|
|
2348
3413
|
return dispose
|
|
@@ -2351,30 +3416,44 @@ window.__ModuleLoader__.load({
|
|
|
2351
3416
|
ctx.effect(() =>
|
|
2352
3417
|
ctx.inject(['sidebarRightTabs', 'sidebarRight'], (sub) => {
|
|
2353
3418
|
sidebarRight = sub.sidebarRight ?? null
|
|
3419
|
+
// Each registration is fenced on its own: one refused registration
|
|
3420
|
+
// used to take the tab TYPE down with it, and a float that cannot
|
|
3421
|
+
// claim its tab cannot open at all.
|
|
3422
|
+
sub.effect(() => {
|
|
3423
|
+
try {
|
|
3424
|
+
return sub.sidebarRightTabs.register({
|
|
3425
|
+
id: CHAT_ID,
|
|
3426
|
+
kind: CHAT_KIND,
|
|
3427
|
+
title: () => t('conversation'),
|
|
3428
|
+
keepMounted: true,
|
|
3429
|
+
})
|
|
3430
|
+
} catch (error) {
|
|
3431
|
+
window.__dshFloatError = 'tab-type: ' + String(error && (error.stack || error))
|
|
3432
|
+
report('[conversation-float] tab type refused:', error)
|
|
3433
|
+
return () => {}
|
|
3434
|
+
}
|
|
3435
|
+
})
|
|
2354
3436
|
sub.effect(() =>
|
|
2355
|
-
sub.
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
3437
|
+
sub.slots.inject('sidebar.right.pane.tab', () => {
|
|
3438
|
+
try {
|
|
3439
|
+
return sub.slots.register({ name: 'sidebar.right.pane.tab', key: CHAT_ID, locale: NS, children: { 'conversation.session.header': { kind: 'single', scope: 'session' } } }, SessionPanel)
|
|
3440
|
+
} catch (error) {
|
|
3441
|
+
// A host that will not let this body own the header slot
|
|
3442
|
+
// still gets the body, with content and composer only.
|
|
3443
|
+
report('[conversation-float] header-capable body refused, retrying:', error)
|
|
3444
|
+
try {
|
|
3445
|
+
return sub.slots.register({ name: 'sidebar.right.pane.tab', key: CHAT_ID, locale: NS }, SessionPanel)
|
|
3446
|
+
} catch (fallbackError) {
|
|
3447
|
+
window.__dshFloatError = 'body: ' + String(fallbackError && (fallbackError.stack || fallbackError))
|
|
3448
|
+
report('[conversation-float] tab body refused:', fallbackError)
|
|
3449
|
+
return () => {}
|
|
3450
|
+
}
|
|
3451
|
+
}
|
|
2364
3452
|
}),
|
|
2365
3453
|
)
|
|
2366
|
-
sub.effect(() =>
|
|
2367
|
-
sub.slots.inject('sidebar.right.pane.tab', () =>
|
|
2368
|
-
sub.slots.register({ name: 'sidebar.right.pane.tab', key: CHAT_ID, locale: NS }, SessionPanel),
|
|
2369
|
-
),
|
|
2370
|
-
)
|
|
2371
3454
|
return () => {
|
|
2372
3455
|
sidebarRight = null
|
|
2373
3456
|
hidePreview()
|
|
2374
|
-
if (dockedLeft) {
|
|
2375
|
-
dockedLeft = false
|
|
2376
|
-
syncDockRow()
|
|
2377
|
-
}
|
|
2378
3457
|
detachColumn()
|
|
2379
3458
|
}
|
|
2380
3459
|
}),
|
|
@@ -2384,20 +3463,141 @@ window.__ModuleLoader__.load({
|
|
|
2384
3463
|
open: openFloating,
|
|
2385
3464
|
findColumn,
|
|
2386
3465
|
bands,
|
|
3466
|
+
/** Test harness: the same moves the drag bands and the menus make. */
|
|
3467
|
+
moveRight: () => drop('right'),
|
|
3468
|
+
moveCentre: () => drop('centre'),
|
|
3469
|
+
/** Test harness: the same switch the window's own chip makes. */
|
|
3470
|
+
switchTo: (id) => switchToWindow(id),
|
|
3471
|
+
/**
|
|
3472
|
+
* Probe: what the plugin believes about the Conversation column. The
|
|
3473
|
+
* breaks this repairs — a column parked in a page the window has left,
|
|
3474
|
+
* a recorded node DSH already took away — are invisible from outside,
|
|
3475
|
+
* so they can only be read from here.
|
|
3476
|
+
*/
|
|
3477
|
+
diag() {
|
|
3478
|
+
const column = movedColumn
|
|
3479
|
+
const page = column === null ? null : column.closest('[data-sidebar-right-session]')
|
|
3480
|
+
const scanned = scanColumn()
|
|
3481
|
+
return {
|
|
3482
|
+
build: window.__dshFloatBuild ?? null,
|
|
3483
|
+
followingSession: followingSelection,
|
|
3484
|
+
live: liveSession(),
|
|
3485
|
+
selected: selectedSession(),
|
|
3486
|
+
moved: column === null ? null : {
|
|
3487
|
+
connected: column.isConnected,
|
|
3488
|
+
session: columnSession(column),
|
|
3489
|
+
host: column.closest(`[${WINDOW_ATTR}]`) !== null ? 'window'
|
|
3490
|
+
: column.closest(`[${FLOAT_ATTR}]`) !== null ? 'float'
|
|
3491
|
+
: page !== null ? 'docked' : 'frame',
|
|
3492
|
+
page: page === null ? null : page.getAttribute('data-sidebar-right-session'),
|
|
3493
|
+
pageVisible: page === null ? null : panelVisible(page),
|
|
3494
|
+
},
|
|
3495
|
+
scanned: scanned === null ? null : columnSession(scanned),
|
|
3496
|
+
columns: document.querySelectorAll('[data-conversation-session]').length,
|
|
3497
|
+
windows: windows.size,
|
|
3498
|
+
compat: compatReport(),
|
|
3499
|
+
lastError: window.__dshFloatLastError ?? null,
|
|
3500
|
+
waits: pendingWaits.size,
|
|
3501
|
+
}
|
|
3502
|
+
},
|
|
3503
|
+
/** Test harness: which window carries the switch chip, and what the
|
|
3504
|
+
* drop outline currently says. */
|
|
3505
|
+
get chips() {
|
|
3506
|
+
const out = {}
|
|
3507
|
+
for (const [id, win] of windows) out[id] = win.switchChip === undefined ? null : !win.switchChip.hidden && win.switchChip.textContent
|
|
3508
|
+
return { top: topWindow(), live: liveSession(), shown: out }
|
|
3509
|
+
},
|
|
3510
|
+
get preview() {
|
|
3511
|
+
return preview === null || preview.zone === null
|
|
3512
|
+
? null
|
|
3513
|
+
: { zone: preview.zone, own: preview.own, label: preview.label.textContent }
|
|
3514
|
+
},
|
|
2387
3515
|
get moved() {
|
|
2388
3516
|
return movedColumn !== null
|
|
2389
3517
|
},
|
|
2390
|
-
get dockedLeft() {
|
|
2391
|
-
return dockedLeft
|
|
2392
|
-
},
|
|
2393
3518
|
/** What the sidebars restore is working from, for the test harness. */
|
|
2394
3519
|
get chrome() {
|
|
2395
|
-
return { saved: savedChrome,
|
|
3520
|
+
return { saved: savedChrome, chromeless, retrying: typeof chromeApplyStop === 'function' }
|
|
2396
3521
|
},
|
|
2397
3522
|
}
|
|
3523
|
+
// The probe is READ-ONLY unless a page asked for the harness. The
|
|
3524
|
+
// mutating entries below move a Session on any script's say-so, which
|
|
3525
|
+
// is a test surface, not an API, and shipped builds should not hand it
|
|
3526
|
+
// to whatever else happens to run on this origin.
|
|
3527
|
+
if (!floatDebugEnabled()) {
|
|
3528
|
+
for (const key of ['open', 'moveRight', 'moveCentre', 'switchTo']) {
|
|
3529
|
+
delete window.__dshSessionWindow[key]
|
|
3530
|
+
}
|
|
3531
|
+
}
|
|
3532
|
+
ctx.effect(() => {
|
|
3533
|
+
window.addEventListener('resize', reclampWindows)
|
|
3534
|
+
return () => window.removeEventListener('resize', reclampWindows)
|
|
3535
|
+
})
|
|
3536
|
+
|
|
3537
|
+
// The Session on screen is DSH's own state, and DSH publishes it: one
|
|
3538
|
+
// store, written by every navigation. Listening to it replaces the polls
|
|
3539
|
+
// that used to stand in for it — a Session switch is a layout pass now,
|
|
3540
|
+
// not a wait for the next tick.
|
|
3541
|
+
ctx.effect(() => {
|
|
3542
|
+
followSelection()
|
|
3543
|
+
return () => {}
|
|
3544
|
+
})
|
|
3545
|
+
|
|
3546
|
+
// Leaving the Conversation for a page outside it (plugins, automations,
|
|
3547
|
+
// settings) swaps the main slot's children and tells no service: the
|
|
3548
|
+
// Session is still "selected", so neither the workspace store nor the
|
|
3549
|
+
// Session list moves. Watch the slot itself, so a window stops following
|
|
3550
|
+
// the user out of the Conversation in the same turn it happens instead
|
|
3551
|
+
// of whenever something else happens to fire.
|
|
3552
|
+
ctx.effect(() => {
|
|
3553
|
+
const inMain = (node) => node instanceof Element
|
|
3554
|
+
&& (node.hasAttribute('data-slot')
|
|
3555
|
+
|| node.closest('[data-slot="main"]') !== null
|
|
3556
|
+
|| node.querySelector('[data-slot="main"]') !== null)
|
|
3557
|
+
const carries = (node) => node instanceof Element
|
|
3558
|
+
&& (node.hasAttribute('data-conversation-session')
|
|
3559
|
+
|| node.querySelector('[data-conversation-session]') !== null
|
|
3560
|
+
|| inMain(node))
|
|
3561
|
+
// Reading the main slot's own shape is what keeps this cheap: a
|
|
3562
|
+
// streaming answer mutates the transcript hundreds of times a second,
|
|
3563
|
+
// and a layout pass per token would cost more than it ever buys. Only
|
|
3564
|
+
// a change to WHAT the slot carries — or to whether a Conversation is
|
|
3565
|
+
// drawn at all — counts, and one pass per 200ms at most.
|
|
3566
|
+
const shape = () => {
|
|
3567
|
+
const slot = document.querySelector('[data-slot="main"]')
|
|
3568
|
+
const kinds = slot === null ? '' : [...slot.children].map((child) => child.getAttribute('data-slot') ?? child.tagName).join(',')
|
|
3569
|
+
return kinds + '|' + (document.querySelector('[data-conversation-session]') === null ? 'none' : 'conversation')
|
|
3570
|
+
}
|
|
3571
|
+
let seen = shape()
|
|
3572
|
+
let lastKick = 0
|
|
3573
|
+
const observer = new MutationObserver((records) => {
|
|
3574
|
+
let interesting = false
|
|
3575
|
+
for (const record of records) {
|
|
3576
|
+
if (record.type !== 'childList') continue
|
|
3577
|
+
if (inMain(record.target)) { interesting = true; break }
|
|
3578
|
+
for (const node of record.addedNodes) if (carries(node)) { interesting = true; break }
|
|
3579
|
+
if (interesting) break
|
|
3580
|
+
for (const node of record.removedNodes) if (carries(node)) { interesting = true; break }
|
|
3581
|
+
if (interesting) break
|
|
3582
|
+
}
|
|
3583
|
+
if (!interesting) return
|
|
3584
|
+
const now = Date.now()
|
|
3585
|
+
if (now - lastKick < 200) return
|
|
3586
|
+
const next = shape()
|
|
3587
|
+
if (next === seen) return
|
|
3588
|
+
seen = next
|
|
3589
|
+
lastKick = now
|
|
3590
|
+
kickLayout(1)
|
|
3591
|
+
})
|
|
3592
|
+
observer.observe(document.body, { childList: true, subtree: true })
|
|
3593
|
+
return () => observer.disconnect()
|
|
3594
|
+
})
|
|
3595
|
+
|
|
2398
3596
|
ctx.effect(() => () => {
|
|
3597
|
+
// Nothing this instance scheduled may outlive it: every wait is a
|
|
3598
|
+
// frame loop, and a frame loop left running holds a dead closure.
|
|
3599
|
+
cancelWaits()
|
|
2399
3600
|
hidePreview()
|
|
2400
|
-
unstowFloat()
|
|
2401
3601
|
// Unloading is not a user close: leave the sidebars alone.
|
|
2402
3602
|
suspendRestore = true
|
|
2403
3603
|
detachColumn()
|