@eum-agent/keyboard-shortcuts 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +13 -0
- package/package.json +51 -3
- package/ui/ui.js +1461 -0
- package/README.md +0 -3
package/ui/ui.js
ADDED
|
@@ -0,0 +1,1461 @@
|
|
|
1
|
+
import { Alert, AlertDialog, BROWSER_RESERVED, Badge, Button, CHORD, EDITING_RESERVED, GLOBAL_WINDOW_BINDING, HOST_OWNER, Input, InputGroup, KeyCaps, Panel, Segmented, Table, TableBody, TableCell, TableHead, TableHeader, TableRow, Tooltip, TooltipContent, TooltipTrigger, Warning, chordRefusal, cn, currentPlatform, formatChord, fromEvent, installHotkeys, localeLeaves, resolveLabel, useKeybindingRows, useKeybindings, useTranslation } from "@eum-agent/host/framework";
|
|
2
|
+
import React, { createContext, createElement, forwardRef, useContext, useEffect, useId, useRef, useState } from "react";
|
|
3
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
+
//#region ui-src/activation.ts
|
|
5
|
+
/** Acquires optional native resources before installing this feature's observers. */
|
|
6
|
+
function activateNativeFeature(ctx, feature, start) {
|
|
7
|
+
const native = ctx.services.get("native-client-features");
|
|
8
|
+
if (!native) {
|
|
9
|
+
start();
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
native.activate(feature, ctx.signal).then(() => {
|
|
13
|
+
if (!ctx.signal.aborted) start();
|
|
14
|
+
}).catch(() => {});
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region ui-src/i18n.ts
|
|
18
|
+
/** Platform browser strings share the host's language and React translation runtime. */
|
|
19
|
+
var translations;
|
|
20
|
+
/** Binds this activation's registered namespace without reconstructing the owner's namespace. */
|
|
21
|
+
function configureTranslations(ctx) {
|
|
22
|
+
translations = ctx.i18n;
|
|
23
|
+
}
|
|
24
|
+
/** Observes the shared language while resolving platform-owned copy. */
|
|
25
|
+
function useTranslation$1() {
|
|
26
|
+
const shared = useTranslation();
|
|
27
|
+
if (!translations) throw new Error("platform browser translations are not registered");
|
|
28
|
+
return {
|
|
29
|
+
...shared,
|
|
30
|
+
t: translations.t
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/** Resolves notification text through this activation's own registered namespace. */
|
|
34
|
+
function platformText(key, options) {
|
|
35
|
+
if (!translations) throw new Error("platform browser translations are not registered");
|
|
36
|
+
return translations.t(key, options);
|
|
37
|
+
}
|
|
38
|
+
var en_US_default = {
|
|
39
|
+
keybindings: {
|
|
40
|
+
"noteGlobalWindow": "Occupied by the global window shortcut",
|
|
41
|
+
"title": "Keyboard shortcuts",
|
|
42
|
+
"resetAll": "Reset all",
|
|
43
|
+
"resetAllTitle": "Reset every shortcut?",
|
|
44
|
+
"resetAllBody": "{{count}} changes will be undone and every shortcut returns to its default. Defaults that clash stay marked as conflicts.",
|
|
45
|
+
"resetAllBody_one": "{{count}} change will be undone and every shortcut returns to its default. Defaults that clash stay marked as conflicts.",
|
|
46
|
+
"resetAllConfirm": "Reset all",
|
|
47
|
+
"cancel": "Cancel",
|
|
48
|
+
"conflictBanner": "{{count}} shortcuts conflict. A conflicting row is inactive; the key triggers the one registered first.",
|
|
49
|
+
"conflictBanner_one": "{{count}} shortcut conflicts. A conflicting row is inactive; the key triggers the one registered first.",
|
|
50
|
+
"onlyConflicts": "Show conflicts",
|
|
51
|
+
"conflictBadge": "{{count}} conflicts",
|
|
52
|
+
"conflictBadge_one": "{{count}} conflict",
|
|
53
|
+
"searchPlaceholder": "Search by action or source",
|
|
54
|
+
"searchByKey": "Search by keys",
|
|
55
|
+
"keyPlaceholder": "Press the keys to look for",
|
|
56
|
+
"filter": "Filter",
|
|
57
|
+
"filterAll": "All {{count}}",
|
|
58
|
+
"filterModified": "Changed {{count}}",
|
|
59
|
+
"filterConflicts": "Conflicts {{count}}",
|
|
60
|
+
"table": "Keyboard shortcuts",
|
|
61
|
+
"columnAction": "Action",
|
|
62
|
+
"columnSource": "Source",
|
|
63
|
+
"columnKeys": "Shortcut",
|
|
64
|
+
"columnState": "State",
|
|
65
|
+
"sourceHost": "YaoGuang",
|
|
66
|
+
"stateModified": "Changed",
|
|
67
|
+
"stateConflict": "Conflict",
|
|
68
|
+
"stateUnbound": "Unassigned",
|
|
69
|
+
"noteConflict": "Conflicts with “{{label}}” ({{source}}); inactive",
|
|
70
|
+
"noteInvalid": "The plugin default {{keys}} cannot be used and was ignored",
|
|
71
|
+
"noteRemoved": "Removed; default {{keys}}",
|
|
72
|
+
"noteDefault": "Default {{keys}}",
|
|
73
|
+
"edit": "Change shortcut",
|
|
74
|
+
"reset": "Reset to default",
|
|
75
|
+
"remove": "Remove shortcut",
|
|
76
|
+
"recording": "Press new keys…",
|
|
77
|
+
"recorderName": "Record keys for “{{label}}”",
|
|
78
|
+
"recordingHint": "Press new keys, Enter to save, esc to cancel. No shortcut fires while recording.",
|
|
79
|
+
"taken": "{{keys}} is used by “{{label}}” ({{source}}). Replacing leaves “{{label}}” unassigned.",
|
|
80
|
+
"replace": "Replace",
|
|
81
|
+
"invalidGrammar": "A shortcut needs {{mod}} or {{alt}}.",
|
|
82
|
+
"invalidReserved": "{{keys}} is reserved and cannot be used.",
|
|
83
|
+
"reservedBrowser": "{{keys}} and similar belong to the browser; editing keys such as copy, paste and undo are reserved too.",
|
|
84
|
+
"reservedDevice": "{{keys}} and similar belong to the app menu; editing keys such as copy, paste and undo are reserved too.",
|
|
85
|
+
"empty": "No matching shortcuts",
|
|
86
|
+
"emptyKey": "No shortcut uses {{keys}}",
|
|
87
|
+
"unsavedBrowser": "This browser does not allow saving settings. Changes hold for this page and are lost on reload.",
|
|
88
|
+
"unsavedDevice": "Shortcut settings could not be written to this computer. Changes hold until the app closes."
|
|
89
|
+
},
|
|
90
|
+
presence: {
|
|
91
|
+
"title": "Global window shortcut",
|
|
92
|
+
"hint": "Show or hide YaoGuang from any application. This shortcut is local to this device.",
|
|
93
|
+
"desired": "Configured shortcut",
|
|
94
|
+
"effective": "Active shortcut",
|
|
95
|
+
"registered": "Registered shortcuts",
|
|
96
|
+
"tray": "Tray available",
|
|
97
|
+
"trayMissing": "Tray unavailable; the window stays visible. Use Quit to exit.",
|
|
98
|
+
"change": "Change window shortcut",
|
|
99
|
+
"disable": "Disable window shortcut",
|
|
100
|
+
"default": "Restore default shortcut",
|
|
101
|
+
"refresh": "Refresh native state",
|
|
102
|
+
"pausing": "Waiting for native recording pause…",
|
|
103
|
+
"none": "None",
|
|
104
|
+
"problem": "Shortcut operation failed",
|
|
105
|
+
"problems": {
|
|
106
|
+
"state": "The native shortcut state needs attention. Check the configured and registered shortcuts, then refresh.",
|
|
107
|
+
"shortcutConflict": "The global shortcut could not be registered or released. Check other applications and the current registrations.",
|
|
108
|
+
"preferencesRead": "Desktop preferences could not be read. Check local file permissions, then refresh.",
|
|
109
|
+
"preferencesWrite": "Desktop preferences could not be saved. Check local file permissions, then retry.",
|
|
110
|
+
"windowAction": "The desktop window operation failed. Refresh native state, then retry."
|
|
111
|
+
},
|
|
112
|
+
"record": "Window shortcut"
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
var zh_CN_default = {
|
|
116
|
+
keybindings: {
|
|
117
|
+
"noteGlobalWindow": "被全局窗口快捷键占用",
|
|
118
|
+
"title": "快捷键",
|
|
119
|
+
"resetAll": "全部重置",
|
|
120
|
+
"resetAllTitle": "重置全部快捷键?",
|
|
121
|
+
"resetAllBody": "{{count}} 处改动将撤销,所有快捷键回到各自的默认组合键。默认组合键冲突的仍标为冲突。",
|
|
122
|
+
"resetAllConfirm": "重置全部",
|
|
123
|
+
"cancel": "取消",
|
|
124
|
+
"conflictBanner": "有 {{count}} 个快捷键冲突,冲突的一行暂不生效,按下时只触发先注册的一方。",
|
|
125
|
+
"onlyConflicts": "只看冲突",
|
|
126
|
+
"conflictBadge": "{{count}} 个冲突",
|
|
127
|
+
"searchPlaceholder": "搜索操作名称或来源",
|
|
128
|
+
"searchByKey": "按按键搜索",
|
|
129
|
+
"keyPlaceholder": "按下要查找的组合键",
|
|
130
|
+
"filter": "筛选",
|
|
131
|
+
"filterAll": "全部 {{count}}",
|
|
132
|
+
"filterModified": "已修改 {{count}}",
|
|
133
|
+
"filterConflicts": "冲突 {{count}}",
|
|
134
|
+
"table": "快捷键",
|
|
135
|
+
"columnAction": "操作",
|
|
136
|
+
"columnSource": "来源",
|
|
137
|
+
"columnKeys": "快捷键",
|
|
138
|
+
"columnState": "状态",
|
|
139
|
+
"sourceHost": "瑶光",
|
|
140
|
+
"stateModified": "已修改",
|
|
141
|
+
"stateConflict": "冲突",
|
|
142
|
+
"stateUnbound": "未绑定",
|
|
143
|
+
"noteConflict": "与「{{label}}」({{source}})冲突,暂不生效",
|
|
144
|
+
"noteInvalid": "插件提供的默认组合键 {{keys}} 不可用,已忽略",
|
|
145
|
+
"noteRemoved": "已移除,默认 {{keys}}",
|
|
146
|
+
"noteDefault": "默认 {{keys}}",
|
|
147
|
+
"edit": "修改快捷键",
|
|
148
|
+
"reset": "重置为默认",
|
|
149
|
+
"remove": "移除快捷键",
|
|
150
|
+
"recording": "按下新的组合键…",
|
|
151
|
+
"recorderName": "为「{{label}}」录入组合键",
|
|
152
|
+
"recordingHint": "按下新的组合键,Enter 保存,esc 取消。录入期间不会触发任何快捷键。",
|
|
153
|
+
"taken": "{{keys}} 正被「{{label}}」({{source}})使用。替换后「{{label}}」将变为未绑定。",
|
|
154
|
+
"replace": "替换",
|
|
155
|
+
"invalidGrammar": "组合键需要包含 {{mod}} 或 {{alt}}。",
|
|
156
|
+
"invalidReserved": "{{keys}} 是保留的组合键,不能使用。",
|
|
157
|
+
"reservedBrowser": "{{keys}} 等由浏览器保留,页面收不到;复制、粘贴、撤销等编辑快捷键也不能占用。",
|
|
158
|
+
"reservedDevice": "{{keys}} 等由应用菜单占用;复制、粘贴、撤销等编辑快捷键也不能占用。",
|
|
159
|
+
"empty": "没有匹配的快捷键",
|
|
160
|
+
"emptyKey": "没有快捷键使用 {{keys}}",
|
|
161
|
+
"unsavedBrowser": "浏览器不允许保存设置,改动只在本页有效,刷新后恢复原样。",
|
|
162
|
+
"unsavedDevice": "快捷键设置没能写入本机,改动只在这次运行中有效,重新打开后恢复原样。"
|
|
163
|
+
},
|
|
164
|
+
presence: {
|
|
165
|
+
"title": "全局窗口快捷键",
|
|
166
|
+
"hint": "在任意应用中显示或隐藏瑶光。此快捷键仅保存在本设备。",
|
|
167
|
+
"desired": "已设置快捷键",
|
|
168
|
+
"effective": "生效快捷键",
|
|
169
|
+
"registered": "已注册快捷键",
|
|
170
|
+
"tray": "托盘可用",
|
|
171
|
+
"trayMissing": "托盘不可用;窗口保持可见。请使用“退出”结束应用。",
|
|
172
|
+
"change": "更改窗口快捷键",
|
|
173
|
+
"disable": "禁用窗口快捷键",
|
|
174
|
+
"default": "恢复默认快捷键",
|
|
175
|
+
"refresh": "刷新原生状态",
|
|
176
|
+
"pausing": "正在等待原生暂停录制确认…",
|
|
177
|
+
"none": "无",
|
|
178
|
+
"problem": "快捷键操作失败",
|
|
179
|
+
"problems": {
|
|
180
|
+
"state": "原生快捷键状态需要处理。请核对已设置和已注册的快捷键后刷新。",
|
|
181
|
+
"shortcutConflict": "全局快捷键无法注册或释放。请检查其他应用是否占用,并核对当前注册结果。",
|
|
182
|
+
"preferencesRead": "无法读取桌面偏好设置。请检查本机文件访问权限后刷新。",
|
|
183
|
+
"preferencesWrite": "无法保存桌面偏好设置。请检查本机文件访问权限后重试。",
|
|
184
|
+
"windowAction": "无法操作桌面窗口。请刷新原生状态后重试。"
|
|
185
|
+
},
|
|
186
|
+
"record": "窗口快捷键"
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
//#endregion
|
|
190
|
+
//#region ui-src/catalogues.ts
|
|
191
|
+
/** Registers this owner's localized client copy for its activation. */
|
|
192
|
+
function registerTranslations(ctx) {
|
|
193
|
+
configureTranslations(ctx);
|
|
194
|
+
ctx.i18n.register({
|
|
195
|
+
"en-US": localeLeaves(en_US_default),
|
|
196
|
+
"zh-CN": localeLeaves(zh_CN_default)
|
|
197
|
+
}, "zh-CN");
|
|
198
|
+
}
|
|
199
|
+
//#endregion
|
|
200
|
+
//#region ../../../node_modules/.pnpm/lucide-react@1.40.0_react@19.2.8/node_modules/lucide-react/dist/esm/shared/src/utils/mergeClasses.mjs
|
|
201
|
+
/**
|
|
202
|
+
* @license lucide-react v1.40.0 - ISC
|
|
203
|
+
*
|
|
204
|
+
* This source code is licensed under the ISC license.
|
|
205
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
206
|
+
*/
|
|
207
|
+
var mergeClasses = (...classes) => classes.filter((className, index, array) => {
|
|
208
|
+
return Boolean(className) && className.trim() !== "" && array.indexOf(className) === index;
|
|
209
|
+
}).join(" ").trim();
|
|
210
|
+
//#endregion
|
|
211
|
+
//#region ../../../node_modules/.pnpm/lucide-react@1.40.0_react@19.2.8/node_modules/lucide-react/dist/esm/shared/src/utils/toKebabCase.mjs
|
|
212
|
+
/**
|
|
213
|
+
* @license lucide-react v1.40.0 - ISC
|
|
214
|
+
*
|
|
215
|
+
* This source code is licensed under the ISC license.
|
|
216
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
217
|
+
*/
|
|
218
|
+
var toKebabCase = (string) => string.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
|
|
219
|
+
//#endregion
|
|
220
|
+
//#region ../../../node_modules/.pnpm/lucide-react@1.40.0_react@19.2.8/node_modules/lucide-react/dist/esm/shared/src/utils/toCamelCase.mjs
|
|
221
|
+
/**
|
|
222
|
+
* @license lucide-react v1.40.0 - ISC
|
|
223
|
+
*
|
|
224
|
+
* This source code is licensed under the ISC license.
|
|
225
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
226
|
+
*/
|
|
227
|
+
var toCamelCase = (string) => string.replace(/^([A-Z])|[\s-_]+(\w)/g, (match, p1, p2) => p2 ? p2.toUpperCase() : p1.toLowerCase());
|
|
228
|
+
//#endregion
|
|
229
|
+
//#region ../../../node_modules/.pnpm/lucide-react@1.40.0_react@19.2.8/node_modules/lucide-react/dist/esm/shared/src/utils/toPascalCase.mjs
|
|
230
|
+
/**
|
|
231
|
+
* @license lucide-react v1.40.0 - ISC
|
|
232
|
+
*
|
|
233
|
+
* This source code is licensed under the ISC license.
|
|
234
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
235
|
+
*/
|
|
236
|
+
var toPascalCase = (string) => {
|
|
237
|
+
const camelCase = toCamelCase(string);
|
|
238
|
+
return camelCase.charAt(0).toUpperCase() + camelCase.slice(1);
|
|
239
|
+
};
|
|
240
|
+
//#endregion
|
|
241
|
+
//#region ../../../node_modules/.pnpm/lucide-react@1.40.0_react@19.2.8/node_modules/lucide-react/dist/esm/defaultAttributes.mjs
|
|
242
|
+
/**
|
|
243
|
+
* @license lucide-react v1.40.0 - ISC
|
|
244
|
+
*
|
|
245
|
+
* This source code is licensed under the ISC license.
|
|
246
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
247
|
+
*/
|
|
248
|
+
var defaultAttributes = {
|
|
249
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
250
|
+
width: 24,
|
|
251
|
+
height: 24,
|
|
252
|
+
viewBox: "0 0 24 24",
|
|
253
|
+
fill: "none",
|
|
254
|
+
stroke: "currentColor",
|
|
255
|
+
strokeWidth: 2,
|
|
256
|
+
strokeLinecap: "round",
|
|
257
|
+
strokeLinejoin: "round"
|
|
258
|
+
};
|
|
259
|
+
//#endregion
|
|
260
|
+
//#region ../../../node_modules/.pnpm/lucide-react@1.40.0_react@19.2.8/node_modules/lucide-react/dist/esm/shared/src/utils/hasA11yProp.mjs
|
|
261
|
+
/**
|
|
262
|
+
* @license lucide-react v1.40.0 - ISC
|
|
263
|
+
*
|
|
264
|
+
* This source code is licensed under the ISC license.
|
|
265
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
266
|
+
*/
|
|
267
|
+
var hasA11yProp = (props) => {
|
|
268
|
+
for (const prop in props) if (prop.startsWith("aria-") || prop === "role" || prop === "title") return true;
|
|
269
|
+
return false;
|
|
270
|
+
};
|
|
271
|
+
//#endregion
|
|
272
|
+
//#region ../../../node_modules/.pnpm/lucide-react@1.40.0_react@19.2.8/node_modules/lucide-react/dist/esm/context.mjs
|
|
273
|
+
/**
|
|
274
|
+
* @license lucide-react v1.40.0 - ISC
|
|
275
|
+
*
|
|
276
|
+
* This source code is licensed under the ISC license.
|
|
277
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
278
|
+
*/
|
|
279
|
+
var LucideContext = createContext({});
|
|
280
|
+
var useLucideContext = () => useContext(LucideContext);
|
|
281
|
+
//#endregion
|
|
282
|
+
//#region ../../../node_modules/.pnpm/lucide-react@1.40.0_react@19.2.8/node_modules/lucide-react/dist/esm/Icon.mjs
|
|
283
|
+
/**
|
|
284
|
+
* @license lucide-react v1.40.0 - ISC
|
|
285
|
+
*
|
|
286
|
+
* This source code is licensed under the ISC license.
|
|
287
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
288
|
+
*/
|
|
289
|
+
var Icon = forwardRef(({ color, size, strokeWidth, absoluteStrokeWidth, className = "", children, iconNode, ...rest }, ref) => {
|
|
290
|
+
const { size: contextSize = 24, strokeWidth: contextStrokeWidth = 2, absoluteStrokeWidth: contextAbsoluteStrokeWidth = false, color: contextColor = "currentColor", className: contextClass = "" } = useLucideContext() ?? {};
|
|
291
|
+
const calculatedStrokeWidth = absoluteStrokeWidth ?? contextAbsoluteStrokeWidth ? Number(strokeWidth ?? contextStrokeWidth) * 24 / Number(size ?? contextSize) : strokeWidth ?? contextStrokeWidth;
|
|
292
|
+
return createElement("svg", {
|
|
293
|
+
ref,
|
|
294
|
+
...defaultAttributes,
|
|
295
|
+
width: size ?? contextSize ?? defaultAttributes.width,
|
|
296
|
+
height: size ?? contextSize ?? defaultAttributes.height,
|
|
297
|
+
stroke: color ?? contextColor,
|
|
298
|
+
strokeWidth: calculatedStrokeWidth,
|
|
299
|
+
className: mergeClasses("lucide", contextClass, className),
|
|
300
|
+
...!children && !hasA11yProp(rest) && { "aria-hidden": "true" },
|
|
301
|
+
...rest
|
|
302
|
+
}, [...iconNode.map(([tag, attrs]) => createElement(tag, attrs)), ...Array.isArray(children) ? children : [children]]);
|
|
303
|
+
});
|
|
304
|
+
//#endregion
|
|
305
|
+
//#region ../../../node_modules/.pnpm/lucide-react@1.40.0_react@19.2.8/node_modules/lucide-react/dist/esm/createLucideIcon.mjs
|
|
306
|
+
/**
|
|
307
|
+
* @license lucide-react v1.40.0 - ISC
|
|
308
|
+
*
|
|
309
|
+
* This source code is licensed under the ISC license.
|
|
310
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
311
|
+
*/
|
|
312
|
+
var createLucideIcon = (iconName, iconNode) => {
|
|
313
|
+
const Component = forwardRef(({ className, ...props }, ref) => createElement(Icon, {
|
|
314
|
+
ref,
|
|
315
|
+
iconNode,
|
|
316
|
+
className: mergeClasses(`lucide-${toKebabCase(toPascalCase(iconName))}`, `lucide-${iconName}`, className),
|
|
317
|
+
...props
|
|
318
|
+
}));
|
|
319
|
+
Component.displayName = toPascalCase(iconName);
|
|
320
|
+
return Component;
|
|
321
|
+
};
|
|
322
|
+
/**
|
|
323
|
+
* @license lucide-react v1.40.0 - ISC
|
|
324
|
+
*
|
|
325
|
+
* This source code is licensed under the ISC license.
|
|
326
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
327
|
+
*/
|
|
328
|
+
var Keyboard = createLucideIcon("keyboard", [
|
|
329
|
+
["path", {
|
|
330
|
+
d: "M10 8h.01",
|
|
331
|
+
key: "1r9ogq"
|
|
332
|
+
}],
|
|
333
|
+
["path", {
|
|
334
|
+
d: "M12 12h.01",
|
|
335
|
+
key: "1mp3jc"
|
|
336
|
+
}],
|
|
337
|
+
["path", {
|
|
338
|
+
d: "M14 8h.01",
|
|
339
|
+
key: "1primd"
|
|
340
|
+
}],
|
|
341
|
+
["path", {
|
|
342
|
+
d: "M16 12h.01",
|
|
343
|
+
key: "1l6xoz"
|
|
344
|
+
}],
|
|
345
|
+
["path", {
|
|
346
|
+
d: "M18 8h.01",
|
|
347
|
+
key: "emo2bl"
|
|
348
|
+
}],
|
|
349
|
+
["path", {
|
|
350
|
+
d: "M6 8h.01",
|
|
351
|
+
key: "x9i8wu"
|
|
352
|
+
}],
|
|
353
|
+
["path", {
|
|
354
|
+
d: "M7 16h10",
|
|
355
|
+
key: "wp8him"
|
|
356
|
+
}],
|
|
357
|
+
["path", {
|
|
358
|
+
d: "M8 12h.01",
|
|
359
|
+
key: "czm47f"
|
|
360
|
+
}],
|
|
361
|
+
["rect", {
|
|
362
|
+
width: "20",
|
|
363
|
+
height: "16",
|
|
364
|
+
x: "2",
|
|
365
|
+
y: "4",
|
|
366
|
+
rx: "2",
|
|
367
|
+
key: "18n3k1"
|
|
368
|
+
}]
|
|
369
|
+
]);
|
|
370
|
+
/**
|
|
371
|
+
* @license lucide-react v1.40.0 - ISC
|
|
372
|
+
*
|
|
373
|
+
* This source code is licensed under the ISC license.
|
|
374
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
375
|
+
*/
|
|
376
|
+
var Pencil = createLucideIcon("pencil", [["path", {
|
|
377
|
+
d: "M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",
|
|
378
|
+
key: "1a8usu"
|
|
379
|
+
}], ["path", {
|
|
380
|
+
d: "m15 5 4 4",
|
|
381
|
+
key: "1mk7zo"
|
|
382
|
+
}]]);
|
|
383
|
+
/**
|
|
384
|
+
* @license lucide-react v1.40.0 - ISC
|
|
385
|
+
*
|
|
386
|
+
* This source code is licensed under the ISC license.
|
|
387
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
388
|
+
*/
|
|
389
|
+
var RotateCcw = createLucideIcon("rotate-ccw", [["path", {
|
|
390
|
+
d: "M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",
|
|
391
|
+
key: "1357e3"
|
|
392
|
+
}], ["path", {
|
|
393
|
+
d: "M3 3v5h5",
|
|
394
|
+
key: "1xhq8a"
|
|
395
|
+
}]]);
|
|
396
|
+
/**
|
|
397
|
+
* @license lucide-react v1.40.0 - ISC
|
|
398
|
+
*
|
|
399
|
+
* This source code is licensed under the ISC license.
|
|
400
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
401
|
+
*/
|
|
402
|
+
var X = createLucideIcon("x", [["path", {
|
|
403
|
+
d: "M18 6 6 18",
|
|
404
|
+
key: "1bl5f8"
|
|
405
|
+
}], ["path", {
|
|
406
|
+
d: "m6 6 12 12",
|
|
407
|
+
key: "d8bk6v"
|
|
408
|
+
}]]);
|
|
409
|
+
//#endregion
|
|
410
|
+
//#region ../../../node_modules/.pnpm/zustand@5.0.15_@types+react@19.2.18_react@19.2.8_use-sync-external-store@1.7.0_react@19.2.8_/node_modules/zustand/esm/vanilla.mjs
|
|
411
|
+
var createStoreImpl = (createState) => {
|
|
412
|
+
let state;
|
|
413
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
414
|
+
const setState = (partial, replace) => {
|
|
415
|
+
const nextState = typeof partial === "function" ? partial(state) : partial;
|
|
416
|
+
if (!Object.is(nextState, state)) {
|
|
417
|
+
const previousState = state;
|
|
418
|
+
state = (replace != null ? replace : typeof nextState !== "object" || nextState === null) ? nextState : Object.assign({}, state, nextState);
|
|
419
|
+
listeners.forEach((listener) => listener(state, previousState));
|
|
420
|
+
}
|
|
421
|
+
};
|
|
422
|
+
const getState = () => state;
|
|
423
|
+
const getInitialState = () => initialState;
|
|
424
|
+
const subscribe = (listener) => {
|
|
425
|
+
listeners.add(listener);
|
|
426
|
+
return () => listeners.delete(listener);
|
|
427
|
+
};
|
|
428
|
+
const api = {
|
|
429
|
+
setState,
|
|
430
|
+
getState,
|
|
431
|
+
getInitialState,
|
|
432
|
+
subscribe
|
|
433
|
+
};
|
|
434
|
+
const initialState = state = createState(setState, getState, api);
|
|
435
|
+
return api;
|
|
436
|
+
};
|
|
437
|
+
var createStore = ((createState) => createState ? createStoreImpl(createState) : createStoreImpl);
|
|
438
|
+
//#endregion
|
|
439
|
+
//#region ../../../node_modules/.pnpm/zustand@5.0.15_@types+react@19.2.18_react@19.2.8_use-sync-external-store@1.7.0_react@19.2.8_/node_modules/zustand/esm/react.mjs
|
|
440
|
+
var identity = (arg) => arg;
|
|
441
|
+
function useStore(api, selector = identity) {
|
|
442
|
+
const slice = React.useSyncExternalStore(api.subscribe, React.useCallback(() => selector(api.getState()), [api, selector]), React.useCallback(() => selector(api.getInitialState()), [api, selector]));
|
|
443
|
+
React.useDebugValue(slice);
|
|
444
|
+
return slice;
|
|
445
|
+
}
|
|
446
|
+
var createImpl = (createState) => {
|
|
447
|
+
const api = createStore(createState);
|
|
448
|
+
const useBoundStore = (selector) => useStore(api, selector);
|
|
449
|
+
Object.assign(useBoundStore, api);
|
|
450
|
+
return useBoundStore;
|
|
451
|
+
};
|
|
452
|
+
var create = ((createState) => createState ? createImpl(createState) : createImpl);
|
|
453
|
+
//#endregion
|
|
454
|
+
//#region ui-src/lib/desktop-presence.ts
|
|
455
|
+
var host = null;
|
|
456
|
+
var problemOf = (error) => {
|
|
457
|
+
if (typeof error === "object" && error !== null && "code" in error && typeof error.code === "string") return error.code;
|
|
458
|
+
return error instanceof Error ? error.message : "Desktop operation failed";
|
|
459
|
+
};
|
|
460
|
+
/** Observed native state for Settings, independent of gateway connectivity. */
|
|
461
|
+
var useDesktopPresence = create()((set, get) => ({
|
|
462
|
+
available: false,
|
|
463
|
+
state: null,
|
|
464
|
+
pending: false,
|
|
465
|
+
lastProblem: null,
|
|
466
|
+
eventProblem: null,
|
|
467
|
+
async refresh() {
|
|
468
|
+
const target = host;
|
|
469
|
+
if (!target || get().pending) return;
|
|
470
|
+
set({ pending: true });
|
|
471
|
+
try {
|
|
472
|
+
const state = await target.read();
|
|
473
|
+
if (target === host) {
|
|
474
|
+
notifyDesktopPresenceChanged(state, target);
|
|
475
|
+
set({ lastProblem: get().eventProblem });
|
|
476
|
+
}
|
|
477
|
+
} catch (error) {
|
|
478
|
+
if (target === host) set({ lastProblem: problemOf(error) });
|
|
479
|
+
} finally {
|
|
480
|
+
if (target === host) set({ pending: false });
|
|
481
|
+
}
|
|
482
|
+
},
|
|
483
|
+
async writeShortcut(shortcut) {
|
|
484
|
+
const target = host;
|
|
485
|
+
if (!target || get().pending) return;
|
|
486
|
+
set({
|
|
487
|
+
pending: true,
|
|
488
|
+
lastProblem: get().eventProblem
|
|
489
|
+
});
|
|
490
|
+
try {
|
|
491
|
+
const state = await target.writeShortcut(shortcut);
|
|
492
|
+
if (target === host) notifyDesktopPresenceChanged(state, target);
|
|
493
|
+
} catch (error) {
|
|
494
|
+
if (target !== host) return;
|
|
495
|
+
set({ lastProblem: problemOf(error) });
|
|
496
|
+
try {
|
|
497
|
+
const state = await target.read();
|
|
498
|
+
if (target === host) notifyDesktopPresenceChanged(state, target);
|
|
499
|
+
} catch {}
|
|
500
|
+
} finally {
|
|
501
|
+
if (target === host) set({ pending: false });
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
}));
|
|
505
|
+
/** Installs the optional native port and returns its synchronous withdrawal. */
|
|
506
|
+
function installDesktopPresenceHost(next) {
|
|
507
|
+
host = next;
|
|
508
|
+
useDesktopPresence.setState({
|
|
509
|
+
available: true,
|
|
510
|
+
state: null,
|
|
511
|
+
pending: false,
|
|
512
|
+
lastProblem: null,
|
|
513
|
+
eventProblem: null
|
|
514
|
+
});
|
|
515
|
+
return () => {
|
|
516
|
+
if (host !== next) return;
|
|
517
|
+
host = null;
|
|
518
|
+
useDesktopPresence.setState({
|
|
519
|
+
available: false,
|
|
520
|
+
state: null,
|
|
521
|
+
pending: false,
|
|
522
|
+
lastProblem: null,
|
|
523
|
+
eventProblem: null
|
|
524
|
+
});
|
|
525
|
+
useKeybindings.getState().setGlobalShortcut(null);
|
|
526
|
+
};
|
|
527
|
+
}
|
|
528
|
+
/** Applies observed state only for the installing host, including the effective reservation. */
|
|
529
|
+
function notifyDesktopPresenceChanged(state, expectedHost) {
|
|
530
|
+
if (!host || expectedHost !== void 0 && expectedHost !== host) return;
|
|
531
|
+
useDesktopPresence.setState({ state });
|
|
532
|
+
useKeybindings.getState().setGlobalShortcut(state.effectiveShortcut);
|
|
533
|
+
}
|
|
534
|
+
var recordings = /* @__PURE__ */ new WeakMap();
|
|
535
|
+
/** Acquires a shared recording pause. Late acknowledgements are resumed after the last release. */
|
|
536
|
+
function acquireDesktopRecording() {
|
|
537
|
+
const target = host;
|
|
538
|
+
if (!target) return {
|
|
539
|
+
ready: Promise.resolve(),
|
|
540
|
+
release() {}
|
|
541
|
+
};
|
|
542
|
+
let recording = recordings.get(target);
|
|
543
|
+
if (!recording) {
|
|
544
|
+
recording = {
|
|
545
|
+
count: 0,
|
|
546
|
+
queue: Promise.resolve(),
|
|
547
|
+
pause: Promise.resolve()
|
|
548
|
+
};
|
|
549
|
+
recordings.set(target, recording);
|
|
550
|
+
}
|
|
551
|
+
const state = recording;
|
|
552
|
+
if (state.count === 0) {
|
|
553
|
+
state.pause = state.queue.then(() => target.setRecording(true));
|
|
554
|
+
state.queue = state.pause.catch(() => {});
|
|
555
|
+
}
|
|
556
|
+
state.count++;
|
|
557
|
+
let released = false;
|
|
558
|
+
return {
|
|
559
|
+
ready: state.pause,
|
|
560
|
+
release() {
|
|
561
|
+
if (released) return;
|
|
562
|
+
released = true;
|
|
563
|
+
state.count--;
|
|
564
|
+
if (state.count !== 0) return;
|
|
565
|
+
state.queue = state.queue.then(() => target.setRecording(false)).catch((error) => {
|
|
566
|
+
if (host === target) useDesktopPresence.setState({ lastProblem: problemOf(error) });
|
|
567
|
+
});
|
|
568
|
+
}
|
|
569
|
+
};
|
|
570
|
+
}
|
|
571
|
+
/** Waits for the native pause before accepting presses and releases it on blur or unmount. */
|
|
572
|
+
function useDesktopRecording(active, onExit) {
|
|
573
|
+
const exit = useRef(onExit);
|
|
574
|
+
exit.current = onExit;
|
|
575
|
+
const [ready, setReady] = useState(host === null);
|
|
576
|
+
useEffect(() => {
|
|
577
|
+
if (!active) return;
|
|
578
|
+
const lease = acquireDesktopRecording();
|
|
579
|
+
let alive = true;
|
|
580
|
+
setReady(host === null);
|
|
581
|
+
lease.ready.then(() => {
|
|
582
|
+
if (alive) setReady(true);
|
|
583
|
+
}, (error) => {
|
|
584
|
+
if (!alive) return;
|
|
585
|
+
useDesktopPresence.setState({ lastProblem: problemOf(error) });
|
|
586
|
+
exit.current();
|
|
587
|
+
});
|
|
588
|
+
const blur = () => {
|
|
589
|
+
lease.release();
|
|
590
|
+
exit.current();
|
|
591
|
+
};
|
|
592
|
+
window.addEventListener("blur", blur);
|
|
593
|
+
return () => {
|
|
594
|
+
alive = false;
|
|
595
|
+
lease.release();
|
|
596
|
+
window.removeEventListener("blur", blur);
|
|
597
|
+
};
|
|
598
|
+
}, [active]);
|
|
599
|
+
return ready;
|
|
600
|
+
}
|
|
601
|
+
//#endregion
|
|
602
|
+
//#region ui-src/components/settings/keybindings/recorder.tsx
|
|
603
|
+
/** How many of the client's reserved chords the standing line names. */
|
|
604
|
+
var NAMED_RESERVED = 4;
|
|
605
|
+
/** Why `chord` cannot be recorded, or `null`. A reserved press the grammar
|
|
606
|
+
* has no key for (`Mod+Tab`) still reads as reserved, which is what the
|
|
607
|
+
* person needs to hear about it. */
|
|
608
|
+
function refusalOf(chord, reserved) {
|
|
609
|
+
if (EDITING_RESERVED.includes(chord) || reserved.includes(chord)) return "reserved";
|
|
610
|
+
return chordRefusal(chord, reserved);
|
|
611
|
+
}
|
|
612
|
+
/** Whether a press is `key` with no modifier held. */
|
|
613
|
+
function isPlain(event, key) {
|
|
614
|
+
return event.key === key && !event.metaKey && !event.ctrlKey && !event.altKey && !event.shiftKey;
|
|
615
|
+
}
|
|
616
|
+
/** Whether a press is plain Tab or Shift+Tab: focus moving on, which a
|
|
617
|
+
* capture field leaves to the browser. */
|
|
618
|
+
function isFocusMove(event) {
|
|
619
|
+
return event.key === "Tab" && !event.metaKey && !event.ctrlKey && !event.altKey;
|
|
620
|
+
}
|
|
621
|
+
function Recorder({ label, platform, reserved, scope, holderOf, onSave, onReplace, onCancel, initialChord = null, initialNotice = null, autoFocus = true }) {
|
|
622
|
+
const { t } = useTranslation$1();
|
|
623
|
+
const ready = useDesktopRecording(true, onCancel);
|
|
624
|
+
const hint = useId();
|
|
625
|
+
const field = useRef(null);
|
|
626
|
+
const [chord, setChord] = useState(initialChord);
|
|
627
|
+
const [notice, setNotice] = useState(initialNotice);
|
|
628
|
+
useEffect(() => {
|
|
629
|
+
if (autoFocus) field.current?.focus();
|
|
630
|
+
}, [autoFocus]);
|
|
631
|
+
function commit(next) {
|
|
632
|
+
const refusal = refusalOf(next, reserved);
|
|
633
|
+
if (refusal !== null) {
|
|
634
|
+
setNotice({
|
|
635
|
+
kind: "invalid",
|
|
636
|
+
chord: next,
|
|
637
|
+
refusal
|
|
638
|
+
});
|
|
639
|
+
return;
|
|
640
|
+
}
|
|
641
|
+
const holder = holderOf(next);
|
|
642
|
+
if (holder !== null) {
|
|
643
|
+
setNotice({
|
|
644
|
+
kind: "taken",
|
|
645
|
+
chord: next,
|
|
646
|
+
holder
|
|
647
|
+
});
|
|
648
|
+
return;
|
|
649
|
+
}
|
|
650
|
+
onSave(next);
|
|
651
|
+
}
|
|
652
|
+
function onKeyDown(event) {
|
|
653
|
+
event.stopPropagation();
|
|
654
|
+
if (isFocusMove(event)) return;
|
|
655
|
+
event.preventDefault();
|
|
656
|
+
if (!ready || event.nativeEvent.isComposing || event.repeat) return;
|
|
657
|
+
if (isPlain(event, "Escape")) {
|
|
658
|
+
onCancel();
|
|
659
|
+
return;
|
|
660
|
+
}
|
|
661
|
+
if (isPlain(event, "Enter")) {
|
|
662
|
+
if (chord !== null) commit(chord);
|
|
663
|
+
return;
|
|
664
|
+
}
|
|
665
|
+
const next = fromEvent(event.nativeEvent, platform);
|
|
666
|
+
if (next === null) return;
|
|
667
|
+
setChord(next);
|
|
668
|
+
setNotice(null);
|
|
669
|
+
}
|
|
670
|
+
const named = (reserved.length > 0 ? reserved : EDITING_RESERVED).slice(0, NAMED_RESERVED).map((one) => formatChord(one, platform)).join(" ");
|
|
671
|
+
return /* @__PURE__ */ jsxs("fieldset", {
|
|
672
|
+
"aria-label": t("keybindings.recorderName", { label }),
|
|
673
|
+
"data-slot": "keybinding-recorder",
|
|
674
|
+
className: "flex min-w-0 flex-col gap-2",
|
|
675
|
+
onBlur: (event) => {
|
|
676
|
+
if (!event.currentTarget.contains(event.relatedTarget)) onCancel();
|
|
677
|
+
},
|
|
678
|
+
children: [
|
|
679
|
+
/* @__PURE__ */ jsxs("div", {
|
|
680
|
+
className: "flex flex-wrap items-center gap-3",
|
|
681
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
682
|
+
ref: field,
|
|
683
|
+
role: "textbox",
|
|
684
|
+
tabIndex: 0,
|
|
685
|
+
"aria-readonly": "true",
|
|
686
|
+
"aria-disabled": !ready,
|
|
687
|
+
"aria-label": t("keybindings.recorderName", { label }),
|
|
688
|
+
"aria-describedby": hint,
|
|
689
|
+
"aria-invalid": notice?.kind === "invalid" || void 0,
|
|
690
|
+
onKeyDown,
|
|
691
|
+
className: cn("flex h-8 min-w-40 items-center rounded-control border border-ring bg-input/30 px-2 text-sm outline-none ring-3 ring-ring/20", notice?.kind === "invalid" && "border-warning ring-warning/20"),
|
|
692
|
+
children: chord === null ? /* @__PURE__ */ jsx("span", {
|
|
693
|
+
className: "text-placeholder",
|
|
694
|
+
children: t(ready ? "keybindings.recording" : "presence.pausing")
|
|
695
|
+
}) : /* @__PURE__ */ jsx(KeyCaps, {
|
|
696
|
+
chord,
|
|
697
|
+
platform
|
|
698
|
+
})
|
|
699
|
+
}), /* @__PURE__ */ jsx("p", {
|
|
700
|
+
id: hint,
|
|
701
|
+
className: "min-w-0 flex-1 text-xs text-muted-foreground",
|
|
702
|
+
children: t("keybindings.recordingHint")
|
|
703
|
+
})]
|
|
704
|
+
}),
|
|
705
|
+
notice?.kind === "invalid" && /* @__PURE__ */ jsx(Alert, {
|
|
706
|
+
tone: "warning",
|
|
707
|
+
role: "status",
|
|
708
|
+
className: "py-2 text-xs",
|
|
709
|
+
children: notice.refusal === "grammar" ? t("keybindings.invalidGrammar", {
|
|
710
|
+
mod: platform === "mac" ? "⌘" : "Ctrl",
|
|
711
|
+
alt: platform === "mac" ? "⌥" : "Alt"
|
|
712
|
+
}) : t("keybindings.invalidReserved", { keys: formatChord(notice.chord, platform) })
|
|
713
|
+
}),
|
|
714
|
+
notice?.kind === "taken" && /* @__PURE__ */ jsx(Alert, {
|
|
715
|
+
tone: "destructive",
|
|
716
|
+
role: "alert",
|
|
717
|
+
className: "py-2 text-xs",
|
|
718
|
+
children: /* @__PURE__ */ jsxs("span", {
|
|
719
|
+
className: "flex flex-wrap items-start justify-between gap-x-4 gap-y-2",
|
|
720
|
+
children: [/* @__PURE__ */ jsx("span", { children: t("keybindings.taken", {
|
|
721
|
+
keys: formatChord(notice.chord, platform),
|
|
722
|
+
label: notice.holder.label,
|
|
723
|
+
source: notice.holder.source
|
|
724
|
+
}) }), /* @__PURE__ */ jsxs("span", {
|
|
725
|
+
className: "flex items-center gap-2",
|
|
726
|
+
children: [/* @__PURE__ */ jsx(Button, {
|
|
727
|
+
variant: "destructive",
|
|
728
|
+
size: "sm",
|
|
729
|
+
type: "button",
|
|
730
|
+
onClick: () => onReplace(notice.chord, notice.holder.key),
|
|
731
|
+
children: t("keybindings.replace")
|
|
732
|
+
}), /* @__PURE__ */ jsx(Button, {
|
|
733
|
+
variant: "secondary",
|
|
734
|
+
size: "sm",
|
|
735
|
+
type: "button",
|
|
736
|
+
onClick: () => {
|
|
737
|
+
setNotice(null);
|
|
738
|
+
setChord(null);
|
|
739
|
+
field.current?.focus();
|
|
740
|
+
},
|
|
741
|
+
children: t("keybindings.cancel")
|
|
742
|
+
})]
|
|
743
|
+
})]
|
|
744
|
+
})
|
|
745
|
+
}),
|
|
746
|
+
/* @__PURE__ */ jsx("p", {
|
|
747
|
+
className: "text-xs text-muted-foreground",
|
|
748
|
+
children: t(scope === "browser" ? "keybindings.reservedBrowser" : "keybindings.reservedDevice", { keys: named })
|
|
749
|
+
})
|
|
750
|
+
]
|
|
751
|
+
});
|
|
752
|
+
}
|
|
753
|
+
//#endregion
|
|
754
|
+
//#region ui-src/components/settings/keybindings/desktop-presence.tsx
|
|
755
|
+
/** Native window controls keep desired settings separate from actual registrations. */
|
|
756
|
+
function DesktopPresenceSection({ platform }) {
|
|
757
|
+
const { t } = useTranslation$1();
|
|
758
|
+
const { available, state, pending, lastProblem, refresh, writeShortcut } = useDesktopPresence();
|
|
759
|
+
const problemKey = (() => {
|
|
760
|
+
switch (lastProblem) {
|
|
761
|
+
case "shortcut-conflict": return "presence.problems.shortcutConflict";
|
|
762
|
+
case "preferences-read": return "presence.problems.preferencesRead";
|
|
763
|
+
case "preferences-write": return "presence.problems.preferencesWrite";
|
|
764
|
+
case "window-action": return "presence.problems.windowAction";
|
|
765
|
+
default: return "presence.problem";
|
|
766
|
+
}
|
|
767
|
+
})();
|
|
768
|
+
const reserved = useKeybindings((value) => value.reserved);
|
|
769
|
+
const [recording, setRecording] = useState(false);
|
|
770
|
+
if (!available) return null;
|
|
771
|
+
const shown = (shortcut) => shortcut ? /* @__PURE__ */ jsx(KeyCaps, {
|
|
772
|
+
chord: shortcut,
|
|
773
|
+
platform
|
|
774
|
+
}) : t("presence.none");
|
|
775
|
+
const write = (shortcut) => {
|
|
776
|
+
setRecording(false);
|
|
777
|
+
writeShortcut(shortcut);
|
|
778
|
+
};
|
|
779
|
+
return /* @__PURE__ */ jsxs(Panel, {
|
|
780
|
+
title: t("presence.title"),
|
|
781
|
+
hint: t("presence.hint"),
|
|
782
|
+
children: [
|
|
783
|
+
/* @__PURE__ */ jsxs("dl", {
|
|
784
|
+
className: "grid grid-cols-[auto_1fr] gap-x-4 gap-y-2",
|
|
785
|
+
children: [
|
|
786
|
+
/* @__PURE__ */ jsx("dt", { children: t("presence.desired") }),
|
|
787
|
+
/* @__PURE__ */ jsx("dd", { children: /* @__PURE__ */ jsx("output", {
|
|
788
|
+
"aria-label": t("presence.desired"),
|
|
789
|
+
children: shown(state?.windowShortcut)
|
|
790
|
+
}) }),
|
|
791
|
+
/* @__PURE__ */ jsx("dt", { children: t("presence.effective") }),
|
|
792
|
+
/* @__PURE__ */ jsx("dd", { children: /* @__PURE__ */ jsx("output", {
|
|
793
|
+
"aria-label": t("presence.effective"),
|
|
794
|
+
children: shown(state?.effectiveShortcut)
|
|
795
|
+
}) }),
|
|
796
|
+
/* @__PURE__ */ jsx("dt", { children: t("presence.registered") }),
|
|
797
|
+
/* @__PURE__ */ jsx("dd", { children: /* @__PURE__ */ jsx("output", {
|
|
798
|
+
"aria-label": t("presence.registered"),
|
|
799
|
+
className: "flex flex-wrap gap-2",
|
|
800
|
+
children: state?.registeredShortcuts.length ? state.registeredShortcuts.map((shortcut) => /* @__PURE__ */ jsx(KeyCaps, {
|
|
801
|
+
chord: shortcut,
|
|
802
|
+
platform
|
|
803
|
+
}, shortcut)) : t("presence.none")
|
|
804
|
+
}) })
|
|
805
|
+
]
|
|
806
|
+
}),
|
|
807
|
+
/* @__PURE__ */ jsx("p", {
|
|
808
|
+
className: "text-xs text-muted-foreground",
|
|
809
|
+
children: t(state?.trayAvailable ? "presence.tray" : "presence.trayMissing")
|
|
810
|
+
}),
|
|
811
|
+
state?.shortcutProblem && /* @__PURE__ */ jsx(Alert, {
|
|
812
|
+
tone: "warning",
|
|
813
|
+
role: "status",
|
|
814
|
+
children: t("presence.problems.state")
|
|
815
|
+
}),
|
|
816
|
+
lastProblem && /* @__PURE__ */ jsx(Alert, {
|
|
817
|
+
tone: "destructive",
|
|
818
|
+
role: "alert",
|
|
819
|
+
children: t(problemKey)
|
|
820
|
+
}),
|
|
821
|
+
/* @__PURE__ */ jsxs("div", {
|
|
822
|
+
className: "flex flex-wrap gap-2",
|
|
823
|
+
children: [
|
|
824
|
+
/* @__PURE__ */ jsx(Button, {
|
|
825
|
+
type: "button",
|
|
826
|
+
variant: "secondary",
|
|
827
|
+
size: "sm",
|
|
828
|
+
disabled: pending || recording,
|
|
829
|
+
onClick: () => setRecording(true),
|
|
830
|
+
children: t("presence.change")
|
|
831
|
+
}),
|
|
832
|
+
/* @__PURE__ */ jsx(Button, {
|
|
833
|
+
type: "button",
|
|
834
|
+
variant: "secondary",
|
|
835
|
+
size: "sm",
|
|
836
|
+
disabled: pending || recording,
|
|
837
|
+
onClick: () => write(null),
|
|
838
|
+
children: t("presence.disable")
|
|
839
|
+
}),
|
|
840
|
+
/* @__PURE__ */ jsx(Button, {
|
|
841
|
+
type: "button",
|
|
842
|
+
variant: "secondary",
|
|
843
|
+
size: "sm",
|
|
844
|
+
disabled: pending || recording,
|
|
845
|
+
onClick: () => write("Alt+Backquote"),
|
|
846
|
+
children: t("presence.default")
|
|
847
|
+
}),
|
|
848
|
+
/* @__PURE__ */ jsx(Button, {
|
|
849
|
+
type: "button",
|
|
850
|
+
variant: "ghost",
|
|
851
|
+
size: "sm",
|
|
852
|
+
disabled: pending || recording,
|
|
853
|
+
onClick: () => void refresh(),
|
|
854
|
+
children: t("presence.refresh")
|
|
855
|
+
})
|
|
856
|
+
]
|
|
857
|
+
}),
|
|
858
|
+
recording && /* @__PURE__ */ jsx(Recorder, {
|
|
859
|
+
label: t("presence.record"),
|
|
860
|
+
platform,
|
|
861
|
+
reserved,
|
|
862
|
+
scope: "device",
|
|
863
|
+
holderOf: () => null,
|
|
864
|
+
onSave: write,
|
|
865
|
+
onReplace: write,
|
|
866
|
+
onCancel: () => setRecording(false)
|
|
867
|
+
})
|
|
868
|
+
]
|
|
869
|
+
});
|
|
870
|
+
}
|
|
871
|
+
//#endregion
|
|
872
|
+
//#region ui-src/components/settings/keybindings/row.tsx
|
|
873
|
+
/** The line under the name, or `null` when the row is on its default. */
|
|
874
|
+
function useNote(model, platform) {
|
|
875
|
+
const { t } = useTranslation$1();
|
|
876
|
+
const { state, modified, defaultKeys } = model;
|
|
877
|
+
const usableDefault = defaultKeys !== void 0 && CHORD.test(defaultKeys) ? formatChord(defaultKeys, platform) : null;
|
|
878
|
+
if (state.kind === "conflict" && state.with === GLOBAL_WINDOW_BINDING) return t("keybindings.noteGlobalWindow");
|
|
879
|
+
if (state.kind === "conflict" && model.holder) return t("keybindings.noteConflict", {
|
|
880
|
+
label: model.holder.label,
|
|
881
|
+
source: model.holder.source
|
|
882
|
+
});
|
|
883
|
+
if (state.kind === "unbound" && state.reason === "invalid" && !modified) return t("keybindings.noteInvalid", { keys: defaultKeys ?? "" });
|
|
884
|
+
if (!modified || usableDefault === null) return null;
|
|
885
|
+
return state.kind === "unbound" ? t("keybindings.noteRemoved", { keys: usableDefault }) : t("keybindings.noteDefault", { keys: usableDefault });
|
|
886
|
+
}
|
|
887
|
+
function StateBadge({ model }) {
|
|
888
|
+
const { t } = useTranslation$1();
|
|
889
|
+
if (model.state.kind === "conflict") return /* @__PURE__ */ jsx(Badge, {
|
|
890
|
+
tone: "destructive",
|
|
891
|
+
size: "sm",
|
|
892
|
+
children: t("keybindings.stateConflict")
|
|
893
|
+
});
|
|
894
|
+
if (model.state.kind === "unbound") return /* @__PURE__ */ jsx(Badge, {
|
|
895
|
+
size: "sm",
|
|
896
|
+
children: t("keybindings.stateUnbound")
|
|
897
|
+
});
|
|
898
|
+
if (model.modified) return /* @__PURE__ */ jsx(Badge, {
|
|
899
|
+
tone: "primary",
|
|
900
|
+
size: "sm",
|
|
901
|
+
children: t("keybindings.stateModified")
|
|
902
|
+
});
|
|
903
|
+
return null;
|
|
904
|
+
}
|
|
905
|
+
/** An icon-only action: named for a screen reader and shown by a tooltip. */
|
|
906
|
+
function RowAction({ label, onClick, children, buttonRef }) {
|
|
907
|
+
return /* @__PURE__ */ jsxs(Tooltip, { children: [/* @__PURE__ */ jsx(TooltipTrigger, {
|
|
908
|
+
"aria-label": label,
|
|
909
|
+
render: /* @__PURE__ */ jsx(Button, {
|
|
910
|
+
ref: buttonRef,
|
|
911
|
+
variant: "ghost",
|
|
912
|
+
size: "sm",
|
|
913
|
+
type: "button",
|
|
914
|
+
onClick,
|
|
915
|
+
className: "aspect-square px-0 text-muted-foreground hover:text-foreground"
|
|
916
|
+
}),
|
|
917
|
+
children
|
|
918
|
+
}), /* @__PURE__ */ jsx(TooltipContent, {
|
|
919
|
+
side: "top",
|
|
920
|
+
sideOffset: 6,
|
|
921
|
+
children: label
|
|
922
|
+
})] });
|
|
923
|
+
}
|
|
924
|
+
/** The table the rows sit in: its name and its five columns. */
|
|
925
|
+
function KeybindingTable({ children }) {
|
|
926
|
+
const { t } = useTranslation$1();
|
|
927
|
+
return /* @__PURE__ */ jsxs(Table, {
|
|
928
|
+
"aria-label": t("keybindings.table"),
|
|
929
|
+
className: "table-fixed",
|
|
930
|
+
children: [/* @__PURE__ */ jsx(TableHeader, { children: /* @__PURE__ */ jsxs(TableRow, {
|
|
931
|
+
className: "hover:bg-transparent",
|
|
932
|
+
children: [
|
|
933
|
+
/* @__PURE__ */ jsx(TableHead, { children: t("keybindings.columnAction") }),
|
|
934
|
+
/* @__PURE__ */ jsx(TableHead, {
|
|
935
|
+
className: "w-28",
|
|
936
|
+
children: t("keybindings.columnSource")
|
|
937
|
+
}),
|
|
938
|
+
/* @__PURE__ */ jsx(TableHead, {
|
|
939
|
+
className: "w-32",
|
|
940
|
+
children: t("keybindings.columnKeys")
|
|
941
|
+
}),
|
|
942
|
+
/* @__PURE__ */ jsx(TableHead, {
|
|
943
|
+
className: "w-20",
|
|
944
|
+
children: t("keybindings.columnState")
|
|
945
|
+
}),
|
|
946
|
+
/* @__PURE__ */ jsx(TableHead, {
|
|
947
|
+
className: "w-24",
|
|
948
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
949
|
+
className: "sr-only",
|
|
950
|
+
children: t("keybindings.edit")
|
|
951
|
+
})
|
|
952
|
+
})
|
|
953
|
+
]
|
|
954
|
+
}) }), /* @__PURE__ */ jsx(TableBody, { children })]
|
|
955
|
+
});
|
|
956
|
+
}
|
|
957
|
+
function KeybindingRow({ model, platform, onEdit, onReset, onRemove, editRef, below }) {
|
|
958
|
+
const { t } = useTranslation$1();
|
|
959
|
+
const note = useNote(model, platform);
|
|
960
|
+
const { state } = model;
|
|
961
|
+
const keys = state.kind === "unbound" ? null : state.keys;
|
|
962
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs(TableRow, {
|
|
963
|
+
"data-slot": "keybinding-row",
|
|
964
|
+
"data-key": model.key,
|
|
965
|
+
className: "group",
|
|
966
|
+
children: [
|
|
967
|
+
/* @__PURE__ */ jsxs(TableCell, {
|
|
968
|
+
className: "min-w-0",
|
|
969
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
970
|
+
"data-slot": "keybinding-label",
|
|
971
|
+
className: "block [overflow-wrap:anywhere]",
|
|
972
|
+
children: model.label
|
|
973
|
+
}), note !== null && /* @__PURE__ */ jsx("span", {
|
|
974
|
+
"data-slot": "keybinding-note",
|
|
975
|
+
className: state.kind === "conflict" ? "mt-0.5 block text-xs text-destructive" : "mt-0.5 block text-xs text-muted-foreground",
|
|
976
|
+
children: note
|
|
977
|
+
})]
|
|
978
|
+
}),
|
|
979
|
+
/* @__PURE__ */ jsx(TableCell, {
|
|
980
|
+
className: "text-xs text-muted-foreground [overflow-wrap:anywhere]",
|
|
981
|
+
children: model.source
|
|
982
|
+
}),
|
|
983
|
+
/* @__PURE__ */ jsx(TableCell, { children: keys === null ? /* @__PURE__ */ jsx("span", {
|
|
984
|
+
className: "text-muted-foreground",
|
|
985
|
+
children: "—"
|
|
986
|
+
}) : /* @__PURE__ */ jsx(KeyCaps, {
|
|
987
|
+
chord: keys,
|
|
988
|
+
platform,
|
|
989
|
+
tone: state.kind === "conflict" ? "conflict" : "default"
|
|
990
|
+
}) }),
|
|
991
|
+
/* @__PURE__ */ jsx(TableCell, { children: /* @__PURE__ */ jsx(StateBadge, { model }) }),
|
|
992
|
+
/* @__PURE__ */ jsx(TableCell, {
|
|
993
|
+
className: "w-0 whitespace-nowrap",
|
|
994
|
+
children: /* @__PURE__ */ jsxs("span", {
|
|
995
|
+
className: "flex items-center justify-end gap-0.5 opacity-0 transition-opacity duration-150 group-focus-within:opacity-100 group-hover:opacity-100 [@media(hover:none)]:opacity-100",
|
|
996
|
+
children: [
|
|
997
|
+
/* @__PURE__ */ jsx(RowAction, {
|
|
998
|
+
label: t("keybindings.edit"),
|
|
999
|
+
onClick: onEdit,
|
|
1000
|
+
buttonRef: editRef,
|
|
1001
|
+
children: /* @__PURE__ */ jsx(Pencil, {
|
|
1002
|
+
"aria-hidden": "true",
|
|
1003
|
+
className: "size-3.5",
|
|
1004
|
+
strokeWidth: 1.75
|
|
1005
|
+
})
|
|
1006
|
+
}),
|
|
1007
|
+
model.modified && /* @__PURE__ */ jsx(RowAction, {
|
|
1008
|
+
label: t("keybindings.reset"),
|
|
1009
|
+
onClick: onReset,
|
|
1010
|
+
children: /* @__PURE__ */ jsx(RotateCcw, {
|
|
1011
|
+
"aria-hidden": "true",
|
|
1012
|
+
className: "size-3.5",
|
|
1013
|
+
strokeWidth: 1.75
|
|
1014
|
+
})
|
|
1015
|
+
}),
|
|
1016
|
+
keys !== null && /* @__PURE__ */ jsx(RowAction, {
|
|
1017
|
+
label: t("keybindings.remove"),
|
|
1018
|
+
onClick: onRemove,
|
|
1019
|
+
children: /* @__PURE__ */ jsx(X, {
|
|
1020
|
+
"aria-hidden": "true",
|
|
1021
|
+
className: "size-3.5",
|
|
1022
|
+
strokeWidth: 1.75
|
|
1023
|
+
})
|
|
1024
|
+
})
|
|
1025
|
+
]
|
|
1026
|
+
})
|
|
1027
|
+
})
|
|
1028
|
+
]
|
|
1029
|
+
}), below !== void 0 && /* @__PURE__ */ jsx(TableRow, {
|
|
1030
|
+
"data-slot": "keybinding-recording",
|
|
1031
|
+
className: "hover:bg-transparent",
|
|
1032
|
+
children: /* @__PURE__ */ jsx(TableCell, {
|
|
1033
|
+
colSpan: 5,
|
|
1034
|
+
className: "pt-0",
|
|
1035
|
+
children: below
|
|
1036
|
+
})
|
|
1037
|
+
})] });
|
|
1038
|
+
}
|
|
1039
|
+
//#endregion
|
|
1040
|
+
//#region ui-src/components/settings/keybindings/keybindings.tsx
|
|
1041
|
+
/**
|
|
1042
|
+
* Settings › Keyboard shortcuts: every binding the host and the loaded
|
|
1043
|
+
* plugins registered, what it is bound to right now, and the person's
|
|
1044
|
+
* changes to it.
|
|
1045
|
+
*
|
|
1046
|
+
* Everything shown is derived: the rows and their states come from
|
|
1047
|
+
* `useKeybindingRows`, which resolves the registrations against the stored
|
|
1048
|
+
* changes, and the only thing this panel writes is a change through
|
|
1049
|
+
* `useKeybindings`. The dispatcher reads the same resolution on every press,
|
|
1050
|
+
* so a saved change is in effect before this panel re-renders.
|
|
1051
|
+
*/
|
|
1052
|
+
function useModels() {
|
|
1053
|
+
const { t } = useTranslation$1();
|
|
1054
|
+
const { rows, resolution } = useKeybindingRows();
|
|
1055
|
+
const nameOf = (row) => ({
|
|
1056
|
+
label: resolveLabel(row.registration.contribution.label, row.registration.contribution.id),
|
|
1057
|
+
source: row.registration.plugin === HOST_OWNER ? t("keybindings.sourceHost") : row.registration.plugin
|
|
1058
|
+
});
|
|
1059
|
+
const names = new Map(rows.map((row) => [row.registration.key, nameOf(row)]));
|
|
1060
|
+
return {
|
|
1061
|
+
models: rows.map((row) => ({
|
|
1062
|
+
key: row.registration.key,
|
|
1063
|
+
...names.get(row.registration.key),
|
|
1064
|
+
state: row.state,
|
|
1065
|
+
modified: row.modified,
|
|
1066
|
+
defaultKeys: row.registration.contribution.defaultKeys,
|
|
1067
|
+
holder: row.state.kind === "conflict" ? names.get(row.state.with) : void 0
|
|
1068
|
+
})),
|
|
1069
|
+
byChord: resolution.byChord
|
|
1070
|
+
};
|
|
1071
|
+
}
|
|
1072
|
+
/** The search field and its two modes: text against the name and source,
|
|
1073
|
+
* or a press whose chord the rows are filtered by. */
|
|
1074
|
+
function SearchField({ platform, query, onQuery, keys, onKeys }) {
|
|
1075
|
+
const { t } = useTranslation$1();
|
|
1076
|
+
const field = useRef(null);
|
|
1077
|
+
const byKey = keys !== void 0;
|
|
1078
|
+
const ready = useDesktopRecording(byKey, () => onKeys(void 0));
|
|
1079
|
+
const name = t("keybindings.searchByKey");
|
|
1080
|
+
return /* @__PURE__ */ jsx(InputGroup, {
|
|
1081
|
+
className: "min-w-48 flex-1",
|
|
1082
|
+
suffix: /* @__PURE__ */ jsxs(Tooltip, { children: [/* @__PURE__ */ jsx(TooltipTrigger, {
|
|
1083
|
+
"aria-label": name,
|
|
1084
|
+
"aria-pressed": byKey,
|
|
1085
|
+
render: /* @__PURE__ */ jsx(Button, {
|
|
1086
|
+
variant: "ghost",
|
|
1087
|
+
size: "sm",
|
|
1088
|
+
type: "button",
|
|
1089
|
+
onClick: () => {
|
|
1090
|
+
onKeys(byKey ? void 0 : null);
|
|
1091
|
+
field.current?.focus();
|
|
1092
|
+
},
|
|
1093
|
+
className: byKey ? "aspect-square px-0 text-foreground" : "aspect-square px-0 text-muted-foreground hover:text-foreground"
|
|
1094
|
+
}),
|
|
1095
|
+
children: /* @__PURE__ */ jsx(Keyboard, {
|
|
1096
|
+
"aria-hidden": "true",
|
|
1097
|
+
className: "size-3.5",
|
|
1098
|
+
strokeWidth: 1.75
|
|
1099
|
+
})
|
|
1100
|
+
}), /* @__PURE__ */ jsx(TooltipContent, {
|
|
1101
|
+
side: "top",
|
|
1102
|
+
sideOffset: 6,
|
|
1103
|
+
children: name
|
|
1104
|
+
})] }),
|
|
1105
|
+
children: byKey ? /* @__PURE__ */ jsx(Input, {
|
|
1106
|
+
ref: field,
|
|
1107
|
+
readOnly: true,
|
|
1108
|
+
"aria-label": name,
|
|
1109
|
+
placeholder: t(ready ? "keybindings.keyPlaceholder" : "presence.pausing"),
|
|
1110
|
+
"aria-disabled": !ready,
|
|
1111
|
+
onBlur: () => onKeys(void 0),
|
|
1112
|
+
value: keys === null ? "" : formatChord(keys, platform),
|
|
1113
|
+
onKeyDown: (event) => {
|
|
1114
|
+
if (isFocusMove(event)) return;
|
|
1115
|
+
if (isPlain(event, "Escape") && keys === null) return;
|
|
1116
|
+
event.stopPropagation();
|
|
1117
|
+
event.preventDefault();
|
|
1118
|
+
if (!ready) return;
|
|
1119
|
+
if (isPlain(event, "Escape")) {
|
|
1120
|
+
onKeys(null);
|
|
1121
|
+
return;
|
|
1122
|
+
}
|
|
1123
|
+
const chord = fromEvent(event.nativeEvent, platform);
|
|
1124
|
+
if (chord !== null) onKeys(chord);
|
|
1125
|
+
}
|
|
1126
|
+
}) : /* @__PURE__ */ jsx(Input, {
|
|
1127
|
+
ref: field,
|
|
1128
|
+
type: "search",
|
|
1129
|
+
"aria-label": t("keybindings.searchPlaceholder"),
|
|
1130
|
+
placeholder: t("keybindings.searchPlaceholder"),
|
|
1131
|
+
value: query,
|
|
1132
|
+
onChange: (event) => onQuery(event.target.value)
|
|
1133
|
+
})
|
|
1134
|
+
});
|
|
1135
|
+
}
|
|
1136
|
+
function KeybindingsPanel({ platform = currentPlatform() }) {
|
|
1137
|
+
const { t } = useTranslation$1();
|
|
1138
|
+
const { models, byChord } = useModels();
|
|
1139
|
+
const scope = useKeybindings((state) => state.scope);
|
|
1140
|
+
const clientReserved = useKeybindings((state) => state.reserved);
|
|
1141
|
+
const globalShortcut = useKeybindings((state) => state.globalShortcut);
|
|
1142
|
+
const reserved = globalShortcut ? [...clientReserved, globalShortcut] : clientReserved;
|
|
1143
|
+
const assign = useKeybindings((state) => state.assign);
|
|
1144
|
+
const replace = useKeybindings((state) => state.replace);
|
|
1145
|
+
const remove = useKeybindings((state) => state.remove);
|
|
1146
|
+
const restore = useKeybindings((state) => state.restore);
|
|
1147
|
+
const resetAll = useKeybindings((state) => state.resetAll);
|
|
1148
|
+
const persistence = useKeybindings((state) => state.persistence);
|
|
1149
|
+
const changes = useKeybindings((state) => Object.keys(state.overrides).length);
|
|
1150
|
+
const [confirming, setConfirming] = useState(false);
|
|
1151
|
+
const [editing, setEditing] = useState(null);
|
|
1152
|
+
const editButtons = useRef(/* @__PURE__ */ new Map());
|
|
1153
|
+
/** The row whose recording just ended, to put focus back on its edit action. */
|
|
1154
|
+
const returnTo = useRef(null);
|
|
1155
|
+
const [query, setQuery] = useState("");
|
|
1156
|
+
const [keys, setKeys] = useState(void 0);
|
|
1157
|
+
const [filter, setFilter] = useState("all");
|
|
1158
|
+
const recording = editing !== null && models.some((one) => one.key === editing) ? editing : null;
|
|
1159
|
+
useEffect(() => {
|
|
1160
|
+
if (recording === null && editing !== null) setEditing(null);
|
|
1161
|
+
}, [recording, editing]);
|
|
1162
|
+
useEffect(() => {
|
|
1163
|
+
if (editing !== null || returnTo.current === null) return;
|
|
1164
|
+
editButtons.current.get(returnTo.current)?.focus();
|
|
1165
|
+
returnTo.current = null;
|
|
1166
|
+
}, [editing]);
|
|
1167
|
+
const finish = () => {
|
|
1168
|
+
returnTo.current = editing;
|
|
1169
|
+
setEditing(null);
|
|
1170
|
+
};
|
|
1171
|
+
const conflicts = models.filter((one) => one.state.kind === "conflict").length;
|
|
1172
|
+
const modified = models.filter((one) => one.modified).length;
|
|
1173
|
+
const needle = query.trim().toLowerCase();
|
|
1174
|
+
const rows = models.filter((one) => {
|
|
1175
|
+
if (filter === "modified" && !one.modified) return false;
|
|
1176
|
+
if (filter === "conflicts" && one.state.kind !== "conflict") return false;
|
|
1177
|
+
if (keys === null) return true;
|
|
1178
|
+
if (keys !== void 0) return one.state.kind !== "unbound" && one.state.keys === keys;
|
|
1179
|
+
return needle === "" || one.label.toLowerCase().includes(needle) || one.source.toLowerCase().includes(needle);
|
|
1180
|
+
});
|
|
1181
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
1182
|
+
"data-slot": "keybindings",
|
|
1183
|
+
className: "flex min-w-0 flex-col gap-4 text-sm",
|
|
1184
|
+
children: [
|
|
1185
|
+
/* @__PURE__ */ jsx(DesktopPresenceSection, { platform }),
|
|
1186
|
+
persistence === "session" && /* @__PURE__ */ jsx(Warning, { children: t(scope === "browser" ? "keybindings.unsavedBrowser" : "keybindings.unsavedDevice") }),
|
|
1187
|
+
conflicts > 0 && /* @__PURE__ */ jsx(Alert, {
|
|
1188
|
+
tone: "destructive",
|
|
1189
|
+
role: "status",
|
|
1190
|
+
"data-slot": "keybindings-conflicts",
|
|
1191
|
+
children: /* @__PURE__ */ jsxs("span", {
|
|
1192
|
+
className: "flex flex-wrap items-start justify-between gap-x-4 gap-y-1",
|
|
1193
|
+
children: [/* @__PURE__ */ jsx("span", { children: t("keybindings.conflictBanner", { count: conflicts }) }), /* @__PURE__ */ jsx(Button, {
|
|
1194
|
+
variant: "link",
|
|
1195
|
+
size: "sm",
|
|
1196
|
+
type: "button",
|
|
1197
|
+
onClick: () => setFilter("conflicts"),
|
|
1198
|
+
className: "h-auto px-0",
|
|
1199
|
+
children: t("keybindings.onlyConflicts")
|
|
1200
|
+
})]
|
|
1201
|
+
})
|
|
1202
|
+
}),
|
|
1203
|
+
/* @__PURE__ */ jsxs("div", {
|
|
1204
|
+
className: "flex flex-wrap items-center gap-3",
|
|
1205
|
+
children: [
|
|
1206
|
+
/* @__PURE__ */ jsx(SearchField, {
|
|
1207
|
+
platform,
|
|
1208
|
+
query,
|
|
1209
|
+
onQuery: setQuery,
|
|
1210
|
+
keys,
|
|
1211
|
+
onKeys: setKeys
|
|
1212
|
+
}),
|
|
1213
|
+
/* @__PURE__ */ jsx(Segmented, {
|
|
1214
|
+
label: t("keybindings.filter"),
|
|
1215
|
+
value: filter,
|
|
1216
|
+
onSelect: setFilter,
|
|
1217
|
+
options: [
|
|
1218
|
+
{
|
|
1219
|
+
value: "all",
|
|
1220
|
+
label: t("keybindings.filterAll", { count: models.length })
|
|
1221
|
+
},
|
|
1222
|
+
{
|
|
1223
|
+
value: "modified",
|
|
1224
|
+
label: t("keybindings.filterModified", { count: modified })
|
|
1225
|
+
},
|
|
1226
|
+
{
|
|
1227
|
+
value: "conflicts",
|
|
1228
|
+
label: t("keybindings.filterConflicts", { count: conflicts })
|
|
1229
|
+
}
|
|
1230
|
+
]
|
|
1231
|
+
}),
|
|
1232
|
+
/* @__PURE__ */ jsx(Button, {
|
|
1233
|
+
variant: "outline",
|
|
1234
|
+
type: "button",
|
|
1235
|
+
disabled: changes === 0,
|
|
1236
|
+
onClick: () => setConfirming(true),
|
|
1237
|
+
children: t("keybindings.resetAll")
|
|
1238
|
+
})
|
|
1239
|
+
]
|
|
1240
|
+
}),
|
|
1241
|
+
/* @__PURE__ */ jsxs(KeybindingTable, { children: [rows.length === 0 && /* @__PURE__ */ jsx(TableRow, {
|
|
1242
|
+
className: "hover:bg-transparent",
|
|
1243
|
+
children: /* @__PURE__ */ jsx(TableCell, {
|
|
1244
|
+
colSpan: 5,
|
|
1245
|
+
className: "py-8 text-center text-muted-foreground",
|
|
1246
|
+
children: keys ? t("keybindings.emptyKey", { keys: formatChord(keys, platform) }) : t("keybindings.empty")
|
|
1247
|
+
})
|
|
1248
|
+
}), rows.map((model) => /* @__PURE__ */ jsx(KeybindingRow, {
|
|
1249
|
+
model,
|
|
1250
|
+
platform,
|
|
1251
|
+
editRef: (button) => {
|
|
1252
|
+
if (button) editButtons.current.set(model.key, button);
|
|
1253
|
+
else editButtons.current.delete(model.key);
|
|
1254
|
+
},
|
|
1255
|
+
onEdit: () => setEditing(model.key),
|
|
1256
|
+
onReset: () => void restore(model.key),
|
|
1257
|
+
onRemove: () => void remove(model.key),
|
|
1258
|
+
below: recording === model.key ? /* @__PURE__ */ jsx(Recorder, {
|
|
1259
|
+
label: model.label,
|
|
1260
|
+
platform,
|
|
1261
|
+
reserved,
|
|
1262
|
+
scope,
|
|
1263
|
+
holderOf: (chord) => {
|
|
1264
|
+
const holder = byChord.get(chord);
|
|
1265
|
+
if (holder === void 0 || holder === model.key) return null;
|
|
1266
|
+
const name = models.find((one) => one.key === holder);
|
|
1267
|
+
return name ? {
|
|
1268
|
+
key: holder,
|
|
1269
|
+
label: name.label,
|
|
1270
|
+
source: name.source
|
|
1271
|
+
} : null;
|
|
1272
|
+
},
|
|
1273
|
+
onSave: (chord) => {
|
|
1274
|
+
if (!(model.state.kind === "active" && model.state.keys === chord)) assign(model.key, chord);
|
|
1275
|
+
finish();
|
|
1276
|
+
},
|
|
1277
|
+
onReplace: (chord, holder) => {
|
|
1278
|
+
replace(model.key, holder, chord);
|
|
1279
|
+
finish();
|
|
1280
|
+
},
|
|
1281
|
+
onCancel: finish
|
|
1282
|
+
}) : void 0
|
|
1283
|
+
}, model.key))] }),
|
|
1284
|
+
/* @__PURE__ */ jsx(AlertDialog, {
|
|
1285
|
+
open: confirming,
|
|
1286
|
+
onOpenChange: setConfirming,
|
|
1287
|
+
title: t("keybindings.resetAllTitle"),
|
|
1288
|
+
actions: /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Button, {
|
|
1289
|
+
variant: "secondary",
|
|
1290
|
+
type: "button",
|
|
1291
|
+
onClick: () => setConfirming(false),
|
|
1292
|
+
children: t("keybindings.cancel")
|
|
1293
|
+
}), /* @__PURE__ */ jsx(Button, {
|
|
1294
|
+
variant: "destructive",
|
|
1295
|
+
type: "button",
|
|
1296
|
+
onClick: () => {
|
|
1297
|
+
setConfirming(false);
|
|
1298
|
+
resetAll();
|
|
1299
|
+
},
|
|
1300
|
+
children: t("keybindings.resetAllConfirm")
|
|
1301
|
+
})] }),
|
|
1302
|
+
children: /* @__PURE__ */ jsx("p", { children: t("keybindings.resetAllBody", { count: changes }) })
|
|
1303
|
+
})
|
|
1304
|
+
]
|
|
1305
|
+
});
|
|
1306
|
+
}
|
|
1307
|
+
//#endregion
|
|
1308
|
+
//#region ui-src/lib/hotkeys/storage.ts
|
|
1309
|
+
/** Keeps only the entries that are a chord or `null`; anything else in
|
|
1310
|
+
* storage is somebody else's writing and reads as no change. */
|
|
1311
|
+
function parseOverrides(value) {
|
|
1312
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return {};
|
|
1313
|
+
const out = {};
|
|
1314
|
+
for (const [key, keys] of Object.entries(value)) if (keys === null || typeof keys === "string") out[key] = keys;
|
|
1315
|
+
return out;
|
|
1316
|
+
}
|
|
1317
|
+
var STORAGE_KEY = "yaoguang.keybindings";
|
|
1318
|
+
/** The browser build's storage: the one reader and writer of this key. */
|
|
1319
|
+
function localStorageKeybindings() {
|
|
1320
|
+
return {
|
|
1321
|
+
scope: "browser",
|
|
1322
|
+
load() {
|
|
1323
|
+
try {
|
|
1324
|
+
const raw = localStorage.getItem(STORAGE_KEY);
|
|
1325
|
+
return raw === null ? {} : parseOverrides(JSON.parse(raw));
|
|
1326
|
+
} catch {
|
|
1327
|
+
return {};
|
|
1328
|
+
}
|
|
1329
|
+
},
|
|
1330
|
+
async save(overrides) {
|
|
1331
|
+
localStorage.setItem(STORAGE_KEY, JSON.stringify(overrides));
|
|
1332
|
+
},
|
|
1333
|
+
subscribe(listener) {
|
|
1334
|
+
const onStorage = (event) => {
|
|
1335
|
+
if (event.key === STORAGE_KEY || event.key === null) listener();
|
|
1336
|
+
};
|
|
1337
|
+
window.addEventListener("storage", onStorage);
|
|
1338
|
+
return () => window.removeEventListener("storage", onStorage);
|
|
1339
|
+
}
|
|
1340
|
+
};
|
|
1341
|
+
}
|
|
1342
|
+
var activation;
|
|
1343
|
+
/** Called by an entry point before the first render. */
|
|
1344
|
+
function initKeybindings(options) {
|
|
1345
|
+
activation?.off?.();
|
|
1346
|
+
const { storage } = options;
|
|
1347
|
+
useKeybindings.getState().attach(storage, options.reserved);
|
|
1348
|
+
const off = storage.subscribe?.(() => useKeybindings.setState({ overrides: storage.load() }));
|
|
1349
|
+
const current = { off };
|
|
1350
|
+
activation = current;
|
|
1351
|
+
return () => {
|
|
1352
|
+
if (activation === current) {
|
|
1353
|
+
off?.();
|
|
1354
|
+
activation = void 0;
|
|
1355
|
+
useKeybindings.getState().reset();
|
|
1356
|
+
}
|
|
1357
|
+
};
|
|
1358
|
+
}
|
|
1359
|
+
//#endregion
|
|
1360
|
+
//#region ui-src/devices.ts
|
|
1361
|
+
/** Observes passive desktop ports; all observers belong to this shortcut activation. */
|
|
1362
|
+
function connectShortcutDevices(ctx) {
|
|
1363
|
+
function keys() {
|
|
1364
|
+
return initKeybindings(ctx.services.get("native-keybindings") ?? {
|
|
1365
|
+
storage: localStorageKeybindings(),
|
|
1366
|
+
reserved: BROWSER_RESERVED
|
|
1367
|
+
});
|
|
1368
|
+
}
|
|
1369
|
+
function presence() {
|
|
1370
|
+
const service = ctx.services.get("desktop-presence");
|
|
1371
|
+
if (!service) return () => {};
|
|
1372
|
+
let stop = () => {};
|
|
1373
|
+
function observe() {
|
|
1374
|
+
stop();
|
|
1375
|
+
const host = service?.host();
|
|
1376
|
+
if (!host) {
|
|
1377
|
+
stop = () => {};
|
|
1378
|
+
return;
|
|
1379
|
+
}
|
|
1380
|
+
const withdraw = installDesktopPresenceHost(host);
|
|
1381
|
+
const unlisten = host.subscribe?.((state, problem) => {
|
|
1382
|
+
if (state) notifyDesktopPresenceChanged(state, host);
|
|
1383
|
+
useDesktopPresence.setState({
|
|
1384
|
+
lastProblem: problem ?? null,
|
|
1385
|
+
eventProblem: problem ?? null
|
|
1386
|
+
});
|
|
1387
|
+
});
|
|
1388
|
+
useDesktopPresence.getState().refresh();
|
|
1389
|
+
stop = () => {
|
|
1390
|
+
unlisten?.();
|
|
1391
|
+
withdraw();
|
|
1392
|
+
};
|
|
1393
|
+
}
|
|
1394
|
+
observe();
|
|
1395
|
+
const off = service.subscribe(observe);
|
|
1396
|
+
return () => {
|
|
1397
|
+
off();
|
|
1398
|
+
stop();
|
|
1399
|
+
};
|
|
1400
|
+
}
|
|
1401
|
+
let stopKeys = keys();
|
|
1402
|
+
let stopPresence = presence();
|
|
1403
|
+
const offKeys = ctx.services.subscribe("native-keybindings", () => {
|
|
1404
|
+
stopKeys();
|
|
1405
|
+
stopKeys = keys();
|
|
1406
|
+
});
|
|
1407
|
+
const offPresence = ctx.services.subscribe("desktop-presence", () => {
|
|
1408
|
+
stopPresence();
|
|
1409
|
+
stopPresence = presence();
|
|
1410
|
+
});
|
|
1411
|
+
return () => {
|
|
1412
|
+
offPresence();
|
|
1413
|
+
offKeys();
|
|
1414
|
+
stopPresence();
|
|
1415
|
+
stopKeys();
|
|
1416
|
+
};
|
|
1417
|
+
}
|
|
1418
|
+
//#endregion
|
|
1419
|
+
//#region ui-src/index.tsx
|
|
1420
|
+
/** Conflicts remain visible beside this feature's settings category. */
|
|
1421
|
+
function ShortcutBadge() {
|
|
1422
|
+
const count = useKeybindingRows().rows.filter((one) => one.state.kind === "conflict").length;
|
|
1423
|
+
if (!count) return null;
|
|
1424
|
+
return /* @__PURE__ */ jsxs("span", {
|
|
1425
|
+
"data-slot": "settings-count",
|
|
1426
|
+
className: "ms-auto",
|
|
1427
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
1428
|
+
"aria-hidden": "true",
|
|
1429
|
+
className: "block min-w-5 rounded-pill bg-destructive px-1.5 text-center text-2xs font-medium leading-5 text-destructive-foreground",
|
|
1430
|
+
children: count
|
|
1431
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
1432
|
+
className: "sr-only",
|
|
1433
|
+
children: platformText("keybindings.conflictBadge", { count })
|
|
1434
|
+
})]
|
|
1435
|
+
});
|
|
1436
|
+
}
|
|
1437
|
+
/** Browser module version understood by the host. */
|
|
1438
|
+
var runtimeVersion = 5;
|
|
1439
|
+
/** This feature consumes optional native device ports. */
|
|
1440
|
+
var provides = [];
|
|
1441
|
+
/** Owns shortcut dispatch, storage observation, conflict controls and native wake admission. */
|
|
1442
|
+
function register(ctx) {
|
|
1443
|
+
registerTranslations(ctx);
|
|
1444
|
+
ctx.slots.register("shell.settings.category", {
|
|
1445
|
+
id: "keybindings",
|
|
1446
|
+
label: () => ctx.i18n.t("keybindings.title"),
|
|
1447
|
+
icon: "keyboard",
|
|
1448
|
+
region: "preset",
|
|
1449
|
+
order: 69,
|
|
1450
|
+
component: () => /* @__PURE__ */ jsx(KeybindingsPanel, {}),
|
|
1451
|
+
badge: ShortcutBadge
|
|
1452
|
+
});
|
|
1453
|
+
activateNativeFeature(ctx, "keyboard-shortcuts", () => {
|
|
1454
|
+
const stops = [connectShortcutDevices(ctx), installHotkeys()];
|
|
1455
|
+
ctx.signal.addEventListener("abort", () => {
|
|
1456
|
+
for (const stop of stops.toReversed()) stop();
|
|
1457
|
+
}, { once: true });
|
|
1458
|
+
});
|
|
1459
|
+
}
|
|
1460
|
+
//#endregion
|
|
1461
|
+
export { provides, register, runtimeVersion };
|