@alexsun-top/opencode-chat-room 0.8.1 → 0.8.3
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 +33 -0
- package/README.md +18 -62
- package/README.zh-CN.md +25 -69
- package/dist/cli.js +1008 -274
- package/package.json +10 -7
- package/packages/chat-room-channeld/README.md +42 -15
- package/packages/chat-room-channeld/dist/mock-adapter.js +5 -5
- package/packages/chat-room-channeld/src/adapter.ts +150 -7
- package/packages/chat-room-channeld/src/cli.ts +72 -5
- package/packages/chat-room-channeld/src/host.ts +41 -11
- package/packages/chat-room-channeld/src/inbound.ts +13 -4
- package/packages/chat-room-channeld/src/pg/database.ts +187 -0
- package/packages/chat-room-channeld/src/pg/migrate.ts +150 -0
- package/packages/chat-room-channeld/src/pg/schema.ts +60 -0
- package/packages/chat-room-channeld/src/pg/sql.mjs +175 -0
- package/packages/chat-room-channeld/src/pg/sqlite.ts +100 -0
- package/packages/chat-room-channeld/src/pg/worker.mjs +133 -0
- package/packages/chat-room-channeld/src/protocol.ts +53 -1
- package/packages/chat-room-channeld/src/rules.ts +7 -2
- package/packages/chat-room-channeld/src/state.ts +73 -97
- package/packages/chat-room-channeld/src/stats.ts +140 -109
- package/plugin.ts +1 -1
- package/server/assets/base.css +11 -3
- package/server/assets/chat/admin-badge.js +32 -30
- package/server/assets/chat/admin.js +198 -163
- package/server/assets/chat/announcements.js +295 -210
- package/server/assets/chat/attachment-store.js +106 -75
- package/server/assets/chat/attachments.js +686 -441
- package/server/assets/chat/chat-background.js +206 -0
- package/server/assets/chat/clipboard.js +44 -25
- package/server/assets/chat/confirm-dialog.js +36 -34
- package/server/assets/chat/copy-action.js +40 -40
- package/server/assets/chat/create-room-dialog.js +50 -48
- package/server/assets/chat/diagram-viewer.js +293 -228
- package/server/assets/chat/doc-preview.js +510 -388
- package/server/assets/chat/editor.js +423 -335
- package/server/assets/chat/events.js +637 -502
- package/server/assets/chat/files.js +476 -426
- package/server/assets/chat/history-loader.js +79 -73
- package/server/assets/chat/icons.js +9 -11
- package/server/assets/chat/image-zoom.js +239 -169
- package/server/assets/chat/index.js +6 -5
- package/server/assets/chat/install-prompt.js +86 -66
- package/server/assets/chat/integration-account-schema.js +101 -0
- package/server/assets/chat/integration-editor.js +162 -153
- package/server/assets/chat/integration-values.js +109 -100
- package/server/assets/chat/integrations.js +696 -479
- package/server/assets/chat/join-requests.js +408 -358
- package/server/assets/chat/locales/de.js +193 -194
- package/server/assets/chat/locales/es.js +193 -194
- package/server/assets/chat/locales/fr.js +193 -194
- package/server/assets/chat/locales/index.js +1 -2
- package/server/assets/chat/locales/it.js +193 -194
- package/server/assets/chat/locales/ja.js +193 -193
- package/server/assets/chat/locales/ko.js +193 -193
- package/server/assets/chat/markdown-footnotes.js +134 -102
- package/server/assets/chat/markdown.js +553 -386
- package/server/assets/chat/members.js +236 -197
- package/server/assets/chat/mentions.js +157 -133
- package/server/assets/chat/message-cache.js +40 -33
- package/server/assets/chat/message-polling.js +280 -227
- package/server/assets/chat/message-window.js +74 -55
- package/server/assets/chat/messages.js +552 -479
- package/server/assets/chat/office-preview.js +46 -45
- package/server/assets/chat/palette.js +450 -412
- package/server/assets/chat/panels.js +94 -58
- package/server/assets/chat/pwa.js +144 -73
- package/server/assets/chat/questions.js +372 -302
- package/server/assets/chat/recall.js +320 -273
- package/server/assets/chat/receipts.js +149 -122
- package/server/assets/chat/reminders.js +331 -216
- package/server/assets/chat/replies.js +165 -136
- package/server/assets/chat/resource-format.js +59 -62
- package/server/assets/chat/room-list.js +58 -55
- package/server/assets/chat/room-watcher.js +72 -50
- package/server/assets/chat/rooms.js +623 -505
- package/server/assets/chat/search.js +136 -114
- package/server/assets/chat/settings.js +229 -140
- package/server/assets/chat/shiki.js +61 -62
- package/server/assets/chat/shortcuts.js +212 -190
- package/server/assets/chat/side-pane.js +166 -131
- package/server/assets/chat/state.js +851 -707
- package/server/assets/chat/system-events.js +55 -27
- package/server/assets/chat/system-messages.js +59 -49
- package/server/assets/chat/task-form.js +178 -182
- package/server/assets/chat/task-row.js +158 -155
- package/server/assets/chat/tasks.js +653 -593
- package/server/assets/chat/viewport.js +32 -29
- package/server/assets/chat/window-controls.js +37 -0
- package/server/assets/code-highlight.css +22 -6
- package/server/assets/conversation.css +65 -16
- 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-server.ts +9 -1
- package/server/chat.html +73 -38
- package/server/manifest.webmanifest +1 -0
- package/server/routes/pages.ts +7 -5
- package/server/sw.js +346 -267
- 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 +141 -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
|
@@ -3,406 +3,528 @@
|
|
|
3
3
|
import { formatBytes, renderMarkdown } from "./markdown.js";
|
|
4
4
|
import { docPreviewFormat, OFFICE_KINDS, OFFICE_PREVIEW_LIMIT, TEXT_PREVIEW_LIMIT } from "./resource-format.js";
|
|
5
5
|
import { createCopyButton, copyResourceText } from "./copy-action.js";
|
|
6
|
-
import { enhanceCodeElement } from "./shiki.js";
|
|
7
|
-
|
|
8
6
|
const PANE_QUERY = "(min-width: 1100px) and (min-height: 560px)";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
void copyResourceText(copyButton, app, async () => {
|
|
32
|
-
// The preview already owns the raw text; over-cap files fail instead of fetching.
|
|
33
|
-
if (Number(target.resource.size) > TEXT_PREVIEW_LIMIT) return "";
|
|
34
|
-
return rawText;
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
const resetCopy = () => {
|
|
38
|
-
clearTimeout(copyButton._copyFeedbackTimer);
|
|
39
|
-
copyButton.classList.remove("is-copied", "is-copy-failed");
|
|
40
|
-
copyButton.setAttribute("aria-label", app.t("copyMessage"));
|
|
41
|
-
copyButton.title = app.t("copyMessage");
|
|
42
|
-
const feedback = copyButton.querySelector(".copy-feedback");
|
|
43
|
-
if (feedback) feedback.textContent = "";
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
const updateFullscreenButton = () => {
|
|
47
|
-
if (!fullscreenButton) return;
|
|
48
|
-
const key = fullscreen ? "docPreviewExitFullscreen" : "docPreviewFullscreen";
|
|
49
|
-
fullscreenButton.dataset.i18nAriaLabel = key;
|
|
50
|
-
fullscreenButton.dataset.i18nTitle = key;
|
|
51
|
-
fullscreenButton.setAttribute("aria-label", app.t(key));
|
|
52
|
-
fullscreenButton.title = app.t(key);
|
|
53
|
-
fullscreenButton.querySelector("use")?.setAttribute("href", `/assets/fluent-icons.svg#fluent-${fullscreen ? "arrow_minimize" : "arrow_maximize"}-24`);
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
const show = () => {
|
|
57
|
-
const targetPane = pane.matches && !fullscreen;
|
|
58
|
-
dialog.classList.toggle("is-pane", targetPane);
|
|
59
|
-
dialog.classList.toggle("is-fullscreen", fullscreen);
|
|
60
|
-
chatView.classList.toggle("has-doc", targetPane);
|
|
61
|
-
if (dialog.open && paneMode !== targetPane) {
|
|
62
|
-
dialog.close();
|
|
63
|
-
}
|
|
64
|
-
if (!dialog.open) {
|
|
65
|
-
if (targetPane) dialog.show();
|
|
66
|
-
else dialog.showModal();
|
|
7
|
+
const MONACO_BUNDLE_URL = "/assets/monaco/integration-rules.js";
|
|
8
|
+
const MONACO_STYLES_URL = "/assets/monaco/integration-rules.css";
|
|
9
|
+
let monacoPromise = null;
|
|
10
|
+
let codeEditor = null;
|
|
11
|
+
function loadMonaco() {
|
|
12
|
+
if (!monacoPromise) {
|
|
13
|
+
monacoPromise = import(MONACO_BUNDLE_URL)
|
|
14
|
+
.then((module) => {
|
|
15
|
+
if (!document.querySelector("link[data-doc-code-editor]")) {
|
|
16
|
+
const link = document.createElement("link");
|
|
17
|
+
link.rel = "stylesheet";
|
|
18
|
+
link.href = MONACO_STYLES_URL;
|
|
19
|
+
link.dataset.docCodeEditor = "true";
|
|
20
|
+
document.head.append(link);
|
|
21
|
+
}
|
|
22
|
+
return module;
|
|
23
|
+
})
|
|
24
|
+
.catch((error) => {
|
|
25
|
+
// A blocked asset must not surface as an uncaught page error; the plain text view stays.
|
|
26
|
+
console.warn("Code preview editor unavailable; keeping the plain text view.", error);
|
|
27
|
+
throw error;
|
|
28
|
+
});
|
|
67
29
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
// returns to the pane or the plain modal according to the current window.
|
|
73
|
-
const setFullscreen = (next) => {
|
|
74
|
-
if (!dialog.open || fullscreen === next) return;
|
|
75
|
-
fullscreen = next;
|
|
76
|
-
document.body.classList.toggle("doc-preview-fullscreen", next);
|
|
77
|
-
updateFullscreenButton();
|
|
78
|
-
show();
|
|
79
|
-
if (!dialog.open) return;
|
|
80
|
-
if (next) title.focus({ preventScroll: true });
|
|
81
|
-
else fullscreenButton?.focus({ preventScroll: true });
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
const leaveFullscreen = () => {
|
|
85
|
-
fullscreen = false;
|
|
86
|
-
document.body.classList.remove("doc-preview-fullscreen");
|
|
87
|
-
dialog.classList.remove("is-fullscreen");
|
|
88
|
-
updateFullscreenButton();
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
// Crossing the breakpoint keeps the document: the pane becomes an overlay, or back.
|
|
92
|
-
const syncMode = () => {
|
|
93
|
-
if (!dialog.open || fullscreen || pane.matches === paneMode) return;
|
|
94
|
-
show();
|
|
95
|
-
title.focus({ preventScroll: true });
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
const contentPath = (roomId, id) => `/rooms/${encodeURIComponent(roomId)}/resources/${encodeURIComponent(id)}/content`;
|
|
99
|
-
|
|
100
|
-
const clearFrame = () => {
|
|
101
|
-
if (objectUrl) { URL.revokeObjectURL(objectUrl); objectUrl = null; }
|
|
102
|
-
dialog.classList.remove("is-pdf", "is-office");
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
const renderText = (text, format) => {
|
|
106
|
-
copyButton.hidden = false;
|
|
107
|
-
languageLabel.textContent = format.label || "";
|
|
108
|
-
languageLabel.hidden = !format.label;
|
|
109
|
-
if (!text) { empty.hidden = false; return; }
|
|
30
|
+
return monacoPromise;
|
|
31
|
+
}
|
|
32
|
+
// Fallback for a failed Monaco import: the same plain block the preview used before.
|
|
33
|
+
function plainCode(text, format) {
|
|
110
34
|
const pre = document.createElement("pre");
|
|
111
35
|
pre.className = "code-block doc-code";
|
|
112
36
|
const code = document.createElement("code");
|
|
113
37
|
code.className = format.language ? `language-${format.language}` : "";
|
|
114
38
|
code.textContent = text;
|
|
115
39
|
pre.append(code);
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
const
|
|
133
|
-
|
|
134
|
-
notice.dataset.i18n = key;
|
|
135
|
-
notice.hidden = false;
|
|
136
|
-
status.textContent = "";
|
|
137
|
-
// The blob is fetched on click, so a huge file still downloads.
|
|
138
|
-
download.disabled = false;
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
const renderOfficeDocument = async (kind, data, request, width = 0) => {
|
|
142
|
-
officeKind = kind;
|
|
143
|
-
const render = ++officeRender;
|
|
144
|
-
dialog.classList.add("is-office");
|
|
40
|
+
return pre;
|
|
41
|
+
}
|
|
42
|
+
export function initDocPreview(app) {
|
|
43
|
+
const dialog = app.$("#docPreview");
|
|
44
|
+
if (!dialog)
|
|
45
|
+
return;
|
|
46
|
+
const title = app.$("#docPreviewTitle"), size = app.$("#docPreviewSize");
|
|
47
|
+
const status = app.$("#docPreviewStatus"), body = app.$("#docPreviewBody");
|
|
48
|
+
const empty = app.$("#docPreviewEmpty"), download = app.$("#btnDocPreviewDownload");
|
|
49
|
+
const languageLabel = app.$("#docPreviewLanguage"), notice = app.$("#docPreviewNotice");
|
|
50
|
+
const eyebrow = app.$("#docPreviewEyebrow");
|
|
51
|
+
const fullscreenButton = app.$("#btnDocPreviewFullscreen");
|
|
52
|
+
const chatView = app.$("#chatView"), pane = matchMedia(PANE_QUERY);
|
|
53
|
+
let current = null, blob = null, objectUrl = null, token = 0, opener = null, openerResourceID = null, restoreOnClose = true;
|
|
54
|
+
let rawText = "", fullscreen = false, paneMode = false;
|
|
55
|
+
let officeKind = null, officeRender = 0, pptxWidth = 0, pptxTimer = 0;
|
|
56
|
+
const copyButton = createCopyButton(app, "doc-preview-copy");
|
|
57
|
+
copyButton.id = "btnDocPreviewCopy";
|
|
145
58
|
copyButton.hidden = true;
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
if (request !== token || render !== officeRender) return;
|
|
158
|
-
await module.renderOffice(kind, data, host, {
|
|
159
|
-
width: width || undefined,
|
|
160
|
-
onProgress: () => { if (request === token && render === officeRender) status.textContent = app.t("resourceLoading"); },
|
|
59
|
+
download.before(copyButton);
|
|
60
|
+
copyButton.addEventListener("click", () => {
|
|
61
|
+
const target = current;
|
|
62
|
+
if (!target)
|
|
63
|
+
return;
|
|
64
|
+
void copyResourceText(copyButton, app, async () => {
|
|
65
|
+
// The preview already owns the raw text; over-cap files fail instead of fetching.
|
|
66
|
+
if (Number(target.resource.size) > TEXT_PREVIEW_LIMIT)
|
|
67
|
+
return "";
|
|
68
|
+
return rawText;
|
|
69
|
+
});
|
|
161
70
|
});
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
download.disabled = true;
|
|
238
|
-
if (app.preserveReadingLayout) await app.preserveReadingLayout(show);
|
|
239
|
-
else show();
|
|
240
|
-
if (request !== token) return;
|
|
241
|
-
title.focus({ preventScroll: true });
|
|
242
|
-
const office = OFFICE_KINDS.has(format.kind);
|
|
243
|
-
officeKind = office ? format.kind : null;
|
|
244
|
-
const limit = office ? OFFICE_PREVIEW_LIMIT : TEXT_PREVIEW_LIMIT;
|
|
245
|
-
if (format.kind !== "pdf" && Number(resource.size) > limit) { showTooLarge(format); return; }
|
|
246
|
-
try {
|
|
247
|
-
const data = await app.apiBlob(contentPath(roomId, resource.id));
|
|
248
|
-
if (request !== token) return;
|
|
249
|
-
blob = data;
|
|
250
|
-
if (format.kind !== "pdf" && data.size > limit) { showTooLarge(format); return; }
|
|
251
|
-
if (format.kind === "pdf") { renderPdf(resource, data); return; }
|
|
252
|
-
if (office) { await renderOfficeDocument(format.kind, data, request); return; }
|
|
253
|
-
const text = await data.text();
|
|
254
|
-
if (request !== token) return;
|
|
255
|
-
rawText = text;
|
|
256
|
-
if (format.kind === "text") renderText(text, format);
|
|
257
|
-
else {
|
|
258
|
-
renderMarkdown(body, text, app);
|
|
259
|
-
empty.hidden = body.children.length > 0;
|
|
71
|
+
const resetCopy = () => {
|
|
72
|
+
clearTimeout(copyButton._copyFeedbackTimer);
|
|
73
|
+
copyButton.classList.remove("is-copied", "is-copy-failed");
|
|
74
|
+
copyButton.setAttribute("aria-label", app.t("copyMessage"));
|
|
75
|
+
copyButton.title = app.t("copyMessage");
|
|
76
|
+
const feedback = copyButton.querySelector(".copy-feedback");
|
|
77
|
+
if (feedback)
|
|
78
|
+
feedback.textContent = "";
|
|
79
|
+
};
|
|
80
|
+
const updateFullscreenButton = () => {
|
|
81
|
+
if (!fullscreenButton)
|
|
82
|
+
return;
|
|
83
|
+
const key = fullscreen ? "docPreviewExitFullscreen" : "docPreviewFullscreen";
|
|
84
|
+
fullscreenButton.dataset.i18nAriaLabel = key;
|
|
85
|
+
fullscreenButton.dataset.i18nTitle = key;
|
|
86
|
+
fullscreenButton.setAttribute("aria-label", app.t(key));
|
|
87
|
+
fullscreenButton.title = app.t(key);
|
|
88
|
+
fullscreenButton.querySelector("use")?.setAttribute("href", `/assets/fluent-icons.svg#fluent-${fullscreen ? "arrow_minimize" : "arrow_maximize"}-24`);
|
|
89
|
+
};
|
|
90
|
+
const show = () => {
|
|
91
|
+
const targetPane = pane.matches && !fullscreen;
|
|
92
|
+
dialog.classList.toggle("is-pane", targetPane);
|
|
93
|
+
dialog.classList.toggle("is-fullscreen", fullscreen);
|
|
94
|
+
chatView.classList.toggle("has-doc", targetPane);
|
|
95
|
+
if (dialog.open && paneMode !== targetPane) {
|
|
96
|
+
dialog.close();
|
|
97
|
+
}
|
|
98
|
+
if (!dialog.open) {
|
|
99
|
+
if (targetPane)
|
|
100
|
+
dialog.show();
|
|
101
|
+
else
|
|
102
|
+
dialog.showModal();
|
|
103
|
+
}
|
|
104
|
+
paneMode = targetPane;
|
|
105
|
+
};
|
|
106
|
+
// Full screen is always a modal so the chat behind it stays inert; leaving it
|
|
107
|
+
// returns to the pane or the plain modal according to the current window.
|
|
108
|
+
const setFullscreen = (next) => {
|
|
109
|
+
if (!dialog.open || fullscreen === next)
|
|
110
|
+
return;
|
|
111
|
+
fullscreen = next;
|
|
112
|
+
document.body.classList.toggle("doc-preview-fullscreen", next);
|
|
113
|
+
updateFullscreenButton();
|
|
114
|
+
show();
|
|
115
|
+
if (!dialog.open)
|
|
116
|
+
return;
|
|
117
|
+
if (next)
|
|
118
|
+
title.focus({ preventScroll: true });
|
|
119
|
+
else
|
|
120
|
+
fullscreenButton?.focus({ preventScroll: true });
|
|
121
|
+
};
|
|
122
|
+
const leaveFullscreen = () => {
|
|
123
|
+
fullscreen = false;
|
|
124
|
+
document.body.classList.remove("doc-preview-fullscreen");
|
|
125
|
+
dialog.classList.remove("is-fullscreen");
|
|
126
|
+
updateFullscreenButton();
|
|
127
|
+
};
|
|
128
|
+
// Crossing the breakpoint keeps the document: the pane becomes an overlay, or back.
|
|
129
|
+
const syncMode = () => {
|
|
130
|
+
if (!dialog.open || fullscreen || pane.matches === paneMode)
|
|
131
|
+
return;
|
|
132
|
+
show();
|
|
133
|
+
title.focus({ preventScroll: true });
|
|
134
|
+
};
|
|
135
|
+
const contentPath = (roomId, id) => `/rooms/${encodeURIComponent(roomId)}/resources/${encodeURIComponent(id)}/content`;
|
|
136
|
+
const clearFrame = () => {
|
|
137
|
+
codeEditor?.dispose();
|
|
138
|
+
codeEditor = null;
|
|
139
|
+
if (objectUrl) {
|
|
140
|
+
URL.revokeObjectURL(objectUrl);
|
|
141
|
+
objectUrl = null;
|
|
142
|
+
}
|
|
143
|
+
dialog.classList.remove("is-pdf", "is-office", "is-code");
|
|
144
|
+
};
|
|
145
|
+
const renderText = async (text, format, request) => {
|
|
260
146
|
copyButton.hidden = false;
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
147
|
+
languageLabel.textContent = format.label || "";
|
|
148
|
+
languageLabel.hidden = !format.label;
|
|
149
|
+
if (!text) {
|
|
150
|
+
empty.hidden = false;
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
dialog.classList.add("is-code");
|
|
154
|
+
const host = document.createElement("div");
|
|
155
|
+
host.className = "doc-monaco";
|
|
156
|
+
body.append(host);
|
|
157
|
+
empty.hidden = true;
|
|
158
|
+
try {
|
|
159
|
+
const module = await loadMonaco();
|
|
160
|
+
// Another document or a close may have run while the import was pending.
|
|
161
|
+
if (request !== token || !dialog.open || !host.isConnected)
|
|
162
|
+
return;
|
|
163
|
+
codeEditor = module.createCodePreviewEditor({
|
|
164
|
+
container: host,
|
|
165
|
+
value: text,
|
|
166
|
+
language: format.language || "plaintext",
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
catch {
|
|
170
|
+
host.remove();
|
|
171
|
+
if (request !== token || !dialog.open)
|
|
172
|
+
return;
|
|
173
|
+
// Let the plain block use the normal padded scroll area.
|
|
174
|
+
dialog.classList.remove("is-code");
|
|
175
|
+
body.append(plainCode(text, format));
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
const showTooLarge = (format) => {
|
|
266
179
|
clearFrame();
|
|
180
|
+
const office = OFFICE_KINDS.has(format.kind);
|
|
181
|
+
copyButton.hidden = office;
|
|
182
|
+
// A render from the previous document may still be running. Invalidate it
|
|
183
|
+
// before clearing the body so it cannot append into the new preview.
|
|
184
|
+
if (office) {
|
|
185
|
+
officeRender++;
|
|
186
|
+
officeKind = null;
|
|
187
|
+
}
|
|
267
188
|
body.textContent = "";
|
|
268
189
|
empty.hidden = true;
|
|
190
|
+
languageLabel.textContent = office ? "" : format.label || "";
|
|
191
|
+
languageLabel.hidden = office || !format.label;
|
|
192
|
+
const key = office ? "docPreviewOfficeTooLarge" : "docPreviewTooLarge";
|
|
193
|
+
notice.textContent = app.t(key);
|
|
194
|
+
notice.dataset.i18n = key;
|
|
195
|
+
notice.hidden = false;
|
|
196
|
+
status.textContent = "";
|
|
197
|
+
// The blob is fetched on click, so a huge file still downloads.
|
|
198
|
+
download.disabled = false;
|
|
199
|
+
};
|
|
200
|
+
const renderOfficeDocument = async (kind, data, request, width = 0) => {
|
|
201
|
+
officeKind = kind;
|
|
202
|
+
const render = ++officeRender;
|
|
203
|
+
dialog.classList.add("is-office");
|
|
269
204
|
copyButton.hidden = true;
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
205
|
+
languageLabel.hidden = true;
|
|
206
|
+
// Render into a private container. A render from an earlier document can
|
|
207
|
+
// finish after the user has switched files; it must never touch the live body.
|
|
208
|
+
const host = document.createElement("div");
|
|
209
|
+
host.className = "office-preview";
|
|
210
|
+
body.replaceChildren(host);
|
|
211
|
+
empty.hidden = true;
|
|
212
|
+
notice.hidden = true;
|
|
213
|
+
// The blob is already here, so download stays available while parsing or after a failure.
|
|
214
|
+
download.disabled = false;
|
|
215
|
+
const module = await import("/assets/chat/office-preview.js");
|
|
216
|
+
if (request !== token || render !== officeRender)
|
|
217
|
+
return;
|
|
218
|
+
await module.renderOffice(kind, data, host, {
|
|
219
|
+
width: width || undefined,
|
|
220
|
+
onProgress: () => { if (request === token && render === officeRender)
|
|
221
|
+
status.textContent = app.t("resourceLoading"); },
|
|
222
|
+
});
|
|
223
|
+
if (request !== token || render !== officeRender || !host.isConnected)
|
|
224
|
+
return;
|
|
225
|
+
body.replaceChildren(host);
|
|
226
|
+
if (kind === "pptx")
|
|
227
|
+
pptxWidth = Math.round(width || body.clientWidth);
|
|
228
|
+
status.textContent = "";
|
|
229
|
+
empty.hidden = body.children.length > 0;
|
|
230
|
+
};
|
|
231
|
+
// A fixed-width slide deck must be laid out again when the reading pane grows
|
|
232
|
+
// (full screen, splitter drag, breakpoint change), or it stays pane-sized.
|
|
233
|
+
const resizePptx = () => {
|
|
234
|
+
if (!dialog.open || officeKind !== "pptx" || !blob)
|
|
235
|
+
return;
|
|
236
|
+
const width = Math.round(body.clientWidth);
|
|
237
|
+
if (width < 200 || Math.abs(width - pptxWidth) < 8)
|
|
238
|
+
return;
|
|
239
|
+
clearTimeout(pptxTimer);
|
|
240
|
+
pptxTimer = setTimeout(() => {
|
|
241
|
+
if (dialog.open && officeKind === "pptx" && blob) {
|
|
242
|
+
void renderOfficeDocument("pptx", blob, token, width).catch(() => undefined);
|
|
243
|
+
}
|
|
244
|
+
}, 150);
|
|
245
|
+
};
|
|
246
|
+
if (typeof ResizeObserver === "function")
|
|
247
|
+
new ResizeObserver(resizePptx).observe(body);
|
|
248
|
+
const renderPdf = (resource, data) => {
|
|
249
|
+
copyButton.hidden = true;
|
|
250
|
+
const pdf = data.type === "application/pdf" ? data : data.slice(0, data.size, "application/pdf");
|
|
251
|
+
objectUrl = URL.createObjectURL(pdf);
|
|
252
|
+
const frame = document.createElement("iframe");
|
|
253
|
+
frame.className = "doc-pdf-frame";
|
|
254
|
+
frame.title = resource.name;
|
|
255
|
+
frame.src = objectUrl;
|
|
256
|
+
frame.addEventListener("error", () => {
|
|
257
|
+
clearFrame();
|
|
258
|
+
body.textContent = "";
|
|
259
|
+
status.textContent = app.t("docPreviewFailed");
|
|
260
|
+
download.disabled = false;
|
|
261
|
+
}, { once: true });
|
|
262
|
+
body.textContent = "";
|
|
263
|
+
body.append(frame);
|
|
264
|
+
dialog.classList.add("is-pdf");
|
|
265
|
+
languageLabel.textContent = "PDF";
|
|
266
|
+
languageLabel.hidden = false;
|
|
267
|
+
empty.hidden = true;
|
|
268
|
+
notice.hidden = true;
|
|
269
|
+
status.textContent = "";
|
|
270
|
+
download.disabled = false;
|
|
271
|
+
};
|
|
272
|
+
const open = async (roomId, resource, source) => {
|
|
273
|
+
opener = source instanceof HTMLElement ? source : null;
|
|
274
|
+
openerResourceID = source instanceof HTMLElement ? source.dataset.previewResource || null : null;
|
|
275
|
+
restoreOnClose = true;
|
|
276
|
+
current = { roomId, resource };
|
|
277
|
+
const request = ++token;
|
|
278
|
+
const format = docPreviewFormat(resource) || { kind: "markdown", language: "", label: "" };
|
|
279
|
+
blob = null;
|
|
280
|
+
rawText = "";
|
|
281
|
+
copyButton.hidden = true;
|
|
282
|
+
resetCopy();
|
|
283
|
+
clearFrame();
|
|
284
|
+
officeKind = null;
|
|
285
|
+
pptxWidth = 0;
|
|
286
|
+
clearTimeout(pptxTimer);
|
|
287
|
+
const eyebrowKey = format.kind === "markdown" ? "docPreviewEyebrow" : "docPreviewFileEyebrow";
|
|
288
|
+
eyebrow.dataset.i18n = eyebrowKey;
|
|
289
|
+
eyebrow.textContent = app.t(eyebrowKey);
|
|
290
|
+
title.textContent = resource.name;
|
|
291
|
+
size.textContent = formatBytes(resource.size);
|
|
292
|
+
status.textContent = app.t("resourceLoading");
|
|
293
|
+
body.textContent = "";
|
|
294
|
+
empty.hidden = true;
|
|
295
|
+
notice.hidden = true;
|
|
296
|
+
notice.textContent = "";
|
|
297
|
+
delete notice.dataset.i18n;
|
|
298
|
+
languageLabel.hidden = true;
|
|
299
|
+
languageLabel.textContent = "";
|
|
300
|
+
download.disabled = true;
|
|
301
|
+
if (app.preserveReadingLayout)
|
|
302
|
+
await app.preserveReadingLayout(show);
|
|
303
|
+
else
|
|
304
|
+
show();
|
|
305
|
+
if (request !== token)
|
|
306
|
+
return;
|
|
307
|
+
title.focus({ preventScroll: true });
|
|
308
|
+
const office = OFFICE_KINDS.has(format.kind);
|
|
309
|
+
officeKind = office ? format.kind : null;
|
|
310
|
+
const limit = office ? OFFICE_PREVIEW_LIMIT : TEXT_PREVIEW_LIMIT;
|
|
311
|
+
if (format.kind !== "pdf" && Number(resource.size) > limit) {
|
|
312
|
+
showTooLarge(format);
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
try {
|
|
316
|
+
const data = await app.apiBlob(contentPath(roomId, resource.id));
|
|
317
|
+
if (request !== token)
|
|
318
|
+
return;
|
|
319
|
+
blob = data;
|
|
320
|
+
if (format.kind !== "pdf" && data.size > limit) {
|
|
321
|
+
showTooLarge(format);
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
if (format.kind === "pdf") {
|
|
325
|
+
renderPdf(resource, data);
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
if (office) {
|
|
329
|
+
await renderOfficeDocument(format.kind, data, request);
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
const text = await data.text();
|
|
333
|
+
if (request !== token)
|
|
334
|
+
return;
|
|
335
|
+
rawText = text;
|
|
336
|
+
if (format.kind === "text")
|
|
337
|
+
void renderText(text, format, request);
|
|
338
|
+
else {
|
|
339
|
+
renderMarkdown(body, text, app);
|
|
340
|
+
empty.hidden = body.children.length > 0;
|
|
341
|
+
copyButton.hidden = false;
|
|
342
|
+
}
|
|
343
|
+
status.textContent = "";
|
|
344
|
+
download.disabled = false;
|
|
345
|
+
}
|
|
346
|
+
catch {
|
|
347
|
+
if (request === token) {
|
|
348
|
+
clearFrame();
|
|
349
|
+
body.textContent = "";
|
|
350
|
+
empty.hidden = true;
|
|
351
|
+
copyButton.hidden = true;
|
|
352
|
+
if (office) {
|
|
353
|
+
status.textContent = "";
|
|
354
|
+
notice.textContent = app.t("docPreviewOfficeFailed");
|
|
355
|
+
notice.dataset.i18n = "docPreviewOfficeFailed";
|
|
356
|
+
notice.hidden = false;
|
|
357
|
+
download.disabled = false;
|
|
358
|
+
}
|
|
359
|
+
else
|
|
360
|
+
status.textContent = app.t("docPreviewFailed");
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
};
|
|
364
|
+
const focusReplacement = (resourceID, allowComposer = false) => {
|
|
365
|
+
if (!resourceID) {
|
|
366
|
+
if (allowComposer)
|
|
367
|
+
app.focusChatComposer?.({ force: true });
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
370
|
+
const query = `#msgList [data-preview-resource="${CSS.escape(resourceID)}"]`;
|
|
371
|
+
const replacement = query ? document.querySelector(query) : null;
|
|
372
|
+
if (replacement instanceof HTMLElement && replacement.getClientRects().length) {
|
|
373
|
+
replacement.focus({ preventScroll: true });
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
// The message list may be halfway through an async card rerender. Retry
|
|
377
|
+
// briefly, but never steal focus if the reader has already clicked elsewhere.
|
|
378
|
+
const active = document.activeElement;
|
|
379
|
+
if (active && active !== document.body && active.id !== "msgInput")
|
|
380
|
+
return;
|
|
381
|
+
if (performance.now() < focusReplacement.until) {
|
|
382
|
+
requestAnimationFrame(() => focusReplacement(resourceID, allowComposer));
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
if (allowComposer && (document.activeElement === document.body || document.activeElement?.id === "msgInput")) {
|
|
386
|
+
document.querySelector("#msgInput")?.focus({ preventScroll: true });
|
|
387
|
+
}
|
|
388
|
+
};
|
|
389
|
+
const close = (restoreFocus = true) => {
|
|
390
|
+
restoreOnClose = restoreFocus;
|
|
391
|
+
if (!restoreFocus)
|
|
392
|
+
opener = null;
|
|
393
|
+
// Invalidate in-flight fetches and Office renders before the close event
|
|
394
|
+
// runs, so none of them can repaint the preview after it starts closing.
|
|
395
|
+
token++;
|
|
396
|
+
officeRender++;
|
|
397
|
+
officeKind = null;
|
|
398
|
+
clearTimeout(pptxTimer);
|
|
399
|
+
// Closing from full screen leaves the locked page as part of the same step.
|
|
400
|
+
if (fullscreen)
|
|
401
|
+
leaveFullscreen();
|
|
402
|
+
// Remove the column class now; the queued close event must not leave Tasks
|
|
403
|
+
// hidden behind a column the task pane is about to take back.
|
|
404
|
+
chatView.classList.remove("has-doc");
|
|
405
|
+
if (dialog.open)
|
|
406
|
+
dialog.close();
|
|
407
|
+
else
|
|
408
|
+
restoreOnClose = true;
|
|
409
|
+
};
|
|
410
|
+
const downloadDocument = async () => {
|
|
411
|
+
const target = current;
|
|
412
|
+
if (!target)
|
|
413
|
+
return;
|
|
414
|
+
let data = blob;
|
|
415
|
+
if (!data) {
|
|
416
|
+
download.disabled = true;
|
|
417
|
+
try {
|
|
418
|
+
data = await app.apiBlob(contentPath(target.roomId, target.resource.id));
|
|
419
|
+
if (current !== target)
|
|
420
|
+
return;
|
|
421
|
+
blob = data;
|
|
422
|
+
}
|
|
423
|
+
catch {
|
|
424
|
+
if (current === target)
|
|
425
|
+
status.textContent = app.t("docPreviewFailed");
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
finally {
|
|
429
|
+
if (current === target)
|
|
430
|
+
download.disabled = false;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
const url = URL.createObjectURL(data), link = document.createElement("a");
|
|
434
|
+
link.href = url;
|
|
435
|
+
link.download = String(target.resource.name).replace(/[\\/\u0000-\u001f\u007f]/g, "_") || "download";
|
|
436
|
+
document.body.append(link);
|
|
437
|
+
link.click();
|
|
438
|
+
link.remove();
|
|
439
|
+
setTimeout(() => URL.revokeObjectURL(url), 1000);
|
|
440
|
+
};
|
|
441
|
+
app.openDocPreview = (roomId, resource, source) => { void open(roomId, resource, source); };
|
|
442
|
+
app.closeDocPreview = (restoreFocus = true) => close(restoreFocus);
|
|
443
|
+
app.registerDismissibleSurface?.("docPreview", { element: dialog, close: (restore = true) => close(restore) });
|
|
444
|
+
updateFullscreenButton();
|
|
445
|
+
app.$("#btnCloseDocPreview")?.addEventListener("click", () => close());
|
|
446
|
+
fullscreenButton?.addEventListener("click", () => setFullscreen(!fullscreen));
|
|
447
|
+
download.addEventListener("click", downloadDocument);
|
|
448
|
+
// A drag that starts in the document and ends on the backdrop produces a click
|
|
449
|
+
// whose target is the dialog; only a press and release on the backdrop closes.
|
|
450
|
+
let dismissPress = false;
|
|
451
|
+
dialog.addEventListener("pointerdown", (event) => { dismissPress = event.target === dialog; });
|
|
452
|
+
dialog.addEventListener("click", (event) => {
|
|
453
|
+
if (event.target === dialog && dismissPress && !fullscreen && !dialog.classList.contains("is-pane"))
|
|
454
|
+
close();
|
|
455
|
+
dismissPress = false;
|
|
456
|
+
});
|
|
457
|
+
const escapePreview = (event) => {
|
|
458
|
+
if (!event || event.altKey || event.key !== "Escape" || !dialog.open)
|
|
459
|
+
return;
|
|
460
|
+
event.preventDefault();
|
|
461
|
+
event.stopPropagation();
|
|
462
|
+
// The first Esc leaves full screen; the next one closes the preview.
|
|
463
|
+
if (fullscreen)
|
|
464
|
+
setFullscreen(false);
|
|
465
|
+
else
|
|
466
|
+
close();
|
|
467
|
+
};
|
|
468
|
+
document.addEventListener("keydown", (event) => {
|
|
469
|
+
// Capture Escape while the preview is open: leaving full screen closes and
|
|
470
|
+
// reopens the dialog, and the reopened dialog must still obey the next Esc.
|
|
471
|
+
escapePreview(event);
|
|
472
|
+
}, true);
|
|
473
|
+
dialog.addEventListener("cancel", escapePreview);
|
|
474
|
+
dialog.addEventListener("close", () => {
|
|
475
|
+
// A breakpoint switch or leaving full screen closes and reopens the same
|
|
476
|
+
// dialog. Its queued close event must not wipe the document that is already
|
|
477
|
+
// back on screen, so it is stale whenever the dialog has been reopened.
|
|
478
|
+
if (dialog.open) {
|
|
479
|
+
restoreOnClose = true;
|
|
480
|
+
return;
|
|
481
|
+
}
|
|
482
|
+
const shouldRestore = restoreOnClose;
|
|
483
|
+
restoreOnClose = true;
|
|
484
|
+
token++;
|
|
485
|
+
leaveFullscreen();
|
|
486
|
+
officeRender++;
|
|
487
|
+
officeKind = null;
|
|
488
|
+
pptxWidth = 0;
|
|
489
|
+
clearTimeout(pptxTimer);
|
|
490
|
+
current = null;
|
|
491
|
+
blob = null;
|
|
492
|
+
rawText = "";
|
|
493
|
+
copyButton.hidden = true;
|
|
494
|
+
resetCopy();
|
|
495
|
+
clearFrame();
|
|
496
|
+
chatView.classList.remove("has-doc");
|
|
497
|
+
dialog.classList.remove("is-pane");
|
|
498
|
+
title.textContent = "";
|
|
499
|
+
size.textContent = "";
|
|
500
|
+
status.textContent = "";
|
|
501
|
+
body.textContent = "";
|
|
502
|
+
empty.hidden = true;
|
|
503
|
+
download.disabled = true;
|
|
504
|
+
languageLabel.hidden = true;
|
|
505
|
+
languageLabel.textContent = "";
|
|
506
|
+
notice.hidden = true;
|
|
507
|
+
notice.textContent = "";
|
|
508
|
+
delete notice.dataset.i18n;
|
|
509
|
+
const target = opener;
|
|
510
|
+
opener = null;
|
|
511
|
+
if (!shouldRestore)
|
|
512
|
+
return;
|
|
513
|
+
if (target?.isConnected && target.getClientRects().length) {
|
|
514
|
+
target.focus({ preventScroll: true });
|
|
515
|
+
return;
|
|
516
|
+
}
|
|
517
|
+
// Inbox polling can rerender the message list while the preview is open,
|
|
518
|
+
// replacing the button that opened it. Focus the current equivalent.
|
|
519
|
+
const resourceID = openerResourceID;
|
|
520
|
+
openerResourceID = null;
|
|
521
|
+
focusReplacement.until = performance.now() + 600;
|
|
522
|
+
focusReplacement(resourceID, true);
|
|
523
|
+
});
|
|
524
|
+
const onChange = () => syncMode();
|
|
525
|
+
if (pane.addEventListener)
|
|
526
|
+
pane.addEventListener("change", onChange);
|
|
527
|
+
else
|
|
528
|
+
pane.addListener(onChange);
|
|
529
|
+
document.addEventListener("chat-room-activated", () => close(false));
|
|
530
|
+
}
|