dsh-panel-dock 0.0.0-stage → 1.0.43
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/LICENSE +21 -0
- package/README.md +231 -2
- package/client.js +1889 -0
- package/cordis.patch.yml +7 -0
- package/dock-core.js +104 -0
- package/index.js +2 -0
- package/package.json +48 -4
package/client.js
ADDED
|
@@ -0,0 +1,1889 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({
|
|
2
|
+
id: 'dsh-panel-dock',
|
|
3
|
+
factory(require) {
|
|
4
|
+
const React = require('react')
|
|
5
|
+
const h = React.createElement
|
|
6
|
+
// Portals are how a card survives being moved between the sidebar and the band.
|
|
7
|
+
// The loader exposes react-dom (dshmarket relies on it); if a host ever does not,
|
|
8
|
+
// the dock falls back to the plain two-host rendering instead of failing.
|
|
9
|
+
const createPortal = (() => {
|
|
10
|
+
try {
|
|
11
|
+
const dom = require('react-dom')
|
|
12
|
+
return dom && typeof dom.createPortal === 'function' ? dom.createPortal : null
|
|
13
|
+
} catch { return null }
|
|
14
|
+
})()
|
|
15
|
+
|
|
16
|
+
// dsh-panel-dock is a slot negotiation layer, not a UI of its own: plugins
|
|
17
|
+
// register a card here and the dock decides where it renders. It never adds a
|
|
18
|
+
// navigation entry, a button or a dialog -- the only affordances belong to the
|
|
19
|
+
// cards themselves.
|
|
20
|
+
const VERSION = '1.0.43'
|
|
21
|
+
const NS = 'panel-dock'
|
|
22
|
+
const STORE_KEY = 'dsh.panel-dock.v1'
|
|
23
|
+
const GAP = 6
|
|
24
|
+
const STACK_GAP = GAP
|
|
25
|
+
// Cards own their shadow, and a scroll container clips at its padding box. So the
|
|
26
|
+
// band only becomes a scroll container when the cards no longer fit the column,
|
|
27
|
+
// and then it grows by the shadow's reach and pads the same amount back.
|
|
28
|
+
const SHADOW_GUTTER = 16
|
|
29
|
+
// The panel declares the width below which its own content is no longer useful
|
|
30
|
+
// (`minWidth` in define()). The dock never renders it narrower than that, and when
|
|
31
|
+
// the whitespace is short it takes exactly the missing pixels out of the transcript.
|
|
32
|
+
// 280 is the default because it is measured, not guessed: at 280 both shipped cards
|
|
33
|
+
// render every value in full, while at 264 the quota card already cuts its 24h column
|
|
34
|
+
// to "35.2/1..." and at 200 it cuts 19 elements.
|
|
35
|
+
const DEFAULT_MIN_WIDTH = 280
|
|
36
|
+
// Nothing is drawn narrower than this, whatever a panel declares.
|
|
37
|
+
const MIN_WIDTH_FLOOR = 120
|
|
38
|
+
// A card wider than this stops reading as a card; the band may be wider than the
|
|
39
|
+
// card and the surplus stays with the conversation.
|
|
40
|
+
const MAX_PANEL_WIDTH = 480
|
|
41
|
+
// A card may eat into the conversation, but not more than half of it: past that the
|
|
42
|
+
// card belongs in the sidebar stack instead of on top of the text.
|
|
43
|
+
const MAX_COVER_RATIO = 0.5
|
|
44
|
+
// A conversation switch tears the transcript down and rebuilds it, so for a few frames
|
|
45
|
+
// the turn rail has no marks at all. Remembering where it was keeps the band's width
|
|
46
|
+
// stable across that gap instead of letting inner mode collapse to intrude.
|
|
47
|
+
const RAIL_MEMORY_MS = 1500
|
|
48
|
+
let railMemory = null
|
|
49
|
+
// The band must not clip: any scroll container turns its children's box-shadow into
|
|
50
|
+
// a hard-edged rectangle. Cards own their shadow, and it has to fall naturally the
|
|
51
|
+
// way it does in the sidebar.
|
|
52
|
+
|
|
53
|
+
const zh = { bandUnavailable: '此页无对话区',
|
|
54
|
+
empty: '暂无面板', toLeft: '移到左侧', toRight: '移到右侧', cardCrashed: '渲染失败(已隔离)',
|
|
55
|
+
}
|
|
56
|
+
const en = { bandUnavailable: 'No conversation on this page',
|
|
57
|
+
empty: 'No panels yet', toLeft: 'Move to the left panel', toRight: 'Move to the right panel',
|
|
58
|
+
cardCrashed: 'failed to render (isolated)',
|
|
59
|
+
}
|
|
60
|
+
let T = (key) => key
|
|
61
|
+
|
|
62
|
+
// The registry lives on the window, not in this module's closure: a hot reload of
|
|
63
|
+
// the dock creates a fresh closure while the panels keep their existing
|
|
64
|
+
// registrations -- wiping them would silently empty both docks.
|
|
65
|
+
const registry = (() => {
|
|
66
|
+
const existing = typeof window === 'undefined' ? null : window.__dshPanelDockRegistry
|
|
67
|
+
const map = existing instanceof Map ? existing : new Map()
|
|
68
|
+
if (typeof window !== 'undefined') window.__dshPanelDockRegistry = map
|
|
69
|
+
return map
|
|
70
|
+
})()
|
|
71
|
+
const listeners = (() => {
|
|
72
|
+
const existing = typeof window === 'undefined' ? null : window.__dshPanelDockListeners
|
|
73
|
+
const set = existing instanceof Set ? existing : new Set()
|
|
74
|
+
if (typeof window !== 'undefined') window.__dshPanelDockListeners = set
|
|
75
|
+
return set
|
|
76
|
+
})()
|
|
77
|
+
|
|
78
|
+
function emit() { for (const fn of listeners) { try { fn() } catch {} } }
|
|
79
|
+
function subscribe(fn) { listeners.add(fn); return () => listeners.delete(fn) }
|
|
80
|
+
// Stacking order: `order` ascending (missing = 100), ties keep registration order.
|
|
81
|
+
// Registration order alone made a card's position depend on which plugin happened to
|
|
82
|
+
// activate first -- nothing a card could reason about or fix from its own side.
|
|
83
|
+
function orderOf(panel) {
|
|
84
|
+
const value = Number(panel.order)
|
|
85
|
+
return Number.isFinite(value) ? value : 100
|
|
86
|
+
}
|
|
87
|
+
function panels() {
|
|
88
|
+
// Array.prototype.sort is stable, so equal orders keep the Map's registration order.
|
|
89
|
+
return [...registry.values()].sort((a, b) => orderOf(a) - orderOf(b))
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function readSides() {
|
|
93
|
+
try {
|
|
94
|
+
const raw = window.localStorage.getItem(STORE_KEY)
|
|
95
|
+
if (!raw) return {}
|
|
96
|
+
const parsed = JSON.parse(raw)
|
|
97
|
+
const source = parsed && typeof parsed.sides === 'object' && parsed.sides ? parsed.sides : {}
|
|
98
|
+
const sides = {}
|
|
99
|
+
for (const id of Object.keys(source)) {
|
|
100
|
+
const side = source[id]
|
|
101
|
+
if (side === 'left' || side === 'right') sides[id] = side
|
|
102
|
+
}
|
|
103
|
+
return sides
|
|
104
|
+
} catch { return {} }
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function writeSides(sides) {
|
|
108
|
+
try { window.localStorage.setItem(STORE_KEY, JSON.stringify({ sides })) } catch {}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function sideOf(id, fallback) {
|
|
112
|
+
const sides = readSides()
|
|
113
|
+
if (sides[id] === 'left' || sides[id] === 'right') return sides[id]
|
|
114
|
+
return fallback === 'right' ? 'right' : 'left'
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function setSide(id, side) {
|
|
118
|
+
const next = side === 'right' ? 'right' : 'left'
|
|
119
|
+
const sides = readSides()
|
|
120
|
+
sides[id] = next
|
|
121
|
+
writeSides(sides)
|
|
122
|
+
emit()
|
|
123
|
+
return next
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function toggleSide(id) {
|
|
127
|
+
const panel = registry.get(id)
|
|
128
|
+
const current = sideOf(id, panel ? panel.side : 'left')
|
|
129
|
+
return setSide(id, current === 'right' ? 'left' : 'right')
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function define(definition) {
|
|
133
|
+
if (!definition || typeof definition.id !== 'string' || definition.id === '') {
|
|
134
|
+
throw new Error('panel-dock: define() needs a non-empty id')
|
|
135
|
+
}
|
|
136
|
+
if (typeof definition.component !== 'function') {
|
|
137
|
+
throw new Error('panel-dock: define(' + definition.id + ') needs a component')
|
|
138
|
+
}
|
|
139
|
+
// minWidth is the panel's own statement of "below this my content stops being
|
|
140
|
+
// useful". The dock honours it as the width it will never undercut, taking the
|
|
141
|
+
// difference out of the transcript only when there is no whitespace left.
|
|
142
|
+
const declared = Number(definition.minWidth)
|
|
143
|
+
const minWidth = Number.isFinite(declared) && declared > 0
|
|
144
|
+
? Math.min(MAX_PANEL_WIDTH, Math.max(MIN_WIDTH_FLOOR, Math.round(declared)))
|
|
145
|
+
: DEFAULT_MIN_WIDTH
|
|
146
|
+
// version is what a shared CardShell shows next to the title; it is the plugin's
|
|
147
|
+
// own version, not the dock's.
|
|
148
|
+
const version = typeof definition.version === 'string' || typeof definition.version === 'number'
|
|
149
|
+
? String(definition.version)
|
|
150
|
+
: null
|
|
151
|
+
revisions.set(definition.id, revisionOf(definition.id) + 1)
|
|
152
|
+
// frame: the dock owns the visible rectangle (background, border, radius, padding,
|
|
153
|
+
// shadow) for every card. Default ON since 0.8.0 -- three cards each painting their
|
|
154
|
+
// own surface is how three cards end up in three different greys and shadows.
|
|
155
|
+
// A card that genuinely needs its own box opts out with frame: false.
|
|
156
|
+
// frameDeclared separates "said false" from "defaulted false": the registry lives on
|
|
157
|
+
// window and survives client reloads, so records written by 0.7.x carry the old
|
|
158
|
+
// default (false) and would otherwise keep their own surface forever.
|
|
159
|
+
const frameDeclared = definition.frame === true || definition.frame === false
|
|
160
|
+
const frame = frameDeclared ? definition.frame === true : true
|
|
161
|
+
// Keep the exact record so the disposer can tell "mine" from "a newer one's".
|
|
162
|
+
const stored = Object.assign({}, definition, { minWidth, version, frame, frameDeclared })
|
|
163
|
+
registry.set(definition.id, stored)
|
|
164
|
+
emit()
|
|
165
|
+
return () => {
|
|
166
|
+
// HMR race: when a module reloads, the new instance defines first and the old
|
|
167
|
+
// one disposes second. Deleting by id alone would remove the *new* registration
|
|
168
|
+
// and leave the card defined nowhere. Only remove the record we created.
|
|
169
|
+
if (registry.get(definition.id) !== stored) return
|
|
170
|
+
registry.delete(definition.id)
|
|
171
|
+
emit()
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function useRegistry() {
|
|
176
|
+
const [, force] = React.useState(0)
|
|
177
|
+
React.useEffect(() => subscribe(() => force((n) => n + 1)), [])
|
|
178
|
+
return panels()
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// Effective surface ownership. Records written before 0.8.0 have no frameDeclared and
|
|
182
|
+
// a defaulted `frame: false`; they must follow the new default rather than keep it.
|
|
183
|
+
function frameEnabled(panel) {
|
|
184
|
+
if (!panel) return false
|
|
185
|
+
if (panel.frameDeclared === true) return panel.frame === true
|
|
186
|
+
if (panel.frameDeclared === false) return true
|
|
187
|
+
return true
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// Cards that opt in with `frame: true` hand the rectangle to the dock: one token set,
|
|
191
|
+
// one radius, one border, so three cards cannot end up in three different greys. The
|
|
192
|
+
// default stays off -- the dock must not repaint a card that draws itself.
|
|
193
|
+
// The host exposes no theme attribute and no surface tokens (verified: empty --dsw-* set,
|
|
194
|
+
// no data-theme, color-scheme:light in both modes), so the theme is read from what is
|
|
195
|
+
// actually painted. Three signals, strongest first:
|
|
196
|
+
// 1. an explicit marker if the host ever adds one (data-ds-dark-theme / data-theme);
|
|
197
|
+
// 2. the painted background, body then <html> (body may be transparent);
|
|
198
|
+
// 3. prefers-color-scheme, only when nothing is painted.
|
|
199
|
+
// R3 closed: verified on invictus (light) and valentines (dark) after this change.
|
|
200
|
+
const paintLuma = (el) => {
|
|
201
|
+
try {
|
|
202
|
+
const bg = getComputedStyle(el).backgroundColor || ''
|
|
203
|
+
const m = bg.match(/rgba?\(([^)]+)\)/)
|
|
204
|
+
if (!m) return null
|
|
205
|
+
const p = m[1].split(',').map((v) => parseFloat(v))
|
|
206
|
+
const a = p.length > 3 ? p[3] : 1
|
|
207
|
+
if (a <= 0.1) return null
|
|
208
|
+
return (0.2126 * p[0] + 0.7152 * p[1] + 0.0722 * p[2]) / 255
|
|
209
|
+
} catch (e) { return null }
|
|
210
|
+
}
|
|
211
|
+
const darkCache = { at: 0, dark: false }
|
|
212
|
+
const hostIsDark = () => {
|
|
213
|
+
const now = Date.now()
|
|
214
|
+
if (now - darkCache.at < 500) return darkCache.dark
|
|
215
|
+
let dark = false
|
|
216
|
+
try {
|
|
217
|
+
const root = document.documentElement
|
|
218
|
+
const marker = (root.getAttribute('data-ds-dark-theme') !== null) ||
|
|
219
|
+
(root.getAttribute('data-theme') === 'dark') ||
|
|
220
|
+
(document.body && document.body.getAttribute
|
|
221
|
+
? (document.body.getAttribute('data-ds-dark-theme') !== null || document.body.getAttribute('data-theme') === 'dark')
|
|
222
|
+
: false)
|
|
223
|
+
if (marker) {
|
|
224
|
+
dark = true
|
|
225
|
+
} else {
|
|
226
|
+
const luma = paintLuma(document.body) ?? paintLuma(root)
|
|
227
|
+
dark = luma === null
|
|
228
|
+
? Boolean(window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches)
|
|
229
|
+
: luma < 0.45
|
|
230
|
+
}
|
|
231
|
+
} catch (e) {}
|
|
232
|
+
darkCache.at = now
|
|
233
|
+
darkCache.dark = dark
|
|
234
|
+
return dark
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// --- theme contract (dock side) -------------------------------------------------
|
|
238
|
+
// Dock owns the card SURFACE (background, border, radius, shadow) and publishes the
|
|
239
|
+
// theme to the cards; cards own their inner content and read these instead of hardcoding
|
|
240
|
+
// colours. Signals, in priority order: data-pd-theme > prefers-color-scheme > currentColor.
|
|
241
|
+
const THEME_TOKENS = {
|
|
242
|
+
light: {
|
|
243
|
+
border: 'rgba(15,23,42,0.08)', fg: 'rgb(15,17,21)',
|
|
244
|
+
muted: 'rgba(15,17,21,0.55)', surface2: 'rgba(15,17,21,0.04)',
|
|
245
|
+
},
|
|
246
|
+
dark: {
|
|
247
|
+
border: 'rgba(255,255,255,0.10)', fg: 'rgb(232,234,237)',
|
|
248
|
+
muted: 'rgba(232,234,237,0.60)', surface2: 'rgba(255,255,255,0.07)',
|
|
249
|
+
},
|
|
250
|
+
}
|
|
251
|
+
const stampTheme = () => {
|
|
252
|
+
const dark = hostIsDark()
|
|
253
|
+
const base = THEME_TOKENS[dark ? 'dark' : 'light']
|
|
254
|
+
// Semantic colours live here because the host's --dsw-alias-state-* are tuned for the
|
|
255
|
+
// host surface, not for the dock card fill; cards asked for a stable set.
|
|
256
|
+
// Semantic colours belong to the dock: the host's state palette is tuned for the host
|
|
257
|
+
// surface, not for the card fill. success/error are aliases of ok/danger so cards can
|
|
258
|
+
// use either naming.
|
|
259
|
+
const tokens = dark
|
|
260
|
+
? { ...base, ok: 'rgb(74,222,128)', warn: 'rgb(251,191,36)', danger: 'rgb(248,113,113)', idle: 'rgba(232,234,237,0.55)', accent: 'rgb(96,165,250)', track: 'rgba(255,255,255,0.14)', shadow: '0 4px 16px rgba(0,0,0,0.55)' }
|
|
261
|
+
: { ...base, ok: 'rgb(34,197,94)', warn: 'rgb(217,119,6)', danger: 'rgb(239,68,68)', idle: 'rgba(15,17,21,0.55)', accent: 'rgb(37,99,235)', track: 'rgba(15,23,42,0.08)', shadow: '0 3px 12px rgba(0,0,0,0.16)' }
|
|
262
|
+
tokens.success = tokens.ok
|
|
263
|
+
tokens.error = tokens.danger
|
|
264
|
+
// Also on :root: internal overlays and portals do not live inside the frame and would
|
|
265
|
+
// otherwise inherit nothing (Loci's map tip / peek are exactly that case).
|
|
266
|
+
const root = document.documentElement
|
|
267
|
+
root.setAttribute('data-pd-theme', dark ? 'dark' : 'light')
|
|
268
|
+
// :root gets a neutral default too: a card rendered outside a frame (or a portal) has no
|
|
269
|
+
// frame to read --pd-card-bg from. Per-frame values still win inside the frame.
|
|
270
|
+
root.style.setProperty('--pd-card-bg', dark ? '#26282b' : 'rgb(249,250,251)')
|
|
271
|
+
// Header metrics: one scale for every card so the logo/title/version row lines up.
|
|
272
|
+
// Values are the ones the three cards already agree on (13/700 title, gap 6) with the
|
|
273
|
+
// mark pinned to 14 and the version to 9 so the outliers have a target.
|
|
274
|
+
root.style.setProperty('--pd-header-gap', '6px')
|
|
275
|
+
root.style.setProperty('--pd-header-mark', '14px')
|
|
276
|
+
root.style.setProperty('--pd-header-title-size', '13px')
|
|
277
|
+
root.style.setProperty('--pd-header-title-weight', '700')
|
|
278
|
+
root.style.setProperty('--pd-header-version-size', '9px')
|
|
279
|
+
root.style.setProperty('--pd-header-actions-gap', '5px')
|
|
280
|
+
root.style.setProperty('--pd-header-bottom', '6px')
|
|
281
|
+
Object.keys(tokens).forEach((k) => {
|
|
282
|
+
const name = k === 'ok' || k === 'warn' || k === 'danger' || k === 'idle' ||
|
|
283
|
+
k === 'success' || k === 'error' || k === 'accent' || k === 'track' || k === 'shadow'
|
|
284
|
+
? '--pd-card-' + k
|
|
285
|
+
: (k === 'surface2' ? '--pd-card-surface-2' : (k === 'border' || k === 'fg' || k === 'muted' ? '--pd-card-' + k : null))
|
|
286
|
+
if (name) root.style.setProperty(name, tokens[k])
|
|
287
|
+
})
|
|
288
|
+
const frames = document.querySelectorAll('[data-panel-dock-frame]')
|
|
289
|
+
for (let i = 0; i < frames.length; i++) {
|
|
290
|
+
const frame = frames[i]
|
|
291
|
+
const inLeft = Boolean(frame.closest('[data-panel-dock-left]'))
|
|
292
|
+
const bg = dark
|
|
293
|
+
? (inLeft ? '#2e3135' : '#232528')
|
|
294
|
+
: (inLeft ? '#ffffff' : (THEME_TOKENS.light.bgRight || 'rgb(249,250,251)'))
|
|
295
|
+
frame.setAttribute('data-pd-theme', dark ? 'dark' : 'light')
|
|
296
|
+
if (dark) frame.setAttribute('data-pd-dark', '')
|
|
297
|
+
else frame.removeAttribute('data-pd-dark')
|
|
298
|
+
const s = frame.style
|
|
299
|
+
s.setProperty('--pd-card-bg', bg)
|
|
300
|
+
s.setProperty('--pd-card-fg', tokens.fg)
|
|
301
|
+
s.setProperty('--pd-card-muted', tokens.muted)
|
|
302
|
+
s.setProperty('--pd-card-border', tokens.border)
|
|
303
|
+
s.setProperty('--pd-card-surface-2', tokens.surface2)
|
|
304
|
+
s.setProperty('--pd-card-ok', tokens.ok)
|
|
305
|
+
s.setProperty('--pd-card-warn', tokens.warn)
|
|
306
|
+
s.setProperty('--pd-card-danger', tokens.danger)
|
|
307
|
+
s.setProperty('--pd-card-idle', tokens.idle)
|
|
308
|
+
s.setProperty('--pd-card-success', tokens.success)
|
|
309
|
+
s.setProperty('--pd-card-error', tokens.error)
|
|
310
|
+
s.setProperty('--pd-card-accent', tokens.accent)
|
|
311
|
+
s.setProperty('--pd-card-track', tokens.track)
|
|
312
|
+
s.setProperty('--pd-card-shadow', tokens.shadow)
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
const themeTimer = setInterval(() => { try { stampTheme() } catch (e) {} }, 2000)
|
|
316
|
+
|
|
317
|
+
const FRAME_STYLE = {
|
|
318
|
+
boxSizing: 'border-box',
|
|
319
|
+
width: '100%',
|
|
320
|
+
minWidth: 0,
|
|
321
|
+
padding: '10px 9px 8px',
|
|
322
|
+
borderRadius: 12,
|
|
323
|
+
border: '1px solid var(--dsw-alias-border-l1, rgba(0,0,0,0.08))',
|
|
324
|
+
background: 'var(--dsw-specific-sidebar-fill, rgba(249,250,251,1))',
|
|
325
|
+
color: 'var(--dsw-alias-label-primary, inherit)',
|
|
326
|
+
// Surface is the dock's business as of 0.8.0: one background, one border, one
|
|
327
|
+
// radius, one shadow for every card. Values are the ones the cards themselves used
|
|
328
|
+
// to write (Codex Advisor's shadow, measured: 0 3px 12px rgba(0,0,0,.16)); they are
|
|
329
|
+
// the user's pick, so changing them needs the user, not a passing maintainer.
|
|
330
|
+
boxShadow: '0 3px 12px 0 rgba(0,0,0,0.16)',
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
// A panel owns its own rectangle: the dock passes sizing through `style` and the
|
|
334
|
+
// component must spread it onto its single root element.
|
|
335
|
+
function renderPanel(panel) {
|
|
336
|
+
const card = h(panel.component, {
|
|
337
|
+
key: panel.id,
|
|
338
|
+
active: true,
|
|
339
|
+
'data-panel-dock-item': panel.id,
|
|
340
|
+
style: {
|
|
341
|
+
width: '100%',
|
|
342
|
+
minWidth: 0,
|
|
343
|
+
boxSizing: 'border-box',
|
|
344
|
+
// Cards carry their own sidebar-footer layout (flex basis, order, margins).
|
|
345
|
+
// Inside a dock those must not leak: the dock owns placement and spacing.
|
|
346
|
+
flex: '0 0 auto',
|
|
347
|
+
order: 0,
|
|
348
|
+
margin: 0,
|
|
349
|
+
pointerEvents: 'auto',
|
|
350
|
+
},
|
|
351
|
+
})
|
|
352
|
+
if (!frameEnabled(panel)) return card
|
|
353
|
+
return h('div', {
|
|
354
|
+
'data-panel-dock-frame': panel.id,
|
|
355
|
+
style: Object.assign({}, FRAME_STYLE, { display: 'flex', flexDirection: 'column' }),
|
|
356
|
+
}, card)
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
// Left panels live in the sidebar footer, in registration order.
|
|
360
|
+
function LeftHost() {
|
|
361
|
+
const layout = useRegistry()
|
|
362
|
+
// No room on the right (narrow conversation, or the right sidebar is open): a card
|
|
363
|
+
// reads better here than squeezed over the transcript.
|
|
364
|
+
const items = layout.filter((panel) => placement.fallback || sideOf(panel.id, panel.side) === 'left')
|
|
365
|
+
if (items.length === 0) return null
|
|
366
|
+
return h('div', {
|
|
367
|
+
'data-panel-dock-left': '',
|
|
368
|
+
style: {
|
|
369
|
+
display: 'flex',
|
|
370
|
+
flexDirection: 'column',
|
|
371
|
+
gap: STACK_GAP,
|
|
372
|
+
// The host footer is a nowrap flex row; claim it and refuse to shrink,
|
|
373
|
+
// otherwise the stack collapses to a sliver of a few pixels.
|
|
374
|
+
flex: '0 0 100%',
|
|
375
|
+
width: '100%',
|
|
376
|
+
minWidth: 0,
|
|
377
|
+
boxSizing: 'border-box',
|
|
378
|
+
},
|
|
379
|
+
}, items.map((panel) => h(CardBoundary, {
|
|
380
|
+
key: panel.id + ':' + revisionOf(panel.id),
|
|
381
|
+
id: panel.id,
|
|
382
|
+
fallback: () => errorCard(panel),
|
|
383
|
+
}, renderPanel(panel))))
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
// Geometry of the right strip: between the transcript drag handle and the turn
|
|
387
|
+
// navigator, starting under the conversation tabs. Both anchors belong to the
|
|
388
|
+
// shipped layout, so they are measured rather than assumed.
|
|
389
|
+
function measureAnchors() {
|
|
390
|
+
if (typeof document === 'undefined') return null
|
|
391
|
+
const box = (el) => el.getBoundingClientRect()
|
|
392
|
+
let left = null
|
|
393
|
+
let right = null
|
|
394
|
+
let top = 8
|
|
395
|
+
let handleRight = null
|
|
396
|
+
let handleLeft = null
|
|
397
|
+
let railRight = null
|
|
398
|
+
let areaRight = null
|
|
399
|
+
let areaLeft = null
|
|
400
|
+
let railInfo = null
|
|
401
|
+
let tabsSeen = false
|
|
402
|
+
let pageRight = null
|
|
403
|
+
let pageTop = 0
|
|
404
|
+
try {
|
|
405
|
+
// Views such as 轨迹/看板 keep the splitter in the DOM at 0x0 while it is not
|
|
406
|
+
// shown. Measuring it yields `left:0/right:0`, which used to drag the band to the
|
|
407
|
+
// top-left corner. Only a splitter with real area is an anchor.
|
|
408
|
+
const handles = [...document.querySelectorAll('[class*="widthHandle"]')]
|
|
409
|
+
.filter((el) => el.getAttribute('data-side') === 'right')
|
|
410
|
+
.filter((el) => { const r = box(el); return r.width > 0 && r.height > 0 })
|
|
411
|
+
const handle = handles[0]
|
|
412
|
+
if (handle) {
|
|
413
|
+
handleRight = Math.round(box(handle).right)
|
|
414
|
+
// The splitter is the only way to widen the conversation back: a squeezed
|
|
415
|
+
// card must stop at its left edge instead of swallowing it.
|
|
416
|
+
handleLeft = Math.round(box(handle).left)
|
|
417
|
+
left = handleRight + GAP
|
|
418
|
+
}
|
|
419
|
+
// The turn rail sits to the right of the band; other turn-navigation buttons live
|
|
420
|
+
// on its left edge. Keep the smallest x that is still right of the handle -- a wide
|
|
421
|
+
// conversation can leave only a few pixels, so the tolerance has to stay small.
|
|
422
|
+
const railMarks = [...document.querySelectorAll('button[aria-label]')]
|
|
423
|
+
.filter((el) => /turnNavigation|轮次|跳转/i.test(el.getAttribute('aria-label') || ''))
|
|
424
|
+
.filter((el) => { const r = box(el); return r.width > 0 && r.height > 0 })
|
|
425
|
+
.map((el) => ({ left: Math.round(box(el).left), right: Math.round(box(el).right) }))
|
|
426
|
+
// Everything to the right of the handle belongs to the rail side; a squeezed
|
|
427
|
+
// band can leave the rail a single pixel right of the handle.
|
|
428
|
+
.filter((mark) => handleRight === null || mark.left > handleRight)
|
|
429
|
+
const rail = railColumn(railMarks)
|
|
430
|
+
railInfo = rail !== null ? { right: rail.left - GAP, railRight: rail.right } : null
|
|
431
|
+
const pageTabs = document.querySelector('[role="tablist"]')
|
|
432
|
+
if (pageTabs) {
|
|
433
|
+
const pr = box(pageTabs)
|
|
434
|
+
if (pr.width > 0) pageTop = Math.round(pr.bottom) + GAP
|
|
435
|
+
// An arbitrary main-area page decides its own content width. Climb from its tab
|
|
436
|
+
// strip to the first ancestor that no longer spans the window: that edge is the
|
|
437
|
+
// page's content boundary, and the gutter right of it is where the band belongs.
|
|
438
|
+
let node = pageTabs.parentElement
|
|
439
|
+
while (node && node !== document.body) {
|
|
440
|
+
const r = box(node)
|
|
441
|
+
if (r.width > 0 && r.height > 40 && r.right < window.innerWidth - 2) {
|
|
442
|
+
pageRight = Math.round(r.right)
|
|
443
|
+
break
|
|
444
|
+
}
|
|
445
|
+
node = node.parentElement
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
const tabs = document.querySelector('[data-conversation-tabs]')
|
|
449
|
+
tabsSeen = Boolean(tabs)
|
|
450
|
+
if (tabs) {
|
|
451
|
+
top = Math.round(box(tabs.parentElement || tabs).bottom) + GAP
|
|
452
|
+
// The right sidebar (开始 / 终端 / 浏览器) owns the window's right side. The column
|
|
453
|
+
// that holds the tabs is the conversation area: climb to the outermost ancestor
|
|
454
|
+
// that still ends where the column ends (the tab strip itself is padded, so it
|
|
455
|
+
// is skipped), and take that edge as the hard limit.
|
|
456
|
+
let node = tabs.parentElement
|
|
457
|
+
let columnRight = null
|
|
458
|
+
while (node && node !== document.body) {
|
|
459
|
+
const rect = box(node)
|
|
460
|
+
if (rect.width === 0 || rect.height < 40) { node = node.parentElement; continue }
|
|
461
|
+
if (columnRight === null) columnRight = rect.right
|
|
462
|
+
else if (Math.abs(rect.right - columnRight) > 3) break
|
|
463
|
+
node = node.parentElement
|
|
464
|
+
}
|
|
465
|
+
if (columnRight !== null && columnRight < window.innerWidth - 2) {
|
|
466
|
+
areaRight = Math.round(columnRight)
|
|
467
|
+
areaLeft = Math.round(box(tabs).left)
|
|
468
|
+
let up = tabs.parentElement
|
|
469
|
+
while (up && up !== document.body) {
|
|
470
|
+
const r = box(up)
|
|
471
|
+
if (r.width > 0 && r.height >= 40 && Math.abs(r.right - columnRight) <= 3) areaLeft = Math.round(r.left)
|
|
472
|
+
up = up.parentElement
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
if (railInfo !== null) {
|
|
477
|
+
right = railInfo.right
|
|
478
|
+
railRight = railInfo.railRight
|
|
479
|
+
railMemory = { right, railRight, handleRight, areaRight, at: Date.now() }
|
|
480
|
+
} else if (
|
|
481
|
+
railMemory !== null
|
|
482
|
+
&& Date.now() - railMemory.at < RAIL_MEMORY_MS
|
|
483
|
+
&& railMemory.handleRight === handleRight
|
|
484
|
+
&& railMemory.areaRight === areaRight
|
|
485
|
+
) {
|
|
486
|
+
// Same window geometry, rail momentarily missing: keep the last known rail.
|
|
487
|
+
right = railMemory.right
|
|
488
|
+
railRight = railMemory.railRight
|
|
489
|
+
}
|
|
490
|
+
} catch {}
|
|
491
|
+
return { left, right, top, handleLeft, handleRight, railRight, areaRight, areaLeft, pageTop, tabsSeen, pageRight }
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
function sameAnchors(a, b) {
|
|
495
|
+
if (!a || !b) return a === b
|
|
496
|
+
return a.left === b.left && a.right === b.right && a.top === b.top
|
|
497
|
+
&& a.handleLeft === b.handleLeft && a.handleRight === b.handleRight
|
|
498
|
+
&& a.railRight === b.railRight && a.areaRight === b.areaRight && a.areaLeft === b.areaLeft
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
// What the cards want, gap included.
|
|
502
|
+
function stackedHeight(el) {
|
|
503
|
+
const kids = [...el.children]
|
|
504
|
+
let total = 0
|
|
505
|
+
for (const kid of kids) total += kid.getBoundingClientRect().height
|
|
506
|
+
return total + STACK_GAP * Math.max(0, kids.length - 1)
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
// The turn rail is a *column*: dozens of marks share one x. Message-level actions
|
|
510
|
+
// ("跳转到该消息", ...) match the same words but stand alone, and one of them sitting
|
|
511
|
+
// left of the rail used to drag the whole band left with it -- cards then rendered
|
|
512
|
+
// at the 200px floor while their real whitespace stayed empty. Pick the column.
|
|
513
|
+
function railColumn(marks) {
|
|
514
|
+
if (!marks.length) return null
|
|
515
|
+
const groups = []
|
|
516
|
+
for (const mark of marks) {
|
|
517
|
+
const group = groups.find((g) => Math.abs(g.left - mark.left) <= 2)
|
|
518
|
+
if (group) {
|
|
519
|
+
group.count += 1
|
|
520
|
+
group.right = Math.max(group.right, mark.right)
|
|
521
|
+
} else {
|
|
522
|
+
groups.push({ left: mark.left, right: mark.right, count: 1 })
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
const columns = groups.filter((g) => g.count >= 4).sort((a, b) => (b.count - a.count) || (a.left - b.left))
|
|
526
|
+
if (columns.length) return columns[0]
|
|
527
|
+
// A short conversation has few marks, but they still share one x. A *single* mark is
|
|
528
|
+
// usually an unrelated "跳转" button floating in the view (轨迹/看板 do that): treating
|
|
529
|
+
// it as the rail put the band at x≈6. Require at least two marks in one column.
|
|
530
|
+
const short = groups.filter((g) => g.count >= 2).sort((a, b) => (b.count - a.count) || (a.left - b.left))
|
|
531
|
+
return short.length ? short[0] : null
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
// Where right-side cards can live: the gutter left of the turn rail, the gutter right
|
|
535
|
+
// of it, or -- when neither can hold a readable card -- back in the sidebar stack.
|
|
536
|
+
// A card squeezed over the transcript is not an option: it hides text to buy a width
|
|
537
|
+
// that is still too small to read.
|
|
538
|
+
const placement = { fallback: false }
|
|
539
|
+
function setFallback(next) {
|
|
540
|
+
if (placement.fallback === next) return
|
|
541
|
+
placement.fallback = next
|
|
542
|
+
emit()
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
// `required` is the widest minimum any right-side card declared: the band is one
|
|
546
|
+
// column, so it has to satisfy the most demanding card in it.
|
|
547
|
+
// Kept so a main-area page shows the card at the same width it had beside the
|
|
548
|
+
// conversation: dropping to `required` there made the card visibly jump narrower.
|
|
549
|
+
let lastPlannedWidth = 0
|
|
550
|
+
// Switching conversations unmounts the turn rail for a moment ("载入历史…"). Treating
|
|
551
|
+
// that as "no conversation surface" flung the band to the window edge and pulled it
|
|
552
|
+
// back once loading finished -- the shrink-then-expand the user sees. Keep the last
|
|
553
|
+
// anchored plan through that gap instead of re-deciding on a half-built page.
|
|
554
|
+
const STICKY_PLAN_MS = 2500
|
|
555
|
+
let lastAnchoredPlan = null
|
|
556
|
+
let lastAnchoredAt = 0
|
|
557
|
+
|
|
558
|
+
// A main-area page (Memory, settings, a plugin panel, 轨迹/看板) has no conversation
|
|
559
|
+
// column to measure, so the band is laid out against the page's own content boundary:
|
|
560
|
+
// sit in the gutter right of the content when it is wide enough, otherwise take only
|
|
561
|
+
// the minimum width so as little content as possible is covered.
|
|
562
|
+
function pagePlan(anchors, required, top) {
|
|
563
|
+
const vw = typeof window === 'undefined' ? 0 : window.innerWidth
|
|
564
|
+
const limit = Math.min(vw, anchors && anchors.areaRight ? anchors.areaRight : vw) - GAP
|
|
565
|
+
const desired = Math.min(MAX_PANEL_WIDTH, Math.max(required, lastPlannedWidth || required))
|
|
566
|
+
const contentRight = anchors && anchors.pageRight ? anchors.pageRight : null
|
|
567
|
+
// Default to the width the band had beside the conversation, so switching between a
|
|
568
|
+
// page and a conversation does not visibly resize the card.
|
|
569
|
+
let width = desired
|
|
570
|
+
if (contentRight !== null) {
|
|
571
|
+
const gutter = vw - contentRight - GAP * 2
|
|
572
|
+
// Only a real gutter may shrink it; a full-width page has nowhere to put the band,
|
|
573
|
+
// so keep the familiar width and let the hover dim signal what it covers.
|
|
574
|
+
if (gutter >= required) width = Math.min(desired, gutter)
|
|
575
|
+
}
|
|
576
|
+
return { mode: 'page', pageTop: top, rightEdge: limit, width, limit }
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
function planBand(anchors, required) {
|
|
580
|
+
const vw = typeof window === 'undefined' ? 0 : window.innerWidth
|
|
581
|
+
const areaEdge = Math.min(vw, anchors && anchors.areaRight ? anchors.areaRight : vw)
|
|
582
|
+
const limit = areaEdge - GAP
|
|
583
|
+
// The band only makes sense beside a conversation. Other main-area surfaces (a plugin
|
|
584
|
+
// panel, settings) have no conversation column, no splitter and no turn rail -- with no
|
|
585
|
+
// surface to dock against, the band used to pin itself to the window top-right corner and
|
|
586
|
+
// cover that page. Fall back to the sidebar stack instead.
|
|
587
|
+
const hasSurface = Boolean(anchors) && (
|
|
588
|
+
anchors.tabsSeen === true
|
|
589
|
+
|| (anchors.handleRight !== null && anchors.handleRight !== undefined)
|
|
590
|
+
|| (anchors.areaRight !== null && anchors.areaRight !== undefined)
|
|
591
|
+
|| (anchors.railRight !== null && anchors.railRight !== undefined)
|
|
592
|
+
)
|
|
593
|
+
if (!hasSurface) {
|
|
594
|
+
const t = (anchors && anchors.pageTop) || 56
|
|
595
|
+
return pagePlan(anchors, required, t)
|
|
596
|
+
}
|
|
597
|
+
const hasRail = Boolean(anchors) && anchors.railRight !== null && anchors.railRight !== undefined
|
|
598
|
+
// 轨迹 / 看板 / Codex are conversation views without a turn rail: they keep the band
|
|
599
|
+
// flush to the right edge. But a *conversation* also loses its rail for a moment
|
|
600
|
+
// while history loads, and that is not a view change -- reuse the anchored plan for
|
|
601
|
+
// a short window so the band does not jump to the edge and back.
|
|
602
|
+
if (!hasRail && anchors !== null && anchors.tabsSeen === true) {
|
|
603
|
+
const now = Date.now()
|
|
604
|
+
if (lastAnchoredPlan && now - lastAnchoredAt < STICKY_PLAN_MS) return lastAnchoredPlan
|
|
605
|
+
return pagePlan(anchors, required, anchors.top || 8)
|
|
606
|
+
}
|
|
607
|
+
// A conversation without turns has no rail yet. That is not "no space": the column
|
|
608
|
+
// simply runs to its own right edge, and that edge is the boundary the band must
|
|
609
|
+
// respect. Treating the missing rail as a wall collapsed the band into the sidebar
|
|
610
|
+
// for the first frames of every new conversation, then brought it back when the
|
|
611
|
+
// rail appeared -- the "shrink in and come back" the user saw.
|
|
612
|
+
const innerRight = anchors && anchors.right !== null ? anchors.right : limit
|
|
613
|
+
const inner = anchors && anchors.left !== null ? innerRight - anchors.left : null
|
|
614
|
+
// The whitespace is used where it exists.
|
|
615
|
+
const remember = (plan) => {
|
|
616
|
+
lastAnchoredPlan = plan
|
|
617
|
+
lastAnchoredAt = Date.now()
|
|
618
|
+
if (plan.width) lastPlannedWidth = plan.width
|
|
619
|
+
return plan
|
|
620
|
+
}
|
|
621
|
+
if (inner !== null && inner >= required) {
|
|
622
|
+
return remember({ mode: 'inner', left: anchors.left, width: Math.min(inner, MAX_PANEL_WIDTH), limit })
|
|
623
|
+
}
|
|
624
|
+
const outer = hasRail ? limit - (anchors.railRight + GAP) : null
|
|
625
|
+
if (outer !== null && outer >= required) {
|
|
626
|
+
return remember({ mode: 'outer', rightEdge: limit, width: Math.min(outer, MAX_PANEL_WIDTH), limit })
|
|
627
|
+
}
|
|
628
|
+
// No whitespace wide enough: take the minimum a card needs out of the transcript,
|
|
629
|
+
// and only that much. The card sits flush with the conversation column so it takes
|
|
630
|
+
// the least possible text out of view; covering the turn rail is accepted.
|
|
631
|
+
const rightEdge = limit
|
|
632
|
+
const column = anchors && anchors.areaRight && anchors.areaLeft
|
|
633
|
+
? Math.max(1, anchors.areaRight - anchors.areaLeft)
|
|
634
|
+
: Math.max(1, areaEdge)
|
|
635
|
+
// The card may cover at most half of the conversation column.
|
|
636
|
+
if (required > column * MAX_COVER_RATIO) return { mode: 'fallback', width: 0, limit }
|
|
637
|
+
return remember({ mode: 'intrude', rightEdge, width: required, limit })
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
function RightHost() {
|
|
641
|
+
const all = useRegistry()
|
|
642
|
+
const [anchors, setAnchors] = React.useState(() => measureAnchors())
|
|
643
|
+
const [scrolls, setScrolls] = React.useState(false)
|
|
644
|
+
const stack = React.useRef(null)
|
|
645
|
+
const measureStack = React.useRef(() => {})
|
|
646
|
+
|
|
647
|
+
React.useEffect(() => {
|
|
648
|
+
let raf = 0
|
|
649
|
+
const sync = () => {
|
|
650
|
+
raf = 0
|
|
651
|
+
const next = measureAnchors()
|
|
652
|
+
// measureAnchors() builds a fresh object on every tick; keep the previous one
|
|
653
|
+
// while nothing moved, otherwise every card re-renders four times a second.
|
|
654
|
+
setAnchors((prev) => (sameAnchors(prev, next) ? prev : next))
|
|
655
|
+
// The tick also re-checks the stack: a minimised or occluded window holds
|
|
656
|
+
// ResizeObserver notifications back far longer than the user can see.
|
|
657
|
+
measureStack.current()
|
|
658
|
+
}
|
|
659
|
+
const schedule = () => { if (!raf) raf = requestAnimationFrame(sync) }
|
|
660
|
+
window.addEventListener('resize', schedule)
|
|
661
|
+
const timer = setInterval(schedule, 700)
|
|
662
|
+
return () => {
|
|
663
|
+
window.removeEventListener('resize', schedule)
|
|
664
|
+
clearInterval(timer)
|
|
665
|
+
if (raf) cancelAnimationFrame(raf)
|
|
666
|
+
}
|
|
667
|
+
}, [])
|
|
668
|
+
|
|
669
|
+
const items = all.filter((panel) => sideOf(panel.id, panel.side) === 'right')
|
|
670
|
+
// Default 280 applies only to a panel that declared nothing; a panel that says it
|
|
671
|
+
// can live with 160 gets 160, so it never takes more text than it needs.
|
|
672
|
+
const required = Math.min(MAX_PANEL_WIDTH, Math.max(MIN_WIDTH_FLOOR,
|
|
673
|
+
items.reduce((widest, panel) => Math.max(widest, panel.minWidth || DEFAULT_MIN_WIDTH), 0)))
|
|
674
|
+
const plan = planBand(anchors, required)
|
|
675
|
+
const top = plan.mode === 'page' ? plan.pageTop : (anchors ? anchors.top : 8)
|
|
676
|
+
|
|
677
|
+
// Publish the decision so the sidebar stack can take the cards over.
|
|
678
|
+
React.useEffect(() => { setFallback(plan.mode === 'fallback') })
|
|
679
|
+
|
|
680
|
+
// A stack that fits stays a plain, non-clipping column, because a card may draw
|
|
681
|
+
// outside its own box (its shadow). Scroll only when the cards exceed the column.
|
|
682
|
+
// Cards reach their real height asynchronously (data arrives after mount), and
|
|
683
|
+
// that never re-renders the dock -- so watch the cards themselves.
|
|
684
|
+
React.useEffect(() => {
|
|
685
|
+
const el = stack.current
|
|
686
|
+
const measure = () => {
|
|
687
|
+
if (!el) { setScrolls(false); return }
|
|
688
|
+
const column = Math.max(0, window.innerHeight - 8 - top)
|
|
689
|
+
const next = stackedHeight(el) > column + 0.5
|
|
690
|
+
setScrolls((prev) => (prev === next ? prev : next))
|
|
691
|
+
}
|
|
692
|
+
measureStack.current = measure
|
|
693
|
+
measure()
|
|
694
|
+
if (!el || typeof ResizeObserver === 'undefined') return undefined
|
|
695
|
+
const observer = new ResizeObserver(measure)
|
|
696
|
+
for (const kid of el.children) observer.observe(kid)
|
|
697
|
+
return () => { observer.disconnect(); measureStack.current = () => {} }
|
|
698
|
+
}, [items.length, top])
|
|
699
|
+
|
|
700
|
+
// An empty column must cost nothing: no panels, no strip, no reserved width.
|
|
701
|
+
// The same goes for a column the band cannot hold: the cards moved to the sidebar.
|
|
702
|
+
if (items.length === 0 || plan.mode === 'fallback') return null
|
|
703
|
+
|
|
704
|
+
const width = plan.width
|
|
705
|
+
|
|
706
|
+
const style = {
|
|
707
|
+
position: 'fixed',
|
|
708
|
+
top,
|
|
709
|
+
bottom: 8,
|
|
710
|
+
display: 'flex',
|
|
711
|
+
flexDirection: 'column',
|
|
712
|
+
gap: STACK_GAP,
|
|
713
|
+
minWidth: 0,
|
|
714
|
+
boxSizing: 'border-box',
|
|
715
|
+
overflow: 'visible',
|
|
716
|
+
// The band is a transparent overlay over the transcript's right margin: it
|
|
717
|
+
// must not swallow clicks meant for the conversation behind it.
|
|
718
|
+
pointerEvents: 'none',
|
|
719
|
+
zIndex: 10000,
|
|
720
|
+
}
|
|
721
|
+
style.width = width
|
|
722
|
+
if (plan.mode === 'inner') {
|
|
723
|
+
// The gutter between the transcript handle and the turn rail.
|
|
724
|
+
style.left = plan.left
|
|
725
|
+
} else {
|
|
726
|
+
// Right of the rail (or, before any conversation is measured, the area's edge).
|
|
727
|
+
style.right = Math.max(GAP, window.innerWidth - plan.rightEdge)
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
if (scrolls) {
|
|
731
|
+
// Grow the box by the shadow's reach, pad the same amount back, and only then
|
|
732
|
+
// scroll. Every card keeps the exact rectangle it had; the scrollport's clip
|
|
733
|
+
// line lands in the gutter instead of across a card's shadow.
|
|
734
|
+
const gutter = SHADOW_GUTTER
|
|
735
|
+
style.top = top - gutter
|
|
736
|
+
style.height = Math.max(0, window.innerHeight - 8 - top) + gutter * 2
|
|
737
|
+
style.bottom = 'auto'
|
|
738
|
+
style.width = width + gutter * 2
|
|
739
|
+
if (style.left !== undefined) style.left -= gutter
|
|
740
|
+
if (style.right !== undefined) style.right -= gutter
|
|
741
|
+
style.padding = gutter
|
|
742
|
+
style.overflowY = 'auto'
|
|
743
|
+
style.overflowX = 'hidden'
|
|
744
|
+
// No scrollbar: it would sit in the gutter as a foreign affordance, and a
|
|
745
|
+
// classic scrollbar would also narrow every card by its own width.
|
|
746
|
+
style.scrollbarWidth = 'none'
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
return h('div', {
|
|
750
|
+
'data-panel-dock-strip': '',
|
|
751
|
+
'data-panel-dock-scrolls': scrolls ? '' : undefined,
|
|
752
|
+
ref: stack,
|
|
753
|
+
style,
|
|
754
|
+
}, items.map((panel) => h(CardBoundary, {
|
|
755
|
+
key: panel.id + ':' + revisionOf(panel.id),
|
|
756
|
+
id: panel.id,
|
|
757
|
+
fallback: () => errorCard(panel),
|
|
758
|
+
}, renderPanel(panel))))
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
|
|
762
|
+
// ---- tray (portal transport) ----
|
|
763
|
+
// Moving a card between the sidebar and the band must not remount it: a data card
|
|
764
|
+
// would refetch and flash. So each card lives in a portal whose *container* is moved
|
|
765
|
+
// in the DOM (appendChild / insertBefore) instead of being recreated. React keeps the
|
|
766
|
+
// subtree mounted across a DOM move -- measured on a live card: content and data stay,
|
|
767
|
+
// loading never flips back on.
|
|
768
|
+
const tray = { cells: new Map(), leftSlot: null, leftStack: null, poke: null }
|
|
769
|
+
|
|
770
|
+
function cellOf(id) {
|
|
771
|
+
let el = tray.cells.get(id)
|
|
772
|
+
if (!el) {
|
|
773
|
+
el = document.createElement('div')
|
|
774
|
+
el.setAttribute('data-panel-dock-cell', id)
|
|
775
|
+
// The card is the visible rectangle; the cell is only a transport box.
|
|
776
|
+
el.style.cssText = 'display:flex;flex-direction:column;flex:0 0 auto;min-width:0;pointer-events:none'
|
|
777
|
+
tray.cells.set(id, el)
|
|
778
|
+
}
|
|
779
|
+
return el
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
function dropDeadCells(alive) {
|
|
783
|
+
for (const [id, el] of [...tray.cells]) {
|
|
784
|
+
if (alive.has(id)) continue
|
|
785
|
+
if (el.parentNode) el.parentNode.removeChild(el)
|
|
786
|
+
tray.cells.delete(id)
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
// ---- deck: same-side cards as a stack (one full card + 24px peek strips) ----
|
|
791
|
+
// Column behaviour up to 0.6.13 is a plain list. A deck trades height for order:
|
|
792
|
+
// every rear card shows only its top strip and the wheel shuffles the front one.
|
|
793
|
+
// WeChat's stacked card set (公众号/收藏 的「堆叠态」): each card behind sits a little
|
|
794
|
+
// higher and to the right, very slightly rotated and scaled, so the stack reads as
|
|
795
|
+
// physical cards rather than tabs. Values are deliberately small -- at 3 cards the
|
|
796
|
+
// whole fan is only a couple of degrees wide.
|
|
797
|
+
// Mostly horizontal: the stack fans to the right, so a card going to the back reads as
|
|
798
|
+
// sliding sideways (WeChat's stack does), not as sliding up or down.
|
|
799
|
+
// The step must clear the card radius, otherwise a rear card can only be clipped by
|
|
800
|
+
// slicing through its rounded corner (5px step vs 12px radius = the "dirty corner").
|
|
801
|
+
// 14px is the smallest step that keeps a whole corner and still reads as a stack.
|
|
802
|
+
// Measured from WeChat 4.2 (60 s window recording, 10 fps): behind the upright front card
|
|
803
|
+
// the pile peeks on the LEFT, each card tilted about 2 degrees, so the visible sliver is a
|
|
804
|
+
// thin diagonal strip rather than a straight band. The band is 14px tall to clear the radius.
|
|
805
|
+
const DECK_STEP_Y = 14
|
|
806
|
+
const DECK_STEP_X = 18
|
|
807
|
+
// The operator's call: keep the flow offsets, no tilt at all. Every card stays upright.
|
|
808
|
+
const DECK_REAR_TILT = 0
|
|
809
|
+
const DECK_ROT = 0.7
|
|
810
|
+
const DECK_SCALE_STEP = 0.014
|
|
811
|
+
// The sidebar keeps the flat tab stack; its step is a readable strip, not a fan.
|
|
812
|
+
const DECK_LEFT_PEEK = 24
|
|
813
|
+
const DECK_PEEK = DECK_LEFT_PEEK
|
|
814
|
+
const DECK_KEY = 'dsh.panel-dock.deck'
|
|
815
|
+
// Which card sits in front is the user's choice, so it outlives the module: a page
|
|
816
|
+
// reload, a client hot-reload or a card that unmounts for a moment all used to drop it
|
|
817
|
+
// back to "lowest order wins", which read as the stack resetting itself at random.
|
|
818
|
+
const DECK_FRONT_KEY = 'dsh.panel-dock.front'
|
|
819
|
+
const loadFront = () => {
|
|
820
|
+
try {
|
|
821
|
+
const raw = localStorage.getItem(DECK_FRONT_KEY)
|
|
822
|
+
const parsed = raw ? JSON.parse(raw) : null
|
|
823
|
+
return parsed && typeof parsed === 'object' ? parsed : {}
|
|
824
|
+
} catch { return {} }
|
|
825
|
+
}
|
|
826
|
+
const savedFront = loadFront()
|
|
827
|
+
const deck = {
|
|
828
|
+
on: null,
|
|
829
|
+
front: { band: savedFront.band || null, left: savedFront.left || null },
|
|
830
|
+
order: { band: null, left: null },
|
|
831
|
+
resync: null, wheelAt: 0, leaving: { band: null, left: null },
|
|
832
|
+
leavingAnim: { band: null, left: null },
|
|
833
|
+
}
|
|
834
|
+
function rememberFront(key, id) {
|
|
835
|
+
if (deck.front[key] === id) return
|
|
836
|
+
deck.front[key] = id
|
|
837
|
+
try {
|
|
838
|
+
localStorage.setItem(DECK_FRONT_KEY, JSON.stringify({ band: deck.front.band, left: deck.front.left }))
|
|
839
|
+
} catch {}
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
function deckOn() {
|
|
843
|
+
if (deck.on === null) {
|
|
844
|
+
try { deck.on = localStorage.getItem(DECK_KEY) === '1' } catch { deck.on = false }
|
|
845
|
+
}
|
|
846
|
+
return deck.on
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
function setDeckMode(next) {
|
|
850
|
+
if (deckOn() === next) return
|
|
851
|
+
deck.on = next
|
|
852
|
+
try { localStorage.setItem(DECK_KEY, next ? '1' : '0') } catch {}
|
|
853
|
+
if (deck.resync) deck.resync()
|
|
854
|
+
if (tray.poke) tray.poke()
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
function deckKeyOf(container) {
|
|
858
|
+
return container && container.hasAttribute('data-panel-dock-strip') ? 'band' : 'left'
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
function cellAt(container, index) {
|
|
862
|
+
const cells = []
|
|
863
|
+
for (const kid of container.children) {
|
|
864
|
+
if (kid.hasAttribute && kid.hasAttribute('data-panel-dock-cell')) cells.push(kid)
|
|
865
|
+
}
|
|
866
|
+
return cells[index] || null
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
function deckBarOf(container) {
|
|
870
|
+
for (const kid of container.children) {
|
|
871
|
+
if (kid.hasAttribute && kid.hasAttribute('data-panel-dock-deck-bar')) return kid
|
|
872
|
+
}
|
|
873
|
+
return null
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
// The affordance is the card edge itself: a narrow strip that drops into a gradient
|
|
877
|
+
// band with three travelling chevrons when the pointer arrives. It is absolutely
|
|
878
|
+
// positioned so it never takes part in the column's flow.
|
|
879
|
+
function ensureDeckBar(container) {
|
|
880
|
+
let bar = deckBarOf(container)
|
|
881
|
+
if (bar) return bar
|
|
882
|
+
// The strip is positioned against this column: without a positioning context it
|
|
883
|
+
// resolved against the viewport and sat at y=-6, off screen (measured).
|
|
884
|
+
if (typeof getComputedStyle === 'function') {
|
|
885
|
+
const position = getComputedStyle(container).position
|
|
886
|
+
if (position === 'static') container.style.position = 'relative'
|
|
887
|
+
}
|
|
888
|
+
bar = document.createElement('div')
|
|
889
|
+
bar.setAttribute('data-panel-dock-deck-bar', '')
|
|
890
|
+
bar.setAttribute('role', 'button')
|
|
891
|
+
bar.setAttribute('tabindex', '-1')
|
|
892
|
+
bar.setAttribute('aria-label', '堆叠 / 并列')
|
|
893
|
+
bar.setAttribute('title', '堆叠 / 并列')
|
|
894
|
+
bar.appendChild(document.createElement('i'))
|
|
895
|
+
bar.appendChild(document.createElement('i'))
|
|
896
|
+
bar.appendChild(document.createElement('i'))
|
|
897
|
+
bar.addEventListener('click', (event) => {
|
|
898
|
+
event.preventDefault()
|
|
899
|
+
event.stopPropagation()
|
|
900
|
+
setDeckMode(!deckOn())
|
|
901
|
+
})
|
|
902
|
+
container.appendChild(bar)
|
|
903
|
+
return bar
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
function rotateDeck(container, step) {
|
|
907
|
+
const key = deckKeyOf(container)
|
|
908
|
+
const order = deck.order[key]
|
|
909
|
+
if (!order || order.length < 2) return
|
|
910
|
+
const at = order.indexOf(deck.front[key])
|
|
911
|
+
const from = at < 0 ? 0 : at
|
|
912
|
+
const next = (from + step + order.length) % order.length
|
|
913
|
+
// The card being replaced first leans out to the left and dims (the "turning over"
|
|
914
|
+
// beat), then drops to the back of the stack; everything else moves up one slot.
|
|
915
|
+
deck.leaving[key] = { id: order[from], until: Date.now() + 170, dir: step >= 0 ? 1 : -1 }
|
|
916
|
+
rememberFront(key, order[next])
|
|
917
|
+
if (deck.resync) deck.resync()
|
|
918
|
+
window.setTimeout(() => {
|
|
919
|
+
if (deck.leaving[key] && Date.now() >= deck.leaving[key].until) {
|
|
920
|
+
deck.leaving[key] = null
|
|
921
|
+
if (deck.resync) deck.resync()
|
|
922
|
+
}
|
|
923
|
+
}, 180)
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
function wireDeckInput(container) {
|
|
927
|
+
if (!container || container.__pdDeckWired) return
|
|
928
|
+
container.__pdDeckWired = true
|
|
929
|
+
container.addEventListener('wheel', (event) => {
|
|
930
|
+
if (!deckOn()) return
|
|
931
|
+
const key = deckKeyOf(container)
|
|
932
|
+
const order = deck.order[key]
|
|
933
|
+
if (!order || order.length < 2) return
|
|
934
|
+
event.preventDefault()
|
|
935
|
+
event.stopPropagation()
|
|
936
|
+
const now = Date.now()
|
|
937
|
+
if (now - deck.wheelAt < 130) return
|
|
938
|
+
deck.wheelAt = now
|
|
939
|
+
rotateDeck(container, event.deltaY > 0 ? 1 : -1)
|
|
940
|
+
}, { passive: false })
|
|
941
|
+
// A click on a rear card's strip promotes that card instead of reaching the card.
|
|
942
|
+
container.addEventListener('pointerdown', (event) => {
|
|
943
|
+
if (!deckOn()) return
|
|
944
|
+
const key = deckKeyOf(container)
|
|
945
|
+
const order = deck.order[key]
|
|
946
|
+
if (!order || order.length < 2) return
|
|
947
|
+
// Anything interactive keeps its own behaviour: only the front card is live (the
|
|
948
|
+
// rest are inert), so a side-toggle press must never be swallowed here.
|
|
949
|
+
const hit = event.target && event.target.closest
|
|
950
|
+
? event.target.closest('button,a,input,select,textarea,[role="button"],[data-panel-dock-toggle]')
|
|
951
|
+
: null
|
|
952
|
+
if (hit) return
|
|
953
|
+
const box = container.getBoundingClientRect()
|
|
954
|
+
const y = event.clientY - box.top
|
|
955
|
+
const slot = Math.floor(y / DECK_STEP_Y)
|
|
956
|
+
if (slot < 0 || slot >= order.length - 1) return
|
|
957
|
+
const target = order[order.length - 1 - slot]
|
|
958
|
+
event.preventDefault()
|
|
959
|
+
event.stopPropagation()
|
|
960
|
+
rememberFront(key, target)
|
|
961
|
+
if (deck.resync) deck.resync()
|
|
962
|
+
}, true)
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
// The strip must sit on the front card's own rectangle. It is positioned during the
|
|
966
|
+
// layout pass, but by then the front card may still be animating into place (measured:
|
|
967
|
+
// bar at y=121 while the front card had settled at 131), so this re-runs after the
|
|
968
|
+
// transitions land.
|
|
969
|
+
function alignDeckBar(container) {
|
|
970
|
+
if (!container || !container.hasAttribute('data-panel-dock-deck')) return
|
|
971
|
+
const key = deckKeyOf(container)
|
|
972
|
+
const order = deck.order[key]
|
|
973
|
+
const bar = deckBarOf(container)
|
|
974
|
+
if (!order || !order.length || !bar) return
|
|
975
|
+
const front = tray.cells.get(order[0])
|
|
976
|
+
if (!front) return
|
|
977
|
+
const containerBox = container.getBoundingClientRect()
|
|
978
|
+
const frontBox = front.getBoundingClientRect()
|
|
979
|
+
if (!frontBox.width) return
|
|
980
|
+
bar.style.top = Math.round(frontBox.top - containerBox.top) + 'px'
|
|
981
|
+
bar.style.left = Math.round(frontBox.left - containerBox.left) + 'px'
|
|
982
|
+
bar.style.right = 'auto'
|
|
983
|
+
bar.style.width = Math.round(frontBox.width) + 'px'
|
|
984
|
+
}
|
|
985
|
+
|
|
986
|
+
// Cards reach their real height asynchronously (data arrives after mount) and never
|
|
987
|
+
// re-render the dock, so the deck height has to follow the front card's size.
|
|
988
|
+
function refreshDeckHeight(container) {
|
|
989
|
+
if (!container || !container.hasAttribute('data-panel-dock-deck')) return
|
|
990
|
+
const key = deckKeyOf(container)
|
|
991
|
+
const order = deck.order[key]
|
|
992
|
+
if (!order || !order.length) return
|
|
993
|
+
const front = tray.cells.get(order[0])
|
|
994
|
+
if (!front) return
|
|
995
|
+
alignDeckBar(container)
|
|
996
|
+
const frontHeight = Math.round(front.getBoundingClientRect().height)
|
|
997
|
+
if (!frontHeight) return
|
|
998
|
+
// Same rule as syncDeck: the box ends at the lowest card bottom, using each cell's real
|
|
999
|
+
// offset inside the container (a card's own height alone over-counts by its step).
|
|
1000
|
+
const step = container.hasAttribute('data-panel-dock-strip') ? DECK_STEP_Y : DECK_PEEK
|
|
1001
|
+
let bottom = frontHeight
|
|
1002
|
+
let tallest = frontHeight
|
|
1003
|
+
const containerTop = container.getBoundingClientRect().top
|
|
1004
|
+
for (const id of order) {
|
|
1005
|
+
const cell = tray.cells.get(id)
|
|
1006
|
+
if (!cell) continue
|
|
1007
|
+
const box = cell.getBoundingClientRect()
|
|
1008
|
+
if (!box.height) continue
|
|
1009
|
+
tallest = Math.max(tallest, Math.round(box.height))
|
|
1010
|
+
bottom = Math.max(bottom, Math.round(box.bottom - containerTop))
|
|
1011
|
+
}
|
|
1012
|
+
deck.stackHeights = deck.stackHeights || {}
|
|
1013
|
+
deck.stackHeights[key] = tallest
|
|
1014
|
+
const total = bottom
|
|
1015
|
+
const box = container.getBoundingClientRect()
|
|
1016
|
+
const room = box.top > 0 ? Math.max(0, Math.round(window.innerHeight - box.top - 8)) : 0
|
|
1017
|
+
// Only the band may cap: it has a fixed top. The sidebar stack is bottom-anchored,
|
|
1018
|
+
// so capping by (innerHeight - top) feeds back on itself -- smaller height pushes
|
|
1019
|
+
// the top down, which shrinks the room again (measured: 268px content collapsed to
|
|
1020
|
+
// an overflowing 201px box).
|
|
1021
|
+
const capped = container.hasAttribute('data-panel-dock-strip') && room > 0 && total > room
|
|
1022
|
+
const next = (capped ? room : total) + 'px'
|
|
1023
|
+
if (container.style.height !== next) container.style.height = next
|
|
1024
|
+
const overflow = capped ? 'auto' : ''
|
|
1025
|
+
if (container.style.overflowY !== overflow) container.style.overflowY = overflow
|
|
1026
|
+
}
|
|
1027
|
+
|
|
1028
|
+
function watchDeckCells(container) {
|
|
1029
|
+
if (!container || typeof ResizeObserver === 'undefined') return
|
|
1030
|
+
if (!container.__pdDeckObserver) {
|
|
1031
|
+
container.__pdDeckObserver = new ResizeObserver(() => refreshDeckHeight(container))
|
|
1032
|
+
}
|
|
1033
|
+
const observer = container.__pdDeckObserver
|
|
1034
|
+
const seen = container.__pdDeckSeen || new Set()
|
|
1035
|
+
for (const kid of container.children) {
|
|
1036
|
+
if (!kid.hasAttribute || !kid.hasAttribute('data-panel-dock-cell')) continue
|
|
1037
|
+
if (seen.has(kid)) continue
|
|
1038
|
+
seen.add(kid)
|
|
1039
|
+
observer.observe(kid)
|
|
1040
|
+
}
|
|
1041
|
+
container.__pdDeckSeen = seen
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
function syncDeck(container, ids, active) {
|
|
1045
|
+
if (!container) return
|
|
1046
|
+
wireDeckInput(container)
|
|
1047
|
+
const key = deckKeyOf(container)
|
|
1048
|
+
const usable = active && deckOn() && ids.length >= 2
|
|
1049
|
+
const bar = ensureDeckBar(container)
|
|
1050
|
+
if (!usable) {
|
|
1051
|
+
deck.order[key] = null
|
|
1052
|
+
container.removeAttribute('data-panel-dock-deck')
|
|
1053
|
+
container.style.perspective = ''
|
|
1054
|
+
container.style.transformStyle = ''
|
|
1055
|
+
container.style.height = ''
|
|
1056
|
+
bar.removeAttribute('data-panel-dock-deck-on')
|
|
1057
|
+
if (bar) {
|
|
1058
|
+
if (ids.length >= 2) bar.removeAttribute('data-panel-dock-hidden')
|
|
1059
|
+
else bar.setAttribute('data-panel-dock-hidden', '')
|
|
1060
|
+
bar.style.top = '0'
|
|
1061
|
+
bar.style.left = '0'
|
|
1062
|
+
bar.style.right = '0'
|
|
1063
|
+
bar.style.width = ''
|
|
1064
|
+
}
|
|
1065
|
+
container.style.overflowY = ''
|
|
1066
|
+
container.style.flex = ''
|
|
1067
|
+
for (const id of ids) {
|
|
1068
|
+
const el = tray.cells.get(id)
|
|
1069
|
+
if (!el) continue
|
|
1070
|
+
el.style.position = ''
|
|
1071
|
+
el.style.left = ''
|
|
1072
|
+
el.style.right = ''
|
|
1073
|
+
el.style.top = ''
|
|
1074
|
+
el.style.transform = ''
|
|
1075
|
+
el.style.zIndex = ''
|
|
1076
|
+
el.style.clipPath = ''
|
|
1077
|
+
el.style.opacity = ''
|
|
1078
|
+
el.style.transition = ''
|
|
1079
|
+
el.style.transformOrigin = ''
|
|
1080
|
+
el.removeAttribute('data-panel-dock-rear')
|
|
1081
|
+
const frame = el.firstElementChild
|
|
1082
|
+
if (frame && frame.hasAttribute && frame.hasAttribute('data-panel-dock-frame')) {
|
|
1083
|
+
frame.style.boxShadow = FRAME_STYLE.boxShadow
|
|
1084
|
+
}
|
|
1085
|
+
// (fill is per side, via CSS: sidebar #fff on a #f9fafb column, band #f9fafb on
|
|
1086
|
+
// a #fff page -- the operator's contrast-by-inversion, not a border)
|
|
1087
|
+
}
|
|
1088
|
+
return
|
|
1089
|
+
}
|
|
1090
|
+
const wechat = container.hasAttribute('data-panel-dock-strip')
|
|
1091
|
+
container.setAttribute('data-panel-dock-deck', '')
|
|
1092
|
+
// Keep the pile FLAT: with `preserve-3d` the browser sorts the cards by their Z
|
|
1093
|
+
// depth instead of by z-index, and a card that swings through a Z offset during the
|
|
1094
|
+
// flip gets painted under the whole pile (then snaps back when the animation ends).
|
|
1095
|
+
container.style.perspective = ''
|
|
1096
|
+
container.style.transformStyle = ''
|
|
1097
|
+
bar.setAttribute('data-panel-dock-deck-on', '')
|
|
1098
|
+
// The "hidden" flag is set when a side has fewer than two cards; nothing used to
|
|
1099
|
+
// clear it when cards arrived later, so the strip stayed display:none forever
|
|
1100
|
+
// (measured: 2 cards in the band, bar rect 0x0, hidden=true).
|
|
1101
|
+
bar.removeAttribute('data-panel-dock-hidden')
|
|
1102
|
+
let front = deck.front[key]
|
|
1103
|
+
// Only fall back when the remembered card is *gone from the dock*, and remember the
|
|
1104
|
+
// fallback so the order stops flickering between two choices while ids settle.
|
|
1105
|
+
if (!front || ids.indexOf(front) < 0) {
|
|
1106
|
+
front = ids[0]
|
|
1107
|
+
rememberFront(key, front)
|
|
1108
|
+
} else {
|
|
1109
|
+
deck.front[key] = front
|
|
1110
|
+
}
|
|
1111
|
+
const start = ids.indexOf(front)
|
|
1112
|
+
const order = ids.slice(start).concat(ids.slice(0, start))
|
|
1113
|
+
deck.order[key] = order
|
|
1114
|
+
let frontHeight = 0
|
|
1115
|
+
const heights = new Map()
|
|
1116
|
+
const leaving = deck.leaving[key]
|
|
1117
|
+
const leavingLive = Boolean(leaving && leaving.id && Date.now() < leaving.until)
|
|
1118
|
+
// Wheel down sends the front card out towards "backwards" of the stack (left / down);
|
|
1119
|
+
// wheel up mirrors it (right / up). Same beat, opposite direction.
|
|
1120
|
+
const leavingDir = leaving && leaving.dir < 0 ? -1 : 1
|
|
1121
|
+
const n = order.length
|
|
1122
|
+
order.forEach((id, position) => {
|
|
1123
|
+
const el = tray.cells.get(id)
|
|
1124
|
+
if (!el) return
|
|
1125
|
+
el.style.position = 'absolute'
|
|
1126
|
+
el.style.left = '0'
|
|
1127
|
+
el.style.right = '0'
|
|
1128
|
+
el.style.top = '0'
|
|
1129
|
+
el.style.transformOrigin = '50% 0%'
|
|
1130
|
+
el.style.zIndex = String(200 - position)
|
|
1131
|
+
const isLeaving = leavingLive && leaving.id === id && position !== 0
|
|
1132
|
+
if (isLeaving && wechat) {
|
|
1133
|
+
// Slide out to the LEFT while shrinking, then settle at the back of the stack.
|
|
1134
|
+
// A CSS transition cannot turn a corner mid-flight (it interpolates straight to
|
|
1135
|
+
// the target), which is why the card used to shrink in place; a keyframe
|
|
1136
|
+
// animation with a midpoint gives the "toss it back under the pile" arc.
|
|
1137
|
+
const slotTransform =
|
|
1138
|
+
'translate3d(' + (-position * DECK_STEP_X) + 'px,' +
|
|
1139
|
+
((n - 1 - position) * DECK_STEP_Y) + 'px,0)' +
|
|
1140
|
+
' rotate(' + (-position * DECK_REAR_TILT) + 'deg)'
|
|
1141
|
+
el.style.transition = 'none'
|
|
1142
|
+
el.style.transform = slotTransform
|
|
1143
|
+
el.style.opacity = '1'
|
|
1144
|
+
// Guard on playState, not on "an animation object exists": a cancelled or
|
|
1145
|
+
// finished animation never clears the slot when its element is re-created, and
|
|
1146
|
+
// every later rotation was silently skipped (measured: no 380ms animation in
|
|
1147
|
+
// document.getAnimations() after the first click).
|
|
1148
|
+
const running = deck.leavingAnim[key]
|
|
1149
|
+
const busy = running && running.playState === 'running'
|
|
1150
|
+
if (el.animate && !busy) {
|
|
1151
|
+
const width = el.offsetWidth || 300
|
|
1152
|
+
const frontTop = (n - 1) * DECK_STEP_Y
|
|
1153
|
+
const anim = el.animate([
|
|
1154
|
+
{ transform: 'translate3d(0px,' + frontTop + 'px,0)', opacity: 1, offset: 0 },
|
|
1155
|
+
{
|
|
1156
|
+
// The card leans TOWARDS the way it is travelling: moving left tilts the top
|
|
1157
|
+
// edge left (negative CSS rotation), moving right tilts it right. The old
|
|
1158
|
+
// mirror kept the tilt on the opposite side of the motion, which is what
|
|
1159
|
+
// "the angle is wrong when it flips left/right" was about.
|
|
1160
|
+
transform: 'translate3d(' + Math.round(leavingDir * -width * 0.42) + 'px,' +
|
|
1161
|
+
(frontTop + 10) + 'px,-150px) rotateY(' + (leavingDir * -16) + 'deg) rotate(' +
|
|
1162
|
+
(leavingDir * -6) + 'deg) scale(.86)',
|
|
1163
|
+
opacity: 0.85,
|
|
1164
|
+
offset: 0.5,
|
|
1165
|
+
},
|
|
1166
|
+
{ transform: slotTransform, opacity: 1, offset: 1 },
|
|
1167
|
+
], { duration: 380, easing: 'cubic-bezier(.3,.7,.25,1)' })
|
|
1168
|
+
deck.leavingAnim[key] = anim
|
|
1169
|
+
anim.onfinish = () => {
|
|
1170
|
+
deck.leavingAnim[key] = null
|
|
1171
|
+
try { anim.cancel() } catch (e) {}
|
|
1172
|
+
el.style.transition = 'transform 260ms cubic-bezier(.2,.9,.25,1),opacity 160ms ease'
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1175
|
+
} else if (isLeaving) {
|
|
1176
|
+
// Sidebar mirrors WeChat vertically: the front card slides DOWN while shrinking,
|
|
1177
|
+
// then settles at the back (the top strip). Same keyframe trick as the band --
|
|
1178
|
+
// a transition would interpolate straight to the target and read as "shrinking
|
|
1179
|
+
// in place", which is what the user complained about.
|
|
1180
|
+
const slotTransform = 'translateY(' + ((n - 1 - position) * DECK_PEEK) + 'px)'
|
|
1181
|
+
el.style.transition = 'none'
|
|
1182
|
+
el.style.transform = slotTransform
|
|
1183
|
+
el.style.opacity = '1'
|
|
1184
|
+
const running = deck.leavingAnim[key]
|
|
1185
|
+
const busy = running && running.playState === 'running'
|
|
1186
|
+
if (el.animate && !busy) {
|
|
1187
|
+
const height = el.offsetHeight || 160
|
|
1188
|
+
const frontTop = (n - 1) * DECK_PEEK
|
|
1189
|
+
const anim = el.animate([
|
|
1190
|
+
{ transform: 'translateY(' + frontTop + 'px)', opacity: 1, offset: 0 },
|
|
1191
|
+
{
|
|
1192
|
+
transform: 'translateY(' +
|
|
1193
|
+
(frontTop + leavingDir * Math.round(height * 0.34)) + 'px) scale(.9)',
|
|
1194
|
+
opacity: 0.9,
|
|
1195
|
+
offset: 0.5,
|
|
1196
|
+
},
|
|
1197
|
+
{ transform: slotTransform, opacity: 1, offset: 1 },
|
|
1198
|
+
], { duration: 360, easing: 'cubic-bezier(.3,.7,.25,1)' })
|
|
1199
|
+
deck.leavingAnim[key] = anim
|
|
1200
|
+
anim.onfinish = () => {
|
|
1201
|
+
deck.leavingAnim[key] = null
|
|
1202
|
+
try { anim.cancel() } catch (e) {}
|
|
1203
|
+
el.style.transition = 'transform 220ms cubic-bezier(.2,.8,.2,1),opacity 160ms ease'
|
|
1204
|
+
}
|
|
1205
|
+
}
|
|
1206
|
+
} else if (wechat) {
|
|
1207
|
+
// Right band: a physical stack -- cards behind sit right, very slightly up and
|
|
1208
|
+
// pushed back on Z so the perspective does the shrinking, with a small Y-fan.
|
|
1209
|
+
// Cards that have been pushed back sit at the BACK-LEFT, not back-right, and the
|
|
1210
|
+
// front card stays perfectly upright (position 0 => no rotation, no scale).
|
|
1211
|
+
// The cascade: back-left by DECK_STEP_X a level, up by DECK_STEP_Y a level. Aligned
|
|
1212
|
+
// corner modes were tried and dropped -- with a front card twice as tall as a rear
|
|
1213
|
+
// one, a pinned corner hides the short cards completely.
|
|
1214
|
+
const x = -position * DECK_STEP_X
|
|
1215
|
+
const y = (n - 1 - position) * DECK_STEP_Y
|
|
1216
|
+
el.style.transformOrigin = '50% 0%'
|
|
1217
|
+
el.style.transition = 'transform 260ms cubic-bezier(.2,.9,.25,1),opacity 160ms ease'
|
|
1218
|
+
el.style.transform =
|
|
1219
|
+
'translate3d(' + x + 'px,' + y + 'px,0)' +
|
|
1220
|
+
' rotate(' + (-position * DECK_REAR_TILT) + 'deg)'
|
|
1221
|
+
el.style.opacity = '1'
|
|
1222
|
+
} else {
|
|
1223
|
+
// Sidebar: narrow and never overlapping the transcript, so it keeps the flat
|
|
1224
|
+
// strip stack (one full card + 24px tabs) instead of a fan.
|
|
1225
|
+
el.style.transition = 'transform 220ms cubic-bezier(.2,.8,.2,1),opacity 160ms ease'
|
|
1226
|
+
el.style.transform = 'translateY(' + ((n - 1 - position) * DECK_PEEK) + 'px)'
|
|
1227
|
+
el.style.opacity = '1'
|
|
1228
|
+
}
|
|
1229
|
+
// Nothing is clipped: in a real pile a short card on top does not shorten the long
|
|
1230
|
+
// one underneath, it just covers part of it. The cards are fully drawn and the
|
|
1231
|
+
// z-order does the covering; the container is sized to the tallest card so the
|
|
1232
|
+
// long one's bottom still lands inside the visible area.
|
|
1233
|
+
el.style.clipPath = ''
|
|
1234
|
+
heights.set(id, el.offsetHeight)
|
|
1235
|
+
// Only the front card is live. The rear cards keep hit-testing (a press on a
|
|
1236
|
+
// strip promotes that card) but every control inside them is disabled by CSS,
|
|
1237
|
+
// so the side-toggle of a card behind cannot switch sides any more.
|
|
1238
|
+
if (position === 0) el.removeAttribute('data-panel-dock-rear')
|
|
1239
|
+
else el.setAttribute('data-panel-dock-rear', '')
|
|
1240
|
+
const frame = el.firstElementChild
|
|
1241
|
+
if (frame && frame.hasAttribute && frame.hasAttribute('data-panel-dock-frame')) {
|
|
1242
|
+
const dark = hostIsDark()
|
|
1243
|
+
if (dark) frame.setAttribute('data-pd-dark', '')
|
|
1244
|
+
else frame.removeAttribute('data-pd-dark')
|
|
1245
|
+
frame.style.boxShadow = dark
|
|
1246
|
+
? (position === 0 ? '0 8px 20px 0 rgba(0,0,0,0.62)' : '0 2px 8px 0 rgba(0,0,0,0.46)')
|
|
1247
|
+
: (position === 0 ? '0 8px 20px 0 rgba(0,0,0,0.16)' : '0 2px 8px 0 rgba(0,0,0,0.12)')
|
|
1248
|
+
}
|
|
1249
|
+
if (position === 0) frontHeight = el.offsetHeight
|
|
1250
|
+
})
|
|
1251
|
+
const step = wechat ? DECK_STEP_Y : DECK_PEEK
|
|
1252
|
+
|
|
1253
|
+
// The affordance belongs to the card the user is looking at, not to the column:
|
|
1254
|
+
// align it with the front card's own rectangle (it used to start at the deepest
|
|
1255
|
+
// rear card's top edge, so it floated above the stack).
|
|
1256
|
+
const frontCell = tray.cells.get(order[0])
|
|
1257
|
+
if (bar && frontCell) {
|
|
1258
|
+
const containerBox = container.getBoundingClientRect()
|
|
1259
|
+
const frontBox = frontCell.getBoundingClientRect()
|
|
1260
|
+
bar.style.top = Math.round(frontBox.top - containerBox.top) + 'px'
|
|
1261
|
+
bar.style.left = Math.round(frontBox.left - containerBox.left) + 'px'
|
|
1262
|
+
bar.style.right = 'auto'
|
|
1263
|
+
bar.style.width = Math.round(frontBox.width) + 'px'
|
|
1264
|
+
bar.style.borderRadius = '12px 12px 0 0'
|
|
1265
|
+
}
|
|
1266
|
+
// The stack is as tall as its TALLEST card, not as tall as the front one: otherwise
|
|
1267
|
+
// a tall card promoted to the front was clipped by a container sized for a short
|
|
1268
|
+
// predecessor, and the column jumped on every rotation. Left and right stacks keep
|
|
1269
|
+
// their own maximum.
|
|
1270
|
+
// The container ends where the LOWEST card bottom ends, computed from each card's own
|
|
1271
|
+
// offset: "tallest + (n-1)*step" double-counted, because the front card already sits
|
|
1272
|
+
// (n-1)*step further down. In the sidebar that surplus showed up as dead space between
|
|
1273
|
+
// the stack and the account row.
|
|
1274
|
+
let bottom = 0
|
|
1275
|
+
order.forEach((id, position) => {
|
|
1276
|
+
const h = heights.get(id) || 0
|
|
1277
|
+
if (h > 0) bottom = Math.max(bottom, (n - 1 - position) * step + h)
|
|
1278
|
+
})
|
|
1279
|
+
// The front card is translated by 0 (position 0), so it contributes its own height only.
|
|
1280
|
+
bottom = Math.max(bottom, frontHeight)
|
|
1281
|
+
const tallest = frontHeight
|
|
1282
|
+
deck.stackHeights = deck.stackHeights || {}
|
|
1283
|
+
deck.stackHeights[key] = tallest
|
|
1284
|
+
const total = bottom
|
|
1285
|
+
deck.frontHeights = deck.frontHeights || {}
|
|
1286
|
+
deck.frontHeights[key] = frontHeight
|
|
1287
|
+
const box = container.getBoundingClientRect()
|
|
1288
|
+
const room = box.top > 0 ? Math.max(0, Math.round(window.innerHeight - box.top - 8)) : 0
|
|
1289
|
+
// A deck taller than the column still has to be reachable; cap and scroll rather
|
|
1290
|
+
// than push the rear strips off the top of the screen.
|
|
1291
|
+
const capped = wechat && room > 0 && total > room
|
|
1292
|
+
container.style.height = total > 0 ? (capped ? room : total) + 'px' : ''
|
|
1293
|
+
container.style.overflowY = capped ? 'auto' : ''
|
|
1294
|
+
watchDeckCells(container)
|
|
1295
|
+
// The sidebar stack is a flex child sized to 100%; with an explicit height it has
|
|
1296
|
+
// to opt out or the host's basis wins.
|
|
1297
|
+
container.style.flex = container.hasAttribute('data-panel-dock-left') ? '0 0 auto' : ''
|
|
1298
|
+
// The new front card is measured before its un-clipped paint settles; without these
|
|
1299
|
+
// two follow-ups a tall card stayed visually cut until an unrelated resize.
|
|
1300
|
+
if (typeof requestAnimationFrame === 'function') requestAnimationFrame(() => refreshDeckHeight(container))
|
|
1301
|
+
window.setTimeout(() => refreshDeckHeight(container), 260)
|
|
1302
|
+
}
|
|
1303
|
+
|
|
1304
|
+
function leftStackNode() {
|
|
1305
|
+
if (!tray.leftStack) {
|
|
1306
|
+
const el = document.createElement('div')
|
|
1307
|
+
el.setAttribute('data-panel-dock-left', '')
|
|
1308
|
+
el.style.cssText = [
|
|
1309
|
+
'display:flex', 'flex-direction:column', 'gap:' + STACK_GAP + 'px',
|
|
1310
|
+
'flex:0 0 100%', 'width:100%', 'min-width:0', 'box-sizing:border-box',
|
|
1311
|
+
].join(';')
|
|
1312
|
+
tray.leftStack = el
|
|
1313
|
+
}
|
|
1314
|
+
return tray.leftStack
|
|
1315
|
+
}
|
|
1316
|
+
|
|
1317
|
+
// The sidebar column does not scroll on its own: the host lays it out with
|
|
1318
|
+
// overflow:visible and simply clips at the window edge, so a stack taller than the
|
|
1319
|
+
// space below it hides its last cards with no way to reach them (verified at
|
|
1320
|
+
// 1280x560: last card bottom 567 in a 560px viewport, no scrollable ancestor).
|
|
1321
|
+
// Cap the stack at the room that actually exists and let it scroll instead.
|
|
1322
|
+
function syncLeftStackScroll() {
|
|
1323
|
+
const el = tray.leftStack
|
|
1324
|
+
if (!el || !el.parentNode) return false
|
|
1325
|
+
const rect = el.getBoundingClientRect()
|
|
1326
|
+
if (rect.top <= 0 && rect.height === 0) return false
|
|
1327
|
+
const room = Math.max(0, Math.round(window.innerHeight - rect.top - 8))
|
|
1328
|
+
const over = el.scrollHeight > room + 0.5
|
|
1329
|
+
el.style.maxHeight = over ? room + 'px' : ''
|
|
1330
|
+
el.style.overflowY = over ? 'auto' : ''
|
|
1331
|
+
el.style.scrollbarWidth = over ? 'thin' : ''
|
|
1332
|
+
if (over) el.setAttribute('data-panel-dock-left-scrolls', '')
|
|
1333
|
+
else el.removeAttribute('data-panel-dock-left-scrolls')
|
|
1334
|
+
return over
|
|
1335
|
+
}
|
|
1336
|
+
|
|
1337
|
+
// The sidebar half is only a placeholder: the tray moves the cell containers in.
|
|
1338
|
+
function LeftSlot() {
|
|
1339
|
+
const ref = React.useRef(null)
|
|
1340
|
+
React.useEffect(() => {
|
|
1341
|
+
tray.leftSlot = ref.current
|
|
1342
|
+
if (tray.poke) tray.poke()
|
|
1343
|
+
return () => { if (tray.leftSlot === ref.current) tray.leftSlot = null }
|
|
1344
|
+
}, [])
|
|
1345
|
+
return h('div', { 'data-panel-dock-left-slot': '', ref, style: { display: 'contents' } })
|
|
1346
|
+
}
|
|
1347
|
+
|
|
1348
|
+
function TrayHost() {
|
|
1349
|
+
const all = useRegistry()
|
|
1350
|
+
const [anchors, setAnchors] = React.useState(() => measureAnchors())
|
|
1351
|
+
const [scrolls, setScrolls] = React.useState(false)
|
|
1352
|
+
const [, bump] = React.useState(0)
|
|
1353
|
+
const band = React.useRef(null)
|
|
1354
|
+
const measureStack = React.useRef(null)
|
|
1355
|
+
const lastPlacement = React.useRef({ left: [], right: [], inBand: false })
|
|
1356
|
+
|
|
1357
|
+
React.useEffect(() => {
|
|
1358
|
+
tray.poke = () => bump((n) => n + 1)
|
|
1359
|
+
return () => { tray.poke = null }
|
|
1360
|
+
}, [])
|
|
1361
|
+
|
|
1362
|
+
const right = all.filter((panel) => sideOf(panel.id, panel.side) === 'right')
|
|
1363
|
+
const needsBand = right.length > 0
|
|
1364
|
+
|
|
1365
|
+
React.useEffect(() => {
|
|
1366
|
+
// Nothing lives on the right: the anchors are irrelevant, and measuring them is a
|
|
1367
|
+
// full-document scan plus ~20 layout reads. Polling that while every card sits in
|
|
1368
|
+
// the sidebar made the dock the busiest thing on the page for no benefit.
|
|
1369
|
+
if (!needsBand) {
|
|
1370
|
+
setAnchors(null)
|
|
1371
|
+
return undefined
|
|
1372
|
+
}
|
|
1373
|
+
let raf = 0
|
|
1374
|
+
const sync = () => {
|
|
1375
|
+
raf = 0
|
|
1376
|
+
const next = measureAnchors()
|
|
1377
|
+
setAnchors((prev) => (sameAnchors(prev, next) ? prev : next))
|
|
1378
|
+
if (measureStack.current) measureStack.current()
|
|
1379
|
+
}
|
|
1380
|
+
const schedule = () => { if (!raf) raf = requestAnimationFrame(sync) }
|
|
1381
|
+
schedule()
|
|
1382
|
+
window.addEventListener('resize', schedule)
|
|
1383
|
+
// The band's anchors move when the window resizes, when the right sidebar opens or
|
|
1384
|
+
// closes, or when the conversation column is dragged -- all of them resize the
|
|
1385
|
+
// column, so observing it replaces the old 700ms poll. The timer stays as a slow
|
|
1386
|
+
// safety net for anything that moves without changing the column's size.
|
|
1387
|
+
let observer = null
|
|
1388
|
+
if (typeof ResizeObserver !== 'undefined') {
|
|
1389
|
+
observer = new ResizeObserver(schedule)
|
|
1390
|
+
const tabs = document.querySelector('[data-conversation-tabs]')
|
|
1391
|
+
const column = tabs && (tabs.parentElement || tabs)
|
|
1392
|
+
if (column) observer.observe(column)
|
|
1393
|
+
}
|
|
1394
|
+
const timer = setInterval(schedule, 2500)
|
|
1395
|
+
return () => {
|
|
1396
|
+
window.removeEventListener('resize', schedule)
|
|
1397
|
+
if (observer) observer.disconnect()
|
|
1398
|
+
clearInterval(timer)
|
|
1399
|
+
if (raf) cancelAnimationFrame(raf)
|
|
1400
|
+
}
|
|
1401
|
+
}, [needsBand])
|
|
1402
|
+
|
|
1403
|
+
const required = Math.min(MAX_PANEL_WIDTH, Math.max(MIN_WIDTH_FLOOR,
|
|
1404
|
+
right.reduce((widest, panel) => Math.max(widest, panel.minWidth || DEFAULT_MIN_WIDTH), 0)))
|
|
1405
|
+
const plan = planBand(anchors, required)
|
|
1406
|
+
const top = plan.mode === 'page' ? plan.pageTop : (anchors ? anchors.top : 8)
|
|
1407
|
+
const inBand = plan.mode !== 'fallback' && right.length > 0
|
|
1408
|
+
React.useEffect(() => { setFallback(plan.mode === 'fallback') }, [plan.mode])
|
|
1409
|
+
|
|
1410
|
+
// The wheel/click path must not wait for a React render: it re-applies the deck
|
|
1411
|
+
// straight from the last placement it knows about.
|
|
1412
|
+
React.useEffect(() => {
|
|
1413
|
+
deck.resync = () => {
|
|
1414
|
+
const last = lastPlacement.current
|
|
1415
|
+
if (tray.leftStack) syncDeck(tray.leftStack, last.left, true)
|
|
1416
|
+
if (band.current) syncDeck(band.current, last.right, last.inBand)
|
|
1417
|
+
}
|
|
1418
|
+
return () => { deck.resync = null }
|
|
1419
|
+
}, [])
|
|
1420
|
+
|
|
1421
|
+
// Placement: every frame after render, put each cell into the stack that owns it.
|
|
1422
|
+
React.useEffect(() => {
|
|
1423
|
+
const alive = new Set(all.map((panel) => panel.id))
|
|
1424
|
+
dropDeadCells(alive)
|
|
1425
|
+
const wantLeft = []
|
|
1426
|
+
const wantRight = []
|
|
1427
|
+
for (const panel of all) {
|
|
1428
|
+
const side = sideOf(panel.id, panel.side)
|
|
1429
|
+
if (side === 'right' && inBand) wantRight.push(panel.id)
|
|
1430
|
+
else wantLeft.push(panel.id)
|
|
1431
|
+
}
|
|
1432
|
+
if (wantLeft.length && tray.leftSlot) {
|
|
1433
|
+
const stack = leftStackNode()
|
|
1434
|
+
if (stack.parentNode !== tray.leftSlot) tray.leftSlot.appendChild(stack)
|
|
1435
|
+
wantLeft.forEach((id, index) => {
|
|
1436
|
+
const el = cellOf(id)
|
|
1437
|
+
const at = cellAt(stack, index)
|
|
1438
|
+
if (at !== el) stack.insertBefore(el, at || deckBarOf(stack) || null)
|
|
1439
|
+
})
|
|
1440
|
+
} else if (tray.leftStack && tray.leftStack.parentNode) {
|
|
1441
|
+
tray.leftStack.parentNode.removeChild(tray.leftStack)
|
|
1442
|
+
}
|
|
1443
|
+
const bandEl = band.current
|
|
1444
|
+
if (bandEl) {
|
|
1445
|
+
wantRight.forEach((id, index) => {
|
|
1446
|
+
const el = cellOf(id)
|
|
1447
|
+
const at = cellAt(bandEl, index)
|
|
1448
|
+
if (at !== el) bandEl.insertBefore(el, at || deckBarOf(bandEl) || null)
|
|
1449
|
+
})
|
|
1450
|
+
}
|
|
1451
|
+
// Deck last: it needs the cells already in their containers to measure the front
|
|
1452
|
+
// card and to compute the strips.
|
|
1453
|
+
lastPlacement.current = { left: wantLeft, right: wantRight, inBand }
|
|
1454
|
+
if (tray.leftStack) syncDeck(tray.leftStack, wantLeft, true)
|
|
1455
|
+
if (bandEl) syncDeck(bandEl, wantRight, inBand)
|
|
1456
|
+
if (wantLeft.length && !deckOn()) syncLeftStackScroll()
|
|
1457
|
+
})
|
|
1458
|
+
|
|
1459
|
+
// The stack scrolls only when the cards outgrow the column (see SHADOW_GUTTER).
|
|
1460
|
+
React.useEffect(() => {
|
|
1461
|
+
const el = band.current
|
|
1462
|
+
const measure = () => {
|
|
1463
|
+
if (!el) { setScrolls(false); return }
|
|
1464
|
+
const column = Math.max(0, window.innerHeight - 8 - top)
|
|
1465
|
+
const next = stackedHeight(el) > column + 0.5
|
|
1466
|
+
setScrolls((prev) => (prev === next ? prev : next))
|
|
1467
|
+
}
|
|
1468
|
+
measureStack.current = measure
|
|
1469
|
+
measure()
|
|
1470
|
+
// The left stack is not covered by the band's own observer above.
|
|
1471
|
+
if (!deckOn()) syncLeftStackScroll()
|
|
1472
|
+
if (typeof ResizeObserver === 'undefined') return () => { measureStack.current = null }
|
|
1473
|
+
const observer = new ResizeObserver(() => { measure(); syncLeftStackScroll() })
|
|
1474
|
+
if (el) for (const kid of el.children) observer.observe(kid)
|
|
1475
|
+
if (tray.leftStack) observer.observe(tray.leftStack)
|
|
1476
|
+
return () => { observer.disconnect(); measureStack.current = null }
|
|
1477
|
+
}, [inBand, right.length, top])
|
|
1478
|
+
|
|
1479
|
+
// Cards in detached containers look perfectly healthy from the registry side, so
|
|
1480
|
+
// say it out loud once if nothing ever mounted a host for them.
|
|
1481
|
+
React.useEffect(() => {
|
|
1482
|
+
if (all.length === 0) return undefined
|
|
1483
|
+
const timer = setTimeout(() => {
|
|
1484
|
+
if (!tray.leftSlot && !band.current) {
|
|
1485
|
+
try {
|
|
1486
|
+
console.error('[panel-dock] ' + all.length + ' card(s) registered but no host slot is mounted (sidebar footer / overlay).')
|
|
1487
|
+
} catch {}
|
|
1488
|
+
}
|
|
1489
|
+
}, 1500)
|
|
1490
|
+
return () => clearTimeout(timer)
|
|
1491
|
+
}, [all.length])
|
|
1492
|
+
|
|
1493
|
+
React.useEffect(() => () => {
|
|
1494
|
+
for (const el of tray.cells.values()) if (el.parentNode) el.parentNode.removeChild(el)
|
|
1495
|
+
tray.cells.clear()
|
|
1496
|
+
if (tray.leftStack && tray.leftStack.parentNode) tray.leftStack.parentNode.removeChild(tray.leftStack)
|
|
1497
|
+
tray.leftStack = null
|
|
1498
|
+
}, [])
|
|
1499
|
+
|
|
1500
|
+
const nodes = []
|
|
1501
|
+
if (inBand) {
|
|
1502
|
+
const style = {
|
|
1503
|
+
position: 'fixed',
|
|
1504
|
+
top,
|
|
1505
|
+
bottom: 8,
|
|
1506
|
+
display: 'flex',
|
|
1507
|
+
flexDirection: 'column',
|
|
1508
|
+
gap: STACK_GAP,
|
|
1509
|
+
minWidth: 0,
|
|
1510
|
+
boxSizing: 'border-box',
|
|
1511
|
+
overflow: 'visible',
|
|
1512
|
+
pointerEvents: 'none',
|
|
1513
|
+
zIndex: 10000,
|
|
1514
|
+
}
|
|
1515
|
+
style.width = plan.width
|
|
1516
|
+
if (plan.mode === 'inner') style.left = plan.left
|
|
1517
|
+
else style.right = Math.max(GAP, window.innerWidth - plan.rightEdge)
|
|
1518
|
+
if (scrolls) {
|
|
1519
|
+
const gutter = SHADOW_GUTTER
|
|
1520
|
+
style.top = top - gutter
|
|
1521
|
+
style.height = Math.max(0, window.innerHeight - 8 - top) + gutter * 2
|
|
1522
|
+
style.bottom = 'auto'
|
|
1523
|
+
style.width = plan.width + gutter * 2
|
|
1524
|
+
if (style.left !== undefined) style.left -= gutter
|
|
1525
|
+
if (style.right !== undefined) style.right -= gutter
|
|
1526
|
+
style.padding = gutter
|
|
1527
|
+
style.overflowY = 'auto'
|
|
1528
|
+
style.overflowX = 'hidden'
|
|
1529
|
+
style.scrollbarWidth = 'none'
|
|
1530
|
+
}
|
|
1531
|
+
nodes.push(h('div', {
|
|
1532
|
+
key: 'band',
|
|
1533
|
+
'data-panel-dock-strip': '',
|
|
1534
|
+
'data-panel-dock-scrolls': scrolls ? '' : undefined,
|
|
1535
|
+
ref: band,
|
|
1536
|
+
style,
|
|
1537
|
+
}))
|
|
1538
|
+
}
|
|
1539
|
+
for (const panel of all) {
|
|
1540
|
+
nodes.push(createPortal(h(CardBoundary, {
|
|
1541
|
+
key: panel.id + ':' + revisionOf(panel.id),
|
|
1542
|
+
id: panel.id,
|
|
1543
|
+
fallback: () => errorCard(panel),
|
|
1544
|
+
}, renderPanel(panel)), cellOf(panel.id), panel.id))
|
|
1545
|
+
}
|
|
1546
|
+
return h(React.Fragment, null, nodes)
|
|
1547
|
+
}
|
|
1548
|
+
|
|
1549
|
+
|
|
1550
|
+
// CardShell: the one shared top bar for a 侧栏卡片 (a card the dock hosts). It is NOT
|
|
1551
|
+
// a layout container -- the card still renders its own frame and body; the shell is
|
|
1552
|
+
// only the row above them: [logo = side toggle] [title] [version] ... [actions].
|
|
1553
|
+
const SHELL_STYLE = {
|
|
1554
|
+
display: 'flex',
|
|
1555
|
+
alignItems: 'center',
|
|
1556
|
+
gap: 6,
|
|
1557
|
+
minWidth: 0,
|
|
1558
|
+
marginBottom: 6,
|
|
1559
|
+
color: 'var(--dsw-alias-label-primary)',
|
|
1560
|
+
}
|
|
1561
|
+
const SHELL_TOGGLE_STYLE = {
|
|
1562
|
+
display: 'inline-flex',
|
|
1563
|
+
alignItems: 'center',
|
|
1564
|
+
justifyContent: 'center',
|
|
1565
|
+
width: 18,
|
|
1566
|
+
height: 18,
|
|
1567
|
+
padding: 0,
|
|
1568
|
+
border: 0,
|
|
1569
|
+
borderRadius: 4,
|
|
1570
|
+
background: 'transparent',
|
|
1571
|
+
color: 'inherit',
|
|
1572
|
+
cursor: 'pointer',
|
|
1573
|
+
flex: '0 0 auto',
|
|
1574
|
+
}
|
|
1575
|
+
const SHELL_TITLE_STYLE = {
|
|
1576
|
+
fontSize: 13,
|
|
1577
|
+
fontWeight: 600,
|
|
1578
|
+
lineHeight: 1.2,
|
|
1579
|
+
whiteSpace: 'nowrap',
|
|
1580
|
+
overflow: 'hidden',
|
|
1581
|
+
textOverflow: 'ellipsis',
|
|
1582
|
+
minWidth: 0,
|
|
1583
|
+
}
|
|
1584
|
+
const SHELL_VERSION_STYLE = {
|
|
1585
|
+
fontSize: 10,
|
|
1586
|
+
fontWeight: 400,
|
|
1587
|
+
lineHeight: 1.2,
|
|
1588
|
+
color: 'var(--dsw-alias-label-secondary)',
|
|
1589
|
+
flex: '0 0 auto',
|
|
1590
|
+
}
|
|
1591
|
+
const SHELL_ACTIONS_STYLE = { display: 'inline-flex', alignItems: 'center', gap: 4, flex: '0 0 auto' }
|
|
1592
|
+
|
|
1593
|
+
// Monochrome logo that doubles as the side toggle: a panel glyph with an arrow
|
|
1594
|
+
// pointing at the side the card would move to.
|
|
1595
|
+
function shellLogo(docked) {
|
|
1596
|
+
return h('svg', {
|
|
1597
|
+
width: 15, height: 15, viewBox: '0 0 16 16', fill: 'none',
|
|
1598
|
+
'aria-hidden': 'true', focusable: 'false',
|
|
1599
|
+
},
|
|
1600
|
+
h('rect', { x: 1.6, y: 2.6, width: 12.8, height: 10.8, rx: 2.4, stroke: 'currentColor', strokeWidth: 1.3 }),
|
|
1601
|
+
h('path', { d: docked ? 'M10.4 2.8 V13.2' : 'M5.6 2.8 V13.2', stroke: 'currentColor', strokeWidth: 1.3 }),
|
|
1602
|
+
h('path', {
|
|
1603
|
+
d: docked ? 'M7.1 6.4 L5.3 8 L7.1 9.6' : 'M8.9 6.4 L10.7 8 L8.9 9.6',
|
|
1604
|
+
stroke: 'currentColor', strokeWidth: 1.3, strokeLinecap: 'round', strokeLinejoin: 'round',
|
|
1605
|
+
}),
|
|
1606
|
+
)
|
|
1607
|
+
}
|
|
1608
|
+
|
|
1609
|
+
// Header only, by design: the card renders its own frame and body *under* this row.
|
|
1610
|
+
// Children are deliberately not rendered -- but silently dropping them would be the
|
|
1611
|
+
// worst kind of bug, so passing them is reported once per card instead of ignored.
|
|
1612
|
+
const shellWarned = new Set()
|
|
1613
|
+
|
|
1614
|
+
function CardShell(props) {
|
|
1615
|
+
const id = props.id
|
|
1616
|
+
if (props.children !== undefined && props.children !== null && !shellWarned.has(id)) {
|
|
1617
|
+
shellWarned.add(id)
|
|
1618
|
+
try {
|
|
1619
|
+
console.warn('[panel-dock] CardShell renders the header row only; put your body next to it, not inside it (card: ' + id + ').')
|
|
1620
|
+
} catch {}
|
|
1621
|
+
}
|
|
1622
|
+
const [, force] = React.useState(0)
|
|
1623
|
+
React.useEffect(() => subscribe(() => force((n) => n + 1)), [])
|
|
1624
|
+
const panel = registry.get(id)
|
|
1625
|
+
const preferred = sideOf(id, panel ? panel.side : 'left')
|
|
1626
|
+
const side = effectiveSide(id)
|
|
1627
|
+
const docked = side === 'right'
|
|
1628
|
+
const blocked = preferred !== side
|
|
1629
|
+
const title = props.title || (panel && panel.title) || id
|
|
1630
|
+
const version = props.version || (panel && panel.version) || null
|
|
1631
|
+
const label = blocked ? T('bandUnavailable') : (docked ? T('toLeft') : T('toRight'))
|
|
1632
|
+
return h('div', {
|
|
1633
|
+
'data-panel-dock-shell': id,
|
|
1634
|
+
style: Object.assign({}, SHELL_STYLE, props.style),
|
|
1635
|
+
},
|
|
1636
|
+
h('button', {
|
|
1637
|
+
type: 'button',
|
|
1638
|
+
'data-panel-dock-shell-toggle': '',
|
|
1639
|
+
'aria-label': label,
|
|
1640
|
+
title: label,
|
|
1641
|
+
disabled: blocked,
|
|
1642
|
+
onClick: () => { try { if (!blocked) toggleSide(id) } catch {} },
|
|
1643
|
+
style: blocked ? Object.assign({}, SHELL_TOGGLE_STYLE, { opacity: 0.4, cursor: 'default' }) : SHELL_TOGGLE_STYLE,
|
|
1644
|
+
}, shellLogo(docked)),
|
|
1645
|
+
h('span', { style: SHELL_TITLE_STYLE, title }, title),
|
|
1646
|
+
version ? h('span', { style: SHELL_VERSION_STYLE }, 'v' + version) : null,
|
|
1647
|
+
h('span', { style: { flex: '1 1 auto', minWidth: 0 } }),
|
|
1648
|
+
props.actions ? h('span', { style: SHELL_ACTIONS_STYLE }, props.actions) : null,
|
|
1649
|
+
)
|
|
1650
|
+
}
|
|
1651
|
+
|
|
1652
|
+
|
|
1653
|
+
// ---- crash isolation ----
|
|
1654
|
+
// The host treats a slot entry that throws as broken and drops the *whole entry*:
|
|
1655
|
+
// one bad card used to take every card down with it, and nothing recovered until a
|
|
1656
|
+
// reload. Each card therefore gets its own boundary, and each slot entry is sealed
|
|
1657
|
+
// so a dock bug cannot be mistaken for a broken host slot.
|
|
1658
|
+
class CardBoundary extends React.Component {
|
|
1659
|
+
constructor(props) {
|
|
1660
|
+
super(props)
|
|
1661
|
+
this.state = { failed: false }
|
|
1662
|
+
}
|
|
1663
|
+
static getDerivedStateFromError() {
|
|
1664
|
+
return { failed: true }
|
|
1665
|
+
}
|
|
1666
|
+
componentDidCatch(error) {
|
|
1667
|
+
try { console.error('[panel-dock] card crashed and was isolated: ' + this.props.id, error) } catch {}
|
|
1668
|
+
}
|
|
1669
|
+
render() {
|
|
1670
|
+
if (!this.state.failed) return this.props.children
|
|
1671
|
+
return this.props.fallback ? this.props.fallback() : null
|
|
1672
|
+
}
|
|
1673
|
+
}
|
|
1674
|
+
|
|
1675
|
+
function errorCard(panel) {
|
|
1676
|
+
return h('div', {
|
|
1677
|
+
'data-panel-dock-item': panel.id,
|
|
1678
|
+
'data-panel-dock-error': '',
|
|
1679
|
+
style: {
|
|
1680
|
+
width: '100%', minWidth: 0, boxSizing: 'border-box', padding: '8px 9px',
|
|
1681
|
+
border: '1px solid var(--dsw-alias-border-l1)', borderRadius: 12,
|
|
1682
|
+
background: 'var(--dsw-alias-bg-layer-1)',
|
|
1683
|
+
color: 'var(--dsw-alias-label-secondary)',
|
|
1684
|
+
fontSize: 11, lineHeight: 1.35, pointerEvents: 'auto',
|
|
1685
|
+
},
|
|
1686
|
+
}, (panel.title || panel.id) + ' · ' + T('cardCrashed'))
|
|
1687
|
+
}
|
|
1688
|
+
|
|
1689
|
+
// Re-registering an id means a new component: remount the boundary instead of leaving
|
|
1690
|
+
// it stuck in the failed state forever.
|
|
1691
|
+
const revisions = new Map()
|
|
1692
|
+
function revisionOf(id) {
|
|
1693
|
+
return revisions.get(id) || 0
|
|
1694
|
+
}
|
|
1695
|
+
|
|
1696
|
+
// A sealed slot entry renders nothing instead of throwing into the host.
|
|
1697
|
+
function seal(Component, name, Alt) {
|
|
1698
|
+
return function SealedSlot() {
|
|
1699
|
+
return h(CardBoundary, { id: name, fallback: Alt ? () => h(Alt) : null }, h(Component))
|
|
1700
|
+
}
|
|
1701
|
+
}
|
|
1702
|
+
|
|
1703
|
+
function effectiveSide(id) {
|
|
1704
|
+
const panel = registry.get(id)
|
|
1705
|
+
const preferred = sideOf(id, panel ? panel.side : 'left')
|
|
1706
|
+
return preferred === 'right' && placement.fallback ? 'left' : preferred
|
|
1707
|
+
}
|
|
1708
|
+
|
|
1709
|
+
// The band floats over the transcript, so a card that swallows the pointer is
|
|
1710
|
+
// worse than one that merely looks solid. Hovering dims it to show what it covers;
|
|
1711
|
+
// it stays hit-testable (click-through is self-contradictory in CSS: an element
|
|
1712
|
+
// that ignores the pointer can never observe hover, so it would flicker).
|
|
1713
|
+
const BAND_CSS = [
|
|
1714
|
+
// Hover used to fade the whole card to 45%, text included. Only the surface goes
|
|
1715
|
+
// translucent now: the content stays at full opacity, so the card reads as glass
|
|
1716
|
+
// over the transcript instead of as a disabled control.
|
|
1717
|
+
'[data-panel-dock-strip] [data-panel-dock-cell] > [data-panel-dock-frame]{',
|
|
1718
|
+
'transition:background-color 140ms ease,box-shadow 140ms ease,border-color 140ms ease;}',
|
|
1719
|
+
// !important is required: the frame's background/border/shadow are written inline by
|
|
1720
|
+
// renderPanel, and an inline declaration beats a plain CSS rule (measured: the card
|
|
1721
|
+
// stayed opaque with the rule present).
|
|
1722
|
+
// Stacked mode is for cycling cards: a card that fades while you reach for the
|
|
1723
|
+
// wheel only adds noise, so the glass hover is limited to the plain column.
|
|
1724
|
+
'[data-panel-dock-strip]:not([data-panel-dock-deck]) [data-panel-dock-cell]:hover > [data-panel-dock-frame]{',
|
|
1725
|
+
'background:color-mix(in srgb,var(--dsw-specific-sidebar-fill,#f9fafb) 34%,transparent) !important;',
|
|
1726
|
+
'border-color:transparent !important;box-shadow:none !important;}',
|
|
1727
|
+
// ---- deck ----
|
|
1728
|
+
'[data-panel-dock-deck]{position:relative;transition:height 200ms cubic-bezier(.2,.8,.2,1)}',
|
|
1729
|
+
'[data-panel-dock-deck] > [data-panel-dock-cell]{position:absolute;left:0;right:0;top:0;',
|
|
1730
|
+
'transition:transform 200ms cubic-bezier(.2,.8,.2,1),opacity 160ms ease}',
|
|
1731
|
+
// Rear cards are only strips: keep them clickable but not visually loud.
|
|
1732
|
+
|
|
1733
|
+
'[data-panel-dock-deck-bar][data-panel-dock-hidden]{display:none}',
|
|
1734
|
+
// Rear cards are visible but not operable: their controls (side toggle, refresh,
|
|
1735
|
+
// links) must not fire while the card sits behind. Clicks fall through to the card
|
|
1736
|
+
// body, which promotes that card to the front.
|
|
1737
|
+
// The card tone is the INVERSE of its column: the sidebar is #f9fafb so its cards are
|
|
1738
|
+
// white, the main page is #ffffff so band cards are #f9fafb. That is the contrast
|
|
1739
|
+
// mechanism the operator designed; a ring was the wrong answer.
|
|
1740
|
+
// The card tone is derived from the host token, not hardcoded: `#ffffff` in dark mode
|
|
1741
|
+
// is a glaring white card under light text (the unreadable state on the dark build).
|
|
1742
|
+
// Light theme: sidebar #f9fafb -> card almost white; band #fff -> card #f9fafb.
|
|
1743
|
+
// Dark theme: both lift a little off the surrounding surface instead of going white.
|
|
1744
|
+
'[data-panel-dock-left] [data-panel-dock-frame]{background:#ffffff !important}',
|
|
1745
|
+
'[data-panel-dock-strip] [data-panel-dock-frame]{',
|
|
1746
|
+
'background:color-mix(in srgb,var(--dsw-specific-sidebar-fill,#f9fafb) 94%,#ffffff) !important}',
|
|
1747
|
+
// Dark palette: `#ffffff` under the light text of a dark host is the unreadable state.
|
|
1748
|
+
// These are keyed on the attribute the renderer sets from hostIsDark().
|
|
1749
|
+
'[data-panel-dock-frame][data-pd-dark]{',
|
|
1750
|
+
'background:#26282b !important;border-color:rgba(255,255,255,.10) !important;',
|
|
1751
|
+
'box-shadow:0 3px 12px 0 rgba(0,0,0,.55) !important;color-scheme:dark}',
|
|
1752
|
+
'[data-panel-dock-left] [data-panel-dock-frame][data-pd-dark]{background:#2e3135 !important}',
|
|
1753
|
+
'[data-panel-dock-strip] [data-panel-dock-frame][data-pd-dark]{background:#232528 !important}',
|
|
1754
|
+
'[data-panel-dock-deck] > [data-panel-dock-cell][data-panel-dock-rear] button,',
|
|
1755
|
+
'[data-panel-dock-deck] > [data-panel-dock-cell][data-panel-dock-rear] a,',
|
|
1756
|
+
'[data-panel-dock-deck] > [data-panel-dock-cell][data-panel-dock-rear] input,',
|
|
1757
|
+
'[data-panel-dock-deck] > [data-panel-dock-cell][data-panel-dock-rear] select,',
|
|
1758
|
+
'[data-panel-dock-deck] > [data-panel-dock-cell][data-panel-dock-rear] textarea,',
|
|
1759
|
+
'[data-panel-dock-deck] > [data-panel-dock-cell][data-panel-dock-rear] summary,',
|
|
1760
|
+
'[data-panel-dock-deck] > [data-panel-dock-cell][data-panel-dock-rear] [role="button"],',
|
|
1761
|
+
'[data-panel-dock-deck] > [data-panel-dock-cell][data-panel-dock-rear] [tabindex]{',
|
|
1762
|
+
'pointer-events:none;}',
|
|
1763
|
+
// The strip is easy to miss at 10px when the pointer approaches from the middle of
|
|
1764
|
+
// the card, so a transparent tab hangs below the centre (ends untouched, nothing
|
|
1765
|
+
// painted): the middle catches the pointer 16px lower, the sides behave as before.
|
|
1766
|
+
'[data-panel-dock-deck-bar]::after{content:"";position:absolute;left:25%;right:25%;',
|
|
1767
|
+
'top:100%;height:16px;border-radius:0 0 10px 10px;}',
|
|
1768
|
+
// frame:true means the dock owns the rectangle, so the card body must not paint a
|
|
1769
|
+
// second one. Cards get this for free -- a card that keeps its own border shows a
|
|
1770
|
+
// box inside a box (seen live: loci drew 12px radius + white fill inside the frame).
|
|
1771
|
+
// !important is deliberate and scoped: the card's own `.card-root` rule has equal
|
|
1772
|
+
// specificity and lands later in the cascade, so without it the frame keeps a box
|
|
1773
|
+
// inside a box (verified: padding/border/radius survived the plain rule).
|
|
1774
|
+
// Surface AND outer inset: the frame already supplies 10px 9px 8px, so a card that also
|
|
1775
|
+
// pads its own root shifts its header by a different amount per card (measured: USTC 17px,
|
|
1776
|
+
// Codex 18px, Memory 9px from the card edge) -- that is the "headers don't line up" report.
|
|
1777
|
+
// Inner blocks keep their own padding; only the root's is dropped.
|
|
1778
|
+
'[data-panel-dock-frame] > *{padding:0 !important;margin:0 !important;border:0 !important;',
|
|
1779
|
+
'border-radius:0 !important;background:transparent !important;box-shadow:none !important;}',
|
|
1780
|
+
// ---- affordance: the card edge drops into a gradient band ----
|
|
1781
|
+
// The affordance is a glass overlay, not a row: it takes no layout space, sits on
|
|
1782
|
+
// the column's own top edge (not above it) and stays invisible until the pointer
|
|
1783
|
+
// arrives -- a permanently visible bar read as "the column got taller".
|
|
1784
|
+
// pointer-events:auto is essential: the band is pointer-events:none, and a child
|
|
1785
|
+
// inherits that, so the strip was unclickable (reported as "click does nothing").
|
|
1786
|
+
// Exactly the card's width: the strip used to stick out 4px on each side, which read
|
|
1787
|
+
// as a floating bar rather than a drawer pulled out of the card. Top corners follow
|
|
1788
|
+
// the card radius (12) so the square edge does not poke out of the rounded corner.
|
|
1789
|
+
'[data-panel-dock-deck-bar]{--pd-chev:45deg;position:absolute;left:0;right:0;top:0;height:10px;',
|
|
1790
|
+
'z-index:400;box-sizing:border-box;pointer-events:auto;cursor:pointer;',
|
|
1791
|
+
'display:flex;align-items:center;justify-content:center;gap:3px;',
|
|
1792
|
+
// Top corners follow the card (12px); the bottom edge is square on purpose --
|
|
1793
|
+
// it reads as a drawer face pulled out of the card, not a floating pill.
|
|
1794
|
+
'border-radius:12px 12px 0 0;border-bottom:1px solid transparent;',
|
|
1795
|
+
'background:linear-gradient(180deg,rgba(0,0,0,0),rgba(0,0,0,0));',
|
|
1796
|
+
'opacity:0;transition:height 170ms ease,opacity 140ms ease,background 170ms ease,',
|
|
1797
|
+
'border-color 170ms ease;-webkit-backdrop-filter:blur(0px);backdrop-filter:blur(0px);}',
|
|
1798
|
+
'[data-panel-dock-deck-bar]:hover,[data-panel-dock-deck-bar]:focus-visible{',
|
|
1799
|
+
'height:30px;opacity:1;',
|
|
1800
|
+
// Real frosted glass needs a *translucent* veil: at 96% the fill hid everything
|
|
1801
|
+
// behind it, so backdrop-filter had nothing to blur and the strip read as opaque.
|
|
1802
|
+
// Keep the veil low-opacity, blur hard, and let a white top highlight carry the
|
|
1803
|
+
// glass edge; the darker tone is now only the bottom hairline.
|
|
1804
|
+
'background:',
|
|
1805
|
+
'linear-gradient(180deg,rgba(255,255,255,.26),rgba(255,255,255,.06)),',
|
|
1806
|
+
'linear-gradient(180deg,',
|
|
1807
|
+
'color-mix(in srgb,var(--dsw-specific-sidebar-fill,#f9fafb) 52%,transparent),',
|
|
1808
|
+
'color-mix(in srgb,var(--dsw-specific-sidebar-fill,#f9fafb) 28%,transparent));',
|
|
1809
|
+
'border-bottom-color:rgba(15,23,42,.09);',
|
|
1810
|
+
'box-shadow:inset 0 1px 0 rgba(255,255,255,.55),inset 0 -1px 0 rgba(15,23,42,.04);',
|
|
1811
|
+
'-webkit-backdrop-filter:blur(14px) saturate(1.25);backdrop-filter:blur(14px) saturate(1.25);}',
|
|
1812
|
+
'[data-panel-dock-deck-bar] > i{display:block;width:7px;height:7px;margin-top:-6px;',
|
|
1813
|
+
'border-right:1.8px solid var(--dsw-alias-label-secondary,rgba(15,23,42,.62));',
|
|
1814
|
+
'border-bottom:1.8px solid var(--dsw-alias-label-secondary,rgba(15,23,42,.62));',
|
|
1815
|
+
'transform:rotate(45deg);opacity:0;',
|
|
1816
|
+
'transition:opacity 140ms ease;animation:pdDeckChevron 1.2s ease-in-out infinite}',
|
|
1817
|
+
'[data-panel-dock-deck-bar]:hover > i,[data-panel-dock-deck-bar]:focus-visible > i{opacity:.92}',
|
|
1818
|
+
// Deck already on: the same press unfolds the stack, so the chevrons point UP.
|
|
1819
|
+
// Only the variable changes -- the running keyframes read it every frame.
|
|
1820
|
+
'[data-panel-dock-deck-bar][data-panel-dock-deck-on]{--pd-chev:-135deg}',
|
|
1821
|
+
'[data-panel-dock-deck-bar][data-panel-dock-deck-on] > i{margin-top:5px}',
|
|
1822
|
+
'@media (prefers-reduced-motion: reduce){[data-panel-dock-deck-bar] > i{animation:none}}',
|
|
1823
|
+
'[data-panel-dock-deck-bar] > i:nth-child(2){animation-delay:.14s}',
|
|
1824
|
+
'[data-panel-dock-deck-bar] > i:nth-child(3){animation-delay:.28s}',
|
|
1825
|
+
// The direction lives in a custom property: the keyframes below run every frame and
|
|
1826
|
+
// used to hard-code rotate(45deg), which silently overrode the deck-on -135deg --
|
|
1827
|
+
// the strip pointed down even while the cards were stacked.
|
|
1828
|
+
'@keyframes pdDeckChevron{0%{opacity:.15;transform:translateY(-2px) rotate(var(--pd-chev,45deg))}',
|
|
1829
|
+
'50%{opacity:.95;transform:translateY(2px) rotate(var(--pd-chev,45deg))}',
|
|
1830
|
+
'100%{opacity:.15;transform:translateY(-2px) rotate(var(--pd-chev,45deg))}}',
|
|
1831
|
+
'@media (prefers-reduced-motion: reduce){',
|
|
1832
|
+
'[data-panel-dock-strip] [data-panel-dock-cell]{transition:none}',
|
|
1833
|
+
'[data-panel-dock-deck]{transition:none}',
|
|
1834
|
+
'[data-panel-dock-deck] > [data-panel-dock-cell]{transition:none}}',
|
|
1835
|
+
].join('')
|
|
1836
|
+
function apply(ctx) {
|
|
1837
|
+
ctx.effect(() => ctx.locale.register(NS, { zh, en }), 'dsh-panel-dock: locale')
|
|
1838
|
+
// Dock-level affordance: every card in the band dims on hover without opting in.
|
|
1839
|
+
ctx.effect(() => {
|
|
1840
|
+
if (typeof document === 'undefined') return undefined
|
|
1841
|
+
const style = document.createElement('style')
|
|
1842
|
+
style.setAttribute('data-dsh-panel-dock', 'band-hover')
|
|
1843
|
+
style.textContent = BAND_CSS
|
|
1844
|
+
document.head.appendChild(style)
|
|
1845
|
+
return () => { try { style.remove() } catch {} }
|
|
1846
|
+
}, 'dsh-panel-dock: band css')
|
|
1847
|
+
T = ctx.locale.bind(NS)
|
|
1848
|
+
// The tray keeps cards mounted when they change hosts; without portals the dock
|
|
1849
|
+
// falls back to rendering each host directly (0.3.x behaviour, cards remount).
|
|
1850
|
+
const leftHost = createPortal ? seal(LeftSlot, 'panel-dock-left', LeftHost) : seal(LeftHost, 'panel-dock-left')
|
|
1851
|
+
const rightHost = createPortal ? seal(TrayHost, 'panel-dock-right', RightHost) : seal(RightHost, 'panel-dock-right')
|
|
1852
|
+
ctx.slots.inject('sidebar.footer.action', () => ctx.slots.register({
|
|
1853
|
+
name: 'sidebar.footer.action', id: 'panel-dock-left', order: 900, locale: NS,
|
|
1854
|
+
}, leftHost))
|
|
1855
|
+
ctx.slots.inject('shell.overlay', () => ctx.slots.register({
|
|
1856
|
+
name: 'shell.overlay', id: 'panel-dock-right', order: 40, locale: NS,
|
|
1857
|
+
}, rightHost))
|
|
1858
|
+
const api = {
|
|
1859
|
+
version: VERSION,
|
|
1860
|
+
define,
|
|
1861
|
+
placementOf: effectiveSide,
|
|
1862
|
+
// Consumers use this to decide whether their native fallback must draw: with the
|
|
1863
|
+
// dock present but their registration missing, neither side used to render.
|
|
1864
|
+
has: (id) => registry.has(id),
|
|
1865
|
+
panel: (id) => {
|
|
1866
|
+
const p = registry.get(id)
|
|
1867
|
+
return p ? { id: p.id, title: p.title, order: p.order, side: sideOf(p.id, p.side), effective: effectiveSide(p.id), minWidth: p.minWidth, version: p.version, frame: frameEnabled(p) } : null
|
|
1868
|
+
},
|
|
1869
|
+
panels: () => panels().map((p) => ({ id: p.id, title: p.title, order: p.order, side: sideOf(p.id, p.side), effective: effectiveSide(p.id), minWidth: p.minWidth, version: p.version, frame: frameEnabled(p) })),
|
|
1870
|
+
CardShell,
|
|
1871
|
+
getSide: (id) => sideOf(id, registry.has(id) ? registry.get(id).side : 'left'),
|
|
1872
|
+
setSide,
|
|
1873
|
+
toggleSide,
|
|
1874
|
+
subscribe,
|
|
1875
|
+
}
|
|
1876
|
+
ctx.effect(() => {
|
|
1877
|
+
try { window.__dshPanelDock = api } catch {}
|
|
1878
|
+
// Disabling the plugin must hand the panels back to their own fallbacks, so the
|
|
1879
|
+
// global has to disappear with us -- leaving it behind silently keeps every card
|
|
1880
|
+
// believing the dock is alive.
|
|
1881
|
+
return () => {
|
|
1882
|
+
try { if (window.__dshPanelDock === api) delete window.__dshPanelDock } catch {}
|
|
1883
|
+
}
|
|
1884
|
+
}, 'dsh-panel-dock: global')
|
|
1885
|
+
}
|
|
1886
|
+
|
|
1887
|
+
return { inject: ['slots', 'locale'], apply }
|
|
1888
|
+
},
|
|
1889
|
+
})
|