@moonsand/dsh-ui-optimize 0.8.4 → 0.9.26

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 CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  English | [中文](README.zh.md)
4
4
 
5
- Two independent features for the DeepSeek Harness web interface: a **theme gallery** of eight minimalist themes (each defining one palette for light and one for dark), and the **desktop Reload/Restart buttons** at the sidebar foot — every feature has its own switch.
5
+ Three independent features for the DeepSeek Harness web interface, each with its own switch: a **theme gallery** of eight minimalist themes (each defining one palette for light and one for dark), the **desktop Reload/Restart buttons** at the sidebar foot, and **sidebar panel folding** — the panel rows collapse into a single **Panels** entry that opens a two-column launcher.
6
6
 
7
7
  Colours travel only through `ctx.theme.overrideTokens`, as a single layer of theme variables. No structural CSS is injected and no other plugin's DOM is read, so an upstream redesign can at worst make the colours inert — it cannot break the layout.
8
8
 
@@ -25,6 +25,14 @@ Two switches control the sidebar-foot buttons:
25
25
  - **Reload UI** — reloads the page and client plugins only; the Host and running tasks keep going
26
26
  - **Restart app** — restarts the whole app including its Host; interrupts the current conversation. **Desktop app only** — in a browser it degrades to reloading the page
27
27
 
28
+ ### Sidebar
29
+
30
+ A switch folds the panel rows in the left rail into a single **Panels** entry. Clicking it opens a two-column launcher with the panel icons, a title and count, a search box once there are more than seven panels, and keyboard control (↑ ↓ to move, Enter to open, Esc to close). Panels that register later — including ones added by other plugins — are picked up on the next open, so nothing silently disappears from the list.
31
+
32
+ The entry calls the shell's own panel-selection API instead of synthesising clicks. A watchdog measures the folded row after mount and on every resize: if it cannot be measured, the switch turns itself off and the native sidebar comes back rather than leaving an empty rail.
33
+
34
+ The **More** row keeps its own line. Folding it in was tried and dropped: the shell's overflow menu only opens from a trusted click, which a plugin cannot produce, and the synthetic pointer events that came close also closed the launcher through the shell's click-outside handler.
35
+
28
36
  ## Relationship to dsh-desktop-restart
29
37
 
30
38
  The desktop actions are ported from [`@moonsand/dsh-desktop-restart`](https://github.com/MoonSand/dsh-desktop-restart) and use their own route prefix, `/ui-optimize/desktop`.
@@ -37,6 +45,9 @@ Both plugins can be installed at the same time without crashing, but you would g
37
45
  - Restart works only in the desktop app; a browser session can only reload
38
46
  - Restart logs still go to `%TEMP%\dsh-desktop-restart.log`, inherited from the ported source
39
47
  - The restart action is a process-level operation that cannot be verified automatically
48
+ - The **More** row is not folded; it stays in the native rail
49
+ - The launcher keeps the shell's own panel order — it does not sort, pin or reorder
50
+ - Sidebar folding and `dsh-sidebar-shelf` rewrite the same rail; enable one of them, not both
40
51
 
41
52
  ## Development
42
53
 
package/README.zh.md CHANGED
@@ -2,10 +2,11 @@
2
2
 
3
3
  [English](README.md) | 中文
4
4
 
5
- 给 DeepSeek Harness 界面换主题,并把「刷新界面 / 重启应用」两个按钮收进同一个插件——两个功能各自独立开关。
5
+ 给 DeepSeek Harness 界面换主题、把「刷新界面 / 重启应用」收进同一个插件,并把侧栏的面板列表收成一个入口——三个功能各自独立开关。
6
6
 
7
7
  - **主题画廊**:8 套极简主题,浅色与深色各定义一组配色,点一张卡片整套配色生效
8
8
  - **桌面操作**:侧栏底部的刷新与重启按钮,可分别关掉
9
+ - **侧栏收纳**:面板行收成一个「面板」入口,点开是两列启动面板
9
10
 
10
11
  配色只通过 `ctx.theme.overrideTokens` 以**单层**覆盖主题变量,不注入任何结构性 CSS、不读写其他插件的 DOM,所以宿主改版最多让颜色不生效,不会把界面layout弄坏。
11
12
 
@@ -43,6 +44,14 @@ dsh plugin 或 GUI 插件管理:安装 @moonsand/dsh-ui-optimize
43
44
  - **刷新界面**:只重新加载页面与客户端插件,Host 与正在跑的任务不受影响
44
45
  - **重启应用**:重启整个应用(含 Host),会中断当前对话;**仅桌面端可用**,网页端会降级为刷新页面
45
46
 
47
+ ### 侧栏
48
+
49
+ 一个开关把左侧竖栏里的面板行收成一个「面板」入口。点开是两列启动面板:图标、标题与数量、面板多于 7 个时出现搜索框,并支持键盘操作(↑ ↓ 移动、回车打开、Esc 关闭)。之后才注册的面板——包括其他插件加进来的——在下次打开时自动出现,不会漏。
50
+
51
+ 入口走宿主自己的面板选中接口,不伪造点击。挂载后与每次缩放时都有一个看门狗在量尺寸:量不到就把开关自动关掉、还原原生侧栏,而不是留一根空栏。
52
+
53
+ 「更多」保持独立一行。把它也收进去试过并放弃了:宿主的溢出菜单只认真实点击,插件造不出来;而伪造的指针事件又会被宿主的「点外部即关闭」吃掉,刚打开的弹层立刻被关掉。
54
+
46
55
  ## 与 dsh-desktop-restart 的关系
47
56
 
48
57
  本插件的桌面操作移植自 [`@moonsand/dsh-desktop-restart`](https://github.com/MoonSand/dsh-desktop-restart),并已改用独立的路由前缀 `/ui-optimize/desktop`。
@@ -55,6 +64,9 @@ dsh plugin 或 GUI 插件管理:安装 @moonsand/dsh-ui-optimize
55
64
  - 重启只适用于桌面端;网页端只能刷新
56
65
  - 重启日志仍写在 `%TEMP%\dsh-desktop-restart.log`(沿用移植来源的路径)
57
66
  - 重启动作为进程级操作,无法在自动化测试中验证,只能人工点一次确认
67
+ - 「更多」没有收进弹层,仍在原生竖栏里
68
+ - 弹层沿用宿主自己的面板顺序,不排序、不置顶、不重排
69
+ - 侧栏收纳与 `dsh-sidebar-shelf` 改的是同一根竖栏,两个只能开一个
58
70
 
59
71
  ## 开发
60
72
 
package/client.js CHANGED
@@ -57,6 +57,15 @@ window.__ModuleLoader__.load({
57
57
  'theme.rose.hint': 'Dusty rose — warm without being loud',
58
58
  applyFailed: 'The theme is not reaching the interface.',
59
59
  'section.desktop': 'Desktop actions',
60
+ 'section.sidebar': 'Sidebar',
61
+ 'sidebar.shelf': 'Panels',
62
+ 'sidebar.shelfEmpty': 'No matching panels',
63
+ 'sidebar.count': 'panels',
64
+ 'sidebar.search': 'Search panels…',
65
+ 'sidebar.hint': '↑↓ move · ↵ open · Esc close',
66
+ 'sidebar.more': 'More',
67
+ 'sidebar.switch': 'Fold the sidebar menu into one Panels entry',
68
+ 'sidebar.switchHint': 'The menu rows collapse into a single launcher that lists every panel; panels a future plugin registers show up on their own. Also narrows the New Session button',
60
69
  'desktop.label': 'Restart app',
61
70
  'desktop.hint': 'Restart DeepSeek Harness (app and Host)',
62
71
  'desktop.refresh': 'Reload UI',
@@ -105,6 +114,15 @@ window.__ModuleLoader__.load({
105
114
  'theme.rose.hint': '灰调玫瑰,暖而不吵',
106
115
  applyFailed: '主题未作用到界面。',
107
116
  'section.desktop': '桌面操作',
117
+ 'section.sidebar': '侧栏',
118
+ 'sidebar.shelf': '面板',
119
+ 'sidebar.shelfEmpty': '没有匹配的面板',
120
+ 'sidebar.count': '个面板',
121
+ 'sidebar.search': '搜索面板…',
122
+ 'sidebar.hint': '↑↓ 选择 · ↵ 打开 · Esc 关闭',
123
+ 'sidebar.more': '更多',
124
+ 'sidebar.switch': '把侧栏菜单收进「面板」',
125
+ 'sidebar.switchHint': '菜单行合并成一个入口,点开列出全部面板;新插件注册的面板会自动出现。同时把「新会话」按钮收窄',
108
126
  'desktop.label': '重启应用',
109
127
  'desktop.hint': '重启 DeepSeek Harness(应用与 Host)',
110
128
  'desktop.refresh': '刷新界面',
@@ -383,7 +401,7 @@ window.__ModuleLoader__.load({
383
401
  * ------------------------------------------------------------------ */
384
402
 
385
403
  function defaultState() {
386
- return { version: 3, theme: null, reload: true, restart: true }
404
+ return { version: 4, theme: null, reload: true, restart: true, sidebar: false }
387
405
  }
388
406
 
389
407
  function normalize(stored) {
@@ -394,6 +412,7 @@ window.__ModuleLoader__.load({
394
412
  }
395
413
  if (typeof stored.reload === 'boolean') out.reload = stored.reload
396
414
  if (typeof stored.restart === 'boolean') out.restart = stored.restart
415
+ if (typeof stored.sidebar === 'boolean') out.sidebar = stored.sidebar
397
416
  return out
398
417
  }
399
418
 
@@ -790,6 +809,29 @@ body:not([data-ds-dark-theme]) .dsuik-mc > .dsuik-mc-b{display:none;}
790
809
  }),
791
810
  ),
792
811
  ),
812
+ h(
813
+ 'div',
814
+ { className: 'dsuik-section' },
815
+ h('p', { className: 'dsuik-sectiontitle' }, translate('section.sidebar')),
816
+ h(
817
+ 'div',
818
+ { className: 'dsuik-row' },
819
+ h(
820
+ 'div',
821
+ { className: 'dsuik-rowtext' },
822
+ h('span', { className: 'dsuik-rowname' }, translate('sidebar.switch')),
823
+ h('span', { className: 'dsuik-rowhint' }, translate('sidebar.switchHint')),
824
+ ),
825
+ h(Switch, {
826
+ checked: state.sidebar === true,
827
+ disabled: !slotsCoreApi,
828
+ label: translate('sidebar.switch'),
829
+ onChange: function (next) {
830
+ store.setFlag('sidebar', next)
831
+ },
832
+ }),
833
+ ),
834
+ ),
793
835
  surface.controller && !surface.controller.active()
794
836
  ? h(
795
837
  'p',
@@ -1199,6 +1241,486 @@ body:not([data-ds-dark-theme]) .dsuik-mc > .dsuik-mc-b{display:none;}
1199
1241
  )
1200
1242
  }
1201
1243
 
1244
+ /* ------------------------------------------------------------------ *
1245
+ * Sidebar panel shelf (feature 3)
1246
+ *
1247
+ * Modelled on dsh-sidebar-shelf: one native row registered into
1248
+ * `sidebar.panellist` becomes the launcher, one scoped rule hides the other
1249
+ * rows, and the popover lists every registered panel read live from
1250
+ * `entriesOfSlot` — so a panel a future plugin registers shows up on its own.
1251
+ *
1252
+ * Opening a panel goes through the official `ctx.layout.selectPanel(id)`;
1253
+ * no synthetic clicks on the shell's DOM.
1254
+ *
1255
+ * Degradation: the slots helper package is required lazily. If it is not
1256
+ * available, this feature stays off and every other feature is unaffected.
1257
+ * ------------------------------------------------------------------ */
1258
+
1259
+ const SHELF_ID = 'muik-panels'
1260
+ const SHELF_ATTR = 'data-muik-shelf'
1261
+ const SHELF_ROW_ATTR = 'data-muik-shelf-row'
1262
+
1263
+ let slotsCoreApi = null
1264
+ try {
1265
+ slotsCoreApi = require('@deepseek-ai/dsh-client-ui-slots')
1266
+ } catch (err) {
1267
+ slotsCoreApi = null
1268
+ }
1269
+
1270
+ let reactDomApi = null
1271
+ try {
1272
+ reactDomApi = require('react-dom')
1273
+ } catch (err) {
1274
+ reactDomApi = null
1275
+ }
1276
+
1277
+ const SHELF_CSS = `
1278
+ [${SHELF_ATTR}="on"] > nav > *:not([${SHELF_ROW_ATTR}]):not([data-muik-keep]){display:none!important}
1279
+ button.muik-shelf-row{display:flex;align-items:center;gap:10px;box-sizing:border-box;width:100%;height:36px;padding:0 10px;border:0;border-radius:8px;background:transparent;color:var(--dsw-alias-label-primary,inherit);font:inherit;font-size:13px;text-align:left;cursor:pointer}
1280
+ button.muik-shelf-row:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(127,127,127,.12))}
1281
+ button.muik-shelf-row:focus-visible{outline:2px solid var(--dsw-alias-brand-primary,#4d6bfe);outline-offset:-2px}
1282
+ .muik-shelf-glyph{flex:none;display:inline-flex;align-items:center;justify-content:center;width:18px;height:18px}
1283
+ .muik-shelf-label{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
1284
+ .muik-shelf-pop{position:fixed;z-index:2147483000;box-sizing:border-box;min-width:190px;max-height:min(60vh,420px);overflow:auto;padding:6px;border-radius:10px;background:var(--dsw-alias-bg-layer-1,#fff);border:1px solid var(--dsw-alias-border-l2,rgba(0,0,0,.12));box-shadow:0 10px 28px rgba(0,0,0,.18);color:var(--dsw-alias-label-primary,inherit)}
1285
+ .muik-shelf-grid{display:grid;grid-template-columns:1fr 1fr;gap:2px;max-height:min(58vh,420px);overflow:auto;padding:2px;overscroll-behavior:contain}
1286
+ .muik-shelf-tile{display:flex;align-items:center;gap:8px;min-width:0;height:38px;padding:0 10px;border:0;border-radius:7px;background:transparent;color:inherit;font:inherit;font-size:13px;text-align:left;cursor:pointer}
1287
+ .muik-shelf-tile:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(127,127,127,.12))}
1288
+ .muik-shelf-tile:focus-visible{outline:2px solid var(--dsw-alias-brand-primary,#4d6bfe);outline-offset:-2px}
1289
+ .muik-shelf-tileglyph{flex:none;display:inline-flex;align-items:center;justify-content:center;width:18px;height:18px}
1290
+ .muik-shelf-tile--wide{grid-column:1 / -1;margin-top:2px;border-top:1px solid var(--dsw-alias-border-l2,rgba(0,0,0,.1));border-radius:0 0 7px 7px}
1291
+ .muik-shelf-tilelabel{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
1292
+ .muik-shelf-fallback{display:inline-flex;align-items:center;justify-content:center;width:18px;height:18px;border-radius:4px;background:var(--dsw-alias-interactive-bg-hover,rgba(127,127,127,.16));font-size:11px;font-weight:600}
1293
+ .muik-shelf-head{display:flex;align-items:baseline;gap:8px;padding:6px 8px 7px}
1294
+ .muik-shelf-title{flex:1;min-width:0;font-size:13px;font-weight:600;letter-spacing:.01em}
1295
+ .muik-shelf-meta{flex:none;font-size:11px;color:var(--dsw-alias-label-tertiary,inherit);font-variant-numeric:tabular-nums}
1296
+ .muik-shelf-search{padding:0 4px 6px}
1297
+ .muik-shelf-search input{box-sizing:border-box;width:100%;height:32px;padding:0 10px;border-radius:7px;border:1px solid var(--dsw-alias-border-l2,rgba(0,0,0,.14));background:var(--dsw-alias-bg-layer-2,transparent);color:inherit;font:inherit;font-size:13px;outline:none}
1298
+ .muik-shelf-search input::placeholder{color:var(--dsw-alias-label-tertiary,#888)}
1299
+ .muik-shelf-hint{padding:6px 8px 4px;font-size:11px;color:var(--dsw-alias-label-tertiary,#888)}
1300
+ .muik-shelf-tile--focus{background:var(--dsw-alias-interactive-bg-hover,rgba(127,127,127,.12));outline:2px solid var(--dsw-alias-brand-primary,#4d6bfe);outline-offset:-2px}
1301
+ .muik-shelf-empty{padding:8px 10px;font-size:12px;color:var(--dsw-alias-label-secondary,inherit)}
1302
+ [${SHELF_ATTR}="on"] > button[class*="_newSession"]{height:30px!important;min-height:30px!important;max-height:30px!important}
1303
+ `
1304
+
1305
+ function readPanelEntries(slotsApi) {
1306
+ if (!slotsApi || typeof slotsApi.entriesOfSlot !== 'function') return []
1307
+ let registered = []
1308
+ try {
1309
+ registered = slotsApi.entriesOfSlot('sidebar.panellist') || []
1310
+ } catch (err) {
1311
+ return []
1312
+ }
1313
+ const out = []
1314
+ const seen = new Set()
1315
+ for (let i = 0; i < registered.length; i += 1) {
1316
+ const entry = registered[i]
1317
+ const options = entry && entry.options
1318
+ const id = options && options.id
1319
+ if (typeof id !== 'string' || id === SHELF_ID || seen.has(id)) continue
1320
+ seen.add(id)
1321
+ let label = id
1322
+ try {
1323
+ if (slotsCoreApi && typeof slotsCoreApi.resolveSlotLabel === 'function') {
1324
+ const resolved = slotsCoreApi.resolveSlotLabel(options.label)
1325
+ if (typeof resolved === 'string' && resolved.length > 0) label = resolved
1326
+ } else if (typeof options.label === 'function') {
1327
+ const resolved = options.label()
1328
+ if (typeof resolved === 'string' && resolved.length > 0) label = resolved
1329
+ } else if (typeof options.label === 'string') {
1330
+ label = options.label
1331
+ }
1332
+ } catch (err) {
1333
+ /* a malformed label must never hide a panel */
1334
+ }
1335
+ out.push({
1336
+ id: id,
1337
+ order: typeof options.order === 'number' ? options.order : 0,
1338
+ label: label,
1339
+ icon: entry.component,
1340
+ })
1341
+ }
1342
+ out.sort(function (a, b) {
1343
+ return a.order - b.order
1344
+ })
1345
+ return out
1346
+ }
1347
+
1348
+ /** One glyph from the panel's own slot component, with a safe fallback. */
1349
+ class GlyphBoundary extends React.Component {
1350
+ constructor(props) {
1351
+ super(props)
1352
+ this.state = { failed: false }
1353
+ }
1354
+ static getDerivedStateFromError() {
1355
+ return { failed: true }
1356
+ }
1357
+ componentDidCatch(error) {
1358
+ console.warn('[dsh-ui-optimize] panel icon failed, using fallback', error)
1359
+ }
1360
+ render() {
1361
+ return this.state.failed === true ? this.props.fallback : this.props.children
1362
+ }
1363
+ }
1364
+
1365
+ function PanelGlyph(props) {
1366
+ const panel = props.panel || {}
1367
+ const label = typeof panel.label === 'string' ? panel.label : ''
1368
+ const initial = label.length > 0 ? label.trim().slice(0, 1).toUpperCase() : '?'
1369
+ const fallback = h('span', { className: 'muik-shelf-fallback', 'aria-hidden': 'true' }, initial)
1370
+ const icon = panel.icon
1371
+ if (typeof icon !== 'function' && (typeof icon !== 'object' || icon === null)) return fallback
1372
+ return h(GlyphBoundary, { fallback: fallback }, h(icon, { size: 18, active: false }))
1373
+ }
1374
+
1375
+ function PanelsShelf(props) {
1376
+ const [state, setState] = React.useState(store.state)
1377
+ const [open, setOpen] = React.useState(false)
1378
+ const [panels, setPanels] = React.useState(function () {
1379
+ return readPanelEntries(props.slotsApi)
1380
+ })
1381
+ const [pos, setPos] = React.useState(null)
1382
+ const [query, setQuery] = React.useState('')
1383
+ const [focusIndex, setFocusIndex] = React.useState(-1)
1384
+ const inputRef = React.useRef(null)
1385
+ const tileRefs = React.useRef([])
1386
+ const glyphRef = React.useRef(null)
1387
+ const rowRef = React.useRef(null)
1388
+ const popRef = React.useRef(null)
1389
+ const toggleRef = React.useRef(null)
1390
+ const moreRef = React.useRef(null)
1391
+ const [hasMore, setHasMore] = React.useState(false)
1392
+ const enabled = state.sidebar === true
1393
+
1394
+ const needle = query.trim().toLowerCase()
1395
+ const filtered =
1396
+ needle.length === 0
1397
+ ? panels
1398
+ : panels.filter(function (panel) {
1399
+ return (
1400
+ String(panel.label).toLowerCase().indexOf(needle) !== -1 ||
1401
+ String(panel.id).toLowerCase().indexOf(needle) !== -1
1402
+ )
1403
+ })
1404
+
1405
+ React.useEffect(function () {
1406
+ return store.subscribe(function () {
1407
+ setState(store.state)
1408
+ })
1409
+ }, [])
1410
+
1411
+ React.useEffect(
1412
+ function () {
1413
+ const glyph = glyphRef.current
1414
+ // The shell wraps every panellist entry in its own <button> and draws the
1415
+ // label itself, so the row to mark is that wrapper — not our glyph.
1416
+ const row = glyph && typeof glyph.closest === 'function' ? glyph.closest('button') : null
1417
+ if (!row) return undefined
1418
+ const nav = row.parentElement
1419
+ const root = nav ? nav.parentElement : null
1420
+ if (!root) return undefined
1421
+ rowRef.current = row
1422
+ row.setAttribute(SHELF_ROW_ATTR, '')
1423
+ row.style.display = enabled ? '' : 'none'
1424
+ root.setAttribute(SHELF_ATTR, enabled ? 'on' : 'off')
1425
+
1426
+ // The shell appends its own "More" row after the registered rows, and its
1427
+ // menu holds content that is not a panellist entry. Hiding that row would
1428
+ // strand it, so it is kept visible whenever the actions list has entries.
1429
+ let keepRow = null
1430
+ try {
1431
+ const actions = props.slotsApi.entriesOfSlot('sidebar.panellist.actions') || []
1432
+ if (actions.length > 0) {
1433
+ const kids = nav.children
1434
+ for (let i = kids.length - 1; i >= 0; i -= 1) {
1435
+ if (kids[i] !== row) {
1436
+ keepRow = kids[i]
1437
+ // Kept visible on purpose. The shell's More menu only opens from a
1438
+ // trusted click: synthetic click(), full pointer sequences and a
1439
+ // re-shown row were each tried (0.9.13 / 0.9.23 / 0.9.24 / 0.9.25)
1440
+ // and none opened it, so the row keeps its own place instead of
1441
+ // being folded into the popover.
1442
+ keepRow.setAttribute('data-muik-keep', '')
1443
+ break
1444
+ }
1445
+ }
1446
+ }
1447
+ } catch (err) {
1448
+ keepRow = null
1449
+ }
1450
+ moreRef.current = null
1451
+ setHasMore(false)
1452
+
1453
+ // The row node is ours to keep only while React does not replace it, and a
1454
+ // replaced node silently loses its listener — the shell's own handler then
1455
+ // wins and selects a panel. Hold the latest toggle in a ref so the listener
1456
+ // itself never needs to be re-attached, and swallow the event completely.
1457
+ toggleRef.current = toggle
1458
+
1459
+ function onClick(event) {
1460
+ if (!enabled) return
1461
+ event.preventDefault()
1462
+ event.stopPropagation()
1463
+ if (typeof event.stopImmediatePropagation === 'function') event.stopImmediatePropagation()
1464
+ if (typeof toggleRef.current === 'function') toggleRef.current(row)
1465
+ }
1466
+ row.addEventListener('click', onClick, true)
1467
+
1468
+ /**
1469
+ * Safety net. Hiding rows is the only destructive thing this feature does,
1470
+ * and a bad measurement once left the whole column blank. If the column or
1471
+ * our own row has no measurable box shortly after mounting, put everything
1472
+ * back and leave the native sidebar alone — a degraded feature beats a
1473
+ * missing sidebar, and it recovers without the user touching anything.
1474
+ */
1475
+ function verify() {
1476
+ if (!enabled) return
1477
+ let healthy = true
1478
+ try {
1479
+ const rootRect = root.getBoundingClientRect()
1480
+ const rowRect = row.getBoundingClientRect()
1481
+ healthy = rootRect.width > 0 && rootRect.height > 0 && rowRect.height > 0
1482
+ } catch (err) {
1483
+ healthy = false
1484
+ }
1485
+ if (!healthy) {
1486
+ root.setAttribute(SHELF_ATTR, 'off')
1487
+ row.removeAttribute(SHELF_ROW_ATTR)
1488
+ row.style.display = ''
1489
+ }
1490
+ }
1491
+ const verifyTimer = window.setTimeout(verify, 400)
1492
+ window.addEventListener('resize', verify)
1493
+
1494
+ return function () {
1495
+ row.removeEventListener('click', onClick, true)
1496
+ window.clearTimeout(verifyTimer)
1497
+ window.removeEventListener('resize', verify)
1498
+ row.removeAttribute(SHELF_ROW_ATTR)
1499
+ row.style.display = ''
1500
+ if (keepRow) keepRow.removeAttribute('data-muik-keep')
1501
+ moreRef.current = null
1502
+ if (root.getAttribute(SHELF_ATTR) === 'on') root.setAttribute(SHELF_ATTR, 'off')
1503
+ rowRef.current = null
1504
+ }
1505
+ },
1506
+ [enabled],
1507
+ )
1508
+
1509
+ React.useEffect(
1510
+ function () {
1511
+ if (!open) return undefined
1512
+ function onPointerDown(event) {
1513
+ const inPop = popRef.current && popRef.current.contains(event.target)
1514
+ const inRow = rowRef.current && rowRef.current.contains(event.target)
1515
+ if (!inPop && !inRow) setOpen(false)
1516
+ }
1517
+ function onKeyDown(event) {
1518
+ if (event.key === 'Escape') {
1519
+ setOpen(false)
1520
+ return
1521
+ }
1522
+ if (filtered.length === 0) return
1523
+ if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
1524
+ event.preventDefault()
1525
+ const step = event.key === 'ArrowDown' ? 1 : -1
1526
+ setFocusIndex(function (prev) {
1527
+ const next = prev + step
1528
+ if (next < 0) return filtered.length - 1
1529
+ if (next >= filtered.length) return 0
1530
+ return next
1531
+ })
1532
+ return
1533
+ }
1534
+ if (event.key === 'Enter') {
1535
+ const target = filtered[focusIndex >= 0 ? focusIndex : 0]
1536
+ if (target) {
1537
+ event.preventDefault()
1538
+ pick(target.id)
1539
+ }
1540
+ }
1541
+ }
1542
+ document.addEventListener('mousedown', onPointerDown, true)
1543
+ document.addEventListener('keydown', onKeyDown, true)
1544
+ return function () {
1545
+ document.removeEventListener('mousedown', onPointerDown, true)
1546
+ document.removeEventListener('keydown', onKeyDown, true)
1547
+ }
1548
+ },
1549
+ [open, filtered, focusIndex],
1550
+ )
1551
+
1552
+ function toggle(row) {
1553
+ const next = !open
1554
+ if (next) {
1555
+ setPanels(readPanelEntries(props.slotsApi))
1556
+ setQuery('')
1557
+ setFocusIndex(-1)
1558
+ if (row) {
1559
+ // Drop the card right under the row; alongside the rail when collapsed.
1560
+ const rect = row.getBoundingClientRect()
1561
+ const viewportWidth = window.innerWidth
1562
+ const viewportHeight = window.innerHeight
1563
+ const width = Math.min(300, viewportWidth - 24)
1564
+ const rail = rect.width < 80
1565
+ const preferredLeft = rail ? rect.right + 10 : rect.left
1566
+ const left = Math.min(Math.max(preferredLeft, 12), viewportWidth - width - 12)
1567
+ const top = Math.min(rect.bottom + 6, viewportHeight - 92)
1568
+ setPos({
1569
+ left: Math.round(left),
1570
+ top: Math.round(top),
1571
+ width: Math.round(width),
1572
+ })
1573
+ }
1574
+ }
1575
+ setOpen(next)
1576
+ }
1577
+
1578
+ function pick(id) {
1579
+ setOpen(false)
1580
+ try {
1581
+ props.selectPanel(id)
1582
+ } catch (err) {
1583
+ /* a panel that cannot be selected must not break the row */
1584
+ }
1585
+ }
1586
+
1587
+ /**
1588
+ * Hand a "More" click to the shell's own row button.
1589
+ *
1590
+ * The row is parked by a static stylesheet rule at --muik-more-x/y, so it keeps
1591
+ * a real (tiny) rect to anchor the shell's menu against while taking no space
1592
+ * in the column. Only two custom properties on <html> are written here, then
1593
+ * the button is clicked. No `display`, `position`, size or opacity is touched
1594
+ * at click time: mutating layout properties on a host node the shell is about
1595
+ * to re-render is exactly what collapsed the sidebar before.
1596
+ */
1597
+ function openMore() {
1598
+ const button = moreRef.current
1599
+ if (!button) return
1600
+ const x = pos ? pos.left : 12
1601
+ const y = pos ? pos.top : 120
1602
+ try {
1603
+ const style = document.documentElement.style
1604
+ style.setProperty('--muik-more-x', x + 'px')
1605
+ style.setProperty('--muik-more-y', y + 'px')
1606
+ } catch (err) {
1607
+ /* a missing coordinate only misplaces the menu, it never breaks the row */
1608
+ }
1609
+ // Click only. Replaying pointerdown/mousedown first made the shell open its
1610
+ // menu and immediately dismiss it again (its outside-press handler fires on
1611
+ // the bubbled mousedown). The menu itself is no longer clipped because the
1612
+ // parked row keeps `overflow: visible`.
1613
+ try {
1614
+ button.click()
1615
+ } catch (err) {
1616
+ /* the shell refusing to open its menu must not break the popover */
1617
+ }
1618
+ setOpen(false)
1619
+ }
1620
+
1621
+ const glyph = h(
1622
+ 'span',
1623
+ { ref: glyphRef, className: 'muik-shelf-glyph', 'aria-hidden': 'true' },
1624
+ h(
1625
+ 'svg',
1626
+ { viewBox: '0 0 16 16', width: 18, height: 18, fill: 'currentColor' },
1627
+ h('rect', { x: 1.5, y: 2.5, width: 5, height: 5, rx: 1.2 }),
1628
+ h('rect', { x: 9.5, y: 2.5, width: 5, height: 5, rx: 1.2 }),
1629
+ h('rect', { x: 1.5, y: 9.5, width: 5, height: 5, rx: 1.2 }),
1630
+ h('rect', { x: 9.5, y: 9.5, width: 5, height: 5, rx: 1.2 }),
1631
+ ),
1632
+ )
1633
+
1634
+ if (!open || !pos) return glyph
1635
+
1636
+ const popover = h(
1637
+ 'div',
1638
+ {
1639
+ ref: popRef,
1640
+ className: 'muik-shelf-pop',
1641
+ style: {
1642
+ left: pos.left + 'px',
1643
+ top: pos.top + 'px',
1644
+ width: pos.width ? pos.width + 'px' : undefined,
1645
+ },
1646
+ },
1647
+ h(
1648
+ 'div',
1649
+ { className: 'muik-shelf-head' },
1650
+ h('span', { className: 'muik-shelf-title' }, translate('sidebar.shelf')),
1651
+ h('span', { className: 'muik-shelf-meta' }, filtered.length + ' ' + translate('sidebar.count')),
1652
+ ),
1653
+ panels.length > 7
1654
+ ? h(
1655
+ 'div',
1656
+ { className: 'muik-shelf-search' },
1657
+ h('input', {
1658
+ ref: inputRef,
1659
+ type: 'text',
1660
+ value: query,
1661
+ placeholder: translate('sidebar.search'),
1662
+ autoFocus: true,
1663
+ onChange: function (event) {
1664
+ setQuery(event.target.value)
1665
+ setFocusIndex(-1)
1666
+ },
1667
+ }),
1668
+ )
1669
+ : null,
1670
+ filtered.length === 0
1671
+ ? h('div', { className: 'muik-shelf-empty' }, translate('sidebar.shelfEmpty'))
1672
+ : h(
1673
+ 'div',
1674
+ { className: 'muik-shelf-grid' },
1675
+ filtered.map(function (panel, index) {
1676
+ return h(
1677
+ 'button',
1678
+ {
1679
+ key: panel.id,
1680
+ ref: function (node) {
1681
+ tileRefs.current[index] = node
1682
+ },
1683
+ type: 'button',
1684
+ className:
1685
+ 'muik-shelf-tile' + (index === focusIndex ? ' muik-shelf-tile--focus' : ''),
1686
+ title: panel.label,
1687
+ onMouseEnter: function () {
1688
+ setFocusIndex(index)
1689
+ },
1690
+ onClick: function () {
1691
+ pick(panel.id)
1692
+ },
1693
+ },
1694
+ h('span', { className: 'muik-shelf-tileglyph' }, h(PanelGlyph, { panel: panel })),
1695
+ h('span', { className: 'muik-shelf-tilelabel' }, panel.label),
1696
+ )
1697
+ }),
1698
+ hasMore
1699
+ ? h(
1700
+ 'button',
1701
+ {
1702
+ type: 'button',
1703
+ className: 'muik-shelf-tile muik-shelf-tile--wide',
1704
+ title: translate('sidebar.more'),
1705
+ onClick: function () {
1706
+ openMore()
1707
+ },
1708
+ },
1709
+ h('span', { className: 'muik-shelf-tilelabel' }, translate('sidebar.more')),
1710
+ )
1711
+ : null,
1712
+ ),
1713
+ h('div', { className: 'muik-shelf-hint' }, translate('sidebar.hint')),
1714
+ )
1715
+
1716
+ const portal =
1717
+ reactDomApi && typeof reactDomApi.createPortal === 'function'
1718
+ ? reactDomApi.createPortal(popover, document.body)
1719
+ : popover
1720
+
1721
+ return h(React.Fragment, null, glyph, portal)
1722
+ }
1723
+
1202
1724
  /* ------------------------------------------------------------------ *
1203
1725
  * Plugin
1204
1726
  * ------------------------------------------------------------------ */
@@ -1289,6 +1811,43 @@ body:not([data-ds-dark-theme]) .dsuik-mc > .dsuik-mc-b{display:none;}
1289
1811
  }
1290
1812
  }, 'dsh-ui-optimize: theme layer')
1291
1813
 
1814
+ /* Feature 3. Skipped entirely when the slots helper package is unavailable,
1815
+ * so a missing optional dependency can never take the whole plugin down. */
1816
+ if (slotsCoreApi) {
1817
+ ctx.effect(function () {
1818
+ const style = document.createElement('style')
1819
+ style.setAttribute('data-dsh-ui-optimize', 'sidebar-shelf')
1820
+ style.textContent = SHELF_CSS
1821
+ document.head.appendChild(style)
1822
+ return function () {
1823
+ style.remove()
1824
+ }
1825
+ }, 'dsh-ui-optimize: sidebar shelf styles')
1826
+
1827
+ ctx.slots.inject('sidebar.panellist', function () {
1828
+ return ctx.slots.register(
1829
+ {
1830
+ name: 'sidebar.panellist',
1831
+ id: SHELF_ID,
1832
+ order: -1000,
1833
+ label: function () {
1834
+ return translate('sidebar.shelf')
1835
+ },
1836
+ inject: function () {
1837
+ return {
1838
+ slotsApi: ctx.slots,
1839
+ selectPanel: function (id) {
1840
+ const layout = typeof ctx.get === 'function' ? ctx.get('layout') : undefined
1841
+ if (layout && typeof layout.selectPanel === 'function') layout.selectPanel(id)
1842
+ },
1843
+ }
1844
+ },
1845
+ },
1846
+ PanelsShelf,
1847
+ )
1848
+ })
1849
+ }
1850
+
1292
1851
  ctx.slots.inject('settings.section', function () {
1293
1852
  return ctx.slots.register(
1294
1853
  {
package/locale/en.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "meta": {
3
3
  "title": "dsh-ui-optimize",
4
- "description": "Minimalist theme gallery for the DSH interface: pick one card in Settings and the whole UI re-colours at once — no per-token tuning. Eight themes — Celadon, Linen, Cream, Graphite, Indigo, Slate, Sage, Rose — each define one palette for light and one for dark and follow the Appearance setting automatically. Choosing Default restores the original look. Colours travel only through the theme token layer, so an upstream redesign cannot break the layout or the plugin."
4
+ "description": "Minimalist theme gallery for the DSH interface: pick one card in Settings and the whole UI re-colours at once — no per-token tuning. Eight themes — Celadon, Linen, Cream, Graphite, Indigo, Slate, Sage, Rose — each define one palette for light and one for dark and follow the Appearance setting automatically. Choosing Default restores the original look. Colours travel only through the theme token layer, so an upstream redesign cannot break the layout or the plugin. The same page also folds the sidebar panel rows into one Panels entry that opens a two-column launcher with search and keyboard control, and adds the desktop Reload/Restart buttons at the sidebar foot — each feature has its own switch."
5
5
  }
6
6
  }
package/locale/zh.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "meta": {
3
3
  "title": "dsh-ui-optimize",
4
- "description": "给 DSH 界面换主题的极简插件:设置页里只有一排主题卡片,点一下整套界面配色跟着换,不必逐个去调颜色。内置 8 套主题——青瓷、亚麻、奶油、石墨、靛蓝、雾蓝、苔绿、玫瑰,每套为浅色与深色各定义一组配色、切换外观时自动跟随;选「默认」即恢复原生外观。配色只走主题变量层、不注入结构性样式,上游改版不会把界面弄坏。"
4
+ "description": "给 DSH 界面换主题的极简插件:设置页里只有一排主题卡片,点一下整套界面配色跟着换,不必逐个去调颜色。内置 8 套主题——青瓷、亚麻、奶油、石墨、靛蓝、雾蓝、苔绿、玫瑰,每套为浅色与深色各定义一组配色、切换外观时自动跟随;选「默认」即恢复原生外观。配色只走主题变量层、不注入结构性样式,上游改版不会把界面弄坏。同一页里还能把侧栏面板行收成一个「面板」入口(点开是两列启动面板,带搜索与键盘操作),并在侧栏底部加上刷新/重启按钮——三个功能各有独立开关。"
5
5
  }
6
6
  }
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@moonsand/dsh-ui-optimize",
3
- "version": "0.8.4",
3
+ "version": "0.9.26",
4
4
  "type": "module",
5
- "description": "Two features for the DSH web interface, each with its own switch: a minimalist theme gallery (eight themes, one palette for light and one for dark) and the desktop Reload/Restart actions at the sidebar foot. · DSH 界面优化:8 套极简主题(浅色与深色各一组配色)+ 侧栏底部的刷新/重启按钮,两个功能各有独立开关。",
5
+ "description": "Three features for the DSH web interface, each with its own switch: a minimalist theme gallery (eight themes, one palette for light and one for dark), the desktop Reload/Restart actions at the sidebar foot, and folding the sidebar panel rows into one Panels launcher. · DSH 界面优化:8 套极简主题(浅色与深色各一组配色)+ 侧栏底部的刷新/重启按钮 + 侧栏面板收成一个「面板」入口,三个功能各有独立开关。",
6
6
  "license": "MIT",
7
7
  "author": "MoonSand",
8
8
  "publishConfig": {