@alexsun-top/opencode-chat-room 0.8.3 → 0.8.5
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 +7 -1
- package/README.md +5 -5
- package/README.zh-CN.md +5 -5
- package/cli.ts +1 -1
- package/dist/cli.js +35 -16
- package/package.json +15 -9
- package/packages/chat-room-channeld/README.md +3 -2
- package/packages/chat-room-channeld/src/inbound.ts +3 -6
- package/packages/chat-room-channeld/src/pg/sql.mjs +157 -142
- package/packages/chat-room-channeld/src/pg/sql.mts +175 -0
- package/packages/chat-room-channeld/src/pg/worker.mjs +107 -99
- package/packages/chat-room-channeld/src/pg/worker.mts +166 -0
- package/plugin.ts +1 -1
- package/server/assets/chat/admin-badge.js +1 -1
- package/server/assets/chat/admin.js +16 -10
- package/server/assets/chat/announcements.js +12 -2
- package/server/assets/chat/attachment-store.js +15 -6
- package/server/assets/chat/attachments.js +48 -33
- package/server/assets/chat/chat-background.js +8 -14
- package/server/assets/chat/clipboard.js +2 -1
- package/server/assets/chat/confirm-dialog.js +3 -3
- package/server/assets/chat/copy-action.js +1 -2
- package/server/assets/chat/diagram-viewer.js +7 -9
- package/server/assets/chat/doc-preview.js +19 -12
- package/server/assets/chat/editor.js +87 -61
- package/server/assets/chat/events.js +49 -34
- package/server/assets/chat/files.js +45 -13
- package/server/assets/chat/history-loader.js +5 -3
- package/server/assets/chat/image-zoom.js +21 -17
- package/server/assets/chat/install-prompt.js +10 -9
- package/server/assets/chat/integration-account-schema.js +5 -3
- package/server/assets/chat/integration-editor.js +2 -2
- package/server/assets/chat/integration-values.js +17 -11
- package/server/assets/chat/integrations.js +138 -81
- package/server/assets/chat/join-requests.js +20 -13
- package/server/assets/chat/markdown-footnotes.js +8 -8
- package/server/assets/chat/markdown.js +48 -38
- package/server/assets/chat/members.js +48 -25
- package/server/assets/chat/mentions.js +39 -12
- package/server/assets/chat/message-cache.js +2 -2
- package/server/assets/chat/message-polling.js +40 -21
- package/server/assets/chat/message-window.js +10 -6
- package/server/assets/chat/messages.js +70 -46
- package/server/assets/chat/office-preview.js +3 -3
- package/server/assets/chat/palette.js +45 -29
- package/server/assets/chat/panels.js +19 -1
- package/server/assets/chat/pwa.js +5 -4
- package/server/assets/chat/questions.js +25 -22
- package/server/assets/chat/recall.js +39 -21
- package/server/assets/chat/receipts.js +9 -7
- package/server/assets/chat/reminders.js +25 -8
- package/server/assets/chat/replies.js +34 -15
- package/server/assets/chat/resource-format.js +2 -2
- package/server/assets/chat/room-list.js +2 -2
- package/server/assets/chat/room-watcher.js +8 -4
- package/server/assets/chat/rooms.js +51 -40
- package/server/assets/chat/search.js +8 -6
- package/server/assets/chat/settings.js +16 -14
- package/server/assets/chat/shiki.js +1 -1
- package/server/assets/chat/shortcuts.js +3 -3
- package/server/assets/chat/side-pane.js +4 -3
- package/server/assets/chat/state.js +65 -37
- package/server/assets/chat/system-events.js +6 -5
- package/server/assets/chat/system-messages.js +15 -15
- package/server/assets/chat/task-form.js +5 -5
- package/server/assets/chat/task-row.js +1 -1
- package/server/assets/chat/tasks.js +41 -28
- package/server/assets/chat/window-controls.js +3 -2
- package/server/assets/conversation.css +14 -2
- package/server/assets/doc-preview.css +6 -0
- package/server/assets/office/THIRD-PARTY-NOTICES.txt +23 -1
- package/server/assets/office/licenses/docx-preview-HEADER.txt +6 -0
- package/server/assets/office/licenses/echarts-LICENSE-d3.txt +27 -0
- package/server/assets/office/licenses/echarts-NOTICE.txt +5 -0
- package/server/assets/office/licenses/immediate-LICENSE.txt +20 -0
- package/server/assets/office/licenses/lie-LICENSE.txt +7 -0
- package/server/assets/office/licenses/pako-LICENSE.txt +21 -0
- package/server/assets/office/licenses/pako-ZLIB.txt +18 -0
- package/server/assets/office/licenses/setimmediate-LICENSE.txt +20 -0
- package/server/chat.html +1 -0
- package/server/sw.js +3 -1
- package/skills/chatroom/SKILL.md +9 -0
- package/src/README.md +1 -1
- package/src/agent/agent-receipts.ts +12 -4
- package/src/center/center-client.ts +1 -1
- package/src/state/pg-sql.mjs +157 -142
- package/src/state/pg-sql.mts +175 -0
- package/src/state/pg-worker.mjs +107 -99
- package/src/state/pg-worker.mts +166 -0
- package/src/state/store.ts +21 -7
- package/src/tui/app-types.mjs +1 -0
- package/src/tui/app-types.mts +175 -0
- package/src/tui/app.mjs +426 -423
- package/src/tui/app.mts +500 -0
- package/src/tui/config.mjs +166 -158
- package/src/tui/config.mts +247 -0
- package/src/tui/http.mjs +239 -206
- package/src/tui/http.mts +412 -0
- package/src/tui/i18n.mjs +17 -20
- package/src/tui/i18n.mts +42 -0
- package/src/tui/info-app.mjs +431 -427
- package/src/tui/info-app.mts +500 -0
- package/src/tui/info-content.mjs +205 -199
- package/src/tui/info-content.mts +341 -0
- package/src/tui/join-app.mjs +75 -64
- package/src/tui/join-app.mts +99 -0
- package/src/tui/locales/en.mjs +302 -320
- package/src/tui/locales/en.mts +349 -0
- package/src/tui/locales/zh-CN.mjs +302 -320
- package/src/tui/locales/zh-CN.mts +349 -0
- package/src/tui/main.mjs +219 -213
- package/src/tui/main.mts +255 -0
- package/src/tui/markdown.mjs +128 -272
- package/src/tui/markdown.mts +152 -0
- package/src/tui/mentions.mjs +181 -184
- package/src/tui/mentions.mts +251 -0
- package/src/tui/message-app.mjs +181 -173
- package/src/tui/message-app.mts +213 -0
- package/src/tui/message-view.mjs +90 -111
- package/src/tui/message-view.mts +151 -0
- package/src/tui/messages.mjs +55 -49
- package/src/tui/messages.mts +106 -0
- package/src/tui/palette-app.mjs +364 -344
- package/src/tui/palette-app.mts +388 -0
- package/src/tui/palette.mjs +100 -98
- package/src/tui/palette.mts +176 -0
- package/src/tui/prefs.mjs +56 -63
- package/src/tui/prefs.mts +126 -0
- package/src/tui/reminder-app.mjs +191 -181
- package/src/tui/reminder-app.mts +228 -0
- package/src/tui/room-settings-app.mjs +257 -242
- package/src/tui/room-settings-app.mts +301 -0
- package/src/tui/session.mjs +30 -29
- package/src/tui/session.mts +51 -0
- package/src/tui/settings-app.mjs +151 -138
- package/src/tui/settings-app.mts +179 -0
- package/src/tui/ui-content.mjs +426 -421
- package/src/tui/ui-content.mts +499 -0
- package/src/tui/ui-help.mjs +58 -67
- package/src/tui/ui-help.mts +87 -0
- package/src/tui/ui-mentions.mjs +34 -36
- package/src/tui/ui-mentions.mts +60 -0
- package/src/tui/ui-overlay-view.mjs +259 -267
- package/src/tui/ui-overlay-view.mts +322 -0
- package/src/tui/ui-suggest-view.mjs +54 -57
- package/src/tui/ui-suggest-view.mts +78 -0
- package/src/tui/ui-suggest.mjs +164 -167
- package/src/tui/ui-suggest.mts +248 -0
- package/src/tui/ui-theme.mjs +52 -57
- package/src/tui/ui-theme.mts +98 -0
- package/src/tui/ui-view.mjs +267 -275
- package/src/tui/ui-view.mts +308 -0
- package/src/tui/ui.mjs +372 -359
- package/src/tui/ui.mts +440 -0
- package/src/tui/wire.mjs +215 -0
- package/src/tui/wire.mts +383 -0
|
@@ -6,22 +6,29 @@ const MAX_BUFFERED_BYTES = 32 * 1024 * 1024; // Pasted files are small; larger o
|
|
|
6
6
|
const TEXT_LIMIT = 5000;
|
|
7
7
|
const previewTypes = new Set(["image/png", "image/jpeg", "image/gif", "image/webp", "image/avif", "image/bmp"]);
|
|
8
8
|
export function initAttachments(app) {
|
|
9
|
-
const $ =
|
|
9
|
+
const $ = (selector) => {
|
|
10
|
+
const node = app.$(selector);
|
|
11
|
+
if (!node)
|
|
12
|
+
throw new Error(`Missing ${selector}`);
|
|
13
|
+
return node;
|
|
14
|
+
};
|
|
15
|
+
const input = $("#msgInput"), list = $("#attachmentList"), tray = $("#attachmentTray"), picker = $("#attachmentPicker");
|
|
10
16
|
const drafts = new Map();
|
|
11
17
|
const statuses = new Map();
|
|
12
|
-
app.state.sendingRooms ||= new Set();
|
|
18
|
+
const sendingRooms = (app.state.sendingRooms ||= new Set());
|
|
13
19
|
let limit = null, configRequest = null, activeUploads = 0, eagerQueued = 0;
|
|
14
20
|
const converting = new Set(), restoring = new Set(), uploadWaiters = new Map();
|
|
15
21
|
let editorLock = null, unloadGuard = false;
|
|
16
22
|
const roomId = () => app.state.room?.id || "";
|
|
17
23
|
const filesFor = (id) => drafts.get(id) || [];
|
|
18
|
-
const
|
|
19
|
-
const
|
|
24
|
+
const resources = (items) => items.flatMap((item) => item.resource ? [item.resource] : []);
|
|
25
|
+
const markers = (items) => resources(items).map((resource) => `[[resource:${resource.id}]]`);
|
|
26
|
+
const validResource = (resource, id) => /^[\da-f]{8}-[\da-f]{4}-[1-8][\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$/i.test(resource?.id ?? "") && resource?.roomID === id;
|
|
20
27
|
// crypto.randomUUID needs a secure context; the chat also runs on plain-HTTP LANs.
|
|
21
28
|
function newUploadID() {
|
|
22
29
|
const bytes = crypto.getRandomValues(new Uint8Array(16));
|
|
23
|
-
bytes[6] = (bytes[6] & 0x0f) | 0x40;
|
|
24
|
-
bytes[8] = (bytes[8] & 0x3f) | 0x80;
|
|
30
|
+
bytes[6] = ((bytes[6] ?? 0) & 0x0f) | 0x40;
|
|
31
|
+
bytes[8] = ((bytes[8] ?? 0) & 0x3f) | 0x80;
|
|
25
32
|
const hex = [...bytes].map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
26
33
|
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
27
34
|
}
|
|
@@ -67,7 +74,7 @@ export function initAttachments(app) {
|
|
|
67
74
|
}
|
|
68
75
|
const textFor = (id, caption) => {
|
|
69
76
|
const parts = [String(caption || "").trim(), ...markers(filesFor(id))].filter(Boolean);
|
|
70
|
-
return { text: parts.join("\n\n"), ids: filesFor(id)
|
|
77
|
+
return { text: parts.join("\n\n"), ids: resources(filesFor(id)).map((resource) => resource.id) };
|
|
71
78
|
};
|
|
72
79
|
function formatSize(size) {
|
|
73
80
|
if (size < 1024)
|
|
@@ -168,7 +175,7 @@ export function initAttachments(app) {
|
|
|
168
175
|
finally {
|
|
169
176
|
restoring.delete(id);
|
|
170
177
|
if (roomId() === id)
|
|
171
|
-
app.updateSendState();
|
|
178
|
+
app.updateSendState?.();
|
|
172
179
|
}
|
|
173
180
|
}
|
|
174
181
|
function lockComposer() {
|
|
@@ -193,29 +200,31 @@ export function initAttachments(app) {
|
|
|
193
200
|
if (selection)
|
|
194
201
|
input.setSelectionRange?.(selection[0], selection[1]);
|
|
195
202
|
}
|
|
203
|
+
// The composer keeps the whole draft item as its conversion; PreparedMessage
|
|
204
|
+
// only advertises a File, so assign through a view that accepts the wider value.
|
|
196
205
|
app.prepareMessage = prepareMessage;
|
|
197
206
|
const baseDraftCount = app.updateDraftCount;
|
|
198
207
|
app.updateDraftCount = () => {
|
|
199
208
|
if (!roomId()) {
|
|
200
209
|
$("#draftCount").classList.remove("over-limit");
|
|
201
|
-
return baseDraftCount();
|
|
210
|
+
return baseDraftCount?.();
|
|
202
211
|
}
|
|
203
212
|
const count = textFor(roomId(), input.value).text.length;
|
|
204
213
|
app.setText($("#draftCount"), "messageCount", { count });
|
|
205
214
|
$("#draftCount").classList.toggle("over-limit", count > TEXT_LIMIT);
|
|
206
215
|
};
|
|
207
216
|
app.updateSendState = () => {
|
|
208
|
-
const id = roomId(), message = id
|
|
209
|
-
$("#btnSend").disabled = !id || !(message?.ready || message?.canConvert) ||
|
|
217
|
+
const id = roomId(), message = id ? prepareMessage(id, input.value) : null;
|
|
218
|
+
$("#btnSend").disabled = !id || !(message?.ready || message?.canConvert) || sendingRooms.has(id) || converting.has(id) || restoring.has(id);
|
|
210
219
|
};
|
|
211
220
|
app.completeAttachments = (id, resourceIDs) => {
|
|
212
|
-
const used = new Set(resourceIDs), items = filesFor(id), removed = items.filter((item) => used.has(item.resource?.id));
|
|
221
|
+
const used = new Set(resourceIDs), items = filesFor(id), removed = items.filter((item) => used.has(item.resource?.id ?? ""));
|
|
213
222
|
for (const item of removed) {
|
|
214
223
|
forget(item);
|
|
215
224
|
if (item.previewUrl)
|
|
216
225
|
URL.revokeObjectURL(item.previewUrl);
|
|
217
226
|
}
|
|
218
|
-
const remaining = items.filter((item) => !used.has(item.resource?.id));
|
|
227
|
+
const remaining = items.filter((item) => !used.has(item.resource?.id ?? ""));
|
|
219
228
|
if (remaining.length)
|
|
220
229
|
drafts.set(id, remaining);
|
|
221
230
|
else {
|
|
@@ -225,7 +234,7 @@ export function initAttachments(app) {
|
|
|
225
234
|
if (roomId() === id)
|
|
226
235
|
render();
|
|
227
236
|
};
|
|
228
|
-
app.completeAttachmentsFromText = (id, text) => app.completeAttachments(id, [...String(text).matchAll(/\[\[resource:([\da-f-]{36})\]\]/gi)].map((match) => match[1]));
|
|
237
|
+
app.completeAttachmentsFromText = (id, text) => app.completeAttachments?.(id, [...String(text).matchAll(/\[\[resource:([\da-f-]{36})\]\]/gi)].map((match) => match[1] ?? ""));
|
|
229
238
|
const applyLocale = app.applyLocale;
|
|
230
239
|
app.applyLocale = () => { applyLocale(); updateLocale(); };
|
|
231
240
|
function updateLocale() {
|
|
@@ -235,7 +244,9 @@ export function initAttachments(app) {
|
|
|
235
244
|
if (!row)
|
|
236
245
|
return;
|
|
237
246
|
const detail = row.querySelector(".attachment-detail"), progress = row.querySelector("progress");
|
|
238
|
-
|
|
247
|
+
if (!detail || !progress)
|
|
248
|
+
return;
|
|
249
|
+
detail.textContent = `${formatSize(item.file.size)} · ${item.status === "failed" ? app.t(item.errorKey ?? "", item.errorValues || {}) : item.status === "uploaded" ? app.t("uploadReady") : item.status === "uploading" ? app.t("uploadPercent", { percent: item.percent || 0 }) : app.t("uploadQueued")}`;
|
|
239
250
|
const retry = row.querySelector('[data-upload-action="retry"]');
|
|
240
251
|
if (retry) {
|
|
241
252
|
retry.textContent = app.t("retryUpload");
|
|
@@ -265,8 +276,8 @@ export function initAttachments(app) {
|
|
|
265
276
|
list.replaceChildren();
|
|
266
277
|
items.forEach((item, index) => { const row = renderItem(item); row.dataset.index = String(index); list.append(row); });
|
|
267
278
|
updateDurability();
|
|
268
|
-
app.updateDraftCount();
|
|
269
|
-
app.updateSendState();
|
|
279
|
+
app.updateDraftCount?.();
|
|
280
|
+
app.updateSendState?.();
|
|
270
281
|
});
|
|
271
282
|
}
|
|
272
283
|
app.renderAttachments = render;
|
|
@@ -287,7 +298,7 @@ export function initAttachments(app) {
|
|
|
287
298
|
name.className = "attachment-name";
|
|
288
299
|
name.textContent = item.file.name;
|
|
289
300
|
detail.className = `attachment-detail${item.status === "failed" ? " attachment-over-limit" : ""}`;
|
|
290
|
-
detail.textContent = `${formatSize(item.file.size)} · ${item.status === "failed" ? app.t(item.errorKey, item.errorValues || {}) : item.status === "uploaded" ? app.t("uploadReady") : item.status === "uploading" ? app.t("uploadPercent", { percent: item.percent || 0 }) : app.t("uploadQueued")}`;
|
|
301
|
+
detail.textContent = `${formatSize(item.file.size)} · ${item.status === "failed" ? app.t(item.errorKey ?? "", item.errorValues || {}) : item.status === "uploaded" ? app.t("uploadReady") : item.status === "uploading" ? app.t("uploadPercent", { percent: item.percent || 0 }) : app.t("uploadQueued")}`;
|
|
291
302
|
progress.max = item.file.size || 1;
|
|
292
303
|
progress.value = item.loaded || 0;
|
|
293
304
|
progress.hidden = item.status !== "uploading";
|
|
@@ -347,11 +358,12 @@ export function initAttachments(app) {
|
|
|
347
358
|
return Promise.resolve(limit);
|
|
348
359
|
if (!configRequest || refresh) {
|
|
349
360
|
const request = app.api("/resources/config").then((data) => {
|
|
350
|
-
|
|
361
|
+
const size = data.maxFileSizeBytes;
|
|
362
|
+
if (typeof size !== "number" || !Number.isSafeInteger(size) || size < 1)
|
|
351
363
|
throw new Error("Invalid upload limit");
|
|
352
364
|
if (configRequest === request)
|
|
353
|
-
limit =
|
|
354
|
-
return
|
|
365
|
+
limit = size;
|
|
366
|
+
return size;
|
|
355
367
|
}).finally(() => { if (configRequest === request)
|
|
356
368
|
configRequest = null; });
|
|
357
369
|
configRequest = request;
|
|
@@ -423,15 +435,16 @@ export function initAttachments(app) {
|
|
|
423
435
|
releaseBuffer(item);
|
|
424
436
|
if (item.cancelled)
|
|
425
437
|
return;
|
|
426
|
-
|
|
438
|
+
const failure = error;
|
|
439
|
+
if (failure.status === 413) {
|
|
427
440
|
limit = null;
|
|
428
441
|
item.errorKey = "fileTooLarge";
|
|
429
442
|
}
|
|
430
|
-
else if (
|
|
443
|
+
else if (failure.unreadable)
|
|
431
444
|
item.errorKey = "fileUnreadable";
|
|
432
445
|
else {
|
|
433
446
|
item.errorKey = "uploadFailed";
|
|
434
|
-
item.errorValues = { reason:
|
|
447
|
+
item.errorValues = { reason: failure.status ? `HTTP ${failure.status}` : failure.timeout ? "timeout" : failure.network ? "network" : failure.message };
|
|
435
448
|
}
|
|
436
449
|
item.status = "failed";
|
|
437
450
|
if (roomId() === id)
|
|
@@ -452,7 +465,8 @@ export function initAttachments(app) {
|
|
|
452
465
|
return await upload(id, item);
|
|
453
466
|
}
|
|
454
467
|
catch (error) {
|
|
455
|
-
|
|
468
|
+
const failure = error;
|
|
469
|
+
if (!failure.network || item.cancelled || item.retried)
|
|
456
470
|
throw error;
|
|
457
471
|
item.retried = true;
|
|
458
472
|
item.loaded = 0;
|
|
@@ -578,7 +592,7 @@ export function initAttachments(app) {
|
|
|
578
592
|
const baseSend = app.send;
|
|
579
593
|
app.send = async () => {
|
|
580
594
|
const id = roomId();
|
|
581
|
-
if (!id || converting.has(id) || restoring.has(id) ||
|
|
595
|
+
if (!id || converting.has(id) || restoring.has(id) || sendingRooms.has(id))
|
|
582
596
|
return false;
|
|
583
597
|
const message = prepareMessage(id, input.value);
|
|
584
598
|
if (!message.canConvert)
|
|
@@ -624,8 +638,8 @@ export function initAttachments(app) {
|
|
|
624
638
|
converting.delete(id);
|
|
625
639
|
if (roomId() === id) {
|
|
626
640
|
unlockComposer();
|
|
627
|
-
app.updateDraftCount();
|
|
628
|
-
app.updateSendState();
|
|
641
|
+
app.updateDraftCount?.();
|
|
642
|
+
app.updateSendState?.();
|
|
629
643
|
}
|
|
630
644
|
else
|
|
631
645
|
editorLock = null;
|
|
@@ -653,7 +667,7 @@ export function initAttachments(app) {
|
|
|
653
667
|
$("#btnAddAttachments").addEventListener("click", () => picker.click());
|
|
654
668
|
picker.addEventListener("change", () => { addFiles(picker.files || []); picker.value = ""; });
|
|
655
669
|
list.addEventListener("click", (event) => {
|
|
656
|
-
const button = event.target.closest
|
|
670
|
+
const button = event.target instanceof Element ? event.target.closest("[data-upload-action]") : null;
|
|
657
671
|
if (!button)
|
|
658
672
|
return;
|
|
659
673
|
const id = roomId(), index = Number(button.closest(".attachment-item")?.dataset.index), item = filesFor(id)[index];
|
|
@@ -675,10 +689,11 @@ export function initAttachments(app) {
|
|
|
675
689
|
chatView.addEventListener("dragenter", (event) => { if (!hasFiles(event))
|
|
676
690
|
return; event.preventDefault(); showDrop(); });
|
|
677
691
|
chatView.addEventListener("dragover", (event) => { if (!hasFiles(event))
|
|
678
|
-
return; event.preventDefault(); event.dataTransfer
|
|
679
|
-
|
|
692
|
+
return; event.preventDefault(); if (event.dataTransfer)
|
|
693
|
+
event.dataTransfer.dropEffect = "copy"; showDrop(); });
|
|
694
|
+
chatView.addEventListener("dragleave", (event) => { if (hasFiles(event) && !(event.relatedTarget instanceof Node && chatView.contains(event.relatedTarget)))
|
|
680
695
|
clearDrop(); });
|
|
681
|
-
chatView.addEventListener("drop", (event) => { if (!hasFiles(event))
|
|
696
|
+
chatView.addEventListener("drop", (event) => { if (!hasFiles(event) || !event.dataTransfer)
|
|
682
697
|
return; event.preventDefault(); clearDrop(); addFiles(event.dataTransfer.files); });
|
|
683
698
|
// Capture before the editor's paste handler: an oversized paste never enters the DOM.
|
|
684
699
|
input.addEventListener("paste", (event) => {
|
|
@@ -693,7 +708,7 @@ export function initAttachments(app) {
|
|
|
693
708
|
const images = Array.from(event.clipboardData?.items || []).filter((item) => item.kind === "file" && item.type.startsWith("image/")).map((item) => item.getAsFile()).filter(Boolean);
|
|
694
709
|
if (!images.length)
|
|
695
710
|
return;
|
|
696
|
-
if (!event.clipboardData
|
|
711
|
+
if (!event.clipboardData?.getData("text/plain"))
|
|
697
712
|
event.preventDefault();
|
|
698
713
|
addFiles(images, true);
|
|
699
714
|
}, true);
|
|
@@ -8,8 +8,9 @@ const clampOpacity = (value) => {
|
|
|
8
8
|
const number = Number(value);
|
|
9
9
|
return Number.isFinite(number) ? Math.min(100, Math.max(0, Math.round(number))) : DEFAULT_OPACITY;
|
|
10
10
|
};
|
|
11
|
+
const isRecord = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
11
12
|
const normalize = (value) => {
|
|
12
|
-
if (!
|
|
13
|
+
if (!isRecord(value))
|
|
13
14
|
return null;
|
|
14
15
|
const opacity = clampOpacity(value.opacity);
|
|
15
16
|
if (value.kind === "image" && typeof value.image === "string" && value.image.startsWith("data:image/") && value.image.length <= MAX_DATA_URL_LENGTH) {
|
|
@@ -28,10 +29,7 @@ const readStored = () => {
|
|
|
28
29
|
};
|
|
29
30
|
const writeStored = (value) => {
|
|
30
31
|
try {
|
|
31
|
-
|
|
32
|
-
localStorage.setItem(GLOBAL_KEY, JSON.stringify(value));
|
|
33
|
-
else
|
|
34
|
-
localStorage.removeItem(GLOBAL_KEY);
|
|
32
|
+
localStorage.setItem(GLOBAL_KEY, JSON.stringify(value));
|
|
35
33
|
return true;
|
|
36
34
|
}
|
|
37
35
|
catch {
|
|
@@ -67,7 +65,7 @@ export function initChatBackground(app) {
|
|
|
67
65
|
const opacityField = $("#chatBackgroundOpacityField");
|
|
68
66
|
const preview = $("#chatBackgroundPreview"), fileName = $("#chatBackgroundFileName");
|
|
69
67
|
const status = $("#chatBackgroundStatus");
|
|
70
|
-
if (!dialog || !mode || !imageInput || !opacity || !imageField || !opacityField || !preview || !status)
|
|
68
|
+
if (!dialog || !mode || !imageInput || !opacity || !opacityValue || !imageField || !opacityField || !preview || !fileName || !status)
|
|
71
69
|
return;
|
|
72
70
|
let previewURL = null;
|
|
73
71
|
const clearPreview = () => {
|
|
@@ -77,10 +75,8 @@ export function initChatBackground(app) {
|
|
|
77
75
|
}
|
|
78
76
|
preview.hidden = true;
|
|
79
77
|
preview.removeAttribute("src");
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
fileName.textContent = "";
|
|
83
|
-
}
|
|
78
|
+
fileName.hidden = true;
|
|
79
|
+
fileName.textContent = "";
|
|
84
80
|
};
|
|
85
81
|
const setPreview = (src, name) => {
|
|
86
82
|
if (previewURL) {
|
|
@@ -89,10 +85,8 @@ export function initChatBackground(app) {
|
|
|
89
85
|
}
|
|
90
86
|
preview.src = src;
|
|
91
87
|
preview.hidden = false;
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
fileName.hidden = !name;
|
|
95
|
-
}
|
|
88
|
+
fileName.textContent = name || "";
|
|
89
|
+
fileName.hidden = !name;
|
|
96
90
|
};
|
|
97
91
|
const setStatus = (key, values, error = false) => {
|
|
98
92
|
status.classList.toggle("is-error", error);
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
// Clipboard writes with a legacy fallback for browsers or permissions that block
|
|
2
2
|
// the async Clipboard API. Mention copy keeps its marker HTML for later pastes.
|
|
3
|
+
const ESCAPES = { "&": "&", "<": "<", ">": ">", '"': """ };
|
|
3
4
|
export async function copyTextToClipboard(text, mentionSource = false) {
|
|
4
5
|
// The HTML marker lets a later paste rebuild mention chips; unmarked external text stays literal.
|
|
5
|
-
const html = mentionSource ? `<div data-chatroom-mentions>${String(text).replace(/[&<>"]/g, (char) =>
|
|
6
|
+
const html = mentionSource ? `<div data-chatroom-mentions>${String(text).replace(/[&<>"]/g, (char) => ESCAPES[char] ?? char)}</div>` : "";
|
|
6
7
|
try {
|
|
7
8
|
if (html && navigator.clipboard?.write && typeof ClipboardItem !== "undefined") {
|
|
8
9
|
await navigator.clipboard.write([new ClipboardItem({ "text/plain": new Blob([text], { type: "text/plain" }), "text/html": new Blob([html], { type: "text/html" }) })]);
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
// One shared confirmation dialog replaces the browser's native confirmation
|
|
2
|
-
// window, so a destructive action stays inside the page.
|
|
3
1
|
export function initConfirmDialog(app) {
|
|
4
2
|
const dialog = app.$("#confirmDialog"), message = app.$("#confirmMessage");
|
|
5
3
|
const accept = app.$("#btnAcceptConfirm"), cancel = app.$("#btnCancelConfirm");
|
|
4
|
+
if (!dialog || !message || !accept || !cancel)
|
|
5
|
+
return;
|
|
6
6
|
let pending = null, opener = null;
|
|
7
7
|
const settle = (value) => { const resolve = pending; pending = null; resolve?.(value); };
|
|
8
|
-
|
|
8
|
+
const close = (value) => { settle(value); dialog.close(); };
|
|
9
9
|
app.confirmAction = (text) => {
|
|
10
10
|
// One dialog at a time: a newer request dismisses the open one as cancelled.
|
|
11
11
|
if (dialog.open)
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// Copy buttons for resource cards, the file list, and the preview header.
|
|
2
1
|
import { copyTextToClipboard } from "./clipboard.js";
|
|
3
2
|
import { iconNode } from "./icons.js";
|
|
4
3
|
export function createCopyButton(app, className = "") {
|
|
@@ -26,7 +25,7 @@ export function setCopyFeedback(button, app, copied) {
|
|
|
26
25
|
feedback.textContent = app.t(key);
|
|
27
26
|
button.setAttribute("aria-label", app.t(key));
|
|
28
27
|
button.title = app.t(key);
|
|
29
|
-
button._copyFeedbackTimer = setTimeout(() => {
|
|
28
|
+
button._copyFeedbackTimer = window.setTimeout(() => {
|
|
30
29
|
button.classList.remove("is-copied", "is-copy-failed");
|
|
31
30
|
button.setAttribute("aria-label", app.t("copyMessage"));
|
|
32
31
|
button.title = app.t("copyMessage");
|
|
@@ -35,9 +35,9 @@ async function initializeMermaid() {
|
|
|
35
35
|
const script = document.querySelector('script[src$="mermaid-11.12.2.min.js"]');
|
|
36
36
|
if (!script)
|
|
37
37
|
return reject(new Error("Mermaid bundle is missing"));
|
|
38
|
-
script.addEventListener("load", resolve, { once: true });
|
|
38
|
+
script.addEventListener("load", () => resolve(), { once: true });
|
|
39
39
|
script.addEventListener("error", reject, { once: true });
|
|
40
|
-
window.addEventListener("load", resolve, { once: true });
|
|
40
|
+
window.addEventListener("load", () => resolve(), { once: true });
|
|
41
41
|
});
|
|
42
42
|
if (!window.mermaid)
|
|
43
43
|
throw new Error("Mermaid bundle failed to load");
|
|
@@ -71,7 +71,7 @@ export async function renderDiagram(node, source, app) {
|
|
|
71
71
|
throw new Error("Diagram SVG was rejected");
|
|
72
72
|
// The intrinsic width stays in the viewBox; the message column scales it down.
|
|
73
73
|
diagram.removeAttribute("style");
|
|
74
|
-
const update = () => node.replaceChildren(fragment);
|
|
74
|
+
const update = async () => { node.replaceChildren(fragment); };
|
|
75
75
|
if (app.preserveReadingLayout)
|
|
76
76
|
await app.preserveReadingLayout(update);
|
|
77
77
|
else
|
|
@@ -104,8 +104,6 @@ export function showDiagramFallback(node, source, app, loading) {
|
|
|
104
104
|
node.append(pre);
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
|
-
// The overlay shows a sanitized copy of the rendered SVG, so the thread keeps its
|
|
108
|
-
// diagram and only the scale changes. A full-screen dialog keeps the thread in place.
|
|
109
107
|
export function initDiagramViewer(app) {
|
|
110
108
|
const dialog = app.$("#diagramViewer"), body = app.$("#diagramViewerBody"), stage = app.$("#diagramViewerStage");
|
|
111
109
|
if (!dialog || !body || !stage)
|
|
@@ -208,15 +206,15 @@ export function initDiagramViewer(app) {
|
|
|
208
206
|
}
|
|
209
207
|
}
|
|
210
208
|
function diagramSize(svg) {
|
|
211
|
-
const box = svg.viewBox
|
|
209
|
+
const box = svg instanceof SVGSVGElement ? svg.viewBox.baseVal : null;
|
|
212
210
|
let width = box?.width || 0, height = box?.height || 0;
|
|
213
211
|
if (!(width > 0) || !(height > 0)) {
|
|
214
|
-
width = parseFloat(svg.getAttribute("width")) || 0;
|
|
215
|
-
height = parseFloat(svg.getAttribute("height")) || 0;
|
|
212
|
+
width = parseFloat(svg.getAttribute("width") || "") || 0;
|
|
213
|
+
height = parseFloat(svg.getAttribute("height") || "") || 0;
|
|
216
214
|
}
|
|
217
215
|
return { width: width > 0 ? width : 640, height: height > 0 ? height : 420 };
|
|
218
216
|
}
|
|
219
|
-
const outside = (target) => target
|
|
217
|
+
const outside = (target) => target instanceof Element && target.closest(".diagram-viewer-toolbar");
|
|
220
218
|
// Only a press that began on the backdrop closes; a drag out of the canvas does not.
|
|
221
219
|
let dismissPress = false;
|
|
222
220
|
dialog.addEventListener("pointerdown", (event) => { dismissPress = event.target === dialog; });
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// Markdown resources open in a reading pane on wide screens, or in a modal overlay
|
|
2
|
-
// when the window is too narrow or too short to give the chat a usable column.
|
|
3
1
|
import { formatBytes, renderMarkdown } from "./markdown.js";
|
|
4
2
|
import { docPreviewFormat, OFFICE_KINDS, OFFICE_PREVIEW_LIMIT, TEXT_PREVIEW_LIMIT } from "./resource-format.js";
|
|
5
3
|
import { createCopyButton, copyResourceText } from "./copy-action.js";
|
|
@@ -43,14 +41,21 @@ export function initDocPreview(app) {
|
|
|
43
41
|
const dialog = app.$("#docPreview");
|
|
44
42
|
if (!dialog)
|
|
45
43
|
return;
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
44
|
+
const $ = (selector) => {
|
|
45
|
+
const element = app.$(selector);
|
|
46
|
+
if (!element)
|
|
47
|
+
throw new Error(`Missing element: ${selector}`);
|
|
48
|
+
return element;
|
|
49
|
+
};
|
|
50
|
+
const title = $("#docPreviewTitle"), size = $("#docPreviewSize");
|
|
51
|
+
const status = $("#docPreviewStatus"), body = $("#docPreviewBody");
|
|
52
|
+
const empty = $("#docPreviewEmpty"), download = $("#btnDocPreviewDownload");
|
|
53
|
+
const languageLabel = $("#docPreviewLanguage"), notice = $("#docPreviewNotice");
|
|
54
|
+
const eyebrow = $("#docPreviewEyebrow");
|
|
51
55
|
const fullscreenButton = app.$("#btnDocPreviewFullscreen");
|
|
52
|
-
const chatView =
|
|
53
|
-
let current = null, blob = null, objectUrl = null, token = 0
|
|
56
|
+
const chatView = $("#chatView"), pane = matchMedia(PANE_QUERY);
|
|
57
|
+
let current = null, blob = null, objectUrl = null, token = 0;
|
|
58
|
+
let opener = null, openerResourceID = null, restoreOnClose = true;
|
|
54
59
|
let rawText = "", fullscreen = false, paneMode = false;
|
|
55
60
|
let officeKind = null, officeRender = 0, pptxWidth = 0, pptxTimer = 0;
|
|
56
61
|
const copyButton = createCopyButton(app, "doc-preview-copy");
|
|
@@ -237,7 +242,7 @@ export function initDocPreview(app) {
|
|
|
237
242
|
if (width < 200 || Math.abs(width - pptxWidth) < 8)
|
|
238
243
|
return;
|
|
239
244
|
clearTimeout(pptxTimer);
|
|
240
|
-
pptxTimer = setTimeout(() => {
|
|
245
|
+
pptxTimer = window.setTimeout(() => {
|
|
241
246
|
if (dialog.open && officeKind === "pptx" && blob) {
|
|
242
247
|
void renderOfficeDocument("pptx", blob, token, width).catch(() => undefined);
|
|
243
248
|
}
|
|
@@ -378,7 +383,7 @@ export function initDocPreview(app) {
|
|
|
378
383
|
const active = document.activeElement;
|
|
379
384
|
if (active && active !== document.body && active.id !== "msgInput")
|
|
380
385
|
return;
|
|
381
|
-
if (performance.now() < focusReplacement.until) {
|
|
386
|
+
if (performance.now() < (focusReplacement.until ?? 0)) {
|
|
382
387
|
requestAnimationFrame(() => focusReplacement(resourceID, allowComposer));
|
|
383
388
|
return;
|
|
384
389
|
}
|
|
@@ -455,7 +460,9 @@ export function initDocPreview(app) {
|
|
|
455
460
|
dismissPress = false;
|
|
456
461
|
});
|
|
457
462
|
const escapePreview = (event) => {
|
|
458
|
-
|
|
463
|
+
const key = event && "key" in event && typeof event.key === "string" ? event.key : "";
|
|
464
|
+
const altKey = Boolean(event && "altKey" in event && event.altKey);
|
|
465
|
+
if (!event || altKey || key !== "Escape" || !dialog.open)
|
|
459
466
|
return;
|
|
460
467
|
event.preventDefault();
|
|
461
468
|
event.stopPropagation();
|