@alexsun-top/opencode-chat-room 0.8.0 → 0.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (176) hide show
  1. package/CHANGELOG.md +52 -0
  2. package/LICENSE +2 -2
  3. package/README.md +40 -8
  4. package/README.zh-CN.md +40 -8
  5. package/cli.ts +27 -1
  6. package/dist/cli.js +5406 -3088
  7. package/package.json +25 -5
  8. package/packages/chat-room-channeld/README.md +111 -33
  9. package/packages/chat-room-channeld/src/adapter.ts +179 -7
  10. package/packages/chat-room-channeld/src/config.ts +63 -1
  11. package/packages/chat-room-channeld/src/delivery.ts +6 -1
  12. package/packages/chat-room-channeld/src/host-helpers.ts +11 -0
  13. package/packages/chat-room-channeld/src/host.ts +142 -9
  14. package/packages/chat-room-channeld/src/inbound.ts +35 -0
  15. package/packages/chat-room-channeld/src/protocol.ts +52 -1
  16. package/packages/chat-room-channeld/src/rules.ts +7 -2
  17. package/packages/chat-room-channeld/src/state.ts +17 -0
  18. package/packages/chat-room-channeld/src/stats.ts +43 -1
  19. package/plugin.ts +1 -1
  20. package/server/admin-state.ts +13 -13
  21. package/server/app.ts +95 -0
  22. package/server/assets/NOTICE.txt +2 -1
  23. package/server/assets/base.css +21 -9
  24. package/server/assets/chat/admin.js +0 -2
  25. package/server/assets/chat/announcements.js +69 -8
  26. package/server/assets/chat/chat-background.js +177 -0
  27. package/server/assets/chat/confirm-dialog.js +0 -1
  28. package/server/assets/chat/create-room-dialog.js +0 -1
  29. package/server/assets/chat/diagram-viewer.js +7 -1
  30. package/server/assets/chat/doc-preview.js +251 -46
  31. package/server/assets/chat/events.js +16 -5
  32. package/server/assets/chat/files.js +53 -7
  33. package/server/assets/chat/image-zoom.js +8 -1
  34. package/server/assets/chat/index.js +6 -2
  35. package/server/assets/chat/integration-account-schema.js +99 -0
  36. package/server/assets/chat/integration-editor.js +163 -0
  37. package/server/assets/chat/integration-values.js +124 -0
  38. package/server/assets/chat/integrations.js +648 -0
  39. package/server/assets/chat/locales/de.js +40 -4
  40. package/server/assets/chat/locales/es.js +40 -4
  41. package/server/assets/chat/locales/fr.js +40 -4
  42. package/server/assets/chat/locales/it.js +40 -4
  43. package/server/assets/chat/locales/ja.js +40 -4
  44. package/server/assets/chat/locales/ko.js +40 -4
  45. package/server/assets/chat/markdown-footnotes.js +1 -1
  46. package/server/assets/chat/markdown.js +45 -8
  47. package/server/assets/chat/messages.js +6 -5
  48. package/server/assets/chat/office-preview.js +69 -0
  49. package/server/assets/chat/palette.js +6 -1
  50. package/server/assets/chat/panels.js +56 -0
  51. package/server/assets/chat/recall.js +58 -7
  52. package/server/assets/chat/receipts.js +17 -6
  53. package/server/assets/chat/reminders.js +68 -9
  54. package/server/assets/chat/replies.js +0 -6
  55. package/server/assets/chat/resource-format.js +11 -0
  56. package/server/assets/chat/rooms.js +1 -6
  57. package/server/assets/chat/settings.js +98 -4
  58. package/server/assets/chat/shortcuts.js +0 -3
  59. package/server/assets/chat/side-pane.js +34 -10
  60. package/server/assets/chat/state.js +125 -12
  61. package/server/assets/chat/system-events.js +58 -0
  62. package/server/assets/chat/system-messages.js +32 -14
  63. package/server/assets/chat/task-row.js +0 -6
  64. package/server/assets/chat/tasks.js +119 -37
  65. package/server/assets/chat/window-controls.js +37 -0
  66. package/server/assets/code-highlight.css +71 -32
  67. package/server/assets/conversation.css +174 -31
  68. package/server/assets/doc-preview.css +40 -3
  69. package/server/assets/files.css +8 -0
  70. package/server/assets/fluent-icons.svg +2 -0
  71. package/server/assets/monaco/LICENSE +21 -0
  72. package/server/assets/monaco/ThirdPartyNotices.txt +448 -0
  73. package/server/assets/monaco/codicon-jdswhhtn.ttf +0 -0
  74. package/server/assets/monaco/editor.worker.js +45 -0
  75. package/server/assets/monaco/integration-rules.css +1 -0
  76. package/server/assets/monaco/integration-rules.js +1605 -0
  77. package/server/assets/monaco/json.worker.js +77 -0
  78. package/server/assets/office/THIRD-PARTY-NOTICES.txt +11 -0
  79. package/server/assets/office/docx.bundle.js +33 -0
  80. package/server/assets/office/licenses/docx-preview-LICENSE.txt +201 -0
  81. package/server/assets/office/licenses/echarts-LICENSE.txt +222 -0
  82. package/server/assets/office/licenses/jszip-LICENSE.txt +651 -0
  83. package/server/assets/office/licenses/lodash-LICENSE.txt +47 -0
  84. package/server/assets/office/licenses/pptx-preview-LICENSE.txt +8 -0
  85. package/server/assets/office/licenses/tslib-LICENSE.txt +12 -0
  86. package/server/assets/office/licenses/uuid-LICENSE.txt +9 -0
  87. package/server/assets/office/licenses/xlsx-LICENSE.txt +201 -0
  88. package/server/assets/office/licenses/zrender-LICENSE.txt +29 -0
  89. package/server/assets/office/pptx.bundle.js +104 -0
  90. package/server/assets/office/xlsx.bundle.js +141 -0
  91. package/server/assets/recall.css +5 -4
  92. package/server/assets/responsive.css +80 -11
  93. package/server/assets/settings.css +185 -9
  94. package/server/assets/tasks.css +57 -7
  95. package/server/assets/window-controls.css +36 -0
  96. package/server/channel-attachments.ts +133 -0
  97. package/server/channel-integration.ts +572 -0
  98. package/server/channel-settings.ts +77 -0
  99. package/server/channels.ts +274 -21
  100. package/server/chat-server.ts +32 -580
  101. package/server/chat.html +234 -34
  102. package/server/http-server.ts +3 -182
  103. package/server/manifest.webmanifest +1 -0
  104. package/server/resource-routes.ts +16 -16
  105. package/server/routes/inbox.ts +100 -0
  106. package/server/routes/pages.ts +83 -0
  107. package/server/routes/questions.ts +39 -0
  108. package/server/routes/room-actions.ts +162 -0
  109. package/server/routes/rooms.ts +160 -0
  110. package/server/startup.ts +84 -0
  111. package/server/sw.js +5 -0
  112. package/server/task-routes.ts +1 -1
  113. package/src/center/center-client.ts +3 -11
  114. package/src/config/file-config.ts +7 -54
  115. package/src/platform/http-server.ts +182 -0
  116. package/src/protocol/addressing.ts +21 -0
  117. package/src/protocol/config.ts +58 -0
  118. package/src/protocol/room.ts +51 -0
  119. package/src/rooms/resources.ts +26 -16
  120. package/src/rooms/room-service.ts +2 -48
  121. package/src/rooms/storage.ts +329 -0
  122. package/src/rooms/tasks.ts +21 -5
  123. package/src/runtime/watch.ts +1 -1
  124. package/src/state/pg-database.ts +183 -0
  125. package/src/state/pg-migrate.ts +175 -0
  126. package/src/state/pg-sql.mjs +175 -0
  127. package/src/state/pg-worker.mjs +133 -0
  128. package/src/state/sqlite-announcements.ts +25 -0
  129. package/src/state/sqlite-database.ts +130 -0
  130. package/src/state/sqlite-legacy.ts +90 -0
  131. package/src/state/sqlite-members.ts +155 -0
  132. package/src/state/sqlite-messages.ts +288 -0
  133. package/src/state/sqlite-resources.ts +39 -0
  134. package/src/state/sqlite-rooms.ts +194 -0
  135. package/src/state/sqlite-schema.ts +80 -0
  136. package/src/state/sqlite-state-store.ts +34 -0
  137. package/src/state/sqlite-state.ts +15 -897
  138. package/src/state/sqlite-tasks.ts +65 -0
  139. package/src/state/sqlite-transaction.ts +13 -0
  140. package/src/state/sqlite.ts +21 -1
  141. package/src/state/store.ts +5 -1
  142. package/src/tui/app.mjs +32 -19
  143. package/src/tui/config.mjs +12 -4
  144. package/src/tui/i18n.mjs +38 -0
  145. package/src/tui/info-app.mjs +50 -51
  146. package/src/tui/info-content.mjs +79 -44
  147. package/src/tui/join-app.mjs +9 -9
  148. package/src/tui/locales/en.mjs +349 -0
  149. package/src/tui/locales/zh-CN.mjs +349 -0
  150. package/src/tui/main.mjs +85 -37
  151. package/src/tui/markdown.mjs +3 -2
  152. package/src/tui/mentions.mjs +3 -1
  153. package/src/tui/message-app.mjs +22 -21
  154. package/src/tui/message-view.mjs +2 -1
  155. package/src/tui/palette-app.mjs +9 -8
  156. package/src/tui/palette.mjs +30 -24
  157. package/src/tui/prefs.mjs +92 -0
  158. package/src/tui/reminder-app.mjs +18 -17
  159. package/src/tui/room-settings-app.mjs +30 -28
  160. package/src/tui/settings-app.mjs +153 -0
  161. package/src/tui/ui-content.mjs +65 -86
  162. package/src/tui/ui-help.mjs +73 -0
  163. package/src/tui/ui-overlay-view.mjs +23 -7
  164. package/src/tui/ui-suggest.mjs +6 -5
  165. package/src/tui/ui-theme.mjs +37 -33
  166. package/src/tui/ui-view.mjs +22 -7
  167. package/src/tui/ui.mjs +15 -3
  168. package/src/web/editor.worker.ts +1 -0
  169. package/src/web/integration-rules-editor.ts +573 -0
  170. package/src/web/integration-rules.ts +26 -0
  171. package/src/web/integration-schema.ts +229 -0
  172. package/src/web/json.worker.ts +1 -0
  173. package/src/web/office-viewer.ts +221 -0
  174. package/packages/chat-room-channeld/dist/feishu-adapter.js +0 -499
  175. package/packages/chat-room-channeld/src/feishu-adapter.ts +0 -473
  176. package/server/assets/chat/forward.js +0 -69
@@ -1,11 +1,47 @@
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
- import { enhanceCodeElement } from "./shiki.js";
7
6
 
8
7
  const PANE_QUERY = "(min-width: 1100px) and (min-height: 560px)";
8
+ const MONACO_BUNDLE_URL = "/assets/monaco/integration-rules.js";
9
+ const MONACO_STYLES_URL = "/assets/monaco/integration-rules.css";
10
+ let monacoPromise = null;
11
+ let codeEditor = null;
12
+
13
+ function loadMonaco() {
14
+ if (!monacoPromise) {
15
+ monacoPromise = import(MONACO_BUNDLE_URL)
16
+ .then((module) => {
17
+ if (!document.querySelector("link[data-doc-code-editor]")) {
18
+ const link = document.createElement("link");
19
+ link.rel = "stylesheet";
20
+ link.href = MONACO_STYLES_URL;
21
+ link.dataset.docCodeEditor = "true";
22
+ document.head.append(link);
23
+ }
24
+ return module;
25
+ })
26
+ .catch((error) => {
27
+ // A blocked asset must not surface as an uncaught page error; the plain text view stays.
28
+ console.warn("Code preview editor unavailable; keeping the plain text view.", error);
29
+ throw error;
30
+ });
31
+ }
32
+ return monacoPromise;
33
+ }
34
+
35
+ // Fallback for a failed Monaco import: the same plain block the preview used before.
36
+ function plainCode(text, format) {
37
+ const pre = document.createElement("pre");
38
+ pre.className = "code-block doc-code";
39
+ const code = document.createElement("code");
40
+ code.className = format.language ? `language-${format.language}` : "";
41
+ code.textContent = text;
42
+ pre.append(code);
43
+ return pre;
44
+ }
9
45
 
10
46
  export function initDocPreview(app) {
11
47
  const dialog = app.$("#docPreview");
@@ -15,9 +51,11 @@ export function initDocPreview(app) {
15
51
  const empty = app.$("#docPreviewEmpty"), download = app.$("#btnDocPreviewDownload");
16
52
  const languageLabel = app.$("#docPreviewLanguage"), notice = app.$("#docPreviewNotice");
17
53
  const eyebrow = app.$("#docPreviewEyebrow");
54
+ const fullscreenButton = app.$("#btnDocPreviewFullscreen");
18
55
  const chatView = app.$("#chatView"), pane = matchMedia(PANE_QUERY);
19
- let current = null, blob = null, objectUrl = null, token = 0, opener = null, pendingReopen = false, restoreOnClose = true;
20
- let rawText = "";
56
+ let current = null, blob = null, objectUrl = null, token = 0, opener = null, openerResourceID = null, restoreOnClose = true;
57
+ let rawText = "", fullscreen = false, paneMode = false;
58
+ let officeKind = null, officeRender = 0, pptxWidth = 0, pptxTimer = 0;
21
59
 
22
60
  const copyButton = createCopyButton(app, "doc-preview-copy");
23
61
  copyButton.id = "btnDocPreviewCopy";
@@ -41,23 +79,54 @@ export function initDocPreview(app) {
41
79
  if (feedback) feedback.textContent = "";
42
80
  };
43
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
+
44
92
  const show = () => {
45
- if (pane.matches) {
46
- dialog.classList.add("is-pane");
47
- chatView.classList.add("has-doc");
48
- if (!dialog.open) dialog.show();
49
- } else {
50
- dialog.classList.remove("is-pane");
51
- chatView.classList.remove("has-doc");
52
- if (!dialog.open) dialog.showModal();
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();
53
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();
54
125
  };
55
126
 
56
127
  // Crossing the breakpoint keeps the document: the pane becomes an overlay, or back.
57
128
  const syncMode = () => {
58
- if (!dialog.open || pane.matches === dialog.classList.contains("is-pane")) return;
59
- pendingReopen = true;
60
- dialog.close();
129
+ if (!dialog.open || fullscreen || pane.matches === paneMode) return;
61
130
  show();
62
131
  title.focus({ preventScroll: true });
63
132
  };
@@ -65,41 +134,103 @@ export function initDocPreview(app) {
65
134
  const contentPath = (roomId, id) => `/rooms/${encodeURIComponent(roomId)}/resources/${encodeURIComponent(id)}/content`;
66
135
 
67
136
  const clearFrame = () => {
137
+ codeEditor?.dispose();
138
+ codeEditor = null;
68
139
  if (objectUrl) { URL.revokeObjectURL(objectUrl); objectUrl = null; }
69
- dialog.classList.remove("is-pdf");
140
+ dialog.classList.remove("is-pdf", "is-office", "is-code");
70
141
  };
71
142
 
72
- const renderText = (text, format) => {
143
+ const renderText = async (text, format, request) => {
73
144
  copyButton.hidden = false;
74
145
  languageLabel.textContent = format.label || "";
75
146
  languageLabel.hidden = !format.label;
76
147
  if (!text) { empty.hidden = false; return; }
77
- const pre = document.createElement("pre");
78
- pre.className = "code-block doc-code";
79
- const code = document.createElement("code");
80
- code.className = format.language ? `language-${format.language}` : "";
81
- code.textContent = text;
82
- pre.append(code);
83
- body.append(pre);
148
+ dialog.classList.add("is-code");
149
+ const host = document.createElement("div");
150
+ host.className = "doc-monaco";
151
+ body.append(host);
84
152
  empty.hidden = true;
85
- void enhanceCodeElement(code);
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
+ }
86
169
  };
87
170
 
88
171
  const showTooLarge = (format) => {
89
172
  clearFrame();
90
- copyButton.hidden = false;
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; }
91
178
  body.textContent = "";
92
179
  empty.hidden = true;
93
- languageLabel.textContent = format.label || "";
94
- languageLabel.hidden = !format.label;
95
- notice.textContent = app.t("docPreviewTooLarge");
96
- notice.dataset.i18n = "docPreviewTooLarge";
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;
97
185
  notice.hidden = false;
98
186
  status.textContent = "";
99
187
  // The blob is fetched on click, so a huge file still downloads.
100
188
  download.disabled = false;
101
189
  };
102
190
 
191
+ const renderOfficeDocument = async (kind, data, request, width = 0) => {
192
+ officeKind = kind;
193
+ const render = ++officeRender;
194
+ dialog.classList.add("is-office");
195
+ copyButton.hidden = true;
196
+ languageLabel.hidden = true;
197
+ // Render into a private container. A render from an earlier document can
198
+ // finish after the user has switched files; it must never touch the live body.
199
+ const host = document.createElement("div");
200
+ host.className = "office-preview";
201
+ body.replaceChildren(host);
202
+ empty.hidden = true;
203
+ notice.hidden = true;
204
+ // The blob is already here, so download stays available while parsing or after a failure.
205
+ download.disabled = false;
206
+ const module = await import("/assets/chat/office-preview.js");
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"); },
211
+ });
212
+ if (request !== token || render !== officeRender || !host.isConnected) return;
213
+ body.replaceChildren(host);
214
+ if (kind === "pptx") pptxWidth = Math.round(width || body.clientWidth);
215
+ status.textContent = "";
216
+ empty.hidden = body.children.length > 0;
217
+ };
218
+
219
+ // A fixed-width slide deck must be laid out again when the reading pane grows
220
+ // (full screen, splitter drag, breakpoint change), or it stays pane-sized.
221
+ const resizePptx = () => {
222
+ if (!dialog.open || officeKind !== "pptx" || !blob) return;
223
+ const width = Math.round(body.clientWidth);
224
+ if (width < 200 || Math.abs(width - pptxWidth) < 8) return;
225
+ clearTimeout(pptxTimer);
226
+ pptxTimer = setTimeout(() => {
227
+ if (dialog.open && officeKind === "pptx" && blob) {
228
+ void renderOfficeDocument("pptx", blob, token, width).catch(() => undefined);
229
+ }
230
+ }, 150);
231
+ };
232
+ if (typeof ResizeObserver === "function") new ResizeObserver(resizePptx).observe(body);
233
+
103
234
  const renderPdf = (resource, data) => {
104
235
  copyButton.hidden = true;
105
236
  const pdf = data.type === "application/pdf" ? data : data.slice(0, data.size, "application/pdf");
@@ -127,6 +258,7 @@ export function initDocPreview(app) {
127
258
 
128
259
  const open = async (roomId, resource, source) => {
129
260
  opener = source instanceof HTMLElement ? source : null;
261
+ openerResourceID = source instanceof HTMLElement ? source.dataset.previewResource || null : null;
130
262
  restoreOnClose = true;
131
263
  current = { roomId, resource };
132
264
  const request = ++token;
@@ -136,6 +268,9 @@ export function initDocPreview(app) {
136
268
  copyButton.hidden = true;
137
269
  resetCopy();
138
270
  clearFrame();
271
+ officeKind = null;
272
+ pptxWidth = 0;
273
+ clearTimeout(pptxTimer);
139
274
  const eyebrowKey = format.kind === "markdown" ? "docPreviewEyebrow" : "docPreviewFileEyebrow";
140
275
  eyebrow.dataset.i18n = eyebrowKey;
141
276
  eyebrow.textContent = app.t(eyebrowKey);
@@ -154,18 +289,21 @@ export function initDocPreview(app) {
154
289
  else show();
155
290
  if (request !== token) return;
156
291
  title.focus({ preventScroll: true });
157
- const textual = format.kind !== "pdf";
158
- if (textual && Number(resource.size) > TEXT_PREVIEW_LIMIT) { showTooLarge(format); return; }
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; }
159
296
  try {
160
297
  const data = await app.apiBlob(contentPath(roomId, resource.id));
161
298
  if (request !== token) return;
162
299
  blob = data;
163
- if (textual && data.size > TEXT_PREVIEW_LIMIT) { showTooLarge(format); return; }
300
+ if (format.kind !== "pdf" && data.size > limit) { showTooLarge(format); return; }
164
301
  if (format.kind === "pdf") { renderPdf(resource, data); return; }
302
+ if (office) { await renderOfficeDocument(format.kind, data, request); return; }
165
303
  const text = await data.text();
166
304
  if (request !== token) return;
167
305
  rawText = text;
168
- if (format.kind === "text") renderText(text, format);
306
+ if (format.kind === "text") void renderText(text, format, request);
169
307
  else {
170
308
  renderMarkdown(body, text, app);
171
309
  empty.hidden = body.children.length > 0;
@@ -176,15 +314,55 @@ export function initDocPreview(app) {
176
314
  } catch {
177
315
  if (request === token) {
178
316
  clearFrame();
317
+ body.textContent = "";
318
+ empty.hidden = true;
179
319
  copyButton.hidden = true;
180
- status.textContent = app.t("docPreviewFailed");
320
+ if (office) {
321
+ status.textContent = "";
322
+ notice.textContent = app.t("docPreviewOfficeFailed");
323
+ notice.dataset.i18n = "docPreviewOfficeFailed";
324
+ notice.hidden = false;
325
+ download.disabled = false;
326
+ } else status.textContent = app.t("docPreviewFailed");
181
327
  }
182
328
  }
183
329
  };
184
330
 
331
+ const focusReplacement = (resourceID, allowComposer = false) => {
332
+ if (!resourceID) {
333
+ if (allowComposer) app.focusChatComposer?.({ force: true });
334
+ return;
335
+ }
336
+ const query = `#msgList [data-preview-resource="${CSS.escape(resourceID)}"]`;
337
+ const replacement = query ? document.querySelector(query) : null;
338
+ if (replacement instanceof HTMLElement && replacement.getClientRects().length) {
339
+ replacement.focus({ preventScroll: true });
340
+ return;
341
+ }
342
+ // The message list may be halfway through an async card rerender. Retry
343
+ // briefly, but never steal focus if the reader has already clicked elsewhere.
344
+ const active = document.activeElement;
345
+ if (active && active !== document.body && active.id !== "msgInput") return;
346
+ if (performance.now() < focusReplacement.until) {
347
+ requestAnimationFrame(() => focusReplacement(resourceID, allowComposer));
348
+ return;
349
+ }
350
+ if (allowComposer && (document.activeElement === document.body || document.activeElement?.id === "msgInput")) {
351
+ document.querySelector("#msgInput")?.focus({ preventScroll: true });
352
+ }
353
+ };
354
+
185
355
  const close = (restoreFocus = true) => {
186
356
  restoreOnClose = restoreFocus;
187
357
  if (!restoreFocus) opener = null;
358
+ // Invalidate in-flight fetches and Office renders before the close event
359
+ // runs, so none of them can repaint the preview after it starts closing.
360
+ token++;
361
+ officeRender++;
362
+ officeKind = null;
363
+ clearTimeout(pptxTimer);
364
+ // Closing from full screen leaves the locked page as part of the same step.
365
+ if (fullscreen) leaveFullscreen();
188
366
  // Remove the column class now; the queued close event must not leave Tasks
189
367
  // hidden behind a column the task pane is about to take back.
190
368
  chatView.classList.remove("has-doc");
@@ -218,25 +396,47 @@ export function initDocPreview(app) {
218
396
 
219
397
  app.openDocPreview = (roomId, resource, source) => { void open(roomId, resource, source); };
220
398
  app.closeDocPreview = (restoreFocus = true) => close(restoreFocus);
399
+ app.registerDismissibleSurface?.("docPreview", { element: dialog, close: (restore = true) => close(restore) });
400
+ updateFullscreenButton();
221
401
 
222
402
  app.$("#btnCloseDocPreview")?.addEventListener("click", () => close());
403
+ fullscreenButton?.addEventListener("click", () => setFullscreen(!fullscreen));
223
404
  download.addEventListener("click", downloadDocument);
405
+ // A drag that starts in the document and ends on the backdrop produces a click
406
+ // whose target is the dialog; only a press and release on the backdrop closes.
407
+ let dismissPress = false;
408
+ dialog.addEventListener("pointerdown", (event) => { dismissPress = event.target === dialog; });
224
409
  dialog.addEventListener("click", (event) => {
225
- if (event.target === dialog && !dialog.classList.contains("is-pane")) close();
410
+ if (event.target === dialog && dismissPress && !fullscreen && !dialog.classList.contains("is-pane")) close();
411
+ dismissPress = false;
226
412
  });
227
- dialog.addEventListener("cancel", (event) => { event.preventDefault(); close(); });
228
- document.addEventListener("keydown", (event) => {
229
- if (event.key !== "Escape" || !dialog.open || !dialog.classList.contains("is-pane")) return;
413
+ const escapePreview = (event) => {
414
+ if (!event || event.altKey || event.key !== "Escape" || !dialog.open) return;
230
415
  event.preventDefault();
231
- close();
232
- });
416
+ event.stopPropagation();
417
+ // The first Esc leaves full screen; the next one closes the preview.
418
+ if (fullscreen) setFullscreen(false);
419
+ else close();
420
+ };
421
+ document.addEventListener("keydown", (event) => {
422
+ // Capture Escape while the preview is open: leaving full screen closes and
423
+ // reopens the dialog, and the reopened dialog must still obey the next Esc.
424
+ escapePreview(event);
425
+ }, true);
426
+ dialog.addEventListener("cancel", escapePreview);
233
427
  dialog.addEventListener("close", () => {
234
- // A breakpoint switch closes and reopens the same dialog; its queued close event
235
- // must not wipe the document that is already back on screen.
236
- if (pendingReopen) { pendingReopen = false; restoreOnClose = true; return; }
428
+ // A breakpoint switch or leaving full screen closes and reopens the same
429
+ // dialog. Its queued close event must not wipe the document that is already
430
+ // back on screen, so it is stale whenever the dialog has been reopened.
431
+ if (dialog.open) { restoreOnClose = true; return; }
237
432
  const shouldRestore = restoreOnClose;
238
433
  restoreOnClose = true;
239
434
  token++;
435
+ leaveFullscreen();
436
+ officeRender++;
437
+ officeKind = null;
438
+ pptxWidth = 0;
439
+ clearTimeout(pptxTimer);
240
440
  current = null; blob = null; rawText = "";
241
441
  copyButton.hidden = true;
242
442
  resetCopy();
@@ -249,8 +449,13 @@ export function initDocPreview(app) {
249
449
  notice.hidden = true; notice.textContent = ""; delete notice.dataset.i18n;
250
450
  const target = opener; opener = null;
251
451
  if (!shouldRestore) return;
252
- if (target?.isConnected && target.getClientRects().length) target.focus({ preventScroll: true });
253
- else app.focusChatComposer?.({ force: true });
452
+ if (target?.isConnected && target.getClientRects().length) { target.focus({ preventScroll: true }); return; }
453
+ // Inbox polling can rerender the message list while the preview is open,
454
+ // replacing the button that opened it. Focus the current equivalent.
455
+ const resourceID = openerResourceID;
456
+ openerResourceID = null;
457
+ focusReplacement.until = performance.now() + 600;
458
+ focusReplacement(resourceID, true);
254
459
  });
255
460
  const onChange = () => syncMode();
256
461
  if (pane.addEventListener) pane.addEventListener("change", onChange);
@@ -258,10 +258,6 @@ export function initEvents(app) {
258
258
  void app.refreshRoomList();
259
259
  });
260
260
  $("#btnCancelToken").addEventListener("click", () => $("#tokenBox").close());
261
- $("#tokenBox").addEventListener("close", () => {
262
- if (LS.token) return;
263
- try { sessionStorage.setItem("chat.keyPromptDismissed", "1"); } catch { /* Storage may be blocked. */ }
264
- });
265
261
  $("#btnRefreshRooms").addEventListener("click", () => void app.refreshRoomList());
266
262
  $("#btnNewRoom").addEventListener("click", () => app.openCreateRoomDialog());
267
263
  $("#railRoomForm").addEventListener("submit", (event) => { event.preventDefault(); void app.createRoom(); });
@@ -332,6 +328,12 @@ export function initEvents(app) {
332
328
  // Stop wheel overscroll at the ends. Without this, some layouts let the
333
329
  // document absorb the leftover delta and the view jumps a few pixels.
334
330
  thread.addEventListener("wheel", (event) => {
331
+ // Trackpad pinch arrives as Ctrl/Cmd + wheel. Blocking it at a scroll
332
+ // edge would also block browser zoom-out.
333
+ if (event.ctrlKey || event.metaKey) return;
334
+ // While pinch-zoomed the default wheel action pans the visual viewport.
335
+ // The document itself never overflows, so preventing it would freeze the page.
336
+ if (Math.abs((window.visualViewport?.scale ?? 1) - 1) > 0.01) return;
335
337
  markScrollIntent();
336
338
  const gap = thread.scrollHeight - thread.clientHeight - thread.scrollTop;
337
339
  if (event.deltaY < 0 && thread.scrollTop <= 0 || event.deltaY > 0 && gap <= 2) event.preventDefault();
@@ -427,14 +429,23 @@ export function initEvents(app) {
427
429
  });
428
430
  });
429
431
 
432
+ // A press inside a dialog released over the backdrop dispatches click to the
433
+ // dialog's common ancestor (body), so it used to read as an outside click and
434
+ // close the dialog through closePanels. Only a press that started outside may.
435
+ let pressInDialog = false;
436
+ document.addEventListener("pointerdown", (event) => {
437
+ pressInDialog = Boolean(event.target.closest?.("dialog[open]"));
438
+ }, true);
430
439
  document.addEventListener("click", (event) => {
440
+ const releasedFromDialog = pressInDialog && !event.target.closest?.("dialog");
441
+ pressInDialog = false;
431
442
  const save = event.target.closest("[data-token-save]");
432
443
  if (save) {
433
444
  saveAccessToken(save, app);
434
445
  return;
435
446
  }
436
447
  if (app.mentionActive && !event.target.closest("#mentionPicker")) app.closeMention();
437
- if (!event.target.closest(".anchor, dialog")) app.closePanels();
448
+ if (!releasedFromDialog && !event.target.closest(".anchor, dialog")) app.closePanels();
438
449
  });
439
450
  let lastEscapeAt = -Infinity;
440
451
  document.addEventListener("keydown", (event) => {
@@ -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, restoreFocus = true;
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 textPreview = docPreview && docPreviewFormat(resource)?.kind !== "pdf";
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,28 +352,43 @@ 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
- dialog.showModal();
355
+ show();
327
356
  heading.focus();
328
357
  Promise.resolve(app.loadManageableMembers?.()).then(() => { if (dialog.open && items.length) render(); });
329
358
  void load(true);
330
359
  };
331
360
  app.openFilesDialog = open;
332
361
 
333
- const close = () => { if (dialog.open) dialog.close(); };
362
+ const close = (restore = true) => {
363
+ restoreFocus = restore;
364
+ if (dialog.open) dialog.close();
365
+ };
334
366
 
335
367
  trigger?.addEventListener("click", () => { app.closePanels(); open(); });
336
368
  $("#btnCloseFiles")?.addEventListener("click", close);
369
+ document.addEventListener("keydown", (event) => {
370
+ if (event.key !== "Escape" || event.altKey || !dialog.open || !dialog.classList.contains("is-pane")) return;
371
+ if (!dialog.contains(document.activeElement)) return;
372
+ event.preventDefault();
373
+ close();
374
+ });
375
+ app.registerPanelSurface?.("files", { element: dialog, close: (restore = true) => close(restore) });
376
+ app.watchPanel?.("files", syncMode);
337
377
  $("#btnRefreshFiles")?.addEventListener("click", () => void load(true));
338
378
  more.addEventListener("click", () => void load(false));
339
379
  select.addEventListener("change", render);
340
- dialog.addEventListener("click", (event) => { if (event.target === dialog) close(); });
341
380
  dialog.addEventListener("cancel", (event) => { event.preventDefault(); close(); });
342
381
  dialog.addEventListener("close", () => {
382
+ // close() queues this event; a rapid reopen can land before it runs, and
383
+ // clearing here would wipe the freshly opened dialog and its in-flight load.
384
+ if (pendingReopen) { pendingReopen = false; return; }
385
+ if (dialog.open) return;
343
386
  generation++;
344
387
  loading = false;
345
388
  setBusy(false);
346
389
  previewToken++;
347
390
  closePreview();
391
+ clearPane();
348
392
  items = [];
349
393
  total = 0;
350
394
  list.textContent = "";
@@ -354,7 +398,9 @@ export function initFiles(app) {
354
398
  const target = opener;
355
399
  opener = null;
356
400
  // A document preview opens right after the file list closes; keep focus there.
357
- if (target?.isConnected && !document.querySelector("dialog[open]")) target.focus({ preventScroll: true });
401
+ const focus = restoreFocus;
402
+ restoreFocus = true;
403
+ if (focus && target?.isConnected && !document.querySelector("dialog[open]")) target.focus({ preventScroll: true });
358
404
  });
359
405
  list.addEventListener("click", (event) => {
360
406
  const button = event.target.closest?.("[data-file-action]");
@@ -91,7 +91,14 @@ export function initImageZoom(app) {
91
91
  open(image);
92
92
  });
93
93
  app.$("#btnCloseImage")?.addEventListener("click", close);
94
- dialog.addEventListener("click", (event) => { if (event.target === dialog) close(); });
94
+ // A backdrop click closes, but a drag that started inside the viewer and was
95
+ // released on the backdrop does not: the click target would be the dialog then.
96
+ let dismissPress = false;
97
+ dialog.addEventListener("pointerdown", (event) => { dismissPress = event.target === dialog; });
98
+ dialog.addEventListener("click", (event) => {
99
+ if (event.target === dialog && dismissPress) close();
100
+ dismissPress = false;
101
+ });
95
102
  // The viewer owns the wheel while it is open so the thread behind it cannot scroll.
96
103
  dialog.addEventListener("wheel", (event) => {
97
104
  if (!dialog.open) return;
@@ -13,7 +13,6 @@ import { initAnnouncements } from "./announcements.js";
13
13
  import { initAdmin } from "./admin.js";
14
14
  import { initAttachments } from "./attachments.js";
15
15
  import { initReplies } from "./replies.js";
16
- import { initForward } from "./forward.js";
17
16
  import { initRecall } from "./recall.js";
18
17
  import { initHistoryLoader } from "./history-loader.js";
19
18
  import { initSearch } from "./search.js";
@@ -30,10 +29,16 @@ import { initSidePaneSplitter } from "./side-pane.js";
30
29
  import { initDiagramViewer } from "./diagram-viewer.js";
31
30
  import { initViewport } from "./viewport.js";
32
31
  import { initSettings } from "./settings.js";
32
+ import { initChatBackground } from "./chat-background.js";
33
+ import { initIntegrations } from "./integrations.js";
34
+ import { initWindowControls } from "./window-controls.js";
33
35
 
34
36
  if (isMobileDevice()) document.documentElement.dataset.mobile = "true";
35
37
 
38
+ initWindowControls();
36
39
  initSettings(app);
40
+ initChatBackground(app);
41
+ initIntegrations(app);
37
42
  initConfirmDialog(app);
38
43
  initDiagramViewer(app);
39
44
  initMentions(app);
@@ -48,7 +53,6 @@ initHistoryLoader(app);
48
53
  initSearch(app);
49
54
  initQuestions(app);
50
55
  initReplies(app);
51
- initForward(app);
52
56
  initRecall(app);
53
57
  initEvents(app);
54
58
  initShortcuts(app);