dsh-project-mcp 0.2.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +71 -25
- package/lib/client.d.ts +77 -0
- package/lib/client.js +10127 -0
- package/lib/client.js.map +1 -0
- package/lib/index.d.ts +3710 -0
- package/lib/index.js +7461 -0
- package/lib/index.js.map +1 -0
- package/package.json +14 -18
- package/src/activation.ts +6 -1
- package/src/client/design-fixtures.ts +96 -1
- package/src/client/design.ts +64 -51
- package/src/client/index.ts +74 -133
- package/src/client/locales/ui.ts +48 -14
- package/src/client/settings.ts +2 -2
- package/src/client/sidebar-tab.ts +521 -0
- package/src/client/view.ts +780 -80
- package/src/index.ts +18 -3
- package/src/runtime.ts +162 -1
- package/src/shared.ts +9 -3
- package/src/types.ts +65 -0
- package/src/ui.ts +61 -3
|
@@ -0,0 +1,521 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The plugin's tab in DSH's **own** right sidebar, and the settings it carries.
|
|
3
|
+
*
|
|
4
|
+
* The panel used to be a tab of `dsh-better-sidebar`, a third-party registry
|
|
5
|
+
* that re-exports DSH's right sidebar with its own descriptor API (and with its
|
|
6
|
+
* own builtin tabs, its own `+` menu and its own side card settings). This module
|
|
7
|
+
* speaks to the shipped surface directly, so the plugin depends on nothing
|
|
8
|
+
* outside the harness:
|
|
9
|
+
*
|
|
10
|
+
* - the type itself goes into `sidebarRightTabs` (stage one: what the type *is* —
|
|
11
|
+
* its id, its kind, and one guide entry, which is the only way a user can open
|
|
12
|
+
* a page type at all);
|
|
13
|
+
* - its body and its chip title go into the keyed `sidebar.right.pane.tab` /
|
|
14
|
+
* `sidebar.right.pane.tab.title` seats under that same id, which is what the
|
|
15
|
+
* sidebar dispatches on for every tab of the kind;
|
|
16
|
+
* - the chip's actions menu gains one row (`sidebar.right.tab.menu.item`) that
|
|
17
|
+
* opens the plugin's settings, and the settings themselves render as an entry
|
|
18
|
+
* of the frame-wide `shell.overlay` layer — because a menu item that acts must
|
|
19
|
+
* dismiss the menu it was pressed in, and the popup cannot live inside the row
|
|
20
|
+
* that opened it. One store drives both halves.
|
|
21
|
+
*
|
|
22
|
+
* The DSH client packages are provided by the web shell and are not dependencies
|
|
23
|
+
* of this package, so each of those contracts is **mirrored structurally** here —
|
|
24
|
+
* the choice `./settings.ts` and `./tab-locale.ts` already make for
|
|
25
|
+
* `settings.section` and the locale service. Nothing in this module imports a
|
|
26
|
+
* `@deepseek-ai/dsh-client-*` package; the slot keys and the service name are
|
|
27
|
+
* the only names it needs from the checkout, and they are dialled as strings.
|
|
28
|
+
*
|
|
29
|
+
* What the port changes for a user: the tab is listed by the shell's own guide
|
|
30
|
+
* page instead of the sidebar's `+` menu, and the side card's plugin settings
|
|
31
|
+
* page is gone — the poll interval and the per-project release panel now sit
|
|
32
|
+
* behind the row this module adds to the tab's actions menu.
|
|
33
|
+
*
|
|
34
|
+
* @module dsh-project-mcp/client/sidebar-tab
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
import { createElement as h, useEffect, useState } from 'react'
|
|
38
|
+
import type { CSSProperties, ReactNode } from 'react'
|
|
39
|
+
import { PACKAGE_NAME, TAB_ID } from '../shared.ts'
|
|
40
|
+
import { hostTranslate } from './locales/host.ts'
|
|
41
|
+
import { tabTranslate, useTabTranslate } from './tab-locale.ts'
|
|
42
|
+
import type { TabLocale } from './tab-locale.ts'
|
|
43
|
+
import type { RefreshStore, Translate } from './view.ts'
|
|
44
|
+
|
|
45
|
+
/** Type discriminator of the panel's page: what `openTab` names and what the sidebar dispatches on. */
|
|
46
|
+
export const TAB_KIND = 'project-mcp'
|
|
47
|
+
|
|
48
|
+
/** Keyed seat a tab type registers its body under. */
|
|
49
|
+
export const TAB_SLOT = 'sidebar.right.pane.tab'
|
|
50
|
+
|
|
51
|
+
/** Keyed seat the same type registers its chip title under. */
|
|
52
|
+
export const TAB_TITLE_SLOT = 'sidebar.right.pane.tab.title'
|
|
53
|
+
|
|
54
|
+
/** List seat a tab type adds its own entries to: the actions menu of the chip. */
|
|
55
|
+
export const TAB_MENU_SLOT = 'sidebar.right.tab.menu.item'
|
|
56
|
+
|
|
57
|
+
/** Frame-wide floating layer the settings popup renders into. */
|
|
58
|
+
export const SETTINGS_DIALOG_SLOT = 'shell.overlay'
|
|
59
|
+
|
|
60
|
+
/** Registration id of the actions-menu row, unique within that menu. */
|
|
61
|
+
export const TAB_MENU_ID = `${PACKAGE_NAME}:settings`
|
|
62
|
+
|
|
63
|
+
/** Position of the row among the menu's entries, after the kit's own close item. */
|
|
64
|
+
export const TAB_MENU_ORDER = 60
|
|
65
|
+
|
|
66
|
+
/** Registration id of the settings popup in the floating layer. */
|
|
67
|
+
export const SETTINGS_DIALOG_ID = `${PACKAGE_NAME}:settings-dialog`
|
|
68
|
+
|
|
69
|
+
/** Position of the popup among the layer's entries, after the toast stack. */
|
|
70
|
+
export const SETTINGS_DIALOG_ORDER = 61
|
|
71
|
+
|
|
72
|
+
/** Identity of the type's guide entry: the box the guide page offers to open a tab. */
|
|
73
|
+
export const TAB_GUIDE_ENTRY_ID = 'servers'
|
|
74
|
+
|
|
75
|
+
/** Position of the guide entry among every registered type's entries; the tab's own descriptor order. */
|
|
76
|
+
export const TAB_GUIDE_ORDER = 55
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* One box the guide page offers, contributed by the type it opens.
|
|
80
|
+
*
|
|
81
|
+
* `title` and `description` are thunks read on every render, so a language
|
|
82
|
+
* switch needs no re-registration — the rule the old descriptor's own copy
|
|
83
|
+
* followed. A guide that lists too many entries drops descriptions and shows
|
|
84
|
+
* titles alone, so the title has to stand on its own.
|
|
85
|
+
*/
|
|
86
|
+
export interface SidebarRightGuideEntry {
|
|
87
|
+
readonly id: string
|
|
88
|
+
readonly order: number
|
|
89
|
+
readonly title: () => string
|
|
90
|
+
readonly description?: (() => string) | undefined
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Stage one of a tab type: what it is, and nothing per-tab.
|
|
95
|
+
*
|
|
96
|
+
* `patterns` is omitted on purpose — the panel is a *page* type, opened by kind
|
|
97
|
+
* (from the guide page, or from another surface's `openTab`), not a viewer that
|
|
98
|
+
* claims an address. `multiple` is omitted too: one project panel per pane is
|
|
99
|
+
* what `single: true` meant in the sidebar the tab came from.
|
|
100
|
+
*/
|
|
101
|
+
export interface SidebarRightTabDefinition {
|
|
102
|
+
readonly id: string
|
|
103
|
+
readonly kind: string
|
|
104
|
+
/** Defaults to `extension` in the shipped registry: a type from outside the product. */
|
|
105
|
+
readonly priority?: 'extension' | 'builtin' | 'fallback' | undefined
|
|
106
|
+
/** Chip text captured when a tab opens. */
|
|
107
|
+
readonly title: (address: string) => string
|
|
108
|
+
readonly guide?: readonly SidebarRightGuideEntry[] | undefined
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** The registry service (stage one), as a registrant uses it. */
|
|
112
|
+
export interface SidebarRightTabsService {
|
|
113
|
+
/** Register one type; the returned disposer removes it and is idempotent. */
|
|
114
|
+
register(definition: SidebarRightTabDefinition): () => void
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** Live tab information the framework binds for a body: the presentation and the record. */
|
|
118
|
+
export interface SidebarTabInfo {
|
|
119
|
+
readonly tab: {
|
|
120
|
+
/** Only a tab on screen is visible: a docked body requires expansion and selection, a float survives a collapse. */
|
|
121
|
+
readonly visible: boolean
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* The framework's own props for a `sidebar.right.pane.tab` body.
|
|
127
|
+
*
|
|
128
|
+
* `sessionId` is the slot's session scope; `useTabInfo` is the slot-owned hook
|
|
129
|
+
* the framework injects (declared as `inject.hooks.tabInfo` in the slot map and
|
|
130
|
+
* delivered flattened under that `use…` name). Both are optional here because a
|
|
131
|
+
* composition — or a test — may hand the body neither, and this module falls
|
|
132
|
+
* back rather than throwing.
|
|
133
|
+
*/
|
|
134
|
+
export interface SidebarTabFrameworkProps {
|
|
135
|
+
readonly sessionId?: string | undefined
|
|
136
|
+
readonly useTabInfo?: (() => SidebarTabInfo) | undefined
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** Owner share of one actions-menu occurrence: the menu's own dismiss seat. */
|
|
140
|
+
export interface SidebarTabMenuOwnerProps {
|
|
141
|
+
readonly dismiss?: (() => void) | undefined
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Options one `slots.register` accepts, as far as this module uses them.
|
|
146
|
+
*
|
|
147
|
+
* `key` addresses a keyed seat; `id` and `order` place a list entry.
|
|
148
|
+
*/
|
|
149
|
+
export interface SidebarTabSlotOptions {
|
|
150
|
+
name: string
|
|
151
|
+
key?: string | undefined
|
|
152
|
+
id?: string | undefined
|
|
153
|
+
order?: number | undefined
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** The slot service, as this module's registrants use it. */
|
|
157
|
+
export interface SidebarTabSlots {
|
|
158
|
+
inject(slot: string, callback: () => unknown): unknown
|
|
159
|
+
register<Props>(options: SidebarTabSlotOptions, component: (props: Props) => ReactNode): unknown
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** The client services the tab's registration needs; each may be absent from a composition. */
|
|
163
|
+
export interface SidebarTabServices {
|
|
164
|
+
effect(execute: () => unknown, label?: string): unknown
|
|
165
|
+
slots: SidebarTabSlots
|
|
166
|
+
sidebarRightTabs: SidebarRightTabsService
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** The tab body's props: the framework's own, plus the seats this module binds. */
|
|
170
|
+
export interface SidebarTabBodyProps {
|
|
171
|
+
/** The session the tab belongs to — the panel shows that session's project only. */
|
|
172
|
+
sessionId: string | undefined
|
|
173
|
+
/** Whether the tab is on screen; an off-screen panel stops polling. */
|
|
174
|
+
visible: boolean
|
|
175
|
+
/** The poll interval, followed live so a change in the settings popup reaches the panel. */
|
|
176
|
+
refreshMs: number
|
|
177
|
+
t: Translate
|
|
178
|
+
hostT: Translate
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** The settings popup's content, with the seats it needs. */
|
|
182
|
+
export interface SidebarSettingsProps {
|
|
183
|
+
refreshMs: number
|
|
184
|
+
/** Write a new interval; the popup's own row is the only writer. */
|
|
185
|
+
onRefreshMs: (value: number) => void
|
|
186
|
+
onClose: () => void
|
|
187
|
+
t: Translate
|
|
188
|
+
hostT: Translate
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Whether the settings popup is on screen, and how the menu row reaches it.
|
|
193
|
+
*
|
|
194
|
+
* The row and the popup are not in one tree: an actions-menu item that acts must
|
|
195
|
+
* dismiss the menu, so the row cannot render the popup itself — it opens this
|
|
196
|
+
* store, the menu closes, and the popup's own entry in the floating layer renders
|
|
197
|
+
* from the same value. It is a store rather than a state setter because exactly
|
|
198
|
+
* one side opens and the other subscribes.
|
|
199
|
+
*/
|
|
200
|
+
export interface SettingsDialogStore {
|
|
201
|
+
isOpen(): boolean
|
|
202
|
+
open(): void
|
|
203
|
+
close(): void
|
|
204
|
+
subscribe(listener: () => void): () => void
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Build a {@link SettingsDialogStore}, closed.
|
|
209
|
+
* @returns the store the menu row and the popup share.
|
|
210
|
+
*/
|
|
211
|
+
export function createSettingsDialogStore(): SettingsDialogStore {
|
|
212
|
+
let open = false
|
|
213
|
+
const listeners = new Set<() => void>()
|
|
214
|
+
const publish = (next: boolean): void => {
|
|
215
|
+
if (next === open) return
|
|
216
|
+
open = next
|
|
217
|
+
for (const listener of listeners) listener()
|
|
218
|
+
}
|
|
219
|
+
return {
|
|
220
|
+
isOpen: () => open,
|
|
221
|
+
open: () => publish(true),
|
|
222
|
+
close: () => publish(false),
|
|
223
|
+
subscribe: (listener: () => void): (() => void) => {
|
|
224
|
+
listeners.add(listener)
|
|
225
|
+
return () => listeners.delete(listener)
|
|
226
|
+
},
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/** Run one render when `open` flips, so a closed popup draws nothing at all. */
|
|
231
|
+
function useSettingsOpen(store: SettingsDialogStore): boolean {
|
|
232
|
+
const [open, setOpen] = useState(() => store.isOpen())
|
|
233
|
+
useEffect(() => store.subscribe(() => setOpen(store.isOpen())), [store])
|
|
234
|
+
return open
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/** Follow the interval store so both the body and the popup re-render on a change. */
|
|
238
|
+
function useRefreshMs(store: RefreshStore): number {
|
|
239
|
+
const [value, setValue] = useState(() => store.get())
|
|
240
|
+
useEffect(() => store.subscribe(() => setValue(store.get())), [store])
|
|
241
|
+
return value
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/** Copy the type publishes to the guide page; overridable so the design stand can name its picture. */
|
|
245
|
+
export interface SidebarTabCopy {
|
|
246
|
+
title: () => string
|
|
247
|
+
description: () => string
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/** What {@link registerSidebarTab} wires up; the product and the design stand differ only here. */
|
|
251
|
+
export interface RegisterSidebarTabOptions {
|
|
252
|
+
/** The shell's locale service, when the composition has one. */
|
|
253
|
+
locale: TabLocale | undefined
|
|
254
|
+
/** The poll interval shared by the body and the popup. */
|
|
255
|
+
refresh: RefreshStore
|
|
256
|
+
/** The tab body. */
|
|
257
|
+
body: (props: SidebarTabBodyProps) => ReactNode
|
|
258
|
+
/** The popup's content. */
|
|
259
|
+
settings: (props: SidebarSettingsProps) => ReactNode
|
|
260
|
+
/** The guide page's copy for this type; the product's own by default. */
|
|
261
|
+
copy?: SidebarTabCopy | undefined
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/** Nothing on screen when no tab information arrives: the frame renders every entry, hidden or not. */
|
|
265
|
+
const ALWAYS_VISIBLE: SidebarTabInfo = { tab: { visible: true } }
|
|
266
|
+
|
|
267
|
+
function useAlwaysVisible(): SidebarTabInfo {
|
|
268
|
+
return ALWAYS_VISIBLE
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Register the panel as a tab type of DSH's own right sidebar.
|
|
273
|
+
*
|
|
274
|
+
* Five registrations, all disposed with the fiber: the type in the registry, its
|
|
275
|
+
* body and its chip title under their keyed seats, the settings row in the chip's
|
|
276
|
+
* actions menu, and the settings popup in the frame-wide floating layer. A
|
|
277
|
+
* composition that lacks any of the services keeps the surfaces it has — the
|
|
278
|
+
* settings page, the toasts and the host half never depend on this module.
|
|
279
|
+
* @param services - the injected `slots` registry, the right-sidebar tab registry, and `effect`.
|
|
280
|
+
* @param options - the two surfaces to draw, the interval they share, and the guide copy.
|
|
281
|
+
*/
|
|
282
|
+
export function registerSidebarTab(
|
|
283
|
+
services: SidebarTabServices,
|
|
284
|
+
options: RegisterSidebarTabOptions,
|
|
285
|
+
): void {
|
|
286
|
+
const t = tabTranslate(options.locale)
|
|
287
|
+
const copy: SidebarTabCopy = options.copy ?? {
|
|
288
|
+
title: () => t('tab'),
|
|
289
|
+
description: () => t('tabDescription'),
|
|
290
|
+
}
|
|
291
|
+
const store = createSettingsDialogStore()
|
|
292
|
+
|
|
293
|
+
services.effect(
|
|
294
|
+
() =>
|
|
295
|
+
services.sidebarRightTabs.register({
|
|
296
|
+
id: TAB_ID,
|
|
297
|
+
kind: TAB_KIND,
|
|
298
|
+
title: () => copy.title(),
|
|
299
|
+
guide: [
|
|
300
|
+
{
|
|
301
|
+
id: TAB_GUIDE_ENTRY_ID,
|
|
302
|
+
order: TAB_GUIDE_ORDER,
|
|
303
|
+
title: () => copy.title(),
|
|
304
|
+
description: () => copy.description(),
|
|
305
|
+
},
|
|
306
|
+
],
|
|
307
|
+
}),
|
|
308
|
+
'dsh-project-mcp: sidebar tab type',
|
|
309
|
+
)
|
|
310
|
+
|
|
311
|
+
services.slots.inject(TAB_SLOT, () =>
|
|
312
|
+
services.slots.register({ name: TAB_SLOT, key: TAB_ID }, (props: SidebarTabFrameworkProps) =>
|
|
313
|
+
h(TabBody, { framework: props, locale: options.locale, refresh: options.refresh, body: options.body }),
|
|
314
|
+
),
|
|
315
|
+
)
|
|
316
|
+
|
|
317
|
+
// The chip's title is re-read here on every render, which is what makes the
|
|
318
|
+
// tab's own label follow a language switch. The registry's `title` thunk above
|
|
319
|
+
// only covers the moment a tab opens: a record keeps the text it was minted
|
|
320
|
+
// with until this seat overrides it.
|
|
321
|
+
services.slots.inject(TAB_TITLE_SLOT, () =>
|
|
322
|
+
services.slots.register({ name: TAB_TITLE_SLOT, key: TAB_ID }, () => h(TabChipTitle, { copy })),
|
|
323
|
+
)
|
|
324
|
+
|
|
325
|
+
services.slots.inject(TAB_MENU_SLOT, () =>
|
|
326
|
+
services.slots.register(
|
|
327
|
+
{ name: TAB_MENU_SLOT, id: TAB_MENU_ID, order: TAB_MENU_ORDER },
|
|
328
|
+
(props: SidebarTabMenuOwnerProps) =>
|
|
329
|
+
h(MenuRow, { locale: options.locale, store, dismiss: props.dismiss }),
|
|
330
|
+
),
|
|
331
|
+
)
|
|
332
|
+
|
|
333
|
+
services.slots.inject(SETTINGS_DIALOG_SLOT, () =>
|
|
334
|
+
services.slots.register(
|
|
335
|
+
{ name: SETTINGS_DIALOG_SLOT, id: SETTINGS_DIALOG_ID, order: SETTINGS_DIALOG_ORDER },
|
|
336
|
+
() =>
|
|
337
|
+
h(SettingsDialog, {
|
|
338
|
+
locale: options.locale,
|
|
339
|
+
store,
|
|
340
|
+
refresh: options.refresh,
|
|
341
|
+
settings: options.settings,
|
|
342
|
+
}),
|
|
343
|
+
),
|
|
344
|
+
)
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* The tab body: the framework's props, the two translate seats and the live
|
|
349
|
+
* interval, handed to the surface the entry supplied.
|
|
350
|
+
* @param props - the framework's share plus the registration's own options.
|
|
351
|
+
* @returns the panel element tree.
|
|
352
|
+
*/
|
|
353
|
+
export function TabBody(props: {
|
|
354
|
+
framework: SidebarTabFrameworkProps
|
|
355
|
+
locale: TabLocale | undefined
|
|
356
|
+
refresh: RefreshStore
|
|
357
|
+
body: (props: SidebarTabBodyProps) => ReactNode
|
|
358
|
+
}): ReactNode {
|
|
359
|
+
const t = useTabTranslate(props.locale)
|
|
360
|
+
const hostT = hostTranslate(props.locale)
|
|
361
|
+
const refreshMs = useRefreshMs(props.refresh)
|
|
362
|
+
// Called unconditionally — the framework injects this hook for the seat. A
|
|
363
|
+
// composition that somehow hands none is drawn as an on-screen tab rather than
|
|
364
|
+
// as an error: `visible` only paces the panel's own polling.
|
|
365
|
+
const info = (props.framework.useTabInfo ?? useAlwaysVisible)()
|
|
366
|
+
// An element, not a bare call: the body is a component of its own, so its
|
|
367
|
+
// hooks belong to its own fiber rather than to this adapter's.
|
|
368
|
+
return h(props.body, {
|
|
369
|
+
sessionId: props.framework.sessionId,
|
|
370
|
+
visible: info.tab.visible,
|
|
371
|
+
refreshMs,
|
|
372
|
+
t,
|
|
373
|
+
hostT,
|
|
374
|
+
})
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* The chip's title: the type's own name, read through the entry's copy thunk on
|
|
379
|
+
* every render.
|
|
380
|
+
*
|
|
381
|
+
* The registry captures a title when a tab opens, and a record keeps that text
|
|
382
|
+
* until this seat replaces it — so without this registration an open tab would
|
|
383
|
+
* keep whatever language it was opened in. The component takes nothing from the
|
|
384
|
+
* tab: the panel's label is the same for every occurrence.
|
|
385
|
+
* @param props - the type's copy.
|
|
386
|
+
* @returns the title text.
|
|
387
|
+
*/
|
|
388
|
+
export function TabChipTitle(props: { copy: SidebarTabCopy }): ReactNode {
|
|
389
|
+
return props.copy.title()
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* The row this plugin adds to a tab chip's actions menu.
|
|
394
|
+
*
|
|
395
|
+
* It dismisses the menu first — the contract for an item that acts, and the
|
|
396
|
+
* reason the popup is not drawn here: the menu unmounts on dismiss, so a popup
|
|
397
|
+
* inside the item would go with it. The row reads the plugin's own dictionary and
|
|
398
|
+
* follows the language like every other surface.
|
|
399
|
+
* @param props - the locale seat, the store the popup subscribes to, and the menu's dismiss seat.
|
|
400
|
+
* @returns the menu item.
|
|
401
|
+
*/
|
|
402
|
+
export function MenuRow(props: {
|
|
403
|
+
locale: TabLocale | undefined
|
|
404
|
+
store: SettingsDialogStore
|
|
405
|
+
dismiss?: (() => void) | undefined
|
|
406
|
+
}): ReactNode {
|
|
407
|
+
const t = useTabTranslate(props.locale)
|
|
408
|
+
return h(
|
|
409
|
+
'button',
|
|
410
|
+
{
|
|
411
|
+
type: 'button',
|
|
412
|
+
role: 'menuitem',
|
|
413
|
+
style: STYLE.menuItem,
|
|
414
|
+
onClick: () => {
|
|
415
|
+
props.dismiss?.()
|
|
416
|
+
props.store.open()
|
|
417
|
+
},
|
|
418
|
+
},
|
|
419
|
+
t('settingsMenuItem'),
|
|
420
|
+
)
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
/**
|
|
424
|
+
* The settings popup: the tab's own settings, rendered as an entry of the
|
|
425
|
+
* frame-wide floating layer.
|
|
426
|
+
*
|
|
427
|
+
* Nothing is drawn while the popup is closed, so the layer holds an empty cell
|
|
428
|
+
* and the frame's click-through is untouched. The backdrop is the entry's own
|
|
429
|
+
* element, which is what makes the layer's `pointer-events: auto` rule apply to
|
|
430
|
+
* it.
|
|
431
|
+
* @param props - the locale seat, the open/closed store, the interval and the content.
|
|
432
|
+
* @returns the backdrop with the popup card, or `null` while it is closed.
|
|
433
|
+
*/
|
|
434
|
+
export function SettingsDialog(props: {
|
|
435
|
+
locale: TabLocale | undefined
|
|
436
|
+
store: SettingsDialogStore
|
|
437
|
+
refresh: RefreshStore
|
|
438
|
+
settings: (props: SidebarSettingsProps) => ReactNode
|
|
439
|
+
}): ReactNode {
|
|
440
|
+
const t = useTabTranslate(props.locale)
|
|
441
|
+
const hostT = hostTranslate(props.locale)
|
|
442
|
+
const refreshMs = useRefreshMs(props.refresh)
|
|
443
|
+
const open = useSettingsOpen(props.store)
|
|
444
|
+
if (!open) return null
|
|
445
|
+
const close = (): void => props.store.close()
|
|
446
|
+
return h(
|
|
447
|
+
'div',
|
|
448
|
+
{ style: STYLE.backdrop, onClick: close },
|
|
449
|
+
h(
|
|
450
|
+
'div',
|
|
451
|
+
{
|
|
452
|
+
style: STYLE.dialog,
|
|
453
|
+
role: 'dialog',
|
|
454
|
+
'aria-modal': true,
|
|
455
|
+
'aria-label': t('settingsMenuItem'),
|
|
456
|
+
// A press inside the card must not reach the backdrop's close.
|
|
457
|
+
onClick: (event: { stopPropagation: () => void }) => event.stopPropagation(),
|
|
458
|
+
},
|
|
459
|
+
// An element too: the popup's content is a component with hooks of its
|
|
460
|
+
// own — the panel polls, and a bare call would fold them into this frame.
|
|
461
|
+
h(props.settings, {
|
|
462
|
+
refreshMs,
|
|
463
|
+
onRefreshMs: (value: number) => props.refresh.set(value),
|
|
464
|
+
onClose: close,
|
|
465
|
+
t,
|
|
466
|
+
hostT,
|
|
467
|
+
}),
|
|
468
|
+
),
|
|
469
|
+
)
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
/**
|
|
473
|
+
* The entries' own style.
|
|
474
|
+
*
|
|
475
|
+
* The popup is deliberately not the panel's `STYLE`: it draws a menu row and a
|
|
476
|
+
* frame-wide card, and neither is part of the tab's surface contract. The tokens
|
|
477
|
+
* are the same alias variables every other surface uses, so the card follows the
|
|
478
|
+
* theme — including the design stand's, which renders the same components.
|
|
479
|
+
*/
|
|
480
|
+
const STYLE = {
|
|
481
|
+
/**
|
|
482
|
+
* The menu row. The kit's own items are hashed CSS the plugin cannot borrow,
|
|
483
|
+
* so the row is drawn the way the plugin draws every other control: an inline
|
|
484
|
+
* style over the alias tokens, matching the kit's item in size and weight.
|
|
485
|
+
*/
|
|
486
|
+
menuItem: {
|
|
487
|
+
display: 'block',
|
|
488
|
+
width: '100%',
|
|
489
|
+
padding: '4px 10px',
|
|
490
|
+
border: 'none',
|
|
491
|
+
borderRadius: 4,
|
|
492
|
+
background: 'transparent',
|
|
493
|
+
color: 'inherit',
|
|
494
|
+
font: 'inherit',
|
|
495
|
+
textAlign: 'left',
|
|
496
|
+
cursor: 'pointer',
|
|
497
|
+
} satisfies CSSProperties,
|
|
498
|
+
/** The layer spans the frame, so the backdrop does too; the card is centred over the whole application. */
|
|
499
|
+
backdrop: {
|
|
500
|
+
position: 'absolute',
|
|
501
|
+
inset: 0,
|
|
502
|
+
display: 'flex',
|
|
503
|
+
alignItems: 'center',
|
|
504
|
+
justifyContent: 'center',
|
|
505
|
+
background: 'rgba(0, 0, 0, 0.4)',
|
|
506
|
+
} satisfies CSSProperties,
|
|
507
|
+
/**
|
|
508
|
+
* The card, which scrolls its own content: the panel lists every project with
|
|
509
|
+
* a live session, and a project with many servers is taller than any window.
|
|
510
|
+
*/
|
|
511
|
+
dialog: {
|
|
512
|
+
maxWidth: 'min(560px, 92vw)',
|
|
513
|
+
maxHeight: '80vh',
|
|
514
|
+
overflowY: 'auto',
|
|
515
|
+
borderRadius: 8,
|
|
516
|
+
border: '1px solid var(--dsw-alias-border-l1, rgba(127, 127, 127, 0.25))',
|
|
517
|
+
background: 'var(--dsw-alias-bg-layer-2, #1f1f22)',
|
|
518
|
+
color: 'var(--dsw-alias-label-primary, inherit)',
|
|
519
|
+
boxShadow: '0 12px 32px rgba(0, 0, 0, 0.45)',
|
|
520
|
+
} satisfies CSSProperties,
|
|
521
|
+
} as const
|