@alexsun-top/opencode-chat-room 0.8.2 → 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 +10 -0
- package/README.md +18 -62
- package/README.zh-CN.md +25 -69
- package/dist/cli.js +466 -188
- package/package.json +8 -5
- package/packages/chat-room-channeld/README.md +25 -3
- package/packages/chat-room-channeld/dist/mock-adapter.js +5 -5
- package/packages/chat-room-channeld/src/adapter.ts +5 -0
- package/packages/chat-room-channeld/src/cli.ts +72 -5
- package/packages/chat-room-channeld/src/host.ts +17 -2
- 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 +1 -0
- package/packages/chat-room-channeld/src/state.ts +73 -97
- package/packages/chat-room-channeld/src/stats.ts +140 -109
- package/server/assets/base.css +3 -1
- package/server/assets/chat/admin-badge.js +32 -30
- package/server/assets/chat/admin.js +198 -161
- package/server/assets/chat/announcements.js +295 -208
- package/server/assets/chat/attachment-store.js +106 -75
- package/server/assets/chat/attachments.js +686 -441
- package/server/assets/chat/chat-background.js +185 -156
- package/server/assets/chat/clipboard.js +44 -25
- package/server/assets/chat/confirm-dialog.js +36 -33
- package/server/assets/chat/copy-action.js +40 -40
- package/server/assets/chat/create-room-dialog.js +50 -47
- package/server/assets/chat/diagram-viewer.js +293 -234
- package/server/assets/chat/doc-preview.js +507 -441
- package/server/assets/chat/editor.js +423 -335
- package/server/assets/chat/events.js +637 -510
- package/server/assets/chat/files.js +476 -430
- 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 -176
- package/server/assets/chat/index.js +2 -3
- package/server/assets/chat/install-prompt.js +86 -66
- package/server/assets/chat/integration-account-schema.js +88 -86
- package/server/assets/chat/integration-editor.js +162 -153
- package/server/assets/chat/integration-values.js +109 -100
- package/server/assets/chat/integrations.js +689 -622
- 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 +547 -403
- 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 -480
- package/server/assets/chat/office-preview.js +46 -45
- package/server/assets/chat/palette.js +450 -417
- package/server/assets/chat/panels.js +94 -78
- 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 -121
- package/server/assets/chat/reminders.js +331 -214
- package/server/assets/chat/replies.js +165 -130
- 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 -500
- package/server/assets/chat/search.js +136 -114
- package/server/assets/chat/settings.js +223 -200
- package/server/assets/chat/shiki.js +61 -62
- package/server/assets/chat/shortcuts.js +212 -187
- package/server/assets/chat/side-pane.js +160 -150
- package/server/assets/chat/state.js +849 -735
- package/server/assets/chat/system-events.js +45 -43
- package/server/assets/chat/system-messages.js +57 -56
- 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 -587
- package/server/assets/chat/viewport.js +32 -29
- package/server/assets/chat/window-controls.js +32 -32
- package/server/assets/conversation.css +10 -4
- package/server/chat-server.ts +9 -1
- package/server/chat.html +2 -1
- package/server/routes/pages.ts +7 -5
- package/server/sw.js +346 -268
- package/src/web/integration-rules-editor.ts +2 -0
|
@@ -3,462 +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
|
-
|
|
7
6
|
const PANE_QUERY = "(min-width: 1100px) and (min-height: 560px)";
|
|
8
7
|
const MONACO_BUNDLE_URL = "/assets/monaco/integration-rules.js";
|
|
9
8
|
const MONACO_STYLES_URL = "/assets/monaco/integration-rules.css";
|
|
10
9
|
let monacoPromise = null;
|
|
11
10
|
let codeEditor = null;
|
|
12
|
-
|
|
13
11
|
function loadMonaco() {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
+
});
|
|
29
|
+
}
|
|
30
|
+
return monacoPromise;
|
|
33
31
|
}
|
|
34
|
-
|
|
35
32
|
// Fallback for a failed Monaco import: the same plain block the preview used before.
|
|
36
33
|
function plainCode(text, format) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
34
|
+
const pre = document.createElement("pre");
|
|
35
|
+
pre.className = "code-block doc-code";
|
|
36
|
+
const code = document.createElement("code");
|
|
37
|
+
code.className = format.language ? `language-${format.language}` : "";
|
|
38
|
+
code.textContent = text;
|
|
39
|
+
pre.append(code);
|
|
40
|
+
return pre;
|
|
44
41
|
}
|
|
45
|
-
|
|
46
42
|
export function initDocPreview(app) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
copyButton.hidden = true;
|
|
63
|
-
download.before(copyButton);
|
|
64
|
-
copyButton.addEventListener("click", () => {
|
|
65
|
-
const target = current;
|
|
66
|
-
if (!target) return;
|
|
67
|
-
void copyResourceText(copyButton, app, async () => {
|
|
68
|
-
// The preview already owns the raw text; over-cap files fail instead of fetching.
|
|
69
|
-
if (Number(target.resource.size) > TEXT_PREVIEW_LIMIT) return "";
|
|
70
|
-
return rawText;
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
const resetCopy = () => {
|
|
74
|
-
clearTimeout(copyButton._copyFeedbackTimer);
|
|
75
|
-
copyButton.classList.remove("is-copied", "is-copy-failed");
|
|
76
|
-
copyButton.setAttribute("aria-label", app.t("copyMessage"));
|
|
77
|
-
copyButton.title = app.t("copyMessage");
|
|
78
|
-
const feedback = copyButton.querySelector(".copy-feedback");
|
|
79
|
-
if (feedback) feedback.textContent = "";
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
const updateFullscreenButton = () => {
|
|
83
|
-
if (!fullscreenButton) return;
|
|
84
|
-
const key = fullscreen ? "docPreviewExitFullscreen" : "docPreviewFullscreen";
|
|
85
|
-
fullscreenButton.dataset.i18nAriaLabel = key;
|
|
86
|
-
fullscreenButton.dataset.i18nTitle = key;
|
|
87
|
-
fullscreenButton.setAttribute("aria-label", app.t(key));
|
|
88
|
-
fullscreenButton.title = app.t(key);
|
|
89
|
-
fullscreenButton.querySelector("use")?.setAttribute("href", `/assets/fluent-icons.svg#fluent-${fullscreen ? "arrow_minimize" : "arrow_maximize"}-24`);
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
const show = () => {
|
|
93
|
-
const targetPane = pane.matches && !fullscreen;
|
|
94
|
-
dialog.classList.toggle("is-pane", targetPane);
|
|
95
|
-
dialog.classList.toggle("is-fullscreen", fullscreen);
|
|
96
|
-
chatView.classList.toggle("has-doc", targetPane);
|
|
97
|
-
if (dialog.open && paneMode !== targetPane) {
|
|
98
|
-
dialog.close();
|
|
99
|
-
}
|
|
100
|
-
if (!dialog.open) {
|
|
101
|
-
if (targetPane) dialog.show();
|
|
102
|
-
else dialog.showModal();
|
|
103
|
-
}
|
|
104
|
-
paneMode = targetPane;
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
// Full screen is always a modal so the chat behind it stays inert; leaving it
|
|
108
|
-
// returns to the pane or the plain modal according to the current window.
|
|
109
|
-
const setFullscreen = (next) => {
|
|
110
|
-
if (!dialog.open || fullscreen === next) return;
|
|
111
|
-
fullscreen = next;
|
|
112
|
-
document.body.classList.toggle("doc-preview-fullscreen", next);
|
|
113
|
-
updateFullscreenButton();
|
|
114
|
-
show();
|
|
115
|
-
if (!dialog.open) return;
|
|
116
|
-
if (next) title.focus({ preventScroll: true });
|
|
117
|
-
else fullscreenButton?.focus({ preventScroll: true });
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
const leaveFullscreen = () => {
|
|
121
|
-
fullscreen = false;
|
|
122
|
-
document.body.classList.remove("doc-preview-fullscreen");
|
|
123
|
-
dialog.classList.remove("is-fullscreen");
|
|
124
|
-
updateFullscreenButton();
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
// Crossing the breakpoint keeps the document: the pane becomes an overlay, or back.
|
|
128
|
-
const syncMode = () => {
|
|
129
|
-
if (!dialog.open || fullscreen || pane.matches === paneMode) return;
|
|
130
|
-
show();
|
|
131
|
-
title.focus({ preventScroll: true });
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
const contentPath = (roomId, id) => `/rooms/${encodeURIComponent(roomId)}/resources/${encodeURIComponent(id)}/content`;
|
|
135
|
-
|
|
136
|
-
const clearFrame = () => {
|
|
137
|
-
codeEditor?.dispose();
|
|
138
|
-
codeEditor = null;
|
|
139
|
-
if (objectUrl) { URL.revokeObjectURL(objectUrl); objectUrl = null; }
|
|
140
|
-
dialog.classList.remove("is-pdf", "is-office", "is-code");
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
const renderText = async (text, format, request) => {
|
|
144
|
-
copyButton.hidden = false;
|
|
145
|
-
languageLabel.textContent = format.label || "";
|
|
146
|
-
languageLabel.hidden = !format.label;
|
|
147
|
-
if (!text) { empty.hidden = false; return; }
|
|
148
|
-
dialog.classList.add("is-code");
|
|
149
|
-
const host = document.createElement("div");
|
|
150
|
-
host.className = "doc-monaco";
|
|
151
|
-
body.append(host);
|
|
152
|
-
empty.hidden = true;
|
|
153
|
-
try {
|
|
154
|
-
const module = await loadMonaco();
|
|
155
|
-
// Another document or a close may have run while the import was pending.
|
|
156
|
-
if (request !== token || !dialog.open || !host.isConnected) return;
|
|
157
|
-
codeEditor = module.createCodePreviewEditor({
|
|
158
|
-
container: host,
|
|
159
|
-
value: text,
|
|
160
|
-
language: format.language || "plaintext",
|
|
161
|
-
});
|
|
162
|
-
} catch {
|
|
163
|
-
host.remove();
|
|
164
|
-
if (request !== token || !dialog.open) return;
|
|
165
|
-
// Let the plain block use the normal padded scroll area.
|
|
166
|
-
dialog.classList.remove("is-code");
|
|
167
|
-
body.append(plainCode(text, format));
|
|
168
|
-
}
|
|
169
|
-
};
|
|
170
|
-
|
|
171
|
-
const showTooLarge = (format) => {
|
|
172
|
-
clearFrame();
|
|
173
|
-
const office = OFFICE_KINDS.has(format.kind);
|
|
174
|
-
copyButton.hidden = office;
|
|
175
|
-
// A render from the previous document may still be running. Invalidate it
|
|
176
|
-
// before clearing the body so it cannot append into the new preview.
|
|
177
|
-
if (office) { officeRender++; officeKind = null; }
|
|
178
|
-
body.textContent = "";
|
|
179
|
-
empty.hidden = true;
|
|
180
|
-
languageLabel.textContent = office ? "" : format.label || "";
|
|
181
|
-
languageLabel.hidden = office || !format.label;
|
|
182
|
-
const key = office ? "docPreviewOfficeTooLarge" : "docPreviewTooLarge";
|
|
183
|
-
notice.textContent = app.t(key);
|
|
184
|
-
notice.dataset.i18n = key;
|
|
185
|
-
notice.hidden = false;
|
|
186
|
-
status.textContent = "";
|
|
187
|
-
// The blob is fetched on click, so a huge file still downloads.
|
|
188
|
-
download.disabled = false;
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
const renderOfficeDocument = async (kind, data, request, width = 0) => {
|
|
192
|
-
officeKind = kind;
|
|
193
|
-
const render = ++officeRender;
|
|
194
|
-
dialog.classList.add("is-office");
|
|
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";
|
|
195
58
|
copyButton.hidden = true;
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
if (request !== token || render !== officeRender) return;
|
|
208
|
-
await module.renderOffice(kind, data, host, {
|
|
209
|
-
width: width || undefined,
|
|
210
|
-
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
|
+
});
|
|
211
70
|
});
|
|
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
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
download.disabled = true;
|
|
288
|
-
if (app.preserveReadingLayout) await app.preserveReadingLayout(show);
|
|
289
|
-
else show();
|
|
290
|
-
if (request !== token) return;
|
|
291
|
-
title.focus({ preventScroll: true });
|
|
292
|
-
const office = OFFICE_KINDS.has(format.kind);
|
|
293
|
-
officeKind = office ? format.kind : null;
|
|
294
|
-
const limit = office ? OFFICE_PREVIEW_LIMIT : TEXT_PREVIEW_LIMIT;
|
|
295
|
-
if (format.kind !== "pdf" && Number(resource.size) > limit) { showTooLarge(format); return; }
|
|
296
|
-
try {
|
|
297
|
-
const data = await app.apiBlob(contentPath(roomId, resource.id));
|
|
298
|
-
if (request !== token) return;
|
|
299
|
-
blob = data;
|
|
300
|
-
if (format.kind !== "pdf" && data.size > limit) { showTooLarge(format); return; }
|
|
301
|
-
if (format.kind === "pdf") { renderPdf(resource, data); return; }
|
|
302
|
-
if (office) { await renderOfficeDocument(format.kind, data, request); return; }
|
|
303
|
-
const text = await data.text();
|
|
304
|
-
if (request !== token) return;
|
|
305
|
-
rawText = text;
|
|
306
|
-
if (format.kind === "text") void renderText(text, format, request);
|
|
307
|
-
else {
|
|
308
|
-
renderMarkdown(body, text, app);
|
|
309
|
-
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) => {
|
|
310
146
|
copyButton.hidden = false;
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
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) => {
|
|
316
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
|
+
}
|
|
317
188
|
body.textContent = "";
|
|
318
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");
|
|
319
204
|
copyButton.hidden = true;
|
|
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
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
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
|
+
}
|