@alexsun-top/opencode-chat-room 0.8.1 → 0.8.2
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/CHANGELOG.md +23 -0
- package/README.md +10 -10
- package/README.zh-CN.md +10 -10
- package/dist/cli.js +544 -88
- package/package.json +4 -4
- package/packages/chat-room-channeld/README.md +17 -12
- package/packages/chat-room-channeld/src/adapter.ts +145 -7
- package/packages/chat-room-channeld/src/host.ts +24 -9
- package/packages/chat-room-channeld/src/inbound.ts +13 -4
- package/packages/chat-room-channeld/src/protocol.ts +52 -1
- package/packages/chat-room-channeld/src/rules.ts +7 -2
- package/plugin.ts +1 -1
- package/server/assets/base.css +8 -2
- package/server/assets/chat/admin.js +0 -2
- package/server/assets/chat/announcements.js +2 -4
- package/server/assets/chat/chat-background.js +177 -0
- package/server/assets/chat/confirm-dialog.js +0 -1
- package/server/assets/chat/create-room-dialog.js +0 -1
- package/server/assets/chat/diagram-viewer.js +7 -1
- package/server/assets/chat/doc-preview.js +71 -15
- package/server/assets/chat/events.js +13 -5
- package/server/assets/chat/files.js +10 -6
- package/server/assets/chat/image-zoom.js +8 -1
- package/server/assets/chat/index.js +4 -2
- package/server/assets/chat/integration-account-schema.js +99 -0
- package/server/assets/chat/integration-editor.js +1 -1
- package/server/assets/chat/integrations.js +207 -57
- package/server/assets/chat/locales/de.js +1 -1
- package/server/assets/chat/locales/es.js +1 -1
- package/server/assets/chat/locales/fr.js +1 -1
- package/server/assets/chat/locales/it.js +1 -1
- package/server/assets/chat/locales/ja.js +1 -1
- package/server/assets/chat/locales/ko.js +1 -1
- package/server/assets/chat/markdown-footnotes.js +1 -1
- package/server/assets/chat/markdown.js +23 -0
- package/server/assets/chat/messages.js +1 -0
- package/server/assets/chat/palette.js +6 -1
- package/server/assets/chat/panels.js +23 -3
- package/server/assets/chat/receipts.js +2 -3
- package/server/assets/chat/reminders.js +2 -4
- package/server/assets/chat/replies.js +0 -6
- package/server/assets/chat/rooms.js +1 -6
- package/server/assets/chat/settings.js +69 -3
- package/server/assets/chat/shortcuts.js +0 -3
- package/server/assets/chat/side-pane.js +33 -8
- package/server/assets/chat/state.js +48 -18
- package/server/assets/chat/system-events.js +29 -3
- package/server/assets/chat/system-messages.js +9 -0
- package/server/assets/chat/tasks.js +2 -8
- package/server/assets/chat/window-controls.js +37 -0
- package/server/assets/code-highlight.css +22 -6
- package/server/assets/conversation.css +55 -12
- package/server/assets/doc-preview.css +6 -1
- package/server/assets/files.css +3 -0
- package/server/assets/monaco/integration-rules.css +1 -1
- package/server/assets/monaco/integration-rules.js +841 -533
- package/server/assets/responsive.css +32 -2
- package/server/assets/settings.css +117 -13
- package/server/assets/window-controls.css +36 -0
- package/server/channel-attachments.ts +133 -0
- package/server/channel-integration.ts +79 -26
- package/server/channels.ts +15 -5
- package/server/chat.html +71 -37
- package/server/manifest.webmanifest +1 -0
- package/server/sw.js +1 -0
- package/src/center/center-client.ts +1 -1
- package/src/state/pg-database.ts +5 -5
- package/src/state/pg-migrate.ts +7 -7
- package/src/state/pg-worker.mjs +2 -17
- package/src/state/sqlite-database.ts +14 -5
- package/src/state/sqlite-rooms.ts +130 -23
- package/src/state/sqlite-state-store.ts +6 -5
- package/src/state/sqlite.ts +3 -3
- package/src/web/integration-rules-editor.ts +139 -5
- package/src/web/integration-rules.ts +6 -2
- package/src/web/integration-schema.ts +7 -6
- package/packages/chat-room-channeld/dist/feishu-adapter.js +0 -1262
- package/packages/chat-room-channeld/src/feishu-adapter.ts +0 -303
- package/packages/chat-room-channeld/src/feishu-card.ts +0 -27
- package/packages/chat-room-channeld/src/feishu-inbound.ts +0 -158
- package/packages/chat-room-channeld/src/feishu-live.ts +0 -355
- package/packages/chat-room-channeld/src/feishu-send.ts +0 -342
- package/packages/chat-room-channeld/src/feishu-ws-frames.ts +0 -173
- package/server/assets/chat/forward.js +0 -69
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
// Settings > Integrations: runtime switch, accounts, plugin uploads, and rules.
|
|
2
2
|
import { initIntegrationEditor } from "./integration-editor.js";
|
|
3
|
+
import { iconNode } from "./icons.js";
|
|
4
|
+
import { readAccountSchema, renderAccountSchema } from "./integration-account-schema.js";
|
|
3
5
|
import { checkInbound, checkRules, knownPlugins, normalizeAccount, parseInbound, parseRules } from "./integration-values.js";
|
|
4
6
|
import { accountBody, cleanError, stateLabel } from "./integration-values.js";
|
|
5
7
|
|
|
6
8
|
const MAX_SOURCE = 256 * 1024;
|
|
7
9
|
const IDENTIFIER = /^[A-Za-z0-9._-]{1,128}$/;
|
|
8
|
-
const PLUGIN_NAME = /^[A-Za-z0-9][A-Za-z0-9._-]*\.(?:js|mjs|cjs)$/;
|
|
10
|
+
const PLUGIN_NAME = /^[A-Za-z0-9][A-Za-z0-9._-]*\.(?:js|mjs|cjs|ts)$/;
|
|
9
11
|
const ENV_KEY = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
10
12
|
|
|
11
13
|
const isRecord = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
@@ -14,6 +16,7 @@ export function initIntegrations(app) {
|
|
|
14
16
|
const $ = app.$;
|
|
15
17
|
const panel = $("#settingsPanelIntegrations"); if (!panel) return;
|
|
16
18
|
const enabledInput = $("#inIntegrationsEnabled"), statusText = $("#integrationStatus");
|
|
19
|
+
const integrationBody = $("#integrationBody"), disabledHint = $("#integrationDisabledHint");
|
|
17
20
|
const panelError = $("#integrationError"), accountsList = $("#integrationAccounts");
|
|
18
21
|
const externalNotice = $("#integrationExternalNotice"), addAccountButton = $("#btnAddIntegrationAccount");
|
|
19
22
|
const uploadPluginButton = $("#btnUploadPlugin");
|
|
@@ -22,16 +25,16 @@ export function initIntegrations(app) {
|
|
|
22
25
|
const rulesError = $("#integrationRulesError"), saveButton = $("#btnSaveIntegrations");
|
|
23
26
|
const accountDialog = $("#integrationAccountDialog"), accountForm = $("#integrationAccountForm");
|
|
24
27
|
const accountError = $("#integrationAccountError"), accountId = $("#integrationAccountId");
|
|
25
|
-
const accountPlugin = $("#integrationAccountPlugin")
|
|
28
|
+
const accountPlugin = $("#integrationAccountPlugin");
|
|
29
|
+
const accountSchema = $("#integrationAccountSchema"), accountSchemaField = $("#integrationAccountSchemaField"), accountAdvanced = $("#integrationAccountAdvanced");
|
|
26
30
|
const accountEnv = $("#integrationAccountEnv"), accountEnvNote = $("#integrationAccountEnvNote");
|
|
27
31
|
const accountClear = $("#btnClearAccountEnv"), accountAddEnv = $("#btnAddAccountEnv");
|
|
28
32
|
const pluginDialog = $("#integrationPluginDialog"), pluginForm = $("#integrationPluginForm");
|
|
29
33
|
const pluginError = $("#integrationPluginError"), pluginFile = $("#integrationPluginFile");
|
|
30
|
-
const pluginName = $("#integrationPluginName"), pluginPlatform = $("#integrationPluginPlatform");
|
|
31
|
-
const pluginSource = $("#integrationPluginSource"), pluginEnv = $("#integrationPluginEnv");
|
|
32
34
|
let data = { enabled: false, source: "managed", editable: true, accounts: [], rules: [], inbound: [], plugins: [] };
|
|
33
35
|
let initialInbound = "[]";
|
|
34
36
|
let loaded = false, loading = false, saving = false, accountDraft = null, clearEnv = false;
|
|
37
|
+
let pluginUploadSource = "", pluginUploadName = "";
|
|
35
38
|
|
|
36
39
|
const text = (key, values) => app.t(key, values);
|
|
37
40
|
const clean = (error) => cleanError(error, text("integrationsLoadFailed"));
|
|
@@ -77,6 +80,12 @@ export function initIntegrations(app) {
|
|
|
77
80
|
inboundSection.setEditable(editable);
|
|
78
81
|
}
|
|
79
82
|
|
|
83
|
+
function applyEnabledState() {
|
|
84
|
+
const enabled = enabledInput.checked;
|
|
85
|
+
integrationBody.hidden = !enabled;
|
|
86
|
+
disabledHint.hidden = enabled;
|
|
87
|
+
}
|
|
88
|
+
|
|
80
89
|
const pluginNameOf = (pluginId) => knownPlugins(data).find((plugin) => plugin.pluginId === pluginId)?.name || pluginId;
|
|
81
90
|
|
|
82
91
|
function adopt(snapshot) {
|
|
@@ -138,8 +147,9 @@ export function initIntegrations(app) {
|
|
|
138
147
|
remove.type = "button"; remove.className = "btn ghost small danger-text"; remove.textContent = text("integrationsRemove");
|
|
139
148
|
remove.setAttribute("aria-label", `${text("integrationsRemove")}: ${account.id}`);
|
|
140
149
|
remove.disabled = data.editable === false;
|
|
141
|
-
remove.addEventListener("click", () => {
|
|
150
|
+
remove.addEventListener("click", async () => {
|
|
142
151
|
if (data.editable === false) return;
|
|
152
|
+
if (!(await app.confirmAction(text("integrationsRemoveAccountConfirm", { id: account.id })))) return;
|
|
143
153
|
data.accounts = data.accounts.filter((item) => item.id !== account.id);
|
|
144
154
|
renderAccounts();
|
|
145
155
|
showStatus(text("integrationsAccountRemoved"));
|
|
@@ -165,12 +175,37 @@ export function initIntegrations(app) {
|
|
|
165
175
|
const platform = document.createElement("span");
|
|
166
176
|
platform.className = "integration-platform";
|
|
167
177
|
platform.textContent = plugin.platform;
|
|
168
|
-
|
|
178
|
+
const download = document.createElement("button");
|
|
179
|
+
download.type = "button";
|
|
180
|
+
download.className = "btn ghost small integration-plugin-download";
|
|
181
|
+
download.title = text("integrationsDownloadPlugin", { name: plugin.name });
|
|
182
|
+
download.setAttribute("aria-label", download.title);
|
|
183
|
+
download.append(iconNode("arrow_download"));
|
|
184
|
+
download.addEventListener("click", () => void downloadPlugin(plugin, download));
|
|
185
|
+
row.append(name, platform, download);
|
|
169
186
|
pluginsList.append(row);
|
|
170
187
|
}
|
|
171
188
|
pluginsEmpty.hidden = plugins.length > 0;
|
|
172
189
|
}
|
|
173
190
|
|
|
191
|
+
async function downloadPlugin(plugin, button) {
|
|
192
|
+
if (button.disabled) return;
|
|
193
|
+
button.disabled = true;
|
|
194
|
+
try {
|
|
195
|
+
const blob = await app.apiBlob(`/channeld/plugins/${encodeURIComponent(plugin.pluginId)}/download`);
|
|
196
|
+
const href = URL.createObjectURL(blob);
|
|
197
|
+
const anchor = document.createElement("a");
|
|
198
|
+
anchor.href = href;
|
|
199
|
+
anchor.download = plugin.name;
|
|
200
|
+
document.body.append(anchor);
|
|
201
|
+
anchor.click();
|
|
202
|
+
anchor.remove();
|
|
203
|
+
setTimeout(() => URL.revokeObjectURL(href), 1000);
|
|
204
|
+
} catch (error) {
|
|
205
|
+
showPanelError(error);
|
|
206
|
+
} finally { button.disabled = false; }
|
|
207
|
+
}
|
|
208
|
+
|
|
174
209
|
function renderRules() {
|
|
175
210
|
rulesSection.refresh();
|
|
176
211
|
inboundSection.refresh();
|
|
@@ -184,6 +219,7 @@ export function initIntegrations(app) {
|
|
|
184
219
|
renderAccounts();
|
|
185
220
|
renderPlugins();
|
|
186
221
|
renderRules();
|
|
222
|
+
applyEnabledState();
|
|
187
223
|
applyEditableState();
|
|
188
224
|
}
|
|
189
225
|
|
|
@@ -195,7 +231,7 @@ export function initIntegrations(app) {
|
|
|
195
231
|
hidePanelError();
|
|
196
232
|
showStatus(text("integrationsLoading"));
|
|
197
233
|
try {
|
|
198
|
-
adopt(await app.api("/channeld/integration"));
|
|
234
|
+
adopt(await app.api("/channeld/integration", { cache: "no-store" }));
|
|
199
235
|
renderAll();
|
|
200
236
|
showStatus("");
|
|
201
237
|
} catch (error) {
|
|
@@ -203,7 +239,7 @@ export function initIntegrations(app) {
|
|
|
203
239
|
showPanelError(error);
|
|
204
240
|
} finally { loading = false; }
|
|
205
241
|
}
|
|
206
|
-
app.loadIntegrations = () => { void load(); };
|
|
242
|
+
app.loadIntegrations = () => { void load(true); };
|
|
207
243
|
|
|
208
244
|
function setSaving(busy) {
|
|
209
245
|
saving = busy;
|
|
@@ -211,6 +247,21 @@ export function initIntegrations(app) {
|
|
|
211
247
|
enabledInput.disabled = busy;
|
|
212
248
|
}
|
|
213
249
|
|
|
250
|
+
let envMenuSerial = 0;
|
|
251
|
+
|
|
252
|
+
function envFields() {
|
|
253
|
+
const plugin = knownPlugins(data).find((item) => item.pluginId === accountPlugin.value);
|
|
254
|
+
return (plugin?.account?.env ?? []).filter((field) => ENV_KEY.test(field.key));
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
function closeEnvMenus(except) {
|
|
258
|
+
for (const menu of accountEnv.querySelectorAll(".integration-env-menu")) {
|
|
259
|
+
if (menu === except) continue;
|
|
260
|
+
menu.hidden = true;
|
|
261
|
+
menu.parentElement?.querySelector(".integration-env-key")?.setAttribute("aria-expanded", "false");
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
214
265
|
function addEnvRow(container, entry = {}, existing = false, onRemove = null) {
|
|
215
266
|
const row = document.createElement("div");
|
|
216
267
|
row.className = `integration-env-row${existing ? " is-stored" : ""}`;
|
|
@@ -228,17 +279,112 @@ export function initIntegrations(app) {
|
|
|
228
279
|
value.placeholder = existing ? text("integrationsLeaveBlank") : "";
|
|
229
280
|
value.setAttribute("aria-label", text("integrationsEnvValue"));
|
|
230
281
|
value.autocomplete = "new-password";
|
|
282
|
+
let keyControl = key;
|
|
283
|
+
if (!existing) {
|
|
284
|
+
const combo = document.createElement("div");
|
|
285
|
+
combo.className = "integration-env-combo";
|
|
286
|
+
const menu = document.createElement("div");
|
|
287
|
+
menu.className = "integration-env-menu";
|
|
288
|
+
menu.id = `integrationEnvMenu-${++envMenuSerial}`;
|
|
289
|
+
menu.role = "listbox";
|
|
290
|
+
menu.hidden = true;
|
|
291
|
+
key.setAttribute("role", "combobox");
|
|
292
|
+
key.setAttribute("aria-autocomplete", "list");
|
|
293
|
+
key.setAttribute("aria-expanded", "false");
|
|
294
|
+
key.setAttribute("aria-controls", menu.id);
|
|
295
|
+
const hide = () => {
|
|
296
|
+
menu.hidden = true;
|
|
297
|
+
key.setAttribute("aria-expanded", "false");
|
|
298
|
+
};
|
|
299
|
+
const choose = (option) => {
|
|
300
|
+
key.value = option.dataset.key;
|
|
301
|
+
hide();
|
|
302
|
+
value.focus();
|
|
303
|
+
};
|
|
304
|
+
const renderMenu = () => {
|
|
305
|
+
closeEnvMenus(menu);
|
|
306
|
+
const used = new Set([...container.querySelectorAll(".integration-env-key")]
|
|
307
|
+
.map((input) => input.value.trim())
|
|
308
|
+
.filter(Boolean));
|
|
309
|
+
const query = key.value.trim().toLowerCase();
|
|
310
|
+
const matches = envFields().filter((field) => !used.has(field.key)).filter((field) => {
|
|
311
|
+
if (!query) return true;
|
|
312
|
+
return [field.key, field.label, field.description]
|
|
313
|
+
.some((text) => String(text ?? "").toLowerCase().includes(query));
|
|
314
|
+
});
|
|
315
|
+
menu.replaceChildren(...matches.map((field) => {
|
|
316
|
+
const option = document.createElement("button");
|
|
317
|
+
option.type = "button";
|
|
318
|
+
option.className = "integration-env-option";
|
|
319
|
+
option.dataset.key = field.key;
|
|
320
|
+
option.tabIndex = -1;
|
|
321
|
+
option.setAttribute("role", "option");
|
|
322
|
+
const name = document.createElement("span");
|
|
323
|
+
name.className = "integration-env-option-key";
|
|
324
|
+
name.textContent = field.key;
|
|
325
|
+
option.append(name);
|
|
326
|
+
const detail = [field.label, field.description].filter(Boolean).join(" · ");
|
|
327
|
+
if (detail) {
|
|
328
|
+
const description = document.createElement("span");
|
|
329
|
+
description.className = "integration-env-option-desc";
|
|
330
|
+
description.textContent = detail;
|
|
331
|
+
option.append(description);
|
|
332
|
+
}
|
|
333
|
+
option.addEventListener("mousedown", (event) => event.preventDefault());
|
|
334
|
+
option.addEventListener("click", () => choose(option));
|
|
335
|
+
option.addEventListener("keydown", (event) => {
|
|
336
|
+
const options = [...menu.querySelectorAll(".integration-env-option")];
|
|
337
|
+
const index = options.indexOf(option);
|
|
338
|
+
if (event.key === "ArrowDown") {
|
|
339
|
+
event.preventDefault();
|
|
340
|
+
options[(index + 1) % options.length]?.focus();
|
|
341
|
+
} else if (event.key === "ArrowUp") {
|
|
342
|
+
event.preventDefault();
|
|
343
|
+
options[(index - 1 + options.length) % options.length]?.focus();
|
|
344
|
+
} else if (event.key === "Escape") {
|
|
345
|
+
event.preventDefault();
|
|
346
|
+
hide();
|
|
347
|
+
key.focus();
|
|
348
|
+
} else if (event.key === "Enter") {
|
|
349
|
+
event.preventDefault();
|
|
350
|
+
choose(option);
|
|
351
|
+
}
|
|
352
|
+
});
|
|
353
|
+
return option;
|
|
354
|
+
}));
|
|
355
|
+
menu.hidden = matches.length === 0;
|
|
356
|
+
key.setAttribute("aria-expanded", String(!menu.hidden));
|
|
357
|
+
};
|
|
358
|
+
key.addEventListener("focus", renderMenu);
|
|
359
|
+
key.addEventListener("click", renderMenu);
|
|
360
|
+
key.addEventListener("input", renderMenu);
|
|
361
|
+
key.addEventListener("keydown", (event) => {
|
|
362
|
+
if (event.key === "ArrowDown") {
|
|
363
|
+
event.preventDefault();
|
|
364
|
+
if (menu.hidden) renderMenu();
|
|
365
|
+
menu.querySelector(".integration-env-option")?.focus();
|
|
366
|
+
} else if (event.key === "Escape") {
|
|
367
|
+
hide();
|
|
368
|
+
}
|
|
369
|
+
});
|
|
370
|
+
key.addEventListener("blur", () => {
|
|
371
|
+
setTimeout(() => { if (!combo.contains(document.activeElement)) hide(); }, 0);
|
|
372
|
+
});
|
|
373
|
+
combo.append(key, menu);
|
|
374
|
+
keyControl = combo;
|
|
375
|
+
}
|
|
231
376
|
const remove = document.createElement("button");
|
|
232
377
|
remove.type = "button";
|
|
233
378
|
remove.className = "btn ghost small integration-env-remove";
|
|
234
|
-
remove.
|
|
379
|
+
remove.append(iconNode("subtract"));
|
|
235
380
|
remove.setAttribute("aria-label", text("integrationsRemove"));
|
|
381
|
+
remove.setAttribute("title", text("integrationsRemove"));
|
|
236
382
|
remove.addEventListener("click", () => {
|
|
237
383
|
const currentKey = key.value.trim();
|
|
238
384
|
row.remove();
|
|
239
385
|
onRemove?.(currentKey, existing);
|
|
240
386
|
});
|
|
241
|
-
row.append(
|
|
387
|
+
row.append(keyControl, value, remove);
|
|
242
388
|
container.append(row);
|
|
243
389
|
return row;
|
|
244
390
|
}
|
|
@@ -270,13 +416,13 @@ export function initIntegrations(app) {
|
|
|
270
416
|
accountPlugin.append(option);
|
|
271
417
|
}
|
|
272
418
|
accountPlugin.value = plugins.some((plugin) => plugin.pluginId === selected) ? selected : plugins[0]?.pluginId || "";
|
|
273
|
-
const plugin = plugins.find((item) => item.pluginId === accountPlugin.value);
|
|
274
|
-
accountPlatform.value = plugin?.platform || accountDraft?.platform || "";
|
|
275
419
|
}
|
|
276
420
|
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
421
|
+
/** Stable once saved; a blank ID is only a convenience for new accounts. */
|
|
422
|
+
function newAccountId(plugin) {
|
|
423
|
+
const prefix = String(plugin?.platform || "account").replace(/[^A-Za-z0-9._-]/g, "") || "account";
|
|
424
|
+
const bytes = crypto.getRandomValues(new Uint8Array(4));
|
|
425
|
+
return `${prefix}-${[...bytes].map((byte) => byte.toString(16).padStart(2, "0")).join("")}`;
|
|
280
426
|
}
|
|
281
427
|
|
|
282
428
|
function setClearEnv(next) {
|
|
@@ -286,6 +432,7 @@ export function initIntegrations(app) {
|
|
|
286
432
|
accountEnvNote.textContent = next ? text("integrationsClearEnvActive") : "";
|
|
287
433
|
accountAddEnv.disabled = next;
|
|
288
434
|
for (const control of accountEnv.querySelectorAll("input, button")) control.disabled = next;
|
|
435
|
+
for (const control of accountSchema.querySelectorAll("input, select, button")) control.disabled = next;
|
|
289
436
|
}
|
|
290
437
|
|
|
291
438
|
function removeStoredKey(key) {
|
|
@@ -297,6 +444,16 @@ export function initIntegrations(app) {
|
|
|
297
444
|
if (accountDraft.envSet) delete accountDraft.envSet[key];
|
|
298
445
|
}
|
|
299
446
|
|
|
447
|
+
function syncAccountSchema() {
|
|
448
|
+
const plugin = knownPlugins(data).find((item) => item.pluginId === accountPlugin.value);
|
|
449
|
+
closeEnvMenus();
|
|
450
|
+
renderAccountSchema(accountSchema, plugin, accountDraft?.id ? accountDraft : null, text);
|
|
451
|
+
accountSchemaField.hidden = accountSchema.hidden;
|
|
452
|
+
// Without a declared schema the raw env rows are the only way to configure
|
|
453
|
+
// the account, so keep them open; schema-backed plugins can collapse them.
|
|
454
|
+
accountAdvanced.open = accountSchema.hidden;
|
|
455
|
+
}
|
|
456
|
+
|
|
300
457
|
function openAccount(account = null, presetPlugin = "") {
|
|
301
458
|
if (data.editable === false) return;
|
|
302
459
|
if (!knownPlugins(data).length) { showPanelError(text("integrationsPluginFirst")); return; }
|
|
@@ -310,13 +467,14 @@ export function initIntegrations(app) {
|
|
|
310
467
|
accountId.readOnly = Boolean(account);
|
|
311
468
|
hideAccountError();
|
|
312
469
|
fillPlugins(account?.pluginId || presetPlugin);
|
|
470
|
+
syncAccountSchema();
|
|
313
471
|
accountEnv.textContent = "";
|
|
314
472
|
const keys = account?.envClear ? account.storedKeys : account?.envKeys || [];
|
|
315
473
|
for (const key of keys) addEnvRow(accountEnv, { key }, true, removeStoredKey);
|
|
316
474
|
if (!keys.length) addEnvRow(accountEnv);
|
|
317
475
|
setClearEnv(Boolean(account?.envClear));
|
|
318
476
|
accountDialog.showModal();
|
|
319
|
-
|
|
477
|
+
accountPlugin.focus();
|
|
320
478
|
}
|
|
321
479
|
|
|
322
480
|
function closeAccount() {
|
|
@@ -328,10 +486,10 @@ export function initIntegrations(app) {
|
|
|
328
486
|
event.preventDefault();
|
|
329
487
|
if (!accountDraft) return;
|
|
330
488
|
hideAccountError();
|
|
331
|
-
const id = accountId.value.trim();
|
|
332
489
|
const pluginId = accountPlugin.value;
|
|
333
490
|
const plugin = knownPlugins(data).find((item) => item.pluginId === pluginId);
|
|
334
|
-
if (!
|
|
491
|
+
if (!plugin) return showAccountError(text("integrationsAccountInvalid"));
|
|
492
|
+
const id = accountDraft.id || accountId.value.trim() || newAccountId(plugin);
|
|
335
493
|
if (!IDENTIFIER.test(id)) return showAccountError(text("integrationsAccountInvalid"));
|
|
336
494
|
if (data.accounts.some((item) => item.id === id && item.id !== accountDraft.id)) {
|
|
337
495
|
return showAccountError(text("integrationsDuplicateAccount"));
|
|
@@ -339,9 +497,16 @@ export function initIntegrations(app) {
|
|
|
339
497
|
let values;
|
|
340
498
|
try { values = clearEnv ? {} : readEnv(accountEnv); }
|
|
341
499
|
catch (error) { return showAccountError(error); }
|
|
342
|
-
|
|
500
|
+
let schema;
|
|
501
|
+
try { schema = readAccountSchema(accountSchema, text); }
|
|
502
|
+
catch (error) { return showAccountError(error); }
|
|
503
|
+
// A schema field and a free-form env row can name the same key: the schema wins.
|
|
504
|
+
for (const key of schema.keys) delete values[key];
|
|
505
|
+
const schemaValues = clearEnv ? {} : schema.values;
|
|
506
|
+
const envSet = clearEnv ? {} : { ...(accountDraft.envSet || {}), ...values, ...schemaValues };
|
|
343
507
|
const deleted = new Set(clearEnv ? [] : accountDraft.envDelete || []);
|
|
344
508
|
for (const key of Object.keys(values)) deleted.delete(key);
|
|
509
|
+
for (const key of Object.keys(schemaValues)) deleted.delete(key);
|
|
345
510
|
const remaining = (accountDraft.envKeys || []).filter((key) => !deleted.has(key));
|
|
346
511
|
const next = {
|
|
347
512
|
id,
|
|
@@ -366,6 +531,11 @@ export function initIntegrations(app) {
|
|
|
366
531
|
|
|
367
532
|
async function save() {
|
|
368
533
|
if (saving || data.editable === false) return;
|
|
534
|
+
if (data.enabled && !enabledInput.checked && !(await app.confirmAction(text("integrationsDisableConfirm")))) {
|
|
535
|
+
enabledInput.checked = true;
|
|
536
|
+
applyEnabledState();
|
|
537
|
+
return;
|
|
538
|
+
}
|
|
369
539
|
hidePanelError();
|
|
370
540
|
hideRulesError();
|
|
371
541
|
if (!data.accounts.length) return showPanelError(text("integrationsNeedAccount"));
|
|
@@ -408,44 +578,25 @@ export function initIntegrations(app) {
|
|
|
408
578
|
finally { setSaving(false); }
|
|
409
579
|
}
|
|
410
580
|
|
|
411
|
-
async function toggleEnabled(next) {
|
|
412
|
-
enabledInput.disabled = true;
|
|
413
|
-
hidePanelError();
|
|
414
|
-
try {
|
|
415
|
-
const result = await app.api(next ? "/channeld/enable" : "/channeld/disable", { method: "POST", body: "{}" });
|
|
416
|
-
data.enabled = typeof result?.enabled === "boolean" ? result.enabled : next;
|
|
417
|
-
enabledInput.checked = data.enabled;
|
|
418
|
-
showStatus(text(data.enabled ? "integrationsEnabled" : "integrationsDisabled"));
|
|
419
|
-
} catch (error) {
|
|
420
|
-
// A first enable may need the managed config that Save writes.
|
|
421
|
-
if (next && /configuration path/i.test(String(error?.message || ""))) {
|
|
422
|
-
data.enabled = true;
|
|
423
|
-
enabledInput.checked = true;
|
|
424
|
-
showStatus(text("integrationsEnablePending"));
|
|
425
|
-
return;
|
|
426
|
-
}
|
|
427
|
-
enabledInput.checked = !next;
|
|
428
|
-
showPanelError(error);
|
|
429
|
-
} finally { enabledInput.disabled = false; }
|
|
430
|
-
}
|
|
431
|
-
|
|
432
581
|
function openUpload() {
|
|
433
582
|
if (data.editable === false) return;
|
|
434
583
|
pluginForm.reset();
|
|
435
|
-
|
|
436
|
-
|
|
584
|
+
pluginUploadSource = "";
|
|
585
|
+
pluginUploadName = "";
|
|
437
586
|
hidePluginError();
|
|
438
587
|
pluginDialog.showModal();
|
|
439
|
-
|
|
588
|
+
pluginFile.focus();
|
|
440
589
|
}
|
|
441
590
|
|
|
442
591
|
pluginFile.addEventListener("change", async () => {
|
|
443
592
|
const file = pluginFile.files?.[0];
|
|
593
|
+
pluginUploadSource = "";
|
|
594
|
+
pluginUploadName = "";
|
|
444
595
|
if (!file) return;
|
|
445
596
|
if (file.size > MAX_SOURCE) return showPluginError(text("integrationsSourceTooLarge"));
|
|
446
597
|
try {
|
|
447
|
-
|
|
448
|
-
|
|
598
|
+
pluginUploadSource = await file.text();
|
|
599
|
+
pluginUploadName = file.name;
|
|
449
600
|
hidePluginError();
|
|
450
601
|
} catch (error) { showPluginError(error); }
|
|
451
602
|
});
|
|
@@ -453,22 +604,24 @@ export function initIntegrations(app) {
|
|
|
453
604
|
pluginForm.addEventListener("submit", async (event) => {
|
|
454
605
|
event.preventDefault();
|
|
455
606
|
hidePluginError();
|
|
456
|
-
const name =
|
|
607
|
+
const name = pluginUploadName || "plugin.js", source = pluginUploadSource;
|
|
457
608
|
if (!PLUGIN_NAME.test(name)) return showPluginError(text("integrationsNameRequired"));
|
|
458
|
-
if (!IDENTIFIER.test(platform)) return showPluginError(text("integrationsPlatformRequired"));
|
|
459
609
|
if (!source.trim()) return showPluginError(text("integrationsSourceRequired"));
|
|
460
610
|
if (new TextEncoder().encode(source).length > MAX_SOURCE) return showPluginError(text("integrationsSourceTooLarge"));
|
|
461
|
-
let env;
|
|
462
|
-
try { env = readEnv(pluginEnv); }
|
|
463
|
-
catch (error) { return showPluginError(error); }
|
|
464
611
|
const submit = $("#btnSaveIntegrationPlugin");
|
|
465
612
|
submit.disabled = true;
|
|
466
613
|
try {
|
|
467
614
|
const result = await app.api("/channeld/plugins", {
|
|
468
615
|
method: "POST",
|
|
469
|
-
body: JSON.stringify({ name,
|
|
616
|
+
body: JSON.stringify({ name, source }),
|
|
470
617
|
});
|
|
471
|
-
const plugin = {
|
|
618
|
+
const plugin = {
|
|
619
|
+
pluginId: result.pluginId,
|
|
620
|
+
name: result.name,
|
|
621
|
+
platform: result.platform,
|
|
622
|
+
...(result.displayName ? { displayName: result.displayName } : {}),
|
|
623
|
+
...(result.account ? { account: result.account } : {}),
|
|
624
|
+
};
|
|
472
625
|
data.plugins = [...data.plugins.filter((item) => item.pluginId !== plugin.pluginId), plugin];
|
|
473
626
|
renderPlugins();
|
|
474
627
|
pluginDialog.close();
|
|
@@ -479,20 +632,17 @@ export function initIntegrations(app) {
|
|
|
479
632
|
});
|
|
480
633
|
|
|
481
634
|
$("#btnAddAccountEnv").addEventListener("click", () => addEnvRow(accountEnv).querySelector(".integration-env-key").focus());
|
|
482
|
-
|
|
635
|
+
accountPlugin.addEventListener("change", syncAccountSchema);
|
|
483
636
|
accountClear.addEventListener("click", () => setClearEnv(!clearEnv));
|
|
484
|
-
|
|
485
|
-
enabledInput.addEventListener("change", () => void toggleEnabled(enabledInput.checked));
|
|
637
|
+
enabledInput.addEventListener("change", applyEnabledState);
|
|
486
638
|
addAccountButton.addEventListener("click", () => openAccount(null));
|
|
487
639
|
uploadPluginButton.addEventListener("click", openUpload);
|
|
488
640
|
$("#btnRefreshIntegrations").addEventListener("click", () => void load(true));
|
|
489
641
|
saveButton.addEventListener("click", () => void save());
|
|
490
642
|
$("#btnCloseIntegrationAccount").addEventListener("click", closeAccount);
|
|
491
643
|
$("#btnCancelIntegrationAccount").addEventListener("click", closeAccount);
|
|
492
|
-
accountDialog.addEventListener("click", (event) => { if (event.target === accountDialog) closeAccount(); });
|
|
493
644
|
accountDialog.addEventListener("cancel", (event) => { event.preventDefault(); closeAccount(); });
|
|
494
645
|
$("#btnCloseIntegrationPlugin").addEventListener("click", () => pluginDialog.close());
|
|
495
646
|
$("#btnCancelIntegrationPlugin").addEventListener("click", () => pluginDialog.close());
|
|
496
|
-
pluginDialog.addEventListener("click", (event) => { if (event.target === pluginDialog) pluginDialog.close(); });
|
|
497
647
|
pluginDialog.addEventListener("cancel", (event) => { event.preventDefault(); pluginDialog.close(); });
|
|
498
648
|
}
|
|
@@ -79,7 +79,7 @@ export const de = {
|
|
|
79
79
|
integrationsAddEnv: "Variable hinzufügen", integrationsClearEnv: "Alle Variablen löschen", integrationsKeepEnv: "Alle Variablen behalten",
|
|
80
80
|
integrationsClearEnvActive: "Alle gespeicherten Variablen werden beim Speichern gelöscht.", integrationsEnvInvalid: "Variablennamen dürfen nur Buchstaben, Ziffern und Unterstriche enthalten und müssen eindeutig sein.",
|
|
81
81
|
integrationsAccountTitle: "Integrationskonto", integrationsAccountId: "Konto-ID", integrationsPlatform: "Plattform",
|
|
82
|
-
integrationsAccountInvalid: "
|
|
82
|
+
integrationsAccountInvalid: "Wählen Sie ein Plugin.", integrationsDuplicateAccount: "Ein Konto mit dieser ID existiert bereits.",
|
|
83
83
|
integrationsAccountSaved: "Konto gespeichert. Integrationen speichern, um es anzuwenden.", integrationsAccountRemoved: "Konto entfernt. Integrationen speichern, um es anzuwenden.",
|
|
84
84
|
integrationsLastError: "Letzter Fehler", integrationsEdit: "Bearbeiten", integrationsRemove: "Entfernen",
|
|
85
85
|
integrationsInvalidJson: "Regel-JSON ist nahe Zeile {line} ungültig.", integrationsInvalidRules: "Regeln müssen ein JSON-Array sein.",
|
|
@@ -78,7 +78,7 @@ export const es = {
|
|
|
78
78
|
integrationsAddEnv: "Añadir variable", integrationsClearEnv: "Borrar todas las variables", integrationsKeepEnv: "Conservar todas las variables",
|
|
79
79
|
integrationsClearEnvActive: "Todas las variables guardadas se borrarán al guardar.", integrationsEnvInvalid: "Usa nombres de variable únicos con letras, números y guiones bajos.",
|
|
80
80
|
integrationsAccountTitle: "Cuenta de integración", integrationsAccountId: "ID de cuenta", integrationsPlatform: "Plataforma",
|
|
81
|
-
integrationsAccountInvalid: "
|
|
81
|
+
integrationsAccountInvalid: "Elige un plugin.", integrationsDuplicateAccount: "Ya existe una cuenta con este ID.",
|
|
82
82
|
integrationsAccountSaved: "Cuenta guardada. Guarda las integraciones para aplicarla.", integrationsAccountRemoved: "Cuenta eliminada. Guarda las integraciones para aplicarlo.",
|
|
83
83
|
integrationsLastError: "Último error", integrationsEdit: "Editar", integrationsRemove: "Quitar",
|
|
84
84
|
integrationsInvalidJson: "El JSON de reglas no es válido cerca de la línea {line}.", integrationsInvalidRules: "Las reglas deben ser una matriz JSON.",
|
|
@@ -79,7 +79,7 @@ export const fr = {
|
|
|
79
79
|
integrationsAddEnv: "Ajouter une variable", integrationsClearEnv: "Effacer toutes les variables", integrationsKeepEnv: "Conserver toutes les variables",
|
|
80
80
|
integrationsClearEnvActive: "Toutes les variables enregistrées seront effacées à l’enregistrement.", integrationsEnvInvalid: "Utilisez des noms de variable uniques composés de lettres, chiffres et traits de soulignement.",
|
|
81
81
|
integrationsAccountTitle: "Compte d’intégration", integrationsAccountId: "ID du compte", integrationsPlatform: "Plateforme",
|
|
82
|
-
integrationsAccountInvalid: "
|
|
82
|
+
integrationsAccountInvalid: "Choisissez un plugin.", integrationsDuplicateAccount: "Un compte avec cet ID existe déjà.",
|
|
83
83
|
integrationsAccountSaved: "Compte enregistré. Enregistrez les intégrations pour l’appliquer.", integrationsAccountRemoved: "Compte supprimé. Enregistrez les intégrations pour l’appliquer.",
|
|
84
84
|
integrationsLastError: "Dernière erreur", integrationsEdit: "Modifier", integrationsRemove: "Retirer",
|
|
85
85
|
integrationsInvalidJson: "Le JSON des règles est invalide vers la ligne {line}.", integrationsInvalidRules: "Les règles doivent être un tableau JSON.",
|
|
@@ -78,7 +78,7 @@ export const it = {
|
|
|
78
78
|
integrationsAddEnv: "Aggiungi variabile", integrationsClearEnv: "Cancella tutte le variabili", integrationsKeepEnv: "Mantieni tutte le variabili",
|
|
79
79
|
integrationsClearEnvActive: "Tutte le variabili salvate verranno cancellate al salvataggio.", integrationsEnvInvalid: "Usa nomi di variabile univoci con lettere, numeri e trattini bassi.",
|
|
80
80
|
integrationsAccountTitle: "Account di integrazione", integrationsAccountId: "ID account", integrationsPlatform: "Piattaforma",
|
|
81
|
-
integrationsAccountInvalid: "
|
|
81
|
+
integrationsAccountInvalid: "Scegli un plugin.", integrationsDuplicateAccount: "Esiste già un account con questo ID.",
|
|
82
82
|
integrationsAccountSaved: "Account salvato. Salva le integrazioni per applicarlo.", integrationsAccountRemoved: "Account rimosso. Salva le integrazioni per applicarlo.",
|
|
83
83
|
integrationsLastError: "Ultimo errore", integrationsEdit: "Modifica", integrationsRemove: "Rimuovi",
|
|
84
84
|
integrationsInvalidJson: "Il JSON delle regole non è valido vicino alla riga {line}.", integrationsInvalidRules: "Le regole devono essere un array JSON.",
|
|
@@ -79,7 +79,7 @@ export const ja = {
|
|
|
79
79
|
integrationsAddEnv: "変数を追加", integrationsClearEnv: "すべての変数を消去", integrationsKeepEnv: "すべての変数を保持",
|
|
80
80
|
integrationsClearEnvActive: "保存時に保存済みの変数がすべて消去されます。", integrationsEnvInvalid: "変数名は英数字とアンダースコアのみの一意な名前にしてください。",
|
|
81
81
|
integrationsAccountTitle: "連携アカウント", integrationsAccountId: "アカウント ID", integrationsPlatform: "プラットフォーム",
|
|
82
|
-
integrationsAccountInvalid: "
|
|
82
|
+
integrationsAccountInvalid: "プラグインを選択してください。", integrationsDuplicateAccount: "この ID のアカウントは既に存在します。",
|
|
83
83
|
integrationsAccountSaved: "アカウントを保存しました。連携を保存すると反映されます。", integrationsAccountRemoved: "アカウントを削除しました。連携を保存すると反映されます。",
|
|
84
84
|
integrationsLastError: "最後のエラー", integrationsEdit: "編集", integrationsRemove: "削除",
|
|
85
85
|
integrationsInvalidJson: "ルール JSON の {line} 行目付近が無効です。", integrationsInvalidRules: "ルールは JSON 配列である必要があります。",
|
|
@@ -79,7 +79,7 @@ export const ko = {
|
|
|
79
79
|
integrationsAddEnv: "변수 추가", integrationsClearEnv: "모든 변수 지우기", integrationsKeepEnv: "모든 변수 유지",
|
|
80
80
|
integrationsClearEnvActive: "저장하면 저장된 모든 변수가 지워집니다.", integrationsEnvInvalid: "변수 이름은 문자, 숫자, 밑줄로 만든 고유한 이름을 사용하세요.",
|
|
81
81
|
integrationsAccountTitle: "연동 계정", integrationsAccountId: "계정 ID", integrationsPlatform: "플랫폼",
|
|
82
|
-
integrationsAccountInvalid: "
|
|
82
|
+
integrationsAccountInvalid: "플러그인을 선택하세요.", integrationsDuplicateAccount: "같은 ID의 계정이 이미 있습니다.",
|
|
83
83
|
integrationsAccountSaved: "계정을 저장했습니다. 연동을 저장하면 적용됩니다.", integrationsAccountRemoved: "계정을 제거했습니다. 연동을 저장하면 적용됩니다.",
|
|
84
84
|
integrationsLastError: "마지막 오류", integrationsEdit: "편집", integrationsRemove: "제거",
|
|
85
85
|
integrationsInvalidJson: "규칙 JSON이 {line}행 근처에서 올바르지 않습니다.", integrationsInvalidRules: "규칙은 JSON 배열이어야 합니다.",
|
|
@@ -64,7 +64,7 @@ export function replaceFootnoteTokens(fragment, notes) {
|
|
|
64
64
|
ids.push(id); notes.refIds.set(label, ids);
|
|
65
65
|
const sup = document.createElement("sup"), link = document.createElement("a");
|
|
66
66
|
sup.className = "footnote-ref";
|
|
67
|
-
link.id = id; link.href = `#${notes.idPrefix}-${number}`; link.textContent =
|
|
67
|
+
link.id = id; link.href = `#${notes.idPrefix}-${number}`; link.textContent = `[${number}]`;
|
|
68
68
|
link.setAttribute("role", "doc-noteref");
|
|
69
69
|
sup.append(link); replacement.append(sup);
|
|
70
70
|
}
|
|
@@ -42,6 +42,17 @@ function escapeHtmlText(value) {
|
|
|
42
42
|
return String(value).replace(/[&<>"']/g, (char) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[char]);
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
/**
|
|
46
|
+
* Render plain text that may contain resource markers into attachment cards.
|
|
47
|
+
* System relay rows use this instead of textContent so inbound files stay openable.
|
|
48
|
+
*/
|
|
49
|
+
export function renderResourceText(root, text, app) {
|
|
50
|
+
root.textContent = text;
|
|
51
|
+
for (const resource of replaceResourceMarkers(root, app)) {
|
|
52
|
+
void loadResourceCard(resource.card, resource.roomId, app);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
45
56
|
export function renderMarkdown(root, text, app) {
|
|
46
57
|
const mentions = [], diagrams = new Map();
|
|
47
58
|
const nonce = createRandomId();
|
|
@@ -116,6 +127,18 @@ function decorateCodeBlock(code, app) {
|
|
|
116
127
|
head.append(label);
|
|
117
128
|
}
|
|
118
129
|
head.append(codeToolbar(code, pre, block, app));
|
|
130
|
+
// The floating toolbar sits over the code's top-right corner. Hide it while a
|
|
131
|
+
// pointer drag starts inside the code so pointerup selects code, not the toolbar.
|
|
132
|
+
pre.addEventListener("pointerdown", () => {
|
|
133
|
+
head.classList.add("is-selecting");
|
|
134
|
+
const done = () => {
|
|
135
|
+
head.classList.remove("is-selecting");
|
|
136
|
+
window.removeEventListener("pointerup", done, true);
|
|
137
|
+
window.removeEventListener("pointercancel", done, true);
|
|
138
|
+
};
|
|
139
|
+
window.addEventListener("pointerup", done, true);
|
|
140
|
+
window.addEventListener("pointercancel", done, true);
|
|
141
|
+
});
|
|
119
142
|
block.append(head, pre);
|
|
120
143
|
}
|
|
121
144
|
|
|
@@ -218,6 +218,7 @@ export function initMessages(app) {
|
|
|
218
218
|
? app.state.room.participants.find((person) => person.id === message.senderId)?.name || app.t("guest")
|
|
219
219
|
: message.senderId;
|
|
220
220
|
row.className = `msg${own ? " own" : ""}`;
|
|
221
|
+
row.dataset.initial = Array.from((own ? app.state.myName : sender).trim())[0]?.toLocaleUpperCase() || "?";
|
|
221
222
|
const meta = document.createElement("div"), name = document.createElement("span"), time = document.createElement("span");
|
|
222
223
|
meta.className = "msg-meta";
|
|
223
224
|
name.className = "msg-name";
|
|
@@ -336,7 +336,12 @@ export function initPalette(app) {
|
|
|
336
336
|
input.addEventListener("compositionend", () => scheduleSearch());
|
|
337
337
|
scopeButton.addEventListener("click", () => { toggleScope(); input.focus(); });
|
|
338
338
|
app.$("#btnClosePalette")?.addEventListener("click", () => closePalette());
|
|
339
|
-
|
|
339
|
+
let dismissPress = false;
|
|
340
|
+
dialog.addEventListener("pointerdown", (event) => { dismissPress = event.target === dialog; });
|
|
341
|
+
dialog.addEventListener("click", (event) => {
|
|
342
|
+
if (event.target === dialog && dismissPress) closePalette();
|
|
343
|
+
dismissPress = false;
|
|
344
|
+
});
|
|
340
345
|
dialog.addEventListener("cancel", (event) => { event.preventDefault(); closePalette(); });
|
|
341
346
|
dialog.addEventListener("close", () => {
|
|
342
347
|
clearTimeout(searchTimer);
|
|
@@ -6,7 +6,7 @@ const PANE_QUERY = "(min-width: 1100px) and (min-height: 560px)";
|
|
|
6
6
|
export function initPanels(app) {
|
|
7
7
|
const $ = app.$;
|
|
8
8
|
const pane = matchMedia(PANE_QUERY);
|
|
9
|
-
const watchers = new Map(), surfaces = new Map();
|
|
9
|
+
const watchers = new Map(), surfaces = new Map(), dismissibles = new Map();
|
|
10
10
|
const readModes = () => {
|
|
11
11
|
const stored = app.LS.panelMode;
|
|
12
12
|
return Object.fromEntries(Object.entries(PANEL_DEFAULTS)
|
|
@@ -26,11 +26,31 @@ export function initPanels(app) {
|
|
|
26
26
|
// Settings is modal; layout changes behind it wait until it closes.
|
|
27
27
|
if (!app.settingsOpen?.()) notify(kind);
|
|
28
28
|
};
|
|
29
|
-
app.registerPanelSurface = (kind, handlers) =>
|
|
29
|
+
app.registerPanelSurface = (kind, handlers) => {
|
|
30
|
+
surfaces.set(kind, handlers);
|
|
31
|
+
dismissibles.set(kind, handlers);
|
|
32
|
+
};
|
|
33
|
+
app.registerDismissibleSurface = (id, handlers) => dismissibles.set(id, handlers);
|
|
30
34
|
app.closeOtherPanelSurfaces = (except) => {
|
|
31
|
-
for (const [kind, surface] of surfaces) if (kind !== except) surface.close?.();
|
|
35
|
+
for (const [kind, surface] of surfaces) if (kind !== except) surface.close?.(false);
|
|
32
36
|
app.closeDocPreview?.(false);
|
|
33
37
|
};
|
|
38
|
+
// Alt+Esc closes the top right-hand surface. A modal dialog above it keeps
|
|
39
|
+
// ownership of the key, and IME composition never closes the pane.
|
|
40
|
+
app.dismissTopSurface = () => {
|
|
41
|
+
const top = [...dismissibles.values()].find((surface) => surface.element?.open && surface.element.getClientRects().length);
|
|
42
|
+
if (!top) return false;
|
|
43
|
+
if ([...document.querySelectorAll("dialog[open]:modal")].some((dialog) => dialog !== top.element)) return "blocked";
|
|
44
|
+
top.close?.(true);
|
|
45
|
+
return "closed";
|
|
46
|
+
};
|
|
47
|
+
document.addEventListener("keydown", (event) => {
|
|
48
|
+
if (event.defaultPrevented || event.isComposing || event.keyCode === 229) return;
|
|
49
|
+
if (!event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) return;
|
|
50
|
+
if (event.key !== "Escape" && event.code !== "Escape") return;
|
|
51
|
+
if (!app.dismissTopSurface()) return;
|
|
52
|
+
event.preventDefault();
|
|
53
|
+
});
|
|
34
54
|
pane.addEventListener("change", () => {
|
|
35
55
|
// Keep the settings modal on top; its close listener re-syncs every surface.
|
|
36
56
|
if (app.settingsOpen?.()) return;
|