@alexsun-top/opencode-chat-room 0.7.7 → 0.7.8

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 (59) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/README.md +3 -3
  3. package/README.zh-CN.md +3 -3
  4. package/dist/cli.js +80 -28
  5. package/package.json +2 -2
  6. package/server/assets/chat/announcements.js +5 -2
  7. package/server/assets/chat/clipboard.js +30 -0
  8. package/server/assets/chat/copy-action.js +48 -0
  9. package/server/assets/chat/diagram-viewer.js +253 -0
  10. package/server/assets/chat/doc-preview.js +150 -12
  11. package/server/assets/chat/events.js +25 -4
  12. package/server/assets/chat/files.js +26 -5
  13. package/server/assets/chat/history-loader.js +3 -1
  14. package/server/assets/chat/index.js +9 -1
  15. package/server/assets/chat/join-requests.js +6 -3
  16. package/server/assets/chat/locales/de.js +2 -2
  17. package/server/assets/chat/locales/es.js +2 -2
  18. package/server/assets/chat/locales/fr.js +2 -2
  19. package/server/assets/chat/locales/it.js +2 -2
  20. package/server/assets/chat/locales/ja.js +2 -2
  21. package/server/assets/chat/locales/ko.js +2 -2
  22. package/server/assets/chat/markdown.js +55 -92
  23. package/server/assets/chat/messages.js +6 -3
  24. package/server/assets/chat/palette.js +32 -15
  25. package/server/assets/chat/pwa.js +2 -0
  26. package/server/assets/chat/questions.js +5 -0
  27. package/server/assets/chat/resource-format.js +74 -0
  28. package/server/assets/chat/rooms.js +3 -0
  29. package/server/assets/chat/side-pane.js +136 -0
  30. package/server/assets/chat/state.js +49 -8
  31. package/server/assets/chat/task-row.js +2 -1
  32. package/server/assets/chat/tasks.js +29 -2
  33. package/server/assets/chat/viewport.js +5 -0
  34. package/server/assets/conversation.css +25 -1
  35. package/server/assets/diagram-viewer.css +141 -0
  36. package/server/assets/doc-preview.css +24 -5
  37. package/server/assets/responsive.css +82 -13
  38. package/server/assets/tasks.css +1 -4
  39. package/server/chat-server.ts +9 -4
  40. package/server/chat.html +23 -2
  41. package/server/resource-routes.ts +3 -1
  42. package/server/sw.js +235 -2
  43. package/skills/chatroom/SKILL.md +1 -1
  44. package/src/agent/chatroom-skill.ts +8 -2
  45. package/src/rooms/resources.ts +2 -2
  46. package/src/runtime/watch.ts +38 -5
  47. package/src/state/sqlite-state.ts +26 -8
  48. package/src/state/store.ts +2 -2
  49. package/src/tui/app.mjs +10 -2
  50. package/src/tui/http.mjs +2 -2
  51. package/src/tui/info-app.mjs +24 -15
  52. package/src/tui/join-app.mjs +3 -3
  53. package/src/tui/main.mjs +1 -1
  54. package/src/tui/markdown.mjs +5 -3
  55. package/src/tui/mentions.mjs +3 -3
  56. package/src/tui/message-app.mjs +14 -11
  57. package/src/tui/palette-app.mjs +10 -7
  58. package/src/tui/reminder-app.mjs +14 -10
  59. package/src/tui/ui-content.mjs +3 -1
@@ -0,0 +1,74 @@
1
+ // Shared classification for resources that open in the reading pane. The server
2
+ // sniffs text and PDF uploads as application/octet-stream, so the filename
3
+ // extension is a first-class signal alongside the MIME type.
4
+ export const TEXT_PREVIEW_LIMIT = 2 * 1024 * 1024;
5
+
6
+ const MIME_LANGUAGES = {
7
+ "application/json": "json", "application/ld+json": "json",
8
+ "application/xml": "xml", "text/xml": "xml",
9
+ "application/javascript": "javascript", "application/x-javascript": "javascript",
10
+ "application/typescript": "typescript",
11
+ "application/x-yaml": "yaml", "application/yaml": "yaml",
12
+ "application/toml": "ini",
13
+ "text/html": "xml", "text/css": "css",
14
+ };
15
+
16
+ const EXTENSION_LANGUAGES = {
17
+ txt: "", log: "", csv: "", tsv: "",
18
+ json: "json", jsonc: "json", yaml: "yaml", yml: "yaml",
19
+ toml: "ini", ini: "ini", conf: "ini", env: "ini", properties: "properties",
20
+ sh: "bash", bash: "bash", zsh: "bash", fish: "bash",
21
+ ps1: "powershell", bat: "dos", cmd: "dos",
22
+ js: "javascript", mjs: "javascript", cjs: "javascript", jsx: "javascript",
23
+ ts: "typescript", tsx: "typescript",
24
+ py: "python", rb: "ruby", go: "go", rs: "rust", java: "java",
25
+ kt: "kotlin", kts: "kotlin", c: "c", h: "c", cpp: "cpp", hpp: "cpp", cc: "cpp",
26
+ cs: "csharp", php: "php", swift: "swift", sql: "sql",
27
+ html: "xml", htm: "xml", css: "css", scss: "scss", less: "less",
28
+ xml: "xml", svg: "xml", vue: "xml", svelte: "xml",
29
+ lua: "lua", r: "r", pl: "perl", pm: "perl", dart: "dart",
30
+ gradle: "groovy", dockerfile: "dockerfile", makefile: "makefile", mk: "makefile",
31
+ };
32
+
33
+ const LANGUAGE_NAMES = {
34
+ typescript: "TypeScript", javascript: "JavaScript", python: "Python", ruby: "Ruby",
35
+ bash: "Shell", yaml: "YAML", json: "JSON", xml: "XML", c: "C", cpp: "C++",
36
+ csharp: "C#", kotlin: "Kotlin", rust: "Rust", go: "Go", java: "Java",
37
+ php: "PHP", swift: "Swift", sql: "SQL", css: "CSS", scss: "SCSS", less: "Less",
38
+ ini: "Config", properties: "Properties", powershell: "PowerShell", dos: "Batch",
39
+ dockerfile: "Dockerfile", makefile: "Makefile", lua: "Lua", r: "R", perl: "Perl",
40
+ dart: "Dart", groovy: "Gradle",
41
+ };
42
+
43
+ const TEXT_MIMES = new Set([
44
+ "application/json", "application/ld+json", "application/xml", "application/x-yaml",
45
+ "application/yaml", "application/toml", "application/javascript",
46
+ "application/x-javascript", "application/typescript",
47
+ ]);
48
+
49
+ function fileExtension(name) {
50
+ const base = String(name || "").toLowerCase().split(/[\\/]/).pop() || "";
51
+ if (base === "dockerfile" || base === "makefile") return base;
52
+ return /\.([a-z0-9]+)$/.exec(base)?.[1] || "";
53
+ }
54
+
55
+ function isTextMime(mime) {
56
+ if (mime === "text/markdown" || mime === "text/x-markdown") return false;
57
+ return mime.startsWith("text/") || TEXT_MIMES.has(mime);
58
+ }
59
+
60
+ export function docPreviewFormat(resource) {
61
+ const mime = String(resource?.mimeType || "").split(";")[0].trim().toLowerCase();
62
+ const name = String(resource?.name || "");
63
+ const ext = fileExtension(name);
64
+ if (mime === "application/pdf" || ext === "pdf") return { kind: "pdf", language: "", label: "PDF" };
65
+ if (mime === "text/markdown" || mime === "text/x-markdown" || ext === "md" || ext === "markdown") {
66
+ return { kind: "markdown", language: "", label: "" };
67
+ }
68
+ const knownExtension = Object.hasOwn(EXTENSION_LANGUAGES, ext);
69
+ if (!knownExtension && !isTextMime(mime)) return null;
70
+ const language = knownExtension ? EXTENSION_LANGUAGES[ext] : MIME_LANGUAGES[mime] || "";
71
+ return { kind: "text", language, label: LANGUAGE_NAMES[language] || (ext ? ext.toUpperCase() : "Text") };
72
+ }
73
+
74
+ export const isDocPreviewResource = (resource) => docPreviewFormat(resource) !== null;
@@ -322,6 +322,9 @@ export function initRooms(app) {
322
322
  clearTimeout(app.state.watcherTimer);
323
323
  if (!app.state.rooms.size && !app.state.restorePending?.size && !app.state.restoreRetry) return;
324
324
  app.state.watcherTimer = setTimeout(async () => {
325
+ // A hidden tab has no reader; skip background room polling until it is
326
+ // visible again (the next timer tick after visibility resumes).
327
+ if (typeof document !== "undefined" && document.hidden) { app.startRoomWatcher(); return; }
325
328
  const inactive = [...app.state.rooms.keys()].filter((id) => id !== app.state.room?.id);
326
329
  await bounded(inactive, 3, (roomId) => watchRoom(roomId, app));
327
330
  if (app.state.restorePending?.size || app.state.restoreRetry) void app.refreshRoomList(true);
@@ -0,0 +1,136 @@
1
+ // Resizes the right-hand pane (Markdown preview or task board) on wide windows.
2
+ // --side-pane-width holds the only width; the rail keeps its 252px column and the
3
+ // chat column never shrinks below MIN_CHAT.
4
+ const STORAGE_KEY = "chat.sidePaneWidth";
5
+ const MIN_WIDTH = 360;
6
+ const MIN_CHAT = 420;
7
+ const RAIL_WIDTH = 252;
8
+ const GUTTER = 8;
9
+ const MAX_WIDTH = 960;
10
+
11
+ export function initSidePaneSplitter(app) {
12
+ const view = app.$("#chatView");
13
+ const handle = app.$("#sidePaneHandle");
14
+ const preview = app.$("#docPreview");
15
+ const tasks = app.$("#tasksDialog");
16
+ if (!view || !handle) return;
17
+
18
+ let stored = readStored();
19
+ let applied = 0;
20
+ let frame = 0;
21
+ let pending = 0;
22
+ let drag = null;
23
+
24
+ const activePane = () => view.classList.contains("has-doc") ? preview
25
+ : view.classList.contains("has-tasks") ? tasks : null;
26
+
27
+ const maxWidth = () => {
28
+ const available = view.clientWidth - RAIL_WIDTH - GUTTER - MIN_CHAT;
29
+ return Math.max(MIN_WIDTH, Math.min(window.innerWidth * 0.7, MAX_WIDTH, available));
30
+ };
31
+ const clamp = (width) => Math.max(MIN_WIDTH, Math.min(width, maxWidth()));
32
+
33
+ const syncAria = () => {
34
+ handle.setAttribute("aria-valuemin", String(MIN_WIDTH));
35
+ handle.setAttribute("aria-valuemax", String(Math.round(maxWidth())));
36
+ const pane = activePane();
37
+ if (pane?.open) {
38
+ handle.setAttribute("aria-valuenow", String(Math.round(pane.getBoundingClientRect().width)));
39
+ }
40
+ };
41
+
42
+ const apply = (width) => {
43
+ applied = Math.round(width);
44
+ view.style.setProperty("--side-pane-width", `${applied}px`);
45
+ syncAria();
46
+ };
47
+
48
+ // Pane classes change on open, close, and breakpoint switches; the hidden
49
+ // attribute changes when the workspace first appears.
50
+ const reflow = () => {
51
+ if (!view.clientWidth) return;
52
+ if (stored == null) syncAria();
53
+ else apply(clamp(stored));
54
+ };
55
+
56
+ const setWidth = (width) => {
57
+ const next = clamp(width);
58
+ apply(next);
59
+ return next;
60
+ };
61
+
62
+ const persist = (width) => {
63
+ stored = Math.round(width);
64
+ try { localStorage.setItem(STORAGE_KEY, String(stored)); } catch { /* The width still applies for this page. */ }
65
+ };
66
+
67
+ handle.addEventListener("pointerdown", (event) => {
68
+ const pane = activePane();
69
+ if (event.button !== 0 || !pane?.open) return;
70
+ drag = { pointerId: event.pointerId, x: event.clientX, width: pane.getBoundingClientRect().width };
71
+ applied = Math.round(drag.width);
72
+ pending = drag.width;
73
+ handle.setPointerCapture(event.pointerId);
74
+ handle.classList.add("is-dragging");
75
+ document.body.classList.add("is-resizing-pane");
76
+ handle.focus({ preventScroll: true });
77
+ });
78
+
79
+ handle.addEventListener("pointermove", (event) => {
80
+ if (!drag || event.pointerId !== drag.pointerId) return;
81
+ // Dragging left widens the right-hand pane; the divider follows the pointer.
82
+ pending = clamp(drag.width - (event.clientX - drag.x));
83
+ if (frame) return;
84
+ frame = requestAnimationFrame(() => {
85
+ frame = 0;
86
+ apply(pending);
87
+ });
88
+ });
89
+
90
+ const endDrag = (event) => {
91
+ if (!drag || event.pointerId !== drag.pointerId) return;
92
+ if (frame) { cancelAnimationFrame(frame); frame = 0; }
93
+ apply(pending);
94
+ persist(applied);
95
+ drag = null;
96
+ handle.classList.remove("is-dragging");
97
+ document.body.classList.remove("is-resizing-pane");
98
+ if (handle.hasPointerCapture(event.pointerId)) handle.releasePointerCapture(event.pointerId);
99
+ };
100
+ handle.addEventListener("pointerup", endDrag);
101
+ handle.addEventListener("pointercancel", endDrag);
102
+
103
+ handle.addEventListener("keydown", (event) => {
104
+ if (!activePane()?.open) return;
105
+ const current = activePane().getBoundingClientRect().width;
106
+ const step = event.shiftKey ? 64 : 16;
107
+ let next;
108
+ if (event.key === "ArrowRight") next = current - step;
109
+ else if (event.key === "ArrowLeft") next = current + step;
110
+ else if (event.key === "Home") next = MIN_WIDTH;
111
+ else if (event.key === "End") next = maxWidth();
112
+ else return;
113
+ event.preventDefault();
114
+ persist(setWidth(next));
115
+ });
116
+
117
+ handle.addEventListener("dblclick", () => {
118
+ stored = null;
119
+ try { localStorage.removeItem(STORAGE_KEY); } catch { /* Ignore unavailable storage. */ }
120
+ view.style.removeProperty("--side-pane-width");
121
+ syncAria();
122
+ });
123
+
124
+ window.addEventListener("resize", reflow);
125
+ new MutationObserver(reflow).observe(view, { attributes: true, attributeFilter: ["class", "hidden"] });
126
+ reflow();
127
+ }
128
+
129
+ function readStored() {
130
+ try {
131
+ const width = Number(localStorage.getItem(STORAGE_KEY));
132
+ return Number.isFinite(width) && width > 0 ? width : null;
133
+ } catch {
134
+ return null;
135
+ }
136
+ }
@@ -23,6 +23,13 @@ export const app = {
23
23
  failedRenderIds: new Set(),
24
24
  };
25
25
 
26
+ // Phones and tablets lack the hardware keyboard the shortcut hint assumes.
27
+ // iPadOS reports a desktop Macintosh UA, so touch points identify it there.
28
+ export function isMobileDevice() {
29
+ const ua = navigator.userAgent || "";
30
+ return /Android|iPhone|iPad|iPod/i.test(ua) || (/Macintosh/.test(ua) && (navigator.maxTouchPoints || 0) > 1);
31
+ }
32
+
26
33
  export function createRandomId() {
27
34
  const crypto = globalThis.crypto;
28
35
  if (crypto?.randomUUID) return crypto.randomUUID();
@@ -34,6 +41,12 @@ export function createRandomId() {
34
41
  return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
35
42
  }
36
43
 
44
+ // Media cached by the service worker belongs to a browser identity; drop it whenever
45
+ // that identity changes and keep only the current identity record.
46
+ const clearMediaCache = () => {
47
+ try { globalThis.navigator?.serviceWorker?.controller?.postMessage({ type: "CLEAR_MEDIA_CACHE" }); } catch { /* Cache cleanup is best effort. */ }
48
+ };
49
+
37
50
  export function createAuth(storage, fetcher, translate = (key) => key, sessionStore) {
38
51
  const memory = Object.create(null);
39
52
  let browserIdentity, identityPersistent = false, identityConflict = false;
@@ -75,14 +88,21 @@ export function createAuth(storage, fetcher, translate = (key) => key, sessionSt
75
88
  };
76
89
  const ensureIdentity = () => {
77
90
  if (browserIdentity) return browserIdentity;
91
+ const priorID = readSession("chat.sessionID");
78
92
  let store;
79
93
  try {
80
94
  store = storage ?? globalThis.localStorage;
81
95
  const canonical = parseIdentity(store.getItem(identityKey));
82
- if (canonical) { browserIdentity = canonical; identityPersistent = true; syncTabIdentity(); return canonical; }
96
+ if (canonical) {
97
+ browserIdentity = canonical;
98
+ identityPersistent = true;
99
+ if (priorID && priorID !== canonical.sessionID) { clearMediaCache(); void postMediaIdentity(); }
100
+ syncTabIdentity();
101
+ return canonical;
102
+ }
83
103
  } catch { /* Keep this tab's identity in memory when storage is blocked. */ }
84
- const previousID = readSession("chat.sessionID");
85
- browserIdentity = { sessionID: validSessionID(previousID) ? previousID : createRandomId(), name: validSessionID(previousID) ? (readSession("chat.name") || "").slice(0, 64) : "" };
104
+ browserIdentity = { sessionID: validSessionID(priorID) ? priorID : createRandomId(), name: validSessionID(priorID) ? (readSession("chat.name") || "").slice(0, 64) : "" };
105
+ if (priorID && priorID !== browserIdentity.sessionID) { clearMediaCache(); void postMediaIdentity(); }
86
106
  syncTabIdentity();
87
107
  try {
88
108
  store ||= storage ?? globalThis.localStorage;
@@ -168,7 +188,15 @@ export function createAuth(storage, fetcher, translate = (key) => key, sessionSt
168
188
  },
169
189
  set failedMessages(value) { writeSession("chat.failedMessages", JSON.stringify(value)); },
170
190
  };
171
- const saveToken = (value) => { auth.token = String(value ?? "").trim(); return auth.token; };
191
+ const saveToken = (value) => {
192
+ const next = String(value ?? "").trim();
193
+ const changed = next !== auth.token;
194
+ auth.token = next;
195
+ // A token change can change what the person may see, so cached images must not
196
+ // survive into the new identity. An empty value is the sign-out path.
197
+ if (changed) { clearMediaCache(); void postMediaIdentity(); }
198
+ return auth.token;
199
+ };
172
200
  const apiResponse = async (url, options = {}) => {
173
201
  assertIdentity();
174
202
  const headers = { ...options.headers };
@@ -248,7 +276,7 @@ export const messages = {
248
276
  reminderEdit: "Edit", reminderEditHeading: "Edit reminder", reminderSave: "Save changes",
249
277
  reminderCreated: "Reminder created.", reminderUpdated: "Reminder updated.", reminderDeleted: "Reminder deleted.",
250
278
  reminderInvalid: "Check the date, 5-field CRON expression, IANA timezone, and reminder text.", reminderLoadFailed: "Could not load reminders. Your draft is still here.",
251
- diagramLoading: "Rendering diagram…", diagramRenderFailed: "Diagram unavailable; showing its source.", resourceLoading: "Loading file…", resourceFailed: "This file could not be loaded.", resourceDownload: "Download", resourceMoreActions: "More actions for {name}", resourcePreview: "Preview", resourceHide: "Hide preview", docPreviewEyebrow: "Markdown preview", docPreviewFailed: "This document could not be loaded.", docPreviewEmpty: "This document is empty.", zoomImage: "Open image", imagePreviewTitle: "Image preview", imageZoomControls: "Image zoom", zoomIn: "Zoom in", zoomOut: "Zoom out", zoomReset: "Reset zoom", installTitle: "Install OC Chat", installBody: "Add it to your home screen for a full-screen chat.", installAction: "Install", installHow: "How to install", installNotNow: "Not now", installIosGuide: "Tap Share, then Add to Home Screen.",
279
+ diagramLoading: "Rendering diagram…", diagramRenderFailed: "Diagram unavailable; showing its source.", resourceLoading: "Loading file…", resourceFailed: "This file could not be loaded.", resourceDownload: "Download", resourceMoreActions: "More actions for {name}", resourcePreview: "Preview", resourceHide: "Hide preview", docPreviewEyebrow: "Markdown preview", docPreviewFileEyebrow: "File preview", docPreviewFailed: "This document could not be loaded.", docPreviewEmpty: "This document is empty.", docPreviewTooLarge: "This file is too large to preview (over 2 MB). Download it instead.", sidePaneResize: "Resize side pane", zoomImage: "Open image", imagePreviewTitle: "Image preview", imageZoomControls: "Image zoom", zoomIn: "Zoom in", zoomOut: "Zoom out", zoomReset: "Reset zoom", openDiagram: "Open diagram", diagramViewerTitle: "Diagram", diagramZoomControls: "Diagram zoom", diagramFit: "Fit", installTitle: "Install OC Chat", installBody: "Add it to your home screen for a full-screen chat.", installAction: "Install", installHow: "How to install", installNotNow: "Not now", installIosGuide: "Tap Share, then Add to Home Screen.",
252
280
  pwaUpdateTitle: "Update available", pwaUpdateBody: "A new version is ready. Reload now, or update the next time you open the app.", pwaUpdateNow: "Update now", pwaUpdateLater: "Later",
253
281
  announcementDelete: "Delete announcement",
254
282
  announcementNew: "New announcement", announcementEmpty: "No announcements yet.", announcementLoading: "Loading announcements…",
@@ -299,7 +327,7 @@ export const messages = {
299
327
  filesUnknownUploader: "Unknown uploader", filesSummary: ({ count, size }) => `${count} file${count === 1 ? "" : "s"} · ${size}`,
300
328
  filesLoading: "Loading files…", filesLoadFailed: "Could not load files. Try again.", filesEmpty: "No files in this room yet.",
301
329
  filesEmptyFiltered: "No files from this uploader.", filesLoadMore: "Load more",
302
- filesHint: "Preview images, audio, video, and Markdown. Download any file.",
330
+ filesHint: "Preview images, audio, video, Markdown, text, code, and PDF. Download any file.",
303
331
  filesPreviewFailed: "Could not load this preview.", filesDownloadFailed: "Could not download this file.",
304
332
  filesPreviewLabel: ({ name }) => `Preview ${name}`, filesDownloadLabel: ({ name }) => `Download ${name}`,
305
333
  filesDeleteLabel: ({ name }) => `Delete ${name}`, filesRefresh: "Refresh files",
@@ -400,7 +428,7 @@ export const messages = {
400
428
  reminderEdit: "编辑", reminderEditHeading: "编辑提醒", reminderSave: "保存修改",
401
429
  reminderCreated: "提醒已创建。", reminderUpdated: "提醒已更新。", reminderDeleted: "提醒已删除。",
402
430
  reminderInvalid: "请检查日期、5 字段 CRON 表达式、IANA 时区和提醒内容。", reminderLoadFailed: "无法加载提醒,草稿仍已保留。",
403
- diagramLoading: "正在渲染图表…", diagramRenderFailed: "图表无法显示,以下为源代码。", resourceLoading: "正在加载文件…", resourceFailed: "无法加载此文件。", resourceDownload: "下载", resourceMoreActions: "{name} 的更多操作", resourcePreview: "预览", resourceHide: "收起预览", docPreviewEyebrow: "Markdown 预览", docPreviewFailed: "无法加载此文档。", docPreviewEmpty: "此文档为空。", zoomImage: "查看大图", imagePreviewTitle: "图片预览", imageZoomControls: "图片缩放", zoomIn: "放大", zoomOut: "缩小", zoomReset: "重置缩放", installTitle: "安装 OC Chat", installBody: "添加到主屏幕,获得全屏聊天体验。", installAction: "安装", installHow: "如何安装", installNotNow: "暂不", installIosGuide: "点击共享按钮,然后选择“添加到主屏幕”。",
431
+ diagramLoading: "正在渲染图表…", diagramRenderFailed: "图表无法显示,以下为源代码。", resourceLoading: "正在加载文件…", resourceFailed: "无法加载此文件。", resourceDownload: "下载", resourceMoreActions: "{name} 的更多操作", resourcePreview: "预览", resourceHide: "收起预览", docPreviewEyebrow: "Markdown 预览", docPreviewFileEyebrow: "文件预览", docPreviewFailed: "无法加载此文档。", docPreviewEmpty: "此文档为空。", docPreviewTooLarge: "文件太大,无法预览(超过 2 MB),请下载查看。", sidePaneResize: "调整侧边栏宽度", zoomImage: "查看大图", imagePreviewTitle: "图片预览", imageZoomControls: "图片缩放", zoomIn: "放大", zoomOut: "缩小", zoomReset: "重置缩放", openDiagram: "查看图表", diagramViewerTitle: "图表", diagramZoomControls: "图表缩放", diagramFit: "适应窗口", installTitle: "安装 OC Chat", installBody: "添加到主屏幕,获得全屏聊天体验。", installAction: "安装", installHow: "如何安装", installNotNow: "暂不", installIosGuide: "点击共享按钮,然后选择“添加到主屏幕”。",
404
432
  pwaUpdateTitle: "有可用更新", pwaUpdateBody: "新版本已准备好。可以立即刷新,或下次打开时再升级。", pwaUpdateNow: "立即升级", pwaUpdateLater: "稍后",
405
433
  announcementDelete: "删除公告",
406
434
  announcementNew: "新建公告", announcementEmpty: "暂无公告。", announcementLoading: "正在加载公告…",
@@ -447,7 +475,7 @@ export const messages = {
447
475
  filesUnknownUploader: "未知上传者", filesSummary: ({ count, size }) => `${count} 个文件 · ${size}`,
448
476
  filesLoading: "正在加载文件…", filesLoadFailed: "无法加载文件,请重试。", filesEmpty: "这个房间还没有文件。",
449
477
  filesEmptyFiltered: "此上传者没有文件。", filesLoadMore: "加载更多",
450
- filesHint: "可预览图片、音频、视频和 Markdown,所有文件都可下载。",
478
+ filesHint: "可预览图片、音频、视频、Markdown、文本、代码和 PDF,所有文件都可下载。",
451
479
  filesPreviewFailed: "无法加载预览。", filesDownloadFailed: "无法下载此文件。",
452
480
  filesPreviewLabel: ({ name }) => `预览 ${name}`, filesDownloadLabel: ({ name }) => `下载 ${name}`,
453
481
  filesDeleteLabel: ({ name }) => `删除 ${name}`, filesRefresh: "刷新文件",
@@ -514,6 +542,19 @@ app.LS = LS;
514
542
  app.api = api;
515
543
  app.apiBlob = apiBlob;
516
544
  app.setToken = saveToken;
545
+ // The service worker partitions its image cache by this hash; raw credentials never
546
+ // leave the page. A missing controller is fine: the identity is posted on controllerchange.
547
+ async function postMediaIdentity() {
548
+ try {
549
+ const controller = globalThis.navigator?.serviceWorker?.controller;
550
+ const subtle = globalThis.crypto?.subtle;
551
+ if (!controller || !subtle) return;
552
+ const digest = await subtle.digest("SHA-256", new TextEncoder().encode(`${LS.token}\n${LS.sessionID}`));
553
+ const identity = [...new Uint8Array(digest).slice(0, 8)].map((byte) => byte.toString(16).padStart(2, "0")).join("");
554
+ controller.postMessage({ type: "SET_MEDIA_IDENTITY", identity });
555
+ } catch { /* Image caching stays disabled until an identity can be posted. */ }
556
+ }
557
+ app.postMediaIdentity = postMediaIdentity;
517
558
  export const SUPPORTED_LOCALES = ["en", "zh-CN", "ja", "ko", "fr", "de", "es", "it"];
518
559
  const intlLocales = { en: "en-US", "zh-CN": "zh-CN", ja: "ja-JP", ko: "ko-KR", fr: "fr-FR", de: "de-DE", es: "es-ES", it: "it-IT" };
519
560
  app.locale = messages[LS.locale] ? LS.locale : "en";
@@ -17,6 +17,7 @@ const statusSelect = (view, task) => {
17
17
  select.append(option);
18
18
  }
19
19
  select.value = view.statusOf(task);
20
+ select.disabled = view.isLocked();
20
21
  select.addEventListener("change", () => void view.onStatus(task, select));
21
22
  return select;
22
23
  };
@@ -96,7 +97,7 @@ export const buildTaskRow = (view, task, index) => {
96
97
  toggle.type = "checkbox";
97
98
  toggle.className = "task-step-toggle";
98
99
  toggle.checked = step.done;
99
- toggle.disabled = !view.canStatus(task);
100
+ toggle.disabled = !view.canStatus(task) || view.isLocked();
100
101
  toggle.dataset.stepIndex = String(position);
101
102
  toggle.setAttribute("aria-label", `${app.t("tasksStepDoneLabel")}: ${step.text}`);
102
103
  toggle.addEventListener("change", () => void view.onToggleStep(task, position, toggle));
@@ -70,7 +70,9 @@ export function initTasks(app) {
70
70
  const setBusy = (busy) => {
71
71
  loading = busy;
72
72
  dialog.setAttribute("aria-busy", String(busy));
73
- refresh.disabled = busy;
73
+ // A reload that finishes while an editor is open must not re-enable the
74
+ // refresh control the editor has locked.
75
+ refresh.disabled = busy || Boolean(editingId);
74
76
  createButton.disabled = busy;
75
77
  syncClear();
76
78
  };
@@ -86,6 +88,8 @@ export function initTasks(app) {
86
88
  };
87
89
 
88
90
  const toggleStep = async (task, index, input) => {
91
+ // render() rebuilds the open edit form; keep unsaved edits alive.
92
+ if (editingId) return;
89
93
  const roomId = app.state.room?.id;
90
94
  if (!roomId) return;
91
95
  const steps = stepsOf(task).map((step, position) => position === index ? { ...step, done: input.checked } : step);
@@ -109,6 +113,8 @@ export function initTasks(app) {
109
113
  };
110
114
 
111
115
  const changeStatus = async (task, select) => {
116
+ // render() rebuilds the open edit form; keep unsaved edits alive.
117
+ if (editingId) return;
112
118
  const roomId = app.state.room?.id, next = select.value;
113
119
  if (!roomId || next === statusOf(task)) return;
114
120
  select.disabled = true;
@@ -193,6 +199,8 @@ export function initTasks(app) {
193
199
  const view = {
194
200
  app, statusOf, updatedOf, canEdit, canStatus, stepsOf, participantsOf, dateValue, formatDue, isOverdue,
195
201
  isEditing: (task) => task.id === editingId,
202
+ // One open editor owns the board; other rows stay visible but inert.
203
+ isLocked: () => Boolean(editingId),
196
204
  onStatus: changeStatus, onEdit: startEdit, onDelete: removeTask, onToggleStep: toggleStep,
197
205
  showError, onCancel: cancelEdit, onSave: saveEdit,
198
206
  };
@@ -231,6 +239,7 @@ export function initTasks(app) {
231
239
  if (!empty.hidden) app.setText(empty, items.length ? "tasksEmptyFiltered" : "tasksEmpty");
232
240
  summary.textContent = items.length ? app.t("tasksSummary", { count: visible.length }) : "";
233
241
  syncClear();
242
+ refresh.disabled = loading || Boolean(editingId);
234
243
  if (editingId && focusEdit) {
235
244
  focusEdit = false;
236
245
  groups.querySelector(".task-edit-title")?.focus();
@@ -394,7 +403,7 @@ export function initTasks(app) {
394
403
 
395
404
  trigger.addEventListener("click", () => { app.closePanels(); open(); });
396
405
  $("#btnCloseTasks")?.addEventListener("click", () => close());
397
- refresh.addEventListener("click", () => void load());
406
+ refresh.addEventListener("click", () => { if (!editingId) void load(); });
398
407
  $("#btnRetryTasks")?.addEventListener("click", () => void load());
399
408
  filter.addEventListener("change", render);
400
409
  createDetails.addEventListener("toggle", () => {
@@ -470,6 +479,24 @@ export function initTasks(app) {
470
479
  close();
471
480
  });
472
481
  document.addEventListener("chat-room-activated", () => {
482
+ // A modal blocks the room switch, so only the side pane survives it.
483
+ if (dialog.open && dialog.classList.contains("is-pane") && app.state.room?.kind !== "direct") {
484
+ items = [];
485
+ editingId = "";
486
+ filter.value = "all";
487
+ // A draft typed for the previous room must not be created in the new one.
488
+ createDetails.open = false;
489
+ resetCreate();
490
+ generation++;
491
+ // The previous room's load may still be in flight and will bail on the
492
+ // newer generation without clearing its busy flag; reset it here.
493
+ setBusy(false);
494
+ failed = false;
495
+ render();
496
+ syncHead();
497
+ void load();
498
+ return;
499
+ }
473
500
  close(false);
474
501
  items = [];
475
502
  editingId = "";
@@ -5,7 +5,12 @@ export function initViewport() {
5
5
  if (!viewport) return;
6
6
  let lastHeight = viewport.height;
7
7
 
8
+ // Pinch zoom shrinks visualViewport.height while the layout stays the same
9
+ // size. Resizing the app then would collapse the whole UI under the fingers.
10
+ const zoomed = () => Math.abs((viewport.scale || 1) - 1) > 0.01;
11
+
8
12
  const sync = () => {
13
+ if (zoomed()) return;
9
14
  root.style.setProperty("--app-height", `${Math.round(viewport.height)}px`);
10
15
  if (viewport.height < lastHeight - 80 && document.activeElement?.id === "msgInput") {
11
16
  requestAnimationFrame(() => {
@@ -12,7 +12,19 @@
12
12
  .room-title-row { display: flex; align-items: center; min-width: 0; gap: 8px; }
13
13
  .room-title-row h1 { flex: 1; min-width: 0; }
14
14
  .rooms-drawer-trigger { display: none; }
15
- .room-drawer-backdrop { position: fixed; inset: 0; z-index: 49; border: 0; background: rgb(9 16 22 / .38); }
15
+ .room-drawer-backdrop {
16
+ position: fixed;
17
+ inset: 0;
18
+ z-index: 49;
19
+ border: 0;
20
+ background: rgb(9 16 22 / .38);
21
+ opacity: 0;
22
+ pointer-events: none;
23
+ transition: opacity .2s cubic-bezier(.2, .7, .3, 1);
24
+ }
25
+ .room-drawer-backdrop.is-open { opacity: 1; pointer-events: auto; }
26
+ /* Phones rarely have a hardware keyboard, so the shortcut hint would be noise. */
27
+ html[data-mobile="true"] #btnShortcuts { display: none; }
16
28
  .room-meta { margin: 4px 0 0; font-size: 11px; color: var(--ink-3); }
17
29
  .room-description { margin: 4px 0 0; font-size: 12.5px; line-height: 1.5; color: var(--ink-2); white-space: pre-wrap; overflow-wrap: anywhere; }
18
30
  .mono { font-family: var(--font-mono); }
@@ -315,6 +327,18 @@
315
327
  .resource-size, .resource-status { color: var(--ink-3); font-size: 12px; }
316
328
  .resource-status { margin: 0; }
317
329
  .resource-button { min-height: 34px; }
330
+ .copy-action { position: relative; display: grid; place-items: center; width: 34px; height: 34px; padding: 0; border: 1px solid transparent; border-radius: 8px; color: var(--ink-3); background: transparent; cursor: pointer; transition: color .12s, border-color .12s, background .12s; }
331
+ .copy-action svg { width: 16px; height: 16px; }
332
+ .copy-action:hover { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 24%, transparent); background: var(--accent-soft); }
333
+ .copy-action:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
334
+ .copy-action.is-copied { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 30%, transparent); background: var(--accent-soft); }
335
+ .copy-action.is-copy-failed { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 28%, transparent); background: var(--danger-soft); }
336
+ .copy-action .copy-check { display: none; }
337
+ .copy-action.is-copied .copy-icon { display: none; }
338
+ .copy-action.is-copied .copy-check { display: block; }
339
+ .resource-copy { border-color: var(--line); background: var(--surface); }
340
+ .copy-feedback { position: absolute; top: calc(100% + 6px); right: 0; z-index: 6; width: max-content; max-width: 200px; padding: 3px 7px; border-radius: 6px; background: var(--ink); color: var(--surface); font: 600 10.5px/1.35 var(--font-sans); text-align: center; opacity: 0; transform: translateY(-2px); pointer-events: none; transition: opacity .12s ease, transform .12s ease; }
341
+ .copy-action.is-copied .copy-feedback, .copy-action.is-copy-failed .copy-feedback { opacity: 1; transform: none; }
318
342
  .chat-resource img, .chat-resource video { display: block; max-width: 100%; max-height: 420px; border-radius: 7px; }
319
343
  .chat-resource audio { width: min(100%, 420px); }
320
344
 
@@ -0,0 +1,141 @@
1
+ /* Mermaid diagrams open in a near-full-screen reading surface with zoom and pan. */
2
+ .diagram-viewer {
3
+ width: calc(100vw - 16px);
4
+ max-width: none;
5
+ height: calc(100dvh - 16px);
6
+ max-height: none;
7
+ margin: auto;
8
+ padding: 0;
9
+ overflow: hidden;
10
+ color: var(--ink);
11
+ background: var(--surface);
12
+ border: 1px solid color-mix(in srgb, var(--accent) 20%, var(--line));
13
+ border-radius: 18px;
14
+ box-shadow: 0 24px 80px rgb(10 25 20 / .28);
15
+ }
16
+ .diagram-viewer[open] { display: flex; flex-direction: column; animation: diagram-viewer-in .16s ease-out both; }
17
+ .diagram-viewer::backdrop { background: rgb(9 22 18 / .58); backdrop-filter: blur(4px); }
18
+ @keyframes diagram-viewer-in { from { opacity: 0; } }
19
+
20
+ .diagram-viewer-toolbar {
21
+ display: flex;
22
+ flex: none;
23
+ align-items: center;
24
+ gap: 8px;
25
+ min-height: 56px;
26
+ padding: 8px 10px 8px 16px;
27
+ border-bottom: 1px solid color-mix(in srgb, var(--line) 84%, transparent);
28
+ background: linear-gradient(180deg, color-mix(in srgb, var(--surface) 86%, var(--accent-soft)), var(--surface));
29
+ }
30
+ .diagram-viewer-toolbar h2 {
31
+ min-width: 0;
32
+ margin: 0;
33
+ overflow: hidden;
34
+ font-family: var(--font-display);
35
+ font-size: 16px;
36
+ font-weight: 650;
37
+ line-height: 1.3;
38
+ letter-spacing: -.01em;
39
+ text-overflow: ellipsis;
40
+ white-space: nowrap;
41
+ }
42
+ .diagram-viewer-tools {
43
+ display: flex;
44
+ flex: none;
45
+ align-items: center;
46
+ gap: 1px;
47
+ margin-left: auto;
48
+ padding: 2px;
49
+ border: 1px solid var(--line);
50
+ border-radius: 999px;
51
+ background: var(--surface-2);
52
+ }
53
+ .diagram-viewer-tool {
54
+ display: grid;
55
+ place-items: center;
56
+ min-width: 34px;
57
+ height: 34px;
58
+ padding: 0 8px;
59
+ border: 1px solid transparent;
60
+ border-radius: 999px;
61
+ color: var(--ink-2);
62
+ background: transparent;
63
+ font: inherit;
64
+ font-size: 12px;
65
+ font-weight: 650;
66
+ line-height: 1;
67
+ cursor: pointer;
68
+ }
69
+ .diagram-viewer-tool .fluent-icon { width: 16px; height: 16px; }
70
+ .diagram-viewer-tool:hover { color: var(--ink); background: var(--surface); }
71
+ .diagram-viewer-tool:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
72
+ .diagram-viewer-tool:disabled { opacity: .38; cursor: default; background: transparent; }
73
+ .diagram-viewer-level {
74
+ min-width: 48px;
75
+ text-align: center;
76
+ color: var(--ink-3);
77
+ font: 600 11.5px/1 var(--font-mono);
78
+ font-variant-numeric: tabular-nums;
79
+ letter-spacing: .02em;
80
+ }
81
+ .diagram-viewer-fit { padding: 0 11px; }
82
+ .diagram-viewer .reader-close { flex: none; width: 38px; height: 38px; }
83
+
84
+ .diagram-viewer-body {
85
+ position: relative;
86
+ flex: 1 1 auto;
87
+ min-height: 0;
88
+ overflow: hidden;
89
+ overscroll-behavior: none;
90
+ touch-action: none;
91
+ user-select: none;
92
+ -webkit-user-select: none;
93
+ background-color: var(--surface);
94
+ background-image:
95
+ radial-gradient(circle at 1px 1px, color-mix(in srgb, var(--ink) 11%, transparent) 1px, transparent 0),
96
+ linear-gradient(180deg, color-mix(in srgb, var(--surface-2) 55%, var(--surface)), var(--surface));
97
+ background-size: 22px 22px, auto;
98
+ }
99
+ .diagram-viewer-stage { position: absolute; left: 50%; top: 50%; transform-origin: center; will-change: transform; }
100
+ .diagram-viewer-stage, .diagram-viewer-stage * { touch-action: none; }
101
+ .diagram-viewer-stage > svg { display: block; width: 100%; height: 100%; max-width: none; max-height: none; }
102
+ .diagram-viewer-body.is-pannable .diagram-viewer-stage { cursor: grab; }
103
+ .diagram-viewer-body.is-dragging .diagram-viewer-stage { cursor: grabbing; }
104
+ .diagram-viewer-source {
105
+ margin: 0;
106
+ padding: 20px;
107
+ color: var(--ink-2);
108
+ font: 12.5px/1.6 var(--font-mono);
109
+ white-space: pre-wrap;
110
+ overflow-wrap: anywhere;
111
+ user-select: text;
112
+ }
113
+ body.diagram-viewer-open { overflow: hidden; overscroll-behavior: none; }
114
+
115
+ /* A rendered diagram reads as a button without shifting its layout. */
116
+ .mermaid-diagram[role="button"] { cursor: zoom-in; border-radius: 10px; transition: background-color .14s ease, box-shadow .14s ease; }
117
+ .mermaid-diagram[role="button"]:hover {
118
+ background: color-mix(in srgb, var(--accent) 5%, transparent);
119
+ box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 26%, transparent), 0 0 0 4px color-mix(in srgb, var(--accent) 8%, transparent);
120
+ }
121
+ .mermaid-diagram[role="button"]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
122
+
123
+ @media (max-width: 560px) {
124
+ .diagram-viewer { width: calc(100vw - 10px); height: calc(100dvh - 10px); border-radius: 14px; }
125
+ .diagram-viewer-toolbar { gap: 4px; min-height: 50px; padding: 6px 4px 6px 12px; }
126
+ .diagram-viewer-toolbar h2 { font-size: 14px; }
127
+ .diagram-viewer-tool { min-width: 30px; height: 30px; padding: 0 5px; }
128
+ .diagram-viewer-tool .fluent-icon { width: 14px; height: 14px; }
129
+ .diagram-viewer-level { min-width: 42px; font-size: 10.5px; }
130
+ .diagram-viewer-fit { padding: 0 8px; }
131
+ .diagram-viewer .reader-close { width: 34px; height: 34px; }
132
+ }
133
+ @media (max-width: 370px) {
134
+ .diagram-viewer-toolbar { justify-content: space-between; }
135
+ .diagram-viewer-toolbar h2 { display: none; }
136
+ .diagram-viewer-tools { margin-left: 0; }
137
+ }
138
+ @media (prefers-reduced-motion: reduce) {
139
+ .diagram-viewer[open] { animation: none; }
140
+ .mermaid-diagram[role="button"] { transition: none; }
141
+ }