@moonsand/dsh-ui-optimize 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +61 -2
- package/README.zh.md +81 -0
- package/client.js +1906 -0
- package/cordis.patch.yml +3 -0
- package/desktop-restart.host.js +808 -0
- package/icon.svg +8 -0
- package/index.js +25 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +50 -3
package/client.js
ADDED
|
@@ -0,0 +1,1906 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser half of @moonsand/dsh-ui-optimize.
|
|
3
|
+
*
|
|
4
|
+
* Model: a small gallery of minimalist themes. Picking a theme stacks ONE
|
|
5
|
+
* `theme.overrideTokens()` layer carrying that theme's complete palette, so
|
|
6
|
+
* switching themes replaces the layer wholesale and picking "Default" removes
|
|
7
|
+
* exactly one layer to restore the untouched look.
|
|
8
|
+
*
|
|
9
|
+
* Every theme defines one palette for light and one for dark, and the token layer
|
|
10
|
+
* supplies both, so a theme follows the light/dark preference by itself.
|
|
11
|
+
*
|
|
12
|
+
* Nothing here reads another plugin's DOM, stylesheet, or component source:
|
|
13
|
+
* colours travel exclusively through the theme token layer.
|
|
14
|
+
*/
|
|
15
|
+
window.__ModuleLoader__.load({
|
|
16
|
+
id: '@moonsand/dsh-ui-optimize',
|
|
17
|
+
factory(require) {
|
|
18
|
+
'use strict'
|
|
19
|
+
|
|
20
|
+
const React = require('react')
|
|
21
|
+
const h = React.createElement
|
|
22
|
+
|
|
23
|
+
const NS = 'dsh-ui-optimize'
|
|
24
|
+
const STORAGE_KEY = 'dsh-ui-optimize:v2'
|
|
25
|
+
const LAYER_SOURCE = 'dsh-ui-optimize:theme'
|
|
26
|
+
/* Shared with the settings page so it can report why the theme is not applied. */
|
|
27
|
+
const surface = { controller: null }
|
|
28
|
+
const HEX_PATTERN = /^#[0-9a-fA-F]{6}$/
|
|
29
|
+
|
|
30
|
+
/* ------------------------------------------------------------------ *
|
|
31
|
+
* Text
|
|
32
|
+
* ------------------------------------------------------------------ */
|
|
33
|
+
|
|
34
|
+
const DICT = {
|
|
35
|
+
en: {
|
|
36
|
+
title: 'UI Optimize',
|
|
37
|
+
subtitle:
|
|
38
|
+
'Pick one theme and the whole interface follows. Each theme defines one palette for light and one for dark; switching Appearance between them carries the theme along — no separate version to pick.',
|
|
39
|
+
defaultName: 'Default',
|
|
40
|
+
defaultHint: 'Keep the current look',
|
|
41
|
+
'section.theme': 'Theme',
|
|
42
|
+
'theme.teal': 'Celadon',
|
|
43
|
+
'theme.teal.hint': 'Cool celadon — quiet and restrained',
|
|
44
|
+
'theme.brown': 'Linen',
|
|
45
|
+
'theme.brown.hint': 'Warm brown — like unbleached cloth',
|
|
46
|
+
'theme.yellow': 'Cream',
|
|
47
|
+
'theme.yellow.hint': 'Pale yellow — soft and easy on the eyes',
|
|
48
|
+
'theme.graphite': 'Graphite',
|
|
49
|
+
'theme.graphite.hint': 'Near-monochrome neutrals — quiet, Linear-like calm',
|
|
50
|
+
'theme.indigo': 'Indigo',
|
|
51
|
+
'theme.indigo.hint': 'Cool indigo accent on a near-white canvas',
|
|
52
|
+
'theme.slate': 'Slate',
|
|
53
|
+
'theme.slate.hint': 'Blue-grey neutrals — the modern dashboard default',
|
|
54
|
+
'theme.sage': 'Sage',
|
|
55
|
+
'theme.sage.hint': 'Muted green — a calmer neighbour of Celadon',
|
|
56
|
+
'theme.rose': 'Rose',
|
|
57
|
+
'theme.rose.hint': 'Dusty rose — warm without being loud',
|
|
58
|
+
applyFailed: 'The theme is not reaching the interface.',
|
|
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',
|
|
69
|
+
'desktop.label': 'Restart app',
|
|
70
|
+
'desktop.hint': 'Restart DeepSeek Harness (app and Host)',
|
|
71
|
+
'desktop.refresh': 'Reload UI',
|
|
72
|
+
'desktop.refreshHint': 'Reloads the interface and client plugins only; the Host keeps running',
|
|
73
|
+
'desktop.refreshBlocked': 'Restarting — hold on…',
|
|
74
|
+
'desktop.reloading': 'Reloading…',
|
|
75
|
+
'desktop.confirm': 'Restart now?',
|
|
76
|
+
'desktop.confirmBusy': 'Restart now? Tasks are running',
|
|
77
|
+
'desktop.restarting': 'Restarting…',
|
|
78
|
+
'desktop.failed': 'Restart failed',
|
|
79
|
+
'desktop.stillAlive': 'The app did not restart — restart it manually, or click again',
|
|
80
|
+
'desktop.notDesktop': 'Not the desktop app — reloading the page instead',
|
|
81
|
+
'desktop.unreachable': 'The Host did not answer — reloading the page instead',
|
|
82
|
+
'desktop.installing': 'Installing…',
|
|
83
|
+
'desktop.reloadSwitch': 'Show the Reload UI button',
|
|
84
|
+
'desktop.reloadSwitchHint': 'Sidebar foot. Reloads the page and client plugins; the Host and running tasks keep going',
|
|
85
|
+
'desktop.restartSwitch': 'Show the Restart app button',
|
|
86
|
+
'desktop.restartSwitchHint': 'Sidebar foot. Restarts the whole app including its Host; the current conversation is interrupted. Desktop app only',
|
|
87
|
+
'desktop.restartNotDesktop': 'This is a browser session, so restart is unavailable — clicking it would only reload the page. The feature works only inside the desktop app.',
|
|
88
|
+
'legacy.title': '@moonsand/dsh-desktop-restart is still installed',
|
|
89
|
+
'legacy.body': 'Both plugins draw reload/restart buttons, so the sidebar foot will show two sets. Uninstall dsh-desktop-restart under Settings → Plugins and keep only this one.',
|
|
90
|
+
storageNote: 'Storage unavailable — the choice lasts until this page reloads.',
|
|
91
|
+
},
|
|
92
|
+
zh: {
|
|
93
|
+
title: '界面优化',
|
|
94
|
+
subtitle:
|
|
95
|
+
'选一个主题,整个界面跟着换。每套主题为浅色与深色各定义一组配色,切换「外观」时自动跟随,不需要为两种模式各选一次。',
|
|
96
|
+
defaultName: '默认',
|
|
97
|
+
defaultHint: '保持当前外观',
|
|
98
|
+
'section.theme': '主题',
|
|
99
|
+
'theme.teal': '青瓷',
|
|
100
|
+
'theme.teal.hint': '冷调青绿,克制安静',
|
|
101
|
+
'theme.brown': '亚麻',
|
|
102
|
+
'theme.brown.hint': '暖调棕褐,像未漂白的布',
|
|
103
|
+
'theme.yellow': '奶油',
|
|
104
|
+
'theme.yellow.hint': '淡黄暖白,柔和护眼',
|
|
105
|
+
'theme.graphite': '石墨',
|
|
106
|
+
'theme.graphite.hint': '近单色中性,冷静克制',
|
|
107
|
+
'theme.indigo': '靛蓝',
|
|
108
|
+
'theme.indigo.hint': '近白画布配冷靛强调',
|
|
109
|
+
'theme.slate': '雾蓝',
|
|
110
|
+
'theme.slate.hint': '蓝灰中性,现代后台的默认脸',
|
|
111
|
+
'theme.sage': '苔绿',
|
|
112
|
+
'theme.sage.hint': '低饱和绿,比青瓷更松弛',
|
|
113
|
+
'theme.rose': '玫瑰',
|
|
114
|
+
'theme.rose.hint': '灰调玫瑰,暖而不吵',
|
|
115
|
+
applyFailed: '主题未作用到界面。',
|
|
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': '菜单行合并成一个入口,点开列出全部面板;新插件注册的面板会自动出现。同时把「新会话」按钮收窄',
|
|
126
|
+
'desktop.label': '重启应用',
|
|
127
|
+
'desktop.hint': '重启 DeepSeek Harness(应用与 Host)',
|
|
128
|
+
'desktop.refresh': '刷新界面',
|
|
129
|
+
'desktop.refreshHint': '只重新加载界面与客户端插件,Host 继续运行,任务不中断',
|
|
130
|
+
'desktop.refreshBlocked': '正在重启,稍等…',
|
|
131
|
+
'desktop.reloading': '刷新中…',
|
|
132
|
+
'desktop.confirm': '确认重启?',
|
|
133
|
+
'desktop.confirmBusy': '确认重启?有任务在跑',
|
|
134
|
+
'desktop.restarting': '重启中…',
|
|
135
|
+
'desktop.failed': '重启失败',
|
|
136
|
+
'desktop.stillAlive': '应用没有重启,请手动重启,或再点一次',
|
|
137
|
+
'desktop.notDesktop': '当前不是桌面端,改为刷新界面',
|
|
138
|
+
'desktop.unreachable': '联系不到 Host,改为刷新界面',
|
|
139
|
+
'desktop.installing': '安装插件中',
|
|
140
|
+
'desktop.reloadSwitch': '显示「刷新界面」按钮',
|
|
141
|
+
'desktop.reloadSwitchHint': '侧栏底部。重载页面与客户端插件,Host 与正在跑的任务都不受影响',
|
|
142
|
+
'desktop.restartSwitch': '显示「重启应用」按钮',
|
|
143
|
+
'desktop.restartSwitchHint': '侧栏底部。重启整个应用(含 Host),当前对话会中断;仅桌面端可用',
|
|
144
|
+
'desktop.restartNotDesktop': '当前是网页端,重启不可用——点了只会刷新页面。此功能仅在桌面应用里有效。',
|
|
145
|
+
'legacy.title': '检测到 @moonsand/dsh-desktop-restart 仍在安装',
|
|
146
|
+
'legacy.body': '两个插件都会提供刷新/重启按钮,侧栏底部会出现两套。请到「设置 → 插件」卸载 dsh-desktop-restart,只保留本插件。',
|
|
147
|
+
storageNote: '浏览器存储不可用——选择的主题只在本次页面加载内有效。',
|
|
148
|
+
},
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function detectLanguage() {
|
|
152
|
+
try {
|
|
153
|
+
const langs = typeof navigator !== 'undefined' && navigator.languages
|
|
154
|
+
const first =
|
|
155
|
+
(langs && langs.length > 0 ? langs[0] : '') ||
|
|
156
|
+
(typeof navigator !== 'undefined' ? navigator.language : '') ||
|
|
157
|
+
''
|
|
158
|
+
return String(first).toLowerCase().indexOf('zh') === 0 ? 'zh' : 'en'
|
|
159
|
+
} catch (err) {
|
|
160
|
+
return 'en'
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
let translate = function (key) {
|
|
165
|
+
const table = DICT[detectLanguage()] || DICT.en
|
|
166
|
+
return table[key] || DICT.en[key] || key
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/* ------------------------------------------------------------------ *
|
|
170
|
+
* Themes
|
|
171
|
+
*
|
|
172
|
+
* One theme is one decision. Every alias token the interface colours itself
|
|
173
|
+
* with lives here per scheme, so the user picks a mood instead of tuning
|
|
174
|
+
* twenty colour values.
|
|
175
|
+
* ------------------------------------------------------------------ */
|
|
176
|
+
|
|
177
|
+
const THEMES = [
|
|
178
|
+
{
|
|
179
|
+
key: 'teal',
|
|
180
|
+
light: {
|
|
181
|
+
'--dsw-alias-bg-base': '#E6F0F0',
|
|
182
|
+
'--dsw-alias-bg-layer-1': '#F8FCFC',
|
|
183
|
+
'--dsw-alias-bg-layer-2': '#DCE8E8',
|
|
184
|
+
'--dsw-alias-bg-overlay': '#F8FCFC',
|
|
185
|
+
'--dsw-specific-sidebar-fill': '#E2EEEE',
|
|
186
|
+
'--dsw-alias-border-l1': '#C9DBDB',
|
|
187
|
+
'--dsw-alias-border-l2': '#AFC7C7',
|
|
188
|
+
'--dsw-alias-brand-primary': '#0B7F7F',
|
|
189
|
+
'--dsw-alias-label-primary': '#12333A',
|
|
190
|
+
'--dsw-alias-label-secondary': '#4E6A6E',
|
|
191
|
+
},
|
|
192
|
+
dark: {
|
|
193
|
+
'--dsw-alias-bg-base': '#0F1719',
|
|
194
|
+
'--dsw-alias-bg-layer-1': '#162124',
|
|
195
|
+
'--dsw-alias-bg-layer-2': '#1D2A2E',
|
|
196
|
+
'--dsw-alias-bg-overlay': '#1F2D31',
|
|
197
|
+
'--dsw-specific-sidebar-fill': '#121B1D',
|
|
198
|
+
'--dsw-alias-border-l1': '#24363B',
|
|
199
|
+
'--dsw-alias-border-l2': '#30474D',
|
|
200
|
+
'--dsw-alias-brand-primary': '#3FBFBF',
|
|
201
|
+
'--dsw-alias-label-primary': '#E3EDEE',
|
|
202
|
+
'--dsw-alias-label-secondary': '#93A9AC',
|
|
203
|
+
},
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
key: 'brown',
|
|
207
|
+
light: {
|
|
208
|
+
'--dsw-alias-bg-base': '#FAF7F3',
|
|
209
|
+
'--dsw-alias-bg-layer-1': '#FFFFFF',
|
|
210
|
+
'--dsw-alias-bg-layer-2': '#F3EDE6',
|
|
211
|
+
'--dsw-alias-bg-overlay': '#FFFFFF',
|
|
212
|
+
'--dsw-specific-sidebar-fill': '#F5EFE8',
|
|
213
|
+
'--dsw-alias-border-l1': '#E7DDD1',
|
|
214
|
+
'--dsw-alias-border-l2': '#D5C6B4',
|
|
215
|
+
'--dsw-alias-brand-primary': '#8A5F3C',
|
|
216
|
+
'--dsw-alias-label-primary': '#2E241C',
|
|
217
|
+
'--dsw-alias-label-secondary': '#6E5B4A',
|
|
218
|
+
},
|
|
219
|
+
dark: {
|
|
220
|
+
'--dsw-alias-bg-base': '#17120F',
|
|
221
|
+
'--dsw-alias-bg-layer-1': '#201A16',
|
|
222
|
+
'--dsw-alias-bg-layer-2': '#2A221C',
|
|
223
|
+
'--dsw-alias-bg-overlay': '#2E251F',
|
|
224
|
+
'--dsw-specific-sidebar-fill': '#1B1512',
|
|
225
|
+
'--dsw-alias-border-l1': '#382C24',
|
|
226
|
+
'--dsw-alias-border-l2': '#4A3A2F',
|
|
227
|
+
'--dsw-alias-brand-primary': '#C79A6B',
|
|
228
|
+
'--dsw-alias-label-primary': '#EFE6DD',
|
|
229
|
+
'--dsw-alias-label-secondary': '#AD9B8B',
|
|
230
|
+
},
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
key: 'yellow',
|
|
234
|
+
light: {
|
|
235
|
+
'--dsw-alias-bg-base': '#FDFBF3',
|
|
236
|
+
'--dsw-alias-bg-layer-1': '#FFFFFF',
|
|
237
|
+
'--dsw-alias-bg-layer-2': '#F7F1E0',
|
|
238
|
+
'--dsw-alias-bg-overlay': '#FFFFFF',
|
|
239
|
+
'--dsw-specific-sidebar-fill': '#F9F5E8',
|
|
240
|
+
'--dsw-alias-border-l1': '#EDE5CF',
|
|
241
|
+
'--dsw-alias-border-l2': '#DED2B4',
|
|
242
|
+
'--dsw-alias-brand-primary': '#9C7C16',
|
|
243
|
+
'--dsw-alias-label-primary': '#2F2A1C',
|
|
244
|
+
'--dsw-alias-label-secondary': '#6B6248',
|
|
245
|
+
},
|
|
246
|
+
dark: {
|
|
247
|
+
'--dsw-alias-bg-base': '#16140F',
|
|
248
|
+
'--dsw-alias-bg-layer-1': '#1F1C15',
|
|
249
|
+
'--dsw-alias-bg-layer-2': '#282419',
|
|
250
|
+
'--dsw-alias-bg-overlay': '#2C2718',
|
|
251
|
+
'--dsw-specific-sidebar-fill': '#1A1711',
|
|
252
|
+
'--dsw-alias-border-l1': '#352F22',
|
|
253
|
+
'--dsw-alias-border-l2': '#47402D',
|
|
254
|
+
'--dsw-alias-brand-primary': '#D9BC63',
|
|
255
|
+
'--dsw-alias-label-primary': '#F0EADA',
|
|
256
|
+
'--dsw-alias-label-secondary': '#ADA48C',
|
|
257
|
+
},
|
|
258
|
+
},
|
|
259
|
+
{
|
|
260
|
+
key: 'graphite',
|
|
261
|
+
light: {
|
|
262
|
+
'--dsw-alias-bg-base': '#EDEDEF',
|
|
263
|
+
'--dsw-alias-bg-layer-1': '#F7F7F8',
|
|
264
|
+
'--dsw-alias-bg-layer-2': '#E2E2E5',
|
|
265
|
+
'--dsw-alias-bg-overlay': '#F7F7F8',
|
|
266
|
+
'--dsw-specific-sidebar-fill': '#E9E9EC',
|
|
267
|
+
'--dsw-alias-border-l1': '#D2D2D6',
|
|
268
|
+
'--dsw-alias-border-l2': '#BABAC0',
|
|
269
|
+
'--dsw-alias-brand-primary': '#2E3238',
|
|
270
|
+
'--dsw-alias-label-primary': '#141417',
|
|
271
|
+
'--dsw-alias-label-secondary': '#5A5A62',
|
|
272
|
+
},
|
|
273
|
+
dark: {
|
|
274
|
+
'--dsw-alias-bg-base': '#131316',
|
|
275
|
+
'--dsw-alias-bg-layer-1': '#1A1A1E',
|
|
276
|
+
'--dsw-alias-bg-layer-2': '#222227',
|
|
277
|
+
'--dsw-alias-bg-overlay': '#242429',
|
|
278
|
+
'--dsw-specific-sidebar-fill': '#17171A',
|
|
279
|
+
'--dsw-alias-border-l1': '#2C2C32',
|
|
280
|
+
'--dsw-alias-border-l2': '#3D3D45',
|
|
281
|
+
'--dsw-alias-brand-primary': '#B4B8C1',
|
|
282
|
+
'--dsw-alias-label-primary': '#EDEDF0',
|
|
283
|
+
'--dsw-alias-label-secondary': '#9B9BA4',
|
|
284
|
+
},
|
|
285
|
+
},
|
|
286
|
+
{
|
|
287
|
+
key: 'indigo',
|
|
288
|
+
light: {
|
|
289
|
+
'--dsw-alias-bg-base': '#E9EDF8',
|
|
290
|
+
'--dsw-alias-bg-layer-1': '#F8FAFD',
|
|
291
|
+
'--dsw-alias-bg-layer-2': '#DEE5F4',
|
|
292
|
+
'--dsw-alias-bg-overlay': '#F8FAFD',
|
|
293
|
+
'--dsw-specific-sidebar-fill': '#E4EAF7',
|
|
294
|
+
'--dsw-alias-border-l1': '#CBD5EC',
|
|
295
|
+
'--dsw-alias-border-l2': '#B0BFE0',
|
|
296
|
+
'--dsw-alias-brand-primary': '#4338CA',
|
|
297
|
+
'--dsw-alias-label-primary': '#161A24',
|
|
298
|
+
'--dsw-alias-label-secondary': '#4A5266',
|
|
299
|
+
},
|
|
300
|
+
dark: {
|
|
301
|
+
'--dsw-alias-bg-base': '#0E1017',
|
|
302
|
+
'--dsw-alias-bg-layer-1': '#151824',
|
|
303
|
+
'--dsw-alias-bg-layer-2': '#1C2030',
|
|
304
|
+
'--dsw-alias-bg-overlay': '#1F2436',
|
|
305
|
+
'--dsw-specific-sidebar-fill': '#11141C',
|
|
306
|
+
'--dsw-alias-border-l1': '#242A3C',
|
|
307
|
+
'--dsw-alias-border-l2': '#333A52',
|
|
308
|
+
'--dsw-alias-brand-primary': '#8A8CF7',
|
|
309
|
+
'--dsw-alias-label-primary': '#E7E9F5',
|
|
310
|
+
'--dsw-alias-label-secondary': '#9BA3B8',
|
|
311
|
+
},
|
|
312
|
+
},
|
|
313
|
+
{
|
|
314
|
+
key: 'slate',
|
|
315
|
+
light: {
|
|
316
|
+
'--dsw-alias-bg-base': '#E8EFF7',
|
|
317
|
+
'--dsw-alias-bg-layer-1': '#F8FAFD',
|
|
318
|
+
'--dsw-alias-bg-layer-2': '#DDE7F3',
|
|
319
|
+
'--dsw-alias-bg-overlay': '#F8FAFD',
|
|
320
|
+
'--dsw-specific-sidebar-fill': '#E3ECF6',
|
|
321
|
+
'--dsw-alias-border-l1': '#C9D8E9',
|
|
322
|
+
'--dsw-alias-border-l2': '#AEC4DC',
|
|
323
|
+
'--dsw-alias-brand-primary': '#1D4ED8',
|
|
324
|
+
'--dsw-alias-label-primary': '#16202E',
|
|
325
|
+
'--dsw-alias-label-secondary': '#4D5F73',
|
|
326
|
+
},
|
|
327
|
+
dark: {
|
|
328
|
+
'--dsw-alias-bg-base': '#0E1626',
|
|
329
|
+
'--dsw-alias-bg-layer-1': '#16202F',
|
|
330
|
+
'--dsw-alias-bg-layer-2': '#1D2838',
|
|
331
|
+
'--dsw-alias-bg-overlay': '#212D3F',
|
|
332
|
+
'--dsw-specific-sidebar-fill': '#101A29',
|
|
333
|
+
'--dsw-alias-border-l1': '#273549',
|
|
334
|
+
'--dsw-alias-border-l2': '#364A63',
|
|
335
|
+
'--dsw-alias-brand-primary': '#5B9DF9',
|
|
336
|
+
'--dsw-alias-label-primary': '#E2E8F0',
|
|
337
|
+
'--dsw-alias-label-secondary': '#94A3B8',
|
|
338
|
+
},
|
|
339
|
+
},
|
|
340
|
+
{
|
|
341
|
+
key: 'sage',
|
|
342
|
+
light: {
|
|
343
|
+
'--dsw-alias-bg-base': '#EAF0E3',
|
|
344
|
+
'--dsw-alias-bg-layer-1': '#F8FBF4',
|
|
345
|
+
'--dsw-alias-bg-layer-2': '#DFE8D6',
|
|
346
|
+
'--dsw-alias-bg-overlay': '#F8FBF4',
|
|
347
|
+
'--dsw-specific-sidebar-fill': '#E5EDDD',
|
|
348
|
+
'--dsw-alias-border-l1': '#CBD8BE',
|
|
349
|
+
'--dsw-alias-border-l2': '#B2C3A3',
|
|
350
|
+
'--dsw-alias-brand-primary': '#3F6B43',
|
|
351
|
+
'--dsw-alias-label-primary': '#1B2318',
|
|
352
|
+
'--dsw-alias-label-secondary': '#4F5C48',
|
|
353
|
+
},
|
|
354
|
+
dark: {
|
|
355
|
+
'--dsw-alias-bg-base': '#12160F',
|
|
356
|
+
'--dsw-alias-bg-layer-1': '#1A2016',
|
|
357
|
+
'--dsw-alias-bg-layer-2': '#222A1C',
|
|
358
|
+
'--dsw-alias-bg-overlay': '#262F20',
|
|
359
|
+
'--dsw-specific-sidebar-fill': '#151A11',
|
|
360
|
+
'--dsw-alias-border-l1': '#2C3626',
|
|
361
|
+
'--dsw-alias-border-l2': '#3C4A33',
|
|
362
|
+
'--dsw-alias-brand-primary': '#8FB57E',
|
|
363
|
+
'--dsw-alias-label-primary': '#E6EBDF',
|
|
364
|
+
'--dsw-alias-label-secondary': '#A3AE99',
|
|
365
|
+
},
|
|
366
|
+
},
|
|
367
|
+
{
|
|
368
|
+
key: 'rose',
|
|
369
|
+
light: {
|
|
370
|
+
'--dsw-alias-bg-base': '#F7E9EC',
|
|
371
|
+
'--dsw-alias-bg-layer-1': '#FDF8F9',
|
|
372
|
+
'--dsw-alias-bg-layer-2': '#F1DFE3',
|
|
373
|
+
'--dsw-alias-bg-overlay': '#FDF8F9',
|
|
374
|
+
'--dsw-specific-sidebar-fill': '#F4E3E7',
|
|
375
|
+
'--dsw-alias-border-l1': '#E2C8CE',
|
|
376
|
+
'--dsw-alias-border-l2': '#CFAEB6',
|
|
377
|
+
'--dsw-alias-brand-primary': '#A02E56',
|
|
378
|
+
'--dsw-alias-label-primary': '#2A1D21',
|
|
379
|
+
'--dsw-alias-label-secondary': '#624E55',
|
|
380
|
+
},
|
|
381
|
+
dark: {
|
|
382
|
+
'--dsw-alias-bg-base': '#171014',
|
|
383
|
+
'--dsw-alias-bg-layer-1': '#20161B',
|
|
384
|
+
'--dsw-alias-bg-layer-2': '#2A1D23',
|
|
385
|
+
'--dsw-alias-bg-overlay': '#2E2028',
|
|
386
|
+
'--dsw-specific-sidebar-fill': '#1A1216',
|
|
387
|
+
'--dsw-alias-border-l1': '#382730',
|
|
388
|
+
'--dsw-alias-border-l2': '#4A3440',
|
|
389
|
+
'--dsw-alias-brand-primary': '#E58AA8',
|
|
390
|
+
'--dsw-alias-label-primary': '#F1E6EA',
|
|
391
|
+
'--dsw-alias-label-secondary': '#B09AA3',
|
|
392
|
+
},
|
|
393
|
+
},
|
|
394
|
+
]
|
|
395
|
+
|
|
396
|
+
const THEME_BY_KEY = {}
|
|
397
|
+
for (let i = 0; i < THEMES.length; i += 1) THEME_BY_KEY[THEMES[i].key] = THEMES[i]
|
|
398
|
+
|
|
399
|
+
/* ------------------------------------------------------------------ *
|
|
400
|
+
* State
|
|
401
|
+
* ------------------------------------------------------------------ */
|
|
402
|
+
|
|
403
|
+
function defaultState() {
|
|
404
|
+
return { version: 4, theme: null, reload: true, restart: true, sidebar: false }
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
function normalize(stored) {
|
|
408
|
+
const out = defaultState()
|
|
409
|
+
if (!stored || typeof stored !== 'object') return out
|
|
410
|
+
if (typeof stored.theme === 'string' && THEME_BY_KEY[stored.theme]) {
|
|
411
|
+
out.theme = stored.theme
|
|
412
|
+
}
|
|
413
|
+
if (typeof stored.reload === 'boolean') out.reload = stored.reload
|
|
414
|
+
if (typeof stored.restart === 'boolean') out.restart = stored.restart
|
|
415
|
+
if (typeof stored.sidebar === 'boolean') out.sidebar = stored.sidebar
|
|
416
|
+
return out
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
function readStored() {
|
|
420
|
+
try {
|
|
421
|
+
const raw = window.localStorage.getItem(STORAGE_KEY)
|
|
422
|
+
if (!raw) return null
|
|
423
|
+
return JSON.parse(raw)
|
|
424
|
+
} catch (err) {
|
|
425
|
+
return null
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
let storageBroken = false
|
|
430
|
+
|
|
431
|
+
function writeStored(state) {
|
|
432
|
+
try {
|
|
433
|
+
window.localStorage.setItem(STORAGE_KEY, JSON.stringify(state))
|
|
434
|
+
storageBroken = false
|
|
435
|
+
} catch (err) {
|
|
436
|
+
storageBroken = true
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
function publish(next) {
|
|
441
|
+
store.state = next
|
|
442
|
+
writeStored(next)
|
|
443
|
+
const snapshot = Array.from(store.listeners)
|
|
444
|
+
for (let i = 0; i < snapshot.length; i += 1) {
|
|
445
|
+
try {
|
|
446
|
+
snapshot[i]()
|
|
447
|
+
} catch (err) {
|
|
448
|
+
/* a broken subscriber must not block the others */
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
const store = {
|
|
454
|
+
state: normalize(readStored()),
|
|
455
|
+
listeners: new Set(),
|
|
456
|
+
subscribe(listener) {
|
|
457
|
+
store.listeners.add(listener)
|
|
458
|
+
return function () {
|
|
459
|
+
store.listeners.delete(listener)
|
|
460
|
+
}
|
|
461
|
+
},
|
|
462
|
+
setTheme(key) {
|
|
463
|
+
publish(
|
|
464
|
+
Object.assign({}, store.state, {
|
|
465
|
+
version: 3,
|
|
466
|
+
theme: THEME_BY_KEY[key] ? key : null,
|
|
467
|
+
}),
|
|
468
|
+
)
|
|
469
|
+
},
|
|
470
|
+
setFlag(name, value) {
|
|
471
|
+
const next = Object.assign({}, store.state, { version: 3 })
|
|
472
|
+
next[name] = value === true
|
|
473
|
+
publish(next)
|
|
474
|
+
},
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
/* ------------------------------------------------------------------ *
|
|
478
|
+
* Layer
|
|
479
|
+
* ------------------------------------------------------------------ */
|
|
480
|
+
|
|
481
|
+
function themeLayer(state) {
|
|
482
|
+
const theme = state.theme ? THEME_BY_KEY[state.theme] : null
|
|
483
|
+
if (!theme) return null
|
|
484
|
+
const tokens = {}
|
|
485
|
+
let count = 0
|
|
486
|
+
const names = Object.keys(theme.light)
|
|
487
|
+
for (let i = 0; i < names.length; i += 1) {
|
|
488
|
+
const name = names[i]
|
|
489
|
+
const light = theme.light[name]
|
|
490
|
+
const dark = theme.dark[name]
|
|
491
|
+
if (!HEX_PATTERN.test(light) || !HEX_PATTERN.test(dark)) continue
|
|
492
|
+
tokens[name] = { light: light, dark: dark }
|
|
493
|
+
count += 1
|
|
494
|
+
}
|
|
495
|
+
return count > 0 ? tokens : null
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
function createController(resolveTheme) {
|
|
499
|
+
let disposeLayer = null
|
|
500
|
+
let lastError = null
|
|
501
|
+
|
|
502
|
+
function release() {
|
|
503
|
+
const dispose = disposeLayer
|
|
504
|
+
disposeLayer = null
|
|
505
|
+
if (typeof dispose !== 'function') return
|
|
506
|
+
try {
|
|
507
|
+
dispose()
|
|
508
|
+
} catch (err) {
|
|
509
|
+
/* the layer may already be covered by a newer override */
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
return {
|
|
514
|
+
active() {
|
|
515
|
+
return disposeLayer !== null
|
|
516
|
+
},
|
|
517
|
+
error() {
|
|
518
|
+
return lastError
|
|
519
|
+
},
|
|
520
|
+
/** Returns true once the wanted state is settled, false while retrying. */
|
|
521
|
+
sync(state) {
|
|
522
|
+
const theme = typeof resolveTheme === 'function' ? resolveTheme() : resolveTheme
|
|
523
|
+
if (!theme || typeof theme.overrideTokens !== 'function') {
|
|
524
|
+
// The theme service is not reachable yet; the caller retries.
|
|
525
|
+
return false
|
|
526
|
+
}
|
|
527
|
+
const tokens = themeLayer(state)
|
|
528
|
+
if (!tokens) {
|
|
529
|
+
release()
|
|
530
|
+
lastError = null
|
|
531
|
+
return true
|
|
532
|
+
}
|
|
533
|
+
const previous = disposeLayer
|
|
534
|
+
let dispose
|
|
535
|
+
try {
|
|
536
|
+
dispose = theme.overrideTokens(LAYER_SOURCE, tokens)
|
|
537
|
+
} catch (err) {
|
|
538
|
+
lastError = err && err.message ? String(err.message) : String(err)
|
|
539
|
+
return false
|
|
540
|
+
}
|
|
541
|
+
if (typeof dispose !== 'function') {
|
|
542
|
+
lastError = 'overrideTokens returned no disposer'
|
|
543
|
+
return false
|
|
544
|
+
}
|
|
545
|
+
disposeLayer = dispose
|
|
546
|
+
lastError = null
|
|
547
|
+
// Re-overriding the same source already replaced the older layer.
|
|
548
|
+
if (previous && previous !== dispose) {
|
|
549
|
+
try {
|
|
550
|
+
previous()
|
|
551
|
+
} catch (err) {
|
|
552
|
+
/* already replaced */
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
return true
|
|
556
|
+
},
|
|
557
|
+
dispose() {
|
|
558
|
+
release()
|
|
559
|
+
},
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
/* ------------------------------------------------------------------ *
|
|
564
|
+
* Styles
|
|
565
|
+
* ------------------------------------------------------------------ */
|
|
566
|
+
|
|
567
|
+
const STYLES = `
|
|
568
|
+
.dsuik-page{display:flex;flex-direction:column;gap:16px;padding:2px 0 28px;font-size:14px;color:var(--dsw-alias-label-primary);}
|
|
569
|
+
.dsuik-header{display:flex;flex-direction:column;gap:6px;}
|
|
570
|
+
.dsuik-title{font-size:16px;font-weight:600;line-height:1.4;}
|
|
571
|
+
.dsuik-sub{margin:0;font-size:13px;line-height:1.65;color:var(--dsw-alias-label-secondary);}
|
|
572
|
+
.dsuik-section{display:flex;flex-direction:column;gap:10px;}
|
|
573
|
+
.dsuik-sectiontitle{margin:0;font-size:12.5px;font-weight:600;letter-spacing:.03em;color:var(--dsw-alias-label-secondary);}
|
|
574
|
+
.dsuik-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(152px,1fr));gap:10px;}
|
|
575
|
+
.dsuik-tile{display:flex;flex-direction:column;padding:0;overflow:hidden;text-align:left;font:inherit;color:inherit;background:var(--dsw-alias-bg-layer-1);border:1px solid var(--dsw-alias-border-l1);border-radius:10px;cursor:pointer;transition:border-color .16s ease;}
|
|
576
|
+
.dsuik-tile:hover{border-color:var(--dsw-alias-border-l2);}
|
|
577
|
+
.dsuik-tile:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:2px;}
|
|
578
|
+
.dsuik-tile.is-active{border-color:var(--dsw-alias-brand-primary);}
|
|
579
|
+
.dsuik-mc{display:flex;}
|
|
580
|
+
.dsuik-mc > i{display:block;flex:1 1 auto;min-width:0;}
|
|
581
|
+
body[data-ds-dark-theme] .dsuik-mc > .dsuik-mc-a{display:none;}
|
|
582
|
+
body:not([data-ds-dark-theme]) .dsuik-mc > .dsuik-mc-b{display:none;}
|
|
583
|
+
.dsuik-bar{height:14px;flex:none;}
|
|
584
|
+
.dsuik-dot{flex:none;width:8px;height:8px;border-radius:2px;}
|
|
585
|
+
.dsuik-tilebody{display:flex;flex-direction:column;gap:2px;padding:7px 10px 9px;}
|
|
586
|
+
.dsuik-tilename{display:flex;align-items:center;gap:6px;font-size:12.5px;font-weight:600;line-height:1.4;}
|
|
587
|
+
.dsuik-tilehint{font-size:11px;line-height:1.45;color:var(--dsw-alias-label-secondary);}
|
|
588
|
+
.dsuik-check{flex:none;width:6px;height:6px;border-radius:50%;background:var(--dsw-alias-brand-primary);}
|
|
589
|
+
.dsuik-warn{margin:0;font-size:12px;line-height:1.5;color:var(--dsw-alias-state-error-primary);}
|
|
590
|
+
.dsuik-row{display:flex;align-items:center;justify-content:space-between;gap:16px;padding:12px 14px;border:1px solid var(--dsw-alias-border-l1);border-radius:12px;background:var(--dsw-alias-bg-layer-1);}
|
|
591
|
+
.dsuik-rowtext{display:flex;flex-direction:column;gap:2px;min-width:0;}
|
|
592
|
+
.dsuik-rowname{font-size:13px;font-weight:600;line-height:1.4;}
|
|
593
|
+
.dsuik-rowhint{font-size:11.5px;line-height:1.5;color:var(--dsw-alias-label-secondary);}
|
|
594
|
+
.dsuik-switch{position:relative;flex:none;width:38px;height:22px;padding:0;border:none;border-radius:999px;background:var(--dsw-alias-state-idle-primary);cursor:pointer;transition:background .16s ease;}
|
|
595
|
+
.dsuik-switch.is-on{background:var(--dsw-alias-brand-primary);}
|
|
596
|
+
.dsuik-switch:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:2px;}
|
|
597
|
+
.dsuik-knob{position:absolute;top:3px;left:3px;width:16px;height:16px;border-radius:50%;background:var(--dsw-alias-bg-base);transition:transform .16s ease;}
|
|
598
|
+
.dsuik-switch.is-on .dsuik-knob{transform:translateX(16px);}
|
|
599
|
+
.dsuik-switch.is-disabled{opacity:.45;cursor:not-allowed;}
|
|
600
|
+
.dsuik-rowhint.is-warn{color:var(--dsw-alias-state-warn-primary);}
|
|
601
|
+
.dsuik-alert{display:flex;flex-direction:column;gap:3px;padding:10px 12px;border:1px solid var(--dsw-alias-state-warn-primary);border-radius:10px;}
|
|
602
|
+
.dsuik-alert-title{font-size:12.5px;font-weight:600;line-height:1.4;color:var(--dsw-alias-state-warn-primary);}
|
|
603
|
+
.dsuik-alert-body{font-size:12px;line-height:1.5;color:var(--dsw-alias-label-secondary);}
|
|
604
|
+
`
|
|
605
|
+
|
|
606
|
+
/* ------------------------------------------------------------------ *
|
|
607
|
+
* View
|
|
608
|
+
* ------------------------------------------------------------------ */
|
|
609
|
+
|
|
610
|
+
/* One colour strip, but correct in both modes: both values are rendered and
|
|
611
|
+
* CSS shows the one matching the active scheme, so no JS has to guess. */
|
|
612
|
+
function ModeColor(props) {
|
|
613
|
+
return h(
|
|
614
|
+
'span',
|
|
615
|
+
{ className: 'dsuik-mc ' + (props.className || '') },
|
|
616
|
+
h('i', { className: 'dsuik-mc-a', style: { background: props.light } }),
|
|
617
|
+
h('i', { className: 'dsuik-mc-b', style: { background: props.dark } }),
|
|
618
|
+
)
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
function Switch(props) {
|
|
622
|
+
const disabled = props.disabled === true
|
|
623
|
+
return h(
|
|
624
|
+
'button',
|
|
625
|
+
{
|
|
626
|
+
type: 'button',
|
|
627
|
+
role: 'switch',
|
|
628
|
+
'aria-checked': props.checked ? 'true' : 'false',
|
|
629
|
+
'aria-label': props.label,
|
|
630
|
+
disabled: disabled,
|
|
631
|
+
className:
|
|
632
|
+
'dsuik-switch' + (props.checked ? ' is-on' : '') + (disabled ? ' is-disabled' : ''),
|
|
633
|
+
onClick: function () {
|
|
634
|
+
if (disabled) return
|
|
635
|
+
props.onChange(!props.checked)
|
|
636
|
+
},
|
|
637
|
+
},
|
|
638
|
+
h('span', { className: 'dsuik-knob', 'aria-hidden': 'true' }),
|
|
639
|
+
)
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
function ThemeTile(props) {
|
|
643
|
+
return h(
|
|
644
|
+
'button',
|
|
645
|
+
{
|
|
646
|
+
type: 'button',
|
|
647
|
+
className: 'dsuik-tile' + (props.active ? ' is-active' : ''),
|
|
648
|
+
'aria-pressed': props.active ? 'true' : 'false',
|
|
649
|
+
onClick: props.onPick,
|
|
650
|
+
},
|
|
651
|
+
h(ModeColor, { className: 'dsuik-bar', light: props.barLight, dark: props.barDark }),
|
|
652
|
+
h(
|
|
653
|
+
'div',
|
|
654
|
+
{ className: 'dsuik-tilebody' },
|
|
655
|
+
h(
|
|
656
|
+
'span',
|
|
657
|
+
{ className: 'dsuik-tilename' },
|
|
658
|
+
h(ModeColor, { className: 'dsuik-dot', light: props.dotLight, dark: props.dotDark }),
|
|
659
|
+
props.name,
|
|
660
|
+
props.active ? h('span', { className: 'dsuik-check', 'aria-hidden': 'true' }) : null,
|
|
661
|
+
),
|
|
662
|
+
h('span', { className: 'dsuik-tilehint' }, props.hint),
|
|
663
|
+
),
|
|
664
|
+
)
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
function SettingsPage() {
|
|
668
|
+
const [state, setState] = React.useState(store.state)
|
|
669
|
+
const [restartUnavailable, setRestartUnavailable] = React.useState(false)
|
|
670
|
+
const [legacyPresent, setLegacyPresent] = React.useState(false)
|
|
671
|
+
|
|
672
|
+
React.useEffect(function () {
|
|
673
|
+
return store.subscribe(function () {
|
|
674
|
+
setState(store.state)
|
|
675
|
+
})
|
|
676
|
+
}, [])
|
|
677
|
+
|
|
678
|
+
/* Ask the Host once whether this page is the desktop shell. A browser session
|
|
679
|
+
* cannot restart anything, so the switch should say so up front instead of
|
|
680
|
+
* leaving the user to discover it on the first click. */
|
|
681
|
+
React.useEffect(function () {
|
|
682
|
+
let alive = true
|
|
683
|
+
void readStatus().then(function (status) {
|
|
684
|
+
if (!alive) return
|
|
685
|
+
if (status && typeof status.desktop === 'boolean') {
|
|
686
|
+
setRestartUnavailable(status.desktop !== true)
|
|
687
|
+
}
|
|
688
|
+
})
|
|
689
|
+
return function () {
|
|
690
|
+
alive = false
|
|
691
|
+
}
|
|
692
|
+
}, [])
|
|
693
|
+
|
|
694
|
+
/* The standalone plugin owns the original route prefix. If it is still
|
|
695
|
+
* loaded, both plugins draw footer buttons — say so instead of leaving the
|
|
696
|
+
* user to wonder why there are two sets. */
|
|
697
|
+
React.useEffect(function () {
|
|
698
|
+
let alive = true
|
|
699
|
+
void detectStandalone().then(function (present) {
|
|
700
|
+
if (alive) setLegacyPresent(present)
|
|
701
|
+
})
|
|
702
|
+
return function () {
|
|
703
|
+
alive = false
|
|
704
|
+
}
|
|
705
|
+
}, [])
|
|
706
|
+
|
|
707
|
+
const tiles = [
|
|
708
|
+
h(ThemeTile, {
|
|
709
|
+
key: 'default',
|
|
710
|
+
active: state.theme === null,
|
|
711
|
+
name: translate('defaultName'),
|
|
712
|
+
hint: translate('defaultHint'),
|
|
713
|
+
barLight: 'var(--dsw-alias-bg-base)',
|
|
714
|
+
barDark: 'var(--dsw-alias-bg-base)',
|
|
715
|
+
dotLight: 'var(--dsw-alias-brand-primary)',
|
|
716
|
+
dotDark: 'var(--dsw-alias-brand-primary)',
|
|
717
|
+
onPick: function () {
|
|
718
|
+
store.setTheme(null)
|
|
719
|
+
},
|
|
720
|
+
}),
|
|
721
|
+
]
|
|
722
|
+
|
|
723
|
+
for (let i = 0; i < THEMES.length; i += 1) {
|
|
724
|
+
const theme = THEMES[i]
|
|
725
|
+
tiles.push(
|
|
726
|
+
h(ThemeTile, {
|
|
727
|
+
key: theme.key,
|
|
728
|
+
active: state.theme === theme.key,
|
|
729
|
+
name: translate('theme.' + theme.key),
|
|
730
|
+
hint: translate('theme.' + theme.key + '.hint'),
|
|
731
|
+
barLight: theme.light['--dsw-alias-bg-base'],
|
|
732
|
+
barDark: theme.dark['--dsw-alias-bg-base'],
|
|
733
|
+
dotLight: theme.light['--dsw-alias-brand-primary'],
|
|
734
|
+
dotDark: theme.dark['--dsw-alias-brand-primary'],
|
|
735
|
+
onPick: function () {
|
|
736
|
+
store.setTheme(theme.key)
|
|
737
|
+
},
|
|
738
|
+
}),
|
|
739
|
+
)
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
return h(
|
|
743
|
+
'div',
|
|
744
|
+
{ className: 'dsuik-page' },
|
|
745
|
+
h('style', null, STYLES),
|
|
746
|
+
h(
|
|
747
|
+
'div',
|
|
748
|
+
{ className: 'dsuik-header' },
|
|
749
|
+
h('div', { className: 'dsuik-title' }, translate('title')),
|
|
750
|
+
h('p', { className: 'dsuik-sub' }, translate('subtitle')),
|
|
751
|
+
),
|
|
752
|
+
legacyPresent
|
|
753
|
+
? h(
|
|
754
|
+
'div',
|
|
755
|
+
{ className: 'dsuik-alert' },
|
|
756
|
+
h('span', { className: 'dsuik-alert-title' }, translate('legacy.title')),
|
|
757
|
+
h('span', { className: 'dsuik-alert-body' }, translate('legacy.body')),
|
|
758
|
+
)
|
|
759
|
+
: null,
|
|
760
|
+
h(
|
|
761
|
+
'div',
|
|
762
|
+
{ className: 'dsuik-section' },
|
|
763
|
+
h('p', { className: 'dsuik-sectiontitle' }, translate('section.theme')),
|
|
764
|
+
h('div', { className: 'dsuik-grid' }, tiles),
|
|
765
|
+
),
|
|
766
|
+
h(
|
|
767
|
+
'div',
|
|
768
|
+
{ className: 'dsuik-section' },
|
|
769
|
+
h('p', { className: 'dsuik-sectiontitle' }, translate('section.desktop')),
|
|
770
|
+
h(
|
|
771
|
+
'div',
|
|
772
|
+
{ className: 'dsuik-row' },
|
|
773
|
+
h(
|
|
774
|
+
'div',
|
|
775
|
+
{ className: 'dsuik-rowtext' },
|
|
776
|
+
h('span', { className: 'dsuik-rowname' }, translate('desktop.reloadSwitch')),
|
|
777
|
+
h('span', { className: 'dsuik-rowhint' }, translate('desktop.reloadSwitchHint')),
|
|
778
|
+
),
|
|
779
|
+
h(Switch, {
|
|
780
|
+
checked: state.reload === true,
|
|
781
|
+
label: translate('desktop.reloadSwitch'),
|
|
782
|
+
onChange: function (next) {
|
|
783
|
+
store.setFlag('reload', next)
|
|
784
|
+
},
|
|
785
|
+
}),
|
|
786
|
+
),
|
|
787
|
+
h(
|
|
788
|
+
'div',
|
|
789
|
+
{ className: 'dsuik-row' },
|
|
790
|
+
h(
|
|
791
|
+
'div',
|
|
792
|
+
{ className: 'dsuik-rowtext' },
|
|
793
|
+
h('span', { className: 'dsuik-rowname' }, translate('desktop.restartSwitch')),
|
|
794
|
+
h(
|
|
795
|
+
'span',
|
|
796
|
+
{ className: 'dsuik-rowhint' + (restartUnavailable ? ' is-warn' : '') },
|
|
797
|
+
restartUnavailable
|
|
798
|
+
? translate('desktop.restartNotDesktop')
|
|
799
|
+
: translate('desktop.restartSwitchHint'),
|
|
800
|
+
),
|
|
801
|
+
),
|
|
802
|
+
h(Switch, {
|
|
803
|
+
checked: state.restart === true,
|
|
804
|
+
disabled: restartUnavailable,
|
|
805
|
+
label: translate('desktop.restartSwitch'),
|
|
806
|
+
onChange: function (next) {
|
|
807
|
+
store.setFlag('restart', next)
|
|
808
|
+
},
|
|
809
|
+
}),
|
|
810
|
+
),
|
|
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
|
+
),
|
|
835
|
+
surface.controller && !surface.controller.active()
|
|
836
|
+
? h(
|
|
837
|
+
'p',
|
|
838
|
+
{ className: 'dsuik-warn' },
|
|
839
|
+
translate('applyFailed') +
|
|
840
|
+
(surface.controller.error() ? ' ' + surface.controller.error() : ''),
|
|
841
|
+
)
|
|
842
|
+
: null,
|
|
843
|
+
storageBroken ? h('p', { className: 'dsuik-sub' }, translate('storageNote')) : null,
|
|
844
|
+
)
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
/* ------------------------------------------------------------------ *
|
|
848
|
+
* Desktop actions — ported from @moonsand/dsh-desktop-restart
|
|
849
|
+
*
|
|
850
|
+
* One footer registration holds both buttons: the host renders one flex item
|
|
851
|
+
* per registration and its footer does not wrap, so two registrations would
|
|
852
|
+
* count as two items and push a neighbour onto a second line.
|
|
853
|
+
* ------------------------------------------------------------------ */
|
|
854
|
+
|
|
855
|
+
/** How long the second click stays armed before the button reverts to idle. */
|
|
856
|
+
const ARM_TIMEOUT_MS = 6000
|
|
857
|
+
/** How long a restart may take before the button reports that nothing happened. */
|
|
858
|
+
const WATCHDOG_MS = 20000
|
|
859
|
+
/** How long the button stays greyed out after a refused restart. */
|
|
860
|
+
const BLOCKED_MS = 3000
|
|
861
|
+
|
|
862
|
+
/**
|
|
863
|
+
* Restart phase shared by both buttons.
|
|
864
|
+
*
|
|
865
|
+
* While a restart is in flight the reload button must be disabled: reloading
|
|
866
|
+
* mid-kill would race the watchdog and could leave the window blank.
|
|
867
|
+
*/
|
|
868
|
+
const restartPhase = { value: 'idle', since: 0, listeners: new Set() }
|
|
869
|
+
|
|
870
|
+
function currentPhase() {
|
|
871
|
+
const spent = Date.now() - restartPhase.since
|
|
872
|
+
if (restartPhase.value === 'restarting' && spent > WATCHDOG_MS + 5000) {
|
|
873
|
+
restartPhase.value = 'idle'
|
|
874
|
+
} else if (restartPhase.value === 'blocked' && spent > BLOCKED_MS) {
|
|
875
|
+
restartPhase.value = 'idle'
|
|
876
|
+
} else if (
|
|
877
|
+
restartPhase.value !== 'idle' &&
|
|
878
|
+
restartPhase.value !== 'restarting' &&
|
|
879
|
+
restartPhase.value !== 'blocked' &&
|
|
880
|
+
spent > ARM_TIMEOUT_MS + 2000
|
|
881
|
+
) {
|
|
882
|
+
restartPhase.value = 'idle'
|
|
883
|
+
}
|
|
884
|
+
return restartPhase.value
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
function publishPhase(next) {
|
|
888
|
+
restartPhase.value = next
|
|
889
|
+
restartPhase.since = Date.now()
|
|
890
|
+
restartPhase.listeners.forEach(function (listener) {
|
|
891
|
+
listener(next)
|
|
892
|
+
})
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
function useRestartPhase() {
|
|
896
|
+
const [phase, setLocal] = React.useState(currentPhase)
|
|
897
|
+
React.useEffect(function () {
|
|
898
|
+
const listener = function (next) {
|
|
899
|
+
setLocal(next)
|
|
900
|
+
}
|
|
901
|
+
restartPhase.listeners.add(listener)
|
|
902
|
+
setLocal(currentPhase())
|
|
903
|
+
return function () {
|
|
904
|
+
restartPhase.listeners.delete(listener)
|
|
905
|
+
}
|
|
906
|
+
}, [])
|
|
907
|
+
return phase
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
const DESKTOP_CSS = `
|
|
911
|
+
.dsuik-dsr-group{display:flex;align-items:center;gap:4px;min-width:0;max-width:100%}
|
|
912
|
+
.dsuik-dsr-btn{display:inline-flex;align-items:center;gap:6px;box-sizing:border-box;height:26px;max-width:100%;padding:0 8px;border:0;border-radius:8px;background:transparent;color:var(--dsw-alias-label-primary,inherit);font:inherit;font-size:12px;line-height:1;cursor:pointer;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
|
913
|
+
.dsuik-dsr-btn:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(127,127,127,.14))}
|
|
914
|
+
.dsuik-dsr-btn:focus-visible{outline:2px solid var(--dsw-focus-ring-color,currentColor);outline-offset:2px}
|
|
915
|
+
.dsuik-dsr-btn[data-phase="confirm"]{color:var(--dsw-alias-state-error-primary,#d1453b);font-weight:600;background:var(--dsw-alias-interactive-bg-hover,rgba(127,127,127,.14))}
|
|
916
|
+
.dsuik-dsr-btn[data-phase="restarting"]{cursor:progress;opacity:.75}
|
|
917
|
+
.dsuik-dsr-btn[data-phase="blocked"]{color:var(--dsw-alias-state-error-primary,#d1453b);font-weight:600;background:var(--dsw-alias-interactive-bg-hover,rgba(127,127,127,.14));cursor:not-allowed}
|
|
918
|
+
.dsuik-dsr-btn[data-phase="failed"]{color:var(--dsw-alias-state-error-primary,#d1453b);font-weight:600;background:var(--dsw-alias-interactive-bg-hover,rgba(127,127,127,.14))}
|
|
919
|
+
.dsuik-dsr-icon{flex:none;display:block}
|
|
920
|
+
.dsuik-dsr-btn[data-phase="restarting"] .dsuik-dsr-icon{animation:dsuik-dsr-spin 1s linear infinite}
|
|
921
|
+
@keyframes dsuik-dsr-spin{from{transform:rotate(0)}to{transform:rotate(360deg)}}
|
|
922
|
+
.dsuik-alert{display:flex;flex-direction:column;gap:3px;padding:10px 12px;border:1px solid var(--dsw-alias-state-warn-primary);border-radius:10px;}
|
|
923
|
+
.dsuik-alert-title{font-size:12.5px;font-weight:600;line-height:1.4;color:var(--dsw-alias-state-warn-primary);}
|
|
924
|
+
.dsuik-alert-body{font-size:12px;line-height:1.5;color:var(--dsw-alias-label-secondary);}
|
|
925
|
+
`
|
|
926
|
+
|
|
927
|
+
function RestartIcon() {
|
|
928
|
+
return h(
|
|
929
|
+
'svg',
|
|
930
|
+
{
|
|
931
|
+
className: 'dsuik-dsr-icon',
|
|
932
|
+
viewBox: '0 0 16 16',
|
|
933
|
+
width: 14,
|
|
934
|
+
height: 14,
|
|
935
|
+
'aria-hidden': true,
|
|
936
|
+
fill: 'none',
|
|
937
|
+
stroke: 'currentColor',
|
|
938
|
+
strokeWidth: 1.7,
|
|
939
|
+
strokeLinecap: 'round',
|
|
940
|
+
strokeLinejoin: 'round',
|
|
941
|
+
},
|
|
942
|
+
h('path', { d: 'M13.2 8a5.2 5.2 0 1 1-1.8-3.95' }),
|
|
943
|
+
h('path', { d: 'M13.2 2.4v3.2h-3.2' }),
|
|
944
|
+
)
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
function RefreshIcon() {
|
|
948
|
+
return h(
|
|
949
|
+
'svg',
|
|
950
|
+
{
|
|
951
|
+
className: 'dsuik-dsr-icon',
|
|
952
|
+
viewBox: '0 0 16 16',
|
|
953
|
+
width: 14,
|
|
954
|
+
height: 14,
|
|
955
|
+
'aria-hidden': true,
|
|
956
|
+
fill: 'none',
|
|
957
|
+
stroke: 'currentColor',
|
|
958
|
+
strokeWidth: 1.7,
|
|
959
|
+
strokeLinecap: 'round',
|
|
960
|
+
strokeLinejoin: 'round',
|
|
961
|
+
},
|
|
962
|
+
h('path', { d: 'M2.6 8a5.4 5.4 0 0 1 9.2-3.8' }),
|
|
963
|
+
h('path', { d: 'M12.1 1.9v2.9H9.2' }),
|
|
964
|
+
h('path', { d: 'M13.4 8a5.4 5.4 0 0 1-9.2 3.8' }),
|
|
965
|
+
h('path', { d: 'M3.9 14.1v-2.9h2.9' }),
|
|
966
|
+
)
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
async function readStatus() {
|
|
970
|
+
try {
|
|
971
|
+
const response = await fetch('/ui-optimize/desktop/status', {
|
|
972
|
+
method: 'GET',
|
|
973
|
+
headers: { accept: 'application/json' },
|
|
974
|
+
credentials: 'same-origin',
|
|
975
|
+
cache: 'no-store',
|
|
976
|
+
signal: AbortSignal.timeout(6000),
|
|
977
|
+
})
|
|
978
|
+
if (!response.ok) return undefined
|
|
979
|
+
return await response.json()
|
|
980
|
+
} catch (err) {
|
|
981
|
+
return undefined
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
/**
|
|
986
|
+
* Detect the standalone `@moonsand/dsh-desktop-restart` plugin.
|
|
987
|
+
*
|
|
988
|
+
* Its own status route is the cheapest proof that it is still loaded, and this
|
|
989
|
+
* plugin deliberately owns a different prefix — so a 200 here can only come
|
|
990
|
+
* from that other installation, never from ourselves.
|
|
991
|
+
*/
|
|
992
|
+
async function detectStandalone() {
|
|
993
|
+
try {
|
|
994
|
+
const response = await fetch('/desktop-restart/status', {
|
|
995
|
+
method: 'GET',
|
|
996
|
+
headers: { accept: 'application/json' },
|
|
997
|
+
credentials: 'same-origin',
|
|
998
|
+
cache: 'no-store',
|
|
999
|
+
signal: AbortSignal.timeout(4000),
|
|
1000
|
+
})
|
|
1001
|
+
return response.ok
|
|
1002
|
+
} catch (err) {
|
|
1003
|
+
return false
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
async function requestRestart() {
|
|
1008
|
+
try {
|
|
1009
|
+
const response = await fetch('/ui-optimize/desktop/restart', {
|
|
1010
|
+
method: 'POST',
|
|
1011
|
+
headers: { accept: 'application/json', 'x-dsh-desktop-restart': '1' },
|
|
1012
|
+
credentials: 'same-origin',
|
|
1013
|
+
cache: 'no-store',
|
|
1014
|
+
signal: AbortSignal.timeout(15000),
|
|
1015
|
+
})
|
|
1016
|
+
let body
|
|
1017
|
+
try {
|
|
1018
|
+
body = await response.json()
|
|
1019
|
+
} catch (err) {
|
|
1020
|
+
body = undefined
|
|
1021
|
+
}
|
|
1022
|
+
return { status: response.status, body: body }
|
|
1023
|
+
} catch (err) {
|
|
1024
|
+
return undefined
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
|
|
1028
|
+
function RefreshButton(props) {
|
|
1029
|
+
const wide = props.wide !== false
|
|
1030
|
+
const [busy, setBusy] = React.useState(false)
|
|
1031
|
+
const restart = useRestartPhase()
|
|
1032
|
+
const blocked = restart === 'restarting'
|
|
1033
|
+
const timer = React.useRef(0)
|
|
1034
|
+
React.useEffect(function () {
|
|
1035
|
+
return function () {
|
|
1036
|
+
clearTimeout(timer.current)
|
|
1037
|
+
}
|
|
1038
|
+
}, [])
|
|
1039
|
+
|
|
1040
|
+
function onClick() {
|
|
1041
|
+
if (busy || blocked) return
|
|
1042
|
+
setBusy(true)
|
|
1043
|
+
timer.current = window.setTimeout(function () {
|
|
1044
|
+
window.location.reload()
|
|
1045
|
+
}, 120)
|
|
1046
|
+
}
|
|
1047
|
+
|
|
1048
|
+
const label = blocked
|
|
1049
|
+
? translate('desktop.refreshBlocked')
|
|
1050
|
+
: busy
|
|
1051
|
+
? translate('desktop.reloading')
|
|
1052
|
+
: translate('desktop.refresh')
|
|
1053
|
+
|
|
1054
|
+
return h(
|
|
1055
|
+
'button',
|
|
1056
|
+
{
|
|
1057
|
+
type: 'button',
|
|
1058
|
+
className: 'dsuik-dsr-btn',
|
|
1059
|
+
'data-phase': blocked ? 'blocked' : busy ? 'restarting' : 'idle',
|
|
1060
|
+
disabled: busy || blocked,
|
|
1061
|
+
'aria-label': translate('desktop.refresh'),
|
|
1062
|
+
title: blocked ? translate('desktop.refreshBlocked') : translate('desktop.refreshHint'),
|
|
1063
|
+
onClick: onClick,
|
|
1064
|
+
},
|
|
1065
|
+
h(RefreshIcon),
|
|
1066
|
+
wide ? h('span', null, label) : null,
|
|
1067
|
+
)
|
|
1068
|
+
}
|
|
1069
|
+
|
|
1070
|
+
function RestartButton(props) {
|
|
1071
|
+
const wide = props.wide !== false
|
|
1072
|
+
const phase = useRestartPhase()
|
|
1073
|
+
const [note, setNote] = React.useState('')
|
|
1074
|
+
const [busyTasks, setBusyTasks] = React.useState(0)
|
|
1075
|
+
const armTimer = React.useRef(0)
|
|
1076
|
+
const watchdog = React.useRef(0)
|
|
1077
|
+
|
|
1078
|
+
React.useEffect(function () {
|
|
1079
|
+
return function () {
|
|
1080
|
+
clearTimeout(armTimer.current)
|
|
1081
|
+
clearTimeout(watchdog.current)
|
|
1082
|
+
}
|
|
1083
|
+
}, [])
|
|
1084
|
+
|
|
1085
|
+
function settle() {
|
|
1086
|
+
clearTimeout(armTimer.current)
|
|
1087
|
+
publishPhase('idle')
|
|
1088
|
+
setNote('')
|
|
1089
|
+
setBusyTasks(0)
|
|
1090
|
+
}
|
|
1091
|
+
|
|
1092
|
+
function reloadInsteadOfRestart(message) {
|
|
1093
|
+
clearTimeout(armTimer.current)
|
|
1094
|
+
publishPhase('failed')
|
|
1095
|
+
setNote(message)
|
|
1096
|
+
window.setTimeout(function () {
|
|
1097
|
+
window.location.reload()
|
|
1098
|
+
}, 1200)
|
|
1099
|
+
}
|
|
1100
|
+
|
|
1101
|
+
async function arm() {
|
|
1102
|
+
clearTimeout(armTimer.current)
|
|
1103
|
+
publishPhase('confirm')
|
|
1104
|
+
setNote(translate('desktop.confirm'))
|
|
1105
|
+
armTimer.current = window.setTimeout(settle, ARM_TIMEOUT_MS)
|
|
1106
|
+
const status = await readStatus()
|
|
1107
|
+
if (status === undefined) return
|
|
1108
|
+
if (status.desktop !== true) {
|
|
1109
|
+
reloadInsteadOfRestart(translate('desktop.notDesktop'))
|
|
1110
|
+
return
|
|
1111
|
+
}
|
|
1112
|
+
if (typeof status.activeAgents === 'number' && status.activeAgents > 0) {
|
|
1113
|
+
setBusyTasks(status.activeAgents)
|
|
1114
|
+
setNote(translate('desktop.confirmBusy'))
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
1117
|
+
|
|
1118
|
+
async function restart() {
|
|
1119
|
+
clearTimeout(armTimer.current)
|
|
1120
|
+
publishPhase('restarting')
|
|
1121
|
+
setNote(translate('desktop.restarting'))
|
|
1122
|
+
const answer = await requestRestart()
|
|
1123
|
+
if (answer === undefined) {
|
|
1124
|
+
reloadInsteadOfRestart(translate('desktop.unreachable'))
|
|
1125
|
+
return
|
|
1126
|
+
}
|
|
1127
|
+
const reason = answer.body && answer.body.reason
|
|
1128
|
+
if (reason === 'installing') {
|
|
1129
|
+
publishPhase('blocked')
|
|
1130
|
+
setNote(translate('desktop.installing'))
|
|
1131
|
+
window.setTimeout(function () {
|
|
1132
|
+
if (restartPhase.value === 'blocked') publishPhase('idle')
|
|
1133
|
+
}, BLOCKED_MS)
|
|
1134
|
+
return
|
|
1135
|
+
}
|
|
1136
|
+
if (answer.status === 409 || reason === 'not-desktop') {
|
|
1137
|
+
reloadInsteadOfRestart(translate('desktop.notDesktop'))
|
|
1138
|
+
return
|
|
1139
|
+
}
|
|
1140
|
+
if (!answer.body || answer.body.ok !== true) {
|
|
1141
|
+
publishPhase('failed')
|
|
1142
|
+
setNote(
|
|
1143
|
+
answer.body && typeof answer.body.message === 'string'
|
|
1144
|
+
? answer.body.message
|
|
1145
|
+
: translate('desktop.failed'),
|
|
1146
|
+
)
|
|
1147
|
+
return
|
|
1148
|
+
}
|
|
1149
|
+
watchdog.current = window.setTimeout(function () {
|
|
1150
|
+
publishPhase('failed')
|
|
1151
|
+
setNote(translate('desktop.stillAlive'))
|
|
1152
|
+
}, WATCHDOG_MS)
|
|
1153
|
+
}
|
|
1154
|
+
|
|
1155
|
+
function onClick() {
|
|
1156
|
+
if (phase === 'restarting') return
|
|
1157
|
+
if (phase === 'confirm') {
|
|
1158
|
+
void restart()
|
|
1159
|
+
return
|
|
1160
|
+
}
|
|
1161
|
+
void arm()
|
|
1162
|
+
}
|
|
1163
|
+
|
|
1164
|
+
function onKeyDown(event) {
|
|
1165
|
+
if (event.key === 'Escape' && phase === 'confirm') {
|
|
1166
|
+
event.preventDefault()
|
|
1167
|
+
settle()
|
|
1168
|
+
}
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1171
|
+
let label = translate('desktop.label')
|
|
1172
|
+
if (phase === 'confirm') {
|
|
1173
|
+
label = busyTasks > 0 ? translate('desktop.confirmBusy') : translate('desktop.confirm')
|
|
1174
|
+
} else if (phase === 'restarting') {
|
|
1175
|
+
label = translate('desktop.restarting')
|
|
1176
|
+
} else if (phase === 'blocked') {
|
|
1177
|
+
label = translate('desktop.installing')
|
|
1178
|
+
} else if (phase === 'failed') {
|
|
1179
|
+
label = translate('desktop.failed')
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1182
|
+
return h(
|
|
1183
|
+
'button',
|
|
1184
|
+
{
|
|
1185
|
+
type: 'button',
|
|
1186
|
+
className: 'dsuik-dsr-btn',
|
|
1187
|
+
'data-phase': phase,
|
|
1188
|
+
disabled: phase === 'restarting',
|
|
1189
|
+
'aria-label': translate('desktop.label'),
|
|
1190
|
+
title: note === '' ? translate('desktop.hint') : note,
|
|
1191
|
+
onClick: onClick,
|
|
1192
|
+
onKeyDown: onKeyDown,
|
|
1193
|
+
},
|
|
1194
|
+
h(RestartIcon),
|
|
1195
|
+
wide || phase !== 'idle' ? h('span', null, label) : null,
|
|
1196
|
+
)
|
|
1197
|
+
}
|
|
1198
|
+
|
|
1199
|
+
/**
|
|
1200
|
+
* Shown right after this bundle is enabled. A plugin cannot intercept its own
|
|
1201
|
+
* installation — the plugin manager performs that — but this slot appears at the
|
|
1202
|
+
* moment the user is looking, so the standalone-plugin conflict is raised there
|
|
1203
|
+
* as well as on the settings page.
|
|
1204
|
+
*/
|
|
1205
|
+
function ActivationNote() {
|
|
1206
|
+
const [legacy, setLegacy] = React.useState(false)
|
|
1207
|
+
React.useEffect(function () {
|
|
1208
|
+
let alive = true
|
|
1209
|
+
void detectStandalone().then(function (present) {
|
|
1210
|
+
if (alive) setLegacy(present)
|
|
1211
|
+
})
|
|
1212
|
+
return function () {
|
|
1213
|
+
alive = false
|
|
1214
|
+
}
|
|
1215
|
+
}, [])
|
|
1216
|
+
if (!legacy) return null
|
|
1217
|
+
return h(
|
|
1218
|
+
'div',
|
|
1219
|
+
{ className: 'dsuik-alert' },
|
|
1220
|
+
h('span', { className: 'dsuik-alert-title' }, translate('legacy.title')),
|
|
1221
|
+
h('span', { className: 'dsuik-alert-body' }, translate('legacy.body')),
|
|
1222
|
+
)
|
|
1223
|
+
}
|
|
1224
|
+
|
|
1225
|
+
function DesktopActions(props) {
|
|
1226
|
+
const [state, setState] = React.useState(store.state)
|
|
1227
|
+
React.useEffect(function () {
|
|
1228
|
+
return store.subscribe(function () {
|
|
1229
|
+
setState(store.state)
|
|
1230
|
+
})
|
|
1231
|
+
}, [])
|
|
1232
|
+
const wide = props.wide !== false
|
|
1233
|
+
const showReload = state.reload === true
|
|
1234
|
+
const showRestart = state.restart === true
|
|
1235
|
+
if (!showReload && !showRestart) return null
|
|
1236
|
+
return h(
|
|
1237
|
+
'div',
|
|
1238
|
+
{ className: 'dsuik-dsr-group' },
|
|
1239
|
+
showReload ? h(RefreshButton, { wide: wide }) : null,
|
|
1240
|
+
showRestart ? h(RestartButton, { wide: wide }) : null,
|
|
1241
|
+
)
|
|
1242
|
+
}
|
|
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
|
+
|
|
1724
|
+
/* ------------------------------------------------------------------ *
|
|
1725
|
+
* Plugin
|
|
1726
|
+
* ------------------------------------------------------------------ */
|
|
1727
|
+
|
|
1728
|
+
return {
|
|
1729
|
+
inject: ['slots'],
|
|
1730
|
+
apply(ctx) {
|
|
1731
|
+
try {
|
|
1732
|
+
const locale = typeof ctx.get === 'function' ? ctx.get('locale') : undefined
|
|
1733
|
+
if (locale && typeof locale.register === 'function' && typeof locale.bind === 'function') {
|
|
1734
|
+
locale.register(NS, { en: DICT.en, zh: DICT.zh })
|
|
1735
|
+
const bound = locale.bind(NS)
|
|
1736
|
+
translate = function (key) {
|
|
1737
|
+
try {
|
|
1738
|
+
const value = bound(key)
|
|
1739
|
+
if (typeof value === 'string' && value.length > 0) return value
|
|
1740
|
+
} catch (err) {
|
|
1741
|
+
/* fall through to the built-in dictionary */
|
|
1742
|
+
}
|
|
1743
|
+
const table = DICT[detectLanguage()] || DICT.en
|
|
1744
|
+
return table[key] || DICT.en[key] || key
|
|
1745
|
+
}
|
|
1746
|
+
}
|
|
1747
|
+
} catch (err) {
|
|
1748
|
+
/* keep the built-in dictionary */
|
|
1749
|
+
}
|
|
1750
|
+
|
|
1751
|
+
/* The client tree may still be composing when this plugin mounts, so the
|
|
1752
|
+
* theme service can be unreachable on the first attempt. Retry briefly
|
|
1753
|
+
* instead of staying silently unapplied for the whole page session, and
|
|
1754
|
+
* re-apply whenever the platform republishes its own theme. */
|
|
1755
|
+
ctx.effect(function () {
|
|
1756
|
+
const controller = createController(function () {
|
|
1757
|
+
return typeof ctx.get === 'function' ? ctx.get('theme') : undefined
|
|
1758
|
+
})
|
|
1759
|
+
surface.controller = controller
|
|
1760
|
+
|
|
1761
|
+
/* Re-entrancy guards. `overrideTokens` emits `theme/change` itself, so an
|
|
1762
|
+
* ungated listener re-applies on our own emission and loops forever —
|
|
1763
|
+
* one full restack and re-render per turn, which reads as stutter. */
|
|
1764
|
+
let applied = null
|
|
1765
|
+
let busy = false
|
|
1766
|
+
|
|
1767
|
+
function sync() {
|
|
1768
|
+
if (busy) return
|
|
1769
|
+
const key = store.state.theme
|
|
1770
|
+
if (key === applied && controller.active()) return
|
|
1771
|
+
busy = true
|
|
1772
|
+
let settled = false
|
|
1773
|
+
try {
|
|
1774
|
+
settled = controller.sync(store.state)
|
|
1775
|
+
} finally {
|
|
1776
|
+
busy = false
|
|
1777
|
+
}
|
|
1778
|
+
applied = settled ? key : null
|
|
1779
|
+
}
|
|
1780
|
+
|
|
1781
|
+
let attempts = 0
|
|
1782
|
+
let timer = null
|
|
1783
|
+
function tick() {
|
|
1784
|
+
timer = null
|
|
1785
|
+
sync()
|
|
1786
|
+
if (controller.active()) return
|
|
1787
|
+
attempts += 1
|
|
1788
|
+
if (attempts >= 20) return
|
|
1789
|
+
timer = setTimeout(tick, 250)
|
|
1790
|
+
}
|
|
1791
|
+
tick()
|
|
1792
|
+
|
|
1793
|
+
/* Only repair the layer when the platform has actually dropped it. */
|
|
1794
|
+
const offChange =
|
|
1795
|
+
typeof ctx.on === 'function'
|
|
1796
|
+
? ctx.on('theme/change', function () {
|
|
1797
|
+
if (controller.active()) return
|
|
1798
|
+
applied = null
|
|
1799
|
+
sync()
|
|
1800
|
+
})
|
|
1801
|
+
: function () {}
|
|
1802
|
+
|
|
1803
|
+
const unsubscribe = store.subscribe(sync)
|
|
1804
|
+
|
|
1805
|
+
return function () {
|
|
1806
|
+
if (timer) clearTimeout(timer)
|
|
1807
|
+
offChange()
|
|
1808
|
+
unsubscribe()
|
|
1809
|
+
controller.dispose()
|
|
1810
|
+
surface.controller = null
|
|
1811
|
+
}
|
|
1812
|
+
}, 'dsh-ui-optimize: theme layer')
|
|
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
|
+
|
|
1851
|
+
ctx.slots.inject('settings.section', function () {
|
|
1852
|
+
return ctx.slots.register(
|
|
1853
|
+
{
|
|
1854
|
+
name: 'settings.section',
|
|
1855
|
+
id: 'ui-optimize',
|
|
1856
|
+
order: 120,
|
|
1857
|
+
label: function () {
|
|
1858
|
+
return translate('title')
|
|
1859
|
+
},
|
|
1860
|
+
},
|
|
1861
|
+
SettingsPage,
|
|
1862
|
+
)
|
|
1863
|
+
})
|
|
1864
|
+
|
|
1865
|
+
/* Footer buttons live outside the settings page, so their styles cannot ride
|
|
1866
|
+
* on the page's <style> element and must be registered with the run itself. */
|
|
1867
|
+
ctx.effect(function () {
|
|
1868
|
+
const style = document.createElement('style')
|
|
1869
|
+
style.setAttribute('data-dsh-ui-optimize', 'desktop-actions')
|
|
1870
|
+
style.textContent = DESKTOP_CSS
|
|
1871
|
+
document.head.appendChild(style)
|
|
1872
|
+
return function () {
|
|
1873
|
+
style.remove()
|
|
1874
|
+
}
|
|
1875
|
+
}, 'dsh-ui-optimize: desktop action styles')
|
|
1876
|
+
|
|
1877
|
+
ctx.slots.inject('sidebar.footer.action', function () {
|
|
1878
|
+
return ctx.slots.register(
|
|
1879
|
+
{
|
|
1880
|
+
name: 'sidebar.footer.action',
|
|
1881
|
+
id: 'ui-optimize-desktop-actions',
|
|
1882
|
+
order: -110,
|
|
1883
|
+
label: function () {
|
|
1884
|
+
return translate('desktop.refresh')
|
|
1885
|
+
},
|
|
1886
|
+
inject: function () {
|
|
1887
|
+
return {}
|
|
1888
|
+
},
|
|
1889
|
+
},
|
|
1890
|
+
DesktopActions,
|
|
1891
|
+
)
|
|
1892
|
+
})
|
|
1893
|
+
|
|
1894
|
+
/* Guidance shown on the bundle row right after it is enabled, keyed by our
|
|
1895
|
+
* own package name. This is the closest thing to an install-time reminder a
|
|
1896
|
+
* plugin can own. */
|
|
1897
|
+
ctx.slots.inject('plugins.bundle.activation', function () {
|
|
1898
|
+
return ctx.slots.register(
|
|
1899
|
+
{ name: 'plugins.bundle.activation', key: '@moonsand/dsh-ui-optimize' },
|
|
1900
|
+
ActivationNote,
|
|
1901
|
+
)
|
|
1902
|
+
})
|
|
1903
|
+
},
|
|
1904
|
+
}
|
|
1905
|
+
},
|
|
1906
|
+
})
|