@alexsun-top/opencode-chat-room 0.8.0 → 0.8.1
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 +29 -0
- package/LICENSE +2 -2
- package/README.md +38 -6
- package/README.zh-CN.md +38 -6
- package/cli.ts +27 -1
- package/dist/cli.js +5074 -3212
- package/package.json +23 -3
- package/packages/chat-room-channeld/README.md +98 -25
- package/packages/chat-room-channeld/dist/feishu-adapter.js +912 -149
- package/packages/chat-room-channeld/src/adapter.ts +36 -2
- package/packages/chat-room-channeld/src/config.ts +63 -1
- package/packages/chat-room-channeld/src/delivery.ts +6 -1
- package/packages/chat-room-channeld/src/feishu-adapter.ts +122 -292
- package/packages/chat-room-channeld/src/feishu-card.ts +27 -0
- package/packages/chat-room-channeld/src/feishu-inbound.ts +158 -0
- package/packages/chat-room-channeld/src/feishu-live.ts +355 -0
- package/packages/chat-room-channeld/src/feishu-send.ts +342 -0
- package/packages/chat-room-channeld/src/feishu-ws-frames.ts +173 -0
- package/packages/chat-room-channeld/src/host-helpers.ts +11 -0
- package/packages/chat-room-channeld/src/host.ts +120 -2
- package/packages/chat-room-channeld/src/inbound.ts +26 -0
- package/packages/chat-room-channeld/src/state.ts +17 -0
- package/packages/chat-room-channeld/src/stats.ts +43 -1
- package/server/admin-state.ts +13 -13
- package/server/app.ts +95 -0
- package/server/assets/NOTICE.txt +2 -1
- package/server/assets/base.css +15 -9
- package/server/assets/chat/announcements.js +70 -7
- package/server/assets/chat/doc-preview.js +184 -35
- package/server/assets/chat/events.js +3 -0
- package/server/assets/chat/files.js +46 -4
- package/server/assets/chat/index.js +2 -0
- package/server/assets/chat/integration-editor.js +163 -0
- package/server/assets/chat/integration-values.js +124 -0
- package/server/assets/chat/integrations.js +498 -0
- package/server/assets/chat/locales/de.js +40 -4
- package/server/assets/chat/locales/es.js +40 -4
- package/server/assets/chat/locales/fr.js +40 -4
- package/server/assets/chat/locales/it.js +40 -4
- package/server/assets/chat/locales/ja.js +40 -4
- package/server/assets/chat/locales/ko.js +40 -4
- package/server/assets/chat/markdown.js +22 -8
- package/server/assets/chat/messages.js +5 -5
- package/server/assets/chat/office-preview.js +69 -0
- package/server/assets/chat/panels.js +36 -0
- package/server/assets/chat/recall.js +58 -7
- package/server/assets/chat/receipts.js +15 -3
- package/server/assets/chat/reminders.js +69 -8
- package/server/assets/chat/resource-format.js +11 -0
- package/server/assets/chat/settings.js +30 -2
- package/server/assets/chat/side-pane.js +1 -2
- package/server/assets/chat/state.js +93 -10
- package/server/assets/chat/system-events.js +32 -0
- package/server/assets/chat/system-messages.js +23 -14
- package/server/assets/chat/task-row.js +0 -6
- package/server/assets/chat/tasks.js +121 -33
- package/server/assets/code-highlight.css +55 -32
- package/server/assets/conversation.css +123 -23
- package/server/assets/doc-preview.css +35 -3
- package/server/assets/files.css +5 -0
- package/server/assets/fluent-icons.svg +2 -0
- package/server/assets/monaco/LICENSE +21 -0
- package/server/assets/monaco/ThirdPartyNotices.txt +448 -0
- package/server/assets/monaco/codicon-jdswhhtn.ttf +0 -0
- package/server/assets/monaco/editor.worker.js +45 -0
- package/server/assets/monaco/integration-rules.css +1 -0
- package/server/assets/monaco/integration-rules.js +1297 -0
- package/server/assets/monaco/json.worker.js +77 -0
- package/server/assets/office/THIRD-PARTY-NOTICES.txt +11 -0
- package/server/assets/office/docx.bundle.js +33 -0
- package/server/assets/office/licenses/docx-preview-LICENSE.txt +201 -0
- package/server/assets/office/licenses/echarts-LICENSE.txt +222 -0
- package/server/assets/office/licenses/jszip-LICENSE.txt +651 -0
- package/server/assets/office/licenses/lodash-LICENSE.txt +47 -0
- package/server/assets/office/licenses/pptx-preview-LICENSE.txt +8 -0
- package/server/assets/office/licenses/tslib-LICENSE.txt +12 -0
- package/server/assets/office/licenses/uuid-LICENSE.txt +9 -0
- package/server/assets/office/licenses/xlsx-LICENSE.txt +201 -0
- package/server/assets/office/licenses/zrender-LICENSE.txt +29 -0
- package/server/assets/office/pptx.bundle.js +104 -0
- package/server/assets/office/xlsx.bundle.js +141 -0
- package/server/assets/recall.css +5 -4
- package/server/assets/responsive.css +50 -11
- package/server/assets/settings.css +73 -1
- package/server/assets/tasks.css +57 -7
- package/server/channel-integration.ts +519 -0
- package/server/channel-settings.ts +77 -0
- package/server/channels.ts +261 -18
- package/server/chat-server.ts +32 -580
- package/server/chat.html +187 -21
- package/server/http-server.ts +3 -182
- package/server/resource-routes.ts +16 -16
- package/server/routes/inbox.ts +100 -0
- package/server/routes/pages.ts +83 -0
- package/server/routes/questions.ts +39 -0
- package/server/routes/room-actions.ts +162 -0
- package/server/routes/rooms.ts +160 -0
- package/server/startup.ts +84 -0
- package/server/sw.js +4 -0
- package/server/task-routes.ts +1 -1
- package/src/center/center-client.ts +2 -10
- package/src/config/file-config.ts +7 -54
- package/src/platform/http-server.ts +182 -0
- package/src/protocol/addressing.ts +21 -0
- package/src/protocol/config.ts +58 -0
- package/src/protocol/room.ts +51 -0
- package/src/rooms/resources.ts +26 -16
- package/src/rooms/room-service.ts +2 -48
- package/src/rooms/storage.ts +329 -0
- package/src/rooms/tasks.ts +21 -5
- package/src/runtime/watch.ts +1 -1
- package/src/state/pg-database.ts +183 -0
- package/src/state/pg-migrate.ts +175 -0
- package/src/state/pg-sql.mjs +175 -0
- package/src/state/pg-worker.mjs +148 -0
- package/src/state/sqlite-announcements.ts +25 -0
- package/src/state/sqlite-database.ts +121 -0
- package/src/state/sqlite-legacy.ts +90 -0
- package/src/state/sqlite-members.ts +155 -0
- package/src/state/sqlite-messages.ts +288 -0
- package/src/state/sqlite-resources.ts +39 -0
- package/src/state/sqlite-rooms.ts +87 -0
- package/src/state/sqlite-schema.ts +80 -0
- package/src/state/sqlite-state-store.ts +33 -0
- package/src/state/sqlite-state.ts +15 -897
- package/src/state/sqlite-tasks.ts +65 -0
- package/src/state/sqlite-transaction.ts +13 -0
- package/src/state/sqlite.ts +21 -1
- package/src/state/store.ts +5 -1
- package/src/tui/app.mjs +32 -19
- package/src/tui/config.mjs +12 -4
- package/src/tui/i18n.mjs +38 -0
- package/src/tui/info-app.mjs +50 -51
- package/src/tui/info-content.mjs +79 -44
- package/src/tui/join-app.mjs +9 -9
- package/src/tui/locales/en.mjs +349 -0
- package/src/tui/locales/zh-CN.mjs +349 -0
- package/src/tui/main.mjs +85 -37
- package/src/tui/markdown.mjs +3 -2
- package/src/tui/mentions.mjs +3 -1
- package/src/tui/message-app.mjs +22 -21
- package/src/tui/message-view.mjs +2 -1
- package/src/tui/palette-app.mjs +9 -8
- package/src/tui/palette.mjs +30 -24
- package/src/tui/prefs.mjs +92 -0
- package/src/tui/reminder-app.mjs +18 -17
- package/src/tui/room-settings-app.mjs +30 -28
- package/src/tui/settings-app.mjs +153 -0
- package/src/tui/ui-content.mjs +65 -86
- package/src/tui/ui-help.mjs +73 -0
- package/src/tui/ui-overlay-view.mjs +23 -7
- package/src/tui/ui-suggest.mjs +6 -5
- package/src/tui/ui-theme.mjs +37 -33
- package/src/tui/ui-view.mjs +22 -7
- package/src/tui/ui.mjs +15 -3
- package/src/web/editor.worker.ts +1 -0
- package/src/web/integration-rules-editor.ts +439 -0
- package/src/web/integration-rules.ts +22 -0
- package/src/web/integration-schema.ts +228 -0
- package/src/web/json.worker.ts +1 -0
- package/src/web/office-viewer.ts +221 -0
|
@@ -2,9 +2,11 @@ import { LS } from "./state.js";
|
|
|
2
2
|
|
|
3
3
|
export function initAnnouncements(app) {
|
|
4
4
|
const $ = app.$, drafts = new Map();
|
|
5
|
-
const
|
|
5
|
+
const surface = $("#announcementsDialog"), trigger = $("#btnAnnouncements"), list = $("#announcementList");
|
|
6
6
|
const dialog = $("#announcementDialog"), heading = $("#announcementDialogHeading");
|
|
7
|
+
const panelHeading = $("#announcementHeading"), chatView = $("#chatView");
|
|
7
8
|
let items = [], selected = "", generation = 0, roomGeneration = 0, editorRevision = 0, saveToken = 0;
|
|
9
|
+
let opener = null, pendingReopen = false, restoreSurfaceFocus = true;
|
|
8
10
|
const key = (id, name = selected) => `${id}\0${name ? `item\0${name}` : "new"}`;
|
|
9
11
|
const roomId = () => app.state.room?.id;
|
|
10
12
|
const currentRoom = (id, request) => roomId() === id && roomGeneration === request;
|
|
@@ -23,6 +25,48 @@ export function initAnnouncements(app) {
|
|
|
23
25
|
function status(text) { $("#announcementStatus").textContent = text; }
|
|
24
26
|
function formStatus(text) { $("#announcementDialogStatus").textContent = text; }
|
|
25
27
|
function count() { $("#announcementCount").textContent = app.t("announcementCount", { count: Array.from($("#announcementContent").value).length }); }
|
|
28
|
+
const clearPane = () => {
|
|
29
|
+
surface.classList.remove("is-pane");
|
|
30
|
+
if (chatView.dataset.sidePane !== "announcements") return;
|
|
31
|
+
delete chatView.dataset.sidePane;
|
|
32
|
+
chatView.classList.remove("has-pane");
|
|
33
|
+
};
|
|
34
|
+
const showSurface = () => {
|
|
35
|
+
if (app.panelPlacement("announcements") === "pane") {
|
|
36
|
+
app.closeOtherPanelSurfaces?.("announcements");
|
|
37
|
+
surface.classList.add("is-pane");
|
|
38
|
+
chatView.classList.add("has-pane");
|
|
39
|
+
chatView.dataset.sidePane = "announcements";
|
|
40
|
+
if (!surface.open) surface.show();
|
|
41
|
+
} else {
|
|
42
|
+
clearPane();
|
|
43
|
+
if (!surface.open) surface.showModal();
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
const syncMode = () => {
|
|
47
|
+
if (!surface.open || (app.panelPlacement("announcements") === "pane") === surface.classList.contains("is-pane")) return;
|
|
48
|
+
pendingReopen = true;
|
|
49
|
+
surface.close();
|
|
50
|
+
showSurface();
|
|
51
|
+
panelHeading.focus({ preventScroll: true });
|
|
52
|
+
};
|
|
53
|
+
const closeSurface = (focus = true) => {
|
|
54
|
+
restoreSurfaceFocus = focus;
|
|
55
|
+
if (surface.open) surface.close();
|
|
56
|
+
};
|
|
57
|
+
function openSurface() {
|
|
58
|
+
const id = roomId();
|
|
59
|
+
if (!id) return;
|
|
60
|
+
if (app.panelPlacement("announcements") === "pane") app.closeDocPreview?.(false);
|
|
61
|
+
if (surface.open) { panelHeading.focus(); return; }
|
|
62
|
+
app.closePanels?.();
|
|
63
|
+
const active = document.activeElement;
|
|
64
|
+
opener = active instanceof HTMLElement && active !== document.body && !active.closest("dialog") && !$("#roomOptions")?.contains(active)
|
|
65
|
+
? active : $("#btnRoomOptions");
|
|
66
|
+
showSurface();
|
|
67
|
+
panelHeading.focus();
|
|
68
|
+
void load(id);
|
|
69
|
+
}
|
|
26
70
|
function render() {
|
|
27
71
|
list.textContent = "";
|
|
28
72
|
for (const entry of items) {
|
|
@@ -139,16 +183,35 @@ export function initAnnouncements(app) {
|
|
|
139
183
|
dialog.addEventListener("click", (event) => { if (event.target === dialog) dialog.close(); });
|
|
140
184
|
trigger.addEventListener("click", () => {
|
|
141
185
|
// The entry lives in the Options menu, so choosing it closes that menu first.
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
186
|
+
app.closePanels();
|
|
187
|
+
openSurface();
|
|
188
|
+
});
|
|
189
|
+
$("#btnCloseAnnouncements").addEventListener("click", () => closeSurface());
|
|
190
|
+
surface.addEventListener("click", (event) => { if (event.target === surface) closeSurface(); });
|
|
191
|
+
surface.addEventListener("cancel", (event) => { event.preventDefault(); closeSurface(); });
|
|
192
|
+
surface.addEventListener("close", () => {
|
|
193
|
+
if (pendingReopen) { pendingReopen = false; return; }
|
|
194
|
+
clearPane();
|
|
195
|
+
const focus = restoreSurfaceFocus;
|
|
196
|
+
restoreSurfaceFocus = true;
|
|
197
|
+
const target = opener;
|
|
198
|
+
opener = null;
|
|
199
|
+
if (focus && target?.isConnected) target.focus({ preventScroll: true });
|
|
200
|
+
});
|
|
201
|
+
document.addEventListener("keydown", (event) => {
|
|
202
|
+
if (event.key !== "Escape" || !surface.open || !surface.classList.contains("is-pane")) return;
|
|
203
|
+
if (!surface.contains(document.activeElement)) return;
|
|
204
|
+
event.preventDefault();
|
|
205
|
+
closeSurface();
|
|
145
206
|
});
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
207
|
+
app.registerPanelSurface?.("announcements", { close: () => closeSurface(false) });
|
|
208
|
+
app.watchPanel?.("announcements", syncMode);
|
|
209
|
+
const closePanels = app.closePanels;
|
|
210
|
+
app.closePanels = () => { closePanels(); if (dialog.open) dialog.close(); };
|
|
149
211
|
document.addEventListener("chat-room-activated", (event) => {
|
|
150
212
|
const id = event.detail;
|
|
151
213
|
if (dialog.open) dialog.close();
|
|
214
|
+
if (surface.open && !surface.classList.contains("is-pane")) closeSurface(false);
|
|
152
215
|
formStatus("");
|
|
153
216
|
roomGeneration++; generation++; saveToken++; $("#btnSaveAnnouncement").disabled = false;
|
|
154
217
|
selected = ""; items = []; select(null); void load(id);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Markdown resources open in a reading pane on wide screens, or in a modal overlay
|
|
2
2
|
// when the window is too narrow or too short to give the chat a usable column.
|
|
3
3
|
import { formatBytes, renderMarkdown } from "./markdown.js";
|
|
4
|
-
import { docPreviewFormat, TEXT_PREVIEW_LIMIT } from "./resource-format.js";
|
|
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
6
|
import { enhanceCodeElement } from "./shiki.js";
|
|
7
7
|
|
|
@@ -15,9 +15,11 @@ export function initDocPreview(app) {
|
|
|
15
15
|
const empty = app.$("#docPreviewEmpty"), download = app.$("#btnDocPreviewDownload");
|
|
16
16
|
const languageLabel = app.$("#docPreviewLanguage"), notice = app.$("#docPreviewNotice");
|
|
17
17
|
const eyebrow = app.$("#docPreviewEyebrow");
|
|
18
|
+
const fullscreenButton = app.$("#btnDocPreviewFullscreen");
|
|
18
19
|
const chatView = app.$("#chatView"), pane = matchMedia(PANE_QUERY);
|
|
19
|
-
let current = null, blob = null, objectUrl = null, token = 0, opener = null,
|
|
20
|
-
let rawText = "";
|
|
20
|
+
let current = null, blob = null, objectUrl = null, token = 0, opener = null, openerResourceID = null, restoreOnClose = true;
|
|
21
|
+
let rawText = "", fullscreen = false, paneMode = false;
|
|
22
|
+
let officeKind = null, officeRender = 0, pptxWidth = 0, pptxTimer = 0;
|
|
21
23
|
|
|
22
24
|
const copyButton = createCopyButton(app, "doc-preview-copy");
|
|
23
25
|
copyButton.id = "btnDocPreviewCopy";
|
|
@@ -41,23 +43,54 @@ export function initDocPreview(app) {
|
|
|
41
43
|
if (feedback) feedback.textContent = "";
|
|
42
44
|
};
|
|
43
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
|
+
|
|
44
56
|
const show = () => {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
dialog.
|
|
51
|
-
|
|
52
|
-
|
|
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();
|
|
53
67
|
}
|
|
68
|
+
paneMode = targetPane;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
// Full screen is always a modal so the chat behind it stays inert; leaving it
|
|
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();
|
|
54
89
|
};
|
|
55
90
|
|
|
56
91
|
// Crossing the breakpoint keeps the document: the pane becomes an overlay, or back.
|
|
57
92
|
const syncMode = () => {
|
|
58
|
-
if (!dialog.open || pane.matches ===
|
|
59
|
-
pendingReopen = true;
|
|
60
|
-
dialog.close();
|
|
93
|
+
if (!dialog.open || fullscreen || pane.matches === paneMode) return;
|
|
61
94
|
show();
|
|
62
95
|
title.focus({ preventScroll: true });
|
|
63
96
|
};
|
|
@@ -66,7 +99,7 @@ export function initDocPreview(app) {
|
|
|
66
99
|
|
|
67
100
|
const clearFrame = () => {
|
|
68
101
|
if (objectUrl) { URL.revokeObjectURL(objectUrl); objectUrl = null; }
|
|
69
|
-
dialog.classList.remove("is-pdf");
|
|
102
|
+
dialog.classList.remove("is-pdf", "is-office");
|
|
70
103
|
};
|
|
71
104
|
|
|
72
105
|
const renderText = (text, format) => {
|
|
@@ -87,19 +120,67 @@ export function initDocPreview(app) {
|
|
|
87
120
|
|
|
88
121
|
const showTooLarge = (format) => {
|
|
89
122
|
clearFrame();
|
|
90
|
-
|
|
123
|
+
const office = OFFICE_KINDS.has(format.kind);
|
|
124
|
+
copyButton.hidden = office;
|
|
125
|
+
// A render from the previous document may still be running. Invalidate it
|
|
126
|
+
// before clearing the body so it cannot append into the new preview.
|
|
127
|
+
if (office) { officeRender++; officeKind = null; }
|
|
91
128
|
body.textContent = "";
|
|
92
129
|
empty.hidden = true;
|
|
93
|
-
languageLabel.textContent = format.label || "";
|
|
94
|
-
languageLabel.hidden = !format.label;
|
|
95
|
-
|
|
96
|
-
notice.
|
|
130
|
+
languageLabel.textContent = office ? "" : format.label || "";
|
|
131
|
+
languageLabel.hidden = office || !format.label;
|
|
132
|
+
const key = office ? "docPreviewOfficeTooLarge" : "docPreviewTooLarge";
|
|
133
|
+
notice.textContent = app.t(key);
|
|
134
|
+
notice.dataset.i18n = key;
|
|
97
135
|
notice.hidden = false;
|
|
98
136
|
status.textContent = "";
|
|
99
137
|
// The blob is fetched on click, so a huge file still downloads.
|
|
100
138
|
download.disabled = false;
|
|
101
139
|
};
|
|
102
140
|
|
|
141
|
+
const renderOfficeDocument = async (kind, data, request, width = 0) => {
|
|
142
|
+
officeKind = kind;
|
|
143
|
+
const render = ++officeRender;
|
|
144
|
+
dialog.classList.add("is-office");
|
|
145
|
+
copyButton.hidden = true;
|
|
146
|
+
languageLabel.hidden = true;
|
|
147
|
+
// Render into a private container. A render from an earlier document can
|
|
148
|
+
// finish after the user has switched files; it must never touch the live body.
|
|
149
|
+
const host = document.createElement("div");
|
|
150
|
+
host.className = "office-preview";
|
|
151
|
+
body.replaceChildren(host);
|
|
152
|
+
empty.hidden = true;
|
|
153
|
+
notice.hidden = true;
|
|
154
|
+
// The blob is already here, so download stays available while parsing or after a failure.
|
|
155
|
+
download.disabled = false;
|
|
156
|
+
const module = await import("/assets/chat/office-preview.js");
|
|
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"); },
|
|
161
|
+
});
|
|
162
|
+
if (request !== token || render !== officeRender || !host.isConnected) return;
|
|
163
|
+
body.replaceChildren(host);
|
|
164
|
+
if (kind === "pptx") pptxWidth = Math.round(width || body.clientWidth);
|
|
165
|
+
status.textContent = "";
|
|
166
|
+
empty.hidden = body.children.length > 0;
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
// A fixed-width slide deck must be laid out again when the reading pane grows
|
|
170
|
+
// (full screen, splitter drag, breakpoint change), or it stays pane-sized.
|
|
171
|
+
const resizePptx = () => {
|
|
172
|
+
if (!dialog.open || officeKind !== "pptx" || !blob) return;
|
|
173
|
+
const width = Math.round(body.clientWidth);
|
|
174
|
+
if (width < 200 || Math.abs(width - pptxWidth) < 8) return;
|
|
175
|
+
clearTimeout(pptxTimer);
|
|
176
|
+
pptxTimer = setTimeout(() => {
|
|
177
|
+
if (dialog.open && officeKind === "pptx" && blob) {
|
|
178
|
+
void renderOfficeDocument("pptx", blob, token, width);
|
|
179
|
+
}
|
|
180
|
+
}, 150);
|
|
181
|
+
};
|
|
182
|
+
if (typeof ResizeObserver === "function") new ResizeObserver(resizePptx).observe(body);
|
|
183
|
+
|
|
103
184
|
const renderPdf = (resource, data) => {
|
|
104
185
|
copyButton.hidden = true;
|
|
105
186
|
const pdf = data.type === "application/pdf" ? data : data.slice(0, data.size, "application/pdf");
|
|
@@ -127,6 +208,7 @@ export function initDocPreview(app) {
|
|
|
127
208
|
|
|
128
209
|
const open = async (roomId, resource, source) => {
|
|
129
210
|
opener = source instanceof HTMLElement ? source : null;
|
|
211
|
+
openerResourceID = source instanceof HTMLElement ? source.dataset.previewResource || null : null;
|
|
130
212
|
restoreOnClose = true;
|
|
131
213
|
current = { roomId, resource };
|
|
132
214
|
const request = ++token;
|
|
@@ -136,6 +218,9 @@ export function initDocPreview(app) {
|
|
|
136
218
|
copyButton.hidden = true;
|
|
137
219
|
resetCopy();
|
|
138
220
|
clearFrame();
|
|
221
|
+
officeKind = null;
|
|
222
|
+
pptxWidth = 0;
|
|
223
|
+
clearTimeout(pptxTimer);
|
|
139
224
|
const eyebrowKey = format.kind === "markdown" ? "docPreviewEyebrow" : "docPreviewFileEyebrow";
|
|
140
225
|
eyebrow.dataset.i18n = eyebrowKey;
|
|
141
226
|
eyebrow.textContent = app.t(eyebrowKey);
|
|
@@ -154,14 +239,17 @@ export function initDocPreview(app) {
|
|
|
154
239
|
else show();
|
|
155
240
|
if (request !== token) return;
|
|
156
241
|
title.focus({ preventScroll: true });
|
|
157
|
-
const
|
|
158
|
-
|
|
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; }
|
|
159
246
|
try {
|
|
160
247
|
const data = await app.apiBlob(contentPath(roomId, resource.id));
|
|
161
248
|
if (request !== token) return;
|
|
162
249
|
blob = data;
|
|
163
|
-
if (
|
|
250
|
+
if (format.kind !== "pdf" && data.size > limit) { showTooLarge(format); return; }
|
|
164
251
|
if (format.kind === "pdf") { renderPdf(resource, data); return; }
|
|
252
|
+
if (office) { await renderOfficeDocument(format.kind, data, request); return; }
|
|
165
253
|
const text = await data.text();
|
|
166
254
|
if (request !== token) return;
|
|
167
255
|
rawText = text;
|
|
@@ -176,15 +264,55 @@ export function initDocPreview(app) {
|
|
|
176
264
|
} catch {
|
|
177
265
|
if (request === token) {
|
|
178
266
|
clearFrame();
|
|
267
|
+
body.textContent = "";
|
|
268
|
+
empty.hidden = true;
|
|
179
269
|
copyButton.hidden = true;
|
|
180
|
-
|
|
270
|
+
if (office) {
|
|
271
|
+
status.textContent = "";
|
|
272
|
+
notice.textContent = app.t("docPreviewOfficeFailed");
|
|
273
|
+
notice.dataset.i18n = "docPreviewOfficeFailed";
|
|
274
|
+
notice.hidden = false;
|
|
275
|
+
download.disabled = false;
|
|
276
|
+
} else status.textContent = app.t("docPreviewFailed");
|
|
181
277
|
}
|
|
182
278
|
}
|
|
183
279
|
};
|
|
184
280
|
|
|
281
|
+
const focusReplacement = (resourceID, allowComposer = false) => {
|
|
282
|
+
if (!resourceID) {
|
|
283
|
+
if (allowComposer) app.focusChatComposer?.({ force: true });
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
const query = `#msgList [data-preview-resource="${CSS.escape(resourceID)}"]`;
|
|
287
|
+
const replacement = query ? document.querySelector(query) : null;
|
|
288
|
+
if (replacement instanceof HTMLElement && replacement.getClientRects().length) {
|
|
289
|
+
replacement.focus({ preventScroll: true });
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
// The message list may be halfway through an async card rerender. Retry
|
|
293
|
+
// briefly, but never steal focus if the reader has already clicked elsewhere.
|
|
294
|
+
const active = document.activeElement;
|
|
295
|
+
if (active && active !== document.body && active.id !== "msgInput") return;
|
|
296
|
+
if (performance.now() < focusReplacement.until) {
|
|
297
|
+
requestAnimationFrame(() => focusReplacement(resourceID, allowComposer));
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
if (allowComposer && (document.activeElement === document.body || document.activeElement?.id === "msgInput")) {
|
|
301
|
+
document.querySelector("#msgInput")?.focus({ preventScroll: true });
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
|
|
185
305
|
const close = (restoreFocus = true) => {
|
|
186
306
|
restoreOnClose = restoreFocus;
|
|
187
307
|
if (!restoreFocus) opener = null;
|
|
308
|
+
// Invalidate in-flight fetches and Office renders before the close event
|
|
309
|
+
// runs, so none of them can repaint the preview after it starts closing.
|
|
310
|
+
token++;
|
|
311
|
+
officeRender++;
|
|
312
|
+
officeKind = null;
|
|
313
|
+
clearTimeout(pptxTimer);
|
|
314
|
+
// Closing from full screen leaves the locked page as part of the same step.
|
|
315
|
+
if (fullscreen) leaveFullscreen();
|
|
188
316
|
// Remove the column class now; the queued close event must not leave Tasks
|
|
189
317
|
// hidden behind a column the task pane is about to take back.
|
|
190
318
|
chatView.classList.remove("has-doc");
|
|
@@ -218,25 +346,41 @@ export function initDocPreview(app) {
|
|
|
218
346
|
|
|
219
347
|
app.openDocPreview = (roomId, resource, source) => { void open(roomId, resource, source); };
|
|
220
348
|
app.closeDocPreview = (restoreFocus = true) => close(restoreFocus);
|
|
349
|
+
updateFullscreenButton();
|
|
221
350
|
|
|
222
351
|
app.$("#btnCloseDocPreview")?.addEventListener("click", () => close());
|
|
352
|
+
fullscreenButton?.addEventListener("click", () => setFullscreen(!fullscreen));
|
|
223
353
|
download.addEventListener("click", downloadDocument);
|
|
224
354
|
dialog.addEventListener("click", (event) => {
|
|
225
|
-
if (event.target === dialog && !dialog.classList.contains("is-pane")) close();
|
|
355
|
+
if (event.target === dialog && !fullscreen && !dialog.classList.contains("is-pane")) close();
|
|
226
356
|
});
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
if (event.key !== "Escape" || !dialog.open || !dialog.classList.contains("is-pane")) return;
|
|
357
|
+
const escapePreview = (event) => {
|
|
358
|
+
if (!event || event.key !== "Escape" || !dialog.open) return;
|
|
230
359
|
event.preventDefault();
|
|
231
|
-
|
|
232
|
-
|
|
360
|
+
event.stopPropagation();
|
|
361
|
+
// The first Esc leaves full screen; the next one closes the preview.
|
|
362
|
+
if (fullscreen) setFullscreen(false);
|
|
363
|
+
else close();
|
|
364
|
+
};
|
|
365
|
+
document.addEventListener("keydown", (event) => {
|
|
366
|
+
// Capture Escape while the preview is open: leaving full screen closes and
|
|
367
|
+
// reopens the dialog, and the reopened dialog must still obey the next Esc.
|
|
368
|
+
escapePreview(event);
|
|
369
|
+
}, true);
|
|
370
|
+
dialog.addEventListener("cancel", escapePreview);
|
|
233
371
|
dialog.addEventListener("close", () => {
|
|
234
|
-
// A breakpoint switch closes and reopens the same
|
|
235
|
-
// must not wipe the document that is already
|
|
236
|
-
|
|
372
|
+
// A breakpoint switch or leaving full screen closes and reopens the same
|
|
373
|
+
// dialog. Its queued close event must not wipe the document that is already
|
|
374
|
+
// back on screen, so it is stale whenever the dialog has been reopened.
|
|
375
|
+
if (dialog.open) { restoreOnClose = true; return; }
|
|
237
376
|
const shouldRestore = restoreOnClose;
|
|
238
377
|
restoreOnClose = true;
|
|
239
378
|
token++;
|
|
379
|
+
leaveFullscreen();
|
|
380
|
+
officeRender++;
|
|
381
|
+
officeKind = null;
|
|
382
|
+
pptxWidth = 0;
|
|
383
|
+
clearTimeout(pptxTimer);
|
|
240
384
|
current = null; blob = null; rawText = "";
|
|
241
385
|
copyButton.hidden = true;
|
|
242
386
|
resetCopy();
|
|
@@ -249,8 +393,13 @@ export function initDocPreview(app) {
|
|
|
249
393
|
notice.hidden = true; notice.textContent = ""; delete notice.dataset.i18n;
|
|
250
394
|
const target = opener; opener = null;
|
|
251
395
|
if (!shouldRestore) return;
|
|
252
|
-
if (target?.isConnected && target.getClientRects().length) target.focus({ preventScroll: true });
|
|
253
|
-
|
|
396
|
+
if (target?.isConnected && target.getClientRects().length) { target.focus({ preventScroll: true }); return; }
|
|
397
|
+
// Inbox polling can rerender the message list while the preview is open,
|
|
398
|
+
// replacing the button that opened it. Focus the current equivalent.
|
|
399
|
+
const resourceID = openerResourceID;
|
|
400
|
+
openerResourceID = null;
|
|
401
|
+
focusReplacement.until = performance.now() + 600;
|
|
402
|
+
focusReplacement(resourceID, true);
|
|
254
403
|
});
|
|
255
404
|
const onChange = () => syncMode();
|
|
256
405
|
if (pane.addEventListener) pane.addEventListener("change", onChange);
|
|
@@ -332,6 +332,9 @@ export function initEvents(app) {
|
|
|
332
332
|
// Stop wheel overscroll at the ends. Without this, some layouts let the
|
|
333
333
|
// document absorb the leftover delta and the view jumps a few pixels.
|
|
334
334
|
thread.addEventListener("wheel", (event) => {
|
|
335
|
+
// Trackpad pinch arrives as Ctrl/Cmd + wheel. Blocking it at a scroll
|
|
336
|
+
// edge would also block browser zoom-out.
|
|
337
|
+
if (event.ctrlKey || event.metaKey) return;
|
|
335
338
|
markScrollIntent();
|
|
336
339
|
const gap = thread.scrollHeight - thread.clientHeight - thread.scrollTop;
|
|
337
340
|
if (event.deltaY < 0 && thread.scrollTop <= 0 || event.deltaY > 0 && gap <= 2) event.preventDefault();
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { LS } from "./state.js";
|
|
3
3
|
import { isRoomAdmin } from "./admin-badge.js";
|
|
4
4
|
import { icon } from "./icons.js";
|
|
5
|
-
import { docPreviewFormat, isDocPreviewResource, TEXT_PREVIEW_LIMIT } from "./resource-format.js";
|
|
5
|
+
import { docPreviewFormat, isDocPreviewResource, OFFICE_KINDS, TEXT_PREVIEW_LIMIT } from "./resource-format.js";
|
|
6
6
|
import { createCopyButton, copyResourceText } from "./copy-action.js";
|
|
7
7
|
|
|
8
8
|
const PAGE_SIZE = 500;
|
|
@@ -23,8 +23,9 @@ export function initFiles(app) {
|
|
|
23
23
|
const $ = app.$;
|
|
24
24
|
const list = $("#fileList"), select = $("#filesUploader"), summary = $("#filesSummary");
|
|
25
25
|
const empty = $("#filesEmpty"), error = $("#filesError"), more = $("#btnFilesMore");
|
|
26
|
-
const roomName = $("#filesRoomName"), heading = $("#filesHeading"), trigger = $("#btnFiles");
|
|
26
|
+
const roomName = $("#filesRoomName"), heading = $("#filesHeading"), trigger = $("#btnFiles"), chatView = $("#chatView");
|
|
27
27
|
let items = [], total = 0, loading = false, generation = 0, opener = null, preview = null, previewToken = 0;
|
|
28
|
+
let pendingReopen = false;
|
|
28
29
|
|
|
29
30
|
const mediaKind = (mime) => /^image\//.test(mime || "") ? "image"
|
|
30
31
|
: /^audio\//.test(mime || "") ? "audio"
|
|
@@ -185,7 +186,8 @@ export function initFiles(app) {
|
|
|
185
186
|
actions.className = "file-actions";
|
|
186
187
|
const previewID = `file-preview-${resource.id}`;
|
|
187
188
|
const docPreview = isDocPreviewResource(resource);
|
|
188
|
-
const
|
|
189
|
+
const previewFormat = docPreview ? docPreviewFormat(resource) : null;
|
|
190
|
+
const textPreview = Boolean(previewFormat && previewFormat.kind !== "pdf" && !OFFICE_KINDS.has(previewFormat.kind));
|
|
189
191
|
if (mediaKind(resource.mimeType) || docPreview) {
|
|
190
192
|
const inline = mediaKind(resource.mimeType);
|
|
191
193
|
actions.append(actionButton("preview", app.t("filesPreviewLabel", { name: resource.name }), ICONS.preview, inline
|
|
@@ -306,8 +308,35 @@ export function initFiles(app) {
|
|
|
306
308
|
hideError();
|
|
307
309
|
};
|
|
308
310
|
|
|
311
|
+
const clearPane = () => {
|
|
312
|
+
dialog.classList.remove("is-pane");
|
|
313
|
+
if (chatView.dataset.sidePane !== "files") return;
|
|
314
|
+
delete chatView.dataset.sidePane;
|
|
315
|
+
chatView.classList.remove("has-pane");
|
|
316
|
+
};
|
|
317
|
+
const show = () => {
|
|
318
|
+
if (app.panelPlacement("files") === "pane") {
|
|
319
|
+
app.closeOtherPanelSurfaces?.("files");
|
|
320
|
+
dialog.classList.add("is-pane");
|
|
321
|
+
chatView.classList.add("has-pane");
|
|
322
|
+
chatView.dataset.sidePane = "files";
|
|
323
|
+
if (!dialog.open) dialog.show();
|
|
324
|
+
} else {
|
|
325
|
+
clearPane();
|
|
326
|
+
if (!dialog.open) dialog.showModal();
|
|
327
|
+
}
|
|
328
|
+
};
|
|
329
|
+
const syncMode = () => {
|
|
330
|
+
if (!dialog.open || (app.panelPlacement("files") === "pane") === dialog.classList.contains("is-pane")) return;
|
|
331
|
+
pendingReopen = true;
|
|
332
|
+
dialog.close();
|
|
333
|
+
show();
|
|
334
|
+
heading.focus({ preventScroll: true });
|
|
335
|
+
};
|
|
336
|
+
|
|
309
337
|
const open = () => {
|
|
310
338
|
if (!app.state.room) return;
|
|
339
|
+
if (app.panelPlacement("files") === "pane") app.closeDocPreview?.(false);
|
|
311
340
|
if (dialog.open) { heading.focus(); return; }
|
|
312
341
|
app.closePanels?.();
|
|
313
342
|
const active = document.activeElement;
|
|
@@ -323,7 +352,7 @@ export function initFiles(app) {
|
|
|
323
352
|
closePreview();
|
|
324
353
|
summary.textContent = app.t("filesLoading");
|
|
325
354
|
roomName.textContent = app.state.room.name ? ` · ${app.state.room.name}` : "";
|
|
326
|
-
|
|
355
|
+
show();
|
|
327
356
|
heading.focus();
|
|
328
357
|
Promise.resolve(app.loadManageableMembers?.()).then(() => { if (dialog.open && items.length) render(); });
|
|
329
358
|
void load(true);
|
|
@@ -334,17 +363,30 @@ export function initFiles(app) {
|
|
|
334
363
|
|
|
335
364
|
trigger?.addEventListener("click", () => { app.closePanels(); open(); });
|
|
336
365
|
$("#btnCloseFiles")?.addEventListener("click", close);
|
|
366
|
+
document.addEventListener("keydown", (event) => {
|
|
367
|
+
if (event.key !== "Escape" || !dialog.open || !dialog.classList.contains("is-pane")) return;
|
|
368
|
+
if (!dialog.contains(document.activeElement)) return;
|
|
369
|
+
event.preventDefault();
|
|
370
|
+
close();
|
|
371
|
+
});
|
|
372
|
+
app.registerPanelSurface?.("files", { close });
|
|
373
|
+
app.watchPanel?.("files", syncMode);
|
|
337
374
|
$("#btnRefreshFiles")?.addEventListener("click", () => void load(true));
|
|
338
375
|
more.addEventListener("click", () => void load(false));
|
|
339
376
|
select.addEventListener("change", render);
|
|
340
377
|
dialog.addEventListener("click", (event) => { if (event.target === dialog) close(); });
|
|
341
378
|
dialog.addEventListener("cancel", (event) => { event.preventDefault(); close(); });
|
|
342
379
|
dialog.addEventListener("close", () => {
|
|
380
|
+
// close() queues this event; a rapid reopen can land before it runs, and
|
|
381
|
+
// clearing here would wipe the freshly opened dialog and its in-flight load.
|
|
382
|
+
if (pendingReopen) { pendingReopen = false; return; }
|
|
383
|
+
if (dialog.open) return;
|
|
343
384
|
generation++;
|
|
344
385
|
loading = false;
|
|
345
386
|
setBusy(false);
|
|
346
387
|
previewToken++;
|
|
347
388
|
closePreview();
|
|
389
|
+
clearPane();
|
|
348
390
|
items = [];
|
|
349
391
|
total = 0;
|
|
350
392
|
list.textContent = "";
|
|
@@ -30,10 +30,12 @@ import { initSidePaneSplitter } from "./side-pane.js";
|
|
|
30
30
|
import { initDiagramViewer } from "./diagram-viewer.js";
|
|
31
31
|
import { initViewport } from "./viewport.js";
|
|
32
32
|
import { initSettings } from "./settings.js";
|
|
33
|
+
import { initIntegrations } from "./integrations.js";
|
|
33
34
|
|
|
34
35
|
if (isMobileDevice()) document.documentElement.dataset.mobile = "true";
|
|
35
36
|
|
|
36
37
|
initSettings(app);
|
|
38
|
+
initIntegrations(app);
|
|
37
39
|
initConfirmDialog(app);
|
|
38
40
|
initDiagramViewer(app);
|
|
39
41
|
initMentions(app);
|